mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-01-18 05:01:13 +00:00
Add: [Script] ScriptEventCompanyRename (#12878)
This commit is contained in:
parent
3a7cfafe51
commit
9ab936f76b
@ -2035,6 +2035,13 @@ function Regression::Start()
|
||||
print(" VehicleID: " + c.GetVehicleID());
|
||||
} break;
|
||||
|
||||
case AIEvent.ET_COMPANY_RENAMED: {
|
||||
local c = AIEventCompanyRenamed.Convert(e);
|
||||
print(" EventName: CompanyRenamed");
|
||||
print(" CompanyID: " + c.GetCompanyID());
|
||||
print(" CompanyName: " + c.GetNewName());
|
||||
} break;
|
||||
|
||||
default:
|
||||
print(" Unknown Event");
|
||||
break;
|
||||
|
@ -9711,6 +9711,16 @@ ERROR: IsEnd() is invalid as Begin() is never called
|
||||
GetDestinationType(): 1
|
||||
GetDestinationIndex(): 7
|
||||
GetCargoType(): 0
|
||||
GetNextEvent: instance
|
||||
GetEventType: 33
|
||||
EventName: CompanyRenamed
|
||||
CompanyID: 1
|
||||
CompanyName: Regression
|
||||
GetNextEvent: instance
|
||||
GetEventType: 33
|
||||
EventName: CompanyRenamed
|
||||
CompanyID: 1
|
||||
CompanyName: Little Frutford Transport
|
||||
IsEventWaiting: false
|
||||
|
||||
--Math--
|
||||
@ -9748,9 +9758,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 [2051]
|
||||
*FUNCTION [unknown()] regression/main.nut line [2058]
|
||||
*FUNCTION [Valuate()] NATIVE line [-1]
|
||||
*FUNCTION [Start()] regression/main.nut line [2052]
|
||||
*FUNCTION [Start()] regression/main.nut line [2059]
|
||||
|
||||
[id] 0
|
||||
[this] TABLE
|
||||
@ -9759,7 +9769,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 [2052]
|
||||
*FUNCTION [Start()] regression/main.nut line [2059]
|
||||
|
||||
[Infinite] CLOSURE
|
||||
[list] INSTANCE
|
||||
|
@ -424,6 +424,8 @@ set_name:;
|
||||
c->name_2 = strp;
|
||||
|
||||
MarkWholeScreenDirty();
|
||||
AI::BroadcastNewEvent(new ScriptEventCompanyRenamed(c->index, name));
|
||||
Game::NewEvent(new ScriptEventCompanyRenamed(c->index, name));
|
||||
|
||||
if (c->is_ai) {
|
||||
auto cni = std::make_unique<CompanyNewsInformation>(c);
|
||||
@ -1184,6 +1186,11 @@ CommandCost CmdRenameCompany(DoCommandFlag flags, const std::string &text)
|
||||
}
|
||||
MarkWholeScreenDirty();
|
||||
CompanyAdminUpdate(c);
|
||||
|
||||
SetDParam(0, c->index);
|
||||
std::string new_name = GetString(STR_COMPANY_NAME);
|
||||
AI::BroadcastNewEvent(new ScriptEventCompanyRenamed(c->index, new_name));
|
||||
Game::NewEvent(new ScriptEventCompanyRenamed(c->index, new_name));
|
||||
}
|
||||
|
||||
return CommandCost();
|
||||
|
@ -19,6 +19,7 @@
|
||||
*
|
||||
* API additions:
|
||||
* \li AIEventVehicleCrashed::GetVictims
|
||||
* \li AIEventCompanyRenamed
|
||||
*
|
||||
* \b 14.0
|
||||
*
|
||||
|
@ -19,6 +19,7 @@
|
||||
*
|
||||
* API additions:
|
||||
* \li GSEventVehicleCrashed::GetVictims
|
||||
* \li GSEventCompanyRenamed
|
||||
*
|
||||
* \b 14.0
|
||||
*
|
||||
|
@ -57,6 +57,7 @@ public:
|
||||
ET_STORYPAGE_BUTTON_CLICK,
|
||||
ET_STORYPAGE_TILE_SELECT,
|
||||
ET_STORYPAGE_VEHICLE_SELECT,
|
||||
ET_COMPANY_RENAMED,
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -346,6 +346,48 @@ private:
|
||||
ScriptCompany::CompanyID owner; ///< The new company.
|
||||
};
|
||||
|
||||
/**
|
||||
* Event Company Renamed, indicating a company has changed name.
|
||||
* @api ai game
|
||||
*/
|
||||
class ScriptEventCompanyRenamed : public ScriptEvent {
|
||||
public:
|
||||
#ifndef DOXYGEN_API
|
||||
/**
|
||||
* @param owner The company that is renamed.
|
||||
*/
|
||||
ScriptEventCompanyRenamed(CompanyID company, const std::string &new_name) :
|
||||
ScriptEvent(ET_COMPANY_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 ScriptEventCompanyRenamed *Convert(ScriptEvent *instance) { return static_cast<ScriptEventCompanyRenamed *>(instance); }
|
||||
|
||||
/**
|
||||
* Get the CompanyID of the company that has been renamed.
|
||||
* @return The CompanyID of the company.
|
||||
*/
|
||||
ScriptCompany::CompanyID GetCompanyID() { return this->company; }
|
||||
|
||||
/**
|
||||
* Get the new name of the company.
|
||||
* @return The new name of the company.
|
||||
*/
|
||||
std::optional<std::string> GetNewName() { return this->new_name; }
|
||||
|
||||
private:
|
||||
|
||||
ScriptCompany::CompanyID company; ///< The company that was renamed.
|
||||
std::string new_name; ///< The new name of the company.
|
||||
};
|
||||
|
||||
/**
|
||||
* Event Company In Trouble, indicating a company is in trouble and might go
|
||||
* bankrupt soon.
|
||||
|
Loading…
Reference in New Issue
Block a user