Skip to content

Commit 8685af7

Browse files
committed
pokemon_shiny: Split out attribute handling, does not belong in scene
Signed-off-by: Kris Bahnsen <Kris@KBEmbedded.com>
1 parent 2208165 commit 8685af7

File tree

5 files changed

+75
-66
lines changed

5 files changed

+75
-66
lines changed

src/include/pokemon_shiny.h

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#ifndef POKEMON_SHINY_H
2+
#define POKEMON_SHINY_H
3+
4+
#pragma once
5+
6+
bool pokemon_is_shiny(PokemonData* pdata);
7+
8+
void pokemon_set_shiny(PokemonData *pdata, bool shiny);
9+
10+
#endif // POKEMON_SHINY_H

src/pokemon_shiny.c

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#include <src/include/pokemon_data.h>
2+
3+
/* This just assumes gen ii for now */
4+
/* For a Gen II pokemon to be shiny, the following must be met:
5+
* Spd, Def, and Spc must all be 10
6+
* Atk must be 2, 3, 6, 7, 10, 11, 14, or 15
7+
*/
8+
bool pokemon_is_shiny(PokemonData* pdata) {
9+
uint8_t atk_iv = pokemon_stat_get(pdata, STAT_ATK_IV, NONE);
10+
uint8_t def_iv = pokemon_stat_get(pdata, STAT_DEF_IV, NONE);
11+
uint8_t spd_iv = pokemon_stat_get(pdata, STAT_SPD_IV, NONE);
12+
uint8_t spc_iv = pokemon_stat_get(pdata, STAT_SPC_IV, NONE);
13+
bool rc = 1;
14+
15+
if(spd_iv != 10) rc = 0;
16+
if(def_iv != 10) rc = 0;
17+
if(spc_iv != 10) rc = 0;
18+
switch(atk_iv) {
19+
case 0:
20+
case 1:
21+
case 4:
22+
case 5:
23+
case 8:
24+
case 9:
25+
case 12:
26+
case 13:
27+
rc = 0;
28+
break;
29+
default:
30+
break;
31+
}
32+
33+
return rc;
34+
}
35+
36+
void pokemon_set_shiny(PokemonData* pdata, bool shiny) {
37+
38+
if(!shiny) {
39+
do {
40+
/* First, reset the IV to the selected stat */
41+
pokemon_stat_set(pdata, STAT_SEL, NONE, pokemon_stat_get(pdata, STAT_SEL, NONE));
42+
43+
/* XXX: This may not be right? */
44+
/* Next, ensure the current IVs wouldn't make the pokemon shiny */
45+
} while(pokemon_is_shiny(pdata));
46+
} else {
47+
/* Set Def, Spd, Spc to 10 */
48+
pokemon_stat_set(pdata, STAT_DEF_IV, NONE, 10);
49+
pokemon_stat_set(pdata, STAT_SPD_IV, NONE, 10);
50+
pokemon_stat_set(pdata, STAT_SPC_IV, NONE, 10);
51+
52+
/* Increase ATK IV until we hit a shiny number. Note that, this only
53+
* affects IVs that are randomly generated, max IV will already be set
54+
* at 15 which will make it shiny.
55+
*/
56+
while(!pokemon_is_shiny(pdata)) {
57+
pokemon_stat_set(
58+
pdata, STAT_ATK_IV, NONE, pokemon_stat_get(pdata, STAT_ATK_IV, NONE) + 1);
59+
}
60+
}
61+
}

src/scenes/include/pokemon_shiny.h

-8
This file was deleted.

src/scenes/pokemon_gen.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include <src/scenes/include/pokemon_scene.h>
1111

