mirror of https://github.com/OpenTTD/OpenTTD
Change: Allow GS access to ScriptEventEnginePreview
parent
62ee9029a1
commit
328bbe50ec
|
@ -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<TimerGameCalendar> _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<ScriptEventEnginePreview>(e->preview_company, e->preview_company, i);
|
||||
if (IsInteractiveCompany(e->preview_company)) ShowEnginePreviewWindow(i);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
* \li GSEventAircraftDestTooFar
|
||||
* \li GSEventVehicleAutoReplaced
|
||||
* \li GSEventCompanyAskMerger
|
||||
* \li GSEventEnginePreview
|
||||
*
|
||||
* Other changes:
|
||||
* \li GSBridge::GetBridgeID renamed to GSBridge::GetBridgeType
|
||||
|
|
|
@ -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<CMD_WANT_ENGINE_PREVIEW>::Do(this->engine);
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue