Skip to content

[FRLG RNG] Check free party slots in applicable RNG programs - #61

Draft
dayfine wants to merge 25 commits into
mainfrom
frlg/party-room-check
Draft

dayfine wants to merge 25 commits into
mainfrom
frlg/party-room-check

Conversation

@dayfine

@dayfine dayfine commented Oct 29, 2026 •

Copy link
Copy Markdown
Owner

The documentation pages of the RNG programs document the number of free party slots needed. Programs might fail after catching / receiving when there is no free slot, as the pokemon got sent to box.

This PR actually checks for those requirements at program startup, by introducing a general pre-startup hook for programs.

Testing

On a lab Switch with a full party (when catching Mewtwo), Static RNG on this build stopped with that message 5 seconds after starting, before any of its own setup; before, it ran five resets (about 30 minutes) and stopped with the seed error.

@dayfine
dayfine force-pushed the frlg/party-room-check branch from 5e9ebb5 to 760a5e1 Compare October 29, 2026 19:38
@dayfine dayfine changed the title FRLG RNG: stop at the start if the party has no free slot FRLG RNG: check the party before the program starts Oct 29, 2026
@dayfine
dayfine force-pushed the frlg/party-room-check branch 2 times, most recently from 13d4322 to 707b17e Compare October 29, 2026 20:57
#include "CommonFramework/Options/LabelCellOption.h"
#include "CommonTools/Options/LanguageOCROption.h"
#include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h"
#include "PokemonFRLG_RngProgram.h"

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

This is in the wrong place

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

should PokemonFRLG_RngProgram not be sorted?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Moved: PokemonFRLG_RngProgram.h now sits with the other same-folder includes at the end, in alphabetical order among them, in all seven program headers (9f36e0d).

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Yes, sorted now (9f36e0d).

using namespace Pokemon;

