summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2008-11-18 23:53:37 +0000
committerrubidium <rubidium@openttd.org>2008-11-18 23:53:37 +0000
commit2ed3c27822109d7c28422b0a61dbab06a8f7be4c (patch)
tree218a482fce834fe95fda7471c7dc81ddd9dddf8c
parent07e3c096b3b744ef1d094c9481faa31ec8d2034a (diff)
downloadopenttd-2ed3c27822109d7c28422b0a61dbab06a8f7be4c.tar.xz
(svn r14592) -Feature [FS#1124]: non-destructive autofill with option to keep waiting times (PhilSophus)
-rw-r--r--src/lang/english.txt2
-rw-r--r--src/timetable_cmd.cpp48
-rw-r--r--src/timetable_gui.cpp9
-rw-r--r--src/vehicle_base.h5
4 files changed, 41 insertions, 23 deletions
diff --git a/src/lang/english.txt b/src/lang/english.txt
index e0e071bbf..c8ff885e2 100644
--- a/src/lang/english.txt
+++ b/src/lang/english.txt
@@ -2941,7 +2941,7 @@ STR_TIMETABLE_STATUS_EARLY :This vehicle is
STR_TIMETABLE_TOTAL_TIME :This timetable will take {STRING1} to complete
STR_TIMETABLE_TOTAL_TIME_INCOMPLETE :This timetable will take at least {STRING1} to complete (not all timetabled)
STR_TIMETABLE_AUTOFILL :{BLACK}Autofill
-STR_TIMETABLE_AUTOFILL_TOOLTIP :{BLACK}Fill the timetable automatically with the values from the first journey
+STR_TIMETABLE_AUTOFILL_TOOLTIP :{BLACK}Fill the timetable automatically with the values from the next journey (CTRL-click to try to keep waiting times)
##id 0x9000
STR_9000_ROAD_VEHICLE_IN_THE_WAY :{WHITE}Road vehicle in the way
diff --git a/src/timetable_cmd.cpp b/src/timetable_cmd.cpp
index 03a84bde9..5a5565f0c 100644
--- a/src/timetable_cmd.cpp
+++ b/src/timetable_cmd.cpp
@@ -133,7 +133,9 @@ CommandCost CmdSetVehicleOnTime(TileIndex tile, uint32 flags, uint32 p1, uint32
* @param tile Not used.
* @param flags Operation to perform.
* @param p1 Vehicle index.
- * @param p2 Set to 1 to enable, 0 to disable.
+ * @param p2 Various bitstuffed elements
+ * - p2 = (bit 0) - Set to 1 to enable, 0 to disable autofill.
+ * - p2 = (bit 1) - Set to 1 to preserve waiting times in non-destructive mode
*/
CommandCost CmdAutofillTimetable(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
{
@@ -146,21 +148,18 @@ CommandCost CmdAutofillTimetable(TileIndex tile, uint32 flags, uint32 p1, uint32
if (!CheckOwnership(v->owner)) return CMD_ERROR;
if (flags & DC_EXEC) {
- if (p2 == 1) {
+ if (HasBit(p2, 0)) {
/* Start autofilling the timetable, which clears all the current
* timings and clears the "timetable has started" bit. */
SetBit(v->vehicle_flags, VF_AUTOFILL_TIMETABLE);
ClrBit(v->vehicle_flags, VF_TIMETABLE_STARTED);
- for (Order *order = GetVehicleOrder(v, 0); order != NULL; order = order->next) {
- order->wait_time = 0;
- order->travel_time = 0;
- }
+ if (HasBit(p2, 1)) SetBit(v->vehicle_flags, VF_AUTOFILL_PRES_WAIT_TIME);
- v->current_order.wait_time = 0;
- v->current_order.travel_time = 0;
+ v->lateness_counter = 0;
} else {
ClrBit(v->vehicle_flags, VF_AUTOFILL_TIMETABLE);
+ ClrBit(v->vehicle_flags, VF_AUTOFILL_PRES_WAIT_TIME);
}
}
@@ -180,33 +179,48 @@ void UpdateVehicleTimetable(Vehicle *v, bool travelling)
if (!_settings_game.order.timetabling) return;
+ bool just_started = false;
+
/* Make sure the timetable only starts when the vehicle reaches the first
* order, not when travelling from the depot to the first station. */
if (v->cur_order_index == 0 && !HasBit(v->vehicle_flags, VF_TIMETABLE_STARTED)) {
SetBit(v->vehicle_flags, VF_TIMETABLE_STARTED);
- return;
+ just_started = true;
}
if (!HasBit(v->vehicle_flags, VF_TIMETABLE_STARTED)) return;
if (HasBit(v->vehicle_flags, VF_AUTOFILL_TIMETABLE)) {
- if (timetabled == 0) {
+ if (travelling && !HasBit(v->vehicle_flags, VF_AUTOFILL_PRES_WAIT_TIME)) {
+ /* Need to clear that now as otherwise we are not able to reduce the wait time */
+ v->current_order.wait_time = 0;
+ }
+
+ if (just_started) return;
+
+ /* Modify station waiting time only if our new value is larger (this is
+ * always the case when we cleared the timetable). */
+ if (!v->current_order.IsType(OT_CONDITIONAL) && (travelling || time_taken > v->current_order.wait_time)) {
/* Round the time taken up to the nearest day, as this will avoid
* confusion for people who are timetabling in days, and can be
* adjusted later by people who aren't. */
time_taken = (((time_taken - 1) / DAY_TICKS) + 1) * DAY_TICKS;
- if (!v->current_order.IsType(OT_CONDITIONAL)) {
- ChangeTimetable(v, v->cur_order_index, time_taken, travelling);
- }
- return;
- } else if (v->cur_order_index == 0) {
- /* Otherwise if we're at the beginning and it already has a value,
- * assume that autofill is finished and turn it off again. */
+ ChangeTimetable(v, v->cur_order_index, time_taken, travelling);
+ }
+
+ if (v->cur_order_index == 0 && travelling) {
+ /* If we just started we would have returned earlier and have not reached
+ * this code. So obviously, we have completed our round: So turn autofill
+ * off again. */
ClrBit(v->vehicle_flags, VF_AUTOFILL_TIMETABLE);
+ ClrBit(v->vehicle_flags, VF_AUTOFILL_PRES_WAIT_TIME);
}
+ return;
}
+ if (just_started) return;
+
/* Vehicles will wait at stations if they arrive early even if they are not
* timetabled to wait there, so make sure the lateness counter is updated
* when this happens. */
diff --git a/src/timetable_gui.cpp b/src/timetable_gui.cpp
index 813354874..f2cd24d1b 100644
--- a/src/timetable_gui.cpp
+++ b/src/timetable_gui.cpp
@@ -301,9 +301,12 @@ struct TimetableWindow : Window {
DoCommandP(0, v->index, 0, NULL, CMD_SET_VEHICLE_ON_TIME | CMD_MSG(STR_CAN_T_TIMETABLE_VEHICLE));
break;
- case TTV_AUTOFILL: /* Autofill the timetable. */
- DoCommandP(0, v->index, HasBit(v->vehicle_flags, VF_AUTOFILL_TIMETABLE) ? 0 : 1, NULL, CMD_AUTOFILL_TIMETABLE | CMD_MSG(STR_CAN_T_TIMETABLE_VEHICLE));
- break;
+ case TTV_AUTOFILL: { /* Autofill the timetable. */
+ uint32 p2 = 0;
+ if (!HasBit(v->vehicle_flags, VF_AUTOFILL_TIMETABLE)) SetBit(p2, 0);
+ if (_ctrl_pressed) SetBit(p2, 1);
+ DoCommandP(0, v->index, p2, NULL, CMD_AUTOFILL_TIMETABLE | CMD_MSG(STR_CAN_T_TIMETABLE_VEHICLE));
+ } break;
}
this->SetDirty();
diff --git a/src/vehicle_base.h b/src/vehicle_base.h
index 39f2673c4..cee6c4d5b 100644
--- a/src/vehicle_base.h
+++ b/src/vehicle_base.h
@@ -75,8 +75,9 @@ enum VehicleFlags {
VF_LOADING_FINISHED,
VF_CARGO_UNLOADING,
VF_BUILT_AS_PROTOTYPE,
- VF_TIMETABLE_STARTED, ///< Whether the vehicle has started running on the timetable yet.
- VF_AUTOFILL_TIMETABLE, ///< Whether the vehicle should fill in the timetable automatically.
+ VF_TIMETABLE_STARTED, ///< Whether the vehicle has started running on the timetable yet.
+ VF_AUTOFILL_TIMETABLE, ///< Whether the vehicle should fill in the timetable automatically.
+ VF_AUTOFILL_PRES_WAIT_TIME, ///< Whether non-destructive auto-fill should preserve waiting times
};
struct VehicleRail {