(svn r25906) -Fix: Simplify condition logic in link refresher.

This commit is contained in:
fonsinchen 2013-10-22 18:46:58 +00:00
parent a9f6a1eeb7
commit fb7ad743d2
2 changed files with 13 additions and 20 deletions

View File

@ -146,33 +146,27 @@ void LinkRefresher::ResetRefit()
const Order *LinkRefresher::PredictNextOrder(const Order *cur, const Order *next, uint8 flags)
{
int num_hops = 0; // Count hops to catch infinite loops without station or implicit orders.
do {
if (HasBit(flags, USE_NEXT)) {
/* First incrementation has to be skipped if a "real" next hop,
* different from cur, was given. */
ClrBit(flags, USE_NEXT);
} else {
const Order *skip_to = NULL;
if (next->IsType(OT_CONDITIONAL)) {
skip_to = this->vehicle->orders.list->GetNextDecisionNode(
this->vehicle->orders.list->GetOrderAt(next->GetConditionSkipToOrder()), num_hops++);
}
/* Reassign next with the following stop. This can be a station or a
* depot.*/
next = this->vehicle->orders.list->GetNextDecisionNode(
this->vehicle->orders.list->GetNext(next), num_hops++);
while (next != NULL && (next->IsType(OT_CONDITIONAL) || cur == next)) {
if (next->IsType(OT_CONDITIONAL)) {
const Order *skip_to = this->vehicle->orders.list->GetNextDecisionNode(
this->vehicle->orders.list->GetOrderAt(next->GetConditionSkipToOrder()), num_hops++);
if (skip_to != NULL) {
/* Make copies of capacity tracking lists. There is potential
* for optimization here. If the vehicle never refits we don't
* need to copy anything. Also, if we've seen the branched link
* before we don't need to branch at all. */
LinkRefresher branch(*this);
branch.RefreshLinks(cur, skip_to, flags | (cur != skip_to ? 1 << USE_NEXT : 0));
/* If skip_to points back to the original order, use the next one.
* Otherwise do use it. */
branch.RefreshLinks(cur, skip_to, flags);
}
}
} while (next != NULL && next->IsType(OT_CONDITIONAL));
/* Reassign next with the following stop. This can be a station or a
* depot.*/
next = this->vehicle->orders.list->GetNextDecisionNode(
this->vehicle->orders.list->GetNext(next), num_hops++);
}
return next;
}

View File

@ -31,7 +31,6 @@ protected:
* an influence on the next one.
*/
enum RefreshFlags {
USE_NEXT, ///< There has been a previous link. Try to use the given next order.
HAS_CARGO, ///< Consist could leave the last stop where it could interact with cargo carrying cargo (i.e. not an "unload all" + "no loading" order).
WAS_REFIT, ///< Consist was refit since the last stop where it could interact with cargo.
RESET_REFIT ///< Consist had a chance to load since the last refit and the refit capacities can be reset.