summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2011-01-18 14:27:43 +0000
committerrubidium <rubidium@openttd.org>2011-01-18 14:27:43 +0000
commit3f900d3580fc4afd967df859e6dfdce664ff3ca9 (patch)
tree3296fd4baf5ead14e7894a870419f7bcd62eb27e /src
parent39d7f3b2bd486d5332ad3a6ddfe518dd86b65fa4 (diff)
downloadopenttd-3f900d3580fc4afd967df859e6dfdce664ff3ca9.tar.xz
(svn r21832) -Feature: limit vehicle lateness to the length of a full timetable cycle, e.g. when a cycle takes 50 days and the vehicle is 65 days later reduce the lateness to 15 days
Diffstat (limited to 'src')
-rw-r--r--src/timetable_cmd.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/timetable_cmd.cpp b/src/timetable_cmd.cpp
index c633ec61b..94c9812ef 100644
--- a/src/timetable_cmd.cpp
+++ b/src/timetable_cmd.cpp
@@ -310,6 +310,18 @@ void UpdateVehicleTimetable(Vehicle *v, bool travelling)
v->lateness_counter -= (timetabled - time_taken);
+ /* When we are more late than this timetabled bit takes we (somewhat expensively)
+ * check how many ticks the (fully filled) timetable has. If a timetable cycle is
+ * shorter than the amount of ticks we are late we reduce the lateness by the
+ * length of a full cycle till lateness is less than the length of a timetable
+ * cycle. When the timetable isn't fully filled the cycle will be INVALID_TICKS. */
+ if (v->lateness_counter > (int)timetabled) {
+ Ticks cycle = v->orders.list->GetTimetableTotalDuration();
+ if (cycle != INVALID_TICKS && v->lateness_counter > cycle) {
+ v->lateness_counter %= cycle;
+ }
+ }
+
for (v = v->FirstShared(); v != NULL; v = v->NextShared()) {
SetWindowDirty(WC_VEHICLE_TIMETABLE, v->index);
}