summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ai/ai_core.cpp12
-rw-r--r--src/ai/ai_gui.cpp8
-rw-r--r--src/ai/ai_instance.cpp2
-rw-r--r--src/ai/api/ai_company.cpp2
-rw-r--r--src/ai/api/ai_group.cpp2
-rw-r--r--src/ai/api/ai_industry.cpp2
-rw-r--r--src/ai/api/ai_sign.cpp2
-rw-r--r--src/ai/api/ai_station.cpp2
-rw-r--r--src/ai/api/ai_town.cpp2
-rw-r--r--src/ai/api/ai_vehicle.cpp2
-rw-r--r--src/ai/api/ai_waypoint.cpp2
-rw-r--r--src/aircraft_cmd.cpp12
-rw-r--r--src/airport_gui.cpp2
-rw-r--r--src/autoreplace.cpp2
-rw-r--r--src/autoreplace_cmd.cpp2
-rw-r--r--src/cheat_gui.cpp2
-rw-r--r--src/command.cpp4
-rw-r--r--src/company_base.h10
-rw-r--r--src/company_cmd.cpp26
-rw-r--r--src/company_gui.cpp6
-rw-r--r--src/console_cmds.cpp14
-rw-r--r--src/depot_base.h5
-rw-r--r--src/dock_gui.cpp2
-rw-r--r--src/economy.cpp6
-rw-r--r--src/graph_gui.cpp14
-rw-r--r--src/group.h9
-rw-r--r--src/group_cmd.cpp22
-rw-r--r--src/group_gui.cpp14
-rw-r--r--src/highscore_gui.cpp4
-rw-r--r--src/industry.h13
-rw-r--r--src/industry_gui.cpp2
-rw-r--r--src/misc_cmd.cpp2
-rw-r--r--src/misc_gui.cpp2
-rw-r--r--src/network/core/tcp_game.h5
-rw-r--r--src/network/network.cpp4
-rw-r--r--src/network/network_base.h5
-rw-r--r--src/network/network_client.cpp12
-rw-r--r--src/network/network_gui.cpp6
-rw-r--r--src/network/network_server.cpp34
-rw-r--r--src/newgrf_engine.cpp2
-rw-r--r--src/newgrf_house.cpp2
-rw-r--r--src/newgrf_industries.cpp2
-rw-r--r--src/oldpool.h10
-rw-r--r--src/order_base.h5
-rw-r--r--src/order_cmd.cpp28
-rw-r--r--src/rail_cmd.cpp2
-rw-r--r--src/rail_gui.cpp4
-rw-r--r--src/road.cpp2
-rw-r--r--src/road_cmd.cpp4
-rw-r--r--src/road_gui.cpp2
-rw-r--r--src/roadveh_cmd.cpp8
-rw-r--r--src/saveload/afterload.cpp28
-rw-r--r--src/saveload/ai_sl.cpp6
-rw-r--r--src/saveload/saveload.cpp4
-rw-r--r--src/ship_cmd.cpp6
-rw-r--r--src/signal.cpp4
-rw-r--r--src/signs_base.h5
-rw-r--r--src/signs_cmd.cpp2
-rw-r--r--src/station_base.h5
-rw-r--r--src/station_cmd.cpp28
-rw-r--r--src/station_gui.cpp2
-rw-r--r--src/strings.cpp4
-rw-r--r--src/terraform_gui.cpp2
-rw-r--r--src/timetable_cmd.cpp6
-rw-r--r--src/toolbar_gui.cpp2
-rw-r--r--src/town.h12
-rw-r--r--src/town_cmd.cpp18
-rw-r--r--src/town_gui.cpp2
-rw-r--r--src/train_cmd.cpp16
-rw-r--r--src/tree_cmd.cpp4
-rw-r--r--src/tree_gui.cpp2
-rw-r--r--src/tunnelbridge_cmd.cpp4
-rw-r--r--src/vehicle.cpp6
-rw-r--r--src/vehicle_base.h10
-rw-r--r--src/vehicle_cmd.cpp8
-rw-r--r--src/vehicle_gui.cpp2
-rw-r--r--src/waypoint.h5
-rw-r--r--src/waypoint_cmd.cpp2
78 files changed, 242 insertions, 303 deletions
diff --git a/src/ai/ai_core.cpp b/src/ai/ai_core.cpp
index 16ad01452..df470d035 100644
--- a/src/ai/ai_core.cpp
+++ b/src/ai/ai_core.cpp
@@ -28,7 +28,7 @@
/* static */ void AI::StartNew(CompanyID company)
{
- assert(IsValidCompanyID(company));
+ assert(Company::IsValidID(company));
/* Clients shouldn't start AIs */
if (_networking && !_network_server) return;
@@ -74,7 +74,7 @@
* Effectively collecting garbage once every two months per AI. */
if ((AI::frame_counter & 255) == 0) {
CompanyID cid = (CompanyID)GB(AI::frame_counter, 8, 4);
- if (IsValidCompanyID(cid) && !IsHumanCompany(cid)) Company::Get(cid)->ai_instance->CollectGarbage();
+ if (Company::IsValidID(cid) && !IsHumanCompany(cid)) Company::Get(cid)->ai_instance->CollectGarbage();
}
_current_company = OWNER_NONE;
@@ -178,7 +178,7 @@
}
/* Only AIs can have an event-queue */
- if (!IsValidCompanyID(company) || IsHumanCompany(company)) {
+ if (!Company::IsValidID(company) || IsHumanCompany(company)) {
event->Release();
return;
}
@@ -227,7 +227,7 @@ void CcAI(bool success, TileIndex tile, uint32 p1, uint32 p2)
/* static */ void AI::Save(CompanyID company)
{
if (!_networking || _network_server) {
- assert(IsValidCompanyID(company));
+ assert(Company::IsValidID(company));
assert(Company::Get(company)->ai_instance != NULL);
CompanyID old_company = _current_company;
@@ -242,7 +242,7 @@ void CcAI(bool success, TileIndex tile, uint32 p1, uint32 p2)
/* static */ void AI::Load(CompanyID company, int version)
{
if (!_networking || _network_server) {
- assert(IsValidCompanyID(company));
+ assert(Company::IsValidID(company));
assert(Company::Get(company)->ai_instance != NULL);
CompanyID old_company = _current_company;
@@ -259,7 +259,7 @@ void CcAI(bool success, TileIndex tile, uint32 p1, uint32 p2)
{
/* Find the first company which doesn't exist yet */
for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
- if (!IsValidCompanyID(c)) return AIConfig::GetConfig(c)->GetSetting("start_date");
+ if (!Company::IsValidID(c)) return AIConfig::GetConfig(c)->GetSetting("start_date");
}
/* Currently no AI can be started, check again in a year. */
diff --git a/src/ai/ai_gui.cpp b/src/ai/ai_gui.cpp
index ac8401dff..f0ffee121 100644
--- a/src/ai/ai_gui.cpp
+++ b/src/ai/ai_gui.cpp
@@ -641,7 +641,7 @@ struct AIDebugWindow : public Window {
{
/* Disable the companies who are not active or not an AI */
for (CompanyID i = COMPANY_FIRST; i < MAX_COMPANIES; i++) {
- this->SetWidgetDisabledState(i + AID_WIDGET_COMPANY_BUTTON_START, !IsValidCompanyID(i) || !Company::Get(i)->is_ai);
+ this->SetWidgetDisabledState(i + AID_WIDGET_COMPANY_BUTTON_START, !Company::IsValidID(i) || !Company::Get(i)->is_ai);
}
this->DisableWidget(AID_WIDGET_RELOAD_TOGGLE);
@@ -659,7 +659,7 @@ struct AIDebugWindow : public Window {
virtual void OnPaint()
{
/* Check if the currently selected company is still active. */
- if (ai_debug_company == INVALID_COMPANY || !IsValidCompanyID(ai_debug_company)) {
+ if (ai_debug_company == INVALID_COMPANY || !Company::IsValidID(ai_debug_company)) {
if (ai_debug_company != INVALID_COMPANY) {
/* Raise and disable the widget for the previous selection. */
this->RaiseWidget(ai_debug_company + AID_WIDGET_COMPANY_BUTTON_START);
@@ -669,7 +669,7 @@ struct AIDebugWindow : public Window {
}
for (CompanyID i = COMPANY_FIRST; i < MAX_COMPANIES; i++) {
- if (IsValidCompanyID(i) && Company::Get(i)->is_ai) {
+ if (Company::IsValidID(i) && Company::Get(i)->is_ai) {
/* Lower the widget corresponding to this company. */
this->LowerWidget(i + AID_WIDGET_COMPANY_BUTTON_START);
@@ -690,7 +690,7 @@ struct AIDebugWindow : public Window {
/* Paint the company icons */
for (CompanyID i = COMPANY_FIRST; i < MAX_COMPANIES; i++) {
- if (!IsValidCompanyID(i) || !Company::Get(i)->is_ai) {
+ if (!Company::IsValidID(i) || !Company::Get(i)->is_ai) {
/* Check if we have the company as an active company */
if (!this->IsWidgetDisabled(i + AID_WIDGET_COMPANY_BUTTON_START)) {
/* Bah, company gone :( */
diff --git a/src/ai/ai_instance.cpp b/src/ai/ai_instance.cpp
index 89f8ab98b..0b140c172 100644
--- a/src/ai/ai_instance.cpp
+++ b/src/ai/ai_instance.cpp
@@ -353,7 +353,7 @@ void AIInstance::CollectGarbage()
/* static */ AIStorage *AIInstance::GetStorage()
{
- assert(IsValidCompanyID(_current_company) && !IsHumanCompany(_current_company));
+ assert(Company::IsValidID(_current_company) && !IsHumanCompany(_current_company));
return Company::Get(_current_company)->ai_instance->storage;
}
diff --git a/src/ai/api/ai_company.cpp b/src/ai/api/ai_company.cpp
index 075ef6b51..ba70d859a 100644
--- a/src/ai/api/ai_company.cpp
+++ b/src/ai/api/ai_company.cpp
@@ -19,7 +19,7 @@
{
if (company == COMPANY_SELF) return (CompanyID)((byte)_current_company);
- return ::IsValidCompanyID((::CompanyID)company) ? company : COMPANY_INVALID;
+ return ::Company::IsValidID((::CompanyID)company) ? company : COMPANY_INVALID;
}
/* static */ bool AICompany::IsMine(AICompany::CompanyID company)
diff --git a/src/ai/api/ai_group.cpp b/src/ai/api/ai_group.cpp
index 165b1028e..6f4d25de9 100644
--- a/src/ai/api/ai_group.cpp
+++ b/src/ai/api/ai_group.cpp
@@ -16,7 +16,7 @@
/* static */ bool AIGroup::IsValidGroup(GroupID group_id)
{
- return ::IsValidGroupID(group_id) && ::Group::Get(group_id)->owner == _current_company;
+ return ::Group::IsValidID(group_id) && ::Group::Get(group_id)->owner == _current_company;
}
/* static */ AIGroup::GroupID AIGroup::CreateGroup(AIVehicle::VehicleType vehicle_type)
diff --git a/src/ai/api/ai_industry.cpp b/src/ai/api/ai_industry.cpp
index 3a1acb213..5b7766fa2 100644
--- a/src/ai/api/ai_industry.cpp
+++ b/src/ai/api/ai_industry.cpp
@@ -18,7 +18,7 @@
/* static */ bool AIIndustry::IsValidIndustry(IndustryID industry_id)
{
- return ::IsValidIndustryID(industry_id);
+ return ::Industry::IsValidID(industry_id);
}
/* static */ char *AIIndustry::GetName(IndustryID industry_id)
diff --git a/src/ai/api/ai_sign.cpp b/src/ai/api/ai_sign.cpp
index 72e34d333..8876bbeec 100644
--- a/src/ai/api/ai_sign.cpp
+++ b/src/ai/api/ai_sign.cpp
@@ -20,7 +20,7 @@
/* static */ bool AISign::IsValidSign(SignID sign_id)
{
- return ::IsValidSignID(sign_id) && ::Sign::Get(sign_id)->owner == _current_company;
+ return ::Sign::IsValidID(sign_id) && ::Sign::Get(sign_id)->owner == _current_company;
}
/* static */ bool AISign::SetName(SignID sign_id, const char *name)
diff --git a/src/ai/api/ai_station.cpp b/src/ai/api/ai_station.cpp
index 7a9f5cb8d..cc1167ddc 100644
--- a/src/ai/api/ai_station.cpp
+++ b/src/ai/api/ai_station.cpp
@@ -17,7 +17,7 @@
/* static */ bool AIStation::IsValidStation(StationID station_id)
{
- return ::IsValidStationID(station_id) && ::Station::Get(station_id)->owner == _current_company;
+ return ::Station::IsValidID(station_id) && ::Station::Get(station_id)->owner == _current_company;
}
/* static */ StationID AIStation::GetStationID(TileIndex tile)
diff --git a/src/ai/api/ai_town.cpp b/src/ai/api/ai_town.cpp
index a37d065e5..e49c1a36a 100644
--- a/src/ai/api/ai_town.cpp
+++ b/src/ai/api/ai_town.cpp
@@ -21,7 +21,7 @@
/* static */ bool AITown::IsValidTown(TownID town_id)
{
- return ::IsValidTownID(town_id);
+ return ::Town::IsValidID(town_id);
}
/* static */ char *AITown::GetName(TownID town_id)
diff --git a/src/ai/api/ai_vehicle.cpp b/src/ai/api/ai_vehicle.cpp
index b61519915..5d1579364 100644
--- a/src/ai/api/ai_vehicle.cpp
+++ b/src/ai/api/ai_vehicle.cpp
@@ -19,7 +19,7 @@
/* static */ bool AIVehicle::IsValidVehicle(VehicleID vehicle_id)
{
- if (!::IsValidVehicleID(vehicle_id)) return false;
+ if (!::Vehicle::IsValidID(vehicle_id)) return false;
const Vehicle *v = ::Vehicle::Get(vehicle_id);
return v->owner == _current_company && (v->IsPrimaryVehicle() || (v->type == VEH_TRAIN && ::IsFreeWagon(v)));
}
diff --git a/src/ai/api/ai_waypoint.cpp b/src/ai/api/ai_waypoint.cpp
index ec6af36eb..0c1e3194b 100644
--- a/src/ai/api/ai_waypoint.cpp
+++ b/src/ai/api/ai_waypoint.cpp
@@ -14,7 +14,7 @@
/* static */ bool AIWaypoint::IsValidWaypoint(WaypointID waypoint_id)
{
- return ::IsValidWaypointID(waypoint_id) && ::Waypoint::Get(waypoint_id)->owner == _current_company;
+ return ::Waypoint::IsValidID(waypoint_id) && ::Waypoint::Get(waypoint_id)->owner == _current_company;
}
/* static */ WaypointID AIWaypoint::GetWaypointID(TileIndex tile)
diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp
index 2c2fac150..7ef62bb94 100644
--- a/src/aircraft_cmd.cpp
+++ b/src/aircraft_cmd.cpp
@@ -440,7 +440,7 @@ CommandCost CmdBuildAircraft(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
*/
CommandCost CmdSellAircraft(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
{
- if (!IsValidVehicleID(p1)) return CMD_ERROR;
+ if (!Vehicle::IsValidID(p1)) return CMD_ERROR;
Vehicle *v = Vehicle::Get(p1);
@@ -494,7 +494,7 @@ CommandCost CmdSendAircraftToHangar(TileIndex tile, DoCommandFlag flags, uint32
return SendAllVehiclesToDepot(VEH_AIRCRAFT, flags, p2 & DEPOT_SERVICE, _current_company, (p2 & VLW_MASK), p1);
}
- if (!IsValidVehicleID(p1)) return CMD_ERROR;
+ if (!Vehicle::IsValidID(p1)) return CMD_ERROR;
Vehicle *v = Vehicle::Get(p1);
@@ -518,7 +518,7 @@ CommandCost CmdRefitAircraft(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
{
byte new_subtype = GB(p2, 8, 8);
- if (!IsValidVehicleID(p1)) return CMD_ERROR;
+ if (!Vehicle::IsValidID(p1)) return CMD_ERROR;
Vehicle *v = Vehicle::Get(p1);
@@ -889,7 +889,7 @@ static byte AircraftGetEntryPoint(const Vehicle *v, const AirportFTAClass *apc)
* or it will simply crash in next tick */
TileIndex tile = 0;
- if (IsValidStationID(v->u.air.targetairport)) {
+ if (Station::IsValidID(v->u.air.targetairport)) {
const Station *st = Station::Get(v->u.air.targetairport);
/* Make sure we don't go to INVALID_TILE if the airport has been removed. */
tile = (st->airport_tile != INVALID_TILE) ? st->airport_tile : st->xy;
@@ -921,7 +921,7 @@ static bool AircraftController(Vehicle *v)
int count;
/* NULL if station is invalid */
- const Station *st = IsValidStationID(v->u.air.targetairport) ? Station::Get(v->u.air.targetairport) : NULL;
+ const Station *st = Station::IsValidID(v->u.air.targetairport) ? Station::Get(v->u.air.targetairport) : NULL;
/* INVALID_TILE if there is no station */
TileIndex tile = INVALID_TILE;
if (st != NULL) {
@@ -2051,7 +2051,7 @@ Station *GetTargetAirportIfValid(const Vehicle *v)
StationID sid = v->u.air.targetairport;
- if (!IsValidStationID(sid)) return NULL;
+ if (!Station::IsValidID(sid)) return NULL;
Station *st = Station::Get(sid);
diff --git a/src/airport_gui.cpp b/src/airport_gui.cpp
index 877d234f9..7298ac5e7 100644
--- a/src/airport_gui.cpp
+++ b/src/airport_gui.cpp
@@ -158,7 +158,7 @@ static const WindowDesc _air_toolbar_desc(
void ShowBuildAirToolbar()
{
- if (!IsValidCompanyID(_local_company)) return;
+ if (!Company::IsValidID(_local_company)) return;
DeleteWindowByClass(WC_BUILD_TOOLBAR);
AllocateWindowDescFront<BuildAirToolbarWindow>(&_air_toolbar_desc, TRANSPORT_AIR);
diff --git a/src/autoreplace.cpp b/src/autoreplace.cpp
index fb206cfaa..f6a714401 100644
--- a/src/autoreplace.cpp
+++ b/src/autoreplace.cpp
@@ -40,7 +40,7 @@ void RemoveAllEngineReplacement(EngineRenewList *erl)
EngineID EngineReplacement(EngineRenewList erl, EngineID engine, GroupID group)
{
const EngineRenew *er = GetEngineReplacement(erl, engine, group);
- if (er == NULL && (group == DEFAULT_GROUP || (IsValidGroupID(group) && !Group::Get(group)->replace_protection))) {
+ if (er == NULL && (group == DEFAULT_GROUP || (Group::IsValidID(group) && !Group::Get(group)->replace_protection))) {
/* We didn't find anything useful in the vehicle's own group so we will try ALL_GROUP */
er = GetEngineReplacement(erl, engine, ALL_GROUP);
}
diff --git a/src/autoreplace_cmd.cpp b/src/autoreplace_cmd.cpp
index acfd985ec..076cc7187 100644
--- a/src/autoreplace_cmd.cpp
+++ b/src/autoreplace_cmd.cpp
@@ -608,7 +608,7 @@ CommandCost CmdAutoreplaceVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1
CommandCost cost = CommandCost(EXPENSES_NEW_VEHICLES, 0);
bool nothing_to_do = true;
- if (!IsValidVehicleID(p1)) return CMD_ERROR;
+ if (!Vehicle::IsValidID(p1)) return CMD_ERROR;
Vehicle *v = Vehicle::Get(p1);
if (!CheckOwnership(v->owner)) return CMD_ERROR;
if (!v->IsInDepot()) return CMD_ERROR;
diff --git a/src/cheat_gui.cpp b/src/cheat_gui.cpp
index 8b3843617..f3ce7d0e1 100644
--- a/src/cheat_gui.cpp
+++ b/src/cheat_gui.cpp
@@ -44,7 +44,7 @@ static int32 ClickMoneyCheat(int32 p1, int32 p2)
static int32 ClickChangeCompanyCheat(int32 p1, int32 p2)
{
while ((uint)p1 < Company::GetPoolSize()) {
- if (IsValidCompanyID((CompanyID)p1)) {
+ if (Company::IsValidID((CompanyID)p1)) {
SetLocalCompany((CompanyID)p1);
return _local_company;
}
diff --git a/src/command.cpp b/src/command.cpp
index 49804f4b4..b80a4e8b1 100644
--- a/src/command.cpp
+++ b/src/command.cpp
@@ -458,7 +458,7 @@ error:
Money GetAvailableMoneyForCommand()
{
CompanyID company = _current_company;
- if (!IsValidCompanyID(company)) return INT64_MAX;
+ if (!Company::IsValidID(company)) return INT64_MAX;
return Company::Get(company)->money;
}
@@ -590,7 +590,7 @@ bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallbac
DEBUG(desync, 1, "cmd: %08x; %08x; %1x; %06x; %08x; %08x; %04x; %s\n", _date, _date_fract, (int)_current_company, tile, p1, p2, cmd & ~CMD_NETWORK_COMMAND, text);
/* update last build coordinate of company. */
- if (tile != 0 && IsValidCompanyID(_current_company)) {
+ if (tile != 0 && Company::IsValidID(_current_company)) {
Company::Get(_current_company)->last_build_coordinate = tile;
}
diff --git a/src/company_base.h b/src/company_base.h
index edffdc684..ecfb61fef 100644
--- a/src/company_base.h
+++ b/src/company_base.h
@@ -83,12 +83,12 @@ struct Company : PoolItem<Company, CompanyByte, &_Company_pool> {
uint16 *num_engines; ///< caches the number of engines of each type the company owns (no need to save this)
inline bool IsValid() const { return this->name_1 != 0; }
-};
-static inline bool IsValidCompanyID(CompanyID company)
-{
- return company < MAX_COMPANIES && (uint)company < Company::GetPoolSize() && Company::Get(company)->IsValid();
-}
+ static inline bool IsValidID(CompanyID company)
+ {
+ return company < MAX_COMPANIES && (uint)company < Company::GetPoolSize() && Company::Get(company)->IsValid();
+ }
+};
#define FOR_ALL_COMPANIES_FROM(d, start) for (d = Company::Get(start); d != NULL; d = (d->index + 1U < Company::GetPoolSize()) ? Company::Get(d->index + 1U) : NULL) if (d->IsValid())
#define FOR_ALL_COMPANIES(d) FOR_ALL_COMPANIES_FROM(d, 0)
diff --git a/src/company_cmd.cpp b/src/company_cmd.cpp
index 358122efc..e63b25a6b 100644
--- a/src/company_cmd.cpp
+++ b/src/company_cmd.cpp
@@ -66,17 +66,17 @@ Company::~Company()
* Sets the local company and updates the settings that are set on a
* per-company basis to reflect the core's state in the GUI.
* @param new_company the new company
- * @pre IsValidCompanyID(new_company) || new_company == COMPANY_SPECTATOR || new_company == OWNER_NONE
+ * @pre Company::IsValidID(new_company) || new_company == COMPANY_SPECTATOR || new_company == OWNER_NONE
*/
void SetLocalCompany(CompanyID new_company)
{
/* company could also be COMPANY_SPECTATOR or OWNER_NONE */
- assert(IsValidCompanyID(new_company) || new_company == COMPANY_SPECTATOR || new_company == OWNER_NONE);
+ assert(Company::IsValidID(new_company) || new_company == COMPANY_SPECTATOR || new_company == OWNER_NONE);
_local_company = new_company;
/* Do not update the settings if we are in the intro GUI */
- if (IsValidCompanyID(new_company) && _game_mode != GM_MENU) {
+ if (Company::IsValidID(new_company) && _game_mode != GM_MENU) {
const Company *c = Company::Get(new_company);
_settings_client.company = c->settings;
InvalidateWindow(WC_GAME_OPTIONS, 0);
@@ -99,7 +99,7 @@ uint16 GetDrawStringCompanyColour(CompanyID company)
{
/* Get the colour for DrawString-subroutines which matches the colour
* of the company */
- if (!IsValidCompanyID(company)) return _colour_gradient[COLOUR_WHITE][4] | IS_PALETTE_COLOUR;
+ if (!Company::IsValidID(company)) return _colour_gradient[COLOUR_WHITE][4] | IS_PALETTE_COLOUR;
return (_colour_gradient[_company_colours[company]][4]) | IS_PALETTE_COLOUR;
}
@@ -151,7 +151,7 @@ bool CheckCompanyHasMoney(CommandCost cost)
{
if (cost.GetCost() > 0) {
CompanyID company = _current_company;
- if (IsValidCompanyID(company) && cost.GetCost() > Company::Get(company)->money) {
+ if (Company::IsValidID(company) && cost.GetCost() > Company::Get(company)->money) {
SetDParam(0, cost.GetCost());
_error_message = STR_ERROR_NOT_ENOUGH_CASH_REQUIRES_CURRENCY;
return false;
@@ -189,7 +189,7 @@ void SubtractMoneyFromCompany(CommandCost cost)
{
CompanyID cid = _current_company;
- if (IsValidCompanyID(cid)) SubtractMoneyFromAnyCompany(Company::Get(cid), cost);
+ if (Company::IsValidID(cid)) SubtractMoneyFromAnyCompany(Company::Get(cid), cost);
}
void SubtractMoneyFromCompanyFract(CompanyID company, CommandCost cst)
@@ -209,7 +209,7 @@ void GetNameOfOwner(Owner owner, TileIndex tile)
SetDParam(2, owner);
if (owner != OWNER_TOWN) {
- if (!IsValidCompanyID(owner)) {
+ if (!Company::IsValidID(owner)) {
SetDParam(0, STR_COMPANY_SOMEONE);
} else {
SetDParam(0, STR_COMPANY_NAME);
@@ -499,7 +499,7 @@ void OnTick_Companies()
{
if (_game_mode == GM_EDITOR) return;
- if (IsValidCompanyID((CompanyID)_cur_company_tick_index)) {
+ if (Company::IsValidID((CompanyID)_cur_company_tick_index)) {
Company *c = Company::Get((CompanyID)_cur_company_tick_index);
if (c->name_1 != 0) GenerateCompanyName(c);
}
@@ -567,7 +567,7 @@ void CompaniesYearlyLoop()
*/
CommandCost CmdSetAutoReplace(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
{
- if (!IsValidCompanyID(_current_company)) return CMD_ERROR;
+ if (!Company::IsValidID(_current_company)) return CMD_ERROR;
Company *c = Company::Get(_current_company);
switch (GB(p1, 0, 3)) {
@@ -615,7 +615,7 @@ CommandCost CmdSetAutoReplace(TileIndex tile, DoCommandFlag flags, uint32 p1, ui
GroupID id_g = GB(p1, 16, 16);
CommandCost cost;
- if (!IsValidGroupID(id_g) && !IsAllGroupID(id_g) && !IsDefaultGroupID(id_g)) return CMD_ERROR;
+ if (!Group::IsValidID(id_g) && !IsAllGroupID(id_g) && !IsDefaultGroupID(id_g)) return CMD_ERROR;
if (new_engine_type != INVALID_ENGINE) {
if (!CheckAutoreplaceValidity(old_engine_type, new_engine_type, _current_company)) return CMD_ERROR;
@@ -780,7 +780,7 @@ CommandCost CmdCompanyCtrl(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
ci->client_playas = c->index;
NetworkUpdateClientInfo(ci->client_id);
- if (IsValidCompanyID(ci->client_playas)) {
+ if (Company::IsValidID(ci->client_playas)) {
CompanyID company_backup = _local_company;
_network_company_states[c->index].months_empty = 0;
_network_company_states[c->index].password[0] = '\0';
@@ -819,7 +819,7 @@ CommandCost CmdCompanyCtrl(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
case 2: { // Delete a company
Company *c;
- if (!IsValidCompanyID((CompanyID)p2)) return CMD_ERROR;
+ if (!Company::IsValidID((CompanyID)p2)) return CMD_ERROR;
if (!(flags & DC_EXEC)) return CommandCost();
@@ -849,7 +849,7 @@ CommandCost CmdCompanyCtrl(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
CompanyID cid_old = (CompanyID)GB(p2, 0, 16);
CompanyID cid_new = (CompanyID)GB(p2, 16, 16);
- if (!IsValidCompanyID(cid_old) || !IsValidCompanyID(cid_new)) return CMD_ERROR;
+ if (!Company::IsValidID(cid_old) || !Company::IsValidID(cid_new)) return CMD_ERROR;
if (!(flags & DC_EXEC)) return CMD_ERROR;
diff --git a/src/company_gui.cpp b/src/company_gui.cpp
index 630223432..0c0776cc9 100644
--- a/src/company_gui.cpp
+++ b/src/company_gui.cpp
@@ -433,7 +433,7 @@ static const WindowDesc _company_finances_small_desc(
*/
static void DoShowCompanyFinances(CompanyID company, bool show_small, bool show_stickied, int top, int left)
{
- if (!IsValidCompanyID(company)) return;
+ if (!Company::IsValidID(company)) return;
if (BringWindowToFrontById(WC_FINANCES, company)) return;
new CompanyFinancesWindow(show_small ? &_company_finances_small_desc : &_company_finances_desc, company, show_small, show_stickied, top, left);
@@ -1381,7 +1381,7 @@ static const WindowDesc _select_company_manager_face_adv_desc(
*/
static void DoSelectCompanyManagerFace(Window *parent, bool adv, int top, int left)
{
- if (!IsValidCompanyID((CompanyID)parent->window_number)) return;
+ if (!Company::IsValidID((CompanyID)parent->window_number)) return;
if (BringWindowToFrontById(WC_COMPANY_MANAGER_FACE, parent->window_number)) return;
new SelectCompanyManagerFaceWindow(adv ? &_select_company_manager_face_adv_desc : &_select_company_manager_face_desc, parent, adv, top, left); // simple or advanced window
@@ -1782,7 +1782,7 @@ static const WindowDesc _company_desc(
void ShowCompany(CompanyID company)
{
- if (!IsValidCompanyID(company)) return;
+ if (!Company::IsValidID(company)) return;
AllocateWindowDescFront<CompanyWindow>(&_company_desc, company);
}
diff --git a/src/console_cmds.cpp b/src/console_cmds.cpp
index 48f5d4a2c..cde830aa0 100644
--- a/src/console_cmds.cpp
+++ b/src/console_cmds.cpp
@@ -635,7 +635,7 @@ DEF_CONSOLE_CMD(ConJoinCompany)
CompanyID company_id = (CompanyID)(atoi(argv[1]) <= MAX_COMPANIES ? atoi(argv[1]) - 1 : atoi(argv[1]));
/* Check we have a valid company id! */
- if (!IsValidCompanyID(company_id) && company_id != COMPANY_SPECTATOR) {
+ if (!Company::IsValidID(company_id) && company_id != COMPANY_SPECTATOR) {
IConsolePrintF(CC_ERROR, "Company does not exist. Company-id must be between 1 and %d.", MAX_COMPANIES);
return true;
}
@@ -688,7 +688,7 @@ DEF_CONSOLE_CMD(ConMoveClient)
return true;
}
- if (!IsValidCompanyID(company_id) && company_id != COMPANY_SPECTATOR) {
+ if (!Company::IsValidID(company_id) && company_id != COMPANY_SPECTATOR) {
IConsolePrintF(CC_ERROR, "Company does not exist. Company-id must be between 1 and %d.", MAX_COMPANIES);
return true;
}
@@ -729,7 +729,7 @@ DEF_CONSOLE_CMD(ConResetCompany)
index = (CompanyID)(atoi(argv[1]) - 1);
/* Check valid range */
- if (!IsValidCompanyID(index)) {
+ if (!Company::IsValidID(index)) {
IConsolePrintF(CC_ERROR, "Company does not exist. Company-id must be between 1 and %d.", MAX_COMPANIES);
return true;
}
@@ -1049,7 +1049,7 @@ DEF_CONSOLE_CMD(ConReloadAI)
}
CompanyID company_id = (CompanyID)(atoi(argv[1]) - 1);
- if (!IsValidCompanyID(company_id)) {
+ if (!Company::IsValidID(company_id)) {
IConsolePrintF(CC_DEFAULT, "Unknown company. Company range is between 1 and %d.", MAX_COMPANIES);
return true;
}
@@ -1086,7 +1086,7 @@ DEF_CONSOLE_CMD(ConStopAI)
}
CompanyID company_id = (CompanyID)(atoi(argv[1]) - 1);
- if (!IsValidCompanyID(company_id)) {
+ if (!Company::IsValidID(company_id)) {
IConsolePrintF(CC_DEFAULT, "Unknown company. Company range is between 1 and %d.", MAX_COMPANIES);
return true;
}
@@ -1464,7 +1464,7 @@ DEF_CONSOLE_CMD(ConSayCompany)
if (argc != 3) return false;
CompanyID company_id = (CompanyID)(atoi(argv[1]) - 1);
- if (!IsValidCompanyID(company_id)) {
+ if (!Company::IsValidID(company_id)) {
IConsolePrintF(CC_DEFAULT, "Unknown company. Company range is between 1 and %d.", MAX_COMPANIES);
return true;
}
@@ -1508,7 +1508,7 @@ bool NetworkChangeCompanyPassword(byte argc, char *argv[])
return true;
}
- if (!IsValidCompanyID(_local_company)) {
+ if (!Company::IsValidID(_local_company)) {
IConsoleError("You have to own a company to make use of this command.");
return false;
}
diff --git a/src/depot_base.h b/src/depot_base.h
index 0e1c39163..b22b7e50f 100644
--- a/src/depot_base.h
+++ b/src/depot_base.h
@@ -22,11 +22,6 @@ struct Depot : PoolItem<Depot, DepotID, &_Depot_pool> {
inline bool IsValid() const { return this->xy != INVALID_TILE; }
};
-static inline bool IsValidDepotID(DepotID index)
-{
- return index < Depot::GetPoolSize() && Depot::Get(index)->IsValid();
-}
-
Depot *GetDepotByTile(TileIndex tile);
#define FOR_ALL_DEPOTS_FROM(d, start) for (d = Depot::Get(start); d != NULL; d = (d->index + 1U < Depot::GetPoolSize()) ? Depot::Get(d->index + 1U) : NULL) if (d->IsValid())
diff --git a/src/dock_gui.cpp b/src/dock_gui.cpp
index 9f23793a3..46ce1db29 100644
--- a/src/dock_gui.cpp
+++ b/src/dock_gui.cpp
@@ -306,7 +306,7 @@ static const WindowDesc _build_docks_toolbar_desc(
void ShowBuildDocksToolbar()
{
- if (!IsValidCompanyID(_local_company)) return;
+ if (!Company::IsValidID(_local_company)) return;
DeleteWindowByClass(WC_BUILD_TOOLBAR);
AllocateWindowDescFront<BuildDocksToolbarWindow>(&_build_docks_toolbar_desc, TRANSPORT_WATER);
diff --git a/src/economy.cpp b/src/economy.cpp
index cc69b8569..102333dd3 100644
--- a/src/economy.cpp
+++ b/src/economy.cpp
@@ -1891,7 +1891,7 @@ CommandCost CmdBuyShareInCompany(TileIndex tile, DoCommandFlag flags, uint32 p1,
/* Check if buying shares is allowed (protection against modified clients)
* Cannot buy own shares */
- if (!IsValidCompanyID((CompanyID)p1) || !_settings_game.economy.allow_shares || _current_company == (CompanyID)p1) return CMD_ERROR;
+ if (!Company::IsValidID((CompanyID)p1) || !_settings_game.economy.allow_shares || _current_company == (CompanyID)p1) return CMD_ERROR;
Company *c = Company::Get((CompanyID)p1);
@@ -1934,7 +1934,7 @@ CommandCost CmdSellShareInCompany(TileIndex tile, DoCommandFlag flags, uint32 p1
{
/* Check if selling shares is allowed (protection against modified clients)
* Cannot sell own shares */
- if (!IsValidCompanyID((CompanyID)p1) || !_settings_game.economy.allow_shares || _current_company == (CompanyID)p1) return CMD_ERROR;
+ if (!Company::IsValidID((CompanyID)p1) || !_settings_game.economy.allow_shares || _current_company == (CompanyID)p1) return CMD_ERROR;
Company *c = Company::Get((CompanyID)p1);
@@ -1968,7 +1968,7 @@ CommandCost CmdBuyCompany(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
CompanyID cid = (CompanyID)p1;
/* Disable takeovers in multiplayer games */
- if (!IsValidCompanyID(cid) || _networking) return CMD_ERROR;
+ if (!Company::IsValidID(cid) || _networking) return CMD_ERROR;
/* Do not allow companies to take over themselves */
if (cid == _current_company) return CMD_ERROR;
diff --git a/src/graph_gui.cpp b/src/graph_gui.cpp
index df4c5f85c..100254b22 100644
--- a/src/graph_gui.cpp
+++ b/src/graph_gui.cpp
@@ -53,7 +53,7 @@ struct GraphLegendWindow : Window {
virtual void OnPaint()
{
for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
- if (IsValidCompanyID(c)) continue;
+ if (Company::IsValidID(c)) continue;
SetBit(_legend_excluded_companies, c);
this->RaiseWidget(c + GLW_FIRST_COMPANY);
@@ -401,7 +401,7 @@ public:
/* Exclude the companies which aren't valid */
for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
- if (!IsValidCompanyID(c)) SetBit(excluded_companies, c);
+ if (!Company::IsValidID(c)) SetBit(excluded_companies, c);
}
this->excluded_data = excluded_companies;
this->num_vert_lines = 24;
@@ -425,7 +425,7 @@ public:
int numd = 0;
for (CompanyID k = COMPANY_FIRST; k < MAX_COMPANIES; k++) {
- if (IsValidCompanyID(k)) {
+ if (Company::IsValidID(k)) {
c = Company::Get(k);
this->colours[numd] = _colour_gradient[c->colour][6];
for (int j = this->num_on_x_axis, i = 0; --j >= 0;) {
@@ -1015,7 +1015,7 @@ struct PerformanceRatingDetailWindow : Window {
{
/* Disable the companies who are not active */
for (CompanyID i = COMPANY_FIRST; i < MAX_COMPANIES; i++) {
- this->SetWidgetDisabledState(i + PRW_COMPANY_FIRST, !IsValidCompanyID(i));
+ this->SetWidgetDisabledState(i + PRW_COMPANY_FIRST, !Company::IsValidID(i));
}
this->UpdateCompanyStats();
@@ -1049,7 +1049,7 @@ struct PerformanceRatingDetailWindow : Window {
this->DrawWidgets();
/* Check if the currently selected company is still active. */
- if (company == INVALID_COMPANY || !IsValidCompanyID(company)) {
+ if (company == INVALID_COMPANY || !Company::IsValidID(company)) {
if (company != INVALID_COMPANY) {
/* Raise and disable the widget for the previous selection. */
this->RaiseWidget(company + PRW_COMPANY_FIRST);
@@ -1060,7 +1060,7 @@ struct PerformanceRatingDetailWindow : Window {
}
for (CompanyID i = COMPANY_FIRST; i < MAX_COMPANIES; i++) {
- if (IsValidCompanyID(i)) {
+ if (Company::IsValidID(i)) {
/* Lower the widget corresponding to this company. */
this->LowerWidget(i + PRW_COMPANY_FIRST);
this->SetDirty();
@@ -1076,7 +1076,7 @@ struct PerformanceRatingDetailWindow : Window {
/* Paint the company icons */
for (CompanyID i = COMPANY_FIRST; i < MAX_COMPANIES; i++) {
- if (!IsValidCompanyID(i)) {
+ if (!Company::IsValidID(i)) {
/* Check if we have the company as an active company */
if (!this->IsWidgetDisabled(i + PRW_COMPANY_FIRST)) {
/* Bah, company gone :( */
diff --git a/src/group.h b/src/group.h
index 84efd6e0e..445e3a66f 100644
--- a/src/group.h
+++ b/src/group.h
@@ -30,11 +30,6 @@ struct Group : PoolItem<Group, GroupID, &_Group_pool> {
};
-static inline bool IsValidGroupID(GroupID index)
-{
- return index < Group::GetPoolSize() && Group::Get(index)->IsValid();
-}
-
static inline bool IsDefaultGroupID(GroupID index)
{
return index == DEFAULT_GROUP;
@@ -77,12 +72,12 @@ uint GetGroupNumEngines(CompanyID company, GroupID id_g, EngineID id_e);
static inline void IncreaseGroupNumVehicle(GroupID id_g)
{
- if (IsValidGroupID(id_g)) Group::Get(id_g)->num_vehicle++;
+ if (Group::IsValidID(id_g)) Group::Get(id_g)->num_vehicle++;
}
static inline void DecreaseGroupNumVehicle(GroupID id_g)
{
- if (IsValidGroupID(id_g)) Group::Get(id_g)->num_vehicle--;
+ if (Group::IsValidID(id_g)) Group::Get(id_g)->num_vehicle--;
}
diff --git a/src/group_cmd.cpp b/src/group_cmd.cpp
index 371881a08..aa8454171 100644
--- a/src/group_cmd.cpp
+++ b/src/group_cmd.cpp
@@ -32,10 +32,10 @@ static inline void UpdateNumEngineGroup(EngineID i, GroupID old_g, GroupID new_g
{
if (old_g != new_g) {
/* Decrease the num engines of EngineID i of the old group if it's not the default one */
- if (!IsDefaultGroupID(old_g) && IsValidGroupID(old_g)) Group::Get(old_g)->num_engines[i]--;
+ if (!IsDefaultGroupID(old_g) && Group::IsValidID(old_g)) Group::Get(old_g)->num_engines[i]--;
/* Increase the num engines of EngineID i of the new group if it's not the default one */
- if (!IsDefaultGroupID(new_g) && IsValidGroupID(new_g)) Group::Get(new_g)->num_engines[i]++;
+ if (!IsDefaultGroupID(new_g) && Group::IsValidID(new_g)) Group::Get(new_g)->num_engines[i]++;
}
}
@@ -105,7 +105,7 @@ CommandCost CmdCreateGroup(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
*/
CommandCost CmdDeleteGroup(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
{
- if (!IsValidGroupID(p1)) return CMD_ERROR;
+ if (!Group::IsValidID(p1)) return CMD_ERROR;
Group *g = Group::Get(p1);
if (g->owner != _current_company) return CMD_ERROR;
@@ -164,7 +164,7 @@ static bool IsUniqueGroupName(const char *name)
*/
CommandCost CmdRenameGroup(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
{
- if (!IsValidGroupID(p1)) return CMD_ERROR;
+ if (!Group::IsValidID(p1)) return CMD_ERROR;
Group *g = Group::Get(p1);
if (g->owner != _current_company) return CMD_ERROR;
@@ -201,11 +201,11 @@ CommandCost CmdAddVehicleGroup(TileIndex tile, DoCommandFlag flags, uint32 p1, u
{
GroupID new_g = p1;
- if (!IsValidVehicleID(p2) || (!IsValidGroupID(new_g) && !IsDefaultGroupID(new_g))) return CMD_ERROR;
+ if (!Vehicle::IsValidID(p2) || (!Group::IsValidID(new_g) && !IsDefaultGroupID(new_g))) return CMD_ERROR;
Vehicle *v = Vehicle::Get(p2);
- if (IsValidGroupID(new_g)) {
+ if (Group::IsValidID(new_g)) {
Group *g = Group::Get(new_g);
if (g->owner != _current_company || g->vehicle_type != v->type) return CMD_ERROR;
}
@@ -247,7 +247,7 @@ CommandCost CmdAddVehicleGroup(TileIndex tile, DoCommandFlag flags, uint32 p1, u
CommandCost CmdAddSharedVehicleGroup(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
{
VehicleType type = (VehicleType)p2;
- if (!IsValidGroupID(p1) || !IsCompanyBuildableVehicleType(type)) return CMD_ERROR;
+ if (!Group::IsValidID(p1) || !IsCompanyBuildableVehicleType(type)) return CMD_ERROR;
if (flags & DC_EXEC) {
Vehicle *v;
@@ -284,7 +284,7 @@ CommandCost CmdAddSharedVehicleGroup(TileIndex tile, DoCommandFlag flags, uint32
CommandCost CmdRemoveAllVehiclesGroup(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
{
VehicleType type = (VehicleType)p2;
- if (!IsValidGroupID(p1) || !IsCompanyBuildableVehicleType(type)) return CMD_ERROR;
+ if (!Group::IsValidID(p1) || !IsCompanyBuildableVehicleType(type)) return CMD_ERROR;
Group *g = Group::Get(p1);
if (g->owner != _current_company) return CMD_ERROR;
@@ -320,7 +320,7 @@ CommandCost CmdRemoveAllVehiclesGroup(TileIndex tile, DoCommandFlag flags, uint3
*/
CommandCost CmdSetGroupReplaceProtection(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
{
- if (!IsValidGroupID(p1)) return CMD_ERROR;
+ if (!Group::IsValidID(p1)) return CMD_ERROR;
Group *g = Group::Get(p1);
if (g->owner != _current_company) return CMD_ERROR;
@@ -356,7 +356,7 @@ void RemoveVehicleFromGroup(const Vehicle *v)
*/
void SetTrainGroupID(Vehicle *v, GroupID new_g)
{
- if (!IsValidGroupID(new_g) && !IsDefaultGroupID(new_g)) return;
+ if (!Group::IsValidID(new_g) && !IsDefaultGroupID(new_g)) return;
assert(v->IsValid() && v->type == VEH_TRAIN && IsFrontEngine(v));
@@ -395,7 +395,7 @@ void UpdateTrainGroupID(Vehicle *v)
uint GetGroupNumEngines(CompanyID company, GroupID id_g, EngineID id_e)
{
- if (IsValidGroupID(id_g)) return Group::Get(id_g)->num_engines[id_e];
+ if (Group::IsValidID(id_g)) return Group::Get(id_g)->num_engines[id_e];
uint num = Company::Get(company)->num_engines[id_e];
if (!IsDefaultGroupID(id_g)) return num;
diff --git a/src/group_gui.cpp b/src/group_gui.cpp
index cf6ece60c..ca49ff3e5 100644
--- a/src/group_gui.cpp
+++ b/src/group_gui.cpp
@@ -76,7 +76,7 @@ static void ShowGroupActionDropdown(Window *w, GroupID gid)
list->push_back(new DropDownListStringItem(STR_SEND_FOR_SERVICING, GALF_SERVICE, false));
list->push_back(new DropDownListStringItem(STR_SEND_TRAIN_TO_DEPOT, GALF_DEPOT, false));
- if (IsValidGroupID(gid)) {
+ if (Group::IsValidID(gid)) {
list->push_back(new DropDownListStringItem(STR_GROUP_ADD_SHARED_VEHICLE, GALF_ADD_SHARED, false));
list->push_back(new DropDownListStringItem(STR_GROUP_REMOVE_ALL_VEHICLES, GALF_REMOVE_ALL, false));
}
@@ -321,7 +321,7 @@ public:
this->groups.ForceResort();
}
- if (!(IsAllGroupID(this->group_sel) || IsDefaultGroupID(this->group_sel) || IsValidGroupID(this->group_sel))) {
+ if (!(IsAllGroupID(this->group_sel) || IsDefaultGroupID(this->group_sel) || Group::IsValidID(this->group_sel))) {
this->group_sel = ALL_GROUP;
HideDropDownMenu(this);
}
@@ -567,7 +567,7 @@ public:
}
case GRP_WIDGET_RENAME_GROUP: { // Rename the selected roup
- assert(IsValidGroupID(this->group_sel));
+ assert(Group::IsValidID(this->group_sel));
const Group *g = Group::Get(this->group_sel);
@@ -595,7 +595,7 @@ public:
}
case GRP_WIDGET_REPLACE_PROTECTION:
- if (IsValidGroupID(this->group_sel)) {
+ if (Group::IsValidID(this->group_sel)) {
const Group *g = Group::Get(this->group_sel);
DoCommandP(0, this->group_sel, !g->replace_protection, CMD_SET_GROUP_REPLACE_PROTECTION);
@@ -703,12 +703,12 @@ public:
| DEPOT_MASS_SEND, GetCmdSendToDepot(this->vehicle_type));
break;
case GALF_ADD_SHARED: // Add shared Vehicles
- assert(IsValidGroupID(this->group_sel));
+ assert(Group::IsValidID(this->group_sel));
DoCommandP(0, this->group_sel, this->vehicle_type, CMD_ADD_SHARED_VEHICLE_GROUP | CMD_MSG(STR_GROUP_CAN_T_ADD_SHARED_VEHICLE));
break;
case GALF_REMOVE_ALL: // Remove all Vehicles from the selected group
- assert(IsValidGroupID(this->group_sel));
+ assert(Group::IsValidID(this->group_sel));
DoCommandP(0, this->group_sel, this->vehicle_type, CMD_REMOVE_ALL_VEHICLES_GROUP | CMD_MSG(STR_GROUP_CAN_T_REMOVE_ALL_VEHICLES));
break;
@@ -758,7 +758,7 @@ static WindowDesc _group_desc(
void ShowCompanyGroup(CompanyID company, VehicleType vehicle_type)
{
- if (!IsValidCompanyID(company)) return;
+ if (!Company::IsValidID(company)) return;
_group_desc.cls = GetWindowClassForVehicleType(vehicle_type);
WindowNumber num = (vehicle_type << 11) | VLW_GROUP_LIST | company;
diff --git a/src/highscore_gui.cpp b/src/highscore_gui.cpp
index 2b0917b6f..920364079 100644
--- a/src/highscore_gui.cpp
+++ b/src/highscore_gui.cpp
@@ -93,7 +93,7 @@ struct EndGameWindow : EndGameHighScoreBaseWindow {
this->SetupHighScoreEndWindow(&x, &y);
- if (!IsValidCompanyID(_local_company)) return;
+ if (!Company::IsValidID(_local_company)) return;
c = Company::Get(_local_company);
/* We need to get performance from last year because the image is shown
@@ -198,7 +198,7 @@ void ShowHighscoreTable(int difficulty, int8 ranking)
void ShowEndGameChart()
{
/* Dedicated server doesn't need the highscore window and neither does -v null. */
- if (_network_dedicated || (!_networking && !IsValidCompanyID(_local_company))) return;
+ if (_network_dedicated || (!_networking && !Company::IsValidID(_local_company))) return;
HideVitalWindows();
DeleteWindowByClass(WC_ENDSCREEN);
diff --git a/src/industry.h b/src/industry.h
index 69af3f436..a36fb5ca0 100644
--- a/src/industry.h
+++ b/src/industry.h
@@ -265,17 +265,6 @@ void BuildIndustriesLegend();
/* industry_cmd.cpp */
void SetIndustryDailyChanges();
-/**
- * Check if an Industry exists whithin the pool of industries
- * @param index of the desired industry
- * @return true if it is inside the pool
- */
-static inline bool IsValidIndustryID(IndustryID index)
-{
- return index < Industry::GetPoolSize() && Industry::Get(index)->IsValid();
-}
-
-
static inline IndustryID GetMaxIndustryIndex()
{
/* TODO - This isn't the real content of the function, but
@@ -346,7 +335,7 @@ static inline Industry *GetRandomIndustry()
index++;
/* Make sure we have a valid industry */
- while (!IsValidIndustryID(index)) {
+ while (!Industry::IsValidID(index)) {
index++;
assert(index <= GetMaxIndustryIndex());
}
diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp
index 3c51b996a..65cdeac4f 100644
--- a/src/industry_gui.cpp
+++ b/src/industry_gui.cpp
@@ -435,7 +435,7 @@ public:
void ShowBuildIndustryWindow()
{
- if (_game_mode != GM_EDITOR && !IsValidCompanyID(_local_company)) return;
+ if (_game_mode != GM_EDITOR && !Company::IsValidID(_local_company)) return;
if (BringWindowToFrontById(WC_BUILD_INDUSTRY, 0)) return;
new BuildIndustryWindow();
}
diff --git a/src/misc_cmd.cpp b/src/misc_cmd.cpp
index 907d6724c..952a8e752 100644
--- a/src/misc_cmd.cpp
+++ b/src/misc_cmd.cpp
@@ -387,7 +387,7 @@ CommandCost CmdGiveMoney(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
/* You can only transfer funds that is in excess of your loan */
if (c->money - c->current_loan < amount.GetCost() || amount.GetCost() <= 0) return CMD_ERROR;
- if (!_networking || !IsValidCompanyID((CompanyID)p2)) return CMD_ERROR;
+ if (!_networking || !Company::IsValidID((CompanyID)p2)) return CMD_ERROR;
if (flags & DC_EXEC) {
/* Add money to company */
diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp
index 2d0ef8931..94ca288f7 100644
--- a/src/misc_gui.cpp
+++ b/src/misc_gui.cpp
@@ -104,7 +104,7 @@ public:
}
LandInfoWindow(TileIndex tile) : Window(&_land_info_desc) {
- Company *c = Company::Get(IsValidCompanyID(_local_company) ? _local_company : COMPANY_FIRST);
+ Company *c = Company::Get(Company::IsValidID(_local_company) ? _local_company : COMPANY_FIRST);
Town *t = ClosestTownFromTile(tile, _settings_game.economy.dist_local_authority);
Money old_money = c->money;
diff --git a/src/network/core/tcp_game.h b/src/network/core/tcp_game.h
index 48abc996d..3bbb3ac0a 100644
--- a/src/network/core/tcp_game.h
+++ b/src/network/core/tcp_game.h
@@ -108,11 +108,6 @@ public:
void Send_Command(Packet *p, const CommandPacket *cp);
};
-static inline bool IsValidNetworkClientSocketIndex(ClientIndex index)
-{
- return (uint)index < NetworkClientSocket::GetPoolSize() && NetworkClientSocket::Get(index)->IsValid();
-}
-
#define FOR_ALL_CLIENT_SOCKETS_FROM(d, start) for (d = NetworkClientSocket::Get(start); d != NULL; d = (d->index + 1U < NetworkClientSocket::GetPoolSize()) ? NetworkClientSocket::Get(d->index + 1U) : NULL) if (d->IsValid())
#define FOR_ALL_CLIENT_SOCKETS(d) FOR_ALL_CLIENT_SOCKETS_FROM(d, 0)
diff --git a/src/network/network.cpp b/src/network/network.cpp
index 95ff34dcc..c661e1a98 100644
--- a/src/network/network.cpp
+++ b/src/network/network.cpp
@@ -97,7 +97,7 @@ extern void StateGameLoop();
*/
NetworkClientInfo *NetworkFindClientInfoFromIndex(ClientIndex index)
{
- return IsValidNetworkClientInfoIndex(index) ? NetworkClientInfo::Get(index) : NULL;
+ return NetworkClientInfo::IsValidID(index) ? NetworkClientInfo::Get(index) : NULL;
}
/**
@@ -339,7 +339,7 @@ static uint NetworkCountActiveClients()
uint count = 0;
FOR_ALL_CLIENT_INFOS(ci) {
- if (IsValidCompanyID(ci->client_playas)) count++;
+ if (Company::IsValidID(ci->client_playas)) count++;
}
return count;
diff --git a/src/network/network_base.h b/src/network/network_base.h
index 3044de7a1..929c4b7ba 100644
--- a/src/network/network_base.h
+++ b/src/network/network_base.h
@@ -27,11 +27,6 @@ struct NetworkClientInfo : PoolItem<NetworkClientInfo, ClientIndex, &_NetworkCli
inline bool IsValid() const { return client_id != INVALID_CLIENT_ID; }
};
-static inline bool IsValidNetworkClientInfoIndex(ClientIndex index)
-{
- return (uint)index < NetworkClientInfo::GetPoolSize() && NetworkClientInfo::Get(index)->IsValid();
-}
-
#define FOR_ALL_CLIENT_INFOS_FROM(d, start) for (d = NetworkClientInfo::Get(start); d != NULL; d = (d->index + 1U < NetworkClientInfo::GetPoolSize()) ? NetworkClientInfo::Get(d->index + 1U) : NULL) if (d->IsValid())
#define FOR_ALL_CLIENT_INFOS(d) FOR_ALL_CLIENT_INFOS_FROM(d, 0)
diff --git a/src/network/network_client.cpp b/src/network/network_client.cpp
index 4a6897bf3..db25c8f7a 100644
--- a/src/network/network_client.cpp
+++ b/src/network/network_client.cpp
@@ -620,7 +620,7 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_MAP)
/* New company/spectator (invalid company) or company we want to join is not active
* Switch local company to spectator and await the server's judgement */
- if (_network_playas == COMPANY_NEW_COMPANY || !IsValidCompanyID(_network_playas)) {
+ if (_network_playas == COMPANY_NEW_COMPANY || !Company::IsValidID(_network_playas)) {
SetLocalCompany(COMPANY_SPECTATOR);
if (_network_playas != COMPANY_SPECTATOR) {
@@ -723,10 +723,10 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_CHAT)
/* For speaking to company or giving money, we need the company-name */
case NETWORK_ACTION_GIVE_MONEY:
- if (!IsValidCompanyID(ci_to->client_playas)) return NETWORK_RECV_STATUS_OKAY;
+ if (!Company::IsValidID(ci_to->client_playas)) return NETWORK_RECV_STATUS_OKAY;
/* fallthrough */
case NETWORK_ACTION_CHAT_COMPANY: {
- StringID str = IsValidCompanyID(ci_to->client_playas) ? STR_COMPANY_NAME : STR_NETWORK_SPECTATORS;
+ StringID str = Company::IsValidID(ci_to->client_playas) ? STR_COMPANY_NAME : STR_NETWORK_SPECTATORS;
SetDParam(0, ci_to->client_playas);
GetString(name, str, lastof(name));
@@ -842,7 +842,7 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_MOVE)
if (ci == NULL) return NETWORK_RECV_STATUS_OKAY;
/* if not valid player, force spectator, else check player exists */
- if (!IsValidCompanyID(company_id)) company_id = COMPANY_SPECTATOR;
+ if (!Company::IsValidID(company_id)) company_id = COMPANY_SPECTATOR;
if (client_id == _network_own_client_id) {
_network_playas = company_id;
@@ -1006,7 +1006,7 @@ void NetworkClientSetPassword(const char *password)
bool NetworkClientPreferTeamChat(const NetworkClientInfo *cio)
{
/* Only companies actually playing can speak to team. Eg spectators cannot */
- if (!_settings_client.gui.prefer_teamchat || !IsValidCompanyID(cio->client_playas)) return false;
+ if (!_settings_client.gui.prefer_teamchat || !Company::IsValidID(cio->client_playas)) return false;
const NetworkClientInfo *ci;
FOR_ALL_CLIENT_INFOS(ci) {
@@ -1044,7 +1044,7 @@ void NetworkPrintClients()
IConsolePrintF(CC_INFO, "Client #%1d name: '%s' company: %1d IP: %s",
ci->client_id,
ci->client_name,
- ci->client_playas + (IsValidCompanyID(ci->client_playas) ? 1 : 0),
+ ci->client_playas + (Company::IsValidID(ci->client_playas) ? 1 : 0),
GetClientIP(ci));
}
}
diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp
index 6256adc10..23cdec35d 100644
--- a/src/network/network_gui.cpp
+++ b/src/network/network_gui.cpp
@@ -1808,7 +1808,7 @@ struct NetworkClientListPopupWindow : Window {
this->proc[i++] = &ClientList_SpeakToClient;
}
- if (IsValidCompanyID(ci->client_playas) || ci->client_playas == COMPANY_SPECTATOR) {
+ if (Company::IsValidID(ci->client_playas) || ci->client_playas == COMPANY_SPECTATOR) {
GetString(this->action[i], STR_NETWORK_CLIENTLIST_SPEAK_TO_COMPANY, lastof(this->action[i]));
this->proc[i++] = &ClientList_SpeakToCompany;
}
@@ -1817,7 +1817,7 @@ struct NetworkClientListPopupWindow : Window {
if (_network_own_client_id != ci->client_id) {
/* We are no spectator and the company we want to give money to is no spectator and money gifts are allowed */
- if (IsValidCompanyID(_network_playas) && IsValidCompanyID(ci->client_playas) && _settings_game.economy.give_money) {
+ if (Company::IsValidID(_network_playas) && Company::IsValidID(ci->client_playas) && _settings_game.economy.give_money) {
GetString(this->action[i], STR_NETWORK_CLIENTLIST_GIVE_MONEY, lastof(this->action[i]));
this->proc[i++] = &ClientList_GiveMoney;
}
@@ -2013,7 +2013,7 @@ struct NetworkClientListWindow : Window
}
/* Filter out spectators */
- if (IsValidCompanyID(ci->client_playas)) DrawCompanyIcon(ci->client_playas, 64, y + 1);
+ if (Company::IsValidID(ci->client_playas)) DrawCompanyIcon(ci->client_playas, 64, y + 1);
DrawString(81, this->width - 2, y, ci->client_name, colour);
diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp
index 9b29070a9..e48137547 100644
--- a/src/network/network_server.cpp
+++ b/src/network/network_server.cpp
@@ -76,7 +76,7 @@ DEF_SERVER_SEND_COMMAND(PACKET_SERVER_COMPANY_INFO)
/* Add the local player (if not dedicated) */
const NetworkClientInfo *ci = NetworkFindClientInfoFromClientID(CLIENT_ID_SERVER);
- if (ci != NULL && IsValidCompanyID(ci->client_playas)) {
+ if (ci != NULL && Company::IsValidID(ci->client_playas)) {
strecpy(clients[ci->client_playas], ci->client_name, lastof(clients[ci->client_playas]));
}
@@ -86,7 +86,7 @@ DEF_SERVER_SEND_COMMAND(PACKET_SERVER_COMPANY_INFO)
NetworkGetClientName(client_name, sizeof(client_name), csi);
ci = csi->GetInfo();
- if (ci != NULL && IsValidCompanyID(ci->client_playas)) {
+ if (ci != NULL && Company::IsValidID(ci->client_playas)) {
if (!StrEmpty(clients[ci->client_playas])) {
strecat(clients[ci->client_playas], ", ", lastof(clients[ci->client_playas]));
}
@@ -632,7 +632,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_NEWGRFS_CHECKED)
if (!StrEmpty(_settings_client.network.server_password)) {
SEND_COMMAND(PACKET_SERVER_NEED_PASSWORD)(cs, NETWORK_GAME_PASSWORD);
} else {
- if (IsValidCompanyID(ci->client_playas) && !StrEmpty(_network_company_states[ci->client_playas].password)) {
+ if (Company::IsValidID(ci->client_playas) && !StrEmpty(_network_company_states[ci->client_playas].password)) {
SEND_COMMAND(PACKET_SERVER_NEED_PASSWORD)(cs, NETWORK_COMPANY_PASSWORD);
} else {
SEND_COMMAND(PACKET_SERVER_WELCOME)(cs);
@@ -686,7 +686,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_JOIN)
}
break;
default: // Join another company (companies 1-8 (index 0-7))
- if (!IsValidCompanyID(playas) || !IsHumanCompany(playas)) {
+ if (!Company::IsValidID(playas) || !IsHumanCompany(playas)) {
SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_COMPANY_MISMATCH);
return;
}
@@ -710,7 +710,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_JOIN)
ci->client_lang = client_lang;
/* Make sure companies to which people try to join are not autocleaned */
- if (IsValidCompanyID(playas)) _network_company_states[playas].months_empty = 0;
+ if (Company::IsValidID(playas)) _network_company_states[playas].months_empty = 0;
if (_grfconfig == NULL) {
RECEIVE_COMMAND(PACKET_CLIENT_NEWGRFS_CHECKED)(cs, NULL);
@@ -738,7 +738,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_PASSWORD)
ci = cs->GetInfo();
- if (IsValidCompanyID(ci->client_playas) && !StrEmpty(_network_company_states[ci->client_playas].password)) {
+ if (Company::IsValidID(ci->client_playas) && !StrEmpty(_network_company_states[ci->client_playas].password)) {
SEND_COMMAND(PACKET_SERVER_NEED_PASSWORD)(cs, NETWORK_COMPANY_PASSWORD);
return;
}
@@ -872,7 +872,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_COMMAND)
return;
}
- if ((GetCommandFlags(cp.cmd) & CMD_SPECTATOR) == 0 && !IsValidCompanyID(cp.company) && ci->client_id != CLIENT_ID_SERVER) {
+ if ((GetCommandFlags(cp.cmd) & CMD_SPECTATOR) == 0 && !Company::IsValidID(cp.company) && ci->client_id != CLIENT_ID_SERVER) {
IConsolePrintF(CC_ERROR, "WARNING: spectator issueing command from client %d (IP: %s), kicking...", ci->client_id, GetClientIP(ci));
SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_KICKED);
return;
@@ -1100,7 +1100,7 @@ void NetworkServerSendChat(NetworkAction action, DestType desttype, int dest, co
if (ci != NULL && show_local) {
if (from_id == CLIENT_ID_SERVER) {
char name[NETWORK_NAME_LENGTH];
- StringID str = IsValidCompanyID(ci_to->client_playas) ? STR_COMPANY_NAME : STR_NETWORK_SPECTATORS;
+ StringID str = Company::IsValidID(ci_to->client_playas) ? STR_COMPANY_NAME : STR_NETWORK_SPECTATORS;
SetDParam(0, ci_to->client_playas);
GetString(name, str, lastof(name));
NetworkTextMessage(action, (ConsoleColour)GetDrawStringCompanyColour(ci_own->client_playas), true, name, msg, data);
@@ -1147,7 +1147,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_CHAT)
NetworkClientInfo *ci = cs->GetInfo();
switch (action) {
case NETWORK_ACTION_GIVE_MONEY:
- if (!IsValidCompanyID(ci->client_playas)) break;
+ if (!Company::IsValidID(ci->client_playas)) break;
/* Fall-through */
case NETWORK_ACTION_CHAT:
case NETWORK_ACTION_CHAT_CLIENT:
@@ -1175,7 +1175,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_SET_PASSWORD)
p->Recv_string(password, sizeof(password));
ci = cs->GetInfo();
- if (IsValidCompanyID(ci->client_playas)) {
+ if (Company::IsValidID(ci->client_playas)) {
strecpy(_network_company_states[ci->client_playas].password, password, lastof(_network_company_states[ci->client_playas].password));
NetworkServerUpdateCompanyPassworded(ci->client_playas, !StrEmpty(_network_company_states[ci->client_playas].password));
}
@@ -1235,7 +1235,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_MOVE)
CompanyID company_id = (Owner)p->Recv_uint8();
/* Check if the company is valid */
- if (!IsValidCompanyID(company_id) && company_id != COMPANY_SPECTATOR) return;
+ if (!Company::IsValidID(company_id) && company_id != COMPANY_SPECTATOR) return;
/* We don't allow moving to AI companies */
if (company_id != COMPANY_SPECTATOR && Company::Get(company_id)->is_ai) return;
@@ -1364,7 +1364,7 @@ void NetworkPopulateCompanyStats(NetworkCompanyStats *stats)
/* Go through all vehicles and count the type of vehicles */
FOR_ALL_VEHICLES(v) {
- if (!IsValidCompanyID(v->owner) || !v->IsPrimaryVehicle()) continue;
+ if (!Company::IsValidID(v->owner) || !v->IsPrimaryVehicle()) continue;
byte type = 0;
switch (v->type) {
case VEH_TRAIN: type = 0; break;
@@ -1378,7 +1378,7 @@ void NetworkPopulateCompanyStats(NetworkCompanyStats *stats)
/* Go through all stations and count the types of stations */
FOR_ALL_STATIONS(s) {
- if (IsValidCompanyID(s->owner)) {
+ if (Company::IsValidID(s->owner)) {
NetworkCompanyStats *npi = &stats[s->owner];
if (s->facilities & FACIL_TRAIN) npi->num_station[0]++;
@@ -1431,12 +1431,12 @@ static void NetworkAutoCleanCompanies()
/* Detect the active companies */
FOR_ALL_CLIENT_INFOS(ci) {
- if (IsValidCompanyID(ci->client_playas)) clients_in_company[ci->client_playas] = true;
+ if (Company::IsValidID(ci->client_playas)) clients_in_company[ci->client_playas] = true;
}
if (!_network_dedicated) {
ci = NetworkFindClientInfoFromClientID(CLIENT_ID_SERVER);
- if (IsValidCompanyID(ci->client_playas)) clients_in_company[ci->client_playas] = true;
+ if (Company::IsValidID(ci->client_playas)) clients_in_company[ci->client_playas] = true;
}
if (_settings_client.network.autoclean_novehicles != 0) {
@@ -1444,7 +1444,7 @@ static void NetworkAutoCleanCompanies()
const Vehicle *v;
FOR_ALL_VEHICLES(v) {
- if (!IsValidCompanyID(v->owner) || !v->IsPrimaryVehicle()) continue;
+ if (!Company::IsValidID(v->owner) || !v->IsPrimaryVehicle()) continue;
vehicles_in_company[v->owner]++;
}
}
@@ -1710,7 +1710,7 @@ void NetworkServerShowStatusToConsole()
status = (cs->status < (ptrdiff_t)lengthof(stat_str) ? stat_str[cs->status] : "unknown");
IConsolePrintF(CC_INFO, "Client #%1d name: '%s' status: '%s' frame-lag: %3d company: %1d IP: %s unique-id: '%s'",
cs->client_id, ci->client_name, status, lag,
- ci->client_playas + (IsValidCompanyID(ci->client_playas) ? 1 : 0),
+ ci->client_playas + (Company::IsValidID(ci->client_playas) ? 1 : 0),
GetClientIP(ci), ci->unique_id);
}
}
diff --git a/src/newgrf_engine.cpp b/src/newgrf_engine.cpp
index 383ccc1ef..b877174e1 100644
--- a/src/newgrf_engine.cpp
+++ b/src/newgrf_engine.cpp
@@ -430,7 +430,7 @@ static uint8 LiveryHelper(EngineID engine, const Vehicle *v)
const Livery *l;
if (v == NULL) {
- if (!IsValidCompanyID(_current_company)) return 0;
+ if (!Company::IsValidID(_current_company)) return 0;
l = GetEngineLivery(engine, _current_company, INVALID_ENGINE, NULL);
} else if (v->type == VEH_TRAIN) {
l = GetEngineLivery(v->engine_type, v->owner, v->u.rail.first_engine, v);
diff --git a/src/newgrf_house.cpp b/src/newgrf_house.cpp
index 3179edbfd..15052c7b5 100644
--- a/src/newgrf_house.cpp
+++ b/src/newgrf_house.cpp
@@ -518,7 +518,7 @@ bool CanDeleteHouse(TileIndex tile)
/* Humans are always allowed to remove buildings, as is water and
* anyone using the scenario editor. */
- if ((IsValidCompanyID(_current_company) && IsHumanCompany(_current_company))
+ if ((Company::IsValidID(_current_company) && IsHumanCompany(_current_company))
|| _current_company == OWNER_WATER || _current_company == OWNER_NONE) return true;
if (HasBit(hs->callback_mask, CBM_HOUSE_DENY_DESTRUCTION)) {
diff --git a/src/newgrf_industries.cpp b/src/newgrf_industries.cpp
index 2cf283574..4b54a2e93 100644
--- a/src/newgrf_industries.cpp
+++ b/src/newgrf_industries.cpp
@@ -214,7 +214,7 @@ uint32 IndustryGetVariable(const ResolverObject *object, byte variable, byte par
byte colours;
bool is_ai = false;
- if (IsValidCompanyID(industry->founder)) {
+ if (Company::IsValidID(industry->founder)) {
const Company *c = Company::Get(industry->founder);
const Livery *l = &c->livery[LS_DEFAULT];
diff --git a/src/oldpool.h b/src/oldpool.h
index 50bbdfe6e..66ae81752 100644
--- a/src/oldpool.h
+++ b/src/oldpool.h
@@ -288,12 +288,22 @@ struct PoolItem {
/**
* Returns size of the pool (in number of items)
+ * @return size of the pool
*/
static FORCEINLINE uint GetPoolSize()
{
return Tpool->GetSize();
}
+ /**
+ * Tests if given ID belongs to valid pool item
+ * @return is given ID valid?
+ */
+ static FORCEINLINE bool IsValidID(uint index)
+ {
+ return index < Tpool->GetSize() && Tpool->Get(index)->IsValid();
+ }
+
private:
static T *AllocateSafeRaw(uint &first);
diff --git a/src/order_base.h b/src/order_base.h
index 1c6566194..67edbb2c2 100644
--- a/src/order_base.h
+++ b/src/order_base.h
@@ -421,11 +421,6 @@ public:
void DebugCheckSanity() const;
};
-static inline bool IsValidOrderListID(uint index)
-{
- return index < OrderList::GetPoolSize() && OrderList::Get(index)->IsValid();
-}
-
#define FOR_ALL_ORDERS_FROM(order, start) for (order = Order::Get(start); order != NULL; order = (order->index + 1U < Order::GetPoolSize()) ? Order::Get(order->index + 1U) : NULL) if (order->IsValid())
#define FOR_ALL_ORDERS(order) FOR_ALL_ORDERS_FROM(order, 0)
diff --git a/src/order_cmd.cpp b/src/order_cmd.cpp
index e71d3b43b..6adb8ca47 100644
--- a/src/order_cmd.cpp
+++ b/src/order_cmd.cpp
@@ -416,7 +416,7 @@ CommandCost CmdInsertOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
VehicleOrderID sel_ord = GB(p1, 16, 16);
Order new_order(p2);
- if (!IsValidVehicleID(veh)) return CMD_ERROR;
+ if (!Vehicle::IsValidID(veh)) return CMD_ERROR;
v = Vehicle::Get(veh);
@@ -426,7 +426,7 @@ CommandCost CmdInsertOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
* and has the correct flags if any */
switch (new_order.GetType()) {
case OT_GOTO_STATION: {
- if (!IsValidStationID(new_order.GetDestination())) return CMD_ERROR;
+ if (!Station::IsValidID(new_order.GetDestination())) return CMD_ERROR;
const Station *st = Station::Get(new_order.GetDestination());
@@ -472,7 +472,7 @@ CommandCost CmdInsertOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
case OT_GOTO_DEPOT: {
if (new_order.GetDepotActionType() != ODATFB_NEAREST_DEPOT) {
if (v->type == VEH_AIRCRAFT) {
- if (!IsValidStationID(new_order.GetDestination())) return CMD_ERROR;
+ if (!Station::IsValidID(new_order.GetDestination())) return CMD_ERROR;
const Station *st = Station::Get(new_order.GetDestination());
@@ -482,7 +482,7 @@ CommandCost CmdInsertOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
return CMD_ERROR;
}
} else {
- if (!IsValidDepotID(new_order.GetDestination())) return CMD_ERROR;
+ if (!Depot::IsValidID(new_order.GetDestination())) return CMD_ERROR;
const Depot *dp = Depot::Get(new_order.GetDestination());
@@ -518,7 +518,7 @@ CommandCost CmdInsertOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
case OT_GOTO_WAYPOINT: {
if (v->type != VEH_TRAIN) return CMD_ERROR;
- if (!IsValidWaypointID(new_order.GetDestination())) return CMD_ERROR;
+ if (!Waypoint::IsValidID(new_order.GetDestination())) return CMD_ERROR;
const Waypoint *wp = Waypoint::Get(new_order.GetDestination());
if (!CheckOwnership(wp->owner)) return CMD_ERROR;
@@ -665,7 +665,7 @@ CommandCost CmdDeleteOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
VehicleOrderID sel_ord = p2;
Order *order;
- if (!IsValidVehicleID(veh_id)) return CMD_ERROR;
+ if (!Vehicle::IsValidID(veh_id)) return CMD_ERROR;
v = Vehicle::Get(veh_id);
@@ -732,7 +732,7 @@ CommandCost CmdSkipToOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
VehicleID veh_id = p1;
VehicleOrderID sel_ord = p2;
- if (!IsValidVehicleID(veh_id)) return CMD_ERROR;
+ if (!Vehicle::IsValidID(veh_id)) return CMD_ERROR;
v = Vehicle::Get(veh_id);
@@ -772,7 +772,7 @@ CommandCost CmdMoveOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
VehicleOrderID moving_order = GB(p2, 0, 16);
VehicleOrderID target_order = GB(p2, 16, 16);
- if (!IsValidVehicleID(veh)) return CMD_ERROR;
+ if (!Vehicle::IsValidID(veh)) return CMD_ERROR;
Vehicle *v = Vehicle::Get(veh);
if (!CheckOwnership(v->owner)) return CMD_ERROR;
@@ -852,7 +852,7 @@ CommandCost CmdModifyOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
uint16 data = GB(p2, 4, 11);
if (mof >= MOF_END) return CMD_ERROR;
- if (!IsValidVehicleID(veh)) return CMD_ERROR;
+ if (!Vehicle::IsValidID(veh)) return CMD_ERROR;
Vehicle *v = Vehicle::Get(veh);
if (!CheckOwnership(v->owner)) return CMD_ERROR;
@@ -1076,7 +1076,7 @@ CommandCost CmdCloneOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
VehicleID veh_src = GB(p1, 16, 16);
VehicleID veh_dst = GB(p1, 0, 16);
- if (!IsValidVehicleID(veh_dst)) return CMD_ERROR;
+ if (!Vehicle::IsValidID(veh_dst)) return CMD_ERROR;
dst = Vehicle::Get(veh_dst);
@@ -1086,7 +1086,7 @@ CommandCost CmdCloneOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
case CO_SHARE: {
Vehicle *src;
- if (!IsValidVehicleID(veh_src)) return CMD_ERROR;
+ if (!Vehicle::IsValidID(veh_src)) return CMD_ERROR;
src = Vehicle::Get(veh_src);
@@ -1132,7 +1132,7 @@ CommandCost CmdCloneOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
Vehicle *src;
int delta;
- if (!IsValidVehicleID(veh_src)) return CMD_ERROR;
+ if (!Vehicle::IsValidID(veh_src)) return CMD_ERROR;
src = Vehicle::Get(veh_src);
@@ -1208,7 +1208,7 @@ CommandCost CmdOrderRefit(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
CargoID cargo = GB(p2, 0, 8);
byte subtype = GB(p2, 8, 8);
- if (!IsValidVehicleID(veh)) return CMD_ERROR;
+ if (!Vehicle::IsValidID(veh)) return CMD_ERROR;
v = Vehicle::Get(veh);
@@ -1361,7 +1361,7 @@ CommandCost CmdRestoreOrderIndex(TileIndex tile, DoCommandFlag flags, uint32 p1,
VehicleOrderID cur_ord = GB(p2, 0, 16);
uint16 serv_int = GB(p2, 16, 16);
- if (!IsValidVehicleID(p1)) return CMD_ERROR;
+ if (!Vehicle::IsValidID(p1)) return CMD_ERROR;
v = Vehicle::Get(p1);
diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp
index 21be9352f..5c3345b49 100644
--- a/src/rail_cmd.cpp
+++ b/src/rail_cmd.cpp
@@ -523,7 +523,7 @@ CommandCost CmdRemoveSingleRail(TileIndex tile, DoCommandFlag flags, uint32 p1,
if (flags & DC_EXEC) {
/* if we got that far, 'owner' variable is set correctly */
- assert(IsValidCompanyID(owner));
+ assert(Company::IsValidID(owner));
MarkTileDirtyByTile(tile);
if (crossing) {
diff --git a/src/rail_gui.cpp b/src/rail_gui.cpp
index 682e508f4..0fbf12cd4 100644
--- a/src/rail_gui.cpp
+++ b/src/rail_gui.cpp
@@ -853,7 +853,7 @@ void ShowBuildRailToolbar(RailType railtype, int button)
{
BuildRailToolbarWindow *w;
- if (!IsValidCompanyID(_local_company)) return;
+ if (!Company::IsValidID(_local_company)) return;
if (!ValParamRailtype(railtype)) return;
/* don't recreate the window if we're clicking on a button and the window exists. */
@@ -1928,7 +1928,7 @@ void ReinitGuiAfterToggleElrail(bool disable)
/** Set the initial (default) railtype to use */
static void SetDefaultRailGui()
{
- if (_local_company == COMPANY_SPECTATOR || !IsValidCompanyID(_local_company)) return;
+ if (_local_company == COMPANY_SPECTATOR || !Company::IsValidID(_local_company)) return;
extern RailType _last_built_railtype;
RailType rt = (RailType)_settings_client.gui.default_rail_type;
diff --git a/src/road.cpp b/src/road.cpp
index 4634d1a6f..26b3d75f8 100644
--- a/src/road.cpp
+++ b/src/road.cpp
@@ -84,7 +84,7 @@ bool HasRoadTypesAvail(const CompanyID company, const RoadTypes rts)
if (company == OWNER_TOWN || _game_mode == GM_EDITOR || IsGeneratingWorld()) {
avail_roadtypes = ROADTYPES_ROAD;
} else {
- if (!IsValidCompanyID(company)) return false;
+ if (!Company::IsValidID(company)) return false;
avail_roadtypes = (RoadTypes)Company::Get(company)->avail_roadtypes | ROADTYPES_ROAD; // road is available for always for everybody
}
return (rts & ~avail_roadtypes) == 0;
diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp
index 4590111e2..356d1696e 100644
--- a/src/road_cmd.cpp
+++ b/src/road_cmd.cpp
@@ -119,7 +119,7 @@ bool CheckAllowRemoveRoad(TileIndex tile, RoadBits remove, Owner owner, RoadType
* Towns are not be allowed to remove non "normal" road pieces, like tram
* tracks as that would result in trams that cannot turn. */
if (_current_company == OWNER_WATER ||
- (rt == ROADTYPE_ROAD && !IsValidCompanyID(_current_company))) return true;
+ (rt == ROADTYPE_ROAD && !Company::IsValidID(_current_company))) return true;
/* Only do the special processing if the road is owned
* by a town */
@@ -455,7 +455,7 @@ CommandCost CmdBuildRoad(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
/* 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 ((IsValidCompanyID(_current_company) && p2 != 0) || (_current_company == OWNER_TOWN && !IsValidTownID(p2))) return CMD_ERROR;
+ if ((Company::IsValidID(_current_company) && p2 != 0) || (_current_company == OWNER_TOWN && !Town::IsValidID(p2))) return CMD_ERROR;
if (_current_company != OWNER_TOWN) {
const Town *town = CalcClosestTownFromTile(tile);
p2 = (town != NULL) ? town->index : (TownID)INVALID_TOWN;
diff --git a/src/road_gui.cpp b/src/road_gui.cpp
index c532439fd..b0d28e135 100644
--- a/src/road_gui.cpp
+++ b/src/road_gui.cpp
@@ -723,7 +723,7 @@ static const WindowDesc _build_tramway_desc(
void ShowBuildRoadToolbar(RoadType roadtype)
{
- if (!IsValidCompanyID(_local_company)) return;
+ if (!Company::IsValidID(_local_company)) return;
_cur_roadtype = roadtype;
DeleteWindowByClass(WC_BUILD_TOOLBAR);
diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp
index bdaab2281..8dcb8572e 100644
--- a/src/roadveh_cmd.cpp
+++ b/src/roadveh_cmd.cpp
@@ -314,7 +314,7 @@ CommandCost CmdSellRoadVeh(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
{
Vehicle *v;
- if (!IsValidVehicleID(p1)) return CMD_ERROR;
+ if (!Vehicle::IsValidID(p1)) return CMD_ERROR;
v = Vehicle::Get(p1);
@@ -423,7 +423,7 @@ CommandCost CmdSendRoadVehToDepot(TileIndex tile, DoCommandFlag flags, uint32 p1
return SendAllVehiclesToDepot(VEH_ROAD, flags, p2 & DEPOT_SERVICE, _current_company, (p2 & VLW_MASK), p1);
}
- if (!IsValidVehicleID(p1)) return CMD_ERROR;
+ if (!Vehicle::IsValidID(p1)) return CMD_ERROR;
Vehicle *v = Vehicle::Get(p1);
@@ -442,7 +442,7 @@ CommandCost CmdTurnRoadVeh(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
{
Vehicle *v;
- if (!IsValidVehicleID(p1)) return CMD_ERROR;
+ if (!Vehicle::IsValidID(p1)) return CMD_ERROR;
v = Vehicle::Get(p1);
@@ -1976,7 +1976,7 @@ CommandCost CmdRefitRoadVeh(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
uint16 capacity = CALLBACK_FAILED;
uint total_capacity = 0;
- if (!IsValidVehicleID(p1)) return CMD_ERROR;
+ if (!Vehicle::IsValidID(p1)) return CMD_ERROR;
v = Vehicle::Get(p1);
diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp
index b33b7e14a..b1829d5f6 100644
--- a/src/saveload/afterload.cpp
+++ b/src/saveload/afterload.cpp
@@ -281,7 +281,7 @@ void CDECL HandleSavegameLoadCrash(int unused)
*/
static void FixOwnerOfRailTrack(TileIndex t)
{
- assert(!IsValidCompanyID(GetTileOwner(t)) && (IsLevelCrossingTile(t) || IsPlainRailTile(t)));
+ assert(!Company::IsValidID(GetTileOwner(t)) && (IsLevelCrossingTile(t) || IsPlainRailTile(t)));
/* remove leftover rail piece from crossing (from very old savegames) */
Vehicle *v = NULL, *w;
@@ -303,7 +303,7 @@ static void FixOwnerOfRailTrack(TileIndex t)
TileIndex tt = t + TileOffsByDiagDir(dd);
if (GetTileTrackStatus(t, TRANSPORT_RAIL, 0, dd) != 0 &&
GetTileTrackStatus(tt, TRANSPORT_RAIL, 0, ReverseDiagDir(dd)) != 0 &&
- IsValidCompanyID(GetTileOwner(tt))) {
+ Company::IsValidID(GetTileOwner(tt))) {
SetTileOwner(t, GetTileOwner(tt));
return;
}
@@ -505,7 +505,7 @@ bool AfterLoadGame()
* a company does not exist yet. So create one here.
* 1 exeption: network-games. Those can have 0 companies
* But this exeption is not true for non dedicated network_servers! */
- if (!IsValidCompanyID(COMPANY_FIRST) && (!_networking || (_networking && _network_server && !_network_dedicated)))
+ if (!Company::IsValidID(COMPANY_FIRST) && (!_networking || (_networking && _network_server && !_network_dedicated)))
DoStartupNewCompany(false);
if (CheckSavegameVersion(72)) {
@@ -673,7 +673,7 @@ bool AfterLoadGame()
* becomes company 0, unless we are in the scenario editor where all the
* companies are 'invalid'.
*/
- if (!_network_dedicated && IsValidCompanyID(COMPANY_FIRST)) {
+ if (!_network_dedicated && Company::IsValidID(COMPANY_FIRST)) {
c = Company::Get(COMPANY_FIRST);
c->settings = _settings_client.company;
}
@@ -1203,7 +1203,7 @@ bool AfterLoadGame()
const CargoList::List *packets = v->cargo.Packets();
for (CargoList::List::const_iterator it = packets->begin(); it != packets->end(); it++) {
CargoPacket *cp = *it;
- cp->source_xy = IsValidStationID(cp->source) ? Station::Get(cp->source)->xy : v->tile;
+ cp->source_xy = Station::IsValidID(cp->source) ? Station::Get(cp->source)->xy : v->tile;
cp->loaded_at_xy = cp->source_xy;
}
v->cargo.InvalidateCache();
@@ -1222,7 +1222,7 @@ bool AfterLoadGame()
const CargoList::List *packets = ge->cargo.Packets();
for (CargoList::List::const_iterator it = packets->begin(); it != packets->end(); it++) {
CargoPacket *cp = *it;
- cp->source_xy = IsValidStationID(cp->source) ? Station::Get(cp->source)->xy : st->xy;
+ cp->source_xy = Station::IsValidID(cp->source) ? Station::Get(cp->source)->xy : st->xy;
cp->loaded_at_xy = cp->source_xy;
}
}
@@ -1481,7 +1481,7 @@ bool AfterLoadGame()
for (uint i = 0; i < 4; i++) {
CompanyID company = c->share_owners[i];
if (company == INVALID_COMPANY) continue;
- if (!IsValidCompanyID(company) || company == c->index) c->share_owners[i] = INVALID_COMPANY;
+ if (!Company::IsValidID(company) || company == c->index) c->share_owners[i] = INVALID_COMPANY;
}
}
}
@@ -1529,7 +1529,7 @@ bool AfterLoadGame()
if (IsBuoyTile(t) || IsDriveThroughStopTile(t) || IsTileType(t, MP_WATER)) {
Owner o = GetTileOwner(t);
- if (o < MAX_COMPANIES && !IsValidCompanyID(o)) {
+ if (o < MAX_COMPANIES && !Company::IsValidID(o)) {
_current_company = o;
ChangeTileOwner(t, o, INVALID_OWNER);
}
@@ -1543,13 +1543,13 @@ bool AfterLoadGame()
for (RoadType rt = ROADTYPE_ROAD; rt < ROADTYPE_END; rt++) {
/* update even non-existing road types to update tile owner too */
Owner o = GetRoadOwner(t, rt);
- if (o < MAX_COMPANIES && !IsValidCompanyID(o)) SetRoadOwner(t, rt, OWNER_NONE);
+ if (o < MAX_COMPANIES && !Company::IsValidID(o)) SetRoadOwner(t, rt, OWNER_NONE);
}
if (IsLevelCrossing(t)) {
- if (!IsValidCompanyID(GetTileOwner(t))) FixOwnerOfRailTrack(t);
+ if (!Company::IsValidID(GetTileOwner(t))) FixOwnerOfRailTrack(t);
}
} else if (IsTileType(t, MP_RAILWAY) && IsPlainRailTile(t)) {
- if (!IsValidCompanyID(GetTileOwner(t))) FixOwnerOfRailTrack(t);
+ if (!Company::IsValidID(GetTileOwner(t))) FixOwnerOfRailTrack(t);
}
}
@@ -1696,7 +1696,7 @@ bool AfterLoadGame()
/* signs with invalid owner left from older savegames */
Sign *si;
FOR_ALL_SIGNS(si) {
- if (si->owner != OWNER_NONE && !IsValidCompanyID(si->owner)) si->owner = OWNER_NONE;
+ if (si->owner != OWNER_NONE && !Company::IsValidID(si->owner)) si->owner = OWNER_NONE;
}
/* Station can get named based on an industry type, but the current ones
@@ -1785,7 +1785,7 @@ bool AfterLoadGame()
* they have st->owner == OWNER_NONE already. */
Station *st;
FOR_ALL_STATIONS(st) {
- if (!IsValidCompanyID(st->owner)) st->owner = OWNER_NONE;
+ if (!Company::IsValidID(st->owner)) st->owner = OWNER_NONE;
}
/* Give owners to waypoints, based on rail tracks it is sitting on.
@@ -1795,7 +1795,7 @@ bool AfterLoadGame()
Waypoint *wp;
FOR_ALL_WAYPOINTS(wp) {
Owner owner = IsTileType(wp->xy, MP_RAILWAY) ? GetTileOwner(wp->xy) : OWNER_NONE;
- wp->owner = IsValidCompanyID(owner) ? owner : OWNER_NONE;
+ wp->owner = Company::IsValidID(owner) ? owner : OWNER_NONE;
}
}
diff --git a/src/saveload/ai_sl.cpp b/src/saveload/ai_sl.cpp
index e963bd03b..ae6253902 100644
--- a/src/saveload/ai_sl.cpp
+++ b/src/saveload/ai_sl.cpp
@@ -43,7 +43,7 @@ static void SaveReal_AIPL(int *index_ptr)
SlObject(NULL, _ai_company);
/* If the AI was active, store his data too */
- if (IsValidCompanyID(index) && !IsHumanCompany(index)) AI::Save(index);
+ if (Company::IsValidID(index) && !IsHumanCompany(index)) AI::Save(index);
}
static void Load_AIPL()
@@ -59,7 +59,7 @@ static void Load_AIPL()
SlObject(NULL, _ai_company);
if (_networking && !_network_server) {
- if (IsValidCompanyID(index) && !IsHumanCompany(index)) AIInstance::LoadEmpty();
+ if (Company::IsValidID(index) && !IsHumanCompany(index)) AIInstance::LoadEmpty();
continue;
}
@@ -86,7 +86,7 @@ static void Load_AIPL()
config->StringToSettings(_ai_saveload_settings);
/* Start the AI directly if it was active in the savegame */
- if (IsValidCompanyID(index) && !IsHumanCompany(index)) {
+ if (Company::IsValidID(index) && !IsHumanCompany(index)) {
AI::StartNew(index);
AI::Load(index, _ai_saveload_version);
}
diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp
index 89731bf9c..8780234da 100644
--- a/src/saveload/saveload.cpp
+++ b/src/saveload/saveload.cpp
@@ -1864,7 +1864,7 @@ void GenerateDefaultSaveName(char *buf, const char *last)
* available company. When there's no company available we'll use
* 'Spectator' as "company" name. */
CompanyID cid = _local_company;
- if (!IsValidCompanyID(cid)) {
+ if (!Company::IsValidID(cid)) {
const Company *c;
FOR_ALL_COMPANIES(c) {
cid = c->index;
@@ -1884,7 +1884,7 @@ void GenerateDefaultSaveName(char *buf, const char *last)
SetDParam(2, _date);
/* Get the correct string (special string for when there's not company) */
- GetString(buf, !IsValidCompanyID(cid) ? STR_GAME_SAVELOAD_SPECTATOR_SAVEGAME : STR_DEFAULT_SAVEGAME_NAME, last);
+ GetString(buf, !Company::IsValidID(cid) ? STR_GAME_SAVELOAD_SPECTATOR_SAVEGAME : STR_DEFAULT_SAVEGAME_NAME, last);
SanitizeFilename(buf);
}
diff --git a/src/ship_cmd.cpp b/src/ship_cmd.cpp
index 2948117a7..6903859ba 100644
--- a/src/ship_cmd.cpp
+++ b/src/ship_cmd.cpp
@@ -821,7 +821,7 @@ CommandCost CmdSellShip(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p
{
Vehicle *v;
- if (!IsValidVehicleID(p1)) return CMD_ERROR;
+ if (!Vehicle::IsValidID(p1)) return CMD_ERROR;
v = Vehicle::Get(p1);
@@ -870,7 +870,7 @@ CommandCost CmdSendShipToDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, u
return SendAllVehiclesToDepot(VEH_SHIP, flags, p2 & DEPOT_SERVICE, _current_company, (p2 & VLW_MASK), p1);
}
- if (!IsValidVehicleID(p1)) return CMD_ERROR;
+ if (!Vehicle::IsValidID(p1)) return CMD_ERROR;
Vehicle *v = Vehicle::Get(p1);
@@ -898,7 +898,7 @@ CommandCost CmdRefitShip(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
byte new_subtype = GB(p2, 8, 8);
uint16 capacity = CALLBACK_FAILED;
- if (!IsValidVehicleID(p1)) return CMD_ERROR;
+ if (!Vehicle::IsValidID(p1)) return CMD_ERROR;
v = Vehicle::Get(p1);
diff --git a/src/signal.cpp b/src/signal.cpp
index 826992370..947e71a9f 100644
--- a/src/signal.cpp
+++ b/src/signal.cpp
@@ -466,11 +466,11 @@ static inline void ResetSets()
*
* @param owner company whose signals we are updating
* @return state of the first block from _globset
- * @pre IsValidCompanyID(owner)
+ * @pre Company::IsValidID(owner)
*/
static SigSegState UpdateSignalsInBuffer(Owner owner)
{
- assert(IsValidCompanyID(owner));
+ assert(Company::IsValidID(owner));
bool first = true; // first block?
SigSegState state = SIGSEG_FREE; // value to return
diff --git a/src/signs_base.h b/src/signs_base.h
index 88e57d330..0170b0a9a 100644
--- a/src/signs_base.h
+++ b/src/signs_base.h
@@ -41,11 +41,6 @@ static inline SignID GetMaxSignIndex()
return Sign::GetPoolSize() - 1;
}
-static inline bool IsValidSignID(uint index)
-{
- return index < Sign::GetPoolSize() && Sign::Get(index)->IsValid();
-}
-
#define FOR_ALL_SIGNS_FROM(ss, start) for (ss = Sign::Get(start); ss != NULL; ss = (ss->index + 1U < Sign::GetPoolSize()) ? Sign::Get(ss->index + 1U) : NULL) if (ss->IsValid())
#define FOR_ALL_SIGNS(ss) FOR_ALL_SIGNS_FROM(ss, 0)
diff --git a/src/signs_cmd.cpp b/src/signs_cmd.cpp
index 93ef28c1a..a44ca2241 100644
--- a/src/signs_cmd.cpp
+++ b/src/signs_cmd.cpp
@@ -66,7 +66,7 @@ CommandCost CmdPlaceSign(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
*/
CommandCost CmdRenameSign(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
{
- if (!IsValidSignID(p1)) return CMD_ERROR;
+ if (!Sign::IsValidID(p1)) return CMD_ERROR;
/* Rename the signs when empty, otherwise remove it */
if (!StrEmpty(text)) {
diff --git a/src/station_base.h b/src/station_base.h
index bbaebbb65..876d0d345 100644
--- a/src/station_base.h
+++ b/src/station_base.h
@@ -219,11 +219,6 @@ static inline uint GetNumStations()
return Station::GetPoolSize();
}
-static inline bool IsValidStationID(StationID index)
-{
- return index < Station::GetPoolSize() && Station::Get(index)->IsValid();
-}
-
#define FOR_ALL_STATIONS_FROM(st, start) for (st = Station::Get(start); st != NULL; st = (st->index + 1U < Station::GetPoolSize()) ? Station::Get(st->index + 1U) : NULL) if (st->IsValid())
#define FOR_ALL_STATIONS(st) FOR_ALL_STATIONS_FROM(st, 0)
diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp
index c26cfacfc..f307c8701 100644
--- a/src/station_cmd.cpp
+++ b/src/station_cmd.cpp
@@ -880,7 +880,7 @@ CommandCost CmdBuildRailroadStation(TileIndex tile_org, DoCommandFlag flags, uin
if (!reuse) station_to_join = INVALID_STATION;
bool distant_join = (station_to_join != INVALID_STATION);
- if (distant_join && (!_settings_game.station.distant_join_stations || !IsValidStationID(station_to_join))) return CMD_ERROR;
+ if (distant_join && (!_settings_game.station.distant_join_stations || !Station::IsValidID(station_to_join))) return CMD_ERROR;
if (h_org > _settings_game.station.station_spread || w_org > _settings_game.station.station_spread) return CMD_ERROR;
@@ -958,7 +958,7 @@ CommandCost CmdBuildRailroadStation(TileIndex tile_org, DoCommandFlag flags, uin
st->town = ClosestTownFromTile(tile_org, UINT_MAX);
st->string_id = GenerateStationName(st, tile_org, STATIONNAMING_RAIL);
- if (IsValidCompanyID(_current_company)) {
+ if (Company::IsValidID(_current_company)) {
SetBit(st->town->have_ratings, _current_company);
}
}
@@ -1365,7 +1365,7 @@ CommandCost CmdBuildRoadStop(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
Owner tram_owner = _current_company;
Owner road_owner = _current_company;
- if (distant_join && (!_settings_game.station.distant_join_stations || !IsValidStationID(station_to_join))) return CMD_ERROR;
+ if (distant_join && (!_settings_game.station.distant_join_stations || !Station::IsValidID(station_to_join))) return CMD_ERROR;
if (!AreValidRoadTypes(rts) || !HasRoadTypesAvail(_current_company, rts)) return CMD_ERROR;
@@ -1454,7 +1454,7 @@ CommandCost CmdBuildRoadStop(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
st->town = ClosestTownFromTile(tile, UINT_MAX);
st->string_id = GenerateStationName(st, tile, STATIONNAMING_ROAD);
- if (IsValidCompanyID(_current_company)) {
+ if (Company::IsValidID(_current_company)) {
SetBit(st->town->have_ratings, _current_company);
}
st->sign.width_1 = 0;
@@ -1817,7 +1817,7 @@ CommandCost CmdBuildAirport(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
if (!reuse) station_to_join = INVALID_STATION;
bool distant_join = (station_to_join != INVALID_STATION);
- if (distant_join && (!_settings_game.station.distant_join_stations || !IsValidStationID(station_to_join))) return CMD_ERROR;
+ if (distant_join && (!_settings_game.station.distant_join_stations || !Station::IsValidID(station_to_join))) return CMD_ERROR;
/* Check if a valid, buildable airport was chosen for construction */
if (p1 >= lengthof(_airport_sections) || !HasBit(GetValidAirports(), p1)) return CMD_ERROR;
@@ -1903,7 +1903,7 @@ CommandCost CmdBuildAirport(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
st->town = t;
st->string_id = GenerateStationName(st, tile, !(afc->flags & AirportFTAClass::AIRPLANES) ? STATIONNAMING_HELIPORT : STATIONNAMING_AIRPORT);
- if (IsValidCompanyID(_current_company)) {
+ if (Company::IsValidID(_current_company)) {
SetBit(st->town->have_ratings, _current_company);
}
st->sign.width_1 = 0;
@@ -2038,7 +2038,7 @@ CommandCost CmdBuildBuoy(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
st->town = ClosestTownFromTile(tile, UINT_MAX);
st->string_id = GenerateStationName(st, tile, STATIONNAMING_BUOY);
- if (IsValidCompanyID(_current_company)) {
+ if (Company::IsValidID(_current_company)) {
SetBit(st->town->have_ratings, _current_company);
}
st->sign.width_1 = 0;
@@ -2087,7 +2087,7 @@ bool HasStationInUse(StationID station, CompanyID company)
static CommandCost RemoveBuoy(Station *st, DoCommandFlag flags)
{
/* XXX: strange stuff */
- if (!IsValidCompanyID(_current_company)) return_cmd_error(INVALID_STRING_ID);
+ if (!Company::IsValidID(_current_company)) return_cmd_error(INVALID_STRING_ID);
TileIndex tile = st->dock_tile;
@@ -2139,7 +2139,7 @@ CommandCost CmdBuildDock(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
if (!reuse) station_to_join = INVALID_STATION;
bool distant_join = (station_to_join != INVALID_STATION);
- if (distant_join && (!_settings_game.station.distant_join_stations || !IsValidStationID(station_to_join))) return CMD_ERROR;
+ if (distant_join && (!_settings_game.station.distant_join_stations || !Station::IsValidID(station_to_join))) return CMD_ERROR;
DiagDirection direction = GetInclinedSlopeDirection(GetTileSlope(tile, NULL));
if (direction == INVALID_DIAGDIR) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
@@ -2208,7 +2208,7 @@ CommandCost CmdBuildDock(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
st->town = ClosestTownFromTile(tile, UINT_MAX);
st->string_id = GenerateStationName(st, tile, STATIONNAMING_DOCK);
- if (IsValidCompanyID(_current_company)) {
+ if (Company::IsValidID(_current_company)) {
SetBit(st->town->have_ratings, _current_company);
}
}
@@ -2294,7 +2294,7 @@ static void DrawTile_Station(TileInfo *ti)
Owner owner = GetTileOwner(ti->tile);
SpriteID palette;
- if (IsValidCompanyID(owner)) {
+ if (Company::IsValidID(owner)) {
palette = COMPANY_SPRITE_COLOUR(owner);
} else {
/* Some stations are not owner by a company, namely oil rigs */
@@ -2750,7 +2750,7 @@ static void UpdateStationRating(Station *st)
(rating += 13, true);
}
- if (IsValidCompanyID(st->owner) && HasBit(st->town->statues, st->owner)) rating += 26;
+ if (Company::IsValidID(st->owner) && HasBit(st->town->statues, st->owner)) rating += 26;
{
byte days = ge->days_since_pickup;
@@ -2842,7 +2842,7 @@ void OnTick_Station()
uint i = _station_tick_ctr;
if (++_station_tick_ctr > GetMaxStationIndex()) _station_tick_ctr = 0;
- if (IsValidStationID(i)) StationHandleBigTick(Station::Get(i));
+ if (Station::IsValidID(i)) StationHandleBigTick(Station::Get(i));
Station *st;
FOR_ALL_STATIONS(st) {
@@ -2911,7 +2911,7 @@ static bool IsUniqueStationName(const char *name)
*/
CommandCost CmdRenameStation(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
{
- if (!IsValidStationID(p1)) return CMD_ERROR;
+ if (!Station::IsValidID(p1)) return CMD_ERROR;
Station *st = Station::Get(p1);
if (!CheckOwnership(st->owner)) return CMD_ERROR;
diff --git a/src/station_gui.cpp b/src/station_gui.cpp
index f0abf4626..6fe69370f 100644
--- a/src/station_gui.cpp
+++ b/src/station_gui.cpp
@@ -676,7 +676,7 @@ static const WindowDesc _company_stations_desc(
*/
void ShowCompanyStations(CompanyID company)
{
- if (!IsValidCompanyID(company)) return;
+ if (!Company::IsValidID(company)) return;
AllocateWindowDescFront<CompanyStationsWindow>(&_company_stations_desc, company);
}
diff --git a/src/strings.cpp b/src/strings.cpp
index 0af358b41..00aee98a2 100644
--- a/src/strings.cpp
+++ b/src/strings.cpp
@@ -847,7 +847,7 @@ static char *FormatString(char *buff, const char *str, const int64 *argv, uint c
case SCC_STATION_NAME: { // {STATION}
StationID sid = GetInt32(&argv);
- if (!IsValidStationID(sid)) {
+ if (!Station::IsValidID(sid)) {
/* The station doesn't exist anymore. The only place where we might
* be "drawing" an invalid station is in the case of cargo that is
* in transit. */
@@ -986,7 +986,7 @@ static char *FormatString(char *buff, const char *str, const int64 *argv, uint c
CompanyID company = (CompanyID)GetInt32(&argv);
/* Nothing is added for AI or inactive companies */
- if (IsValidCompanyID(company) && IsHumanCompany(company)) {
+ if (Company::IsValidID(company) && IsHumanCompany(company)) {
int64 args[1];
args[0] = company + 1;
buff = GetStringWithArgs(buff, STR_COMPANY_NUM, args, last);
diff --git a/src/terraform_gui.cpp b/src/terraform_gui.cpp
index d16c14046..729b20511 100644
--- a/src/terraform_gui.cpp
+++ b/src/terraform_gui.cpp
@@ -352,7 +352,7 @@ static const WindowDesc _terraform_desc(
void ShowTerraformToolbar(Window *link)
{
- if (!IsValidCompanyID(_local_company)) return;
+ if (!Company::IsValidID(_local_company)) return;
Window *w = AllocateWindowDescFront<TerraformToolbarWindow>(&_terraform_desc, 0);
if (link == NULL) return;
diff --git a/src/timetable_cmd.cpp b/src/timetable_cmd.cpp
index 5f12bb365..1897d46eb 100644
--- a/src/timetable_cmd.cpp
+++ b/src/timetable_cmd.cpp
@@ -57,7 +57,7 @@ CommandCost CmdChangeTimetable(TileIndex tile, DoCommandFlag flags, uint32 p1, u
if (!_settings_game.order.timetabling) return CMD_ERROR;
VehicleID veh = GB(p1, 0, 16);
- if (!IsValidVehicleID(veh)) return CMD_ERROR;
+ if (!Vehicle::IsValidID(veh)) return CMD_ERROR;
Vehicle *v = Vehicle::Get(veh);
if (!CheckOwnership(v->owner)) return CMD_ERROR;
@@ -115,7 +115,7 @@ CommandCost CmdSetVehicleOnTime(TileIndex tile, DoCommandFlag flags, uint32 p1,
if (!_settings_game.order.timetabling) return CMD_ERROR;
VehicleID veh = GB(p1, 0, 16);
- if (!IsValidVehicleID(veh)) return CMD_ERROR;
+ if (!Vehicle::IsValidID(veh)) return CMD_ERROR;
Vehicle *v = Vehicle::Get(veh);
if (!CheckOwnership(v->owner)) return CMD_ERROR;
@@ -143,7 +143,7 @@ CommandCost CmdAutofillTimetable(TileIndex tile, DoCommandFlag flags, uint32 p1,
if (!_settings_game.order.timetabling) return CMD_ERROR;
VehicleID veh = GB(p1, 0, 16);
- if (!IsValidVehicleID(veh)) return CMD_ERROR;
+ if (!Vehicle::IsValidID(veh)) return CMD_ERROR;
Vehicle *v = Vehicle::Get(veh);
if (!CheckOwnership(v->owner)) return CMD_ERROR;
diff --git a/src/toolbar_gui.cpp b/src/toolbar_gui.cpp
index 3be67b7d3..fffe40ad9 100644
--- a/src/toolbar_gui.cpp
+++ b/src/toolbar_gui.cpp
@@ -222,7 +222,7 @@ static void PopupMainCompanyToolbMenu(Window *w, int widget, int grey = 0)
#endif /* ENABLE_NETWORK */
for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
- if (!IsValidCompanyID(c)) continue;
+ if (!Company::IsValidID(c)) continue;
list->push_back(new DropDownListCompanyItem(c, false, HasBit(grey, c)));
}
diff --git a/src/town.h b/src/town.h
index bc746fb83..db7bf04f5 100644
--- a/src/town.h
+++ b/src/town.h
@@ -295,16 +295,6 @@ static inline HouseSpec *GetHouseSpecs(HouseID house_id)
TileIndexDiff GetHouseNorthPart(HouseID &house);
-/**
- * Check if a TownID is valid.
- * @param index to inquiry in the pool of town
- * @return true if it exists
- */
-static inline bool IsValidTownID(TownID index)
-{
- return index < Town::GetPoolSize() && Town::Get(index)->IsValid();
-}
-
static inline TownID GetMaxTownIndex()
{
/* TODO - This isn't the real content of the function, but
@@ -335,7 +325,7 @@ static inline Town *GetRandomTown()
index++;
/* Make sure we have a valid town */
- while (!IsValidTownID(index)) {
+ while (!Town::IsValidID(index)) {
index++;
assert(index <= GetMaxTownIndex());
}
diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp
index e36fd2905..f56c35205 100644
--- a/src/town_cmd.cpp
+++ b/src/town_cmd.cpp
@@ -535,7 +535,7 @@ static CommandCost ClearTile_Town(TileIndex tile, DoCommandFlag flags)
_cleared_town_rating += rating;
Town *t = _cleared_town = GetTownByTile(tile);
- if (IsValidCompanyID(_current_company)) {
+ if (Company::IsValidID(_current_company)) {
if (rating > t->ratings[_current_company] && !(flags & DC_NO_TEST_TOWN_RATING) && !_cheats.magic_bulldozer.value) {
SetDParam(0, t->index);
return_cmd_error(STR_ERROR_LOCAL_AUTHORITY_REFUSES_TO_ALLOW_THIS);
@@ -693,7 +693,7 @@ void OnTick_Town()
if (++_cur_town_ctr > GetMaxTownIndex())
_cur_town_ctr = 0;
- if (IsValidTownID(i)) TownTickHandler(Town::Get(i));
+ if (Town::IsValidID(i)) TownTickHandler(Town::Get(i));
}
}
@@ -2278,7 +2278,7 @@ static bool IsUniqueTownName(const char *name)
*/
CommandCost CmdRenameTown(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
{
- if (!IsValidTownID(p1)) return CMD_ERROR;
+ if (!Town::IsValidID(p1)) return CMD_ERROR;
bool reset = StrEmpty(text);
@@ -2553,7 +2553,7 @@ uint GetMaskOfTownActions(int *nump, CompanyID cid, const Town *t)
*/
CommandCost CmdDoTownAction(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
{
- if (!IsValidTownID(p1) || p2 >= lengthof(_town_action_proc)) return CMD_ERROR;
+ if (!Town::IsValidID(p1) || p2 >= lengthof(_town_action_proc)) return CMD_ERROR;
Town *t = Town::Get(p1);
@@ -2586,12 +2586,12 @@ static void UpdateTownGrowRate(Town *t)
if (DistanceSquare(st->xy, t->xy) <= t->squared_town_zone_radius[0]) {
if (st->time_since_load <= 20 || st->time_since_unload <= 20) {
n++;
- if (IsValidCompanyID(st->owner)) {
+ if (Company::IsValidID(st->owner)) {
int new_rating = t->ratings[st->owner] + RATING_STATION_UP_STEP;
t->ratings[st->owner] = min(new_rating, INT16_MAX); // do not let it overflow
}
} else {
- if (IsValidCompanyID(st->owner)) {
+ if (Company::IsValidID(st->owner)) {
int new_rating = t->ratings[st->owner] + RATING_STATION_DOWN_STEP;
t->ratings[st->owner] = max(new_rating, INT16_MIN);
}
@@ -2682,7 +2682,7 @@ static void UpdateTownUnwanted(Town *t)
*/
bool CheckIfAuthorityAllowsNewStation(TileIndex tile, DoCommandFlag flags)
{
- if (!IsValidCompanyID(_current_company) || (flags & DC_NO_TEST_TOWN_RATING)) return true;
+ if (!Company::IsValidID(_current_company) || (flags & DC_NO_TEST_TOWN_RATING)) return true;
Town *t = ClosestTownFromTile(tile, _settings_game.economy.dist_local_authority);
if (t == NULL) return true;
@@ -2784,7 +2784,7 @@ void ChangeTownRating(Town *t, int add, int max, DoCommandFlag flags)
{
/* if magic_bulldozer cheat is active, town doesn't penaltize for removing stuff */
if (t == NULL || (flags & DC_NO_MODIFY_TOWN_RATING) ||
- !IsValidCompanyID(_current_company) ||
+ !Company::IsValidID(_current_company) ||
(_cheats.magic_bulldozer.value && add < 0)) {
return;
}
@@ -2813,7 +2813,7 @@ void ChangeTownRating(Town *t, int add, int max, DoCommandFlag flags)
bool CheckforTownRating(DoCommandFlag flags, Town *t, TownRatingCheckType type)
{
/* if magic_bulldozer cheat is active, town doesn't restrict your destructive actions */
- if (t == NULL || !IsValidCompanyID(_current_company) ||
+ if (t == NULL || !Company::IsValidID(_current_company) ||
_cheats.magic_bulldozer.value || (flags & DC_NO_TEST_TOWN_RATING)) {
return true;
}
diff --git a/src/town_gui.cpp b/src/town_gui.cpp
index 92147a31b..07296d08a 100644
--- a/src/town_gui.cpp
+++ b/src/town_gui.cpp
@@ -976,6 +976,6 @@ static const WindowDesc _found_town_desc(
void ShowBuildTownWindow()
{
- if (_game_mode != GM_EDITOR && !IsValidCompanyID(_local_company)) return;
+ if (_game_mode != GM_EDITOR && !Company::IsValidID(_local_company)) return;
AllocateWindowDescFront<FoundTownWindow>(&_found_town_desc, 0);
}
diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp
index 0fc2a6ff1..061f78d34 100644
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -1040,7 +1040,7 @@ CommandCost CmdMoveRailVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, u
VehicleID s = GB(p1, 0, 16);
VehicleID d = GB(p1, 16, 16);
- if (!IsValidVehicleID(s)) return CMD_ERROR;
+ if (!Vehicle::IsValidID(s)) return CMD_ERROR;
Vehicle *src = Vehicle::Get(s);
@@ -1054,7 +1054,7 @@ CommandCost CmdMoveRailVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, u
if (d == INVALID_VEHICLE) {
dst = IsTrainEngine(src) ? NULL : FindGoodVehiclePos(src);
} else {
- if (!IsValidVehicleID(d)) return CMD_ERROR;
+ if (!Vehicle::IsValidID(d)) return CMD_ERROR;
dst = Vehicle::Get(d);
if (dst->type != VEH_TRAIN || !CheckOwnership(dst->owner)) return CMD_ERROR;
@@ -1290,7 +1290,7 @@ CommandCost CmdMoveRailVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, u
assert(src->orders.list == NULL);
/* Decrease the engines number of the src engine_type */
- if (!IsDefaultGroupID(src->group_id) && IsValidGroupID(src->group_id)) {
+ if (!IsDefaultGroupID(src->group_id) && Group::IsValidID(src->group_id)) {
Group::Get(src->group_id)->num_engines[src->engine_type]--;
}
@@ -1395,7 +1395,7 @@ CommandCost CmdSellRailWagon(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
/* Check if we deleted a vehicle window */
Window *w = NULL;
- if (!IsValidVehicleID(p1) || p2 > 1) return CMD_ERROR;
+ if (!Vehicle::IsValidID(p1) || p2 > 1) return CMD_ERROR;
Vehicle *v = Vehicle::Get(p1);
@@ -1952,7 +1952,7 @@ static void ReverseTrainDirection(Vehicle *v)
*/
CommandCost CmdReverseTrainDirection(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
{
- if (!IsValidVehicleID(p1)) return CMD_ERROR;
+ if (!Vehicle::IsValidID(p1)) return CMD_ERROR;
Vehicle *v = Vehicle::Get(p1);
@@ -2013,7 +2013,7 @@ CommandCost CmdReverseTrainDirection(TileIndex tile, DoCommandFlag flags, uint32
*/
CommandCost CmdForceTrainProceed(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
{
- if (!IsValidVehicleID(p1)) return CMD_ERROR;
+ if (!Vehicle::IsValidID(p1)) return CMD_ERROR;
Vehicle *v = Vehicle::Get(p1);
@@ -2040,7 +2040,7 @@ CommandCost CmdRefitRailVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1,
byte new_subtype = GB(p2, 8, 8);
bool only_this = HasBit(p2, 16);
- if (!IsValidVehicleID(p1)) return CMD_ERROR;
+ if (!Vehicle::IsValidID(p1)) return CMD_ERROR;
Vehicle *v = Vehicle::Get(p1);
@@ -2246,7 +2246,7 @@ CommandCost CmdSendTrainToDepot(TileIndex tile, DoCommandFlag flags, uint32 p1,
return SendAllVehiclesToDepot(VEH_TRAIN, flags, p2 & DEPOT_SERVICE, _current_company, (p2 & VLW_MASK), p1);
}
- if (!IsValidVehicleID(p1)) return CMD_ERROR;
+ if (!Vehicle::IsValidID(p1)) return CMD_ERROR;
Vehicle *v = Vehicle::Get(p1);
diff --git a/src/tree_cmd.cpp b/src/tree_cmd.cpp
index 8487ac4c2..2924f238d 100644
--- a/src/tree_cmd.cpp
+++ b/src/tree_cmd.cpp
@@ -388,7 +388,7 @@ CommandCost CmdPlantTree(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
}
}
- if (_game_mode != GM_EDITOR && IsValidCompanyID(_current_company)) {
+ if (_game_mode != GM_EDITOR && Company::IsValidID(_current_company)) {
Town *t = ClosestTownFromTile(tile, _settings_game.economy.dist_local_authority);
if (t != NULL) ChangeTownRating(t, RATING_TREE_UP_STEP, RATING_TREE_MAXIMUM, flags);
}
@@ -531,7 +531,7 @@ static CommandCost ClearTile_Trees(TileIndex tile, DoCommandFlag flags)
{
uint num;
- if (IsValidCompanyID(_current_company)) {
+ if (Company::IsValidID(_current_company)) {
Town *t = ClosestTownFromTile(tile, _settings_game.economy.dist_local_authority);
if (t != NULL) ChangeTownRating(t, RATING_TREE_DOWN_STEP, RATING_TREE_MINIMUM, flags);
}
diff --git a/src/tree_gui.cpp b/src/tree_gui.cpp
index 18e4c9aae..3bdc0a838 100644
--- a/src/tree_gui.cpp
+++ b/src/tree_gui.cpp
@@ -246,6 +246,6 @@ static const WindowDesc _build_trees_desc(
void ShowBuildTreesToolbar()
{
- if (_game_mode != GM_EDITOR && !IsValidCompanyID(_local_company)) return;
+ if (_game_mode != GM_EDITOR && !Company::IsValidID(_local_company)) return;
AllocateWindowDescFront<BuildTreesWindow>(&_build_trees_desc, 0);
}
diff --git a/src/tunnelbridge_cmd.cpp b/src/tunnelbridge_cmd.cpp
index ce36289e6..7f2c7bd5e 100644
--- a/src/tunnelbridge_cmd.cpp
+++ b/src/tunnelbridge_cmd.cpp
@@ -440,10 +440,10 @@ not_valid_below:;
* It's unnecessary to execute this command every time for every bridge. So it is done only
* and cost is computed in "bridge_gui.c". For AI, Towns this has to be of course calculated
*/
- if (!(flags & DC_QUERY_COST) || (IsValidCompanyID(_current_company) && Company::Get(_current_company)->is_ai)) {
+ if (!(flags & DC_QUERY_COST) || (Company::IsValidID(_current_company) && Company::Get(_current_company)->is_ai)) {
bridge_len += 2; // begin and end tiles/ramps
- if (IsValidCompanyID(_current_company))
+ if (Company::IsValidID(_current_company))
bridge_len = CalcBridgeLenCostFactor(bridge_len);
cost.AddCost((int64)bridge_len * _price.build_bridge * GetBridgeSpec(bridge_type)->price >> 8);
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index 8982c23e3..94842b383 100644
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -509,7 +509,7 @@ void Vehicle::PreDestructor()
{
if (CleaningPool()) return;
- if (IsValidStationID(this->last_station_visited)) {
+ if (Station::IsValidID(this->last_station_visited)) {
Station::Get(this->last_station_visited)->loading_vehicles.remove(this);
HideFillingPercent(&this->fill_percent_te_id);
@@ -520,7 +520,7 @@ void Vehicle::PreDestructor()
if (this->owner == _local_company) InvalidateAutoreplaceWindow(this->engine_type, this->group_id);
DeleteGroupHighlightOfVehicle(this);
- if (IsValidGroupID(this->group_id)) Group::Get(this->group_id)->num_engines[this->engine_type]--;
+ if (Group::IsValidID(this->group_id)) Group::Get(this->group_id)->num_engines[this->engine_type]--;
if (this->IsPrimaryVehicle()) DecreaseGroupNumVehicle(this->group_id);
}
@@ -1283,7 +1283,7 @@ bool CanBuildVehicleInfrastructure(VehicleType type)
{
assert(IsCompanyBuildableVehicleType(type));
- if (!IsValidCompanyID(_local_company)) return false;
+ if (!Company::IsValidID(_local_company)) return false;
if (_settings_client.gui.always_build_infrastructure) return true;
UnitID max;
diff --git a/src/vehicle_base.h b/src/vehicle_base.h
index 9d611c01a..47e87d0a4 100644
--- a/src/vehicle_base.h
+++ b/src/vehicle_base.h
@@ -660,16 +660,6 @@ static inline uint GetNumVehicles()
#define FOR_ALL_VEHICLES_FROM(v, start) for (v = Vehicle::Get(start); v != NULL; v = (v->index + 1U < Vehicle::GetPoolSize()) ? Vehicle::Get(v->index + 1) : NULL) if (v->IsValid())
#define FOR_ALL_VEHICLES(v) FOR_ALL_VEHICLES_FROM(v, 0)
-/**
- * Check if an index is a vehicle-index (so between 0 and max-vehicles)
- * @param index of the vehicle to query
- * @return Returns true if the vehicle-id is in range
- */
-static inline bool IsValidVehicleID(uint index)
-{
- return index < Vehicle::GetPoolSize() && Vehicle::Get(index)->IsValid();
-}
-
/** Generates sequence of free UnitID numbers */
struct FreeUnitIDGenerator {
diff --git a/src/vehicle_cmd.cpp b/src/vehicle_cmd.cpp
index e127b6107..72e1df6d2 100644
--- a/src/vehicle_cmd.cpp
+++ b/src/vehicle_cmd.cpp
@@ -61,7 +61,7 @@ CommandCost CmdStartStopVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1,
/* Disable the effect of p2 bit 0, when DC_AUTOREPLACE is not set */
if ((flags & DC_AUTOREPLACE) == 0) SetBit(p2, 0);
- if (!IsValidVehicleID(p1)) return CMD_ERROR;
+ if (!Vehicle::IsValidID(p1)) return CMD_ERROR;
Vehicle *v = Vehicle::Get(p1);
@@ -334,7 +334,7 @@ CommandCost CmdCloneVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
CommandCost total_cost(EXPENSES_NEW_VEHICLES);
uint32 build_argument = 2;
- if (!IsValidVehicleID(p1)) return CMD_ERROR;
+ if (!Vehicle::IsValidID(p1)) return CMD_ERROR;
Vehicle *v = Vehicle::Get(p1);
Vehicle *v_front = v;
@@ -532,7 +532,7 @@ CommandCost SendAllVehiclesToDepot(VehicleType type, DoCommandFlag flags, bool s
*/
CommandCost CmdRenameVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
{
- if (!IsValidVehicleID(p1)) return CMD_ERROR;
+ if (!Vehicle::IsValidID(p1)) return CMD_ERROR;
Vehicle *v = Vehicle::Get(p1);
if (!CheckOwnership(v->owner)) return CMD_ERROR;
@@ -565,7 +565,7 @@ CommandCost CmdChangeServiceInt(TileIndex tile, DoCommandFlag flags, uint32 p1,
{
uint16 serv_int = GetServiceIntervalClamped(p2); // Double check the service interval from the user-input
- if (serv_int != p2 || !IsValidVehicleID(p1)) return CMD_ERROR;
+ if (serv_int != p2 || !Vehicle::IsValidID(p1)) return CMD_ERROR;
Vehicle *v = Vehicle::Get(p1);
diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp
index 34737643d..63ca667c4 100644
--- a/src/vehicle_gui.cpp
+++ b/src/vehicle_gui.cpp
@@ -1212,7 +1212,7 @@ static WindowDesc _vehicle_list_desc(
static void ShowVehicleListWindowLocal(CompanyID company, uint16 VLW_flag, VehicleType vehicle_type, uint16 unique_number)
{
- if (!IsValidCompanyID(company)) return;
+ if (!Company::IsValidID(company)) return;
_vehicle_list_desc.cls = GetWindowClassForVehicleType(vehicle_type);
WindowNumber num = (unique_number << 16) | (vehicle_type << 11) | VLW_flag | company;
diff --git a/src/waypoint.h b/src/waypoint.h
index fe80b2ba9..eedef025b 100644
--- a/src/waypoint.h
+++ b/src/waypoint.h
@@ -40,11 +40,6 @@ struct Waypoint : PoolItem<Waypoint, WaypointID, &_Waypoint_pool> {
inline bool IsValid() const { return this->xy != INVALID_TILE; }
};
-static inline bool IsValidWaypointID(WaypointID index)
-{
- return index < Waypoint::GetPoolSize() && Waypoint::Get(index)->IsValid();
-}
-
#define FOR_ALL_WAYPOINTS_FROM(wp, start) for (wp = Waypoint::Get(start); wp != NULL; wp = (wp->index + 1U < Waypoint::GetPoolSize()) ? Waypoint::Get(wp->index + 1U) : NULL) if (wp->IsValid())
#define FOR_ALL_WAYPOINTS(wp) FOR_ALL_WAYPOINTS_FROM(wp, 0)
diff --git a/src/waypoint_cmd.cpp b/src/waypoint_cmd.cpp
index e47310bfd..301835361 100644
--- a/src/waypoint_cmd.cpp
+++ b/src/waypoint_cmd.cpp
@@ -314,7 +314,7 @@ static bool IsUniqueWaypointName(const char *name)
*/
CommandCost CmdRenameWaypoint(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
{
- if (!IsValidWaypointID(p1)) return CMD_ERROR;
+ if (!Waypoint::IsValidID(p1)) return CMD_ERROR;
Waypoint *wp = Waypoint::Get(p1);
if (!CheckOwnership(wp->owner)) return CMD_ERROR;