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 dP
parent c681ad21fb
commit 19bd512cef

View File

@@ -2521,7 +2521,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++;
}
@@ -2546,7 +2546,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);