mirror of https://github.com/OpenTTD/OpenTTD
Codechange: OrderBackups are indexed through DepotID instead of TileIndex.
parent
6c5ce41b0a
commit
829c5c33cf
|
@ -35,7 +35,7 @@ Depot::~Depot()
|
|||
}
|
||||
|
||||
/* Clear the order backup. */
|
||||
OrderBackup::Reset(this->xy, false);
|
||||
OrderBackup::Reset(this->index, false);
|
||||
|
||||
/* Clear the depot from all order-lists */
|
||||
RemoveOrderFromAllVehicles(OT_GOTO_DEPOT, this->index);
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
#include "order_cmd.h"
|
||||
#include "group_cmd.h"
|
||||
#include "vehicle_func.h"
|
||||
#include "depot_map.h"
|
||||
#include "depot_base.h"
|
||||
|
||||
#include "safeguards.h"
|
||||
|
||||
|
@ -45,8 +47,9 @@ OrderBackup::~OrderBackup()
|
|||
*/
|
||||
OrderBackup::OrderBackup(const Vehicle *v, uint32_t user)
|
||||
{
|
||||
assert(IsDepotTile(v->tile));
|
||||
this->user = user;
|
||||
this->tile = v->tile;
|
||||
this->depot_id = GetDepotIndex(v->tile);
|
||||
this->group = v->group_id;
|
||||
|
||||
this->CopyConsistPropertiesFrom(v);
|
||||
|
@ -123,8 +126,10 @@ void OrderBackup::DoRestore(Vehicle *v)
|
|||
*/
|
||||
/* static */ void OrderBackup::Restore(Vehicle *v, uint32_t user)
|
||||
{
|
||||
assert(IsDepotTile(v->tile));
|
||||
DepotID depot_id_veh = GetDepotIndex(v->tile);
|
||||
for (OrderBackup *ob : OrderBackup::Iterate()) {
|
||||
if (v->tile != ob->tile || ob->user != user) continue;
|
||||
if (depot_id_veh != ob->depot_id || ob->user != user) continue;
|
||||
|
||||
ob->DoRestore(v);
|
||||
delete ob;
|
||||
|
@ -133,28 +138,28 @@ void OrderBackup::DoRestore(Vehicle *v)
|
|||
|
||||
/**
|
||||
* Reset an OrderBackup given a tile and user.
|
||||
* @param tile The tile associated with the OrderBackup.
|
||||
* @param depot_id The depot associated with the OrderBackup.
|
||||
* @param user The user associated with the OrderBackup.
|
||||
* @note Must not be used from the GUI!
|
||||
*/
|
||||
/* static */ void OrderBackup::ResetOfUser(TileIndex tile, uint32_t user)
|
||||
/* static */ void OrderBackup::ResetOfUser(DepotID depot_id, uint32_t user)
|
||||
{
|
||||
for (OrderBackup *ob : OrderBackup::Iterate()) {
|
||||
if (ob->user == user && (ob->tile == tile || tile == INVALID_TILE)) delete ob;
|
||||
if (ob->user == user && (ob->depot_id == depot_id || depot_id == INVALID_DEPOT)) delete ob;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear an OrderBackup
|
||||
* @param flags For command.
|
||||
* @param tile Tile related to the to-be-cleared OrderBackup.
|
||||
* @param depot_id Tile related to the to-be-cleared OrderBackup.
|
||||
* @param user_id User that had the OrderBackup.
|
||||
* @return The cost of this operation or an error.
|
||||
*/
|
||||
CommandCost CmdClearOrderBackup(DoCommandFlag flags, TileIndex tile, ClientID user_id)
|
||||
CommandCost CmdClearOrderBackup(DoCommandFlag flags, DepotID depot_id, ClientID user_id)
|
||||
{
|
||||
/* No need to check anything. If the tile or user don't exist we just ignore it. */
|
||||
if (flags & DC_EXEC) OrderBackup::ResetOfUser(tile == 0 ? INVALID_TILE : tile, user_id);
|
||||
assert(Depot::IsValidID(depot_id));
|
||||
if (flags & DC_EXEC) OrderBackup::ResetOfUser(depot_id, user_id);
|
||||
|
||||
return CommandCost();
|
||||
}
|
||||
|
@ -173,18 +178,18 @@ CommandCost CmdClearOrderBackup(DoCommandFlag flags, TileIndex tile, ClientID us
|
|||
/* If it's not a backup of us, ignore it. */
|
||||
if (ob->user != user) continue;
|
||||
|
||||
Command<CMD_CLEAR_ORDER_BACKUP>::Post(0, static_cast<ClientID>(user));
|
||||
Command<CMD_CLEAR_ORDER_BACKUP>::Post(ob->depot_id, static_cast<ClientID>(user));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the OrderBackups from GUI/game logic.
|
||||
* @param t The tile of the order backup.
|
||||
* @param depot_id The index of the depot associated to the order backups.
|
||||
* @param from_gui Whether the call came from the GUI, i.e. whether
|
||||
* it must be synced over the network.
|
||||
*/
|
||||
/* static */ void OrderBackup::Reset(TileIndex t, bool from_gui)
|
||||
/* static */ void OrderBackup::Reset(DepotID depot_id, bool from_gui)
|
||||
{
|
||||
/* The user has CLIENT_ID_SERVER as default when network play is not active,
|
||||
* but compiled it. A network client has its own variable for the unique
|
||||
|
@ -195,16 +200,16 @@ CommandCost CmdClearOrderBackup(DoCommandFlag flags, TileIndex tile, ClientID us
|
|||
for (OrderBackup *ob : OrderBackup::Iterate()) {
|
||||
/* If this is a GUI action, and it's not a backup of us, ignore it. */
|
||||
if (from_gui && ob->user != user) continue;
|
||||
/* If it's not for our chosen tile either, ignore it. */
|
||||
if (t != INVALID_TILE && t != ob->tile) continue;
|
||||
/* If it's not for our chosen depot either, ignore it. */
|
||||
if (depot_id != INVALID_DEPOT && depot_id != ob->depot_id) continue;
|
||||
|
||||
if (from_gui) {
|
||||
/* We need to circumvent the "prevention" from this command being executed
|
||||
* while the game is paused, so use the internal method. Nor do we want
|
||||
* this command to get its cost estimated when shift is pressed. */
|
||||
Command<CMD_CLEAR_ORDER_BACKUP>::Unsafe<CommandCallback>(STR_NULL, nullptr, true, false, ob->tile, CommandTraits<CMD_CLEAR_ORDER_BACKUP>::Args{ ob->tile, static_cast<ClientID>(user) });
|
||||
Command<CMD_CLEAR_ORDER_BACKUP>::Unsafe<CommandCallback>(STR_NULL, nullptr, true, false, ob->depot_id, CommandTraits<CMD_CLEAR_ORDER_BACKUP>::Args{ ob->depot_id, static_cast<ClientID>(user) });
|
||||
} else {
|
||||
/* The command came from the game logic, i.e. the clearing of a tile.
|
||||
/* The command came from the game logic, i.e. the clearing of a depot.
|
||||
* In that case we have no need to actually sync this, just do it. */
|
||||
delete ob;
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include "vehicle_type.h"
|
||||
#include "base_consist.h"
|
||||
#include "saveload/saveload.h"
|
||||
#include "depot_type.h"
|
||||
|
||||
/** Unique identifier for an order backup. */
|
||||
typedef uint8_t OrderBackupID;
|
||||
|
@ -35,7 +36,7 @@ private:
|
|||
friend SaveLoadTable GetOrderBackupDescription(); ///< Saving and loading of order backups.
|
||||
friend struct BKORChunkHandler; ///< Creating empty orders upon savegame loading.
|
||||
uint32_t user; ///< The user that requested the backup.
|
||||
TileIndex tile; ///< Tile of the depot where the order was changed.
|
||||
DepotID depot_id; ///< Depot where the order was changed.
|
||||
GroupID group; ///< The group the vehicle was part of.
|
||||
|
||||
const Vehicle *clone; ///< Vehicle this vehicle was a clone of.
|
||||
|
@ -53,9 +54,9 @@ public:
|
|||
static void Backup(const Vehicle *v, uint32_t user);
|
||||
static void Restore(Vehicle *v, uint32_t user);
|
||||
|
||||
static void ResetOfUser(TileIndex tile, uint32_t user);
|
||||
static void ResetOfUser(DepotID depot_id, uint32_t user);
|
||||
static void ResetUser(uint32_t user);
|
||||
static void Reset(TileIndex tile = INVALID_TILE, bool from_gui = true);
|
||||
static void Reset(DepotID depot = INVALID_DEPOT, bool from_gui = true);
|
||||
|
||||
static void ClearGroup(GroupID group);
|
||||
static void ClearVehicle(const Vehicle *v);
|
||||
|
|
|
@ -21,7 +21,7 @@ CommandCost CmdInsertOrder(DoCommandFlag flags, VehicleID veh, VehicleOrderID se
|
|||
CommandCost CmdOrderRefit(DoCommandFlag flags, VehicleID veh, VehicleOrderID order_number, CargoID cargo);
|
||||
CommandCost CmdCloneOrder(DoCommandFlag flags, CloneOptions action, VehicleID veh_dst, VehicleID veh_src);
|
||||
CommandCost CmdMoveOrder(DoCommandFlag flags, VehicleID veh, VehicleOrderID moving_order, VehicleOrderID target_order);
|
||||
CommandCost CmdClearOrderBackup(DoCommandFlag flags, TileIndex tile, ClientID user_id);
|
||||
CommandCost CmdClearOrderBackup(DoCommandFlag flags, DepotID depot_id, ClientID user_id);
|
||||
|
||||
DEF_CMD_TRAIT(CMD_MODIFY_ORDER, CmdModifyOrder, CMD_LOCATION, CMDT_ROUTE_MANAGEMENT)
|
||||
DEF_CMD_TRAIT(CMD_SKIP_TO_ORDER, CmdSkipToOrder, CMD_LOCATION, CMDT_ROUTE_MANAGEMENT)
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include "../order_backup.h"
|
||||
#include "../settings_type.h"
|
||||
#include "../network/network.h"
|
||||
#include "../depot_map.h"
|
||||
|
||||
#include "../safeguards.h"
|
||||
|
||||
|
@ -243,11 +244,14 @@ struct ORDLChunkHandler : ChunkHandler {
|
|||
}
|
||||
};
|
||||
|
||||
static TileIndex _tile;
|
||||
|
||||
SaveLoadTable GetOrderBackupDescription()
|
||||
{
|
||||
static const SaveLoad _order_backup_desc[] = {
|
||||
SLE_VAR(OrderBackup, user, SLE_UINT32),
|
||||
SLE_VAR(OrderBackup, tile, SLE_UINT32),
|
||||
SLEG_CONDVAR("tile", _tile, SLE_UINT32, SL_MIN_VERSION, SLV_DEPOTID_BACKUP_ORDERS),
|
||||
SLE_CONDVAR(OrderBackup, depot_id, SLE_UINT16, SLV_DEPOTID_BACKUP_ORDERS, SL_MAX_VERSION),
|
||||
SLE_VAR(OrderBackup, group, SLE_UINT16),
|
||||
SLE_CONDVAR(OrderBackup, service_interval, SLE_FILE_U32 | SLE_VAR_U16, SL_MIN_VERSION, SLV_192),
|
||||
SLE_CONDVAR(OrderBackup, service_interval, SLE_UINT16, SLV_192, SL_MAX_VERSION),
|
||||
|
@ -297,6 +301,8 @@ struct BKORChunkHandler : ChunkHandler {
|
|||
OrderBackup *ob = new (index) OrderBackup();
|
||||
SlObject(ob, slt);
|
||||
}
|
||||
|
||||
if (IsSavegameVersionBefore(SLV_DEPOTID_BACKUP_ORDERS)) _order_backup_pool.CleanPool();
|
||||
}
|
||||
|
||||
void FixPointers() const override
|
||||
|
|
|
@ -386,6 +386,7 @@ enum SaveLoadVersion : uint16_t {
|
|||
SLV_ADD_DEPOTS_TO_HANGARS, ///< 339 PR#10691 Add depots to airports that have a hangar.
|
||||
|
||||
SLV_DEPOTID_IN_HANGAR_ORDERS, ///< 340 PR#10691 Go to hangar orders store the DepotID instead of StationID.
|
||||
SLV_DEPOTID_BACKUP_ORDERS, ///< 341 PR#XXXXX Backup orders are indexed through DepotIDs.
|
||||
|
||||
SL_MAX_VERSION, ///< Highest possible saveload version
|
||||
};
|
||||
|
|
|
@ -2679,10 +2679,6 @@ static CommandCost RemoveAirport(TileIndex tile, DoCommandFlag flags)
|
|||
}
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
for (uint i = 0; i < st->airport.GetNumHangars(); ++i) {
|
||||
TileIndex tile_cur = st->airport.GetHangarTile(i);
|
||||
OrderBackup::Reset(tile_cur, false);
|
||||
}
|
||||
st->airport.RemoveHangar();
|
||||
|
||||
/* The noise level is the noise from the airport and reduce it to account for the distance to the town center.
|
||||
|
|
Loading…
Reference in New Issue