summaryrefslogtreecommitdiff
path: root/src/order_cmd.cpp
diff options
context:
space:
mode:
authorbjarni <bjarni@openttd.org>2008-04-27 20:09:29 +0000
committerbjarni <bjarni@openttd.org>2008-04-27 20:09:29 +0000
commit783e20a263a5e72bfed81ef7a9535a2caefebf79 (patch)
treeefbff2346a07d27ade486566153b76347444eb3f /src/order_cmd.cpp
parentd6c971fd9b3777bcd0fa41ecaefb52ab2567bc89 (diff)
downloadopenttd-783e20a263a5e72bfed81ef7a9535a2caefebf79.tar.xz
(svn r12913) -Add: ability to backup and restore a player's economic data and data for a vehicle (or chain of vehicles)
Autoreplace uses this with the following benefits: -Mass autoreplace (the button in the depot window) will now estimate costs correctly -Autoreplace now either replaces correctly or manages to keep the original vehicle (no more broken trains) Thanks to Ammler for testing this
Diffstat (limited to 'src/order_cmd.cpp')
-rw-r--r--src/order_cmd.cpp38
1 files changed, 37 insertions, 1 deletions
diff --git a/src/order_cmd.cpp b/src/order_cmd.cpp
index 59fb9a01f..f9f849a01 100644
--- a/src/order_cmd.cpp
+++ b/src/order_cmd.cpp
@@ -1233,7 +1233,7 @@ void BackupVehicleOrders(const Vehicle *v, BackuppedOrders *bak)
/* Copy the orders */
FOR_VEHICLE_ORDERS(v, order) {
- *dest = *order;
+ memcpy(dest, order, sizeof(Order));
dest++;
}
/* End the list with an empty order */
@@ -1285,6 +1285,42 @@ void RestoreVehicleOrders(const Vehicle *v, const BackuppedOrders *bak)
DoCommandP(0, bak->group, v->index, NULL, CMD_ADD_VEHICLE_GROUP);
}
+/** Restores vehicle orders that was previously backed up by BackupVehicleOrders()
+ * This will restore to the point where it was at the time of the backup meaning
+ * it will presume the same order indexes can be used.
+ * This is needed when restoring a backed up vehicle
+ * @param v The vehicle that should gain the orders
+ * @param bak the backup of the orders
+ */
+void RestoreVehicleOrdersBruteForce(Vehicle *v, const BackuppedOrders *bak)
+{
+ if (bak->name != NULL) {
+ /* Restore the name. */
+ v->name = strdup(bak->name);
+ }
+
+ /* If we had shared orders, recover that */
+ if (bak->clone != INVALID_VEHICLE) {
+ /* We will place it at the same location in the linked list as it previously was. */
+ if (v->prev_shared != NULL) {
+ assert(v->prev_shared->next_shared == v->next_shared);
+ v->prev_shared->next_shared = v;
+ }
+ if (v->next_shared != NULL) {
+ assert(v->next_shared->prev_shared == v->prev_shared);
+ v->next_shared->prev_shared = v;
+ }
+ } else {
+ /* Restore the orders at the indexes they originally were. */
+ for (Order *order = bak->order; order->IsValid(); order++) {
+ Order *dst = GetOrder(order->index);
+ /* Since we are restoring something we removed a moment ago all the orders should be free. */
+ assert(!dst->IsValid());
+ memcpy(dst, order, sizeof(Order));
+ }
+ }
+}
+
/** Restore the current order-index of a vehicle and sets service-interval.
* @param tile unused
* @param flags operation to perform