mirror of https://github.com/OpenTTD/OpenTTD
(svn r25906) -Fix: Simplify condition logic in link refresher.
parent
a9f6a1eeb7
commit
fb7ad743d2
|
@ -146,33 +146,27 @@ void LinkRefresher::ResetRefit()
|
||||||
const Order *LinkRefresher::PredictNextOrder(const Order *cur, const Order *next, uint8 flags)
|
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.
|
int num_hops = 0; // Count hops to catch infinite loops without station or implicit orders.
|
||||||
do {
|
while (next != NULL && (next->IsType(OT_CONDITIONAL) || cur == next)) {
|
||||||
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)) {
|
if (next->IsType(OT_CONDITIONAL)) {
|
||||||
skip_to = this->vehicle->orders.list->GetNextDecisionNode(
|
const Order *skip_to = this->vehicle->orders.list->GetNextDecisionNode(
|
||||||
this->vehicle->orders.list->GetOrderAt(next->GetConditionSkipToOrder()), num_hops++);
|
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++);
|
|
||||||
|
|
||||||
if (skip_to != NULL) {
|
if (skip_to != NULL) {
|
||||||
/* Make copies of capacity tracking lists. There is potential
|
/* 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
|
* need to copy anything. Also, if we've seen the branched link
|
||||||
* before we don't need to branch at all. */
|
* before we don't need to branch at all. */
|
||||||
LinkRefresher branch(*this);
|
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;
|
return next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,6 @@ protected:
|
||||||
* an influence on the next one.
|
* an influence on the next one.
|
||||||
*/
|
*/
|
||||||
enum RefreshFlags {
|
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).
|
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.
|
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.
|
RESET_REFIT ///< Consist had a chance to load since the last refit and the refit capacities can be reset.
|
||||||
|
|
Loading…
Reference in New Issue