summaryrefslogtreecommitdiff
path: root/yapf
diff options
context:
space:
mode:
authorKUDr <KUDr@openttd.org>2006-11-16 10:51:42 +0000
committerKUDr <KUDr@openttd.org>2006-11-16 10:51:42 +0000
commit3a90d6d00c22120ae1f007a340e44fac39951d10 (patch)
tree601b52cc2b7207ad8db6b806a065e3041747c7f2 /yapf
parenta15768953b8ba5aabdd6a18cd0b69d209178387a (diff)
downloadopenttd-3a90d6d00c22120ae1f007a340e44fac39951d10.tar.xz
(svn r7164) -Fix: [YAPF] assert when look-ahead polynomial result (red-signal penalty) is negative. Such penalty is now added as positive penalty for the appropriate green signal. (DannyA)
Diffstat (limited to 'yapf')
-rw-r--r--yapf/yapf_costrail.hpp12
1 files changed, 10 insertions, 2 deletions
diff --git a/yapf/yapf_costrail.hpp b/yapf/yapf_costrail.hpp
index c19e296d8..c8e34dfbd 100644
--- a/yapf/yapf_costrail.hpp
+++ b/yapf/yapf_costrail.hpp
@@ -100,9 +100,16 @@ public:
n.m_segment->flags_u.flags_s.m_end_of_line = true;
} else if (has_signal_along) {
SignalState sig_state = GetSignalStateByTrackdir(tile, trackdir);
+ // cache the look-ahead polynomial constant only if we didn't pass more signals than the look-ahead limit is
+ int look_ahead_cost = (n.m_num_signals_passed < m_sig_look_ahead_costs.Size()) ? m_sig_look_ahead_costs.Data()[n.m_num_signals_passed] : 0;
if (sig_state != SIGNAL_STATE_RED) {
// green signal
n.flags_u.flags_s.m_last_signal_was_red = false;
+ // negative look-ahead red-signal penalties would cause problems later, so use them as positive penalties for green signal
+ if (look_ahead_cost < 0) {
+ // add its negation to the cost
+ cost -= look_ahead_cost;
+ }
} else {
// we have a red signal in our direction
// was it first signal which is two-way?
@@ -116,8 +123,9 @@ public:
n.flags_u.flags_s.m_last_signal_was_red = true;
// look-ahead signal penalty
- if (n.m_num_signals_passed < m_sig_look_ahead_costs.Size()) {
- cost += m_sig_look_ahead_costs.Data()[n.m_num_signals_passed];
+ if (look_ahead_cost > 0) {
+ // add the look ahead penalty only if it is positive
+ cost += look_ahead_cost;
}
// special signal penalties