summaryrefslogtreecommitdiff
path: root/roadveh_cmd.c
diff options
context:
space:
mode:
authortron <tron@openttd.org>2004-12-05 12:43:04 +0000
committertron <tron@openttd.org>2004-12-05 12:43:04 +0000
commitb8e83ca03fb8d652b8160419d9f1d07384f6f3e5 (patch)
treef4ed902f473744cc8497d09b3f372d3da1524f4f /roadveh_cmd.c
parenta39770f23adf7d6e3c312deaf662900486123a5d (diff)
downloadopenttd-b8e83ca03fb8d652b8160419d9f1d07384f6f3e5.tar.xz
(svn r955) Replace uint16 for orders with struct Order
This adds no functionality, but is a stepping stone for future improvement (like 16bit order indices) and is easier to read. This changes preserves binary compatibility wrt savegames.
Diffstat (limited to 'roadveh_cmd.c')
-rw-r--r--roadveh_cmd.c128
1 files changed, 73 insertions, 55 deletions
diff --git a/roadveh_cmd.c b/roadveh_cmd.c
index 7c5d8688a..6b39a5a11 100644
--- a/roadveh_cmd.c
+++ b/roadveh_cmd.c
@@ -169,7 +169,9 @@ int32 CmdBuildRoadVeh(int x, int y, uint32 flags, uint32 p1, uint32 p2)
_new_roadveh_id = v->index;
v->string_id = STR_SV_ROADVEH_NAME;
- *(v->schedule_ptr = _ptr_to_next_order++) = 0;
+ _ptr_to_next_order->type = OT_NOTHING;
+ _ptr_to_next_order->flags = 0;
+ v->schedule_ptr = _ptr_to_next_order++;
v->service_interval = _patches.servint_roadveh;
@@ -300,11 +302,12 @@ int32 CmdSendRoadVehToDepot(int x, int y, uint32 flags, uint32 p1, uint32 p2)
if (v->type != VEH_Road || !CheckOwnership(v->owner))
return CMD_ERROR;
- if ((v->next_order & OT_MASK) == OT_GOTO_DEPOT) {
+ if (v->current_order.type == OT_GOTO_DEPOT) {
if (flags & DC_EXEC) {
- if (v->next_order & OF_UNLOAD)
+ if (v->current_order.flags & OF_UNLOAD)
v->cur_order_index++;
- v->next_order = OT_DUMMY;
+ v->current_order.type = OT_DUMMY;
+ v->current_order.flags = 0;
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, 4);
}
return 0;
@@ -315,8 +318,9 @@ int32 CmdSendRoadVehToDepot(int x, int y, uint32 flags, uint32 p1, uint32 p2)
return_cmd_error(STR_9019_UNABLE_TO_FIND_LOCAL_DEPOT);
if (flags & DC_EXEC) {
- v->next_order = OF_NON_STOP | OF_FULL_LOAD | OT_GOTO_DEPOT;
- v->next_order_param = (byte)depot;
+ v->current_order.type = OT_GOTO_DEPOT;
+ v->current_order.flags = OF_NON_STOP | OF_FULL_LOAD;
+ v->current_order.station = (byte)depot;
v->dest_tile = _depots[depot].xy;
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, 4);
}
@@ -556,16 +560,18 @@ static void HandleBrokenRoadVeh(Vehicle *v)
static void ProcessRoadVehOrder(Vehicle *v)
{
- uint order;
+ Order order;
Station *st;
- if ((v->next_order & OT_MASK) >= OT_GOTO_DEPOT && (v->next_order & OT_MASK) <= OT_LEAVESTATION) {
+ if (v->current_order.type >= OT_GOTO_DEPOT && v->current_order.type <= OT_LEAVESTATION) {
// Let a depot order in the schedule interrupt.
- if ((v->next_order & (OT_MASK|OF_UNLOAD)) != (OT_GOTO_DEPOT|OF_UNLOAD))
+ if (v->current_order.type != OT_GOTO_DEPOT ||
+ !(v->current_order.flags & OF_UNLOAD))
return;
}
- if ((v->next_order & (OT_MASK|OF_UNLOAD|OF_FULL_LOAD)) == (OT_GOTO_DEPOT|OF_UNLOAD|OF_FULL_LOAD) &&
+ if (v->current_order.type == OT_GOTO_DEPOT &&
+ (v->current_order.flags & (OF_UNLOAD | OF_FULL_LOAD)) == (OF_UNLOAD | OF_FULL_LOAD) &&
SERVICE_INTERVAL ) {
v->cur_order_index++;
}
@@ -575,27 +581,29 @@ static void ProcessRoadVehOrder(Vehicle *v)
order = v->schedule_ptr[v->cur_order_index];
- if (order == 0) {
- v->next_order = OT_NOTHING;
+ if (order.type == OT_NOTHING) {
+ v->current_order.type = OT_NOTHING;
+ v->current_order.flags = 0;
v->dest_tile = 0;
return;
}
- if (order == (uint)((v->next_order | (v->next_order_param<<8))))
+ if (order.type == v->current_order.type &&
+ order.flags == v->current_order.flags &&
+ order.station == v->current_order.station)
return;
- v->next_order = (byte)order;
- v->next_order_param = (byte)(order >> 8);
+ v->current_order = order;
v->dest_tile = 0;
- if ((order & OT_MASK) == OT_GOTO_STATION) {
- if ( (byte)(order >> 8) == v->last_station_visited)
+ if (order.type == OT_GOTO_STATION) {
+ if (order.station == v->last_station_visited)
v->last_station_visited = 0xFF;
- st = DEREF_STATION(order >> 8);
+ st = DEREF_STATION(order.station);
v->dest_tile = v->cargo_type==CT_PASSENGERS ? st->bus_tile : st->lorry_tile;
- } else if ((order & OT_MASK) == OT_GOTO_DEPOT) {
- v->dest_tile = _depots[order >> 8].xy;
+ } else if (order.type == OT_GOTO_DEPOT) {
+ v->dest_tile = _depots[order.station].xy;
}
InvalidateVehicleOrderWidget(v);
@@ -603,17 +611,17 @@ static void ProcessRoadVehOrder(Vehicle *v)
static void HandleRoadVehLoading(Vehicle *v)
{
- if (v->next_order == OT_NOTHING)
+ if (v->current_order.type == OT_NOTHING)
return;
- if (v->next_order != OT_DUMMY) {
- if ((v->next_order&OT_MASK) != OT_LOADING)
+ if (v->current_order.type != OT_DUMMY) {
+ if (v->current_order.type != OT_LOADING)
return;
if (--v->load_unload_time_rem)
return;
- if (v->next_order&OF_FULL_LOAD && CanFillVehicle(v)) {
+ if (v->current_order.flags & OF_FULL_LOAD && CanFillVehicle(v)) {
SET_EXPENSES_TYPE(EXPENSES_ROADVEH_INC);
if (LoadUnloadVehicle(v)) {
InvalidateWindow(WC_ROADVEH_LIST, v->owner);
@@ -623,9 +631,10 @@ static void HandleRoadVehLoading(Vehicle *v)
}
{
- byte b = v->next_order;
- v->next_order = OT_LEAVESTATION;
- if (!(b & OF_NON_STOP))
+ Order b = v->current_order;
+ v->current_order.type = OT_LEAVESTATION;
+ v->current_order.flags = 0;
+ if (!(b.flags & OF_NON_STOP))
return;
}
}
@@ -1052,7 +1061,7 @@ static const byte _roadveh_data_2[4] = { 0,1,8,9 };
static void RoadVehEventHandler(Vehicle *v)
{
GetNewVehiclePosResult gp;
- byte new_dir,old_dir,old_order;
+ byte new_dir, old_dir;
RoadDriveEntry rd;
int x,y;
Station *st;
@@ -1088,7 +1097,7 @@ static void RoadVehEventHandler(Vehicle *v)
ProcessRoadVehOrder(v);
HandleRoadVehLoading(v);
- if ((v->next_order & OT_MASK) == OT_LOADING)
+ if (v->current_order.type == OT_LOADING)
return;
if (v->u.road.state == 254) {
@@ -1305,8 +1314,9 @@ again:
st = DEREF_STATION(_map2[v->tile]);
b = IS_BYTE_INSIDE(_map5[v->tile], 0x43, 0x47) ? &st->truck_stop_status : &st->bus_stop_status;
- if ( (v->next_order&OT_MASK) != OT_LEAVESTATION &&
- (v->next_order&OT_MASK) != OT_GOTO_DEPOT) {
+ if (v->current_order.type != OT_LEAVESTATION &&
+ v->current_order.type != OT_GOTO_DEPOT) {
+ Order old_order;
*b &= ~0x80;
@@ -1314,12 +1324,14 @@ again:
RoadVehArrivesAt(v, st);
- old_order = v->next_order;
- v->next_order = OT_LOADING;
+ old_order = v->current_order;
+ v->current_order.type = OT_LOADING;
+ v->current_order.flags = 0;
- if ((old_order & OT_MASK) == OT_GOTO_STATION &&
- v->next_order_param == v->last_station_visited) {
- v->next_order = OT_LOADING | OF_NON_STOP | (old_order & (OF_FULL_LOAD|OF_UNLOAD));
+ if (old_order.type == OT_GOTO_STATION &&
+ v->current_order.station == v->last_station_visited) {
+ v->current_order.flags =
+ (old_order.flags & (OF_FULL_LOAD | OF_UNLOAD)) | OF_NON_STOP;
}
SET_EXPENSES_TYPE(EXPENSES_ROADVEH_INC);
@@ -1331,12 +1343,13 @@ again:
return;
}
- if ((v->next_order & OT_MASK) != OT_GOTO_DEPOT) {
+ if (v->current_order.type != OT_GOTO_DEPOT) {
if (*b&0x80) {
v->cur_speed = 0;
return;
}
- v->next_order = 0;
+ v->current_order.type = OT_NOTHING;
+ v->current_order.flags = 0;
}
*b |= 0x80;
@@ -1361,8 +1374,6 @@ again:
void RoadVehEnterDepot(Vehicle *v)
{
- byte t;
-
v->u.road.state = 254;
v->vehstatus |= VS_HIDDEN;
@@ -1375,16 +1386,19 @@ void RoadVehEnterDepot(Vehicle *v)
TriggerVehicle(v, VEHICLE_TRIGGER_DEPOT);
- if ((v->next_order&OT_MASK) == OT_GOTO_DEPOT) {
+ if (v->current_order.type == OT_GOTO_DEPOT) {
+ Order t;
+
InvalidateWindow(WC_VEHICLE_VIEW, v->index);
- t = v->next_order;
- v->next_order = OT_DUMMY;
+ t = v->current_order;
+ v->current_order.type = OT_DUMMY;
+ v->current_order.flags = 0;
// Part of the schedule?
- if (t & OF_UNLOAD) { v->cur_order_index++; }
-
- else if (t & OF_FULL_LOAD) {
+ if (t.flags & OF_UNLOAD) {
+ v->cur_order_index++;
+ } else if (t.flags & OF_FULL_LOAD) {
v->vehstatus |= VS_STOPPED;
if (v->owner == _local_player) {
SetDParam(0, v->unitnumber);
@@ -1432,25 +1446,29 @@ static void CheckIfRoadVehNeedsService(Vehicle *v)
// Don't interfere with a depot visit scheduled by the user, or a
// depot visit by the order list.
- if ((v->next_order & OT_MASK) == OT_GOTO_DEPOT &&
- (v->next_order & (OF_FULL_LOAD|OF_UNLOAD)) != 0)
+ if (v->current_order.type == OT_GOTO_DEPOT &&
+ (v->current_order.flags & (OF_FULL_LOAD | OF_UNLOAD)) != 0)
return;
i = FindClosestRoadDepot(v);
if (i < 0 || GetTileDist(v->tile, (&_depots[i])->xy) > 12) {
- if ((v->next_order & OT_MASK) == OT_GOTO_DEPOT) {
- v->next_order = OT_DUMMY;
+ if (v->current_order.type == OT_GOTO_DEPOT) {
+ v->current_order.type = OT_DUMMY;
+ v->current_order.flags = 0;
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, 4);
}
return;
}
- if (v->next_order == (OT_GOTO_DEPOT | OF_NON_STOP) && !CHANCE16(1,20))
+ if (v->current_order.type == OT_GOTO_DEPOT &&
+ v->current_order.flags & OF_NON_STOP &&
+ !CHANCE16(1,20))
return;
- v->next_order = OT_GOTO_DEPOT | OF_NON_STOP;
- v->next_order_param = (byte)i;
+ v->current_order.type = OT_GOTO_DEPOT;
+ v->current_order.flags = OF_NON_STOP;
+ v->current_order.station = (byte)i;
v->dest_tile = (&_depots[i])->xy;
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, 4);
}
@@ -1473,8 +1491,8 @@ void OnNewDay_RoadVeh(Vehicle *v)
CheckOrders(v);
/* update destination */
- if ((v->next_order & OT_MASK) == OT_GOTO_STATION) {
- st = DEREF_STATION(v->next_order_param);
+ if (v->current_order.type == OT_GOTO_STATION) {
+ st = DEREF_STATION(v->current_order.station);
if ((tile=(v->cargo_type==CT_PASSENGERS ? st->bus_tile : st->lorry_tile)) != 0)
v->dest_tile = tile;
}