mirror of https://github.com/OpenTTD/OpenTTD
Codechange: strongly type TownID
parent
d3408a4542
commit
1003967267
|
@ -81,7 +81,7 @@ inline CargoMonitorID EncodeCargoTownMonitor(CompanyID company, CargoType ctype,
|
||||||
assert(company < (1 << CCB_COMPANY_LENGTH));
|
assert(company < (1 << CCB_COMPANY_LENGTH));
|
||||||
|
|
||||||
uint32_t ret = 0;
|
uint32_t ret = 0;
|
||||||
SB(ret, CCB_TOWN_IND_NUMBER_START, CCB_TOWN_IND_NUMBER_LENGTH, town);
|
SB(ret, CCB_TOWN_IND_NUMBER_START, CCB_TOWN_IND_NUMBER_LENGTH, town.base());
|
||||||
SB(ret, CCB_CARGO_TYPE_START, CCB_CARGO_TYPE_LENGTH, ctype);
|
SB(ret, CCB_CARGO_TYPE_START, CCB_CARGO_TYPE_LENGTH, ctype);
|
||||||
SB(ret, CCB_COMPANY_START, CCB_COMPANY_LENGTH, company.base());
|
SB(ret, CCB_COMPANY_START, CCB_COMPANY_LENGTH, company.base());
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -170,7 +170,7 @@ static uint32_t GetCountAndDistanceOfClosestInstance(uint8_t param_setID, uint8_
|
||||||
case 0x81: return GB(this->tile.base(), 8, 8);
|
case 0x81: return GB(this->tile.base(), 8, 8);
|
||||||
|
|
||||||
/* Pointer to the town the industry is associated with */
|
/* Pointer to the town the industry is associated with */
|
||||||
case 0x82: return this->industry->town->index;
|
case 0x82: return this->industry->town->index.base();
|
||||||
case 0x83:
|
case 0x83:
|
||||||
case 0x84:
|
case 0x84:
|
||||||
case 0x85: Debug(grf, 0, "NewGRFs shouldn't be doing pointer magic"); break; // not supported
|
case 0x85: Debug(grf, 0, "NewGRFs shouldn't be doing pointer magic"); break; // not supported
|
||||||
|
@ -357,7 +357,7 @@ static uint32_t GetCountAndDistanceOfClosestInstance(uint8_t param_setID, uint8_
|
||||||
case 0x80: return this->industry->location.tile.base();
|
case 0x80: return this->industry->location.tile.base();
|
||||||
case 0x81: return GB(this->industry->location.tile.base(), 8, 8);
|
case 0x81: return GB(this->industry->location.tile.base(), 8, 8);
|
||||||
/* Pointer to the town the industry is associated with */
|
/* Pointer to the town the industry is associated with */
|
||||||
case 0x82: return this->industry->town->index;
|
case 0x82: return this->industry->town->index.base();
|
||||||
case 0x83:
|
case 0x83:
|
||||||
case 0x84:
|
case 0x84:
|
||||||
case 0x85: Debug(grf, 0, "NewGRFs shouldn't be doing pointer magic"); break; // not supported
|
case 0x85: Debug(grf, 0, "NewGRFs shouldn't be doing pointer magic"); break; // not supported
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* Town index */
|
/* Town index */
|
||||||
case 0x41: return this->t->index;
|
case 0x41: return this->t->index.base();
|
||||||
|
|
||||||
/* Get a variable from the persistent storage */
|
/* Get a variable from the persistent storage */
|
||||||
case 0x7C: {
|
case 0x7C: {
|
||||||
|
|
|
@ -923,7 +923,7 @@ uint32_t SerialiseNewsReference(const NewsReference &reference)
|
||||||
uint32_t operator()(const VehicleID v) { return v; }
|
uint32_t operator()(const VehicleID v) { return v; }
|
||||||
uint32_t operator()(const StationID s) { return s; }
|
uint32_t operator()(const StationID s) { return s; }
|
||||||
uint32_t operator()(const IndustryID i) { return i.base(); }
|
uint32_t operator()(const IndustryID i) { return i.base(); }
|
||||||
uint32_t operator()(const TownID t) { return t; }
|
uint32_t operator()(const TownID t) { return t.base(); }
|
||||||
uint32_t operator()(const EngineID e) { return e.base(); }
|
uint32_t operator()(const EngineID e) { return e.base(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -636,7 +636,7 @@ inline void MakeRoadNormal(Tile t, RoadBits bits, RoadType road_rt, RoadType tra
|
||||||
{
|
{
|
||||||
SetTileType(t, MP_ROAD);
|
SetTileType(t, MP_ROAD);
|
||||||
SetTileOwner(t, road);
|
SetTileOwner(t, road);
|
||||||
t.m2() = town;
|
t.m2() = town.base();
|
||||||
t.m3() = (tram_rt != INVALID_ROADTYPE ? bits : 0);
|
t.m3() = (tram_rt != INVALID_ROADTYPE ? bits : 0);
|
||||||
t.m5() = (road_rt != INVALID_ROADTYPE ? bits : 0) | ROAD_TILE_NORMAL << 6;
|
t.m5() = (road_rt != INVALID_ROADTYPE ? bits : 0) | ROAD_TILE_NORMAL << 6;
|
||||||
SB(t.m6(), 2, 4, 0);
|
SB(t.m6(), 2, 4, 0);
|
||||||
|
@ -661,7 +661,7 @@ inline void MakeRoadCrossing(Tile t, Owner road, Owner tram, Owner rail, Axis ro
|
||||||
{
|
{
|
||||||
SetTileType(t, MP_ROAD);
|
SetTileType(t, MP_ROAD);
|
||||||
SetTileOwner(t, rail);
|
SetTileOwner(t, rail);
|
||||||
t.m2() = town;
|
t.m2() = town.base();
|
||||||
t.m3() = 0;
|
t.m3() = 0;
|
||||||
t.m4() = INVALID_ROADTYPE;
|
t.m4() = INVALID_ROADTYPE;
|
||||||
t.m5() = ROAD_TILE_CROSSING << 6 | roaddir;
|
t.m5() = ROAD_TILE_CROSSING << 6 | roaddir;
|
||||||
|
|
|
@ -1010,7 +1010,7 @@ bool AfterLoadGame()
|
||||||
if ((GB(t.m5(), 4, 2) == ROAD_TILE_CROSSING ? (Owner)t.m3() : GetTileOwner(t)) == OWNER_TOWN) {
|
if ((GB(t.m5(), 4, 2) == ROAD_TILE_CROSSING ? (Owner)t.m3() : GetTileOwner(t)) == OWNER_TOWN) {
|
||||||
SetTownIndex(t, CalcClosestTownFromTile(t)->index);
|
SetTownIndex(t, CalcClosestTownFromTile(t)->index);
|
||||||
} else {
|
} else {
|
||||||
SetTownIndex(t, TOWN_BEGIN);
|
SetTownIndex(t, TownID::Begin());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -1234,11 +1234,11 @@ bool AfterLoadGame()
|
||||||
GetRailType(t)
|
GetRailType(t)
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
TownID town = IsTileOwner(t, OWNER_TOWN) ? ClosestTownFromTile(t, UINT_MAX)->index : TOWN_BEGIN;
|
TownID town = IsTileOwner(t, OWNER_TOWN) ? ClosestTownFromTile(t, UINT_MAX)->index : TownID::Begin();
|
||||||
|
|
||||||
/* MakeRoadNormal */
|
/* MakeRoadNormal */
|
||||||
SetTileType(t, MP_ROAD);
|
SetTileType(t, MP_ROAD);
|
||||||
t.m2() = town;
|
t.m2() = town.base();
|
||||||
t.m3() = 0;
|
t.m3() = 0;
|
||||||
t.m5() = (axis == AXIS_X ? ROAD_Y : ROAD_X) | ROAD_TILE_NORMAL << 6;
|
t.m5() = (axis == AXIS_X ? ROAD_Y : ROAD_X) | ROAD_TILE_NORMAL << 6;
|
||||||
SB(t.m6(), 2, 4, 0);
|
SB(t.m6(), 2, 4, 0);
|
||||||
|
@ -1626,7 +1626,7 @@ bool AfterLoadGame()
|
||||||
if (IsSavegameVersionBefore(SLV_52)) {
|
if (IsSavegameVersionBefore(SLV_52)) {
|
||||||
for (auto t : Map::Iterate()) {
|
for (auto t : Map::Iterate()) {
|
||||||
if (IsTileType(t, MP_OBJECT) && t.m5() == OBJECT_STATUE) {
|
if (IsTileType(t, MP_OBJECT) && t.m5() == OBJECT_STATUE) {
|
||||||
t.m2() = CalcClosestTownFromTile(t)->index;
|
t.m2() = CalcClosestTownFromTile(t)->index.base();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,7 @@ struct DEPTChunkHandler : ChunkHandler {
|
||||||
SlObject(depot, slt);
|
SlObject(depot, slt);
|
||||||
|
|
||||||
/* Set the town 'pointer' so we can restore it later. */
|
/* Set the town 'pointer' so we can restore it later. */
|
||||||
if (IsSavegameVersionBefore(SLV_141)) depot->town = (Town *)(size_t)_town_index;
|
if (IsSavegameVersionBefore(SLV_141)) depot->town = reinterpret_cast<Town *>(static_cast<size_t>(_town_index.base()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ static const uint TOWN_GROWTH_DESERT = 0xFFFFFFFF; ///< The town needs the cargo
|
||||||
static const uint16_t TOWN_GROWTH_RATE_NONE = 0xFFFF; ///< Special value for Town::growth_rate to disable town growth.
|
static const uint16_t TOWN_GROWTH_RATE_NONE = 0xFFFF; ///< Special value for Town::growth_rate to disable town growth.
|
||||||
static const uint16_t MAX_TOWN_GROWTH_TICKS = 930; ///< Max amount of original town ticks that still fit into uint16_t, about equal to UINT16_MAX / TOWN_GROWTH_TICKS but slightly less to simplify calculations
|
static const uint16_t MAX_TOWN_GROWTH_TICKS = 930; ///< Max amount of original town ticks that still fit into uint16_t, about equal to UINT16_MAX / TOWN_GROWTH_TICKS but slightly less to simplify calculations
|
||||||
|
|
||||||
typedef Pool<Town, TownID, 64, TOWN_END> TownPool;
|
typedef Pool<Town, TownID, 64, TownID::End().base()> TownPool;
|
||||||
extern TownPool _town_pool;
|
extern TownPool _town_pool;
|
||||||
|
|
||||||
/** Data structure with cached data of towns. */
|
/** Data structure with cached data of towns. */
|
||||||
|
|
|
@ -35,7 +35,7 @@ inline TownID GetTownIndex(Tile t)
|
||||||
inline void SetTownIndex(Tile t, TownID index)
|
inline void SetTownIndex(Tile t, TownID index)
|
||||||
{
|
{
|
||||||
assert(IsTileType(t, MP_HOUSE) || (IsTileType(t, MP_ROAD) && !IsRoadDepot(t)));
|
assert(IsTileType(t, MP_HOUSE) || (IsTileType(t, MP_ROAD) && !IsRoadDepot(t)));
|
||||||
t.m2() = index;
|
t.m2() = index.base();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -378,7 +378,7 @@ inline void MakeHouseTile(Tile t, TownID tid, uint8_t counter, uint8_t stage, Ho
|
||||||
|
|
||||||
SetTileType(t, MP_HOUSE);
|
SetTileType(t, MP_HOUSE);
|
||||||
t.m1() = random_bits;
|
t.m1() = random_bits;
|
||||||
t.m2() = tid;
|
t.m2() = tid.base();
|
||||||
t.m3() = 0;
|
t.m3() = 0;
|
||||||
SetHouseType(t, type);
|
SetHouseType(t, type);
|
||||||
SetHouseCompleted(t, stage == TOWN_HOUSE_COMPLETED);
|
SetHouseCompleted(t, stage == TOWN_HOUSE_COMPLETED);
|
||||||
|
|
|
@ -11,12 +11,10 @@
|
||||||
#define TOWN_TYPE_H
|
#define TOWN_TYPE_H
|
||||||
|
|
||||||
#include "core/enum_type.hpp"
|
#include "core/enum_type.hpp"
|
||||||
|
#include "core/pool_type.hpp"
|
||||||
|
|
||||||
enum TownID : uint16_t {
|
using TownID = PoolID<uint16_t, struct TownIDTag, 64000, 0xFFFF>;
|
||||||
TOWN_BEGIN = 0,
|
static constexpr TownID INVALID_TOWN = TownID::Invalid();
|
||||||
TOWN_END = 64000,
|
|
||||||
INVALID_TOWN = 0xFFFF
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Town;
|
struct Town;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue