Repository navigation
Conversation
BBQSoloFarmer::program() runs its quest rounds inline against the console, so the round logic (which quests count, when to stop, when to save) can only be exercised by running the farmer on a Switch. Move the round loop into run_bbq_rounds(), which takes the game actions it depends on as a BBQGameActions interface: read the quests, process them, do a quest, report a completed quest, and end the round (saving if due). BBQSoloFarmer implements these with the calls they replace, in the same order; the date fix, save/reset, stats and notification move together into end_round(). Startup, flying to the plaza and end-of-program handling stay in program(). The commented-out single-quest debug block declares its own egg counter now that the loop locals have moved. process_quest_list() only reads its quest list and egg count, so take them as const& and by value. Add PokemonSV::BBQFarmerRounds, a table of scenarios run against a simulated singleplayer quest panel: 3 blue quests, completed quests are replaced, impossible quests are skipped, and a panel with nothing doable is rerolled. Each scenario checks the number of completed quests and the exact action sequence: finishing the round that reaches the goal, a quest already gone, a failed quest, a panel with nothing doable, saving at exact multiples, and stopping when out of eggs. No behavior change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
dayfine
left a comment
There was a problem hiding this comment.
Where the code in this diff came from. Moved lines without a comment are unchanged.
dayfine
left a comment
There was a problem hiding this comment.
Where the code in this diff came from (comments cover line ranges). Moved lines without a comment are unchanged.
| void run_bbq_rounds(Logger& logger, const BBQOption& options, BBQGameActions& game){ | ||
| std::vector<BBQuests> quest_list; //all quests | ||
| std::vector<BBQuests> quests_to_do; //do-able quests | ||
| uint8_t eggs_hatched = 0; //Track eggs | ||
| uint64_t num_completed_quests = 0; | ||
|
|
||
| //Test a specific quest | ||
| /* | ||
| BBQuests test_quest = BBQuests::catch_water; | ||
| bool questTest = process_and_do_quest(env, env.console, context, BBQ_OPTIONS, test_quest, eggs_hatched); | ||
| if (questTest){ | ||
| env.log("Finished quest."); | ||
| } | ||
| */ | ||
|
|
||
| while (num_completed_quests < BBQ_OPTIONS.NUM_QUESTS){ | ||
| if (BBQ_OPTIONS.OUT_OF_EGGS == BBQOption::OOEggs::Stop && eggs_hatched >= BBQ_OPTIONS.NUM_EGGS){ | ||
| env.log("Stop when out of eggs selected. Stopping program."); | ||
| while (num_completed_quests < options.NUM_QUESTS){ | ||
| if (options.OUT_OF_EGGS == BBQOption::OOEggs::Stop && eggs_hatched >= options.NUM_EGGS){ | ||
| logger.log("Stop when out of eggs selected. Stopping program."); | ||
| break; | ||
| } | ||
|
|
||
| //Get and reroll quests until we can at least one | ||
| while (quests_to_do.size() < 1){ | ||
| quest_list = read_quests(env.program_info(), env.console, context, BBQ_OPTIONS); | ||
| quests_to_do = process_quest_list(env.program_info(), env.console, context, BBQ_OPTIONS, quest_list, eggs_hatched); | ||
| quest_list = game.read_quests(); | ||
| quests_to_do = game.process_quest_list(quest_list, eggs_hatched); | ||
|
|
||
| //Clear out the regular quest list. | ||
| quest_list.clear(); |
There was a problem hiding this comment.
Old program() loop, kept in place by the diff (old L109–170). It continues past this hunk to L125. Only the calls change:
env.log→logger.logBBQ_OPTIONS→options- console calls →
game.read_quests(),game.process_quest_list(),game.do_quest(),game.quest_completed()
The end-of-round block moves to end_round() (L157–177).
| class BBQSoloFarmerGameActions : public BBQGameActions{ | ||
| public: | ||
| BBQSoloFarmerGameActions( | ||
| SingleSwitchProgramEnvironment& env, ProControllerContext& context, | ||
| BBQOption& options, BBQSoloFarmer_Descriptor::Stats& stats, | ||
| EventNotificationOption& status_update | ||
| ) | ||
| : m_env(env), m_context(context) | ||
| , m_options(options), m_stats(stats) | ||
| , m_status_update(status_update) | ||
| {} | ||
|
|
||
| virtual std::vector<BBQuests> read_quests() override{ | ||
| return PokemonSV::read_quests(m_env.program_info(), m_env.console, m_context, m_options); | ||
| } | ||
| virtual std::vector<BBQuests> process_quest_list( | ||
| const std::vector<BBQuests>& quests, uint8_t eggs_hatched | ||
| ) override{ | ||
| return PokemonSV::process_quest_list(m_env.program_info(), m_env.console, m_context, m_options, quests, eggs_hatched); | ||
| } | ||
| virtual bool do_quest(BBQuests quest, uint8_t& eggs_hatched) override{ | ||
| return process_and_do_quest(m_env, m_env.console, m_context, m_options, quest, eggs_hatched); | ||
| } | ||
| virtual void quest_completed() override{ | ||
| m_stats.questsCompleted++; | ||
| m_env.update_stats(); | ||
| } | ||
| virtual void end_round(bool save) override{ | ||
| //Fix the time to prevent running out of years | ||
| pbf_wait(m_context, 2000ms); | ||
| m_context.wait_for_all_requests(); | ||
| go_home(m_env.console, m_context); | ||
| home_to_date_time(m_env.console, m_context, false); | ||
| pbf_press_button(m_context, BUTTON_A, 160ms, 840ms); | ||
| pbf_press_button(m_context, BUTTON_A, 160ms, 840ms); | ||
| pbf_press_button(m_context, BUTTON_HOME, 160ms, ConsoleSettings::instance().SETTINGS_TO_HOME_DELAY0); | ||
| resume_game_from_home(m_env.console, m_context); | ||
|
|
||
| if (save){ | ||
| m_env.log("Saving and resetting."); | ||
| save_game_from_overworld(m_env.program_info(), m_env.console, m_context); | ||
| reset_game(m_env.program_info(), m_env.console, m_context); | ||
| m_stats.saves++; | ||
| } | ||
|
|
||
| env.update_stats(); | ||
| send_program_status_notification(env, NOTIFICATION_STATUS_UPDATE); | ||
| m_env.update_stats(); | ||
| send_program_status_notification(m_env, m_status_update); | ||
| } | ||
|
|
||
| private: | ||
| SingleSwitchProgramEnvironment& m_env; | ||
| ProControllerContext& m_context; | ||
| BBQOption& m_options; | ||
| BBQSoloFarmer_Descriptor::Stats& m_stats; | ||
| EventNotificationOption& m_status_update; | ||
| }; |
There was a problem hiding this comment.
New. Each method forwards to the call it replaces in the old loop, with the same arguments.
| virtual void end_round(bool save) override{ | ||
| //Fix the time to prevent running out of years | ||
| pbf_wait(m_context, 2000ms); | ||
| m_context.wait_for_all_requests(); | ||
| go_home(m_env.console, m_context); | ||
| home_to_date_time(m_env.console, m_context, false); | ||
| pbf_press_button(m_context, BUTTON_A, 160ms, 840ms); | ||
| pbf_press_button(m_context, BUTTON_A, 160ms, 840ms); | ||
| pbf_press_button(m_context, BUTTON_HOME, 160ms, ConsoleSettings::instance().SETTINGS_TO_HOME_DELAY0); | ||
| resume_game_from_home(m_env.console, m_context); | ||
|
|
||
| if (save){ | ||
| m_env.log("Saving and resetting."); | ||
| save_game_from_overworld(m_env.program_info(), m_env.console, m_context); | ||
| reset_game(m_env.program_info(), m_env.console, m_context); | ||
| m_stats.saves++; | ||
| } | ||
|
|
||
| env.update_stats(); | ||
| send_program_status_notification(env, NOTIFICATION_STATUS_UPDATE); | ||
| m_env.update_stats(); | ||
| send_program_status_notification(m_env, m_status_update); | ||
| } |
There was a problem hiding this comment.
Moved with renames from the end of each loop round (old L150–169). Changes:
env→m_env,context→m_context,stats→m_statsNOTIFICATION_STATUS_UPDATE→m_status_update- the loop decides whether a save is due and passes it in as
save
Every line has a rename, so git can't match this block as moved. Compare it with the removed lines by eye.
| void BBQSoloFarmer::program(SingleSwitchProgramEnvironment& env, ProControllerContext& context){ | ||
| StartProgramChecks::check_performance_class_wired_or_wireless(context); | ||
| assert_16_9_720p_min(env.logger(), env.console); | ||
|
|
||
| BBQSoloFarmer_Descriptor::Stats& stats = env.current_stats<BBQSoloFarmer_Descriptor::Stats>(); | ||
|
|
||
| //Make sure console type is set | ||
| if (env.console.state().console_type() == ConsoleType::Unknown){ | ||
| throw UserSetupError(env.console, "Console Type (Switch 1 or 2) must be specified."); | ||
| } | ||
|
|
||
| // Connect the controller. | ||
| require_player(env.console, context, BUTTON_LCLICK); | ||
|
|
||
| //Fly to plaza | ||
| open_map_from_overworld(env.program_info(), env.console, context); | ||
| fly_to_overworld_from_map(env.program_info(), env.console, context); | ||
|
|
||
| //Test a specific quest | ||
| /* | ||
| uint8_t eggs_hatched = 0; | ||
| BBQuests test_quest = BBQuests::catch_water; | ||
| bool questTest = process_and_do_quest(env, env.console, context, BBQ_OPTIONS, test_quest, eggs_hatched); | ||
| if (questTest){ | ||
| env.log("Finished quest."); | ||
| } | ||
| */ |
There was a problem hiding this comment.
Moved unchanged: the startup (old L77–93) and the commented-out single-quest test (old L100–106). The test now declares its own eggs_hatched, since that local moved into run_bbq_rounds().
| BBQSoloFarmerGameActions game(env, context, BBQ_OPTIONS, stats, NOTIFICATION_STATUS_UPDATE); | ||
| run_bbq_rounds(env.logger(), BBQ_OPTIONS, game); |
There was a problem hiding this comment.
New: build the console actions and run the loop.
Windows Clang (clang-cl /W4 /WX) errors on designated initializers that leave out a field with no default member initializer (-Wmissing-designated-field-initializers); tests built on these scenarios omit these fields. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
|
Closing: duplicate of #37 (same branch head), kept only for the review-annotation trial. |
Trial: a copy of PokemonAutomation#1632 with inline comments marking moved code, to see whether that reads well on github.com. Not for merging; will be closed after the trial.