22
33#include <src/include/pokemon_app.h>
44#include <src/include/pokemon_data.h>
5+ #include <src/include/pokemon_gender.h>
56
67#include <src/scenes/include/pokemon_scene.h>
78
8- static const char * gender_str [] = {
9- "Unknown" ,
10- "Female" ,
11- "Male" ,
12- };
13-
14- /* This returns a string pointer if the gender is static, NULL if it is not and
15- * the gender needs to be calculated.
16- */
17- const char * select_gender_is_static (PokemonData * pdata , uint8_t ratio ) {
18- switch (ratio ) {
19- case 0xFF :
20- return gender_str [0 ];
21- case 0xFE :
22- return gender_str [1 ];
23- case 0x00 :
24- if (pokemon_stat_get (pdata , STAT_NUM , NONE ) != 0xEB ) { // Tyrogue can be either gender
25- return gender_str [2 ];
26- }
27- break ;
28- default :
29- break ;
30- }
31-
32- return NULL ;
33- }
34-
35- const char * select_gender_get (PokemonData * pdata ) {
36- uint8_t ratio = table_stat_base_get (
37- pdata -> pokemon_table ,
38- pokemon_stat_get (pdata , STAT_NUM , NONE ),
39- STAT_BASE_GENDER_RATIO ,
40- NONE );
41- uint8_t atk_iv ;
42- const char * rc ;
43-
44- rc = select_gender_is_static (pdata , ratio );
45- if (rc ) return rc ;
46-
47- /* Falling through here means now we need to calculate the gender from
48- * its ratio and ATK_IV.
49- */
50- atk_iv = pokemon_stat_get (pdata , STAT_ATK_IV , NONE );
51- if (atk_iv * 17 <= ratio )
52- return gender_str [1 ];
53- else
54- return gender_str [2 ];
55- }
56-
579static void select_gender_selected_callback (void * context , uint32_t index ) {
5810 PokemonFap * pokemon_fap = (PokemonFap * )context ;
59- PokemonData * pdata = pokemon_fap -> pdata ;
60- uint8_t ratio = table_stat_base_get (
61- pdata -> pokemon_table ,
62- pokemon_stat_get (pdata , STAT_NUM , NONE ),
63- STAT_BASE_GENDER_RATIO ,
64- NONE );
65- uint8_t atk_iv = pokemon_stat_get (pdata , STAT_ATK_IV , NONE );
66-
67- /* If we need to make the pokemon a male, increase atk IV until it exceeds
68- * the gender ratio.
69- *
70- * Note that, there is no checking here for impossible situations as the
71- * scene enter function will immediately quit if its not possible to change
72- * the gender (the extremes of gender_ratio value).
73- *
74- * The check for gender is a percentage, if ATK_IV*(255/15) <= the ratio,
75- * then the pokemon is a female. The gender ratio values end up being:
76- * DEF GENDER_F0 EQU 0 percent
77- * DEF GENDER_F12_5 EQU 12 percent + 1
78- * DEF GENDER_F25 EQU 25 percent
79- * DEF GENDER_F50 EQU 50 percent
80- * DEF GENDER_F75 EQU 75 percent
81- * DEF GENDER_F100 EQU 100 percent - 1
82- * Where percent is (255/100)
83- */
84- if (index ) {
85- while ((atk_iv * 17 ) <= ratio ) atk_iv ++ ;
86- } else {
87- while ((atk_iv * 17 ) > ratio ) atk_iv -- ;
88- }
8911
90- pokemon_stat_set ( pdata , STAT_ATK_IV , NONE , atk_iv );
12+ pokemon_gender_set ( pokemon_fap -> pdata , index );
9113
9214 scene_manager_previous_scene (pokemon_fap -> scene_manager );
9315}
@@ -98,10 +20,10 @@ void pokemon_scene_select_gender_on_enter(void* context) {
9820 submenu_reset (pokemon_fap -> submenu );
9921
10022 submenu_add_item (
101- pokemon_fap -> submenu , "Female" , 0 , select_gender_selected_callback , pokemon_fap );
23+ pokemon_fap -> submenu , "Female" , GENDER_FEMALE , select_gender_selected_callback , pokemon_fap );
10224
10325 submenu_add_item (
104- pokemon_fap -> submenu , "Male" , 1 , select_gender_selected_callback , pokemon_fap );
26+ pokemon_fap -> submenu , "Male" , GENDER_MALE , select_gender_selected_callback , pokemon_fap );
10527}
10628
10729bool pokemon_scene_select_gender_on_event (void * context , SceneManagerEvent event )
0 commit comments