|
@@ -216,12 +216,14 @@ CommandCost CmdBuildRoadVeh(TileIndex ti
|
|
|
x = TileX(tile) * TILE_SIZE + TILE_SIZE / 2;
|
|
|
y = TileY(tile) * TILE_SIZE + TILE_SIZE / 2;
|
|
|
v->x_pos = x;
|
|
|
v->y_pos = y;
|
|
|
v->z_pos = GetSlopeZ(x, y);
|
|
|
|
|
|
v->running_ticks = 0;
|
|
|
|
|
|
v->u.road.state = RVSB_IN_DEPOT;
|
|
|
v->vehstatus = VS_HIDDEN | VS_STOPPED | VS_DEFPAL;
|
|
|
|
|
|
v->spritenum = rvi->image_index;
|
|
|
v->cargo_type = rvi->cargo_type;
|
|
|
v->cargo_subtype = 0;
|
|
@@ -1963,13 +1965,16 @@ static void AgeRoadVehCargo(Vehicle *v)
|
|
|
}
|
|
|
|
|
|
void RoadVehicle::Tick()
|
|
|
{
|
|
|
AgeRoadVehCargo(this);
|
|
|
|
|
|
if (IsRoadVehFront(this)) RoadVehController(this);
|
|
|
if (IsRoadVehFront(this)) {
|
|
|
if (!(this->vehstatus & VS_STOPPED)) this->running_ticks++;
|
|
|
RoadVehController(this);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
static void CheckIfRoadVehNeedsService(Vehicle *v)
|
|
|
{
|
|
|
/* If we already got a slot at a stop, use that FIRST, and go to a depot later */
|
|
|
if (v->u.road.slot != NULL || _patches.servint_roadveh == 0 || !VehicleNeedsService(v)) return;
|
|
@@ -2005,14 +2010,12 @@ static void CheckIfRoadVehNeedsService(V
|
|
|
v->dest_tile = depot->xy;
|
|
|
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH);
|
|
|
}
|
|
|
|
|
|
void RoadVehicle::OnNewDay()
|
|
|
{
|
|
|
CommandCost cost(EXPENSES_ROADVEH_RUN);
|
|
|
|
|
|
if (!IsRoadVehFront(this)) return;
|
|
|
|
|
|
if ((++this->day_counter & 7) == 0) DecreaseVehicleValue(this);
|
|
|
if (this->u.road.blocked_ctr == 0) CheckVehicleBreakdown(this);
|
|
|
|
|
|
AgeVehicle(this);
|
|
@@ -2024,16 +2027,14 @@ void RoadVehicle::OnNewDay()
|
|
|
if (this->current_order.type == OT_GOTO_STATION && this->u.road.slot != NULL && this->u.road.slot_age-- == 0) {
|
|
|
DEBUG(ms, 3, "Slot expired for vehicle %d (index %d) at stop 0x%X",
|
|
|
this->unitnumber, this->index, this->u.road.slot->xy);
|
|
|
ClearSlot(this);
|
|
|
}
|
|
|
|
|
|
if (this->vehstatus & VS_STOPPED) return;
|
|
|
|
|
|
/* update destination */
|
|
|
if (this->current_order.type == OT_GOTO_STATION && this->u.road.slot == NULL && !(this->vehstatus & VS_CRASHED)) {
|
|
|
if (!(this->vehstatus & VS_STOPPED) && this->current_order.type == OT_GOTO_STATION && this->u.road.slot == NULL && !(this->vehstatus & VS_CRASHED)) {
|
|
|
Station *st = GetStation(this->current_order.dest);
|
|
|
RoadStop *rs = st->GetPrimaryRoadStop(this);
|
|
|
RoadStop *best = NULL;
|
|
|
|
|
|
if (rs != NULL) {
|
|
|
/* We try to obtain a slot if:
|
|
@@ -2085,15 +2086,18 @@ void RoadVehicle::OnNewDay()
|
|
|
} else {
|
|
|
DEBUG(ms, 4, "No road stop for vehicle %d (index %d) at station %d (0x%X)",
|
|
|
this->unitnumber, this->index, st->index, st->xy);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
cost = CommandCost(EXPENSES_ROADVEH_RUN, RoadVehInfo(this->engine_type)->running_cost * _price.roadveh_running / 364);
|
|
|
if (this->running_ticks == 0) return;
|
|
|
|
|
|
this->profit_this_year -= cost.GetCost() >> 8;
|
|
|
CommandCost cost(EXPENSES_ROADVEH_RUN, RoadVehInfo(this->engine_type)->running_cost * _price.roadveh_running * 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_ROADVEH_LIST);
|
|
|
}
|