mirror of https://github.com/OpenTTD/OpenTTD
Codechange: make TownID an enum
parent
cda9c2759e
commit
cd4482b5df
|
@ -136,7 +136,7 @@ inline IndustryID DecodeMonitorIndustry(CargoMonitorID num)
|
|||
inline TownID DecodeMonitorTown(CargoMonitorID num)
|
||||
{
|
||||
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);
|
||||
|
|
|
@ -1008,7 +1008,7 @@ bool AfterLoadGame()
|
|||
if ((GB(t.m5(), 4, 2) == ROAD_TILE_CROSSING ? (Owner)t.m3() : GetTileOwner(t)) == OWNER_TOWN) {
|
||||
SetTownIndex(t, CalcClosestTownFromTile(t)->index);
|
||||
} else {
|
||||
SetTownIndex(t, 0);
|
||||
SetTownIndex(t, TOWN_BEGIN);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -1232,7 +1232,7 @@ bool AfterLoadGame()
|
|||
GetRailType(t)
|
||||
);
|
||||
} 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 */
|
||||
SetTileType(t, MP_ROAD);
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
return (type == GT_NONE && destination == 0) ||
|
||||
(type == GT_TILE && ScriptMap::IsValidTile(::TileIndex(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_STORY_PAGE && story_page != nullptr && (c == INVALID_COMPANY ? story_page->company == INVALID_COMPANY : story_page->company == INVALID_COMPANY || story_page->company == c));
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
(ref_type == NR_TILE && ScriptMap::IsValidTile(::TileIndex(reference))) ||
|
||||
(ref_type == NR_STATION && ScriptStation::IsValidStation(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);
|
||||
|
||||
|
|
|
@ -37,8 +37,8 @@
|
|||
EnforcePrecondition(false, ScriptCargo::IsValidCargo(cargo_type));
|
||||
EnforcePrecondition(false, from_type == SPT_INDUSTRY || from_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, (to_type == SPT_INDUSTRY && ScriptIndustry::IsValidIndustry(to_id)) || (to_type == SPT_TOWN && ScriptTown::IsValidTown(to_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(static_cast<TownID>(to_id))));
|
||||
|
||||
Source from{static_cast<SourceID>(from_id), static_cast<SourceType>(from_type)};
|
||||
Source to{static_cast<SourceID>(to_id), static_cast<SourceType>(to_type)};
|
||||
|
|
|
@ -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 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;
|
||||
|
||||
/** Data structure with cached data of towns. */
|
||||
|
|
|
@ -326,7 +326,7 @@ public:
|
|||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -521,12 +521,12 @@ public:
|
|||
break;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -615,7 +615,7 @@ public:
|
|||
{
|
||||
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) {
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
inline TownID GetTownIndex(Tile t)
|
||||
{
|
||||
assert(IsTileType(t, MP_HOUSE) || (IsTileType(t, MP_ROAD) && !IsRoadDepot(t)));
|
||||
return t.m2();
|
||||
return static_cast<TownID>(t.m2());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -12,8 +12,11 @@
|
|||
|
||||
#include "core/enum_type.hpp"
|
||||
|
||||
typedef uint16_t TownID;
|
||||
static const TownID INVALID_TOWN = 0xFFFF;
|
||||
enum TownID : uint16_t {
|
||||
TOWN_BEGIN = 0,
|
||||
TOWN_END = 64000,
|
||||
INVALID_TOWN = 0xFFFF
|
||||
};
|
||||
|
||||
struct Town;
|
||||
|
||||
|
|
Loading…
Reference in New Issue