summaryrefslogtreecommitdiff
path: root/src/train_cmd.cpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2007-08-29 21:27:16 +0000
committerrubidium <rubidium@openttd.org>2007-08-29 21:27:16 +0000
commitdc8019575404425b52abc121c6bd9159596fee87 (patch)
treec750fba2dc3e7efcc74cbccf329c29e874b3102e /src/train_cmd.cpp
parentfff12fd22e6e526c7a8259606bb9235f1ed97e06 (diff)
downloadopenttd-dc8019575404425b52abc121c6bd9159596fee87.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.cpp37
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;