1010#include < stdint.h>
1111#include < utility>
1212#include < vector>
13+ #include < stdexcept>
1314#include " Pokemon_StatsCalculation.h"
1415
1516namespace PokemonAutomation {
@@ -28,6 +29,25 @@ struct AdvIVs{
2829 uint8_t spatk = 0 ;
2930 uint8_t spdef = 0 ;
3031 uint8_t speed = 0 ;
32+
33+ uint8_t & operator [](int index){
34+ switch (index){
35+ case 0 :
36+ return hp;
37+ case 1 :
38+ return attack;
39+ case 2 :
40+ return defense;
41+ case 3 :
42+ return speed;
43+ case 4 :
44+ return spatk;
45+ case 5 :
46+ return spdef;
47+ default :
48+ throw std::runtime_error (" Invalid IVs index. Please report this as a bug." );
49+ }
50+ }
3151};
3252
3353enum class AdvNature {
@@ -79,12 +99,19 @@ enum class AdvShinyType{
7999};
80100
81101enum class AdvRngMethod {
82- Method1,
83- Method2,
84- Method4,
102+ Method1, // egg normal
103+ Method2, // egg split
104+ Method3, // egg alternate
105+ Method4, // egg mixed
85106 Any
86107};
87108
109+ enum class AdvEggCompatibility {
110+ low,
111+ medium,
112+ high
113+ };
114+
88115struct AdvRngState {
89116 uint16_t seed;
90117 uint64_t advance;
@@ -94,10 +121,18 @@ struct AdvRngState{
94121 uint32_t s2;
95122 uint32_t s3;
96123 uint32_t s4;
124+ uint32_t s5;
97125
98126 bool operator <(const AdvRngState& rhs) const noexcept {
99127 return this ->advance < rhs.advance ;
100128 }
129+
130+ bool operator ==(const AdvRngState& rhs) const noexcept {
131+ return (
132+ this ->advance == rhs.advance
133+ && this ->seed == rhs.seed \
134+ );
135+ }
101136};
102137
103138struct AdvEncounterSlot {
@@ -125,6 +160,15 @@ struct AdvWildPokemonResult{
125160 uint8_t level;
126161};
127162
163+ struct AdvEggResult {
164+ uint32_t pid;
165+ uint8_t gender;
166+ AdvNature nature;
167+ AdvAbility ability;
168+ AdvIVs ivs;
169+ AdvIVs inherited_ivs;
170+ };
171+
128172struct AdvObservedPokemon {
129173 std::string species;
130174 AdvGender gender;
@@ -155,9 +199,22 @@ void level_up_observed_pokemon(AdvObservedPokemon& pokemon, const StatReads& new
155199// returns the appropriate NatureAdjustments for an AdvNature
156200Pokemon::NatureAdjustments nature_to_adjustment (AdvNature nature);
157201
202+ Pokemon::AdvNature string_to_nature (const std::string& nature_string);
203+ std::string nature_to_string (const AdvNature& nature);
204+
205+ std::string gender_to_string (const AdvGender& gender);
206+
207+ AdvGender gender_from_gender_value (uint8_t gender_value, int16_t threshold);
208+
158209// returns search filters that correspond with observed stats
159210AdvRngFilters observation_to_filters (const AdvObservedPokemon& observation, const BaseStats& basestats, AdvRngMethod method = AdvRngMethod::Method1);
160211
212+ AdvPokemonResult egg_to_pokemon (
213+ AdvEggResult& egg_result,
214+ AdvIVs& parentA_ivs,
215+ AdvIVs& parentB_ivs
216+ );
217+
161218class AdvRngSearcher {
162219public:
163220 uint16_t seed;
@@ -230,6 +287,90 @@ class AdvRngWildSearcher{
230287};
231288
232289
290+ class AdvRngEggSearcher {
291+ public:
292+ uint16_t held_seed;
293+ AdvRngState held_state;
294+
295+ uint16_t pickup_seed;
296+ AdvRngState pickup_state;
297+
298+ AdvRngEggSearcher (uint16_t held_seed, AdvRngState held_state, uint16_t pickup_seed, AdvRngState pickup_state);
299+ AdvRngEggSearcher (
300+ uint16_t held_seed, uint64_t min_seed_advances,
301+ uint16_t pickup_seed, uint64_t min_pickup_advances,
302+ AdvRngMethod method = AdvRngMethod::Any
303+ );
304+
305+ void set_held_seed (uint16_t seed);
306+ void set_held_state_advances (uint64_t advances);
307+ void advance_held_state ();
308+
309+ void set_pickup_seed (uint16_t seed);
310+ void set_pickup_state_advances (uint64_t advances);
311+ void advance_pickup_state ();
312+
313+ AdvEggResult generate_egg ();
314+ AdvPokemonResult generate_pokemon (AdvIVs& parentA_ivs, AdvIVs& parentB_ivs);
315+
316+ std::vector<std::pair<AdvRngState, AdvRngState>> search (
317+ AdvRngFilters& target,
318+ const std::vector<uint16_t >& held_seeds,
319+ uint64_t min_held_advances,
320+ uint64_t max_held_advances,
321+ const std::vector<uint16_t >& pickup_seeds,
322+ uint64_t min_pickup_advances,
323+ uint64_t max_pickup_advances,
324+ AdvIVs& parentA_ivs,
325+ AdvIVs& parentB_ivs,
326+ AdvEggCompatibility compatibility,
327+ int16_t gender_threshold = 126 ,
328+ uint16_t tid_xor_sid = 0
329+ );
330+
331+ private:
332+
333+ void search_held_advances_range (
334+ std::vector<std::pair<AdvRngState, AdvRngState>>& hits,
335+ AdvRngFilters& target,
336+ uint64_t min_held_advances,
337+ uint64_t max_held_advances,
338+ const std::vector<uint16_t >& pickup_seeds,
339+ uint64_t min_pickup_advances,
340+ uint64_t max_pickup_advances,
341+ AdvIVs& parentA_ivs,
342+ AdvIVs& parentB_ivs,
343+ AdvEggCompatibility compatibility,
344+ int16_t gender_threshold,
345+ uint16_t tid_xor_sid
346+ );
347+
348+ void search_pickups (
349+ std::vector<std::pair<AdvRngState, AdvRngState>>& hits,
350+ AdvRngFilters& target,
351+ uint16_t held_pid_half,
352+ const std::vector<uint16_t >& pickup_seeds,
353+ uint64_t min_pickup_advances,
354+ uint64_t max_pickup_advances,
355+ AdvIVs& parentA_ivs,
356+ AdvIVs& parentB_ivs,
357+ int16_t gender_threshold,
358+ uint16_t tid_xor_sid
359+ );
360+
361+ void search_pickup_advances_range (
362+ std::vector<std::pair<AdvRngState, AdvRngState>>& hits,
363+ AdvRngFilters& target,
364+ uint16_t held_pid_half,
365+ uint64_t min_pickup_advances,
366+ uint64_t max_pickup_advances,
367+ AdvIVs& parentA_ivs,
368+ AdvIVs& parentB_ivs,
369+ int16_t gender_threshold,
370+ uint16_t tid_xor_sid
371+ );
372+ };
373+
233374
234375}
235376}
0 commit comments