Skip to content

Commit

Permalink
Add: NewGRF property to set town production multiplier.
Browse files Browse the repository at this point in the history
This allows adjusting the amount of cargo produces when Town Production Effect is set.
  • Loading branch information
PeterN committed Jan 7, 2024
1 parent 3e2340e commit 16d3c21
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/cargotype.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ enum CargoClass {

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

static const uint TOWN_PRODUCTION_DIVISOR = 0x100;

/** Specification of a cargo type. */
struct CargoSpec {
CargoLabel label; ///< Unique label of the cargo type.
Expand All @@ -81,6 +83,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; ///< 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.
Expand Down
4 changes: 4 additions & 0 deletions src/newgrf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3096,6 +3096,10 @@ static ChangeInfoResult CargoChangeInfo(uint cid, int numinfo, int prop, ByteRea
break;
}

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

default:
ret = CIR_UNKNOWN;
break;
Expand Down
2 changes: 1 addition & 1 deletion src/table/cargo_const.h
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand Down
4 changes: 2 additions & 2 deletions src/town_cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ static void OriginalTownProduceCargo(Town *t, TownProductionEffect tpe, uint8_t
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;

if (EconomyIsInRecession()) amt = (amt + 1) >> 1;
t->supplied[cid].new_max += amt;
Expand All @@ -544,7 +544,7 @@ static void BinominalTownProduceCargo(Town *t, TownProductionEffect tpe, uint8_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;

/* Adjust. */
if (EconomyIsInRecession()) amt = (amt + 1) >> 1;
Expand Down

0 comments on commit 16d3c21

Please sign in to comment.