From 328bbe50ec36aec991b7967ad2e2e97181d2c142 Mon Sep 17 00:00:00 2001 From: SamuXarick <43006711+SamuXarick@users.noreply.github.com> Date: Wed, 25 Jan 2023 15:30:17 +0000 Subject: [PATCH] Change: Allow GS access to ScriptEventEnginePreview --- src/engine.cpp | 5 ++--- src/script/api/game_changelog.hpp | 1 + src/script/api/script_event_types.cpp | 1 + src/script/api/script_event_types.hpp | 14 ++++++++++++-- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/engine.cpp b/src/engine.cpp index 0a571f987e..2aa3fb8c5d 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -20,8 +20,7 @@ #include "window_func.h" #include "autoreplace_gui.h" #include "string_func.h" -#include "ai/ai.hpp" -#include "game/game.hpp" +#include "script/script_trigger.hpp" #include "core/pool_func.hpp" #include "engine_gui.h" #include "engine_func.h" @@ -992,7 +991,7 @@ static IntervalTimer _calendar_engines_daily({TimerGameCalend * 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)) ScriptTrigger::NewEvent(e->preview_company, e->preview_company, i); if (IsInteractiveCompany(e->preview_company)) ShowEnginePreviewWindow(i); } } diff --git a/src/script/api/game_changelog.hpp b/src/script/api/game_changelog.hpp index 78650ab9fc..b92194af31 100644 --- a/src/script/api/game_changelog.hpp +++ b/src/script/api/game_changelog.hpp @@ -37,6 +37,7 @@ * \li GSEventAircraftDestTooFar * \li GSEventVehicleAutoReplaced * \li GSEventCompanyAskMerger + * \li GSEventEnginePreview * * Other changes: * \li GSBridge::GetBridgeID renamed to GSBridge::GetBridgeType diff --git a/src/script/api/script_event_types.cpp b/src/script/api/script_event_types.cpp index 24893bc1d6..d9a8726459 100644 --- a/src/script/api/script_event_types.cpp +++ b/src/script/api/script_event_types.cpp @@ -106,6 +106,7 @@ int32_t ScriptEventEnginePreview::GetVehicleType() bool ScriptEventEnginePreview::AcceptPreview() { EnforceCompanyModeValid(false); + EnforcePrecondition(false, ScriptObject::GetCompany() == ScriptCompany::FromScriptCompanyID(this->owner)); if (!this->IsEngineValid()) return false; return ScriptObject::Command::Do(this->engine); } diff --git a/src/script/api/script_event_types.hpp b/src/script/api/script_event_types.hpp index f44dd74fe0..e821b3d3bd 100644 --- a/src/script/api/script_event_types.hpp +++ b/src/script/api/script_event_types.hpp @@ -238,16 +238,18 @@ private: * 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::ToScriptCompanyID(owner)), engine(engine) {} #endif /* DOXYGEN_API */ @@ -259,6 +261,13 @@ public: */ 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. @@ -319,6 +328,7 @@ public: bool AcceptPreview(); private: + ScriptCompany::CompanyID owner; ///< The company the engine preview is for. EngineID engine; ///< The engine the preview is for. /**