Changeset - r11919:363b629324b9
[Not reviewed]
master
! ! !
smatz - 16 years ago 2009-05-17 01:00:56
smatz@openttd.org
(svn r16327) -Codechange: replace IsValidPoolItemID(index) by PoolItem::IsValidID(index)
78 files changed with 242 insertions and 303 deletions:
0 comments (0 inline, 0 general)
src/ai/ai_core.cpp
Show inline comments
 
@@ -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, 
 
/* 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, 
 
/* 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, 
 
{
 
	/* 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. */
src/ai/ai_gui.cpp
Show inline comments
 
@@ -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 :( */
src/ai/ai_instance.cpp
Show inline comments
 
@@ -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;
 
}
 

	
src/ai/api/ai_company.cpp
Show inline comments
 
@@ -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)
src/ai/api/ai_group.cpp
Show inline comments
 
@@ -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)
src/ai/api/ai_industry.cpp
Show inline comments
 
@@ -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)
src/ai/api/ai_sign.cpp
Show inline comments
 
@@ -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)
src/ai/api/ai_station.cpp
Show inline comments
 
@@ -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)
src/ai/api/ai_town.cpp
Show inline comments
 
@@ -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)
src/ai/api/ai_vehicle.cpp
Show inline comments
 
@@ -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)));
 
}
src/ai/api/ai_waypoint.cpp
Show inline comments
 
@@ -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)
src/aircraft_cmd.cpp
Show inline comments
 
@@ -440,7 +440,7 @@ CommandCost CmdBuildAircraft(TileIndex t
 
 */
 
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(Tile
 
		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 t
 
{
 
	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 
 
	 * 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 *
 
	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 V
 

	
 
	StationID sid = v->u.air.targetairport;
 

	
 
	if (!IsValidStationID(sid)) return NULL;
 
	if (!Station::IsValidID(sid)) return NULL;
 

	
 
	Station *st = Station::Get(sid);
 

	
src/airport_gui.cpp
Show inline comments
 
@@ -158,7 +158,7 @@ static const WindowDesc _air_toolbar_des
 

	
 
void ShowBuildAirToolbar()
 
{
 
	if (!IsValidCompanyID(_local_company)) return;
 
	if (!Company::IsValidID(_local_company)) return;
 

	
 
	DeleteWindowByClass(WC_BUILD_TOOLBAR);
 
	AllocateWindowDescFront<BuildAirToolbarWindow>(&_air_toolbar_desc, TRANSPORT_AIR);
src/autoreplace.cpp
Show inline comments
 
@@ -40,7 +40,7 @@ void RemoveAllEngineReplacement(EngineRe
 
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);
 
	}
src/autoreplace_cmd.cpp
Show inline comments
 
@@ -608,7 +608,7 @@ CommandCost CmdAutoreplaceVehicle(TileIn
 
	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;
src/cheat_gui.cpp
Show inline comments
 
@@ -44,7 +44,7 @@ static int32 ClickMoneyCheat(int32 p1, i
 
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;
 
		}
src/command.cpp
Show inline comments
 
@@ -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 p
 
	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;
 
	}
 

	
src/company_base.h
Show inline comments
 
@@ -83,13 +83,13 @@ struct Company : PoolItem<Company, Compa
 
	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)
 

	
src/company_cmd.cpp
Show inline comments
 
@@ -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(Compan
 
{
 
	/* 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 co
 
{
 
	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(CommandCos
 
{
 
	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, TileInd
 
	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 
 
			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 til
 
				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 til
 
		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 til
 
			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;
 

	
src/company_gui.cpp
Show inline comments
 
@@ -433,7 +433,7 @@ static const WindowDesc _company_finance
 
 */
 
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_
 
 */
 
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);
 
}
src/console_cmds.cpp
Show inline comments
 
@@ -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 a
 
		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;
 
	}
src/depot_base.h
Show inline comments
 
@@ -22,11 +22,6 @@ struct Depot : PoolItem<Depot, DepotID, 
 
	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())
src/dock_gui.cpp
Show inline comments
 
@@ -306,7 +306,7 @@ static const WindowDesc _build_docks_too
 

	
 
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);
src/economy.cpp
Show inline comments
 
@@ -1891,7 +1891,7 @@ CommandCost CmdBuyShareInCompany(TileInd
 

	
 
	/* 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(TileIn
 
{
 
	/* 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
 
	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;
src/graph_gui.cpp
Show inline comments
 
@@ -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 : W
 
	{
 
		/* 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 : W
 
		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 : W
 
			}
 

	
 
			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 : W
 

	
 
		/* 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 :( */
src/group.h
Show inline comments
 
@@ -30,11 +30,6 @@ struct Group : PoolItem<Group, GroupID, 
 
};
 

	
 

	
 
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 compan
 

	
 
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--;
 
}
 

	
 

	
src/group_cmd.cpp
Show inline comments
 
