|
@@ -912,48 +912,49 @@ CommandCost CmdOrderRefit(TileIndex tile
|
|
|
u->current_order.refit_subtype = subtype;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return CommandCost();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
*
|
|
|
* Backup a vehicle order-list, so you can replace a vehicle
|
|
|
* without loosing the order-list
|
|
|
*
|
|
|
*/
|
|
|
void BackupVehicleOrders(const Vehicle *v, BackuppedOrders *bak)
|
|
|
{
|
|
|
/* Make sure we always have freed the stuff */
|
|
|
free(bak->order);
|
|
|
bak->order = NULL;
|
|
|
free(bak->name);
|
|
|
bak->name = NULL;
|
|
|
|
|
|
/* 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);
|
|
|
|
|
|
/* If we have shared orders, store it on a special way */
|
|
|
if (v->IsOrderListShared()) {
|
|
|
const Vehicle *u = (v->next_shared) ? v->next_shared : v->prev_shared;
|
|
|
|
|
|
bak->clone = u->index;
|
|
|
} else {
|
|
|
/* Else copy the orders */
|
|
|
|
|
|
/* 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;
|
|
@@ -971,55 +972,66 @@ void BackupVehicleOrders(const Vehicle *
|
|
|
/**
|
|
|
*
|
|
|
* Restore vehicle orders that are backupped via BackupVehicleOrders
|
|
|
*
|
|
|
*/
|
|
|
void RestoreVehicleOrders(const Vehicle *v, const BackuppedOrders *bak)
|
|
|
{
|
|
|
/* If we have a custom name, process that */
|
|
|
if (bak->name != NULL) {
|
|
|
_cmd_text = bak->name;
|
|
|
DoCommandP(0, v->index, 0, NULL, CMD_NAME_VEHICLE);
|
|
|
}
|
|
|
|
|
|
/* If we had shared orders, recover that */
|
|
|
if (bak->clone != INVALID_VEHICLE) {
|
|
|
DoCommandP(0, v->index | (bak->clone << 16), CO_SHARE, NULL, CMD_CLONE_ORDER);
|
|
|
} else {
|
|
|
|
|
|
/* 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. */
|
|
|
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.
|
|
|
* @param tile unused
|
|
|
* @param flags operation to perform
|
|
|
* @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;"
|
|
|
*/
|
|
|
CommandCost CmdRestoreOrderIndex(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
|
|
{
|
|
|
Vehicle *v;
|
|
|
VehicleOrderID cur_ord = GB(p2, 0, 16);
|
|
|
uint16 serv_int = GB(p2, 16, 16);
|
|
|
|
|
|
if (!IsValidVehicleID(p1)) return CMD_ERROR;
|
|
|
|