mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-08-06 03:09:05 +01:00
Fix: Never delete the last existing company in singleplayer mode
This commit is contained in:
parent
b17177bd20
commit
485aafc1b7
@ -863,9 +863,16 @@ CommandCost CmdCompanyCtrl(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
|
|||||||
}
|
}
|
||||||
|
|
||||||
case CCA_NEW_AI: { // Make a new AI company
|
case CCA_NEW_AI: { // Make a new AI company
|
||||||
|
if (company_id != INVALID_COMPANY && company_id >= MAX_COMPANIES) return CMD_ERROR;
|
||||||
|
|
||||||
|
/* For network games, company deletion is delayed. */
|
||||||
|
if (!_networking && company_id != INVALID_COMPANY && Company::IsValidID(company_id)) return CMD_ERROR;
|
||||||
|
|
||||||
if (!(flags & DC_EXEC)) return CommandCost();
|
if (!(flags & DC_EXEC)) return CommandCost();
|
||||||
|
|
||||||
if (company_id != INVALID_COMPANY && (company_id >= MAX_COMPANIES || Company::IsValidID(company_id))) return CMD_ERROR;
|
/* For network game, just assume deletion happened. */
|
||||||
|
assert(company_id == INVALID_COMPANY || !Company::IsValidID(company_id));
|
||||||
|
|
||||||
Company *c = DoStartupNewCompany(true, company_id);
|
Company *c = DoStartupNewCompany(true, company_id);
|
||||||
if (c != nullptr) NetworkServerNewCompany(c, nullptr);
|
if (c != nullptr) NetworkServerNewCompany(c, nullptr);
|
||||||
break;
|
break;
|
||||||
@ -875,6 +882,9 @@ CommandCost CmdCompanyCtrl(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
|
|||||||
CompanyRemoveReason reason = (CompanyRemoveReason)GB(p1, 24, 8);
|
CompanyRemoveReason reason = (CompanyRemoveReason)GB(p1, 24, 8);
|
||||||
if (reason >= CRR_END) return CMD_ERROR;
|
if (reason >= CRR_END) return CMD_ERROR;
|
||||||
|
|
||||||
|
/* We can't delete the last existing company in offline mode. */
|
||||||
|
if (!_networking && Company::GetNumItems() == 1) return CMD_ERROR;
|
||||||
|
|
||||||
Company *c = Company::GetIfValid(company_id);
|
Company *c = Company::GetIfValid(company_id);
|
||||||
if (c == nullptr) return CMD_ERROR;
|
if (c == nullptr) return CMD_ERROR;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user