Просмотр исходного кода

pokemon_shiny: Split out attribute handling, does not belong in scene

Signed-off-by: Kris Bahnsen <Kris@KBEmbedded.com>
Kris Bahnsen 1 год назад
Родитель
Сommit
2f9f53608a
5 измененных файлов с 75 добавлено и 66 удалено
  1. 10 0
      src/include/pokemon_shiny.h
  2. 61 0
      src/pokemon_shiny.c
  3. 0 8
      src/scenes/include/pokemon_shiny.h
  4. 2 2
      src/scenes/pokemon_gen.c
  5. 2 56
      src/scenes/pokemon_shiny.c

+ 10 - 0
src/include/pokemon_shiny.h

@@ -0,0 +1,10 @@
+#ifndef POKEMON_SHINY_H
+#define POKEMON_SHINY_H
+
+#pragma once
+
+bool pokemon_is_shiny(PokemonData* pdata);
+
+void pokemon_set_shiny(PokemonData *pdata, bool shiny);
+
+#endif // POKEMON_SHINY_H

+ 61 - 0
src/pokemon_shiny.c

@@ -0,0 +1,61 @@
+#include <src/include/pokemon_data.h>
+
+/* This just assumes gen ii for now */
+/* For a Gen II pokemon to be shiny, the following must be met:
+ * Spd, Def, and Spc must all be 10
+ * Atk must be 2, 3, 6, 7, 10, 11, 14, or 15
+ */
+bool pokemon_is_shiny(PokemonData* pdata) {
+    uint8_t atk_iv = pokemon_stat_get(pdata, STAT_ATK_IV, NONE);
+    uint8_t def_iv = pokemon_stat_get(pdata, STAT_DEF_IV, NONE);
+    uint8_t spd_iv = pokemon_stat_get(pdata, STAT_SPD_IV, NONE);
+    uint8_t spc_iv = pokemon_stat_get(pdata, STAT_SPC_IV, NONE);
+    bool rc = 1;
+
+    if(spd_iv != 10) rc = 0;
+    if(def_iv != 10) rc = 0;
+    if(spc_iv != 10) rc = 0;
+    switch(atk_iv) {
+    case 0:
+    case 1:
+    case 4:
+    case 5:
+    case 8:
+    case 9:
+    case 12:
+    case 13:
+        rc = 0;
+        break;
+    default:
+        break;
+    }
+
+    return rc;
+}
+
+void pokemon_set_shiny(PokemonData* pdata, bool shiny) {
+
+    if(!shiny) {
+        do {
+            /* First, reset the IV to the selected stat */
+            pokemon_stat_set(pdata, STAT_SEL, NONE, pokemon_stat_get(pdata, STAT_SEL, NONE));
+
+	    /* XXX: This may not be right? */
+            /* Next, ensure the current IVs wouldn't make the pokemon shiny */
+        } while(pokemon_is_shiny(pdata));
+    } else {
+        /* Set Def, Spd, Spc to 10 */
+        pokemon_stat_set(pdata, STAT_DEF_IV, NONE, 10);
+        pokemon_stat_set(pdata, STAT_SPD_IV, NONE, 10);
+        pokemon_stat_set(pdata, STAT_SPC_IV, NONE, 10);
+
+        /* Increase ATK IV until we hit a shiny number. Note that, this only
+         * affects IVs that are randomly generated, max IV will already be set
+         * at 15 which will make it shiny.
+         */
+        while(!pokemon_is_shiny(pdata)) {
+            pokemon_stat_set(
+                pdata, STAT_ATK_IV, NONE, pokemon_stat_get(pdata, STAT_ATK_IV, NONE) + 1);
+        }
+    }
+}

+ 0 - 8
src/scenes/include/pokemon_shiny.h

@@ -1,8 +0,0 @@
-#ifndef POKEMON_SHINY_H
-#define POKEMON_SHINY_H
-
-#pragma once
-
-bool select_shiny_is_shiny(PokemonData* pdata);
-
-#endif // POKEMON_SHINY_H

+ 2 - 2
src/scenes/pokemon_gen.c

@@ -10,7 +10,7 @@
 #include <src/scenes/include/pokemon_scene.h>
 #include <src/scenes/include/pokemon_scene.h>
 
 
 #include <src/scenes/include/pokemon_menu.h>
 #include <src/scenes/include/pokemon_menu.h>
