1
0
Fork 0

Codechange: make TownID an enum

pull/13512/head
Rubidium 2025-01-19 15:18:47 +01:00 committed by rubidium42
parent cda9c2759e
commit cd4482b5df
9 changed files with 18 additions and 15 deletions

View File

@ -136,7 +136,7 @@ inline IndustryID DecodeMonitorIndustry(CargoMonitorID num)
inline TownID DecodeMonitorTown(CargoMonitorID num) inline TownID DecodeMonitorTown(CargoMonitorID num)
{ {
if (MonitorMonitorsIndustry(num)) return INVALID_TOWN; if (MonitorMonitorsIndustry(num)) return INVALID_TOWN;
return GB(num, CCB_TOWN_IND_NUMBER_START, CCB_TOWN_IND_NUMBER_LENGTH); return static_cast<TownID>(GB(num, CCB_TOWN_IND_NUMBER_START, CCB_TOWN_IND_NUMBER_LENGTH));
} }
void ClearCargoPickupMonitoring(CompanyID company = INVALID_OWNER); void ClearCargoPickupMonitoring(CompanyID company = INVALID_OWNER);

View File

@ -1008,7 +1008,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, 0); SetTownIndex(t, TOWN_BEGIN);
} }
break; break;
@ -1232,7 +1232,7 @@ bool AfterLoadGame()
GetRailType(t) GetRailType(t)
); );
} else { } else {
TownID town = IsTileOwner(t, OWNER_TOWN) ? ClosestTownFromTile(t, UINT_MAX)->index : 0; TownID town = IsTileOwner(t, OWNER_TOWN) ? ClosestTownFromTile(t, UINT_MAX)->index : TOWN_BEGIN;
/* MakeRoadNormal */ /* MakeRoadNormal */
SetTileType(t, MP_ROAD); SetTileType(t, MP_ROAD);

View File

@ -36,7 +36,7 @@
return (type == GT_NONE && destination == 0) || return (type == GT_NONE && destination == 0) ||
(type == GT_TILE && ScriptMap::IsValidTile(::TileIndex(destination))) || (type == GT_TILE && ScriptMap::IsValidTile(::TileIndex(destination))) ||
(type == GT_INDUSTRY && ScriptIndustry::IsValidIndustry(destination)) || (type == GT_INDUSTRY && ScriptIndustry::IsValidIndustry(destination)) ||
(type == GT_TOWN && ScriptTown::IsValidTown(destination)) || (type == GT_TOWN && ScriptTown::IsValidTown(static_cast<TownID>(destination))) ||
(type == GT_COMPANY && ScriptCompany::ResolveCompanyID(ScriptCompany::ToScriptCompanyID(static_cast<::CompanyID>(destination))) != ScriptCompany::COMPANY_INVALID) || (type == GT_COMPANY && ScriptCompany::ResolveCompanyID(ScriptCompany::ToScriptCompanyID(static_cast<::CompanyID>(destination))) != ScriptCompany::COMPANY_INVALID) ||
(type == GT_STORY_PAGE && story_page != nullptr && (c == INVALID_COMPANY ? story_page->company == INVALID_COMPANY : story_page->company == INVALID_COMPANY || story_page->company == c)); (type == GT_STORY_PAGE && story_page != nullptr && (c == INVALID_COMPANY ? story_page->company == INVALID_COMPANY : story_page->company == INVALID_COMPANY || story_page->company == c));
} }

View File

@ -34,7 +34,7 @@
(ref_type == NR_TILE && ScriptMap::IsValidTile(::TileIndex(reference))) || (ref_type == NR_TILE && ScriptMap::IsValidTile(::TileIndex(reference))) ||
(ref_type == NR_STATION && ScriptStation::IsValidStation(reference)) || (ref_type == NR_STATION && ScriptStation::IsValidStation(reference)) ||
(ref_type == NR_INDUSTRY && ScriptIndustry::IsValidIndustry(reference)) || (ref_type == NR_INDUSTRY && ScriptIndustry::IsValidIndustry(reference)) ||
(ref_type == NR_TOWN && ScriptTown::IsValidTown(reference))); (ref_type == NR_TOWN && ScriptTown::IsValidTown(static_cast<TownID>(reference))));
::CompanyID c = ScriptCompany::FromScriptCompanyID(company); ::CompanyID c = ScriptCompany::FromScriptCompanyID(company);

View File

