From e5107141e915551b4bdc89aeae16ef5221947804 Mon Sep 17 00:00:00 2001 From: Ted John Date: Tue, 8 Sep 2020 00:08:07 +0100 Subject: [PATCH] Add plugin API for park flags --- distribution/openrct2.d.ts | 28 +++++++++++++++++++ src/openrct2/scripting/ScPark.hpp | 36 +++++++++++++++++++++++++ src/openrct2/scripting/ScriptEngine.cpp | 2 +- 3 files changed, 65 insertions(+), 1 deletion(-) diff --git a/distribution/openrct2.d.ts b/distribution/openrct2.d.ts index c37757a5f7..ad25517878 100644 --- a/distribution/openrct2.d.ts +++ b/distribution/openrct2.d.ts @@ -1424,6 +1424,21 @@ declare global { subject?: number; } + type ParkFlags = + "difficultGuestGeneration" | + "difficultParkRating" | + "forbidHighConstruction" | + "forbidLandscapeChanges" | + "forbidMarketingCampaigns" | + "forbidTreeRemoval" | + "freeParkEntry" | + "noMoney" | + "open" | + "preferLessIntenseRides" | + "preferMoreIntenseRides" | + "scenarioCompleteNameInput" | + "unlockAllPrices"; + interface Park { cash: number; rating: number; @@ -1438,6 +1453,19 @@ declare global { name: string; messages: ParkMessage[]; + /** + * Gets whether a given flag is set or not. + * @param key The flag to test. + */ + getFlag(flag: ParkFlags): boolean; + + /** + * Sets the given flag to the given value. + * @param key The flag to set. + * @param value Whether to set or clear the flag. + */ + setFlag(flag: ParkFlags, value: boolean): void; + postMessage(message: string): void; postMessage(message: ParkMessageDesc): void; } diff --git a/src/openrct2/scripting/ScPark.hpp b/src/openrct2/scripting/ScPark.hpp index 78e646c9b3..fd122e9b30 100644 --- a/src/openrct2/scripting/ScPark.hpp +++ b/src/openrct2/scripting/ScPark.hpp @@ -229,6 +229,23 @@ namespace OpenRCT2::Scripting } }; + static const DukEnumMap ParkFlagMap({ + { "open", PARK_FLAGS_PARK_OPEN }, + { "scenarioCompleteNameInput", PARK_FLAGS_SCENARIO_COMPLETE_NAME_INPUT }, + { "forbidLandscapeChanges", PARK_FLAGS_FORBID_LANDSCAPE_CHANGES }, + { "forbidTreeRemoval", PARK_FLAGS_FORBID_TREE_REMOVAL }, + { "forbidHighConstruction", PARK_FLAGS_FORBID_HIGH_CONSTRUCTION }, + { "preferLessIntenseRides", PARK_FLAGS_PREF_LESS_INTENSE_RIDES }, + { "forbidMarketingCampaigns", PARK_FLAGS_FORBID_MARKETING_CAMPAIGN }, + { "preferMoreIntenseRides", PARK_FLAGS_PREF_MORE_INTENSE_RIDES }, + { "noMoney", PARK_FLAGS_NO_MONEY }, + { "difficultGuestGeneration", PARK_FLAGS_DIFFICULT_GUEST_GENERATION }, + { "freeParkEntry", PARK_FLAGS_PARK_FREE_ENTRY }, + { "difficultParkRating", PARK_FLAGS_DIFFICULT_PARK_RATING }, + { "noMoney", PARK_FLAGS_NO_MONEY_SCENARIO }, + { "unlockAllPrices", PARK_FLAGS_UNLOCK_ALL_PRICES }, + }); + class ScPark { public: @@ -300,6 +317,23 @@ namespace OpenRCT2::Scripting GetContext()->GetGameState()->GetPark().Name = value; } + bool getFlag(const std::string& key) const + { + auto mask = ParkFlagMap[key]; + return (gParkFlags & mask) != 0; + } + + void setFlag(const std::string& key, bool value) + { + ThrowIfGameStateNotMutable(); + auto mask = ParkFlagMap[key]; + if (value) + gParkFlags |= mask; + else + gParkFlags &= ~mask; + gfx_invalidate_screen(); + } + std::vector> messages_get() const { std::vector> result; @@ -395,6 +429,8 @@ namespace OpenRCT2::Scripting dukglue_register_property(ctx, &ScPark::entranceFee_get, &ScPark::entranceFee_set, "entranceFee"); dukglue_register_property(ctx, &ScPark::name_get, &ScPark::name_set, "name"); dukglue_register_property(ctx, &ScPark::messages_get, &ScPark::messages_set, "messages"); + dukglue_register_method(ctx, &ScPark::getFlag, "getFlag"); + dukglue_register_method(ctx, &ScPark::setFlag, "setFlag"); dukglue_register_method(ctx, &ScPark::postMessage, "postMessage"); } }; diff --git a/src/openrct2/scripting/ScriptEngine.cpp b/src/openrct2/scripting/ScriptEngine.cpp index 89c0195c33..b7cd51a4d6 100644 --- a/src/openrct2/scripting/ScriptEngine.cpp +++ b/src/openrct2/scripting/ScriptEngine.cpp @@ -42,7 +42,7 @@ using namespace OpenRCT2; using namespace OpenRCT2::Scripting; -static constexpr int32_t OPENRCT2_PLUGIN_API_VERSION = 6; +static constexpr int32_t OPENRCT2_PLUGIN_API_VERSION = 7; struct ExpressionStringifier final {