From bf3c75c34cf4b1781ccebd83f4d11fe149a43ccd Mon Sep 17 00:00:00 2001 From: rubidium Date: Sat, 22 Oct 2011 20:54:23 +0000 Subject: [PATCH] (svn r23052) [1.1] -Backport from trunk: - Fix: Palette conversion windows to DOS for light house / stadium animated colour was mixed up (r23032) - Fix: For the admin 'bots' there was no distinction between bankruptcy and manual removal of companies even though the API suggested that [FS#4804] (r23031) - Fix: Always show a chat message and send an admin packet when a new company is made [FS#4796] (r23030) - Fix: Pass bottom of dropdown item rather than bottom of dropdown window, so the dropdown gets drawn better with different font sizes (r23018) --- src/ai/ai_gui.cpp | 2 +- src/company_cmd.cpp | 23 ++++++++++++----------- src/company_type.h | 9 +++++++++ src/console_cmds.cpp | 6 +++--- src/economy.cpp | 2 +- src/network/core/tcp_admin.cpp | 6 ++++++ src/network/core/tcp_admin.h | 4 +++- src/network/network_server.cpp | 6 ++---- src/table/palette_convert.h | 2 +- src/widgets/dropdown.cpp | 2 +- 10 files changed, 39 insertions(+), 23 deletions(-) diff --git a/src/ai/ai_gui.cpp b/src/ai/ai_gui.cpp index 5e417c785c..48289fe730 100644 --- a/src/ai/ai_gui.cpp +++ b/src/ai/ai_gui.cpp @@ -1002,7 +1002,7 @@ struct AIDebugWindow : public QueryStringBaseWindow { switch (widget) { case AID_WIDGET_RELOAD_TOGGLE: /* 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, 0, CMD_COMPANY_CTRL); + DoCommandP(0, 2 | ai_debug_company << 16, CRR_MANUAL, CMD_COMPANY_CTRL); DoCommandP(0, 1 | ai_debug_company << 16, 0, CMD_COMPANY_CTRL); break; diff --git a/src/company_cmd.cpp b/src/company_cmd.cpp index 6fcedaf94a..0b6d2a5b94 100644 --- a/src/company_cmd.cpp +++ b/src/company_cmd.cpp @@ -773,13 +773,14 @@ void CompanyAdminUpdate(const Company *company) } /** - * Called whenever a company goes bankrupt in order to notify admins. - * @param company_id The company that went bankrupt. + * Called whenever a company is removed in order to notify admins. + * @param company_id The company that was removed. + * @param reason The reason the company was removed. */ -void CompanyAdminBankrupt(CompanyID company_id) +void CompanyAdminRemove(CompanyID company_id, CompanyRemoveReason reason) { #ifdef ENABLE_NETWORK - if (_network_server) NetworkAdminCompanyRemove(company_id, ADMIN_CRR_BANKRUPT); + if (_network_server) NetworkAdminCompanyRemove(company_id, (AdminCompanyRemoveReason)reason); #endif /* ENABLE_NETWORK */ } @@ -846,7 +847,6 @@ CommandCost CmdCompanyCtrl(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3 } if (_network_server) { - CompanyID old_playas = ci->client_playas; ci->client_playas = c->index; NetworkUpdateClientInfo(ci->client_id); @@ -869,11 +869,9 @@ CommandCost CmdCompanyCtrl(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3 NetworkSendCommand(0, 0, 0, CMD_RENAME_PRESIDENT, NULL, ci->client_name, ci->client_playas); } - /* Announce new company on network, if the client was a SPECTATOR before */ - if (old_playas == COMPANY_SPECTATOR) { - NetworkAdminCompanyInfo(c, true); - NetworkServerSendChat(NETWORK_ACTION_COMPANY_NEW, DESTTYPE_BROADCAST, 0, "", ci->client_id, ci->client_playas + 1); - } + /* Announce new company on network. */ + NetworkAdminCompanyInfo(c, true); + NetworkServerSendChat(NETWORK_ACTION_COMPANY_NEW, DESTTYPE_BROADCAST, 0, "", ci->client_id, ci->client_playas + 1); } #endif /* ENABLE_NETWORK */ break; @@ -887,6 +885,9 @@ CommandCost CmdCompanyCtrl(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3 break; case 2: { // Delete a company + CompanyRemoveReason reason = (CompanyRemoveReason)GB(p2, 0, 2); + if (reason >= CRR_END) return CMD_ERROR; + Company *c = Company::GetIfValid(company_id); if (c == NULL) return CMD_ERROR; @@ -910,7 +911,7 @@ CommandCost CmdCompanyCtrl(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3 CompanyID c_index = c->index; delete c; AI::BroadcastNewEvent(new AIEventCompanyBankrupt(c_index)); - CompanyAdminBankrupt(c_index); + CompanyAdminRemove(c_index, (CompanyRemoveReason)reason); break; } diff --git a/src/company_type.h b/src/company_type.h index 88949b9ad3..387b8c8e7f 100644 --- a/src/company_type.h +++ b/src/company_type.h @@ -56,4 +56,13 @@ typedef uint16 CompanyMask; struct Company; typedef uint32 CompanyManagerFace; ///< Company manager face bits, info see in company_manager_face.h +/** The reason why the company was removed. */ +enum CompanyRemoveReason { + CRR_MANUAL, ///< The company is manually removed. + CRR_AUTOCLEAN, ///< The company is removed due to autoclean. + CRR_BANKRUPT, ///< The company went belly-up. + + CRR_END ///< Sentinel for end. +}; + #endif /* COMPANY_TYPE_H */ diff --git a/src/console_cmds.cpp b/src/console_cmds.cpp index c5b4385510..8244cbdd94 100644 --- a/src/console_cmds.cpp +++ b/src/console_cmds.cpp @@ -836,7 +836,7 @@ DEF_CONSOLE_CMD(ConResetCompany) } /* It is safe to remove this company */ - DoCommandP(0, 2 | index << 16, 0, CMD_COMPANY_CTRL); + DoCommandP(0, 2 | index << 16, CRR_MANUAL, CMD_COMPANY_CTRL); IConsolePrint(CC_DEFAULT, "Company deleted."); return true; @@ -1196,7 +1196,7 @@ DEF_CONSOLE_CMD(ConReloadAI) } /* 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, 0, CMD_COMPANY_CTRL); + DoCommandP(0, 2 | company_id << 16, CRR_MANUAL, CMD_COMPANY_CTRL); DoCommandP(0, 1 | company_id << 16, 0, CMD_COMPANY_CTRL); IConsolePrint(CC_DEFAULT, "AI reloaded."); @@ -1233,7 +1233,7 @@ DEF_CONSOLE_CMD(ConStopAI) } /* Now kill the company of the AI. */ - DoCommandP(0, 2 | company_id << 16, 0, CMD_COMPANY_CTRL); + DoCommandP(0, 2 | company_id << 16, CRR_MANUAL, CMD_COMPANY_CTRL); IConsolePrint(CC_DEFAULT, "AI stopped, company deleted."); return true; diff --git a/src/economy.cpp b/src/economy.cpp index f99c73a7f8..d2248a5be8 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -546,7 +546,7 @@ static void CompanyCheckBankrupt(Company *c) * that changing the current company is okay. In case of single * 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) DoCommandP(0, 2 | (c->index << 16), 0, CMD_COMPANY_CTRL); + if (!_networking || _network_server) DoCommandP(0, 2 | (c->index << 16), CRR_BANKRUPT, CMD_COMPANY_CTRL); break; } } diff --git a/src/network/core/tcp_admin.cpp b/src/network/core/tcp_admin.cpp index 3765b070c8..31d5d7a953 100644 --- a/src/network/core/tcp_admin.cpp +++ b/src/network/core/tcp_admin.cpp @@ -19,6 +19,12 @@ #include "tcp_admin.h" #include "../../debug.h" +/* Make sure that these enums match. */ +assert_compile((int)CRR_MANUAL == (int)ADMIN_CRR_MANUAL); +assert_compile((int)CRR_AUTOCLEAN == (int)ADMIN_CRR_AUTOCLEAN); +assert_compile((int)CRR_BANKRUPT == (int)ADMIN_CRR_BANKRUPT); +assert_compile((int)CRR_END == (int)ADMIN_CRR_END); + NetworkAdminSocketHandler::NetworkAdminSocketHandler(SOCKET s) { this->sock = s; diff --git a/src/network/core/tcp_admin.h b/src/network/core/tcp_admin.h index 1048a5e93d..2348caf8f3 100644 --- a/src/network/core/tcp_admin.h +++ b/src/network/core/tcp_admin.h @@ -99,7 +99,9 @@ DECLARE_ENUM_AS_BIT_SET(AdminUpdateFrequency) enum AdminCompanyRemoveReason { ADMIN_CRR_MANUAL, ///< The company is manually removed. ADMIN_CRR_AUTOCLEAN, ///< The company is removed due to autoclean. - ADMIN_CRR_BANKRUPT ///< The company went belly-up. + ADMIN_CRR_BANKRUPT, ///< The company went belly-up. + + ADMIN_CRR_END ///< Sentinel for end. }; #define DECLARE_ADMIN_RECEIVE_COMMAND(type) virtual NetworkRecvStatus NetworkPacketReceive_## type ##_command(Packet *p) diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp index 5ddfca723c..5a2b582c84 100644 --- a/src/network/network_server.cpp +++ b/src/network/network_server.cpp @@ -1574,8 +1574,7 @@ static void NetworkAutoCleanCompanies() /* 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)) { /* Shut the company down */ - DoCommandP(0, 2 | c->index << 16, 0, CMD_COMPANY_CTRL); - NetworkAdminCompanyRemove(c->index, ADMIN_CRR_AUTOCLEAN); + DoCommandP(0, 2 | c->index << 16, CRR_AUTOCLEAN, CMD_COMPANY_CTRL); 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? */ @@ -1589,8 +1588,7 @@ static void NetworkAutoCleanCompanies() /* 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) { /* Shut the company down */ - DoCommandP(0, 2 | c->index << 16, 0, CMD_COMPANY_CTRL); - NetworkAdminCompanyRemove(c->index, ADMIN_CRR_AUTOCLEAN); + DoCommandP(0, 2 | c->index << 16, CRR_AUTOCLEAN, CMD_COMPANY_CTRL); IConsolePrintF(CC_DEFAULT, "Auto-cleaned company #%d with no vehicles", c->index + 1); } } else { diff --git a/src/table/palette_convert.h b/src/table/palette_convert.h index 02f4478f3e..2fbc74042e 100644 --- a/src/table/palette_convert.h +++ b/src/table/palette_convert.h @@ -41,7 +41,7 @@ static const byte _palmap_w2d[] = { 2, 245, 246, 247, 248, 249, 250, 251, // 216..223 252, 253, 254, 229, 230, 231, 227, 228, // 224..231 235, 236, 237, 238, 232, 233, 234, 239, // 232..239 - 240, 241, 242, 244, 243, 9, 218, 219, // 240..247 + 240, 241, 242, 243, 244, 9, 218, 219, // 240..247 220, 221, 222, 223, 224, 225, 226, 255, // 248..255 }; diff --git a/src/widgets/dropdown.cpp b/src/widgets/dropdown.cpp index 15865a3594..8cc8c36cfa 100644 --- a/src/widgets/dropdown.cpp +++ b/src/widgets/dropdown.cpp @@ -239,7 +239,7 @@ struct DropdownWindow : Window { bool selected = (this->selected_index == item->result); if (selected) GfxFillRect(r.left + 2, y, r.right - 1, y + item_height - 1, 0); - item->Draw(r.left, r.right, y, r.bottom, selected, colour); + item->Draw(r.left, r.right, y, y + item_height, selected, colour); if (item->masked) { GfxFillRect(r.left + 1, y, r.right - 1, y + item_height - 1, _colour_gradient[colour][5], FILLRECT_CHECKER);