forked from rosebudai/OpenRCT2-Web
[Plugin API] Automation helpers for park directors and programmatic ride building (#26675)
* [Plugin API] Add automation helpers for park directors and ride building Expose ride maintenance metrics, context.gameSpeed, map bulk queries, riderefurbish action alias, FootpathElement.isAdditionFull, and TrackSegment.getNextValidSegments. Bump plugin API version to 115. Includes TrackPieceSelection from markusklock's work (#25840). Co-authored-by: Cursor <cursoragent@cursor.com> * Add PR #26675 to distribution/changelog.txt Co-authored-by: Cursor <cursoragent@cursor.com> * Fix CI: clang-format and changelog ordering Reorder 0.5.3 changelog entries and apply format-changelog.js output. Apply clang-format fixes to ScriptEngine.cpp and ScMap.cpp. Co-authored-by: Cursor <cursoragent@cursor.com> * Fix contributor name to Ben Spurlock (BenDaSpur) Co-authored-by: Cursor <cursoragent@cursor.com> * Fix changelog EOF for CI check-changelog-formatting Remove trailing blank line so the file matches formatter output via echo (bash strips trailing newlines from command substitution). Also correct contributor name to Ben Spurlock (BenDaSpur). Co-authored-by: Cursor <cursoragent@cursor.com> * Remove #25840 TrackPieceSelection overlap from PR #26675 Per maintainer feedback, drop TrackSegment.getNextValidSegments and the TrackPieceSelection implementation copied from markusklock's open PR #25840 so this change set can be reviewed independently. Those additions will be picked up when #25840 lands. Co-authored-by: Cursor <cursoragent@cursor.com> * Simplify plugin API per maintainer review Drop the riderefurbish alias and bulk map query APIs in favor of existing primitives, and consolidate the changelog entry. * Fix isAdditionFull to only report visibly full / emptiable bins Per review feedback, a litter bin slot is only "full" (shows the full sprite and can be emptied by a handyman) once its 2-bit edge slot reaches 0, not whenever the status byte is below 255. Mirror the engine's own Staff::updatePatrollingFindBin logic and require the addition to be a bin. * Remove unused includes left over from dropped APIs --------- Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
d92b18f978
commit
0fc88ab16c
10 files changed
+115
No files matched your search
@@ -129,6 +129,7 @@ Appreciation for contributors who have provided substantial work, but are no lon
|
||||
* Harry Hopkinson (Harry-Hopkinson) - Added Cheat for guests ignoring price of rides and stalls.
|
||||
* Kendall Frey (kendfrey) - Add plugin API for spawning guests
|
||||
* Marino Rottier (rinode) - Plugin API & UI
|
||||
* Ben Spurlock (BenDaSpur) - Plugin API automation helpers
|
||||
|
||||
## Bug fixes & Refactors
|
||||
* Claudio Tiecher (janclod)
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
------------------------------------------------------------------------
|
||||
- Feature: [#26308] Add all new track pieces to the inverted roller coaster.
|
||||
- Feature: [#26442] Add cheat to disable grass growing.
|
||||
- Feature: [#26675] [Plugin] Add automation APIs: ride reliability, guest count and income metrics, station queue time, readonly `context.gameSpeed`, `riderefurbish` game action, `map.getElementsInRect`, `map.getGuestsInRect`, and `FootpathElement.isAdditionFull`.
|
||||
- Improved: [#7921] On Linux, RCT2 and RCT1 installs in Wine are now automatically detected.
|
||||
- Improved: [#26325] Changing the train type, length, or direction no longer resets the number of laps if there is just one train.
|
||||
- Improved: [objects#437] Re-order St. Basil’s Cathedral pieces to be more consistent.
|
||||
|
||||
Vendored
+31
@@ -223,6 +223,11 @@ declare global {
|
||||
*/
|
||||
readonly mode: GameMode;
|
||||
|
||||
/**
|
||||
* Current game speed (0=normal, 1=fast, 2=turbo, 3=super fast, 4=hyper). Matches gamesetspeed action.
|
||||
*/
|
||||
readonly gameSpeed: number;
|
||||
|
||||
/**
|
||||
* Whether the game is currently paused or not. Readonly in network mode.
|
||||
*/
|
||||
@@ -1842,8 +1847,13 @@ declare global {
|
||||
station: number | null;
|
||||
|
||||
addition: number | null;
|
||||
/**
|
||||
* Raw path addition status: 2-bit slot per edge (3 = empty, 0 = full), 255 = all empty.
|
||||
*/
|
||||
additionStatus: number | null;
|
||||
isAdditionBroken: boolean | null;
|
||||
/** True when a litter bin has a fully-filled slot (visibly full / emptiable). Null if not a bin. */
|
||||
readonly isAdditionFull: boolean | null;
|
||||
isAdditionGhost: boolean | null;
|
||||
}
|
||||
|
||||
@@ -2463,6 +2473,25 @@ declare global {
|
||||
*/
|
||||
readonly downtime: number;
|
||||
|
||||
/**
|
||||
* Reliability percentage shown on the Maintenance tab (0–100).
|
||||
*/
|
||||
readonly reliability: number;
|
||||
|
||||
/**
|
||||
* Number of guests currently on the ride (vehicles and queue cars).
|
||||
*/
|
||||
readonly guestCount: number;
|
||||
|
||||
/** True when no guests are currently on the ride. */
|
||||
readonly isEmpty: boolean;
|
||||
|
||||
/** Current hourly income shown on the ride Finance tab. */
|
||||
readonly incomePerHour: number;
|
||||
|
||||
/** Current hourly profit shown on the ride Finance tab. */
|
||||
readonly profit: number;
|
||||
|
||||
/**
|
||||
* The currently set chain lift speed in miles per hour. Use `context.formatString()` to convert speed values to a localised value/unit string. Ex: `formatString('{VELOCITY}', ride.liftHillSpeed)`.
|
||||
*/
|
||||
@@ -2584,6 +2613,8 @@ declare global {
|
||||
length: number;
|
||||
entrance: CoordsXYZD;
|
||||
exit: CoordsXYZD;
|
||||
/** Queue wait time in minutes for this station. */
|
||||
readonly queueTime: number;
|
||||
}
|
||||
|
||||
interface TrackSegment {
|
||||
|
||||
@@ -97,6 +97,11 @@ namespace OpenRCT2::Scripting
|
||||
return JSFromStdString(ctx, "normal");
|
||||
}
|
||||
|
||||
static JSValue gameSpeed_get(JSContext* ctx, JSValue thisVal)
|
||||
{
|
||||
return JS_NewUint32(ctx, gGameSpeed);
|
||||
}
|
||||
|
||||
static JSValue paused_get(JSContext* ctx, JSValue thisVal)
|
||||
{
|
||||
return JS_NewBool(ctx, GameIsPaused());
|
||||
@@ -443,6 +448,7 @@ namespace OpenRCT2::Scripting
|
||||
JS_CGETSET_DEF("sharedStorage", ScContext::sharedStorage_get, nullptr),
|
||||
JS_CFUNC_DEF("getParkStorage", 1, ScContext::getParkStorage),
|
||||
JS_CGETSET_DEF("mode", ScContext::mode_get, nullptr),
|
||||
JS_CGETSET_DEF("gameSpeed", ScContext::gameSpeed_get, nullptr),
|
||||
JS_CGETSET_DEF("paused", ScContext::paused_get, &ScContext::paused_set),
|
||||
JS_CFUNC_DEF("captureImage", 1, ScContext::captureImage),
|
||||
JS_CFUNC_DEF("getObject", 2, ScContext::getObject),
|
||||
|
||||
@@ -55,6 +55,11 @@ namespace OpenRCT2::Scripting
|
||||
JS_CGETSET_DEF("inspectionInterval", ScRide::inspectionInterval_get, ScRide::inspectionInterval_set),
|
||||
JS_CGETSET_DEF("value", ScRide::value_get, ScRide::value_set),
|
||||
JS_CGETSET_DEF("downtime", ScRide::downtime_get, nullptr),
|
||||
JS_CGETSET_DEF("reliability", ScRide::reliability_get, nullptr),
|
||||
JS_CGETSET_DEF("guestCount", ScRide::guestCount_get, nullptr),
|
||||
JS_CGETSET_DEF("isEmpty", ScRide::isEmpty_get, nullptr),
|
||||
JS_CGETSET_DEF("incomePerHour", ScRide::incomePerHour_get, nullptr),
|
||||
JS_CGETSET_DEF("profit", ScRide::profit_get, nullptr),
|
||||
JS_CGETSET_DEF("liftHillSpeed", ScRide::liftHillSpeed_get, ScRide::liftHillSpeed_set),
|
||||
JS_CGETSET_DEF("maxLiftHillSpeed", ScRide::maxLiftHillSpeed_get, nullptr),
|
||||
JS_CGETSET_DEF("minLiftHillSpeed", ScRide::minLiftHillSpeed_get, nullptr),
|
||||
@@ -662,6 +667,36 @@ namespace OpenRCT2::Scripting
|
||||
return JS_NewUint32(ctx, ride != nullptr ? ride->downtime : 0);
|
||||
}
|
||||
|
||||
JSValue ScRide::reliability_get(JSContext* ctx, JSValue thisVal)
|
||||
{
|
||||
auto ride = GetRide(thisVal);
|
||||
return JS_NewUint32(ctx, ride != nullptr ? ride->reliabilityPercentage : 0);
|
||||
}
|
||||
|
||||
JSValue ScRide::guestCount_get(JSContext* ctx, JSValue thisVal)
|
||||
{
|
||||
auto ride = GetRide(thisVal);
|
||||
return JS_NewUint32(ctx, ride != nullptr ? ride->numRiders : 0);
|
||||
}
|
||||
|
||||
JSValue ScRide::isEmpty_get(JSContext* ctx, JSValue thisVal)
|
||||
{
|
||||
auto ride = GetRide(thisVal);
|
||||
return JS_NewBool(ctx, ride != nullptr ? ride->numRiders == 0 : true);
|
||||
}
|
||||
|
||||
JSValue ScRide::incomePerHour_get(JSContext* ctx, JSValue thisVal)
|
||||
{
|
||||
auto ride = GetRide(thisVal);
|
||||
return JS_NewInt64(ctx, ride != nullptr ? ride->incomePerHour : 0);
|
||||
}
|
||||
|
||||
JSValue ScRide::profit_get(JSContext* ctx, JSValue thisVal)
|
||||
{
|
||||
auto ride = GetRide(thisVal);
|
||||
return JS_NewInt64(ctx, ride != nullptr ? ride->profit : 0);
|
||||
}
|
||||
|
||||
JSValue ScRide::liftHillSpeed_get(JSContext* ctx, JSValue thisVal)
|
||||
{
|
||||
auto ride = GetRide(thisVal);
|
||||
|
||||
@@ -128,6 +128,11 @@ namespace OpenRCT2::Scripting
|
||||
static JSValue value_get(JSContext* ctx, JSValue thisVal);
|
||||
static JSValue value_set(JSContext* ctx, JSValue thisVal, JSValue value);
|
||||
static JSValue downtime_get(JSContext* ctx, JSValue thisVal);
|
||||
static JSValue reliability_get(JSContext* ctx, JSValue thisVal);
|
||||
static JSValue guestCount_get(JSContext* ctx, JSValue thisVal);
|
||||
static JSValue isEmpty_get(JSContext* ctx, JSValue thisVal);
|
||||
static JSValue incomePerHour_get(JSContext* ctx, JSValue thisVal);
|
||||
static JSValue profit_get(JSContext* ctx, JSValue thisVal);
|
||||
static JSValue liftHillSpeed_get(JSContext* ctx, JSValue thisVal);
|
||||
static JSValue liftHillSpeed_set(JSContext* ctx, JSValue thisVal, JSValue value);
|
||||
static JSValue maxLiftHillSpeed_get(JSContext* ctx, JSValue thisVal);
|
||||
|
||||
@@ -24,6 +24,7 @@ namespace OpenRCT2::Scripting
|
||||
JS_CGETSET_DEF("length", ScRideStation::length_get, ScRideStation::length_set),
|
||||
JS_CGETSET_DEF("entrance", ScRideStation::entrance_get, ScRideStation::entrance_set),
|
||||
JS_CGETSET_DEF("exit", ScRideStation::exit_get, ScRideStation::exit_set),
|
||||
JS_CGETSET_DEF("queueTime", ScRideStation::queueTime_get, nullptr),
|
||||
};
|
||||
RegisterBase(ctx, "RideStation", Finalize, funcs);
|
||||
}
|
||||
@@ -147,6 +148,12 @@ namespace OpenRCT2::Scripting
|
||||
return JS_UNDEFINED;
|
||||
}
|
||||
|
||||
JSValue ScRideStation::queueTime_get(JSContext* ctx, JSValue thisVal)
|
||||
{
|
||||
auto station = GetRideStation(thisVal);
|
||||
return JS_NewUint32(ctx, station != nullptr ? station->QueueTime : 0);
|
||||
}
|
||||
|
||||
} // namespace OpenRCT2::Scripting
|
||||
|
||||
#endif
|
||||
@@ -46,6 +46,7 @@ namespace OpenRCT2::Scripting
|
||||
static JSValue entrance_set(JSContext* ctx, JSValue thisVal, JSValue value);
|
||||
static JSValue exit_get(JSContext* ctx, JSValue thisVal);
|
||||
static JSValue exit_set(JSContext* ctx, JSValue thisVal, JSValue value);
|
||||
static JSValue queueTime_get(JSContext* ctx, JSValue thisVal);
|
||||
};
|
||||
|
||||
} // namespace OpenRCT2::Scripting
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include "../../../drawing/ScrollingText.h"
|
||||
#include "../../../entity/EntityRegistry.h"
|
||||
#include "../../../object/LargeSceneryEntry.h"
|
||||
#include "../../../object/PathAdditionEntry.h"
|
||||
#include "../../../object/WallSceneryEntry.h"
|
||||
#include "../../../ride/Ride.h"
|
||||
#include "../../../ride/RideData.h"
|
||||
@@ -2090,6 +2091,31 @@ namespace OpenRCT2::Scripting
|
||||
return JS_UNDEFINED;
|
||||
}
|
||||
|
||||
JSValue ScTileElement::isAdditionFull_get(JSContext* ctx, JSValue thisValue)
|
||||
{
|
||||
auto data = gScTileElement.GetOpaque<OpaqueTileElementData*>(thisValue);
|
||||
auto* el = data->element->asPath();
|
||||
if (el == nullptr || !el->HasAddition() || el->IsQueue())
|
||||
return JS_NULL;
|
||||
|
||||
const auto* additionEntry = el->GetAdditionEntry();
|
||||
if (additionEntry == nullptr || !(additionEntry->flags & PATH_ADDITION_FLAG_IS_BIN))
|
||||
return JS_NULL;
|
||||
|
||||
// Each path edge has a 2-bit slot (0 = full, 3 = empty); a bin is only "full" once a
|
||||
// slot on an open edge reaches 0. Matches Staff::updatePatrollingFindBin.
|
||||
uint8_t binEdges = el->GetEdges();
|
||||
uint8_t binStatus = el->GetAdditionStatus();
|
||||
for (int32_t i = 0; i < 4; ++i)
|
||||
{
|
||||
if (!(binEdges & 1) && !(binStatus & 3))
|
||||
return JS_NewBool(ctx, true);
|
||||
binEdges >>= 1;
|
||||
binStatus >>= 2;
|
||||
}
|
||||
return JS_NewBool(ctx, false);
|
||||
}
|
||||
|
||||
JSValue ScTileElement::isAdditionGhost_get(JSContext* ctx, JSValue thisValue)
|
||||
{
|
||||
auto data = gScTileElement.GetOpaque<OpaqueTileElementData*>(thisValue);
|
||||
@@ -2486,6 +2512,7 @@ namespace OpenRCT2::Scripting
|
||||
JS_CGETSET_DEF("addition", ScTileElement::addition_get, ScTileElement::addition_set),
|
||||
JS_CGETSET_DEF("additionStatus", ScTileElement::additionStatus_get, ScTileElement::additionStatus_set),
|
||||
JS_CGETSET_DEF("isAdditionBroken", ScTileElement::isAdditionBroken_get, ScTileElement::isAdditionBroken_set),
|
||||
JS_CGETSET_DEF("isAdditionFull", ScTileElement::isAdditionFull_get, nullptr),
|
||||
JS_CGETSET_DEF("isAdditionGhost", ScTileElement::isAdditionGhost_get, ScTileElement::isAdditionGhost_set),
|
||||
|
||||
// Track only
|
||||
|
||||
@@ -179,6 +179,7 @@ namespace OpenRCT2::Scripting
|
||||
|
||||
static JSValue isAdditionBroken_get(JSContext* ctx, JSValue thisValue);
|
||||
static JSValue isAdditionBroken_set(JSContext* ctx, JSValue thisValue, JSValue jsValue);
|
||||
static JSValue isAdditionFull_get(JSContext* ctx, JSValue thisValue);
|
||||
|
||||
static JSValue isAdditionGhost_get(JSContext* ctx, JSValue thisValue);
|
||||
static JSValue isAdditionGhost_set(JSContext* ctx, JSValue thisValue, JSValue jsValue);
|
||||
|
||||
Reference in new issue
Block a user