(svn r22328) -Add: a flag to GroundVehicles to disable insertion and removal of automatic orders until the next real order is reached.

This commit is contained in:
frosch 2011-04-16 16:45:35 +00:00
parent aedd38255b
commit 194a941a37
3 changed files with 25 additions and 5 deletions

View File

@ -50,8 +50,9 @@ struct GroundVehicleCache {
/** Ground vehicle flags. */ /** Ground vehicle flags. */
enum GroundVehicleFlags { enum GroundVehicleFlags {
GVF_GOINGUP_BIT = 0, GVF_GOINGUP_BIT = 0, ///< Vehicle is currently going uphill. (Cached track information for acceleration)
GVF_GOINGDOWN_BIT = 1, GVF_GOINGDOWN_BIT = 1, ///< Vehicle is currently going downhill. (Cached track information for acceleration)
GVF_SUPPRESS_AUTOMATIC_ORDERS = 2, ///< Disable insertion and removal of automatic orders until the vehicle completes the real order.
}; };
/** /**

View File

@ -2287,19 +2287,21 @@ static bool TryReserveSafeTrack(const Train *v, TileIndex tile, Trackdir td, boo
class VehicleOrderSaver class VehicleOrderSaver
{ {
private: private:
Vehicle *v; Train *v;
Order old_order; Order old_order;
TileIndex old_dest_tile; TileIndex old_dest_tile;
StationID old_last_station_visited; StationID old_last_station_visited;
VehicleOrderID index; VehicleOrderID index;
bool suppress_automatic_orders;
public: public:
VehicleOrderSaver(Vehicle *_v) : VehicleOrderSaver(Train *_v) :
v(_v), v(_v),
old_order(_v->current_order), old_order(_v->current_order),
old_dest_tile(_v->dest_tile), old_dest_tile(_v->dest_tile),
old_last_station_visited(_v->last_station_visited), old_last_station_visited(_v->last_station_visited),
index(_v->cur_real_order_index) index(_v->cur_real_order_index),
suppress_automatic_orders(HasBit(_v->gv_flags, GVF_SUPPRESS_AUTOMATIC_ORDERS))
{ {
} }
@ -2308,6 +2310,7 @@ public:
this->v->current_order = this->old_order; this->v->current_order = this->old_order;
this->v->dest_tile = this->old_dest_tile; this->v->dest_tile = this->old_dest_tile;
this->v->last_station_visited = this->old_last_station_visited; this->v->last_station_visited = this->old_last_station_visited;
SB(this->v->gv_flags, GVF_SUPPRESS_AUTOMATIC_ORDERS, 1, suppress_automatic_orders ? 1: 0);
} }
/** /**
@ -3767,6 +3770,7 @@ static void CheckIfTrainNeedsService(Train *v)
return; return;
} }
SetBit(v->gv_flags, GVF_SUPPRESS_AUTOMATIC_ORDERS);
v->current_order.MakeGoToDepot(depot, ODTFB_SERVICE); v->current_order.MakeGoToDepot(depot, ODTFB_SERVICE);
v->dest_tile = tfdd.tile; v->dest_tile = tfdd.tile;
SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH); SetWindowWidgetDirty(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH);

View File

@ -1797,6 +1797,17 @@ uint GetVehicleCapacity(const Vehicle *v, uint16 *mail_capacity)
*/ */
void Vehicle::DeleteUnreachedAutoOrders() void Vehicle::DeleteUnreachedAutoOrders()
{ {
if (this->IsGroundVehicle()) {
uint16 &gv_flags = this->GetGroundVehicleFlags();
if (HasBit(gv_flags, GVF_SUPPRESS_AUTOMATIC_ORDERS)) {
/* Do not delete orders, only skip them */
ClrBit(gv_flags, GVF_SUPPRESS_AUTOMATIC_ORDERS);
this->cur_auto_order_index = this->cur_real_order_index;
InvalidateVehicleOrder(this, 0);
return;
}
}
const Order *order = this->GetOrder(this->cur_auto_order_index); const Order *order = this->GetOrder(this->cur_auto_order_index);
while (order != NULL) { while (order != NULL) {
if (this->cur_auto_order_index == this->cur_real_order_index) break; if (this->cur_auto_order_index == this->cur_real_order_index) break;
@ -1843,6 +1854,9 @@ void Vehicle::BeginLoading()
this->current_order.SetNonStopType(ONSF_NO_STOP_AT_ANY_STATION); this->current_order.SetNonStopType(ONSF_NO_STOP_AT_ANY_STATION);
} else { } else {
assert(this->IsGroundVehicle());
bool suppress_automatic_orders = HasBit(this->GetGroundVehicleFlags(), GVF_SUPPRESS_AUTOMATIC_ORDERS);
/* We weren't scheduled to stop here. Insert an automatic order /* We weren't scheduled to stop here. Insert an automatic order
* to show that we are stopping here, but only do that if the order * to show that we are stopping here, but only do that if the order
* list isn't empty. */ * list isn't empty. */
@ -1850,6 +1864,7 @@ void Vehicle::BeginLoading()
if (in_list != NULL && this->orders.list->GetNumOrders() < MAX_VEH_ORDER_ID && if (in_list != NULL && this->orders.list->GetNumOrders() < MAX_VEH_ORDER_ID &&
(!in_list->IsType(OT_AUTOMATIC) || (!in_list->IsType(OT_AUTOMATIC) ||
in_list->GetDestination() != this->last_station_visited) && in_list->GetDestination() != this->last_station_visited) &&
!suppress_automatic_orders &&
Order::CanAllocateItem()) { Order::CanAllocateItem()) {
Order *auto_order = new Order(); Order *auto_order = new Order();
auto_order->MakeAutomatic(this->last_station_visited); auto_order->MakeAutomatic(this->last_station_visited);