diff options
author | rubidium <rubidium@openttd.org> | 2007-08-29 21:27:16 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2007-08-29 21:27:16 +0000 |
commit | 3f3b013b99ac0378ed94098ca19e864d208880c7 (patch) | |
tree | c750fba2dc3e7efcc74cbccf329c29e874b3102e /src/train_cmd.cpp | |
parent | 99409d99d0cffdbd82aaa5f3a6f5da2c96623678 (diff) | |
download | openttd-3f3b013b99ac0378ed94098ca19e864d208880c7.tar.xz |
(svn r10999) -Codechange: unify the way the running cost of a vehicle is determined. Patch by nycom.
Diffstat (limited to 'src/train_cmd.cpp')
-rw-r--r-- | src/train_cmd.cpp | 37 |
1 files changed, 20 insertions, 17 deletions
diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index 59765bf40..f1c428ff5 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -3313,6 +3313,25 @@ static void TrainLocoHandler(Vehicle *v, bool mode) } + +Money Train::GetRunningCost() const +{ + Money cost = 0; + const Vehicle *v = this; + + do { + const RailVehicleInfo *rvi = RailVehInfo(v->engine_type); + + byte cost_factor = GetVehicleProperty(v, 0x0D, rvi->running_cost_base); + if (cost_factor == 0) continue; + + cost += cost_factor * _price.running_rail[rvi->running_cost_class]; + } while ((v = GetNextVehicle(v)) != NULL); + + return cost; +} + + void Train::Tick() { if (_age_cargo_skip_counter == 0) this->cargo.AgeCargo(); @@ -3384,22 +3403,6 @@ static void CheckIfTrainNeedsService(Vehicle *v) InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR); } -Money GetTrainRunningCost(const Vehicle *v) -{ - Money cost = 0; - - do { - const RailVehicleInfo *rvi = RailVehInfo(v->engine_type); - - byte cost_factor = GetVehicleProperty(v, 0x0D, rvi->running_cost_base); - if (cost_factor == 0) continue; - - cost += cost_factor * _price.running_rail[rvi->running_cost_class]; - } while ((v = GetNextVehicle(v)) != NULL); - - return cost; -} - void OnNewDay_Train(Vehicle *v) { if ((++v->day_counter & 7) == 0) DecreaseVehicleValue(v); @@ -3420,7 +3423,7 @@ void OnNewDay_Train(Vehicle *v) if ((v->vehstatus & VS_STOPPED) == 0) { /* running costs */ - CommandCost cost(GetTrainRunningCost(v) / 364); + CommandCost cost(v->GetRunningCost() / 364); v->profit_this_year -= cost.GetCost() >> 8; |