@ -37,8 +37,8 @@
EnforcePrecondition(false, ScriptCargo::IsValidCargo(cargo_type)); EnforcePrecondition(false, ScriptCargo::IsValidCargo(cargo_type));
EnforcePrecondition(false, from_type == SPT_INDUSTRY || from_type == SPT_TOWN); EnforcePrecondition(false, from_type == SPT_INDUSTRY || from_type == SPT_TOWN);
EnforcePrecondition(false, to_type == SPT_INDUSTRY || to_type == SPT_TOWN); EnforcePrecondition(false, to_type == SPT_INDUSTRY || to_type == SPT_TOWN);
EnforcePrecondition(false, (from_type == SPT_INDUSTRY && ScriptIndustry::IsValidIndustry(from_id)) || (from_type == SPT_TOWN && ScriptTown::IsValidTown(from_id))); EnforcePrecondition(false, (from_type == SPT_INDUSTRY && ScriptIndustry::IsValidIndustry(from_id)) || (from_type == SPT_TOWN && ScriptTown::IsValidTown(static_cast<TownID>(from_id))));
EnforcePrecondition(false, (to_type == SPT_INDUSTRY && ScriptIndustry::IsValidIndustry(to_id)) || (to_type == SPT_TOWN && ScriptTown::IsValidTown(to_id))); EnforcePrecondition(false, (to_type == SPT_INDUSTRY && ScriptIndustry::IsValidIndustry(to_id)) || (to_type == SPT_TOWN && ScriptTown::IsValidTown(static_cast<TownID>(to_id))));
Source from{static_cast<SourceID>(from_id), static_cast<SourceType>(from_type)}; Source from{static_cast<SourceID>(from_id), static_cast<SourceType>(from_type)};
Source to{static_cast<SourceID>(to_id), static_cast<SourceType>(to_type)}; Source to{static_cast<SourceID>(to_id), static_cast<SourceType>(to_type)};

View File

@ -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, 64000> TownPool; typedef Pool<Town, TownID, 64, TOWN_END> TownPool;
extern TownPool _town_pool; extern TownPool _town_pool;
/** Data structure with cached data of towns. */ /** Data structure with cached data of towns. */

View File

@ -326,7 +326,7 @@ public:
} }
case WID_TA_EXECUTE: case WID_TA_EXECUTE:
Command<CMD_DO_TOWN_ACTION>::Post(STR_ERROR_CAN_T_DO_THIS, this->town->xy, this->window_number, this->sel_index); Command<CMD_DO_TOWN_ACTION>::Post(STR_ERROR_CAN_T_DO_THIS, this->town->xy, static_cast<TownID>(this->window_number), this->sel_index);
break; break;
} }
} }
@ -521,12 +521,12 @@ public:
break; break;
case WID_TV_EXPAND: { // expand town - only available on Scenario editor case WID_TV_EXPAND: { // expand town - only available on Scenario editor
Command<CMD_EXPAND_TOWN>::Post(STR_ERROR_CAN_T_EXPAND_TOWN, this->window_number, 0); Command<CMD_EXPAND_TOWN>::Post(STR_ERROR_CAN_T_EXPAND_TOWN, static_cast<TownID>(this->window_number), 0);
break; break;
} }
case WID_TV_DELETE: // delete town - only available on Scenario editor case WID_TV_DELETE: // delete town - only available on Scenario editor
Command<CMD_DELETE_TOWN>::Post(STR_ERROR_TOWN_CAN_T_DELETE, this->window_number); Command<CMD_DELETE_TOWN>::Post(STR_ERROR_TOWN_CAN_T_DELETE, static_cast<TownID>(this->window_number));
break; break;
} }
} }
@ -615,7 +615,7 @@ public:
{ {
if (!str.has_value()) return; if (!str.has_value()) return;
Command<CMD_RENAME_TOWN>::Post(STR_ERROR_CAN_T_RENAME_TOWN, this->window_number, *str); Command<CMD_RENAME_TOWN>::Post(STR_ERROR_CAN_T_RENAME_TOWN, static_cast<TownID>(this->window_number), *str);
} }
IntervalTimer<TimerGameCalendar> daily_interval = {{TimerGameCalendar::DAY, TimerGameCalendar::Priority::NONE}, [this](auto) { IntervalTimer<TimerGameCalendar> daily_interval = {{TimerGameCalendar::DAY, TimerGameCalendar::Priority::NONE}, [this](auto) {

View File

@ -23,7 +23,7 @@
inline TownID GetTownIndex(Tile t) inline TownID GetTownIndex(Tile t)
{ {
assert(IsTileType(t, MP_HOUSE) || (IsTileType(t, MP_ROAD) && !IsRoadDepot(t))); assert(IsTileType(t, MP_HOUSE) || (IsTileType(t, MP_ROAD) && !IsRoadDepot(t)));
return t.m2(); return static_cast<TownID>(t.m2());
} }
/** /**

View File

@ -12,8 +12,11 @@
#include "core/enum_type.hpp" #include "core/enum_type.hpp"
typedef uint16_t TownID; enum TownID : uint16_t {
static const TownID INVALID_TOWN = 0xFFFF; TOWN_BEGIN = 0,
TOWN_END = 64000,
INVALID_TOWN = 0xFFFF
};
struct Town; struct Town;