1
0
Fork 0

Add: CompanyCtrlAction enum for CMD_COMPANY_CTRL actions

pull/7175/head
glx 2019-02-04 18:06:19 +01:00 committed by glx22
parent 33e3f49161
commit 8e7fe3973f
8 changed files with 28 additions and 22 deletions

View File

@ -1282,8 +1282,8 @@ struct AIDebugWindow : public Window {
case WID_AID_RELOAD_TOGGLE: case WID_AID_RELOAD_TOGGLE:
if (ai_debug_company == OWNER_DEITY) break; if (ai_debug_company == OWNER_DEITY) break;
/* First kill the company of the AI, then start a new one. This should start the current AI again */ /* First kill the company of the AI, then start a new one. This should start the current AI again */
DoCommandP(0, 2 | ai_debug_company << 16, CRR_MANUAL, CMD_COMPANY_CTRL); DoCommandP(0, CCA_DELETE | ai_debug_company << 16, CRR_MANUAL, CMD_COMPANY_CTRL);
DoCommandP(0, 1 | ai_debug_company << 16, 0, CMD_COMPANY_CTRL); DoCommandP(0, CCA_NEW_AI | ai_debug_company << 16, 0, CMD_COMPANY_CTRL);
break; break;
case WID_AID_SETTINGS: case WID_AID_SETTINGS:

View File

@ -612,7 +612,7 @@ static bool MaybeStartNewCompany()
if (n < (uint)_settings_game.difficulty.max_no_competitors) { if (n < (uint)_settings_game.difficulty.max_no_competitors) {
/* Send a command to all clients to start up a new AI. /* Send a command to all clients to start up a new AI.
* Works fine for Multiplayer and Singleplayer */ * Works fine for Multiplayer and Singleplayer */
return DoCommandP(0, 1 | INVALID_COMPANY << 16, 0, CMD_COMPANY_CTRL); return DoCommandP(0, CCA_NEW_AI | INVALID_COMPANY << 16, 0, CMD_COMPANY_CTRL);
} }
return false; return false;
@ -810,10 +810,7 @@ void CompanyAdminRemove(CompanyID company_id, CompanyRemoveReason reason)
* @param tile unused * @param tile unused
* @param flags operation to perform * @param flags operation to perform
* @param p1 various functionality * @param p1 various functionality
* - bits 0..15: * - bits 0..15: CompanyCtrlAction
* = 0 - create a new company
* = 1 - create a new AI company
* = 2 - delete a company
* - bits 16..24: CompanyID * - bits 16..24: CompanyID
* @param p2 ClientID * @param p2 ClientID
* @param text unused * @param text unused
@ -827,8 +824,8 @@ CommandCost CmdCompanyCtrl(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
ClientID client_id = (ClientID)p2; ClientID client_id = (ClientID)p2;
#endif /* ENABLE_NETWORK */ #endif /* ENABLE_NETWORK */
switch (GB(p1, 0, 16)) { switch ((CompanyCtrlAction)GB(p1, 0, 16)) {
case 0: { // Create a new company case CCA_NEW: { // Create a new company
/* This command is only executed in a multiplayer game */ /* This command is only executed in a multiplayer game */
if (!_networking) return CMD_ERROR; if (!_networking) return CMD_ERROR;
@ -878,7 +875,7 @@ CommandCost CmdCompanyCtrl(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
break; break;
} }
case 1: { // Make a new AI company case CCA_NEW_AI: { // Make a new AI company
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; if (company_id != INVALID_COMPANY && (company_id >= MAX_COMPANIES || Company::IsValidID(company_id))) return CMD_ERROR;
@ -889,7 +886,7 @@ CommandCost CmdCompanyCtrl(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
break; break;
} }
case 2: { // Delete a company case CCA_DELETE: { // Delete a company
CompanyRemoveReason reason = (CompanyRemoveReason)GB(p2, 0, 2); CompanyRemoveReason reason = (CompanyRemoveReason)GB(p2, 0, 2);
if (reason >= CRR_END) return CMD_ERROR; if (reason >= CRR_END) return CMD_ERROR;

View File

@ -64,4 +64,13 @@ enum CompanyRemoveReason {
CRR_END, ///< Sentinel for end. CRR_END, ///< Sentinel for end.
}; };
/** The action to do with CMD_COMPANY_CTRL. */
enum CompanyCtrlAction {
CCA_NEW, ///< Create a new company.
CCA_NEW_AI, ///< Create a new AI company.
CCA_DELETE, ///< Delete a company.
CCA_END, ///< Sentinel for end.
};
#endif /* COMPANY_TYPE_H */ #endif /* COMPANY_TYPE_H */

View File

@ -836,7 +836,7 @@ DEF_CONSOLE_CMD(ConResetCompany)
} }
/* It is safe to remove this company */ /* It is safe to remove this company */
DoCommandP(0, 2 | index << 16, CRR_MANUAL, CMD_COMPANY_CTRL); DoCommandP(0, CCA_DELETE | index << 16, CRR_MANUAL, CMD_COMPANY_CTRL);
IConsolePrint(CC_DEFAULT, "Company deleted."); IConsolePrint(CC_DEFAULT, "Company deleted.");
return true; return true;
@ -1178,7 +1178,7 @@ DEF_CONSOLE_CMD(ConStartAI)
} }
/* Start a new AI company */ /* Start a new AI company */
DoCommandP(0, 1 | INVALID_COMPANY << 16, 0, CMD_COMPANY_CTRL); DoCommandP(0, CCA_NEW_AI | INVALID_COMPANY << 16, 0, CMD_COMPANY_CTRL);
return true; return true;
} }
@ -1213,8 +1213,8 @@ DEF_CONSOLE_CMD(ConReloadAI)
} }
/* First kill the company of the AI, then start a new one. This should start the current AI again */ /* First kill the company of the AI, then start a new one. This should start the current AI again */
DoCommandP(0, 2 | company_id << 16, CRR_MANUAL, CMD_COMPANY_CTRL); DoCommandP(0, CCA_DELETE | company_id << 16, CRR_MANUAL, CMD_COMPANY_CTRL);
DoCommandP(0, 1 | company_id << 16, 0, CMD_COMPANY_CTRL); DoCommandP(0, CCA_NEW_AI | company_id << 16, 0, CMD_COMPANY_CTRL);
IConsolePrint(CC_DEFAULT, "AI reloaded."); IConsolePrint(CC_DEFAULT, "AI reloaded.");
return true; return true;
@ -1250,7 +1250,7 @@ DEF_CONSOLE_CMD(ConStopAI)
} }
/* Now kill the company of the AI. */ /* Now kill the company of the AI. */
DoCommandP(0, 2 | company_id << 16, CRR_MANUAL, CMD_COMPANY_CTRL); DoCommandP(0, CCA_DELETE | company_id << 16, CRR_MANUAL, CMD_COMPANY_CTRL);
IConsolePrint(CC_DEFAULT, "AI stopped, company deleted."); IConsolePrint(CC_DEFAULT, "AI stopped, company deleted.");
return true; return true;

View File

@ -642,7 +642,7 @@ static void CompanyCheckBankrupt(Company *c)
* that changing the current company is okay. In case of single * that changing the current company is okay. In case of single
* player we are sure (the above check) that we are not the local * player we are sure (the above check) that we are not the local
* company and thus we won't be moved. */ * company and thus we won't be moved. */
if (!_networking || _network_server) DoCommandP(0, 2 | (c->index << 16), CRR_BANKRUPT, CMD_COMPANY_CTRL); if (!_networking || _network_server) DoCommandP(0, CCA_DELETE | (c->index << 16), CRR_BANKRUPT, CMD_COMPANY_CTRL);
break; break;
} }
} }

View File

@ -878,7 +878,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_MAP_DONE(Packet
* the server will give us a client-id and let us in */ * the server will give us a client-id and let us in */
_network_join_status = NETWORK_JOIN_STATUS_REGISTERING; _network_join_status = NETWORK_JOIN_STATUS_REGISTERING;
ShowJoinStatusWindow(); ShowJoinStatusWindow();
NetworkSendCommand(0, 0, 0, CMD_COMPANY_CTRL, NULL, NULL, _local_company); NetworkSendCommand(0, CCA_NEW, 0, CMD_COMPANY_CTRL, NULL, NULL, _local_company);
} }
} else { } else {
/* take control over an existing company */ /* take control over an existing company */

View File

@ -1675,7 +1675,7 @@ static void NetworkAutoCleanCompanies()
/* Is the company empty for autoclean_unprotected-months, and is there no protection? */ /* Is the company empty for autoclean_unprotected-months, and is there no protection? */
if (_settings_client.network.autoclean_unprotected != 0 && _network_company_states[c->index].months_empty > _settings_client.network.autoclean_unprotected && StrEmpty(_network_company_states[c->index].password)) { if (_settings_client.network.autoclean_unprotected != 0 && _network_company_states[c->index].months_empty > _settings_client.network.autoclean_unprotected && StrEmpty(_network_company_states[c->index].password)) {
/* Shut the company down */ /* Shut the company down */
DoCommandP(0, 2 | c->index << 16, CRR_AUTOCLEAN, CMD_COMPANY_CTRL); DoCommandP(0, CCA_DELETE | c->index << 16, CRR_AUTOCLEAN, CMD_COMPANY_CTRL);
IConsolePrintF(CC_DEFAULT, "Auto-cleaned company #%d with no password", c->index + 1); IConsolePrintF(CC_DEFAULT, "Auto-cleaned company #%d with no password", c->index + 1);
} }
/* Is the company empty for autoclean_protected-months, and there is a protection? */ /* Is the company empty for autoclean_protected-months, and there is a protection? */
@ -1689,7 +1689,7 @@ static void NetworkAutoCleanCompanies()
/* Is the company empty for autoclean_novehicles-months, and has no vehicles? */ /* Is the company empty for autoclean_novehicles-months, and has no vehicles? */
if (_settings_client.network.autoclean_novehicles != 0 && _network_company_states[c->index].months_empty > _settings_client.network.autoclean_novehicles && vehicles_in_company[c->index] == 0) { if (_settings_client.network.autoclean_novehicles != 0 && _network_company_states[c->index].months_empty > _settings_client.network.autoclean_novehicles && vehicles_in_company[c->index] == 0) {
/* Shut the company down */ /* Shut the company down */
DoCommandP(0, 2 | c->index << 16, CRR_AUTOCLEAN, CMD_COMPANY_CTRL); DoCommandP(0, CCA_DELETE | c->index << 16, CRR_AUTOCLEAN, CMD_COMPANY_CTRL);
IConsolePrintF(CC_DEFAULT, "Auto-cleaned company #%d with no vehicles", c->index + 1); IConsolePrintF(CC_DEFAULT, "Auto-cleaned company #%d with no vehicles", c->index + 1);
} }
} else { } else {

View File

@ -618,9 +618,9 @@ static CallBackFunction MenuClickCompany(int index)
case CTMN_NEW_COMPANY: case CTMN_NEW_COMPANY:
if (_network_server) { if (_network_server) {
DoCommandP(0, 0, _network_own_client_id, CMD_COMPANY_CTRL); DoCommandP(0, CCA_NEW, _network_own_client_id, CMD_COMPANY_CTRL);
} else { } else {
NetworkSendCommand(0, 0, 0, CMD_COMPANY_CTRL, NULL, NULL, _local_company); NetworkSendCommand(0, CCA_NEW, 0, CMD_COMPANY_CTRL, NULL, NULL, _local_company);
} }
return CBF_NONE; return CBF_NONE;