summaryrefslogtreecommitdiff
path: root/src/timetable_cmd.cpp
diff options
context:
space:
mode:
authormaedhros <maedhros@openttd.org>2007-06-20 19:26:25 +0000
committermaedhros <maedhros@openttd.org>2007-06-20 19:26:25 +0000
commitb2609653e46abeaf447df6052c10887a6055adc9 (patch)
tree26d7f1b5529efce03ec75daad0e589566ec822da /src/timetable_cmd.cpp
parentcf0118ee63603132dc1d08d7f7e800b26e53fc97 (diff)
downloadopenttd-b2609653e46abeaf447df6052c10887a6055adc9.tar.xz
(svn r10237) -Fix (r10236): It helps if you use svn add with new files...
Diffstat (limited to 'src/timetable_cmd.cpp')
-rw-r--r--src/timetable_cmd.cpp103
1 files changed, 103 insertions, 0 deletions
diff --git a/src/timetable_cmd.cpp b/src/timetable_cmd.cpp
new file mode 100644
index 000000000..c210d9420
--- /dev/null
+++ b/src/timetable_cmd.cpp
@@ -0,0 +1,103 @@
+/* $Id$ */
+
+/** @file timetable_cmd.cpp */
+
+#include "stdafx.h"
+#include "openttd.h"
+#include "functions.h"
+#include "variables.h"
+#include "table/strings.h"
+#include "command.h"
+#include "vehicle.h"
+
+
+/**
+ * Add or remove waiting times from an order.
+ * @param tile Not used.
+ * @param flags Operation to perform.
+ * @param p1 Various bitstuffed elements
+ * - p1 = (bit 0-15) - Vehicle with the orders to change.
+ * - p1 = (bit 16-23) - Order index to modify.
+ * - p1 = (bit 24) - Whether to change the waiting time or the travelling
+ * time.
+ * @param p2 The amount of time to wait.
+ */
+CommandCost CmdChangeTimetable(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
+{
+ if (!_patches.timetabling) return CMD_ERROR;
+
+ VehicleID veh = GB(p1, 0, 16);
+ if (!IsValidVehicleID(veh)) return CMD_ERROR;
+
+ Vehicle *v = GetVehicle(veh);
+ if (!CheckOwnership(v->owner)) return CMD_ERROR;
+
+ VehicleOrderID order_number = GB(p1, 16, 8);
+ Order *order = GetVehicleOrder(v, order_number);
+ if (order == NULL) return CMD_ERROR;
+
+ bool is_journey = HASBIT(p1, 24);
+ if (!is_journey) {
+ if (order->type != OT_GOTO_STATION) return_cmd_error(STR_TIMETABLE_ONLY_WAIT_AT_STATIONS);
+ if (_patches.new_nonstop && (order->flags & OF_NON_STOP)) return_cmd_error(STR_TIMETABLE_NOT_STOPPING_HERE);
+ }
+
+ if (flags & DC_EXEC) {
+ if (is_journey) {
+ order->travel_time = p2;
+ } else {
+ order->wait_time = p2;
+ }
+
+ if (v->cur_order_index == order_number && HASBIT(v->current_order.flags, OFB_PART_OF_ORDERS)) {
+ if (is_journey) {
+ v->current_order.travel_time = p2;
+ } else {
+ v->current_order.wait_time = p2;
+ }
+ }
+
+ InvalidateWindow(WC_VEHICLE_TIMETABLE, v->index);
+ }
+
+ return CommandCost();
+}
+
+/**
+ * Clear the lateness counter to make the vehicle on time.
+ * @param tile Not used.
+ * @param flags Operation to perform.
+ * @param p1 Various bitstuffed elements
+ * - p1 = (bit 0-15) - Vehicle with the orders to change.
+ */
+CommandCost CmdSetVehicleOnTime(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
+{
+ if (!_patches.timetabling) return CMD_ERROR;
+
+ VehicleID veh = GB(p1, 0, 16);
+ if (!IsValidVehicleID(veh)) return CMD_ERROR;
+
+ Vehicle *v = GetVehicle(veh);
+ if (!CheckOwnership(v->owner)) return CMD_ERROR;
+
+ if (flags & DC_EXEC) {
+ v->lateness_counter = 0;
+ }
+
+ return CommandCost();
+}
+
+
+void UpdateVehicleTimetable(Vehicle *v, bool travelling)
+{
+ uint timetabled = travelling ? v->current_order.travel_time : v->current_order.wait_time;
+ uint time_taken = v->current_order_time;
+
+ v->current_order_time = 0;
+
+ if (!_patches.timetabling || timetabled == 0) return;
+
+ v->lateness_counter -= (timetabled - time_taken);
+
+ InvalidateWindow(WC_VEHICLE_TIMETABLE, v->index);
+}