diff options
author | AnonymousRandomPerson <chenghanngan.us@gmail.com> | 2021-12-26 00:03:03 -0600 |
---|---|---|
committer | AnonymousRandomPerson <chenghanngan.us@gmail.com> | 2021-12-28 21:38:39 -0600 |
commit | 4bf154654bbf3dbb259e5ce6985e17d24260a72e (patch) | |
tree | bfd54e0ce1e95caee136d11e77c7546079341fce | |
parent | 6512ebff67e163a5a6c0f5e19847e2a4dda19ad1 (diff) |
Decomped TargetThrownItem()
-rw-r--r-- | asm/code_8073CF0.s (renamed from asm/code_8073B78.s) | 203 | ||||
-rw-r--r-- | include/dungeon_ai_items.h | 2 | ||||
-rw-r--r-- | include/dungeon_entity.h | 1 | ||||
-rwxr-xr-x | ld_script.txt | 2 | ||||
-rw-r--r-- | src/dungeon_ai_items.c | 77 |
5 files changed, 79 insertions, 206 deletions
diff --git a/asm/code_8073B78.s b/asm/code_8073CF0.s index 84affaa..bb9a59e 100644 --- a/asm/code_8073B78.s +++ b/asm/code_8073CF0.s @@ -1,211 +1,10 @@ #include "asm/constants/gba_constants.inc" - #include "asm/macros.inc" + #include "asm/macros.inc" .syntax unified .text - thumb_func_start TargetThrownItem -TargetThrownItem: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - adds r4, r0, 0 - adds r5, r1, 0 - mov r9, r2 - mov r10, r3 - ldr r0, [sp, 0x20] - lsls r0, 24 - lsrs r0, 24 - mov r8, r0 - movs r0, 0x4 - ldrsh r1, [r4, r0] - movs r2, 0x4 - ldrsh r0, [r5, r2] - subs r2, r1, r0 - cmp r2, 0 - bge _08073BA2 - negs r2, r2 -_08073BA2: - movs r3, 0x6 - ldrsh r1, [r4, r3] - movs r6, 0x6 - ldrsh r0, [r5, r6] - subs r1, r0 - cmp r1, 0 - bge _08073BB2 - negs r1, r1 -_08073BB2: - ldr r0, [r4, 0x70] - adds r0, 0xE0 - ldrb r0, [r0] - cmp r0, 0 - bne _08073BCA - adds r0, r1, 0 - cmp r1, r2 - bge _08073BC4 - adds r0, r2, 0 -_08073BC4: - cmp r0, 0xA - ble _08073BCA - b _08073CDC -_08073BCA: - movs r6, 0x1 - negs r6, r6 - cmp r2, r1 - bne _08073C14 - movs r7, 0x4 - ldrsh r1, [r4, r7] - movs r2, 0x4 - ldrsh r0, [r5, r2] - ldrh r2, [r4, 0x4] - ldrh r3, [r5, 0x4] - cmp r1, r0 - bge _08073BFA - movs r6, 0x6 - ldrsh r1, [r4, r6] - movs r7, 0x6 - ldrsh r0, [r5, r7] - cmp r1, r0 - bge _08073BF2 - movs r6, 0x1 - b _08073C7E -_08073BF2: - cmp r1, r0 - ble _08073BFA - movs r6, 0x3 - b _08073C7E -_08073BFA: - lsls r1, r2, 16 - lsls r0, r3, 16 - movs r6, 0x7 - cmp r1, r0 - ble _08073C7A - movs r0, 0x6 - ldrsh r1, [r4, r0] - movs r2, 0x6 - ldrsh r0, [r5, r2] - cmp r1, r0 - ble _08073C7A - movs r6, 0x5 - b _08073C7E -_08073C14: - movs r3, 0x4 - ldrsh r1, [r4, r3] - movs r7, 0x4 - ldrsh r0, [r5, r7] - ldrh r2, [r4, 0x4] - ldrh r3, [r5, 0x4] - cmp r1, r0 - bne _08073C34 - movs r0, 0x6 - ldrsh r1, [r4, r0] - movs r7, 0x6 - ldrsh r0, [r5, r7] - cmp r1, r0 - bge _08073C34 - movs r6, 0 - b _08073C7E -_08073C34: - lsls r1, r2, 16 - lsls r0, r3, 16 - cmp r1, r0 - bge _08073C4C - movs r0, 0x6 - ldrsh r1, [r4, r0] - movs r7, 0x6 - ldrsh r0, [r5, r7] - cmp r1, r0 - bne _08073C4C - movs r6, 0x2 - b _08073C7E -_08073C4C: - lsls r1, r2, 16 - lsls r0, r3, 16 - cmp r1, r0 - bne _08073C64 - movs r0, 0x6 - ldrsh r1, [r4, r0] - movs r7, 0x6 - ldrsh r0, [r5, r7] - cmp r1, r0 - ble _08073C64 - movs r6, 0x4 - b _08073C7E -_08073C64: - lsls r1, r2, 16 - lsls r0, r3, 16 - cmp r1, r0 - ble _08073C7A - movs r0, 0x6 - ldrsh r1, [r4, r0] - movs r2, 0x6 - ldrsh r0, [r5, r2] - cmp r1, r0 - bne _08073C7A - movs r6, 0x6 -_08073C7A: - cmp r6, 0 - blt _08073CDC -_08073C7E: - ldr r0, _08073CC0 - adds r7, r6, r0 - ldrb r0, [r7] - cmp r0, 0 - bne _08073CDC - adds r0, r4, 0 - adds r1, r5, 0 - adds r2, r6, 0 - movs r3, 0xA - bl IsTargetStraightAhead - lsls r0, 24 - cmp r0, 0 - beq _08073CDC - movs r0, 0x1 - strb r0, [r7] - ldr r1, _08073CC4 - ldr r0, _08073CC8 - ldr r0, [r0] - lsls r0, 2 - adds r1, r0, r1 - str r6, [r1] - ldr r1, _08073CCC - adds r4, r0, r1 - mov r3, r8 - cmp r3, 0 - bne _08073CD0 - adds r0, r5, 0 - mov r1, r9 - mov r2, r10 - bl EvaluateItem - b _08073CD2 - .align 2, 0 -_08073CC0: .4byte gTargetAhead -_08073CC4: .4byte gPotentialTargetDirections -_08073CC8: .4byte gNumPotentialTargets -_08073CCC: .4byte gPotentialTargetWeights -_08073CD0: - movs r0, 0x64 -_08073CD2: - str r0, [r4] - ldr r1, _08073CEC - ldr r0, [r1] - adds r0, 0x1 - str r0, [r1] -_08073CDC: - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .align 2, 0 -_08073CEC: .4byte gNumPotentialTargets - thumb_func_end TargetThrownItem - thumb_func_start sub_8073CF0 sub_8073CF0: push {lr} diff --git a/include/dungeon_ai_items.h b/include/dungeon_ai_items.h index 676200a..5daf7b0 100644 --- a/include/dungeon_ai_items.h +++ b/include/dungeon_ai_items.h @@ -10,5 +10,7 @@ void DecideUseItem(struct DungeonEntity *pokemon); void FindStraightThrowableTargets(struct DungeonEntity *pokemon, s32 thrownAIFlag, struct ItemSlot *item, bool8 ignoreRollChance); // 0x73AA0 void FindRockItemTargets(struct DungeonEntity *pokemon, struct ItemSlot *item, struct Position potentialTargets[], bool8 ignoreRollChance); +// 0x73B78 +void TargetThrownItem(struct DungeonEntity *pokemon, struct DungeonEntity *targetPokemon, struct ItemSlot *item, s32 targetingFlags, bool8 ignoreRollChance); #endif diff --git a/include/dungeon_entity.h b/include/dungeon_entity.h index 29fda0a..527d817 100644 --- a/include/dungeon_entity.h +++ b/include/dungeon_entity.h @@ -2,6 +2,7 @@ #define GUARD_DUNGEON_ENTITY_H #include "constants/move.h" +#include "global.h" #include "item.h" #include "position.h" diff --git a/ld_script.txt b/ld_script.txt index 0dce9c7..6c6301c 100755 --- a/ld_script.txt +++ b/ld_script.txt @@ -218,7 +218,7 @@ SECTIONS { src/dungeon_pokemon_attributes_1.o(.text); asm/code_80718D8.o(.text); src/dungeon_ai_items.o(.text); - asm/code_8073B78.o(.text); + asm/code_8073CF0.o(.text); src/dungeon_movement.o(.text); asm/code_8075BA4.o(.text); src/dungeon_range.o(.text); diff --git a/src/dungeon_ai_items.c b/src/dungeon_ai_items.c index 4afc928..e0202ee 100644 --- a/src/dungeon_ai_items.c +++ b/src/dungeon_ai_items.c @@ -3,6 +3,7 @@ #include "constants/direction.h" #include "constants/dungeon_action.h" #include "constants/iq_skill.h" +#include "constants/status.h" #include "constants/targeting.h" #include "dungeon_action.h" #include "dungeon_ai_1.h" @@ -24,6 +25,7 @@ #define NUM_POTENTIAL_ROCK_TARGETS 20 #define GROUND_ITEM_TOOLBOX_INDEX 0x80 #define HELD_ITEM_TOOLBOX_INDEX 0x81 +#define RANGED_ATTACK_RANGE 10 enum ItemTargetFlag { @@ -32,9 +34,9 @@ enum ItemTargetFlag }; extern s32 CalculateFacingDir(struct Position*, struct Position*); -extern u32 EvaluateItem(struct DungeonEntity*, struct ItemSlot*, u8); +extern u32 EvaluateItem(struct DungeonEntity*, struct ItemSlot*, u32); extern void sub_8077274(struct DungeonEntity *, struct DungeonEntity *); -extern void TargetThrownItem(struct DungeonEntity*, struct DungeonEntity*, struct ItemSlot*, u8, bool8); +extern bool8 IsTargetStraightAhead(struct DungeonEntity*, struct DungeonEntity*, s32, s32); extern s32 gNumPotentialTargets; extern u32 gPotentialTargetWeights[NUM_DIRECTIONS]; @@ -284,7 +286,7 @@ void FindStraightThrowableTargets(struct DungeonEntity *pokemon, s32 thrownAIFla struct DungeonEntity* targetPokemon = gDungeonGlobalData->allPokemon[i]; if (EntityExists(targetPokemon) && pokemon != targetPokemon) { - u8 targetingFlags; + s32 targetingFlags; if (thrownAIFlag == ITEM_AI_FLAG_TARGET_ALLY) { if (CanTarget(pokemon, targetPokemon, FALSE, FALSE) == TARGET_CAPABILITY_CANNOT_ATTACK) @@ -357,3 +359,72 @@ void FindRockItemTargets(struct DungeonEntity *pokemon, struct ItemSlot *item, s } } } + +void TargetThrownItem(struct DungeonEntity *pokemon, struct DungeonEntity *targetPokemon, struct ItemSlot *item, s32 targetingFlags, bool8 ignoreRollChance) +{ + s32 posDiffX = pokemon->posWorld.x - targetPokemon->posWorld.x; + s32 posDiffY; + s32 targetDirection; + posDiffX = posDiffX < 0 ? -posDiffX : posDiffX; + posDiffY = pokemon->posWorld.y - targetPokemon->posWorld.y; + posDiffY = posDiffY < 0 ? -posDiffY : posDiffY; + if (pokemon->entityData->itemStatus == ITEM_STATUS_NONE) + { + s32 maxPosDiff = posDiffY < posDiffX ? posDiffX : posDiffY; + if (maxPosDiff > RANGED_ATTACK_RANGE) + { + return; + } + } + targetDirection = -1; + if (posDiffX == posDiffY) + { + if (pokemon->posWorld.x < targetPokemon->posWorld.x && pokemon->posWorld.y < targetPokemon->posWorld.y) + { + targetDirection = DIRECTION_SOUTHEAST; + } + else if (pokemon->posWorld.x < targetPokemon->posWorld.x && pokemon->posWorld.y > targetPokemon->posWorld.y) + { + targetDirection = DIRECTION_NORTHEAST; + } + else if (pokemon->posWorld.x > targetPokemon->posWorld.x && pokemon->posWorld.y > targetPokemon->posWorld.y) + { + targetDirection = DIRECTION_NORTHWEST; + } + else + { + targetDirection = DIRECTION_SOUTHWEST; + } + } + else + { + if (pokemon->posWorld.x == targetPokemon->posWorld.x && pokemon->posWorld.y < targetPokemon->posWorld.y) + { + targetDirection = DIRECTION_SOUTH; + } + else if (pokemon->posWorld.x < targetPokemon->posWorld.x && pokemon->posWorld.y == targetPokemon->posWorld.y) + { + targetDirection = DIRECTION_EAST; + } + else if (pokemon->posWorld.x == targetPokemon->posWorld.x && pokemon->posWorld.y > targetPokemon->posWorld.y) + { + targetDirection = DIRECTION_NORTH; + } + else if (pokemon->posWorld.x > targetPokemon->posWorld.x && pokemon->posWorld.y == targetPokemon->posWorld.y) + { + targetDirection = DIRECTION_WEST; + } + } + + if (targetDirection > -1 && !gTargetAhead[targetDirection] && IsTargetStraightAhead(pokemon, targetPokemon, targetDirection, RANGED_ATTACK_RANGE)) + { + u32 itemWeight; + u32 *targetWeight; + gTargetAhead[targetDirection] = TRUE; + gPotentialTargetDirections[gNumPotentialTargets] = targetDirection; + targetWeight = &gPotentialTargetWeights[gNumPotentialTargets]; + itemWeight = !ignoreRollChance ? EvaluateItem(targetPokemon, item, targetingFlags) : 100; + *targetWeight = itemWeight; + gNumPotentialTargets++; + } +} |