Add plugin API for park flags

This commit is contained in:
Ted John 2020-09-08 00:08:07 +01:00
parent cf5b48a9dd
commit e5107141e9
3 changed files with 65 additions and 1 deletions

View file

@ -1424,6 +1424,21 @@ declare global {
subject?: number; subject?: number;
} }
type ParkFlags =
"difficultGuestGeneration" |
"difficultParkRating" |
"forbidHighConstruction" |
"forbidLandscapeChanges" |
"forbidMarketingCampaigns" |
"forbidTreeRemoval" |
"freeParkEntry" |
"noMoney" |
"open" |
"preferLessIntenseRides" |
"preferMoreIntenseRides" |
"scenarioCompleteNameInput" |
"unlockAllPrices";
interface Park { interface Park {
cash: number; cash: number;
rating: number; rating: number;
@ -1438,6 +1453,19 @@ declare global {
name: string; name: string;
messages: ParkMessage[]; 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: string): void;
postMessage(message: ParkMessageDesc): void; postMessage(message: ParkMessageDesc): void;
} }

View file

@ -229,6 +229,23 @@ namespace OpenRCT2::Scripting
} }
}; };
static const DukEnumMap<uint32_t> 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 class ScPark
{ {
public: public:
@ -300,6 +317,23 @@ namespace OpenRCT2::Scripting
GetContext()->GetGameState()->GetPark().Name = value; 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<std::shared_ptr<ScParkMessage>> messages_get() const std::vector<std::shared_ptr<ScParkMessage>> messages_get() const
{ {
std::vector<std::shared_ptr<ScParkMessage>> result; std::vector<std::shared_ptr<ScParkMessage>> result;
@ -395,6 +429,8 @@ namespace OpenRCT2::Scripting
dukglue_register_property(ctx, &ScPark::entranceFee_get, &ScPark::entranceFee_set, "entranceFee"); 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::name_get, &ScPark::name_set, "name");
dukglue_register_property(ctx, &ScPark::messages_get, &ScPark::messages_set, "messages"); 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"); dukglue_register_method(ctx, &ScPark::postMessage, "postMessage");
} }
}; };

View file

@ -42,7 +42,7 @@
using namespace OpenRCT2; using namespace OpenRCT2;
using namespace OpenRCT2::Scripting; 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 struct ExpressionStringifier final
{ {