Skip to content
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

Feat: enable sending guest to specific ride #21897

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from

Conversation

ltsSmitty
Copy link
Contributor

This PR adds a new feature (I'd say a cheat), the ability to specifically send guests to a given ride, regardless of whether they'd naturally choose it or not.

Calling the Guest::SendToRide method will override their current state if they're walking, sitting, watching a ride, or using the bin. It'll also override their behavior if they were trying to leave the park, and will send them to the ride instead.

This is exposed to the plugin api through the direct guest property method sendToRide(rideId), or via the cheatset game action. For player visibility, also adds rideHeadedTo as a getter prop on Guest.

This is my first c++ submission, and I'd appreciate a thorough review in case I've done anything non-optimally.

Future improvement would include stealing guests out of other queue lines, but I ran into issues when the original ride would try and process guests who are no longer in the queue and the game would crash. I wasn't able to solve this in a satisfying way that would scale as a user tries looping through all the guests in a park.

TODO: I know the plugin api version will need a bump after this, but unsure when that happens in the PR process.

return;
if (x == LOCATION_NULL)
return;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function does not seem to check if the guest is actually in the park.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this line was copypasted from Guest::PickRideToGoOn(), which was what I based all this code on. I'm not sure what it does but left it since it didn't obviously hurt anything.

the guest is checked to be in the park in the PeepState check.

Copy link
Contributor

@KatieZeldaKat KatieZeldaKat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally looking forward to the changes, just have a little feedback as I was looking through the PR.

src/openrct2/scripting/bindings/entity/ScGuest.cpp Outdated Show resolved Hide resolved
distribution/openrct2.d.ts Outdated Show resolved Hide resolved
@ltsSmitty
Copy link
Contributor Author

I've gone ahead per @Basssiiie's suggestion and moved all the code out of Guest and into ScGuest.

Couple questions-

  • I went ahead and made it return an int_16t so that the plugin api gets a value of -1 if the guest isn't headed to a ride. Was this a right way to do this?
  • How do i make the code formatting check pass? I'm unsure how to run it locally (Macos) or interpret what the issue is from the run details

@Basssiiie Basssiiie self-requested a review April 29, 2024 15:43
Copy link
Member

@Basssiiie Basssiiie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one! 😀

distribution/openrct2.d.ts Outdated Show resolved Hide resolved
src/openrct2/scripting/bindings/entity/ScGuest.cpp Outdated Show resolved Hide resolved
@Basssiiie
Copy link
Member

Regarding the formatting, it should be possible to run clang-format from cmdline, though I've never done it before.

@Harry-Hopkinson
Copy link
Contributor

Harry-Hopkinson commented Apr 29, 2024

From the base directory of OpenRCT2 - you should be able to run

sh scripts/check-code-formatting

Presuming you have bash installed...

@ltsSmitty ltsSmitty requested a review from Gymnasiast May 1, 2024 14:16
@Basssiiie
Copy link
Member

Tested it and found no issues. LGTM! 😄

Click here for the plugin I used for testing.
registerPlugin({
	name: "Test guest ride head to",
	version: "1",
	authors: ['Basssiiie'],
	targetApiVersion: 82,
	type: "local",
	licence: "MIT",
	main()
	{
		ui.registerMenuItem("Test guest ride head to", function()
		{
			ui.activateTool({
				id: "test-guest-ride-head-to",
				cursor: "cross_hair",
				onDown: function(args)
				{
					var id = args.entityId;
					if (id == undefined) return;

					var guest = map.getEntity(id);
					if (guest.type !== "guest") return;

					var rides = map.rides.slice().sort(function(l,r){return l.name.localeCompare(r.name)});
					var window = ui.openWindow({
						classification: "test-guest-ride-head-to",
						title: "Guest ride head to",
						width: 210,
						height: 100,
						onUpdate: function()
						{
							var label = window.findWidget("guest-ride");
							var rideId = guest.rideHeadedTo;
							var ride = rides.filter(function(r){return r.id == rideId})[0];
							if (ride)
							{
								label.text = "Ride head to: " + ride.name + " (" + guest.rideHeadedTo + ")";
							}
							else
							{
								label.text = "Ride head to: null";
							}
						},
						widgets: [
							{
								type: "label",
								x: 5,
								y: 20,
								width: 200,
								height: 15,
								text: "Name: " + guest.name
							},
							{
								name: "guest-ride",
								type: "label",
								x: 5,
								y: 40,
								width: 200,
								height: 15,
							},
							{
								type: "dropdown",
								x: 5,
								y: 60,
								width: 200,
								height: 15,
								items: rides.map(function(r){return r.name}),
								onChange: function(index)
								{
									guest.rideHeadedTo = rides[index].id;
								}
							},
							{
								type: "button",
								text: "Reset ride headed to",
								x: 5,
								y: 80,
								width: 200,
								height: 15,
								onClick: function()
								{
									guest.rideHeadedTo = null;
								}
							},
						]
					})
				}
			})
		})
	}
});

@KatieZeldaKat
Copy link
Contributor

I believe code formatting is failing just because of include "../../../peep/PeepAnimationData.h" being in the wrong place, where it would work being directly after include "../../../localisation/Localisation.h" (if I'm reading the error correctly).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants