(svn r6052) -Codechange: change OrderType (order->type) in a typedef

-Codechange: renamed DeleteDestinationFromVehicleOrder to RemoveOrderFromAllVehicles to reflect his function better
-Codechange: changed the params of RemoveOrderFromAllVehicles, to avoid unneeded variable-creation
pull/155/head
truelight 18 years ago
parent 8d436dee69
commit bdc1d681a7

@ -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;

@ -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);

@ -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*);

@ -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;

@ -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;

@ -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;

@ -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;

@ -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) {

@ -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?

@ -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);

Loading…
Cancel
Save