diff options
author | glx22 <glx@openttd.org> | 2021-01-18 15:31:07 +0100 |
---|---|---|
committer | Loïc Guilloux <glx22@users.noreply.github.com> | 2021-01-22 22:19:55 +0100 |
commit | 485aafc1b7d51967e06cc5db76c195edcf8dc644 (patch) | |
tree | 55c7ec128fcc89d42926d6bebf16a6688f33fb2b | |
parent | b17177bd2033cfa026873e9166a835034fe39fd2 (diff) | |
download | openttd-485aafc1b7d51967e06cc5db76c195edcf8dc644.tar.xz |
Fix: Never delete the last existing company in singleplayer mode
-rw-r--r-- | src/company_cmd.cpp | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/company_cmd.cpp b/src/company_cmd.cpp index 5a6a114e7..b846c53ba 100644 --- a/src/company_cmd.cpp +++ b/src/company_cmd.cpp @@ -863,9 +863,16 @@ CommandCost CmdCompanyCtrl(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3 } 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 (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); if (c != nullptr) NetworkServerNewCompany(c, nullptr); break; @@ -875,6 +882,9 @@ CommandCost CmdCompanyCtrl(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3 CompanyRemoveReason reason = (CompanyRemoveReason)GB(p1, 24, 8); 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); if (c == nullptr) return CMD_ERROR; |