changeset 11924:fccc9cea27a7 draft

(svn r16327) -Codechange: replace IsValidPoolItemID(index) by PoolItem::IsValidID(index)
author smatz <smatz@openttd.org>
date Sun, 17 May 2009 01:00:56 +0000
parents ee96e716b842
children fa2b09b44490
files src/ai/ai_core.cpp src/ai/ai_gui.cpp src/ai/ai_instance.cpp src/ai/api/ai_company.cpp src/ai/api/ai_group.cpp src/ai/api/ai_industry.cpp src/ai/api/ai_sign.cpp src/ai/api/ai_station.cpp src/ai/api/ai_town.cpp src/ai/api/ai_vehicle.cpp src/ai/api/ai_waypoint.cpp src/aircraft_cmd.cpp src/airport_gui.cpp src/autoreplace.cpp src/autoreplace_cmd.cpp src/cheat_gui.cpp src/command.cpp src/company_base.h src/company_cmd.cpp src/company_gui.cpp src/console_cmds.cpp src/depot_base.h src/dock_gui.cpp src/economy.cpp src/graph_gui.cpp src/group.h src/group_cmd.cpp src/group_gui.cpp src/highscore_gui.cpp src/industry.h src/industry_gui.cpp src/misc_cmd.cpp src/misc_gui.cpp src/network/core/tcp_game.h src/network/network.cpp src/network/network_base.h src/network/network_client.cpp src/network/network_gui.cpp src/network/network_server.cpp src/newgrf_engine.cpp src/newgrf_house.cpp src/newgrf_industries.cpp src/oldpool.h src/order_base.h src/order_cmd.cpp src/rail_cmd.cpp src/rail_gui.cpp src/road.cpp src/road_cmd.cpp src/road_gui.cpp src/roadveh_cmd.cpp src/saveload/afterload.cpp src/saveload/ai_sl.cpp src/saveload/saveload.cpp src/ship_cmd.cpp src/signal.cpp src/signs_base.h src/signs_cmd.cpp src/station_base.h src/station_cmd.cpp src/station_gui.cpp src/strings.cpp src/terraform_gui.cpp src/timetable_cmd.cpp src/toolbar_gui.cpp src/town.h src/town_cmd.cpp src/town_gui.cpp src/train_cmd.cpp src/tree_cmd.cpp src/tree_gui.cpp src/tunnelbridge_cmd.cpp src/vehicle.cpp src/vehicle_base.h src/vehicle_cmd.cpp src/vehicle_gui.cpp src/waypoint.h src/waypoint_cmd.cpp
diffstat 78 files changed, 242 insertions(+), 303 deletions(-) [+]
line wrap: on
line diff
--- 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 @@
 /* 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 @@
 /* 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 @@
 {
 	/* 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. */
--- a/src/ai/ai_gui.cpp
+++ b/src/ai/ai_gui.cpp
@@ -641,7 +641,7 @@
 	{
 		/* 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 @@
 	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 @@
 			}
 
 			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 @@
 
 		/* 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 :( */
--- a/src/ai/ai_instance.cpp
+++ b/src/ai/ai_instance.cpp
@@ -353,7 +353,7 @@
 
 /* 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;
 }
 
--- 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)
--- 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)
--- 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)
--- 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)
--- 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)
--- 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)
--- 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)));
 }
--- 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)
--- a/src/aircraft_cmd.cpp
+++ b/src/aircraft_cmd.cpp
@@ -440,7 +440,7 @@
  */
 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 @@
 		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 @@
 {
 	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 @@
 	 * 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 @@
 	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 @@
 
 	StationID sid = v->u.air.targetairport;
 
-	if (!IsValidStationID(sid)) return NULL;
+	if (!Station::IsValidID(sid)) return NULL;
 
 	Station *st = Station::Get(sid);
 
--- a/src/airport_gui.cpp
+++ b/src/airport_gui.cpp
@@ -158,7 +158,7 @@
 
 void ShowBuildAirToolbar()
 {
-	if (!IsValidCompanyID(_local_company)) return;
+	if (!Company::IsValidID(_local_company)) return;
 
 	DeleteWindowByClass(WC_BUILD_TOOLBAR);
 	AllocateWindowDescFront<BuildAirToolbarWindow>(&_air_toolbar_desc, TRANSPORT_AIR);
--- a/src/autoreplace.cpp
+++ b/src/autoreplace.cpp
@@ -40,7 +40,7 @@
 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);
 	}
--- a/src/autoreplace_cmd.cpp
+++ b/src/autoreplace_cmd.cpp
@@ -608,7 +608,7 @@
 	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;
--- a/src/cheat_gui.cpp
+++ b/src/cheat_gui.cpp
@@ -44,7 +44,7 @@
 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;
 		}
