i'm like some insights on how the industry count target are computed, because the code doesn't seem to make any sense to me.
I'm struggling with the wanted_inds variable and its uses.
The variable seems to be initialized only in IndustryBuildData::Reset(), where we write the current amount of industries in the map into the higher 16bits, or when loading a save.
In other parts of the code, we fetch that value to see it we need to create industries by comparing the actual industry count and the target "wanted_inds". (SetupTargetCount for example)
My main issue is MonthlyLoop, where we increase the lower 16bits of the variables in a particular check if validated.
Meaning that after doing this a lot of times, we'll actually increase the 16 higher bits.
Snippet:
Code: Select all
/* To prevent running out of unused industries for the player to connect,
* add a fraction of new industries each month, but only if the manager can keep up. */
uint max_behind = 1 + std::min(99u, ScaleByMapSize(3)); // At most 2 industries for small maps, and 100 at the biggest map (about 6 months industry build attempts).
if (GetCurrentTotalNumberOfIndustries() + max_behind >= (this->wanted_inds >> 16)) {
this->wanted_inds += ScaleByMapSize(NEWINDS_PER_MONTH);
}
This doesn't seem right, and I'm wondering if I missed something, an obfuscated use / modification through pointer arithmetic. Any help is appreciated.
This far, i'm thinking of rewriting this part and:
- Keep the "industry density" parameter for map creation only
- Add a new option "industry creation" for game only in the environment -> industry menu, with three possible values: "Funding only", "Original behavior", "Maintain industry density".
What's your opinion ?