|
@@ -726,24 +726,25 @@ CommandCost CmdBuildRailVehicle(TileInde
|
|
|
DiagDirection dir = GetRailDepotDirection(tile);
|
|
|
int x = TileX(tile) * TILE_SIZE + _vehicle_initial_x_fract[dir];
|
|
|
int y = TileY(tile) * TILE_SIZE + _vehicle_initial_y_fract[dir];
|
|
|
|
|
|
v = new (v) Train();
|
|
|
v->unitnumber = unit_num;
|
|
|
v->direction = DiagDirToDir(dir);
|
|
|
v->tile = tile;
|
|
|
v->owner = _current_player;
|
|
|
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;
|
|
|
v->cargo_type = rvi->cargo_type;
|
|
|
v->cargo_subtype = 0;
|
|
|
v->cargo_cap = rvi->capacity;
|
|
|
v->max_speed = rvi->max_speed;
|
|
|
v->value = value.GetCost();
|
|
|
v->last_station_visited = INVALID_STATION;
|
|
|
v->dest_tile = 0;
|
|
|
|
|
|
v->engine_type = p1;
|
|
@@ -3586,24 +3587,25 @@ Money Train::GetRunningCost() const
|
|
|
|
|
|
return cost;
|
|
|
}
|
|
|
|
|
|
|
|
|
void Train::Tick()
|
|
|
{
|
|
|
if (_age_cargo_skip_counter == 0) this->cargo.AgeCargo();
|
|
|
|
|
|
this->tick_counter++;
|
|
|
|
|
|
if (IsFrontEngine(this)) {
|
|
|
if (!(this->vehstatus & VS_STOPPED)) this->running_ticks++;
|
|
|
this->current_order_time++;
|
|
|
|
|
|
TrainLocoHandler(this, false);
|
|
|
|
|
|
/* make sure vehicle wasn't deleted. */
|
|
|
if (this->type == VEH_TRAIN && IsFrontEngine(this))
|
|
|
TrainLocoHandler(this, true);
|
|
|
} else if (IsFreeWagon(this) && HASBITS(this->vehstatus, VS_CRASHED)) {
|
|
|
/* Delete flooded standalone wagon chain */
|
|
|
if (++this->u.rail.crash_anim_pos >= 4400) DeleteVehicleChain(this);
|
|
|
}
|
|
|
}
|
|
@@ -3656,29 +3658,30 @@ void Train::OnNewDay()
|
|
|
AgeVehicle(this);
|
|
|
|
|
|
CheckIfTrainNeedsService(this);
|
|
|
|
|
|
CheckOrders(this);
|
|
|
|
|
|
/* update destination */
|
|
|
if (this->current_order.type == OT_GOTO_STATION) {
|
|
|
TileIndex tile = GetStation(this->current_order.dest)->train_tile;
|
|
|
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);
|
|
|
|
|
|
this->profit_this_year -= cost.GetCost() >> 8;
|
|
|
CommandCost cost(EXPENSES_TRAIN_RUN, this->GetRunningCost() * this->running_ticks / (364 * DAY_TICKS));
|
|
|
|
|
|
this->profit_this_year -= cost.GetCost();
|
|
|
this->running_ticks = 0;
|
|
|
|
|
|
SubtractMoneyFromPlayerFract(this->owner, cost);
|
|
|
|
|
|
InvalidateWindow(WC_VEHICLE_DETAILS, this->index);
|
|
|
InvalidateWindowClasses(WC_TRAINS_LIST);
|
|
|
}
|
|
|
} else if (IsTrainEngine(this)) {
|
|
|
/* Also age engines that aren't front engines */
|
|
|
AgeVehicle(this);
|
|
|
}
|
|
|
}
|
|
|
|