--- a/src/command.cpp
+++ b/src/command.cpp
@@ -458,7 +458,7 @@
 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 @@
 	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;
 	}
 
--- a/src/company_base.h
+++ b/src/company_base.h
@@ -83,13 +83,13 @@
 	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 IsValidID(CompanyID company)
+	{
+		return company < MAX_COMPANIES && (uint)company < Company::GetPoolSize() && Company::Get(company)->IsValid();
+	}
 };
 
-static inline bool IsValidCompanyID(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)
 
--- a/src/company_cmd.cpp
+++ b/src/company_cmd.cpp
@@ -66,17 +66,17 @@
  * 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 @@
 {
 	/* 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 @@
 {
 	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 @@
 {
 	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 @@
 	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 @@
 {
 	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 @@
  */
 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 @@
 			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 @@
 				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 @@
 		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 @@
 			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;
 
--- a/src/company_gui.cpp
+++ b/src/company_gui.cpp
@@ -433,7 +433,7 @@
  */
 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 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 @@
 
 void ShowCompany(CompanyID company)
 {
-	if (!IsValidCompanyID(company)) return;
+	if (!Company::IsValidID(company)) return;
 
 	AllocateWindowDescFront<CompanyWindow>(&_company_desc, company);
 }
--- a/src/console_cmds.cpp
+++ b/src/console_cmds.cpp
@@ -635,7 +635,7 @@
 	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 @@
 		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 @@
 	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 @@
 	}
 
 	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 @@
 	}
 
 	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 @@
 	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 @@
 		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;
 	}
--- a/src/depot_base.h
+++ b/src/depot_base.h
@@ -22,11 +22,6 @@
 	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())
--- a/src/dock_gui.cpp
+++ b/src/dock_gui.cpp
@@ -306,7 +306,7 @@
 
 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);
--- a/src/economy.cpp
+++ b/src/economy.cpp
@@ -1891,7 +1891,7 @@
 
 	/* 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 @@
 {
 	/* 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 @@
 	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;
--- a/src/graph_gui.cpp
+++ b/src/graph_gui.cpp
@@ -53,7 +53,7 @@
 	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 @@
 
 		/* 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 @@
 
 		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 @@
 	{
 		/* 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 @@
 		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 @@
 			}
 
 			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 @@
 
 		/* 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 :( */
--- a/src/group.h
+++ b/src/group.h
@@ -30,11 +30,6 @@
 };
 
 
-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 @@
 
 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--;
 }
 
 
--- a/src/group_cmd.cpp
+++ b/src/group_cmd.cpp
@@ -32,10 +32,10 @@
 {
 	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 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 @@
  */
 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 @@
 {
 	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 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 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 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 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 @@
 
 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;
--- a/src/group_gui.cpp
+++ b/src/group_gui.cpp
@@ -76,7 +76,7 @@
 	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 @@
 			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 @@
 			}
 
 			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 @@
 			}
 
 			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 @@
 									| 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 @@
 
 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;
--- a/src/highscore_gui.cpp
+++ b/src/highscore_gui.cpp
@@ -93,7 +93,7 @@
 
 		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 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);
--- a/src/industry.h
+++ b/src/industry.h
@@ -265,17 +265,6 @@
 /* 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 @@
 		index++;
 
 		/* Make sure we have a valid industry */
-		while (!IsValidIndustryID(index)) {
+		while (!Industry::IsValidID(index)) {
 			index++;
 			assert(index <= GetMaxIndustryIndex());
 		}
--- a/src/industry_gui.cpp
+++ b/src/industry_gui.cpp
@@ -435,7 +435,7 @@
 
 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();
 }
--- a/src/misc_cmd.cpp
+++ b/src/misc_cmd.cpp
@@ -387,7 +387,7 @@
 
 	/* 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 */
--- a/src/misc_gui.cpp
+++ b/src/misc_gui.cpp
@@ -104,7 +104,7 @@
 	}
 
 	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;
--- a/src/network/core/tcp_game.h
+++ b/src/network/core/tcp_game.h
@@ -108,11 +108,6 @@
 	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)
 
