Skip to content

Commit 2d7cc64

Browse files
committed
Merge frlg/stage19-victory-road into frlg/party-menu-once: upstream PokemonAutomation#1881 free party slots (c09beca)
2 parents 1ce9a85 + 54946de commit 2d7cc64

17 files changed

Lines changed: 172 additions & 28 deletions

‎SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_EggRng.cpp‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -722,11 +722,10 @@ void EggRng::program(SingleSwitchProgramEnvironment& env, ProControllerContext&
722722
/*
723723
* Settings: Text Speed fast
724724
*/
725+
run_precheck(env, context);
725726

726727
EggRng_Descriptor::Stats& stats = env.current_stats<EggRng_Descriptor::Stats>();
727728

728-
home_black_border_check(env.console, context);
729-
730729
// prepare database of base stats and gender thresholds
731730
RngStatsDatabase STATS_DATA("PokemonFRLG/BaseStats.json");
732731

‎SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_EggRng.h‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
#include "CommonFramework/Notifications/EventNotificationsTable.h"
1515
#include "CommonFramework/Options/LabelCellOption.h"
1616
#include "CommonTools/Options/LanguageOCROption.h"
17-
#include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h"
1817
#include "NintendoSwitch/Options/NintendoSwitch_GoHomeWhenDoneOption.h"
1918
#include "Pokemon/Options/Pokemon_NameSelectOption.h"
2019
#include "Pokemon/Pokemon_AdvRng.h"
2120
#include "PokemonFRLG_BlindNavigation.h"
2221
#include "PokemonFRLG_RngCalibration.h"
22+
#include "PokemonFRLG_RngProgram.h"
2323
#include "PokemonFRLG_RngStatsDatabase.h"
2424
#include "PokemonFRLG_RngDisplays.h"
2525
#include "PokemonFRLG_RngLoopRoutines.h"
@@ -56,9 +56,16 @@ class EggRng_Descriptor : public SingleSwitchProgramDescriptor{
5656
virtual std::unique_ptr<StatsTracker> make_stats() const override;
5757
};
5858

59-
class EggRng : public SingleSwitchProgramInstance, public ConfigOption::Listener{
59+
// Calibrates timings to hit an RNG target for a daycare egg.
60+
class EggRng : public RngProgramInstance, public ConfigOption::Listener{
6061
public:
6162
using Descriptor = EggRng_Descriptor;
63+
virtual size_t free_party_slots_needed() const override{
64+
if (STARTING_POINT == EggProgramState::pickup_calibration){
65+
return 2;
66+
}
67+
return 3;
68+
}
6269
~EggRng();
6370
EggRng();
6471
virtual void program(SingleSwitchProgramEnvironment& env, ProControllerContext &context) override;

‎SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_GiftRng.cpp‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,10 @@ void GiftRng::program(SingleSwitchProgramEnvironment& env, ProControllerContext&
214214
/*
215215
* Settings: Text Speed fast
216216
*/
217+
run_precheck(env, context);
217218

218219
GiftRngStats& stats = env.current_stats<GiftRng_Descriptor::Stats>();
219220

220-
home_black_border_check(env.console, context);
221-
222221
RNG_FILTERS.reset();
223222
RNG_CALIBRATION.reset_hits();
224223

‎SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_GiftRng.h‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
#include "Common/Cpp/Options/StaticTextOption.h"
1313
#include "CommonFramework/Notifications/EventNotificationsTable.h"
1414
#include "CommonTools/Options/LanguageOCROption.h"
15-
#include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h"
1615
#include "NintendoSwitch/Options/NintendoSwitch_GoHomeWhenDoneOption.h"
1716
#include "PokemonFRLG_BlindNavigation.h"
1817
#include "PokemonFRLG_GiftRngAttempts.h"
1918
#include "PokemonFRLG_RngDisplays.h"
19+
#include "PokemonFRLG_RngProgram.h"
2020
#include "PokemonFRLG_SeedsDatabase.h"
2121

2222
namespace PokemonAutomation{
@@ -30,9 +30,11 @@ class GiftRng_Descriptor : public SingleSwitchProgramDescriptor{
3030
virtual std::unique_ptr<StatsTracker> make_stats() const override;
3131
};
3232

33-
class GiftRng : public SingleSwitchProgramInstance, private ConfigOption::Listener{
33+
// Calibrates timings to hit an RNG target for a gift Pokemon.
34+
class GiftRng : public RngProgramInstance, private ConfigOption::Listener{
3435
public:
3536
using Descriptor = GiftRng_Descriptor;
37+
virtual size_t free_party_slots_needed() const override{ return 1; }
3638
~GiftRng();
3739
GiftRng();
3840
virtual void program(SingleSwitchProgramEnvironment& env, ProControllerContext &context) override;

‎SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngHelper.cpp‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,11 +242,10 @@ void RngHelper::program(SingleSwitchProgramEnvironment& env, ProControllerContex
242242
/*
243243
* Settings: Text Speed fast
244244
*/
245+
run_precheck(env, context);
245246

246247
RngHelper_Descriptor::Stats& stats = env.current_stats<RngHelper_Descriptor::Stats>();
247248

248-
home_black_border_check(env.console, context);
249-
250249
bool shiny_found = false;
251250

252251
static const int64_t FIXED_SEED_OFFSET = -845; // milliseconds, approximate

‎SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngHelper.h‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
#include "Common/Cpp/Options/StaticTextOption.h"
1414
#include "CommonFramework/Notifications/EventNotificationsTable.h"
1515
#include "CommonTools/Options/LanguageOCROption.h"
16-
#include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h"
1716
#include "NintendoSwitch/Options/NintendoSwitch_GoHomeWhenDoneOption.h"
1817
#include "PokemonFRLG_BlindNavigation.h"
18+
#include "PokemonFRLG_RngProgram.h"
1919

2020
namespace PokemonAutomation{
2121
namespace NintendoSwitch{
@@ -28,9 +28,12 @@ class RngHelper_Descriptor : public SingleSwitchProgramDescriptor{
2828
virtual std::unique_ptr<StatsTracker> make_stats() const override;
2929
};
3030

31-
class RngHelper : public SingleSwitchProgramInstance{
31+
// Soft resets with given timings to hit a target seed and frame.
32+
class RngHelper : public RngProgramInstance{
3233
public:
3334
using Descriptor = RngHelper_Descriptor;
35+
// The manual tool: the user sets the target and the party, so no check.
36+
virtual size_t free_party_slots_needed() const override{ return 0; }
3437
RngHelper();
3538
virtual void program(SingleSwitchProgramEnvironment& env, ProControllerContext &context) override;
3639
virtual void start_program_border_check(
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/* RNG Program
2+
*
3+
* From: https://github.com/PokemonAutomation/
4+
*
5+
*/
6+
7+
#include <format>
8+
#include <string>
9+
#include "Common/Cpp/Exceptions.h"
10+
#include "CommonFramework/Exceptions/OperationFailedException.h"
11+
#include "Pokemon/Pokemon_Strings.h"
12+
#include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_PartySlot.h"
13+
#include "VideoGames/PokemonFRLG/PokemonFRLG_Navigation.h"
14+
#include "PokemonFRLG_RngProgram.h"
15+
16+
namespace PokemonAutomation{
17+
namespace NintendoSwitch{
18+
namespace PokemonFRLG{
19+
20+
21+
namespace{
22+
23+
std::string not_enough_free_slots_message(size_t party_size, size_t free_slots_needed){
24+
if (free_slots_needed == 1){
25+
return std::format(
26+
"Your party is full. Leave a party slot free so the program can check the {} it catches or receives.",
27+
Pokemon::STRING_POKEMON
28+
);
29+
}
30+
return std::format(
31+
"Your party has {} {}. Leave at least {} party slots free for the {} the program catches or receives.",
32+
party_size, Pokemon::STRING_POKEMON, free_slots_needed, Pokemon::STRING_POKEMON
33+
);
34+
}
35+
36+
} // namespace
37+
38+
39+
void RngProgramInstance::check_free_party_slots(
40+
SingleSwitchProgramEnvironment& env,
41+
ProControllerContext& context
42+
){
43+
const size_t free_slots_needed = free_party_slots_needed();
44+
if (free_slots_needed == 0){
45+
return;
46+
}
47+
Logger& logger = env.console.logger();
48+
logger.log("Checking for " + std::to_string(free_slots_needed) + " free party slot(s)...");
49+
try{
50+
open_party_menu_from_overworld(env.console, context);
51+
}catch (OperationFailedException&){
52+
logger.log("Unable to open the party menu. Skipping the free party slot check.", COLOR_RED);
53+
return;
54+
}
55+
context.wait_for_all_requests();
56+
constexpr size_t MAX_PARTY_SIZE = 6;
57+
const size_t party_size = static_cast<size_t>(detect_last_occupied_party_slot(env.console)) + 1;
58+
if (MAX_PARTY_SIZE - party_size < free_slots_needed){
59+
throw UserSetupError(logger, not_enough_free_slots_message(party_size, free_slots_needed));
60+
}
61+
logger.log("Party has enough free slots.");
62+
}
63+
64+
void RngProgramInstance::run_precheck(
65+
SingleSwitchProgramEnvironment& env,
66+
ProControllerContext& context
67+
){
68+
home_black_border_check(env.console, context);
69+
check_free_party_slots(env, context);
70+
}
71+
72+
} // namespace PokemonFRLG
73+
} // namespace NintendoSwitch
74+
} // namespace PokemonAutomation
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/* RNG Program
2+
*
3+
* From: https://github.com/PokemonAutomation/
4+
*
5+
* Base class for the FRLG RNG programs. Each program states what the game
6+
* must look like when it starts, and checks it first thing, so a setup
7+
* mistake stops the run at once instead of failing in a misleading way many
8+
* resets later.
9+
*
10+
*/
11+
12+
#ifndef PokemonAutomation_PokemonFRLG_RngProgram_H
13+
#define PokemonAutomation_PokemonFRLG_RngProgram_H
14+
15+
#include <cstddef>
16+
#include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h"
17+
18+
namespace PokemonAutomation{
19+
namespace NintendoSwitch{
20+
namespace PokemonFRLG{
21+
22+
23+
// Base class of the RNG programs.
24+
class RngProgramInstance : public SingleSwitchProgramInstance{
25+
public:
26+
using SingleSwitchProgramInstance::SingleSwitchProgramInstance;
27+
28+
// How many free party slots the program needs: one for each Pokemon it
29+
// catches or receives and then reads from the end of the party. In a full
30+
// party that Pokemon would go to the PC instead.
31+
virtual size_t free_party_slots_needed() const = 0;
32+
33+
protected:
34+
// Call first in program(), with the game on the overworld where the
35+
// player saved: checks the party has the free slots
36+
// free_party_slots_needed() asks for, then goes Home for the black
37+
// border check. Throws UserSetupError if a check fails.
38+
void run_precheck(
39+
SingleSwitchProgramEnvironment& env,
40+
ProControllerContext& context
41+
);
42+
43+
private:
44+
void check_free_party_slots(
45+
SingleSwitchProgramEnvironment& env,
46+
ProControllerContext& context
47+
);
48+
};
49+
50+
51+
} // namespace PokemonFRLG
52+
} // namespace NintendoSwitch
53+
} // namespace PokemonAutomation
54+
#endif

‎SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RoamingLegendaryRng.cpp‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,11 +226,10 @@ void RoamingLegendaryRng::program(SingleSwitchProgramEnvironment& env, ProContro
226226
/*
227227
* Settings: Text Speed fast
228228
*/
229+
run_precheck(env, context);
229230

230231
RoamingLegendaryRng_Descriptor::Stats& stats = env.current_stats<RoamingLegendaryRng_Descriptor::Stats>();
231232

232-
home_black_border_check(env.console, context);
233-
234233
RNG_FILTERS.reset();
235234
RNG_CALIBRATION.reset_hits();
236235

‎SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RoamingLegendaryRng.h‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
#include "Common/Cpp/Options/StaticTextOption.h"
1313
#include "CommonFramework/Notifications/EventNotificationsTable.h"
1414
#include "CommonTools/Options/LanguageOCROption.h"
15-
#include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h"
1615
#include "NintendoSwitch/Options/NintendoSwitch_GoHomeWhenDoneOption.h"
1716
#include "PokemonFRLG_BlindNavigation.h"
1817
#include "PokemonFRLG_RngDisplays.h"
18+
#include "PokemonFRLG_RngProgram.h"
1919
#include "PokemonFRLG_SeedsDatabase.h"
2020

2121
namespace PokemonAutomation{
@@ -29,9 +29,11 @@ class RoamingLegendaryRng_Descriptor : public SingleSwitchProgramDescriptor{
2929
virtual std::unique_ptr<StatsTracker> make_stats() const override;
3030
};
3131

32-
class RoamingLegendaryRng : public SingleSwitchProgramInstance, private ConfigOption::Listener{
32+
// Calibrates timings to hit an RNG target for a roaming legendary.
33+
class RoamingLegendaryRng : public RngProgramInstance, private ConfigOption::Listener{
3334
public:
3435
using Descriptor = RoamingLegendaryRng_Descriptor;
36+
virtual size_t free_party_slots_needed() const override{ return 1; }
3537
~RoamingLegendaryRng();
3638
RoamingLegendaryRng();
3739
virtual void program(SingleSwitchProgramEnvironment& env, ProControllerContext &context) override;

0 commit comments

Comments
 (0)