Fix industry production scaling of periodic production callback

pull/211/head
Jonathan G Rennison 4 years ago
parent 5665d88067
commit c82f31bf03

@ -1165,6 +1165,19 @@ static void ChopLumberMillTrees(Industry *i)
}
}
static void ProduceIndustryGoodsFromRate(Industry *i, bool scale)
{
for (size_t j = 0; j < lengthof(i->produced_cargo_waiting); j++) {
uint amount = i->production_rate[j];
if (amount != 0 && scale) {
amount = ScaleQuantity(amount, _settings_game.economy.industry_cargo_scale_factor);
}
i->produced_cargo_waiting[j] = min(0xffff, i->produced_cargo_waiting[j] + amount);
}
}
static uint _scaled_production_ticks;
static void ProduceIndustryGoods(Industry *i)
{
const IndustrySpec *indsp = GetIndustrySpec(i->type);
@ -1187,19 +1200,22 @@ static void ProduceIndustryGoods(Industry *i)
i->counter--;
const bool scale_ticks = (_settings_game.economy.industry_cargo_scale_factor != 0) && HasBit(indsp->callback_mask, CBM_IND_PRODUCTION_256_TICKS);
if (scale_ticks) {
if ((i->counter % _scaled_production_ticks) == 0) {
if (HasBit(indsp->callback_mask, CBM_IND_PRODUCTION_256_TICKS)) IndustryProductionCallback(i, 1);
ProduceIndustryGoodsFromRate(i, false);
}
}
/* produce some cargo */
if ((i->counter % INDUSTRY_PRODUCE_TICKS) == 0) {
if (HasBit(indsp->callback_mask, CBM_IND_PRODUCTION_256_TICKS)) IndustryProductionCallback(i, 1);
IndustryBehaviour indbehav = indsp->behaviour;
for (size_t j = 0; j < lengthof(i->produced_cargo_waiting); j++) {
uint amount = i->production_rate[j];
if (amount != 0) {
amount = ScaleQuantity(amount, _settings_game.economy.industry_cargo_scale_factor);
}
i->produced_cargo_waiting[j] = min(0xffff, i->produced_cargo_waiting[j] + amount);
if (!scale_ticks) {
if (HasBit(indsp->callback_mask, CBM_IND_PRODUCTION_256_TICKS)) IndustryProductionCallback(i, 1);
ProduceIndustryGoodsFromRate(i, true);
}
IndustryBehaviour indbehav = indsp->behaviour;
if ((indbehav & INDUSTRYBEH_PLANT_FIELDS) != 0) {
uint16 cb_res = CALLBACK_FAILED;
if (HasBit(indsp->callback_mask, CBM_IND_SPECIAL_EFFECT)) {
@ -1251,6 +1267,7 @@ void OnTick_Industry()
if (_game_mode == GM_EDITOR) return;
_scaled_production_ticks = ScaleQuantity(INDUSTRY_PRODUCE_TICKS, -_settings_game.economy.industry_cargo_scale_factor);
for (Industry *i : Industry::Iterate()) {
ProduceIndustryGoods(i);
}

@ -579,6 +579,12 @@ class NIHIndustry : public NIHelper {
print(buffer);
seprintf(buffer, lastof(buffer), " CBM_IND_PRODUCTION_256_TICKS: %s", HasBit(indsp->callback_mask, CBM_IND_PRODUCTION_256_TICKS) ? "yes" : "no");
print(buffer);
seprintf(buffer, lastof(buffer), " Counter: %u", ind->counter);
print(buffer);
if ((_settings_game.economy.industry_cargo_scale_factor != 0) && HasBit(indsp->callback_mask, CBM_IND_PRODUCTION_256_TICKS)) {
seprintf(buffer, lastof(buffer), " Counter production interval: %u", ScaleQuantity(INDUSTRY_PRODUCE_TICKS, -_settings_game.economy.industry_cargo_scale_factor));
print(buffer);
}
}
}
};

@ -1194,8 +1194,8 @@ var = economy.industry_cargo_scale_factor
type = SLE_INT16
guiflags = SGF_DECIMAL1
def = 0
min = -160
max = +80
min = -50
max = +50
interval = 1
str = STR_CONFIG_SETTING_INDUSTRY_CARGO_FACTOR
strval = STR_JUST_DECIMAL1

Loading…
Cancel
Save