@@ -32,10 +32,10 @@ static inline void UpdateNumEngineGroup(
 
{
 
	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 til
 
 */
 
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
 
 */
 
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
 
{
 
	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
 
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(Til
 
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(Ti
 
 */
 
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 Vehicl
 
 */
 
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;
src/group_gui.cpp
Show inline comments
 
@@ -76,7 +76,7 @@ static void ShowGroupActionDropdown(Wind
 
	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;
src/highscore_gui.cpp
Show inline comments
 
@@ -93,7 +93,7 @@ struct EndGameWindow : EndGameHighScoreB
 

	
 
		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, 
 
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);
src/industry.h
Show inline comments
 
@@ -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 *GetRandomIndustr
 
		index++;
 

	
 
		/* Make sure we have a valid industry */
 
		while (!IsValidIndustryID(index)) {
 
		while (!Industry::IsValidID(index)) {
 
			index++;
 
			assert(index <= GetMaxIndustryIndex());
 
		}
src/industry_gui.cpp
Show inline comments
 
@@ -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();
 
}
src/misc_cmd.cpp
Show inline comments
 
@@ -387,7 +387,7 @@ CommandCost CmdGiveMoney(TileIndex tile,
 

	
 
	/* 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 */
src/misc_gui.cpp
Show inline comments
 
@@ -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;
src/network/core/tcp_game.h
Show inline comments
 
@@ -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)
 

	
src/network/network.cpp
Show inline comments
 
@@ -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;
src/network/network_base.h
Show inline comments
 
@@ -27,11 +27,6 @@ struct NetworkClientInfo : PoolItem<Netw
 
	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)
 

	
src/network/network_client.cpp
Show inline comments
 
@@ -620,7 +620,7 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER
 

	
 
		/* 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
 

	
 
			/* 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
 
	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
 
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));
 
	}
 
}
src/network/network_gui.cpp
Show inline comments
 
@@ -1808,7 +1808,7 @@ struct NetworkClientListPopupWindow : Wi
 
			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 : Wi
 

	
 
		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);
 

	
src/network/network_server.cpp
Show inline comments
 
@@ -76,7 +76,7 @@ DEF_SERVER_SEND_COMMAND(PACKET_SERVER_CO
 

	
 
	/* 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_CO
 
		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
 
	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
 
			}
 
			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
 
	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
 

	
 
		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
 
		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
 
		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
 
	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
 
	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
 
	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(Network
 

	
 
	/* 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(Network
 

	
 
	/* 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);
 
	}
 
}
src/newgrf_engine.cpp
Show inline comments
 
@@ -430,7 +430,7 @@ static uint8 LiveryHelper(EngineID engin
 
	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);
src/newgrf_house.cpp
Show inline comments
 
@@ -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)) {
src/newgrf_industries.cpp
Show inline comments
 
@@ -214,7 +214,7 @@ uint32 IndustryGetVariable(const Resolve
 
			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];
 

	
src/oldpool.h
Show inline comments
 
@@ -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);
 

	
src/order_base.h
Show inline comments
 
@@ -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)
 

	
src/order_cmd.cpp
Show inline comments
 
@@ -416,7 +416,7 @@ CommandCost CmdInsertOrder(TileIndex til
 
	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 til
 
	 * 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 til
 
		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 til
 
						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 til
 
		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 til
 
	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 til
 
	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,
 
	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 til
 
	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
 
	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
 
		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
 
			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
 
	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(TileInd
 
	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);
 

	
src/rail_cmd.cpp
Show inline comments
 
@@ -523,7 +523,7 @@ CommandCost CmdRemoveSingleRail(TileInde
 

	
 
	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) {
src/rail_gui.cpp
Show inline comments
 
@@ -853,7 +853,7 @@ void ShowBuildRailToolbar(RailType railt
 
{
 
	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 dis
 
/** 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;
src/road.cpp
Show inline comments
 
@@ -84,7 +84,7 @@ bool HasRoadTypesAvail(const CompanyID c
 
	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;
src/road_cmd.cpp
Show inline comments
 
@@ -119,7 +119,7 @@ bool CheckAllowRemoveRoad(TileIndex tile
 
	 * 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,
 

	
 
	/* 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;
src/road_gui.cpp
Show inline comments
 
@@ -723,7 +723,7 @@ static const WindowDesc _build_tramway_d
 

	
 
void ShowBuildRoadToolbar(RoadType roadtype)
 
{
 
	if (!IsValidCompanyID(_local_company)) return;
 
	if (!Company::IsValidID(_local_company)) return;
 
	_cur_roadtype = roadtype;
 

	
 
	DeleteWindowByClass(WC_BUILD_TOOLBAR);
src/roadveh_cmd.cpp
Show inline comments
 
@@ -314,7 +314,7 @@ CommandCost CmdSellRoadVeh(TileIndex til
 
{
 
	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(TileIn
 
		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 til
 
{
 
	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 ti
 
	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);
 

	
src/saveload/afterload.cpp
Show inline comments
 
@@ -281,7 +281,7 @@ void CDECL HandleSavegameLoadCrash(int u
 
 */
 
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(TileInde
 
		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;
 
		}
 
	}
 

	
src/saveload/ai_sl.cpp
Show inline comments
 
@@ -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);
 
		}
src/saveload/saveload.cpp
Show inline comments
 
@@ -1864,7 +1864,7 @@ void GenerateDefaultSaveName(char *buf, 
 
	 * 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, 
 
	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);
 
}
 

	
src/ship_cmd.cpp
Show inline comments
 
@@ -821,7 +821,7 @@ CommandCost CmdSellShip(TileIndex tile, 
 
{
 
	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
 
		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,
 
	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);
 

	
src/signal.cpp
Show inline comments
 
@@ -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
src/signs_base.h
Show inline comments
 
@@ -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)
 

	
src/signs_cmd.cpp
Show inline comments
 
@@ -66,7 +66,7 @@ CommandCost CmdPlaceSign(TileIndex tile,
 
 */
 
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)) {
src/station_base.h
Show inline comments
 
@@ -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)
 

	
src/station_cmd.cpp
Show inline comments
 
@@ -880,7 +880,7 @@ CommandCost CmdBuildRailroadStation(Tile
 
	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(Tile
 
			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 t
 
	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 t
 
			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 ti
 
	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 ti
 
			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,
 
		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, 
 
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,
 
	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,
 
			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 *t
 
	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 
 
				(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 ch
 
 */
 
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;
src/station_gui.cpp
Show inline comments
 
@@ -676,7 +676,7 @@ static const WindowDesc _company_station
 
 */
 
void ShowCompanyStations(CompanyID company)
 
{
 
	if (!IsValidCompanyID(company)) return;
 
	if (!Company::IsValidID(company)) return;
 

	
 
	AllocateWindowDescFront<CompanyStationsWindow>(&_company_stations_desc, company);
 
}
src/strings.cpp
Show inline comments
 
@@ -847,7 +847,7 @@ static char *FormatString(char *buff, co
 
			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, co
 
				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);
src/terraform_gui.cpp
Show inline comments
 
@@ -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;
src/timetable_cmd.cpp
Show inline comments
 
@@ -57,7 +57,7 @@ CommandCost CmdChangeTimetable(TileIndex
 
	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(TileInde
 
	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(TileInd
 
	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;
src/toolbar_gui.cpp
Show inline comments
 
@@ -222,7 +222,7 @@ static void PopupMainCompanyToolbMenu(Wi
 
#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)));
 
	}
 

	
src/town.h
Show inline comments
 
@@ -295,16 +295,6 @@ static inline HouseSpec *GetHouseSpecs(H
 

	
 
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());
 
		}
src/town_cmd.cpp
Show inline comments
 
@@ -535,7 +535,7 @@ static CommandCost ClearTile_Town(TileIn
 
	_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 
 
 */
 
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, Com
 
 */
 
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, 
 
{
 
	/* 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, 
 
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;
 
	}
src/town_gui.cpp
Show inline comments
 
@@ -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);
 
}
src/train_cmd.cpp
Show inline comments
 
@@ -1040,7 +1040,7 @@ CommandCost CmdMoveRailVehicle(TileIndex
 
	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
 
	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
 
					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 t
 
	/* 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(Vehicl
 
 */
 
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(Til
 
 */
 
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(TileInde
 
	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(TileInde
 
		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);
 

	
src/tree_cmd.cpp
Show inline comments
 
@@ -388,7 +388,7 @@ CommandCost CmdPlantTree(TileIndex tile,
 
						}
 
					}
 

	
 
					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(TileI
 
{
 
	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);
 
	}
src/tree_gui.cpp
Show inline comments
 
@@ -246,6 +246,6 @@ static const WindowDesc _build_trees_des
 

	
 
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);
 
}
src/tunnelbridge_cmd.cpp
Show inline comments
 
@@ -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);
src/vehicle.cpp
Show inline comments
 
@@ -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(Vehic
 
{
 
	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;
src/vehicle_base.h
Show inline comments
 
@@ -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 {
src/vehicle_cmd.cpp
Show inline comments
 
@@ -61,7 +61,7 @@ CommandCost CmdStartStopVehicle(TileInde
 
	/* 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 ti
 
	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(Vehic
 
 */
 
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(TileInde
 
{
 
	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);
 

	
src/vehicle_gui.cpp
Show inline comments
 
@@ -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;
src/waypoint.h
Show inline comments
 
@@ -40,11 +40,6 @@ struct Waypoint : PoolItem<Waypoint, Way
 
	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)
 

	
src/waypoint_cmd.cpp
Show inline comments
 
@@ -314,7 +314,7 @@ static bool IsUniqueWaypointName(const c
 
 */
 
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;
0 comments (0 inline, 0 general)