Changeset - r24693:a7a1c9d9241f
[Not reviewed]
master
0 1 0
glx22 - 4 years ago 2021-01-18 14:31:07
glx@openttd.org
Fix: Never delete the last existing company in singleplayer mode
1 file changed with 11 insertions and 1 deletions:
0 comments (0 inline, 0 general)
src/company_cmd.cpp
Show inline comments
 
@@ -863,9 +863,16 @@ CommandCost CmdCompanyCtrl(TileIndex til
 
		}
 

	
 
		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 til
 
			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;
 

	
0 comments (0 inline, 0 general)