diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ai/default/default.cpp | 6 | ||||
-rw-r--r-- | src/aircraft_gui.cpp | 2 | ||||
-rw-r--r-- | src/depot_gui.cpp | 2 | ||||
-rw-r--r-- | src/order.h | 12 | ||||
-rw-r--r-- | src/order_cmd.cpp | 30 | ||||
-rw-r--r-- | src/roadveh_gui.cpp | 2 | ||||
-rw-r--r-- | src/ship_gui.cpp | 2 | ||||
-rw-r--r-- | src/train_gui.cpp | 2 |
8 files changed, 32 insertions, 26 deletions
diff --git a/src/ai/default/default.cpp b/src/ai/default/default.cpp index 92b852e43..1d6ca0189 100644 --- a/src/ai/default/default.cpp +++ b/src/ai/default/default.cpp @@ -305,7 +305,7 @@ static void AiRestoreVehicleOrders(Vehicle *v, BackuppedOrders *bak) static void AiHandleReplaceTrain(Player *p) { const Vehicle* v = p->ai.cur_veh; - BackuppedOrders orderbak[1]; + BackuppedOrders orderbak; EngineID veh; // wait until the vehicle reaches the depot. @@ -318,13 +318,13 @@ static void AiHandleReplaceTrain(Player *p) if (veh != INVALID_ENGINE) { TileIndex tile; - BackupVehicleOrders(v, orderbak); + BackupVehicleOrders(v, &orderbak); tile = v->tile; if (CmdSucceeded(DoCommand(0, v->index, 2, DC_EXEC, CMD_SELL_RAIL_WAGON)) && CmdSucceeded(DoCommand(tile, veh, 0, DC_EXEC, CMD_BUILD_RAIL_VEHICLE))) { VehicleID veh = _new_vehicle_id; - AiRestoreVehicleOrders(GetVehicle(veh), orderbak); + AiRestoreVehicleOrders(GetVehicle(veh), &orderbak); DoCommand(0, veh, 0, DC_EXEC, CMD_START_STOP_TRAIN); DoCommand(0, veh, _ai_service_interval, DC_EXEC, CMD_CHANGE_SERVICE_INT); diff --git a/src/aircraft_gui.cpp b/src/aircraft_gui.cpp index fc94df771..218ace608 100644 --- a/src/aircraft_gui.cpp +++ b/src/aircraft_gui.cpp @@ -95,7 +95,7 @@ void CcBuildAircraft(bool success, TileIndex tile, uint32 p1, uint32 p2) if (v->tile == _backup_orders_tile) { _backup_orders_tile = 0; - RestoreVehicleOrders(v, _backup_orders_data); + RestoreVehicleOrders(v); } ShowVehicleViewWindow(v); } diff --git a/src/depot_gui.cpp b/src/depot_gui.cpp index 9c0e87da1..f89e56400 100644 --- a/src/depot_gui.cpp +++ b/src/depot_gui.cpp @@ -928,7 +928,7 @@ static void DepotWndProc(Window *w, WindowEvent *e) if (is_engine) { _backup_orders_tile = v->tile; - BackupVehicleOrders(v, _backup_orders_data); + BackupVehicleOrders(v); } switch (v->type) { diff --git a/src/order.h b/src/order.h index a9ccf383e..2887972ec 100644 --- a/src/order.h +++ b/src/order.h @@ -116,18 +116,18 @@ struct Order : PoolItem<Order, OrderID, &_Order_pool> { void FreeChain(); }; -#define MAX_BACKUP_ORDER_COUNT 40 - struct BackuppedOrders { + BackuppedOrders() : order(NULL) { } + VehicleID clone; VehicleOrderID orderindex; - Order order[MAX_BACKUP_ORDER_COUNT + 1]; + Order *order; uint16 service_interval; char name[32]; }; VARDEF TileIndex _backup_orders_tile; -VARDEF BackuppedOrders _backup_orders_data[1]; +VARDEF BackuppedOrders _backup_orders_data; static inline VehicleOrderID GetMaxOrderIndex() { @@ -200,8 +200,8 @@ static inline Order UnpackOrder(uint32 packed) } /* Functions */ -void BackupVehicleOrders(const Vehicle *v, BackuppedOrders *order); -void RestoreVehicleOrders(const Vehicle* v, const BackuppedOrders* order); +void BackupVehicleOrders(const Vehicle *v, BackuppedOrders *order = &_backup_orders_data); +void RestoreVehicleOrders(const Vehicle *v, const BackuppedOrders *order = &_backup_orders_data); void RemoveOrderFromAllVehicles(OrderType type, DestinationID destination); void InvalidateVehicleOrder(const Vehicle *v); bool VehicleHasDepotOrders(const Vehicle *v); diff --git a/src/order_cmd.cpp b/src/order_cmd.cpp index 9067c3e99..d8c570540 100644 --- a/src/order_cmd.cpp +++ b/src/order_cmd.cpp @@ -317,10 +317,6 @@ CommandCost CmdInsertOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) if (!HasOrderPoolFree(1)) return_cmd_error(STR_8831_NO_MORE_SPACE_FOR_ORDERS); - /* XXX - This limit is only here because the backuppedorders can't - * handle any more then this.. */ - if (v->num_orders >= MAX_BACKUP_ORDER_COUNT) return_cmd_error(STR_8832_TOO_MANY_ORDERS); - if (v->type == VEH_SHIP && IsHumanPlayer(v->owner) && !_patches.new_pathfinding_all) { @@ -920,6 +916,10 @@ CommandCost CmdOrderRefit(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) */ void BackupVehicleOrders(const Vehicle *v, BackuppedOrders *bak) { + /* Make sure we always have freed the stuff */ + free(bak->order); + bak->order = NULL; + /* Save general info */ bak->orderindex = v->cur_order_index; bak->service_interval = v->service_interval; @@ -939,13 +939,21 @@ void BackupVehicleOrders(const Vehicle *v, BackuppedOrders *bak) bak->clone = u->index; } else { /* Else copy the orders */ - Order *order, *dest; - - dest = bak->order; /* We do not have shared orders */ bak->clone = INVALID_VEHICLE; + + /* Count the number of orders */ + uint cnt = 0; + const Order *order; + FOR_VEHICLE_ORDERS(v, order) cnt++; + + /* Allocate memory for the orders plus an end-of-orders marker */ + bak->order = MallocT<Order>(cnt + 1); + + Order *dest = bak->order; + /* Copy the orders */ FOR_VEHICLE_ORDERS(v, order) { *dest = *order; @@ -961,12 +969,10 @@ void BackupVehicleOrders(const Vehicle *v, BackuppedOrders *bak) * Restore vehicle orders that are backupped via BackupVehicleOrders * */ -void RestoreVehicleOrders(const Vehicle* v, const BackuppedOrders* bak) +void RestoreVehicleOrders(const Vehicle *v, const BackuppedOrders *bak) { - uint i; - /* If we have a custom name, process that */ - if (bak->name[0] != 0) { + if (!StrEmpty(bak->name)) { _cmd_text = bak->name; DoCommandP(0, v->index, 0, NULL, CMD_NAME_VEHICLE); } @@ -981,7 +987,7 @@ void RestoreVehicleOrders(const Vehicle* v, const BackuppedOrders* bak) * order number is one more than the current amount of orders, and because * in network the commands are queued before send, the second insert always * fails in test mode. By bypassing the test-mode, that no longer is a problem. */ - for (i = 0; bak->order[i].IsValid(); i++) { + 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)) break; } diff --git a/src/roadveh_gui.cpp b/src/roadveh_gui.cpp index ae5bfd255..cf472d054 100644 --- a/src/roadveh_gui.cpp +++ b/src/roadveh_gui.cpp @@ -128,7 +128,7 @@ void CcBuildRoadVeh(bool success, TileIndex tile, uint32 p1, uint32 p2) v = GetVehicle(_new_vehicle_id); if (v->tile == _backup_orders_tile) { _backup_orders_tile = 0; - RestoreVehicleOrders(v, _backup_orders_data); + RestoreVehicleOrders(v); } ShowVehicleViewWindow(v); } diff --git a/src/ship_gui.cpp b/src/ship_gui.cpp index 1e885de86..e08ea3948 100644 --- a/src/ship_gui.cpp +++ b/src/ship_gui.cpp @@ -35,7 +35,7 @@ void CcBuildShip(bool success, TileIndex tile, uint32 p1, uint32 p2) v = GetVehicle(_new_vehicle_id); if (v->tile == _backup_orders_tile) { _backup_orders_tile = 0; - RestoreVehicleOrders(v, _backup_orders_data); + RestoreVehicleOrders(v); } ShowVehicleViewWindow(v); } diff --git a/src/train_gui.cpp b/src/train_gui.cpp index 78672613c..dce7e5e87 100644 --- a/src/train_gui.cpp +++ b/src/train_gui.cpp @@ -54,7 +54,7 @@ void CcBuildLoco(bool success, TileIndex tile, uint32 p1, uint32 p2) v = GetVehicle(_new_vehicle_id); if (tile == _backup_orders_tile) { _backup_orders_tile = 0; - RestoreVehicleOrders(v, _backup_orders_data); + RestoreVehicleOrders(v); } ShowVehicleViewWindow(v); } |