1212
#include <src/scenes/include/pokemon_menu.h>
13-
#include <src/scenes/include/pokemon_shiny.h>
13+
#include <src/include/pokemon_shiny.h>
1414
#include <src/include/pokemon_gender.h>
1515
#include <src/scenes/include/pokemon_pokerus.h>
1616
#include <src/include/unown_form.h>
@@ -180,7 +180,7 @@ void pokemon_scene_gen_on_enter(void* context) {
180180
buf,
181181
sizeof(buf),
182182
"Shiny: %s",
183-
select_shiny_is_shiny(pokemon_fap->pdata) ? "Yes" : "No");
183+
pokemon_is_shiny(pokemon_fap->pdata) ? "Yes" : "No");
184184
submenu_add_item(
185185
pokemon_fap->submenu, buf, PokemonSceneShiny, scene_change_from_main_cb, pokemon_fap);
186186

src/scenes/pokemon_shiny.c

+2-56
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,14 @@
11
#include <gui/modules/submenu.h>
22

33
#include <src/include/pokemon_app.h>
4+
#include <src/include/pokemon_shiny.h>
45

56
#include <src/scenes/include/pokemon_scene.h>
67

7-
/* This just assumes gen ii for now */
8-
/* For a Gen II pokemon to be shiny, the following must be met:
9-
* Spd, Def, and Spc must all be 10
10-
* Atk must be 2, 3, 6, 7, 10, 11, 14, or 15
11-
*/
12-
bool select_shiny_is_shiny(PokemonData* pdata) {
13-
uint8_t atk_iv = pokemon_stat_get(pdata, STAT_ATK_IV, NONE);
14-
uint8_t def_iv = pokemon_stat_get(pdata, STAT_DEF_IV, NONE);
15-
uint8_t spd_iv = pokemon_stat_get(pdata, STAT_SPD_IV, NONE);
16-
uint8_t spc_iv = pokemon_stat_get(pdata, STAT_SPC_IV, NONE);
17-
bool rc = 1;
18-
19-
if(spd_iv != 10) rc = 0;
20-
if(def_iv != 10) rc = 0;
21-
if(spc_iv != 10) rc = 0;
22-
switch(atk_iv) {
23-
case 0:
24-
case 1:
25-
case 4:
26-
case 5:
27-
case 8:
28-
case 9:
29-
case 12:
30-
case 13:
31-
rc = 0;
32-
break;
33-
default:
34-
break;
35-
}
36-
37-
return rc;
38-
}
39-
408
static void select_shiny_selected_callback(void* context, uint32_t index) {
419
PokemonFap* pokemon_fap = (PokemonFap*)context;
42-
PokemonData* pdata = pokemon_fap->pdata;
43-
44-
if(!index) {
45-
do {
46-
/* First, reset the IV to the selected stat */
47-
pokemon_stat_set(pdata, STAT_SEL, NONE, pokemon_stat_get(pdata, STAT_SEL, NONE));
48-
49-
/* Next, ensure the current IVs wouldn't make the pokemon shiny */
50-
} while(select_shiny_is_shiny(pdata));
51-
} else {
52-
/* Set Def, Spd, Spc to 10 */
53-
pokemon_stat_set(pdata, STAT_DEF_IV, NONE, 10);
54-
pokemon_stat_set(pdata, STAT_SPD_IV, NONE, 10);
55-
pokemon_stat_set(pdata, STAT_SPC_IV, NONE, 10);
5610

57-
/* Increase ATK IV until we hit a shiny number. Note that, this only
58-
* affects IVs that are randomly generated, max IV will already be set
59-
* at 15 which will make it shiny.
60-
*/
61-
while(!select_shiny_is_shiny(pdata)) {
62-
pokemon_stat_set(
63-
pdata, STAT_ATK_IV, NONE, pokemon_stat_get(pdata, STAT_ATK_IV, NONE) + 1);
64-
}
65-
}
11+
pokemon_set_shiny(pokemon_fap->pdata, (bool)index);
6612

6713
scene_manager_previous_scene(pokemon_fap->scene_manager);
6814
}

0 commit comments

Comments
 (0)