From 74c3fdfba79f0b18cbc94805f496295004f339e2 Mon Sep 17 00:00:00 2001 From: Eduardo Quezada Date: Sun, 4 Sep 2022 19:41:01 -0300 Subject: [PATCH] Flag to allow certain species to always have perfect IVs (like Partner Pikachu and Eevee) --- include/constants/pokemon.h | 1 + include/pokemon.h | 2 +- src/pokemon.c | 87 ++++++++++++++++++++----------------- 3 files changed, 50 insertions(+), 40 deletions(-) diff --git a/include/constants/pokemon.h b/include/constants/pokemon.h index f5d0e9509..dd813e509 100644 --- a/include/constants/pokemon.h +++ b/include/constants/pokemon.h @@ -350,6 +350,7 @@ #define FLAG_GALARIAN_FORM (1 << 4) #define FLAG_HISUIAN_FORM (1 << 5) #define FLAG_GENDER_DIFFERENCE (1 << 6) +#define FLAG_ALL_PERFECT_IVS (1 << 7) #define LEGENDARY_PERFECT_IV_COUNT 3 diff --git a/include/pokemon.h b/include/pokemon.h index 94fdff91d..648a1f5bb 100644 --- a/include/pokemon.h +++ b/include/pokemon.h @@ -323,7 +323,7 @@ struct BaseStats u8 safariZoneFleeRate; u8 bodyColor : 7; u8 noFlip : 1; - u8 flags; + u16 flags; }; #include "constants/battle_config.h" diff --git a/src/pokemon.c b/src/pokemon.c index 350aebf0b..9b760dbb9 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -3370,50 +3370,59 @@ void CreateBoxMon(struct BoxPokemon *boxMon, u16 species, u8 level, u8 fixedIV, iv = (value & (MAX_IV_MASK << 10)) >> 10; SetBoxMonData(boxMon, MON_DATA_SPDEF_IV, &iv); - #if P_LEGENDARY_PERFECT_IVS >= GEN_6 - if (gBaseStats[species].flags & (FLAG_LEGENDARY | FLAG_MYTHICAL | FLAG_ULTRA_BEAST)) + if (gBaseStats[species].flags & FLAG_ALL_PERFECT_IVS) + { + iv = MAX_PER_STAT_IVS; + SetBoxMonData(boxMon, MON_DATA_HP_IV, &iv); + SetBoxMonData(boxMon, MON_DATA_ATK_IV, &iv); + SetBoxMonData(boxMon, MON_DATA_DEF_IV, &iv); + SetBoxMonData(boxMon, MON_DATA_SPEED_IV, &iv); + SetBoxMonData(boxMon, MON_DATA_SPATK_IV, &iv); + SetBoxMonData(boxMon, MON_DATA_SPDEF_IV, &iv); + } + #if P_LEGENDARY_PERFECT_IVS >= GEN_6 + else if (gBaseStats[species].flags & (FLAG_LEGENDARY | FLAG_MYTHICAL | FLAG_ULTRA_BEAST)) + { + iv = MAX_PER_STAT_IVS; + // Initialize a list of IV indices. + for (i = 0; i < NUM_STATS; i++) { - iv = MAX_PER_STAT_IVS; - // Initialize a list of IV indices. - for (i = 0; i < NUM_STATS; i++) - { - availableIVs[i] = i; - } + availableIVs[i] = i; + } - // Select the 3 IVs that will be perfected. - for (i = 0; i < LEGENDARY_PERFECT_IV_COUNT; i++) + // Select the 3 IVs that will be perfected. + for (i = 0; i < LEGENDARY_PERFECT_IV_COUNT; i++) + { + u8 index = Random() % (NUM_STATS - i); + selectedIvs[i] = availableIVs[index]; + RemoveIVIndexFromList(availableIVs, index); + } + for (i = 0; i < LEGENDARY_PERFECT_IV_COUNT; i++) + { + switch (selectedIvs[i]) { - u8 index = Random() % (NUM_STATS - i); - selectedIvs[i] = availableIVs[index]; - RemoveIVIndexFromList(availableIVs, index); - } - for (i = 0; i < LEGENDARY_PERFECT_IV_COUNT; i++) - { - switch (selectedIvs[i]) - { - case STAT_HP: - SetBoxMonData(boxMon, MON_DATA_HP_IV, &iv); - break; - case STAT_ATK: - SetBoxMonData(boxMon, MON_DATA_ATK_IV, &iv); - break; - case STAT_DEF: - SetBoxMonData(boxMon, MON_DATA_DEF_IV, &iv); - break; - case STAT_SPEED: - SetBoxMonData(boxMon, MON_DATA_SPEED_IV, &iv); - break; - case STAT_SPATK: - SetBoxMonData(boxMon, MON_DATA_SPATK_IV, &iv); - break; - case STAT_SPDEF: - SetBoxMonData(boxMon, MON_DATA_SPDEF_IV, &iv); - break; - } + case STAT_HP: + SetBoxMonData(boxMon, MON_DATA_HP_IV, &iv); + break; + case STAT_ATK: + SetBoxMonData(boxMon, MON_DATA_ATK_IV, &iv); + break; + case STAT_DEF: + SetBoxMonData(boxMon, MON_DATA_DEF_IV, &iv); + break; + case STAT_SPEED: + SetBoxMonData(boxMon, MON_DATA_SPEED_IV, &iv); + break; + case STAT_SPATK: + SetBoxMonData(boxMon, MON_DATA_SPATK_IV, &iv); + break; + case STAT_SPDEF: + SetBoxMonData(boxMon, MON_DATA_SPDEF_IV, &iv); + break; } } - #endif - + } + #endif } if (gBaseStats[species].abilities[1])