Skip to content

Commit 7b733c7

Browse files
committed
Fix negative city population on load
When cities are loaded, their buildings do not exist yet and therefore do not contribute to total citizens. This caused an overflow during target_cities weighted vector re-calculation during load. git-svn-id: svn://tron.homeunix.org/simutrans/simutrans/trunk@11890 8aca7d54-2c30-db11-9de9-000461428c89
1 parent 24dbd4d commit 7b733c7

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/simutrans/world/simcity.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1832,9 +1832,11 @@ void stadt_t::step_passagiere()
18321832
if (step_count >= buildings.get_count()) {
18331833
step_count = 0;
18341834
}
1835+
18351836
if (buildings.empty()) {
18361837
return;
18371838
}
1839+
18381840
const gebaeude_t* gb = buildings[step_count];
18391841

18401842
// since now backtravels occur, we damp the numbers a little

src/simutrans/world/simcity.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,14 @@ class stadt_t
481481
/**
482482
* ermittelt die Einwohnerzahl der City
483483
*/
484-
sint32 get_einwohner() const {return (buildings.get_sum_weight()*6)+((2*bev-arb-won)>>1);}
484+
sint32 get_einwohner() const
485+
{
486+
const sint32 pop_from_buildings = 6 * (sint32)buildings.get_sum_weight();
487+
const sint32 pop_from_citizens = (2 * bev - arb - won) / 2;
488+
const sint32 pop = pop_from_buildings + pop_from_citizens;
489+
490+
return std::max(pop, 0);
491+
}
485492

486493
uint32 get_buildings() const { return buildings.get_count(); }
487494
sint32 get_unemployed() const { return bev - arb; }

0 commit comments

Comments
 (0)