Changeset - r28658:e37e71fc895e
[Not reviewed]
master
0 4 0
Peter Nelson - 4 months ago 2024-02-03 13:58:31
peter1138@openttd.org
Feature: NewGRF properties to set town production effect and multiplier. (#11947)

Town production effect is modelled on town acceptance (growth) effect, and so takes an original cargo slot for behaviour instead of a direct value.

NewGRF feature 0x0B, property 0x1E, takes 1 byte.

Valid values are:
- 0x00 to behave like passengers
- 0x02 to behave like mail
- 0xFF to behave like other cargo (i.e. not produced.)

If not set, town production effect is set based on the cargo label ('PASS' or 'MAIL').

Town production multiplier allows adjusting the amount of cargo produces when Town Production Effect is set, without needing to use callbacks.

NewGRF feature 0x0B (cargo), property 0x1F, accepts a 2 byte (word) value, similar to the cargo capacity multiplier property. The default value is 256 which means 100%, i.e. normal rate.
4 files changed with 24 insertions and 3 deletions:
0 comments (0 inline, 0 general)
src/cargotype.h
Show inline comments
 
@@ -65,6 +65,8 @@ enum CargoClass {
 

	
 
static const byte INVALID_CARGO_BITNUM = 0xFF; ///< Constant representing invalid cargo
 

	
 
static const uint TOWN_PRODUCTION_DIVISOR = 256;
 

	
 
/** Specification of a cargo type. */
 
struct CargoSpec {
 
	CargoLabel label;                ///< Unique label of the cargo type.
 
@@ -80,6 +82,7 @@ struct CargoSpec {
 
	bool is_freight;                 ///< Cargo type is considered to be freight (affects train freight multiplier).
 
	TownAcceptanceEffect town_acceptance_effect; ///< The effect that delivering this cargo type has on towns. Also affects destination of subsidies.
 
	TownProductionEffect town_production_effect{INVALID_TPE}; ///< The effect on town cargo production.
 
	uint16_t town_production_multiplier{TOWN_PRODUCTION_DIVISOR}; ///< Town production multipler, if commanded by TownProductionEffect.
 
	uint8_t callback_mask;             ///< Bitmask of cargo callbacks that have to be called
 

	
 
	StringID name;                   ///< Name of this type of cargo.
src/newgrf.cpp
Show inline comments
 
@@ -3091,6 +3091,24 @@ static ChangeInfoResult CargoChangeInfo(
 
				cs->multiplier = std::max<uint16_t>(1u, buf->ReadWord());
 
				break;
 

	
 
			case 0x1E: { // Town production substitute type
 
				uint8_t substitute_type = buf->ReadByte();
 

	
 
				switch (substitute_type) {
 
					case 0x00: cs->town_production_effect = TPE_PASSENGERS; break;
 
					case 0x02: cs->town_production_effect = TPE_MAIL; break;
 
					default:
 
						GrfMsg(1, "CargoChangeInfo: Unknown town production substitute value {}, setting to none.", substitute_type);
 
						[[fallthrough]];
 
					case 0xFF: cs->town_production_effect = TPE_NONE; break;
 
				}
 
				break;
 
			}
 

	
 
			case 0x1F: // Town production multiplier
 
				cs->town_production_multiplier = std::max<uint16_t>(1U, buf->ReadWord());
 
				break;
 

	
 
			default:
 
				ret = CIR_UNKNOWN;
 
				break;
src/table/cargo_const.h
Show inline comments
 
@@ -44,7 +44,7 @@
 
 * @param classes      Classes of this cargo type. @see CargoClass
 
 */
 
#define MK(bt, label, colour, weight, mult, ip, td1, td2, freight, tae, str_plural, str_singular, str_volume, classes) \
 
		{label, bt, colour, colour, weight, mult, classes, ip, {td1, td2}, freight, tae, INVALID_TPE, 0, \
 
		{label, bt, colour, colour, weight, mult, classes, ip, {td1, td2}, freight, tae, INVALID_TPE, TOWN_PRODUCTION_DIVISOR, 0, \
 
		MK_STR_CARGO_PLURAL(str_plural), MK_STR_CARGO_SINGULAR(str_singular), str_volume, MK_STR_QUANTITY(str_plural), MK_STR_ABBREV(str_plural), \
 
		MK_SPRITE(str_plural), nullptr, nullptr, 0}
 

	
src/town_cmd.cpp
Show inline comments
 
@@ -558,7 +558,7 @@ static void TownGenerateCargoOriginal(To
 
		uint32_t r = Random();
 
		if (GB(r, 0, 8) < rate) {
 
			CargoID cid = cs->Index();
 
			uint amt = GB(r, 0, 8) / 8 + 1;
 
			uint amt = (GB(r, 0, 8) * cs->town_production_multiplier / TOWN_PRODUCTION_DIVISOR) / 8 + 1;
 

	
 
			TownGenerateCargo(t, cid, amt, stations, true);
 
		}
 
@@ -583,7 +583,7 @@ static void TownGenerateCargoBinominal(T
 
		uint32_t genmask = (genmax >= 32) ? 0xFFFFFFFF : ((1 << genmax) - 1);
 

	
 
		/* Mask random value by potential pax and count number of actual pax. */
 
		uint amt = CountBits(r & genmask);
 
		uint amt = CountBits(r & genmask) * cs->town_production_multiplier / TOWN_PRODUCTION_DIVISOR;
 

	
 
		TownGenerateCargo(t, cid, amt, stations, true);
 
	}
0 comments (0 inline, 0 general)