1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2026-01-18 01:42:38 +01:00

Fix #14915: Crash due to divide-by-zero of industry probabilities. (#14918)

This commit is contained in:
Peter Nelson
2025-12-15 16:42:10 +00:00
committed by GitHub
parent 859b56a066
commit f6eba87e47

View File

@@ -2474,7 +2474,7 @@ static IndustryGenerationProbabilities GetScaledProbabilities(bool water)
for (IndustryType it = 0; it < NUM_INDUSTRYTYPES; it++) {
p.probs[it] = GetScaledIndustryGenerationProbability(it, water, &p.force_one[it]);
p.total += p.probs[it];;
p.total += p.probs[it];
if (p.force_one[it]) p.num_forced++;
}
@@ -2499,7 +2499,8 @@ void GenerateIndustries()
auto &p = water ? wprob : lprob;
/* Total number of industries scaled by land/water proportion. */
uint total_amount = p.total * GetNumberOfIndustries() / (lprob.total + wprob.total);
uint total_amount = 0;
if (lprob.total + wprob.total > 0) total_amount = p.total * GetNumberOfIndustries() / (lprob.total + wprob.total);
/* Scale land-based industries to the land proportion, unless the player has set a custom industry count. */
if (!water && _settings_game.difficulty.industry_density != ID_CUSTOM) total_amount = Map::ScaleByLandProportion(total_amount);