void check_party_has_free_slot(ConsoleHandle& console, ProControllerContext& context, StartMenuContext menu_context){
console.log("Checking for a free party slot...");

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

why is not just in SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.cpp?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Agreed, nothing else uses it. It's now a private helper in PokemonFRLG_RngProgram.cpp, and RngNavigation is back to upstream's version (9f36e0d).

dayfine and others added 2 commits October 29, 2026 19:30
Static, Wild, Gift and Roaming RNG read the Pokemon they catch or receive
from the end of the party. With a full party it goes to the PC instead, every
attempt reads the wrong Pokemon, and after a few resets the program stops with
"The target Seed is missing from the list of nearby seeds", which points at
the wrong setting.

SingleSwitchProgramInstance gets start_program_game_checks(), a no-op hook
called with the controller ready just before program(), for checking that
the game is set up the way a program needs. The FRLG RNG programs now derive
from RngProgramInstance, which implements it from a required
party_requirement() (and start_menu_context() for the Safari Zone): with
FREE_SLOT it opens the party and stops with a setup error naming the real
problem, or skips the check if the party menu can't be opened.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
…clude

The free-slot check is only used by RngProgramInstance, so it lives in
PokemonFRLG_RngProgram.cpp instead of RngNavigation. The base class's
header joins the other same-folder includes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
@dayfine
dayfine force-pushed the frlg/party-room-check branch from 707b17e to 9f36e0d Compare October 30, 2026 02:34
@dayfine

dayfine commented Oct 30, 2026

Copy link
Copy Markdown
Owner Author

LGTM

dayfine and others added 4 commits October 29, 2026 22:31
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
Take the party check's game steps through a small PartyCheckActions
interface, so check_party_requirement() runs against scripted steps in
tests, and read the last occupied party slot from an image, so it runs on
the party menu screenshots already in CommandLineTests. Behavior is
unchanged.

Tests: PokemonFRLG::RngPartyCheck (no requirement, free slot, full party,
menu not opened) and PokemonFRLG::LastOccupiedPartySlot (Party_1..6 and
the held-item/JPN/SPA party screenshots).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
@dayfine

dayfine commented Oct 31, 2026

Copy link
Copy Markdown
Owner Author

Added unit tests in bdbeb41 (new commit on top; behavior unchanged). The check now takes its two game steps (open the party menu, read the last occupied slot) through a small PartyCheckActions interface, so PokemonFRLG::RngPartyCheck runs check_party_requirement() against scripted steps: no requirement (menu never opened), one and five Pokémon (passes), full party (UserSetupError "Your party is full…"), and menu not opened (skips). detect_last_occupied_party_slot() also takes an image now, and PokemonFRLG::LastOccupiedPartySlot runs it on the party screenshots already in CommandLineTests (Party_1–Party_6, held-item, JPN and SPA). CI: Mac, Windows Clang, Ubuntu.

@dayfine

dayfine commented Oct 31, 2026

Copy link
Copy Markdown
Owner Author

well I was thinking whether we can actually check the program actually perform the party check, with the right setttings -- maybe harder / impossible?

dayfine and others added 2 commits October 31, 2026 10:16
Build each FRLG RNG program, load its settings from JSON, and check the
party requirement and start menu its start check uses (WildRng on Route 1
and in the Safari Zone). Make RngProgramInstance's start hook final, so no
RNG program can skip the check by overriding it. Behavior is unchanged.

Tests: PokemonFRLG::RngProgramPartyRequirement.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
The party screenshot test expected three; the existing empty-slot tests
for the same image mark slots 5 and 6 empty.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
@dayfine

dayfine commented Oct 31, 2026

Copy link
Copy Markdown
Owner Author

whether we can actually check the program actually perform the party check, with the right settings

Mostly, yes. fda0033 adds PokemonFRLG::RngProgramPartyRequirement. For each RNG program, it builds the real program, loads its settings from JSON the way a saved profile does, and checks what the start check will ask for. Gift, Static, Roaming and Wild need a free slot. Starter, Egg and RngHelper don't. WildRng uses the standard start menu on Route 1 and the Safari Zone menu at safari_zone_entrance. That commit also makes RngProgramInstance::start_program_game_checks() final, so the compiler stops any RNG program from overriding the hook and skipping the check. The requirement is fixed per program today; no setting changes it. Location only changes which start menu it opens.

What isn't unit tested: that SingleSwitchProgramInstance calls the hook before program(). That needs a running program environment (console, video, controller). It's one line in the shared wrapper, and the lab run that stopped on a full party covered it. SidHelper isn't an RNG program instance and has no party check.

85c066e fixes my expected count for JPN_Party.png (it shows four Pokémon). The CI links in my earlier comment are for the run with that mistake. All three pass at 85c066e, including the 23 new tests: Mac, Windows Clang, Ubuntu.

const RngProgramPartyScenario scenarios[] = {
{.name = "RngHelper", .make_program = make_rng_program<RngHelper>, .expected_requirement = NONE},
{.name = "StarterRng", .make_program = make_rng_program<StarterRng>, .expected_requirement = NONE},
{.name = "EggRng", .make_program = make_rng_program<EggRng>, .expected_requirement = NONE},

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

EggRng needs three free slots (the egg and the two wild Pokemon it
catches to confirm the seed), and what RngHelper needs depends on its
target: gifts, prizes, Togepi and the daycare egg pickup read the
received Pokemon from the party, while encounters are only watched. So
programs now say how many free slots they need instead of whether they
need one, and RngHelper derives it from its Target setting.

Tests: PokemonFRLG::RngPartyCheck adds three-slot cases;
PokemonFRLG::RngProgramPartyRequirement covers EggRng and RngHelper
targets.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
@dayfine dayfine added game:frlg FireRed/LeafGreen rng RNG programs labels Nov 1, 2026
dayfine and others added 5 commits November 2, 2026 12:59
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E

# Conflicts:
#	SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp
….cpp at its size

origin/main grew the file to its code-health allowance (1656 lines over the
1000-line limit); the image overload this PR adds needs three lines.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
dayfine and others added 6 commits November 7, 2026 07:01
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
# Conflicts:
#	SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp
Fix the stale function name in the PartyCheckActions comment, name the
party size, word the one-slot message for gifts too, sort the new
Navigation.h include, and take the test image path as string_view.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss
Table-driven input/expectation cases for the party check tests, a
comment on each RNG program class and the new overload, and closing
namespace comments in the new files.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss
return "Your party is full. Leave a party slot free so the program can check the "
+ Pokemon::STRING_POKEMON + " it catches or receives.";
}
return "Your party has " + std::to_string(party_size) + " " + Pokemon::STRING_POKEMON

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

strformat + raw string?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Now std::format for both messages (8490e0c); the text is unchanged, so the tests still match. I left out the raw string: the messages have no quotes or backslashes, so R"(...)" would read the same.

PA_ADD_OPTION(NOTIFICATIONS);
}

size_t RngHelper::free_party_slots_needed() const{

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

do we need this? I hope not?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

It's there because RngHelper is the one program whose target is a setting, and only some targets read the received Pokemon from the end of the party (check_for_shiny() → shiny_check_summary()). Options to drop the switch: (a) always ask for 1 free slot except for starters (wild/static users would need a free slot they don't strictly need), (b) no check in RngHelper (return 0; it's the manual tool), (c) one shared shiny_check_reads_party(target) next to check_for_shiny() so the list lives in one place (touches RngNavigation again). Which do you prefer?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Went with (b): RngHelper returns 0 with a one-line comment, the per-target switch is gone, and RngHelper.cpp is back to upstream's version. The party tests keep one RngHelper case (expects 0). (a48b54d)

dayfine and others added 3 commits November 9, 2026 19:19
@dayfine dayfine changed the title FRLG RNG: check the party before the program starts [FRLG RNG] Check free party slots in applicable RNG programs Nov 10, 2026
@dayfine

dayfine commented Nov 10, 2026

Copy link
Copy Markdown
Owner Author

Upstream: PokemonAutomation#1881 (branch upstream/frlg-free-party-slots, one squashed commit, same tree as this PR's fixes).

dayfine and others added 2 commits November 10, 2026 07:02
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

game:frlg FireRed/LeafGreen rng RNG programs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant