summaryrefslogtreecommitdiff
path: root/src/order_cmd.cpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2008-04-11 15:58:46 +0000
committerrubidium <rubidium@openttd.org>2008-04-11 15:58:46 +0000
commit6fa700153126e843fc85a28dc8e43fb9b6845900 (patch)
tree75b2ce202d816827b4568b0bd0659c211f84cd08 /src/order_cmd.cpp
parent48703f69f460633a359f17f3796b42b5583d18c4 (diff)
downloadopenttd-6fa700153126e843fc85a28dc8e43fb9b6845900.tar.xz
(svn r12661) -Add: ability to send a vehicle (using default orders) to the nearest depot.
Diffstat (limited to 'src/order_cmd.cpp')
-rw-r--r--src/order_cmd.cpp80
1 files changed, 54 insertions, 26 deletions
diff --git a/src/order_cmd.cpp b/src/order_cmd.cpp
index a1c5f76f7..7682ba660 100644
--- a/src/order_cmd.cpp
+++ b/src/order_cmd.cpp
@@ -366,44 +366,48 @@ CommandCost CmdInsertOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
}
case OT_GOTO_DEPOT: {
- if (v->type == VEH_AIRCRAFT) {
- if (!IsValidStationID(new_order.GetDestination())) return CMD_ERROR;
+ if (new_order.GetDepotActionType() != ODATFB_NEAREST_DEPOT) {
+ if (v->type == VEH_AIRCRAFT) {
+ if (!IsValidStationID(new_order.GetDestination())) return CMD_ERROR;
- const Station *st = GetStation(new_order.GetDestination());
+ const Station *st = GetStation(new_order.GetDestination());
- if (!CheckOwnership(st->owner) ||
- !(st->facilities & FACIL_AIRPORT) ||
- st->Airport()->nof_depots == 0 ||
- !CanAircraftUseStation(v->engine_type, st)) {
- return CMD_ERROR;
- }
- } else {
- if (!IsValidDepotID(new_order.GetDestination())) return CMD_ERROR;
+ if (!CheckOwnership(st->owner) ||
+ !(st->facilities & FACIL_AIRPORT) ||
+ st->Airport()->nof_depots == 0 ||
+ !CanAircraftUseStation(v->engine_type, st)) {
+ return CMD_ERROR;
+ }
+ } else {
+ if (!IsValidDepotID(new_order.GetDestination())) return CMD_ERROR;
- const Depot *dp = GetDepot(new_order.GetDestination());
+ const Depot *dp = GetDepot(new_order.GetDestination());
- if (!CheckOwnership(GetTileOwner(dp->xy))) return CMD_ERROR;
+ if (!CheckOwnership(GetTileOwner(dp->xy))) return CMD_ERROR;
- switch (v->type) {
- case VEH_TRAIN:
- if (!IsTileDepotType(dp->xy, TRANSPORT_RAIL)) return CMD_ERROR;
- break;
+ switch (v->type) {
+ case VEH_TRAIN:
+ if (!IsTileDepotType(dp->xy, TRANSPORT_RAIL)) return CMD_ERROR;
+ break;
- case VEH_ROAD:
- if (!IsTileDepotType(dp->xy, TRANSPORT_ROAD)) return CMD_ERROR;
- break;
+ case VEH_ROAD:
+ if (!IsTileDepotType(dp->xy, TRANSPORT_ROAD)) return CMD_ERROR;
+ break;
- case VEH_SHIP:
- if (!IsTileDepotType(dp->xy, TRANSPORT_WATER)) return CMD_ERROR;
- break;
+ case VEH_SHIP:
+ if (!IsTileDepotType(dp->xy, TRANSPORT_WATER)) return CMD_ERROR;
+ break;
- default: return CMD_ERROR;
+ default: return CMD_ERROR;
+ }
}
+ } else {
+ if (!IsPlayerBuildableVehicleType(v)) return CMD_ERROR;
}
if (new_order.GetNonStopType() != ONSF_STOP_EVERYWHERE && v->type != VEH_TRAIN) return CMD_ERROR;
if (new_order.GetDepotOrderType() & ~ODTFB_PART_OF_ORDERS) return CMD_ERROR;
- if (new_order.GetDepotActionType() & ~ODATFB_HALT) return CMD_ERROR;
+ if (new_order.GetDepotActionType() & ~ODATFB_NEAREST_DEPOT) return CMD_ERROR;
break;
}
@@ -1516,7 +1520,31 @@ bool ProcessOrders(Vehicle *v)
break;
case OT_GOTO_DEPOT:
- if (v->type != VEH_AIRCRAFT) v->dest_tile = GetDepot(order->GetDestination())->xy;
+ if (v->current_order.GetDepotActionType() & ODATFB_NEAREST_DEPOT) {
+ /* We need to search for the nearest depot (hangar). */
+ TileIndex location;
+ DestinationID destination;
+ bool reverse;
+
+ if (v->FindClosestDepot(&location, &destination, &reverse)) {
+ v->dest_tile = location;
+ v->current_order.MakeGoToDepot(destination, ODTFB_PART_OF_ORDERS);
+
+ /* If there is no depot in front, reverse automatically (trains only) */
+ if (v->type == VEH_TRAIN && reverse) DoCommand(v->tile, v->index, 0, DC_EXEC, CMD_REVERSE_TRAIN_DIRECTION);
+
+ if (v->type == VEH_AIRCRAFT && v->u.air.state == FLYING && v->u.air.targetairport != destination) {
+ /* The aircraft is now heading for a different hangar than the next in the orders */
+ extern void AircraftNextAirportPos_and_Order(Vehicle *v);
+ AircraftNextAirportPos_and_Order(v);
+ }
+ } else {
+ UpdateVehicleTimetable(v, true);
+ v->cur_order_index++;
+ }
+ } else if (v->type != VEH_AIRCRAFT) {
+ v->dest_tile = GetDepot(order->GetDestination())->xy;
+ }
break;
case OT_GOTO_WAYPOINT: