From d2b632afc2c9e322de47d05eaa4121bc1f0752d9 Mon Sep 17 00:00:00 2001 From: AnonymousRandomPerson Date: Mon, 16 Jun 2025 22:24:21 -0500 Subject: [PATCH] Decomped ShouldMonsterRunAwayAndShowEffect --- asm/include/itcm.inc | 2 +- asm/include/overlay_29_022F05B4.inc | 2 +- asm/include/overlay_29_022F52B0.inc | 2 +- ...9_023016A8.inc => overlay_29_023016D8.inc} | 3 +-- asm/include/overlay_29_0230F02C.inc | 2 +- asm/include/overlay_29_02344B1C.inc | 2 +- asm/itcm.s | 14 +++++----- asm/overlay_29_022E37DC.s | 6 ++--- asm/overlay_29_022F05B4.s | 6 ++--- asm/overlay_29_022F52B0.s | 2 +- ...ay_29_023016A8.s => overlay_29_023016D8.s} | 26 ++++--------------- asm/overlay_29_0230F02C.s | 2 +- asm/overlay_29_02344B1C.s | 2 +- include/dungeon_ai_targeting.h | 5 ++++ include/dungeon_logic_3.h | 4 +++ main.lsf | 2 +- src/dungeon_ai_itcm.c | 4 +-- src/dungeon_ai_targeting.c | 13 ++++++++++ src/overlay_31_02382820.c | 7 +++-- 19 files changed, 55 insertions(+), 51 deletions(-) rename asm/include/{overlay_29_023016A8.inc => overlay_29_023016D8.inc} (54%) rename asm/{overlay_29_023016A8.s => overlay_29_023016D8.s} (57%) diff --git a/asm/include/itcm.inc b/asm/include/itcm.inc index 54774049..c9799fb9 100644 --- a/asm/include/itcm.inc +++ b/asm/include/itcm.inc @@ -81,7 +81,7 @@ .public SetMonsterActionFields .public ShouldMonsterFollowLeader .public ShouldMonsterHeadToStairs -.public ShouldMonsterRunAwayVariation +.public ShouldMonsterRunAwayAndShowEffect .public sub_0201BD50 .public sub_0201BD80 .public sub_0202760C diff --git a/asm/include/overlay_29_022F05B4.inc b/asm/include/overlay_29_022F05B4.inc index 0ea5e688..dcde4209 100644 --- a/asm/include/overlay_29_022F05B4.inc +++ b/asm/include/overlay_29_022F05B4.inc @@ -177,7 +177,7 @@ .public SetLeaderActionFields .public SetMonsterActionFields .public ShouldMonsterRunAway -.public ShouldMonsterRunAwayVariation +.public ShouldMonsterRunAwayAndShowEffect .public SpawnItem .public sub_02001AB0 .public sub_02006B70 diff --git a/asm/include/overlay_29_022F52B0.inc b/asm/include/overlay_29_022F52B0.inc index 25286e66..5668c003 100644 --- a/asm/include/overlay_29_022F52B0.inc +++ b/asm/include/overlay_29_022F52B0.inc @@ -37,6 +37,6 @@ .public RemoveGroundItem .public RemoveUsedItem .public ShouldDisplayEntityWrapper -.public ShouldMonsterRunAwayVariation +.public ShouldMonsterRunAwayAndShowEffect .public SpawnItem .public TryTriggerMonsterHouse diff --git a/asm/include/overlay_29_023016A8.inc b/asm/include/overlay_29_023016D8.inc similarity index 54% rename from asm/include/overlay_29_023016A8.inc rename to asm/include/overlay_29_023016D8.inc index ce71f221..f8427fbc 100644 --- a/asm/include/overlay_29_023016A8.inc +++ b/asm/include/overlay_29_023016D8.inc @@ -1,5 +1,4 @@ #pragma once .public AbilityIsActive -.public ov29_022E62A8 -.public ShouldMonsterRunAway .public UpdateStateFlags +.public PlayEffectAnimation0x29 diff --git a/asm/include/overlay_29_0230F02C.inc b/asm/include/overlay_29_0230F02C.inc index 2b2d4679..d0d2a931 100644 --- a/asm/include/overlay_29_0230F02C.inc +++ b/asm/include/overlay_29_0230F02C.inc @@ -33,7 +33,7 @@ .public ov29_02348DD8 .public ov29_02348ECC .public RemoveGroundItem -.public ShouldMonsterRunAwayVariation +.public ShouldMonsterRunAwayAndShowEffect .public sub_0200D8AC .public SubstitutePlaceholderStringTags .public UseThrowableItem diff --git a/asm/include/overlay_29_02344B1C.inc b/asm/include/overlay_29_02344B1C.inc index 949942ed..d6fa441f 100644 --- a/asm/include/overlay_29_02344B1C.inc +++ b/asm/include/overlay_29_02344B1C.inc @@ -44,7 +44,7 @@ .public RemoveEmptyItemsInBag .public RemoveEquivItemNoHole .public RemoveGroundItem -.public ShouldMonsterRunAwayVariation +.public ShouldMonsterRunAwayAndShowEffect .public SpawnItemEntity .public sub_0200D8AC .public sub_02024FE8 diff --git a/asm/itcm.s b/asm/itcm.s index d01b9ea6..ba07977f 100644 --- a/asm/itcm.s +++ b/asm/itcm.s @@ -2792,12 +2792,12 @@ _01FFA37C: _01FFA38C: .word ov29_02353530 arm_func_end sub_01FF9F80 - arm_func_start ShouldMonsterRunAwayVariationOutlawCheck -ShouldMonsterRunAwayVariationOutlawCheck: ; 0x01FFA390 + arm_func_start ShouldMonsterRunAwayAndShowEffectOutlawCheck +ShouldMonsterRunAwayAndShowEffectOutlawCheck: ; 0x01FFA390 stmdb sp!, {r3, r4, r5, lr} mov r4, #0 mov r5, r0 - bl ShouldMonsterRunAwayVariation + bl ShouldMonsterRunAwayAndShowEffect cmp r0, #0 movne r4, #1 bne _01FFA3BC @@ -2808,7 +2808,7 @@ ShouldMonsterRunAwayVariationOutlawCheck: ; 0x01FFA390 _01FFA3BC: mov r0, r4 ldmia sp!, {r3, r4, r5, pc} - arm_func_end ShouldMonsterRunAwayVariationOutlawCheck + arm_func_end ShouldMonsterRunAwayAndShowEffectOutlawCheck arm_func_start AiMovement AiMovement: ; 0x01FFA3C4 @@ -2894,7 +2894,7 @@ _01FFA494: _01FFA4D4: ldr r1, [sp] mov r0, r4 - bl ShouldMonsterRunAwayVariationOutlawCheck + bl ShouldMonsterRunAwayAndShowEffectOutlawCheck cmp r0, #0 beq _01FFA9A8 ldr sb, [r4, #0xb4] @@ -3775,7 +3775,7 @@ _01FFB16C: movne sl, #5 mov r0, r4 moveq sl, #3 - bl ShouldMonsterRunAwayVariationOutlawCheck + bl ShouldMonsterRunAwayAndShowEffectOutlawCheck cmp r0, #0 ldreqb r0, [sb, #0x7f] mov r8, #1 @@ -4169,7 +4169,7 @@ ChooseAiMove: ; 0x01FFB658 bne _01FFBD0C mov r0, sl mov r1, #1 - bl ShouldMonsterRunAwayVariation + bl ShouldMonsterRunAwayAndShowEffect cmp r0, #0 bne _01FFBD0C ldr r0, [sl, #0xb4] diff --git a/asm/overlay_29_022E37DC.s b/asm/overlay_29_022E37DC.s index 067c1752..6eecc30b 100644 --- a/asm/overlay_29_022E37DC.s +++ b/asm/overlay_29_022E37DC.s @@ -3516,8 +3516,8 @@ ov29_022E6260: ; 0x022E6260 ldmia sp!, {r4, pc} arm_func_end ov29_022E6260 - arm_func_start ov29_022E62A8 -ov29_022E62A8: ; 0x022E62A8 + arm_func_start PlayEffectAnimation0x29 +PlayEffectAnimation0x29: ; 0x022E62A8 stmdb sp!, {r4, lr} sub sp, sp, #0x10 mov r4, r0 @@ -3536,7 +3536,7 @@ ov29_022E62A8: ; 0x022E62A8 bl PlayEffectAnimationEntity add sp, sp, #0x10 ldmia sp!, {r4, pc} - arm_func_end ov29_022E62A8 + arm_func_end PlayEffectAnimation0x29 arm_func_start ov29_022E62F0 ov29_022E62F0: ; 0x022E62F0 diff --git a/asm/overlay_29_022F05B4.s b/asm/overlay_29_022F05B4.s index 1dbae5c9..1f7684f4 100644 --- a/asm/overlay_29_022F05B4.s +++ b/asm/overlay_29_022F05B4.s @@ -814,7 +814,7 @@ _022F0F58: _022F0FAC: bl GetLeader mov r1, #1 - bl ShouldMonsterRunAwayVariation + bl ShouldMonsterRunAwayAndShowEffect cmp r0, #0 bne _022F1000 mov r0, #0xa @@ -1545,7 +1545,7 @@ _022F19DC: _022F1A64: mov r0, r6 mov r1, #1 - bl ShouldMonsterRunAwayVariation + bl ShouldMonsterRunAwayAndShowEffect cmp r0, #0 beq _022F1AA0 ldr r1, _022F1DF4 ; =0x00000B9A @@ -2648,7 +2648,7 @@ _022F2A00: beq _022F2A70 bl GetLeader mov r1, #1 - bl ShouldMonsterRunAwayVariation + bl ShouldMonsterRunAwayAndShowEffect cmp r0, #0 bne _022F2A70 mov r0, #4 diff --git a/asm/overlay_29_022F52B0.s b/asm/overlay_29_022F52B0.s index d8c53fb8..c5c5d1fe 100644 --- a/asm/overlay_29_022F52B0.s +++ b/asm/overlay_29_022F52B0.s @@ -242,7 +242,7 @@ _022F5578: _022F55B8: mov r0, sb mov r1, #1 - bl ShouldMonsterRunAwayVariation + bl ShouldMonsterRunAwayAndShowEffect cmp r0, #0 beq _022F55E8 ldr r1, _022F5984 ; =0x00000BBE diff --git a/asm/overlay_29_023016A8.s b/asm/overlay_29_023016D8.s similarity index 57% rename from asm/overlay_29_023016A8.s rename to asm/overlay_29_023016D8.s index 77a3fccb..3fe2e0be 100644 --- a/asm/overlay_29_023016A8.s +++ b/asm/overlay_29_023016D8.s @@ -1,26 +1,10 @@ .include "asm/macros.inc" - .include "overlay_29_023016A8.inc" + .include "overlay_29_023016D8.inc" .text - arm_func_start ShouldMonsterRunAwayVariation -ShouldMonsterRunAwayVariation: ; 0x023016A8 - stmdb sp!, {r3, r4, r5, lr} - mov r5, r0 - mov r4, r1 - bl ShouldMonsterRunAway - cmp r0, #0 - moveq r0, #0 - ldmeqia sp!, {r3, r4, r5, pc} - mov r0, r5 - mov r1, r4 - bl ov29_023016D8 - mov r0, #1 - ldmia sp!, {r3, r4, r5, pc} - arm_func_end ShouldMonsterRunAwayVariation - - arm_func_start ov29_023016D8 -ov29_023016D8: ; 0x023016D8 + arm_func_start DisplayRunAwayIfTriggered +DisplayRunAwayIfTriggered: ; 0x023016D8 stmdb sp!, {r4, r5, r6, lr} mov r6, r0 ldr r4, [r6, #0xb4] @@ -51,8 +35,8 @@ ov29_023016D8: ; 0x023016D8 cmpne r0, #0 ldmeqia sp!, {r4, r5, r6, pc} mov r0, r6 - bl ov29_022E62A8 + bl PlayEffectAnimation0x29 ldmia sp!, {r4, r5, r6, pc} .align 2, 0 _02301758: .word 0x000003E7 - arm_func_end ov29_023016D8 + arm_func_end DisplayRunAwayIfTriggered diff --git a/asm/overlay_29_0230F02C.s b/asm/overlay_29_0230F02C.s index 13cfe0d1..bd64ab7d 100644 --- a/asm/overlay_29_0230F02C.s +++ b/asm/overlay_29_0230F02C.s @@ -86,7 +86,7 @@ _0230F22C: beq _0230F624 mov r0, r8 mov r1, #1 - bl ShouldMonsterRunAwayVariation + bl ShouldMonsterRunAwayAndShowEffect cmp r0, #0 beq _0230F274 mov r1, r4 diff --git a/asm/overlay_29_02344B1C.s b/asm/overlay_29_02344B1C.s index 048cd440..43fa5fdd 100644 --- a/asm/overlay_29_02344B1C.s +++ b/asm/overlay_29_02344B1C.s @@ -469,7 +469,7 @@ TryLeaderItemPickUp: ; 0x02345058 b _02345508 _02345108: mov r1, #1 - bl ShouldMonsterRunAwayVariation + bl ShouldMonsterRunAwayAndShowEffect cmp r0, #0 beq _0234515C cmp sb, #0 diff --git a/include/dungeon_ai_targeting.h b/include/dungeon_ai_targeting.h index 596c9bcd..4018a351 100644 --- a/include/dungeon_ai_targeting.h +++ b/include/dungeon_ai_targeting.h @@ -6,5 +6,10 @@ // Checks if a monster should run away from other monsters // return: True if the monster should run away, false otherwise bool8 ShouldMonsterRunAway(struct entity *monster); +// Calls ShouldMonsterRunAway and returns its result. It also calls DisplayRunAwayIfTriggered if the result was true. +// monster: Entity pointer +// show_run_away_effect: Boolean value. If true, display a visual "poof" effect if the Run Away ability caused the monster to run away. +// return: Result of the call to ShouldMonsterRunAway +bool8 ShouldMonsterRunAwayAndShowEffect(struct entity *monster, bool8 show_run_away_effect); #endif //PMDSKY_DUNGEON_AI_TARGETING_H diff --git a/include/dungeon_logic_3.h b/include/dungeon_logic_3.h index d11c554a..c8e52089 100644 --- a/include/dungeon_logic_3.h +++ b/include/dungeon_logic_3.h @@ -3,6 +3,10 @@ #include "dungeon_mode.h" +// Returns false if the entity has any of these conditions: sleep, nightmare, napping, frozen, wrapped/wrapping, petrified, cringe, paused, infatuated, paralysis. Also returns false if ShouldMonsterRunAway returns true. +// pokemon: Entity pointer +// skip_sleep: If true, ignore sleep conditions (sleep, nightmare, napping) when checking if the entity cannot attack. +// return: bool bool8 MonsterCannotAttack(struct entity *pokemon, bool8 skip_sleep); // Checks if the given monster can move in the specified direction // Returns false if any monster is standing on the target tile diff --git a/main.lsf b/main.lsf index a563889b..1c123bcc 100644 --- a/main.lsf +++ b/main.lsf @@ -347,7 +347,7 @@ Overlay OVY_29 Object src/dungeon_logic_3.o Object asm/overlay_29_02300FCC.o Object src/dungeon_ai_targeting.o - Object asm/overlay_29_023016A8.o + Object asm/overlay_29_023016D8.o Object src/dungeon_ai_targeting_1.o Object asm/overlay_29_rodata_023527C0.o Object asm/overlay_29_023018AC.o diff --git a/src/dungeon_ai_itcm.c b/src/dungeon_ai_itcm.c index bbb7090f..c2b02f8e 100644 --- a/src/dungeon_ai_itcm.c +++ b/src/dungeon_ai_itcm.c @@ -2,6 +2,7 @@ #include "dg_random.h" #include "direction.h" #include "dungeon_action.h" +#include "dungeon_ai_targeting.h" #include "dungeon_logic_3.h" #include "dungeon_parameters.h" #include "dungeon_pokemon_attributes.h" @@ -15,7 +16,6 @@ const s16 AI_REGULAR_ATTACK_WEIGHTS[5] = { 100, 20, 30, 40, 50 }; extern struct dungeon *DUNGEON_PTR[]; -extern u32 ShouldMonsterRunAwayVariation(struct entity *monster, u32 param_2); extern bool8 IsMonsterCornered(struct entity *monster); extern bool8 IsChargingTwoTurnMove(struct entity *user, struct move *move); extern void SetActionUseMoveAi(struct action_data *monster_action, s16 move_index, u8 direction); @@ -38,7 +38,7 @@ void ChooseAiMove(struct entity *monster) if (!AreMovesEnabled(DUNGEON_PTR[0]->gen_info.fixed_room_id) || MonsterCannotAttack(monster, FALSE) || - ShouldMonsterRunAwayVariation(monster, TRUE) || + ShouldMonsterRunAwayAndShowEffect(monster, TRUE) || GetEntInfo(monster)->monster_behavior == BEHAVIOR_FLEEING_OUTLAW && IsMonsterCornered(monster) || IsTacticSet(monster, TACTIC_KEEP_YOUR_DISTANCE) || (pokemon_info->cringe_class_status.cringe == STATUS_CRINGE_CONFUSED && DungeonRandOutcome__022EAB20(AI_CONFUSED_NO_ATTACK_CHANCE))) diff --git a/src/dungeon_ai_targeting.c b/src/dungeon_ai_targeting.c index ff8dc49c..ba14ec30 100644 --- a/src/dungeon_ai_targeting.c +++ b/src/dungeon_ai_targeting.c @@ -4,6 +4,8 @@ #include "dungeon_util_static.h" #include "overlay_29_023000E4.h" +extern void DisplayRunAwayIfTriggered(struct entity *monster, bool8 show_run_away_effect); + bool8 ShouldMonsterRunAway(struct entity *monster) { if (!EntityIsValid__023000E4(monster)) @@ -42,3 +44,14 @@ bool8 ShouldMonsterRunAway(struct entity *monster) } return FALSE; } + +bool8 ShouldMonsterRunAwayAndShowEffect(struct entity *monster, bool8 show_run_away_effect) +{ + if (ShouldMonsterRunAway(monster)) + { + DisplayRunAwayIfTriggered(monster, show_run_away_effect); + return TRUE; + } + + return FALSE; +} diff --git a/src/overlay_31_02382820.c b/src/overlay_31_02382820.c index a517000f..f8f7d863 100644 --- a/src/overlay_31_02382820.c +++ b/src/overlay_31_02382820.c @@ -1,4 +1,5 @@ #include "overlay_31_02382820.h" +#include "dungeon_ai_targeting.h" #include "number_util.h" extern struct dungeon* DUNGEON_PTR[]; @@ -36,7 +37,6 @@ extern u8* AllocateTemp1024ByteBufferFromPool(void); extern struct Window* GetWindow(struct Window*); extern s32 sub_020265A8(u8*); // Measures the text's width in pixels -extern u32 ShouldMonsterRunAwayVariation(struct entity*, u32); extern u32 Arm9LoadUnkFieldNa0x2029EC8(u32, u8*); extern u8 CreateParentMenuFromStringIds(u32*, u32, struct struct_2*, u32*); extern u8 CreateTextBox(u32*, void (*fun)(struct Window*)); @@ -44,7 +44,6 @@ extern u32 IsParentMenuActive(s8); extern u32 sub_0202AB80(s8); extern void Arm9StoreUnkFieldNa0x2029ED8(u32, u8); extern u32 GetPressedButtons(u32, u16*); -extern u32 ShouldMonsterRunAwayVariation(struct entity*, u32); extern void sub_0202AB94(s8, u32); extern void sub_0202B030(s8); extern void sub_0202F954(s8); @@ -173,7 +172,7 @@ u32 ov31_02382B54(void) OVERLAY31_UNKNOWN_POINTER__NA_238A260[0]->b[i] = 0; } leader = GetLeader(); - if (ShouldMonsterRunAwayVariation(leader, 1)) { + if (ShouldMonsterRunAwayAndShowEffect(leader, 1)) { OVERLAY31_UNKNOWN_POINTER__NA_238A260[0]->b[0] = 3; OVERLAY31_UNKNOWN_POINTER__NA_238A260[0]->b[1] = 3; OVERLAY31_UNKNOWN_POINTER__NA_238A260[0]->b[2] = 3; @@ -201,7 +200,7 @@ u32 ov31_02382B54(void) struct entity* leader = GetLeader(); - if (ShouldMonsterRunAwayVariation(leader, 1)) + if (ShouldMonsterRunAwayAndShowEffect(leader, 1)) break; sub_0202AB94(OVERLAY31_UNKNOWN_POINTER__NA_238A260[0]->f[0], 0);