summaryrefslogtreecommitdiff
path: root/src/train_cmd.cpp
diff options
context:
space:
mode:
authorsmatz <smatz@openttd.org>2008-02-13 19:24:40 +0000
committersmatz <smatz@openttd.org>2008-02-13 19:24:40 +0000
commita0ddc43e92c33436bccc0d16ae935237e02a357e (patch)
treeaf07b8c3ed3437ba91111379ab438956940c60bb /src/train_cmd.cpp
parentb7cd7919883ebec71a0e8ac88beb4bf72312e0d2 (diff)
downloadopenttd-a0ddc43e92c33436bccc0d16ae935237e02a357e.tar.xz
(svn r12134) -Change: count the number of ticks a vehicle was running this day to calculate running cost
-Fix [FS#1739]: vehicle profit is now counted with 8bit fract, so it is now shown properly in the vehicle details window
Diffstat (limited to 'src/train_cmd.cpp')
-rw-r--r--src/train_cmd.cpp9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp
index 1cfb2feb9..b890a7a8d 100644
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -735,6 +735,7 @@ CommandCost CmdBuildRailVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32
v->x_pos = x;
v->y_pos = y;
v->z_pos = GetSlopeZ(x, y);
+ v->running_ticks = 0;
v->u.rail.track = TRACK_BIT_DEPOT;
v->vehstatus = VS_HIDDEN | VS_STOPPED | VS_DEFPAL;
v->spritenum = rvi->image_index;
@@ -3595,6 +3596,7 @@ void Train::Tick()
this->tick_counter++;
if (IsFrontEngine(this)) {
+ if (!(this->vehstatus & VS_STOPPED)) this->running_ticks++;
this->current_order_time++;
TrainLocoHandler(this, false);
@@ -3665,11 +3667,12 @@ void Train::OnNewDay()
if (tile != 0) this->dest_tile = tile;
}
- if ((this->vehstatus & VS_STOPPED) == 0) {
+ if (this->running_ticks != 0) {
/* running costs */
- CommandCost cost(EXPENSES_TRAIN_RUN, this->GetRunningCost() / 364);
+ CommandCost cost(EXPENSES_TRAIN_RUN, this->GetRunningCost() * this->running_ticks / (364 * DAY_TICKS));
- this->profit_this_year -= cost.GetCost() >> 8;
+ this->profit_this_year -= cost.GetCost();
+ this->running_ticks = 0;
SubtractMoneyFromPlayerFract(this->owner, cost);