2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "stdafx.h"
|
2005-06-02 19:30:21 +00:00
|
|
|
#include "openttd.h"
|
2005-04-22 05:41:09 +00:00
|
|
|
#include "airport.h"
|
|
|
|
#include "depot.h"
|
2005-07-22 07:02:20 +00:00
|
|
|
#include "functions.h"
|
2004-11-25 10:47:30 +00:00
|
|
|
#include "table/strings.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "vehicle.h"
|
2005-04-22 05:41:09 +00:00
|
|
|
#include "waypoint.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "command.h"
|
|
|
|
#include "station.h"
|
|
|
|
#include "player.h"
|
2004-08-11 10:15:38 +00:00
|
|
|
#include "news.h"
|
2005-01-15 19:06:22 +00:00
|
|
|
#include "saveload.h"
|
2005-05-02 23:59:11 +00:00
|
|
|
#include "vehicle_gui.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-02-06 10:24:57 +00:00
|
|
|
enum {
|
|
|
|
/* Max orders: 64000 (64 * 1000) */
|
|
|
|
ORDER_POOL_BLOCK_SIZE_BITS = 6, /* In bits, so (1 << 6) == 64 */
|
|
|
|
ORDER_POOL_MAX_BLOCKS = 1000,
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called if a new block is added to the order-pool
|
|
|
|
*/
|
|
|
|
static void OrderPoolNewBlock(uint start_item)
|
|
|
|
{
|
|
|
|
Order *order;
|
|
|
|
|
|
|
|
FOR_ALL_ORDERS_FROM(order, start_item)
|
|
|
|
order->index = start_item++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize the order-pool */
|
|
|
|
MemoryPool _order_pool = { "Orders", ORDER_POOL_MAX_BLOCKS, ORDER_POOL_BLOCK_SIZE_BITS, sizeof(Order), &OrderPoolNewBlock, 0, 0, NULL };
|
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Unpacks a order from savegames made with TTD(Patch)
|
|
|
|
*
|
2004-08-09 17:04:08 +00:00
|
|
|
*/
|
2005-01-15 19:06:22 +00:00
|
|
|
Order UnpackOldOrder(uint16 packed)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-01-15 19:06:22 +00:00
|
|
|
Order order;
|
2005-07-20 15:29:28 +00:00
|
|
|
order.type = GB(packed, 0, 4);
|
|
|
|
order.flags = GB(packed, 4, 4);
|
|
|
|
order.station = GB(packed, 8, 8);
|
2005-01-15 19:06:22 +00:00
|
|
|
order.next = NULL;
|
|
|
|
|
|
|
|
// Sanity check
|
|
|
|
// TTD stores invalid orders as OT_NOTHING with non-zero flags/station
|
|
|
|
if (order.type == OT_NOTHING && (order.flags != 0 || order.station != 0)) {
|
|
|
|
order.type = OT_DUMMY;
|
|
|
|
order.flags = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return order;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Unpacks a order from savegames with version 4 and lower
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
Order UnpackVersion4Order(uint16 packed)
|
|
|
|
{
|
|
|
|
Order order;
|
2005-07-20 15:29:28 +00:00
|
|
|
order.type = GB(packed, 0, 4);
|
|
|
|
order.flags = GB(packed, 4, 4);
|
|
|
|
order.station = GB(packed, 8, 8);
|
2005-01-15 19:06:22 +00:00
|
|
|
order.next = NULL;
|
2005-06-01 11:52:44 +00:00
|
|
|
order.index = 0; // avoid compiler warning
|
2005-01-15 19:06:22 +00:00
|
|
|
return order;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Updates the widgets of a vehicle which contains the order-data
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void InvalidateVehicleOrder(const Vehicle *v)
|
|
|
|
{
|
|
|
|
InvalidateWindow(WC_VEHICLE_VIEW, v->index);
|
|
|
|
InvalidateWindow(WC_VEHICLE_ORDERS, v->index);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Swap two orders
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static void SwapOrders(Order *order1, Order *order2)
|
|
|
|
{
|
|
|
|
Order temp_order;
|
|
|
|
|
|
|
|
temp_order = *order1;
|
2005-01-16 14:42:53 +00:00
|
|
|
AssignOrder(order1, *order2);
|
|
|
|
order1->next = order2->next;
|
|
|
|
AssignOrder(order2, temp_order);
|
|
|
|
order2->next = temp_order.next;
|
2005-01-15 19:06:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Allocate a new order
|
|
|
|
*
|
|
|
|
* @return Order* if a free space is found, else NULL.
|
|
|
|
*
|
|
|
|
*/
|
2005-01-22 20:23:18 +00:00
|
|
|
static Order *AllocateOrder(void)
|
2005-01-15 19:06:22 +00:00
|
|
|
{
|
|
|
|
Order *order;
|
|
|
|
|
|
|
|
FOR_ALL_ORDERS(order) {
|
|
|
|
if (order->type == OT_NOTHING) {
|
|
|
|
uint index = order->index;
|
2005-02-06 10:24:57 +00:00
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
memset(order, 0, sizeof(Order));
|
|
|
|
order->index = index;
|
2005-01-23 13:30:02 +00:00
|
|
|
order->next = NULL;
|
2005-02-06 10:24:57 +00:00
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
return order;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-02-06 10:24:57 +00:00
|
|
|
/* Check if we can add a block to the pool */
|
|
|
|
if (AddBlockToPool(&_order_pool))
|
|
|
|
return AllocateOrder();
|
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Assign data to an order (from an other order)
|
|
|
|
* This function makes sure that the index is maintained correctly
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void AssignOrder(Order *order, Order data)
|
|
|
|
{
|
|
|
|
order->type = data.type;
|
|
|
|
order->flags = data.flags;
|
|
|
|
order->station = data.station;
|
|
|
|
}
|
|
|
|
|
2005-05-11 00:00:27 +00:00
|
|
|
/** Add an order to the orderlist of a vehicle.
|
|
|
|
* @param x,y unused
|
|
|
|
* @param p1 various bitstuffed elements
|
2005-07-20 15:29:28 +00:00
|
|
|
* - p1 = (bit 0 - 15) - ID of the vehicle
|
2005-05-11 00:00:27 +00:00
|
|
|
* - p1 = (bit 16 - 31) - the selected order (if any). If the last order is given,
|
2005-07-20 15:29:28 +00:00
|
|
|
* the order will be inserted before that one
|
|
|
|
* only the first 8 bits used currently (bit 16 - 23) (max 255)
|
2005-05-11 00:00:27 +00:00
|
|
|
* @param p2 packed order to insert
|
2005-01-15 19:06:22 +00:00
|
|
|
*/
|
2005-05-11 00:00:27 +00:00
|
|
|
int32 CmdInsertOrder(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
2005-01-15 19:06:22 +00:00
|
|
|
{
|
2005-04-22 05:41:09 +00:00
|
|
|
Vehicle *v;
|
2005-07-20 15:29:28 +00:00
|
|
|
VehicleID veh = GB(p1, 0, 16);
|
|
|
|
OrderID sel_ord = GB(p1, 16, 16);
|
2005-05-11 00:00:27 +00:00
|
|
|
Order new_order = UnpackOrder(p2);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-05-11 00:00:27 +00:00
|
|
|
if (!IsVehicleIndex(veh)) return CMD_ERROR;
|
|
|
|
v = GetVehicle(veh);
|
2005-04-22 05:41:09 +00:00
|
|
|
if (v->type == 0 || !CheckOwnership(v->owner)) return CMD_ERROR;
|
|
|
|
|
2005-05-11 00:00:27 +00:00
|
|
|
/* Check if the inserted order is to the correct destination (owner, type),
|
|
|
|
* and has the correct flags if any */
|
2005-04-22 05:41:09 +00:00
|
|
|
switch (new_order.type) {
|
|
|
|
case OT_GOTO_STATION: {
|
2005-05-11 00:00:27 +00:00
|
|
|
const Station *st;
|
2005-04-22 05:41:09 +00:00
|
|
|
|
|
|
|
if (!IsStationIndex(new_order.station)) return CMD_ERROR;
|
|
|
|
st = GetStation(new_order.station);
|
|
|
|
|
|
|
|
if (!IsValidStation(st) ||
|
2005-05-02 22:13:20 +00:00
|
|
|
(st->airport_type != AT_OILRIG && !(IsBuoy(st)) && !CheckOwnership(st->owner))) {
|
2005-04-22 05:41:09 +00:00
|
|
|
return CMD_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (v->type) {
|
|
|
|
case VEH_Train:
|
|
|
|
if (!(st->facilities & FACIL_TRAIN)) return CMD_ERROR;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VEH_Road:
|
|
|
|
if (v->cargo_type == CT_PASSENGERS) {
|
|
|
|
if (!(st->facilities & FACIL_BUS_STOP)) return CMD_ERROR;
|
|
|
|
} else {
|
|
|
|
if (!(st->facilities & FACIL_TRUCK_STOP)) return CMD_ERROR;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VEH_Ship:
|
|
|
|
if (!(st->facilities & FACIL_DOCK)) return CMD_ERROR;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VEH_Aircraft:
|
|
|
|
if (!(st->facilities & FACIL_AIRPORT)) return CMD_ERROR;
|
|
|
|
break;
|
|
|
|
|
2005-05-11 00:00:27 +00:00
|
|
|
default: return CMD_ERROR;
|
2005-04-22 05:41:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (new_order.flags) {
|
|
|
|
case 0:
|
|
|
|
case OF_FULL_LOAD:
|
|
|
|
case OF_UNLOAD:
|
|
|
|
case OF_NON_STOP:
|
|
|
|
case OF_NON_STOP | OF_FULL_LOAD:
|
|
|
|
case OF_NON_STOP | OF_UNLOAD:
|
|
|
|
break;
|
|
|
|
|
2005-05-11 00:00:27 +00:00
|
|
|
default: return CMD_ERROR;
|
2005-04-22 05:41:09 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case OT_GOTO_DEPOT: {
|
|
|
|
if (v->type == VEH_Aircraft) {
|
|
|
|
const Station* st;
|
|
|
|
|
|
|
|
if (!IsStationIndex(new_order.station)) return CMD_ERROR;
|
|
|
|
st = GetStation(new_order.station);
|
|
|
|
|
|
|
|
if (!IsValidStation(st) ||
|
|
|
|
(st->airport_type != AT_OILRIG && !CheckOwnership(st->owner)) ||
|
|
|
|
!(st->facilities & FACIL_AIRPORT) ||
|
|
|
|
GetAirport(st->airport_type)->nof_depots == 0) {
|
|
|
|
return CMD_ERROR;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
const Depot* dp;
|
|
|
|
|
|
|
|
if (!IsDepotIndex(new_order.station)) return CMD_ERROR;
|
|
|
|
dp = GetDepot(new_order.station);
|
|
|
|
|
|
|
|
if (!IsValidDepot(dp) ||
|
|
|
|
!CheckOwnership(GetTileOwner(dp->xy))) {
|
|
|
|
return CMD_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (v->type) {
|
|
|
|
case VEH_Train:
|
|
|
|
if (!IsTileDepotType(dp->xy, TRANSPORT_RAIL)) return CMD_ERROR;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VEH_Road:
|
|
|
|
if (!IsTileDepotType(dp->xy, TRANSPORT_ROAD)) return CMD_ERROR;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VEH_Ship:
|
|
|
|
if (!IsTileDepotType(dp->xy, TRANSPORT_WATER)) return CMD_ERROR;
|
|
|
|
break;
|
|
|
|
|
2005-05-11 00:00:27 +00:00
|
|
|
default: return CMD_ERROR;
|
2005-04-22 05:41:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (new_order.flags) {
|
|
|
|
case OF_PART_OF_ORDERS:
|
|
|
|
case OF_PART_OF_ORDERS | OF_HALT_IN_DEPOT:
|
|
|
|
case OF_NON_STOP | OF_PART_OF_ORDERS:
|
|
|
|
case OF_NON_STOP | OF_PART_OF_ORDERS | OF_HALT_IN_DEPOT:
|
|
|
|
break;
|
|
|
|
|
2005-05-11 00:00:27 +00:00
|
|
|
default: return CMD_ERROR;
|
2005-04-22 05:41:09 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case OT_GOTO_WAYPOINT: {
|
|
|
|
const Waypoint* wp;
|
|
|
|
|
|
|
|
if (v->type != VEH_Train) return CMD_ERROR;
|
|
|
|
|
|
|
|
if (!IsWaypointIndex(new_order.station)) return CMD_ERROR;
|
|
|
|
wp = GetWaypoint(new_order.station);
|
|
|
|
|
|
|
|
if (!CheckOwnership(GetTileOwner(wp->xy))) return CMD_ERROR;
|
|
|
|
|
|
|
|
switch (new_order.flags) {
|
|
|
|
case 0:
|
|
|
|
case OF_NON_STOP:
|
|
|
|
break;
|
|
|
|
|
2005-05-11 00:00:27 +00:00
|
|
|
default: return CMD_ERROR;
|
2005-04-22 05:41:09 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-05-11 00:00:27 +00:00
|
|
|
default: return CMD_ERROR;
|
2005-04-22 05:41:09 +00:00
|
|
|
}
|
|
|
|
|
2005-05-11 00:00:27 +00:00
|
|
|
if (sel_ord > v->num_orders) return CMD_ERROR;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-05-11 00:00:27 +00:00
|
|
|
if (IsOrderPoolFull()) return_cmd_error(STR_8831_NO_MORE_SPACE_FOR_ORDERS);
|
2005-01-15 19:06:22 +00:00
|
|
|
|
|
|
|
/* XXX - This limit is only here because the backuppedorders can't
|
2005-05-11 00:00:27 +00:00
|
|
|
* handle any more then this.. */
|
|
|
|
if (v->num_orders >= 40) return_cmd_error(STR_8832_TOO_MANY_ORDERS);
|
2005-01-15 19:06:22 +00:00
|
|
|
|
2005-01-31 11:23:10 +00:00
|
|
|
/* For ships, make sure that the station is not too far away from the
|
|
|
|
* previous destination, for human players with new pathfinding disabled */
|
2004-08-09 17:04:08 +00:00
|
|
|
if (v->type == VEH_Ship && IS_HUMAN_PLAYER(v->owner) &&
|
2005-05-11 00:00:27 +00:00
|
|
|
sel_ord != 0 && GetVehicleOrder(v, sel_ord - 1)->type == OT_GOTO_STATION
|
2005-01-31 11:23:10 +00:00
|
|
|
&& !_patches.new_pathfinding_all) {
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2005-01-31 07:23:15 +00:00
|
|
|
int dist = DistanceManhattan(
|
2005-05-11 00:00:27 +00:00
|
|
|
GetStation(GetVehicleOrder(v, sel_ord - 1)->station)->xy,
|
2005-04-22 05:41:09 +00:00
|
|
|
GetStation(new_order.station)->xy // XXX type != OT_GOTO_STATION?
|
2004-12-05 12:43:04 +00:00
|
|
|
);
|
2004-08-09 17:04:08 +00:00
|
|
|
if (dist >= 130)
|
|
|
|
return_cmd_error(STR_0210_TOO_FAR_FROM_PREVIOUS_DESTINATIO);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
|
|
|
Vehicle *u;
|
2005-05-11 00:00:27 +00:00
|
|
|
Order *new = AllocateOrder();
|
2005-01-15 19:06:22 +00:00
|
|
|
AssignOrder(new, new_order);
|
|
|
|
|
|
|
|
/* Create new order and link in list */
|
|
|
|
if (v->orders == NULL) {
|
|
|
|
v->orders = new;
|
|
|
|
} else {
|
|
|
|
/* Try to get the previous item (we are inserting above the
|
|
|
|
selected) */
|
2005-05-11 00:00:27 +00:00
|
|
|
Order *order = GetVehicleOrder(v, sel_ord - 1);
|
2005-01-15 19:06:22 +00:00
|
|
|
|
2005-05-11 00:00:27 +00:00
|
|
|
if (order == NULL && GetVehicleOrder(v, sel_ord) != NULL) {
|
2005-01-15 19:06:22 +00:00
|
|
|
/* There is no previous item, so we are altering v->orders itself
|
|
|
|
But because the orders can be shared, we copy the info over
|
|
|
|
the v->orders, so we don't have to change the pointers of
|
|
|
|
all vehicles */
|
|
|
|
SwapOrders(v->orders, new);
|
|
|
|
/* Now update the next pointers */
|
|
|
|
v->orders->next = new;
|
|
|
|
} else if (order == NULL) {
|
|
|
|
/* 'sel' is a non-existing order, add him to the end */
|
|
|
|
order = GetLastVehicleOrder(v);
|
|
|
|
order->next = new;
|
|
|
|
} else {
|
|
|
|
/* Put the new order in between */
|
|
|
|
new->next = order->next;
|
|
|
|
order->next = new;
|
|
|
|
}
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
u = GetFirstVehicleFromSharedList(v);
|
|
|
|
while (u != NULL) {
|
|
|
|
/* Increase amount of orders */
|
|
|
|
u->num_orders++;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
/* If the orderlist was empty, assign it */
|
2005-05-11 00:00:27 +00:00
|
|
|
if (u->orders == NULL) u->orders = v->orders;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
assert(v->orders == u->orders);
|
|
|
|
|
|
|
|
/* If there is added an order before the current one, we need
|
|
|
|
to update the selected order */
|
2005-05-11 00:00:27 +00:00
|
|
|
if (sel_ord <= u->cur_order_index) {
|
2005-01-15 19:06:22 +00:00
|
|
|
uint cur = u->cur_order_index + 1;
|
|
|
|
/* Check if we don't go out of bound */
|
|
|
|
if (cur < u->num_orders)
|
|
|
|
u->cur_order_index = cur;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2005-01-15 19:06:22 +00:00
|
|
|
/* Update any possible open window of the vehicle */
|
|
|
|
InvalidateVehicleOrder(u);
|
|
|
|
|
|
|
|
u = u->next_shared;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2004-12-10 18:16:08 +00:00
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
/* Make sure to rebuild the whole list */
|
2004-12-10 18:16:08 +00:00
|
|
|
RebuildVehicleLists();
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-05-11 00:00:27 +00:00
|
|
|
/** Declone an order-list
|
|
|
|
* @param *dst delete the orders of this vehicle
|
|
|
|
* @param flags execution flags
|
2005-01-15 19:06:22 +00:00
|
|
|
*/
|
2004-08-09 17:04:08 +00:00
|
|
|
static int32 DecloneOrder(Vehicle *dst, uint32 flags)
|
|
|
|
{
|
|
|
|
if (flags & DC_EXEC) {
|
2005-01-15 19:06:22 +00:00
|
|
|
/* Delete orders from vehicle */
|
|
|
|
DeleteVehicleOrders(dst);
|
2004-12-10 18:16:08 +00:00
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
InvalidateVehicleOrder(dst);
|
2004-12-10 18:16:08 +00:00
|
|
|
RebuildVehicleLists();
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-05-11 00:00:27 +00:00
|
|
|
/** Delete an order from the orderlist of a vehicle.
|
|
|
|
* @param x,y unused
|
|
|
|
* @param p1 the ID of the vehicle
|
|
|
|
* @param p2 the order to delete (max 255)
|
2004-08-09 17:04:08 +00:00
|
|
|
*/
|
2005-05-11 00:00:27 +00:00
|
|
|
int32 CmdDeleteOrder(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-05-11 00:00:27 +00:00
|
|
|
Vehicle *v, *u;
|
|
|
|
VehicleID veh_id = p1;
|
|
|
|
OrderID sel_ord = p2;
|
2005-01-15 19:06:22 +00:00
|
|
|
Order *order;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-05-11 00:00:27 +00:00
|
|
|
if (!IsVehicleIndex(veh_id)) return CMD_ERROR;
|
|
|
|
v = GetVehicle(veh_id);
|
2005-04-22 05:41:09 +00:00
|
|
|
if (v->type == 0 || !CheckOwnership(v->owner)) return CMD_ERROR;
|
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
/* If we did not select an order, we maybe want to de-clone the orders */
|
2005-05-11 00:00:27 +00:00
|
|
|
if (sel_ord >= v->num_orders)
|
2004-08-09 17:04:08 +00:00
|
|
|
return DecloneOrder(v, flags);
|
|
|
|
|
2005-05-11 00:00:27 +00:00
|
|
|
order = GetVehicleOrder(v, sel_ord);
|
|
|
|
if (order == NULL) return CMD_ERROR;
|
2005-01-15 19:06:22 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
if (flags & DC_EXEC) {
|
2005-05-11 00:00:27 +00:00
|
|
|
if (GetVehicleOrder(v, sel_ord - 1) == NULL) {
|
|
|
|
if (GetVehicleOrder(v, sel_ord + 1) != NULL) {
|
2005-01-15 19:06:22 +00:00
|
|
|
/* First item, but not the last, so we need to alter v->orders
|
|
|
|
Because we can have shared order, we copy the data
|
|
|
|
from the next item over the deleted */
|
2005-05-11 00:00:27 +00:00
|
|
|
order = GetVehicleOrder(v, sel_ord + 1);
|
2005-01-15 19:06:22 +00:00
|
|
|
SwapOrders(v->orders, order);
|
|
|
|
} else {
|
|
|
|
/* Last item, so clean the list */
|
|
|
|
v->orders = NULL;
|
|
|
|
}
|
|
|
|
} else {
|
2005-05-11 00:00:27 +00:00
|
|
|
GetVehicleOrder(v, sel_ord - 1)->next = order->next;
|
2005-01-15 19:06:22 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
/* Give the item free */
|
|
|
|
order->type = OT_NOTHING;
|
2005-01-23 11:37:27 +00:00
|
|
|
order->next = NULL;
|
2005-01-15 19:06:22 +00:00
|
|
|
|
|
|
|
u = GetFirstVehicleFromSharedList(v);
|
|
|
|
while (u != NULL) {
|
|
|
|
u->num_orders--;
|
|
|
|
|
2005-05-11 00:00:27 +00:00
|
|
|
if (sel_ord < u->cur_order_index)
|
2005-01-15 19:06:22 +00:00
|
|
|
u->cur_order_index--;
|
|
|
|
|
|
|
|
/* If we removed the last order, make sure the shared vehicles
|
2005-05-11 00:00:27 +00:00
|
|
|
* also set their orders to NULL */
|
|
|
|
if (v->orders == NULL) u->orders = NULL;
|
2005-01-15 19:06:22 +00:00
|
|
|
|
|
|
|
assert(v->orders == u->orders);
|
|
|
|
|
|
|
|
/* NON-stop flag is misused to see if a train is in a station that is
|
2005-05-11 00:00:27 +00:00
|
|
|
* on his order list or not */
|
|
|
|
if (sel_ord == u->cur_order_index && u->current_order.type == OT_LOADING &&
|
2005-01-15 19:06:22 +00:00
|
|
|
HASBIT(u->current_order.flags, OFB_NON_STOP)) {
|
|
|
|
u->current_order.flags = 0;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2005-01-15 19:06:22 +00:00
|
|
|
|
|
|
|
/* Update any possible open window of the vehicle */
|
|
|
|
InvalidateVehicleOrder(u);
|
|
|
|
|
|
|
|
u = u->next_shared;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2004-12-10 18:16:08 +00:00
|
|
|
|
|
|
|
RebuildVehicleLists();
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-05-11 00:00:27 +00:00
|
|
|
/** Goto next order of order-list.
|
|
|
|
* @param x,y unused
|
|
|
|
* @param p1 The ID of the vehicle which order is skipped
|
|
|
|
* @param p2 unused
|
2005-01-15 19:06:22 +00:00
|
|
|
*/
|
2005-05-11 00:00:27 +00:00
|
|
|
int32 CmdSkipOrder(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-04-22 05:41:09 +00:00
|
|
|
Vehicle *v;
|
2005-05-11 00:00:27 +00:00
|
|
|
VehicleID veh_id = p1;
|
2005-04-22 05:41:09 +00:00
|
|
|
|
2005-05-11 00:00:27 +00:00
|
|
|
if (!IsVehicleIndex(veh_id)) return CMD_ERROR;
|
|
|
|
v = GetVehicle(veh_id);
|
2005-04-22 05:41:09 +00:00
|
|
|
if (v->type == 0 || !CheckOwnership(v->owner)) return CMD_ERROR;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-01-15 09:28:08 +00:00
|
|
|
if (flags & DC_EXEC) {
|
2005-01-15 19:06:22 +00:00
|
|
|
/* Goto next order */
|
2005-05-11 00:00:27 +00:00
|
|
|
OrderID b = v->cur_order_index + 1;
|
|
|
|
if (b >= v->num_orders) b = 0;
|
2005-01-15 19:06:22 +00:00
|
|
|
|
2005-05-11 00:00:27 +00:00
|
|
|
v->cur_order_index = b;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2005-05-11 00:00:27 +00:00
|
|
|
if (v->type == VEH_Train) v->u.rail.days_since_order_progr = 0;
|
2005-01-29 19:41:44 +00:00
|
|
|
|
2005-05-11 00:00:27 +00:00
|
|
|
if (v->type == VEH_Road) ClearSlot(v, v->u.road.slot);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
/* NON-stop flag is misused to see if a train is in a station that is
|
2005-05-11 00:00:27 +00:00
|
|
|
* on his order list or not */
|
|
|
|
if (v->current_order.type == OT_LOADING && HASBIT(v->current_order.flags, OFB_NON_STOP))
|
2004-12-05 12:43:04 +00:00
|
|
|
v->current_order.flags = 0;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
InvalidateVehicleOrder(v);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2005-01-15 09:28:08 +00:00
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
/* We have an aircraft/ship, they have a mini-schedule, so update them all */
|
2005-01-18 09:35:31 +00:00
|
|
|
if (v->type == VEH_Aircraft) InvalidateWindowClasses(WC_AIRCRAFT_LIST);
|
|
|
|
if (v->type == VEH_Ship) InvalidateWindowClasses(WC_SHIPS_LIST);
|
2005-01-15 09:28:08 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
|
2005-05-11 00:00:27 +00:00
|
|
|
/** Modify an order in the orderlist of a vehicle.
|
|
|
|
* @param x,y unused
|
|
|
|
* @param p1 various bitstuffed elements
|
2005-07-20 15:29:28 +00:00
|
|
|
* - p1 = (bit 0 - 15) - ID of the vehicle
|
2005-05-11 00:00:27 +00:00
|
|
|
* - p1 = (bit 16 - 31) - the selected order (if any). If the last order is given,
|
2005-07-20 15:29:28 +00:00
|
|
|
* the order will be inserted before that one
|
|
|
|
* only the first 8 bits used currently (bit 16 - 23) (max 255)
|
2005-05-11 00:00:27 +00:00
|
|
|
* @param p2 mode to change the order to (always set)
|
2004-08-09 17:04:08 +00:00
|
|
|
*/
|
2005-05-11 00:00:27 +00:00
|
|
|
int32 CmdModifyOrder(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-04-22 05:41:09 +00:00
|
|
|
Vehicle *v;
|
2005-01-15 19:06:22 +00:00
|
|
|
Order *order;
|
2005-07-20 15:29:28 +00:00
|
|
|
OrderID sel_ord = GB(p1, 16, 16); // XXX - automatically truncated to 8 bits.
|
|
|
|
VehicleID veh = GB(p1, 0, 16);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-05-11 00:00:27 +00:00
|
|
|
if (!IsVehicleIndex(veh)) return CMD_ERROR;
|
2005-06-15 16:58:15 +00:00
|
|
|
if (p2 != OFB_FULL_LOAD && p2 != OFB_UNLOAD && p2 != OFB_NON_STOP && p2 != OFB_TRANSFER) return CMD_ERROR;
|
2005-05-11 00:00:27 +00:00
|
|
|
|
|
|
|
v = GetVehicle(veh);
|
2005-04-22 05:41:09 +00:00
|
|
|
if (v->type == 0 || !CheckOwnership(v->owner)) return CMD_ERROR;
|
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
/* Is it a valid order? */
|
2005-05-11 00:00:27 +00:00
|
|
|
if (sel_ord >= v->num_orders) return CMD_ERROR;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-05-11 00:00:27 +00:00
|
|
|
order = GetVehicleOrder(v, sel_ord);
|
2005-01-15 19:06:22 +00:00
|
|
|
if (order->type != OT_GOTO_STATION &&
|
2005-05-11 00:00:27 +00:00
|
|
|
(order->type != OT_GOTO_DEPOT || p2 == OFB_UNLOAD) &&
|
|
|
|
(order->type != OT_GOTO_WAYPOINT || p2 != OFB_NON_STOP))
|
2004-08-09 17:04:08 +00:00
|
|
|
return CMD_ERROR;
|
|
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
2005-05-11 00:00:27 +00:00
|
|
|
switch (p2) {
|
2005-01-15 19:06:22 +00:00
|
|
|
case OFB_FULL_LOAD:
|
|
|
|
TOGGLEBIT(order->flags, OFB_FULL_LOAD);
|
|
|
|
if (order->type != OT_GOTO_DEPOT)
|
|
|
|
CLRBIT(order->flags, OFB_UNLOAD);
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
2005-01-15 19:06:22 +00:00
|
|
|
case OFB_UNLOAD:
|
|
|
|
TOGGLEBIT(order->flags, OFB_UNLOAD);
|
|
|
|
CLRBIT(order->flags, OFB_FULL_LOAD);
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
2005-01-15 19:06:22 +00:00
|
|
|
case OFB_NON_STOP:
|
|
|
|
TOGGLEBIT(order->flags, OFB_NON_STOP);
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
2005-06-15 16:58:15 +00:00
|
|
|
case OFB_TRANSFER:
|
|
|
|
TOGGLEBIT(order->flags, OFB_TRANSFER);
|
|
|
|
break;
|
2005-05-11 00:00:27 +00:00
|
|
|
default: NOT_REACHED();
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-05-03 22:18:40 +00:00
|
|
|
/* Update the windows and full load flags, also for vehicles that share the same order list */
|
2005-01-15 19:06:22 +00:00
|
|
|
{
|
|
|
|
Vehicle *u = GetFirstVehicleFromSharedList(v);
|
|
|
|
while (u != NULL) {
|
2005-05-03 22:18:40 +00:00
|
|
|
/* toggle u->current_order "Full load" flag if it changed */
|
2005-05-11 00:00:27 +00:00
|
|
|
if (sel_ord == u->cur_order_index &&
|
2005-05-03 22:18:40 +00:00
|
|
|
HASBIT(u->current_order.flags, OFB_FULL_LOAD) != HASBIT(order->flags, OFB_FULL_LOAD))
|
|
|
|
TOGGLEBIT(u->current_order.flags, OFB_FULL_LOAD);
|
2005-01-15 19:06:22 +00:00
|
|
|
InvalidateVehicleOrder(u);
|
|
|
|
u = u->next_shared;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-05-12 00:11:37 +00:00
|
|
|
/** Clone/share/copy an order-list of an other vehicle.
|
|
|
|
* @param p1 various bitstuffed elements
|
|
|
|
* - p1 = (bit 0-15) - destination vehicle to clone orders to (p1 & 0xFFFF)
|
|
|
|
* - p1 = (bit 16-31) - source vehicle to clone orders from, if any (none for CO_UNSHARE)
|
|
|
|
* @param p2 mode of cloning: CO_SHARE, CO_COPY, or CO_UNSHARE
|
2005-01-15 19:06:22 +00:00
|
|
|
*/
|
2005-05-12 00:11:37 +00:00
|
|
|
int32 CmdCloneOrder(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
2005-01-15 19:06:22 +00:00
|
|
|
{
|
2005-05-12 00:11:37 +00:00
|
|
|
Vehicle *dst;
|
2005-07-20 15:29:28 +00:00
|
|
|
VehicleID veh_src = GB(p1, 16, 16);
|
|
|
|
VehicleID veh_dst = GB(p1, 0, 16);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-05-12 00:11:37 +00:00
|
|
|
if (!IsVehicleIndex(veh_dst)) return CMD_ERROR;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-05-12 00:11:37 +00:00
|
|
|
dst = GetVehicle(veh_dst);
|
|
|
|
|
|
|
|
if (dst->type == 0 || !CheckOwnership(dst->owner)) return CMD_ERROR;
|
|
|
|
|
|
|
|
switch (p2) {
|
2005-01-15 19:06:22 +00:00
|
|
|
case CO_SHARE: {
|
2005-05-12 00:11:37 +00:00
|
|
|
Vehicle *src;
|
|
|
|
|
|
|
|
if (!IsVehicleIndex(veh_src)) return CMD_ERROR;
|
|
|
|
|
|
|
|
src = GetVehicle(veh_src);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
/* Sanity checks */
|
2005-05-12 00:11:37 +00:00
|
|
|
if (src->type == 0 || !CheckOwnership(src->owner) || dst->type != src->type || dst == src)
|
2005-01-15 19:06:22 +00:00
|
|
|
return CMD_ERROR;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
/* Trucks can't share orders with busses (and visa versa) */
|
|
|
|
if (src->type == VEH_Road) {
|
|
|
|
if (src->cargo_type != dst->cargo_type && (src->cargo_type == CT_PASSENGERS || dst->cargo_type == CT_PASSENGERS))
|
|
|
|
return CMD_ERROR;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
/* Is the vehicle already in the shared list? */
|
|
|
|
{
|
|
|
|
Vehicle *u = GetFirstVehicleFromSharedList(src);
|
|
|
|
while (u != NULL) {
|
|
|
|
if (u == dst)
|
|
|
|
return CMD_ERROR;
|
|
|
|
u = u->next_shared;
|
|
|
|
}
|
|
|
|
}
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
if (flags & DC_EXEC) {
|
|
|
|
/* If the destination vehicle had a OrderList, destroy it */
|
|
|
|
DeleteVehicleOrders(dst);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
dst->orders = src->orders;
|
|
|
|
dst->num_orders = src->num_orders;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
/* Link this vehicle in the shared-list */
|
|
|
|
dst->next_shared = src->next_shared;
|
|
|
|
dst->prev_shared = src;
|
|
|
|
if (src->next_shared != NULL)
|
|
|
|
src->next_shared->prev_shared = dst;
|
|
|
|
src->next_shared = dst;
|
|
|
|
|
|
|
|
InvalidateVehicleOrder(dst);
|
|
|
|
InvalidateVehicleOrder(src);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
RebuildVehicleLists();
|
|
|
|
}
|
|
|
|
} break;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
case CO_COPY: {
|
2005-05-12 00:11:37 +00:00
|
|
|
Vehicle *src;
|
2005-01-15 19:06:22 +00:00
|
|
|
int delta;
|
2004-12-10 18:16:08 +00:00
|
|
|
|
2005-05-12 00:11:37 +00:00
|
|
|
if (!IsVehicleIndex(veh_src)) return CMD_ERROR;
|
|
|
|
|
|
|
|
src = GetVehicle(veh_src);
|
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
/* Sanity checks */
|
2005-05-12 00:11:37 +00:00
|
|
|
if (src->type == 0 || !CheckOwnership(src->owner) || dst->type != src->type || dst == src)
|
2005-01-15 19:06:22 +00:00
|
|
|
return CMD_ERROR;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
/* Trucks can't copy all the orders from busses (and visa versa) */
|
|
|
|
if (src->type == VEH_Road) {
|
|
|
|
const Order *order;
|
2005-02-05 15:05:52 +00:00
|
|
|
TileIndex required_dst = INVALID_TILE;
|
2005-01-15 19:06:22 +00:00
|
|
|
|
|
|
|
FOR_VEHICLE_ORDERS(src, order) {
|
|
|
|
if (order->type == OT_GOTO_STATION) {
|
|
|
|
const Station *st = GetStation(order->station);
|
2005-02-05 15:05:52 +00:00
|
|
|
if (dst->cargo_type == CT_PASSENGERS) {
|
|
|
|
if (st->bus_stops != NULL) required_dst = st->bus_stops->xy;
|
|
|
|
} else {
|
|
|
|
if (st->truck_stops != NULL) required_dst = st->truck_stops->xy;
|
|
|
|
}
|
2005-01-15 19:06:22 +00:00
|
|
|
/* This station has not the correct road-bay, so we can't copy! */
|
2005-02-05 15:05:52 +00:00
|
|
|
if (required_dst == INVALID_TILE)
|
2005-01-15 19:06:22 +00:00
|
|
|
return CMD_ERROR;
|
|
|
|
}
|
2004-08-12 21:29:26 +00:00
|
|
|
}
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
/* make sure there are orders available */
|
|
|
|
delta = IsOrderListShared(dst) ? src->num_orders + 1 : src->num_orders - dst->num_orders;
|
|
|
|
if (!HasOrderPoolFree(delta))
|
|
|
|
return_cmd_error(STR_8831_NO_MORE_SPACE_FOR_ORDERS);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
if (flags & DC_EXEC) {
|
|
|
|
const Order *order;
|
|
|
|
Order **order_dst;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
/* If the destination vehicle had a OrderList, destroy it */
|
|
|
|
DeleteVehicleOrders(dst);
|
2004-12-10 18:16:08 +00:00
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
order_dst = &dst->orders;
|
|
|
|
FOR_VEHICLE_ORDERS(src, order) {
|
|
|
|
*order_dst = AllocateOrder();
|
|
|
|
AssignOrder(*order_dst, *order);
|
|
|
|
order_dst = &(*order_dst)->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
dst->num_orders = src->num_orders;
|
|
|
|
|
|
|
|
InvalidateVehicleOrder(dst);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
RebuildVehicleLists();
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
2005-05-12 00:11:37 +00:00
|
|
|
case CO_UNSHARE: return DecloneOrder(dst, flags);
|
2005-05-12 23:46:01 +00:00
|
|
|
default: return CMD_ERROR;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Backup a vehicle order-list, so you can replace a vehicle
|
|
|
|
* without loosing the order-list
|
|
|
|
*
|
|
|
|
*/
|
2005-05-12 23:46:01 +00:00
|
|
|
void BackupVehicleOrders(const Vehicle *v, BackuppedOrders *bak)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-01-15 19:06:22 +00:00
|
|
|
/* Save general info */
|
|
|
|
bak->orderindex = v->cur_order_index;
|
2004-08-09 17:04:08 +00:00
|
|
|
bak->service_interval = v->service_interval;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
/* Safe custom string, if any */
|
2004-08-09 17:04:08 +00:00
|
|
|
if ((v->string_id & 0xF800) != 0x7800) {
|
|
|
|
bak->name[0] = 0;
|
|
|
|
} else {
|
|
|
|
GetName(v->string_id & 0x7FF, bak->name);
|
|
|
|
}
|
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
/* If we have shared orders, store it on a special way */
|
2005-05-12 23:46:01 +00:00
|
|
|
if (IsOrderListShared(v)) {
|
|
|
|
const Vehicle *u = (v->next_shared) ? v->next_shared : v->prev_shared;
|
2005-01-15 19:06:22 +00:00
|
|
|
|
2004-12-05 12:43:04 +00:00
|
|
|
bak->clone = u->index;
|
|
|
|
} else {
|
2005-01-15 19:06:22 +00:00
|
|
|
/* Else copy the orders */
|
|
|
|
Order *order, *dest;
|
|
|
|
|
2005-05-12 23:46:01 +00:00
|
|
|
dest = bak->order;
|
2004-12-05 12:43:04 +00:00
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
/* We do not have shared orders */
|
2004-12-05 12:43:04 +00:00
|
|
|
bak->clone = INVALID_VEHICLE;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
/* Copy the orders */
|
|
|
|
FOR_VEHICLE_ORDERS(v, order) {
|
|
|
|
*dest = *order;
|
|
|
|
dest++;
|
|
|
|
}
|
|
|
|
/* End the list with an OT_NOTHING */
|
|
|
|
dest->type = OT_NOTHING;
|
2005-01-23 11:37:27 +00:00
|
|
|
dest->next = NULL;
|
2004-12-05 12:43:04 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Restore vehicle orders that are backupped via BackupVehicleOrders
|
|
|
|
*
|
|
|
|
*/
|
2004-08-09 17:04:08 +00:00
|
|
|
void RestoreVehicleOrders(Vehicle *v, BackuppedOrders *bak)
|
|
|
|
{
|
2005-05-12 23:46:01 +00:00
|
|
|
uint i;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
/* If we have a custom name, process that */
|
|
|
|
if (bak->name[0] != 0) {
|
2005-05-15 18:50:55 +00:00
|
|
|
_cmd_text = bak->name;
|
2004-08-09 17:04:08 +00:00
|
|
|
DoCommandP(0, v->index, 0, NULL, CMD_NAME_VEHICLE);
|
|
|
|
}
|
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
/* If we had shared orders, recover that */
|
2004-12-05 12:43:04 +00:00
|
|
|
if (bak->clone != INVALID_VEHICLE) {
|
2005-01-15 19:06:22 +00:00
|
|
|
DoCommandP(0, v->index | (bak->clone << 16), 0, NULL, CMD_CLONE_ORDER);
|
2004-08-09 17:04:08 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
/* CMD_NO_TEST_IF_IN_NETWORK is used here, because CMD_INSERT_ORDER checks if the
|
|
|
|
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. */
|
2005-05-12 23:46:01 +00:00
|
|
|
for (i = 0; bak->order[i].type != OT_NOTHING; i++) {
|
2004-12-05 12:43:04 +00:00
|
|
|
if (!DoCommandP(0, v->index + (i << 16), PackOrder(&bak->order[i]), NULL, CMD_INSERT_ORDER | CMD_NO_TEST_IF_IN_NETWORK))
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
2005-05-12 23:46:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Restore vehicle order-index and service interval */
|
|
|
|
DoCommandP(0, v->index, bak->orderindex | (bak->service_interval << 16) , NULL, CMD_RESTORE_ORDER_INDEX);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-05-12 23:46:01 +00:00
|
|
|
/** Restore the current order-index of a vehicle and sets service-interval.
|
|
|
|
* @param x,y unused
|
|
|
|
* @param p1 the ID of the vehicle
|
|
|
|
* @param p2 various bistuffed elements
|
|
|
|
* - p2 = (bit 0-15) - current order-index (p2 & 0xFFFF)
|
|
|
|
* - p2 = (bit 16-31) - service interval (p2 >> 16)
|
|
|
|
* @todo Unfortunately you cannot safely restore the unitnumber or the old vehicle
|
|
|
|
* as far as I can see. We can store it in BackuppedOrders, and restore it, but
|
|
|
|
* but we have no way of seeing it has been tampered with or not, as we have no
|
|
|
|
* legit way of knowing what that ID was.@n
|
|
|
|
* If we do want to backup/restore it, just add UnitID uid to BackuppedOrders, and
|
|
|
|
* restore it as parameter 'y' (ugly hack I know) for example. "v->unitnumber = y;"
|
2004-08-09 17:04:08 +00:00
|
|
|
*/
|
2005-05-12 23:46:01 +00:00
|
|
|
int32 CmdRestoreOrderIndex(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-05-12 23:46:01 +00:00
|
|
|
Vehicle *v;
|
|
|
|
OrderID cur_ord = p2 & 0xFFFF;
|
|
|
|
uint16 serv_int = p2 >> 16;
|
|
|
|
|
|
|
|
if (!IsVehicleIndex(p1)) return CMD_ERROR;
|
2005-04-22 05:41:09 +00:00
|
|
|
|
2005-05-12 23:46:01 +00:00
|
|
|
v = GetVehicle(p1);
|
|
|
|
/* Check the vehicle type and ownership, and if the service interval and order are in range */
|
2005-04-22 05:41:09 +00:00
|
|
|
if (v->type == 0 || !CheckOwnership(v->owner)) return CMD_ERROR;
|
2005-05-12 23:46:01 +00:00
|
|
|
if (serv_int != GetServiceIntervalClamped(serv_int) || cur_ord >= v->num_orders) return CMD_ERROR;
|
2005-04-22 05:41:09 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
if (flags & DC_EXEC) {
|
2005-05-12 23:46:01 +00:00
|
|
|
v->cur_order_index = cur_ord;
|
|
|
|
v->service_interval = serv_int;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2005-01-15 19:06:22 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2004-08-11 10:15:38 +00:00
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Check the orders of a vehicle, to see if there are invalid orders and stuff
|
|
|
|
*
|
|
|
|
*/
|
2005-01-17 21:54:45 +00:00
|
|
|
bool CheckOrders(uint data_a, uint data_b)
|
2004-08-11 10:15:38 +00:00
|
|
|
{
|
2005-01-17 21:54:45 +00:00
|
|
|
Vehicle *v = GetVehicle(data_a);
|
2005-01-15 19:06:22 +00:00
|
|
|
/* Does the user wants us to check things? */
|
|
|
|
if (_patches.order_review_system == 0)
|
|
|
|
return false;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
/* Do nothing for crashed vehicles */
|
2004-12-19 09:30:05 +00:00
|
|
|
if(v->vehstatus & VS_CRASHED)
|
2005-01-15 19:06:22 +00:00
|
|
|
return false;
|
2004-12-19 09:30:05 +00:00
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
/* Do nothing for stopped vehicles if setting is '1' */
|
2004-12-19 09:30:05 +00:00
|
|
|
if ( (_patches.order_review_system == 1) && (v->vehstatus & VS_STOPPED) )
|
2005-01-15 19:06:22 +00:00
|
|
|
return false;
|
2004-08-11 10:15:38 +00:00
|
|
|
|
2005-01-17 21:54:45 +00:00
|
|
|
/* do nothing we we're not the first vehicle in a share-chain */
|
|
|
|
if (v->next_shared != NULL)
|
|
|
|
return false;
|
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
/* Only check every 20 days, so that we don't flood the message log */
|
2005-07-17 12:29:33 +00:00
|
|
|
if ( (v->owner == _local_player) && (v->day_counter % 20 == 0) ) {
|
2005-01-15 19:06:22 +00:00
|
|
|
int n_st, problem_type = -1;
|
|
|
|
const Order *order;
|
|
|
|
const Station *st;
|
|
|
|
int message = 0;
|
|
|
|
|
|
|
|
/* Check the order list */
|
2004-08-15 13:21:18 +00:00
|
|
|
n_st = 0;
|
|
|
|
|
2005-01-17 21:54:45 +00:00
|
|
|
/*if (data_b == OC_INIT) {
|
|
|
|
DEBUG(misc, 3) ("CheckOrder called in mode 0 (initiation mode) for %d", v->index);
|
|
|
|
} else {
|
|
|
|
DEBUG(misc, 3) ("CheckOrder called in mode 1 (validation mode) for %d", v->index);
|
|
|
|
}*/
|
2005-01-23 11:37:27 +00:00
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
FOR_VEHICLE_ORDERS(v, order) {
|
|
|
|
/* Dummy order? */
|
|
|
|
if (order->type == OT_DUMMY) {
|
2004-08-15 13:21:18 +00:00
|
|
|
problem_type = 1;
|
|
|
|
break;
|
|
|
|
}
|
2005-01-15 19:06:22 +00:00
|
|
|
/* Does station have a load-bay for this vehicle? */
|
|
|
|
if (order->type == OT_GOTO_STATION) {
|
|
|
|
TileIndex required_tile;
|
|
|
|
|
2004-08-11 10:15:38 +00:00
|
|
|
n_st++;
|
2005-01-15 19:06:22 +00:00
|
|
|
st = GetStation(order->station);
|
|
|
|
required_tile = GetStationTileForVehicle(v, st);
|
|
|
|
if (!required_tile)
|
|
|
|
problem_type = 3;
|
2004-08-11 10:15:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
/* Check if the last and the first order are the same */
|
|
|
|
if (v->num_orders > 1 &&
|
|
|
|
v->orders->type == GetLastVehicleOrder(v)->type &&
|
|
|
|
v->orders->flags == GetLastVehicleOrder(v)->flags &&
|
|
|
|
v->orders->station == GetLastVehicleOrder(v)->station)
|
2004-08-15 13:21:18 +00:00
|
|
|
problem_type = 2;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
/* Do we only have 1 station in our order list? */
|
|
|
|
if ((n_st < 2) && (problem_type == -1))
|
|
|
|
problem_type = 0;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
/* We don't have a problem */
|
2005-01-17 21:54:45 +00:00
|
|
|
if (problem_type < 0) {
|
|
|
|
/*if (data_b == OC_INIT) {
|
|
|
|
DEBUG(misc, 3) ("CheckOrder mode 0: no problems found for %d", v->index);
|
|
|
|
} else {
|
|
|
|
DEBUG(misc, 3) ("CheckOrder mode 1: news item surpressed for %d", v->index);
|
|
|
|
}*/
|
2005-01-15 19:06:22 +00:00
|
|
|
return false;
|
2005-01-17 21:54:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* we have a problem, are we're just in the validation process
|
|
|
|
so don't display an error message */
|
|
|
|
if (data_b == OC_VALIDATE) {
|
|
|
|
/*DEBUG(misc, 3) ("CheckOrder mode 1: new item validated for %d", v->index);*/
|
|
|
|
return true;
|
|
|
|
}
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-15 13:21:18 +00:00
|
|
|
message = (STR_TRAIN_HAS_TOO_FEW_ORDERS) + (((v->type) - VEH_Train) << 2) + problem_type;
|
2005-01-17 21:54:45 +00:00
|
|
|
/*DEBUG(misc, 3) ("Checkorder mode 0: Triggered News Item for %d", v->index);*/
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
SetDParam(0, v->unitnumber);
|
2005-01-17 21:54:45 +00:00
|
|
|
AddValidatedNewsItem(
|
2004-08-15 13:21:18 +00:00
|
|
|
message,
|
2005-01-15 19:06:22 +00:00
|
|
|
NEWS_FLAGS(NM_SMALL, NF_VIEWPORT | NF_VEHICLE, NT_ADVICE, 0),
|
2004-08-15 13:21:18 +00:00
|
|
|
v->index,
|
2005-01-17 21:54:45 +00:00
|
|
|
OC_VALIDATE, //next time, just validate the orders
|
|
|
|
CheckOrders);
|
2004-08-11 10:15:38 +00:00
|
|
|
}
|
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Delete a destination (like station, waypoint, ..) from the orders of vehicles
|
|
|
|
*
|
|
|
|
* @param dest type and station has to be set. This order will be removed from all orders of vehicles
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void DeleteDestinationFromVehicleOrder(Order dest)
|
|
|
|
{
|
|
|
|
Vehicle *v;
|
|
|
|
Order *order;
|
|
|
|
bool need_invalidate;
|
|
|
|
|
|
|
|
/* Go through all vehicles */
|
|
|
|
FOR_ALL_VEHICLES(v) {
|
|
|
|
if (v->type == 0 || v->orders == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Forget about this station if this station is removed */
|
|
|
|
if (v->last_station_visited == dest.station && dest.type == OT_GOTO_STATION)
|
2005-02-02 16:16:43 +00:00
|
|
|
v->last_station_visited = INVALID_STATION;
|
2005-01-15 19:06:22 +00:00
|
|
|
|
|
|
|
/* Check the current order */
|
|
|
|
if (v->current_order.type == dest.type &&
|
|
|
|
v->current_order.station == dest.station) {
|
|
|
|
/* Mark the order as DUMMY */
|
|
|
|
v->current_order.type = OT_DUMMY;
|
|
|
|
v->current_order.flags = 0;
|
|
|
|
InvalidateWindow(WC_VEHICLE_VIEW, v->index);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Clear the order from the order-list */
|
|
|
|
need_invalidate = false;
|
|
|
|
FOR_VEHICLE_ORDERS(v, order) {
|
|
|
|
if (order->type == dest.type && order->station == dest.station) {
|
|
|
|
/* Mark the order as DUMMY */
|
|
|
|
order->type = OT_DUMMY;
|
|
|
|
order->flags = 0;
|
|
|
|
|
|
|
|
need_invalidate = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Only invalidate once, and if needed */
|
|
|
|
if (need_invalidate)
|
|
|
|
InvalidateWindow(WC_VEHICLE_ORDERS, v->index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Checks if a vehicle has a GOTO_DEPOT in his order list
|
|
|
|
*
|
|
|
|
* @return True if this is true (lol ;))
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
bool VehicleHasDepotOrders(const Vehicle *v)
|
|
|
|
{
|
|
|
|
const Order *order;
|
|
|
|
|
|
|
|
FOR_VEHICLE_ORDERS(v, order) {
|
|
|
|
if (order->type == OT_GOTO_DEPOT)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Delete all orders from a vehicle
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void DeleteVehicleOrders(Vehicle *v)
|
|
|
|
{
|
|
|
|
Order *order, *cur;
|
|
|
|
|
|
|
|
/* If we have a shared order-list, don't delete the list, but just
|
|
|
|
remove our pointer */
|
|
|
|
if (IsOrderListShared(v)) {
|
|
|
|
const Vehicle *u = v;
|
|
|
|
|
|
|
|
v->orders = NULL;
|
|
|
|
v->num_orders = 0;
|
|
|
|
|
|
|
|
/* Unlink ourself */
|
|
|
|
if (v->prev_shared != NULL) {
|
|
|
|
v->prev_shared->next_shared = v->next_shared;
|
|
|
|
u = v->prev_shared;
|
|
|
|
}
|
|
|
|
if (v->next_shared != NULL) {
|
|
|
|
v->next_shared->prev_shared = v->prev_shared;
|
|
|
|
u = v->next_shared;
|
|
|
|
}
|
|
|
|
v->prev_shared = NULL;
|
|
|
|
v->next_shared = NULL;
|
|
|
|
|
|
|
|
/* We only need to update this-one, because if there is a third
|
|
|
|
vehicle which shares the same order-list, nothing will change. If
|
|
|
|
this is the last vehicle, the last line of the order-window
|
|
|
|
will change from Shared order list, to Order list, so it needs
|
|
|
|
an update */
|
|
|
|
InvalidateVehicleOrder(u);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Remove the orders */
|
|
|
|
cur = v->orders;
|
|
|
|
v->orders = NULL;
|
|
|
|
v->num_orders = 0;
|
|
|
|
|
|
|
|
order = NULL;
|
|
|
|
while (cur != NULL) {
|
|
|
|
if (order != NULL) {
|
|
|
|
order->type = OT_NOTHING;
|
|
|
|
order->next = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
order = cur;
|
|
|
|
cur = cur->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (order != NULL) {
|
|
|
|
order->type = OT_NOTHING;
|
|
|
|
order->next = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Check if we share our orders with an other vehicle
|
|
|
|
*
|
|
|
|
* @return Returns the vehicle who has the same order
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
bool IsOrderListShared(const Vehicle *v)
|
|
|
|
{
|
|
|
|
if (v->next_shared != NULL)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (v->prev_shared != NULL)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Check if a vehicle has any valid orders
|
|
|
|
*
|
|
|
|
* @return false if there are no valid orders
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
bool CheckForValidOrders(Vehicle *v)
|
|
|
|
{
|
|
|
|
const Order *order;
|
|
|
|
|
|
|
|
FOR_VEHICLE_ORDERS(v, order)
|
|
|
|
if (order->type != OT_DUMMY)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void InitializeOrders(void)
|
|
|
|
{
|
2005-02-06 10:24:57 +00:00
|
|
|
CleanPool(&_order_pool);
|
|
|
|
AddBlockToPool(&_order_pool);
|
2005-01-15 19:06:22 +00:00
|
|
|
|
|
|
|
_backup_orders_tile = 0;
|
|
|
|
}
|
|
|
|
|
2005-05-30 22:16:05 +00:00
|
|
|
static const SaveLoad _order_desc[] = {
|
2005-01-15 19:06:22 +00:00
|
|
|
SLE_VAR(Order,type, SLE_UINT8),
|
|
|
|
SLE_VAR(Order,flags, SLE_UINT8),
|
|
|
|
SLE_VAR(Order,station, SLE_UINT16),
|
|
|
|
SLE_REF(Order,next, REF_ORDER),
|
|
|
|
|
|
|
|
// reserve extra space in savegame here. (currently 10 bytes)
|
|
|
|
SLE_CONDARR(NullStruct,null,SLE_FILE_U8 | SLE_VAR_NULL, 10, 5, 255),
|
|
|
|
SLE_END()
|
|
|
|
};
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
static void Save_ORDR(void)
|
2005-01-15 19:06:22 +00:00
|
|
|
{
|
|
|
|
Order *order;
|
|
|
|
|
|
|
|
FOR_ALL_ORDERS(order) {
|
|
|
|
if (order->type != OT_NOTHING) {
|
|
|
|
SlSetArrayIndex(order->index);
|
|
|
|
SlObject(order, _order_desc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
static void Load_ORDR(void)
|
2005-01-15 19:06:22 +00:00
|
|
|
{
|
2005-08-06 17:40:21 +00:00
|
|
|
if (_sl_full_version <= 0x501) {
|
2005-01-15 19:06:22 +00:00
|
|
|
/* Version older than 0x502 did not have a ->next pointer. Convert them
|
|
|
|
(in the old days, the orderlist was 5000 items big) */
|
|
|
|
uint len = SlGetFieldLength();
|
|
|
|
uint i;
|
|
|
|
|
2005-08-06 17:40:21 +00:00
|
|
|
if (_sl_version < 5) {
|
2005-01-15 19:06:22 +00:00
|
|
|
/* Pre-version 5 had an other layout for orders
|
|
|
|
(uint16 instead of uint32) */
|
|
|
|
uint16 orders[5000];
|
|
|
|
|
|
|
|
len /= sizeof(uint16);
|
2005-02-06 10:24:57 +00:00
|
|
|
assert (len <= lengthof(orders));
|
2005-01-15 19:06:22 +00:00
|
|
|
|
|
|
|
SlArray(orders, len, SLE_UINT16);
|
|
|
|
|
|
|
|
for (i = 0; i < len; ++i) {
|
2005-02-06 10:24:57 +00:00
|
|
|
if (!AddBlockIfNeeded(&_order_pool, i))
|
|
|
|
error("Orders: failed loading savegame: too many orders");
|
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
AssignOrder(GetOrder(i), UnpackVersion4Order(orders[i]));
|
|
|
|
}
|
2005-08-06 17:40:21 +00:00
|
|
|
} else if (_sl_full_version <= 0x501) {
|
2005-01-15 19:06:22 +00:00
|
|
|
uint32 orders[5000];
|
|
|
|
|
|
|
|
len /= sizeof(uint32);
|
2005-02-06 10:24:57 +00:00
|
|
|
assert (len <= lengthof(orders));
|
2005-01-15 19:06:22 +00:00
|
|
|
|
|
|
|
SlArray(orders, len, SLE_UINT32);
|
|
|
|
|
|
|
|
for (i = 0; i < len; ++i) {
|
2005-02-06 10:24:57 +00:00
|
|
|
if (!AddBlockIfNeeded(&_order_pool, i))
|
|
|
|
error("Orders: failed loading savegame: too many orders");
|
|
|
|
|
2005-01-15 19:06:22 +00:00
|
|
|
AssignOrder(GetOrder(i), UnpackOrder(orders[i]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Update all the next pointer */
|
|
|
|
for (i = 1; i < len; ++i) {
|
|
|
|
/* The orders were built like this:
|
|
|
|
Vehicle one had order[0], and as long as order++.type was not
|
|
|
|
OT_NOTHING, it was part of the order-list of that vehicle */
|
|
|
|
if (GetOrder(i)->type != OT_NOTHING)
|
|
|
|
GetOrder(i - 1)->next = GetOrder(i);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
int index;
|
|
|
|
|
|
|
|
while ((index = SlIterateArray()) != -1) {
|
2005-02-06 10:24:57 +00:00
|
|
|
Order *order;
|
|
|
|
|
|
|
|
if (!AddBlockIfNeeded(&_order_pool, index))
|
|
|
|
error("Orders: failed loading savegame: too many orders");
|
2005-01-15 19:06:22 +00:00
|
|
|
|
2005-02-06 10:24:57 +00:00
|
|
|
order = GetOrder(index);
|
2005-01-15 19:06:22 +00:00
|
|
|
SlObject(order, _order_desc);
|
|
|
|
}
|
|
|
|
}
|
2004-08-11 10:15:38 +00:00
|
|
|
}
|
2005-01-15 19:06:22 +00:00
|
|
|
|
|
|
|
const ChunkHandler _order_chunk_handlers[] = {
|
|
|
|
{ 'ORDR', Save_ORDR, Load_ORDR, CH_ARRAY | CH_LAST},
|
|
|
|
};
|