mirror of https://github.com/OpenTTD/OpenTTD
(svn r16634) -Codechange: use Company::IsHumanID() instead of IsHumanCompany()
parent
192b9bda7b
commit
22cf8d8480
|
@ -82,15 +82,20 @@ struct Company : CompanyPool::PoolItem<&_company_pool> {
|
||||||
|
|
||||||
static FORCEINLINE bool IsValidAiID(size_t index)
|
static FORCEINLINE bool IsValidAiID(size_t index)
|
||||||
{
|
{
|
||||||
const Company *c = GetIfValid(index);
|
const Company *c = Company::GetIfValid(index);
|
||||||
return c != NULL && c->is_ai;
|
return c != NULL && c->is_ai;
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCEINLINE bool IsValidHumanID(size_t index)
|
static FORCEINLINE bool IsValidHumanID(size_t index)
|
||||||
{
|
{
|
||||||
const Company *c = GetIfValid(index);
|
const Company *c = Company::GetIfValid(index);
|
||||||
return c != NULL && !c->is_ai;
|
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)
|
#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);
|
Money CalculateCompanyValue(const Company *c);
|
||||||
|
|
||||||
static inline bool IsHumanCompany(CompanyID company)
|
|
||||||
{
|
|
||||||
return !Company::Get(company)->is_ai;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
extern uint _next_competitor_start;
|
extern uint _next_competitor_start;
|
||||||
extern uint _cur_company_tick_index;
|
extern uint _cur_company_tick_index;
|
||||||
|
|
||||||
|
|
|
@ -666,7 +666,7 @@ DEF_CONSOLE_CMD(ConJoinCompany)
|
||||||
return true;
|
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.");
|
IConsoleError("Cannot join AI company.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -709,7 +709,7 @@ DEF_CONSOLE_CMD(ConMoveClient)
|
||||||
return true;
|
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.");
|
IConsoleError("You cannot move clients to AI companies.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -741,15 +741,14 @@ DEF_CONSOLE_CMD(ConResetCompany)
|
||||||
if (argc != 2) return false;
|
if (argc != 2) return false;
|
||||||
|
|
||||||
CompanyID index = (CompanyID)(atoi(argv[1]) - 1);
|
CompanyID index = (CompanyID)(atoi(argv[1]) - 1);
|
||||||
const Company *c = Company::GetIfValid(index);
|
|
||||||
|
|
||||||
/* Check valid range */
|
/* 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);
|
IConsolePrintF(CC_ERROR, "Company does not exist. Company-id must be between 1 and %d.", MAX_COMPANIES);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (c->is_ai) {
|
if (!Company::IsHumanID(index)) {
|
||||||
IConsoleError("Company is owned by an AI.");
|
IConsoleError("Company is owned by an AI.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1064,7 +1063,7 @@ DEF_CONSOLE_CMD(ConReloadAI)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IsHumanCompany(company_id)) {
|
if (Company::IsHumanID(company_id)) {
|
||||||
IConsoleWarning("Company is not controlled by an AI.");
|
IConsoleWarning("Company is not controlled by an AI.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1101,7 +1100,7 @@ DEF_CONSOLE_CMD(ConStopAI)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IsHumanCompany(company_id)) {
|
if (Company::IsHumanID(company_id)) {
|
||||||
IConsoleWarning("Company is not controlled by an AI.");
|
IConsoleWarning("Company is not controlled by an AI.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,7 +62,7 @@ static void DisasterClearSquare(TileIndex tile)
|
||||||
|
|
||||||
switch (GetTileType(tile)) {
|
switch (GetTileType(tile)) {
|
||||||
case MP_RAILWAY:
|
case MP_RAILWAY:
|
||||||
if (IsHumanCompany(GetTileOwner(tile)) && !IsRailWaypoint(tile)) {
|
if (Company::IsHumanID(GetTileOwner(tile)) && !IsRailWaypoint(tile)) {
|
||||||
CompanyID old_company = _current_company;
|
CompanyID old_company = _current_company;
|
||||||
_current_company = OWNER_WATER;
|
_current_company = OWNER_WATER;
|
||||||
DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
|
DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR);
|
||||||
|
@ -555,7 +555,7 @@ static bool DisasterTick_Big_Ufo(DisasterVehicle *v)
|
||||||
TileIndex tile = tile_org;
|
TileIndex tile = tile_org;
|
||||||
do {
|
do {
|
||||||
if (IsPlainRailTile(tile) &&
|
if (IsPlainRailTile(tile) &&
|
||||||
IsHumanCompany(GetTileOwner(tile))) {
|
Company::IsHumanID(GetTileOwner(tile))) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
tile = TILE_MASK(tile + 1);
|
tile = TILE_MASK(tile + 1);
|
||||||
|
|
|
@ -1230,10 +1230,8 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_MOVE)
|
||||||
{
|
{
|
||||||
CompanyID company_id = (Owner)p->Recv_uint8();
|
CompanyID company_id = (Owner)p->Recv_uint8();
|
||||||
|
|
||||||
/* Check if the company is valid */
|
/* Check if the company is valid, we don't allow moving to AI companies */
|
||||||
if (!Company::IsValidID(company_id) && company_id != COMPANY_SPECTATOR) return;
|
if (company_id != COMPANY_SPECTATOR && !Company::IsValidHumanID(company_id)) return;
|
||||||
/* We don't allow moving to AI companies */
|
|
||||||
if (company_id != COMPANY_SPECTATOR && Company::Get(company_id)->is_ai) return;
|
|
||||||
|
|
||||||
/* Check if we require a password for this company */
|
/* Check if we require a password for this company */
|
||||||
if (company_id != COMPANY_SPECTATOR && !StrEmpty(_network_company_states[company_id].password)) {
|
if (company_id != COMPANY_SPECTATOR && !StrEmpty(_network_company_states[company_id].password)) {
|
||||||
|
|
|
@ -585,7 +585,7 @@ static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, by
|
||||||
|
|
||||||
case 0x43: // Company information
|
case 0x43: // Company information
|
||||||
if (!HasBit(v->vcache.cache_valid, 3)) {
|
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);
|
SetBit(v->vcache.cache_valid, 3);
|
||||||
}
|
}
|
||||||
return v->vcache.cached_var43;
|
return v->vcache.cached_var43;
|
||||||
|
|
Loading…
Reference in New Issue