From ab535c0a8665e6380c5037d7b6f0a507fc91d36a Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Mon, 6 Nov 2023 20:29:35 +0000 Subject: [PATCH] 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. --- src/build_vehicle_gui.cpp | 4 ++-- src/cheat_gui.cpp | 4 ++-- src/company_cmd.cpp | 2 +- src/company_gui.cpp | 2 +- src/core/format.hpp | 2 +- src/core/math_func.hpp | 4 ++-- src/core/strong_typedef_type.hpp | 8 ++++---- src/date_gui.cpp | 4 ++-- src/disaster_vehicle.cpp | 6 +++--- src/economy.cpp | 2 +- src/engine.cpp | 14 ++++++------- src/genworld_gui.cpp | 2 +- src/industry_cmd.cpp | 2 +- src/landscape.cpp | 6 +++--- src/linkgraph/flowmapper.cpp | 2 +- src/linkgraph/linkgraph.cpp | 2 +- src/linkgraph/linkgraph.h | 4 ++-- src/linkgraph/linkgraphschedule.cpp | 4 ++-- src/map.cpp | 2 +- src/map_func.h | 28 +++++++++++++------------- src/misc/dbg_helpers.cpp | 2 +- src/misc/endian_buffer.hpp | 2 +- src/misc_gui.cpp | 6 +++--- src/network/core/network_game_info.cpp | 8 ++++---- src/network/network_admin.cpp | 8 ++++---- src/newgrf.cpp | 13 ++++++------ src/newgrf_engine.cpp | 12 +++++------ src/newgrf_house.cpp | 2 +- src/newgrf_industries.cpp | 12 +++++------ src/newgrf_object.cpp | 4 ++-- src/newgrf_railtype.cpp | 8 ++++---- src/newgrf_roadtype.cpp | 8 ++++---- src/newgrf_town.cpp | 4 ++-- src/news_func.h | 2 +- src/object_cmd.cpp | 2 +- src/openttd.cpp | 4 ++-- src/order_cmd.cpp | 2 +- src/pathfinder/yapf/yapf_node.hpp | 4 ++-- src/pathfinder/yapf/yapf_node_rail.hpp | 2 +- src/rail.cpp | 2 +- src/rail_cmd.cpp | 4 ++-- src/road.cpp | 4 ++-- src/saveload/afterload.cpp | 2 +- src/saveload/oldloader_sl.cpp | 6 +++--- src/script/api/script_basestation.cpp | 2 +- src/script/api/script_bridge.cpp | 4 ++-- src/script/api/script_client.cpp | 2 +- src/script/api/script_date.cpp | 6 +++--- src/script/api/script_date.hpp | 2 +- src/script/api/script_depotlist.cpp | 4 ++-- src/script/api/script_engine.cpp | 4 ++-- src/script/api/script_industry.cpp | 8 ++++---- src/script/api/script_map.hpp | 2 +- src/script/api/script_road.cpp | 4 ++-- src/script/api/script_story_page.cpp | 2 +- src/script/api/script_tilelist.cpp | 8 ++++---- src/script/api/script_tunnel.cpp | 2 +- src/script/api/script_vehicle.cpp | 8 ++++---- src/script/squirrel_helper.hpp | 2 +- src/settings_internal.h | 8 ++++---- src/station_cmd.cpp | 6 +++--- src/story.cpp | 2 +- src/strings_func.h | 4 ++-- src/strings_internal.h | 2 +- src/timer/timer_game_calendar.cpp | 8 ++++---- src/timer/timer_game_calendar.h | 4 ++-- src/timetable_cmd.cpp | 2 +- src/toolbar_gui.cpp | 2 +- src/town_cmd.cpp | 6 +++--- src/tree_cmd.cpp | 2 +- src/vehicle.cpp | 2 +- src/window_func.h | 8 ++++---- src/window_gui.h | 4 ++-- 73 files changed, 174 insertions(+), 173 deletions(-) diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp index af8b927863..cfedffa181 100644 --- a/src/build_vehicle_gui.cpp +++ b/src/build_vehicle_gui.cpp @@ -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(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(tile); + uint num = (tile == INVALID_TILE) ? (int)type : tile.base(); assert(IsCompanyBuildableVehicleType(type)); diff --git a/src/cheat_gui.cpp b/src/cheat_gui.cpp index 2b69bbceb9..57899b9cc0 100644 --- a/src/cheat_gui.cpp +++ b/src/cheat_gui.cpp @@ -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(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(TimerGameCalendar::year); + return TimerGameCalendar::year.base(); } /** diff --git a/src/company_cmd.cpp b/src/company_cmd.cpp index 02663c301e..0e13ea05e5 100644 --- a/src/company_cmd.cpp +++ b/src/company_cmd.cpp @@ -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(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; } diff --git a/src/company_gui.cpp b/src/company_gui.cpp index 0df7e23cd4..986336b444 100644 --- a/src/company_gui.cpp +++ b/src/company_gui.cpp @@ -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(age - wid_offset)]); + DrawYearColumn(r, TimerGameCalendar::year - (age - wid_offset), c->yearly_expenses[(age - wid_offset).base()]); } break; } diff --git a/src/core/format.hpp b/src/core/format.hpp index 97abe7951c..a94c1580eb 100644 --- a/src/core/format.hpp +++ b/src/core/format.hpp @@ -37,7 +37,7 @@ struct fmt::formatter::value, int> = 0> constexpr To ClampTo(From value) { - return ClampTo(static_cast(value)); + return ClampTo(value.base()); } /** @@ -268,7 +268,7 @@ template ) { - return (size_t)(static_cast(x) - min) < (max - min); + return (size_t)(x.base() - min) < (max - min); } else { return (size_t)(x - min) < (max - min); } diff --git a/src/core/strong_typedef_type.hpp b/src/core/strong_typedef_type.hpp index f5715ed586..e1baeee311 100644 --- a/src/core/strong_typedef_type.hpp +++ b/src/core/strong_typedef_type.hpp @@ -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 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__ */ diff --git a/src/date_gui.cpp b/src/date_gui.cpp index c93dabe1e9..c81252f70f 100644 --- a/src/date_gui.cpp +++ b/src/date_gui.cpp @@ -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(STR_JUST_INT, static_cast(i), false)); + list.push_back(std::make_unique(STR_JUST_INT, i.base(), false)); } - selected = static_cast(this->date.year); + selected = this->date.year.base(); break; } diff --git a/src/disaster_vehicle.cpp b/src/disaster_vehicle.cpp index fed432fdc4..6d3ffc9e75 100644 --- a/src/disaster_vehicle.cpp +++ b/src/disaster_vehicle.cpp @@ -358,7 +358,7 @@ static bool DisasterTick_Ufo(DisasterVehicle *v) return true; } else { /* Target a vehicle */ - RoadVehicle *u = RoadVehicle::Get(static_cast(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(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(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); diff --git a/src/economy.cpp b/src/economy.cpp index bc2bd93878..53bd70c6a8 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -928,7 +928,7 @@ void StartupEconomy() if (_settings_game.economy.inflation) { /* Apply inflation that happened before our game start year. */ - int months = static_cast(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); } diff --git a/src/engine.cpp b/src/engine.cpp index d5138ad2cc..bbccfa6ffd 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -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(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(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(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(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(re->info.base_intro) << 12) ^ (re->info.decay_speed << 8) ^ - (static_cast(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(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); diff --git a/src/genworld_gui.cpp b/src/genworld_gui.cpp index 5b9e36f3d3..693d7f60c1 100644 --- a/src/genworld_gui.cpp +++ b/src/genworld_gui.cpp @@ -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(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; diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp index 7f9f6c546d..6c42240ba3 100644 --- a/src/industry_cmd.cpp +++ b/src/industry_cmd.cpp @@ -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(tile_cur)); + DeleteNewGRFInspectWindow(GSF_INDUSTRYTILES, tile_cur.base()); /* MakeWaterKeepingClass() can also handle 'land' */ MakeWaterKeepingClass(tile_cur, OWNER_NONE); diff --git a/src/landscape.cpp b/src/landscape.cpp index 87c2c73943..b534c8345a 100644 --- a/src/landscape.cpp +++ b/src/landscape.cpp @@ -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(tile) >> 1) ^ (-(int32_t)(static_cast(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(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(tile) % update_freq) == 0) IncreaseGeneratingWorldProgress(GWP_LANDSCAPE); + if ((tile.base() % update_freq) == 0) IncreaseGeneratingWorldProgress(GWP_LANDSCAPE); if (!IsValidTile(tile)) continue; diff --git a/src/linkgraph/flowmapper.cpp b/src/linkgraph/flowmapper.cpp index dfbce810a1..2fdd0a61f9 100644 --- a/src/linkgraph/flowmapper.cpp +++ b/src/linkgraph/flowmapper.cpp @@ -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(runtime)); + it.second.ScaleToMonthly(runtime.base()); } } /* Clear paths. */ diff --git a/src/linkgraph/linkgraph.cpp b/src/linkgraph/linkgraph.cpp index b573df0913..1dcb2eecff 100644 --- a/src/linkgraph/linkgraph.cpp +++ b/src/linkgraph/linkgraph.cpp @@ -65,7 +65,7 @@ void LinkGraph::ShiftDates(TimerGameCalendar::Date interval) void LinkGraph::Compress() { - this->last_compression = static_cast(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) { diff --git a/src/linkgraph/linkgraph.h b/src/linkgraph/linkgraph.h index ff1778e0c7..12f32a2885 100644 --- a/src/linkgraph/linkgraph.h +++ b/src/linkgraph/linkgraph.h @@ -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(target_age) / static_cast(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(TimerGameCalendar::date - this->last_compression + 1); + return base * 30 / (TimerGameCalendar::date - this->last_compression + 1).base(); } NodeID AddNode(const Station *st); diff --git a/src/linkgraph/linkgraphschedule.cpp b/src/linkgraph/linkgraphschedule.cpp index 3f3fed8168..0e2f03785c 100644 --- a/src/linkgraph/linkgraphschedule.cpp +++ b/src/linkgraph/linkgraphschedule.cpp @@ -178,7 +178,7 @@ void StateGameLoop_LinkGraphPauseControl() } } else if (_pause_mode == PM_UNPAUSED && TimerGameCalendar::date_fract == LinkGraphSchedule::SPAWN_JOIN_TICK - 2 && - static_cast(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(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) { diff --git a/src/map.cpp b/src/map.cpp index 2fea8ae36c..f9a8ff5db9 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -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 diff --git a/src/map_func.h b/src/map_func.h index 89507a9c70..d4b3de70bc 100644 --- a/src/map_func.h +++ b/src/map_func.h @@ -77,7 +77,7 @@ public: /** * Implicit conversion to the uint for bounds checking. */ - debug_inline constexpr operator uint() const { return static_cast(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(tile)].type; + return base_tiles[tile.base()].type; } /** @@ -100,7 +100,7 @@ public: */ debug_inline byte &height() { - return base_tiles[static_cast(tile)].height; + return base_tiles[tile.base()].height; } /** @@ -112,7 +112,7 @@ public: */ debug_inline byte &m1() { - return base_tiles[static_cast(tile)].m1; + return base_tiles[tile.base()].m1; } /** @@ -124,7 +124,7 @@ public: */ debug_inline uint16_t &m2() { - return base_tiles[static_cast(tile)].m2; + return base_tiles[tile.base()].m2; } /** @@ -136,7 +136,7 @@ public: */ debug_inline byte &m3() { - return base_tiles[static_cast(tile)].m3; + return base_tiles[tile.base()].m3; } /** @@ -148,7 +148,7 @@ public: */ debug_inline byte &m4() { - return base_tiles[static_cast(tile)].m4; + return base_tiles[tile.base()].m4; } /** @@ -160,7 +160,7 @@ public: */ debug_inline byte &m5() { - return base_tiles[static_cast(tile)].m5; + return base_tiles[tile.base()].m5; } /** @@ -172,7 +172,7 @@ public: */ debug_inline byte &m6() { - return extended_tiles[static_cast(tile)].m6; + return extended_tiles[tile.base()].m6; } /** @@ -184,7 +184,7 @@ public: */ debug_inline byte &m7() { - return extended_tiles[static_cast(tile)].m7; + return extended_tiles[tile.base()].m7; } /** @@ -196,7 +196,7 @@ public: */ debug_inline uint16_t &m8() { - return extended_tiles[static_cast(tile)].m8; + return extended_tiles[tile.base()].m8; } }; @@ -316,7 +316,7 @@ public: */ static inline TileIndex WrapToMap(TileIndex tile) { - return static_cast(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(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(tile) >> Map::LogX(); + return tile.base() >> Map::LogX(); } /** diff --git a/src/misc/dbg_helpers.cpp b/src/misc/dbg_helpers.cpp index 8c18d7b77c..b2e743c7ea 100644 --- a/src/misc/dbg_helpers.cpp +++ b/src/misc/dbg_helpers.cpp @@ -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(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(); } diff --git a/src/misc/endian_buffer.hpp b/src/misc/endian_buffer.hpp index 8422ebb4d3..17cb576878 100644 --- a/src/misc/endian_buffer.hpp +++ b/src/misc/endian_buffer.hpp @@ -53,7 +53,7 @@ public: if constexpr (std::is_enum_v) { this->Write(static_cast>(data)); } else if constexpr (std::is_base_of_v) { - this->Write(static_cast(data)); + this->Write(data.base()); } else { this->Write(data); } diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp index 0780d3b876..49dd4cc552 100644 --- a/src/misc_gui.cpp +++ b/src/misc_gui.cpp @@ -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(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(this->tile)); + return ::IsNewGRFInspectable(GetGrfSpecFeature(this->tile), this->tile.base()); } void ShowNewGRFInspectWindow() const override { - ::ShowNewGRFInspectWindow(GetGrfSpecFeature(this->tile), static_cast(this->tile)); + ::ShowNewGRFInspectWindow(GetGrfSpecFeature(this->tile), this->tile.base()); } void OnClick([[maybe_unused]] Point pt, int widget, [[maybe_unused]] int click_count) override diff --git a/src/network/core/network_game_info.cpp b/src/network/core/network_game_info.cpp index 817eb518b8..ecf6569d86 100644 --- a/src/network/core/network_game_info.cpp +++ b/src/network/core/network_game_info.cpp @@ -227,8 +227,8 @@ void SerializeNetworkGameInfo(Packet *p, const NetworkServerGameInfo *info, bool } /* NETWORK_GAME_INFO_VERSION = 3 */ - p->Send_uint32(static_cast(info->game_date)); - p->Send_uint32(static_cast(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(CalendarTime::MAX_DATE)); - info->start_date = Clamp(p->Recv_uint32(), 0, static_cast(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: diff --git a/src/network/network_admin.cpp b/src/network/network_admin.cpp index 3e633f9b34..3df0182937 100644 --- a/src/network/network_admin.cpp +++ b/src/network/network_admin.cpp @@ -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(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(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(cs->client_address).GetHostname()); p->Send_string(ci->client_name); p->Send_uint8 (0); // Used to be language - p->Send_uint32(static_cast(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(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 diff --git a/src/newgrf.cpp b/src/newgrf.cpp index 604fe777e8..5bf37d1554 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -6512,18 +6512,18 @@ bool GetGlobalVariable(byte param, uint32_t *value, const GRFFile *grffile) { switch (param) { case 0x00: // current date - *value = static_cast(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(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(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(TimerGameCalendar::date); + *value = TimerGameCalendar::date.base(); return true; case 0x24: // long format year - *value = static_cast(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(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; diff --git a/src/newgrf_engine.cpp b/src/newgrf_engine.cpp index 27321ec496..df3be19561 100644 --- a/src/newgrf_engine.cpp +++ b/src/newgrf_engine.cpp @@ -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(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(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(v->age), 8, 8); case 0x42: return ClampTo(v->max_age); case 0x43: return GB(ClampTo(v->max_age), 8, 8); - case 0x44: return static_cast(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(TimerGameCalendar::year); // 'Long' format build year - case 0x4B: return static_cast(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(TimerGameCalendar::date - CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR); // Date of last service case 0x93: return GB(ClampTo(TimerGameCalendar::date - CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR), 8, 8); - case 0xC4: return static_cast(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 diff --git a/src/newgrf_house.cpp b/src/newgrf_house.cpp index feab4c4fc0..63e7c44d69 100644 --- a/src/newgrf_house.cpp +++ b/src/newgrf_house.cpp @@ -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(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); diff --git a/src/newgrf_industries.cpp b/src/newgrf_industries.cpp index b25691267c..2f37abf5d4 100644 --- a/src/newgrf_industries.cpp +++ b/src/newgrf_industries.cpp @@ -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(this->tile); - case 0x81: return GB(static_cast(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(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(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(this->industry->location.tile); - case 0x81: return GB(static_cast(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: diff --git a/src/newgrf_object.cpp b/src/newgrf_object.cpp index c6098d54c7..740f82ec97 100644 --- a/src/newgrf_object.cpp +++ b/src/newgrf_object.cpp @@ -277,7 +277,7 @@ static uint32_t GetCountAndDistanceOfClosestInstance(byte local_id, uint32_t grf break; /* Construction date */ - case 0x42: return static_cast(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(this->obj->build_date); + case 0x42: return this->obj->build_date.base(); /* Animation counter */ case 0x43: return GetAnimationFrame(this->tile); diff --git a/src/newgrf_railtype.cpp b/src/newgrf_railtype.cpp index 694025ef07..608e63546f 100644 --- a/src/newgrf_railtype.cpp +++ b/src/newgrf_railtype.cpp @@ -19,7 +19,7 @@ /* virtual */ uint32_t RailTypeScopeResolver::GetRandomBits() const { - uint tmp = CountBits(static_cast(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(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(Depot::GetByTile(this->tile)->build_date); - return static_cast(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)) { diff --git a/src/newgrf_roadtype.cpp b/src/newgrf_roadtype.cpp index c49850d687..4a877c8bf3 100644 --- a/src/newgrf_roadtype.cpp +++ b/src/newgrf_roadtype.cpp @@ -19,7 +19,7 @@ /* virtual */ uint32_t RoadTypeScopeResolver::GetRandomBits() const { - uint tmp = CountBits(static_cast(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(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(Depot::GetByTile(this->tile)->build_date); - return static_cast(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)) { diff --git a/src/newgrf_town.cpp b/src/newgrf_town.cpp index 5f8f5972c8..83eda4204c 100644 --- a/src/newgrf_town.cpp +++ b/src/newgrf_town.cpp @@ -44,8 +44,8 @@ } /* Town properties */ - case 0x80: return static_cast(this->t->xy); - case 0x81: return GB(static_cast(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(this->t->cache.population); case 0x83: return GB(ClampTo(this->t->cache.population), 8, 8); case 0x8A: return this->t->grow_counter / Ticks::TOWN_GROWTH_TICKS; diff --git a/src/news_func.h b/src/news_func.h index 941e6b54c9..01f22ebc8a 100644 --- a/src/news_func.h +++ b/src/news_func.h @@ -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(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) diff --git a/src/object_cmd.cpp b/src/object_cmd.cpp index fb39133dc7..f8c503499b 100644 --- a/src/object_cmd.cpp +++ b/src/object_cmd.cpp @@ -511,7 +511,7 @@ static void ReallyClearObjectTile(Object *o) { Object::DecTypeCount(o->type); for (TileIndex tile_cur : o->location) { - DeleteNewGRFInspectWindow(GSF_OBJECTS, static_cast(tile_cur)); + DeleteNewGRFInspectWindow(GSF_OBJECTS, tile_cur.base()); MakeWaterKeepingClass(tile_cur, GetTileOwner(tile_cur)); } diff --git a/src/openttd.cpp b/src/openttd.cpp index 611d21f1e3..19eb01432f 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -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(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(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); diff --git a/src/order_cmd.cpp b/src/order_cmd.cpp index fc32913bdc..2650843c1f 100644 --- a/src/order_cmd.cpp +++ b/src/order_cmd.cpp @@ -1900,7 +1900,7 @@ static bool OrderConditionCompare(OrderConditionComparator occ, int variable, in template ::value, int> = 0> static bool OrderConditionCompare(OrderConditionComparator occ, T variable, int value) { - return OrderConditionCompare(occ, static_cast(variable), value); + return OrderConditionCompare(occ, variable.base(), value); } /** diff --git a/src/pathfinder/yapf/yapf_node.hpp b/src/pathfinder/yapf/yapf_node.hpp index 9d079ae918..760ed330bb 100644 --- a/src/pathfinder/yapf/yapf_node.hpp +++ b/src/pathfinder/yapf/yapf_node.hpp @@ -25,7 +25,7 @@ struct CYapfNodeKeyExitDir { inline int CalcHash() const { - return m_exitdir | (static_cast(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(m_tile) << 4); + return m_td | (m_tile.base() << 4); } inline bool operator==(const CYapfNodeKeyTrackDir &other) const diff --git a/src/pathfinder/yapf/yapf_node_rail.hpp b/src/pathfinder/yapf/yapf_node_rail.hpp index cecaaa95c4..a7a0795150 100644 --- a/src/pathfinder/yapf/yapf_node_rail.hpp +++ b/src/pathfinder/yapf/yapf_node_rail.hpp @@ -27,7 +27,7 @@ struct CYapfRailSegmentKey inline void Set(const CYapfNodeKeyTrackDir &node_key) { - m_value = (static_cast(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 diff --git a/src/rail.cpp b/src/rail.cpp index 9bd11e391c..01b6421535 100644 --- a/src/rail.cpp +++ b/src/rail.cpp @@ -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(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; diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp index 1d312ffd49..d4dd2fe65d 100644 --- a/src/rail_cmd.cpp +++ b/src/rail_cmd.cpp @@ -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(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(tile)); + DeleteNewGRFInspectWindow(GSF_RAILTYPES, tile.base()); } else { SetTrackBits(tile, present); SetTrackReservation(tile, GetRailReservationTrackBits(tile) & present); diff --git a/src/road.cpp b/src/road.cpp index bf607fdb36..d3de25d44f 100644 --- a/src/road.cpp +++ b/src/road.cpp @@ -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(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(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; diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp index d94b17306d..1a13b011c9 100644 --- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -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(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; } diff --git a/src/saveload/oldloader_sl.cpp b/src/saveload/oldloader_sl.cpp index 54c4f51090..7589e87708 100644 --- a/src/saveload/oldloader_sl.cpp +++ b/src/saveload/oldloader_sl.cpp @@ -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(t) * 2]; - tile.m4() = _old_map3[static_cast(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(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 */ diff --git a/src/script/api/script_basestation.cpp b/src/script/api/script_basestation.cpp index caa5cf8034..2dc0ce6c81 100644 --- a/src/script/api/script_basestation.cpp +++ b/src/script/api/script_basestation.cpp @@ -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(); } diff --git a/src/script/api/script_bridge.cpp b/src/script/api/script_bridge.cpp index b128c87d2b..165fc60a2f 100644 --- a/src/script/api/script_bridge.cpp +++ b/src/script/api/script_bridge.cpp @@ -83,8 +83,8 @@ static void _DoCommandReturnBuildBridge1(class ScriptInstance *instance) switch (vehicle_type) { case ScriptVehicle::VT_ROAD: - ScriptObject::SetCallbackVariable(0, static_cast(start)); - ScriptObject::SetCallbackVariable(1, static_cast(end)); + ScriptObject::SetCallbackVariable(0, start.base()); + ScriptObject::SetCallbackVariable(1, end.base()); return ScriptObject::Command::Do(&::_DoCommandReturnBuildBridge1, end, start, TRANSPORT_ROAD, bridge_id, ScriptRoad::GetCurrentRoadType()); case ScriptVehicle::VT_RAIL: return ScriptObject::Command::Do(end, start, TRANSPORT_RAIL, bridge_id, ScriptRail::GetCurrentRailType()); diff --git a/src/script/api/script_client.cpp b/src/script/api/script_client.cpp index 5445698913..9b65f638db 100644 --- a/src/script/api/script_client.cpp +++ b/src/script/api/script_client.cpp @@ -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(); } diff --git a/src/script/api/script_date.cpp b/src/script/api/script_date.cpp index 886bef830f..d82c2815f4 100644 --- a/src/script/api/script_date.cpp +++ b/src/script/api/script_date.cpp @@ -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() diff --git a/src/script/api/script_date.hpp b/src/script/api/script_date.hpp index 2e108a74c8..b224c6e62b 100644 --- a/src/script/api/script_date.hpp +++ b/src/script/api/script_date.hpp @@ -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. }; /** diff --git a/src/script/api/script_depotlist.cpp b/src/script/api/script_depotlist.cpp index 9f2dc96ee4..6f3caa2900 100644 --- a/src/script/api/script_depotlist.cpp +++ b/src/script/api/script_depotlist.cpp @@ -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(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(depot->xy)); + if ((::GetTileOwner(depot->xy) == ScriptObject::GetCompany() || ScriptCompanyMode::IsDeity()) && ::IsTileType(depot->xy, tile_type)) this->AddItem(depot->xy.base()); } } diff --git a/src/script/api/script_engine.cpp b/src/script/api/script_engine.cpp index 9797b863c4..22caa1fad9 100644 --- a/src/script/api/script_engine.cpp +++ b/src/script/api/script_engine.cpp @@ -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) diff --git a/src/script/api/script_industry.cpp b/src/script/api/script_industry.cpp index 3196e9c698..86f5a85e40 100644 --- a/src/script/api/script_industry.cpp +++ b/src/script/api/script_industry.cpp @@ -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(); } } diff --git a/src/script/api/script_map.hpp b/src/script/api/script_map.hpp index 45b4a4b191..323ba31c28 100644 --- a/src/script/api/script_map.hpp +++ b/src/script/api/script_map.hpp @@ -19,7 +19,7 @@ */ class ScriptMap : public ScriptObject { public: - static const int TILE_INVALID = static_cast(INVALID_TILE); ///< Invalid TileIndex. + static const int TILE_INVALID = INVALID_TILE.base(); ///< Invalid TileIndex. /** * Checks whether the given tile is valid. diff --git a/src/script/api/script_road.cpp b/src/script/api/script_road.cpp index 8c702f1b41..2be3dac282 100644 --- a/src/script/api/script_road.cpp +++ b/src/script/api/script_road.cpp @@ -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(start_); - int32_t end = static_cast(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; diff --git a/src/script/api/script_story_page.cpp b/src/script/api/script_story_page.cpp index 4a049f540c..87a46427eb 100644 --- a/src/script/api/script_story_page.cpp +++ b/src/script/api/script_story_page.cpp @@ -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) diff --git a/src/script/api/script_tilelist.cpp b/src/script/api/script_tilelist.cpp index e23b4eaa33..6262db3acc 100644 --- a/src/script/api/script_tilelist.cpp +++ b/src/script/api/script_tilelist.cpp @@ -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(t)); + for (TileIndex t : ta) this->AddItem(t.base()); } void ScriptTileList::AddTile(TileIndex tile) { if (!::IsValidTile(tile)) return; - this->AddItem(static_cast(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(t)); + for (TileIndex t : ta) this->RemoveItem(t.base()); } void ScriptTileList::RemoveTile(TileIndex tile) { if (!::IsValidTile(tile)) return; - this->RemoveItem(static_cast(tile)); + this->RemoveItem(tile.base()); } /** diff --git a/src/script/api/script_tunnel.cpp b/src/script/api/script_tunnel.cpp index a1ff3e03e2..1ae9f2d78f 100644 --- a/src/script/api/script_tunnel.cpp +++ b/src/script/api/script_tunnel.cpp @@ -93,7 +93,7 @@ static void _DoCommandReturnBuildTunnel1(class ScriptInstance *instance) /* For rail we do nothing special */ return ScriptObject::Command::Do(start, TRANSPORT_RAIL, ScriptRail::GetCurrentRailType()); } else { - ScriptObject::SetCallbackVariable(0, static_cast(start)); + ScriptObject::SetCallbackVariable(0, start.base()); return ScriptObject::Command::Do(&::_DoCommandReturnBuildTunnel1, start, TRANSPORT_ROAD, ScriptRoad::GetCurrentRoadType()); } } diff --git a/src/script/api/script_vehicle.cpp b/src/script/api/script_vehicle.cpp index 76f4f282b0..4b1c3c2baf 100644 --- a/src/script/api/script_vehicle.cpp +++ b/src/script/api/script_vehicle.cpp @@ -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) diff --git a/src/script/squirrel_helper.hpp b/src/script/squirrel_helper.hpp index ba22fc881a..cff129c6d2 100644 --- a/src/script/squirrel_helper.hpp +++ b/src/script/squirrel_helper.hpp @@ -37,7 +37,7 @@ namespace SQConvert { template <> struct Return { static inline int Set(HSQUIRRELVM vm, int32_t res) { sq_pushinteger(vm, res); return 1; } }; template <> struct Return { static inline int Set(HSQUIRRELVM vm, int64_t res) { sq_pushinteger(vm, res); return 1; } }; template <> struct Return { static inline int Set(HSQUIRRELVM vm, Money res) { sq_pushinteger(vm, res); return 1; } }; - template <> struct Return { static inline int Set(HSQUIRRELVM vm, TileIndex res) { sq_pushinteger(vm, (int32_t)static_cast(res)); return 1; } }; + template <> struct Return { static inline int Set(HSQUIRRELVM vm, TileIndex res) { sq_pushinteger(vm, (int32_t)res.base()); return 1; } }; template <> struct Return { static inline int Set(HSQUIRRELVM vm, bool res) { sq_pushbool (vm, res); return 1; } }; template <> struct Return { /* Do not use char *, use std::optional instead. */ }; template <> struct Return { /* Do not use const char *, use std::optional instead. */ }; diff --git a/src/settings_internal.h b/src/settings_internal.h index 7980ebae03..914071909b 100644 --- a/src/settings_internal.h +++ b/src/settings_internal.h @@ -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) { - this->def = static_cast(def); + this->def = def.base(); } else { this->def = def; } if constexpr (std::is_base_of_v) { - this->min = static_cast(min); + this->min = min.base(); } else { this->min = min; } if constexpr (std::is_base_of_v) { - this->max = static_cast(max); + this->max = max.base(); } else { this->max = max; } if constexpr (std::is_base_of_v) { - this->interval = static_cast(interval); + this->interval = interval.base(); } else { this->interval = interval; } diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index 2f03490441..4a561ad060 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -1664,7 +1664,7 @@ CommandCost RemoveFromRailBaseStation(TileArea ta, std::vector &affected_st if (!build_rail && !IsStationTileBlocked(tile)) Company::Get(owner)->infrastructure.rail[rt]--; DoClearSquare(tile); - DeleteNewGRFInspectWindow(GSF_STATIONS, static_cast(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(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(tile_cur)); + DeleteNewGRFInspectWindow(GSF_AIRPORTTILES, tile_cur.base()); } } diff --git a/src/story.cpp b/src/story.cpp index 86e09a0705..a03c2a12f7 100644 --- a/src/story.cpp +++ b/src/story.cpp @@ -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(tile); + pe.referenced_id = tile.base(); break; case SPET_GOAL: pe.referenced_id = (GoalID)reference; diff --git a/src/strings_func.h b/src/strings_func.h index 38417a85b7..bb2e5476d5 100644 --- a/src/strings_func.h +++ b/src/strings_func.h @@ -86,13 +86,13 @@ void SetDParamMaxDigits(size_t n, uint count, FontSize size = FS_NORMAL); template ::value, int> = 0> void SetDParam(size_t n, T v) { - SetDParam(n, static_cast(v)); + SetDParam(n, v.base()); } template ::value, int> = 0> void SetDParamMaxValue(size_t n, T max_value, uint min_count = 0, FontSize size = FS_NORMAL) { - SetDParamMaxValue(n, static_cast(max_value), min_count, size); + SetDParamMaxValue(n, max_value.base(), min_count, size); } void SetDParamStr(size_t n, const char *str); diff --git a/src/strings_internal.h b/src/strings_internal.h index ef5499059a..f5648d3d39 100644 --- a/src/strings_internal.h +++ b/src/strings_internal.h @@ -156,7 +156,7 @@ public: template ::value, int> = 0> void SetParam(size_t n, T v) { - SetParam(n, static_cast(v)); + SetParam(n, v.base()); } void SetParam(size_t n, const char *str) diff --git a/src/timer/timer_game_calendar.cpp b/src/timer/timer_game_calendar.cpp index dcdabfb021..4b62da7f6a 100644 --- a/src/timer/timer_game_calendar.cpp +++ b/src/timer/timer_game_calendar.cpp @@ -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(date) / (CalendarTime::DAYS_IN_YEAR * 400 + 97)); - int rem = static_cast(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(yr) % 4 == 0 && (static_cast(yr) % 100 != 0 || static_cast(yr) % 400 == 0); + return yr.base() % 4 == 0 && (yr.base() % 100 != 0 || yr.base() % 400 == 0); } /** @@ -215,7 +215,7 @@ void TimerManager::Elapsed([[maybe_unused]] TimerGameCalendar timer->Elapsed(TimerGameCalendar::DAY); } - if ((static_cast(TimerGameCalendar::date) % 7) == 3) { + if ((TimerGameCalendar::date.base() % 7) == 3) { for (auto timer : timers) { timer->Elapsed(TimerGameCalendar::WEEK); } diff --git a/src/timer/timer_game_calendar.h b/src/timer/timer_game_calendar.h index e62f745615..0b82db80c6 100644 --- a/src/timer/timer_game_calendar.h +++ b/src/timer/timer_game_calendar.h @@ -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(date) / 366; + return date.base() / 366; } /** @@ -123,7 +123,7 @@ public: */ static constexpr Date DateAtStartOfYear(Year year) { - int32_t year_as_int = static_cast(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. */ diff --git a/src/timetable_cmd.cpp b/src/timetable_cmd.cpp index 6b77355c59..a18ed54426 100644 --- a/src/timetable_cmd.cpp +++ b/src/timetable_cmd.cpp @@ -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(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; } diff --git a/src/toolbar_gui.cpp b/src/toolbar_gui.cpp index 7df6a2c833..8919c99dac 100644 --- a/src/toolbar_gui.cpp +++ b/src/toolbar_gui.cpp @@ -2499,7 +2499,7 @@ struct ScenarioEditorToolbarWindow : Window { value = atoi(str); } else { /* An empty string means revert to the default */ - value = static_cast(CalendarTime::DEF_START_YEAR); + value = CalendarTime::DEF_START_YEAR.base(); } SetStartingYear(value); diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index 49a4ab1acf..30463dd25d 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -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(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(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(tile)); + DeleteNewGRFInspectWindow(GSF_HOUSES, tile.base()); } /** diff --git a/src/tree_cmd.cpp b/src/tree_cmd.cpp index e0dc5279bc..99406f81fb 100644 --- a/src/tree_cmd.cpp +++ b/src/tree_cmd.cpp @@ -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(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 */ diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 2fc8ee6cc1..e2cf5ba841 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -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(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; diff --git a/src/window_func.h b/src/window_func.h index c99ef98616..8cc02153ee 100644 --- a/src/window_func.h +++ b/src/window_func.h @@ -23,7 +23,7 @@ void ChangeWindowOwner(Owner old_owner, Owner new_owner); template::value, int> = 0> Window *FindWindowById(WindowClass cls, T number) { - return FindWindowById(cls, static_cast(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::value, int> = 0> void InvalidateWindowData(WindowClass cls, T number, int data = 0, bool gui_scope = false) { - InvalidateWindowData(cls, static_cast(number), data, gui_scope); + InvalidateWindowData(cls, number.base(), data, gui_scope); } void CloseNonVitalWindows(); @@ -70,7 +70,7 @@ void SetWindowClassesDirty(WindowClass cls); template::value, int> = 0> void SetWindowDirty(WindowClass cls, T number) { - SetWindowDirty(cls, static_cast(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::value, int> = 0> void CloseWindowById(WindowClass cls, T number, bool force = true, int data = 0) { - CloseWindowById(cls, static_cast(number), force, data); + CloseWindowById(cls, number.base(), force, data); } bool EditBoxInGlobalFocus(); diff --git a/src/window_gui.h b/src/window_gui.h index e444c6ea89..46dcdd6acb 100644 --- a/src/window_gui.h +++ b/src/window_gui.h @@ -289,7 +289,7 @@ public: template::value, int> = 0> void FinishInitNested(T number) { - this->FinishInitNested(static_cast(number)); + this->FinishInitNested(number.base()); } /** @@ -935,7 +935,7 @@ Window *FindWindowFromPt(int x, int y); template::value, int> = 0> Window *BringWindowToFrontById(WindowClass cls, T number) { - return BringWindowToFrontById(cls, static_cast(number)); + return BringWindowToFrontById(cls, number.base()); } /**