summaryrefslogtreecommitdiff
path: root/src/linkgraph
diff options
context:
space:
mode:
authorfonsinchen <fonsinchen@openttd.org>2013-10-23 17:11:34 +0000
committerfonsinchen <fonsinchen@openttd.org>2013-10-23 17:11:34 +0000
commitb5dd83e84f355eedbfc78838c0961864cd7a8fb1 (patch)
treee2c983f6945cb3d6f0db881a14909e15fd90e265 /src/linkgraph
parent6c4e7ab51dbac9089644b2d7388092a6027c6223 (diff)
downloadopenttd-b5dd83e84f355eedbfc78838c0961864cd7a8fb1.tar.xz
(svn r25909) -Fix (r25906): That simplification was a bit too much.
Diffstat (limited to 'src/linkgraph')
-rw-r--r--src/linkgraph/refresh.cpp19
-rw-r--r--src/linkgraph/refresh.h1
2 files changed, 16 insertions, 4 deletions
diff --git a/src/linkgraph/refresh.cpp b/src/linkgraph/refresh.cpp
index 2c2b11383..53a1d28df 100644
--- a/src/linkgraph/refresh.cpp
+++ b/src/linkgraph/refresh.cpp
@@ -146,18 +146,26 @@ 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.
- while (next != NULL && (next->IsType(OT_CONDITIONAL) || cur == next)) {
+
+ /* next is good if it's either NULL (then the caller will stop the
+ * evaluation) or if it's not conditional and the caller allows it to be
+ * chosen (by setting USE_NEXT). */
+ while (next != NULL && (!HasBit(flags, USE_NEXT) || next->IsType(OT_CONDITIONAL))) {
+
+ /* After the first step any further non-conditional order is good,
+ * regardless of previous USE_NEXT settings. The case of cur and next or
+ * their respective stations being equal is handled elsewhere. */
+ SetBit(flags, USE_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
+ * 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);
- /* If skip_to points back to the original order, use the next one.
- * Otherwise do use it. */
branch.RefreshLinks(cur, skip_to, flags);
}
}
@@ -234,6 +242,9 @@ void LinkRefresher::RefreshLinks(const Order *cur, const Order *next, uint8 flag
this->seen_hops->insert(hop);
}
+ /* Don't use the same order again, but choose a new one in the next round. */
+ ClrBit(flags, USE_NEXT);
+
/* Skip resetting and link refreshing if next order won't do anything with cargo. */
if (!next->IsType(OT_GOTO_STATION) && !next->IsType(OT_IMPLICIT)) continue;
diff --git a/src/linkgraph/refresh.h b/src/linkgraph/refresh.h
index ff9662224..aa3d8850d 100644
--- a/src/linkgraph/refresh.h
+++ b/src/linkgraph/refresh.h
@@ -31,6 +31,7 @@ protected:
* an influence on the next one.
*/
enum RefreshFlags {
+ USE_NEXT, ///< There was a conditional jump. Try to use the given next order when looking for a new one.
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.