summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorterkhen <terkhen@openttd.org>2010-12-14 21:26:03 +0000
committerterkhen <terkhen@openttd.org>2010-12-14 21:26:03 +0000
commit79e2b3153d4d89a653a72e07727e58300b435ac4 (patch)
tree62d1f676a9a63df00b92b64d8e866a98b080dc3b /src
parent96b98b392ad89e3d1718a7a46a3e41d4eeab61d3 (diff)
downloadopenttd-79e2b3153d4d89a653a72e07727e58300b435ac4.tar.xz
(svn r21516) -Codechange: Add IsGroundVehicle function to the Vehicle class.
Diffstat (limited to 'src')
-rw-r--r--src/depot_gui.cpp2
-rw-r--r--src/disaster_cmd.cpp2
-rw-r--r--src/newgrf_engine.cpp2
-rw-r--r--src/order_cmd.cpp8
-rw-r--r--src/order_gui.cpp10
-rw-r--r--src/pathfinder/npf/npf.cpp2
-rw-r--r--src/saveload/afterload.cpp2
-rw-r--r--src/vehicle_base.h9
-rw-r--r--src/vehicle_gui.cpp8
9 files changed, 27 insertions, 18 deletions
diff --git a/src/depot_gui.cpp b/src/depot_gui.cpp
index 095c41af9..8caeea967 100644
--- a/src/depot_gui.cpp
+++ b/src/depot_gui.cpp
@@ -305,7 +305,7 @@ struct DepotWindow : Window {
}
uint diff_x, diff_y;
- if (v->type == VEH_TRAIN || v->type == VEH_ROAD) {
+ if (v->IsGroundVehicle()) {
/* Arrange unitnumber and flag horizontally */
diff_x = this->flag_width + WD_FRAMERECT_LEFT;
diff_y = (this->resize.step_height - this->flag_height) / 2 - 2;
diff --git a/src/disaster_cmd.cpp b/src/disaster_cmd.cpp
index faac56b00..e86448c5f 100644
--- a/src/disaster_cmd.cpp
+++ b/src/disaster_cmd.cpp
@@ -506,7 +506,7 @@ static bool DisasterTick_Big_Ufo(DisasterVehicle *v)
Vehicle *target;
FOR_ALL_VEHICLES(target) {
- if (target->type == VEH_TRAIN || target->type == VEH_ROAD) {
+ if (target->IsGroundVehicle()) {
if (Delta(target->x_pos, v->x_pos) + Delta(target->y_pos, v->y_pos) <= 12 * (int)TILE_SIZE) {
target->breakdown_ctr = 5;
target->breakdown_delay = 0xF0;
diff --git a/src/newgrf_engine.cpp b/src/newgrf_engine.cpp
index cd6023861..8e276623c 100644
--- a/src/newgrf_engine.cpp
+++ b/src/newgrf_engine.cpp
@@ -611,7 +611,7 @@ static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, by
* B - current wagon to next wagon, 0 if wagon is last
* T - previous wagon to next wagon, 0 in an S-bend
*/
- if (v->type != VEH_TRAIN && v->type != VEH_ROAD) return 0;
+ if (!v->IsGroundVehicle()) return 0;
const Vehicle *u_p = v->Previous();
const Vehicle *u_n = v->Next();
diff --git a/src/order_cmd.cpp b/src/order_cmd.cpp
index 13bdf2d8c..ba8d51f87 100644
--- a/src/order_cmd.cpp
+++ b/src/order_cmd.cpp
@@ -485,8 +485,8 @@ CommandCost CmdInsertOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
if (!CanVehicleUseStation(u, st)) return_cmd_error(STR_ERROR_CAN_T_ADD_ORDER_SHARED);
}
- /* 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;
+ /* Non stop only allowed for ground vehicles. */
+ if (new_order.GetNonStopType() != ONSF_STOP_EVERYWHERE && !v->IsGroundVehicle()) return CMD_ERROR;
/* No load and no unload are mutual exclusive. */
if ((new_order.GetLoadType() & OLFB_NO_LOAD) && (new_order.GetUnloadType() & OUFB_NO_UNLOAD)) return CMD_ERROR;
@@ -556,7 +556,7 @@ CommandCost CmdInsertOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
}
}
- if (new_order.GetNonStopType() != ONSF_STOP_EVERYWHERE && v->type != VEH_TRAIN && v->type != VEH_ROAD) return CMD_ERROR;
+ if (new_order.GetNonStopType() != ONSF_STOP_EVERYWHERE && !v->IsGroundVehicle()) return CMD_ERROR;
if (new_order.GetDepotOrderType() & ~(ODTFB_PART_OF_ORDERS | ((new_order.GetDepotOrderType() & ODTFB_PART_OF_ORDERS) != 0 ? ODTFB_SERVICE : 0))) return CMD_ERROR;
if (new_order.GetDepotActionType() & ~(ODATFB_HALT | ODATFB_NEAREST_DEPOT)) return CMD_ERROR;
if ((new_order.GetDepotOrderType() & ODTFB_SERVICE) && (new_order.GetDepotActionType() & ODATFB_HALT)) return CMD_ERROR;
@@ -973,7 +973,7 @@ CommandCost CmdModifyOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
default: NOT_REACHED();
case MOF_NON_STOP:
- if (v->type != VEH_TRAIN && v->type != VEH_ROAD) return CMD_ERROR;
+ if (!v->IsGroundVehicle()) return CMD_ERROR;
if (data >= ONSF_END) return CMD_ERROR;
if (data == order->GetNonStopType()) return CMD_ERROR;
break;
diff --git a/src/order_gui.cpp b/src/order_gui.cpp
index bdba6bf64..a3ed0ce06 100644
--- a/src/order_gui.cpp
+++ b/src/order_gui.cpp
@@ -216,7 +216,7 @@ void DrawOrderString(const Vehicle *v, const Order *order, int order_index, int
OrderUnloadFlags unload = order->GetUnloadType();
SetDParam(0, STR_ORDER_GO_TO_STATION);
- SetDParam(1, STR_ORDER_GO_TO + ((v->type == VEH_TRAIN || v->type == VEH_ROAD) ? order->GetNonStopType() : 0));
+ SetDParam(1, STR_ORDER_GO_TO + (v->IsGroundVehicle() ? order->GetNonStopType() : 0));
SetDParam(2, order->GetDestination());
if (timetable) {
@@ -382,7 +382,7 @@ static Order GetOrderCmdFromTile(const Vehicle *v, TileIndex tile)
if (st->facilities & facil) {
order.MakeGoToStation(st_index);
if (_ctrl_pressed) order.SetLoadType(OLF_FULL_LOAD_ANY);
- if (_settings_client.gui.new_nonstop && (v->type == VEH_TRAIN || v->type == VEH_ROAD)) order.SetNonStopType(ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS);
+ if (_settings_client.gui.new_nonstop && v->IsGroundVehicle()) order.SetNonStopType(ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS);
order.SetStopLocation(v->type == VEH_TRAIN ? (OrderStopLocation)(_settings_client.gui.stop_location) : OSL_PLATFORM_FAR_END);
return order;
}
@@ -572,7 +572,7 @@ private:
order.next = NULL;
order.index = 0;
order.MakeGoToDepot(0, ODTFB_PART_OF_ORDERS,
- _settings_client.gui.new_nonstop && (this->vehicle->type == VEH_TRAIN || this->vehicle->type == VEH_ROAD) ? ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS : ONSF_STOP_EVERYWHERE);
+ _settings_client.gui.new_nonstop && this->vehicle->IsGroundVehicle() ? ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS : ONSF_STOP_EVERYWHERE);
order.SetDepotActionType(ODATFB_NEAREST_DEPOT);
DoCommandP(this->vehicle->tile, this->vehicle->index + (this->OrderGetSel() << 20), order.Pack(), CMD_INSERT_ORDER | CMD_MSG(STR_ERROR_CAN_T_INSERT_NEW_ORDER));
@@ -647,7 +647,7 @@ private:
*/
void OrderClick_Nonstop(int non_stop)
{
- if (this->vehicle->type != VEH_TRAIN && this->vehicle->type != VEH_ROAD) return;
+ if (!this->vehicle->IsGroundVehicle()) return;
VehicleOrderID sel_ord = this->OrderGetSel();
const Order *order = this->vehicle->GetOrder(sel_ord);
@@ -1605,6 +1605,6 @@ void ShowOrdersWindow(const Vehicle *v)
if (v->owner != _local_company) {
new OrdersWindow(&_other_orders_desc, v);
} else {
- new OrdersWindow((v->type == VEH_TRAIN || v->type == VEH_ROAD) ? &_orders_train_desc : &_orders_desc, v);
+ new OrdersWindow(v->IsGroundVehicle() ? &_orders_train_desc : &_orders_desc, v);
}
}
diff --git a/src/pathfinder/npf/npf.cpp b/src/pathfinder/npf/npf.cpp
index 45c1c2d9c..e8e13f5fd 100644
--- a/src/pathfinder/npf/npf.cpp
+++ b/src/pathfinder/npf/npf.cpp
@@ -1101,7 +1101,7 @@ static void NPFFillWithOrderData(NPFFindStationOrTileData *fstd, const Vehicle *
* So only for train orders to stations we fill fstd->station_index, for all
* others only dest_coords */
if (v->type != VEH_SHIP && (v->current_order.IsType(OT_GOTO_STATION) || v->current_order.IsType(OT_GOTO_WAYPOINT))) {
- assert(v->type == VEH_TRAIN || v->type == VEH_ROAD);
+ assert(v->IsGroundVehicle());
fstd->station_index = v->current_order.GetDestination();
fstd->station_type = (v->type == VEH_TRAIN) ? (v->current_order.IsType(OT_GOTO_STATION) ? STATION_RAIL : STATION_WAYPOINT) : (RoadVehicle::From(v)->IsBus() ? STATION_BUS : STATION_TRUCK);
fstd->not_articulated = v->type == VEH_ROAD && !RoadVehicle::From(v)->HasArticulatedPart();
diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp
index 4bd466e1e..26531a78b 100644
--- a/src/saveload/afterload.cpp
+++ b/src/saveload/afterload.cpp
@@ -1025,7 +1025,7 @@ bool AfterLoadGame()
}
FOR_ALL_VEHICLES(v) {
- if (v->type != VEH_TRAIN && v->type != VEH_ROAD) continue;
+ if (!v->IsGroundVehicle()) continue;
if (IsBridgeTile(v->tile)) {
DiagDirection dir = GetTunnelBridgeDirection(v->tile);
diff --git a/src/vehicle_base.h b/src/vehicle_base.h
index 642b80424..d81713d74 100644
--- a/src/vehicle_base.h
+++ b/src/vehicle_base.h
@@ -360,6 +360,15 @@ public:
}
/**
+ * Check if the vehicle is a ground vehicle.
+ * @return True iff the vehicle is a train or a road vehicle.
+ */
+ FORCEINLINE bool IsGroundVehicle() const
+ {
+ return this->type == VEH_TRAIN || this->type == VEH_ROAD;
+ }
+
+ /**
* Gets the speed in km-ish/h that can be sent into SetDParam for string processing.
* @return the vehicle's speed
*/
diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp
index 259528f4a..fec5c1d39 100644
--- a/src/vehicle_gui.cpp
+++ b/src/vehicle_gui.cpp
@@ -435,7 +435,7 @@ struct RefitWindow : public Window {
}
current_index++;
}
- } while ((v->type == VEH_TRAIN || v->type == VEH_ROAD) && (v = v->Next()) != NULL);
+ } while (v->IsGroundVehicle() && (v = v->Next()) != NULL);
int scroll_size = 0;
for (uint i = 0; i < NUM_CARGO; i++) {
@@ -2033,7 +2033,7 @@ static bool IsVehicleRefitable(const Vehicle *v)
do {
if (IsEngineRefittable(v->engine_type)) return true;
- } while ((v->type == VEH_TRAIN || v->type == VEH_ROAD) && (v = v->Next()) != NULL);
+ } while (v->IsGroundVehicle() && (v = v->Next()) != NULL);
return false;
}
@@ -2311,7 +2311,7 @@ public:
CcCloneVehicle);
break;
case VVW_WIDGET_TURN_AROUND: // turn around
- assert(v->type == VEH_TRAIN || v->type == VEH_ROAD);
+ assert(v->IsGroundVehicle());
DoCommandP(v->tile, v->index, 0,
_vehicle_command_translation_table[VCT_CMD_TURN_AROUND][v->type]);
break;
@@ -2345,7 +2345,7 @@ public:
this->SetWidgetDirty(VVW_WIDGET_SELECT_DEPOT_CLONE);
}
/* The same system applies to widget VVW_WIDGET_REFIT_VEH and VVW_WIDGET_TURN_AROUND.*/
- if (v->type == VEH_ROAD || v->type == VEH_TRAIN) {
+ if (v->IsGroundVehicle()) {
PlaneSelections plane = veh_stopped ? SEL_RT_REFIT : SEL_RT_TURN_AROUND;
NWidgetStacked *nwi = this->GetWidget<NWidgetStacked>(VVW_WIDGET_SELECT_REFIT_TURN);
if (nwi->shown_plane + SEL_RT_BASEPLANE != plane) {