mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-01-18 05:01:13 +00:00
Add: [Script] Event for when a company's president name changes
This commit is contained in:
parent
9ab936f76b
commit
29129e12fd
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
|
@ -20,6 +20,7 @@
|
||||
* API additions:
|
||||
* \li AIEventVehicleCrashed::GetVictims
|
||||
* \li AIEventCompanyRenamed
|
||||
* \li AIEventPresidentRenamed
|
||||
*
|
||||
* \b 14.0
|
||||
*
|
||||
|
@ -20,6 +20,7 @@
|
||||
* API additions:
|
||||
* \li GSEventVehicleCrashed::GetVictims
|
||||
* \li GSEventCompanyRenamed
|
||||
* \li GSEventPresidentRenamed
|
||||
*
|
||||
* \b 14.0
|
||||
*
|
||||
|
@ -58,6 +58,7 @@ public:
|
||||
ET_STORYPAGE_TILE_SELECT,
|
||||
ET_STORYPAGE_VEHICLE_SELECT,
|
||||
ET_COMPANY_RENAMED,
|
||||
ET_PRESIDENT_RENAMED,
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -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<ScriptCompany::CompanyID>(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<ScriptEventPresidentRenamed *>(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<std::string> 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 */
|
||||
|
Loading…
Reference in New Issue
Block a user