Codechange: Add base() method to StrongType to allow access to the base type without casting. (#11445)

This removes the ability to explicitly cast to the base type, but the requirement
to use .base() means the conversion is still explicit.
pull/615/head
Peter Nelson 6 months ago committed by GitHub
parent 737775f834
commit ab535c0a86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1186,7 +1186,7 @@ struct BuildVehicleWindow : Window {
{
this->vehicle_type = type;
this->listview_mode = tile == INVALID_TILE;
this->window_number = this->listview_mode ? (int)type : static_cast<uint32_t>(tile);
this->window_number = this->listview_mode ? (int)type : tile.base();
this->sel_engine = INVALID_ENGINE;
@ -1917,7 +1917,7 @@ void ShowBuildVehicleWindow(TileIndex tile, VehicleType type)
* so if tile == INVALID_TILE (Available XXX Window), use 'type' as unique number.
* As it always is a low value, it won't collide with any real tile
* number. */
uint num = (tile == INVALID_TILE) ? (int)type : static_cast<uint32_t>(tile);
uint num = (tile == INVALID_TILE) ? (int)type : tile.base();
assert(IsCompanyBuildableVehicleType(type));

@ -102,7 +102,7 @@ static int32_t ClickChangeDateCheat(int32_t new_value, int32_t)
{
/* Don't allow changing to an invalid year, or the current year. */
auto new_year = Clamp(TimerGameCalendar::Year(new_value), CalendarTime::MIN_YEAR, CalendarTime::MAX_YEAR);
if (new_year == TimerGameCalendar::year) return static_cast<int32_t>(TimerGameCalendar::year);
if (new_year == TimerGameCalendar::year) return TimerGameCalendar::year.base();
TimerGameCalendar::YearMonthDay ymd;
TimerGameCalendar::ConvertDateToYMD(TimerGameCalendar::date, &ymd);
@ -122,7 +122,7 @@ static int32_t ClickChangeDateCheat(int32_t new_value, int32_t)
InvalidateWindowClassesData(WC_TRUCK_STATION, 0);
InvalidateWindowClassesData(WC_BUILD_OBJECT, 0);
ResetSignalVariant();
return static_cast<int32_t>(TimerGameCalendar::year);
return TimerGameCalendar::year.base();
}
/**

@ -389,7 +389,7 @@ set_name:;
SetDParam(1, STR_NEWS_COMPANY_LAUNCH_DESCRIPTION);
SetDParamStr(2, cni->company_name);
SetDParam(3, t->index);
AddNewsItem(STR_MESSAGE_NEWS_FORMAT, NT_COMPANY_INFO, NF_COMPANY, NR_TILE, static_cast<uint32_t>(c->last_build_coordinate), NR_NONE, UINT32_MAX, cni);
AddNewsItem(STR_MESSAGE_NEWS_FORMAT, NT_COMPANY_INFO, NF_COMPANY, NR_TILE, c->last_build_coordinate.base(), NR_NONE, UINT32_MAX, cni);
}
return;
}

@ -432,7 +432,7 @@ struct CompanyFinancesWindow : Window {
auto age = std::min(TimerGameCalendar::year - c->inaugurated_year, TimerGameCalendar::Year(2));
int wid_offset = widget - WID_CF_EXPS_PRICE1;
if (wid_offset <= age) {
DrawYearColumn(r, TimerGameCalendar::year - (age - wid_offset), c->yearly_expenses[static_cast<int32_t>(age - wid_offset)]);
DrawYearColumn(r, TimerGameCalendar::year - (age - wid_offset), c->yearly_expenses[(age - wid_offset).base()]);
}
break;
}

@ -37,7 +37,7 @@ struct fmt::formatter<T, Char, std::enable_if_t<std::is_base_of<StrongTypedefBas
}
fmt::format_context::iterator format(const T &t, format_context &ctx) const {
return parent::format(underlying_type(t), ctx);
return parent::format(t.base(), ctx);
}
};

@ -220,7 +220,7 @@ constexpr To ClampTo(From value)
template <typename To, typename From, std::enable_if_t<std::is_base_of<StrongTypedefBase, From>::value, int> = 0>
constexpr To ClampTo(From value)
{
return ClampTo<To>(static_cast<typename From::BaseType>(value));
return ClampTo<To>(value.base());
}
/**
@ -268,7 +268,7 @@ template <typename T, std::enable_if_t<std::disjunction_v<std::is_convertible<T,
static constexpr inline bool IsInsideMM(const T x, const size_t min, const size_t max) noexcept
{
if constexpr (std::is_base_of_v<StrongTypedefBase, T>) {
return (size_t)(static_cast<typename T::BaseType>(x) - min) < (max - min);
return (size_t)(x.base() - min) < (max - min);
} else {
return (size_t)(x - min) < (max - min);
}

@ -160,10 +160,10 @@ namespace StrongType {
constexpr Typedef &operator =(Typedef &&rhs) { this->value = std::move(rhs.value); return *this; }
constexpr Typedef &operator =(const TBaseType &rhs) { this->value = rhs; return *this; }
/* Only allow explicit conversions to BaseType. */
explicit constexpr operator TBaseType () const { return this->value; }
/* Only allow conversion to BaseType via method. */
constexpr TBaseType base() const { return this->value; }
/* Only allow TProperties classes access to the internal value. Everyone else needs to do an explicit cast. */
/* Only allow TProperties classes access to the internal value. Everyone else needs to call .base(). */
friend struct Compare;
friend struct Integer;
template <typename TCompatibleType> friend struct Compatible;
@ -171,7 +171,7 @@ namespace StrongType {
/* GCC / MSVC don't pick up on the "friend struct" above, where CLang does.
* As in our CI we compile for all three targets, it is sufficient to have one
* that errors on this; but nobody should be using "value" directly. Instead,
* use a static_cast<> to convert to the base type. */
* use base() to convert to the base type. */
#ifdef __clang__
protected:
#endif /* __clang__ */

@ -90,9 +90,9 @@ struct SetDateWindow : Window {
case WID_SD_YEAR:
for (TimerGameCalendar::Year i = this->min_year; i <= this->max_year; i++) {
SetDParam(0, i);
list.push_back(std::make_unique<DropDownListStringItem>(STR_JUST_INT, static_cast<int32_t>(i), false));
list.push_back(std::make_unique<DropDownListStringItem>(STR_JUST_INT, i.base(), false));
}
selected = static_cast<int32_t>(this->date.year);
selected = this->date.year.base();
break;
}

@ -358,7 +358,7 @@ static bool DisasterTick_Ufo(DisasterVehicle *v)
return true;
} else {
/* Target a vehicle */
RoadVehicle *u = RoadVehicle::Get(static_cast<uint32_t>(v->dest_tile));
RoadVehicle *u = RoadVehicle::Get(v->dest_tile.base());
assert(u != nullptr && u->type == VEH_ROAD && u->IsFrontEngine());
uint dist = Delta(v->x_pos, u->x_pos) + Delta(v->y_pos, u->y_pos);
@ -437,7 +437,7 @@ static bool DisasterTick_Aircraft(DisasterVehicle *v, uint16_t image_override, b
if (v->state == 2) {
if (GB(v->tick_counter, 0, 2) == 0) {
Industry *i = Industry::Get(static_cast<uint32_t>(v->dest_tile)); // Industry destructor calls ReleaseDisastersTargetingIndustry, so this is valid
Industry *i = Industry::Get(v->dest_tile.base()); // Industry destructor calls ReleaseDisastersTargetingIndustry, so this is valid
int x = TileX(i->location.tile) * TILE_SIZE;
int y = TileY(i->location.tile) * TILE_SIZE;
uint32_t r = Random();
@ -455,7 +455,7 @@ static bool DisasterTick_Aircraft(DisasterVehicle *v, uint16_t image_override, b
v->state = 2;
v->age = 0;
Industry *i = Industry::Get(static_cast<uint32_t>(v->dest_tile)); // Industry destructor calls ReleaseDisastersTargetingIndustry, so this is valid
Industry *i = Industry::Get(v->dest_tile.base()); // Industry destructor calls ReleaseDisastersTargetingIndustry, so this is valid
DestructIndustry(i);
SetDParam(0, i->town->index);

@ -928,7 +928,7 @@ void StartupEconomy()
if (_settings_game.economy.inflation) {
/* Apply inflation that happened before our game start year. */
int months = static_cast<int32_t>(std::min(TimerGameCalendar::year, CalendarTime::ORIGINAL_MAX_YEAR) - CalendarTime::ORIGINAL_BASE_YEAR) * 12;
int months = (std::min(TimerGameCalendar::year, CalendarTime::ORIGINAL_MAX_YEAR) - CalendarTime::ORIGINAL_BASE_YEAR).base() * 12;
for (int i = 0; i < months; i++) {
AddInflation(false);
}

@ -439,7 +439,7 @@ uint Engine::GetDisplayMaxTractiveEffort() const
TimerGameCalendar::Date Engine::GetLifeLengthInDays() const
{
/* Assume leap years; this gives the player a bit more than the given amount of years, but never less. */
return static_cast<int32_t>(this->info.lifelength + _settings_game.vehicle.extend_vehicle_life) * CalendarTime::DAYS_IN_LEAP_YEAR;
return (this->info.lifelength + _settings_game.vehicle.extend_vehicle_life).base() * CalendarTime::DAYS_IN_LEAP_YEAR;
}
/**
@ -664,7 +664,7 @@ void SetYearEngineAgingStops()
/* Base year ending date on half the model life */
TimerGameCalendar::YearMonthDay ymd;
TimerGameCalendar::ConvertDateToYMD(ei->base_intro + (static_cast<int32_t>(ei->lifelength) * CalendarTime::DAYS_IN_LEAP_YEAR) / 2, &ymd);
TimerGameCalendar::ConvertDateToYMD(ei->base_intro + (ei->lifelength.base() * CalendarTime::DAYS_IN_LEAP_YEAR) / 2, &ymd);
_year_engine_aging_stops = std::max(_year_engine_aging_stops, ymd.year);
}
@ -690,7 +690,7 @@ void StartupOneEngine(Engine *e, TimerGameCalendar::Date aging_date, uint32_t se
SavedRandomSeeds saved_seeds;
SaveRandomSeeds(&saved_seeds);
SetRandomSeed(_settings_game.game_creation.generation_seed ^ seed ^
static_cast<int32_t>(ei->base_intro) ^
ei->base_intro.base() ^
e->type ^
e->GetGRFID());
uint32_t r = Random();
@ -700,7 +700,7 @@ void StartupOneEngine(Engine *e, TimerGameCalendar::Date aging_date, uint32_t se
* Note: TTDP uses fixed 1922 */
e->intro_date = ei->base_intro <= TimerGameCalendar::ConvertYMDToDate(_settings_game.game_creation.starting_year + 2, 0, 1) ? ei->base_intro : (TimerGameCalendar::Date)GB(r, 0, 9) + ei->base_intro;
if (e->intro_date <= TimerGameCalendar::date) {
e->age = static_cast<int32_t>(aging_date - e->intro_date) >> 5;
e->age = (aging_date - e->intro_date).base() >> 5;
e->company_avail = MAX_UVALUE(CompanyMask);
e->flags |= ENGINE_AVAILABLE;
}
@ -712,8 +712,8 @@ void StartupOneEngine(Engine *e, TimerGameCalendar::Date aging_date, uint32_t se
}
SetRandomSeed(_settings_game.game_creation.generation_seed ^ seed ^
(re->index << 16) ^ (static_cast<int32_t>(re->info.base_intro) << 12) ^ (re->info.decay_speed << 8) ^
(static_cast<int32_t>(re->info.lifelength) << 4) ^ re->info.retire_early ^
(re->index << 16) ^ (re->info.base_intro.base() << 12) ^ (re->info.decay_speed << 8) ^
(re->info.lifelength.base() << 4) ^ re->info.retire_early ^
e->type ^
e->GetGRFID());
@ -724,7 +724,7 @@ void StartupOneEngine(Engine *e, TimerGameCalendar::Date aging_date, uint32_t se
r = Random();
e->reliability_final = GB(r, 16, 14) + 0x3FFF;
e->duration_phase_1 = GB(r, 0, 5) + 7;
e->duration_phase_2 = GB(r, 5, 4) + static_cast<int32_t>(ei->base_life) * 12 - 96;
e->duration_phase_2 = GB(r, 5, 4) + ei->base_life.base() * 12 - 96;
e->duration_phase_3 = GB(r, 9, 7) + 120;
RestoreRandomSeeds(saved_seeds);

@ -962,7 +962,7 @@ struct GenerateLandscapeWindow : public Window {
/* An empty string means revert to the default */
switch (this->widget_id) {
case WID_GL_HEIGHTMAP_HEIGHT_TEXT: value = MAP_HEIGHT_LIMIT_AUTO_MINIMUM; break;
case WID_GL_START_DATE_TEXT: value = static_cast<int32_t>(CalendarTime::DEF_START_YEAR); break;
case WID_GL_START_DATE_TEXT: value = CalendarTime::DEF_START_YEAR.base(); break;
case WID_GL_SNOW_COVERAGE_TEXT: value = DEF_SNOW_COVERAGE; break;
case WID_GL_DESERT_COVERAGE_TEXT: value = DEF_DESERT_COVERAGE; break;
case WID_GL_TOWN_PULLDOWN: value = 1; break;

@ -153,7 +153,7 @@ Industry::~Industry()
for (TileIndex tile_cur : this->location) {
if (IsTileType(tile_cur, MP_INDUSTRY)) {
if (GetIndustryIndex(tile_cur) == this->index) {
DeleteNewGRFInspectWindow(GSF_INDUSTRYTILES, static_cast<uint32_t>(tile_cur));
DeleteNewGRFInspectWindow(GSF_INDUSTRYTILES, tile_cur.base());
/* MakeWaterKeepingClass() can also handle 'land' */
MakeWaterKeepingClass(tile_cur, OWNER_NONE);

@ -787,7 +787,7 @@ void RunTileLoop()
_tile_type_procs[GetTileType(tile)]->tile_loop_proc(tile);
/* Get the next tile in sequence using a Galois LFSR. */
tile = (static_cast<uint32_t>(tile) >> 1) ^ (-(int32_t)(static_cast<uint32_t>(tile) & 1) & feedback);
tile = (tile.base() >> 1) ^ (-(int32_t)(tile.base() & 1) & feedback);
}
_cur_tileloop_tile = tile;
@ -939,7 +939,7 @@ static void CreateDesertOrRainForest(uint desert_tropic_line)
const TileIndexDiffC *data;
for (TileIndex tile = 0; tile != Map::Size(); ++tile) {
if ((static_cast<uint32_t>(tile) % update_freq) == 0) IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
if ((tile.base() % update_freq) == 0) IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
if (!IsValidTile(tile)) continue;
@ -960,7 +960,7 @@ static void CreateDesertOrRainForest(uint desert_tropic_line)
}
for (TileIndex tile = 0; tile != Map::Size(); ++tile) {
if ((static_cast<uint32_t>(tile) % update_freq) == 0) IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
if ((tile.base() % update_freq) == 0) IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
if (!IsValidTile(tile)) continue;

@ -52,7 +52,7 @@ void FlowMapper::Run(LinkGraphJob &job) const
* LinkGraph::Monthly(). */
auto runtime = job.JoinDate() - job.Settings().recalc_time / CalendarTime::SECONDS_PER_DAY - job.LastCompression() + 1;
for (auto &it : flows) {
it.second.ScaleToMonthly(static_cast<int32_t>(runtime));
it.second.ScaleToMonthly(runtime.base());
}
}
/* Clear paths. */

@ -65,7 +65,7 @@ void LinkGraph::ShiftDates(TimerGameCalendar::Date interval)
void LinkGraph::Compress()
{
this->last_compression = static_cast<int32_t>(TimerGameCalendar::date + this->last_compression) / 2;
this->last_compression = (TimerGameCalendar::date + this->last_compression).base() / 2;
for (NodeID node1 = 0; node1 < this->Size(); ++node1) {
this->nodes[node1].supply /= 2;
for (BaseEdge &edge : this->nodes[node1].edges) {

@ -185,7 +185,7 @@ public:
*/
inline static uint Scale(uint val, TimerGameCalendar::Date target_age, TimerGameCalendar::Date orig_age)
{
return val > 0 ? std::max(1U, val * static_cast<int32_t>(target_age) / static_cast<int32_t>(orig_age)) : 0;
return val > 0 ? std::max(1U, val * target_age.base() / orig_age.base()) : 0;
}
/** Bare constructor, only for save/load. */
@ -248,7 +248,7 @@ public:
*/
inline uint Monthly(uint base) const
{
return base * 30 / static_cast<int32_t>(TimerGameCalendar::date - this->last_compression + 1);
return base * 30 / (TimerGameCalendar::date - this->last_compression + 1).base();
}
NodeID AddNode(const Station *st);

@ -178,7 +178,7 @@ void StateGameLoop_LinkGraphPauseControl()
}
} else if (_pause_mode == PM_UNPAUSED &&
TimerGameCalendar::date_fract == LinkGraphSchedule::SPAWN_JOIN_TICK - 2 &&
static_cast<int32_t>(TimerGameCalendar::date) % (_settings_game.linkgraph.recalc_interval / CalendarTime::SECONDS_PER_DAY) == (_settings_game.linkgraph.recalc_interval / CalendarTime::SECONDS_PER_DAY) / 2 &&
TimerGameCalendar::date.base() % (_settings_game.linkgraph.recalc_interval / CalendarTime::SECONDS_PER_DAY) == (_settings_game.linkgraph.recalc_interval / CalendarTime::SECONDS_PER_DAY) / 2 &&
LinkGraphSchedule::instance.IsJoinWithUnfinishedJobDue()) {
/* Perform check two TimerGameCalendar::date_fract ticks before we would join, to make
* sure it also works in multiplayer. */
@ -205,7 +205,7 @@ void AfterLoad_LinkGraphPauseControl()
void OnTick_LinkGraph()
{
if (TimerGameCalendar::date_fract != LinkGraphSchedule::SPAWN_JOIN_TICK) return;
TimerGameCalendar::Date offset = static_cast<int32_t>(TimerGameCalendar::date) % (_settings_game.linkgraph.recalc_interval / CalendarTime::SECONDS_PER_DAY);
TimerGameCalendar::Date offset = TimerGameCalendar::date.base() % (_settings_game.linkgraph.recalc_interval / CalendarTime::SECONDS_PER_DAY);
if (offset == 0) {
LinkGraphSchedule::instance.SpawnNext();
} else if (offset == (_settings_game.linkgraph.recalc_interval / CalendarTime::SECONDS_PER_DAY) / 2) {

@ -83,7 +83,7 @@ TileIndex TileAdd(TileIndex tile, TileIndexDiff add,
if (x >= Map::SizeX() || y >= Map::SizeY()) {
std::string message = fmt::format("TILE_ADD({}) when adding 0x{:04X} and 0x{%04X} failed",
exp, (uint32_t)tile, add);
exp, tile, add);
#if !defined(_MSC_VER)
fmt::print(stderr, "{}:{} {}\n", file, line, message);
#else

@ -77,7 +77,7 @@ public:
/**
* Implicit conversion to the uint for bounds checking.
*/
debug_inline constexpr operator uint() const { return static_cast<uint32_t>(tile); }
debug_inline constexpr operator uint() const { return tile.base(); }
/**
* The type (bits 4..7), bridges (2..3), rainforest/desert (0..1)
@ -88,7 +88,7 @@ public:
*/
debug_inline byte &type()
{
return base_tiles[static_cast<uint32_t>(tile)].type;
return base_tiles[tile.base()].type;
}
/**
@ -100,7 +100,7 @@ public:
*/
debug_inline byte &height()
{
return base_tiles[static_cast<uint32_t>(tile)].height;
return base_tiles[tile.base()].height;
}
/**
@ -112,7 +112,7 @@ public:
*/
debug_inline byte &m1()
{
return base_tiles[static_cast<uint32_t>(tile)].m1;
return base_tiles[tile.base()].m1;
}
/**
@ -124,7 +124,7 @@ public:
*/
debug_inline uint16_t &m2()
{
return base_tiles[static_cast<uint32_t>(tile)].m2;
return base_tiles[tile.base()].m2;
}
/**
@ -136,7 +136,7 @@ public:
*/
debug_inline byte &m3()
{
return base_tiles[static_cast<uint32_t>(tile)].m3;
return base_tiles[tile.base()].m3;
}
/**
@ -148,7 +148,7 @@ public:
*/
debug_inline byte &m4()
{
return base_tiles[static_cast<uint32_t>(tile)].m4;
return base_tiles[tile.base()].m4;
}
/**
@ -160,7 +160,7 @@ public:
*/
debug_inline byte &m5()
{
return base_tiles[static_cast<uint32_t>(tile)].m5;
return base_tiles[tile.base()].m5;
}
/**
@ -172,7 +172,7 @@ public:
*/
debug_inline byte &m6()
{
return extended_tiles[static_cast<uint32_t>(tile)].m6;
return extended_tiles[tile.base()].m6;
}
/**
@ -184,7 +184,7 @@ public:
*/
debug_inline byte &m7()
{
return extended_tiles[static_cast<uint32_t>(tile)].m7;
return extended_tiles[tile.base()].m7;
}
/**
@ -196,7 +196,7 @@ public:
*/
debug_inline uint16_t &m8()
{
return extended_tiles[static_cast<uint32_t>(tile)].m8;
return extended_tiles[tile.base()].m8;
}
};
@ -316,7 +316,7 @@ public:
*/
static inline TileIndex WrapToMap(TileIndex tile)
{
return static_cast<uint32_t>(tile) & Map::tile_mask;
return tile.base() & Map::tile_mask;
}
/**
@ -426,7 +426,7 @@ debug_inline static TileIndex TileVirtXY(uint x, uint y)
*/
debug_inline static uint TileX(TileIndex tile)
{
return static_cast<uint32_t>(tile) & Map::MaxX();
return tile.base() & Map::MaxX();
}
/**
@ -436,7 +436,7 @@ debug_inline static uint TileX(TileIndex tile)
*/
debug_inline static uint TileY(TileIndex tile)
{
return static_cast<uint32_t>(tile) >> Map::LogX();
return tile.base() >> Map::LogX();
}
/**

@ -63,7 +63,7 @@ std::string ValueStr(SignalType t)
std::string TileStr(TileIndex tile)
{
std::stringstream ss;
ss << "0x" << std::setfill('0') << std::setw(4) << std::hex << static_cast<uint32_t>(tile); // 0x%04X
ss << "0x" << std::setfill('0') << std::setw(4) << std::hex << tile.base(); // 0x%04X
ss << " (" << TileX(tile) << ", " << TileY(tile) << ")";
return ss.str();
}

@ -53,7 +53,7 @@ public:
if constexpr (std::is_enum_v<T>) {
this->Write(static_cast<std::underlying_type_t<const T>>(data));
} else if constexpr (std::is_base_of_v<StrongTypedefBase, T>) {
this->Write(static_cast<typename T::BaseType>(data));
this->Write(data.base());
} else {
this->Write(data);
}

@ -207,7 +207,7 @@ public:
/* Location */
std::stringstream tile_ss;
tile_ss << "0x" << std::setfill('0') << std::setw(4) << std::hex << std::uppercase << static_cast<uint32_t>(tile); // 0x%.4X
tile_ss << "0x" << std::setfill('0') << std::setw(4) << std::hex << std::uppercase << tile.base(); // 0x%.4X
SetDParam(0, TileX(tile));
SetDParam(1, TileY(tile));
@ -332,12 +332,12 @@ public:
bool IsNewGRFInspectable() const override
{
return ::IsNewGRFInspectable(GetGrfSpecFeature(this->tile), static_cast<uint32_t>(this->tile));
return ::IsNewGRFInspectable(GetGrfSpecFeature(this->tile), this->tile.base());
}
void ShowNewGRFInspectWindow() const override
{
::ShowNewGRFInspectWindow(GetGrfSpecFeature(this->tile), static_cast<uint32_t>(this->tile));
::ShowNewGRFInspectWindow(GetGrfSpecFeature(this->tile), this->tile.base());
}
void OnClick([[maybe_unused]] Point pt, int widget, [[maybe_unused]] int click_count) override

@ -227,8 +227,8 @@ void SerializeNetworkGameInfo(Packet *p, const NetworkServerGameInfo *info, bool
}
/* NETWORK_GAME_INFO_VERSION = 3 */
p->Send_uint32(static_cast<int32_t>(info->game_date));
p->Send_uint32(static_cast<int32_t>(info->start_date));
p->Send_uint32(info->game_date.base());
p->Send_uint32(info->start_date.base());
/* NETWORK_GAME_INFO_VERSION = 2 */
p->Send_uint8 (info->companies_max);
@ -321,8 +321,8 @@ void DeserializeNetworkGameInfo(Packet *p, NetworkGameInfo *info, const GameInfo
}
case 3:
info->game_date = Clamp(p->Recv_uint32(), 0, static_cast<int32_t>(CalendarTime::MAX_DATE));
info->start_date = Clamp(p->Recv_uint32(), 0, static_cast<int32_t>(CalendarTime::MAX_DATE));
info->game_date = Clamp(p->Recv_uint32(), 0, CalendarTime::MAX_DATE.base());
info->start_date = Clamp(p->Recv_uint32(), 0, CalendarTime::MAX_DATE.base());
FALLTHROUGH;
case 2:

@ -178,7 +178,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendWelcome()
p->Send_string(""); // Used to be map-name.
p->Send_uint32(_settings_game.game_creation.generation_seed);
p->Send_uint8 (_settings_game.game_creation.landscape);
p->Send_uint32(static_cast<int32_t>(TimerGameCalendar::ConvertYMDToDate(_settings_game.game_creation.starting_year, 0, 1)));
p->Send_uint32(TimerGameCalendar::ConvertYMDToDate(_settings_game.game_creation.starting_year, 0, 1).base());
p->Send_uint16(Map::SizeX());
p->Send_uint16(Map::SizeY());
@ -208,7 +208,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendDate()
{
Packet *p = new Packet(ADMIN_PACKET_SERVER_DATE);
p->Send_uint32(static_cast<int32_t>(TimerGameCalendar::date));
p->Send_uint32(TimerGameCalendar::date.base());
this->SendPacket(p);
return NETWORK_RECV_STATUS_OKAY;
@ -244,7 +244,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendClientInfo(const NetworkC
p->Send_string(cs == nullptr ? "" : const_cast<NetworkAddress &>(cs->client_address).GetHostname());
p->Send_string(ci->client_name);
p->Send_uint8 (0); // Used to be language
p->Send_uint32(static_cast<int32_t>(ci->join_date));
p->Send_uint32(ci->join_date.base());
p->Send_uint8 (ci->client_playas);
this->SendPacket(p);
@ -329,7 +329,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::SendCompanyInfo(const Company
p->Send_string(GetString(STR_PRESIDENT_NAME));
p->Send_uint8 (c->colour);
p->Send_bool (NetworkCompanyIsPassworded(c->index));
p->Send_uint32(static_cast<int32_t>(c->inaugurated_year));
p->Send_uint32(c->inaugurated_year.base());
p->Send_bool (c->is_ai);
p->Send_uint8 (CeilDiv(c->months_of_bankruptcy, 3)); // send as quarters_of_bankruptcy

@ -6512,18 +6512,18 @@ bool GetGlobalVariable(byte param, uint32_t *value, const GRFFile *grffile)
{
switch (param) {
case 0x00: // current date
*value = static_cast<int32_t>(std::max(TimerGameCalendar::date - CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR, TimerGameCalendar::Date(0)));
*value = std::max(TimerGameCalendar::date - CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR, TimerGameCalendar::Date(0)).base();
return true;
case 0x01: // current year
*value = static_cast<int32_t>(Clamp(TimerGameCalendar::year, CalendarTime::ORIGINAL_BASE_YEAR, CalendarTime::ORIGINAL_MAX_YEAR) - CalendarTime::ORIGINAL_BASE_YEAR);
*value = (Clamp(TimerGameCalendar::year, CalendarTime::ORIGINAL_BASE_YEAR, CalendarTime::ORIGINAL_MAX_YEAR) - CalendarTime::ORIGINAL_BASE_YEAR).base();
return true;
case 0x02: { // detailed date information: month of year (bit 0-7), day of month (bit 8-12), leap year (bit 15), day of year (bit 16-24)
TimerGameCalendar::YearMonthDay ymd;
TimerGameCalendar::ConvertDateToYMD(TimerGameCalendar::date, &ymd);
TimerGameCalendar::Date start_of_year = TimerGameCalendar::ConvertYMDToDate(ymd.year, 0, 1);
*value = ymd.month | (ymd.day - 1) << 8 | (TimerGameCalendar::IsLeapYear(ymd.year) ? 1 << 15 : 0) | static_cast<int32_t>(TimerGameCalendar::date - start_of_year) << 16;
*value = ymd.month | (ymd.day - 1) << 8 | (TimerGameCalendar::IsLeapYear(ymd.year) ? 1 << 15 : 0) | (TimerGameCalendar::date - start_of_year).base() << 16;
return true;
}
@ -6629,11 +6629,11 @@ bool GetGlobalVariable(byte param, uint32_t *value, const GRFFile *grffile)
return true;
case 0x23: // long format date
*value = static_cast<int32_t>(TimerGameCalendar::date);
*value = TimerGameCalendar::date.base();
return true;
case 0x24: // long format year
*value = static_cast<int32_t>(TimerGameCalendar::year);
*value = TimerGameCalendar::year.base();
return true;
default: return false;
@ -6646,6 +6646,7 @@ static uint32_t GetParamVal(byte param, uint32_t *cond_val)
uint32_t value;
if (GetGlobalVariable(param - 0x80, &value, _cur.grffile)) return value;
/* Non-common variable */
switch (param) {
case 0x84: { // GRF loading stage
@ -7228,7 +7229,7 @@ static uint32_t GetPatchVariable(uint8_t param)
{
switch (param) {
/* start year - 1920 */
case 0x0B: return static_cast<int32_t>(std::max(_settings_game.game_creation.starting_year, CalendarTime::ORIGINAL_BASE_YEAR) - CalendarTime::ORIGINAL_BASE_YEAR);
case 0x0B: return (std::max(_settings_game.game_creation.starting_year, CalendarTime::ORIGINAL_BASE_YEAR) - CalendarTime::ORIGINAL_BASE_YEAR).base();
/* freight trains weight factor */
case 0x0E: return _settings_game.vehicle.freight_trains;

@ -557,7 +557,7 @@ static uint32_t VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *objec
}
case 0x48: return v->GetEngine()->flags; // Vehicle Type Info
case 0x49: return static_cast<int32_t>(v->build_year);
case 0x49: return v->build_year.base();
case 0x4A:
switch (v->type) {
@ -582,7 +582,7 @@ static uint32_t VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *objec
}
case 0x4B: // Long date of last service
return static_cast<int32_t>(v->date_of_last_service_newgrf);
return v->date_of_last_service_newgrf.base();
case 0x4C: // Current maximum speed in NewGRF units
if (!v->IsPrimaryVehicle()) return 0;
@ -814,7 +814,7 @@ static uint32_t VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *objec
case 0x41: return GB(ClampTo<uint16_t>(v->age), 8, 8);
case 0x42: return ClampTo<uint16_t>(v->max_age);
case 0x43: return GB(ClampTo<uint16_t>(v->max_age), 8, 8);
case 0x44: return static_cast<int32_t>(Clamp(v->build_year, CalendarTime::ORIGINAL_BASE_YEAR, CalendarTime::ORIGINAL_MAX_YEAR) - CalendarTime::ORIGINAL_BASE_YEAR);
case 0x44: return (Clamp(v->build_year, CalendarTime::ORIGINAL_BASE_YEAR, CalendarTime::ORIGINAL_MAX_YEAR) - CalendarTime::ORIGINAL_BASE_YEAR).base();
case 0x45: return v->unitnumber;
case 0x46: return v->GetEngine()->grf_prop.local_id;
case 0x47: return GB(v->GetEngine()->grf_prop.local_id, 8, 8);
@ -957,11 +957,11 @@ static uint32_t VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *objec
}
}
case 0x48: return Engine::Get(this->self_type)->flags; // Vehicle Type Info
case 0x49: return static_cast<int32_t>(TimerGameCalendar::year); // 'Long' format build year
case 0x4B: return static_cast<int32_t>(TimerGameCalendar::date); // Long date of last service
case 0x49: return TimerGameCalendar::year.base(); // 'Long' format build year
case 0x4B: return TimerGameCalendar::date.base(); // Long date of last service
case 0x92: return ClampTo<uint16_t>(TimerGameCalendar::date - CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR); // Date of last service
case 0x93: return GB(ClampTo<uint16_t>(TimerGameCalendar::date - CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR), 8, 8);
case 0xC4: return static_cast<int32_t>(Clamp(TimerGameCalendar::year, CalendarTime::ORIGINAL_BASE_YEAR, CalendarTime::ORIGINAL_MAX_YEAR) - CalendarTime::ORIGINAL_BASE_YEAR); // Build year
case 0xC4: return (Clamp(TimerGameCalendar::year, CalendarTime::ORIGINAL_BASE_YEAR, CalendarTime::ORIGINAL_MAX_YEAR) - CalendarTime::ORIGINAL_BASE_YEAR).base(); // Build year
case 0xC6: return Engine::Get(this->self_type)->grf_prop.local_id;
case 0xC7: return GB(Engine::Get(this->self_type)->grf_prop.local_id, 8, 8);
case 0xDA: return INVALID_VEHICLE; // Next vehicle

@ -301,7 +301,7 @@ static uint32_t GetDistanceFromNearbyHouse(uint8_t parameter, TileIndex tile, Ho
case 0x40: return (IsTileType(this->tile, MP_HOUSE) ? GetHouseBuildingStage(this->tile) : 0) | TileHash2Bit(TileX(this->tile), TileY(this->tile)) << 2;
/* Building age. */
case 0x41: return static_cast<int32_t>(IsTileType(this->tile, MP_HOUSE) ? GetHouseAge(this->tile) : 0);
case 0x41: return IsTileType(this->tile, MP_HOUSE) ? GetHouseAge(this->tile).base() : 0;
/* Town zone */
case 0x42: return GetTownRadiusGroup(this->town, this->tile);

@ -162,8 +162,8 @@ static uint32_t GetCountAndDistanceOfClosestInstance(byte param_setID, byte layo
/* Variables available during construction check. */
switch (variable) {
case 0x80: return static_cast<uint32_t>(this->tile);
case 0x81: return GB(static_cast<uint32_t>(this->tile), 8, 8);
case 0x80: return this->tile.base();
case 0x81: return GB(this->tile.base(), 8, 8);
/* Pointer to the town the industry is associated with */
case 0x82: return this->industry->town->index;
@ -247,7 +247,7 @@ static uint32_t GetCountAndDistanceOfClosestInstance(byte param_setID, byte layo
return this->industry->founder | (is_ai ? 0x10000 : 0) | (colours << 24);
}
case 0x46: return static_cast<int32_t>(this->industry->construction_date); // Date when built - long format - (in days)
case 0x46: return this->industry->construction_date.base(); // Date when built - long format - (in days)
/* Override flags from GS */
case 0x47: return this->industry->ctlflags;
@ -338,7 +338,7 @@ static uint32_t GetCountAndDistanceOfClosestInstance(byte param_setID, byte layo
if (!IsValidCargoID(cargo)) return 0;
auto it = this->industry->GetCargoAccepted(cargo);
if (it == std::end(this->industry->accepted)) return 0; // invalid cargo
if (variable == 0x6E) return static_cast<int32_t>(it->last_accepted);
if (variable == 0x6E) return it->last_accepted.base();
if (variable == 0x6F) return it->waiting;
NOT_REACHED();
}
@ -347,8 +347,8 @@ static uint32_t GetCountAndDistanceOfClosestInstance(byte param_setID, byte layo
case 0x7C: return (this->industry->psa != nullptr) ? this->industry->psa->GetValue(parameter) : 0;
/* Industry structure access*/
case 0x80: return static_cast<uint32_t>(this->industry->location.tile);
case 0x81: return GB(static_cast<uint32_t>(this->industry->location.tile), 8, 8);
case 0x80: return this->industry->location.tile.base();
case 0x81: return GB(this->industry->location.tile.base(), 8, 8);
/* Pointer to the town the industry is associated with */
case 0x82: return this->industry->town->index;
case 0x83:

@ -277,7 +277,7 @@ static uint32_t GetCountAndDistanceOfClosestInstance(byte local_id, uint32_t grf
break;
/* Construction date */
case 0x42: return static_cast<int32_t>(TimerGameCalendar::date);
case 0x42: return TimerGameCalendar::date.base();
/* Object founder information */
case 0x44: return _current_company;
@ -315,7 +315,7 @@ static uint32_t GetCountAndDistanceOfClosestInstance(byte local_id, uint32_t grf
case 0x41: return GetTileSlope(this->tile) << 8 | GetTerrainType(this->tile);
/* Construction date */
case 0x42: return static_cast<int32_t>(this->obj->build_date);
case 0x42: return this->obj->build_date.base();
/* Animation counter */
case 0x43: return GetAnimationFrame(this->tile);

@ -19,7 +19,7 @@
/* virtual */ uint32_t RailTypeScopeResolver::GetRandomBits() const
{
uint tmp = CountBits(static_cast<uint32_t>(this->tile + (TileX(this->tile) + TileY(this->tile)) * TILE_SIZE));
uint tmp = CountBits(this->tile.base() + (TileX(this->tile) + TileY(this->tile)) * TILE_SIZE);
return GB(tmp, 0, 2);
}
@ -30,7 +30,7 @@
case 0x40: return 0;
case 0x41: return 0;
case 0x42: return 0;
case 0x43: return static_cast<int32_t>(TimerGameCalendar::date);
case 0x43: return TimerGameCalendar::date.base();
case 0x44: return HZB_TOWN_EDGE;
}
}
@ -40,8 +40,8 @@
case 0x41: return 0;
case 0x42: return IsLevelCrossingTile(this->tile) && IsCrossingBarred(this->tile);
case 0x43:
if (IsRailDepotTile(this->tile)) return static_cast<int32_t>(Depot::GetByTile(this->tile)->build_date);
return static_cast<int32_t>(TimerGameCalendar::date);
if (IsRailDepotTile(this->tile)) return Depot::GetByTile(this->tile)->build_date.base();
return TimerGameCalendar::date.base();
case 0x44: {
const Town *t = nullptr;
if (IsRailDepotTile(this->tile)) {

@ -19,7 +19,7 @@
/* virtual */ uint32_t RoadTypeScopeResolver::GetRandomBits() const
{
uint tmp = CountBits(static_cast<uint32_t>(this->tile + (TileX(this->tile) + TileY(this->tile)) * TILE_SIZE));
uint tmp = CountBits(this->tile.base() + (TileX(this->tile) + TileY(this->tile)) * TILE_SIZE);
return GB(tmp, 0, 2);
}
@ -30,7 +30,7 @@
case 0x40: return 0;
case 0x41: return 0;
case 0x42: return 0;
case 0x43: return static_cast<int32_t>(TimerGameCalendar::date);
case 0x43: return TimerGameCalendar::date.base();
case 0x44: return HZB_TOWN_EDGE;
}
}
@ -40,8 +40,8 @@
case 0x41: return 0;
case 0x42: return IsLevelCrossingTile(this->tile) && IsCrossingBarred(this->tile);
case 0x43:
if (IsRoadDepotTile(this->tile)) return static_cast<int32_t>(Depot::GetByTile(this->tile)->build_date);
return static_cast<int32_t>(TimerGameCalendar::date);
if (IsRoadDepotTile(this->tile)) return Depot::GetByTile(this->tile)->build_date.base();
return TimerGameCalendar::date.base();
case 0x44: {
const Town *t = nullptr;
if (IsRoadDepotTile(this->tile)) {

@ -44,8 +44,8 @@
}
/* Town properties */
case 0x80: return static_cast<uint32_t>(this->t->xy);
case 0x81: return GB(static_cast<uint32_t>(this->t->xy), 8, 8);
case 0x80: return this->t->xy.base();
case 0x81: return GB(this->t->xy.base(), 8, 8);
case 0x82: return ClampTo<uint16_t>(this->t->cache.population);
case 0x83: return GB(ClampTo<uint16_t>(this->t->cache.population), 8, 8);
case 0x8A: return this->t->grow_counter / Ticks::TOWN_GROWTH_TICKS;

@ -44,7 +44,7 @@ static inline void AddVehicleAdviceNewsItem(StringID string, VehicleID vehicle)
static inline void AddTileNewsItem(StringID string, NewsType type, TileIndex tile, const NewsAllocatedData *data = nullptr, StationID station = INVALID_STATION)
{
AddNewsItem(string, type, NF_NO_TRANSPARENT | NF_SHADE | NF_THIN, NR_TILE, static_cast<uint32_t>(tile), station == INVALID_STATION ? NR_NONE : NR_STATION, station, data);
AddNewsItem(string, type, NF_NO_TRANSPARENT | NF_SHADE | NF_THIN, NR_TILE, tile.base(), station == INVALID_STATION ? NR_NONE : NR_STATION, station, data);
}
static inline void AddIndustryNewsItem(StringID string, NewsType type, IndustryID industry, const NewsAllocatedData *data = nullptr)

@ -511,7 +511,7 @@ static void ReallyClearObjectTile(Object *o)
{
Object::DecTypeCount(o->type);
for (TileIndex tile_cur : o->location) {
DeleteNewGRFInspectWindow(GSF_OBJECTS, static_cast<uint32_t>(tile_cur));
DeleteNewGRFInspectWindow(GSF_OBJECTS, tile_cur.base());
MakeWaterKeepingClass(tile_cur, GetTileOwner(tile_cur));
}

@ -429,7 +429,7 @@ struct AfterNewGRFScan : NewGRFScanCallback {
MusicDriver::GetInstance()->SetVolume(_settings_client.music.music_vol);
SetEffectVolume(_settings_client.music.effect_vol);
if (startyear != CalendarTime::INVALID_YEAR) IConsoleSetSetting("game_creation.starting_year", static_cast<int32_t>(startyear));
if (startyear != CalendarTime::INVALID_YEAR) IConsoleSetSetting("game_creation.starting_year", startyear.base());
if (generation_seed != GENERATE_NEW_SEED) _settings_newgame.game_creation.generation_seed = generation_seed;
if (!dedicated_host.empty()) {
@ -1409,7 +1409,7 @@ void StateGameLoop()
CallWindowGameTickEvent();
NewsLoop();
} else {
if (_debug_desync_level > 2 && TimerGameCalendar::date_fract == 0 && (static_cast<int32_t>(TimerGameCalendar::date) & 0x1F) == 0) {
if (_debug_desync_level > 2 && TimerGameCalendar::date_fract == 0 && (TimerGameCalendar::date.base() & 0x1F) == 0) {
/* Save the desync savegame if needed. */
std::string name = fmt::format("dmp_cmds_{:08x}_{:08x}.sav", _settings_game.game_creation.generation_seed, TimerGameCalendar::date);
SaveOrLoad(name, SLO_SAVE, DFT_GAME_FILE, AUTOSAVE_DIR, false);

@ -1900,7 +1900,7 @@ static bool OrderConditionCompare(OrderConditionComparator occ, int variable, in
template <typename T, std::enable_if_t<std::is_base_of<StrongTypedefBase, T>::value, int> = 0>
static bool OrderConditionCompare(OrderConditionComparator occ, T variable, int value)
{
return OrderConditionCompare(occ, static_cast<typename T::BaseType>(variable), value);
return OrderConditionCompare(occ, variable.base(), value);
}
/**

@ -25,7 +25,7 @@ struct CYapfNodeKeyExitDir {
inline int CalcHash() const
{
return m_exitdir | (static_cast<uint32_t>(m_tile) << 2);
return m_exitdir | (m_tile.base() << 2);
}
inline bool operator==(const CYapfNodeKeyExitDir &other) const
@ -45,7 +45,7 @@ struct CYapfNodeKeyTrackDir : public CYapfNodeKeyExitDir
{
inline int CalcHash() const
{
return m_td | (static_cast<uint32_t>(m_tile) << 4);
return m_td | (m_tile.base() << 4);
}
inline bool operator==(const CYapfNodeKeyTrackDir &other) const

@ -27,7 +27,7 @@ struct CYapfRailSegmentKey
inline void Set(const CYapfNodeKeyTrackDir &node_key)
{
m_value = (static_cast<uint32_t>(node_key.m_tile) << 4) | node_key.m_td;
m_value = (node_key.m_tile.base() << 4) | node_key.m_td;
}
inline int32_t CalcHash() const

@ -225,7 +225,7 @@ RailTypes AddDateIntroducedRailTypes(RailTypes current, TimerGameCalendar::Date
if (rti->label == 0) continue;
/* Not date introduced. */
if (!IsInsideMM(rti->introduction_date, 0, static_cast<int32_t>(CalendarTime::MAX_DATE))) continue;
if (!IsInsideMM(rti->introduction_date, 0, CalendarTime::MAX_DATE.base())) continue;
/* Not yet introduced at this date. */
if (rti->introduction_date > date) continue;

@ -656,7 +656,7 @@ CommandCost CmdRemoveSingleRail(DoCommandFlag flags, TileIndex tile, Track track
Company::Get(owner)->infrastructure.rail[GetRailType(tile)] -= LEVELCROSSING_TRACKBIT_FACTOR;
DirtyCompanyInfrastructureWindows(owner);
MakeRoadNormal(tile, GetCrossingRoadBits(tile), GetRoadTypeRoad(tile), GetRoadTypeTram(tile), GetTownIndex(tile), GetRoadOwner(tile, RTT_ROAD), GetRoadOwner(tile, RTT_TRAM));
DeleteNewGRFInspectWindow(GSF_RAILTYPES, static_cast<uint32_t>(tile));
DeleteNewGRFInspectWindow(GSF_RAILTYPES, tile.base());
}
break;
}
@ -714,7 +714,7 @@ CommandCost CmdRemoveSingleRail(DoCommandFlag flags, TileIndex tile, Track track
} else {
DoClearSquare(tile);
}
DeleteNewGRFInspectWindow(GSF_RAILTYPES, static_cast<uint32_t>(tile));
DeleteNewGRFInspectWindow(GSF_RAILTYPES, tile.base());
} else {
SetTrackBits(tile, present);
SetTrackReservation(tile, GetRailReservationTrackBits(tile) & present);

@ -115,7 +115,7 @@ bool HasRoadTypeAvail(const CompanyID company, RoadType roadtype)
if (rti->label == 0) return false;
/* Not yet introduced at this date. */
if (IsInsideMM(rti->introduction_date, 0, static_cast<int32_t>(CalendarTime::MAX_DATE)) && rti->introduction_date > TimerGameCalendar::date) return false;
if (IsInsideMM(rti->introduction_date, 0, CalendarTime::MAX_DATE.base()) && rti->introduction_date > TimerGameCalendar::date) return false;
/*
* Do not allow building hidden road types, except when a town may build it.
@ -173,7 +173,7 @@ RoadTypes AddDateIntroducedRoadTypes(RoadTypes current, TimerGameCalendar::Date
if (rti->label == 0) continue;
/* Not date introduced. */
if (!IsInsideMM(rti->introduction_date, 0, static_cast<int32_t>(CalendarTime::MAX_DATE))) continue;
if (!IsInsideMM(rti->introduction_date, 0, CalendarTime::MAX_DATE.base())) continue;
/* Not yet introduced at this date. */
if (rti->introduction_date > date) continue;

@ -2144,7 +2144,7 @@ bool AfterLoadGame()
/* Delete small ufos heading for non-existing vehicles */
for (DisasterVehicle *v : DisasterVehicle::Iterate()) {
if (v->subtype == 2 /* ST_SMALL_UFO */ && v->state != 0) {
const Vehicle *u = Vehicle::GetIfValid(static_cast<uint32_t>(v->dest_tile));
const Vehicle *u = Vehicle::GetIfValid(v->dest_tile.base());
if (u == nullptr || u->type != VEH_ROAD || !RoadVehicle::From(u)->IsFrontEngine()) {
delete v;
}

@ -57,8 +57,8 @@ static void FixTTDMapArray()
/* _old_map3 is moved to _m::m3 and _m::m4 */
for (TileIndex t = 0; t < OLD_MAP_SIZE; t++) {
Tile tile(t);
tile.m3() = _old_map3[static_cast<uint32_t>(t) * 2];
tile.m4() = _old_map3[static_cast<uint32_t>(t) * 2 + 1];
tile.m3() = _old_map3[t.base() * 2];
tile.m4() = _old_map3[t.base() * 2 + 1];
}
for (TileIndex t = 0; t < OLD_MAP_SIZE; t++) {
@ -416,7 +416,7 @@ static bool FixTTOEngines()
if (TimerGameCalendar::date >= e->intro_date && HasBit(e->info.climates, 0)) {
e->flags |= ENGINE_AVAILABLE;
e->company_avail = MAX_UVALUE(CompanyMask);
e->age = TimerGameCalendar::date > e->intro_date ? static_cast<int32_t>(TimerGameCalendar::date - e->intro_date) / 30 : 0;
e->age = TimerGameCalendar::date > e->intro_date ? (TimerGameCalendar::date - e->intro_date).base() / 30 : 0;
}
} else {
/* Using data from TTO savegame */

@ -63,5 +63,5 @@
{
if (!IsValidBaseStation(station_id)) return ScriptDate::DATE_INVALID;
return (ScriptDate::Date)(int32_t)::BaseStation::Get(station_id)->build_date;
return (ScriptDate::Date)::BaseStation::Get(station_id)->build_date.base();
}

@ -83,8 +83,8 @@ static void _DoCommandReturnBuildBridge1(class ScriptInstance *instance)
switch (vehicle_type) {
case ScriptVehicle::VT_ROAD:
ScriptObject::SetCallbackVariable(0, static_cast<uint32_t>(start));
ScriptObject::SetCallbackVariable(1, static_cast<uint32_t>(end));
ScriptObject::SetCallbackVariable(0, start.base());
ScriptObject::SetCallbackVariable(1, end.base());
return ScriptObject::Command<CMD_BUILD_BRIDGE>::Do(&::_DoCommandReturnBuildBridge1, end, start, TRANSPORT_ROAD, bridge_id, ScriptRoad::GetCurrentRoadType());
case ScriptVehicle::VT_RAIL:
return ScriptObject::Command<CMD_BUILD_BRIDGE>::Do(end, start, TRANSPORT_RAIL, bridge_id, ScriptRail::GetCurrentRailType());

@ -50,5 +50,5 @@ static NetworkClientInfo *FindClientInfo(ScriptClient::ClientID client)
{
NetworkClientInfo *ci = FindClientInfo(client);
if (ci == nullptr) return ScriptDate::DATE_INVALID;
return (ScriptDate::Date)(int32_t)ci->join_date;
return (ScriptDate::Date)ci->join_date.base();
}

@ -22,7 +22,7 @@
/* static */ ScriptDate::Date ScriptDate::GetCurrentDate()
{
return (ScriptDate::Date)(int32_t)TimerGameCalendar::date;
return (ScriptDate::Date)TimerGameCalendar::date.base();
}
/* static */ SQInteger ScriptDate::GetYear(ScriptDate::Date date)
@ -31,7 +31,7 @@
::TimerGameCalendar::YearMonthDay ymd;
::TimerGameCalendar::ConvertDateToYMD(date, &ymd);
return (int32_t)ymd.year;
return ymd.year.base();
}
/* static */ SQInteger ScriptDate::GetMonth(ScriptDate::Date date)
@ -58,7 +58,7 @@
if (day_of_month < 1 || day_of_month > 31) return DATE_INVALID;
if (year < 0 || year > CalendarTime::MAX_YEAR) return DATE_INVALID;
return (ScriptDate::Date)(int32_t)::TimerGameCalendar::ConvertYMDToDate(year, month - 1, day_of_month);
return (ScriptDate::Date)::TimerGameCalendar::ConvertYMDToDate(year, month - 1, day_of_month).base();
}
/* static */ SQInteger ScriptDate::GetSystemTime()

@ -31,7 +31,7 @@ public:
* compose valid date values for a known year, month and day.
*/
enum Date {
DATE_INVALID = (int32_t)::CalendarTime::INVALID_DATE, ///< A value representing an invalid date.
DATE_INVALID = ::CalendarTime::INVALID_DATE.base(), ///< A value representing an invalid date.
};
/**

@ -30,7 +30,7 @@ ScriptDepotList::ScriptDepotList(ScriptTile::TransportType transport_type)
for (const Station *st : Station::Iterate()) {
if (st->owner == ScriptObject::GetCompany() || ScriptCompanyMode::IsDeity()) {
for (uint i = 0; i < st->airport.GetNumHangars(); i++) {
this->AddItem(static_cast<uint32_t>(st->airport.GetHangarTile(i)));
this->AddItem(st->airport.GetHangarTile(i).base());
}
}
}
@ -40,6 +40,6 @@ ScriptDepotList::ScriptDepotList(ScriptTile::TransportType transport_type)
/* Handle 'standard' depots. */
for (const Depot *depot : Depot::Iterate()) {
if ((::GetTileOwner(depot->xy) == ScriptObject::GetCompany() || ScriptCompanyMode::IsDeity()) && ::IsTileType(depot->xy, tile_type)) this->AddItem(static_cast<uint32_t>(depot->xy));
if ((::GetTileOwner(depot->xy) == ScriptObject::GetCompany() || ScriptCompanyMode::IsDeity()) && ::IsTileType(depot->xy, tile_type)) this->AddItem(depot->xy.base());
}
}

@ -139,7 +139,7 @@
if (!IsValidEngine(engine_id)) return -1;
if (GetVehicleType(engine_id) == ScriptVehicle::VT_RAIL && IsWagon(engine_id)) return -1;
return (int32_t)::Engine::Get(engine_id)->GetLifeLengthInDays();
return ::Engine::Get(engine_id)->GetLifeLengthInDays().base();
}
/* static */ Money ScriptEngine::GetRunningCost(EngineID engine_id)
@ -179,7 +179,7 @@
{
if (!IsValidEngine(engine_id)) return ScriptDate::DATE_INVALID;
return (ScriptDate::Date)(int32_t)::Engine::Get(engine_id)->intro_date;
return (ScriptDate::Date)::Engine::Get(engine_id)->intro_date.base();
}
/* static */ ScriptVehicle::VehicleType ScriptEngine::GetVehicleType(EngineID engine_id)

@ -53,7 +53,7 @@
{
Industry *i = Industry::GetIfValid(industry_id);
if (i == nullptr) return ScriptDate::DATE_INVALID;
return (ScriptDate::Date)(int32_t)i->construction_date;
return (ScriptDate::Date)i->construction_date.base();
}
/* static */ bool ScriptIndustry::SetText(IndustryID industry_id, Text *text)
@ -222,7 +222,7 @@
{
Industry *i = Industry::GetIfValid(industry_id);
if (i == nullptr) return 0;
return (int32_t)i->last_prod_year;
return i->last_prod_year.base();
}
/* static */ ScriptDate::Date ScriptIndustry::GetCargoLastAcceptedDate(IndustryID industry_id, CargoID cargo_type)
@ -232,11 +232,11 @@
if (!::IsValidCargoID(cargo_type)) {
auto it = std::max_element(std::begin(i->accepted), std::end(i->accepted), [](const auto &a, const auto &b) { return a.last_accepted < b.last_accepted; });
return (ScriptDate::Date)(int32_t)it->last_accepted;
return (ScriptDate::Date)it->last_accepted.base();
} else {
auto it = i->GetCargoAccepted(cargo_type);
if (it == std::end(i->accepted)) return ScriptDate::DATE_INVALID;
return (ScriptDate::Date)(int32_t)it->last_accepted;
return (ScriptDate::Date)it->last_accepted.base();
}
}

@ -19,7 +19,7 @@
*/
class ScriptMap : public ScriptObject {
public:
static const int TILE_INVALID = static_cast<uint32_t>(INVALID_TILE); ///< Invalid TileIndex.
static const int TILE_INVALID = INVALID_TILE.base(); ///< Invalid TileIndex.
/**
* Checks whether the given tile is valid.

@ -382,8 +382,8 @@ static bool NormaliseTileOffset(int32_t *tile)
/* static */ SQInteger ScriptRoad::CanBuildConnectedRoadParts(ScriptTile::Slope slope_, Array<> &&existing, TileIndex start_, TileIndex end_)
{
::Slope slope = (::Slope)slope_;
int32_t start = static_cast<uint32_t>(start_);
int32_t end = static_cast<uint32_t>(end_);
int32_t start = start_.base();
int32_t end = end_.base();
/* The start tile and end tile cannot be the same tile either. */
if (start == end) return -1;

@ -182,7 +182,7 @@ static inline bool StoryPageElementTypeRequiresText(StoryPageElementType type)
EnforcePrecondition(ScriptDate::DATE_INVALID, IsValidStoryPage(story_page_id));
EnforceDeityMode(ScriptDate::DATE_INVALID);
return (ScriptDate::Date)(int32_t)StoryPage::Get(story_page_id)->date;
return (ScriptDate::Date)StoryPage::Get(story_page_id)->date.base();
}
/* static */ bool ScriptStoryPage::SetDate(StoryPageID story_page_id, ScriptDate::Date date)

@ -21,14 +21,14 @@ void ScriptTileList::AddRectangle(TileIndex t1, TileIndex t2)
if (!::IsValidTile(t2)) return;
TileArea ta(t1, t2);
for (TileIndex t : ta) this->AddItem(static_cast<uint32_t>(t));
for (TileIndex t : ta) this->AddItem(t.base());
}
void ScriptTileList::AddTile(TileIndex tile)
{
if (!::IsValidTile(tile)) return;
this->AddItem(static_cast<uint32_t>(tile));
this->AddItem(tile.base());
}
void ScriptTileList::RemoveRectangle(TileIndex t1, TileIndex t2)
@ -37,14 +37,14 @@ void ScriptTileList::RemoveRectangle(TileIndex t1, TileIndex t2)
if (!::IsValidTile(t2)) return;
TileArea ta(t1, t2);
for (TileIndex t : ta) this->RemoveItem(static_cast<uint32_t>(t));
for (TileIndex t : ta) this->RemoveItem(t.base());
}
void ScriptTileList::RemoveTile(TileIndex tile)
{
if (!::IsValidTile(tile)) return;
this->RemoveItem(static_cast<uint32_t>(tile));
this->RemoveItem(tile.base());
}
/**

@ -93,7 +93,7 @@ static void _DoCommandReturnBuildTunnel1(class ScriptInstance *instance)
/* For rail we do nothing special */
return ScriptObject::Command<CMD_BUILD_TUNNEL>::Do(start, TRANSPORT_RAIL, ScriptRail::GetCurrentRailType());
} else {
ScriptObject::SetCallbackVariable(0, static_cast<uint32_t>(start));
ScriptObject::SetCallbackVariable(0, start.base());
return ScriptObject::Command<CMD_BUILD_TUNNEL>::Do(&::_DoCommandReturnBuildTunnel1, start, TRANSPORT_ROAD, ScriptRoad::GetCurrentRoadType());
}
}

@ -311,7 +311,7 @@
{
if (!IsValidVehicle(vehicle_id)) return -1;
return (int32_t)::Vehicle::Get(vehicle_id)->age;
return ::Vehicle::Get(vehicle_id)->age.base();
}
/* static */ SQInteger ScriptVehicle::GetWagonAge(VehicleID vehicle_id, SQInteger wagon)
@ -323,21 +323,21 @@
if (v->type == VEH_TRAIN) {
while (wagon-- > 0) v = ::Train::From(v)->GetNextUnit();
}
return (int32_t)v->age;
return v->age.base();
}
/* static */ SQInteger ScriptVehicle::GetMaxAge(VehicleID vehicle_id)
{
if (!IsPrimaryVehicle(vehicle_id)) return -1;
return (int32_t)::Vehicle::Get(vehicle_id)->max_age;
return ::Vehicle::Get(vehicle_id)->max_age.base();
}
/* static */ SQInteger ScriptVehicle::GetAgeLeft(VehicleID vehicle_id)
{
if (!IsPrimaryVehicle(vehicle_id)) return -1;
return (int32_t)(::Vehicle::Get(vehicle_id)->max_age - ::Vehicle::Get(vehicle_id)->age);
return (::Vehicle::Get(vehicle_id)->max_age - ::Vehicle::Get(vehicle_id)->age).base();
}
/* static */ SQInteger ScriptVehicle::GetCurrentSpeed(VehicleID vehicle_id)

@ -37,7 +37,7 @@ namespace SQConvert {
template <> struct Return<int32_t> { static inline int Set(HSQUIRRELVM vm, int32_t res) { sq_pushinteger(vm, res); return 1; } };
template <> struct Return<int64_t> { static inline int Set(HSQUIRRELVM vm, int64_t res) { sq_pushinteger(vm, res); return 1; } };
template <> struct Return<Money> { static inline int Set(HSQUIRRELVM vm, Money res) { sq_pushinteger(vm, res); return 1; } };
template <> struct Return<TileIndex> { static inline int Set(HSQUIRRELVM vm, TileIndex res) { sq_pushinteger(vm, (int32_t)static_cast<uint32_t>(res)); return 1; } };
template <> struct Return<TileIndex> { static inline int Set(HSQUIRRELVM vm, TileIndex res) { sq_pushinteger(vm, (int32_t)res.base()); return 1; } };
template <> struct Return<bool> { static inline int Set(HSQUIRRELVM vm, bool res) { sq_pushbool (vm, res); return 1; } };
template <> struct Return<char *> { /* Do not use char *, use std::optional<std::string> instead. */ };
template <> struct Return<const char *> { /* Do not use const char *, use std::optional<std::string> instead. */ };

@ -174,25 +174,25 @@ struct IntSettingDesc : SettingDesc {
str(str), str_help(str_help), str_val(str_val), cat(cat), pre_check(pre_check),
post_callback(post_callback) {
if constexpr (std::is_base_of_v<StrongTypedefBase, Tdef>) {
this->def = static_cast<typename Tdef::BaseType>(def);
this->def = def.base();
} else {
this->def = def;
}
if constexpr (std::is_base_of_v<StrongTypedefBase, Tmin>) {
this->min = static_cast<typename Tmin::BaseType>(min);
this->min = min.base();
} else {
this->min = min;
}
if constexpr (std::is_base_of_v<StrongTypedefBase, Tmax>) {
this->max = static_cast<typename Tmax::BaseType>(max);
this->max = max.base();
} else {
this->max = max;
}
if constexpr (std::is_base_of_v<StrongTypedefBase, Tinterval>) {
this->interval = static_cast<typename Tinterval::BaseType>(interval);
this->interval = interval.base();
} else {
this->interval = interval;
}

@ -1664,7 +1664,7 @@ CommandCost RemoveFromRailBaseStation(TileArea ta, std::vector<T *> &affected_st
if (!build_rail && !IsStationTileBlocked(tile)) Company::Get(owner)->infrastructure.rail[rt]--;
DoClearSquare(tile);
DeleteNewGRFInspectWindow(GSF_STATIONS, static_cast<uint32_t>(tile));
DeleteNewGRFInspectWindow(GSF_STATIONS, tile.base());
if (build_rail) MakeRailNormal(tile, owner, TrackToTrackBits(track), rt);
Company::Get(owner)->infrastructure.station--;
DirtyCompanyInfrastructureWindows(owner);
@ -2162,7 +2162,7 @@ static CommandCost RemoveRoadStop(TileIndex tile, DoCommandFlag flags, int repla
uint specindex = GetCustomRoadStopSpecIndex(tile);
DeleteNewGRFInspectWindow(GSF_ROADSTOPS, static_cast<uint32_t>(tile));
DeleteNewGRFInspectWindow(GSF_ROADSTOPS, tile.base());
if (IsDriveThroughStopTile(tile)) {
/* Clears the tile for us */
@ -2546,7 +2546,7 @@ static CommandCost RemoveAirport(TileIndex tile, DoCommandFlag flags)
if (flags & DC_EXEC) {
DeleteAnimatedTile(tile_cur);
DoClearSquare(tile_cur);
DeleteNewGRFInspectWindow(GSF_AIRPORTTILES, static_cast<uint32_t>(tile_cur));
DeleteNewGRFInspectWindow(GSF_AIRPORTTILES, tile_cur.base());
}
}

@ -99,7 +99,7 @@ static void UpdateElement(StoryPageElement &pe, TileIndex tile, uint32_t referen
break;
case SPET_LOCATION:
pe.text = text;
pe.referenced_id = static_cast<uint32_t>(tile);
pe.referenced_id = tile.base();
break;
case SPET_GOAL:
pe.referenced_id = (GoalID)reference;

@ -86,13 +86,13 @@ void SetDParamMaxDigits(size_t n, uint count, FontSize size = FS_NORMAL);
template <typename T, std::enable_if_t<std::is_base_of<StrongTypedefBase, T>::value, int> = 0>
void SetDParam(size_t n, T v)
{
SetDParam(n, static_cast<typename T::BaseType>(v));
SetDParam(n, v.base());
}
template <typename T, std::enable_if_t<std::is_base_of<StrongTypedefBase, T>::value, int> = 0>
void SetDParamMaxValue(size_t n, T max_value, uint min_count = 0, FontSize size = FS_NORMAL)
{
SetDParamMaxValue(n, static_cast<typename T::BaseType>(max_value), min_count, size);
SetDParamMaxValue(n, max_value.base(), min_count, size);
}
void SetDParamStr(size_t n, const char *str);

@ -156,7 +156,7 @@ public:
template <typename T, std::enable_if_t<std::is_base_of<StrongTypedefBase, T>::value, int> = 0>
void SetParam(size_t n, T v)
{
SetParam(n, static_cast<typename T::BaseType>(v));
SetParam(n, v.base());
}
void SetParam(size_t n, const char *str)

@ -75,8 +75,8 @@ static const uint16_t _accum_days_for_month[] = {
*/
/* There are 97 leap years in 400 years */
TimerGameCalendar::Year yr = 400 * (static_cast<int32_t>(date) / (CalendarTime::DAYS_IN_YEAR * 400 + 97));
int rem = static_cast<int32_t>(date) % (CalendarTime::DAYS_IN_YEAR * 400 + 97);
TimerGameCalendar::Year yr = 400 * (date.base() / (CalendarTime::DAYS_IN_YEAR * 400 + 97));
int rem = date.base() % (CalendarTime::DAYS_IN_YEAR * 400 + 97);
uint16_t x;
if (rem >= CalendarTime::DAYS_IN_YEAR * 100 + 25) {
@ -141,7 +141,7 @@ static const uint16_t _accum_days_for_month[] = {
*/
/* static */ bool TimerGameCalendar::IsLeapYear(TimerGameCalendar::Year yr)
{
return static_cast<int32_t>(yr) % 4 == 0 && (static_cast<int32_t>(yr) % 100 != 0 || static_cast<int32_t>(yr) % 400 == 0);
return yr.base() % 4 == 0 && (yr.base() % 100 != 0 || yr.base() % 400 == 0);
}
/**
@ -215,7 +215,7 @@ void TimerManager<TimerGameCalendar>::Elapsed([[maybe_unused]] TimerGameCalendar
timer->Elapsed(TimerGameCalendar::DAY);
}
if ((static_cast<int32_t>(TimerGameCalendar::date) % 7) == 3) {
if ((TimerGameCalendar::date.base() % 7) == 3) {
for (auto timer : timers) {
timer->Elapsed(TimerGameCalendar::WEEK);
}

@ -113,7 +113,7 @@ public:
static constexpr Year DateToYear(Date date)
{
/* Hardcode the number of days in a year because we can't access CalendarTime from here. */
return static_cast<int32_t>(date) / 366;
return date.base() / 366;
}
/**
@ -123,7 +123,7 @@ public:
*/
static constexpr Date DateAtStartOfYear(Year year)
{
int32_t year_as_int = static_cast<int32_t>(year);
int32_t year_as_int = year.base();
uint number_of_leap_years = (year == 0) ? 0 : ((year_as_int - 1) / 4 - (year_as_int - 1) / 100 + (year_as_int - 1) / 400 + 1);
/* Hardcode the number of days in a year because we can't access CalendarTime from here. */

@ -437,7 +437,7 @@ void UpdateVehicleTimetable(Vehicle *v, bool travelling)
just_started = !HasBit(v->vehicle_flags, VF_TIMETABLE_STARTED);
if (v->timetable_start != 0) {
v->lateness_counter = static_cast<int32_t>(TimerGameCalendar::date - v->timetable_start) * Ticks::DAY_TICKS + TimerGameCalendar::date_fract;
v->lateness_counter = (TimerGameCalendar::date - v->timetable_start).base() * Ticks::DAY_TICKS + TimerGameCalendar::date_fract;
v->timetable_start = 0;
}

@ -2499,7 +2499,7 @@ struct ScenarioEditorToolbarWindow : Window {
value = atoi(str);
} else {
/* An empty string means revert to the default */
value = static_cast<int32_t>(CalendarTime::DEF_START_YEAR);
value = CalendarTime::DEF_START_YEAR.base();
}
SetStartingYear(value);

@ -594,7 +594,7 @@ static void TileLoop_Town(TileIndex tile)
/* Binomial distribution per tick, by a series of coin flips */
/* Reduce generation rate to a 1/4, using tile bits to spread out distribution.
* As tick counter is incremented by 256 between each call, we ignore the lower 8 bits. */
if (GB(TimerGameTick::counter, 8, 2) == GB(static_cast<uint32_t>(tile), 0, 2)) {
if (GB(TimerGameTick::counter, 8, 2) == GB(tile.base(), 0, 2)) {
/* Make a bitmask with up to 32 bits set, one for each potential pax */
int genmax = (hs->population + 7) / 8;
uint32_t genmask = (genmax >= 32) ? 0xFFFFFFFF : ((1 << genmax) - 1);
@ -870,7 +870,7 @@ RoadType GetTownRoadType()
if (!HasBit(rti->flags, ROTF_TOWN_BUILD)) continue;
/* Not yet introduced at this date. */
if (IsInsideMM(rti->introduction_date, 0, static_cast<int32_t>(CalendarTime::MAX_DATE)) && rti->introduction_date > TimerGameCalendar::date) continue;
if (IsInsideMM(rti->introduction_date, 0, CalendarTime::MAX_DATE.base()) && rti->introduction_date > TimerGameCalendar::date) continue;
if (best != nullptr) {
if ((rti->max_speed == 0 ? assume_max_speed : rti->max_speed) < (best->max_speed == 0 ? assume_max_speed : best->max_speed)) continue;
@ -2720,7 +2720,7 @@ static void DoClearTownHouseHelper(TileIndex tile, Town *t, HouseID house)
DoClearSquare(tile);
DeleteAnimatedTile(tile);
DeleteNewGRFInspectWindow(GSF_HOUSES, static_cast<uint32_t>(tile));
DeleteNewGRFInspectWindow(GSF_HOUSES, tile.base());
}
/**

@ -527,7 +527,7 @@ static void DrawTile_Trees(TileInfo *ti)
/* Do not draw trees when the invisible trees setting is set */
if (IsInvisibilitySet(TO_TREES)) return;
uint tmp = CountBits(static_cast<uint32_t>(ti->tile + ti->x + ti->y));
uint tmp = CountBits(ti->tile.base() + ti->x + ti->y);
uint index = GB(tmp, 0, 2) + (GetTreeType(ti->tile) << 2);
/* different tree styles above one of the grounds */

@ -1400,7 +1400,7 @@ void AgeVehicle(Vehicle *v)
str = STR_NEWS_VEHICLE_IS_GETTING_OLD;
} else if (age == TimerGameCalendar::DateAtStartOfYear(0)) {
str = STR_NEWS_VEHICLE_IS_GETTING_VERY_OLD;
} else if (age > TimerGameCalendar::DateAtStartOfYear(0) && (static_cast<int32_t>(age) % CalendarTime::DAYS_IN_LEAP_YEAR) == 0) {
} else if (age > TimerGameCalendar::DateAtStartOfYear(0) && (age.base() % CalendarTime::DAYS_IN_LEAP_YEAR) == 0) {
str = STR_NEWS_VEHICLE_IS_GETTING_VERY_OLD_AND;
} else {
return;

@ -23,7 +23,7 @@ void ChangeWindowOwner(Owner old_owner, Owner new_owner);
template<typename T, std::enable_if_t<std::is_base_of<StrongTypedefBase, T>::value, int> = 0>
Window *FindWindowById(WindowClass cls, T number)
{
return FindWindowById(cls, static_cast<typename T::BaseType>(number));
return FindWindowById(cls, number.base());
}
void ResizeWindow(Window *w, int x, int y, bool clamp_to_screen = true);
@ -47,7 +47,7 @@ void InvalidateWindowClassesData(WindowClass cls, int data = 0, bool gui_scope =
template<typename T, std::enable_if_t<std::is_base_of<StrongTypedefBase, T>::value, int> = 0>
void InvalidateWindowData(WindowClass cls, T number, int data = 0, bool gui_scope = false)
{
InvalidateWindowData(cls, static_cast<typename T::BaseType>(number), data, gui_scope);
InvalidateWindowData(cls, number.base(), data, gui_scope);
}
void CloseNonVitalWindows();
@ -70,7 +70,7 @@ void SetWindowClassesDirty(WindowClass cls);
template<typename T, std::enable_if_t<std::is_base_of<StrongTypedefBase, T>::value, int> = 0>
void SetWindowDirty(WindowClass cls, T number)
{
SetWindowDirty(cls, static_cast<typename T::BaseType>(number));
SetWindowDirty(cls, number.base());
}
void CloseWindowById(WindowClass cls, WindowNumber number, bool force = true, int data = 0);
@ -79,7 +79,7 @@ void CloseWindowByClass(WindowClass cls, int data = 0);
template<typename T, std::enable_if_t<std::is_base_of<StrongTypedefBase, T>::value, int> = 0>
void CloseWindowById(WindowClass cls, T number, bool force = true, int data = 0)
{
CloseWindowById(cls, static_cast<typename T::BaseType>(number), force, data);
CloseWindowById(cls, number.base(), force, data);
}
bool EditBoxInGlobalFocus();

@ -289,7 +289,7 @@ public:
template<typename T, std::enable_if_t<std::is_base_of<StrongTypedefBase, T>::value, int> = 0>
void FinishInitNested(T number)
{
this->FinishInitNested(static_cast<typename T::BaseType>(number));
this->FinishInitNested(number.base());
}
/**
@ -935,7 +935,7 @@ Window *FindWindowFromPt(int x, int y);
template<typename T, std::enable_if_t<std::is_base_of<StrongTypedefBase, T>::value, int> = 0>
Window *BringWindowToFrontById(WindowClass cls, T number)
{
return BringWindowToFrontById(cls, static_cast<typename T::BaseType>(number));
return BringWindowToFrontById(cls, number.base());
}
/**

Loading…
Cancel
Save