summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2007-10-21 16:44:19 +0000
committerrubidium <rubidium@openttd.org>2007-10-21 16:44:19 +0000
commitaf9521ff141848685c80e6d535b25965cb7bfb0f (patch)
tree18768b097888c999eaa069e9e9cf1ebf9a4d63c8 /src
parentf4775d06bb53f927ad05c7e6344a4e839c884c44 (diff)
downloadopenttd-af9521ff141848685c80e6d535b25965cb7bfb0f.tar.xz
(svn r11331) -Fix: do not misuse CommandCost for overflow safe stuff as Money supports that now too.
Diffstat (limited to 'src')
-rw-r--r--src/economy.cpp39
1 files changed, 17 insertions, 22 deletions
diff --git a/src/economy.cpp b/src/economy.cpp
index 084da0c05..67e704d00 100644
--- a/src/economy.cpp
+++ b/src/economy.cpp
@@ -63,39 +63,34 @@ Money CalculateCompanyValue(const Player* p)
{
PlayerID owner = p->index;
/* Do a little nasty by using CommandCost, so we can use the "overflow" protection of CommandCost */
- CommandCost value;
+ Money value = 0;
- {
- Station *st;
- uint num = 0;
-
- FOR_ALL_STATIONS(st) {
- if (st->owner == owner) num += COUNTBITS(st->facilities);
- }
+ Station *st;
+ uint num = 0;
- value.AddCost(num * _price.station_value * 25);
+ FOR_ALL_STATIONS(st) {
+ if (st->owner == owner) num += COUNTBITS(st->facilities);
}
- {
- Vehicle *v;
+ value += num * _price.station_value * 25;
- FOR_ALL_VEHICLES(v) {
- if (v->owner != owner) continue;
+ Vehicle *v;
+ FOR_ALL_VEHICLES(v) {
+ if (v->owner != owner) continue;
- if (v->type == VEH_TRAIN ||
- v->type == VEH_ROAD ||
- (v->type == VEH_AIRCRAFT && IsNormalAircraft(v)) ||
- v->type == VEH_SHIP) {
- value.AddCost(v->value * 3 >> 1);
- }
+ if (v->type == VEH_TRAIN ||
+ v->type == VEH_ROAD ||
+ (v->type == VEH_AIRCRAFT && IsNormalAircraft(v)) ||
+ v->type == VEH_SHIP) {
+ value += v->value * 3 >> 1;
}
}
/* Add real money value */
- value.AddCost(-p->current_loan);
- value.AddCost(p->player_money);
+ value -= p->current_loan;
+ value += p->player_money;
- return max(value.GetCost(), (Money)1);
+ return max(value, (Money)1);
}
/** if update is set to true, the economy is updated with this score