Skip to content

Commit

Permalink
-Feature: allow implicit orders even if no explicit ones are given.
Browse files Browse the repository at this point in the history
  • Loading branch information
ulfhermann committed Jul 31, 2013
1 parent f549b7d commit 4a87b7f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/vehicle.cpp
Expand Up @@ -1942,13 +1942,12 @@ void Vehicle::BeginLoading()

} else {
/* 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
* list isn't empty.
* to show that we are stopping here.
* While only groundvehicles have implicit orders, e.g. aircraft might still enter
* the 'wrong' terminal when skipping orders etc. */
Order *in_list = this->GetOrder(this->cur_implicit_order_index);
if (this->IsGroundVehicle() && in_list != NULL &&
(!in_list->IsType(OT_IMPLICIT) ||
if (this->IsGroundVehicle() &&
(in_list == NULL || !in_list->IsType(OT_IMPLICIT) ||
in_list->GetDestination() != this->last_station_visited)) {
bool suppress_implicit_orders = HasBit(this->GetGroundVehicleFlags(), GVF_SUPPRESS_IMPLICIT_ORDERS);
/* Do not create consecutive duplicates of implicit orders */
Expand All @@ -1961,15 +1960,16 @@ void Vehicle::BeginLoading()
* so test whether the right order follows later */
int target_index = this->cur_implicit_order_index;
bool found = false;
while (target_index != this->cur_real_order_index) {
while (target_index != this->cur_real_order_index || !this->HasExplicitOrders()) {
const Order *order = this->GetOrder(target_index);
if (order == NULL) break; // No orders.
if (order->IsType(OT_IMPLICIT) && order->GetDestination() == this->last_station_visited) {
found = true;
break;
}
target_index++;
if (target_index >= this->orders.list->GetNumOrders()) target_index = 0;
assert(target_index != this->cur_implicit_order_index); // infinite loop?
if (target_index == this->cur_implicit_order_index) break; // Avoid infinite loop.
}

if (found) {
Expand Down Expand Up @@ -1999,7 +1999,10 @@ void Vehicle::BeginLoading()
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 */
Order *implicit_order = new Order();
implicit_order->MakeImplicit(this->last_station_visited);
Expand Down Expand Up @@ -2402,7 +2405,7 @@ CommandCost Vehicle::SendToDepot(DoCommandFlag flags, DepotCommand command)
if (flags & DC_EXEC) {
if (this->current_order.IsType(OT_LOADING)) this->LeaveStation();

if (this->IsGroundVehicle()) {
if (this->IsGroundVehicle() && this->HasExplicitOrders()) {
uint16 &gv_flags = this->GetGroundVehicleFlags();
SetBit(gv_flags, GVF_SUPPRESS_IMPLICIT_ORDERS);
}
Expand Down
12 changes: 12 additions & 0 deletions src/vehicle_base.h
Expand Up @@ -779,6 +779,18 @@ struct Vehicle : VehiclePool::PoolItem<&_vehicle_pool>, BaseVehicle, BaseConsist
}
}

/**
* A vehicle has explicit orders if the current real order index points to
* such an order. As soon as there is one explicit order the index will
* point to that one and it will never change to an implicit one.
* @return If vehicle has explicit orders
*/
bool HasExplicitOrders() const
{
const Order *cur = this->GetOrder(this->cur_real_order_index);
return cur != NULL && !cur->IsType(OT_IMPLICIT);
}

/**
* Returns order 'index' of a vehicle or NULL when it doesn't exists
* @param index the order to fetch
Expand Down

0 comments on commit 4a87b7f

Please sign in to comment.