summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorglx <glx@openttd.org>2008-02-27 21:46:57 +0000
committerglx <glx@openttd.org>2008-02-27 21:46:57 +0000
commit19b0f752265c4525784ff89d506fd228f614e0b7 (patch)
treed50859c17e044259f64f82a82eb4e823029d060c /src
parent6c4060a59a93e79b1fda36ad71aad61cef432142 (diff)
downloadopenttd-19b0f752265c4525784ff89d506fd228f614e0b7.tar.xz
(svn r12296) -Fix [FS#1549]: restore timetable from backupped orders and add group ID to the backup
Diffstat (limited to 'src')
-rw-r--r--src/group_cmd.cpp3
-rw-r--r--src/order.h1
-rw-r--r--src/order_cmd.cpp14
-rw-r--r--src/timetable_cmd.cpp10
4 files changed, 25 insertions, 3 deletions
diff --git a/src/group_cmd.cpp b/src/group_cmd.cpp
index c1698bbe4..84aa0b39e 100644
--- a/src/group_cmd.cpp
+++ b/src/group_cmd.cpp
@@ -134,6 +134,9 @@ CommandCost CmdDeleteGroup(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
if (v->group_id == g->index && v->type == g->vehicle_type) v->group_id = DEFAULT_GROUP;
}
+ /* Update backupped orders if needed */
+ if (_backup_orders_data.group == g->index) _backup_orders_data.group = DEFAULT_GROUP;
+
/* If we set an autoreplace for the group we delete, remove it. */
if (_current_player < MAX_PLAYERS) {
Player *p;
diff --git a/src/order.h b/src/order.h
index 350d8c563..d1442e605 100644
--- a/src/order.h
+++ b/src/order.h
@@ -126,6 +126,7 @@ struct BackuppedOrders {
VehicleID clone;
VehicleOrderID orderindex;
+ GroupID group;
Order *order;
uint16 service_interval;
char *name;
diff --git a/src/order_cmd.cpp b/src/order_cmd.cpp
index dbc1dac79..b83c1c93d 100644
--- a/src/order_cmd.cpp
+++ b/src/order_cmd.cpp
@@ -933,6 +933,7 @@ void BackupVehicleOrders(const Vehicle *v, BackuppedOrders *bak)
/* Save general info */
bak->orderindex = v->cur_order_index;
+ bak->group = v->group_id;
bak->service_interval = v->service_interval;
if (v->name != NULL) bak->name = strdup(v->name);
@@ -992,13 +993,24 @@ void RestoreVehicleOrders(const Vehicle *v, const BackuppedOrders *bak)
* fails in test mode. By bypassing the test-mode, that no longer is a problem. */
for (uint i = 0; bak->order[i].IsValid(); i++) {
if (!DoCommandP(0, v->index + (i << 16), PackOrder(&bak->order[i]), NULL,
- CMD_INSERT_ORDER | CMD_NO_TEST_IF_IN_NETWORK))
+ CMD_INSERT_ORDER | CMD_NO_TEST_IF_IN_NETWORK)) {
break;
+ }
+
+ /* Copy timetable */
+ if (!DoCommandP(0, v->index | (i << 16) | (1 << 25),
+ bak->order[i].wait_time << 16 | bak->order[i].travel_time, NULL,
+ CMD_CHANGE_TIMETABLE | CMD_NO_TEST_IF_IN_NETWORK)) {
+ break;
+ }
}
}
/* Restore vehicle order-index and service interval */
DoCommandP(0, v->index, bak->orderindex | (bak->service_interval << 16) , NULL, CMD_RESTORE_ORDER_INDEX);
+
+ /* Restore vehicle group */
+ DoCommandP(0, bak->group, v->index, NULL, CMD_ADD_VEHICLE_GROUP);
}
/** Restore the current order-index of a vehicle and sets service-interval.
diff --git a/src/timetable_cmd.cpp b/src/timetable_cmd.cpp
index 720635498..9d2769a32 100644
--- a/src/timetable_cmd.cpp
+++ b/src/timetable_cmd.cpp
@@ -46,7 +46,11 @@ static void ChangeTimetable(Vehicle *v, VehicleOrderID order_number, uint16 time
* - p1 = (bit 16-23) - Order index to modify.
* - p1 = (bit 24) - Whether to change the waiting time or the travelling
* time.
+ * - p1 = (bit 25) - Whether p2 contains waiting and travelling time.
* @param p2 The amount of time to wait.
+ * - p2 = (bit 0-15) - Waiting or travelling time as specified by p1 bit 24 if p1 bit 25 is not set,
+ * Travelling time if p1 bit 25 is set.
+ * - p2 = (bit 16-31) - Waiting time if p1 bit 25 is set
*/
CommandCost CmdChangeTimetable(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
{
@@ -62,14 +66,16 @@ CommandCost CmdChangeTimetable(TileIndex tile, uint32 flags, uint32 p1, uint32 p
Order *order = GetVehicleOrder(v, order_number);
if (order == NULL) return CMD_ERROR;
- bool is_journey = HasBit(p1, 24);
+ bool packed_time = HasBit(p1, 25);
+ bool is_journey = HasBit(p1, 24) || packed_time;
if (!is_journey) {
if (order->type != OT_GOTO_STATION) return_cmd_error(STR_TIMETABLE_ONLY_WAIT_AT_STATIONS);
if (_patches.new_nonstop && (order->flags & OFB_NON_STOP)) return_cmd_error(STR_TIMETABLE_NOT_STOPPING_HERE);
}
if (flags & DC_EXEC) {
- ChangeTimetable(v, order_number, p2, is_journey);
+ ChangeTimetable(v, order_number, GB(p2, 0, 16), is_journey);
+ if (packed_time) ChangeTimetable(v, order_number, GB(p2, 16, 16), false);
}
return CommandCost();