From eb7ddeb66cf433502d7b92e70f8d60aa71b7b0df Mon Sep 17 00:00:00 2001 From: LOuroboros Date: Thu, 15 Feb 2024 04:01:34 -0300 Subject: [PATCH] Updated the way in which ScriptGiveMonParameterized and ScrCmd_givemon chooe a default ability (#4192) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Updated the way in which ScrCmd_givemon and ScriptGiveMon assign a default ability When an abilityNum is not assigned in a call to givemon performed inside of an overworld script, ScriptGiveMonParameterized will make sure to generate an abilityNum of 0 or 1 in the same way vanilla does it; by defaulting to 0, and then tweaking it based on the least relevant bit of the Pokémon's personality. ScriptGiveMon will set the default ability of a Pokémon in the same way now too, because even though it was rewritten in #3924, it should ideally produce a Pokémon in a similar way than vanilla does it. * Removed pointless abilityNum setup in ScriptGiveMonParameterized --- include/constants/pokemon.h | 3 +++ src/script_pokemon_util.c | 10 +++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/include/constants/pokemon.h b/include/constants/pokemon.h index 13b76ed328..49de31f1b3 100644 --- a/include/constants/pokemon.h +++ b/include/constants/pokemon.h @@ -323,6 +323,9 @@ #define NUM_NORMAL_ABILITY_SLOTS 2 #define NUM_HIDDEN_ABILITY_SLOTS 1 +// Used as a signal for givemon to generate a default ability in the vanilla Pokémon Emerald way. +#define NUM_ABILITY_VANILLA 0xFF + #define LEGENDARY_PERFECT_IV_COUNT 3 #endif // GUARD_CONSTANTS_POKEMON_H diff --git a/src/script_pokemon_util.c b/src/script_pokemon_util.c index f37a70a146..8ed44e8f59 100644 --- a/src/script_pokemon_util.c +++ b/src/script_pokemon_util.c @@ -345,7 +345,11 @@ u32 ScriptGiveMonParameterized(u16 species, u8 level, u16 item, u8 ball, u8 natu } // ability - if (abilityNum >= NUM_ABILITY_SLOTS || GetAbilityBySpecies(species, abilityNum) == ABILITY_NONE) + if (abilityNum == NUM_ABILITY_VANILLA) + { + abilityNum = GetMonData(&mon, MON_DATA_PERSONALITY) & 1; + } + else if (abilityNum > NUM_NORMAL_ABILITY_SLOTS || GetAbilityBySpecies(species, abilityNum) == ABILITY_NONE) { do { abilityNum = Random() % NUM_ABILITY_SLOTS; // includes hidden abilities @@ -410,7 +414,7 @@ u32 ScriptGiveMon(u16 species, u8 level, u16 item) MAX_PER_STAT_IVS + 1, MAX_PER_STAT_IVS + 1, MAX_PER_STAT_IVS + 1}; // ScriptGiveMonParameterized won't touch the stats' IV. u16 moves[MAX_MON_MOVES] = {MOVE_NONE, MOVE_NONE, MOVE_NONE, MOVE_NONE}; - return ScriptGiveMonParameterized(species, level, item, ITEM_POKE_BALL, NUM_NATURES, NUM_ABILITY_SLOTS, MON_GENDERLESS, evs, ivs, moves, FALSE, FALSE, NUMBER_OF_MON_TYPES); + return ScriptGiveMonParameterized(species, level, item, ITEM_POKE_BALL, NUM_NATURES, NUM_ABILITY_VANILLA, MON_GENDERLESS, evs, ivs, moves, FALSE, FALSE, NUMBER_OF_MON_TYPES); } #define PARSE_FLAG(n, default_) (flags & (1 << (n))) ? VarGet(ScriptReadHalfword(ctx)) : (default_) @@ -424,7 +428,7 @@ void ScrCmd_givemon(struct ScriptContext *ctx) u16 item = PARSE_FLAG(0, ITEM_NONE); u8 ball = PARSE_FLAG(1, ITEM_POKE_BALL); u8 nature = PARSE_FLAG(2, NUM_NATURES); - u8 abilityNum = PARSE_FLAG(3, NUM_ABILITY_SLOTS); + u8 abilityNum = PARSE_FLAG(3, NUM_ABILITY_VANILLA); u8 gender = PARSE_FLAG(4, MON_GENDERLESS); // TODO: Find a better way to assign a random gender. u8 hpEv = PARSE_FLAG(5, 0); u8 atkEv = PARSE_FLAG(6, 0);