diff options
author | fonsinchen <fonsinchen@openttd.org> | 2013-10-22 18:46:58 +0000 |
---|---|---|
committer | fonsinchen <fonsinchen@openttd.org> | 2013-10-22 18:46:58 +0000 |
commit | fb7ad743d2fc8362ec77b8b23d4f8c75ac2d9320 (patch) | |
tree | 03b2acdf410514632bf91d2e40972747bb589da4 /src/linkgraph | |
parent | a9f6a1eeb77b78a00bd6e597b1fd352a2a5fe7ea (diff) | |
download | openttd-fb7ad743d2fc8362ec77b8b23d4f8c75ac2d9320.tar.xz |
(svn r25906) -Fix: Simplify condition logic in link refresher.
Diffstat (limited to 'src/linkgraph')
-rw-r--r-- | src/linkgraph/refresh.cpp | 32 | ||||
-rw-r--r-- | src/linkgraph/refresh.h | 1 |
2 files changed, 13 insertions, 20 deletions
diff --git a/src/linkgraph/refresh.cpp b/src/linkgraph/refresh.cpp index f8d98fe16..2c2b11383 100644 --- a/src/linkgraph/refresh.cpp +++ b/src/linkgraph/refresh.cpp @@ -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; } diff --git a/src/linkgraph/refresh.h b/src/linkgraph/refresh.h index 1551d33fa..ba96aa559 100644 --- a/src/linkgraph/refresh.h +++ b/src/linkgraph/refresh.h @@ -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. |