-#include <src/scenes/include/pokemon_shiny.h>
+#include <src/include/pokemon_shiny.h>
 #include <src/include/pokemon_gender.h>
 #include <src/include/pokemon_gender.h>
 #include <src/scenes/include/pokemon_pokerus.h>
 #include <src/scenes/include/pokemon_pokerus.h>
 #include <src/include/unown_form.h>
 #include <src/include/unown_form.h>
@@ -180,7 +180,7 @@ void pokemon_scene_gen_on_enter(void* context) {
             buf,
             buf,
             sizeof(buf),
             sizeof(buf),
             "Shiny:             %s",
             "Shiny:             %s",
-            select_shiny_is_shiny(pokemon_fap->pdata) ? "Yes" : "No");
+            pokemon_is_shiny(pokemon_fap->pdata) ? "Yes" : "No");
         submenu_add_item(
         submenu_add_item(
             pokemon_fap->submenu, buf, PokemonSceneShiny, scene_change_from_main_cb, pokemon_fap);
             pokemon_fap->submenu, buf, PokemonSceneShiny, scene_change_from_main_cb, pokemon_fap);
 
 

+ 2 - 56
src/scenes/pokemon_shiny.c

@@ -1,68 +1,14 @@
 #include <gui/modules/submenu.h>
 #include <gui/modules/submenu.h>
 
 
 #include <src/include/pokemon_app.h>
 #include <src/include/pokemon_app.h>
+#include <src/include/pokemon_shiny.h>
 
 
 #include <src/scenes/include/pokemon_scene.h>
 #include <src/scenes/include/pokemon_scene.h>
 
 
-/* This just assumes gen ii for now */
-/* For a Gen II pokemon to be shiny, the following must be met:
- * Spd, Def, and Spc must all be 10
- * Atk must be 2, 3, 6, 7, 10, 11, 14, or 15
- */
-bool select_shiny_is_shiny(PokemonData* pdata) {
-    uint8_t atk_iv = pokemon_stat_get(pdata, STAT_ATK_IV, NONE);
-    uint8_t def_iv = pokemon_stat_get(pdata, STAT_DEF_IV, NONE);
-    uint8_t spd_iv = pokemon_stat_get(pdata, STAT_SPD_IV, NONE);
-    uint8_t spc_iv = pokemon_stat_get(pdata, STAT_SPC_IV, NONE);
-    bool rc = 1;
-
-    if(spd_iv != 10) rc = 0;
-    if(def_iv != 10) rc = 0;
-    if(spc_iv != 10) rc = 0;
-    switch(atk_iv) {
-    case 0:
-    case 1:
-    case 4:
-    case 5:
-    case 8:
-    case 9:
-    case 12:
-    case 13:
-        rc = 0;
-        break;
-    default:
-        break;
-    }
-
-    return rc;
-}
-
 static void select_shiny_selected_callback(void* context, uint32_t index) {
 static void select_shiny_selected_callback(void* context, uint32_t index) {
     PokemonFap* pokemon_fap = (PokemonFap*)context;
     PokemonFap* pokemon_fap = (PokemonFap*)context;
-    PokemonData* pdata = pokemon_fap->pdata;
-
-    if(!index) {
-        do {
-            /* First, reset the IV to the selected stat */
-            pokemon_stat_set(pdata, STAT_SEL, NONE, pokemon_stat_get(pdata, STAT_SEL, NONE));
-
-            /* Next, ensure the current IVs wouldn't make the pokemon shiny */
-        } while(select_shiny_is_shiny(pdata));
-    } else {
-        /* Set Def, Spd, Spc to 10 */
-        pokemon_stat_set(pdata, STAT_DEF_IV, NONE, 10);
-        pokemon_stat_set(pdata, STAT_SPD_IV, NONE, 10);
-        pokemon_stat_set(pdata, STAT_SPC_IV, NONE, 10);
 
 
-        /* Increase ATK IV until we hit a shiny number. Note that, this only
-         * affects IVs that are randomly generated, max IV will already be set
-         * at 15 which will make it shiny.
-         */
-        while(!select_shiny_is_shiny(pdata)) {
-            pokemon_stat_set(
-                pdata, STAT_ATK_IV, NONE, pokemon_stat_get(pdata, STAT_ATK_IV, NONE) + 1);
-        }
-    }
+    pokemon_set_shiny(pokemon_fap->pdata, (bool)index);
 
 
     scene_manager_previous_scene(pokemon_fap->scene_manager);
     scene_manager_previous_scene(pokemon_fap->scene_manager);
 }
 }