summaryrefslogtreecommitdiff
path: root/src/vehicle_cmd.cpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2010-08-18 20:48:38 +0000
committerrubidium <rubidium@openttd.org>2010-08-18 20:48:38 +0000
commit926594b599e76886fd877e953036918687418b0c (patch)
treedb13aaa32a38c15aa14f64f4d01a0962889f9c0e /src/vehicle_cmd.cpp
parent04d6648c5efd89a32669a17d6ad2711c719820d9 (diff)
downloadopenttd-926594b599e76886fd877e953036918687418b0c.tar.xz
(svn r20547) -Change: the way order backups are performed. Now restoring an order doesn't require up to 765 commands.
Diffstat (limited to 'src/vehicle_cmd.cpp')
-rw-r--r--src/vehicle_cmd.cpp21
1 files changed, 18 insertions, 3 deletions
diff --git a/src/vehicle_cmd.cpp b/src/vehicle_cmd.cpp
index 0a2c255f6..45b6e3674 100644
--- a/src/vehicle_cmd.cpp
+++ b/src/vehicle_cmd.cpp
@@ -32,6 +32,7 @@
#include "articulated_vehicles.h"
#include "autoreplace_gui.h"
#include "company_base.h"
+#include "order_backup.h"
#include "table/strings.h"
@@ -144,12 +145,14 @@ CommandCost CmdBuildVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
}
Company::Get(_current_company)->num_engines[eid]++;
+
+ if (v->IsPrimaryVehicle()) OrderBackup::Restore(v, p2);
}
return value;
}
-CommandCost CmdSellRailWagon(DoCommandFlag flags, Vehicle *v, uint16 data);
+CommandCost CmdSellRailWagon(DoCommandFlag flags, Vehicle *v, uint16 data, uint32 user);
/**
* Sell a vehicle.
@@ -157,7 +160,8 @@ CommandCost CmdSellRailWagon(DoCommandFlag flags, Vehicle *v, uint16 data);
* @param flags for command.
* @param p1 various bitstuffed data.
* bits 0-15: vehicle ID being sold.
- * bits 16-31: vehicle type specific bits passed on to the vehicle build functions.
+ * bits 16-30: vehicle type specific bits passed on to the vehicle build functions.
+ * bit 31: make a backup of the vehicle's order (if an engine).
* @param p2 unused.
* @param text unused.
* @return the cost of this operation or an error.
@@ -176,12 +180,23 @@ CommandCost CmdSellVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
if (!front->IsStoppedInDepot()) return_cmd_error(STR_ERROR_TRAIN_MUST_BE_STOPPED_INSIDE_DEPOT + front->type);
+ /* Can we actually make the order backup, i.e. are there enough orders? */
+ if (p1 & MAKE_ORDER_BACKUP_FLAG &&
+ front->orders.list != NULL &&
+ !front->orders.list->IsShared() &&
+ !Order::CanAllocateItem(front->orders.list->GetNumOrders())) {
+ /* Only happens in exceptional cases when there aren't enough orders anyhow.
+ * Thus it should be safe to just drop the orders in that case. */
+ p1 &= ~MAKE_ORDER_BACKUP_FLAG;
+ }
+
if (v->type == VEH_TRAIN) {
- ret = CmdSellRailWagon(flags, v, GB(p1, 16, 16));
+ ret = CmdSellRailWagon(flags, v, GB(p1, 16, 16), p2);
} else {
ret = CommandCost(EXPENSES_NEW_VEHICLES, -front->value);
if (flags & DC_EXEC) {
+ if (v->IsPrimaryVehicle() && p1 & MAKE_ORDER_BACKUP_FLAG) OrderBackup::Backup(v, p2);
delete front;
}
}