Mercurial > hg > openttd
changeset 7502:2250b8ea9466 draft
(svn r11017) -Codechange: unify determining whether a vehicle needs/can be service a little more.
author | rubidium <rubidium@openttd.org> |
---|---|
date | Fri, 31 Aug 2007 17:13:39 +0000 |
parents | a99f8ea26c2a |
children | 876e29bc9d5d |
files | src/aircraft_cmd.cpp src/roadveh_cmd.cpp src/ship_cmd.cpp src/train_cmd.cpp src/vehicle.cpp |
diffstat | 5 files changed, 12 insertions(+), 58 deletions(-) [+] |
line wrap: on
line diff
--- a/src/aircraft_cmd.cpp +++ b/src/aircraft_cmd.cpp @@ -696,17 +696,8 @@ 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 @@ 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);
--- a/src/roadveh_cmd.cpp +++ b/src/roadveh_cmd.cpp @@ -1841,29 +1841,15 @@ 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) {
--- a/src/ship_cmd.cpp +++ b/src/ship_cmd.cpp @@ -140,24 +140,13 @@ 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 @@ 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;
--- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -3348,18 +3348,8 @@ 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 @@ 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;
--- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -91,8 +91,10 @@ 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 */