--- a/src/roadveh_cmd.cpp Sun Apr 06 14:12:19 2008 +0000
+++ b/src/roadveh_cmd.cpp Sun Apr 06 23:07:42 2008 +0000
@@ -10,7 +10,6 @@
#include "road_map.h"
#include "roadveh.h"
#include "station_map.h"
-#include "timetable.h"
#include "command_func.h"
#include "station_base.h"
#include "news_func.h"
@@ -438,7 +437,7 @@
/* search in all directions */
for (DiagDirection d = DIAGDIR_BEGIN; d < DIAGDIR_END; d++) {
- FollowTrack(v->tile, TRANSPORT_ROAD, v->u.road.compatible_roadtypes, d, EnumRoadSignalFindDepot, NULL, &rfdd);
+ FollowTrack(v->tile, PATHFIND_FLAGS_NONE, TRANSPORT_ROAD, v->u.road.compatible_roadtypes, d, EnumRoadSignalFindDepot, NULL, &rfdd);
}
if (rfdd.best_length != UINT_MAX) return GetDepotByTile(rfdd.tile);
@@ -478,14 +477,15 @@
if (v->IsInDepot()) return CMD_ERROR;
/* If the current orders are already goto-depot */
- if (v->current_order.type == OT_GOTO_DEPOT) {
- if (!!(p2 & DEPOT_SERVICE) == HasBit(v->current_order.flags, OF_HALT_IN_DEPOT)) {
+ if (v->current_order.IsType(OT_GOTO_DEPOT)) {
+ bool halt_in_depot = HasBit(v->current_order.GetDepotActionType(), OF_HALT_IN_DEPOT);
+ if (!!(p2 & DEPOT_SERVICE) == halt_in_depot) {
/* We called with a different DEPOT_SERVICE setting.
* Now we change the setting to apply the new one and let the vehicle head for the same depot.
* Note: the if is (true for requesting service == true for ordered to stop in depot) */
if (flags & DC_EXEC) {
- ClrBit(v->current_order.flags, OF_PART_OF_ORDERS);
- ToggleBit(v->current_order.flags, OF_HALT_IN_DEPOT);
+ v->current_order.SetDepotOrderType(OFB_MANUAL_ORDER);
+ v->current_order.SetDepotActionType(halt_in_depot ? OFB_NORMAL_ACTION : OFB_HALT_IN_DEPOT);
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH);
}
return CommandCost();
@@ -495,11 +495,9 @@
if (flags & DC_EXEC) {
/* If the orders to 'goto depot' are in the orders list (forced servicing),
* then skip to the next order; effectively cancelling this forced service */
- if (HasBit(v->current_order.flags, OF_PART_OF_ORDERS))
- v->cur_order_index++;
+ if (v->current_order.GetDepotOrderType() & OFB_PART_OF_ORDERS) v->cur_order_index++;
- v->current_order.type = OT_DUMMY;
- v->current_order.flags = 0;
+ v->current_order.MakeDummy();
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH);
}
return CommandCost();
@@ -509,14 +507,11 @@
if (dep == NULL) return_cmd_error(STR_9019_UNABLE_TO_FIND_LOCAL_DEPOT);
if (flags & DC_EXEC) {
- if (v->current_order.type == OT_LOADING) v->LeaveStation();
+ if (v->current_order.IsType(OT_LOADING)) v->LeaveStation();
ClearSlot(v);
- v->current_order.type = OT_GOTO_DEPOT;
- v->current_order.flags = OFB_NON_STOP;
- if (!(p2 & DEPOT_SERVICE)) SetBit(v->current_order.flags, OF_HALT_IN_DEPOT);
- v->current_order.refit_cargo = CT_INVALID;
- v->current_order.dest = dep->index;
+ v->current_order.MakeGoToDepot(dep->index, false);
+ if (!(p2 & DEPOT_SERVICE)) v->current_order.SetDepotActionType(OFB_HALT_IN_DEPOT);
v->dest_tile = dep->xy;
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH);
}
@@ -586,9 +581,9 @@
uint32 x = _delta_xy_table[direction];
this->x_offs = GB(x, 0, 8);
this->y_offs = GB(x, 8, 8);
- this->sprite_width = GB(x, 16, 8);
- this->sprite_height = GB(x, 24, 8);
- this->z_height = 6;
+ this->x_extent = GB(x, 16, 8);
+ this->y_extent = GB(x, 24, 8);
+ this->z_extent = 6;
}
static void ClearCrashedStation(Vehicle *v)
@@ -758,89 +753,32 @@
}
}
-static void ProcessRoadVehOrder(Vehicle *v)
+TileIndex RoadVehicle::GetOrderStationLocation(StationID station)
{
- const Order *order;
-
- switch (v->current_order.type) {
- case OT_GOTO_DEPOT:
- /* Let a depot order in the orderlist interrupt. */
- if (!(v->current_order.flags & OFB_PART_OF_ORDERS)) return;
- if (v->current_order.flags & OFB_SERVICE_IF_NEEDED &&
- !VehicleNeedsService(v)) {
- UpdateVehicleTimetable(v, true);
- v->cur_order_index++;
- }
- break;
+ if (station == this->last_station_visited) this->last_station_visited = INVALID_STATION;
- case OT_LOADING:
- case OT_LEAVESTATION:
- return;
-
- default: break;
- }
-
- if (v->cur_order_index >= v->num_orders) v->cur_order_index = 0;
-
- order = GetVehicleOrder(v, v->cur_order_index);
+ TileIndex dest = INVALID_TILE;
+ const RoadStop *rs = GetStation(station)->GetPrimaryRoadStop(this);
+ if (rs != NULL) {
+ uint mindist = MAX_UVALUE(uint);
- if (order == NULL) {
- v->current_order.Free();
- v->dest_tile = 0;
- ClearSlot(v);
- return;
- }
+ for (; rs != NULL; rs = rs->GetNextRoadStop(this)) {
+ uint dist = DistanceManhattan(this->tile, rs->xy);
- if (order->type == v->current_order.type &&
- order->flags == v->current_order.flags &&
- order->dest == v->current_order.dest) {
- return;
+ if (dist < mindist) {
+ mindist = dist;
+ dest = rs->xy;
+ }
+ }
}
- v->current_order = *order;
-
- switch (order->type) {
- case OT_GOTO_STATION: {
- if (order->dest == v->last_station_visited) {
- v->last_station_visited = INVALID_STATION;
- }
-
- const RoadStop *rs = GetStation(order->dest)->GetPrimaryRoadStop(v);
-
- TileIndex dest = INVALID_TILE;
- if (rs != NULL) {
- uint mindist = MAX_UVALUE(uint);
-
- for (; rs != NULL; rs = rs->GetNextRoadStop(v)) {
- uint dist = DistanceManhattan(v->tile, rs->xy);
-
- if (dist < mindist) {
- mindist = dist;
- dest = rs->xy;
- }
- }
- }
-
- if (dest != INVALID_TILE) {
- v->dest_tile = dest;
- } else {
- /* There is no stop left at the station, so don't even TRY to go there */
- v->cur_order_index++;
- v->dest_tile = 0;
- }
- break;
- }
-
- case OT_GOTO_DEPOT:
- v->dest_tile = GetDepot(order->dest)->xy;
- break;
-
- default:
- v->dest_tile = 0;
- break;
+ if (dest != INVALID_TILE) {
+ return dest;
+ } else {
+ /* There is no stop left at the station, so don't even TRY to go there */
+ this->cur_order_index++;
+ return 0;
}
-
- InvalidateVehicleOrder(v);
}
static void StartRoadVehSound(const Vehicle* v)
@@ -1286,7 +1224,7 @@
if (best_track == INVALID_TRACKDIR) best_track = (Trackdir)i; // in case we don't find the path, just pick a track
frd.maxtracklen = UINT_MAX;
frd.mindist = UINT_MAX;
- FollowTrack(tile, TRANSPORT_ROAD, v->u.road.compatible_roadtypes, _road_pf_directions[i], EnumRoadTrackFindDist, NULL, &frd);
+ FollowTrack(tile, PATHFIND_FLAGS_NONE, TRANSPORT_ROAD, v->u.road.compatible_roadtypes, _road_pf_directions[i], EnumRoadTrackFindDist, NULL, &frd);
if (frd.mindist < best_dist || (frd.mindist == best_dist && frd.maxtracklen < best_maxlen)) {
best_dist = frd.mindist;
@@ -1808,7 +1746,7 @@
if (IsRoadVehFront(v) && ((IsInsideMM(v->u.road.state, RVSB_IN_ROAD_STOP, RVSB_IN_ROAD_STOP_END) &&
_road_veh_data_1[v->u.road.state - RVSB_IN_ROAD_STOP + (_opt.road_side << RVS_DRIVE_SIDE)] == v->u.road.frame) ||
(IsInsideMM(v->u.road.state, RVSB_IN_DT_ROAD_STOP, RVSB_IN_DT_ROAD_STOP_END) &&
- v->current_order.dest == GetStationIndex(v->tile) &&
+ v->current_order.GetDestination() == GetStationIndex(v->tile) &&
GetRoadStopType(v->tile) == (IsCargoInClass(v->cargo_type, CC_PASSENGERS) ? ROADSTOP_BUS : ROADSTOP_TRUCK) &&
v->u.road.frame == RVC_DRIVE_THROUGH_STOP_FRAME))) {
@@ -1818,8 +1756,8 @@
/* Vehicle is at the stop position (at a bay) in a road stop.
* Note, if vehicle is loading/unloading it has already been handled,
* so if we get here the vehicle has just arrived or is just ready to leave. */
- if (v->current_order.type != OT_LEAVESTATION &&
- v->current_order.type != OT_GOTO_DEPOT) {
+ if (!v->current_order.IsType(OT_LEAVESTATION) &&
+ !v->current_order.IsType(OT_GOTO_DEPOT)) {
/* Vehicle has arrived at a bay in a road stop */
if (IsDriveThroughStopTile(v->tile)) {
@@ -1856,7 +1794,7 @@
}
/* Vehicle is ready to leave a bay in a road stop */
- if (v->current_order.type != OT_GOTO_DEPOT) {
+ if (!v->current_order.IsType(OT_GOTO_DEPOT)) {
if (rs->IsEntranceBusy()) {
/* Road stop entrance is busy, so wait as there is nowhere else to go */
v->cur_speed = 0;
@@ -1882,12 +1820,12 @@
if (v->dest_tile != v->u.road.slot->xy) {
DEBUG(ms, 2, " stop tile 0x%X is not destination tile 0x%X. Multistop desync", v->u.road.slot->xy, v->dest_tile);
}
- if (v->current_order.type != OT_GOTO_STATION) {
- DEBUG(ms, 2, " current order type (%d) is not OT_GOTO_STATION", v->current_order.type);
+ if (!v->current_order.IsType(OT_GOTO_STATION)) {
+ DEBUG(ms, 2, " current order type (%d) is not OT_GOTO_STATION", v->current_order.GetType());
} else {
- if (v->current_order.dest != st->index)
+ if (v->current_order.GetDestination() != st->index)
DEBUG(ms, 2, " current station %d is not target station in current_order.station (%d)",
- st->index, v->current_order.dest);
+ st->index, v->current_order.GetDestination());
}
DEBUG(ms, 2, " force a slot clearing");
@@ -1942,10 +1880,10 @@
if (v->vehstatus & VS_STOPPED) return;
- ProcessRoadVehOrder(v);
+ ProcessOrders(v);
v->HandleLoading();
- if (v->current_order.type == OT_LOADING) return;
+ if (v->current_order.IsType(OT_LOADING)) return;
if (v->IsInDepot() && RoadVehLeaveDepot(v, true)) return;
@@ -1986,26 +1924,23 @@
const Depot *depot = FindClosestRoadDepot(v);
if (depot == NULL || DistanceManhattan(v->tile, depot->xy) > 12) {
- if (v->current_order.type == OT_GOTO_DEPOT) {
- v->current_order.type = OT_DUMMY;
- v->current_order.flags = 0;
+ if (v->current_order.IsType(OT_GOTO_DEPOT)) {
+ v->current_order.MakeDummy();
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH);
}
return;
}
- if (v->current_order.type == OT_GOTO_DEPOT &&
- v->current_order.flags & OFB_NON_STOP &&
+ if (v->current_order.IsType(OT_GOTO_DEPOT) &&
+ v->current_order.GetNonStopType() & OFB_NON_STOP &&
!Chance16(1, 20)) {
return;
}
- if (v->current_order.type == OT_LOADING) v->LeaveStation();
+ if (v->current_order.IsType(OT_LOADING)) v->LeaveStation();
ClearSlot(v);
- v->current_order.type = OT_GOTO_DEPOT;
- v->current_order.flags = OFB_NON_STOP;
- v->current_order.dest = depot->index;
+ v->current_order.MakeGoToDepot(depot->index, false);
v->dest_tile = depot->xy;
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH);
}
@@ -2023,15 +1958,15 @@
CheckOrders(this);
/* Current slot has expired */
- if (this->current_order.type == OT_GOTO_STATION && this->u.road.slot != NULL && this->u.road.slot_age-- == 0) {
+ if (this->current_order.IsType(OT_GOTO_STATION) && this->u.road.slot != NULL && this->u.road.slot_age-- == 0) {
DEBUG(ms, 3, "Slot expired for vehicle %d (index %d) at stop 0x%X",
this->unitnumber, this->index, this->u.road.slot->xy);
ClearSlot(this);
}
/* update destination */
- if (!(this->vehstatus & VS_STOPPED) && this->current_order.type == OT_GOTO_STATION && this->u.road.slot == NULL && !(this->vehstatus & VS_CRASHED)) {
- Station *st = GetStation(this->current_order.dest);
+ if (!(this->vehstatus & VS_STOPPED) && this->current_order.IsType(OT_GOTO_STATION) && this->u.road.slot == NULL && !(this->vehstatus & VS_CRASHED)) {
+ Station *st = GetStation(this->current_order.GetDestination());
RoadStop *rs = st->GetPrimaryRoadStop(this);
RoadStop *best = NULL;