1
0
Fork 0

Codechange: strongly type DepotID

pull/13512/head
Rubidium 2025-02-07 16:45:45 +01:00 committed by rubidium42
parent d55b9cff9d
commit 798e9f229c
8 changed files with 12 additions and 9 deletions

View File

@ -14,7 +14,7 @@
#include "core/pool_type.hpp"
#include "timer/timer_game_calendar.h"
typedef Pool<Depot, DepotID, 64, 64000> DepotPool;
typedef Pool<Depot, DepotID, 64, DepotID::End().base()> DepotPool;
extern DepotPool _depot_pool;
struct Depot : DepotPool::PoolItem<&_depot_pool> {

View File

@ -54,7 +54,7 @@ inline DepotID GetDepotIndex(Tile t)
{
/* Hangars don't have a Depot class, thus store no DepotID. */
assert(IsRailDepotTile(t) || IsRoadDepotTile(t) || IsShipDepotTile(t));
return t.m2();
return DepotID{t.m2()};
}
/**

View File

@ -10,10 +10,12 @@
#ifndef DEPOT_TYPE_H
#define DEPOT_TYPE_H
typedef uint16_t DepotID; ///< Type for the unique identifier of depots.
#include "core/pool_type.hpp"
using DepotID = PoolID<uint16_t, struct DepotIDTag, 64000, 0xFFFF>; ///< Type for the unique identifier of depots.
struct Depot;
static const DepotID INVALID_DEPOT = UINT16_MAX;
static constexpr DepotID INVALID_DEPOT = DepotID::Invalid();
static const uint MAX_LENGTH_DEPOT_NAME_CHARS = 32; ///< The maximum length of a depot name in characters including '\0'

View File

@ -25,6 +25,7 @@ struct DestinationID {
explicit DestinationID() = default;
constexpr DestinationID(size_t index) : value(static_cast<BaseType>(index)) {}
constexpr DestinationID(DepotID depot) : value(depot.base()) {}
constexpr DepotID ToDepotID() const noexcept { return static_cast<DepotID>(this->value); }
constexpr StationID ToStationID() const noexcept { return static_cast<StationID>(this->value); }

View File

@ -554,7 +554,7 @@ inline void MakeRailDepot(Tile tile, Owner owner, DepotID depot_id, DiagDirectio
SetTileType(tile, MP_RAILWAY);
SetTileOwner(tile, owner);
SetDockingTile(tile, false);
tile.m2() = depot_id;
tile.m2() = depot_id.base();
tile.m3() = 0;
tile.m4() = 0;
tile.m5() = RAIL_TILE_DEPOT << 6 | dir;

View File

@ -695,7 +695,7 @@ inline void MakeRoadDepot(Tile tile, Owner owner, DepotID depot_id, DiagDirectio
{
SetTileType(tile, MP_ROAD);
SetTileOwner(tile, owner);
tile.m2() = depot_id;
tile.m2() = depot_id.base();
tile.m3() = 0;
tile.m4() = INVALID_ROADTYPE;
tile.m5() = ROAD_TILE_DEPOT << 6 | dir;

View File

@ -2355,8 +2355,8 @@ bool AfterLoadGame()
d = nullptr;
continue;
}
tile.m2() = d->index;
if (IsTileType(tile, MP_WATER)) Tile(GetOtherShipDepotTile(tile)).m2() = d->index;
tile.m2() = d->index.base();
if (IsTileType(tile, MP_WATER)) Tile(GetOtherShipDepotTile(tile)).m2() = d->index.base();
}
}

View File

@ -461,7 +461,7 @@ inline void MakeShipDepot(Tile t, Owner o, DepotID did, DepotPart part, Axis a,
SetTileOwner(t, o);
SetWaterClass(t, original_water_class);
SetDockingTile(t, false);
t.m2() = did;
t.m2() = did.base();
t.m3() = 0;
t.m4() = 0;
t.m5() = part << WBL_DEPOT_PART | a << WBL_DEPOT_AXIS;