summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--aircraft_cmd.c2
-rw-r--r--depot.c5
-rw-r--r--order.h10
-rw-r--r--order_cmd.c17
-rw-r--r--order_gui.c2
-rw-r--r--roadveh_cmd.c2
-rw-r--r--ship_cmd.c2
-rw-r--r--station_cmd.c7
-rw-r--r--train_cmd.c2
-rw-r--r--waypoint.c6
10 files changed, 26 insertions, 29 deletions
diff --git a/aircraft_cmd.c b/aircraft_cmd.c
index c7ba62f20..1f9da7aa6 100644
--- a/aircraft_cmd.c
+++ b/aircraft_cmd.c
@@ -1179,6 +1179,8 @@ static void ProcessAircraftOrder(Vehicle *v)
break;
case OT_LOADING: return;
+
+ default: break;
}
if (v->cur_order_index >= v->num_orders) v->cur_order_index = 0;
diff --git a/depot.c b/depot.c
index a9e788ed4..e092940b8 100644
--- a/depot.c
+++ b/depot.c
@@ -79,7 +79,6 @@ Depot *AllocateDepot(void)
*/
void DoDeleteDepot(TileIndex tile)
{
- Order order;
Depot *depot;
/* Get the depot */
@@ -92,9 +91,7 @@ void DoDeleteDepot(TileIndex tile)
depot->xy = 0;
/* Clear the depot from all order-lists */
- order.type = OT_GOTO_DEPOT;
- order.station = depot->index;
- DeleteDestinationFromVehicleOrder(order);
+ RemoveOrderFromAllVehicles(OT_GOTO_DEPOT, depot->index);
/* Delete the depot-window */
DeleteWindowById(WC_VEHICLE_DEPOT, tile);
diff --git a/order.h b/order.h
index 5d0bdb204..ea210063c 100644
--- a/order.h
+++ b/order.h
@@ -10,7 +10,7 @@
#include "pool.h"
/* Order types */
-enum {
+typedef enum OrderTypes {
OT_NOTHING = 0,
OT_GOTO_STATION = 1,
OT_GOTO_DEPOT = 2,
@@ -18,7 +18,7 @@ enum {
OT_LEAVESTATION = 4,
OT_DUMMY = 5,
OT_GOTO_WAYPOINT = 6
-};
+} OrderType;
/* Order flags -- please use OFB instead OF and use HASBIT/SETBIT/CLEARBIT */
@@ -77,7 +77,7 @@ enum {
* - REF_SHEDULE (all REFs are currently limited to 16 bits!!)
*/
typedef struct Order {
- uint8 type;
+ OrderType type;
uint8 flags;
StationID station;
@@ -162,7 +162,7 @@ static inline uint32 PackOrder(const Order *order)
static inline Order UnpackOrder(uint32 packed)
{
Order order;
- order.type = GB(packed, 0, 8);
+ order.type = (OrderType)GB(packed, 0, 8);
order.flags = GB(packed, 8, 8);
order.station = GB(packed, 16, 16);
order.next = NULL;
@@ -173,7 +173,7 @@ static inline Order UnpackOrder(uint32 packed)
/* Functions */
void BackupVehicleOrders(const Vehicle *v, BackuppedOrders *order);
void RestoreVehicleOrders(const Vehicle* v, const BackuppedOrders* order);
-void DeleteDestinationFromVehicleOrder(Order dest);
+void RemoveOrderFromAllVehicles(OrderType type, StationID destination);
void InvalidateVehicleOrder(const Vehicle *v);
bool VehicleHasDepotOrders(const Vehicle *v);
void CheckOrders(const Vehicle*);
diff --git a/order_cmd.c b/order_cmd.c
index 53c96c769..0f84d40f6 100644
--- a/order_cmd.c
+++ b/order_cmd.c
@@ -953,13 +953,11 @@ void CheckOrders(const Vehicle* v)
}
/**
- *
- * Delete a destination (like station, waypoint, ..) from the orders of vehicles
- *
- * @param dest type and station has to be set. This order will be removed from all orders of vehicles
- *
+ * Removes an order from all vehicles. Triggers when, say, a station is removed.
+ * @param type The type of the order (OT_GOTO_[STATION|DEPOT|WAYPOINT]).
+ * @param destination The destination. Can be a StationID, DepotID or WaypointID.
*/
-void DeleteDestinationFromVehicleOrder(Order dest)
+void RemoveOrderFromAllVehicles(OrderType type, StationID destination)
{
Vehicle *v;
Order *order;
@@ -970,12 +968,11 @@ void DeleteDestinationFromVehicleOrder(Order dest)
if (v->orders == NULL) continue;
/* Forget about this station if this station is removed */
- if (v->last_station_visited == dest.station && dest.type == OT_GOTO_STATION)
+ if (v->last_station_visited == destination && type == OT_GOTO_STATION)
v->last_station_visited = INVALID_STATION;
/* Check the current order */
- if (v->current_order.type == dest.type &&
- v->current_order.station == dest.station) {
+ if (v->current_order.type == type && v->current_order.station == destination) {
/* Mark the order as DUMMY */
v->current_order.type = OT_DUMMY;
v->current_order.flags = 0;
@@ -985,7 +982,7 @@ void DeleteDestinationFromVehicleOrder(Order dest)
/* Clear the order from the order-list */
need_invalidate = false;
FOR_VEHICLE_ORDERS(v, order) {
- if (order->type == dest.type && order->station == dest.station) {
+ if (order->type == type && order->station == destination) {
/* Mark the order as DUMMY */
order->type = OT_DUMMY;
order->flags = 0;
diff --git a/order_gui.c b/order_gui.c
index 2ef68ee8f..1cbdb56f9 100644
--- a/order_gui.c
+++ b/order_gui.c
@@ -164,6 +164,8 @@ static void DrawOrdersWindow(Window *w)
SetDParam(1, (order->flags & OF_NON_STOP) ? STR_GO_NON_STOP_TO_WAYPOINT : STR_GO_TO_WAYPOINT);
SetDParam(2, order->station);
break;
+
+ default: break;
}
color = (i == WP(w,order_d).sel) ? 0xC : 0x10;
diff --git a/roadveh_cmd.c b/roadveh_cmd.c
index 88396661c..1f3f81083 100644
--- a/roadveh_cmd.c
+++ b/roadveh_cmd.c
@@ -631,6 +631,8 @@ static void ProcessRoadVehOrder(Vehicle *v)
case OT_LOADING:
case OT_LEAVESTATION:
return;
+
+ default: break;
}
if (v->cur_order_index >= v->num_orders) v->cur_order_index = 0;
diff --git a/ship_cmd.c b/ship_cmd.c
index 913112816..d5b5a1dfc 100644
--- a/ship_cmd.c
+++ b/ship_cmd.c
@@ -212,6 +212,8 @@ static void ProcessShipOrder(Vehicle *v)
case OT_LOADING:
case OT_LEAVESTATION:
return;
+
+ default: break;
}
if (v->cur_order_index >= v->num_orders) v->cur_order_index = 0;
diff --git a/station_cmd.c b/station_cmd.c
index afd5e3581..974d7be1d 100644
--- a/station_cmd.c
+++ b/station_cmd.c
@@ -2399,7 +2399,6 @@ static uint32 VehicleEnter_Station(Vehicle *v, TileIndex tile, int x, int y)
*/
static void DeleteStation(Station *st)
{
- Order order;
StationID index;
Vehicle *v;
st->xy = 0;
@@ -2412,10 +2411,8 @@ static void DeleteStation(Station *st)
index = st->index;
DeleteWindowById(WC_STATION_VIEW, index);
- //Now delete all orders that go to the station
- order.type = OT_GOTO_STATION;
- order.station = index;
- DeleteDestinationFromVehicleOrder(order);
+ /* Now delete all orders that go to the station */
+ RemoveOrderFromAllVehicles(OT_GOTO_STATION, index);
//And do the same with aircraft that have the station as a hangar-stop
FOR_ALL_VEHICLES(v) {
diff --git a/train_cmd.c b/train_cmd.c
index 2b06dd92b..fad5245af 100644
--- a/train_cmd.c
+++ b/train_cmd.c
@@ -2397,6 +2397,8 @@ static bool ProcessTrainOrder(Vehicle *v)
case OT_LOADING:
case OT_LEAVESTATION:
return false;
+
+ default: break;
}
// check if we've reached the waypoint?
diff --git a/waypoint.c b/waypoint.c
index 378c959cc..ca9c9987f 100644
--- a/waypoint.c
+++ b/waypoint.c
@@ -247,13 +247,9 @@ int32 CmdBuildTrainWaypoint(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
/* Internal handler to delete a waypoint */
static void DoDeleteWaypoint(Waypoint *wp)
{
- Order order;
-
wp->xy = 0;
- order.type = OT_GOTO_WAYPOINT;
- order.station = wp->index;
- DeleteDestinationFromVehicleOrder(order);
+ RemoveOrderFromAllVehicles(OT_GOTO_WAYPOINT, wp->index);
if (wp->string != STR_NULL) DeleteName(wp->string);