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

Arbitrary trainer scripts + on frame/trigger softlock prevention #5033

Draft
wants to merge 9 commits into
base: upcoming
Choose a base branch
from

Conversation

mrgriffin
Copy link
Collaborator

Script_HasNoEffect returns TRUE if the script definitely has no player-visible effect, or FALSE if it may/does have a player-visible effect.

Opcodes have been manually tagged with whether they abort if they would have a player-visible effect, and the natives and specials have been manually tagged with whether they definitely have no player-visible effect or not.

Using these, we're able to execute scripts until they either exit with no effect, or would possibly have an effect. This allows us to:

  1. Not run on frame map scripts or triggers if they would have no effect.
  2. Support arbitrary control flow in trainer scripts. The trainer does not see the player if the script has no effect, and the trainer will use whichever trainerbattle command is branched to.
  3. Support arbitrary scripts in trainer scripts. cant_see and cant_see_if_* commands have been introduced so that scripts are able to do something when the player interacts with the trainer even if that trainer wouldn't see them.

@mrgriffin
Copy link
Collaborator Author

There's obviously a comparison to be drawn between point 3 and ghoulslash's trainer_see_scripts branch.

The small difference is that this PR puts the check to see if the script should run inside the script (via cant_see/cant_see_if_*), whereas trainer_see_scripts puns the "Trainer Type" field in Porymap as a flag which controls whether the trainer should run (equivalent to cant_see_if_flag_set).

A consequence of punning the flag is iiuc that flags 1-3 are treated as trainer types, meaning that FLAG_TEMP_1-FLAG_TEMP_3 don't work in trainer_see_scripts, and out of the box nor do any flags with IDs greater than 0xFF (which is most of them, including all trainer flags).

I personally prefer the design in this branch—if a user has a script that doesn't start with trainerbattle then it will automatically work, but they might get immediately re-seen after the script finishes. imo this behavior is preferable to a crash and/or an unexpected battle, and I would expect that if somebody described their situation on Discord the helpers there would quickly learn to suggest a cant_see_if_* check.

Script_HasNoEffect returns TRUE if the script definitely has no player-
visible effect, or FALSE if it may/does have a player-visible effect.

Opcodes have been manually tagged with whether they abort if they would
have a player-visible effect, and the natives and specials have been
manually tagged with whether they definitely have no player-visible
effect or not.

Using these, we're able to execute scripts until they either exit with
no effect, or would possibly have an effect. This allows us to:
1. Not run on frame map scripts or triggers if they would have no
   effect.
2. Support arbitrary control flow in trainer scripts. The trainer does
   not see the player if the script has no effect, and the trainer will
   use whichever trainerbattle command is branched to.
3. Support arbitrary scripts in trainer scripts. cant_see and
   cant_see_if_* commands have been introduced so that scripts are able
   to do something when the player interacts with the trainer even if
   that trainer wouldn't see them.
@mrgriffin mrgriffin force-pushed the rhh-script-has-no-effect branch from 2c04041 to 1eb51c4 Compare July 25, 2024 07:59
@mrgriffin mrgriffin marked this pull request as ready for review July 25, 2024 09:06
Copy link
Collaborator

@Bassoonian Bassoonian left a comment

Choose a reason for hiding this comment

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

Quite a bit of this is out of my league, but some preliminary thoughts before other people review this

asm/macros/event.inc Outdated Show resolved Hide resolved
asm/macros/event.inc Outdated Show resolved Hide resolved
asm/macros/event.inc Outdated Show resolved Hide resolved
data/script_cmd_table.inc Outdated Show resolved Hide resolved
@mrgriffin
Copy link
Collaborator Author

mrgriffin commented Jul 25, 2024

EDIT: special flags are no longer supported due to the issue mentioned at the bottom of this message.

Oh, to quickly justify why I think that special vars, special flags, and string buffers do not count as player-visible but everything else does:

  1. Soft-resets will clear special vars/flags and string buffers. Therefore no script should assume that they hold any particular value when it starts, and so Script_HasNoEffect mutating those values just moves them from one indeterminate value to another.
  2. Interacting with the UI and/or walking around the map can easily alter special vars and string buffers.

I think you could argue that special flags shouldn't be counted as non-visible, e.g. FLAG_HIDE_MAP_NAME_POPUP or FLAG_DONT_TRANSITION_MUSIC do have visible effects if the script executes at the right time. I'd be happy to drop the idea of special flags being non-player-visible if pushed.

@mrgriffin mrgriffin added this to the 1.10 milestone Jul 26, 2024
asm/macros/event.inc Show resolved Hide resolved
src/script.c Outdated Show resolved Hide resolved
src/script.c Outdated Show resolved Hide resolved
@mrgriffin mrgriffin marked this pull request as draft August 5, 2024 08:35
@mrgriffin
Copy link
Collaborator Author

Temporarily marked as draft to give myself time to think about Deokishisu's comments on Discord.

@Bassoonian Bassoonian removed this from the 1.10 milestone Oct 18, 2024
@mrgriffin mrgriffin added the category: overworld Pertains to out-of-battle mechanics label Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: overworld Pertains to out-of-battle mechanics
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants