summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/company_base.h15
-rw-r--r--src/console_cmds.cpp13
-rw-r--r--src/disaster_cmd.cpp4
-rw-r--r--src/network/network_server.cpp6
-rw-r--r--src/newgrf_engine.cpp2
5 files changed, 18 insertions, 22 deletions
diff --git a/src/company_base.h b/src/company_base.h
index 6d0f2abd0..35a2e918c 100644
--- a/src/company_base.h
+++ b/src/company_base.h
@@ -82,15 +82,20 @@ struct Company : CompanyPool::PoolItem<&_company_pool> {
static FORCEINLINE bool IsValidAiID(size_t index)
{
- const Company *c = GetIfValid(index);
+ const Company *c = Company::GetIfValid(index);
return c != NULL && c->is_ai;
}
static FORCEINLINE bool IsValidHumanID(size_t index)
{
- const Company *c = GetIfValid(index);
+ const Company *c = Company::GetIfValid(index);
return c != NULL && !c->is_ai;
}
+
+ static FORCEINLINE bool IsHumanID(size_t index)
+ {
+ return !Company::Get(index)->is_ai;
+ }
};
#define FOR_ALL_COMPANIES_FROM(var, start) FOR_ALL_ITEMS_FROM(Company, company_index, var, start)
@@ -98,12 +103,6 @@ struct Company : CompanyPool::PoolItem<&_company_pool> {
Money CalculateCompanyValue(const Company *c);
-static inline bool IsHumanCompany(CompanyID company)
-{
- return !Company::Get(company)->is_ai;
-}
-
-
extern uint _next_competitor_start;
extern uint _cur_company_tick_index;
diff --git a/src/console_cmds.cpp b/src/console_cmds.cpp
index 787d0c647..7922248d0 100644
--- a/src/console_cmds.cpp
+++ b/src/console_cmds.cpp
@@ -666,7 +666,7 @@ DEF_CONSOLE_CMD(ConJoinCompany)
return true;
}
- if (company_id != COMPANY_SPECTATOR && Company::Get(company_id)->is_ai) {
+ if (company_id != COMPANY_SPECTATOR && !Company::IsHumanID(company_id)) {
IConsoleError("Cannot join AI company.");
return true;
}
@@ -709,7 +709,7 @@ DEF_CONSOLE_CMD(ConMoveClient)
return true;
}
- if (company_id != COMPANY_SPECTATOR && Company::Get(company_id)->is_ai) {
+ if (company_id != COMPANY_SPECTATOR && !Company::IsHumanID(company_id)) {
IConsoleError("You cannot move clients to AI companies.");
return true;
}
@@ -741,15 +741,14 @@ DEF_CONSOLE_CMD(ConResetCompany)
if (argc != 2) return false;
CompanyID index = (CompanyID)(atoi(argv[1]) - 1);
- const Company *c = Company::GetIfValid(index);
/* Check valid range */
- if (c == NULL) {
+ if (!Company::IsValidID(index)) {
IConsolePrintF(CC_ERROR, "Company does not exist. Company-id must be between 1 and %d.", MAX_COMPANIES);
return true;
}
- if (c->is_ai) {
+ if (!Company::IsHumanID(index)) {
IConsoleError("Company is owned by an AI.");
return true;
}
@@ -1064,7 +1063,7 @@ DEF_CONSOLE_CMD(ConReloadAI)
return true;
}
- if (IsHumanCompany(company_id)) {
+ if (Company::IsHumanID(company_id)) {
IConsoleWarning("Company is not controlled by an AI.");
return true;
}
@@ -1101,7 +1100,7 @@ DEF_CONSOLE_CMD(ConStopAI)
return true;
}
- if (IsHumanCompany(company_id)) {
+ if (Company::IsHumanID(company_id)) {
IConsoleWarning("Company is not controlled by an AI.");
return true;
}
diff --git a/src/disaster_cmd.cpp b/src/disaster_cmd.cpp
index bee1db1a7..f23cfe26f 100644
--- a/src/disaster_cmd.cpp
+++ b/src/disaster_cmd.cpp
@@ -62,7 +62,7 @@ static void DisasterClearSquare(TileIndex tile)
switch (GetTileType(tile)) {
case MP_RAILWAY:
- if (IsHumanCompany(GetTileOwner(tile)) && !IsRailWaypoint(tile)) {
+ if (Company::IsHumanID(GetTileOwner(tile)) && !IsRailWaypoint(tile)) {
CompanyID old_company = _current_company;
_current_company = OWNER_WATER;
DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
@@ -555,7 +555,7 @@ static bool DisasterTick_Big_Ufo(DisasterVehicle *v)
TileIndex tile = tile_org;
do {
if (IsPlainRailTile(tile) &&
- IsHumanCompany(GetTileOwner(tile))) {
+ Company::IsHumanID(GetTileOwner(tile))) {
break;
}
tile = TILE_MASK(tile + 1);
diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp
index 889885482..1ae3d64b0 100644
--- a/src/network/network_server.cpp
+++ b/src/network/network_server.cpp
@@ -1230,10 +1230,8 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_MOVE)
{
CompanyID company_id = (Owner)p->Recv_uint8();
- /* Check if the company is valid */
- 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;
+ /* Check if the company is valid, we don't allow moving to AI companies */
+ if (company_id != COMPANY_SPECTATOR && !Company::IsValidHumanID(company_id)) return;
/* Check if we require a password for this company */
if (company_id != COMPANY_SPECTATOR && !StrEmpty(_network_company_states[company_id].password)) {
diff --git a/src/newgrf_engine.cpp b/src/newgrf_engine.cpp
index 66cd163b9..7805967ed 100644
--- a/src/newgrf_engine.cpp
+++ b/src/newgrf_engine.cpp
@@ -585,7 +585,7 @@ static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, by
case 0x43: // Company information
if (!HasBit(v->vcache.cache_valid, 3)) {
- v->vcache.cached_var43 = v->owner | (Company::Get(v->owner)->is_ai ? 0x10000 : 0) | (LiveryHelper(v->engine_type, v) << 24);
+ v->vcache.cached_var43 = v->owner | (Company::IsHumanID(v->owner) ? 0 : 0x10000) | (LiveryHelper(v->engine_type, v) << 24);
SetBit(v->vcache.cache_valid, 3);
}
return v->vcache.cached_var43;