--- a/src/network/network.cpp
+++ b/src/network/network.cpp
@@ -97,7 +97,7 @@
  */
 NetworkClientInfo *NetworkFindClientInfoFromIndex(ClientIndex index)
 {
-	return IsValidNetworkClientInfoIndex(index) ? NetworkClientInfo::Get(index) : NULL;
+	return NetworkClientInfo::IsValidID(index) ? NetworkClientInfo::Get(index) : NULL;
 }
 
 /**
@@ -339,7 +339,7 @@
 	uint count = 0;
 
 	FOR_ALL_CLIENT_INFOS(ci) {
-		if (IsValidCompanyID(ci->client_playas)) count++;
+		if (Company::IsValidID(ci->client_playas)) count++;
 	}
 
 	return count;
--- a/src/network/network_base.h
+++ b/src/network/network_base.h
@@ -27,11 +27,6 @@
 	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)
 
--- a/src/network/network_client.cpp
+++ b/src/network/network_client.cpp
@@ -620,7 +620,7 @@
 
 		/* 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 @@
 
 			/* 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 @@
 	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 @@
 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 @@
 		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));
 	}
 }
--- a/src/network/network_gui.cpp
+++ b/src/network/network_gui.cpp
@@ -1808,7 +1808,7 @@
 			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 @@
 
 		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 @@
 			}
 
 			/* 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);
 
--- a/src/network/network_server.cpp
+++ b/src/network/network_server.cpp
@@ -76,7 +76,7 @@
 
 	/* 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 @@
 		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 @@
 	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 @@
 			}
 			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 @@
 	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 @@
 
 		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 @@
 		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 @@
 		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 @@
 	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 @@
 	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 @@
 	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 @@
 
 	/* 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 @@
 
 	/* 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 @@
 
 	/* 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 @@
 
 		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 @@
 		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);
 	}
 }
--- a/src/newgrf_engine.cpp
+++ b/src/newgrf_engine.cpp
@@ -430,7 +430,7 @@
 	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);
--- a/src/newgrf_house.cpp
+++ b/src/newgrf_house.cpp
@@ -518,7 +518,7 @@
 
 	/* 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)) {
--- a/src/newgrf_industries.cpp
+++ b/src/newgrf_industries.cpp
@@ -214,7 +214,7 @@
 			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];
 
--- a/src/oldpool.h
+++ b/src/oldpool.h
@@ -288,12 +288,22 @@
 
 	/**
 	 * 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);
 
--- a/src/order_base.h
+++ b/src/order_base.h
@@ -421,11 +421,6 @@
 	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)
 
--- a/src/order_cmd.cpp
+++ b/src/order_cmd.cpp
@@ -416,7 +416,7 @@
 	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 @@
 	 * 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 @@
 		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 @@
 						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 @@
 		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 @@
 	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 @@
 	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 @@
 	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 @@
 	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 @@
 	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 @@
 		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 @@
 			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 @@
 	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 @@
 	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);
 
--- a/src/rail_cmd.cpp
+++ b/src/rail_cmd.cpp
@@ -523,7 +523,7 @@
 
 	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) {
--- a/src/rail_gui.cpp
+++ b/src/rail_gui.cpp
@@ -853,7 +853,7 @@
 {
 	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 @@
 /** 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;
--- a/src/road.cpp
+++ b/src/road.cpp
@@ -84,7 +84,7 @@
 	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;
--- a/src/road_cmd.cpp
+++ b/src/road_cmd.cpp
@@ -119,7 +119,7 @@
 	 * 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 @@
 
 	/* 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;
--- a/src/road_gui.cpp
+++ b/src/road_gui.cpp
@@ -723,7 +723,7 @@
 
 void ShowBuildRoadToolbar(RoadType roadtype)
 {
-	if (!IsValidCompanyID(_local_company)) return;
+	if (!Company::IsValidID(_local_company)) return;
 	_cur_roadtype = roadtype;
 
 	DeleteWindowByClass(WC_BUILD_TOOLBAR);
--- a/src/roadveh_cmd.cpp
+++ b/src/roadveh_cmd.cpp
@@ -314,7 +314,7 @@
 {
 	Vehicle *v;
 
-	if (!IsValidVehicleID(p1)) return CMD_ERROR;
+	if (!Vehicle::IsValidID(p1)) return CMD_ERROR;
 
 	v = Vehicle::Get(p1);
 
@@ -423,7 +423,7 @@
 		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 @@
 {
 	Vehicle *v;
 
-	if (!IsValidVehicleID(p1)) return CMD_ERROR;
+	if (!Vehicle::IsValidID(p1)) return CMD_ERROR;
 
 	v = Vehicle::Get(p1);
 
@@ -1976,7 +1976,7 @@
 	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);
 
--- a/src/saveload/afterload.cpp
+++ b/src/saveload/afterload.cpp
@@ -281,7 +281,7 @@
  */
 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 @@
 		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 @@
 	 *  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 @@
 		 * 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 @@
 			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 @@
 				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 @@
 			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 @@
 
 			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 @@
 				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 @@
 		/* 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 @@
 		 * 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 @@
 		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;
 		}
 	}
 
--- a/src/saveload/ai_sl.cpp
+++ b/src/saveload/ai_sl.cpp
@@ -43,7 +43,7 @@
 
 	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 @@
 		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 @@
 		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);
 		}
--- a/src/saveload/saveload.cpp
+++ b/src/saveload/saveload.cpp
@@ -1864,7 +1864,7 @@
 	 * 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 @@
 	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);
 }
 
--- a/src/ship_cmd.cpp
+++ b/src/ship_cmd.cpp
@@ -821,7 +821,7 @@
 {
 	Vehicle *v;
 
-	if (!IsValidVehicleID(p1)) return CMD_ERROR;
+	if (!Vehicle::IsValidID(p1)) return CMD_ERROR;
 
 	v = Vehicle::Get(p1);
 
@@ -870,7 +870,7 @@
 		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 @@
 	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);
 
--- a/src/signal.cpp
+++ b/src/signal.cpp
@@ -466,11 +466,11 @@
  *
  * @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
--- a/src/signs_base.h
+++ b/src/signs_base.h
@@ -41,11 +41,6 @@
 	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)
 
--- a/src/signs_cmd.cpp
+++ b/src/signs_cmd.cpp
@@ -66,7 +66,7 @@
  */
 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)) {
--- a/src/station_base.h
+++ b/src/station_base.h
@@ -219,11 +219,6 @@
 	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)
 
