From 06bbf5ddda00420696f7d8eb2f42393e52deb207 Mon Sep 17 00:00:00 2001 From: Ted John Date: Mon, 27 Apr 2020 17:41:49 +0100 Subject: [PATCH] Implement SmallSceneryObject for getObject plugin API (#11489) --- distribution/openrct2.d.ts | 34 +++++++++-- src/openrct2/scripting/ScContext.hpp | 2 + src/openrct2/scripting/ScObject.hpp | 76 +++++++++++++++++++++++++ src/openrct2/scripting/ScriptEngine.cpp | 1 + 4 files changed, 109 insertions(+), 4 deletions(-) diff --git a/distribution/openrct2.d.ts b/distribution/openrct2.d.ts index d1c737e9f7..a3a9b858b2 100644 --- a/distribution/openrct2.d.ts +++ b/distribution/openrct2.d.ts @@ -119,6 +119,7 @@ declare global { */ getObject(type: ObjectType, index: number): Object; getObject(type: "ride", index: number): RideObject; + getObject(type: "small_scenery", index: number): SmallSceneryObject; getAllObjects(type: ObjectType): Object[]; getAllObjects(type: "ride"): RideObject[]; @@ -450,6 +451,31 @@ declare global { readonly capacity: string; } + /** + * Represents the object definition of a small scenery item such a tree. + */ + interface SmallSceneryObject extends Object { + /** + * Raw bit flags that describe characteristics of the scenery item. + */ + readonly flags: number; + + /** + * The default clearance height of the scenery item. + */ + readonly height: number; + + /** + * How much the scenery item costs to build. + */ + readonly price: number; + + /** + * How much the scenery item costs to remove. + */ + readonly removalPrice: number; + } + /** * Represents a ride or stall within the park. */ @@ -607,10 +633,10 @@ declare global { * Park APIs */ - /** - * The type of park message, including icon and behaviour. - */ - type ParkMessageType = + /** + * The type of park message, including icon and behaviour. + */ + type ParkMessageType = "attraction" | "peep_on_attraction" | "peep" | "money" | "blank" | "research" | "guests" | "award" | "chart"; interface ParkMessage { diff --git a/src/openrct2/scripting/ScContext.hpp b/src/openrct2/scripting/ScContext.hpp index 0b9994621b..928c37490d 100644 --- a/src/openrct2/scripting/ScContext.hpp +++ b/src/openrct2/scripting/ScContext.hpp @@ -59,6 +59,8 @@ namespace OpenRCT2::Scripting { case OBJECT_TYPE_RIDE: return GetObjectAsDukValue(ctx, std::make_shared(type, index)); + case OBJECT_TYPE_SMALL_SCENERY: + return GetObjectAsDukValue(ctx, std::make_shared(type, index)); default: return GetObjectAsDukValue(ctx, std::make_shared(type, index)); } diff --git a/src/openrct2/scripting/ScObject.hpp b/src/openrct2/scripting/ScObject.hpp index 38cc49b2c5..7eeb4bf0c5 100644 --- a/src/openrct2/scripting/ScObject.hpp +++ b/src/openrct2/scripting/ScObject.hpp @@ -15,6 +15,7 @@ # include "../common.h" # include "../object/ObjectManager.h" # include "../object/RideObject.h" +# include "../object/SmallSceneryObject.h" # include "Duktape.hpp" # include "ScriptEngine.h" @@ -147,6 +148,81 @@ namespace OpenRCT2::Scripting return static_cast(ScObject::GetObject()); } }; + + class ScSmallSceneryObject : public ScObject + { + public: + ScSmallSceneryObject(uint8_t type, int32_t index) + : ScObject(type, index) + { + } + + static void Register(duk_context* ctx) + { + dukglue_set_base_class(ctx); + dukglue_register_property(ctx, &ScSmallSceneryObject::flags_get, nullptr, "flags"); + dukglue_register_property(ctx, &ScSmallSceneryObject::height_get, nullptr, "height"); + dukglue_register_property(ctx, &ScSmallSceneryObject::price_get, nullptr, "price"); + dukglue_register_property(ctx, &ScSmallSceneryObject::removalPrice_get, nullptr, "removalPrice"); + } + + private: + uint32_t flags_get() const + { + auto sceneryEntry = GetLegacyData(); + if (sceneryEntry != nullptr) + { + return sceneryEntry->small_scenery.flags; + } + return 0; + } + + uint8_t height_get() const + { + auto sceneryEntry = GetLegacyData(); + if (sceneryEntry != nullptr) + { + return sceneryEntry->small_scenery.height; + } + return 0; + } + + uint8_t price_get() const + { + auto sceneryEntry = GetLegacyData(); + if (sceneryEntry != nullptr) + { + return sceneryEntry->small_scenery.price; + } + return 0; + } + + uint8_t removalPrice_get() const + { + auto sceneryEntry = GetLegacyData(); + if (sceneryEntry != nullptr) + { + return sceneryEntry->small_scenery.removal_price; + } + return 0; + } + + protected: + rct_scenery_entry* GetLegacyData() const + { + auto obj = GetObject(); + if (obj != nullptr) + { + return static_cast(obj->GetLegacyData()); + } + return nullptr; + } + + SmallSceneryObject* GetObject() const + { + return static_cast(ScObject::GetObject()); + } + }; } // namespace OpenRCT2::Scripting #endif diff --git a/src/openrct2/scripting/ScriptEngine.cpp b/src/openrct2/scripting/ScriptEngine.cpp index 889db5a430..8b67b46b98 100644 --- a/src/openrct2/scripting/ScriptEngine.cpp +++ b/src/openrct2/scripting/ScriptEngine.cpp @@ -375,6 +375,7 @@ void ScriptEngine::Initialise() ScMap::Register(ctx); ScNetwork::Register(ctx); ScObject::Register(ctx); + ScSmallSceneryObject::Register(ctx); ScPark::Register(ctx); ScPlayer::Register(ctx); ScPlayerGroup::Register(ctx);