From d7a38a1a9179ae58fbbe0fde533f02b68ed227f4 Mon Sep 17 00:00:00 2001 From: Eduardo Quezada Date: Sat, 27 Jul 2024 12:58:26 -0400 Subject: [PATCH 1/2] Changed EVO_OVERWORLD_STEPS to use an EWRAM variable --- data/scripts/debug.inc | 10 ++++++++++ include/constants/pokemon.h | 2 +- include/pokemon.h | 1 + src/debug.c | 17 +++++++++++++++++ src/field_control_avatar.c | 26 +++++--------------------- src/party_menu.c | 3 +++ src/pokemon.c | 3 ++- test/species.c | 3 --- 8 files changed, 39 insertions(+), 26 deletions(-) diff --git a/data/scripts/debug.inc b/data/scripts/debug.inc index 02a93a4d9c7b..12dc693fd02a 100644 --- a/data/scripts/debug.inc +++ b/data/scripts/debug.inc @@ -439,4 +439,14 @@ Debug_EventScript_InflictStatus1_Text_Freeze: Debug_EventScript_InflictStatus1_Text_Frostbite: .string "Frostbite$" +Debug_EventScript_EWRAMCounters:: + callnative CheckEWRAMCounters + msgbox Debug_EventScript_EWRAMCounters_Text, MSGBOX_DEFAULT + release + end + +Debug_EventScript_EWRAMCounters_Text:: + .string "Follower Steps: {STR_VAR_1}.\n" + .string "Fishing Chain: {STR_VAR_2}.$" + .endif diff --git a/include/constants/pokemon.h b/include/constants/pokemon.h index bebda44834cd..33988ad4b876 100644 --- a/include/constants/pokemon.h +++ b/include/constants/pokemon.h @@ -297,7 +297,7 @@ #define EVO_RECOIL_DAMAGE_FEMALE 49 // Pokémon levels up after having suffered specified amount of non-fainting recoil damage as a female #define EVO_ITEM_COUNT_999 50 // Pokémon levels up after trainer has collected 999 of a specific item #define EVO_DEFEAT_WITH_ITEM 51 // Pokémon levels up after having defeat 3 Pokémon of the same species holding the specified item -#define EVO_OVERWORLD_STEPS 52 // Pokémon levels up after having taken a specific amount of steps in the overworld +#define EVO_OVERWORLD_STEPS 52 // Pokémon levels up after having taken a specific amount of steps in the overworld (or as the party lead if OW_FOLLOWERS_ENABLED is FALSE) without switching // Evolution 'modes,' for GetEvolutionTargetSpecies #define EVO_MODE_NORMAL 0 diff --git a/include/pokemon.h b/include/pokemon.h index 920aee7e2ff2..b299ab7d61e5 100644 --- a/include/pokemon.h +++ b/include/pokemon.h @@ -684,6 +684,7 @@ extern struct Pokemon gPlayerParty[PARTY_SIZE]; extern u8 gEnemyPartyCount; extern struct Pokemon gEnemyParty[PARTY_SIZE]; extern struct SpriteTemplate gMultiuseSpriteTemplate; +extern u16 gFollowerSteps; extern const struct MoveInfo gMovesInfo[]; extern const u8 gFacilityClassToPicIndex[]; diff --git a/src/debug.c b/src/debug.c index 049e2f0ed865..f4b6f68840ea 100644 --- a/src/debug.c +++ b/src/debug.c @@ -99,6 +99,7 @@ enum UtilDebugMenu DEBUG_UTIL_MENU_ITEM_CHEAT, DEBUG_UTIL_MENU_ITEM_EXPANSION_VER, DEBUG_UTIL_MENU_ITEM_BERRY_FUNCTIONS, + DEBUG_UTIL_MENU_ITEM_EWRAM_COUNTERS, }; enum GivePCBagDebugMenu @@ -374,6 +375,7 @@ static void DebugAction_Util_Player_Id(u8 taskId); static void DebugAction_Util_CheatStart(u8 taskId); static void DebugAction_Util_ExpansionVersion(u8 taskId); static void DebugAction_Util_BerryFunctions(u8 taskId); +static void DebugAction_Util_CheckEWRAMCounters(u8 taskId); static void DebugAction_OpenPCBagFillMenu(u8 taskId); static void DebugAction_PCBag_Fill_PCBoxes_Fast(u8 taskId); @@ -476,6 +478,7 @@ extern const u8 Debug_CheckSaveBlock[]; extern const u8 Debug_CheckROMSpace[]; extern const u8 Debug_BoxFilledMessage[]; extern const u8 Debug_ShowExpansionVersion[]; +extern const u8 Debug_EventScript_EWRAMCounters[]; extern const u8 Debug_BerryPestsDisabled[]; extern const u8 Debug_BerryWeedsDisabled[]; @@ -532,6 +535,7 @@ static const u8 sDebugText_Util_Player_Id[] = _("New Trainer ID") static const u8 sDebugText_Util_CheatStart[] = _("Cheat start"); static const u8 sDebugText_Util_ExpansionVersion[] = _("Expansion Version"); static const u8 sDebugText_Util_BerryFunctions[] = _("Berry Functions…{CLEAR_TO 110}{RIGHT_ARROW}"); +static const u8 sDebugText_Util_EWRAMCounters[] = _("EWRAM Counters…{CLEAR_TO 110}{RIGHT_ARROW}"); // PC/Bag Menu static const u8 sDebugText_PCBag_Fill[] = _("Fill…{CLEAR_TO 110}{RIGHT_ARROW}"); static const u8 sDebugText_PCBag_Fill_Pc_Fast[] = _("Fill PC Boxes Fast"); @@ -720,6 +724,7 @@ static const struct ListMenuItem sDebugMenu_Items_Utilities[] = [DEBUG_UTIL_MENU_ITEM_CHEAT] = {sDebugText_Util_CheatStart, DEBUG_UTIL_MENU_ITEM_CHEAT}, [DEBUG_UTIL_MENU_ITEM_EXPANSION_VER] = {sDebugText_Util_ExpansionVersion, DEBUG_UTIL_MENU_ITEM_EXPANSION_VER}, [DEBUG_UTIL_MENU_ITEM_BERRY_FUNCTIONS] = {sDebugText_Util_BerryFunctions, DEBUG_UTIL_MENU_ITEM_BERRY_FUNCTIONS}, + [DEBUG_UTIL_MENU_ITEM_EWRAM_COUNTERS] = {sDebugText_Util_EWRAMCounters, DEBUG_UTIL_MENU_ITEM_EWRAM_COUNTERS}, }; static const struct ListMenuItem sDebugMenu_Items_PCBag[] = @@ -889,6 +894,7 @@ static void (*const sDebugMenu_Actions_Utilities[])(u8) = [DEBUG_UTIL_MENU_ITEM_CHEAT] = DebugAction_Util_CheatStart, [DEBUG_UTIL_MENU_ITEM_EXPANSION_VER] = DebugAction_Util_ExpansionVersion, [DEBUG_UTIL_MENU_ITEM_BERRY_FUNCTIONS] = DebugAction_Util_BerryFunctions, + [DEBUG_UTIL_MENU_ITEM_EWRAM_COUNTERS] = DebugAction_Util_CheckEWRAMCounters, }; static void (*const sDebugMenu_Actions_PCBag[])(u8) = @@ -5113,4 +5119,15 @@ static void DebugAction_Party_ClearParty(u8 taskId) Debug_DestroyMenu_Full(taskId); } +void CheckEWRAMCounters(struct ScriptContext *ctx) +{ + ConvertIntToDecimalStringN(gStringVar1, gFollowerSteps, STR_CONV_MODE_LEFT_ALIGN, 5); + ConvertIntToDecimalStringN(gStringVar2, gChainFishingDexNavStreak, STR_CONV_MODE_LEFT_ALIGN, 5); +} + +static void DebugAction_Util_CheckEWRAMCounters(u8 taskId) +{ + Debug_DestroyMenu_Full_Script(taskId, Debug_EventScript_EWRAMCounters); +} + #endif //DEBUG_OVERWORLD_MENU == TRUE diff --git a/src/field_control_avatar.c b/src/field_control_avatar.c index 5e709a9fb0d0..891c07713b08 100644 --- a/src/field_control_avatar.c +++ b/src/field_control_avatar.c @@ -69,7 +69,7 @@ static bool8 TryStartWarpEventScript(struct MapPosition *, u16); static bool8 TryStartMiscWalkingScripts(u16); static bool8 TryStartStepCountScript(u16); static void UpdateFriendshipStepCounter(void); -static void UpdateLetsGoEvolutionTracker(void); +static void UpdateFollowerStepCounter(void); #if OW_POISON_DAMAGE < GEN_5 static bool8 UpdatePoisonStepCounter(void); #endif // OW_POISON_DAMAGE @@ -566,7 +566,7 @@ static bool8 TryStartStepCountScript(u16 metatileBehavior) IncrementRematchStepCounter(); UpdateFriendshipStepCounter(); UpdateFarawayIslandStepCounter(); - UpdateLetsGoEvolutionTracker(); + UpdateFollowerStepCounter(); if (!(gPlayerAvatar.flags & PLAYER_AVATAR_FLAG_FORCED_MOVE) && !MetatileBehavior_IsForcedMovementTile(metatileBehavior)) { @@ -660,26 +660,10 @@ static void UpdateFriendshipStepCounter(void) } } -static void UpdateLetsGoEvolutionTracker(void) +static void UpdateFollowerStepCounter(void) { - u32 i; - u16 count; - struct Pokemon *followingMon = GetFirstLiveMon(); - const struct Evolution *evolutions = GetSpeciesEvolutions(GetMonData(followingMon, MON_DATA_SPECIES)); - - if (evolutions == NULL) - return; - - for (i = 0; evolutions[i].method != EVOLUTIONS_END; i++) - { - if (evolutions[i].method != EVO_OVERWORLD_STEPS || SanitizeSpeciesId(evolutions[i].targetSpecies) == SPECIES_NONE) - continue; - - // We only have 10 bits to use - count = min(1023, GetMonData(followingMon, MON_DATA_EVOLUTION_TRACKER) + 1); - SetMonData(followingMon, MON_DATA_EVOLUTION_TRACKER, &count); - return; - } + if (gPlayerPartyCount > 0 && gFollowerSteps < (u16)-1) + gFollowerSteps++; } void ClearPoisonStepCounter(void) diff --git a/src/party_menu.c b/src/party_menu.c index 2fd666d10d73..5214ddc2be63 100644 --- a/src/party_menu.c +++ b/src/party_menu.c @@ -2987,6 +2987,9 @@ static void CB2_ReturnToPartyMenuFromSummaryScreen(void) static void CursorCb_Switch(u8 taskId) { + // Reset follower steps when the party leader is changed + if (gPartyMenu.slotId == 0 || gPartyMenu.slotId2 == 0) + gFollowerSteps = 0; PlaySE(SE_SELECT); gPartyMenu.action = PARTY_ACTION_SWITCH; PartyMenuRemoveWindow(&sPartyMenuInternal->windowId[1]); diff --git a/src/pokemon.c b/src/pokemon.c index 1fd18f510eba..befede6fd115 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -85,6 +85,7 @@ EWRAM_DATA struct Pokemon gEnemyParty[PARTY_SIZE] = {0}; EWRAM_DATA struct SpriteTemplate gMultiuseSpriteTemplate = {0}; EWRAM_DATA static struct MonSpritesGfxManager *sMonSpritesGfxManagers[MON_SPR_GFX_MANAGERS_COUNT] = {NULL}; EWRAM_DATA static u8 sTriedEvolving = 0; +EWRAM_DATA u16 gFollowerSteps = 0; #include "data/moves_info.h" #include "data/abilities.h" @@ -4708,7 +4709,7 @@ u16 GetEvolutionTargetSpecies(struct Pokemon *mon, u8 mode, u16 evolutionItem, s targetSpecies = evolutions[i].targetSpecies; break; case EVO_OVERWORLD_STEPS: - if (evolutionTracker >= evolutions[i].param) + if (mon == GetFirstLiveMon() && gFollowerSteps >= evolutions[i].param) targetSpecies = evolutions[i].targetSpecies; break; } diff --git a/test/species.c b/test/species.c index d09f1e3eb93a..052fc1e1949a 100644 --- a/test/species.c +++ b/test/species.c @@ -119,9 +119,6 @@ TEST("No species has two evolutions that use the evolution tracker") #ifdef EVO_DEFEAT_WITH_ITEM || evolutions[i].method == EVO_DEFEAT_WITH_ITEM #endif //EVO_DEFEAT_WITH_ITEM - #ifdef EVO_OVERWORLD_STEPS - || evolutions[i].method == EVO_OVERWORLD_STEPS - #endif //EVO_OVERWORLD_STEPS ) evolutionTrackerEvolutions++; From 83b9f897d6fd869da696e20a6b2976875f46ffb4 Mon Sep 17 00:00:00 2001 From: Eduardo Quezada Date: Sat, 27 Jul 2024 14:33:19 -0400 Subject: [PATCH 2/2] Fixed PC swapping not resetting the follower steps --- src/pokemon_storage_system.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/pokemon_storage_system.c b/src/pokemon_storage_system.c index c846e8facf82..fe65df011485 100644 --- a/src/pokemon_storage_system.c +++ b/src/pokemon_storage_system.c @@ -6,6 +6,7 @@ #include "dma3.h" #include "dynamic_placeholder_text_util.h" #include "event_data.h" +#include "event_object_movement.h" #include "field_screen_effect.h" #include "field_weather.h" #include "fldeff_misc.h" @@ -6412,9 +6413,15 @@ static void RefreshDisplayMon(void) static void SetMovingMonData(u8 boxId, u8 position) { if (boxId == TOTAL_BOXES_COUNT) + { sStorage->movingMon = gPlayerParty[sCursorPosition]; + if (&gPlayerParty[sCursorPosition] == GetFirstLiveMon()) + gFollowerSteps = 0; + } else + { BoxMonAtToMon(boxId, position, &sStorage->movingMon); + } PurgeMonOrBoxMon(boxId, position); sMovingMonOrigBoxId = boxId; @@ -6427,9 +6434,15 @@ static void SetPlacedMonData(u8 boxId, u8 position) HealPokemon(&sStorage->movingMon); if (boxId == TOTAL_BOXES_COUNT) + { gPlayerParty[position] = sStorage->movingMon; + if (&gPlayerParty[position] == GetFirstLiveMon()) + gFollowerSteps = 0; + } else + { SetBoxMonAt(boxId, position, &sStorage->movingMon.box); + } } static void PurgeMonOrBoxMon(u8 boxId, u8 position)