diff --git a/src/company_cmd.cpp b/src/company_cmd.cpp index 7d9ad424df..c53b9a1312 100644 --- a/src/company_cmd.cpp +++ b/src/company_cmd.cpp @@ -674,7 +674,7 @@ TimeoutTimer _new_competitor_timeout({ TimerGameTick::Priority::C /* Send a command to all clients to start up a new AI. * Works fine for Multiplayer and Singleplayer */ - Command::Post(CCA_NEW_AI, CompanyID::Invalid(), CRR_NONE, INVALID_CLIENT_ID); + Command::Post(CCA_NEW_AI, CompanyID::Invalid(), CompanyRemoveReason::None, INVALID_CLIENT_ID); }); /** Start of a new game. */ @@ -795,7 +795,7 @@ void OnTick_Companies() for (auto i = 0; i < _settings_game.difficulty.max_no_competitors; i++) { if (_networking && num_companies++ >= _settings_client.network.max_companies) break; if (num_ais++ >= _settings_game.difficulty.max_no_competitors) break; - Command::Post(CCA_NEW_AI, CompanyID::Invalid(), CRR_NONE, INVALID_CLIENT_ID); + Command::Post(CCA_NEW_AI, CompanyID::Invalid(), {}, INVALID_CLIENT_ID); } timeout = 10 * 60 * Ticks::TICKS_PER_SECOND; } @@ -964,7 +964,7 @@ CommandCost CmdCompanyCtrl(DoCommandFlags flags, CompanyCtrlAction cca, CompanyI } case CCA_DELETE: { // Delete a company - if (reason >= CRR_END) return CMD_ERROR; + if (reason >= CompanyRemoveReason::End) return CMD_ERROR; /* We can't delete the last existing company in singleplayer mode. */ if (!_networking && Company::GetNumItems() == 1) return CMD_ERROR; diff --git a/src/company_type.h b/src/company_type.h index 9e7a552912..a16f61ae9c 100644 --- a/src/company_type.h +++ b/src/company_type.h @@ -57,14 +57,14 @@ struct CompanyManagerFace { }; /** The reason why the company was removed. */ -enum CompanyRemoveReason : uint8_t { - CRR_MANUAL, ///< The company is manually removed. - CRR_AUTOCLEAN, ///< The company is removed due to autoclean. - CRR_BANKRUPT, ///< The company went belly-up. +enum class CompanyRemoveReason : uint8_t { + Manual, ///< The company is manually removed. + Autoclean, ///< The company is removed due to autoclean. + Bankrupt, ///< The company went belly-up. - CRR_END, ///< Sentinel for end. + End, ///< Sentinel for end. - CRR_NONE = CRR_MANUAL, ///< Dummy reason for actions that don't need one. + None = Manual, ///< Dummy reason for actions that don't need one. }; /** The action to do with Commands::CompanyControl. */ diff --git a/src/console_cmds.cpp b/src/console_cmds.cpp index 8e4c80933a..381c0813f8 100644 --- a/src/console_cmds.cpp +++ b/src/console_cmds.cpp @@ -1126,7 +1126,7 @@ static bool ConResetCompany(std::span argv) } /* It is safe to remove this company */ - Command::Post(CCA_DELETE, *index, CRR_MANUAL, INVALID_CLIENT_ID); + Command::Post(CCA_DELETE, *index, CompanyRemoveReason::Manual, INVALID_CLIENT_ID); IConsolePrint(CC_DEFAULT, "Company deleted."); return true; @@ -1563,7 +1563,7 @@ static bool ConStartAI(std::span argv) } /* Start a new AI company */ - Command::Post(CCA_NEW_AI, CompanyID::Invalid(), CRR_NONE, INVALID_CLIENT_ID); + Command::Post(CCA_NEW_AI, CompanyID::Invalid(), CompanyRemoveReason::None, INVALID_CLIENT_ID); return true; } @@ -1605,8 +1605,8 @@ static bool ConReloadAI(std::span argv) } /* First kill the company of the AI, then start a new one. This should start the current AI again */ - Command::Post(CCA_DELETE, *company_id, CRR_MANUAL, INVALID_CLIENT_ID); - Command::Post(CCA_NEW_AI, *company_id, CRR_NONE, INVALID_CLIENT_ID); + Command::Post(CCA_DELETE, *company_id, CompanyRemoveReason::Manual, INVALID_CLIENT_ID); + Command::Post(CCA_NEW_AI, *company_id, CompanyRemoveReason::None, INVALID_CLIENT_ID); IConsolePrint(CC_DEFAULT, "AI reloaded."); return true; @@ -1649,7 +1649,7 @@ static bool ConStopAI(std::span argv) } /* Now kill the company of the AI. */ - Command::Post(CCA_DELETE, *company_id, CRR_MANUAL, INVALID_CLIENT_ID); + Command::Post(CCA_DELETE, *company_id, CompanyRemoveReason::Manual, INVALID_CLIENT_ID); IConsolePrint(CC_DEFAULT, "AI stopped, company deleted."); return true; diff --git a/src/economy.cpp b/src/economy.cpp index b445c3ef25..e3b9d98824 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -624,7 +624,7 @@ static void CompanyCheckBankrupt(Company *c) * player we are sure (the above check) that we are not the local * company and thus we won't be moved. */ if (!_networking || _network_server) { - Command::Post(CCA_DELETE, c->index, CRR_BANKRUPT, INVALID_CLIENT_ID); + Command::Post(CCA_DELETE, c->index, CompanyRemoveReason::Bankrupt, INVALID_CLIENT_ID); return; } break; diff --git a/src/network/core/tcp_admin.cpp b/src/network/core/tcp_admin.cpp index 1e7150a569..35010076e8 100644 --- a/src/network/core/tcp_admin.cpp +++ b/src/network/core/tcp_admin.cpp @@ -16,10 +16,10 @@ #include "../../safeguards.h" /* Make sure that these enums match. */ -static_assert((int)CRR_MANUAL == (int)ADMIN_CRR_MANUAL); -static_assert((int)CRR_AUTOCLEAN == (int)ADMIN_CRR_AUTOCLEAN); -static_assert((int)CRR_BANKRUPT == (int)ADMIN_CRR_BANKRUPT); -static_assert((int)CRR_END == (int)ADMIN_CRR_END); +static_assert(to_underlying(CompanyRemoveReason::Manual) == to_underlying(ADMIN_CRR_MANUAL)); +static_assert(to_underlying(CompanyRemoveReason::Autoclean) == to_underlying(ADMIN_CRR_AUTOCLEAN)); +static_assert(to_underlying(CompanyRemoveReason::Bankrupt) == to_underlying(ADMIN_CRR_BANKRUPT)); +static_assert(to_underlying(CompanyRemoveReason::End) == to_underlying(ADMIN_CRR_END)); NetworkRecvStatus NetworkAdminSocketHandler::CloseConnection(bool) { diff --git a/src/network/network_client.cpp b/src/network/network_client.cpp index f0698ad3c5..70118b793c 100644 --- a/src/network/network_client.cpp +++ b/src/network/network_client.cpp @@ -885,7 +885,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_MAP_DONE(Packet Debug(net, 9, "Client::join_status = REGISTERING"); _network_join_status = NETWORK_JOIN_STATUS_REGISTERING; ShowJoinStatusWindow(); - Command::Post(CCA_NEW, CompanyID::Invalid(), CRR_NONE, _network_own_client_id); + Command::Post(CCA_NEW, CompanyID::Invalid(), CompanyRemoveReason::None, _network_own_client_id); } } else { /* take control over an existing company */ diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp index 3adf4ad477..18114fcc9c 100644 --- a/src/network/network_gui.cpp +++ b/src/network/network_gui.cpp @@ -1305,7 +1305,7 @@ static void AdminCompanyResetCallback(Window *, bool confirmed) { if (confirmed) { if (NetworkCompanyHasClients(_admin_company_id)) return; - Command::Post(CCA_DELETE, _admin_company_id, CRR_MANUAL, INVALID_CLIENT_ID); + Command::Post(CCA_DELETE, _admin_company_id, CompanyRemoveReason::Manual, INVALID_CLIENT_ID); } } @@ -1590,7 +1590,7 @@ private: */ static void OnClickCompanyNew([[maybe_unused]] NetworkClientListWindow *w, [[maybe_unused]] Point pt, CompanyID) { - Command::Post(CCA_NEW, CompanyID::Invalid(), CRR_NONE, _network_own_client_id); + Command::Post(CCA_NEW, CompanyID::Invalid(), CompanyRemoveReason::None, _network_own_client_id); } /** diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp index 45d4c06c31..0e6905dba4 100644 --- a/src/network/network_server.cpp +++ b/src/network/network_server.cpp @@ -1635,13 +1635,13 @@ static void NetworkAutoCleanCompanies() /* Is the company empty for autoclean_protected-months? */ if (_settings_client.network.autoclean_protected != 0 && c->months_empty > _settings_client.network.autoclean_protected) { /* Shut the company down */ - Command::Post(CCA_DELETE, c->index, CRR_AUTOCLEAN, INVALID_CLIENT_ID); + Command::Post(CCA_DELETE, c->index, CompanyRemoveReason::Autoclean, INVALID_CLIENT_ID); IConsolePrint(CC_INFO, "Auto-cleaned company #{}.", c->index + 1); } /* Is the company empty for autoclean_novehicles-months, and has no vehicles? */ if (_settings_client.network.autoclean_novehicles != 0 && c->months_empty > _settings_client.network.autoclean_novehicles && !has_vehicles.Test(c->index)) { /* Shut the company down */ - Command::Post(CCA_DELETE, c->index, CRR_AUTOCLEAN, INVALID_CLIENT_ID); + Command::Post(CCA_DELETE, c->index, CompanyRemoveReason::Autoclean, INVALID_CLIENT_ID); IConsolePrint(CC_INFO, "Auto-cleaned company #{} with no vehicles.", c->index + 1); } } else { diff --git a/src/script/script_gui.cpp b/src/script/script_gui.cpp index 9d86a08e8b..64c26d563f 100644 --- a/src/script/script_gui.cpp +++ b/src/script/script_gui.cpp @@ -1016,8 +1016,8 @@ struct ScriptDebugWindow : public Window { case WID_SCRD_RELOAD_TOGGLE: if (this->filter.script_debug_company == OWNER_DEITY) break; /* First kill the company of the AI, then start a new one. This should start the current AI again */ - Command::Post(CCA_DELETE, this->filter.script_debug_company, CRR_MANUAL, INVALID_CLIENT_ID); - Command::Post(CCA_NEW_AI, this->filter.script_debug_company, CRR_NONE, INVALID_CLIENT_ID); + Command::Post(CCA_DELETE, this->filter.script_debug_company, CompanyRemoveReason::Manual, INVALID_CLIENT_ID); + Command::Post(CCA_NEW_AI, this->filter.script_debug_company, CompanyRemoveReason::None, INVALID_CLIENT_ID); break; case WID_SCRD_SETTINGS: