diff --git a/asm/include/overlay_29_02324B24.inc b/asm/include/overlay_29_02324BE8.inc similarity index 100% rename from asm/include/overlay_29_02324B24.inc rename to asm/include/overlay_29_02324BE8.inc diff --git a/asm/overlay_29_02324B24.s b/asm/overlay_29_02324BE8.s similarity index 91% rename from asm/overlay_29_02324B24.s rename to asm/overlay_29_02324BE8.s index 684776ce..67dda5ab 100644 --- a/asm/overlay_29_02324B24.s +++ b/asm/overlay_29_02324BE8.s @@ -1,69 +1,8 @@ .include "asm/macros.inc" - .include "overlay_29_02324B24.inc" + .include "overlay_29_02324BE8.inc" .text - arm_func_start CanMonsterUseMove -CanMonsterUseMove: ; 0x02324B24 - stmdb sp!, {r3, r4, r5, lr} - mov r5, r1 - ldrh r3, [r5, #4] - ldr r1, _02324BE4 ; =0x00000163 - ldr r4, [r0, #0xb4] - cmp r3, r1 - moveq r0, #1 - ldmeqia sp!, {r3, r4, r5, pc} - ldrb r0, [r5] - tst r0, #0x20 - movne r0, #0 - ldmneia sp!, {r3, r4, r5, pc} - ldrh r0, [r5, #2] - tst r0, #1 - movne r0, #0 - ldmneia sp!, {r3, r4, r5, pc} - cmp r2, #0 - moveq r0, #1 - ldmeqia sp!, {r3, r4, r5, pc} - ldrb r0, [r5, #6] - cmp r0, #0 - moveq r0, #0 - ldmeqia sp!, {r3, r4, r5, pc} - ldrb r0, [r4, #0xd0] - cmp r0, #5 - bne _02324BA0 - mov r0, r5 - bl IsUsableWhileTaunted - cmp r0, #0 - moveq r0, #0 - ldmeqia sp!, {r3, r4, r5, pc} -_02324BA0: - ldrb r0, [r4, #0xd0] - cmp r0, #6 - bne _02324BDC - ldrh r0, [r5, #4] - cmp r0, #0x160 - bne _02324BCC -#ifdef JAPAN - ldrb r0, [r4, #0x140] -#else - ldrb r0, [r4, #0x144] -#endif - tst r0, #0x10 - bne _02324BDC - mov r0, #0 - ldmia sp!, {r3, r4, r5, pc} -_02324BCC: - ldrb r0, [r5] - tst r0, #0x10 - moveq r0, #0 - ldmeqia sp!, {r3, r4, r5, pc} -_02324BDC: - mov r0, #1 - ldmia sp!, {r3, r4, r5, pc} - .align 2, 0 -_02324BE4: .word 0x00000163 - arm_func_end CanMonsterUseMove - arm_func_start ov29_02324BE8 ov29_02324BE8: ; 0x02324BE8 stmdb sp!, {r3, r4, r5, lr} diff --git a/include/dungeon_move_util.h b/include/dungeon_move_util.h index 3d3b0c66..ea656fdd 100644 --- a/include/dungeon_move_util.h +++ b/include/dungeon_move_util.h @@ -6,6 +6,17 @@ // Checks if an AI-controlled monster can use a move. // Will return false if the any of the flags move::f_exists, move::f_subsequent_in_link_chain or move::f_disabled is true. The function does not check if the flag move::f_enabled_for_ai is set. This function also returns true if the call to CanMonsterUseMove is true. // The function contains a loop that is supposed to check other moves after the specified one, but the loop breaks after it finds a move that isn't linked, which is always true given the checks in place at the start of the function. +// monster: Entity pointer +// move_index: Move index +// extra_checks: extra_checks parameter when calling CanMonsterUseMove +// return: True if the AI can use the move (not accounting for move::f_enabled_for_ai) bool8 CanAiUseMove(struct entity *monster, u32 move_index, bool8 extra_checks); +// Checks if a monster can use the given move. +// Will always return true for the regular attack. Will return false if the move if the flag move::f_disabled is true, if the // flag move::f_sealed is true. More things will be checked if the extra_checks parameter is true. +// monster: Entity pointer +// move: Move pointer +// extra_checks: True to check whether the move is out of PP, whether it can be used under the taunted status and whether the encore status prevents using the move +// return: True if the monster can use the move, false otherwise. +bool8 CanMonsterUseMove(struct entity *monster, struct move *move, bool8 extra_checks); #endif //PMDSKY_DUNGEON_MOVE_UTIL_H diff --git a/main.lsf b/main.lsf index 81cbe519..07c14ecb 100644 --- a/main.lsf +++ b/main.lsf @@ -563,7 +563,7 @@ Overlay OVY_29 Object asm/overlay_29_rodata_02352A6C.o Object asm/overlay_29_02324698.o Object src/dungeon_move_util.o - Object asm/overlay_29_02324B24.o + Object asm/overlay_29_02324BE8.o Object src/overlay_29_02325620.o Object asm/overlay_29_02325644.o Object src/overlay_29_0232800C.o diff --git a/src/dungeon_move_util.c b/src/dungeon_move_util.c index 685e8a29..ef53899d 100644 --- a/src/dungeon_move_util.c +++ b/src/dungeon_move_util.c @@ -1,8 +1,7 @@ #include "dungeon_move_util.h" #include "dungeon_util_static.h" #include "move.h" - -extern bool8 CanMonsterUseMove(struct entity *monster, struct move *move, bool8 extra_checks); +#include "moves_3.h" bool8 CanAiUseMove(struct entity *monster, u32 move_index, bool8 extra_checks) { @@ -36,3 +35,38 @@ bool8 CanAiUseMove(struct entity *monster, u32 move_index, bool8 extra_checks) return FALSE; } + +bool8 CanMonsterUseMove(struct entity *monster, struct move *move, bool8 extra_checks) +{ + struct monster *pokemon_info = GetEntInfo(monster); + if (move->id == MOVE_REGULAR_ATTACK) + return TRUE; + + if (move->flags0 & MOVE_FLAG_DISABLED) + return FALSE; + + if (move->flags2 & MOVE_FLAG_SEALED) + return FALSE; + + if (!extra_checks) + return TRUE; + + if (move->pp == 0) + return FALSE; + + if (pokemon_info->cringe_class_status.cringe == STATUS_CRINGE_TAUNTED && !IsUsableWhileTaunted(move)) + return FALSE; + + if (pokemon_info->cringe_class_status.cringe == STATUS_CRINGE_ENCORE) + { + if (move->id == MOVE_STRUGGLE) + { + if (!(pokemon_info->moves.struggle_move_flags & MOVE_FLAG_LAST_USED)) + return FALSE; + } + else if (!(move->flags0 & MOVE_FLAG_LAST_USED)) + return FALSE; + } + + return TRUE; +}