summaryrefslogtreecommitdiff
path: root/src/order_cmd.cpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-01-10 09:51:14 +0000
committerrubidium <rubidium@openttd.org>2009-01-10 09:51:14 +0000
commit3d6c09b38d54da55ba7688fab8acb5879a34c861 (patch)
treec150281da19ec8c75bcae7d7526de3017ee154db /src/order_cmd.cpp
parentece7d9a16f66102aa2b384c45c13dc2a31cce7f8 (diff)
downloadopenttd-3d6c09b38d54da55ba7688fab8acb5879a34c861.tar.xz
(svn r14952) -Codechange: unify the "can vehicle go to station" tests
Diffstat (limited to 'src/order_cmd.cpp')
-rw-r--r--src/order_cmd.cpp47
1 files changed, 8 insertions, 39 deletions
diff --git a/src/order_cmd.cpp b/src/order_cmd.cpp
index c1ac606a0..a0b675f10 100644
--- a/src/order_cmd.cpp
+++ b/src/order_cmd.cpp
@@ -425,35 +425,8 @@ CommandCost CmdInsertOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, c
const Station *st = GetStation(new_order.GetDestination());
- if (st->owner != OWNER_NONE && !CheckOwnership(st->owner)) {
- return CMD_ERROR;
- }
-
- switch (v->type) {
- case VEH_TRAIN:
- if (!(st->facilities & FACIL_TRAIN)) return CMD_ERROR;
- break;
-
- case VEH_ROAD:
- if (IsCargoInClass(v->cargo_type, CC_PASSENGERS)) {
- if (!(st->facilities & FACIL_BUS_STOP)) return CMD_ERROR;
- } else {
- if (!(st->facilities & FACIL_TRUCK_STOP)) return CMD_ERROR;
- }
- break;
-
- case VEH_SHIP:
- if (!(st->facilities & FACIL_DOCK)) return CMD_ERROR;
- break;
-
- case VEH_AIRCRAFT:
- if (!(st->facilities & FACIL_AIRPORT) || !CanAircraftUseStation(v->engine_type, st)) {
- return CMD_ERROR;
- }
- break;
-
- default: return CMD_ERROR;
- }
+ if (st->owner != OWNER_NONE && !CheckOwnership(st->owner)) return CMD_ERROR;
+ if (!CanVehicleUseStation(v, st)) return CMD_ERROR;
/* Non stop not allowed for non-trains. */
if (new_order.GetNonStopType() != ONSF_STOP_EVERYWHERE && v->type != VEH_TRAIN && v->type != VEH_ROAD) return CMD_ERROR;
@@ -481,9 +454,8 @@ CommandCost CmdInsertOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, c
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)) {
+ !CanVehicleUseStation(v, st) ||
+ st->Airport()->nof_depots == 0) {
return CMD_ERROR;
}
} else {
@@ -1376,17 +1348,14 @@ CommandCost CmdRestoreOrderIndex(TileIndex tile, uint32 flags, uint32 p1, uint32
static TileIndex GetStationTileForVehicle(const Vehicle *v, const Station *st)
{
+ if (!CanVehicleUseStation(v, st)) return INVALID_TILE;
+
switch (v->type) {
default: NOT_REACHED();
case VEH_TRAIN: return st->train_tile;
- case VEH_AIRCRAFT: return CanAircraftUseStation(v->engine_type, st) ? st->airport_tile : INVALID_TILE;
+ case VEH_AIRCRAFT: return st->airport_tile;
case VEH_SHIP: return st->dock_tile;
- case VEH_ROAD:
- if (IsCargoInClass(v->cargo_type, CC_PASSENGERS)) {
- return (st->bus_stops != NULL) ? st->bus_stops->xy : INVALID_TILE;
- } else {
- return (st->truck_stops != NULL) ? st->truck_stops->xy : INVALID_TILE;
- }
+ case VEH_ROAD: return IsCargoInClass(v->cargo_type, CC_PASSENGERS) ? st->bus_stops->xy : st->truck_stops->xy;
}
}