summaryrefslogtreecommitdiff
path: root/src/town_cmd.cpp
diff options
context:
space:
mode:
authorsmatz <smatz@openttd.org>2008-04-04 15:10:54 +0000
committersmatz <smatz@openttd.org>2008-04-04 15:10:54 +0000
commit401c7b675293ff2127a4c6b29b730f57f8422d07 (patch)
tree14e274ea4f6cbf2bc11dc5bdbbd72443fd676085 /src/town_cmd.cpp
parent39dc3d3eda780939d12c848b920390e44d4bb5a6 (diff)
downloadopenttd-401c7b675293ff2127a4c6b29b730f57f8422d07.tar.xz
(svn r12561) -Fix: do not affect town rating change by the order in which we examine stations
Diffstat (limited to 'src/town_cmd.cpp')
-rw-r--r--src/town_cmd.cpp11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp
index 777da9c8e..5837b7896 100644
--- a/src/town_cmd.cpp
+++ b/src/town_cmd.cpp
@@ -2261,16 +2261,23 @@ static void UpdateTownGrowRate(Town *t)
if (st->time_since_load <= 20 || st->time_since_unload <= 20) {
n++;
if (IsValidPlayer(st->owner)) {
- t->ratings[st->owner] = min((int)RATING_MAXIMUM, t->ratings[st->owner] + RATING_STATION_UP_STEP);
+ int new_rating = t->ratings[st->owner] + RATING_STATION_UP_STEP;
+ t->ratings[st->owner] = min(new_rating, INT16_MAX); // do not let it overflow
}
} else {
if (IsValidPlayer(st->owner)) {
- t->ratings[st->owner] = max((int)RATING_MINIMUM, t->ratings[st->owner] + RATING_STATION_DOWN_STEP);
+ int new_rating = t->ratings[st->owner] + RATING_STATION_DOWN_STEP;
+ t->ratings[st->owner] = max(new_rating, INT16_MIN);
}
}
}
}
+ /* clamp all ratings to valid values */
+ for (uint i = 0; i < MAX_PLAYERS; i++) {
+ t->ratings[i] = Clamp(t->ratings[i], RATING_MINIMUM, RATING_MAXIMUM);
+ }
+
ClrBit(t->flags12, TOWN_IS_FUNDED);
if (_patches.town_growth_rate == 0 && t->fund_buildings_months == 0) return;