--- a/src/station_cmd.cpp
+++ b/src/station_cmd.cpp
@@ -880,7 +880,7 @@
 	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 @@
 			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 @@
 	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 @@
 			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 @@
 	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 @@
 			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 @@
 		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 @@
 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 @@
 	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 @@
 			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 @@
 	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 @@
 				(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 @@
 	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 @@
  */
 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;
--- a/src/station_gui.cpp
+++ b/src/station_gui.cpp
@@ -676,7 +676,7 @@
  */
 void ShowCompanyStations(CompanyID company)
 {
-	if (!IsValidCompanyID(company)) return;
+	if (!Company::IsValidID(company)) return;
 
 	AllocateWindowDescFront<CompanyStationsWindow>(&_company_stations_desc, company);
 }
--- a/src/strings.cpp
+++ b/src/strings.cpp
@@ -847,7 +847,7 @@
 			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 @@
 				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);
--- a/src/terraform_gui.cpp
+++ b/src/terraform_gui.cpp
@@ -352,7 +352,7 @@
 
 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;
--- a/src/timetable_cmd.cpp
+++ b/src/timetable_cmd.cpp
@@ -57,7 +57,7 @@
 	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 @@
 	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 @@
 	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;
--- a/src/toolbar_gui.cpp
+++ b/src/toolbar_gui.cpp
@@ -222,7 +222,7 @@
 #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)));
 	}
 
--- a/src/town.h
+++ b/src/town.h
@@ -295,16 +295,6 @@
 
 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 @@
 
 		index++;
 		/* Make sure we have a valid town */
-		while (!IsValidTownID(index)) {
+		while (!Town::IsValidID(index)) {
 			index++;
 			assert(index <= GetMaxTownIndex());
 		}
--- a/src/town_cmd.cpp
+++ b/src/town_cmd.cpp
@@ -535,7 +535,7 @@
 	_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 @@
 		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 @@
  */
 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 @@
  */
 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 @@
 		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 @@
  */
 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 @@
 {
 	/* 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 @@
 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;
 	}
--- a/src/town_gui.cpp
+++ b/src/town_gui.cpp
@@ -976,6 +976,6 @@
 
 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);
 }
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -1040,7 +1040,7 @@
 	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 @@
 	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 @@
 					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 @@
 	/* 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 @@
  */
 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 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 @@
 	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 @@
 		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);
 
--- a/src/tree_cmd.cpp
+++ b/src/tree_cmd.cpp
@@ -388,7 +388,7 @@
 						}
 					}
 
-					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 @@
 {
 	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);
 	}
--- a/src/tree_gui.cpp
+++ b/src/tree_gui.cpp
@@ -246,6 +246,6 @@
 
 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);
 }
--- a/src/tunnelbridge_cmd.cpp
+++ b/src/tunnelbridge_cmd.cpp
@@ -440,10 +440,10 @@
 	 * 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);
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -509,7 +509,7 @@
 {
 	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 @@
 		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 @@
 {
 	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;
--- a/src/vehicle_base.h
+++ b/src/vehicle_base.h
@@ -660,16 +660,6 @@
 #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 {
--- a/src/vehicle_cmd.cpp
+++ b/src/vehicle_cmd.cpp
@@ -61,7 +61,7 @@
 	/* 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 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 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 @@
 {
 	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);
 
--- a/src/vehicle_gui.cpp
+++ b/src/vehicle_gui.cpp
@@ -1212,7 +1212,7 @@
 
 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;
--- a/src/waypoint.h
+++ b/src/waypoint.h
@@ -40,11 +40,6 @@
 	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)
 
--- a/src/waypoint_cmd.cpp
+++ b/src/waypoint_cmd.cpp
@@ -314,7 +314,7 @@
  */
 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;