Skip to content

Commit

Permalink
Change: Allow GS access to ScriptEventEnginePreview
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuXarick committed Feb 2, 2023
1 parent 02afb5e commit 1fc32fd
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/engine.cpp
Expand Up @@ -911,7 +911,10 @@ void EnginesDailyLoop()
* boost that they wouldn't have gotten against other human companies. The check on
* the line below is just to make AIs not notice that they have a preview if they
* cannot build the vehicle. */
if (!IsVehicleTypeDisabled(e->type, true)) AI::NewEvent(e->preview_company, new ScriptEventEnginePreview(i));
if (!IsVehicleTypeDisabled(e->type, true)) {
AI::NewEvent(e->preview_company, new ScriptEventEnginePreview(e->preview_company, i));
Game::NewEvent(new ScriptEventEnginePreview(e->preview_company, i));
}
if (IsInteractiveCompany(e->preview_company)) ShowEnginePreviewWindow(i);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/script/api/game_changelog.hpp
Expand Up @@ -72,6 +72,7 @@
* \li GSGroupList
* \li GSVehicleList_Group
* \li GSVehicleList_DefaultGroup
* \li GSEventEnginePreview
* \li GSEventCompanyAskMerger
* \li GSEventVehicleLost
* \li GSEventVehicleWaitingInDepot
Expand Down
1 change: 1 addition & 0 deletions src/script/api/script_event_types.cpp
Expand Up @@ -111,6 +111,7 @@ int32 ScriptEventEnginePreview::GetVehicleType()

bool ScriptEventEnginePreview::AcceptPreview()
{
EnforcePrecondition(false, ScriptObject::GetCompany() == (::CompanyID)this->owner);
if (!this->IsEngineValid()) return false;
return ScriptObject::Command<CMD_WANT_ENGINE_PREVIEW>::Do(this->engine);
}
Expand Down
17 changes: 14 additions & 3 deletions src/script/api/script_event_types.hpp
Expand Up @@ -214,16 +214,18 @@ class ScriptEventSubsidyExpired : public ScriptEvent {
* Event Engine Preview, indicating a manufacturer offer you to test a new engine.
* You can get the same information about the offered engine as a real user
* would see in the offer window. And you can also accept the offer.
* @api ai
* @api ai game
*/
class ScriptEventEnginePreview : public ScriptEvent {
public:
#ifndef DOXYGEN_API
/**
* @param owner The company being offered the test engine.
* @param engine The engine offered to test.
*/
ScriptEventEnginePreview(EngineID engine) :
ScriptEventEnginePreview(Owner owner, EngineID engine) :
ScriptEvent(ET_ENGINE_PREVIEW),
owner((ScriptCompany::CompanyID)owner),
engine(engine)
{}
#endif /* DOXYGEN_API */
Expand All @@ -235,6 +237,13 @@ class ScriptEventEnginePreview : public ScriptEvent {
*/
static ScriptEventEnginePreview *Convert(ScriptEvent *instance) { return (ScriptEventEnginePreview *)instance; }

/**
* Get the company being offered the test engine.
* @return The company being offered to test the engine.
* @api -ai
*/
ScriptCompany::CompanyID GetCompanyID() { return this->owner; }

/**
* Get the name of the offered engine.
* @return The name the engine has.
Expand Down Expand Up @@ -290,11 +299,13 @@ class ScriptEventEnginePreview : public ScriptEvent {
/**
* Accept the engine preview.
* @return True when the accepting succeeded.
* @game @pre Valid ScriptCompanyMode active in scope.
*/
bool AcceptPreview();

private:
EngineID engine; ///< The engine the preview is for.
ScriptCompany::CompanyID owner; ///< The company the engine preview is for.
EngineID engine; ///< The engine the preview is for.

/**
* Check whether the engine from this preview is still valid.
Expand Down

0 comments on commit 1fc32fd

Please sign in to comment.