diff --git a/src/ai/ai_core.cpp b/src/ai/ai_core.cpp index 6827546bcb..122c4fb83c 100644 --- a/src/ai/ai_core.cpp +++ b/src/ai/ai_core.cpp @@ -190,7 +190,7 @@ AI::scanner_info = nullptr; AI::scanner_library = nullptr; - for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; ++c) { + for (CompanyID c = CompanyID::Begin(); c < MAX_COMPANIES; ++c) { if (_settings_game.ai_config[c] != nullptr) { delete _settings_game.ai_config[c]; _settings_game.ai_config[c] = nullptr; @@ -208,7 +208,7 @@ /* Check for both newgame as current game if we can reload the AIInfo inside * the AIConfig. If not, remove the AI from the list (which will assign * a random new AI on reload). */ - for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; ++c) { + for (CompanyID c = CompanyID::Begin(); c < MAX_COMPANIES; ++c) { if (_settings_game.ai_config[c] != nullptr && _settings_game.ai_config[c]->HasScript()) { if (!_settings_game.ai_config[c]->ResetInfo(true)) { Debug(script, 0, "After a reload, the AI by the name '{}' was no longer found, and removed from the list.", _settings_game.ai_config[c]->GetName()); @@ -270,7 +270,7 @@ } /* Try to send the event to all AIs */ - for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; ++c) { + for (CompanyID c = CompanyID::Begin(); c < MAX_COMPANIES; ++c) { if (c != skip_company) AI::NewEvent(c, event); } } diff --git a/src/ai/ai_gui.cpp b/src/ai/ai_gui.cpp index 8c4143bf93..41ccf0e2b1 100644 --- a/src/ai/ai_gui.cpp +++ b/src/ai/ai_gui.cpp @@ -93,7 +93,7 @@ static WindowDesc _ai_config_desc( * Window to configure which AIs will start. */ struct AIConfigWindow : public Window { - CompanyID selected_slot; ///< The currently selected AI slot or \c INVALID_COMPANY. + CompanyID selected_slot; ///< The currently selected AI slot or \c CompanyID::Invalid(). int line_height; ///< Height of a single AI-name line. Scrollbar *vscroll; ///< Cache of the vertical scrollbar. @@ -101,7 +101,7 @@ struct AIConfigWindow : public Window { { this->InitNested(WN_GAME_OPTIONS_AI); // Initializes 'this->line_height' as a side effect. this->vscroll = this->GetScrollbar(WID_AIC_SCROLLBAR); - this->selected_slot = INVALID_COMPANY; + this->selected_slot = CompanyID::Invalid(); NWidgetCore *nwi = this->GetWidget(WID_AIC_LIST); this->vscroll->SetCapacity(nwi->current_y / this->line_height); this->vscroll->SetCount(MAX_COMPANIES); @@ -169,7 +169,7 @@ struct AIConfigWindow : public Window { for (const Company *c : Company::Iterate()) { if (c->is_ai) max_slot--; } - for (CompanyID cid = COMPANY_FIRST; cid < max_slot && cid < MAX_COMPANIES; ++cid) { + for (CompanyID cid = CompanyID::Begin(); cid < max_slot && cid < MAX_COMPANIES; ++cid) { if (Company::IsValidID(cid)) max_slot++; } } else { @@ -206,7 +206,7 @@ struct AIConfigWindow : public Window { void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override { if (widget >= WID_AIC_TEXTFILE && widget < WID_AIC_TEXTFILE + TFT_CONTENT_END) { - if (this->selected_slot == INVALID_COMPANY || AIConfig::GetConfig(this->selected_slot) == nullptr) return; + if (this->selected_slot == CompanyID::Invalid() || AIConfig::GetConfig(this->selected_slot) == nullptr) return; ShowScriptTextfileWindow((TextfileType)(widget - WID_AIC_TEXTFILE), this->selected_slot); return; @@ -266,7 +266,7 @@ struct AIConfigWindow : public Window { case WID_AIC_OPEN_URL: { const AIConfig *config = AIConfig::GetConfig(this->selected_slot); - if (this->selected_slot == INVALID_COMPANY || config == nullptr || config->GetInfo() == nullptr) return; + if (this->selected_slot == CompanyID::Invalid() || config == nullptr || config->GetInfo() == nullptr) return; OpenBrowser(config->GetInfo()->GetURL()); break; } @@ -297,25 +297,25 @@ struct AIConfigWindow : public Window { void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override { if (!IsEditable(this->selected_slot) && !Company::IsValidAiID(this->selected_slot)) { - this->selected_slot = INVALID_COMPANY; + this->selected_slot = CompanyID::Invalid(); } if (!gui_scope) return; - AIConfig *config = this->selected_slot == INVALID_COMPANY ? nullptr : AIConfig::GetConfig(this->selected_slot); + AIConfig *config = this->selected_slot == CompanyID::Invalid() ? nullptr : AIConfig::GetConfig(this->selected_slot); this->SetWidgetDisabledState(WID_AIC_DECREASE_NUMBER, GetGameSettings().difficulty.max_no_competitors == 0); this->SetWidgetDisabledState(WID_AIC_INCREASE_NUMBER, GetGameSettings().difficulty.max_no_competitors == MAX_COMPANIES - 1); this->SetWidgetDisabledState(WID_AIC_DECREASE_INTERVAL, GetGameSettings().difficulty.competitors_interval == MIN_COMPETITORS_INTERVAL); this->SetWidgetDisabledState(WID_AIC_INCREASE_INTERVAL, GetGameSettings().difficulty.competitors_interval == MAX_COMPETITORS_INTERVAL); this->SetWidgetDisabledState(WID_AIC_CHANGE, !IsEditable(this->selected_slot)); - this->SetWidgetDisabledState(WID_AIC_CONFIGURE, this->selected_slot == INVALID_COMPANY || config->GetConfigList()->empty()); + this->SetWidgetDisabledState(WID_AIC_CONFIGURE, this->selected_slot == CompanyID::Invalid() || config->GetConfigList()->empty()); this->SetWidgetDisabledState(WID_AIC_MOVE_UP, !IsEditable(this->selected_slot) || !IsEditable((CompanyID)(this->selected_slot - 1))); this->SetWidgetDisabledState(WID_AIC_MOVE_DOWN, !IsEditable(this->selected_slot) || !IsEditable((CompanyID)(this->selected_slot + 1))); - this->SetWidgetDisabledState(WID_AIC_OPEN_URL, this->selected_slot == INVALID_COMPANY || config->GetInfo() == nullptr || config->GetInfo()->GetURL().empty()); + this->SetWidgetDisabledState(WID_AIC_OPEN_URL, this->selected_slot == CompanyID::Invalid() || config->GetInfo() == nullptr || config->GetInfo()->GetURL().empty()); for (TextfileType tft = TFT_CONTENT_BEGIN; tft < TFT_CONTENT_END; tft++) { - this->SetWidgetDisabledState(WID_AIC_TEXTFILE + tft, this->selected_slot == INVALID_COMPANY || !config->GetTextfile(tft, this->selected_slot).has_value()); + this->SetWidgetDisabledState(WID_AIC_TEXTFILE + tft, this->selected_slot == CompanyID::Invalid() || !config->GetTextfile(tft, this->selected_slot).has_value()); } } }; diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp index 34410e069c..9914e93132 100644 --- a/src/aircraft_cmd.cpp +++ b/src/aircraft_cmd.cpp @@ -116,15 +116,15 @@ enum HelicopterRotorStates : uint8_t { /** * Find the nearest hangar to v - * INVALID_STATION is returned, if the company does not have any suitable + * StationID::Invalid() is returned, if the company does not have any suitable * airports (like helipads only) * @param v vehicle looking for a hangar - * @return the StationID if one is found, otherwise, INVALID_STATION + * @return the StationID if one is found, otherwise, StationID::Invalid() */ static StationID FindNearestHangar(const Aircraft *v) { uint best = 0; - StationID index = INVALID_STATION; + StationID index = StationID::Invalid(); TileIndex vtile = TileVirtXY(v->x_pos, v->y_pos); const AircraftVehicleInfo *avi = AircraftVehInfo(v->engine_type); uint max_range = v->acache.cached_max_range_sqr; @@ -163,7 +163,7 @@ static StationID FindNearestHangar(const Aircraft *v) /* v->tile can't be used here, when aircraft is flying v->tile is set to 0 */ uint distance = DistanceSquare(vtile, st->airport.tile); - if (distance < best || index == INVALID_STATION) { + if (distance < best || index == StationID::Invalid()) { best = distance; index = st->index; } @@ -318,8 +318,8 @@ CommandCost CmdBuildAircraft(DoCommandFlags flags, TileIndex tile, const Engine } v->name.clear(); - v->last_station_visited = INVALID_STATION; - v->last_loading_station = INVALID_STATION; + v->last_station_visited = StationID::Invalid(); + v->last_loading_station = StationID::Invalid(); v->acceleration = avi->acceleration; v->engine_type = e->index; @@ -404,7 +404,7 @@ ClosestDepot Aircraft::FindClosestDepot() /* the aircraft has to search for a hangar on its own */ StationID station = FindNearestHangar(this); - if (station == INVALID_STATION) return ClosestDepot(); + if (station == StationID::Invalid()) return ClosestDepot(); st = Station::Get(station); } @@ -1357,7 +1357,7 @@ static void CrashAirplane(Aircraft *v) newstype = NewsType::AccidentOther; } - AddTileNewsItem(newsitem, newstype, vt, st != nullptr ? st->index : INVALID_STATION); + AddTileNewsItem(newsitem, newstype, vt, st != nullptr ? st->index : StationID::Invalid()); ModifyStationRatingAround(vt, v->owner, -160, 30); if (_settings_client.sound.disaster) SndPlayVehicleFx(SND_12_EXPLOSION, v); diff --git a/src/airport_gui.cpp b/src/airport_gui.cpp index 7384f39a13..3c7811c35b 100644 --- a/src/airport_gui.cpp +++ b/src/airport_gui.cpp @@ -70,7 +70,7 @@ static void PlaceAirport(TileIndex tile) auto proc = [=](bool test, StationID to_join) -> bool { if (test) { - return Command::Do(CommandFlagsToDCFlags(GetCommandFlags()), tile, airport_type, layout, INVALID_STATION, adjacent).Succeeded(); + return Command::Do(CommandFlagsToDCFlags(GetCommandFlags()), tile, airport_type, layout, StationID::Invalid(), adjacent).Succeeded(); } else { return Command::Post(STR_ERROR_CAN_T_BUILD_AIRPORT_HERE, CcBuildAirport, tile, airport_type, layout, to_join, adjacent); } diff --git a/src/articulated_vehicles.cpp b/src/articulated_vehicles.cpp index 3845385958..c26e03ed51 100644 --- a/src/articulated_vehicles.cpp +++ b/src/articulated_vehicles.cpp @@ -29,7 +29,7 @@ static const uint MAX_ARTICULATED_PARTS = 100; ///< Maximum of articulated parts * @param front_type Front engine type * @param front Front engine * @param mirrored Returns whether the part shall be flipped. - * @return engine to add or INVALID_ENGINE + * @return engine to add or EngineID::Invalid() */ static EngineID GetNextArticulatedPart(uint index, EngineID front_type, Vehicle *front = nullptr, bool *mirrored = nullptr) { @@ -38,17 +38,17 @@ static EngineID GetNextArticulatedPart(uint index, EngineID front_type, Vehicle const Engine *front_engine = Engine::Get(front_type); uint16_t callback = GetVehicleCallback(CBID_VEHICLE_ARTIC_ENGINE, index, 0, front_type, front); - if (callback == CALLBACK_FAILED) return INVALID_ENGINE; + if (callback == CALLBACK_FAILED) return EngineID::Invalid(); if (front_engine->GetGRF()->grf_version < 8) { /* 8 bits, bit 7 for mirroring */ callback = GB(callback, 0, 8); - if (callback == 0xFF) return INVALID_ENGINE; + if (callback == 0xFF) return EngineID::Invalid(); if (mirrored != nullptr) *mirrored = HasBit(callback, 7); callback = GB(callback, 0, 7); } else { /* 15 bits, bit 14 for mirroring */ - if (callback == 0x7FFF) return INVALID_ENGINE; + if (callback == 0x7FFF) return EngineID::Invalid(); if (mirrored != nullptr) *mirrored = HasBit(callback, 14); callback = GB(callback, 0, 14); } @@ -89,7 +89,7 @@ uint CountArticulatedParts(EngineID engine_type, bool purchase_window) uint i; for (i = 1; i < MAX_ARTICULATED_PARTS; i++) { - if (GetNextArticulatedPart(i, engine_type, v) == INVALID_ENGINE) break; + if (GetNextArticulatedPart(i, engine_type, v) == EngineID::Invalid()) break; } delete v; @@ -150,7 +150,7 @@ CargoArray GetCapacityOfArticulatedParts(EngineID engine) for (uint i = 1; i < MAX_ARTICULATED_PARTS; i++) { EngineID artic_engine = GetNextArticulatedPart(i, engine); - if (artic_engine == INVALID_ENGINE) break; + if (artic_engine == EngineID::Invalid()) break; if (auto [cargo, cap] = GetVehicleDefaultCapacity(artic_engine); IsValidCargoType(cargo)) { capacity[cargo] += cap; @@ -180,7 +180,7 @@ CargoTypes GetCargoTypesOfArticulatedParts(EngineID engine) for (uint i = 1; i < MAX_ARTICULATED_PARTS; i++) { EngineID artic_engine = GetNextArticulatedPart(i, engine); - if (artic_engine == INVALID_ENGINE) break; + if (artic_engine == EngineID::Invalid()) break; if (auto [cargo, cap] = GetVehicleDefaultCapacity(artic_engine); IsValidCargoType(cargo) && cap > 0) { SetBit(cargoes, cargo); @@ -206,7 +206,7 @@ bool IsArticulatedVehicleRefittable(EngineID engine) for (uint i = 1; i < MAX_ARTICULATED_PARTS; i++) { EngineID artic_engine = GetNextArticulatedPart(i, engine); - if (artic_engine == INVALID_ENGINE) break; + if (artic_engine == EngineID::Invalid()) break; if (IsEngineRefittable(artic_engine)) return true; } @@ -233,7 +233,7 @@ void GetArticulatedRefitMasks(EngineID engine, bool include_initial_cargo_type, for (uint i = 1; i < MAX_ARTICULATED_PARTS; i++) { EngineID artic_engine = GetNextArticulatedPart(i, engine); - if (artic_engine == INVALID_ENGINE) break; + if (artic_engine == EngineID::Invalid()) break; veh_cargoes = GetAvailableVehicleCargoTypes(artic_engine, include_initial_cargo_type); *union_mask |= veh_cargoes; @@ -344,7 +344,7 @@ void AddArticulatedParts(Vehicle *first) for (uint i = 1; i < MAX_ARTICULATED_PARTS; i++) { bool flip_image; EngineID engine_type = GetNextArticulatedPart(i, first->engine_type, first, &flip_image); - if (engine_type == INVALID_ENGINE) return; + if (engine_type == EngineID::Invalid()) return; /* In the (very rare) case the GRF reported wrong number of articulated parts * and we run out of available vehicles, bail out. */ diff --git a/src/autoreplace.cpp b/src/autoreplace.cpp index 48c6a575fa..6d3c0f16b4 100644 --- a/src/autoreplace.cpp +++ b/src/autoreplace.cpp @@ -59,7 +59,7 @@ void RemoveAllEngineReplacement(EngineRenewList *erl) * @param engine Engine type to be replaced. * @param group The group related to this replacement. * @param[out] replace_when_old Set to true if the replacement should be done when old. - * @return The engine type to replace with, or INVALID_ENGINE if no + * @return The engine type to replace with, or EngineID::Invalid() if no * replacement is in the list. */ EngineID EngineReplacement(EngineRenewList erl, EngineID engine, GroupID group, bool *replace_when_old) @@ -81,7 +81,7 @@ EngineID EngineReplacement(EngineRenewList erl, EngineID engine, GroupID group, *replace_when_old = er->replace_when_old; } } - return er == nullptr ? INVALID_ENGINE : er->to; + return er == nullptr ? EngineID::Invalid() : er->to; } /** diff --git a/src/autoreplace_base.h b/src/autoreplace_base.h index 2abbe47548..16c041aac5 100644 --- a/src/autoreplace_base.h +++ b/src/autoreplace_base.h @@ -37,7 +37,7 @@ struct EngineRenew : EngineRenewPool::PoolItem<&_enginerenew_pool> { GroupID group_id; bool replace_when_old; ///< Do replacement only when vehicle is old. - EngineRenew(EngineID from = INVALID_ENGINE, EngineID to = INVALID_ENGINE) : from(from), to(to) {} + EngineRenew(EngineID from = EngineID::Invalid(), EngineID to = EngineID::Invalid()) : from(from), to(to) {} ~EngineRenew() {} }; diff --git a/src/autoreplace_cmd.cpp b/src/autoreplace_cmd.cpp index 0b513d24a1..35619f36eb 100644 --- a/src/autoreplace_cmd.cpp +++ b/src/autoreplace_cmd.cpp @@ -276,14 +276,14 @@ static CargoType GetNewCargoTypeForReplace(Vehicle *v, EngineID engine_type, boo * @param v The vehicle to find a replacement for * @param c The vehicle's owner (it's faster to forward the pointer than refinding it) * @param always_replace Always replace, even if not old. - * @param[out] e the EngineID of the replacement. INVALID_ENGINE if no replacement is found + * @param[out] e the EngineID of the replacement. EngineID::Invalid() if no replacement is found * @return Error if the engine to build is not available */ static CommandCost GetNewEngineType(const Vehicle *v, const Company *c, bool always_replace, EngineID &e) { assert(v->type != VEH_TRAIN || !v->IsArticulatedPart()); - e = INVALID_ENGINE; + e = EngineID::Invalid(); if (v->type == VEH_TRAIN && Train::From(v)->IsRearDualheaded()) { /* we build the rear ends of multiheaded trains with the front ones */ @@ -292,10 +292,10 @@ static CommandCost GetNewEngineType(const Vehicle *v, const Company *c, bool alw bool replace_when_old; e = EngineReplacementForCompany(c, v->engine_type, v->group_id, &replace_when_old); - if (!always_replace && replace_when_old && !v->NeedsAutorenewing(c, false)) e = INVALID_ENGINE; + if (!always_replace && replace_when_old && !v->NeedsAutorenewing(c, false)) e = EngineID::Invalid(); /* Autoreplace, if engine is available */ - if (e != INVALID_ENGINE && IsEngineBuildable(e, v->type, _current_company)) { + if (e != EngineID::Invalid() && IsEngineBuildable(e, v->type, _current_company)) { return CommandCost(); } @@ -303,7 +303,7 @@ static CommandCost GetNewEngineType(const Vehicle *v, const Company *c, bool alw if (v->NeedsAutorenewing(c)) e = v->engine_type; /* Nothing to do or all is fine? */ - if (e == INVALID_ENGINE || IsEngineBuildable(e, v->type, _current_company)) return CommandCost(); + if (e == EngineID::Invalid() || IsEngineBuildable(e, v->type, _current_company)) return CommandCost(); /* The engine we need is not available. Report error to user */ return CommandCost(STR_ERROR_RAIL_VEHICLE_NOT_AVAILABLE + v->type); @@ -327,7 +327,7 @@ static CommandCost BuildReplacementVehicle(Vehicle *old_veh, Vehicle **new_vehic EngineID e; CommandCost cost = GetNewEngineType(old_veh, c, true, e); if (cost.Failed()) return cost; - if (e == INVALID_ENGINE) return CommandCost(); // neither autoreplace is set, nor autorenew is triggered + if (e == EngineID::Invalid()) return CommandCost(); // neither autoreplace is set, nor autorenew is triggered /* Does it need to be refitted */ CargoType refit_cargo = GetNewCargoTypeForReplace(old_veh, e, part_of_chain); @@ -397,7 +397,7 @@ static inline CommandCost DoCmdStartStopVehicle(const Vehicle *v, bool evaluate_ */ static inline CommandCost CmdMoveVehicle(const Vehicle *v, const Vehicle *after, DoCommandFlags flags, bool whole_chain) { - return Command::Do(flags.Set(DoCommandFlag::NoCargoCapacityCheck), v->index, after != nullptr ? after->index : INVALID_VEHICLE, whole_chain); + return Command::Do(flags.Set(DoCommandFlag::NoCargoCapacityCheck), v->index, after != nullptr ? after->index : VehicleID::Invalid(), whole_chain); } /** @@ -763,7 +763,7 @@ CommandCost CmdAutoreplaceVehicle(DoCommandFlags flags, VehicleID veh_id) EngineID e; CommandCost cost = GetNewEngineType(w, c, false, e); if (cost.Failed()) return cost; - any_replacements |= (e != INVALID_ENGINE); + any_replacements |= (e != EngineID::Invalid()); w = (!free_wagon && w->type == VEH_TRAIN ? Train::From(w)->GetNextUnit() : nullptr); } @@ -828,7 +828,7 @@ CommandCost CmdSetAutoReplace(DoCommandFlags flags, GroupID id_g, EngineID old_e if (!Engine::IsValidID(old_engine_type)) return CMD_ERROR; if (Group::IsValidID(id_g) && Group::Get(id_g)->vehicle_type != Engine::Get(old_engine_type)->type) return CMD_ERROR; - if (new_engine_type != INVALID_ENGINE) { + if (new_engine_type != EngineID::Invalid()) { if (!Engine::IsValidID(new_engine_type)) return CMD_ERROR; if (!CheckAutoreplaceValidity(old_engine_type, new_engine_type, _current_company)) return CMD_ERROR; diff --git a/src/autoreplace_func.h b/src/autoreplace_func.h index 574761fc32..3c332ed9bd 100644 --- a/src/autoreplace_func.h +++ b/src/autoreplace_func.h @@ -33,7 +33,7 @@ inline void RemoveAllEngineReplacementForCompany(Company *c) * @param engine Engine type. * @param group The group related to this replacement. * @param[out] replace_when_old Set to true if the replacement should be done when old. - * @return The engine type to replace with, or INVALID_ENGINE if no + * @return The engine type to replace with, or EngineID::Invalid() if no * replacement is in the list. */ inline EngineID EngineReplacementForCompany(const Company *c, EngineID engine, GroupID group, bool *replace_when_old = nullptr) @@ -50,7 +50,7 @@ inline EngineID EngineReplacementForCompany(const Company *c, EngineID engine, G */ inline bool EngineHasReplacementForCompany(const Company *c, EngineID engine, GroupID group) { - return EngineReplacementForCompany(c, engine, group) != INVALID_ENGINE; + return EngineReplacementForCompany(c, engine, group) != EngineID::Invalid(); } /** diff --git a/src/autoreplace_gui.cpp b/src/autoreplace_gui.cpp index 7e727edd5c..c8f8e0cb96 100644 --- a/src/autoreplace_gui.cpp +++ b/src/autoreplace_gui.cpp @@ -118,7 +118,7 @@ class ReplaceVehicleWindow : public Window { void GenerateReplaceVehList(bool draw_left) { std::vector variants; - EngineID selected_engine = INVALID_ENGINE; + EngineID selected_engine = EngineID::Invalid(); VehicleType type = this->window_number; uint8_t side = draw_left ? 0 : 1; @@ -147,7 +147,7 @@ class ReplaceVehicleWindow : public Window { const uint num_engines = GetGroupNumEngines(_local_company, this->sel_group, eid); /* Skip drawing the engines we don't have any of and haven't set for replacement */ - if (num_engines == 0 && EngineReplacementForCompany(Company::Get(_local_company), eid, this->sel_group) == INVALID_ENGINE) continue; + if (num_engines == 0 && EngineReplacementForCompany(Company::Get(_local_company), eid, this->sel_group) == EngineID::Invalid()) continue; } else { if (!CheckAutoreplaceValidity(this->sel_engine[0], eid, _local_company)) continue; } @@ -156,7 +156,7 @@ class ReplaceVehicleWindow : public Window { if (side == 1) { EngineID parent = e->info.variant_id; - while (parent != INVALID_ENGINE) { + while (parent != EngineID::Invalid()) { variants.push_back(parent); parent = Engine::Get(parent)->info.variant_id; } @@ -199,28 +199,28 @@ class ReplaceVehicleWindow : public Window { /* We need to rebuild the left engines list */ this->GenerateReplaceVehList(true); this->vscroll[0]->SetCount(this->engines[0].size()); - if (this->reset_sel_engine && this->sel_engine[0] == INVALID_ENGINE && !this->engines[0].empty()) { + if (this->reset_sel_engine && this->sel_engine[0] == EngineID::Invalid() && !this->engines[0].empty()) { this->sel_engine[0] = this->engines[0][0].engine_id; } } if (this->engines[1].NeedRebuild() || e != this->sel_engine[0]) { /* Either we got a request to rebuild the right engines list, or the left engines list selected a different engine */ - if (this->sel_engine[0] == INVALID_ENGINE) { + if (this->sel_engine[0] == EngineID::Invalid()) { /* Always empty the right engines list when nothing is selected in the left engines list */ this->engines[1].clear(); - this->sel_engine[1] = INVALID_ENGINE; + this->sel_engine[1] = EngineID::Invalid(); this->vscroll[1]->SetCount(this->engines[1].size()); } else { - if (this->reset_sel_engine && this->sel_engine[0] != INVALID_ENGINE) { + if (this->reset_sel_engine && this->sel_engine[0] != EngineID::Invalid()) { /* Select the current replacement for sel_engine[0]. */ const Company *c = Company::Get(_local_company); this->sel_engine[1] = EngineReplacementForCompany(c, this->sel_engine[0], this->sel_group); } - /* Regenerate the list on the right. Note: This resets sel_engine[1] to INVALID_ENGINE, if it is no longer available. */ + /* Regenerate the list on the right. Note: This resets sel_engine[1] to EngineID::Invalid(), if it is no longer available. */ this->GenerateReplaceVehList(false); this->vscroll[1]->SetCount(this->engines[1].size()); - if (this->reset_sel_engine && this->sel_engine[1] != INVALID_ENGINE) { + if (this->reset_sel_engine && this->sel_engine[1] != EngineID::Invalid()) { int position = 0; for (const auto &item : this->engines[1]) { if (item.engine_id == this->sel_engine[1]) break; @@ -272,8 +272,8 @@ public: this->engines[1].ForceRebuild(); this->reset_sel_engine = true; this->details_height = ((vehicletype == VEH_TRAIN) ? 10 : 9); - this->sel_engine[0] = INVALID_ENGINE; - this->sel_engine[1] = INVALID_ENGINE; + this->sel_engine[0] = EngineID::Invalid(); + this->sel_engine[1] = EngineID::Invalid(); this->show_hidden_engines = _engine_sort_show_hidden_engines[vehicletype]; this->CreateNestedTree(); @@ -441,7 +441,7 @@ public: case WID_RV_INFO_TAB: { const Company *c = Company::Get(_local_company); StringID str; - if (this->sel_engine[0] != INVALID_ENGINE) { + if (this->sel_engine[0] != EngineID::Invalid()) { if (!EngineHasReplacementForCompany(c, this->sel_engine[0], this->sel_group)) { str = STR_REPLACE_NOT_REPLACING; } else { @@ -479,12 +479,12 @@ public: * Either engines list is empty * or The selected replacement engine has a replacement (to prevent loops). */ this->SetWidgetDisabledState(WID_RV_START_REPLACE, - this->sel_engine[0] == INVALID_ENGINE || this->sel_engine[1] == INVALID_ENGINE || EngineReplacementForCompany(c, this->sel_engine[1], this->sel_group) != INVALID_ENGINE); + this->sel_engine[0] == EngineID::Invalid() || this->sel_engine[1] == EngineID::Invalid() || EngineReplacementForCompany(c, this->sel_engine[1], this->sel_group) != EngineID::Invalid()); /* Disable the "Stop Replacing" button if: * The left engines list (existing vehicle) is empty * or The selected vehicle has no replacement set up */ - this->SetWidgetDisabledState(WID_RV_STOP_REPLACE, this->sel_engine[0] == INVALID_ENGINE || !EngineHasReplacementForCompany(c, this->sel_engine[0], this->sel_group)); + this->SetWidgetDisabledState(WID_RV_STOP_REPLACE, this->sel_engine[0] == EngineID::Invalid() || !EngineHasReplacementForCompany(c, this->sel_engine[0], this->sel_group)); this->DrawWidgets(); @@ -492,7 +492,7 @@ public: int needed_height = this->details_height; /* Draw details panels. */ for (int side = 0; side < 2; side++) { - if (this->sel_engine[side] != INVALID_ENGINE) { + if (this->sel_engine[side] != EngineID::Invalid()) { /* Use default engine details without refitting */ const Engine *e = Engine::Get(this->sel_engine[side]); TestedEngineDetails ted; @@ -575,7 +575,7 @@ public: case WID_RV_STOP_REPLACE: { // Stop replacing EngineID veh_from = this->sel_engine[0]; - Command::Post(this->sel_group, veh_from, INVALID_ENGINE, false); + Command::Post(this->sel_group, veh_from, EngineID::Invalid(), false); break; } @@ -588,14 +588,14 @@ public: click_side = 1; } - EngineID e = INVALID_ENGINE; + EngineID e = EngineID::Invalid(); const auto it = this->vscroll[click_side]->GetScrolledItemFromWidget(this->engines[click_side], pt.y, this, widget); if (it != this->engines[click_side].end()) { const auto &item = *it; const Rect r = this->GetWidget(widget)->GetCurrentRect().Shrink(WidgetDimensions::scaled.matrix).WithWidth(WidgetDimensions::scaled.hsep_indent * (item.indent + 1), _current_text_dir == TD_RTL); if (item.flags.Test(EngineDisplayFlag::HasVariants) && IsInsideMM(r.left, r.right, pt.x)) { /* toggle folded flag on engine */ - assert(item.variant_id != INVALID_ENGINE); + assert(item.variant_id != EngineID::Invalid()); Engine *engine = Engine::Get(item.variant_id); engine->display_flags.Flip(EngineDisplayFlag::IsFolded); @@ -608,10 +608,10 @@ public: /* If Ctrl is pressed on the left side and we don't have any engines of the selected type, stop autoreplacing. * This is most common when we have finished autoreplacing the engine and want to remove it from the list. */ - if (click_side == 0 && _ctrl_pressed && e != INVALID_ENGINE && + if (click_side == 0 && _ctrl_pressed && e != EngineID::Invalid() && (GetGroupNumEngines(_local_company, sel_group, e) == 0 || GetGroupNumEngines(_local_company, ALL_GROUP, e) == 0)) { EngineID veh_from = e; - Command::Post(this->sel_group, veh_from, INVALID_ENGINE, false); + Command::Post(this->sel_group, veh_from, EngineID::Invalid(), false); break; } diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp index 25f0da948a..81204d510e 100644 --- a/src/build_vehicle_gui.cpp +++ b/src/build_vehicle_gui.cpp @@ -132,7 +132,7 @@ static bool EngineIntroDateSorter(const GUIEngineListItem &a, const GUIEngineLis } /* cached values for EngineNameSorter to spare many GetString() calls */ -static EngineID _last_engine[2] = { INVALID_ENGINE, INVALID_ENGINE }; +static EngineID _last_engine[2] = { EngineID::Invalid(), EngineID::Invalid() }; /** * Determines order of engines by name @@ -1132,8 +1132,8 @@ void GUIEngineListAddChildren(GUIEngineList &dst, const GUIEngineList &src, Engi const Engine *e = Engine::Get(item.engine_id); EngineDisplayFlags flags = item.flags; - if (e->display_last_variant != INVALID_ENGINE) flags.Reset(EngineDisplayFlag::Shaded); - dst.emplace_back(e->display_last_variant == INVALID_ENGINE ? item.engine_id : e->display_last_variant, item.engine_id, flags, indent); + if (e->display_last_variant != EngineID::Invalid()) flags.Reset(EngineDisplayFlag::Shaded); + dst.emplace_back(e->display_last_variant == EngineID::Invalid() ? item.engine_id : e->display_last_variant, item.engine_id, flags, indent); /* Add variants if not folded */ if (item.flags.Test(EngineDisplayFlag::HasVariants) && !item.flags.Test(EngineDisplayFlag::IsFolded)) { @@ -1172,7 +1172,7 @@ struct BuildVehicleWindow : Window { uint8_t sort_criteria; ///< Current sort criterium. bool show_hidden_engines; ///< State of the 'show hidden engines' button. bool listview_mode; ///< If set, only display the available vehicles and do not show a 'build' button. - EngineID sel_engine; ///< Currently selected engine, or #INVALID_ENGINE + EngineID sel_engine; ///< Currently selected engine, or #EngineID::Invalid() EngineID rename_engine; ///< Engine being renamed. GUIEngineList eng_list; CargoType cargo_filter_criteria; ///< Selected cargo filter @@ -1187,7 +1187,7 @@ struct BuildVehicleWindow : Window { { NWidgetCore *widget = this->GetWidget(WID_BV_BUILD); - bool refit = this->sel_engine != INVALID_ENGINE && this->cargo_filter_criteria != CargoFilterCriteria::CF_ANY && this->cargo_filter_criteria != CargoFilterCriteria::CF_NONE && this->cargo_filter_criteria != CargoFilterCriteria::CF_ENGINES; + bool refit = this->sel_engine != EngineID::Invalid() && this->cargo_filter_criteria != CargoFilterCriteria::CF_ANY && this->cargo_filter_criteria != CargoFilterCriteria::CF_NONE && this->cargo_filter_criteria != CargoFilterCriteria::CF_ENGINES; if (refit) refit = Engine::Get(this->sel_engine)->GetDefaultCargoType() != this->cargo_filter_criteria; if (refit) { @@ -1203,7 +1203,7 @@ struct BuildVehicleWindow : Window { this->listview_mode = tile == INVALID_TILE; this->window_number = this->listview_mode ? (int)type : tile.base(); - this->sel_engine = INVALID_ENGINE; + this->sel_engine = EngineID::Invalid(); this->sort_criteria = _engine_sort_last_criteria[type]; this->descending_sort_order = _engine_sort_last_order[type]; @@ -1249,7 +1249,7 @@ struct BuildVehicleWindow : Window { this->GenerateBuildList(); // generate the list, since we need it in the next line /* Select the first unshaded engine in the list as default when opening the window */ - EngineID engine = INVALID_ENGINE; + EngineID engine = EngineID::Invalid(); auto it = std::ranges::find_if(this->eng_list, [](const GUIEngineListItem &item) { return !item.flags.Test(EngineDisplayFlag::Shaded); }); if (it != this->eng_list.end()) engine = it->engine_id; this->SelectEngine(engine); @@ -1314,7 +1314,7 @@ struct BuildVehicleWindow : Window { this->sel_engine = engine; this->SetBuyVehicleText(); - if (this->sel_engine == INVALID_ENGINE) return; + if (this->sel_engine == EngineID::Invalid()) return; const Engine *e = Engine::Get(this->sel_engine); @@ -1346,7 +1346,7 @@ struct BuildVehicleWindow : Window { { this->eng_list.Filter(this->cargo_filter_criteria); if (0 == this->eng_list.size()) { // no engine passed through the filter, invalidate the previously selected engine - this->SelectEngine(INVALID_ENGINE); + this->SelectEngine(EngineID::Invalid()); } else if (std::ranges::find(this->eng_list, this->sel_engine, &GUIEngineListItem::engine_id) == this->eng_list.end()) { // previously selected engine didn't pass the filter, select the first engine of the list this->SelectEngine(this->eng_list[0].engine_id); } @@ -1380,14 +1380,14 @@ struct BuildVehicleWindow : Window { void GenerateBuildTrainList(GUIEngineList &list) { std::vector variants; - EngineID sel_id = INVALID_ENGINE; + EngineID sel_id = EngineID::Invalid(); size_t num_engines = 0; list.clear(); /* Make list of all available train engines and wagons. * Also check to see if the previously selected engine is still available, - * and if not, reset selection to INVALID_ENGINE. This could be the case + * and if not, reset selection to EngineID::Invalid(). This could be the case * when engines become obsolete and are removed */ for (const Engine *e : Engine::IterateType(VEH_TRAIN)) { if (!this->show_hidden_engines && e->IsVariantHidden(_local_company)) continue; @@ -1409,7 +1409,7 @@ struct BuildVehicleWindow : Window { /* Add all parent variants of this engine to the variant list */ EngineID parent = e->info.variant_id; - while (parent != INVALID_ENGINE) { + while (parent != EngineID::Invalid()) { variants.push_back(parent); parent = Engine::Get(parent)->info.variant_id; } @@ -1429,7 +1429,7 @@ struct BuildVehicleWindow : Window { this->SelectEngine(sel_id); /* invalidate cached values for name sorter - engine names could change */ - _last_engine[0] = _last_engine[1] = INVALID_ENGINE; + _last_engine[0] = _last_engine[1] = EngineID::Invalid(); /* make engines first, and then wagons, sorted by selected sort_criteria */ _engine_sort_direction = false; @@ -1446,7 +1446,7 @@ struct BuildVehicleWindow : Window { /* Figure out what road vehicle EngineIDs to put in the list */ void GenerateBuildRoadVehList() { - EngineID sel_id = INVALID_ENGINE; + EngineID sel_id = EngineID::Invalid(); this->eng_list.clear(); @@ -1469,7 +1469,7 @@ struct BuildVehicleWindow : Window { /* Figure out what ship EngineIDs to put in the list */ void GenerateBuildShipList() { - EngineID sel_id = INVALID_ENGINE; + EngineID sel_id = EngineID::Invalid(); this->eng_list.clear(); for (const Engine *e : Engine::IterateType(VEH_SHIP)) { @@ -1490,7 +1490,7 @@ struct BuildVehicleWindow : Window { /* Figure out what aircraft EngineIDs to put in the list */ void GenerateBuildAircraftList() { - EngineID sel_id = INVALID_ENGINE; + EngineID sel_id = EngineID::Invalid(); this->eng_list.clear(); @@ -1498,7 +1498,7 @@ struct BuildVehicleWindow : Window { /* Make list of all available planes. * Also check to see if the previously selected plane is still available, - * and if not, reset selection to INVALID_ENGINE. This could be the case + * and if not, reset selection to EngineID::Invalid(). This could be the case * when planes become obsolete and are removed */ for (const Engine *e : Engine::IterateType(VEH_AIRCRAFT)) { if (!this->show_hidden_engines && e->IsVariantHidden(_local_company)) continue; @@ -1554,7 +1554,7 @@ struct BuildVehicleWindow : Window { std::vector variants; for (const auto &item : this->eng_list) { EngineID parent = item.variant_id; - while (parent != INVALID_ENGINE) { + while (parent != EngineID::Invalid()) { variants.push_back(parent); parent = Engine::Get(parent)->info.variant_id; } @@ -1571,7 +1571,7 @@ struct BuildVehicleWindow : Window { EngList_Sort(this->eng_list, _engine_sort_functions[this->vehicle_type][this->sort_criteria]); this->eng_list.swap(list); - GUIEngineListAddChildren(this->eng_list, list, INVALID_ENGINE, 0); + GUIEngineListAddChildren(this->eng_list, list, EngineID::Invalid(), 0); this->eng_list.RebuildDone(); } @@ -1602,7 +1602,7 @@ struct BuildVehicleWindow : Window { void BuildVehicle() { EngineID sel_eng = this->sel_engine; - if (sel_eng == INVALID_ENGINE) return; + if (sel_eng == EngineID::Invalid()) return; CargoType cargo = this->cargo_filter_criteria; if (cargo == CargoFilterCriteria::CF_ANY || cargo == CargoFilterCriteria::CF_ENGINES || cargo == CargoFilterCriteria::CF_NONE) cargo = INVALID_CARGO; @@ -1615,7 +1615,7 @@ struct BuildVehicleWindow : Window { /* Update last used variant in hierarchy and refresh if necessary. */ bool refresh = false; EngineID parent = sel_eng; - while (parent != INVALID_ENGINE) { + while (parent != EngineID::Invalid()) { Engine *e = Engine::Get(parent); refresh |= (e->display_last_variant != sel_eng); e->display_last_variant = sel_eng; @@ -1647,14 +1647,14 @@ struct BuildVehicleWindow : Window { break; case WID_BV_LIST: { - EngineID e = INVALID_ENGINE; + EngineID e = EngineID::Invalid(); const auto it = this->vscroll->GetScrolledItemFromWidget(this->eng_list, pt.y, this, WID_BV_LIST); if (it != this->eng_list.end()) { const auto &item = *it; const Rect r = this->GetWidget(widget)->GetCurrentRect().Shrink(WidgetDimensions::scaled.matrix).WithWidth(WidgetDimensions::scaled.hsep_indent * (item.indent + 1), _current_text_dir == TD_RTL); if (item.flags.Test(EngineDisplayFlag::HasVariants) && IsInsideMM(r.left, r.right, pt.x)) { /* toggle folded flag on engine */ - assert(item.variant_id != INVALID_ENGINE); + assert(item.variant_id != EngineID::Invalid()); Engine *engine = Engine::Get(item.variant_id); engine->display_flags.Flip(EngineDisplayFlag::IsFolded); @@ -1683,7 +1683,7 @@ struct BuildVehicleWindow : Window { break; case WID_BV_SHOW_HIDE: { - const Engine *e = (this->sel_engine == INVALID_ENGINE) ? nullptr : Engine::Get(this->sel_engine); + const Engine *e = (this->sel_engine == EngineID::Invalid()) ? nullptr : Engine::Get(this->sel_engine); if (e != nullptr) { Command::Post(this->sel_engine, !e->IsHidden(_current_company)); } @@ -1696,7 +1696,7 @@ struct BuildVehicleWindow : Window { case WID_BV_RENAME: { EngineID sel_eng = this->sel_engine; - if (sel_eng != INVALID_ENGINE) { + if (sel_eng != EngineID::Invalid()) { this->rename_engine = sel_eng; ShowQueryString(GetString(STR_ENGINE_NAME, PackEngineNameDParam(sel_eng, EngineNameContext::Generic)), STR_QUERY_RENAME_TRAIN_TYPE_CAPTION + this->vehicle_type, MAX_LENGTH_ENGINE_NAME_CHARS, this, CS_ALPHANUMERAL, QSF_ENABLE_DEFAULT | QSF_LEN_IN_CHARS); } @@ -1747,7 +1747,7 @@ struct BuildVehicleWindow : Window { break; case WID_BV_SHOW_HIDE: { - const Engine *e = (this->sel_engine == INVALID_ENGINE) ? nullptr : Engine::Get(this->sel_engine); + const Engine *e = (this->sel_engine == EngineID::Invalid()) ? nullptr : Engine::Get(this->sel_engine); if (e != nullptr && e->IsHidden(_local_company)) { SetDParam(0, STR_BUY_VEHICLE_TRAIN_SHOW_TOGGLE_BUTTON + this->vehicle_type); } else { @@ -1825,17 +1825,17 @@ struct BuildVehicleWindow : Window { this->GenerateBuildList(); this->vscroll->SetCount(this->eng_list.size()); - this->SetWidgetsDisabledState(this->sel_engine == INVALID_ENGINE, WID_BV_SHOW_HIDE, WID_BV_BUILD); + this->SetWidgetsDisabledState(this->sel_engine == EngineID::Invalid(), WID_BV_SHOW_HIDE, WID_BV_BUILD); /* Disable renaming engines in network games if you are not the server. */ - this->SetWidgetDisabledState(WID_BV_RENAME, this->sel_engine == INVALID_ENGINE || (_networking && !_network_server)); + this->SetWidgetDisabledState(WID_BV_RENAME, this->sel_engine == EngineID::Invalid() || (_networking && !_network_server)); this->DrawWidgets(); if (!this->IsShaded()) { int needed_height = this->details_height; /* Draw details panels. */ - if (this->sel_engine != INVALID_ENGINE) { + if (this->sel_engine != EngineID::Invalid()) { const Rect r = this->GetWidget(WID_BV_PANEL)->GetCurrentRect().Shrink(WidgetDimensions::scaled.framerect); int text_end = DrawVehiclePurchaseInfo(r.left, r.right, r.top, this->sel_engine, this->te); needed_height = std::max(needed_height, (text_end - r.top) / GetCharacterHeight(FS_NORMAL)); diff --git a/src/cargomonitor.h b/src/cargomonitor.h index b26807434e..8d015f024e 100644 --- a/src/cargomonitor.h +++ b/src/cargomonitor.h @@ -120,22 +120,22 @@ inline bool MonitorMonitorsIndustry(CargoMonitorID num) /** * Extract the industry number from the cargo monitor. * @param num Cargo monitoring number to decode. - * @return The extracted industry id, or #INVALID_INDUSTRY if the number does not monitor an industry. + * @return The extracted industry id, or #IndustryID::Invalid() if the number does not monitor an industry. */ inline IndustryID DecodeMonitorIndustry(CargoMonitorID num) { - if (!MonitorMonitorsIndustry(num)) return INVALID_INDUSTRY; + if (!MonitorMonitorsIndustry(num)) return IndustryID::Invalid(); return static_cast(GB(num, CCB_TOWN_IND_NUMBER_START, CCB_TOWN_IND_NUMBER_LENGTH)); } /** * Extract the town number from the cargo monitor. * @param num Cargo monitoring number to decode. - * @return The extracted town id, or #INVALID_TOWN if the number does not monitor a town. + * @return The extracted town id, or #TownID::Invalid() if the number does not monitor a town. */ inline TownID DecodeMonitorTown(CargoMonitorID num) { - if (MonitorMonitorsIndustry(num)) return INVALID_TOWN; + if (MonitorMonitorsIndustry(num)) return TownID::Invalid(); return static_cast(GB(num, CCB_TOWN_IND_NUMBER_START, CCB_TOWN_IND_NUMBER_LENGTH)); } @@ -143,6 +143,6 @@ void ClearCargoPickupMonitoring(CompanyID company = INVALID_OWNER); void ClearCargoDeliveryMonitoring(CompanyID company = INVALID_OWNER); int32_t GetDeliveryAmount(CargoMonitorID monitor, bool keep_monitoring); int32_t GetPickupAmount(CargoMonitorID monitor, bool keep_monitoring); -void AddCargoDelivery(CargoType cargo_type, CompanyID company, uint32_t amount, Source src, const Station *st, IndustryID dest = INVALID_INDUSTRY); +void AddCargoDelivery(CargoType cargo_type, CompanyID company, uint32_t amount, Source src, const Station *st, IndustryID dest = IndustryID::Invalid()); #endif /* CARGOMONITOR_H */ diff --git a/src/cargopacket.cpp b/src/cargopacket.cpp index eba48da6f1..5dfe57c873 100644 --- a/src/cargopacket.cpp +++ b/src/cargopacket.cpp @@ -137,13 +137,13 @@ void CargoPacket::Reduce(uint count) } /** - * Invalidates (sets source to INVALID_STATION) all cargo packets from given station. + * Invalidates (sets source to StationID::Invalid()) all cargo packets from given station. * @param sid Station that gets removed. */ /* static */ void CargoPacket::InvalidateAllFrom(StationID sid) { for (CargoPacket *cp : CargoPacket::Iterate()) { - if (cp->first_station == sid) cp->first_station = INVALID_STATION; + if (cp->first_station == sid) cp->first_station = StationID::Invalid(); } } @@ -406,7 +406,7 @@ void VehicleCargoList::AgeCargo() /* static */ VehicleCargoList::MoveToAction VehicleCargoList::ChooseAction(const CargoPacket *cp, StationID cargo_next, StationID current_station, bool accepted, StationIDStack next_station) { - if (cargo_next == INVALID_STATION) { + if (cargo_next == StationID::Invalid()) { return (accepted && cp->first_station != current_station) ? MTA_DELIVER : MTA_KEEP; } else if (cargo_next == current_station) { return MTA_DELIVER; @@ -452,7 +452,7 @@ bool VehicleCargoList::Stage(bool accepted, StationID current_station, StationID CargoPacket *cp = *it; this->packets.erase(it++); - StationID cargo_next = INVALID_STATION; + StationID cargo_next = StationID::Invalid(); MoveToAction action = MTA_LOAD; if (force_keep) { action = MTA_KEEP; @@ -464,7 +464,7 @@ bool VehicleCargoList::Stage(bool accepted, StationID current_station, StationID * also not to the current station. */ FlowStatMap::const_iterator flow_it(flows.find(cp->first_station)); if (flow_it == flows.end()) { - cargo_next = INVALID_STATION; + cargo_next = StationID::Invalid(); } else { FlowStat new_shares = flow_it->second; new_shares.ChangeShare(current_station, INT_MIN); @@ -473,7 +473,7 @@ bool VehicleCargoList::Stage(bool accepted, StationID current_station, StationID new_shares.ChangeShare(StationID{excluded.Pop()}, INT_MIN); } if (new_shares.GetShares()->empty()) { - cargo_next = INVALID_STATION; + cargo_next = StationID::Invalid(); } else { cargo_next = new_shares.GetVia(); } @@ -481,13 +481,13 @@ bool VehicleCargoList::Stage(bool accepted, StationID current_station, StationID } else { /* Rewrite an invalid source station to some random other one to * avoid keeping the cargo in the vehicle forever. */ - if (cp->first_station == INVALID_STATION && !flows.empty()) { + if (cp->first_station == StationID::Invalid() && !flows.empty()) { cp->first_station = flows.begin()->first; } bool restricted = false; FlowStatMap::const_iterator flow_it(flows.find(cp->first_station)); if (flow_it == flows.end()) { - cargo_next = INVALID_STATION; + cargo_next = StationID::Invalid(); } else { cargo_next = flow_it->second.GetViaWithRestricted(restricted); } @@ -577,7 +577,7 @@ uint VehicleCargoList::ReassignCount(); this->packets.insert(it, cp_split); } - cp->next_hop = INVALID_STATION; + cp->next_hop = StationID::Invalid(); } this->action_counts[MTA_DELIVER] -= max_move; @@ -734,7 +734,7 @@ bool StationCargoList::ShiftCargo(Taction &action, StationID next) * will be kept and the loop will be aborted. * @param action Action instance to be applied. * @param next Next hop the cargo wants to visit. - * @param include_invalid If cargo from the INVALID_STATION list should be + * @param include_invalid If cargo from the StationID::Invalid() list should be * used if necessary. * @return Amount of cargo actually moved. */ @@ -747,7 +747,7 @@ uint StationCargoList::ShiftCargo(Taction action, StationIDStack next, bool incl if (action.MaxMove() == 0) break; } if (include_invalid && action.MaxMove() > 0) { - this->ShiftCargo(action, INVALID_STATION); + this->ShiftCargo(action, StationID::Invalid()); } return max_move - action.MaxMove(); } diff --git a/src/cargopacket.h b/src/cargopacket.h index 59093dc39e..477f9b07bc 100644 --- a/src/cargopacket.h +++ b/src/cargopacket.h @@ -60,8 +60,8 @@ private: bool in_vehicle = false; ///< NOSAVE: Whether this cargo is in a vehicle or not. #endif /* WITH_ASSERT */ - StationID first_station = INVALID_STATION; ///< The station where the cargo came from first. - StationID next_hop = INVALID_STATION; ///< Station where the cargo wants to go next. + StationID first_station = StationID::Invalid(); ///< The station where the cargo came from first. + StationID next_hop = StationID::Invalid(); ///< Station where the cargo wants to go next. /** The CargoList caches, thus needs to know about it. */ template friend class CargoList; @@ -395,7 +395,7 @@ public: */ inline StationID GetFirstStation() const { - return this->count == 0 ? INVALID_STATION : this->packets.front()->first_station; + return this->count == 0 ? StationID::Invalid() : this->packets.front()->first_station; } /** @@ -557,8 +557,8 @@ public: while (!next.IsEmpty()) { if (this->packets.find(StationID{next.Pop()}) != this->packets.end()) return true; } - /* Packets for INVALID_STATION can go anywhere. */ - return this->packets.find(INVALID_STATION) != this->packets.end(); + /* Packets for StationID::Invalid() can go anywhere. */ + return this->packets.find(StationID::Invalid()) != this->packets.end(); } /** @@ -567,7 +567,7 @@ public: */ inline StationID GetFirstStation() const { - return this->count == 0 ? INVALID_STATION : this->packets.begin()->second.front()->first_station; + return this->count == 0 ? StationID::Invalid() : this->packets.begin()->second.front()->first_station; } /** diff --git a/src/clear_cmd.cpp b/src/clear_cmd.cpp index d19b769230..ccbb85c0a5 100644 --- a/src/clear_cmd.cpp +++ b/src/clear_cmd.cpp @@ -265,7 +265,7 @@ static void TileLoop_Clear(TileIndex tile) SetClearCounter(tile, 0); } - if (GetIndustryIndexOfField(tile) == INVALID_INDUSTRY && GetFieldType(tile) >= 7) { + if (GetIndustryIndexOfField(tile) == IndustryID::Invalid() && GetFieldType(tile) >= 7) { /* This farmfield is no longer farmfield, so make it grass again */ MakeClear(tile, CLEAR_GRASS, 2); } else { diff --git a/src/command_type.h b/src/command_type.h index 0a28bcc794..6f1a457113 100644 --- a/src/command_type.h +++ b/src/command_type.h @@ -26,7 +26,7 @@ class CommandCost { StringID message; ///< Warning message for when success is unset ExpensesType expense_type; ///< the type of expence as shown on the finances view bool success; ///< Whether the command went fine up to this moment - Owner owner = INVALID_COMPANY; ///< Originator owner of error. + Owner owner = CompanyID::Invalid(); ///< Originator owner of error. const GRFFile *textref_stack_grffile = nullptr; ///< NewGRF providing the #TextRefStack content. uint textref_stack_size = 0; ///< Number of uint32_t values to put on the #TextRefStack for the error message. StringID extra_message = INVALID_STRING_ID; ///< Additional warning message for when success is unset diff --git a/src/company_cmd.cpp b/src/company_cmd.cpp index 562591a0f7..587b350df4 100644 --- a/src/company_cmd.cpp +++ b/src/company_cmd.cpp @@ -73,7 +73,7 @@ Company::Company(StringID name_1, bool is_ai) this->tree_limit = (uint32_t)_settings_game.construction.tree_frame_burst << 16; this->build_object_limit = (uint32_t)_settings_game.construction.build_object_frame_burst << 16; - InvalidateWindowData(WC_PERFORMANCE_DETAIL, 0, INVALID_COMPANY); + InvalidateWindowData(WC_PERFORMANCE_DETAIL, 0, CompanyID::Invalid()); } /** Destructor. */ @@ -574,7 +574,7 @@ void ResetCompanyLivery(Company *c) * @param company CompanyID to use for the new company * @return the company struct */ -Company *DoStartupNewCompany(bool is_ai, CompanyID company = INVALID_COMPANY) +Company *DoStartupNewCompany(bool is_ai, CompanyID company = CompanyID::Invalid()) { if (!Company::CanAllocateItem()) return nullptr; @@ -582,7 +582,7 @@ Company *DoStartupNewCompany(bool is_ai, CompanyID company = INVALID_COMPANY) Colours colour = GenerateCompanyColour(); Company *c; - if (company == INVALID_COMPANY) { + if (company == CompanyID::Invalid()) { c = new Company(STR_SV_UNNAMED, is_ai); } else { if (Company::IsValidID(company)) return nullptr; @@ -644,7 +644,7 @@ TimeoutTimer _new_competitor_timeout({ TimerGameTick::Priority::C /* Send a command to all clients to start up a new AI. * Works fine for Multiplayer and Singleplayer */ - Command::Post(CCA_NEW_AI, INVALID_COMPANY, CRR_NONE, INVALID_CLIENT_ID); + Command::Post(CCA_NEW_AI, CompanyID::Invalid(), CRR_NONE, INVALID_CLIENT_ID); }); /** Start of a new game. */ @@ -764,7 +764,7 @@ void OnTick_Companies() for (auto i = 0; i < _settings_game.difficulty.max_no_competitors; i++) { if (_networking && Company::GetNumItems() >= _settings_client.network.max_companies) break; if (n++ >= _settings_game.difficulty.max_no_competitors) break; - Command::Post(CCA_NEW_AI, INVALID_COMPANY, CRR_NONE, INVALID_CLIENT_ID); + Command::Post(CCA_NEW_AI, CompanyID::Invalid(), CRR_NONE, INVALID_CLIENT_ID); } timeout = 10 * 60 * Ticks::TICKS_PER_SECOND; } @@ -906,15 +906,15 @@ CommandCost CmdCompanyCtrl(DoCommandFlags flags, CompanyCtrlAction cca, CompanyI } case CCA_NEW_AI: { // Make a new AI company - if (company_id != INVALID_COMPANY && company_id >= MAX_COMPANIES) return CMD_ERROR; + if (company_id != CompanyID::Invalid() && company_id >= MAX_COMPANIES) return CMD_ERROR; /* For network games, company deletion is delayed. */ - if (!_networking && company_id != INVALID_COMPANY && Company::IsValidID(company_id)) return CMD_ERROR; + if (!_networking && company_id != CompanyID::Invalid() && Company::IsValidID(company_id)) return CMD_ERROR; if (!flags.Test(DoCommandFlag::Execute)) return CommandCost(); /* For network game, just assume deletion happened. */ - assert(company_id == INVALID_COMPANY || !Company::IsValidID(company_id)); + assert(company_id == CompanyID::Invalid() || !Company::IsValidID(company_id)); Company *c = DoStartupNewCompany(true, company_id); if (c != nullptr) { @@ -1325,7 +1325,7 @@ CommandCost CmdGiveMoney(DoCommandFlags flags, Money money, CompanyID dest_compa * to get the index of the company: * 1st - get the first existing human company. * 2nd - get the first non-existing company. - * 3rd - get COMPANY_FIRST. + * 3rd - get CompanyID::Begin(). * @return the index of the first available company. */ CompanyID GetFirstPlayableCompanyID() @@ -1337,12 +1337,12 @@ CompanyID GetFirstPlayableCompanyID() } if (Company::CanAllocateItem()) { - for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; ++c) { + for (CompanyID c = CompanyID::Begin(); c < MAX_COMPANIES; ++c) { if (!Company::IsValidID(c)) { return c; } } } - return COMPANY_FIRST; + return CompanyID::Begin(); } diff --git a/src/company_gui.cpp b/src/company_gui.cpp index b7861d143e..955b06b215 100644 --- a/src/company_gui.cpp +++ b/src/company_gui.cpp @@ -634,7 +634,7 @@ private: } else { const Group *g = Group::Get(this->sel); livery = &g->livery; - if (g->parent == INVALID_GROUP) { + if (g->parent == GroupID::Invalid()) { default_livery = &c->livery[LS_DEFAULT]; } else { const Group *pg = Group::Get(g->parent); @@ -697,7 +697,7 @@ public: this->CreateNestedTree(); this->vscroll = this->GetScrollbar(WID_SCL_MATRIX_SCROLLBAR); - if (group == INVALID_GROUP) { + if (group == GroupID::Invalid()) { this->livery_class = LC_OTHER; this->sel = 1; this->LowerWidget(WID_SCL_CLASS_GENERAL); @@ -796,7 +796,7 @@ public: bool local = this->window_number == _local_company; /* Disable dropdown controls if no scheme is selected */ - bool disabled = this->livery_class < LC_GROUP_RAIL ? (this->sel == 0) : (this->sel == INVALID_GROUP); + bool disabled = this->livery_class < LC_GROUP_RAIL ? (this->sel == 0) : (this->sel == GroupID::Invalid()); this->SetWidgetDisabledState(WID_SCL_PRI_COL_DROPDOWN, !local || disabled); this->SetWidgetDisabledState(WID_SCL_SEC_COL_DROPDOWN, !local || disabled); @@ -831,7 +831,7 @@ public: } } } else { - if (this->sel != INVALID_GROUP) { + if (this->sel != GroupID::Invalid()) { const Group *g = Group::Get(this->sel); const Livery *livery = &g->livery; if (HasBit(livery->in_use, primary ? 0 : 1)) { @@ -944,7 +944,7 @@ public: } } } else { - this->sel = INVALID_GROUP.base(); + this->sel = GroupID::Invalid().base(); this->groups.ForceRebuild(); this->BuildGroupList(this->window_number); @@ -1038,7 +1038,7 @@ public: this->SetRows(); if (!Group::IsValidID(this->sel)) { - this->sel = INVALID_GROUP.base(); + this->sel = GroupID::Invalid().base(); if (!this->groups.empty()) this->sel = this->groups[0].group->index.base(); } @@ -1112,7 +1112,7 @@ void ShowCompanyLiveryWindow(CompanyID company, GroupID group) SelectCompanyLiveryWindow *w = (SelectCompanyLiveryWindow *)BringWindowToFrontById(WC_COMPANY_COLOUR, company); if (w == nullptr) { new SelectCompanyLiveryWindow(_select_company_livery_desc, company, group); - } else if (group != INVALID_GROUP) { + } else if (group != GroupID::Invalid()) { w->SetSelectedGroup(company, group); } } @@ -2452,7 +2452,7 @@ struct CompanyWindow : Window case WID_C_NEW_FACE: DoSelectCompanyManagerFace(this); break; case WID_C_COLOUR_SCHEME: - ShowCompanyLiveryWindow(this->window_number, INVALID_GROUP); + ShowCompanyLiveryWindow(this->window_number, GroupID::Invalid()); break; case WID_C_PRESIDENT_NAME: diff --git a/src/company_type.h b/src/company_type.h index 485bdc051b..17ce117399 100644 --- a/src/company_type.h +++ b/src/company_type.h @@ -14,8 +14,6 @@ #include "core/pool_type.hpp" using CompanyID = PoolID; -static constexpr CompanyID COMPANY_FIRST = CompanyID::Begin(); -static constexpr CompanyID INVALID_COMPANY = CompanyID::Invalid(); ///< An invalid company /* 'Fake' companies used for networks */ static constexpr CompanyID COMPANY_INACTIVE_CLIENT{253}; ///< The client is joining diff --git a/src/console.cpp b/src/console.cpp index fa23eacf14..d09f6fc109 100644 --- a/src/console.cpp +++ b/src/console.cpp @@ -40,7 +40,7 @@ void IConsoleInit() { _iconsole_output_file = std::nullopt; _redirect_console_to_client = INVALID_CLIENT_ID; - _redirect_console_to_admin = INVALID_ADMIN_ID; + _redirect_console_to_admin = AdminID::Invalid(); IConsoleGUIInit(); @@ -96,7 +96,7 @@ void IConsolePrint(TextColour colour_code, const std::string &string) return; } - if (_redirect_console_to_admin != INVALID_ADMIN_ID) { + if (_redirect_console_to_admin != AdminID::Invalid()) { NetworkServerSendAdminRcon(_redirect_console_to_admin, colour_code, string); return; } diff --git a/src/console_cmds.cpp b/src/console_cmds.cpp index bac12d079c..e66af26f6a 100644 --- a/src/console_cmds.cpp +++ b/src/console_cmds.cpp @@ -1088,7 +1088,7 @@ DEF_CONSOLE_CMD(ConNetworkReconnect) default: /* From a user pov 0 is a new company, internally it's different and all * companies are offset by one to ease up on users (eg companies 1-8 not 0-7) */ - if (playas < COMPANY_FIRST + 1 || playas > MAX_COMPANIES + 1) return false; + if (playas < CompanyID::Begin() + 1 || playas > MAX_COMPANIES + 1) return false; break; } @@ -1451,7 +1451,7 @@ DEF_CONSOLE_CMD(ConStartAI) } /* Start a new AI company */ - Command::Post(CCA_NEW_AI, INVALID_COMPANY, CRR_NONE, INVALID_CLIENT_ID); + Command::Post(CCA_NEW_AI, CompanyID::Invalid(), CRR_NONE, INVALID_CLIENT_ID); return true; } @@ -1898,7 +1898,7 @@ DEF_CONSOLE_CMD(ConSay) if (!_network_server) { NetworkClientSendChat(NETWORK_ACTION_CHAT, DESTTYPE_BROADCAST, 0 /* param does not matter */, argv[1]); } else { - bool from_admin = (_redirect_console_to_admin < INVALID_ADMIN_ID); + bool from_admin = (_redirect_console_to_admin < AdminID::Invalid()); NetworkServerSendChat(NETWORK_ACTION_CHAT, DESTTYPE_BROADCAST, 0, argv[1], CLIENT_ID_SERVER, from_admin); } @@ -1924,7 +1924,7 @@ DEF_CONSOLE_CMD(ConSayCompany) if (!_network_server) { NetworkClientSendChat(NETWORK_ACTION_CHAT_COMPANY, DESTTYPE_TEAM, company_id.base(), argv[2]); } else { - bool from_admin = (_redirect_console_to_admin < INVALID_ADMIN_ID); + bool from_admin = (_redirect_console_to_admin < AdminID::Invalid()); NetworkServerSendChat(NETWORK_ACTION_CHAT_COMPANY, DESTTYPE_TEAM, company_id.base(), argv[2], CLIENT_ID_SERVER, from_admin); } @@ -1944,7 +1944,7 @@ DEF_CONSOLE_CMD(ConSayClient) if (!_network_server) { NetworkClientSendChat(NETWORK_ACTION_CHAT_CLIENT, DESTTYPE_CLIENT, atoi(argv[1]), argv[2]); } else { - bool from_admin = (_redirect_console_to_admin < INVALID_ADMIN_ID); + bool from_admin = (_redirect_console_to_admin < AdminID::Invalid()); NetworkServerSendChat(NETWORK_ACTION_CHAT_CLIENT, DESTTYPE_CLIENT, atoi(argv[1]), argv[2], CLIENT_ID_SERVER, from_admin); } @@ -1964,7 +1964,7 @@ enum ConNetworkAuthorizedKeyAction : uint8_t { CNAKA_REMOVE, }; -static void PerformNetworkAuthorizedKeyAction(std::string_view name, NetworkAuthorizedKeys *authorized_keys, ConNetworkAuthorizedKeyAction action, const std::string &authorized_key, CompanyID company = INVALID_COMPANY) +static void PerformNetworkAuthorizedKeyAction(std::string_view name, NetworkAuthorizedKeys *authorized_keys, ConNetworkAuthorizedKeyAction action, const std::string &authorized_key, CompanyID company = CompanyID::Invalid()) { switch (action) { case CNAKA_LIST: @@ -1978,7 +1978,7 @@ static void PerformNetworkAuthorizedKeyAction(std::string_view name, NetworkAuth return; } - if (company == INVALID_COMPANY) { + if (company == CompanyID::Invalid()) { authorized_keys->Add(authorized_key); } else { AutoRestoreBackup backup(_current_company, company); @@ -1993,7 +1993,7 @@ static void PerformNetworkAuthorizedKeyAction(std::string_view name, NetworkAuth return; } - if (company == INVALID_COMPANY) { + if (company == CompanyID::Invalid()) { authorized_keys->Remove(authorized_key); } else { AutoRestoreBackup backup(_current_company, company); diff --git a/src/depot_gui.cpp b/src/depot_gui.cpp index 6ca6778349..83bd961627 100644 --- a/src/depot_gui.cpp +++ b/src/depot_gui.cpp @@ -144,7 +144,7 @@ static void TrainDepotMoveVehicle(const Vehicle *wagon, VehicleID sel, const Veh if (wagon == v) return; - Command::Post(STR_ERROR_CAN_T_MOVE_VEHICLE, v->tile, v->index, wagon == nullptr ? INVALID_VEHICLE : wagon->index, _ctrl_pressed); + Command::Post(STR_ERROR_CAN_T_MOVE_VEHICLE, v->tile, v->index, wagon == nullptr ? VehicleID::Invalid() : wagon->index, _ctrl_pressed); } static VehicleCellSize _base_block_sizes_depot[VEH_COMPANY_END]; ///< Cell size for vehicle images in the depot view. @@ -255,7 +255,7 @@ const Sprite *GetAircraftSprite(EngineID engine); struct DepotWindow : Window { VehicleID sel; - VehicleID vehicle_over; ///< Rail vehicle over which another one is dragged, \c INVALID_VEHICLE if none. + VehicleID vehicle_over; ///< Rail vehicle over which another one is dragged, \c VehicleID::Invalid() if none. VehicleType type; bool generate_list; bool check_unitnumber_digits; @@ -271,8 +271,8 @@ struct DepotWindow : Window { { assert(IsCompanyBuildableVehicleType(type)); // ensure that we make the call with a valid type - this->sel = INVALID_VEHICLE; - this->vehicle_over = INVALID_VEHICLE; + this->sel = VehicleID::Invalid(); + this->vehicle_over = VehicleID::Invalid(); this->generate_list = true; this->check_unitnumber_digits = true; this->hovered_widget = -1; @@ -558,8 +558,8 @@ struct DepotWindow : Window { VehicleID sel = this->sel; - if (this->type == VEH_TRAIN && sel != INVALID_VEHICLE) { - this->sel = INVALID_VEHICLE; + if (this->type == VEH_TRAIN && sel != VehicleID::Invalid()) { + this->sel = VehicleID::Invalid(); TrainDepotMoveVehicle(v, sel, gdvp.head); } else if (v != nullptr) { SetObjectToPlaceWnd(SPR_CURSOR_MOUSE, PAL_NONE, HT_DRAG, this); @@ -980,8 +980,8 @@ struct DepotWindow : Window { this->SetWidgetDirty(WID_D_CLONE); /* abort drag & drop */ - this->sel = INVALID_VEHICLE; - this->vehicle_over = INVALID_VEHICLE; + this->sel = VehicleID::Invalid(); + this->vehicle_over = VehicleID::Invalid(); this->SetWidgetDirty(WID_D_MATRIX); if (this->hovered_widget != -1) { @@ -1002,7 +1002,7 @@ struct DepotWindow : Window { void OnMouseDrag(Point pt, WidgetID widget) override { - if (this->sel == INVALID_VEHICLE) return; + if (this->sel == VehicleID::Invalid()) return; if (widget != this->hovered_widget) { if (this->hovered_widget == WID_D_SELL || this->hovered_widget == WID_D_SELL_CHAIN) { this->SetWidgetLoweredState(this->hovered_widget, false); @@ -1018,8 +1018,8 @@ struct DepotWindow : Window { /* A rail vehicle is dragged.. */ if (widget != WID_D_MATRIX) { // ..outside of the depot matrix. - if (this->vehicle_over != INVALID_VEHICLE) { - this->vehicle_over = INVALID_VEHICLE; + if (this->vehicle_over != VehicleID::Invalid()) { + this->vehicle_over = VehicleID::Invalid(); this->SetWidgetDirty(WID_D_MATRIX); } return; @@ -1030,7 +1030,7 @@ struct DepotWindow : Window { if (this->GetVehicleFromDepotWndPt(pt.x, pt.y, &v, &gdvp) != MODE_DRAG_VEHICLE) return; - VehicleID new_vehicle_over = INVALID_VEHICLE; + VehicleID new_vehicle_over = VehicleID::Invalid(); if (gdvp.head != nullptr) { if (gdvp.wagon == nullptr && gdvp.head->Last()->index != this->sel) { // ..at the end of the train. /* NOTE: As a wagon can't be moved at the begin of a train, head index isn't used to mark a drag-and-drop @@ -1058,17 +1058,17 @@ struct DepotWindow : Window { const Vehicle *v = nullptr; VehicleID sel = this->sel; - this->sel = INVALID_VEHICLE; + this->sel = VehicleID::Invalid(); this->SetDirty(); if (this->type == VEH_TRAIN) { GetDepotVehiclePtData gdvp = { nullptr, nullptr }; - if (this->GetVehicleFromDepotWndPt(pt.x, pt.y, &v, &gdvp) == MODE_DRAG_VEHICLE && sel != INVALID_VEHICLE) { + if (this->GetVehicleFromDepotWndPt(pt.x, pt.y, &v, &gdvp) == MODE_DRAG_VEHICLE && sel != VehicleID::Invalid()) { if (gdvp.wagon != nullptr && gdvp.wagon->index == sel && _ctrl_pressed) { Command::Post(STR_ERROR_CAN_T_REVERSE_DIRECTION_RAIL_VEHICLE, Vehicle::Get(sel)->tile, Vehicle::Get(sel)->index, true); } else if (gdvp.wagon == nullptr || gdvp.wagon->index != sel) { - this->vehicle_over = INVALID_VEHICLE; + this->vehicle_over = VehicleID::Invalid(); TrainDepotMoveVehicle(gdvp.wagon, sel, gdvp.head); } else if (gdvp.head != nullptr && gdvp.head->IsFrontEngine()) { ShowVehicleViewWindow(gdvp.head); @@ -1082,12 +1082,12 @@ struct DepotWindow : Window { case WID_D_SELL: case WID_D_SELL_CHAIN: { if (this->IsWidgetDisabled(widget)) return; - if (this->sel == INVALID_VEHICLE) return; + if (this->sel == VehicleID::Invalid()) return; this->HandleButtonClick(widget); const Vehicle *v = Vehicle::Get(this->sel); - this->sel = INVALID_VEHICLE; + this->sel = VehicleID::Invalid(); this->SetDirty(); bool sell_cmd = (v->type == VEH_TRAIN && (widget == WID_D_SELL_CHAIN || _ctrl_pressed)); @@ -1096,7 +1096,7 @@ struct DepotWindow : Window { } default: - this->sel = INVALID_VEHICLE; + this->sel = VehicleID::Invalid(); this->SetDirty(); break; } @@ -1129,7 +1129,7 @@ struct DepotWindow : Window { EventState OnCTRLStateChange() override { - if (this->sel != INVALID_VEHICLE) { + if (this->sel != VehicleID::Invalid()) { _cursor.vehchain = _ctrl_pressed; this->SetWidgetDirty(WID_D_MATRIX); return ES_HANDLED; diff --git a/src/depot_type.h b/src/depot_type.h index d76693aa26..c99e732ae4 100644 --- a/src/depot_type.h +++ b/src/depot_type.h @@ -15,8 +15,6 @@ using DepotID = PoolID; ///< Type for the unique identifier of depots. struct Depot; -static constexpr DepotID INVALID_DEPOT = DepotID::Invalid(); - static const uint MAX_LENGTH_DEPOT_NAME_CHARS = 32; ///< The maximum length of a depot name in characters including '\0' #endif /* DEPOT_TYPE_H */ diff --git a/src/disaster_vehicle.cpp b/src/disaster_vehicle.cpp index 81c51d1fdb..6701364a6a 100644 --- a/src/disaster_vehicle.cpp +++ b/src/disaster_vehicle.cpp @@ -348,7 +348,7 @@ static bool DisasterTick_Ufo(DisasterVehicle *v) for (RoadVehicle *u : RoadVehicle::Iterate()) { /* Find (n+1)-th road vehicle. */ if (u->IsFrontEngine() && (n-- == 0)) { - if (u->crashed_ctr != 0 || u->disaster_vehicle != INVALID_VEHICLE) { + if (u->crashed_ctr != 0 || u->disaster_vehicle != VehicleID::Invalid()) { /* Targetted vehicle is crashed or already a target, destroy the UFO. */ delete v; return false; @@ -385,7 +385,7 @@ static bool DisasterTick_Ufo(DisasterVehicle *v) v->age++; if (u->crashed_ctr == 0) { uint victims = u->Crash(); - u->disaster_vehicle = INVALID_VEHICLE; + u->disaster_vehicle = VehicleID::Invalid(); AddTileNewsItem(STR_NEWS_DISASTER_SMALL_UFO, NewsType::Accident, u->tile); diff --git a/src/disaster_vehicle.h b/src/disaster_vehicle.h index 7b24c58895..995f80e5b5 100644 --- a/src/disaster_vehicle.h +++ b/src/disaster_vehicle.h @@ -42,7 +42,7 @@ struct DisasterVehicle final : public SpecializedVehicle bool { if (test) { - return Command::Do(CommandFlagsToDCFlags(GetCommandFlags()), tile, INVALID_STATION, adjacent).Succeeded(); + return Command::Do(CommandFlagsToDCFlags(GetCommandFlags()), tile, StationID::Invalid(), adjacent).Succeeded(); } else { return Command::Post(STR_ERROR_CAN_T_BUILD_DOCK_HERE, CcBuildDocks, tile, to_join, adjacent); } diff --git a/src/economy.cpp b/src/economy.cpp index f179bcb6c3..12fe4c3079 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -399,7 +399,7 @@ void ChangeOwnershipOfCompanyItems(Owner old_owner, Owner new_owner) t->exclusivity = new_owner; } else { t->exclusive_counter = 0; - t->exclusivity = INVALID_COMPANY; + t->exclusivity = CompanyID::Invalid(); } } } @@ -1114,7 +1114,7 @@ static Money DeliverGoods(int num_pieces, CargoType cargo_type, StationID dest, Station *st = Station::Get(dest); /* Give the goods to the industry. */ - uint accepted_ind = DeliverGoodsToIndustry(st, cargo_type, num_pieces, src.type == SourceType::Industry ? src.ToIndustryID() : INVALID_INDUSTRY, company->index); + uint accepted_ind = DeliverGoodsToIndustry(st, cargo_type, num_pieces, src.type == SourceType::Industry ? src.ToIndustryID() : IndustryID::Invalid(), company->index); /* If this cargo type is always accepted, accept all */ uint accepted_total = HasBit(st->always_accepted, cargo_type) ? num_pieces : accepted_ind; @@ -1507,7 +1507,7 @@ static void HandleStationRefit(Vehicle *v, CargoArray &consist_capleft, Station bool is_auto_refit = new_cargo_type == CARGO_AUTO_REFIT; if (is_auto_refit) { - /* Get a refittable cargo type with waiting cargo for next_station or INVALID_STATION. */ + /* Get a refittable cargo type with waiting cargo for next_station or StationID::Invalid(). */ new_cargo_type = v_start->cargo_type; for (CargoType cargo_type : SetCargoBitIterator(refit_mask)) { if (st->goods[cargo_type].HasData() && st->goods[cargo_type].GetData().cargo.HasCargoFor(next_station)) { @@ -1531,11 +1531,11 @@ static void HandleStationRefit(Vehicle *v, CargoArray &consist_capleft, Station /* Refit if given a valid cargo. */ if (new_cargo_type < NUM_CARGO && new_cargo_type != v_start->cargo_type) { - /* INVALID_STATION because in the DT_MANUAL case that's correct and in the DT_(A)SYMMETRIC + /* StationID::Invalid() because in the DT_MANUAL case that's correct and in the DT_(A)SYMMETRIC * cases the next hop of the vehicle doesn't really tell us anything if the cargo had been * "via any station" before reserving. We rather produce some more "any station" cargo than * misrouting it. */ - IterateVehicleParts(v_start, ReturnCargoAction(st, INVALID_STATION)); + IterateVehicleParts(v_start, ReturnCargoAction(st, StationID::Invalid())); CommandCost cost = std::get<0>(Command::Do(DoCommandFlag::Execute, v_start->index, new_cargo_type, 0xFF, true, false, 1)); // Auto-refit and only this vehicle including artic parts. if (cost.Succeeded()) v->First()->profit_this_year -= cost.GetCost() << 8; } @@ -1700,7 +1700,7 @@ static void LoadUnloadVehicle(Vehicle *front) uint new_remaining = v->cargo.RemainingCount() + v->cargo.ActionCount(VehicleCargoList::MTA_DELIVER); if (v->cargo_cap < new_remaining) { /* Return some of the reserved cargo to not overload the vehicle. */ - v->cargo.Return(new_remaining - v->cargo_cap, &ge->GetOrCreateData().cargo, INVALID_STATION, v->GetCargoTile()); + v->cargo.Return(new_remaining - v->cargo_cap, &ge->GetOrCreateData().cargo, StationID::Invalid(), v->GetCargoTile()); } /* Keep instead of delivering. This may lead to no cargo being unloaded, so ...*/ diff --git a/src/engine.cpp b/src/engine.cpp index afa54cb33a..dbdf17d3b9 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -73,8 +73,8 @@ Engine::Engine(VehicleType type, uint16_t local_id) this->type = type; this->grf_prop.local_id = local_id; this->list_position = local_id; - this->preview_company = INVALID_COMPANY; - this->display_last_variant = INVALID_ENGINE; + this->preview_company = CompanyID::Invalid(); + this->display_last_variant = EngineID::Invalid(); /* Check if this base engine is within the original engine data range */ if (local_id >= _engine_counts[type]) { @@ -99,7 +99,7 @@ Engine::Engine(VehicleType type, uint16_t local_id) /* Set cargo aging period to the default value. */ this->info.cargo_age_period = Ticks::CARGO_AGING_TICKS; /* Not a variant */ - this->info.variant_id = INVALID_ENGINE; + this->info.variant_id = EngineID::Invalid(); return; } @@ -496,7 +496,7 @@ bool Engine::IsVariantHidden(CompanyID c) const * the last display variant rather than the actual parent variant. */ const Engine *re = this; const Engine *ve = re->GetDisplayVariant(); - while (!(ve->IsHidden(c)) && re->info.variant_id != INVALID_ENGINE) { + while (!(ve->IsHidden(c)) && re->info.variant_id != EngineID::Invalid()) { re = Engine::Get(re->info.variant_id); ve = re->GetDisplayVariant(); } @@ -525,14 +525,14 @@ void EngineOverrideManager::ResetToDefaultMapping() * @param grfid The GrfID that defines the scope of grf_local_id. * If a newgrf overrides the engines of another newgrf, the "scope grfid" is the ID of the overridden newgrf. * If dynnamic_engines is disabled, all newgrf share the same ID scope identified by INVALID_GRFID. - * @return The engine ID if present, or INVALID_ENGINE if not. + * @return The engine ID if present, or EngineID::Invalid() if not. */ EngineID EngineOverrideManager::GetID(VehicleType type, uint16_t grf_local_id, uint32_t grfid) { const auto &map = this->mappings[type]; const auto key = EngineIDMapping::Key(grfid, grf_local_id); auto it = std::ranges::lower_bound(map, key, std::less{}, EngineIDMappingKeyProjection{}); - if (it == std::end(map) || it->Key() != key) return INVALID_ENGINE; + if (it == std::end(map) || it->Key() != key) return EngineID::Invalid(); return it->engine; } @@ -544,14 +544,14 @@ EngineID EngineOverrideManager::GetID(VehicleType type, uint16_t grf_local_id, u * If a newgrf overrides the engines of another newgrf, the "scope grfid" is the ID of the overridden newgrf. * If dynnamic_engines is disabled, all newgrf share the same ID scope identified by INVALID_GRFID. * @param static_access Whether to actually reserve the EngineID. - * @return The engine ID if present and now reserved, or INVALID_ENGINE if not. + * @return The engine ID if present and now reserved, or EngineID::Invalid() if not. */ EngineID EngineOverrideManager::UseUnreservedID(VehicleType type, uint16_t grf_local_id, uint32_t grfid, bool static_access) { auto &map = _engine_mngr.mappings[type]; const auto key = EngineIDMapping::Key(INVALID_GRFID, grf_local_id); auto it = std::ranges::lower_bound(map, key, std::less{}, EngineIDMappingKeyProjection{}); - if (it == std::end(map) || it->Key() != key) return INVALID_ENGINE; + if (it == std::end(map) || it->Key() != key) return EngineID::Invalid(); if (!static_access && grfid != INVALID_GRFID) { /* Reserve the engine slot for the new grfid. */ @@ -636,7 +636,7 @@ static bool IsWagon(EngineID index) static void ClearLastVariant(EngineID engine_id, VehicleType type) { for (Engine *e : Engine::IterateType(type)) { - if (e->display_last_variant == engine_id) e->display_last_variant = INVALID_ENGINE; + if (e->display_last_variant == engine_id) e->display_last_variant = EngineID::Invalid(); } } @@ -648,7 +648,7 @@ void CalcEngineReliability(Engine *e, bool new_month) { /* Get source engine for reliability age. This is normally our engine unless variant reliability syncing is requested. */ Engine *re = e; - while (re->info.variant_id != INVALID_ENGINE && re->info.extra_flags.Test(ExtraEngineFlag::SyncReliability)) { + while (re->info.variant_id != EngineID::Invalid() && re->info.extra_flags.Test(ExtraEngineFlag::SyncReliability)) { re = Engine::Get(re->info.variant_id); } @@ -750,7 +750,7 @@ void StartupOneEngine(Engine *e, const TimerGameCalendar::YearMonthDay &aging_ym /* Get parent variant index for syncing reliability via random seed. */ const Engine *re = e; - while (re->info.variant_id != INVALID_ENGINE && re->info.extra_flags.Test(ExtraEngineFlag::SyncReliability)) { + while (re->info.variant_id != EngineID::Invalid() && re->info.extra_flags.Test(ExtraEngineFlag::SyncReliability)) { re = Engine::Get(re->info.variant_id); } @@ -884,7 +884,7 @@ static void AcceptEnginePreview(EngineID eid, CompanyID company, int recursion_d { Engine *e = Engine::Get(eid); - e->preview_company = INVALID_COMPANY; + e->preview_company = CompanyID::Invalid(); e->preview_asked.Set(); EnableEngineForCompany(eid, company); @@ -910,11 +910,11 @@ static void AcceptEnginePreview(EngineID eid, CompanyID company, int recursion_d /** * Get the best company for an engine preview. * @param e Engine to preview. - * @return Best company if it exists, #INVALID_COMPANY otherwise. + * @return Best company if it exists, #CompanyID::Invalid() otherwise. */ static CompanyID GetPreviewCompany(Engine *e) { - CompanyID best_company = INVALID_COMPANY; + CompanyID best_company = CompanyID::Invalid(); /* For trains the cargomask has no useful meaning, since you can attach other wagons */ CargoTypes cargomask = e->type != VEH_TRAIN ? GetUnionOfArticulatedRefitMasks(e->index, true) : ALL_CARGOTYPES; @@ -971,15 +971,15 @@ static IntervalTimer _calendar_engines_daily({TimerGameCalend for (Engine *e : Engine::Iterate()) { EngineID i = e->index; if (e->flags.Test(EngineFlag::ExclusivePreview)) { - if (e->preview_company != INVALID_COMPANY) { + if (e->preview_company != CompanyID::Invalid()) { if (!--e->preview_wait) { CloseWindowById(WC_ENGINE_PREVIEW, i); - e->preview_company = INVALID_COMPANY; + e->preview_company = CompanyID::Invalid(); } } else if (CountBits(e->preview_asked.base()) < MAX_COMPANIES) { e->preview_company = GetPreviewCompany(e); - if (e->preview_company == INVALID_COMPANY) { + if (e->preview_company == CompanyID::Invalid()) { e->preview_asked.Set(); continue; } @@ -1177,7 +1177,7 @@ void CalendarEnginesMonthlyLoop() /* Show preview dialog to one of the companies. */ e->flags.Set(EngineFlag::ExclusivePreview); - e->preview_company = INVALID_COMPANY; + e->preview_company = CompanyID::Invalid(); e->preview_asked = CompanyMask{}; } } diff --git a/src/engine_base.h b/src/engine_base.h index b662de7507..61b40bc6d2 100644 --- a/src/engine_base.h +++ b/src/engine_base.h @@ -55,7 +55,7 @@ struct Engine : EnginePool::PoolItem<&_engine_pool> { uint16_t duration_phase_3; ///< Third reliability phase in months, decaying to #reliability_final. EngineFlags flags; ///< Flags of the engine. @see EngineFlags - CompanyID preview_company; ///< Company which is currently being offered a preview \c INVALID_COMPANY means no company. + CompanyID preview_company; ///< Company which is currently being offered a preview \c CompanyID::Invalid() means no company. uint8_t preview_wait; ///< Daily countdown timer for timeout of offering the engine to the #preview_company company. uint8_t original_image_index; ///< Original vehicle image index, thus the image index of the overridden vehicle VehicleType type; ///< %Vehicle type, ie #VEH_ROAD, #VEH_TRAIN, etc. @@ -149,7 +149,7 @@ struct Engine : EnginePool::PoolItem<&_engine_pool> { */ const Engine *GetDisplayVariant() const { - if (this->display_last_variant == this->index || this->display_last_variant == INVALID_ENGINE) return this; + if (this->display_last_variant == this->index || this->display_last_variant == EngineID::Invalid()) return this; return Engine::Get(this->display_last_variant); } diff --git a/src/engine_gui.h b/src/engine_gui.h index 5fa8aa3319..b536f400ab 100644 --- a/src/engine_gui.h +++ b/src/engine_gui.h @@ -53,6 +53,6 @@ extern EngList_SortTypeFunction * const _engine_sort_functions[][11]; uint GetEngineListHeight(VehicleType type); void DisplayVehicleSortDropDown(Window *w, VehicleType vehicle_type, int selected, WidgetID button); void DrawEngineList(VehicleType type, const Rect &r, const GUIEngineList &eng_list, const Scrollbar &sb, EngineID selected_id, bool show_count, GroupID selected_group); -void GUIEngineListAddChildren(GUIEngineList &dst, const GUIEngineList &src, EngineID parent = INVALID_ENGINE, uint8_t indent = 0); +void GUIEngineListAddChildren(GUIEngineList &dst, const GUIEngineList &src, EngineID parent = EngineID::Invalid(), uint8_t indent = 0); #endif /* ENGINE_GUI_H */ diff --git a/src/engine_type.h b/src/engine_type.h index 02fc763cf7..145d34497e 100644 --- a/src/engine_type.h +++ b/src/engine_type.h @@ -22,7 +22,6 @@ /** Unique identification number of an engine. */ using EngineID = PoolID; -static constexpr EngineID INVALID_ENGINE = EngineID::Invalid(); ///< Constant denoting an invalid engine. struct Engine; diff --git a/src/error.h b/src/error.h index 3f8797a30d..d1746134e4 100644 --- a/src/error.h +++ b/src/error.h @@ -38,17 +38,17 @@ protected: EncodedString detailed_msg; ///< Detailed error message showed in second line. Can be #INVALID_STRING_ID. EncodedString extra_msg; ///< Extra error message shown in third line. Can be #INVALID_STRING_ID. Point position; ///< Position of the error message window. - CompanyID company; ///< Company belonging to the face being shown. #INVALID_COMPANY if no face present. + CompanyID company; ///< Company belonging to the face being shown. #CompanyID::Invalid() if no face present. public: ErrorMessageData(const ErrorMessageData &data); - ErrorMessageData(EncodedString &&summary_msg, EncodedString &&detailed_msg, bool is_critical = false, int x = 0, int y = 0, const GRFFile *textref_stack_grffile = nullptr, uint textref_stack_size = 0, const uint32_t *textref_stack = nullptr, EncodedString &&extra_msg = {}, CompanyID company = INVALID_COMPANY); + ErrorMessageData(EncodedString &&summary_msg, EncodedString &&detailed_msg, bool is_critical = false, int x = 0, int y = 0, const GRFFile *textref_stack_grffile = nullptr, uint textref_stack_size = 0, const uint32_t *textref_stack = nullptr, EncodedString &&extra_msg = {}, CompanyID company = CompanyID::Invalid()); /* Remove the copy assignment, as the default implementation will not do the right thing. */ ErrorMessageData &operator=(ErrorMessageData &rhs) = delete; /** Check whether error window shall display a company manager face */ - bool HasFace() const { return company != INVALID_COMPANY; } + bool HasFace() const { return company != CompanyID::Invalid(); } }; /** Define a queue with errors. */ @@ -58,7 +58,7 @@ void ScheduleErrorMessage(ErrorList &datas); void ScheduleErrorMessage(const ErrorMessageData &data); void ShowErrorMessage(EncodedString &&summary_msg, int x, int y, const CommandCost &cc); -void ShowErrorMessage(EncodedString &&summary_msg, EncodedString &&detailed_msg, WarningLevel wl, int x = 0, int y = 0, const GRFFile *textref_stack_grffile = nullptr, uint textref_stack_size = 0, const uint32_t *textref_stack = nullptr, EncodedString &&extra_msg = {}, CompanyID company = INVALID_COMPANY); +void ShowErrorMessage(EncodedString &&summary_msg, EncodedString &&detailed_msg, WarningLevel wl, int x = 0, int y = 0, const GRFFile *textref_stack_grffile = nullptr, uint textref_stack_size = 0, const uint32_t *textref_stack = nullptr, EncodedString &&extra_msg = {}, CompanyID company = CompanyID::Invalid()); bool HideActiveErrorMessage(); void ClearErrorMessages(); diff --git a/src/error_gui.cpp b/src/error_gui.cpp index 316511f501..081a9f825d 100644 --- a/src/error_gui.cpp +++ b/src/error_gui.cpp @@ -197,12 +197,12 @@ public: void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override { /* If company gets shut down, while displaying an error about it, remove the error message. */ - if (this->company != INVALID_COMPANY && !Company::IsValidID(this->company)) this->Close(); + if (this->company != CompanyID::Invalid() && !Company::IsValidID(this->company)) this->Close(); } void SetStringParameters(WidgetID widget) const override { - if (widget == WID_EM_CAPTION && this->company != INVALID_COMPANY) SetDParam(0, this->company); + if (widget == WID_EM_CAPTION && this->company != CompanyID::Invalid()) SetDParam(0, this->company); } void DrawWidget(const Rect &r, WidgetID widget) const override diff --git a/src/genworld.cpp b/src/genworld.cpp index 60aaf61b25..1cb8bec969 100644 --- a/src/genworld.cpp +++ b/src/genworld.cpp @@ -373,7 +373,7 @@ static bool TryFoundTownNearby(TileIndex tile, void *user_data) TownID id = std::get(result); /* Check if the command failed. */ - if (id == INVALID_TOWN) return false; + if (id == TownID::Invalid()) return false; /* The command succeeded, send the ID back through user_data. */ town.town_id = id; diff --git a/src/goal.cpp b/src/goal.cpp index ac0d9e1789..0902bf2607 100644 --- a/src/goal.cpp +++ b/src/goal.cpp @@ -57,7 +57,7 @@ INSTANTIATE_POOL_METHODS(Goal) case GT_STORY_PAGE: { if (!StoryPage::IsValidID(dest)) return false; CompanyID story_company = StoryPage::Get(dest)->company; - if (company == INVALID_COMPANY ? story_company != INVALID_COMPANY : story_company != INVALID_COMPANY && story_company != company) return false; + if (company == CompanyID::Invalid() ? story_company != CompanyID::Invalid() : story_company != CompanyID::Invalid() && story_company != company) return false; break; } @@ -77,12 +77,12 @@ INSTANTIATE_POOL_METHODS(Goal) */ std::tuple CmdCreateGoal(DoCommandFlags flags, CompanyID company, GoalType type, GoalTypeID dest, const std::string &text) { - if (!Goal::CanAllocateItem()) return { CMD_ERROR, INVALID_GOAL }; + if (!Goal::CanAllocateItem()) return { CMD_ERROR, GoalID::Invalid() }; - if (_current_company != OWNER_DEITY) return { CMD_ERROR, INVALID_GOAL }; - if (text.empty()) return { CMD_ERROR, INVALID_GOAL }; - if (company != INVALID_COMPANY && !Company::IsValidID(company)) return { CMD_ERROR, INVALID_GOAL }; - if (!Goal::IsValidGoalDestination(company, type, dest)) return { CMD_ERROR, INVALID_GOAL }; + if (_current_company != OWNER_DEITY) return { CMD_ERROR, GoalID::Invalid() }; + if (text.empty()) return { CMD_ERROR, GoalID::Invalid() }; + if (company != CompanyID::Invalid() && !Company::IsValidID(company)) return { CMD_ERROR, GoalID::Invalid() }; + if (!Goal::IsValidGoalDestination(company, type, dest)) return { CMD_ERROR, GoalID::Invalid() }; if (flags.Test(DoCommandFlag::Execute)) { Goal *g = new Goal(); @@ -92,7 +92,7 @@ std::tuple CmdCreateGoal(DoCommandFlags flags, CompanyID co g->text = text; g->completed = false; - if (g->company == INVALID_COMPANY) { + if (g->company == CompanyID::Invalid()) { InvalidateWindowClassesData(WC_GOALS_LIST); } else { InvalidateWindowData(WC_GOALS_LIST, g->company); @@ -102,7 +102,7 @@ std::tuple CmdCreateGoal(DoCommandFlags flags, CompanyID co return { CommandCost(), g->index }; } - return { CommandCost(), INVALID_GOAL }; + return { CommandCost(), GoalID::Invalid() }; } /** @@ -121,7 +121,7 @@ CommandCost CmdRemoveGoal(DoCommandFlags flags, GoalID goal) CompanyID c = g->company; delete g; - if (c == INVALID_COMPANY) { + if (c == CompanyID::Invalid()) { InvalidateWindowClassesData(WC_GOALS_LIST); } else { InvalidateWindowData(WC_GOALS_LIST, c); @@ -172,7 +172,7 @@ CommandCost CmdSetGoalText(DoCommandFlags flags, GoalID goal, const std::string Goal *g = Goal::Get(goal); g->text = text; - if (g->company == INVALID_COMPANY) { + if (g->company == CompanyID::Invalid()) { InvalidateWindowClassesData(WC_GOALS_LIST); } else { InvalidateWindowData(WC_GOALS_LIST, g->company); @@ -198,7 +198,7 @@ CommandCost CmdSetGoalProgress(DoCommandFlags flags, GoalID goal, const std::str Goal *g = Goal::Get(goal); g->progress = text; - if (g->company == INVALID_COMPANY) { + if (g->company == CompanyID::Invalid()) { InvalidateWindowClassesData(WC_GOALS_LIST); } else { InvalidateWindowData(WC_GOALS_LIST, g->company); @@ -224,7 +224,7 @@ CommandCost CmdSetGoalCompleted(DoCommandFlags flags, GoalID goal, bool complete Goal *g = Goal::Get(goal); g->completed = completed; - if (g->company == INVALID_COMPANY) { + if (g->company == CompanyID::Invalid()) { InvalidateWindowClassesData(WC_GOALS_LIST); } else { InvalidateWindowData(WC_GOALS_LIST, g->company); @@ -263,7 +263,7 @@ CommandCost CmdGoalQuestion(DoCommandFlags flags, uint16_t uniqueid, uint32_t ta * fact the client is no longer here. */ if (!flags.Test(DoCommandFlag::Execute) && _network_server && NetworkClientInfo::GetByClientID(client) == nullptr) return CMD_ERROR; } else { - if (company != INVALID_COMPANY && !Company::IsValidID(company)) return CMD_ERROR; + if (company != CompanyID::Invalid() && !Company::IsValidID(company)) return CMD_ERROR; } uint min_buttons = (type == GQT_QUESTION ? 1 : 0); if (CountBits(button_mask) < min_buttons || CountBits(button_mask) > 3) return CMD_ERROR; @@ -273,8 +273,8 @@ CommandCost CmdGoalQuestion(DoCommandFlags flags, uint16_t uniqueid, uint32_t ta if (is_client) { if (client != _network_own_client_id) return CommandCost(); } else { - if (company == INVALID_COMPANY && !Company::IsValidID(_local_company)) return CommandCost(); - if (company != INVALID_COMPANY && company != _local_company) return CommandCost(); + if (company == CompanyID::Invalid() && !Company::IsValidID(_local_company)) return CommandCost(); + if (company != CompanyID::Invalid() && company != _local_company) return CommandCost(); } ShowGoalQuestion(uniqueid, type, button_mask, text); } diff --git a/src/goal_base.h b/src/goal_base.h index 8423bcb8b9..217dda5426 100644 --- a/src/goal_base.h +++ b/src/goal_base.h @@ -19,7 +19,7 @@ extern GoalPool _goal_pool; /** Struct about goals, current and completed */ struct Goal : GoalPool::PoolItem<&_goal_pool> { - CompanyID company; ///< Goal is for a specific company; INVALID_COMPANY if it is global + CompanyID company; ///< Goal is for a specific company; CompanyID::Invalid() if it is global GoalType type; ///< Type of the goal GoalTypeID dst; ///< Index of type std::string text; ///< Text of the goal. diff --git a/src/goal_gui.cpp b/src/goal_gui.cpp index 0df0a2dfc2..fe73ef11ed 100644 --- a/src/goal_gui.cpp +++ b/src/goal_gui.cpp @@ -47,7 +47,7 @@ struct GoalListWindow : public Window { this->FinishInitNested(window_number); this->owner = this->window_number; NWidgetStacked *wi = this->GetWidget(WID_GOAL_SELECT_BUTTONS); - wi->SetDisplayedPlane(window_number == INVALID_COMPANY ? 1 : 0); + wi->SetDisplayedPlane(window_number == CompanyID::Invalid() ? 1 : 0); this->OnInvalidateData(0); } @@ -55,7 +55,7 @@ struct GoalListWindow : public Window { { if (widget != WID_GOAL_CAPTION) return; - if (this->window_number == INVALID_COMPANY) { + if (this->window_number == CompanyID::Invalid()) { SetDParam(0, STR_GOALS_SPECTATOR_CAPTION); } else { SetDParam(0, STR_GOALS_CAPTION); @@ -67,7 +67,7 @@ struct GoalListWindow : public Window { { switch (widget) { case WID_GOAL_GLOBAL_BUTTON: - ShowGoalsList(INVALID_COMPANY); + ShowGoalsList(CompanyID::Invalid()); break; case WID_GOAL_COMPANY_BUTTON: @@ -134,7 +134,7 @@ struct GoalListWindow : public Window { */ CompanyID goal_company = s->company; CompanyID story_company = StoryPage::Get(s->dst)->company; - if (goal_company == INVALID_COMPANY ? story_company != INVALID_COMPANY : story_company != INVALID_COMPANY && story_company != goal_company) return; + if (goal_company == CompanyID::Invalid() ? story_company != CompanyID::Invalid() : story_company != CompanyID::Invalid() && story_company != goal_company) return; ShowStoryBook(static_cast(this->window_number), static_cast(s->dst)); return; @@ -311,11 +311,11 @@ static WindowDesc _goals_list_desc( /** * Open a goal list window. - * @param company %Company to display the goals for, use #INVALID_COMPANY to display global goals. + * @param company %Company to display the goals for, use #CompanyID::Invalid() to display global goals. */ void ShowGoalsList(CompanyID company) { - if (!Company::IsValidID(company)) company = (CompanyID)INVALID_COMPANY; + if (!Company::IsValidID(company)) company = (CompanyID)CompanyID::Invalid(); AllocateWindowDescFront(_goals_list_desc, company); } diff --git a/src/goal_type.h b/src/goal_type.h index dbc7a8ae08..0ea1e96200 100644 --- a/src/goal_type.h +++ b/src/goal_type.h @@ -39,6 +39,5 @@ typedef uint32_t GoalTypeID; ///< Contains either tile, industry ID, town ID, co using GoalID = PoolID; struct Goal; -static constexpr GoalID INVALID_GOAL = GoalID::Invalid(); ///< Constant representing a non-existing goal. #endif /* GOAL_TYPE_H */ diff --git a/src/graph_gui.cpp b/src/graph_gui.cpp index bade233ac7..6179d775bc 100644 --- a/src/graph_gui.cpp +++ b/src/graph_gui.cpp @@ -54,7 +54,7 @@ struct GraphLegendWindow : Window { { this->InitNested(window_number); - for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; ++c) { + for (CompanyID c = CompanyID::Begin(); c < MAX_COMPANIES; ++c) { if (!_legend_excluded_companies.Test(c)) this->LowerWidget(WID_GL_FIRST_COMPANY + c); this->OnInvalidateData(c.base()); @@ -676,7 +676,7 @@ public: CompanyMask excluded_companies = _legend_excluded_companies; /* Exclude the companies which aren't valid */ - for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; ++c) { + for (CompanyID c = CompanyID::Begin(); c < MAX_COMPANIES; ++c) { if (!Company::IsValidID(c)) excluded_companies.Set(c); } @@ -704,7 +704,7 @@ public: this->month = mo; this->data.clear(); - for (CompanyID k = COMPANY_FIRST; k < MAX_COMPANIES; ++k) { + for (CompanyID k = CompanyID::Begin(); k < MAX_COMPANIES; ++k) { const Company *c = Company::GetIfValid(k); if (c == nullptr) continue; @@ -1269,7 +1269,7 @@ struct PerformanceRatingDetailWindow : Window { this->UpdateCompanyStats(); this->InitNested(window_number); - this->OnInvalidateData(INVALID_COMPANY.base()); + this->OnInvalidateData(CompanyID::Invalid().base()); } void UpdateCompanyStats() @@ -1353,7 +1353,7 @@ struct PerformanceRatingDetailWindow : Window { void DrawWidget(const Rect &r, WidgetID widget) const override { /* No need to draw when there's nothing to draw */ - if (this->company == INVALID_COMPANY) return; + if (this->company == CompanyID::Invalid()) return; if (IsInsideMM(widget, WID_PRD_COMPANY_FIRST, WID_PRD_COMPANY_LAST + 1)) { if (this->IsWidgetDisabled(widget)) return; @@ -1460,18 +1460,18 @@ struct PerformanceRatingDetailWindow : Window { { if (!gui_scope) return; /* Disable the companies who are not active */ - for (CompanyID i = COMPANY_FIRST; i < MAX_COMPANIES; ++i) { + for (CompanyID i = CompanyID::Begin(); i < MAX_COMPANIES; ++i) { this->SetWidgetDisabledState(WID_PRD_COMPANY_FIRST + i, !Company::IsValidID(i)); } /* Check if the currently selected company is still active. */ - if (this->company != INVALID_COMPANY && !Company::IsValidID(this->company)) { + if (this->company != CompanyID::Invalid() && !Company::IsValidID(this->company)) { /* Raise the widget for the previous selection. */ this->RaiseWidget(WID_PRD_COMPANY_FIRST + this->company); - this->company = INVALID_COMPANY; + this->company = CompanyID::Invalid(); } - if (this->company == INVALID_COMPANY) { + if (this->company == CompanyID::Invalid()) { for (const Company *c : Company::Iterate()) { this->company = c->index; break; @@ -1479,13 +1479,13 @@ struct PerformanceRatingDetailWindow : Window { } /* Make sure the widget is lowered */ - if (this->company != INVALID_COMPANY) { + if (this->company != CompanyID::Invalid()) { this->LowerWidget(WID_PRD_COMPANY_FIRST + this->company); } } }; -CompanyID PerformanceRatingDetailWindow::company = INVALID_COMPANY; +CompanyID PerformanceRatingDetailWindow::company = CompanyID::Invalid(); /*******************************/ /* INDUSTRY PRODUCTION HISTORY */ diff --git a/src/ground_vehicle.hpp b/src/ground_vehicle.hpp index b82cb33e3c..bd6863dae3 100644 --- a/src/ground_vehicle.hpp +++ b/src/ground_vehicle.hpp @@ -41,7 +41,7 @@ struct GroundVehicleCache { /* Cached NewGRF values, recalculated on load and each time a vehicle is added to/removed from the consist. */ uint16_t cached_total_length; ///< Length of the whole vehicle (valid only for the first engine). - EngineID first_engine; ///< Cached EngineID of the front vehicle. INVALID_ENGINE for the front vehicle itself. + EngineID first_engine; ///< Cached EngineID of the front vehicle. EngineID::Invalid() for the front vehicle itself. uint8_t cached_veh_length; ///< Length of this vehicle in units of 1/VEHICLE_LENGTH of normal length. It is cached because this can be set by a callback. /* Cached UI information. */ diff --git a/src/group.h b/src/group.h index 41ae9a3236..e398ea49f6 100644 --- a/src/group.h +++ b/src/group.h @@ -83,7 +83,7 @@ struct Group : GroupPool::PoolItem<&_group_pool> { GroupID parent; ///< Parent group uint16_t number; ///< Per-company group number. - Group(CompanyID owner = INVALID_COMPANY); + Group(CompanyID owner = CompanyID::Invalid()); }; diff --git a/src/group_cmd.cpp b/src/group_cmd.cpp index 6cdce04fac..5c1efbd389 100644 --- a/src/group_cmd.cpp +++ b/src/group_cmd.cpp @@ -265,7 +265,7 @@ static inline void UpdateNumEngineGroup(const Vehicle *v, GroupID old_g, GroupID const Livery *GetParentLivery(const Group *g) { - if (g->parent == INVALID_GROUP) { + if (g->parent == GroupID::Invalid()) { const Company *c = Company::Get(g->owner); return &c->livery[LS_DEFAULT]; } @@ -311,7 +311,7 @@ static void PropagateChildLivery(const Group *g, bool reset_cache) void UpdateCompanyGroupLiveries(const Company *c) { for (Group *g : Group::Iterate()) { - if (g->owner == c->index && g->parent == INVALID_GROUP) { + if (g->owner == c->index && g->parent == GroupID::Invalid()) { if (!HasBit(g->livery.in_use, 0)) g->livery.colour1 = c->livery[LS_DEFAULT].colour1; if (!HasBit(g->livery.in_use, 1)) g->livery.colour2 = c->livery[LS_DEFAULT].colour2; PropagateChildLivery(g, false); @@ -335,20 +335,20 @@ Group::Group(Owner owner) */ std::tuple CmdCreateGroup(DoCommandFlags flags, VehicleType vt, GroupID parent_group) { - if (!IsCompanyBuildableVehicleType(vt)) return { CMD_ERROR, INVALID_GROUP }; + if (!IsCompanyBuildableVehicleType(vt)) return { CMD_ERROR, GroupID::Invalid() }; - if (!Group::CanAllocateItem()) return { CMD_ERROR, INVALID_GROUP }; + if (!Group::CanAllocateItem()) return { CMD_ERROR, GroupID::Invalid() }; const Group *pg = Group::GetIfValid(parent_group); if (pg != nullptr) { - if (pg->owner != _current_company) return { CMD_ERROR, INVALID_GROUP }; - if (pg->vehicle_type != vt) return { CMD_ERROR, INVALID_GROUP }; + if (pg->owner != _current_company) return { CMD_ERROR, GroupID::Invalid() }; + if (pg->vehicle_type != vt) return { CMD_ERROR, GroupID::Invalid() }; } if (flags.Test(DoCommandFlag::Execute)) { Group *g = new Group(_current_company); g->vehicle_type = vt; - g->parent = INVALID_GROUP; + g->parent = GroupID::Invalid(); Company *c = Company::Get(g->owner); g->number = c->freegroups.UseID(c->freegroups.NextID()); @@ -369,7 +369,7 @@ std::tuple CmdCreateGroup(DoCommandFlags flags, VehicleTyp return { CommandCost(), g->index }; } - return { CommandCost(), INVALID_GROUP}; + return { CommandCost(), GroupID::Invalid()}; } @@ -466,7 +466,7 @@ CommandCost CmdAlterGroup(DoCommandFlags flags, AlterGroupMode mode, GroupID gro } if (flags.Test(DoCommandFlag::Execute)) { - g->parent = (pg == nullptr) ? INVALID_GROUP : pg->index; + g->parent = (pg == nullptr) ? GroupID::Invalid() : pg->index; GroupStatistics::UpdateAutoreplace(g->owner); if (!HasBit(g->livery.in_use, 0) || !HasBit(g->livery.in_use, 1)) { @@ -537,30 +537,30 @@ static void AddVehicleToGroup(Vehicle *v, GroupID new_g) std::tuple CmdAddVehicleGroup(DoCommandFlags flags, GroupID group_id, VehicleID veh_id, bool add_shared, const VehicleListIdentifier &vli) { GroupID new_g = group_id; - if (!Group::IsValidID(new_g) && !IsDefaultGroupID(new_g) && new_g != NEW_GROUP) return { CMD_ERROR, INVALID_GROUP }; + if (!Group::IsValidID(new_g) && !IsDefaultGroupID(new_g) && new_g != NEW_GROUP) return { CMD_ERROR, GroupID::Invalid() }; VehicleList list; - if (veh_id == INVALID_VEHICLE && vli.Valid()) { - if (!GenerateVehicleSortList(&list, vli) || list.empty()) return { CMD_ERROR, INVALID_GROUP }; + if (veh_id == VehicleID::Invalid() && vli.Valid()) { + if (!GenerateVehicleSortList(&list, vli) || list.empty()) return { CMD_ERROR, GroupID::Invalid() }; } else { Vehicle *v = Vehicle::GetIfValid(veh_id); - if (v == nullptr) return { CMD_ERROR, INVALID_GROUP }; + if (v == nullptr) return { CMD_ERROR, GroupID::Invalid() }; list.push_back(v); } VehicleType vtype = list.front()->type; for (const Vehicle *v : list) { - if (v->owner != _current_company || !v->IsPrimaryVehicle()) return { CMD_ERROR, INVALID_GROUP }; + if (v->owner != _current_company || !v->IsPrimaryVehicle()) return { CMD_ERROR, GroupID::Invalid() }; } if (Group::IsValidID(new_g)) { Group *g = Group::Get(new_g); - if (g->owner != _current_company || g->vehicle_type != vtype) return { CMD_ERROR, INVALID_GROUP }; + if (g->owner != _current_company || g->vehicle_type != vtype) return { CMD_ERROR, GroupID::Invalid() }; } if (new_g == NEW_GROUP) { /* Create new group. */ - auto [ret, new_group_id] = CmdCreateGroup(flags, vtype, INVALID_GROUP); + auto [ret, new_group_id] = CmdCreateGroup(flags, vtype, GroupID::Invalid()); if (ret.Failed()) return { ret, new_group_id }; new_g = new_group_id; @@ -878,7 +878,7 @@ bool GroupIsInGroup(GroupID search, GroupID group) do { if (search == group) return true; search = Group::Get(search)->parent; - } while (search != INVALID_GROUP); + } while (search != GroupID::Invalid()); return false; } diff --git a/src/group_gui.cpp b/src/group_gui.cpp index c040312c2e..11fbbe7df8 100644 --- a/src/group_gui.cpp +++ b/src/group_gui.cpp @@ -118,7 +118,7 @@ static constexpr NWidgetPart _nested_group_widgets[] = { * @param parent Current tree parent (set by self with recursion). * @param indent Current tree indentation level (set by self with recursion). */ -static void GuiGroupListAddChildren(GUIGroupList &dst, const GUIGroupList &src, bool fold, GroupID parent = INVALID_GROUP, uint8_t indent = 0) +static void GuiGroupListAddChildren(GUIGroupList &dst, const GUIGroupList &src, bool fold, GroupID parent = GroupID::Invalid(), uint8_t indent = 0) { for (const auto &item : src) { if (item.group->parent != parent) continue; @@ -182,7 +182,7 @@ void BuildGuiGroupList(GUIGroupList &dst, bool fold, Owner owner, VehicleType ve return r < 0; }); - GuiGroupListAddChildren(dst, list, fold, INVALID_GROUP, 0); + GuiGroupListAddChildren(dst, list, fold, GroupID::Invalid(), 0); } class VehicleGroupWindow : public BaseVehicleListWindow { @@ -200,8 +200,8 @@ private: }; GroupID group_sel; ///< Selected group (for drag/drop) - GroupID group_rename; ///< Group being renamed, INVALID_GROUP if none - GroupID group_over; ///< Group over which a vehicle is dragged, INVALID_GROUP if none + GroupID group_rename; ///< Group being renamed, GroupID::Invalid() if none + GroupID group_over; ///< Group over which a vehicle is dragged, GroupID::Invalid() if none GroupID group_confirm; ///< Group awaiting delete confirmation GUIGroupList groups; ///< List of groups uint tiny_step_height; ///< Step height for the group list @@ -374,7 +374,7 @@ private: */ void DirtyHighlightedGroupWidget() { - if (this->group_over == INVALID_GROUP) return; + if (this->group_over == GroupID::Invalid()) return; if (IsAllGroupID(this->group_over)) { this->SetWidgetDirty(WID_GL_ALL_VEHICLES); @@ -394,9 +394,9 @@ public: this->group_sb = this->GetScrollbar(WID_GL_LIST_GROUP_SCROLLBAR); this->vli.SetIndex(ALL_GROUP); - this->group_sel = INVALID_GROUP; - this->group_rename = INVALID_GROUP; - this->group_over = INVALID_GROUP; + this->group_sel = GroupID::Invalid(); + this->group_rename = GroupID::Invalid(); + this->group_over = GroupID::Invalid(); this->groups.ForceRebuild(); this->groups.NeedResort(); @@ -496,9 +496,9 @@ public: } /* Process ID-invalidation in command-scope as well */ - if (this->group_rename != INVALID_GROUP && !Group::IsValidID(this->group_rename)) { + if (this->group_rename != GroupID::Invalid() && !Group::IsValidID(this->group_rename)) { CloseWindowByClass(WC_QUERY_STRING); - this->group_rename = INVALID_GROUP; + this->group_rename = GroupID::Invalid(); } GroupID group = this->vli.ToGroupID(); @@ -757,7 +757,7 @@ public: this->vli.SetIndex(g); break; } - } while (g != INVALID_GROUP); + } while (g != GroupID::Invalid()); } Group::Get(it->group->index)->folded = !it->group->folded; @@ -886,25 +886,25 @@ public: switch (widget) { case WID_GL_ALL_VEHICLES: // All vehicles case WID_GL_DEFAULT_VEHICLES: // Ungrouped vehicles - if (g->parent != INVALID_GROUP) { - Command::Post(STR_ERROR_GROUP_CAN_T_SET_PARENT, AlterGroupMode::SetParent, this->group_sel, INVALID_GROUP, {}); + if (g->parent != GroupID::Invalid()) { + Command::Post(STR_ERROR_GROUP_CAN_T_SET_PARENT, AlterGroupMode::SetParent, this->group_sel, GroupID::Invalid(), {}); } - this->group_sel = INVALID_GROUP; - this->group_over = INVALID_GROUP; + this->group_sel = GroupID::Invalid(); + this->group_over = GroupID::Invalid(); this->SetDirty(); break; case WID_GL_LIST_GROUP: { // Matrix group auto it = this->group_sb->GetScrolledItemFromWidget(this->groups, pt.y, this, WID_GL_LIST_GROUP); - GroupID new_g = it == this->groups.end() ? INVALID_GROUP : it->group->index; + GroupID new_g = it == this->groups.end() ? GroupID::Invalid() : it->group->index; if (this->group_sel != new_g && g->parent != new_g) { Command::Post(STR_ERROR_GROUP_CAN_T_SET_PARENT, AlterGroupMode::SetParent, this->group_sel, new_g, {}); } - this->group_sel = INVALID_GROUP; - this->group_over = INVALID_GROUP; + this->group_sel = GroupID::Invalid(); + this->group_over = GroupID::Invalid(); this->SetDirty(); break; } @@ -917,16 +917,16 @@ public: case WID_GL_DEFAULT_VEHICLES: // Ungrouped vehicles Command::Post(STR_ERROR_GROUP_CAN_T_ADD_VEHICLE, DEFAULT_GROUP, this->vehicle_sel, _ctrl_pressed || this->grouping == GB_SHARED_ORDERS, VehicleListIdentifier{}); - this->vehicle_sel = INVALID_VEHICLE; - this->group_over = INVALID_GROUP; + this->vehicle_sel = VehicleID::Invalid(); + this->group_over = GroupID::Invalid(); this->SetDirty(); break; case WID_GL_LIST_GROUP: { // Matrix group const VehicleID vindex = this->vehicle_sel; - this->vehicle_sel = INVALID_VEHICLE; - this->group_over = INVALID_GROUP; + this->vehicle_sel = VehicleID::Invalid(); + this->group_over = GroupID::Invalid(); this->SetDirty(); auto it = this->group_sb->GetScrolledItemFromWidget(this->groups, pt.y, this, WID_GL_LIST_GROUP); @@ -938,8 +938,8 @@ public: case WID_GL_LIST_VEHICLE: { // Matrix vehicle const VehicleID vindex = this->vehicle_sel; - this->vehicle_sel = INVALID_VEHICLE; - this->group_over = INVALID_GROUP; + this->vehicle_sel = VehicleID::Invalid(); + this->group_over = GroupID::Invalid(); this->SetDirty(); auto it = this->vscroll->GetScrolledItemFromWidget(this->vehgroups, pt.y, this, WID_GL_LIST_VEHICLE); @@ -979,16 +979,16 @@ public: void OnDragDrop(Point pt, WidgetID widget) override { - if (this->vehicle_sel != INVALID_VEHICLE) OnDragDrop_Vehicle(pt, widget); - if (this->group_sel != INVALID_GROUP) OnDragDrop_Group(pt, widget); + if (this->vehicle_sel != VehicleID::Invalid()) OnDragDrop_Vehicle(pt, widget); + if (this->group_sel != GroupID::Invalid()) OnDragDrop_Group(pt, widget); _cursor.vehchain = false; } void OnQueryTextFinished(std::optional str) override { - if (str.has_value()) Command::Post(STR_ERROR_GROUP_CAN_T_RENAME, AlterGroupMode::Rename, this->group_rename, INVALID_GROUP, *str); - this->group_rename = INVALID_GROUP; + if (str.has_value()) Command::Post(STR_ERROR_GROUP_CAN_T_RENAME, AlterGroupMode::Rename, this->group_rename, GroupID::Invalid(), *str); + this->group_rename = GroupID::Invalid(); } void OnResize() override @@ -1021,12 +1021,12 @@ public: break; case ADI_SERVICE: // Send for servicing case ADI_DEPOT: { // Send to Depots - Command::Post(GetCmdSendToDepotMsg(this->vli.vtype), INVALID_VEHICLE, (index == ADI_SERVICE ? DepotCommandFlag::Service : DepotCommandFlags{}) | DepotCommandFlag::MassSend, this->vli); + Command::Post(GetCmdSendToDepotMsg(this->vli.vtype), VehicleID::Invalid(), (index == ADI_SERVICE ? DepotCommandFlag::Service : DepotCommandFlags{}) | DepotCommandFlag::MassSend, this->vli); break; } case ADI_CREATE_GROUP: // Create group - Command::Post(CcAddVehicleNewGroup, NEW_GROUP, INVALID_VEHICLE, false, this->vli); + Command::Post(CcAddVehicleNewGroup, NEW_GROUP, VehicleID::Invalid(), false, this->vli); break; case ADI_ADD_SHARED: // Add shared Vehicles @@ -1059,19 +1059,19 @@ public: void OnPlaceObjectAbort() override { /* abort drag & drop */ - this->vehicle_sel = INVALID_VEHICLE; + this->vehicle_sel = VehicleID::Invalid(); this->DirtyHighlightedGroupWidget(); - this->group_sel = INVALID_GROUP; - this->group_over = INVALID_GROUP; + this->group_sel = GroupID::Invalid(); + this->group_over = GroupID::Invalid(); this->SetWidgetDirty(WID_GL_LIST_VEHICLE); } void OnMouseDrag(Point pt, WidgetID widget) override { - if (this->vehicle_sel == INVALID_VEHICLE && this->group_sel == INVALID_GROUP) return; + if (this->vehicle_sel == VehicleID::Invalid() && this->group_sel == GroupID::Invalid()) return; /* A vehicle is dragged over... */ - GroupID new_group_over = INVALID_GROUP; + GroupID new_group_over = GroupID::Invalid(); switch (widget) { case WID_GL_DEFAULT_VEHICLES: // ... the 'default' group. new_group_over = DEFAULT_GROUP; @@ -1085,10 +1085,10 @@ public: } /* Do not highlight when dragging over the current group */ - if (this->vehicle_sel != INVALID_VEHICLE) { - if (Vehicle::Get(vehicle_sel)->group_id == new_group_over) new_group_over = INVALID_GROUP; - } else if (this->group_sel != INVALID_GROUP) { - if (this->group_sel == new_group_over || Group::Get(this->group_sel)->parent == new_group_over) new_group_over = INVALID_GROUP; + if (this->vehicle_sel != VehicleID::Invalid()) { + if (Vehicle::Get(vehicle_sel)->group_id == new_group_over) new_group_over = GroupID::Invalid(); + } else if (this->group_sel != GroupID::Invalid()) { + if (this->group_sel == new_group_over || Group::Get(this->group_sel)->parent == new_group_over) new_group_over = GroupID::Invalid(); } /* Mark widgets as dirty if the group changed. */ @@ -1128,7 +1128,7 @@ public: */ void SelectGroup(const GroupID g_id) { - if (g_id == INVALID_GROUP || g_id == this->vli.ToGroupID()) return; + if (g_id == GroupID::Invalid() || g_id == this->vli.ToGroupID()) return; this->vli.SetIndex(g_id); if (g_id != ALL_GROUP && g_id != DEFAULT_GROUP) { @@ -1184,7 +1184,7 @@ static WindowDesc _vehicle_group_desc[] = { * Show the group window for the given company and vehicle type. * @param company The company to show the window for. * @param vehicle_type The type of vehicle to show it for. - * @param group The group to be selected. Defaults to INVALID_GROUP. + * @param group The group to be selected. Defaults to GroupID::Invalid(). * @tparam Tneed_existing_window Whether the existing window is needed. */ template @@ -1202,7 +1202,7 @@ static void ShowCompanyGroupInternal(CompanyID company, VehicleType vehicle_type * Show the group window for the given company and vehicle type. * @param company The company to show the window for. * @param vehicle_type The type of vehicle to show it for. - * @param group The group to be selected. Defaults to INVALID_GROUP. + * @param group The group to be selected. Defaults to GroupID::Invalid(). */ void ShowCompanyGroup(CompanyID company, VehicleType vehicle_type, GroupID group) { diff --git a/src/group_gui.h b/src/group_gui.h index 816fcc4d50..7b855deafb 100644 --- a/src/group_gui.h +++ b/src/group_gui.h @@ -13,7 +13,7 @@ #include "company_type.h" #include "vehicle_type.h" -void ShowCompanyGroup(CompanyID company, VehicleType veh, GroupID group = INVALID_GROUP); +void ShowCompanyGroup(CompanyID company, VehicleType veh, GroupID group = GroupID::Invalid()); void ShowCompanyGroupForVehicle(const Vehicle *v); void DeleteGroupHighlightOfVehicle(const Vehicle *v); diff --git a/src/group_type.h b/src/group_type.h index 09b87fc64a..274c720af3 100644 --- a/src/group_type.h +++ b/src/group_type.h @@ -16,7 +16,6 @@ using GroupID = PoolID; static constexpr GroupID NEW_GROUP{0xFFFC}; ///< Sentinel for a to-be-created group. static constexpr GroupID ALL_GROUP{0xFFFD}; ///< All vehicles are in this group. static constexpr GroupID DEFAULT_GROUP{0xFFFE}; ///< Ungrouped vehicles are in this group. -static constexpr GroupID INVALID_GROUP = GroupID::Invalid(); ///< Sentinel for invalid groups. static const uint MAX_LENGTH_GROUP_NAME_CHARS = 32; ///< The maximum length of a group name in characters including '\0' diff --git a/src/gui.h b/src/gui.h index d06b2714a1..ed8a7d3e98 100644 --- a/src/gui.h +++ b/src/gui.h @@ -65,7 +65,7 @@ void ShowGoalsList(CompanyID company); void ShowGoalQuestion(uint16_t id, uint8_t type, uint32_t button_mask, const std::string &question); /* story_gui.cpp */ -void ShowStoryBook(CompanyID company, StoryPageID page_id = INVALID_STORY_PAGE, bool centered = false); +void ShowStoryBook(CompanyID company, StoryPageID page_id = StoryPageID::Invalid(), bool centered = false); /* viewport_gui.cpp */ void ShowExtraViewportWindow(TileIndex tile = INVALID_TILE); diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp index d7c953537f..0714c8b7c9 100644 --- a/src/industry_cmd.cpp +++ b/src/industry_cmd.cpp @@ -178,7 +178,7 @@ Industry::~Industry() for (TileIndex tile_cur : ta) { if (IsTileType(tile_cur, MP_CLEAR) && IsClearGround(tile_cur, CLEAR_FIELDS) && GetIndustryIndexOfField(tile_cur) == this->index) { - SetIndustryIndexOfField(tile_cur, INVALID_INDUSTRY); + SetIndustryIndexOfField(tile_cur, IndustryID::Invalid()); } } } diff --git a/src/industry_type.h b/src/industry_type.h index b6975c0d86..7915b45564 100644 --- a/src/industry_type.h +++ b/src/industry_type.h @@ -11,7 +11,6 @@ #define INDUSTRY_TYPE_H using IndustryID = PoolID; -static constexpr IndustryID INVALID_INDUSTRY = IndustryID::Invalid(); typedef uint16_t IndustryGfx; typedef uint8_t IndustryType; diff --git a/src/intro_gui.cpp b/src/intro_gui.cpp index 78b37cdf57..dee8f26762 100644 --- a/src/intro_gui.cpp +++ b/src/intro_gui.cpp @@ -62,7 +62,7 @@ struct IntroGameViewportCommand { int command_index = 0; ///< Sequence number of the command (order they are performed in). Point position{ 0, 0 }; ///< Calculated world coordinate to position viewport top-left at. - VehicleID vehicle = INVALID_VEHICLE; ///< Vehicle to follow, or INVALID_VEHICLE if not following a vehicle. + VehicleID vehicle = VehicleID::Invalid(); ///< Vehicle to follow, or VehicleID::Invalid() if not following a vehicle. uint delay = 0; ///< Delay until next command. int zoom_adjust = 0; ///< Adjustment to zoom level from base zoom level. bool pan_to_next = false; ///< If true, do a smooth pan from this position to the next. @@ -77,7 +77,7 @@ struct IntroGameViewportCommand { */ Point PositionForViewport(const Viewport *vp) { - if (this->vehicle != INVALID_VEHICLE) { + if (this->vehicle != VehicleID::Invalid()) { const Vehicle *v = Vehicle::Get(this->vehicle); this->position = RemapCoords(v->x_pos, v->y_pos, v->z_pos); } @@ -228,7 +228,7 @@ struct SelectGameWindow : public Window { Viewport *vp = mw->viewport; /* Early exit if the current command hasn't elapsed and isn't animated. */ - if (!changed_command && !vc.pan_to_next && vc.vehicle == INVALID_VEHICLE) return; + if (!changed_command && !vc.pan_to_next && vc.vehicle == VehicleID::Invalid()) return; /* Suppress panning commands, while user interacts with GUIs. */ if (!changed_command && suppress_panning) return; @@ -256,7 +256,7 @@ struct SelectGameWindow : public Window { mw->SetDirty(); // Required during panning, otherwise logo graphics disappears /* If there is only one command, we just executed it and don't need to do any more */ - if (intro_viewport_commands.size() == 1 && vc.vehicle == INVALID_VEHICLE) intro_viewport_commands.clear(); + if (intro_viewport_commands.size() == 1 && vc.vehicle == VehicleID::Invalid()) intro_viewport_commands.clear(); } /** diff --git a/src/league_base.h b/src/league_base.h index 3dd3180208..07569d625f 100644 --- a/src/league_base.h +++ b/src/league_base.h @@ -31,7 +31,7 @@ extern LeagueTablePool _league_table_pool; struct LeagueTableElement : LeagueTableElementPool::PoolItem<&_league_table_element_pool> { LeagueTableID table; ///< Id of the table which this element belongs to int64_t rating; ///< Value that determines ordering of elements in the table (higher=better) - CompanyID company; ///< Company Id to show the color blob for or INVALID_COMPANY + CompanyID company; ///< Company Id to show the color blob for or CompanyID::Invalid() std::string text; ///< Text of the element std::string score; ///< String representation of the score associated with the element Link link; ///< What opens when element is clicked diff --git a/src/league_cmd.cpp b/src/league_cmd.cpp index dfcc28f7c5..4db3d3086f 100644 --- a/src/league_cmd.cpp +++ b/src/league_cmd.cpp @@ -55,9 +55,9 @@ bool IsValidLink(Link link) */ std::tuple CmdCreateLeagueTable(DoCommandFlags flags, const std::string &title, const std::string &header, const std::string &footer) { - if (_current_company != OWNER_DEITY) return { CMD_ERROR, INVALID_LEAGUE_TABLE }; - if (!LeagueTable::CanAllocateItem()) return { CMD_ERROR, INVALID_LEAGUE_TABLE }; - if (title.empty()) return { CMD_ERROR, INVALID_LEAGUE_TABLE }; + if (_current_company != OWNER_DEITY) return { CMD_ERROR, LeagueTableID::Invalid() }; + if (!LeagueTable::CanAllocateItem()) return { CMD_ERROR, LeagueTableID::Invalid() }; + if (title.empty()) return { CMD_ERROR, LeagueTableID::Invalid() }; if (flags.Test(DoCommandFlag::Execute)) { LeagueTable *lt = new LeagueTable(); @@ -67,7 +67,7 @@ std::tuple CmdCreateLeagueTable(DoCommandFlags flags return { CommandCost(), lt->index }; } - return { CommandCost(), INVALID_LEAGUE_TABLE }; + return { CommandCost(), LeagueTableID::Invalid() }; } @@ -76,7 +76,7 @@ std::tuple CmdCreateLeagueTable(DoCommandFlags flags * @param flags type of operation * @param table Id of the league table this element belongs to * @param rating Value that elements are ordered by - * @param company Company to show the color blob for or INVALID_COMPANY + * @param company Company to show the color blob for or CompanyID::Invalid() * @param text Text of the element * @param score String representation of the score associated with the element * @param link_type Type of the referenced object @@ -85,11 +85,11 @@ std::tuple CmdCreateLeagueTable(DoCommandFlags flags */ std::tuple CmdCreateLeagueTableElement(DoCommandFlags flags, LeagueTableID table, int64_t rating, CompanyID company, const std::string &text, const std::string &score, LinkType link_type, LinkTargetID link_target) { - if (_current_company != OWNER_DEITY) return { CMD_ERROR, INVALID_LEAGUE_TABLE_ELEMENT }; - if (!LeagueTableElement::CanAllocateItem()) return { CMD_ERROR, INVALID_LEAGUE_TABLE_ELEMENT }; + if (_current_company != OWNER_DEITY) return { CMD_ERROR, LeagueTableElementID::Invalid() }; + if (!LeagueTableElement::CanAllocateItem()) return { CMD_ERROR, LeagueTableElementID::Invalid() }; Link link{link_type, link_target}; - if (!IsValidLink(link)) return { CMD_ERROR, INVALID_LEAGUE_TABLE_ELEMENT }; - if (company != INVALID_COMPANY && !Company::IsValidID(company)) return { CMD_ERROR, INVALID_LEAGUE_TABLE_ELEMENT }; + if (!IsValidLink(link)) return { CMD_ERROR, LeagueTableElementID::Invalid() }; + if (company != CompanyID::Invalid() && !Company::IsValidID(company)) return { CMD_ERROR, LeagueTableElementID::Invalid() }; if (flags.Test(DoCommandFlag::Execute)) { LeagueTableElement *lte = new LeagueTableElement(); @@ -102,14 +102,14 @@ std::tuple CmdCreateLeagueTableElement(DoComm InvalidateWindowData(WC_COMPANY_LEAGUE, table); return { CommandCost(), lte->index }; } - return { CommandCost(), INVALID_LEAGUE_TABLE_ELEMENT }; + return { CommandCost(), LeagueTableElementID::Invalid() }; } /** * Update the attributes of a league table element. * @param flags type of operation * @param element Id of the element to update - * @param company Company to show the color blob for or INVALID_COMPANY + * @param company Company to show the color blob for or CompanyID::Invalid() * @param text Text of the element * @param link_type Type of the referenced object * @param link_target Id of the referenced object @@ -120,7 +120,7 @@ CommandCost CmdUpdateLeagueTableElementData(DoCommandFlags flags, LeagueTableEle if (_current_company != OWNER_DEITY) return CMD_ERROR; auto lte = LeagueTableElement::GetIfValid(element); if (lte == nullptr) return CMD_ERROR; - if (company != INVALID_COMPANY && !Company::IsValidID(company)) return CMD_ERROR; + if (company != CompanyID::Invalid() && !Company::IsValidID(company)) return CMD_ERROR; Link link{link_type, link_target}; if (!IsValidLink(link)) return CMD_ERROR; diff --git a/src/league_gui.cpp b/src/league_gui.cpp index b03cb6f5dc..2f4028ce4d 100644 --- a/src/league_gui.cpp +++ b/src/league_gui.cpp @@ -343,7 +343,7 @@ public: for (auto [rank, lte] : this->rows) { SetDParam(0, rank + 1); DrawString(rank_rect.left, rank_rect.right, ir.top + text_y_offset, STR_COMPANY_LEAGUE_COMPANY_RANK); - if (this->icon_size.width > 0 && lte->company != INVALID_COMPANY) DrawCompanyIcon(lte->company, icon_rect.left, ir.top + icon_y_offset); + if (this->icon_size.width > 0 && lte->company != CompanyID::Invalid()) DrawCompanyIcon(lte->company, icon_rect.left, ir.top + icon_y_offset); SetDParamStr(0, lte->text); DrawString(text_rect.left, text_rect.right, ir.top + text_y_offset, STR_JUST_RAW_STRING, TC_BLACK); SetDParamStr(0, lte->score); @@ -378,7 +378,7 @@ public: this->text_width = std::max(this->text_width, GetStringBoundingBox(STR_JUST_RAW_STRING).width); SetDParamStr(0, lte->score); this->score_width = std::max(this->score_width, GetStringBoundingBox(STR_JUST_RAW_STRING).width); - if (lte->company != INVALID_COMPANY) show_icon_column = true; + if (lte->company != CompanyID::Invalid()) show_icon_column = true; } if (!show_icon_column) this->icon_size.width = 0; diff --git a/src/league_type.h b/src/league_type.h index e423a7421d..6ff106110d 100644 --- a/src/league_type.h +++ b/src/league_type.h @@ -33,10 +33,8 @@ struct Link { using LeagueTableID = PoolID; ///< ID of a league table struct LeagueTable; -static constexpr LeagueTableID INVALID_LEAGUE_TABLE = LeagueTableID::Invalid(); ///< Invalid/unknown index of LeagueTable using LeagueTableElementID = PoolID; ///< ID of a league table struct LeagueTableElement; -static constexpr LeagueTableElementID INVALID_LEAGUE_TABLE_ELEMENT = LeagueTableElementID::Invalid(); ///< Invalid/unknown index of LeagueTableElement #endif /* LEAGUE_TYPE_H */ diff --git a/src/linkgraph/linkgraph.h b/src/linkgraph/linkgraph.h index e89259fd0a..3b4b56c844 100644 --- a/src/linkgraph/linkgraph.h +++ b/src/linkgraph/linkgraph.h @@ -96,7 +96,7 @@ public: std::vector edges; ///< Sorted list of outgoing edges from this node. - BaseNode(TileIndex xy = INVALID_TILE, StationID st = INVALID_STATION, uint demand = 0); + BaseNode(TileIndex xy = INVALID_TILE, StationID st = StationID::Invalid(), uint demand = 0); /** * Update the node's supply and set last_update to the current date. diff --git a/src/linkgraph/linkgraph_gui.cpp b/src/linkgraph/linkgraph_gui.cpp index 0348bf2496..e898b13d9e 100644 --- a/src/linkgraph/linkgraph_gui.cpp +++ b/src/linkgraph/linkgraph_gui.cpp @@ -561,7 +561,7 @@ void LinkGraphLegendWindow::SetOverlay(std::shared_ptr overlay { this->overlay = overlay; CompanyMask companies = this->overlay->GetCompanyMask(); - for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; ++c) { + for (CompanyID c = CompanyID::Begin(); c < MAX_COMPANIES; ++c) { if (!this->IsWidgetDisabled(WID_LGL_COMPANY_FIRST + c)) { this->SetWidgetLoweredState(WID_LGL_COMPANY_FIRST + c, companies.Test(c)); } @@ -658,7 +658,7 @@ bool LinkGraphLegendWindow::OnTooltip([[maybe_unused]] Point, WidgetID widget, T void LinkGraphLegendWindow::UpdateOverlayCompanies() { CompanyMask mask; - for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; ++c) { + for (CompanyID c = CompanyID::Begin(); c < MAX_COMPANIES; ++c) { if (this->IsWidgetDisabled(WID_LGL_COMPANY_FIRST + c)) continue; if (!this->IsWidgetLowered(WID_LGL_COMPANY_FIRST + c)) continue; mask.Set(c); @@ -688,7 +688,7 @@ void LinkGraphLegendWindow::OnClick([[maybe_unused]] Point pt, WidgetID widget, this->UpdateOverlayCompanies(); } } else if (widget == WID_LGL_COMPANIES_ALL || widget == WID_LGL_COMPANIES_NONE) { - for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; ++c) { + for (CompanyID c = CompanyID::Begin(); c < MAX_COMPANIES; ++c) { if (this->IsWidgetDisabled(WID_LGL_COMPANY_FIRST + c)) continue; this->SetWidgetLoweredState(WID_LGL_COMPANY_FIRST + c, widget == WID_LGL_COMPANIES_ALL); } @@ -719,7 +719,7 @@ void LinkGraphLegendWindow::OnInvalidateData([[maybe_unused]] int data, [[maybe_ } /* Disable the companies who are not active */ - for (CompanyID i = COMPANY_FIRST; i < MAX_COMPANIES; ++i) { + for (CompanyID i = CompanyID::Begin(); i < MAX_COMPANIES; ++i) { this->SetWidgetDisabledState(WID_LGL_COMPANY_FIRST + i, !Company::IsValidID(i)); } } diff --git a/src/linkgraph/linkgraph_type.h b/src/linkgraph/linkgraph_type.h index e60134b112..94791d01d0 100644 --- a/src/linkgraph/linkgraph_type.h +++ b/src/linkgraph/linkgraph_type.h @@ -13,10 +13,7 @@ #include "../core/pool_type.hpp" using LinkGraphID = PoolID; -static constexpr LinkGraphID INVALID_LINK_GRAPH = LinkGraphID::Invalid(); - using LinkGraphJobID = PoolID; -static constexpr LinkGraphJobID INVALID_LINK_GRAPH_JOB = LinkGraphJobID::Invalid(); typedef uint16_t NodeID; static const NodeID INVALID_NODE = UINT16_MAX; diff --git a/src/linkgraph/linkgraphjob.cpp b/src/linkgraph/linkgraphjob.cpp index 296d2a26f6..d8b889b93d 100644 --- a/src/linkgraph/linkgraphjob.cpp +++ b/src/linkgraph/linkgraphjob.cpp @@ -156,7 +156,7 @@ LinkGraphJob::~LinkGraphJob() it->second.Invalidate(); ++it; } else { - FlowStat shares(INVALID_STATION, 1); + FlowStat shares(StationID::Invalid(), 1); it->second.SwapShares(shares); geflows.erase(it++); for (FlowStat::SharesMap::const_iterator shares_it(shares.GetShares()->begin()); diff --git a/src/linkgraph/refresh.cpp b/src/linkgraph/refresh.cpp index a363305aa1..b9c8e6eae4 100644 --- a/src/linkgraph/refresh.cpp +++ b/src/linkgraph/refresh.cpp @@ -35,7 +35,7 @@ HopSet seen_hops; LinkRefresher refresher(v, &seen_hops, allow_merge, is_full_loading); - refresher.RefreshLinks(first, first, v->last_loading_station != INVALID_STATION ? 1 << HAS_CARGO : 0); + refresher.RefreshLinks(first, first, v->last_loading_station != StationID::Invalid() ? 1 << HAS_CARGO : 0); } /** @@ -200,7 +200,7 @@ void LinkRefresher::RefreshStats(const Order *cur, const Order *next) { StationID next_station = next->GetDestination().ToStationID(); Station *st = Station::GetIfValid(cur->GetDestination().ToStationID()); - if (st != nullptr && next_station != INVALID_STATION && next_station != st->index) { + if (st != nullptr && next_station != StationID::Invalid() && next_station != st->index) { Station *st_to = Station::Get(next_station); for (CargoType c = 0; c < NUM_CARGO; c++) { /* Refresh the link and give it a minimum capacity. */ diff --git a/src/main_gui.cpp b/src/main_gui.cpp index ff1893e1dd..931142b6f6 100644 --- a/src/main_gui.cpp +++ b/src/main_gui.cpp @@ -436,7 +436,7 @@ struct MainWindow : Window bool in = wheel < 0; /* When following, only change zoom - otherwise zoom to the cursor. */ - if (this->viewport->follow_vehicle != INVALID_VEHICLE) { + if (this->viewport->follow_vehicle != VehicleID::Invalid()) { DoZoomInOutWindow(in ? ZOOM_IN : ZOOM_OUT, this); } else { ZoomInOrOutToCursorWindow(in, this); diff --git a/src/network/network_admin.cpp b/src/network/network_admin.cpp index 4a9132381d..f5c540f624 100644 --- a/src/network/network_admin.cpp +++ b/src/network/network_admin.cpp @@ -29,7 +29,7 @@ /* This file handles all the admin network commands. */ /** Redirection of the (remote) console to the admin. */ -AdminID _redirect_console_to_admin = INVALID_ADMIN_ID; +AdminID _redirect_console_to_admin = AdminID::Invalid(); /** The pool with sockets/clients. */ NetworkAdminSocketPool _networkadminsocket_pool("NetworkAdminSocket"); @@ -74,7 +74,7 @@ ServerNetworkAdminSocketHandler::ServerNetworkAdminSocketHandler(SOCKET s) : Net ServerNetworkAdminSocketHandler::~ServerNetworkAdminSocketHandler() { Debug(net, 3, "[admin] '{}' ({}) has disconnected", this->admin_name, this->admin_version); - if (_redirect_console_to_admin == this->index) _redirect_console_to_admin = INVALID_ADMIN_ID; + if (_redirect_console_to_admin == this->index) _redirect_console_to_admin = AdminID::Invalid(); if (this->update_frequency[ADMIN_UPDATE_CONSOLE] & ADMIN_FREQUENCY_AUTOMATIC) { this->update_frequency[ADMIN_UPDATE_CONSOLE] = (AdminUpdateFrequency)0; @@ -492,7 +492,7 @@ NetworkRecvStatus ServerNetworkAdminSocketHandler::Receive_ADMIN_RCON(Packet &p) _redirect_console_to_admin = this->index; IConsoleCmdExec(command); - _redirect_console_to_admin = INVALID_ADMIN_ID; + _redirect_console_to_admin = AdminID::Invalid(); return this->SendRconEnd(command); } diff --git a/src/network/network_client.cpp b/src/network/network_client.cpp index a51756dc67..f716af4361 100644 --- a/src/network/network_client.cpp +++ b/src/network/network_client.cpp @@ -858,7 +858,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_MAP_DONE(Packet Debug(net, 9, "Client::join_status = REGISTERING"); _network_join_status = NETWORK_JOIN_STATUS_REGISTERING; ShowJoinStatusWindow(); - Command::Post(CCA_NEW, INVALID_COMPANY, CRR_NONE, _network_own_client_id); + Command::Post(CCA_NEW, CompanyID::Invalid(), CRR_NONE, _network_own_client_id); } } else { /* take control over an existing company */ diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp index ff38342106..a5078260cc 100644 --- a/src/network/network_gui.cpp +++ b/src/network/network_gui.cpp @@ -57,7 +57,7 @@ static void ShowNetworkStartServerWindow(); static ClientID _admin_client_id = INVALID_CLIENT_ID; ///< For what client a confirmation window is open. -static CompanyID _admin_company_id = INVALID_COMPANY; ///< For what company a confirmation window is open. +static CompanyID _admin_company_id = CompanyID::Invalid(); ///< For what company a confirmation window is open. /** * Update the network new window because a new server is @@ -1462,7 +1462,7 @@ private: */ static void OnClickCompanyNew([[maybe_unused]] NetworkClientListWindow *w, [[maybe_unused]] Point pt, CompanyID) { - Command::Post(CCA_NEW, INVALID_COMPANY, CRR_NONE, _network_own_client_id); + Command::Post(CCA_NEW, CompanyID::Invalid(), CRR_NONE, _network_own_client_id); } /** diff --git a/src/network/network_internal.h b/src/network/network_internal.h index 4c9e7ecae4..c7e6cf240a 100644 --- a/src/network/network_internal.h +++ b/src/network/network_internal.h @@ -92,7 +92,7 @@ void UpdateNetworkGameWindow(); * Everything we need to know about a command to be able to execute it. */ struct CommandPacket { - CommandPacket() : company(INVALID_COMPANY), frame(0), my_cmd(false) {} + CommandPacket() : company(CompanyID::Invalid()), frame(0), my_cmd(false) {} CompanyID company; ///< company that is executing the command uint32_t frame; ///< the frame in which this packet is executed bool my_cmd; ///< did the command originate from "me" diff --git a/src/network/network_type.h b/src/network/network_type.h index 23fbdd7195..ac04e1e3be 100644 --- a/src/network/network_type.h +++ b/src/network/network_type.h @@ -52,9 +52,6 @@ using ClientPoolID = PoolID; -/** An invalid admin marker. */ -static constexpr AdminID INVALID_ADMIN_ID = AdminID::Invalid(); - /** Simple calculated statistics of a company */ struct NetworkCompanyStats { uint16_t num_vehicle[NETWORK_VEH_END]; ///< How many vehicles are there of this type? diff --git a/src/newgrf.cpp b/src/newgrf.cpp index 74b3a22f75..e6f5ffe85b 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -644,7 +644,7 @@ static Engine *GetNewEngine(const GRFFile *file, VehicleType type, uint16_t inte /* Check if the engine is registered in the override manager */ EngineID engine = _engine_mngr.GetID(type, internal_id, scope_grfid); - if (engine != INVALID_ENGINE) { + if (engine != EngineID::Invalid()) { Engine *e = Engine::Get(engine); if (!e->grf_prop.HasGrfFile()) { e->grf_prop.grfid = file->grfid; @@ -656,7 +656,7 @@ static Engine *GetNewEngine(const GRFFile *file, VehicleType type, uint16_t inte /* Check if there is an unreserved slot */ EngineID engine = _engine_mngr.UseUnreservedID(type, internal_id, scope_grfid, static_access); - if (engine != INVALID_ENGINE) { + if (engine != EngineID::Invalid()) { Engine *e = Engine::Get(engine); if (!e->grf_prop.HasGrfFile()) { @@ -9244,7 +9244,7 @@ static void FinaliseEngineArray() } /* Do final mapping on variant engine ID. */ - if (e->info.variant_id != INVALID_ENGINE) { + if (e->info.variant_id != EngineID::Invalid()) { e->info.variant_id = GetNewEngineID(e->grf_prop.grffile, e->type, e->info.variant_id.base()); } @@ -9252,7 +9252,7 @@ static void FinaliseEngineArray() /* Skip wagons, there livery is defined via the engine */ if (e->type != VEH_TRAIN || e->u.rail.railveh_type != RAILVEH_WAGON) { - LiveryScheme ls = GetEngineLiveryScheme(e->index, INVALID_ENGINE, nullptr); + LiveryScheme ls = GetEngineLiveryScheme(e->index, EngineID::Invalid(), nullptr); SetBit(_loaded_newgrf_features.used_liveries, ls); /* Note: For ships and roadvehicles we assume that they cannot be refitted between passenger and freight */ @@ -9282,18 +9282,18 @@ static void FinaliseEngineArray() * on variant engine. This is performed separately as all variant engines need to have been resolved. */ for (Engine *e : Engine::Iterate()) { EngineID parent = e->info.variant_id; - while (parent != INVALID_ENGINE) { + while (parent != EngineID::Invalid()) { parent = Engine::Get(parent)->info.variant_id; if (parent != e->index) continue; /* Engine looped back on itself, so clear the variant. */ - e->info.variant_id = INVALID_ENGINE; + e->info.variant_id = EngineID::Invalid(); GrfMsg(1, "FinaliseEngineArray: Variant of engine {:x} in '{}' loops back on itself", e->grf_prop.local_id, e->GetGRF()->filename); break; } - if (e->info.variant_id != INVALID_ENGINE) { + if (e->info.variant_id != EngineID::Invalid()) { Engine::Get(e->info.variant_id)->display_flags.Set(EngineDisplayFlag::HasVariants).Set(EngineDisplayFlag::IsFolded); } } diff --git a/src/newgrf_debug_gui.cpp b/src/newgrf_debug_gui.cpp index 19ca491418..c18f64d1c7 100644 --- a/src/newgrf_debug_gui.cpp +++ b/src/newgrf_debug_gui.cpp @@ -437,7 +437,7 @@ struct NewGRFInspectWindow : Window { GrfSpecFeature f = GetFeatureNum(this->window_number); int h = GetVehicleImageCellSize((VehicleType)(VEH_TRAIN + (f - GSF_TRAINS)), EIT_IN_DEPOT).height; int y = CenterBounds(br.top, br.bottom, h); - DrawVehicleImage(v->First(), br, INVALID_VEHICLE, EIT_IN_DETAILS, skip); + DrawVehicleImage(v->First(), br, VehicleID::Invalid(), EIT_IN_DETAILS, skip); /* Highlight the articulated part (this is different to the whole-vehicle highlighting of DrawVehicleImage */ if (_current_text_dir == TD_RTL) { diff --git a/src/newgrf_engine.cpp b/src/newgrf_engine.cpp index fd01d19caa..401f05e622 100644 --- a/src/newgrf_engine.cpp +++ b/src/newgrf_engine.cpp @@ -376,11 +376,11 @@ static const Livery *LiveryHelper(EngineID engine, const Vehicle *v) if (v == nullptr) { if (!Company::IsValidID(_current_company)) return nullptr; - l = GetEngineLivery(engine, _current_company, INVALID_ENGINE, nullptr, LIT_ALL); + l = GetEngineLivery(engine, _current_company, EngineID::Invalid(), nullptr, LIT_ALL); } else if (v->IsGroundVehicle()) { l = GetEngineLivery(v->engine_type, v->owner, v->GetGroundVehicleCache()->first_engine, v, LIT_ALL); } else { - l = GetEngineLivery(v->engine_type, v->owner, INVALID_ENGINE, v, LIT_ALL); + l = GetEngineLivery(v->engine_type, v->owner, EngineID::Invalid(), v, LIT_ALL); } return l; @@ -839,7 +839,7 @@ static uint32_t VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *objec case 0x57: return GB(ClampTo(v->GetDisplayProfitLastYear()), 8, 24); case 0x58: return GB(ClampTo(v->GetDisplayProfitLastYear()), 16, 16); case 0x59: return GB(ClampTo(v->GetDisplayProfitLastYear()), 24, 8); - case 0x5A: return (v->Next() == nullptr ? INVALID_VEHICLE : v->Next()->index).base(); + case 0x5A: return (v->Next() == nullptr ? VehicleID::Invalid() : v->Next()->index).base(); case 0x5B: break; // not implemented case 0x5C: return ClampTo(v->value); case 0x5D: return GB(ClampTo(v->value), 8, 24); @@ -964,7 +964,7 @@ static uint32_t VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *objec 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.base(); // Next vehicle + case 0xDA: return VehicleID::Invalid().base(); // Next vehicle case 0xF2: return 0; // Cargo subtype } @@ -1345,7 +1345,7 @@ void CommitVehicleListOrderChanges() if (engine_source->grf_prop.local_id == loc.target) continue; EngineID target = _engine_mngr.GetID(engine_source->type, loc.target, engine_source->grf_prop.grfid); - if (target == INVALID_ENGINE) continue; + if (target == EngineID::Invalid()) continue; auto it_source = std::ranges::find(ordering, source); auto it_target = std::ranges::find(ordering, target); diff --git a/src/newgrf_industries.cpp b/src/newgrf_industries.cpp index ba65ff55da..cdf3a844c4 100644 --- a/src/newgrf_industries.cpp +++ b/src/newgrf_industries.cpp @@ -269,7 +269,7 @@ static uint32_t GetCountAndDistanceOfClosestInstance(uint8_t param_setID, uint8_ /* Land info of nearby tiles */ case 0x62: if (this->tile == INVALID_TILE) break; - return GetNearbyIndustryTileInformation(parameter, this->tile, INVALID_INDUSTRY, false, this->ro.grffile->grf_version >= 8); + return GetNearbyIndustryTileInformation(parameter, this->tile, IndustryID::Invalid(), false, this->ro.grffile->grf_version >= 8); /* Animation stage of nearby tiles */ case 0x63: { @@ -435,7 +435,7 @@ static uint32_t GetCountAndDistanceOfClosestInstance(uint8_t param_setID, uint8_ /* virtual */ void IndustriesScopeResolver::StorePSA(uint pos, int32_t value) { - if (this->industry->index == INVALID_INDUSTRY) return; + if (this->industry->index == IndustryID::Invalid()) return; if (this->industry->psa == nullptr) { /* There is no need to create a storage if the value is zero. */ @@ -490,7 +490,7 @@ TownScopeResolver *IndustriesResolverObject::GetTown() bool readonly = true; if (this->industries_scope.industry != nullptr) { t = this->industries_scope.industry->town; - readonly = this->industries_scope.industry->index == INVALID_INDUSTRY; + readonly = this->industries_scope.industry->index == IndustryID::Invalid(); } else if (this->industries_scope.tile != INVALID_TILE) { t = ClosestTownFromTile(this->industries_scope.tile, UINT_MAX); } @@ -542,7 +542,7 @@ CommandCost CheckIfCallBackAllowsCreation(TileIndex tile, IndustryType type, siz const IndustrySpec *indspec = GetIndustrySpec(type); Industry ind; - ind.index = INVALID_INDUSTRY; + ind.index = IndustryID::Invalid(); ind.location.tile = tile; ind.location.w = 0; // important to mark the industry invalid ind.type = type; diff --git a/src/newgrf_industrytiles.cpp b/src/newgrf_industrytiles.cpp index d57888ea05..c2d86fb63e 100644 --- a/src/newgrf_industrytiles.cpp +++ b/src/newgrf_industrytiles.cpp @@ -78,7 +78,7 @@ uint32_t GetRelativePosition(TileIndex tile, TileIndex ind_tile) /* Land info of nearby tiles */ case 0x60: return GetNearbyIndustryTileInformation(parameter, this->tile, - this->industry == nullptr ? (IndustryID)INVALID_INDUSTRY : this->industry->index, true, this->ro.grffile->grf_version >= 8); + this->industry == nullptr ? (IndustryID)IndustryID::Invalid() : this->industry->index, true, this->ro.grffile->grf_version >= 8); /* Animation stage of nearby tiles */ case 0x61: { @@ -102,16 +102,16 @@ uint32_t GetRelativePosition(TileIndex tile, TileIndex ind_tile) /* virtual */ uint32_t IndustryTileScopeResolver::GetRandomBits() const { assert(this->industry != nullptr && IsValidTile(this->tile)); - assert(this->industry->index == INVALID_INDUSTRY || IsTileType(this->tile, MP_INDUSTRY)); + assert(this->industry->index == IndustryID::Invalid() || IsTileType(this->tile, MP_INDUSTRY)); - return (this->industry->index != INVALID_INDUSTRY) ? GetIndustryRandomBits(this->tile) : 0; + return (this->industry->index != IndustryID::Invalid()) ? GetIndustryRandomBits(this->tile) : 0; } /* virtual */ uint32_t IndustryTileScopeResolver::GetTriggers() const { assert(this->industry != nullptr && IsValidTile(this->tile)); - assert(this->industry->index == INVALID_INDUSTRY || IsTileType(this->tile, MP_INDUSTRY)); - if (this->industry->index == INVALID_INDUSTRY) return 0; + assert(this->industry->index == IndustryID::Invalid() || IsTileType(this->tile, MP_INDUSTRY)); + if (this->industry->index == IndustryID::Invalid()) return 0; return GetIndustryTriggers(this->tile); } @@ -181,7 +181,7 @@ static void IndustryDrawTileLayout(const TileInfo *ti, const TileLayoutSpriteGro uint16_t GetIndustryTileCallback(CallbackID callback, uint32_t param1, uint32_t param2, IndustryGfx gfx_id, Industry *industry, TileIndex tile) { assert(industry != nullptr && IsValidTile(tile)); - assert(industry->index == INVALID_INDUSTRY || IsTileType(tile, MP_INDUSTRY)); + assert(industry->index == IndustryID::Invalid() || IsTileType(tile, MP_INDUSTRY)); IndustryTileResolverObject object(gfx_id, tile, industry, callback, param1, param2); return object.ResolveCallback(); @@ -230,7 +230,7 @@ extern bool IsSlopeRefused(Slope current, Slope refused); CommandCost PerformIndustryTileSlopeCheck(TileIndex ind_base_tile, TileIndex ind_tile, const IndustryTileSpec *its, IndustryType type, IndustryGfx gfx, size_t layout_index, uint16_t initial_random_bits, Owner founder, IndustryAvailabilityCallType creation_type) { Industry ind; - ind.index = INVALID_INDUSTRY; + ind.index = IndustryID::Invalid(); ind.location.tile = ind_base_tile; ind.location.w = 0; ind.type = type; diff --git a/src/newgrf_object.cpp b/src/newgrf_object.cpp index 5b42eda793..3604a62b31 100644 --- a/src/newgrf_object.cpp +++ b/src/newgrf_object.cpp @@ -346,7 +346,7 @@ static uint32_t GetCountAndDistanceOfClosestInstance(uint8_t local_id, uint32_t } /* Land info of nearby tiles */ - case 0x62: return GetNearbyObjectTileInformation(parameter, this->tile, this->obj == nullptr ? INVALID_OBJECT : this->obj->index, this->ro.grffile->grf_version >= 8); + case 0x62: return GetNearbyObjectTileInformation(parameter, this->tile, this->obj == nullptr ? ObjectID::Invalid() : this->obj->index, this->ro.grffile->grf_version >= 8); /* Animation counter of nearby tile */ case 0x63: { diff --git a/src/newgrf_station.cpp b/src/newgrf_station.cpp index 606b14f3f6..9ce7e6c2fc 100644 --- a/src/newgrf_station.cpp +++ b/src/newgrf_station.cpp @@ -457,7 +457,7 @@ uint32_t Station::GetNewGRFVariable(const ResolverObject &object, uint8_t variab case 1: return GB(g->HasData() ? std::min(g->GetData().cargo.TotalCount(), 4095u) : 0, 0, 4) | (GB(g->status, GoodsEntry::GES_ACCEPTANCE, 1) << 7); case 2: return g->time_since_pickup; case 3: return g->rating; - case 4: return (g->HasData() ? g->GetData().cargo.GetFirstStation() : INVALID_STATION).base(); + case 4: return (g->HasData() ? g->GetData().cargo.GetFirstStation() : StationID::Invalid()).base(); case 5: return g->HasData() ? g->GetData().cargo.PeriodsInTransit() : 0; case 6: return g->last_speed; case 7: return g->last_age; @@ -491,7 +491,7 @@ uint32_t Waypoint::GetNewGRFVariable(const ResolverObject &, uint8_t variable, [ if (variable >= 0x8C && variable <= 0xEC) { switch (GB(variable - 0x8C, 0, 3)) { case 3: return INITIAL_STATION_RATING; - case 4: return INVALID_STATION.base(); + case 4: return StationID::Invalid().base(); default: return 0; } } diff --git a/src/news_func.h b/src/news_func.h index a9503b035d..79ff3ecbee 100644 --- a/src/news_func.h +++ b/src/news_func.h @@ -27,9 +27,9 @@ inline void AddCompanyNewsItem(StringID string, std::unique_ptr; struct Object; struct ObjectSpec; -static constexpr ObjectID INVALID_OBJECT = ObjectID::Invalid(); ///< An invalid object - #endif /* OBJECT_TYPE_H */ diff --git a/src/openttd.cpp b/src/openttd.cpp index e23a62d37e..269c9c2d38 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -95,7 +95,7 @@ void CallWindowGameTickEvent(); bool HandleBootstrap(); extern void CheckCaches(); -extern Company *DoStartupNewCompany(bool is_ai, CompanyID company = INVALID_COMPANY); +extern Company *DoStartupNewCompany(bool is_ai, CompanyID company = CompanyID::Invalid()); extern void OSOpenBrowser(const std::string &url); extern void ShowOSErrorBox(const char *buf, bool system); extern std::string _config_file; @@ -327,7 +327,7 @@ static void LoadIntroGame(bool load_newgrfs = true) GenerateWorld(GWM_EMPTY, 64, 64); // if failed loading, make empty world. SetLocalCompany(COMPANY_SPECTATOR); } else { - SetLocalCompany(COMPANY_FIRST); + SetLocalCompany(CompanyID::Begin()); } FixTitleGameZoom(); @@ -341,7 +341,7 @@ static void LoadIntroGame(bool load_newgrfs = true) void MakeNewgameSettingsLive() { - for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; ++c) { + for (CompanyID c = CompanyID::Begin(); c < MAX_COMPANIES; ++c) { if (_settings_game.ai_config[c] != nullptr) { delete _settings_game.ai_config[c]; } @@ -355,7 +355,7 @@ void MakeNewgameSettingsLive() _settings_game = _settings_newgame; _old_vds = _settings_client.company.vehicle; - for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; ++c) { + for (CompanyID c = CompanyID::Begin(); c < MAX_COMPANIES; ++c) { _settings_game.ai_config[c] = nullptr; if (_settings_newgame.ai_config[c] != nullptr) { _settings_game.ai_config[c] = new AIConfig(_settings_newgame.ai_config[c]); @@ -865,7 +865,7 @@ static void MakeNewGameDone() /* Create a single company */ DoStartupNewCompany(false); - Company *c = Company::Get(COMPANY_FIRST); + Company *c = Company::Get(CompanyID::Begin()); c->settings = _settings_client.company; /* Overwrite color from settings if needed diff --git a/src/order_cmd.cpp b/src/order_cmd.cpp index 33876caa4a..4b8719ce43 100644 --- a/src/order_cmd.cpp +++ b/src/order_cmd.cpp @@ -381,7 +381,7 @@ const Order *OrderList::GetNextDecisionNode(const Order *next, uint hops) const * @param v The vehicle we're looking at. * @param first Order to start searching at or nullptr to start at cur_implicit_order_index + 1. * @param hops Number of orders we have already looked at. - * @return Next stopping station or INVALID_STATION. + * @return Next stopping station or StationID::Invalid(). * @pre The vehicle is currently loading and v->last_station_visited is meaningful. * @note This function may draw a random number. Don't use it from the GUI. */ @@ -393,7 +393,7 @@ StationIDStack OrderList::GetNextStoppingStation(const Vehicle *v, const Order * next = this->GetOrderAt(v->cur_implicit_order_index); if (next == nullptr) { next = this->GetFirstOrder(); - if (next == nullptr) return INVALID_STATION.base(); + if (next == nullptr) return StationID::Invalid().base(); } else { /* GetNext never returns nullptr if there is a valid station in the list. * As the given "next" is already valid and a station in the list, we @@ -430,7 +430,7 @@ StationIDStack OrderList::GetNextStoppingStation(const Vehicle *v, const Order * if (next == nullptr || ((next->IsType(OT_GOTO_STATION) || next->IsType(OT_IMPLICIT)) && next->GetDestination() == v->last_station_visited && (next->GetUnloadType() & (OUFB_TRANSFER | OUFB_UNLOAD)) != 0)) { - return INVALID_STATION.base(); + return StationID::Invalid().base(); } } while (next->IsType(OT_GOTO_DEPOT) || next->GetDestination() == v->last_station_visited); @@ -604,7 +604,7 @@ void OrderList::DebugCheckSanity() const static inline bool OrderGoesToStation(const Vehicle *v, const Order *o) { return o->IsType(OT_GOTO_STATION) || - (v->type == VEH_AIRCRAFT && o->IsType(OT_GOTO_DEPOT) && o->GetDestination() != INVALID_STATION); + (v->type == VEH_AIRCRAFT && o->IsType(OT_GOTO_DEPOT) && o->GetDestination() != StationID::Invalid()); } /** @@ -634,7 +634,7 @@ TileIndex Order::GetLocation(const Vehicle *v, bool airport) const return BaseStation::Get(this->GetDestination().ToStationID())->xy; case OT_GOTO_DEPOT: - if (this->GetDestination() == INVALID_DEPOT) return INVALID_TILE; + if (this->GetDestination() == DepotID::Invalid()) return INVALID_TILE; return (v->type == VEH_AIRCRAFT) ? Station::Get(this->GetDestination().ToStationID())->xy : Depot::Get(this->GetDestination().ToDepotID())->xy; default: diff --git a/src/order_gui.cpp b/src/order_gui.cpp index 7338cceade..727e5f44bd 100644 --- a/src/order_gui.cpp +++ b/src/order_gui.cpp @@ -666,7 +666,7 @@ private: Order order; order.next = nullptr; order.index = OrderID::Begin(); - order.MakeGoToDepot(INVALID_DEPOT, ODTFB_PART_OF_ORDERS, + order.MakeGoToDepot(DepotID::Invalid(), ODTFB_PART_OF_ORDERS, _settings_client.gui.new_nonstop && this->vehicle->IsGroundVehicle() ? ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS : ONSF_STOP_EVERYWHERE); order.SetDepotActionType(ODATFB_NEAREST_DEPOT); diff --git a/src/order_type.h b/src/order_type.h index aeb97acde9..aa3bbbfccd 100644 --- a/src/order_type.h +++ b/src/order_type.h @@ -41,9 +41,6 @@ static const VehicleOrderID INVALID_VEH_ORDER_ID = 0xFF; /** Last valid VehicleOrderID. */ static const VehicleOrderID MAX_VEH_ORDER_ID = INVALID_VEH_ORDER_ID - 1; -/** Invalid order (sentinel) */ -static constexpr OrderID INVALID_ORDER = OrderID::Invalid(); - /** * Maximum number of orders in implicit-only lists before we start searching * harder for duplicates. diff --git a/src/pathfinder/yapf/yapf_destrail.hpp b/src/pathfinder/yapf/yapf_destrail.hpp index 7262060dc7..754cb2b710 100644 --- a/src/pathfinder/yapf/yapf_destrail.hpp +++ b/src/pathfinder/yapf/yapf_destrail.hpp @@ -159,7 +159,7 @@ public: default: this->dest_tile = v->dest_tile; - this->dest_station_id = INVALID_STATION; + this->dest_station_id = StationID::Invalid(); this->dest_trackdirs = TrackStatusToTrackdirBits(GetTileTrackStatus(v->dest_tile, TRANSPORT_RAIL, 0)); break; } @@ -175,7 +175,7 @@ public: /** Called by YAPF to detect if node ends in the desired destination */ inline bool PfDetectDestination(TileIndex tile, Trackdir td) { - if (this->dest_station_id != INVALID_STATION) { + if (this->dest_station_id != StationID::Invalid()) { return HasStationTileRail(tile) && (GetStationIndex(tile) == this->dest_station_id) && (GetRailStationTrack(tile) == TrackdirToTrack(td)); diff --git a/src/pathfinder/yapf/yapf_road.cpp b/src/pathfinder/yapf/yapf_road.cpp index 448cc7adf4..b065274858 100644 --- a/src/pathfinder/yapf/yapf_road.cpp +++ b/src/pathfinder/yapf/yapf_road.cpp @@ -253,7 +253,7 @@ public: this->non_artic = !v->HasArticulatedPart(); this->dest_trackdirs = INVALID_TRACKDIR_BIT; } else { - this->dest_station = INVALID_STATION; + this->dest_station = StationID::Invalid(); this->dest_tile = v->dest_tile; this->dest_trackdirs = TrackStatusToTrackdirBits(GetTileTrackStatus(v->dest_tile, TRANSPORT_ROAD, GetRoadTramType(v->roadtype))); } @@ -261,7 +261,7 @@ public: const Station *GetDestinationStation() const { - return this->dest_station != INVALID_STATION ? Station::GetIfValid(this->dest_station) : nullptr; + return this->dest_station != StationID::Invalid() ? Station::GetIfValid(this->dest_station) : nullptr; } protected: @@ -280,7 +280,7 @@ public: inline bool PfDetectDestinationTile(TileIndex tile, Trackdir trackdir) { - if (this->dest_station != INVALID_STATION) { + if (this->dest_station != StationID::Invalid()) { return IsTileType(tile, MP_STATION) && GetStationIndex(tile) == this->dest_station && (this->station_type == GetStationType(tile)) && diff --git a/src/pathfinder/yapf/yapf_ship.cpp b/src/pathfinder/yapf/yapf_ship.cpp index c439c7abfb..f3a953097a 100644 --- a/src/pathfinder/yapf/yapf_ship.cpp +++ b/src/pathfinder/yapf/yapf_ship.cpp @@ -49,7 +49,7 @@ public: this->dest_tile = CalcClosestStationTile(this->dest_station, v->tile, StationType::Dock); this->dest_trackdirs = INVALID_TRACKDIR_BIT; } else { - this->dest_station = INVALID_STATION; + this->dest_station = StationID::Invalid(); this->dest_tile = v->dest_tile; this->dest_trackdirs = TrackStatusToTrackdirBits(GetTileTrackStatus(v->dest_tile, TRANSPORT_WATER, 0)); } @@ -84,7 +84,7 @@ public: return GetWaterRegionPatchInfo(tile) == this->intermediate_dest_region_patch; } - if (this->dest_station != INVALID_STATION) return IsDockingTile(tile) && IsShipDestinationTile(tile, this->dest_station); + if (this->dest_station != StationID::Invalid()) return IsDockingTile(tile) && IsShipDestinationTile(tile, this->dest_station); return tile == this->dest_tile && ((this->dest_trackdirs & TrackdirToTrackdirBits(trackdir)) != TRACKDIR_BIT_NONE); } diff --git a/src/rail_gui.cpp b/src/rail_gui.cpp index 5bcb60ae5c..0b45e65d3e 100644 --- a/src/rail_gui.cpp +++ b/src/rail_gui.cpp @@ -177,7 +177,7 @@ static void PlaceRail_Waypoint(TileIndex tile) } else { /* Tile where we can't build rail waypoints. This is always going to fail, * but provides the user with a proper error message. */ - Command::Post(STR_ERROR_CAN_T_BUILD_TRAIN_WAYPOINT, tile, AXIS_X, 1, 1, STAT_CLASS_WAYP, 0, INVALID_STATION, false); + Command::Post(STR_ERROR_CAN_T_BUILD_TRAIN_WAYPOINT, tile, AXIS_X, 1, 1, STAT_CLASS_WAYP, 0, StationID::Invalid(), false); } } @@ -215,7 +215,7 @@ static void PlaceRail_Station(TileIndex tile) auto proc = [=](bool test, StationID to_join) -> bool { if (test) { - return Command::Do(CommandFlagsToDCFlags(GetCommandFlags()), tile, rt, params.axis, numtracks, platlength, params.sel_class, params.sel_type, INVALID_STATION, adjacent).Succeeded(); + return Command::Do(CommandFlagsToDCFlags(GetCommandFlags()), tile, rt, params.axis, numtracks, platlength, params.sel_class, params.sel_type, StationID::Invalid(), adjacent).Succeeded(); } else { return Command::Post(STR_ERROR_CAN_T_BUILD_RAILROAD_STATION, CcStation, tile, rt, params.axis, numtracks, platlength, params.sel_class, params.sel_type, to_join, adjacent); } @@ -776,7 +776,7 @@ struct BuildRailToolbarWindow : Window { auto proc = [=](bool test, StationID to_join) -> bool { if (test) { - return Command::Do(CommandFlagsToDCFlags(GetCommandFlags()), ta.tile, axis, ta.w, ta.h, _waypoint_gui.sel_class, _waypoint_gui.sel_type, INVALID_STATION, adjacent).Succeeded(); + return Command::Do(CommandFlagsToDCFlags(GetCommandFlags()), ta.tile, axis, ta.w, ta.h, _waypoint_gui.sel_class, _waypoint_gui.sel_type, StationID::Invalid(), adjacent).Succeeded(); } else { return Command::Post(STR_ERROR_CAN_T_BUILD_TRAIN_WAYPOINT, CcPlaySound_CONSTRUCTION_RAIL, ta.tile, axis, ta.w, ta.h, _waypoint_gui.sel_class, _waypoint_gui.sel_type, to_join, adjacent); } @@ -943,7 +943,7 @@ static void HandleStationPlacement(TileIndex start, TileIndex end) auto proc = [=](bool test, StationID to_join) -> bool { if (test) { - return Command::Do(CommandFlagsToDCFlags(GetCommandFlags()), ta.tile, rt, params.axis, numtracks, platlength, params.sel_class, params.sel_type, INVALID_STATION, adjacent).Succeeded(); + return Command::Do(CommandFlagsToDCFlags(GetCommandFlags()), ta.tile, rt, params.axis, numtracks, platlength, params.sel_class, params.sel_type, StationID::Invalid(), adjacent).Succeeded(); } else { return Command::Post(STR_ERROR_CAN_T_BUILD_RAILROAD_STATION, CcStation, ta.tile, rt, params.axis, numtracks, platlength, params.sel_class, params.sel_type, to_join, adjacent); } diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp index 9db92e4a27..f35d751f72 100644 --- a/src/road_cmd.cpp +++ b/src/road_cmd.cpp @@ -465,7 +465,7 @@ static CommandCost RemoveRoad(TileIndex tile, DoCommandFlags flags, RoadBits pie if (rtt == RTT_ROAD && IsRoadOwner(tile, rtt, OWNER_TOWN)) { /* Update nearest-town index */ const Town *town = CalcClosestTownFromTile(tile); - SetTownIndex(tile, town == nullptr ? INVALID_TOWN : town->index); + SetTownIndex(tile, town == nullptr ? TownID::Invalid() : town->index); } if (rtt == RTT_ROAD) SetDisallowedRoadDirections(tile, DRD_NONE); SetRoadBits(tile, ROAD_NONE, rtt); @@ -603,7 +603,7 @@ static CommandCost CheckRoadSlope(Slope tileh, RoadBits *pieces, RoadBits existi * @param pieces road pieces to build (RoadBits) * @param rt road type * @param toggle_drd disallowed directions to toggle - * @param town_id the town that is building the road (INVALID_TOWN if not applicable) + * @param town_id the town that is building the road (TownID::Invalid() if not applicable) * @return the cost of this operation or an error */ CommandCost CmdBuildRoad(DoCommandFlags flags, TileIndex tile, RoadBits pieces, RoadType rt, DisallowedRoadDirections toggle_drd, TownID town_id) @@ -616,10 +616,10 @@ CommandCost CmdBuildRoad(DoCommandFlags flags, TileIndex tile, RoadBits pieces, /* Road pieces are max 4 bitset values (NE, NW, SE, SW) and town can only be non-zero * if a non-company is building the road */ - if ((Company::IsValidID(company) && town_id != INVALID_TOWN) || (company == OWNER_TOWN && !Town::IsValidID(town_id)) || (company == OWNER_DEITY && town_id != INVALID_TOWN)) return CMD_ERROR; + if ((Company::IsValidID(company) && town_id != TownID::Invalid()) || (company == OWNER_TOWN && !Town::IsValidID(town_id)) || (company == OWNER_DEITY && town_id != TownID::Invalid())) return CMD_ERROR; if (company != OWNER_TOWN) { const Town *town = CalcClosestTownFromTile(tile); - town_id = (town != nullptr) ? town->index : INVALID_TOWN; + town_id = (town != nullptr) ? town->index : TownID::Invalid(); if (company == OWNER_DEITY) { company = OWNER_TOWN; @@ -1025,7 +1025,7 @@ CommandCost CmdBuildLongRoad(DoCommandFlags flags, TileIndex end_tile, TileIndex if (tile == start_tile && start_half) bits &= DiagDirToRoadBits(dir); } - CommandCost ret = Command::Do(flags, tile, bits, rt, drd, INVALID_TOWN); + CommandCost ret = Command::Do(flags, tile, bits, rt, drd, TownID::Invalid()); if (ret.Failed()) { last_error = ret; if (last_error.GetErrorMessage() != STR_ERROR_ALREADY_BUILT) { @@ -1920,7 +1920,7 @@ void UpdateNearestTownForRoadTiles(bool invalidate) for (const auto t : Map::Iterate()) { if (IsTileType(t, MP_ROAD) && !IsRoadDepot(t) && !HasTownOwnedRoad(t)) { - TownID tid = INVALID_TOWN; + TownID tid = TownID::Invalid(); if (!invalidate) { const Town *town = CalcClosestTownFromTile(t); if (town != nullptr) tid = town->index; diff --git a/src/road_gui.cpp b/src/road_gui.cpp index b760564718..9410035b52 100644 --- a/src/road_gui.cpp +++ b/src/road_gui.cpp @@ -165,7 +165,7 @@ void ConnectRoadToStructure(TileIndex tile, DiagDirection direction) /* if there is a roadpiece just outside of the station entrance, build a connecting route */ if (IsNormalRoadTile(tile)) { if (GetRoadBits(tile, GetRoadTramType(_cur_roadtype)) != ROAD_NONE) { - Command::Post(tile, DiagDirToRoadBits(ReverseDiagDir(direction)), _cur_roadtype, DRD_NONE, INVALID_TOWN); + Command::Post(tile, DiagDirToRoadBits(ReverseDiagDir(direction)), _cur_roadtype, DRD_NONE, TownID::Invalid()); } } } @@ -237,7 +237,7 @@ static void PlaceRoadStop(TileIndex start_tile, TileIndex end_tile, RoadStopType auto proc = [=](bool test, StationID to_join) -> bool { if (test) { return Command::Do(CommandFlagsToDCFlags(GetCommandFlags()), ta.tile, ta.w, ta.h, stop_type, drive_through, - ddir, rt, spec_class, spec_index, INVALID_STATION, adjacent).Succeeded(); + ddir, rt, spec_class, spec_index, StationID::Invalid(), adjacent).Succeeded(); } else { return Command::Post(err_msg, CcRoadStop, ta.tile, ta.w, ta.h, stop_type, drive_through, ddir, rt, spec_class, spec_index, to_join, adjacent); @@ -266,7 +266,7 @@ static void PlaceRoad_Waypoint(TileIndex tile) } else { /* Tile where we can't build road waypoints. This is always going to fail, * but provides the user with a proper error message. */ - Command::Post(STR_ERROR_CAN_T_BUILD_ROAD_WAYPOINT, tile, AXIS_X, 1, 1, ROADSTOP_CLASS_WAYP, 0, INVALID_STATION, false); + Command::Post(STR_ERROR_CAN_T_BUILD_ROAD_WAYPOINT, tile, AXIS_X, 1, 1, ROADSTOP_CLASS_WAYP, 0, StationID::Invalid(), false); } } @@ -766,7 +766,7 @@ struct BuildRoadToolbarWindow : Window { auto proc = [=](bool test, StationID to_join) -> bool { if (test) { - return Command::Do(CommandFlagsToDCFlags(GetCommandFlags()), ta.tile, axis, ta.w, ta.h, _waypoint_gui.sel_class, _waypoint_gui.sel_type, INVALID_STATION, adjacent).Succeeded(); + return Command::Do(CommandFlagsToDCFlags(GetCommandFlags()), ta.tile, axis, ta.w, ta.h, _waypoint_gui.sel_class, _waypoint_gui.sel_type, StationID::Invalid(), adjacent).Succeeded(); } else { return Command::Post(STR_ERROR_CAN_T_BUILD_ROAD_WAYPOINT, CcPlaySound_CONSTRUCTION_OTHER, ta.tile, axis, ta.w, ta.h, _waypoint_gui.sel_class, _waypoint_gui.sel_type, to_join, adjacent); } diff --git a/src/roadveh.h b/src/roadveh.h index 253606fb4c..9a959ed840 100644 --- a/src/roadveh.h +++ b/src/roadveh.h @@ -106,7 +106,7 @@ struct RoadVehicle final : public GroundVehicle { uint8_t reverse_ctr; RoadType roadtype; ///< NOSAVE: Roadtype of this vehicle. - VehicleID disaster_vehicle = INVALID_VEHICLE; ///< NOSAVE: Disaster vehicle targetting this vehicle. + VehicleID disaster_vehicle = VehicleID::Invalid(); ///< NOSAVE: Disaster vehicle targetting this vehicle. RoadTypes compatible_roadtypes; ///< NOSAVE: Roadtypes this consist is powered on. /** We don't want GCC to zero our struct! It already is zeroed and has an index! */ diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp index aa82ac7d48..48948d74e5 100644 --- a/src/roadveh_cmd.cpp +++ b/src/roadveh_cmd.cpp @@ -229,7 +229,7 @@ void RoadVehUpdateCache(RoadVehicle *v, bool same_length) assert(u->First() == v); /* Update the 'first engine' */ - u->gcache.first_engine = (v == u) ? INVALID_ENGINE : v->engine_type; + u->gcache.first_engine = (v == u) ? EngineID::Invalid() : v->engine_type; /* Update the length of the vehicle. */ uint veh_len = GetRoadVehLength(u); @@ -289,10 +289,10 @@ CommandCost CmdBuildRoadVehicle(DoCommandFlags flags, TileIndex tile, const Engi v->cargo_cap = rvi->capacity; v->refit_cap = 0; - v->last_station_visited = INVALID_STATION; - v->last_loading_station = INVALID_STATION; + v->last_station_visited = StationID::Invalid(); + v->last_loading_station = StationID::Invalid(); v->engine_type = e->index; - v->gcache.first_engine = INVALID_ENGINE; // needs to be set before first callback + v->gcache.first_engine = EngineID::Invalid(); // needs to be set before first callback v->reliability = e->reliability; v->reliability_spd_dec = e->reliability_spd_dec; @@ -582,7 +582,7 @@ static bool RoadVehCheckTrainCrash(RoadVehicle *v) TileIndex RoadVehicle::GetOrderStationLocation(StationID station) { - if (station == this->last_station_visited) this->last_station_visited = INVALID_STATION; + if (station == this->last_station_visited) this->last_station_visited = StationID::Invalid(); const Station *st = Station::Get(station); if (!CanVehicleUseStation(this, st)) { @@ -1126,7 +1126,7 @@ static bool CanBuildTramTrackOnTile(CompanyID c, TileIndex t, RoadType rt, RoadB /* The 'current' company is not necessarily the owner of the vehicle. */ Backup cur_company(_current_company, c); - CommandCost ret = Command::Do(DoCommandFlag::NoWater, t, r, rt, DRD_NONE, INVALID_TOWN); + CommandCost ret = Command::Do(DoCommandFlag::NoWater, t, r, rt, DRD_NONE, TownID::Invalid()); cur_company.Restore(); return ret.Succeeded(); diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp index 404bc94566..85d8734c83 100644 --- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -73,7 +73,7 @@ #include "../safeguards.h" -extern Company *DoStartupNewCompany(bool is_ai, CompanyID company = INVALID_COMPANY); +extern Company *DoStartupNewCompany(bool is_ai, CompanyID company = CompanyID::Invalid()); /** * Makes a tile canal or water depending on the surroundings. @@ -179,7 +179,7 @@ static void ConvertTownOwner() static void UpdateExclusiveRights() { for (Town *t : Town::Iterate()) { - t->exclusivity = INVALID_COMPANY; + t->exclusivity = CompanyID::Invalid(); } /* FIXME old exclusive rights status is not being imported (stored in s->blocked_months_obsolete) @@ -2285,7 +2285,7 @@ bool AfterLoadGame() if (s->remaining < 12) { /* Converting nonawarded subsidy */ s->remaining = 12 - s->remaining; // convert "age" to "remaining" - s->awarded = INVALID_COMPANY; // not awarded to anyone + s->awarded = CompanyID::Invalid(); // not awarded to anyone const CargoSpec *cs = CargoSpec::Get(s->cargo_type); switch (cs->town_acceptance_effect) { case TAE_PASSENGERS: @@ -3416,7 +3416,7 @@ void ReloadNewGRFData() /* Delete news referring to no longer existing entities */ DeleteInvalidEngineNews(); /* Update livery selection windows */ - for (CompanyID i = COMPANY_FIRST; i < MAX_COMPANIES; ++i) InvalidateWindowData(WC_COMPANY_COLOUR, i); + for (CompanyID i = CompanyID::Begin(); i < MAX_COMPANIES; ++i) InvalidateWindowData(WC_COMPANY_COLOUR, i); /* Update company infrastructure counts. */ InvalidateWindowClassesData(WC_COMPANY_INFRASTRUCTURE); InvalidateWindowClassesData(WC_BUILD_TOOLBAR); diff --git a/src/saveload/ai_sl.cpp b/src/saveload/ai_sl.cpp index 6e8887ed66..29f759361c 100644 --- a/src/saveload/ai_sl.cpp +++ b/src/saveload/ai_sl.cpp @@ -80,7 +80,7 @@ struct AIPLChunkHandler : ChunkHandler { const std::vector slt = SlCompatTableHeader(_ai_company_desc, _ai_company_sl_compat); /* Free all current data */ - for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; ++c) { + for (CompanyID c = CompanyID::Begin(); c < MAX_COMPANIES; ++c) { AIConfig::GetConfig(c, AIConfig::SSS_FORCE_GAME)->Change(std::nullopt); } @@ -160,7 +160,7 @@ struct AIPLChunkHandler : ChunkHandler { { SlTableHeader(_ai_company_desc); - for (CompanyID i = COMPANY_FIRST; i < MAX_COMPANIES; ++i) { + for (CompanyID i = CompanyID::Begin(); i < MAX_COMPANIES; ++i) { SlSetArrayIndex(i); SlAutolength(SaveReal_AIPL, i.base()); } diff --git a/src/saveload/cargopacket_sl.cpp b/src/saveload/cargopacket_sl.cpp index 22cdd58c95..b841ac7b48 100644 --- a/src/saveload/cargopacket_sl.cpp +++ b/src/saveload/cargopacket_sl.cpp @@ -55,9 +55,9 @@ } if (IsSavegameVersionBefore(SLV_120)) { - /* CargoPacket's source should be either INVALID_STATION or a valid station */ + /* CargoPacket's source should be either StationID::Invalid() or a valid station */ for (CargoPacket *cp : CargoPacket::Iterate()) { - if (!Station::IsValidID(cp->first_station)) cp->first_station = INVALID_STATION; + if (!Station::IsValidID(cp->first_station)) cp->first_station = StationID::Invalid(); } } diff --git a/src/saveload/engine_sl.cpp b/src/saveload/engine_sl.cpp index d41fcdf43b..695f5ada57 100644 --- a/src/saveload/engine_sl.cpp +++ b/src/saveload/engine_sl.cpp @@ -83,7 +83,7 @@ struct ENGNChunkHandler : ChunkHandler { /* preview_company_rank was replaced with preview_company and preview_asked. * Just cancel any previews. */ e->flags.Reset(EngineFlag{4}); // ENGINE_OFFER_WINDOW_OPEN - e->preview_company = INVALID_COMPANY; + e->preview_company = CompanyID::Invalid(); e->preview_asked.Set(); } } diff --git a/src/saveload/group_sl.cpp b/src/saveload/group_sl.cpp index 82ef465e08..788d0c6139 100644 --- a/src/saveload/group_sl.cpp +++ b/src/saveload/group_sl.cpp @@ -53,7 +53,7 @@ struct GRPSChunkHandler : ChunkHandler { Group *g = new (index) Group(); SlObject(g, slt); - if (IsSavegameVersionBefore(SLV_189)) g->parent = INVALID_GROUP; + if (IsSavegameVersionBefore(SLV_189)) g->parent = GroupID::Invalid(); } } }; diff --git a/src/saveload/oldloader_sl.cpp b/src/saveload/oldloader_sl.cpp index c8fc594470..e266a1e06a 100644 --- a/src/saveload/oldloader_sl.cpp +++ b/src/saveload/oldloader_sl.cpp @@ -437,7 +437,7 @@ static bool FixTTOEngines() e->info.climates = LandscapeType::Temperate; } - e->preview_company = INVALID_COMPANY; + e->preview_company = CompanyID::Invalid(); e->preview_asked.Set(); e->preview_wait = 0; e->name = std::string{}; @@ -724,8 +724,8 @@ static bool LoadOldGood(LoadgameState &ls, int num) AssignBit(ge->status, GoodsEntry::GES_ACCEPTANCE, HasBit(_waiting_acceptance, 15)); AssignBit(ge->status, GoodsEntry::GES_RATING, _cargo_source != 0xFF); if (GB(_waiting_acceptance, 0, 12) != 0 && CargoPacket::CanAllocateItem()) { - ge->GetOrCreateData().cargo.Append(new CargoPacket(GB(_waiting_acceptance, 0, 12), _cargo_periods, (_cargo_source == 0xFF) ? INVALID_STATION : StationID{_cargo_source}, INVALID_TILE, 0), - INVALID_STATION); + ge->GetOrCreateData().cargo.Append(new CargoPacket(GB(_waiting_acceptance, 0, 12), _cargo_periods, (_cargo_source == 0xFF) ? StationID::Invalid() : StationID{_cargo_source}, INVALID_TILE, 0), + StationID::Invalid()); } return true; @@ -1372,8 +1372,8 @@ bool LoadOldVehicle(LoadgameState &ls, int num) v->next = (Vehicle *)(size_t)_old_next_ptr; if (_cargo_count != 0 && CargoPacket::CanAllocateItem()) { - StationID source = (_cargo_source == 0xFF) ? INVALID_STATION : StationID{_cargo_source}; - TileIndex source_xy = (source != INVALID_STATION) ? Station::Get(source)->xy : (TileIndex)0; + StationID source = (_cargo_source == 0xFF) ? StationID::Invalid() : StationID{_cargo_source}; + TileIndex source_xy = (source != StationID::Invalid()) ? Station::Get(source)->xy : (TileIndex)0; v->cargo.Append(new CargoPacket(_cargo_count, _cargo_periods, source, source_xy, 0)); } } diff --git a/src/saveload/station_sl.cpp b/src/saveload/station_sl.cpp index db93528ea0..7f6b43ffb6 100644 --- a/src/saveload/station_sl.cpp +++ b/src/saveload/station_sl.cpp @@ -193,15 +193,15 @@ static void SwapPackets(GoodsEntry *ge) StationCargoPacketMap &ge_packets = const_cast(*ge->GetOrCreateData().cargo.Packets()); if (_packets.empty()) { - std::map >::iterator it(ge_packets.find(INVALID_STATION)); + std::map >::iterator it(ge_packets.find(StationID::Invalid())); if (it == ge_packets.end()) { return; } else { it->second.swap(_packets); } } else { - assert(ge_packets[INVALID_STATION].empty()); - ge_packets[INVALID_STATION].swap(_packets); + assert(ge_packets[StationID::Invalid()].empty()); + ge_packets[StationID::Invalid()].swap(_packets); } } @@ -322,7 +322,7 @@ public: GoodsEntry::GoodsEntryData &data = ge->GetOrCreateData(); FlowSaveLoad flow{}; FlowStat *fs = nullptr; - StationID prev_source = INVALID_STATION; + StationID prev_source = StationID::Invalid(); for (uint32_t j = 0; j < num_flows; ++j) { SlObject(&flow, this->GetLoadDescription()); if (fs == nullptr || prev_source != flow.source) { @@ -416,8 +416,8 @@ public: if (IsSavegameVersionBefore(SLV_68)) { AssignBit(ge.status, GoodsEntry::GES_ACCEPTANCE, HasBit(_waiting_acceptance, 15)); if (GB(_waiting_acceptance, 0, 12) != 0) { - /* In old versions, enroute_from used 0xFF as INVALID_STATION */ - StationID source = (IsSavegameVersionBefore(SLV_7) && _cargo_source == 0xFF) ? INVALID_STATION : static_cast(_cargo_source); + /* In old versions, enroute_from used 0xFF as StationID::Invalid() */ + StationID source = (IsSavegameVersionBefore(SLV_7) && _cargo_source == 0xFF) ? StationID::Invalid() : static_cast(_cargo_source); /* Make sure we can allocate the CargoPacket. This is safe * as there can only be ~64k stations and 32 cargoes in these @@ -427,7 +427,7 @@ public: /* Don't construct the packet with station here, because that'll fail with old savegames */ CargoPacket *cp = new CargoPacket(GB(_waiting_acceptance, 0, 12), _cargo_periods, source, TileIndex{_cargo_source_xy}, _cargo_feeder_share); - ge.GetOrCreateData().cargo.Append(cp, INVALID_STATION); + ge.GetOrCreateData().cargo.Append(cp, StationID::Invalid()); SetBit(ge.status, GoodsEntry::GES_RATING); } } diff --git a/src/saveload/vehicle_sl.cpp b/src/saveload/vehicle_sl.cpp index bf9be46fd1..144dd621b6 100644 --- a/src/saveload/vehicle_sl.cpp +++ b/src/saveload/vehicle_sl.cpp @@ -225,7 +225,7 @@ void UpdateOldAircraft() static void CheckValidVehicles() { size_t total_engines = Engine::GetPoolSize(); - EngineID first_engine[4] = { INVALID_ENGINE, INVALID_ENGINE, INVALID_ENGINE, INVALID_ENGINE }; + EngineID first_engine[4] = { EngineID::Invalid(), EngineID::Invalid(), EngineID::Invalid(), EngineID::Invalid() }; for (const Engine *e : Engine::IterateType(VEH_TRAIN)) { first_engine[VEH_TRAIN] = e->index; break; } for (const Engine *e : Engine::IterateType(VEH_ROAD)) { first_engine[VEH_ROAD] = e->index; break; } @@ -262,7 +262,7 @@ void AfterLoadVehiclesPhase1(bool part_of_load) if (part_of_load) v->fill_percent_te_id = INVALID_TE_ID; v->first = nullptr; - if (v->IsGroundVehicle()) v->GetGroundVehicleCache()->first_engine = INVALID_ENGINE; + if (v->IsGroundVehicle()) v->GetGroundVehicleCache()->first_engine = EngineID::Invalid(); } /* AfterLoadVehicles may also be called in case of NewGRF reload, in this @@ -515,7 +515,7 @@ void AfterLoadVehiclesPhase2(bool part_of_load) RoadVehicle *u = RoadVehicle::GetIfValid(v->dest_tile.base()); if (u != nullptr && u->IsFrontEngine()) { /* Delete UFO targetting a vehicle which is already a target. */ - if (u->disaster_vehicle != INVALID_VEHICLE && u->disaster_vehicle != dv->index) { + if (u->disaster_vehicle != VehicleID::Invalid() && u->disaster_vehicle != dv->index) { delete v; continue; } else { @@ -1144,10 +1144,10 @@ struct VEHSChunkHandler : ChunkHandler { /* Old savegames used 'last_station_visited = 0xFF' */ if (IsSavegameVersionBefore(SLV_5) && v->last_station_visited == 0xFF) { - v->last_station_visited = INVALID_STATION; + v->last_station_visited = StationID::Invalid(); } - if (IsSavegameVersionBefore(SLV_182)) v->last_loading_station = INVALID_STATION; + if (IsSavegameVersionBefore(SLV_182)) v->last_loading_station = StationID::Invalid(); if (IsSavegameVersionBefore(SLV_5)) { /* Convert the current_order.type (which is a mix of type and flags, because diff --git a/src/script/api/script_airport.cpp b/src/script/api/script_airport.cpp index 683e9af291..054c3f4add 100644 --- a/src/script/api/script_airport.cpp +++ b/src/script/api/script_airport.cpp @@ -77,7 +77,7 @@ EnforcePrecondition(false, IsValidAirportType(type)); EnforcePrecondition(false, station_id == ScriptStation::STATION_NEW || station_id == ScriptStation::STATION_JOIN_ADJACENT || ScriptStation::IsValidStation(station_id)); - return ScriptObject::Command::Do(tile, type, 0, (ScriptStation::IsValidStation(station_id) ? station_id : INVALID_STATION), station_id != ScriptStation::STATION_JOIN_ADJACENT); + return ScriptObject::Command::Do(tile, type, 0, (ScriptStation::IsValidStation(station_id) ? station_id : StationID::Invalid()), station_id != ScriptStation::STATION_JOIN_ADJACENT); } /* static */ bool ScriptAirport::RemoveAirport(TileIndex tile) @@ -148,11 +148,11 @@ /* static */ TownID ScriptAirport::GetNearestTown(TileIndex tile, AirportType type) { - if (!::IsValidTile(tile)) return INVALID_TOWN; - if (!IsAirportInformationAvailable(type)) return INVALID_TOWN; + if (!::IsValidTile(tile)) return TownID::Invalid(); + if (!IsAirportInformationAvailable(type)) return TownID::Invalid(); const AirportSpec *as = AirportSpec::Get(type); - if (!as->IsWithinMapBounds(0, tile)) return INVALID_TOWN; + if (!as->IsWithinMapBounds(0, tile)) return TownID::Invalid(); uint dist; const auto &layout = as->layouts[0]; diff --git a/src/script/api/script_basestation.hpp b/src/script/api/script_basestation.hpp index 9edd43ba9a..c46326cdfb 100644 --- a/src/script/api/script_basestation.hpp +++ b/src/script/api/script_basestation.hpp @@ -22,7 +22,7 @@ class ScriptBaseStation : public ScriptObject { public: static constexpr StationID STATION_NEW = ::NEW_STATION; ///< Build a new station static constexpr StationID STATION_JOIN_ADJACENT = ::ADJACENT_STATION; ///< Join an neighbouring station if one exists - static constexpr StationID STATION_INVALID = ::INVALID_STATION; ///< Invalid station id. + static constexpr StationID STATION_INVALID = ::StationID::Invalid(); ///< Invalid station id. /** * Checks whether the given basestation is valid and owned by you. diff --git a/src/script/api/script_bridge.cpp b/src/script/api/script_bridge.cpp index 34661d151f..c6a4a8b57d 100644 --- a/src/script/api/script_bridge.cpp +++ b/src/script/api/script_bridge.cpp @@ -105,7 +105,7 @@ static void _DoCommandReturnBuildBridge1(class ScriptInstance *instance) DiagDirection dir_1 = ::DiagdirBetweenTiles(end, start); DiagDirection dir_2 = ::ReverseDiagDir(dir_1); - return ScriptObject::Command::Do(&::_DoCommandReturnBuildBridge2, start + ::TileOffsByDiagDir(dir_1), ::DiagDirToRoadBits(dir_2), (::RoadType)ScriptRoad::GetCurrentRoadType(), DRD_NONE, INVALID_TOWN); + return ScriptObject::Command::Do(&::_DoCommandReturnBuildBridge2, start + ::TileOffsByDiagDir(dir_1), ::DiagDirToRoadBits(dir_2), (::RoadType)ScriptRoad::GetCurrentRoadType(), DRD_NONE, TownID::Invalid()); } /* static */ bool ScriptBridge::_BuildBridgeRoad2() @@ -119,7 +119,7 @@ static void _DoCommandReturnBuildBridge1(class ScriptInstance *instance) DiagDirection dir_1 = ::DiagdirBetweenTiles(end, start); DiagDirection dir_2 = ::ReverseDiagDir(dir_1); - return ScriptObject::Command::Do(end + ::TileOffsByDiagDir(dir_2), ::DiagDirToRoadBits(dir_1), (::RoadType)ScriptRoad::GetCurrentRoadType(), DRD_NONE, INVALID_TOWN); + return ScriptObject::Command::Do(end + ::TileOffsByDiagDir(dir_2), ::DiagDirToRoadBits(dir_1), (::RoadType)ScriptRoad::GetCurrentRoadType(), DRD_NONE, TownID::Invalid()); } /* static */ bool ScriptBridge::RemoveBridge(TileIndex tile) diff --git a/src/script/api/script_company.cpp b/src/script/api/script_company.cpp index 7ba6bab47b..c33d4cbf36 100644 --- a/src/script/api/script_company.cpp +++ b/src/script/api/script_company.cpp @@ -33,13 +33,13 @@ /* If this assert gets triggered, then ScriptCompany::ResolveCompanyID needed to be called before. */ assert(company != ScriptCompany::COMPANY_SELF && company != ScriptCompany::COMPANY_SPECTATOR); - if (company == ScriptCompany::COMPANY_INVALID) return ::INVALID_COMPANY; + if (company == ScriptCompany::COMPANY_INVALID) return ::CompanyID::Invalid(); return static_cast<::CompanyID>(company); } /* static */ ScriptCompany::CompanyID ScriptCompany::ToScriptCompanyID(::CompanyID company) { - if (company == ::INVALID_COMPANY) return ScriptCompany::COMPANY_INVALID; + if (company == ::CompanyID::Invalid()) return ScriptCompany::COMPANY_INVALID; return static_cast<::ScriptCompany::CompanyID>(company.base()); } diff --git a/src/script/api/script_company.hpp b/src/script/api/script_company.hpp index 58e2f5242a..ba9f72bacd 100644 --- a/src/script/api/script_company.hpp +++ b/src/script/api/script_company.hpp @@ -30,8 +30,8 @@ public: /** Different constants related to CompanyID. */ enum CompanyID { /* Note: these values represent part of the in-game Owner enum */ - COMPANY_FIRST = ::COMPANY_FIRST.base(), ///< The first available company. - COMPANY_LAST = ::MAX_COMPANIES, ///< The last available company. + COMPANY_FIRST = ::CompanyID::Begin().base(), ///< The first available company. + COMPANY_LAST = ::CompanyID::End().base(), ///< The last available company. /* Custom added value, only valid for this API */ COMPANY_INVALID = -1, ///< An invalid company. diff --git a/src/script/api/script_goal.cpp b/src/script/api/script_goal.cpp index 3775f5bace..b36ad62272 100644 --- a/src/script/api/script_goal.cpp +++ b/src/script/api/script_goal.cpp @@ -38,7 +38,7 @@ (type == GT_INDUSTRY && ScriptIndustry::IsValidIndustry(static_cast(destination))) || (type == GT_TOWN && ScriptTown::IsValidTown(static_cast(destination))) || (type == GT_COMPANY && ScriptCompany::ResolveCompanyID(ScriptCompany::ToScriptCompanyID(static_cast<::CompanyID>(destination))) != ScriptCompany::COMPANY_INVALID) || - (type == GT_STORY_PAGE && story_page != nullptr && (c == INVALID_COMPANY ? story_page->company == INVALID_COMPANY : story_page->company == INVALID_COMPANY || story_page->company == c)); + (type == GT_STORY_PAGE && story_page != nullptr && (c == CompanyID::Invalid() ? story_page->company == CompanyID::Invalid() : story_page->company == CompanyID::Invalid() || story_page->company == c)); } /* static */ GoalID ScriptGoal::New(ScriptCompany::CompanyID company, Text *goal, GoalType type, SQInteger destination) diff --git a/src/script/api/script_goal.hpp b/src/script/api/script_goal.hpp index f0229ecd32..7a4ff7e991 100644 --- a/src/script/api/script_goal.hpp +++ b/src/script/api/script_goal.hpp @@ -25,7 +25,7 @@ */ class ScriptGoal : public ScriptObject { public: - static constexpr GoalID GOAL_INVALID = ::INVALID_GOAL; ///< An invalid goal id. + static constexpr GoalID GOAL_INVALID = ::GoalID::Invalid(); ///< An invalid goal id. /** * Goal types that can be given to a goal. diff --git a/src/script/api/script_group.cpp b/src/script/api/script_group.cpp index 27505e67c7..769993bbd8 100644 --- a/src/script/api/script_group.cpp +++ b/src/script/api/script_group.cpp @@ -65,7 +65,7 @@ EnforcePreconditionEncodedText(false, text); EnforcePreconditionCustomError(false, ::Utf8StringLength(text) < MAX_LENGTH_GROUP_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG); - return ScriptObject::Command::Do(AlterGroupMode::Rename, group_id, ::INVALID_GROUP, text); + return ScriptObject::Command::Do(AlterGroupMode::Rename, group_id, ::GroupID::Invalid(), text); } /* static */ std::optional ScriptGroup::GetName(GroupID group_id) @@ -87,7 +87,7 @@ /* static */ GroupID ScriptGroup::GetParent(GroupID group_id) { - EnforcePrecondition(INVALID_GROUP, IsValidGroup(group_id)); + EnforcePrecondition(::GroupID::Invalid(), IsValidGroup(group_id)); const Group *g = ::Group::GetIfValid(group_id); return g->parent; @@ -163,8 +163,8 @@ /* static */ EngineID ScriptGroup::GetEngineReplacement(GroupID group_id, EngineID engine_id) { - EnforceCompanyModeValid(::INVALID_ENGINE); - if (!IsValidGroup(group_id) && group_id != GROUP_DEFAULT && group_id != GROUP_ALL) return ::INVALID_ENGINE; + EnforceCompanyModeValid(::EngineID::Invalid()); + if (!IsValidGroup(group_id) && group_id != GROUP_DEFAULT && group_id != GROUP_ALL) return ::EngineID::Invalid(); return ::EngineReplacementForCompany(Company::Get(ScriptObject::GetCompany()), engine_id, group_id); } @@ -174,7 +174,7 @@ EnforceCompanyModeValid(false); EnforcePrecondition(false, IsValidGroup(group_id) || group_id == GROUP_DEFAULT || group_id == GROUP_ALL); - return ScriptObject::Command::Do(group_id, engine_id, ::INVALID_ENGINE, false); + return ScriptObject::Command::Do(group_id, engine_id, ::EngineID::Invalid(), false); } /* static */ Money ScriptGroup::GetProfitThisYear(GroupID group_id) diff --git a/src/script/api/script_group.hpp b/src/script/api/script_group.hpp index 7236b91d21..a4a497c05d 100644 --- a/src/script/api/script_group.hpp +++ b/src/script/api/script_group.hpp @@ -21,7 +21,7 @@ class ScriptGroup : public ScriptObject { public: static constexpr GroupID GROUP_ALL = ::ALL_GROUP; ///< All vehicles are in this group. static constexpr GroupID GROUP_DEFAULT = ::DEFAULT_GROUP; ///< Vehicles not put in any other group are in this one. - static constexpr GroupID GROUP_INVALID = ::INVALID_GROUP; ///< An invalid group id. + static constexpr GroupID GROUP_INVALID = ::GroupID::Invalid(); ///< An invalid group id. /** * Checks whether the given group is valid. diff --git a/src/script/api/script_industry.cpp b/src/script/api/script_industry.cpp index 115040f4a5..abe692d501 100644 --- a/src/script/api/script_industry.cpp +++ b/src/script/api/script_industry.cpp @@ -37,7 +37,7 @@ /* static */ IndustryID ScriptIndustry::GetIndustryID(TileIndex tile) { - if (!::IsValidTile(tile) || !::IsTileType(tile, MP_INDUSTRY)) return INVALID_INDUSTRY; + if (!::IsValidTile(tile) || !::IsTileType(tile, MP_INDUSTRY)) return IndustryID::Invalid(); return ::GetIndustryIndex(tile); } diff --git a/src/script/api/script_league.hpp b/src/script/api/script_league.hpp index 70864eaa38..aa335d6af9 100644 --- a/src/script/api/script_league.hpp +++ b/src/script/api/script_league.hpp @@ -25,9 +25,9 @@ */ class ScriptLeagueTable : public ScriptObject { public: - static constexpr LeagueTableID LEAGUE_TABLE_INVALID = ::INVALID_LEAGUE_TABLE; ///< An invalid league table id. + static constexpr LeagueTableID LEAGUE_TABLE_INVALID = ::LeagueTableID::Invalid(); ///< An invalid league table id. - static constexpr LeagueTableElementID LEAGUE_TABLE_ELEMENT_INVALID = ::INVALID_LEAGUE_TABLE_ELEMENT; ///< An invalid league table element id. + static constexpr LeagueTableElementID LEAGUE_TABLE_ELEMENT_INVALID = ::LeagueTableElementID::Invalid(); ///< An invalid league table element id. /** * The type of a link. diff --git a/src/script/api/script_marine.cpp b/src/script/api/script_marine.cpp index 6c04e19046..e7525d1368 100644 --- a/src/script/api/script_marine.cpp +++ b/src/script/api/script_marine.cpp @@ -92,7 +92,7 @@ EnforcePrecondition(false, ::IsValidTile(tile)); EnforcePrecondition(false, station_id == ScriptStation::STATION_NEW || station_id == ScriptStation::STATION_JOIN_ADJACENT || ScriptStation::IsValidStation(station_id)); - return ScriptObject::Command::Do(tile, ScriptStation::IsValidStation(station_id) ? station_id : INVALID_STATION, station_id != ScriptStation::STATION_JOIN_ADJACENT); + return ScriptObject::Command::Do(tile, ScriptStation::IsValidStation(station_id) ? station_id : StationID::Invalid(), station_id != ScriptStation::STATION_JOIN_ADJACENT); } /* static */ bool ScriptMarine::BuildBuoy(TileIndex tile) diff --git a/src/script/api/script_order.cpp b/src/script/api/script_order.cpp index 9fe3195075..8aa1c09566 100644 --- a/src/script/api/script_order.cpp +++ b/src/script/api/script_order.cpp @@ -484,7 +484,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr if (order_flags & OF_GOTO_NEAREST_DEPOT) odaf |= ODATFB_NEAREST_DEPOT; OrderNonStopFlags onsf = (OrderNonStopFlags)((order_flags & OF_NON_STOP_INTERMEDIATE) ? ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS : ONSF_STOP_EVERYWHERE); if (order_flags & OF_GOTO_NEAREST_DEPOT) { - order.MakeGoToDepot(INVALID_DEPOT, odtf, onsf, odaf); + order.MakeGoToDepot(DepotID::Invalid(), odtf, onsf, odaf); } else { /* Check explicitly if the order is to a station (for aircraft) or * to a depot (other vehicle types). */ @@ -680,7 +680,7 @@ static void _DoCommandReturnSetOrderFlags(class ScriptInstance *instance) EnforceCompanyModeValid(false); EnforcePrecondition(false, ScriptVehicle::IsPrimaryVehicle(vehicle_id)); - return ScriptObject::Command::Do(0, CO_UNSHARE, vehicle_id, ::INVALID_VEHICLE); + return ScriptObject::Command::Do(0, CO_UNSHARE, vehicle_id, VehicleID::Invalid()); } /* static */ SQInteger ScriptOrder::GetOrderDistance(ScriptVehicle::VehicleType vehicle_type, TileIndex origin_tile, TileIndex dest_tile) diff --git a/src/script/api/script_rail.cpp b/src/script/api/script_rail.cpp index 4337248798..7e028c7b8e 100644 --- a/src/script/api/script_rail.cpp +++ b/src/script/api/script_rail.cpp @@ -159,7 +159,7 @@ EnforcePrecondition(false, station_id == ScriptStation::STATION_NEW || station_id == ScriptStation::STATION_JOIN_ADJACENT || ScriptStation::IsValidStation(station_id)); bool adjacent = station_id != ScriptStation::STATION_JOIN_ADJACENT; - return ScriptObject::Command::Do(tile, (::RailType)GetCurrentRailType(), direction == RAILTRACK_NW_SE ? AXIS_Y : AXIS_X, num_platforms, platform_length, STAT_CLASS_DFLT, 0, ScriptStation::IsValidStation(station_id) ? station_id : INVALID_STATION, adjacent); + return ScriptObject::Command::Do(tile, (::RailType)GetCurrentRailType(), direction == RAILTRACK_NW_SE ? AXIS_Y : AXIS_X, num_platforms, platform_length, STAT_CLASS_DFLT, 0, ScriptStation::IsValidStation(station_id) ? station_id : StationID::Invalid(), adjacent); } /* static */ bool ScriptRail::BuildNewGRFRailStation(TileIndex tile, RailTrack direction, SQInteger num_platforms, SQInteger platform_length, StationID station_id, CargoType cargo_type, IndustryType source_industry, IndustryType goal_industry, SQInteger distance, bool source_station) @@ -191,7 +191,7 @@ Axis axis = direction == RAILTRACK_NW_SE ? AXIS_Y : AXIS_X; bool adjacent = station_id != ScriptStation::STATION_JOIN_ADJACENT; - StationID to_join = ScriptStation::IsValidStation(station_id) ? station_id : INVALID_STATION; + StationID to_join = ScriptStation::IsValidStation(station_id) ? station_id : StationID::Invalid(); if (res != CALLBACK_FAILED) { const StationSpec *spec = StationClass::GetByGrf(file->grfid, res); if (spec == nullptr) { @@ -213,7 +213,7 @@ EnforcePrecondition(false, GetRailTracks(tile) == RAILTRACK_NE_SW || GetRailTracks(tile) == RAILTRACK_NW_SE); EnforcePrecondition(false, IsRailTypeAvailable(GetCurrentRailType())); - return ScriptObject::Command::Do(tile, GetRailTracks(tile) == RAILTRACK_NE_SW ? AXIS_X : AXIS_Y, 1, 1, STAT_CLASS_WAYP, 0, INVALID_STATION, false); + return ScriptObject::Command::Do(tile, GetRailTracks(tile) == RAILTRACK_NE_SW ? AXIS_X : AXIS_Y, 1, 1, STAT_CLASS_WAYP, 0, StationID::Invalid(), false); } /* static */ bool ScriptRail::RemoveRailWaypointTileRectangle(TileIndex tile, TileIndex tile2, bool keep_rail) diff --git a/src/script/api/script_road.cpp b/src/script/api/script_road.cpp index 364c5cb5ab..ab2ac0b4cb 100644 --- a/src/script/api/script_road.cpp +++ b/src/script/api/script_road.cpp @@ -579,7 +579,7 @@ static bool NeighbourHasReachableRoad(::RoadType rt, TileIndex start_tile, DiagD DiagDirection entrance_dir = DiagdirBetweenTiles(tile, front); RoadStopType stop_type = road_veh_type == ROADVEHTYPE_TRUCK ? RoadStopType::Truck : RoadStopType::Bus; - StationID to_join = ScriptStation::IsValidStation(station_id) ? station_id : INVALID_STATION; + StationID to_join = ScriptStation::IsValidStation(station_id) ? station_id : StationID::Invalid(); return ScriptObject::Command::Do(tile, 1, 1, stop_type, drive_through, entrance_dir, ScriptObject::GetRoadType(), ROADSTOP_CLASS_DFLT, 0, to_join, station_id != ScriptStation::STATION_JOIN_ADJACENT); } diff --git a/src/script/api/script_sign.cpp b/src/script/api/script_sign.cpp index 63b9f5b642..4525796118 100644 --- a/src/script/api/script_sign.cpp +++ b/src/script/api/script_sign.cpp @@ -74,14 +74,14 @@ { ScriptObjectRef counter(name); - EnforceDeityOrCompanyModeValid(INVALID_SIGN); - EnforcePrecondition(INVALID_SIGN, ::IsValidTile(location)); - EnforcePrecondition(INVALID_SIGN, name != nullptr); + EnforceDeityOrCompanyModeValid(SignID::Invalid()); + EnforcePrecondition(SignID::Invalid(), ::IsValidTile(location)); + EnforcePrecondition(SignID::Invalid(), name != nullptr); const std::string &text = name->GetDecodedText(); - EnforcePreconditionEncodedText(INVALID_SIGN, text); - EnforcePreconditionCustomError(INVALID_SIGN, ::Utf8StringLength(text) < MAX_LENGTH_SIGN_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG); + EnforcePreconditionEncodedText(SignID::Invalid(), text); + EnforcePreconditionCustomError(SignID::Invalid(), ::Utf8StringLength(text) < MAX_LENGTH_SIGN_NAME_CHARS, ScriptError::ERR_PRECONDITION_STRING_TOO_LONG); - if (!ScriptObject::Command::Do(&ScriptInstance::DoCommandReturnSignID, location, text)) return INVALID_SIGN; + if (!ScriptObject::Command::Do(&ScriptInstance::DoCommandReturnSignID, location, text)) return SignID::Invalid(); /* In case of test-mode, we return SignID 0 */ return SignID::Begin(); diff --git a/src/script/api/script_station.cpp b/src/script/api/script_station.cpp index 11b04514a0..fb54eeacbe 100644 --- a/src/script/api/script_station.cpp +++ b/src/script/api/script_station.cpp @@ -35,7 +35,7 @@ /* static */ StationID ScriptStation::GetStationID(TileIndex tile) { - if (!::IsValidTile(tile) || !::IsTileType(tile, MP_STATION)) return INVALID_STATION; + if (!::IsValidTile(tile) || !::IsTileType(tile, MP_STATION)) return StationID::Invalid(); return ::GetStationIndex(tile); } @@ -229,7 +229,7 @@ template /* static */ TownID ScriptStation::GetNearestTown(StationID station_id) { - if (!IsValidStation(station_id)) return INVALID_TOWN; + if (!IsValidStation(station_id)) return TownID::Invalid(); return ::Station::Get(station_id)->town->index; } diff --git a/src/script/api/script_stationlist.cpp b/src/script/api/script_stationlist.cpp index d6e0d231f7..564fbe5766 100644 --- a/src/script/api/script_stationlist.cpp +++ b/src/script/api/script_stationlist.cpp @@ -122,7 +122,7 @@ private: CargoCollector::CargoCollector(ScriptStationList_Cargo *parent, StationID station_id, CargoType cargo, StationID other) : - list(parent), ge(nullptr), other_station(other), last_key(INVALID_STATION), amount(0) + list(parent), ge(nullptr), other_station(other), last_key(StationID::Invalid()), amount(0) { if (!ScriptStation::IsValidStation(station_id)) return; if (!ScriptCargo::IsValidCargo(cargo)) return; @@ -149,7 +149,7 @@ void CargoCollector::SetValue() template void CargoCollector::Update(StationID from, StationID via, uint amount) { - StationID key = INVALID_STATION; + StationID key = StationID::Invalid(); switch (Tselector) { case ScriptStationList_Cargo::CS_VIA_BY_FROM: if (via != this->other_station) return; diff --git a/src/script/api/script_stationlist.hpp b/src/script/api/script_stationlist.hpp index e0fd720319..0331502a87 100644 --- a/src/script/api/script_stationlist.hpp +++ b/src/script/api/script_stationlist.hpp @@ -93,7 +93,7 @@ protected: * @param other_station Other station to restrict the query with. */ template - void Add(StationID station_id, CargoType cargo, StationID other_station = INVALID_STATION); + void Add(StationID station_id, CargoType cargo, StationID other_station = StationID::Invalid()); public: @@ -130,7 +130,7 @@ protected: * @param other_station Other station to restrict the query with. */ template - void Add(StationID station_id, CargoType cargo, StationID other_station = INVALID_STATION); + void Add(StationID station_id, CargoType cargo, StationID other_station = StationID::Invalid()); public: diff --git a/src/script/api/script_story_page.cpp b/src/script/api/script_story_page.cpp index cba2360222..2977e4f1d5 100644 --- a/src/script/api/script_story_page.cpp +++ b/src/script/api/script_story_page.cpp @@ -76,7 +76,7 @@ static inline bool StoryPageElementTypeRequiresText(StoryPageElementType type) } EnforcePrecondition(STORY_PAGE_ELEMENT_INVALID, type != SPET_LOCATION || ::IsValidTile((::TileIndex)reference)); EnforcePrecondition(STORY_PAGE_ELEMENT_INVALID, type != SPET_GOAL || ScriptGoal::IsValidGoal(static_cast<::GoalID>(reference))); - EnforcePrecondition(STORY_PAGE_ELEMENT_INVALID, type != SPET_GOAL || !(StoryPage::Get(story_page_id)->company == INVALID_COMPANY && Goal::Get(reference)->company != INVALID_COMPANY)); + EnforcePrecondition(STORY_PAGE_ELEMENT_INVALID, type != SPET_GOAL || !(StoryPage::Get(story_page_id)->company == CompanyID::Invalid() && Goal::Get(reference)->company != CompanyID::Invalid())); uint32_t refid = 0; TileIndex reftile{}; @@ -125,7 +125,7 @@ static inline bool StoryPageElementTypeRequiresText(StoryPageElementType type) } EnforcePrecondition(false, type != ::SPET_LOCATION || ::IsValidTile((::TileIndex)reference)); EnforcePrecondition(false, type != ::SPET_GOAL || ScriptGoal::IsValidGoal(static_cast<::GoalID>(reference))); - EnforcePrecondition(false, type != ::SPET_GOAL || !(p->company == INVALID_COMPANY && Goal::Get(reference)->company != INVALID_COMPANY)); + EnforcePrecondition(false, type != ::SPET_GOAL || !(p->company == CompanyID::Invalid() && Goal::Get(reference)->company != CompanyID::Invalid())); uint32_t refid = 0; TileIndex reftile{}; diff --git a/src/script/api/script_story_page.hpp b/src/script/api/script_story_page.hpp index 5d77d05178..2a6391a711 100644 --- a/src/script/api/script_story_page.hpp +++ b/src/script/api/script_story_page.hpp @@ -38,8 +38,8 @@ */ class ScriptStoryPage : public ScriptObject { public: - static constexpr StoryPageID STORY_PAGE_INVALID = ::INVALID_STORY_PAGE; ///< An invalid story page id. - static constexpr StoryPageElementID STORY_PAGE_ELEMENT_INVALID = ::INVALID_STORY_PAGE_ELEMENT; ///< An invalid story page element id. + static constexpr StoryPageID STORY_PAGE_INVALID = ::StoryPageID::Invalid(); ///< An invalid story page id. + static constexpr StoryPageElementID STORY_PAGE_ELEMENT_INVALID = ::StoryPageElementID::Invalid(); ///< An invalid story page element id. /** * Story page element types. diff --git a/src/script/api/script_storypagelist.cpp b/src/script/api/script_storypagelist.cpp index aa1eebd075..0faf6e995d 100644 --- a/src/script/api/script_storypagelist.cpp +++ b/src/script/api/script_storypagelist.cpp @@ -19,6 +19,6 @@ ScriptStoryPageList::ScriptStoryPageList(ScriptCompany::CompanyID company) ::CompanyID c = ScriptCompany::FromScriptCompanyID(company); ScriptList::FillList(this, - [c](const StoryPage *p) {return p->company == c || p->company == INVALID_COMPANY; } + [c](const StoryPage *p) {return p->company == c || p->company == CompanyID::Invalid(); } ); } diff --git a/src/script/api/script_tile.cpp b/src/script/api/script_tile.cpp index f02a6f6f8c..9cc3264ef4 100644 --- a/src/script/api/script_tile.cpp +++ b/src/script/api/script_tile.cpp @@ -310,20 +310,20 @@ /* static */ TownID ScriptTile::GetTownAuthority(TileIndex tile) { - if (!::IsValidTile(tile)) return INVALID_TOWN; + if (!::IsValidTile(tile)) return TownID::Invalid(); Town *town = ::ClosestTownFromTile(tile, _settings_game.economy.dist_local_authority); - if (town == nullptr) return INVALID_TOWN; + if (town == nullptr) return TownID::Invalid(); return town->index; } /* static */ TownID ScriptTile::GetClosestTown(TileIndex tile) { - if (!::IsValidTile(tile)) return INVALID_TOWN; + if (!::IsValidTile(tile)) return TownID::Invalid(); Town *town = ::ClosestTownFromTile(tile, UINT_MAX); - if (town == nullptr) return INVALID_TOWN; + if (town == nullptr) return TownID::Invalid(); return town->index; } diff --git a/src/script/api/script_tunnel.cpp b/src/script/api/script_tunnel.cpp index 4dea5787c4..2703922d27 100644 --- a/src/script/api/script_tunnel.cpp +++ b/src/script/api/script_tunnel.cpp @@ -108,7 +108,7 @@ static void _DoCommandReturnBuildTunnel1(class ScriptInstance *instance) DiagDirection dir_1 = ::DiagdirBetweenTiles(end, start); DiagDirection dir_2 = ::ReverseDiagDir(dir_1); - return ScriptObject::Command::Do(&::_DoCommandReturnBuildTunnel2, start + ::TileOffsByDiagDir(dir_1), ::DiagDirToRoadBits(dir_2), ScriptRoad::GetRoadType(), DRD_NONE, INVALID_TOWN); + return ScriptObject::Command::Do(&::_DoCommandReturnBuildTunnel2, start + ::TileOffsByDiagDir(dir_1), ::DiagDirToRoadBits(dir_2), ScriptRoad::GetRoadType(), DRD_NONE, TownID::Invalid()); } /* static */ bool ScriptTunnel::_BuildTunnelRoad2() @@ -122,7 +122,7 @@ static void _DoCommandReturnBuildTunnel1(class ScriptInstance *instance) DiagDirection dir_1 = ::DiagdirBetweenTiles(end, start); DiagDirection dir_2 = ::ReverseDiagDir(dir_1); - return ScriptObject::Command::Do(end + ::TileOffsByDiagDir(dir_2), ::DiagDirToRoadBits(dir_1), ScriptRoad::GetRoadType(), DRD_NONE, INVALID_TOWN); + return ScriptObject::Command::Do(end + ::TileOffsByDiagDir(dir_2), ::DiagDirToRoadBits(dir_1), ScriptRoad::GetRoadType(), DRD_NONE, TownID::Invalid()); } /* static */ bool ScriptTunnel::RemoveTunnel(TileIndex tile) diff --git a/src/script/api/script_vehicle.cpp b/src/script/api/script_vehicle.cpp index a36a22aad7..2de36d7954 100644 --- a/src/script/api/script_vehicle.cpp +++ b/src/script/api/script_vehicle.cpp @@ -134,7 +134,7 @@ while (dest_wagon-- > 0) w = w->GetNextUnit(); } - return ScriptObject::Command::Do(v->index, w == nullptr ? ::INVALID_VEHICLE : w->index, move_attached_wagons); + return ScriptObject::Command::Do(v->index, w == nullptr ? VehicleID::Invalid() : w->index, move_attached_wagons); } /* static */ bool ScriptVehicle::MoveWagon(VehicleID source_vehicle_id, SQInteger source_wagon, SQInteger dest_vehicle_id, SQInteger dest_wagon) @@ -275,15 +275,15 @@ /* static */ EngineID ScriptVehicle::GetEngineType(VehicleID vehicle_id) { - if (!IsValidVehicle(vehicle_id)) return INVALID_ENGINE; + if (!IsValidVehicle(vehicle_id)) return ::EngineID::Invalid(); return ::Vehicle::Get(vehicle_id)->engine_type; } /* static */ EngineID ScriptVehicle::GetWagonEngineType(VehicleID vehicle_id, SQInteger wagon) { - if (!IsValidVehicle(vehicle_id)) return INVALID_ENGINE; - if (wagon >= GetNumWagons(vehicle_id)) return INVALID_ENGINE; + if (!IsValidVehicle(vehicle_id)) return ::EngineID::Invalid(); + if (wagon >= GetNumWagons(vehicle_id)) return ::EngineID::Invalid(); const Vehicle *v = ::Vehicle::Get(vehicle_id); if (v->type == VEH_TRAIN) { diff --git a/src/script/api/script_vehicle.hpp b/src/script/api/script_vehicle.hpp index b2d3f35e55..e0324daf27 100644 --- a/src/script/api/script_vehicle.hpp +++ b/src/script/api/script_vehicle.hpp @@ -95,7 +95,7 @@ public: VS_INVALID = 0xFF, ///< An invalid vehicle state. }; - static constexpr VehicleID VEHICLE_INVALID = ::INVALID_VEHICLE; ///< Invalid VehicleID. + static constexpr VehicleID VEHICLE_INVALID = ::VehicleID::Invalid(); ///< Invalid VehicleID. /** * Checks whether the given vehicle is valid and owned by you. diff --git a/src/script/api/script_waypoint.cpp b/src/script/api/script_waypoint.cpp index 168d85ac94..45ea701ab5 100644 --- a/src/script/api/script_waypoint.cpp +++ b/src/script/api/script_waypoint.cpp @@ -24,7 +24,7 @@ /* static */ StationID ScriptWaypoint::GetWaypointID(TileIndex tile) { - if (!::IsValidTile(tile) || !::IsTileType(tile, MP_STATION) || ::Waypoint::GetByTile(tile) == nullptr) return INVALID_STATION; + if (!::IsValidTile(tile) || !::IsTileType(tile, MP_STATION) || ::Waypoint::GetByTile(tile) == nullptr) return StationID::Invalid(); return ::GetStationIndex(tile); } diff --git a/src/script/script_config.cpp b/src/script/script_config.cpp index 9900675786..463b26703e 100644 --- a/src/script/script_config.cpp +++ b/src/script/script_config.cpp @@ -176,7 +176,7 @@ std::string ScriptConfig::SettingsToString() const std::optional ScriptConfig::GetTextfile(TextfileType type, CompanyID slot) const { - if (slot == INVALID_COMPANY || this->GetInfo() == nullptr) return std::nullopt; + if (slot == CompanyID::Invalid() || this->GetInfo() == nullptr) return std::nullopt; return ::GetTextfile(type, (slot == OWNER_DEITY) ? GAME_DIR : AI_DIR, this->GetInfo()->GetMainScript()); } diff --git a/src/script/script_gui.cpp b/src/script/script_gui.cpp index 40222441ce..b4b5b62f72 100644 --- a/src/script/script_gui.cpp +++ b/src/script/script_gui.cpp @@ -700,7 +700,7 @@ struct ScriptDebugWindow : public Window { static inline FilterState initial_state = { "", - INVALID_COMPANY, + CompanyID::Invalid(), true, false, }; @@ -743,14 +743,14 @@ struct ScriptDebugWindow : public Window { bool IsValidDebugCompany(CompanyID company) const { switch (company.base()) { - case INVALID_COMPANY.base(): return false; + case CompanyID::Invalid().base(): return false; case OWNER_DEITY.base(): return Game::GetInstance() != nullptr; default: return Company::IsValidAiID(company); } } /** - * Ensure that \c script_debug_company refers to a valid AI company or GS, or is set to #INVALID_COMPANY. + * Ensure that \c script_debug_company refers to a valid AI company or GS, or is set to #CompanyID::Invalid(). * If no valid company is selected, it selects the first valid AI or GS if any. */ void SelectValidDebugCompany() @@ -758,7 +758,7 @@ struct ScriptDebugWindow : public Window { /* Check if the currently selected company is still active. */ if (this->IsValidDebugCompany(this->filter.script_debug_company)) return; - this->filter.script_debug_company = INVALID_COMPANY; + this->filter.script_debug_company = CompanyID::Invalid(); for (const Company *c : Company::Iterate()) { if (c->is_ai) { @@ -798,7 +798,7 @@ struct ScriptDebugWindow : public Window { this->break_editbox.text.Assign(this->filter.break_string); this->break_string_filter.SetFilterTerm(this->filter.break_string); - if (show_company == INVALID_COMPANY) { + if (show_company == CompanyID::Invalid()) { this->SelectValidDebugCompany(); } else { this->ChangeToScript(show_company); @@ -847,7 +847,7 @@ struct ScriptDebugWindow : public Window { SetDParam(0, STR_AI_DEBUG_NAME_AND_VERSION); SetDParamStr(1, info->GetName()); SetDParam(2, info->GetVersion()); - } else if (this->filter.script_debug_company == INVALID_COMPANY || !Company::IsValidAiID(this->filter.script_debug_company)) { + } else if (this->filter.script_debug_company == CompanyID::Invalid() || !Company::IsValidAiID(this->filter.script_debug_company)) { SetDParam(0, STR_EMPTY); } else { const AIInfo *info = Company::Get(this->filter.script_debug_company)->ai_info; @@ -893,7 +893,7 @@ struct ScriptDebugWindow : public Window { */ void DrawWidgetLog(const Rect &r) const { - if (this->filter.script_debug_company == INVALID_COMPANY) return; + if (this->filter.script_debug_company == CompanyID::Invalid()) return; const ScriptLogTypes::LogData &log = this->GetLogData(); if (log.empty()) return; @@ -942,8 +942,8 @@ struct ScriptDebugWindow : public Window { */ void UpdateLogScroll() { - this->SetWidgetsDisabledState(this->filter.script_debug_company == INVALID_COMPANY, WID_SCRD_VSCROLLBAR, WID_SCRD_HSCROLLBAR); - if (this->filter.script_debug_company == INVALID_COMPANY) return; + this->SetWidgetsDisabledState(this->filter.script_debug_company == CompanyID::Invalid(), WID_SCRD_VSCROLLBAR, WID_SCRD_HSCROLLBAR); + if (this->filter.script_debug_company == CompanyID::Invalid()) return; ScriptLogTypes::LogData &log = this->GetLogData(); @@ -977,7 +977,7 @@ struct ScriptDebugWindow : public Window { void UpdateAIButtonsState() { /* Update company buttons */ - for (CompanyID i = COMPANY_FIRST; i < MAX_COMPANIES; ++i) { + for (CompanyID i = CompanyID::Begin(); i < MAX_COMPANIES; ++i) { /* Mark dead/paused AIs by setting the background colour. */ bool valid = Company::IsValidAiID(i); bool dead = valid && Company::Get(i)->ai_instance->IsDead(); @@ -1159,14 +1159,14 @@ struct ScriptDebugWindow : public Window { this->SelectValidDebugCompany(); uint max_width = 0; - if (this->filter.script_debug_company != INVALID_COMPANY) { + if (this->filter.script_debug_company != CompanyID::Invalid()) { for (auto &line : this->GetLogData()) { if (line.width == 0 || data == -1) line.width = GetStringBoundingBox(line.text).width; max_width = std::max(max_width, line.width); } } - this->vscroll->SetCount(this->filter.script_debug_company != INVALID_COMPANY ? this->GetLogData().size() : 0); + this->vscroll->SetCount(this->filter.script_debug_company != CompanyID::Invalid() ? this->GetLogData().size() : 0); this->hscroll->SetCount(max_width + WidgetDimensions::scaled.frametext.Horizontal()); this->UpdateAIButtonsState(); @@ -1175,14 +1175,14 @@ struct ScriptDebugWindow : public Window { this->SetWidgetLoweredState(WID_SCRD_BREAK_STR_ON_OFF_BTN, this->filter.break_check_enabled); this->SetWidgetLoweredState(WID_SCRD_MATCH_CASE_BTN, this->filter.case_sensitive_break_check); - this->SetWidgetDisabledState(WID_SCRD_SETTINGS, this->filter.script_debug_company == INVALID_COMPANY || + this->SetWidgetDisabledState(WID_SCRD_SETTINGS, this->filter.script_debug_company == CompanyID::Invalid() || GetConfig(this->filter.script_debug_company)->GetConfigList()->empty()); extern CompanyID _local_company; this->SetWidgetDisabledState(WID_SCRD_RELOAD_TOGGLE, - this->filter.script_debug_company == INVALID_COMPANY || + this->filter.script_debug_company == CompanyID::Invalid() || this->filter.script_debug_company == OWNER_DEITY || this->filter.script_debug_company == _local_company); - this->SetWidgetDisabledState(WID_SCRD_CONTINUE_BTN, this->filter.script_debug_company == INVALID_COMPANY || + this->SetWidgetDisabledState(WID_SCRD_CONTINUE_BTN, this->filter.script_debug_company == CompanyID::Invalid() || (this->filter.script_debug_company == OWNER_DEITY ? !Game::IsPaused() : !AI::IsPaused(this->filter.script_debug_company))); } @@ -1200,7 +1200,7 @@ struct ScriptDebugWindow : public Window { static EventState ScriptDebugGlobalHotkeys(int hotkey) { if (_game_mode != GM_NORMAL) return ES_NOT_HANDLED; - Window *w = ShowScriptDebugWindow(INVALID_COMPANY); + Window *w = ShowScriptDebugWindow(CompanyID::Invalid()); if (w == nullptr) return ES_NOT_HANDLED; return w->OnHotkey(hotkey); } @@ -1335,7 +1335,7 @@ Window *ShowScriptDebugWindow(CompanyID show_company, bool new_window) */ void InitializeScriptGui() { - ScriptDebugWindow::initial_state.script_debug_company = INVALID_COMPANY; + ScriptDebugWindow::initial_state.script_debug_company = CompanyID::Invalid(); } /** Open the AI debug window if one of the AI scripts has crashed. */ diff --git a/src/script/script_gui.h b/src/script/script_gui.h index 807557ac69..e2adceb40c 100644 --- a/src/script/script_gui.h +++ b/src/script/script_gui.h @@ -14,7 +14,7 @@ #include "../textfile_type.h" void ShowScriptListWindow(CompanyID slot, bool show_all); -Window *ShowScriptDebugWindow(CompanyID show_company = INVALID_COMPANY, bool new_window = false); +Window *ShowScriptDebugWindow(CompanyID show_company = CompanyID::Invalid(), bool new_window = false); void ShowScriptSettingsWindow(CompanyID slot); void ShowScriptTextfileWindow(TextfileType file_type, CompanyID slot); void ShowScriptDebugWindowIfScriptError(); diff --git a/src/settings.cpp b/src/settings.cpp index 799a54b7b5..5be008251c 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -960,14 +960,14 @@ static void AILoadConfig(const IniFile &ini, const char *grpname) const IniGroup *group = ini.GetGroup(grpname); /* Clean any configured AI */ - for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; ++c) { + for (CompanyID c = CompanyID::Begin(); c < MAX_COMPANIES; ++c) { AIConfig::GetConfig(c, AIConfig::SSS_FORCE_NEWGAME)->Change(std::nullopt); } /* If no group exists, return */ if (group == nullptr) return; - CompanyID c = COMPANY_FIRST; + CompanyID c = CompanyID::Begin(); for (const IniItem &item : group->items) { AIConfig *config = AIConfig::GetConfig(c, AIConfig::SSS_FORCE_NEWGAME); @@ -1173,7 +1173,7 @@ static void AISaveConfig(IniFile &ini, const char *grpname) IniGroup &group = ini.GetOrCreateGroup(grpname); group.Clear(); - for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; ++c) { + for (CompanyID c = CompanyID::Begin(); c < MAX_COMPANIES; ++c) { AIConfig *config = AIConfig::GetConfig(c, AIConfig::SSS_FORCE_NEWGAME); std::string name; std::string value = config->SettingsToString(); diff --git a/src/ship_cmd.cpp b/src/ship_cmd.cpp index 3b50feec65..9c11b377d4 100644 --- a/src/ship_cmd.cpp +++ b/src/ship_cmd.cpp @@ -317,7 +317,7 @@ void Ship::PlayLeaveStationSound(bool force) const TileIndex Ship::GetOrderStationLocation(StationID station) { - if (station == this->last_station_visited) this->last_station_visited = INVALID_STATION; + if (station == this->last_station_visited) this->last_station_visited = StationID::Invalid(); const Station *st = Station::Get(station); if (CanVehicleUseStation(this, st)) { @@ -921,8 +921,8 @@ CommandCost CmdBuildShip(DoCommandFlags flags, TileIndex tile, const Engine *e, v->cargo_cap = svi->capacity; v->refit_cap = 0; - v->last_station_visited = INVALID_STATION; - v->last_loading_station = INVALID_STATION; + v->last_station_visited = StationID::Invalid(); + v->last_loading_station = StationID::Invalid(); v->engine_type = e->index; v->reliability = e->reliability; diff --git a/src/signs_cmd.cpp b/src/signs_cmd.cpp index da87305d7e..e9e74a3fb2 100644 --- a/src/signs_cmd.cpp +++ b/src/signs_cmd.cpp @@ -35,10 +35,10 @@ std::tuple CmdPlaceSign(DoCommandFlags flags, TileIndex tile, const std::string &text) { /* Try to locate a new sign */ - if (!Sign::CanAllocateItem()) return { CommandCost(STR_ERROR_TOO_MANY_SIGNS), INVALID_SIGN }; + if (!Sign::CanAllocateItem()) return { CommandCost(STR_ERROR_TOO_MANY_SIGNS), SignID::Invalid() }; /* Check sign text length if any */ - if (Utf8StringLength(text) >= MAX_LENGTH_SIGN_NAME_CHARS) return { CMD_ERROR, INVALID_SIGN }; + if (Utf8StringLength(text) >= MAX_LENGTH_SIGN_NAME_CHARS) return { CMD_ERROR, SignID::Invalid() }; /* When we execute, really make the sign */ if (flags.Test(DoCommandFlag::Execute)) { @@ -57,7 +57,7 @@ std::tuple CmdPlaceSign(DoCommandFlags flags, TileIndex til return { CommandCost(), si->index }; } - return { CommandCost(), INVALID_SIGN }; + return { CommandCost(), SignID::Invalid() }; } /** diff --git a/src/signs_type.h b/src/signs_type.h index b7e12f13f6..ff298611f6 100644 --- a/src/signs_type.h +++ b/src/signs_type.h @@ -12,7 +12,6 @@ /** The type of the IDs of signs. */ using SignID = PoolID; -static constexpr SignID INVALID_SIGN = SignID::Invalid(); ///< Sentinel for an invalid sign. struct Sign; diff --git a/src/smallmap_gui.cpp b/src/smallmap_gui.cpp index d7d606abea..6ff8ef3df7 100644 --- a/src/smallmap_gui.cpp +++ b/src/smallmap_gui.cpp @@ -60,25 +60,25 @@ static uint8_t _linkstat_colours_in_legenda[] = {0, 1, 3, 5, 7, 9, 11}; static const int NUM_NO_COMPANY_ENTRIES = 4; ///< Number of entries in the owner legend that are not companies. /** Macro for ordinary entry of LegendAndColour */ -#define MK(a, b) {a, b, IT_INVALID, 0, INVALID_COMPANY, true, false, false} +#define MK(a, b) {a, b, IT_INVALID, 0, CompanyID::Invalid(), true, false, false} /** Macro for a height legend entry with configurable colour. */ -#define MC(col_break) {0, STR_TINY_BLACK_HEIGHT, IT_INVALID, 0, INVALID_COMPANY, true, false, col_break} +#define MC(col_break) {0, STR_TINY_BLACK_HEIGHT, IT_INVALID, 0, CompanyID::Invalid(), true, false, col_break} /** Macro for non-company owned property entry of LegendAndColour */ -#define MO(a, b) {a, b, IT_INVALID, 0, INVALID_COMPANY, true, false, false} +#define MO(a, b) {a, b, IT_INVALID, 0, CompanyID::Invalid(), true, false, false} /** Macro used for forcing a rebuild of the owner legend the first time it is used. */ #define MOEND() {0, STR_NULL, IT_INVALID, 0, OWNER_NONE, true, true, false} /** Macro for end of list marker in arrays of LegendAndColour */ -#define MKEND() {0, STR_NULL, IT_INVALID, 0, INVALID_COMPANY, true, true, false} +#define MKEND() {0, STR_NULL, IT_INVALID, 0, CompanyID::Invalid(), true, true, false} /** * Macro for break marker in arrays of LegendAndColour. * It will have valid data, though */ -#define MS(a, b) {a, b, IT_INVALID, 0, INVALID_COMPANY, true, false, true} +#define MS(a, b) {a, b, IT_INVALID, 0, CompanyID::Invalid(), true, false, true} /** Legend text giving the colours to look for on the minimap */ static LegendAndColour _legend_land_contours[] = { @@ -1538,7 +1538,7 @@ public: SetDParam(0, tbl->legend); str = STR_SMALLMAP_LINKSTATS; } else if (i == SMT_OWNER) { - if (tbl->company != INVALID_COMPANY) { + if (tbl->company != CompanyID::Invalid()) { if (!Company::IsValidID(tbl->company)) { /* Rebuild the owner legend. */ BuildOwnerLegend(); @@ -1581,7 +1581,7 @@ public: { if (this->map_type == SMT_OWNER) { for (const LegendAndColour *tbl = _legend_table[this->map_type]; !tbl->end; ++tbl) { - if (tbl->company != INVALID_COMPANY && !Company::IsValidID(tbl->company)) { + if (tbl->company != CompanyID::Invalid() && !Company::IsValidID(tbl->company)) { /* Rebuild the owner legend. */ BuildOwnerLegend(); this->InvalidateData(1); @@ -1660,7 +1660,7 @@ public: [[fallthrough]]; case SMT_OWNER: - if (this->map_type != SMT_OWNER || tbl->company != INVALID_COMPANY) { + if (this->map_type != SMT_OWNER || tbl->company != CompanyID::Invalid()) { if (this->map_type == SMT_OWNER) SetDParam(0, tbl->company); if (!tbl->show_on_map) { /* Simply draw the string, not the black border of the legend colour. diff --git a/src/station.cpp b/src/station.cpp index 51443b28b9..83dfbb40f8 100644 --- a/src/station.cpp +++ b/src/station.cpp @@ -96,7 +96,7 @@ Station::~Station() for (Aircraft *a : Aircraft::Iterate()) { if (!a->IsNormalAircraft()) continue; - if (a->targetairport == this->index) a->targetairport = INVALID_STATION; + if (a->targetairport == this->index) a->targetairport = StationID::Invalid(); } for (CargoType c = 0; c < NUM_CARGO; ++c) { @@ -122,10 +122,10 @@ Station::~Station() for (Vehicle *v : Vehicle::Iterate()) { /* Forget about this station if this station is removed */ if (v->last_station_visited == this->index) { - v->last_station_visited = INVALID_STATION; + v->last_station_visited = StationID::Invalid(); } if (v->last_loading_station == this->index) { - v->last_loading_station = INVALID_STATION; + v->last_loading_station = StationID::Invalid(); } } diff --git a/src/station_base.h b/src/station_base.h index 4627f35674..de2ae03ad1 100644 --- a/src/station_base.h +++ b/src/station_base.h @@ -132,10 +132,10 @@ public: assert(!this->shares.empty()); return this->unrestricted > 0 ? this->shares.upper_bound(RandomRange(this->unrestricted))->second : - INVALID_STATION; + StationID::Invalid(); } - StationID GetVia(StationID excluded, StationID excluded2 = INVALID_STATION) const; + StationID GetVia(StationID excluded, StationID excluded2 = StationID::Invalid()) const; void Invalidate(); @@ -219,7 +219,7 @@ struct GoodsEntry { uint max_waiting_cargo = 0; ///< Max cargo from this station waiting at any station. NodeID node = INVALID_NODE; ///< ID of node in link graph referring to this goods entry. - LinkGraphID link_graph = INVALID_LINK_GRAPH; ///< Link graph this station belongs to. + LinkGraphID link_graph = LinkGraphID::Invalid(); ///< Link graph this station belongs to. uint8_t status = 0; ///< Status of this cargo, see #GoodsEntryStatus. @@ -270,14 +270,14 @@ struct GoodsEntry { /** * Get the best next hop for a cargo packet from station source. * @param source Source of the packet. - * @return The chosen next hop or INVALID_STATION if none was found. + * @return The chosen next hop or StationID::Invalid() if none was found. */ inline StationID GetVia(StationID source) const { - if (!this->HasData()) return INVALID_STATION; + if (!this->HasData()) return StationID::Invalid(); FlowStatMap::const_iterator flow_it(this->GetData().flows.find(source)); - return flow_it != this->GetData().flows.end() ? flow_it->second.GetVia() : INVALID_STATION; + return flow_it != this->GetData().flows.end() ? flow_it->second.GetVia() : StationID::Invalid(); } /** @@ -285,15 +285,15 @@ struct GoodsEntry { * excluding one or two stations. * @param source Source of the packet. * @param excluded If this station would be chosen choose the second best one instead. - * @param excluded2 Second station to be excluded, if != INVALID_STATION. - * @return The chosen next hop or INVALID_STATION if none was found. + * @param excluded2 Second station to be excluded, if != StationID::Invalid(). + * @return The chosen next hop or StationID::Invalid() if none was found. */ - inline StationID GetVia(StationID source, StationID excluded, StationID excluded2 = INVALID_STATION) const + inline StationID GetVia(StationID source, StationID excluded, StationID excluded2 = StationID::Invalid()) const { - if (!this->HasData()) return INVALID_STATION; + if (!this->HasData()) return StationID::Invalid(); FlowStatMap::const_iterator flow_it(this->GetData().flows.find(source)); - return flow_it != this->GetData().flows.end() ? flow_it->second.GetVia(excluded, excluded2) : INVALID_STATION; + return flow_it != this->GetData().flows.end() ? flow_it->second.GetVia(excluded, excluded2) : StationID::Invalid(); } /** diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index 03b16a1a5e..1992b89efb 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -125,14 +125,14 @@ CommandCost GetStationAround(TileArea ta, StationID closest_station, CompanyID c if (IsTileType(tile_cur, MP_STATION)) { StationID t = GetStationIndex(tile_cur); if (!T::IsValidID(t) || T::Get(t)->owner != company || !filter(T::Get(t))) continue; - if (closest_station == INVALID_STATION) { + if (closest_station == StationID::Invalid()) { closest_station = t; } else if (closest_station != t) { return CommandCost(STR_ERROR_ADJOINS_MORE_THAN_ONE_EXISTING); } } } - *st = (closest_station == INVALID_STATION) ? nullptr : T::Get(closest_station); + *st = (closest_station == StationID::Invalid()) ? nullptr : T::Get(closest_station); return CommandCost(); } @@ -900,14 +900,14 @@ static CommandCost CheckFlatLandRailStation(TileIndex tile_cur, TileIndex north_ } /* if station is set, then we have special handling to allow building on top of already existing stations. - * so station points to INVALID_STATION if we can build on any station. + * so station points to StationID::Invalid() if we can build on any station. * Or it points to a station if we're only allowed to build on exactly that station. */ if (station != nullptr && IsTileType(tile_cur, MP_STATION)) { if (!IsRailStation(tile_cur)) { return ClearTile_Station(tile_cur, DoCommandFlag::Auto); // get error message } else { StationID st = GetStationIndex(tile_cur); - if (*station == INVALID_STATION) { + if (*station == StationID::Invalid()) { *station = st; } else if (*station != st) { return CommandCost(STR_ERROR_ADJOINS_MORE_THAN_ONE_EXISTING); @@ -972,7 +972,7 @@ CommandCost CheckFlatLandRoadStop(TileIndex cur_tile, int &allowed_z, DoCommandF cost.AddCost(ret); /* If station is set, then we have special handling to allow building on top of already existing stations. - * Station points to INVALID_STATION if we can build on any station. + * Station points to StationID::Invalid() if we can build on any station. * Or it points to a station if we're only allowed to build on exactly that station. */ if (station != nullptr && IsTileType(cur_tile, MP_STATION)) { if (!IsAnyRoadStop(cur_tile)) { @@ -987,7 +987,7 @@ CommandCost CheckFlatLandRoadStop(TileIndex cur_tile, int &allowed_z, DoCommandF return CommandCost(STR_ERROR_DRIVE_THROUGH_DIRECTION); } StationID st = GetStationIndex(cur_tile); - if (*station == INVALID_STATION) { + if (*station == StationID::Invalid()) { *station = st; } else if (*station != st) { return CommandCost(STR_ERROR_ADJOINS_MORE_THAN_ONE_EXISTING); @@ -1163,7 +1163,7 @@ CommandCost FindJoiningBaseStation(StationID existing_station, StationID station assert(*st == nullptr); bool check_surrounding = true; - if (existing_station != INVALID_STATION) { + if (existing_station != StationID::Invalid()) { if (adjacent && existing_station != station_to_join) { /* You can't build an adjacent station over the top of one that * already exists. */ @@ -1188,7 +1188,7 @@ CommandCost FindJoiningBaseStation(StationID existing_station, StationID station } /* Distant join */ - if (*st == nullptr && station_to_join != INVALID_STATION) *st = T::GetIfValid(station_to_join); + if (*st == nullptr && station_to_join != StationID::Invalid()) *st = T::GetIfValid(station_to_join); return CommandCost(); } @@ -1364,8 +1364,8 @@ CommandCost CmdBuildRailStation(DoCommandFlags flags, TileIndex tile_org, RailTy } bool reuse = (station_to_join != NEW_STATION); - if (!reuse) station_to_join = INVALID_STATION; - bool distant_join = (station_to_join != INVALID_STATION); + if (!reuse) station_to_join = StationID::Invalid(); + bool distant_join = (station_to_join != StationID::Invalid()); if (distant_join && (!_settings_game.station.distant_join_stations || !Station::IsValidID(station_to_join))) return CMD_ERROR; @@ -1375,7 +1375,7 @@ CommandCost CmdBuildRailStation(DoCommandFlags flags, TileIndex tile_org, RailTy TileArea new_location(tile_org, w_org, h_org); /* Make sure the area below consists of clear tiles. (OR tiles belonging to a certain rail station) */ - StationID est = INVALID_STATION; + StationID est = StationID::Invalid(); std::vector affected_vehicles; /* Add construction and clearing expenses. */ CommandCost cost = CalculateRailStationCost(new_location, flags, axis, &est, rt, affected_vehicles, spec_class, spec_index, plat_len, numtracks); @@ -1964,8 +1964,8 @@ CommandCost CmdBuildRoadStop(DoCommandFlags flags, TileIndex tile, uint8_t width { if (!ValParamRoadType(rt) || !IsValidDiagDirection(ddir) || stop_type >= RoadStopType::End) return CMD_ERROR; bool reuse = (station_to_join != NEW_STATION); - if (!reuse) station_to_join = INVALID_STATION; - bool distant_join = (station_to_join != INVALID_STATION); + if (!reuse) station_to_join = StationID::Invalid(); + bool distant_join = (station_to_join != StationID::Invalid()); /* Check if the given station class is valid */ if (static_cast(spec_class) >= RoadStopClass::GetClassCount()) return CMD_ERROR; @@ -2008,7 +2008,7 @@ CommandCost CmdBuildRoadStop(DoCommandFlags flags, TileIndex tile, uint8_t width } else { unit_cost = _price[is_truck_stop ? PR_BUILD_STATION_TRUCK : PR_BUILD_STATION_BUS]; } - StationID est = INVALID_STATION; + StationID est = StationID::Invalid(); CommandCost cost = CalculateRoadStopCost(roadstop_area, flags, is_drive_through, is_truck_stop ? StationType::Truck : StationType::Bus, axis, ddir, &est, rt, unit_cost); if (cost.Failed()) return cost; @@ -2523,8 +2523,8 @@ void UpdateAirportsNoise() CommandCost CmdBuildAirport(DoCommandFlags flags, TileIndex tile, uint8_t airport_type, uint8_t layout, StationID station_to_join, bool allow_adjacent) { bool reuse = (station_to_join != NEW_STATION); - if (!reuse) station_to_join = INVALID_STATION; - bool distant_join = (station_to_join != INVALID_STATION); + if (!reuse) station_to_join = StationID::Invalid(); + bool distant_join = (station_to_join != StationID::Invalid()); if (distant_join && (!_settings_game.station.distant_join_stations || !Station::IsValidID(station_to_join))) return CMD_ERROR; @@ -2584,7 +2584,7 @@ CommandCost CmdBuildAirport(DoCommandFlags flags, TileIndex tile, uint8_t airpor } Station *st = nullptr; - ret = FindJoiningStation(INVALID_STATION, station_to_join, allow_adjacent, airport_area, &st); + ret = FindJoiningStation(StationID::Invalid(), station_to_join, allow_adjacent, airport_area, &st); if (ret.Failed()) return ret; /* Distant join */ @@ -2788,8 +2788,8 @@ static const uint8_t _dock_h_chk[4] = { 1, 2, 1, 2 }; CommandCost CmdBuildDock(DoCommandFlags flags, TileIndex tile, StationID station_to_join, bool adjacent) { bool reuse = (station_to_join != NEW_STATION); - if (!reuse) station_to_join = INVALID_STATION; - bool distant_join = (station_to_join != INVALID_STATION); + if (!reuse) station_to_join = StationID::Invalid(); + bool distant_join = (station_to_join != StationID::Invalid()); if (distant_join && (!_settings_game.station.distant_join_stations || !Station::IsValidID(station_to_join))) return CMD_ERROR; @@ -2836,7 +2836,7 @@ CommandCost CmdBuildDock(DoCommandFlags flags, TileIndex tile, StationID station /* middle */ Station *st = nullptr; - ret = FindJoiningStation(INVALID_STATION, station_to_join, adjacent, dock_area, &st); + ret = FindJoiningStation(StationID::Invalid(), station_to_join, adjacent, dock_area, &st); if (ret.Failed()) return ret; /* Distant join */ @@ -3861,7 +3861,7 @@ static void UpdateStationRating(Station *st) uint waiting = ge->HasData() ? ge->GetData().cargo.AvailableCount() : 0; /* num_dests is at least 1 if there is any cargo as - * INVALID_STATION is also a destination. + * StationID::Invalid() is also a destination. */ uint num_dests = ge->HasData() ? static_cast(ge->GetData().cargo.Packets()->MapSize()) : 0; @@ -3869,7 +3869,7 @@ static void UpdateStationRating(Station *st) * with only one or two next hops. They are allowed to have more * cargo waiting per next hop. * With manual cargo distribution waiting_avg = waiting / 2 as then - * INVALID_STATION is the only destination. + * StationID::Invalid() is the only destination. */ uint waiting_avg = waiting / (num_dests + 1); @@ -4120,8 +4120,8 @@ void IncreaseStats(Station *st, CargoType cargo, StationID next_station_id, uint Station *st2 = Station::Get(next_station_id); GoodsEntry &ge2 = st2->goods[cargo]; LinkGraph *lg = nullptr; - if (ge1.link_graph == INVALID_LINK_GRAPH) { - if (ge2.link_graph == INVALID_LINK_GRAPH) { + if (ge1.link_graph == LinkGraphID::Invalid()) { + if (ge2.link_graph == LinkGraphID::Invalid()) { if (LinkGraph::CanAllocateItem()) { lg = new LinkGraph(cargo); LinkGraphSchedule::instance.Queue(lg); @@ -4137,7 +4137,7 @@ void IncreaseStats(Station *st, CargoType cargo, StationID next_station_id, uint ge1.link_graph = lg->index; ge1.node = lg->AddNode(st); } - } else if (ge2.link_graph == INVALID_LINK_GRAPH) { + } else if (ge2.link_graph == LinkGraphID::Invalid()) { lg = LinkGraph::Get(ge1.link_graph); ge2.link_graph = lg->index; ge2.node = lg->AddNode(st2); @@ -4262,7 +4262,7 @@ static uint UpdateStationWaiting(Station *st, CargoType type, uint amount, Sourc StationID next = ge.GetVia(st->index); ge.GetOrCreateData().cargo.Append(new CargoPacket(st->index, amount, source), next); LinkGraph *lg = nullptr; - if (ge.link_graph == INVALID_LINK_GRAPH) { + if (ge.link_graph == LinkGraphID::Invalid()) { if (LinkGraph::CanAllocateItem()) { lg = new LinkGraph(type); LinkGraphSchedule::instance.Queue(lg); @@ -4797,7 +4797,7 @@ uint FlowStat::GetShare(StationID st) const */ StationID FlowStat::GetVia(StationID excluded, StationID excluded2) const { - if (this->unrestricted == 0) return INVALID_STATION; + if (this->unrestricted == 0) return StationID::Invalid(); assert(!this->shares.empty()); SharesMap::const_iterator it = this->shares.upper_bound(RandomRange(this->unrestricted)); assert(it != this->shares.end() && it->first <= this->unrestricted); @@ -4809,7 +4809,7 @@ StationID FlowStat::GetVia(StationID excluded, StationID excluded2) const uint end = it->first; uint begin = (it == this->shares.begin() ? 0 : (--it)->first); uint interval = end - begin; - if (interval >= this->unrestricted) return INVALID_STATION; // Only one station in the map. + if (interval >= this->unrestricted) return StationID::Invalid(); // Only one station in the map. uint new_max = this->unrestricted - interval; uint rand = RandomRange(new_max); SharesMap::const_iterator it2 = (rand < begin) ? this->shares.upper_bound(rand) : @@ -4823,7 +4823,7 @@ StationID FlowStat::GetVia(StationID excluded, StationID excluded2) const uint end2 = it2->first; uint begin2 = (it2 == this->shares.begin() ? 0 : (--it2)->first); uint interval2 = end2 - begin2; - if (interval2 >= new_max) return INVALID_STATION; // Only the two excluded stations in the map. + if (interval2 >= new_max) return StationID::Invalid(); // Only the two excluded stations in the map. new_max -= interval2; if (begin > begin2) { Swap(begin, begin2); @@ -5028,11 +5028,11 @@ void FlowStatMap::PassOnFlow(StationID origin, StationID via, uint flow) FlowStatMap::iterator prev_it = this->find(origin); if (prev_it == this->end()) { FlowStat fs(via, flow); - fs.AppendShare(INVALID_STATION, flow); + fs.AppendShare(StationID::Invalid(), flow); this->emplace(origin, fs); } else { prev_it->second.ChangeShare(via, flow); - prev_it->second.ChangeShare(INVALID_STATION, flow); + prev_it->second.ChangeShare(StationID::Invalid(), flow); assert(!prev_it->second.GetShares()->empty()); } } @@ -5045,14 +5045,14 @@ void FlowStatMap::FinalizeLocalConsumption(StationID self) { for (auto &i : *this) { FlowStat &fs = i.second; - uint local = fs.GetShare(INVALID_STATION); + uint local = fs.GetShare(StationID::Invalid()); if (local > INT_MAX) { // make sure it fits in an int fs.ChangeShare(self, -INT_MAX); - fs.ChangeShare(INVALID_STATION, -INT_MAX); + fs.ChangeShare(StationID::Invalid(), -INT_MAX); local -= INT_MAX; } fs.ChangeShare(self, -(int)local); - fs.ChangeShare(INVALID_STATION, -(int)local); + fs.ChangeShare(StationID::Invalid(), -(int)local); /* If the local share is used up there must be a share for some * remote station. */ diff --git a/src/station_gui.cpp b/src/station_gui.cpp index d904606819..47b133e52a 100644 --- a/src/station_gui.cpp +++ b/src/station_gui.cpp @@ -1063,7 +1063,7 @@ private: CargoDataEntry::CargoDataEntry() : parent(nullptr), - station(INVALID_STATION), + station(StationID::Invalid()), num_children(0), count(0), children(new CargoDataSet(CargoSorter(CargoSortType::CargoType))) @@ -1580,7 +1580,7 @@ struct StationViewWindow : public Window { } if (tmp.GetCount() == 0) { - dest->InsertOrRetrieve(INVALID_STATION)->Update(count); + dest->InsertOrRetrieve(StationID::Invalid())->Update(count); } else { uint sum_estimated = 0; while (sum_estimated < count) { @@ -1607,7 +1607,7 @@ struct StationViewWindow : public Window { } } } else { - dest->InsertOrRetrieve(INVALID_STATION)->Update(count); + dest->InsertOrRetrieve(StationID::Invalid())->Update(count); } } @@ -1649,13 +1649,13 @@ struct StationViewWindow : public Window { const CargoDataEntry *source_entry = source_dest->Retrieve(cp->GetFirstStation()); if (source_entry == nullptr) { - this->ShowCargo(cargo, i, cp->GetFirstStation(), next, INVALID_STATION, cp->Count()); + this->ShowCargo(cargo, i, cp->GetFirstStation(), next, StationID::Invalid(), cp->Count()); continue; } const CargoDataEntry *via_entry = source_entry->Retrieve(next); if (via_entry == nullptr) { - this->ShowCargo(cargo, i, cp->GetFirstStation(), next, INVALID_STATION, cp->Count()); + this->ShowCargo(cargo, i, cp->GetFirstStation(), next, StationID::Invalid(), cp->Count()); continue; } @@ -1747,7 +1747,7 @@ struct StationViewWindow : public Window { { if (station == this->window_number) { return here; - } else if (station == INVALID_STATION) { + } else if (station == StationID::Invalid()) { return any; } else if (station == NEW_STATION) { return STR_STATION_VIEW_RESERVED; @@ -2462,7 +2462,7 @@ static bool StationJoinerNeeded(TileArea ta, const StationPickerCmdProc &proc) if (!_ctrl_pressed) return false; /* Now check if we could build there */ - if (!proc(true, INVALID_STATION)) return false; + if (!proc(true, StationID::Invalid())) return false; return FindStationsNearby(ta, false) == nullptr; } @@ -2480,7 +2480,7 @@ void ShowSelectBaseStationIfNeeded(TileArea ta, StationPickerCmdProc&& proc) if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace(); new SelectStationWindow(_select_station_desc, ta, std::move(proc)); } else { - proc(false, INVALID_STATION); + proc(false, StationID::Invalid()); } } diff --git a/src/station_type.h b/src/station_type.h index 48ee626406..45943b77e4 100644 --- a/src/station_type.h +++ b/src/station_type.h @@ -17,7 +17,6 @@ using StationID = PoolID; static constexpr StationID NEW_STATION{0xFFFD}; static constexpr StationID ADJACENT_STATION{0xFFFE}; -static constexpr StationID INVALID_STATION = StationID::Invalid(); using RoadStopID = PoolID; @@ -27,7 +26,7 @@ struct RoadStop; struct StationSpec; struct Waypoint; -using StationIDStack = SmallStack; +using StationIDStack = SmallStack; /** Station types */ enum class StationType : uint8_t { diff --git a/src/story.cpp b/src/story.cpp index 8a25451b24..0e9dc743eb 100644 --- a/src/story.cpp +++ b/src/story.cpp @@ -62,7 +62,7 @@ static bool VerifyElementContentParameters(StoryPageID page_id, StoryPageElement case SPET_GOAL: if (!Goal::IsValidID((GoalID)reference)) return false; /* Reject company specific goals on global pages */ - if (StoryPage::Get(page_id)->company == INVALID_COMPANY && Goal::Get((GoalID)reference)->company != INVALID_COMPANY) return false; + if (StoryPage::Get(page_id)->company == CompanyID::Invalid() && Goal::Get((GoalID)reference)->company != CompanyID::Invalid()) return false; break; case SPET_BUTTON_PUSH: if (!button_data.ValidateColour()) return false; @@ -208,10 +208,10 @@ bool StoryPageButtonData::ValidateVehicleType() const */ std::tuple CmdCreateStoryPage(DoCommandFlags flags, CompanyID company, const std::string &text) { - if (!StoryPage::CanAllocateItem()) return { CMD_ERROR, INVALID_STORY_PAGE }; + if (!StoryPage::CanAllocateItem()) return { CMD_ERROR, StoryPageID::Invalid() }; - if (_current_company != OWNER_DEITY) return { CMD_ERROR, INVALID_STORY_PAGE }; - if (company != INVALID_COMPANY && !Company::IsValidID(company)) return { CMD_ERROR, INVALID_STORY_PAGE }; + if (_current_company != OWNER_DEITY) return { CMD_ERROR, StoryPageID::Invalid() }; + if (company != CompanyID::Invalid() && !Company::IsValidID(company)) return { CMD_ERROR, StoryPageID::Invalid() }; if (flags.Test(DoCommandFlag::Execute)) { if (StoryPage::GetNumItems() == 0) { @@ -232,7 +232,7 @@ std::tuple CmdCreateStoryPage(DoCommandFlags flags, Co return { CommandCost(), s->index }; } - return { CommandCost(), INVALID_STORY_PAGE }; + return { CommandCost(), StoryPageID::Invalid() }; } /** @@ -247,18 +247,18 @@ std::tuple CmdCreateStoryPage(DoCommandFlags flags, Co */ std::tuple CmdCreateStoryPageElement(DoCommandFlags flags, TileIndex tile, StoryPageID page_id, StoryPageElementType type, uint32_t reference, const std::string &text) { - if (!StoryPageElement::CanAllocateItem()) return { CMD_ERROR, INVALID_STORY_PAGE_ELEMENT }; + if (!StoryPageElement::CanAllocateItem()) return { CMD_ERROR, StoryPageElementID::Invalid() }; /* Allow at most 128 elements per page. */ uint16_t element_count = 0; for (StoryPageElement *iter : StoryPageElement::Iterate()) { if (iter->page == page_id) element_count++; } - if (element_count >= 128) return { CMD_ERROR, INVALID_STORY_PAGE_ELEMENT }; + if (element_count >= 128) return { CMD_ERROR, StoryPageElementID::Invalid() }; - if (_current_company != OWNER_DEITY) return { CMD_ERROR, INVALID_STORY_PAGE_ELEMENT }; - if (!StoryPage::IsValidID(page_id)) return { CMD_ERROR, INVALID_STORY_PAGE_ELEMENT }; - if (!VerifyElementContentParameters(page_id, type, tile, reference, text)) return { CMD_ERROR, INVALID_STORY_PAGE_ELEMENT }; + if (_current_company != OWNER_DEITY) return { CMD_ERROR, StoryPageElementID::Invalid() }; + if (!StoryPage::IsValidID(page_id)) return { CMD_ERROR, StoryPageElementID::Invalid() }; + if (!VerifyElementContentParameters(page_id, type, tile, reference, text)) return { CMD_ERROR, StoryPageElementID::Invalid() }; if (flags.Test(DoCommandFlag::Execute)) { @@ -279,7 +279,7 @@ std::tuple CmdCreateStoryPageElement(DoCommandF return { CommandCost(), pe->index }; } - return { CommandCost(), INVALID_STORY_PAGE_ELEMENT }; + return { CommandCost(), StoryPageElementID::Invalid() }; } /** @@ -368,7 +368,7 @@ CommandCost CmdShowStoryPage(DoCommandFlags flags, StoryPageID page_id) if (flags.Test(DoCommandFlag::Execute)) { StoryPage *g = StoryPage::Get(page_id); - if ((g->company != INVALID_COMPANY && g->company == _local_company) || (g->company == INVALID_COMPANY && Company::IsValidID(_local_company))) ShowStoryBook(_local_company, page_id, true); + if ((g->company != CompanyID::Invalid() && g->company == _local_company) || (g->company == CompanyID::Invalid() && Company::IsValidID(_local_company))) ShowStoryBook(_local_company, page_id, true); } return CommandCost(); @@ -440,7 +440,7 @@ CommandCost CmdStoryPageButton(DoCommandFlags flags, TileIndex tile, StoryPageEl /* Check the player belongs to the company that owns the page. */ const StoryPage *const sp = StoryPage::Get(pe->page); - if (sp->company != INVALID_COMPANY && sp->company != _current_company) return CMD_ERROR; + if (sp->company != CompanyID::Invalid() && sp->company != _current_company) return CMD_ERROR; switch (pe->type) { case SPET_BUTTON_PUSH: diff --git a/src/story_base.h b/src/story_base.h index c784944055..459a2bae2f 100644 --- a/src/story_base.h +++ b/src/story_base.h @@ -164,7 +164,7 @@ struct StoryPageElement : StoryPageElementPool::PoolItem<&_story_page_element_po struct StoryPage : StoryPagePool::PoolItem<&_story_page_pool> { uint32_t sort_value; ///< A number that increases for every created story page. Used for sorting. The id of a story page is the pool index. TimerGameCalendar::Date date; ///< Date when the page was created. - CompanyID company; ///< StoryPage is for a specific company; INVALID_COMPANY if it is global + CompanyID company; ///< StoryPage is for a specific company; CompanyID::Invalid() if it is global std::string title; ///< Title of story page diff --git a/src/story_gui.cpp b/src/story_gui.cpp index e95542f65f..e925ae59b3 100644 --- a/src/story_gui.cpp +++ b/src/story_gui.cpp @@ -124,7 +124,7 @@ protected: */ bool IsPageAvailable(const StoryPage *page) const { - return page->company == INVALID_COMPANY || page->company == this->window_number; + return page->company == CompanyID::Invalid() || page->company == this->window_number; } /** @@ -191,7 +191,7 @@ protected: this->story_page_elements.ForceRebuild(); this->BuildStoryPageElementList(); - if (this->active_button_id != INVALID_STORY_PAGE_ELEMENT) ResetObjectToPlace(); + if (this->active_button_id != StoryPageElementID::Invalid()) ResetObjectToPlace(); this->vscroll->SetCount(this->GetContentHeight()); this->SetWidgetDirty(WID_SB_SCROLLBAR); @@ -551,18 +551,18 @@ protected: break; case SPET_BUTTON_PUSH: - if (this->active_button_id != INVALID_STORY_PAGE_ELEMENT) ResetObjectToPlace(); + if (this->active_button_id != StoryPageElementID::Invalid()) ResetObjectToPlace(); this->active_button_id = pe.index; this->SetTimeout(); this->SetWidgetDirty(WID_SB_PAGE_PANEL); - Command::Post(TileIndex{}, pe.index, INVALID_VEHICLE); + Command::Post(TileIndex{}, pe.index, VehicleID::Invalid()); break; case SPET_BUTTON_TILE: if (this->active_button_id == pe.index) { ResetObjectToPlace(); - this->active_button_id = INVALID_STORY_PAGE_ELEMENT; + this->active_button_id = StoryPageElementID::Invalid(); } else { CursorID cursor = TranslateStoryPageButtonCursor(StoryPageButtonData{ pe.referenced_id }.GetCursor()); SetObjectToPlaceWnd(cursor, PAL_NONE, HT_RECT, this); @@ -574,7 +574,7 @@ protected: case SPET_BUTTON_VEHICLE: if (this->active_button_id == pe.index) { ResetObjectToPlace(); - this->active_button_id = INVALID_STORY_PAGE_ELEMENT; + this->active_button_id = StoryPageElementID::Invalid(); } else { CursorID cursor = TranslateStoryPageButtonCursor(StoryPageButtonData{ pe.referenced_id }.GetCursor()); SetObjectToPlaceWnd(cursor, PAL_NONE, HT_VEHICLE, this); @@ -607,9 +607,9 @@ public: /* Initialize selected vars. */ this->selected_generic_title.clear(); - this->selected_page_id = INVALID_STORY_PAGE; + this->selected_page_id = StoryPageID::Invalid(); - this->active_button_id = INVALID_STORY_PAGE_ELEMENT; + this->active_button_id = StoryPageElementID::Invalid(); this->OnInvalidateData(-1); } @@ -633,7 +633,7 @@ public: { if (this->selected_page_id != page_index) { if (this->active_button_id != 0) ResetObjectToPlace(); - this->active_button_id = INVALID_STORY_PAGE_ELEMENT; + this->active_button_id = StoryPageElementID::Invalid(); this->selected_page_id = page_index; this->RefreshSelectedPage(); this->UpdatePrevNextDisabledState(); @@ -649,7 +649,7 @@ public: break; } case WID_SB_CAPTION: - if (this->window_number == INVALID_COMPANY) { + if (this->window_number == CompanyID::Invalid()) { SetDParam(0, STR_STORY_BOOK_SPECTATOR_CAPTION); } else { SetDParam(0, STR_STORY_BOOK_CAPTION); @@ -872,9 +872,9 @@ public: /* Verify page selection. */ if (!StoryPage::IsValidID(this->selected_page_id)) { - this->selected_page_id = INVALID_STORY_PAGE; + this->selected_page_id = StoryPageID::Invalid(); } - if (this->selected_page_id == INVALID_STORY_PAGE && !this->story_pages.empty()) { + if (this->selected_page_id == StoryPageID::Invalid() && !this->story_pages.empty()) { /* No page is selected, but there exist at least one available. * => Select first page. */ @@ -891,7 +891,7 @@ public: void OnTimeout() override { - this->active_button_id = INVALID_STORY_PAGE_ELEMENT; + this->active_button_id = StoryPageElementID::Invalid(); this->SetWidgetDirty(WID_SB_PAGE_PANEL); } @@ -900,12 +900,12 @@ public: const StoryPageElement *const pe = StoryPageElement::GetIfValid(this->active_button_id); if (pe == nullptr || pe->type != SPET_BUTTON_TILE) { ResetObjectToPlace(); - this->active_button_id = INVALID_STORY_PAGE_ELEMENT; + this->active_button_id = StoryPageElementID::Invalid(); this->SetWidgetDirty(WID_SB_PAGE_PANEL); return; } - Command::Post(tile, pe->index, INVALID_VEHICLE); + Command::Post(tile, pe->index, VehicleID::Invalid()); ResetObjectToPlace(); } @@ -914,7 +914,7 @@ public: const StoryPageElement *const pe = StoryPageElement::GetIfValid(this->active_button_id); if (pe == nullptr || pe->type != SPET_BUTTON_VEHICLE) { ResetObjectToPlace(); - this->active_button_id = INVALID_STORY_PAGE_ELEMENT; + this->active_button_id = StoryPageElementID::Invalid(); this->SetWidgetDirty(WID_SB_PAGE_PANEL); return false; } @@ -931,7 +931,7 @@ public: void OnPlaceObjectAbort() override { - this->active_button_id = INVALID_STORY_PAGE_ELEMENT; + this->active_button_id = StoryPageElementID::Invalid(); this->SetWidgetDirty(WID_SB_PAGE_PANEL); } }; @@ -1043,14 +1043,14 @@ static CursorID TranslateStoryPageButtonCursor(StoryPageButtonCursor cursor) /** * Raise or create the story book window for \a company, at page \a page_id. - * @param company 'Owner' of the story book, may be #INVALID_COMPANY. - * @param page_id Page to open, may be #INVALID_STORY_PAGE. + * @param company 'Owner' of the story book, may be #CompanyID::Invalid(). + * @param page_id Page to open, may be #StoryPageID::Invalid(). * @param centered Whether to open the window centered. */ void ShowStoryBook(CompanyID company, StoryPageID page_id, bool centered) { - if (!Company::IsValidID(company)) company = (CompanyID)INVALID_COMPANY; + if (!Company::IsValidID(company)) company = (CompanyID)CompanyID::Invalid(); StoryBookWindow *w = AllocateWindowDescFront(centered ? _story_book_gs_desc : _story_book_desc, company); - if (page_id != INVALID_STORY_PAGE) w->SetSelectedPage(page_id); + if (page_id != StoryPageID::Invalid()) w->SetSelectedPage(page_id); } diff --git a/src/story_type.h b/src/story_type.h index 3eddaf3460..3c6ad0a1a7 100644 --- a/src/story_type.h +++ b/src/story_type.h @@ -19,8 +19,5 @@ struct StoryPageElement; struct StoryPage; enum StoryPageElementType : uint8_t; -static constexpr StoryPageElementID INVALID_STORY_PAGE_ELEMENT = StoryPageElementID::Invalid(); ///< Constant representing a non-existing story page element. -static constexpr StoryPageID INVALID_STORY_PAGE = StoryPageID::Invalid(); ///< Constant representing a non-existing story page. - #endif /* STORY_TYPE_H */ diff --git a/src/subsidy.cpp b/src/subsidy.cpp index 945a00852b..89885c8e61 100644 --- a/src/subsidy.cpp +++ b/src/subsidy.cpp @@ -206,7 +206,7 @@ void CreateSubsidy(CargoType cargo_type, Source src, Source dst) s->src = src; s->dst = dst; s->remaining = SUBSIDY_OFFER_MONTHS; - s->awarded = INVALID_COMPANY; + s->awarded = CompanyID::Invalid(); std::pair references = SetupSubsidyDecodeParam(s, SubsidyDecodeParamType::NewsOffered); AddNewsItem(STR_NEWS_SERVICE_SUBSIDY_OFFERED, NewsType::Subsidies, NewsStyle::Normal, {}, references.first, references.second); diff --git a/src/subsidy_base.h b/src/subsidy_base.h index cd3020090e..62c2bca180 100644 --- a/src/subsidy_base.h +++ b/src/subsidy_base.h @@ -23,7 +23,7 @@ extern SubsidyPool _subsidy_pool; struct Subsidy : SubsidyPool::PoolItem<&_subsidy_pool> { CargoType cargo_type; ///< Cargo type involved in this subsidy, INVALID_CARGO for invalid subsidy uint16_t remaining; ///< Remaining months when this subsidy is valid - CompanyID awarded; ///< Subsidy is awarded to this company; INVALID_COMPANY if it's not awarded to anyone + CompanyID awarded; ///< Subsidy is awarded to this company; CompanyID::Invalid() if it's not awarded to anyone Source src; ///< Source of subsidised path Source dst; ///< Destination of subsidised path @@ -43,7 +43,7 @@ struct Subsidy : SubsidyPool::PoolItem<&_subsidy_pool> { */ inline bool IsAwarded() const { - return this->awarded != INVALID_COMPANY; + return this->awarded != CompanyID::Invalid(); } void AwardTo(CompanyID company); diff --git a/src/table/engines.h b/src/table/engines.h index 2e74123508..b34b2e7602 100644 --- a/src/table/engines.h +++ b/src/table/engines.h @@ -24,7 +24,7 @@ * @param f Bitmask of the climates * @note the 5 between b and f is the load amount */ -#define MT(a, b, c, d, e, f) { CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR + a, TimerGameCalendar::Year{c}, TimerGameCalendar::Year{d}, b, 5, f, INVALID_CARGO, e, 0, 8, EngineMiscFlags{}, VehicleCallbackMasks{}, 0, {}, STR_EMPTY, Ticks::CARGO_AGING_TICKS, INVALID_ENGINE } +#define MT(a, b, c, d, e, f) { CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR + a, TimerGameCalendar::Year{c}, TimerGameCalendar::Year{d}, b, 5, f, INVALID_CARGO, e, 0, 8, EngineMiscFlags{}, VehicleCallbackMasks{}, 0, {}, STR_EMPTY, Ticks::CARGO_AGING_TICKS, EngineID::Invalid() } /** * Writes the properties of a multiple-unit train into the EngineInfo struct. @@ -37,7 +37,7 @@ * @param f Bitmask of the climates * @note the 5 between b and f is the load amount */ -#define MM(a, b, c, d, e, f) { CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR + a, TimerGameCalendar::Year{c}, TimerGameCalendar::Year{d}, b, 5, f, INVALID_CARGO, e, 0, 8, EngineMiscFlags{EngineMiscFlag::RailIsMU}, VehicleCallbackMasks{}, 0, {}, STR_EMPTY, Ticks::CARGO_AGING_TICKS, INVALID_ENGINE } +#define MM(a, b, c, d, e, f) { CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR + a, TimerGameCalendar::Year{c}, TimerGameCalendar::Year{d}, b, 5, f, INVALID_CARGO, e, 0, 8, EngineMiscFlags{EngineMiscFlag::RailIsMU}, VehicleCallbackMasks{}, 0, {}, STR_EMPTY, Ticks::CARGO_AGING_TICKS, EngineID::Invalid() } /** * Writes the properties of a train carriage into the EngineInfo struct. @@ -50,7 +50,7 @@ * @see MT * @note the 5 between b and f is the load amount */ -#define MW(a, b, c, d, e, f) { CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR + a, TimerGameCalendar::Year{c}, TimerGameCalendar::Year{d}, b, 5, f, INVALID_CARGO, e, 0, 8, EngineMiscFlags{}, VehicleCallbackMasks{}, 0, {}, STR_EMPTY, Ticks::CARGO_AGING_TICKS, INVALID_ENGINE } +#define MW(a, b, c, d, e, f) { CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR + a, TimerGameCalendar::Year{c}, TimerGameCalendar::Year{d}, b, 5, f, INVALID_CARGO, e, 0, 8, EngineMiscFlags{}, VehicleCallbackMasks{}, 0, {}, STR_EMPTY, Ticks::CARGO_AGING_TICKS, EngineID::Invalid() } /** * Writes the properties of a road vehicle into the EngineInfo struct. @@ -63,7 +63,7 @@ * @param f Bitmask of the climates * @note the 5 between b and f is the load amount */ -#define MR(a, b, c, d, e, f) { CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR + a, TimerGameCalendar::Year{c}, TimerGameCalendar::Year{d}, b, 5, f, INVALID_CARGO, e, 0, 8, EngineMiscFlags{}, VehicleCallbackMasks{}, 0, {}, STR_EMPTY, Ticks::CARGO_AGING_TICKS, INVALID_ENGINE } +#define MR(a, b, c, d, e, f) { CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR + a, TimerGameCalendar::Year{c}, TimerGameCalendar::Year{d}, b, 5, f, INVALID_CARGO, e, 0, 8, EngineMiscFlags{}, VehicleCallbackMasks{}, 0, {}, STR_EMPTY, Ticks::CARGO_AGING_TICKS, EngineID::Invalid() } /** * Writes the properties of a ship into the EngineInfo struct. @@ -75,7 +75,7 @@ * @param f Bitmask of the climates * @note the 10 between b and f is the load amount */ -#define MS(a, b, c, d, e, f) { CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR + a, TimerGameCalendar::Year{c}, TimerGameCalendar::Year{d}, b, 10, f, INVALID_CARGO, e, 0, 8, EngineMiscFlags{}, VehicleCallbackMasks{}, 0, {}, STR_EMPTY, Ticks::CARGO_AGING_TICKS, INVALID_ENGINE } +#define MS(a, b, c, d, e, f) { CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR + a, TimerGameCalendar::Year{c}, TimerGameCalendar::Year{d}, b, 10, f, INVALID_CARGO, e, 0, 8, EngineMiscFlags{}, VehicleCallbackMasks{}, 0, {}, STR_EMPTY, Ticks::CARGO_AGING_TICKS, EngineID::Invalid() } /** * Writes the properties of an aeroplane into the EngineInfo struct. @@ -86,7 +86,7 @@ * @param e Bitmask of the climates * @note the 20 between b and e is the load amount */ -#define MA(a, b, c, d, e) { CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR + a, TimerGameCalendar::Year{c}, TimerGameCalendar::Year{d}, b, 20, e, INVALID_CARGO, CT_INVALID, 0, 8, EngineMiscFlags{}, VehicleCallbackMasks{}, 0, {}, STR_EMPTY, Ticks::CARGO_AGING_TICKS, INVALID_ENGINE } +#define MA(a, b, c, d, e) { CalendarTime::DAYS_TILL_ORIGINAL_BASE_YEAR + a, TimerGameCalendar::Year{c}, TimerGameCalendar::Year{d}, b, 20, e, INVALID_CARGO, CT_INVALID, 0, 8, EngineMiscFlags{}, VehicleCallbackMasks{}, 0, {}, STR_EMPTY, Ticks::CARGO_AGING_TICKS, EngineID::Invalid() } /* Climates * T = Temperate diff --git a/src/timetable_gui.cpp b/src/timetable_gui.cpp index 8f22ed1769..5b3d3208db 100644 --- a/src/timetable_gui.cpp +++ b/src/timetable_gui.cpp @@ -278,7 +278,7 @@ struct TimetableWindow : Window { int GetOrderFromTimetableWndPt(int y, [[maybe_unused]] const Vehicle *v) { int32_t sel = this->vscroll->GetScrolledRowFromWidget(y, this, WID_VT_TIMETABLE_PANEL, WidgetDimensions::scaled.framerect.top); - if (sel == INT32_MAX) return INVALID_ORDER.base(); + if (sel == INT32_MAX) return OrderID::Invalid().base(); assert(IsInsideBS(sel, 0, v->GetNumOrders() * 2)); return sel; } @@ -645,7 +645,7 @@ struct TimetableWindow : Window { int selected = GetOrderFromTimetableWndPt(pt.y, v); this->CloseChildWindows(); - this->sel_index = (selected == INVALID_ORDER.base() || selected == this->sel_index) ? -1 : selected; + this->sel_index = (selected == OrderID::Invalid().base() || selected == this->sel_index) ? -1 : selected; break; } diff --git a/src/toolbar_gui.cpp b/src/toolbar_gui.cpp index 4e0e78658b..4bde8fbab6 100644 --- a/src/toolbar_gui.cpp +++ b/src/toolbar_gui.cpp @@ -173,7 +173,7 @@ static void PopupMainCompanyToolbMenu(Window *w, WidgetID widget, CompanyMask gr break; } - for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; ++c) { + for (CompanyID c = CompanyID::Begin(); c < MAX_COMPANIES; ++c) { if (!Company::IsValidID(c)) continue; list.push_back(std::make_unique(c, grey.Test(c))); } @@ -615,7 +615,7 @@ static CallBackFunction ToolbarStoryClick(Window *w) */ static CallBackFunction MenuClickStory(int index) { - ShowStoryBook(index == CTMN_SPECTATOR ? INVALID_COMPANY : (CompanyID)index); + ShowStoryBook(index == CTMN_SPECTATOR ? CompanyID::Invalid() : (CompanyID)index); return CBF_NONE; } @@ -635,7 +635,7 @@ static CallBackFunction ToolbarGoalClick(Window *w) */ static CallBackFunction MenuClickGoal(int index) { - ShowGoalsList(index == CTMN_SPECTATOR ? INVALID_COMPANY : (CompanyID)index); + ShowGoalsList(index == CTMN_SPECTATOR ? CompanyID::Invalid() : (CompanyID)index); return CBF_NONE; } @@ -1164,7 +1164,7 @@ static CallBackFunction MenuClickHelp(int index) case 0: return PlaceLandBlockInfo(); case 1: ShowHelpWindow(); break; case 2: IConsoleSwitch(); break; - case 3: ShowScriptDebugWindow(INVALID_COMPANY, _ctrl_pressed); break; + case 3: ShowScriptDebugWindow(CompanyID::Invalid(), _ctrl_pressed); break; case 4: ShowScreenshotWindow(); break; case 5: ShowFramerateWindow(); break; case 6: ShowAboutWindow(); break; diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index fac2ae7f59..9b04ba493a 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -2063,7 +2063,7 @@ static void DoCreateTown(Town *t, TileIndex tile, uint32_t townnameparts, TownSi for (uint i = 0; i != MAX_COMPANIES; i++) t->ratings[i] = RATING_INITIAL; t->have_ratings = {}; - t->exclusivity = INVALID_COMPANY; + t->exclusivity = CompanyID::Invalid(); t->exclusive_counter = 0; t->statues = {}; @@ -2156,37 +2156,37 @@ std::tuple CmdFoundTown(DoCommandFlags flags, TileIn { TownNameParams par(_settings_game.game_creation.town_name); - if (size >= TSZ_END) return { CMD_ERROR, 0, INVALID_TOWN }; - if (layout >= NUM_TLS) return { CMD_ERROR, 0, INVALID_TOWN }; + if (size >= TSZ_END) return { CMD_ERROR, 0, TownID::Invalid() }; + if (layout >= NUM_TLS) return { CMD_ERROR, 0, TownID::Invalid() }; /* Some things are allowed only in the scenario editor and for game scripts. */ if (_game_mode != GM_EDITOR && _current_company != OWNER_DEITY) { - if (_settings_game.economy.found_town == TF_FORBIDDEN) return { CMD_ERROR, 0, INVALID_TOWN }; - if (size == TSZ_LARGE) return { CMD_ERROR, 0, INVALID_TOWN }; - if (random_location) return { CMD_ERROR, 0, INVALID_TOWN }; + if (_settings_game.economy.found_town == TF_FORBIDDEN) return { CMD_ERROR, 0, TownID::Invalid() }; + if (size == TSZ_LARGE) return { CMD_ERROR, 0, TownID::Invalid() }; + if (random_location) return { CMD_ERROR, 0, TownID::Invalid() }; if (_settings_game.economy.found_town != TF_CUSTOM_LAYOUT && layout != _settings_game.economy.town_layout) { - return { CMD_ERROR, 0, INVALID_TOWN }; + return { CMD_ERROR, 0, TownID::Invalid() }; } } else if (_current_company == OWNER_DEITY && random_location) { /* Random parameter is not allowed for Game Scripts. */ - return { CMD_ERROR, 0, INVALID_TOWN }; + return { CMD_ERROR, 0, TownID::Invalid() }; } if (text.empty()) { /* If supplied name is empty, townnameparts has to generate unique automatic name */ - if (!VerifyTownName(townnameparts, &par)) return { CommandCost(STR_ERROR_NAME_MUST_BE_UNIQUE), 0, INVALID_TOWN }; + if (!VerifyTownName(townnameparts, &par)) return { CommandCost(STR_ERROR_NAME_MUST_BE_UNIQUE), 0, TownID::Invalid() }; } else { /* If name is not empty, it has to be unique custom name */ - if (Utf8StringLength(text) >= MAX_LENGTH_TOWN_NAME_CHARS) return { CMD_ERROR, 0, INVALID_TOWN }; - if (!IsUniqueTownName(text)) return { CommandCost(STR_ERROR_NAME_MUST_BE_UNIQUE), 0, INVALID_TOWN }; + if (Utf8StringLength(text) >= MAX_LENGTH_TOWN_NAME_CHARS) return { CMD_ERROR, 0, TownID::Invalid() }; + if (!IsUniqueTownName(text)) return { CommandCost(STR_ERROR_NAME_MUST_BE_UNIQUE), 0, TownID::Invalid() }; } /* Allocate town struct */ - if (!Town::CanAllocateItem()) return { CommandCost(STR_ERROR_TOO_MANY_TOWNS), 0, INVALID_TOWN }; + if (!Town::CanAllocateItem()) return { CommandCost(STR_ERROR_TOO_MANY_TOWNS), 0, TownID::Invalid() }; if (!random_location) { CommandCost ret = TownCanBePlacedHere(tile); - if (ret.Failed()) return { ret, 0, INVALID_TOWN }; + if (ret.Failed()) return { ret, 0, TownID::Invalid() }; } static const uint8_t price_mult[][TSZ_RANDOM + 1] = {{ 15, 25, 40, 25 }, { 20, 35, 55, 35 }}; @@ -2199,10 +2199,10 @@ std::tuple CmdFoundTown(DoCommandFlags flags, TileIn cost.MultiplyCost(mult); /* Create the town */ - TownID new_town = INVALID_TOWN; + TownID new_town = TownID::Invalid(); if (flags.Test(DoCommandFlag::Execute)) { if (cost.GetCost() > GetAvailableMoneyForCommand()) { - return { CommandCost(EXPENSES_OTHER), cost.GetCost(), INVALID_TOWN }; + return { CommandCost(EXPENSES_OTHER), cost.GetCost(), TownID::Invalid() }; } Backup old_generating_world(_generating_world, true); @@ -2218,7 +2218,7 @@ std::tuple CmdFoundTown(DoCommandFlags flags, TileIn UpdateNearestTownForRoadTiles(false); old_generating_world.Restore(); - if (t == nullptr) return { CommandCost(STR_ERROR_NO_SPACE_FOR_TOWN), 0, INVALID_TOWN }; + if (t == nullptr) return { CommandCost(STR_ERROR_NO_SPACE_FOR_TOWN), 0, TownID::Invalid() }; new_town = t->index; @@ -3555,7 +3555,7 @@ static CommandCost TownActionBuyRights(Town *t, DoCommandFlags flags) { /* Check if it's allowed to buy the rights */ if (!_settings_game.economy.exclusive_rights) return CMD_ERROR; - if (t->exclusivity != INVALID_COMPANY) return CMD_ERROR; + if (t->exclusivity != CompanyID::Invalid()) return CMD_ERROR; if (flags.Test(DoCommandFlag::Execute)) { t->exclusive_counter = 12; @@ -3612,8 +3612,8 @@ static CommandCost TownActionBribe(Town *t, DoCommandFlags flags) } } else { ChangeTownRating(t, RATING_BRIBE_UP_STEP, RATING_BRIBE_MAXIMUM, DoCommandFlag::Execute); - if (t->exclusivity != _current_company && t->exclusivity != INVALID_COMPANY) { - t->exclusivity = INVALID_COMPANY; + if (t->exclusivity != _current_company && t->exclusivity != CompanyID::Invalid()) { + t->exclusivity = CompanyID::Invalid(); t->exclusive_counter = 0; } } @@ -3938,8 +3938,8 @@ Town *ClosestTownFromTile(TileIndex tile, uint threshold) if (!HasTownOwnedRoad(tile)) { TownID tid = GetTownIndex(tile); - if (tid == INVALID_TOWN) { - /* in the case we are generating "many random towns", this value may be INVALID_TOWN */ + if (tid == TownID::Invalid()) { + /* in the case we are generating "many random towns", this value may be TownID::Invalid() */ if (_generating_world) return CalcClosestTownFromTile(tile, threshold); assert(Town::GetNumItems() == 0); return nullptr; @@ -4083,7 +4083,7 @@ static IntervalTimer _economy_towns_monthly({TimerGameEconomy: if (t->fund_buildings_months != 0) t->fund_buildings_months--; if (t->exclusive_counter != 0) { - if (--t->exclusive_counter == 0) t->exclusivity = INVALID_COMPANY; + if (--t->exclusive_counter == 0) t->exclusivity = CompanyID::Invalid(); } /* Check for active failed bribe cooloff periods and decrement them. */ diff --git a/src/town_type.h b/src/town_type.h index b2ed127d26..8925b8d9af 100644 --- a/src/town_type.h +++ b/src/town_type.h @@ -14,7 +14,6 @@ #include "core/pool_type.hpp" using TownID = PoolID; -static constexpr TownID INVALID_TOWN = TownID::Invalid(); struct Town; diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index f4e5296237..ed17b297c7 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -112,7 +112,7 @@ void Train::ConsistChanged(ConsistChangeFlags allowed_changes) assert(this->IsFrontEngine() || this->IsFreeWagon()); const RailVehicleInfo *rvi_v = RailVehInfo(this->engine_type); - EngineID first_engine = this->IsFrontEngine() ? this->engine_type : INVALID_ENGINE; + EngineID first_engine = this->IsFrontEngine() ? this->engine_type : EngineID::Invalid(); this->gcache.cached_total_length = 0; this->compatible_railtypes = RAILTYPES_NONE; @@ -126,7 +126,7 @@ void Train::ConsistChanged(ConsistChangeFlags allowed_changes) assert(u->First() == this); /* update the 'first engine' */ - u->gcache.first_engine = this == u ? INVALID_ENGINE : first_engine; + u->gcache.first_engine = this == u ? EngineID::Invalid() : first_engine; u->railtype = rvi_u->railtype; if (u->IsEngine()) first_engine = u->engine_type; @@ -624,7 +624,7 @@ static CommandCost CmdBuildRailWagon(DoCommandFlags flags, TileIndex tile, const v->spritenum = rvi->image_index; v->engine_type = e->index; - v->gcache.first_engine = INVALID_ENGINE; // needs to be set before first callback + v->gcache.first_engine = EngineID::Invalid(); // needs to be set before first callback DiagDirection dir = GetRailDepotDirection(tile); @@ -775,11 +775,11 @@ CommandCost CmdBuildRailVehicle(DoCommandFlags flags, TileIndex tile, const Engi assert(IsValidCargoType(v->cargo_type)); v->cargo_cap = rvi->capacity; v->refit_cap = 0; - v->last_station_visited = INVALID_STATION; - v->last_loading_station = INVALID_STATION; + v->last_station_visited = StationID::Invalid(); + v->last_loading_station = StationID::Invalid(); v->engine_type = e->index; - v->gcache.first_engine = INVALID_ENGINE; // needs to be set before first callback + v->gcache.first_engine = EngineID::Invalid(); // needs to be set before first callback v->reliability = e->reliability; v->reliability_spd_dec = e->reliability_spd_dec; @@ -1033,7 +1033,7 @@ static CommandCost CheckTrainAttachment(Train *t) if (!t->IsArticulatedPart() && !t->IsRearDualheaded()) { /* Back up and clear the first_engine data to avoid using wagon override group */ EngineID first_engine = t->gcache.first_engine; - t->gcache.first_engine = INVALID_ENGINE; + t->gcache.first_engine = EngineID::Invalid(); /* We don't want the cache to interfere. head's cache is cleared before * the loop and after each callback does not need to be cleared here. */ @@ -1184,7 +1184,7 @@ static void NormaliseTrainHead(Train *head) * @param flags type of operation * Note: DoCommandFlag::AutoReplace is set when autoreplace tries to undo its modifications or moves vehicles to temporary locations inside the depot. * @param src_veh source vehicle index - * @param dest_veh what wagon to put the source wagon AFTER, XXX - INVALID_VEHICLE to make a new line + * @param dest_veh what wagon to put the source wagon AFTER, XXX - VehicleID::Invalid() to make a new line * @param move_chain move all vehicles following the source vehicle * @return the cost of this operation or an error */ @@ -1201,7 +1201,7 @@ CommandCost CmdMoveRailVehicle(DoCommandFlags flags, VehicleID src_veh, VehicleI /* if nothing is selected as destination, try and find a matching vehicle to drag to. */ Train *dst; - if (dest_veh == INVALID_VEHICLE) { + if (dest_veh == VehicleID::Invalid()) { dst = (src->IsEngine() || flags.Test(DoCommandFlag::AutoReplace)) ? nullptr : FindGoodVehiclePos(src); } else { dst = Train::GetIfValid(dest_veh); @@ -2388,7 +2388,7 @@ void FreeTrainTrackReservation(const Train *v) TileIndex tile = v->tile; Trackdir td = v->GetVehicleTrackdir(); bool free_tile = !(IsRailStationTile(v->tile) || IsTileType(v->tile, MP_TUNNELBRIDGE)); - StationID station_id = IsRailStationTile(v->tile) ? GetStationIndex(v->tile) : INVALID_STATION; + StationID station_id = IsRailStationTile(v->tile) ? GetStationIndex(v->tile) : StationID::Invalid(); /* Can't be holding a reservation if we enter a depot. */ if (IsRailDepotTile(tile) && TrackdirToExitdir(td) != GetRailDepotDirection(tile)) return; @@ -2948,7 +2948,7 @@ static bool CheckReverseTrain(const Train *v) */ TileIndex Train::GetOrderStationLocation(StationID station) { - if (station == this->last_station_visited) this->last_station_visited = INVALID_STATION; + if (station == this->last_station_visited) this->last_station_visited = StationID::Invalid(); const Station *st = Station::Get(station); if (!st->facilities.Test(StationFacility::Train)) { diff --git a/src/train_gui.cpp b/src/train_gui.cpp index 8ed12f9c22..daf28ff239 100644 --- a/src/train_gui.cpp +++ b/src/train_gui.cpp @@ -61,7 +61,7 @@ static int HighlightDragPosition(int px, int max_width, int y, VehicleID selecti { bool rtl = _current_text_dir == TD_RTL; - assert(selection != INVALID_VEHICLE); + assert(selection != VehicleID::Invalid()); int dragged_width = 0; for (Train *t = Train::Get(selection); t != nullptr; t = chain ? t->Next() : (t->HasArticulatedPart() ? t->GetNextArticulatedPart() : nullptr)) { dragged_width += t->GetDisplayImageWidth(nullptr); @@ -88,7 +88,7 @@ static int HighlightDragPosition(int px, int max_width, int y, VehicleID selecti * @param r Rect to draw at * @param selection Selected vehicle to draw a frame around * @param skip Number of pixels to skip at the front (for scrolling) - * @param drag_dest The vehicle another one is dragged over, \c INVALID_VEHICLE if none. + * @param drag_dest The vehicle another one is dragged over, \c VehicleID::Invalid() if none. */ void DrawTrainImage(const Train *v, const Rect &r, VehicleID selection, EngineImageType image_type, int skip, VehicleID drag_dest) { @@ -113,7 +113,7 @@ void DrawTrainImage(const Train *v, const Rect &r, VehicleID selection, EngineIm int px = rtl ? max_width + skip : -skip; int y = r.Height() / 2; bool sel_articulated = false; - bool dragging = (drag_dest != INVALID_VEHICLE); + bool dragging = (drag_dest != VehicleID::Invalid()); bool drag_at_end_of_train = (drag_dest == v->index); // Head index is used to mark dragging at end of train. for (; v != nullptr && (rtl ? px > 0 : px < max_width); v = v->Next()) { if (dragging && !drag_at_end_of_train && drag_dest == v->index) { @@ -288,12 +288,12 @@ static void GetCargoSummaryOfArticulatedVehicle(const Train *v, CargoSummary &su item->subtype = new_item.subtype; item->capacity = 0; item->amount = 0; - item->source = INVALID_STATION; + item->source = StationID::Invalid(); } item->capacity += v->cargo_cap; item->amount += v->cargo.StoredCount(); - if (item->source == INVALID_STATION) item->source = v->cargo.GetFirstStation(); + if (item->source == StationID::Invalid()) item->source = v->cargo.GetFirstStation(); } while ((v = v->Next()) != nullptr && v->IsArticulatedPart()); } diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 2bc7d1a421..564bd116b2 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -227,7 +227,7 @@ bool Vehicle::NeedsServicing() const EngineID new_engine = EngineReplacementForCompany(c, v->engine_type, v->group_id, &replace_when_old); /* Check engine availability */ - if (new_engine == INVALID_ENGINE || !Engine::Get(new_engine)->company_avail.Test(v->owner)) continue; + if (new_engine == EngineID::Invalid() || !Engine::Get(new_engine)->company_avail.Test(v->owner)) continue; /* Is the vehicle old if we are not always replacing? */ if (replace_when_old && !v->NeedsAutorenewing(c, false)) continue; @@ -365,8 +365,8 @@ Vehicle::Vehicle(VehicleType type) this->first = this; this->colourmap = PAL_NONE; this->cargo_age_counter = 1; - this->last_station_visited = INVALID_STATION; - this->last_loading_station = INVALID_STATION; + this->last_station_visited = StationID::Invalid(); + this->last_loading_station = StationID::Invalid(); } /* Size of the hash, 6 = 64 x 64, 7 = 128 x 128. Larger sizes will (in theory) reduce hash @@ -829,7 +829,7 @@ void Vehicle::PreDestructor() st->loading_vehicles.remove(this); HideFillingPercent(&this->fill_percent_te_id); - this->CancelReservation(INVALID_STATION, st); + this->CancelReservation(StationID::Invalid(), st); delete this->cargo_payment; assert(this->cargo_payment == nullptr); // cleared by ~CargoPayment } @@ -862,7 +862,7 @@ void Vehicle::PreDestructor() RoadStop::GetByTile(v->tile, GetRoadStopType(v->tile))->Leave(v); } - if (v->disaster_vehicle != INVALID_VEHICLE) ReleaseDisasterVehicle(v->disaster_vehicle); + if (v->disaster_vehicle != VehicleID::Invalid()) ReleaseDisasterVehicle(v->disaster_vehicle); } if (this->Previous() == nullptr) { @@ -1653,7 +1653,7 @@ void VehicleEnterDepot(Vehicle *v) /* Invalidate last_loading_station. As the link from the station * before the stop to the station after the stop can't be predicted * we shouldn't construct it when the vehicle visits the next stop. */ - v->last_loading_station = INVALID_STATION; + v->last_loading_station = StationID::Invalid(); /* Clear unbunching data. */ v->ResetDepotUnbunching(); @@ -1960,7 +1960,7 @@ bool CanBuildVehicleInfrastructure(VehicleType type, uint8_t subtype) /** * Determines the #LiveryScheme for a vehicle. * @param engine_type Engine of the vehicle. - * @param parent_engine_type Engine of the front vehicle, #INVALID_ENGINE if vehicle is at front itself. + * @param parent_engine_type Engine of the front vehicle, #EngineID::Invalid() if vehicle is at front itself. * @param v the vehicle, \c nullptr if in purchase list etc. * @return livery scheme to use. */ @@ -1971,7 +1971,7 @@ LiveryScheme GetEngineLiveryScheme(EngineID engine_type, EngineID parent_engine_ switch (e->type) { default: NOT_REACHED(); case VEH_TRAIN: - if (v != nullptr && parent_engine_type != INVALID_ENGINE && (UsesWagonOverride(v) || (v->IsArticulatedPart() && e->u.rail.railveh_type != RAILVEH_WAGON))) { + if (v != nullptr && parent_engine_type != EngineID::Invalid() && (UsesWagonOverride(v) || (v->IsArticulatedPart() && e->u.rail.railveh_type != RAILVEH_WAGON))) { /* Wagonoverrides use the colour scheme of the front engine. * Articulated parts use the colour scheme of the first part. (Not supported for articulated wagons) */ engine_type = parent_engine_type; @@ -1984,7 +1984,7 @@ LiveryScheme GetEngineLiveryScheme(EngineID engine_type, EngineID parent_engine_ assert(IsValidCargoType(cargo_type)); if (e->u.rail.railveh_type == RAILVEH_WAGON) { if (!CargoSpec::Get(cargo_type)->is_freight) { - if (parent_engine_type == INVALID_ENGINE) { + if (parent_engine_type == EngineID::Invalid()) { return LS_PASSENGER_WAGON_STEAM; } else { bool is_mu = EngInfo(parent_engine_type)->misc_flags.Test(EngineMiscFlag::RailIsMU); @@ -2015,7 +2015,7 @@ LiveryScheme GetEngineLiveryScheme(EngineID engine_type, EngineID parent_engine_ case VEH_ROAD: /* Always use the livery of the front */ - if (v != nullptr && parent_engine_type != INVALID_ENGINE) { + if (v != nullptr && parent_engine_type != EngineID::Invalid()) { engine_type = parent_engine_type; e = Engine::Get(engine_type); cargo_type = v->First()->cargo_type; @@ -2053,7 +2053,7 @@ LiveryScheme GetEngineLiveryScheme(EngineID engine_type, EngineID parent_engine_ * Determines the livery for a vehicle. * @param engine_type EngineID of the vehicle * @param company Owner of the vehicle - * @param parent_engine_type EngineID of the front vehicle. INVALID_VEHICLE if vehicle is at front itself. + * @param parent_engine_type EngineID of the front vehicle. VehicleID::Invalid() if vehicle is at front itself. * @param v the vehicle. nullptr if in purchase list etc. * @param livery_setting The livery settings to use for acquiring the livery information. * @return livery to use @@ -2068,7 +2068,7 @@ const Livery *GetEngineLivery(EngineID engine_type, CompanyID company, EngineID const Group *g = Group::GetIfValid(v->First()->group_id); if (g != nullptr) { /* Traverse parents until we find a livery or reach the top */ - while (g->livery.in_use == 0 && g->parent != INVALID_GROUP) { + while (g->livery.in_use == 0 && g->parent != GroupID::Invalid()) { g = Group::Get(g->parent); } if (g->livery.in_use != 0) return &g->livery; @@ -2138,7 +2138,7 @@ static PaletteID GetEngineColourMap(EngineID engine_type, CompanyID company, Eng */ PaletteID GetEnginePalette(EngineID engine_type, CompanyID company) { - return GetEngineColourMap(engine_type, company, INVALID_ENGINE, nullptr); + return GetEngineColourMap(engine_type, company, EngineID::Invalid(), nullptr); } /** @@ -2152,7 +2152,7 @@ PaletteID GetVehiclePalette(const Vehicle *v) return GetEngineColourMap(v->engine_type, v->owner, v->GetGroundVehicleCache()->first_engine, v); } - return GetEngineColourMap(v->engine_type, v->owner, INVALID_ENGINE, v); + return GetEngineColourMap(v->engine_type, v->owner, EngineID::Invalid(), v); } /** @@ -2304,7 +2304,7 @@ void Vehicle::BeginLoading() this->current_order.MakeLoading(false); } - if (this->last_loading_station != INVALID_STATION && + if (this->last_loading_station != StationID::Invalid() && this->last_loading_station != this->last_station_visited && ((this->current_order.GetLoadType() & OLFB_NO_LOAD) == 0 || (this->current_order.GetUnloadType() & OUFB_NO_UNLOAD) == 0)) { @@ -2356,7 +2356,7 @@ void Vehicle::LeaveStation() if ((this->current_order.GetLoadType() & OLFB_NO_LOAD) == 0 || (this->current_order.GetUnloadType() & OUFB_NO_UNLOAD) == 0) { - if (this->current_order.CanLeaveWithCargo(this->last_loading_station != INVALID_STATION)) { + if (this->current_order.CanLeaveWithCargo(this->last_loading_station != StationID::Invalid())) { /* Refresh next hop stats to make sure we've done that at least once * during the stop and that refit_cap == cargo_cap for each vehicle in * the consist. */ @@ -2369,13 +2369,13 @@ void Vehicle::LeaveStation() } else { /* if the vehicle couldn't load and had to unload or transfer everything * set the last loading station to invalid as it will leave empty. */ - this->last_loading_station = INVALID_STATION; + this->last_loading_station = StationID::Invalid(); } } this->current_order.MakeLeaveStation(); Station *st = Station::Get(this->last_station_visited); - this->CancelReservation(INVALID_STATION, st); + this->CancelReservation(StationID::Invalid(), st); st->loading_vehicles.remove(this); HideFillingPercent(&this->fill_percent_te_id); diff --git a/src/vehicle_base.h b/src/vehicle_base.h index 6c2ea473d2..a64357b3f7 100644 --- a/src/vehicle_base.h +++ b/src/vehicle_base.h @@ -739,11 +739,11 @@ public: /** * Get the next station the vehicle will stop at. - * @return ID of the next station the vehicle will stop at or INVALID_STATION. + * @return ID of the next station the vehicle will stop at or StationID::Invalid(). */ inline StationIDStack GetNextStoppingStation() const { - return (this->orders == nullptr) ? INVALID_STATION.base() : this->orders->GetNextStoppingStation(this); + return (this->orders == nullptr) ? StationID::Invalid().base() : this->orders->GetNextStoppingStation(this); } void ResetRefitCaps(); diff --git a/src/vehicle_cmd.cpp b/src/vehicle_cmd.cpp index 5c8c55461a..0dfd0ceac7 100644 --- a/src/vehicle_cmd.cpp +++ b/src/vehicle_cmd.cpp @@ -101,22 +101,22 @@ const StringID _send_to_depot_msg_table[] = { std::tuple CmdBuildVehicle(DoCommandFlags flags, TileIndex tile, EngineID eid, bool use_free_vehicles, CargoType cargo, ClientID client_id) { /* Elementary check for valid location. */ - if (!IsDepotTile(tile) || !IsTileOwner(tile, _current_company)) return { CMD_ERROR, INVALID_VEHICLE, 0, 0, {} }; + if (!IsDepotTile(tile) || !IsTileOwner(tile, _current_company)) return { CMD_ERROR, VehicleID::Invalid(), 0, 0, {} }; VehicleType type = GetDepotVehicleType(tile); /* Validate the engine type. */ - if (!IsEngineBuildable(eid, type, _current_company)) return { CommandCost(STR_ERROR_RAIL_VEHICLE_NOT_AVAILABLE + type), INVALID_VEHICLE, 0, 0, {} }; + if (!IsEngineBuildable(eid, type, _current_company)) return { CommandCost(STR_ERROR_RAIL_VEHICLE_NOT_AVAILABLE + type), VehicleID::Invalid(), 0, 0, {} }; /* Validate the cargo type. */ - if (cargo >= NUM_CARGO && IsValidCargoType(cargo)) return { CMD_ERROR, INVALID_VEHICLE, 0, 0, {} }; + if (cargo >= NUM_CARGO && IsValidCargoType(cargo)) return { CMD_ERROR, VehicleID::Invalid(), 0, 0, {} }; const Engine *e = Engine::Get(eid); CommandCost value(EXPENSES_NEW_VEHICLES, e->GetCost()); /* Engines without valid cargo should not be available */ CargoType default_cargo = e->GetDefaultCargoType(); - if (!IsValidCargoType(default_cargo)) return { CMD_ERROR, INVALID_VEHICLE, 0, 0, {} }; + if (!IsValidCargoType(default_cargo)) return { CMD_ERROR, VehicleID::Invalid(), 0, 0, {} }; bool refitting = IsValidCargoType(cargo) && cargo != default_cargo; @@ -129,13 +129,13 @@ std::tuple CmdBuildVehicle(D case VEH_AIRCRAFT: num_vehicles = e->u.air.subtype & AIR_CTOL ? 2 : 3; break; default: NOT_REACHED(); // Safe due to IsDepotTile() } - if (!Vehicle::CanAllocateItem(num_vehicles)) return { CommandCost(STR_ERROR_TOO_MANY_VEHICLES_IN_GAME), INVALID_VEHICLE, 0, 0, {} }; + if (!Vehicle::CanAllocateItem(num_vehicles)) return { CommandCost(STR_ERROR_TOO_MANY_VEHICLES_IN_GAME), VehicleID::Invalid(), 0, 0, {} }; /* Check whether we can allocate a unit number. Autoreplace does not allocate * an unit number as it will (always) reuse the one of the replaced vehicle * and (train) wagons don't have an unit number in any scenario. */ UnitID unit_num = (flags.Test(DoCommandFlag::QueryCost) || flags.Test(DoCommandFlag::AutoReplace) || (type == VEH_TRAIN && e->u.rail.railveh_type == RAILVEH_WAGON)) ? 0 : GetFreeUnitNumber(type); - if (unit_num == UINT16_MAX) return { CommandCost(STR_ERROR_TOO_MANY_VEHICLES_IN_GAME), INVALID_VEHICLE, 0, 0, {} }; + if (unit_num == UINT16_MAX) return { CommandCost(STR_ERROR_TOO_MANY_VEHICLES_IN_GAME), VehicleID::Invalid(), 0, 0, {} }; /* If we are refitting we need to temporarily purchase the vehicle to be able to * test it. */ @@ -156,7 +156,7 @@ std::tuple CmdBuildVehicle(D default: NOT_REACHED(); // Safe due to IsDepotTile() } - VehicleID veh_id = INVALID_VEHICLE; + VehicleID veh_id = VehicleID::Invalid(); uint refitted_capacity = 0; uint16_t refitted_mail_capacity = 0; CargoArray cargo_capacities{}; @@ -842,7 +842,7 @@ std::tuple CmdCloneVehicle(DoCommandFlags flags, TileInd CommandCost total_cost(EXPENSES_NEW_VEHICLES); Vehicle *v = Vehicle::GetIfValid(veh_id); - if (v == nullptr || !v->IsPrimaryVehicle()) return { CMD_ERROR, INVALID_VEHICLE }; + if (v == nullptr || !v->IsPrimaryVehicle()) return { CMD_ERROR, VehicleID::Invalid() }; Vehicle *v_front = v; Vehicle *w = nullptr; Vehicle *w_front = nullptr; @@ -857,9 +857,9 @@ std::tuple CmdCloneVehicle(DoCommandFlags flags, TileInd */ CommandCost ret = CheckOwnership(v->owner); - if (ret.Failed()) return { ret, INVALID_VEHICLE }; + if (ret.Failed()) return { ret, VehicleID::Invalid() }; - if (v->type == VEH_TRAIN && (!v->IsFrontEngine() || Train::From(v)->crash_anim_pos >= 4400)) return { CMD_ERROR, INVALID_VEHICLE }; + if (v->type == VEH_TRAIN && (!v->IsFrontEngine() || Train::From(v)->crash_anim_pos >= 4400)) return { CMD_ERROR, VehicleID::Invalid() }; /* check that we can allocate enough vehicles */ if (!flags.Test(DoCommandFlag::Execute)) { @@ -869,13 +869,13 @@ std::tuple CmdCloneVehicle(DoCommandFlags flags, TileInd } while ((v = v->Next()) != nullptr); if (!Vehicle::CanAllocateItem(veh_counter)) { - return { CommandCost(STR_ERROR_TOO_MANY_VEHICLES_IN_GAME), INVALID_VEHICLE }; + return { CommandCost(STR_ERROR_TOO_MANY_VEHICLES_IN_GAME), VehicleID::Invalid() }; } } v = v_front; - VehicleID new_veh_id = INVALID_VEHICLE; + VehicleID new_veh_id = VehicleID::Invalid(); do { if (v->type == VEH_TRAIN && Train::From(v)->IsRearDualheaded()) { /* we build the rear ends of multiheaded trains with the front ones */ @@ -897,7 +897,7 @@ std::tuple CmdCloneVehicle(DoCommandFlags flags, TileInd if (cost.Failed()) { /* Can't build a part, then sell the stuff we already made; clear up the mess */ if (w_front != nullptr) Command::Do(flags, w_front->index, true, false, INVALID_CLIENT_ID); - return { cost, INVALID_VEHICLE }; + return { cost, VehicleID::Invalid() }; } total_cost.AddCost(cost); @@ -918,7 +918,7 @@ std::tuple CmdCloneVehicle(DoCommandFlags flags, TileInd * Sell what we already made (clean up) and return an error. */ Command::Do(flags, w_front->index, true, false, INVALID_CLIENT_ID); Command::Do(flags, w->index, true, false, INVALID_CLIENT_ID); - return { result, INVALID_VEHICLE }; // return error and the message returned from CMD_MOVE_RAIL_VEHICLE + return { result, VehicleID::Invalid() }; // return error and the message returned from CMD_MOVE_RAIL_VEHICLE } } else { /* this is a front engine or not a train. */ @@ -999,7 +999,7 @@ std::tuple CmdCloneVehicle(DoCommandFlags flags, TileInd if (result.Failed()) { /* The vehicle has already been bought, so now it must be sold again. */ Command::Do(flags, w_front->index, true, false, INVALID_CLIENT_ID); - return { result, INVALID_VEHICLE }; + return { result, VehicleID::Invalid() }; } /* Now clone the vehicle's name, if it has one. */ @@ -1010,7 +1010,7 @@ std::tuple CmdCloneVehicle(DoCommandFlags flags, TileInd if (!CheckCompanyHasMoney(total_cost)) { /* The vehicle has already been bought, so now it must be sold again. */ Command::Do(flags, w_front->index, true, false, INVALID_CLIENT_ID); - return { total_cost, INVALID_VEHICLE }; + return { total_cost, VehicleID::Invalid() }; } } diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp index 8cacb6f869..74ef78faab 100644 --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -164,7 +164,7 @@ const StringID BaseVehicleListWindow::vehicle_depot_name[] = { BaseVehicleListWindow::BaseVehicleListWindow(WindowDesc &desc, const VehicleListIdentifier &vli) : Window(desc), vli(vli) { - this->vehicle_sel = INVALID_VEHICLE; + this->vehicle_sel = VehicleID::Invalid(); this->grouping = _grouping[vli.type][vli.vtype]; this->UpdateSortingFromGrouping(); } @@ -442,9 +442,9 @@ void BaseVehicleListWindow::FilterVehicleList() this->vehgroups.Filter(this->cargo_filter_criteria); if (this->vehicles.empty()) { /* No vehicle passed through the filter, invalidate the previously selected vehicle */ - this->vehicle_sel = INVALID_VEHICLE; - } else if (this->vehicle_sel != INVALID_VEHICLE && std::ranges::find(this->vehicles, Vehicle::Get(this->vehicle_sel)) == this->vehicles.end()) { // previously selected engine didn't pass the filter, remove selection - this->vehicle_sel = INVALID_VEHICLE; + this->vehicle_sel = VehicleID::Invalid(); + } else if (this->vehicle_sel != VehicleID::Invalid() && std::ranges::find(this->vehicles, Vehicle::Get(this->vehicle_sel)) == this->vehicles.end()) { // previously selected engine didn't pass the filter, remove selection + this->vehicle_sel = VehicleID::Invalid(); } } @@ -1050,7 +1050,7 @@ struct RefitWindow : public Window { case WID_VR_VEHICLE_PANEL_DISPLAY: { Vehicle *v = Vehicle::Get(this->window_number); DrawVehicleImage(v, {this->sprite_left, r.top, this->sprite_right, r.bottom}, - INVALID_VEHICLE, EIT_IN_DETAILS, this->hscroll != nullptr ? this->hscroll->GetPosition() : 0); + VehicleID::Invalid(), EIT_IN_DETAILS, this->hscroll != nullptr ? this->hscroll->GetPosition() : 0); /* Highlight selected vehicles. */ if (this->order != INVALID_VEH_ORDER_ID) break; @@ -2070,7 +2070,7 @@ public: break; case WID_VL_LIST: - this->DrawVehicleListItems(INVALID_VEHICLE, this->resize.step_height, r); + this->DrawVehicleListItems(VehicleID::Invalid(), this->resize.step_height, r); break; } } @@ -2228,11 +2228,11 @@ public: break; case ADI_SERVICE: // Send for servicing case ADI_DEPOT: // Send to Depots - Command::Post(GetCmdSendToDepotMsg(this->vli.vtype), INVALID_VEHICLE, (index == ADI_SERVICE ? DepotCommandFlag::Service : DepotCommandFlags{}) | DepotCommandFlag::MassSend, this->vli); + Command::Post(GetCmdSendToDepotMsg(this->vli.vtype), VehicleID::Invalid(), (index == ADI_SERVICE ? DepotCommandFlag::Service : DepotCommandFlags{}) | DepotCommandFlag::MassSend, this->vli); break; case ADI_CREATE_GROUP: // Create group - Command::Post(CcAddVehicleNewGroup, NEW_GROUP, INVALID_VEHICLE, false, this->vli); + Command::Post(CcAddVehicleNewGroup, NEW_GROUP, VehicleID::Invalid(), false, this->vli); break; default: NOT_REACHED(); @@ -2247,7 +2247,7 @@ public: void OnGameTick() override { if (this->vehgroups.NeedResort()) { - StationID station = (this->vli.type == VL_STATION_LIST) ? this->vli.ToStationID() : INVALID_STATION; + StationID station = (this->vli.type == VL_STATION_LIST) ? this->vli.ToStationID() : StationID::Invalid(); Debug(misc, 3, "Periodic resort {} list company {} at station {}", this->vli.vtype, this->owner, station); this->SetDirty(); @@ -2698,10 +2698,10 @@ struct VehicleDetailsWindow : Window { /* Articulated road vehicles use a complete line. */ if (v->type == VEH_ROAD && v->HasArticulatedPart()) { - DrawVehicleImage(v, tr.WithHeight(ScaleGUITrad(GetVehicleHeight(v->type)), false), INVALID_VEHICLE, EIT_IN_DETAILS, 0); + DrawVehicleImage(v, tr.WithHeight(ScaleGUITrad(GetVehicleHeight(v->type)), false), VehicleID::Invalid(), EIT_IN_DETAILS, 0); } else { Rect sr = tr.WithWidth(sprite_width, rtl); - DrawVehicleImage(v, sr.WithHeight(ScaleGUITrad(GetVehicleHeight(v->type)), false), INVALID_VEHICLE, EIT_IN_DETAILS, 0); + DrawVehicleImage(v, sr.WithHeight(ScaleGUITrad(GetVehicleHeight(v->type)), false), VehicleID::Invalid(), EIT_IN_DETAILS, 0); } DrawVehicleDetails(v, tr.Indent(sprite_width, rtl), 0, 0, this->tab); @@ -3220,7 +3220,7 @@ public: SetDParam(0, v->type); SetDParam(1, v->current_order.GetDestination()); SetDParam(2, PackVelocity(v->GetDisplaySpeed(), v->type)); - if (v->current_order.GetDestination() == INVALID_DEPOT) { + if (v->current_order.GetDestination() == DepotID::Invalid()) { /* This case *only* happens when multiple nearest depot orders * follow each other (including an order list only one order: a * nearest depot order) and there are no reachable depots. @@ -3314,7 +3314,7 @@ public: /* main window 'follows' vehicle */ mainwindow->viewport->follow_vehicle = v->index; } else { - if (mainwindow->viewport->follow_vehicle == v->index) mainwindow->viewport->follow_vehicle = INVALID_VEHICLE; + if (mainwindow->viewport->follow_vehicle == v->index) mainwindow->viewport->follow_vehicle = VehicleID::Invalid(); ScrollMainWindowTo(v->x_pos, v->y_pos, v->z_pos); } } @@ -3540,7 +3540,7 @@ void StopGlobalFollowVehicle(const Vehicle *v) Window *w = GetMainWindow(); if (w->viewport->follow_vehicle == v->index) { ScrollMainWindowTo(v->x_pos, v->y_pos, v->z_pos, true); // lock the main view on the vehicle's last position - w->viewport->follow_vehicle = INVALID_VEHICLE; + w->viewport->follow_vehicle = VehicleID::Invalid(); } } diff --git a/src/vehicle_gui.h b/src/vehicle_gui.h index 262a04eeeb..2c0a167960 100644 --- a/src/vehicle_gui.h +++ b/src/vehicle_gui.h @@ -51,7 +51,7 @@ struct TestedEngineDetails { int DrawVehiclePurchaseInfo(int left, int right, int y, EngineID engine_number, TestedEngineDetails &te); -void DrawTrainImage(const Train *v, const Rect &r, VehicleID selection, EngineImageType image_type, int skip, VehicleID drag_dest = INVALID_VEHICLE); +void DrawTrainImage(const Train *v, const Rect &r, VehicleID selection, EngineImageType image_type, int skip, VehicleID drag_dest = VehicleID::Invalid()); void DrawRoadVehImage(const Vehicle *v, const Rect &r, VehicleID selection, EngineImageType image_type, int skip = 0); void DrawShipImage(const Vehicle *v, const Rect &r, VehicleID selection, EngineImageType image_type); void DrawAircraftImage(const Vehicle *v, const Rect &r, VehicleID selection, EngineImageType image_type); diff --git a/src/vehicle_type.h b/src/vehicle_type.h index 4a8fc419b8..fa640aff9b 100644 --- a/src/vehicle_type.h +++ b/src/vehicle_type.h @@ -15,7 +15,6 @@ /** The type all our vehicle IDs have. */ using VehicleID = PoolID; -static constexpr VehicleID INVALID_VEHICLE = VehicleID::Invalid(); ///< Constant representing a non-existing vehicle. static const int GROUND_ACCELERATION = 9800; ///< Acceleration due to gravity, 9.8 m/s^2 diff --git a/src/viewport.cpp b/src/viewport.cpp index bea1f333b5..3ea84802c1 100644 --- a/src/viewport.cpp +++ b/src/viewport.cpp @@ -260,7 +260,7 @@ void InitializeWindowViewport(Window *w, int x, int y, y = TileY(tile) * TILE_SIZE; pt = MapXYZToViewport(vp, x, y, GetSlopePixelZ(x, y)); } - vp->follow_vehicle = INVALID_VEHICLE; + vp->follow_vehicle = VehicleID::Invalid(); } vp->scrollpos_x = pt.x; @@ -1968,7 +1968,7 @@ void UpdateViewportPosition(Window *w, uint32_t delta_ms) { const Viewport *vp = w->viewport; - if (w->viewport->follow_vehicle != INVALID_VEHICLE) { + if (w->viewport->follow_vehicle != VehicleID::Invalid()) { const Vehicle *veh = Vehicle::Get(w->viewport->follow_vehicle); Point pt = MapXYZToViewport(vp, veh->x_pos, veh->y_pos, veh->z_pos); @@ -2530,7 +2530,7 @@ bool ScrollWindowTo(int x, int y, int z, Window *w, bool instant) } Point pt = MapXYZToViewport(w->viewport, x, y, z); - w->viewport->follow_vehicle = INVALID_VEHICLE; + w->viewport->follow_vehicle = VehicleID::Invalid(); if (w->viewport->dest_scrollpos_x == pt.x && w->viewport->dest_scrollpos_y == pt.y) return false; diff --git a/src/viewport_gui.cpp b/src/viewport_gui.cpp index a4631c73d4..046db96abb 100644 --- a/src/viewport_gui.cpp +++ b/src/viewport_gui.cpp @@ -85,7 +85,7 @@ public: /* set this view to same location. Based on the center, adjusting for zoom */ w->viewport->dest_scrollpos_x = x - (w->viewport->virtual_width - this->viewport->virtual_width) / 2; w->viewport->dest_scrollpos_y = y - (w->viewport->virtual_height - this->viewport->virtual_height) / 2; - w->viewport->follow_vehicle = INVALID_VEHICLE; + w->viewport->follow_vehicle = VehicleID::Invalid(); break; } diff --git a/src/waypoint_cmd.cpp b/src/waypoint_cmd.cpp index 1dd62ce84a..fe75aeb072 100644 --- a/src/waypoint_cmd.cpp +++ b/src/waypoint_cmd.cpp @@ -146,14 +146,14 @@ extern CommandCost ClearTile_Station(TileIndex tile, DoCommandFlags flags); static CommandCost IsValidTileForWaypoint(TileIndex tile, Axis axis, StationID *waypoint) { /* if waypoint is set, then we have special handling to allow building on top of already existing waypoints. - * so waypoint points to INVALID_STATION if we can build on any waypoint. + * so waypoint points to StationID::Invalid() if we can build on any waypoint. * Or it points to a waypoint if we're only allowed to build on exactly that waypoint. */ if (waypoint != nullptr && IsTileType(tile, MP_STATION)) { if (!IsRailWaypoint(tile)) { return ClearTile_Station(tile, DoCommandFlag::Auto); // get error message } else { StationID wp = GetStationIndex(tile); - if (*waypoint == INVALID_STATION) { + if (*waypoint == StationID::Invalid()) { *waypoint = wp; } else if (*waypoint != wp) { return CommandCost(STR_ERROR_WAYPOINT_ADJOINS_MORE_THAN_ONE_EXISTING); @@ -215,8 +215,8 @@ CommandCost CmdBuildRailWaypoint(DoCommandFlags flags, TileIndex start_tile, Axi if (count == 0 || count > _settings_game.station.station_spread) return CMD_ERROR; bool reuse = (station_to_join != NEW_STATION); - if (!reuse) station_to_join = INVALID_STATION; - bool distant_join = (station_to_join != INVALID_STATION); + if (!reuse) station_to_join = StationID::Invalid(); + bool distant_join = (station_to_join != StationID::Invalid()); if (distant_join && (!_settings_game.station.distant_join_stations || !Waypoint::IsValidID(station_to_join))) return CMD_ERROR; @@ -229,7 +229,7 @@ CommandCost CmdBuildRailWaypoint(DoCommandFlags flags, TileIndex start_tile, Axi } /* Make sure the area below consists of clear tiles. (OR tiles belonging to a certain rail station) */ - StationID est = INVALID_STATION; + StationID est = StationID::Invalid(); /* Check whether the tiles we're building on are valid rail or not. */ TileIndexDiff offset = TileOffsByAxis(OtherAxis(axis)); @@ -349,8 +349,8 @@ CommandCost CmdBuildRoadWaypoint(DoCommandFlags flags, TileIndex start_tile, Axi if (count == 0 || count > _settings_game.station.station_spread) return CMD_ERROR; bool reuse = (station_to_join != NEW_STATION); - if (!reuse) station_to_join = INVALID_STATION; - bool distant_join = (station_to_join != INVALID_STATION); + if (!reuse) station_to_join = StationID::Invalid(); + bool distant_join = (station_to_join != StationID::Invalid()); if (distant_join && (!_settings_game.station.distant_join_stations || !Waypoint::IsValidID(station_to_join))) return CMD_ERROR; @@ -363,7 +363,7 @@ CommandCost CmdBuildRoadWaypoint(DoCommandFlags flags, TileIndex start_tile, Axi } else { unit_cost = _price[PR_BUILD_STATION_TRUCK]; } - StationID est = INVALID_STATION; + StationID est = StationID::Invalid(); CommandCost cost = CalculateRoadStopCost(roadstop_area, flags, true, StationType::RoadWaypoint, axis, AxisToDiagDir(axis), &est, INVALID_ROADTYPE, unit_cost); if (cost.Failed()) return cost; diff --git a/src/window.cpp b/src/window.cpp index 6fce13f1d7..760f6486c1 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -2369,7 +2369,7 @@ static EventState HandleViewportScroll() return ES_NOT_HANDLED; } - if (_last_scroll_window == GetMainWindow() && _last_scroll_window->viewport->follow_vehicle != INVALID_VEHICLE) { + if (_last_scroll_window == GetMainWindow() && _last_scroll_window->viewport->follow_vehicle != VehicleID::Invalid()) { /* If the main window is following a vehicle, then first let go of it! */ const Vehicle *veh = Vehicle::Get(_last_scroll_window->viewport->follow_vehicle); ScrollMainWindowTo(veh->x_pos, veh->y_pos, veh->z_pos, true); // This also resets follow_vehicle @@ -2691,17 +2691,17 @@ static void HandleAutoscroll() /* If we succeed at scrolling in any direction, stop following a vehicle. */ static const int SCROLLSPEED = 3; if (x - 15 < 0) { - w->viewport->follow_vehicle = INVALID_VEHICLE; + w->viewport->follow_vehicle = VehicleID::Invalid(); w->viewport->dest_scrollpos_x += ScaleByZoom((x - 15) * SCROLLSPEED, vp->zoom); } else if (15 - (vp->width - x) > 0) { - w->viewport->follow_vehicle = INVALID_VEHICLE; + w->viewport->follow_vehicle = VehicleID::Invalid(); w->viewport->dest_scrollpos_x += ScaleByZoom((15 - (vp->width - x)) * SCROLLSPEED, vp->zoom); } if (y - 15 < 0) { - w->viewport->follow_vehicle = INVALID_VEHICLE; + w->viewport->follow_vehicle = VehicleID::Invalid(); w->viewport->dest_scrollpos_y += ScaleByZoom((y - 15) * SCROLLSPEED, vp->zoom); } else if (15 - (vp->height - y) > 0) { - w->viewport->follow_vehicle = INVALID_VEHICLE; + w->viewport->follow_vehicle = VehicleID::Invalid(); w->viewport->dest_scrollpos_y += ScaleByZoom((15 - (vp->height - y)) * SCROLLSPEED, vp->zoom); } } @@ -2769,7 +2769,7 @@ static void HandleKeyScrolling() if (_game_mode != GM_MENU && _game_mode != GM_BOOTSTRAP) { /* Key scrolling stops following a vehicle. */ - GetMainWindow()->viewport->follow_vehicle = INVALID_VEHICLE; + GetMainWindow()->viewport->follow_vehicle = VehicleID::Invalid(); } ScrollMainViewport(scrollamt[_dirkeys][0] * factor, scrollamt[_dirkeys][1] * factor); diff --git a/src/window_gui.h b/src/window_gui.h index 5ba278a263..6f54ca3881 100644 --- a/src/window_gui.h +++ b/src/window_gui.h @@ -244,12 +244,12 @@ static const int WHITE_BORDER_DURATION = 3; ///< The initial timeout value for W /** * Data structure for a window viewport. * A viewport is either following a vehicle (its id in then in #follow_vehicle), or it aims to display a specific - * location #dest_scrollpos_x, #dest_scrollpos_y (#follow_vehicle is then #INVALID_VEHICLE). + * location #dest_scrollpos_x, #dest_scrollpos_y (#follow_vehicle is then #VehicleID::Invalid()). * The actual location being shown is #scrollpos_x, #scrollpos_y. * @see InitializeViewport(), UpdateViewportPosition(), UpdateViewportCoordinates(). */ struct ViewportData : Viewport { - VehicleID follow_vehicle; ///< VehicleID to follow if following a vehicle, #INVALID_VEHICLE otherwise. + VehicleID follow_vehicle; ///< VehicleID to follow if following a vehicle, #VehicleID::Invalid() otherwise. int32_t scrollpos_x; ///< Currently shown x coordinate (virtual screen coordinate of topleft corner of the viewport). int32_t scrollpos_y; ///< Currently shown y coordinate (virtual screen coordinate of topleft corner of the viewport). int32_t dest_scrollpos_x; ///< Current destination x coordinate to display (virtual screen coordinate of topleft corner of the viewport).