diff --git a/regression/regression/main.nut b/regression/regression/main.nut index d20b2bb298..f023f0f7d0 100644 --- a/regression/regression/main.nut +++ b/regression/regression/main.nut @@ -2042,6 +2042,13 @@ function Regression::Start() print(" CompanyName: " + c.GetNewName()); } break; + case AIEvent.ET_PRESIDENT_RENAMED: { + local c = AIEventPresidentRenamed.Convert(e); + print(" EventName: PresidentRenamed"); + print(" CompanyID: " + c.GetCompanyID()); + print(" PresidentName: " + c.GetNewName()); + } break; + default: print(" Unknown Event"); break; diff --git a/regression/regression/result.txt b/regression/regression/result.txt index 9c14a3bc57..8611b2f8aa 100644 --- a/regression/regression/result.txt +++ b/regression/regression/result.txt @@ -9716,6 +9716,11 @@ ERROR: IsEnd() is invalid as Begin() is never called EventName: CompanyRenamed CompanyID: 1 CompanyName: Regression + GetNextEvent: instance + GetEventType: 34 + EventName: PresidentRenamed + CompanyID: 1 + PresidentName: Regression AI GetNextEvent: instance GetEventType: 33 EventName: CompanyRenamed @@ -9758,9 +9763,9 @@ ERROR: IsEnd() is invalid as Begin() is never called --Valuate() with excessive CPU usage-- Your script made an error: excessive CPU usage in valuator function -*FUNCTION [unknown()] regression/main.nut line [2058] +*FUNCTION [unknown()] regression/main.nut line [2065] *FUNCTION [Valuate()] NATIVE line [-1] -*FUNCTION [Start()] regression/main.nut line [2059] +*FUNCTION [Start()] regression/main.nut line [2066] [id] 0 [this] TABLE @@ -9769,7 +9774,7 @@ Your script made an error: excessive CPU usage in valuator function [this] INSTANCE Your script made an error: excessive CPU usage in valuator function -*FUNCTION [Start()] regression/main.nut line [2059] +*FUNCTION [Start()] regression/main.nut line [2066] [Infinite] CLOSURE [list] INSTANCE diff --git a/src/company_cmd.cpp b/src/company_cmd.cpp index 48bf2afbc7..e955091c5b 100644 --- a/src/company_cmd.cpp +++ b/src/company_cmd.cpp @@ -1241,6 +1241,11 @@ CommandCost CmdRenamePresident(DoCommandFlag flags, const std::string &text) InvalidateWindowClassesData(WC_COMPANY, 1); MarkWholeScreenDirty(); CompanyAdminUpdate(c); + + SetDParam(0, c->index); + std::string new_name = GetString(STR_PRESIDENT_NAME); + AI::BroadcastNewEvent(new ScriptEventPresidentRenamed(c->index, new_name)); + Game::NewEvent(new ScriptEventPresidentRenamed(c->index, new_name)); } return CommandCost(); diff --git a/src/script/api/ai_changelog.hpp b/src/script/api/ai_changelog.hpp index 0992a6e080..ecc51d8072 100644 --- a/src/script/api/ai_changelog.hpp +++ b/src/script/api/ai_changelog.hpp @@ -20,6 +20,7 @@ * API additions: * \li AIEventVehicleCrashed::GetVictims * \li AIEventCompanyRenamed + * \li AIEventPresidentRenamed * * \b 14.0 * diff --git a/src/script/api/game_changelog.hpp b/src/script/api/game_changelog.hpp index bbd1f876a0..655cfac0b6 100644 --- a/src/script/api/game_changelog.hpp +++ b/src/script/api/game_changelog.hpp @@ -20,6 +20,7 @@ * API additions: * \li GSEventVehicleCrashed::GetVictims * \li GSEventCompanyRenamed + * \li GSEventPresidentRenamed * * \b 14.0 * diff --git a/src/script/api/script_event.hpp b/src/script/api/script_event.hpp index 4758ac2e03..09fbb643eb 100644 --- a/src/script/api/script_event.hpp +++ b/src/script/api/script_event.hpp @@ -58,6 +58,7 @@ public: ET_STORYPAGE_TILE_SELECT, ET_STORYPAGE_VEHICLE_SELECT, ET_COMPANY_RENAMED, + ET_PRESIDENT_RENAMED, }; /** diff --git a/src/script/api/script_event_types.hpp b/src/script/api/script_event_types.hpp index c8403f5ec6..95e22cd003 100644 --- a/src/script/api/script_event_types.hpp +++ b/src/script/api/script_event_types.hpp @@ -1373,4 +1373,48 @@ private: VehicleID vehicle_id; }; + +/** + * Event President Renamed, indicating a company's president's name has changed. + * This event is not sent to the company for who the president's name changed. + * @api ai game + */ +class ScriptEventPresidentRenamed : public ScriptEvent { +public: +#ifndef DOXYGEN_API + /** + * @param company The company of the president. + * @param new_name The new name of the president. + */ + ScriptEventPresidentRenamed(CompanyID company, const std::string &new_name) : + ScriptEvent(ET_PRESIDENT_RENAMED), + company(static_cast(company)), + new_name(new_name) + {} +#endif /* DOXYGEN_API */ + + /** + * Convert an ScriptEvent to the real instance. + * @param instance The instance to convert. + * @return The converted instance. + */ + static ScriptEventPresidentRenamed *Convert(ScriptEvent *instance) { return static_cast(instance); } + + /** + * Get the CompanyID of the company that got its president renamed. + * @return The CompanyID of the company. + */ + ScriptCompany::CompanyID GetCompanyID() { return this->company; } + + /** + * Get the new name of the president. + * @return The new name of the president. + */ + std::optional GetNewName() { return this->new_name; } + +private: + ScriptCompany::CompanyID company; ///< The company of the renamed president. + std::string new_name; ///< The new name of the president. +}; + #endif /* SCRIPT_EVENT_TYPES_HPP */