Fix #6544: Don't join AI company when loading network game in singleplayer

This commit is contained in:
Tyler Trahan
2022-01-19 16:46:51 -07:00
committed by rubidium42
parent 5ea55f3948
commit ec90fb4c99
4 changed files with 41 additions and 10 deletions

View File

@@ -1198,3 +1198,31 @@ CommandCost CmdGiveMoney(DoCommandFlag flags, uint32 money, CompanyID dest_compa
/* Subtract money from local-company */
return amount;
}
/**
* Get the index of the first available company. It attempts,
* from first to last, and as soon as the attempt succeeds,
* to get the index of the company:
* 1st - get the first existing human company.
* 2nd - get the first non-existing company.
* 3rd - get COMPANY_FIRST.
* @return the index of the first available company.
*/
CompanyID GetFirstPlayableCompanyID()
{
for (Company *c : Company::Iterate()) {
if (Company::IsHumanID(c->index)) {
return c->index;
}
}
if (Company::CanAllocateItem()) {
for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
if (!Company::IsValidID(c)) {
return c;
}
}
}
return COMPANY_FIRST;
}