mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r11017) -Codechange: unify determining whether a vehicle needs/can be service a little more.
This commit is contained in:
parent
976ce8ad3f
commit
2c8e50f20c
|
@ -696,17 +696,8 @@ CommandCost CmdRefitAircraft(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
|||
|
||||
static void CheckIfAircraftNeedsService(Vehicle *v)
|
||||
{
|
||||
if (_patches.servint_aircraft == 0) return;
|
||||
if (!VehicleNeedsService(v)) return;
|
||||
if (v->vehstatus & VS_STOPPED) return;
|
||||
|
||||
if (v->current_order.type == OT_GOTO_DEPOT &&
|
||||
v->current_order.flags & OF_HALT_IN_DEPOT)
|
||||
return;
|
||||
|
||||
if (_patches.gotodepot && VehicleHasDepotOrders(v)) return;
|
||||
|
||||
if (v->IsInDepot()) {
|
||||
if (_patches.servint_aircraft == 0 || !VehicleNeedsService(v)) return;
|
||||
if (v->IsInDepot()) {
|
||||
VehicleServiceInDepot(v);
|
||||
return;
|
||||
}
|
||||
|
@ -716,7 +707,6 @@ static void CheckIfAircraftNeedsService(Vehicle *v)
|
|||
if (st->IsValid() && st->airport_tile != 0 && st->Airport()->terminals != NULL) {
|
||||
// printf("targetairport = %d, st->index = %d\n", v->u.air.targetairport, st->index);
|
||||
// v->u.air.targetairport = st->index;
|
||||
if (v->current_order.type == OT_LOADING) v->LeaveStation();
|
||||
v->current_order.type = OT_GOTO_DEPOT;
|
||||
v->current_order.flags = OF_NON_STOP;
|
||||
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
|
||||
|
|
|
@ -1841,29 +1841,15 @@ void RoadVehicle::Tick()
|
|||
|
||||
static void CheckIfRoadVehNeedsService(Vehicle *v)
|
||||
{
|
||||
const Depot* depot;
|
||||
|
||||
if (_patches.servint_roadveh == 0) return;
|
||||
if (!VehicleNeedsService(v)) return;
|
||||
if (v->vehstatus & VS_STOPPED) return;
|
||||
if (_patches.gotodepot && VehicleHasDepotOrders(v)) return;
|
||||
|
||||
/* Don't interfere with a depot visit scheduled by the user, or a
|
||||
* depot visit by the order list. */
|
||||
if (v->current_order.type == OT_GOTO_DEPOT &&
|
||||
(v->current_order.flags & (OF_HALT_IN_DEPOT | OF_PART_OF_ORDERS)) != 0)
|
||||
return;
|
||||
|
||||
/* If we already got a slot at a stop, use that FIRST, and go to a depot later */
|
||||
if (v->u.road.slot != NULL) return;
|
||||
|
||||
if (v->u.road.slot != NULL || _patches.servint_roadveh == 0 || !VehicleNeedsService(v)) return;
|
||||
if (v->IsInDepot()) {
|
||||
VehicleServiceInDepot(v);
|
||||
return;
|
||||
}
|
||||
|
||||
/* XXX If we already have a depot order, WHY do we search over and over? */
|
||||
depot = FindClosestRoadDepot(v);
|
||||
const Depot *depot = FindClosestRoadDepot(v);
|
||||
|
||||
if (depot == NULL || DistanceManhattan(v->tile, depot->xy) > 12) {
|
||||
if (v->current_order.type == OT_GOTO_DEPOT) {
|
||||
|
|
|
@ -140,24 +140,13 @@ static const Depot* FindClosestShipDepot(const Vehicle* v)
|
|||
|
||||
static void CheckIfShipNeedsService(Vehicle *v)
|
||||
{
|
||||
const Depot* depot;
|
||||
|
||||
if (_patches.servint_ships == 0) return;
|
||||
if (!VehicleNeedsService(v)) return;
|
||||
if (v->vehstatus & VS_STOPPED) return;
|
||||
|
||||
if (v->current_order.type == OT_GOTO_DEPOT &&
|
||||
v->current_order.flags & OF_HALT_IN_DEPOT)
|
||||
return;
|
||||
|
||||
if (_patches.gotodepot && VehicleHasDepotOrders(v)) return;
|
||||
|
||||
if (_patches.servint_ships == 0 || !VehicleNeedsService(v)) return;
|
||||
if (v->IsInDepot()) {
|
||||
VehicleServiceInDepot(v);
|
||||
return;
|
||||
}
|
||||
|
||||
depot = FindClosestShipDepot(v);
|
||||
const Depot *depot = FindClosestShipDepot(v);
|
||||
|
||||
if (depot == NULL || DistanceManhattan(v->tile, depot->xy) > 12) {
|
||||
if (v->current_order.type == OT_GOTO_DEPOT) {
|
||||
|
@ -168,7 +157,6 @@ static void CheckIfShipNeedsService(Vehicle *v)
|
|||
return;
|
||||
}
|
||||
|
||||
if (v->current_order.type == OT_LOADING) v->LeaveStation();
|
||||
v->current_order.type = OT_GOTO_DEPOT;
|
||||
v->current_order.flags = OF_NON_STOP;
|
||||
v->current_order.dest = depot->index;
|
||||
|
|
|
@ -3348,18 +3348,8 @@ void Train::Tick()
|
|||
|
||||
static void CheckIfTrainNeedsService(Vehicle *v)
|
||||
{
|
||||
if (_patches.servint_trains == 0) return;
|
||||
if (!VehicleNeedsService(v)) return;
|
||||
if (v->vehstatus & VS_STOPPED) return;
|
||||
if (_patches.gotodepot && VehicleHasDepotOrders(v)) return;
|
||||
|
||||
/* Don't interfere with a depot visit scheduled by the user, or a
|
||||
* depot visit by the order list. */
|
||||
if (v->current_order.type == OT_GOTO_DEPOT &&
|
||||
(v->current_order.flags & (OF_HALT_IN_DEPOT | OF_PART_OF_ORDERS)) != 0)
|
||||
return;
|
||||
|
||||
if (CheckTrainIsInsideDepot(v)) {
|
||||
if (_patches.servint_trains == 0 || !VehicleNeedsService(v)) return;
|
||||
if (v->IsInDepot()) {
|
||||
VehicleServiceInDepot(v);
|
||||
return;
|
||||
}
|
||||
|
@ -3386,8 +3376,6 @@ static void CheckIfTrainNeedsService(Vehicle *v)
|
|||
return;
|
||||
}
|
||||
|
||||
if (v->current_order.type == OT_LOADING) v->LeaveStation();
|
||||
|
||||
v->current_order.type = OT_GOTO_DEPOT;
|
||||
v->current_order.flags = OF_NON_STOP;
|
||||
v->current_order.dest = depot->index;
|
||||
|
|
|
@ -91,8 +91,10 @@ void VehicleServiceInDepot(Vehicle *v)
|
|||
|
||||
bool VehicleNeedsService(const Vehicle *v)
|
||||
{
|
||||
if (v->vehstatus & VS_CRASHED)
|
||||
return false; // Crashed vehicles don't need service anymore
|
||||
if (v->vehstatus & (VS_STOPPED | VS_CRASHED)) return false;
|
||||
if (_patches.gotodepot && VehicleHasDepotOrders(v)) return false;
|
||||
if (v->current_order.type == OT_LOADING) return false;
|
||||
if (v->current_order.type == OT_GOTO_DEPOT && v->current_order.flags & OF_HALT_IN_DEPOT) return false;
|
||||
|
||||
if (_patches.no_servicing_if_no_breakdowns && _opt.diff.vehicle_breakdowns == 0) {
|
||||
return EngineHasReplacementForPlayer(GetPlayer(v->owner), v->engine_type, v->group_id); /* Vehicles set for autoreplacing needs to go to a depot even if breakdowns are turned off */
|
||||
|
|
Loading…
Reference in New Issue