mirror of https://github.com/OpenTTD/OpenTTD
Codechange: strongly type DepotID
parent
d55b9cff9d
commit
798e9f229c
|
@ -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> {
|
||||
|
|
|
@ -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()};
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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'
|
||||
|
||||
|
|
|
@ -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); }
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue