mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-07-19 18:35:48 +01:00
(svn r18270) -Codechange: split the code for finding a road stop to stop at into a seperate function
This commit is contained in:
parent
e57d6a8e48
commit
32926facf9
@ -130,6 +130,7 @@ struct RoadVehicle : public SpecializedVehicle<RoadVehicle, VEH_ROAD> {
|
||||
Trackdir GetVehicleTrackdir() const;
|
||||
TileIndex GetOrderStationLocation(StationID station);
|
||||
bool FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse);
|
||||
void FindRoadStopSlot();
|
||||
|
||||
/**
|
||||
* Check if vehicle is a front engine
|
||||
|
@ -1906,12 +1906,40 @@ void RoadVehicle::OnNewDay()
|
||||
}
|
||||
|
||||
/* update destination */
|
||||
if (!(this->vehstatus & VS_STOPPED) && this->current_order.IsType(OT_GOTO_STATION) && !(this->current_order.GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) && this->slot == NULL && !(this->vehstatus & VS_CRASHED)) {
|
||||
this->FindRoadStopSlot();
|
||||
|
||||
if (this->running_ticks == 0) return;
|
||||
|
||||
CommandCost cost(EXPENSES_ROADVEH_RUN, this->GetRunningCost() * this->running_ticks / (DAYS_IN_YEAR * DAY_TICKS));
|
||||
|
||||
this->profit_this_year -= cost.GetCost();
|
||||
this->running_ticks = 0;
|
||||
|
||||
SubtractMoneyFromCompanyFract(this->owner, cost);
|
||||
|
||||
SetWindowDirty(WC_VEHICLE_DETAILS, this->index);
|
||||
SetWindowClassesDirty(WC_ROADVEH_LIST);
|
||||
}
|
||||
|
||||
void RoadVehicle::FindRoadStopSlot()
|
||||
{
|
||||
if (this->slot != NULL ||
|
||||
(this->vehstatus & (VS_STOPPED | VS_CRASHED)) != 0 ||
|
||||
!this->current_order.IsType(OT_GOTO_STATION) ||
|
||||
(this->current_order.GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
Station *st = Station::Get(this->current_order.GetDestination());
|
||||
RoadStop *rs = st->GetPrimaryRoadStop(this);
|
||||
RoadStop *best = NULL;
|
||||
|
||||
if (rs != NULL) {
|
||||
if (rs == NULL) {
|
||||
DEBUG(ms, 4, "No road stop for vehicle %d (index %d) at station %d (0x%X)",
|
||||
this->unitnumber, this->index, st->index, st->xy);
|
||||
return;
|
||||
}
|
||||
|
||||
/* We try to obtain a slot if:
|
||||
* 1) we're reasonably close to the primary road stop
|
||||
* or
|
||||
@ -1962,23 +1990,6 @@ void RoadVehicle::OnNewDay()
|
||||
DEBUG(ms, 5, "Distance from station too far. Postponing slotting for vehicle %d (index %d) at station %d, (0x%X)",
|
||||
this->unitnumber, this->index, st->index, st->xy);
|
||||
}
|
||||
} 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);
|
||||
}
|
||||
}
|
||||
|
||||
if (this->running_ticks == 0) return;
|
||||
|
||||
CommandCost cost(EXPENSES_ROADVEH_RUN, this->GetRunningCost() * this->running_ticks / (DAYS_IN_YEAR * DAY_TICKS));
|
||||
|
||||
this->profit_this_year -= cost.GetCost();
|
||||
this->running_ticks = 0;
|
||||
|
||||
SubtractMoneyFromCompanyFract(this->owner, cost);
|
||||
|
||||
SetWindowDirty(WC_VEHICLE_DETAILS, this->index);
|
||||
SetWindowClassesDirty(WC_ROADVEH_LIST);
|
||||
}
|
||||
|
||||
Trackdir RoadVehicle::GetVehicleTrackdir() const
|
||||
|
Loading…
Reference in New Issue
Block a user