diff --git a/src/include/pokemon_pokerus.h b/src/include/pokemon_pokerus.h new file mode 100644 index 00000000000..2b385bab4a9 --- /dev/null +++ b/src/include/pokemon_pokerus.h @@ -0,0 +1,14 @@ +#ifndef POKEMON_POKERUS_H +#define POKEMON_POKERUS_H + +#include + +#pragma once + +const char* pokerus_get_status_str(PokemonData* pdata); + +void pokerus_set_strain(PokemonData* pdata, uint8_t strain); + +void pokerus_set_days(PokemonData *pdata, uint8_t days); + +#endif // POKEMON_POKERUS_H diff --git a/src/pokemon_pokerus.c b/src/pokemon_pokerus.c new file mode 100644 index 00000000000..6ab5ac67d7f --- /dev/null +++ b/src/pokemon_pokerus.c @@ -0,0 +1,51 @@ +#include +#include + +#include + +static const char* pokerus_states[] = { + "Clean", + "Infected", + "Cured", + "", +}; + +const char* pokerus_get_status_str(PokemonData* pdata) { + uint8_t pokerus; + + pokerus = pokemon_stat_get(pdata, STAT_POKERUS, NONE); + + if(pokerus == 0x00) + return pokerus_states[0]; + + if((pokerus & 0x0f) != 0x00) + return pokerus_states[1]; + + return pokerus_states[2]; +} + +void pokerus_set_strain(PokemonData* pdata, uint8_t strain) { + uint8_t pokerus; + + /* Need to read/modify/write the existing stat */ + pokerus = pokemon_stat_get(pdata, STAT_POKERUS, NONE); + pokerus &= 0x0f; + pokerus |= (strain << 4); + + if((pokerus & 0xf0) == 0x00) + pokerus = 0; + + pokemon_stat_set(pdata, STAT_POKERUS, NONE, pokerus); +} + +void pokerus_set_days(PokemonData *pdata, uint8_t days) { + uint8_t pokerus; + + days &= 0x0f; + + /* Need to read/modify/write the existing stat */ + pokerus = pokemon_stat_get(pdata, STAT_POKERUS, NONE); + pokerus &= 0xf0; + pokerus |= days; + pokemon_stat_set(pdata, STAT_POKERUS, NONE, pokerus); +} diff --git a/src/scenes/include/pokemon_pokerus.h b/src/scenes/include/pokemon_pokerus.h deleted file mode 100644 index e62b6541f6a..00000000000 --- a/src/scenes/include/pokemon_pokerus.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef POKEMON_POKERUS_H -#define POKEMON_POKERUS_H - -#include - -#pragma once - -const char* select_pokerus_status(PokemonFap* pokemon_fap); - -#endif // POKEMON_POKERUS_H diff --git a/src/scenes/pokemon_gen.c b/src/scenes/pokemon_gen.c index e66288e102d..4fa879674f2 100644 --- a/src/scenes/pokemon_gen.c +++ b/src/scenes/pokemon_gen.c @@ -12,7 +12,7 @@ #include #include #include -#include +#include #include static void scene_change_from_main_cb(void* context, uint32_t index) { @@ -188,7 +188,7 @@ void pokemon_scene_gen_on_enter(void* context) { submenu_add_item( pokemon_fap->submenu, buf, PokemonSceneGender, scene_change_from_main_cb, pokemon_fap); - snprintf(buf, sizeof(buf), "Pokerus: %s", select_pokerus_status(pokemon_fap)); + snprintf(buf, sizeof(buf), "Pokerus: %s", pokerus_get_status_str(pokemon_fap->pdata)); submenu_add_item( pokemon_fap->submenu, buf, PokemonScenePokerus, scene_change_from_main_cb, pokemon_fap); diff --git a/src/scenes/pokemon_pokerus.c b/src/scenes/pokemon_pokerus.c index d76e61aaecc..d6f25b74a2b 100644 --- a/src/scenes/pokemon_pokerus.c +++ b/src/scenes/pokemon_pokerus.c @@ -4,13 +4,7 @@ #include #include - -static const char* pokerus_states[] = { - "Clean", - "Infected", - "Cured", - "", -}; +#include static const char* strains[] = { "None", @@ -21,16 +15,6 @@ static const char* strains[] = { "", }; -const char* select_pokerus_status(PokemonFap* pokemon_fap) { - uint8_t pokerus; - - pokerus = pokemon_stat_get(pokemon_fap->pdata, STAT_POKERUS, NONE); - - if(pokerus == 0x00) return pokerus_states[0]; - if((pokerus & 0x0f) != 0x00) return pokerus_states[1]; - return pokerus_states[2]; -} - struct pokerus_itemlist { VariableItem* strain; VariableItem* days; @@ -41,13 +25,8 @@ static void select_pokerus_rebuild_list(PokemonFap* pokemon_fap); static void select_strain_callback(VariableItem* item) { uint8_t index = variable_item_get_current_value_index(item); - uint8_t pokerus; PokemonFap* pokemon_fap = variable_item_get_context(item); - /* Need to read/modify/write the existing stat */ - pokerus = pokemon_stat_get(pokemon_fap->pdata, STAT_POKERUS, NONE); - pokerus &= 0x0f; - /* Need to set the new text from the mangled index */ variable_item_set_current_value_text(item, strains[index]); @@ -58,9 +37,8 @@ static void select_strain_callback(VariableItem* item) { index = 0x04; // Map this back to the A strain else index--; - pokerus |= (index << 4); - if((pokerus & 0xf0) == 0x00) pokerus = 0; - pokemon_stat_set(pokemon_fap->pdata, STAT_POKERUS, NONE, pokerus); + + pokerus_set_strain(pokemon_fap->pdata, index); select_pokerus_rebuild_list(pokemon_fap); variable_item_list_set_selected_item(pokemon_fap->variable_item_list, 0); @@ -68,14 +46,9 @@ static void select_strain_callback(VariableItem* item) { static void select_days_callback(VariableItem* item) { uint8_t index = variable_item_get_current_value_index(item); - uint8_t pokerus; PokemonFap* pokemon_fap = variable_item_get_context(item); - /* Need to read/modify/write the existing stat */ - pokerus = pokemon_stat_get(pokemon_fap->pdata, STAT_POKERUS, NONE); - pokerus &= 0xf0; - pokerus |= index; - pokemon_stat_set(pokemon_fap->pdata, STAT_POKERUS, NONE, pokerus); + pokerus_set_days(pokemon_fap->pdata, index); select_pokerus_rebuild_list(pokemon_fap); variable_item_list_set_selected_item(pokemon_fap->variable_item_list, 1);