-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[Plugin] Fix track origin being miscalculated for plugins on downward slopes #24142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Plugin] Fix track origin being miscalculated for plugins on downward slopes #24142
Conversation
@Sadret Can you review this? (You are much more familiar with the ins and outs of the scripting system.) |
I am just barely aware that there are some anomalities with track z positions, and I have not yet worked with the TrackIterator api. So unfortunately I do not have anything to add here. |
Oh I forgot, if anyone wants to test it, they can do so with this plugin: Click to show plugin/// <reference path="../bin/openrct2.d.ts" />
// @ts-check
registerPlugin({
name: "Test track location",
version: "1",
authors: ['Basssiiie'],
targetApiVersion: 82,
type: "local",
licence: "MIT",
main() {
ui.registerMenuItem("Test track location", function() {
ui.activateTool({
id: 'test-pick-vehicle',
cursor: 'cross_hair',
filter: ["entity"],
onDown: function(args) {
var entityId = args.entityId;
if (entityId === undefined) return;
ui.tool.cancel();
console.log("Entity "+entityId+" selected");
var entity = map.getEntity(entityId);
var window = ui.openWindow({
classification: "test-track-location",
title: "Test track location",
width: 200,
height: 170,
onUpdate: function()
{
var trackLocation = entity.trackLocation;
window.findWidget("info-label").text =
"Entity id: "+entityId
+"\nTile: "+[Math.floor(trackLocation.x / 32), Math.floor(trackLocation.y / 32)].join(", ")
+"\nTrack: "+[trackLocation.x, trackLocation.y, trackLocation.z].join(", ")
+"\nDirection: "+trackLocation.direction
+"\nType: "+trackLocation.trackType
+"\nProgress: "+entity.trackProgress+" / "+context.getTrackSegment(trackLocation.trackType).getSubpositionLength(entity.subposition, trackLocation.direction);
},
widgets: [
{
name: "info-label",
type: "label",
x: 10,
y: 25,
width: 180,
height: 15,
},
{
name: "move-location-button",
type: "button",
x: 10,
y: 125,
width: 180,
height: 15,
text: "Move track location",
onClick: function() {
ui.activateTool({
id: "test-move-track-location",
cursor: "cross_hair",
filter: ["ride"],
onDown: function(args) {
var coords = args.mapCoords;
var index = args.tileElementIndex;
if (!coords || index === undefined) return;
ui.tool.cancel();
var x = Math.floor(coords.x / 32);
var y = Math.floor(coords.y / 32);
console.log("Move location to", x, y, index);
entity.moveToTrack(x, y, index);
}
})
}
},
{
name: "travel-by",
type: "spinner",
text: "Travel by",
x: 10,
y: 145,
width: 180,
height: 15,
onDecrement: function() {
console.log("Travel backwards by 1.000.000");
entity.travelBy(-1000000)
},
onIncrement: function() {
console.log("Travel forwards by 1.000.000");
entity.travelBy(1000000)
},
},
]
})
}
})
})
}
}); |
Can you rebase and then amend the changelog? |
09aa506
to
75de5b8
Compare
- Feature: [#24206] [Plugin] Add APIs for breaking down rides, reading the current breakdown, and for fixing broken down rides. - Improved: [#20073] The OpenGL drawing engine now supports screen invalidation which avoids the redrawing of unchanged regions. - Improved: [#21767] RCT Classic for macOS can now be used as the source game. - Improved: [#23590] Title bars are now drawn bigger when “Enlarged UI” is enabled. - Improved: [#23626] Add small, medium and large flat and sloped turns, S-bends and diagonal track to the Go-Karts. - Improved: [#23982] The scenario objective window has been merged into the scenario options window. - Improved: [#24233] RCT Classic+ from Apple Arcade can now be used as the source game, and is detected automatically. - Improved: [#24260] Better performance on parks that have a lot of Guests and Entertainers. - Improved: [#24319] RCT Classic installs via Steam are now detected automatically on Windows. - Change: [#23803] Lightning strikes and thunder now happen at the same frequency independently of the game speed. - Change: [#23857] Replace display options tab with custom sprites. - Change: [#24069] [Plugin] Plugins are now available in the scenario editor and track designer. - Change: [#24135] Compress Emscripten js/wasm files. - Change: [#24194] The advanced options tab has been reworked to make it easier to find the RCT1 path setting. - Change: [#24235] Small changes to RCT1 theme. - Change: [#24236] Controls and Interface options now both have their own tabs in the Options window. - Change: [#24308] “Software” and “Software (hardware display)” renderers have been merged into a single “Software” renderer. - Change: [#24317] The scenery window now shows at least one row of scenery objects, even if there are multiple rows of tabs. - Fix: [#18479] Tile elements ordered beneath water do not draw correctly. - Fix: [#19782] Game stops counting inversions and golf holes after 31 (original bug). - Fix: [#21207] Track List window gets positioned incorrectly. - Fix: [#21919] Non-recolourable cars still show colour picker (original bug). - Fix: [#22182] [Plugin] Crash when using map.getAllEntities("car"). - Fix: [#22634] Asset packs with sound effect overrides are not loaded correctly at startup. - Fix: [#23108] Missing pieces on Hypercoaster and Hyper-Twister, even with the ‘all drawable track pieces’ cheat enabled. - Fix: [#24013] Failure to load a scenario preview image (minimap) could lead to an uncaught exception error message. - Fix: [#24045] [Plugin] Data storage is not cleared when converting save game to scenario. - Fix: [#24121] Checkbox labels run beyond the edge of the window if they’re too long to fit. - Fix: [#24142] [Plugin] Track origin is miscalculated on downward slopes. - Fix: [#24220] Narrow station platforms have missing sides on certain rotations. - Fix: [#24286] Steam installs of RCT1 and RCT2 are not autodetected on macOS. - Fix: [#24310] [Plugin] Missing invalidation on various plugin api setters for entities.
[Plugin] Fix regression from #24142 breaking `ScTrackIterator` on specific track pieces
Hey all,
This PR fixes quite an obscure bug in the plugin API's
TrackIterator
and the recently addedcar.moveToTrack()
, where if it selected a non-origin track element on a large downward slope (for example), it would report thez
position of the selected non-origin track element as thez
of the origin track piece. I unfortunately only found this today while attempting to wrap up the RVE implementation and not during testing of thecar.moveToTrack()
PR, so my apologies for that.This issue happens with all pieces where the track piece origin has a non-zero
z
-offset, for example large downward slopes and downward turns. For reference, the downwards slope has 4 sequence parts:z
= 80 (origin)z
= 64z
= 32z
= 0Except for these few track pieces, most of the other track pieces have a origin
z
of 0, and are thus not affected by this issue.Example screenshot of the issue, with the numbered sequences and the vehicle having been moved to the track piece via sequence 3:

The fix adds the origin
z
to the equation to ensure this weird offset at the origin is accounted for, which brings it in line with how similar code works within the OpenRCT2 code base. The affected function here is only used by theScTrackIterator
andScVehicle::moveToTrack()
, so impact is minimal.Thank you for your time. 🙂