Fix industry production scaling of periodic production callback
This commit is contained in:
@@ -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)
|
static void ProduceIndustryGoods(Industry *i)
|
||||||
{
|
{
|
||||||
const IndustrySpec *indsp = GetIndustrySpec(i->type);
|
const IndustrySpec *indsp = GetIndustrySpec(i->type);
|
||||||
@@ -1187,19 +1200,22 @@ static void ProduceIndustryGoods(Industry *i)
|
|||||||
|
|
||||||
i->counter--;
|
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 */
|
/* produce some cargo */
|
||||||
if ((i->counter % INDUSTRY_PRODUCE_TICKS) == 0) {
|
if ((i->counter % INDUSTRY_PRODUCE_TICKS) == 0) {
|
||||||
|
if (!scale_ticks) {
|
||||||
if (HasBit(indsp->callback_mask, CBM_IND_PRODUCTION_256_TICKS)) IndustryProductionCallback(i, 1);
|
if (HasBit(indsp->callback_mask, CBM_IND_PRODUCTION_256_TICKS)) IndustryProductionCallback(i, 1);
|
||||||
|
ProduceIndustryGoodsFromRate(i, true);
|
||||||
|
}
|
||||||
|
|
||||||
IndustryBehaviour indbehav = indsp->behaviour;
|
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 ((indbehav & INDUSTRYBEH_PLANT_FIELDS) != 0) {
|
if ((indbehav & INDUSTRYBEH_PLANT_FIELDS) != 0) {
|
||||||
uint16 cb_res = CALLBACK_FAILED;
|
uint16 cb_res = CALLBACK_FAILED;
|
||||||
if (HasBit(indsp->callback_mask, CBM_IND_SPECIAL_EFFECT)) {
|
if (HasBit(indsp->callback_mask, CBM_IND_SPECIAL_EFFECT)) {
|
||||||
@@ -1251,6 +1267,7 @@ void OnTick_Industry()
|
|||||||
|
|
||||||
if (_game_mode == GM_EDITOR) return;
|
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()) {
|
for (Industry *i : Industry::Iterate()) {
|
||||||
ProduceIndustryGoods(i);
|
ProduceIndustryGoods(i);
|
||||||
}
|
}
|
||||||
|
@@ -579,6 +579,12 @@ class NIHIndustry : public NIHelper {
|
|||||||
print(buffer);
|
print(buffer);
|
||||||
seprintf(buffer, lastof(buffer), " CBM_IND_PRODUCTION_256_TICKS: %s", HasBit(indsp->callback_mask, CBM_IND_PRODUCTION_256_TICKS) ? "yes" : "no");
|
seprintf(buffer, lastof(buffer), " CBM_IND_PRODUCTION_256_TICKS: %s", HasBit(indsp->callback_mask, CBM_IND_PRODUCTION_256_TICKS) ? "yes" : "no");
|
||||||
print(buffer);
|
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
|
type = SLE_INT16
|
||||||
guiflags = SGF_DECIMAL1
|
guiflags = SGF_DECIMAL1
|
||||||
def = 0
|
def = 0
|
||||||
min = -160
|
min = -50
|
||||||
max = +80
|
max = +50
|
||||||
interval = 1
|
interval = 1
|
||||||
str = STR_CONFIG_SETTING_INDUSTRY_CARGO_FACTOR
|
str = STR_CONFIG_SETTING_INDUSTRY_CARGO_FACTOR
|
||||||
strval = STR_JUST_DECIMAL1
|
strval = STR_JUST_DECIMAL1
|
||||||
|
Reference in New Issue
Block a user