(svn r25735) -Feature: allow implicit orders even if no explicit ones are given.

This commit is contained in:
fonsinchen 2013-08-20 20:05:31 +00:00
parent ae629c028a
commit d8365c63fd
2 changed files with 28 additions and 10 deletions

View File

@ -27,6 +27,12 @@ static const VehicleOrderID MAX_VEH_ORDER_ID = INVALID_VEH_ORDER_ID - 1;
/** Invalid order (sentinel) */ /** Invalid order (sentinel) */
static const OrderID INVALID_ORDER = 0xFFFF; static const OrderID INVALID_ORDER = 0xFFFF;
/**
* Maximum number of orders in implicit-only lists before we start searching
* harder for duplicates.
*/
static const uint IMPLICIT_ORDER_ONLY_CAP = 32;
/** Order types */ /** Order types */
enum OrderType { enum OrderType {
OT_BEGIN = 0, OT_BEGIN = 0,

View File

@ -1943,13 +1943,12 @@ void Vehicle::BeginLoading()
} else { } else {
/* We weren't scheduled to stop here. Insert an implicit order /* We weren't scheduled to stop here. Insert an implicit order
* to show that we are stopping here, but only do that if the order * to show that we are stopping here.
* list isn't empty.
* While only groundvehicles have implicit orders, e.g. aircraft might still enter * While only groundvehicles have implicit orders, e.g. aircraft might still enter
* the 'wrong' terminal when skipping orders etc. */ * the 'wrong' terminal when skipping orders etc. */
Order *in_list = this->GetOrder(this->cur_implicit_order_index); Order *in_list = this->GetOrder(this->cur_implicit_order_index);
if (this->IsGroundVehicle() && in_list != NULL && if (this->IsGroundVehicle() &&
(!in_list->IsType(OT_IMPLICIT) || (in_list == NULL || !in_list->IsType(OT_IMPLICIT) ||
in_list->GetDestination() != this->last_station_visited)) { in_list->GetDestination() != this->last_station_visited)) {
bool suppress_implicit_orders = HasBit(this->GetGroundVehicleFlags(), GVF_SUPPRESS_IMPLICIT_ORDERS); bool suppress_implicit_orders = HasBit(this->GetGroundVehicleFlags(), GVF_SUPPRESS_IMPLICIT_ORDERS);
/* Do not create consecutive duplicates of implicit orders */ /* Do not create consecutive duplicates of implicit orders */
@ -1959,18 +1958,28 @@ void Vehicle::BeginLoading()
prev_order->GetDestination() != this->last_station_visited) { prev_order->GetDestination() != this->last_station_visited) {
/* Prefer deleting implicit orders instead of inserting new ones, /* Prefer deleting implicit orders instead of inserting new ones,
* so test whether the right order follows later */ * so test whether the right order follows later. In case of only
* implicit orders treat the last order in the list like an
* explicit one, except if the overall number of orders surpasses
* IMPLICIT_ORDER_ONLY_CAP. */
int target_index = this->cur_implicit_order_index; int target_index = this->cur_implicit_order_index;
bool found = false; bool found = false;
while (target_index != this->cur_real_order_index) { while (target_index != this->cur_real_order_index || this->GetNumManualOrders() == 0) {
const Order *order = this->GetOrder(target_index); const Order *order = this->GetOrder(target_index);
if (order == NULL) break; // No orders.
if (order->IsType(OT_IMPLICIT) && order->GetDestination() == this->last_station_visited) { if (order->IsType(OT_IMPLICIT) && order->GetDestination() == this->last_station_visited) {
found = true; found = true;
break; break;
} }
target_index++; target_index++;
if (target_index >= this->orders.list->GetNumOrders()) target_index = 0; if (target_index >= this->orders.list->GetNumOrders()) {
assert(target_index != this->cur_implicit_order_index); // infinite loop? if (this->GetNumManualOrders() == 0 &&
this->GetNumOrders() < IMPLICIT_ORDER_ONLY_CAP) {
break;
}
target_index = 0;
}
if (target_index == this->cur_implicit_order_index) break; // Avoid infinite loop.
} }
if (found) { if (found) {
@ -2000,7 +2009,10 @@ void Vehicle::BeginLoading()
assert(order != NULL); assert(order != NULL);
} }
} }
} else if (!suppress_implicit_orders && this->orders.list->GetNumOrders() < MAX_VEH_ORDER_ID && Order::CanAllocateItem()) { } else if (!suppress_implicit_orders &&
((this->orders.list == NULL && OrderList::CanAllocateItem()) ||
this->orders.list->GetNumOrders() < MAX_VEH_ORDER_ID) &&
Order::CanAllocateItem()) {
/* Insert new implicit order */ /* Insert new implicit order */
Order *implicit_order = new Order(); Order *implicit_order = new Order();
implicit_order->MakeImplicit(this->last_station_visited); implicit_order->MakeImplicit(this->last_station_visited);
@ -2381,7 +2393,7 @@ CommandCost Vehicle::SendToDepot(DoCommandFlag flags, DepotCommand command)
if (flags & DC_EXEC) { if (flags & DC_EXEC) {
if (this->current_order.IsType(OT_LOADING)) this->LeaveStation(); if (this->current_order.IsType(OT_LOADING)) this->LeaveStation();
if (this->IsGroundVehicle()) { if (this->IsGroundVehicle() && this->GetNumManualOrders() > 0) {
uint16 &gv_flags = this->GetGroundVehicleFlags(); uint16 &gv_flags = this->GetGroundVehicleFlags();
SetBit(gv_flags, GVF_SUPPRESS_IMPLICIT_ORDERS); SetBit(gv_flags, GVF_SUPPRESS_IMPLICIT_ORDERS);
} }