diff options
author | Seth Barberee <seth.barberee@gmail.com> | 2021-12-28 23:00:59 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-28 23:00:59 -0600 |
commit | edf909be4da55a435bf81f96ffcbd156b2120562 (patch) | |
tree | 7bbce0d40ce8c714e793ef22f3a7c125f9ff3fbd /src/dungeon_ai_items.c | |
parent | 6512ebff67e163a5a6c0f5e19847e2a4dda19ad1 (diff) | |
parent | ea10f7b7bd6957312b9b0dfa371761c5936bc80a (diff) |
Merge pull request #91 from AnonymousRandomPerson/master
More item AI decomp
Diffstat (limited to 'src/dungeon_ai_items.c')
-rw-r--r-- | src/dungeon_ai_items.c | 77 |
1 files changed, 74 insertions, 3 deletions
diff --git a/src/dungeon_ai_items.c b/src/dungeon_ai_items.c index 4afc928..56e4447 100644 --- a/src/dungeon_ai_items.c +++ b/src/dungeon_ai_items.c @@ -3,9 +3,11 @@ #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" +#include "dungeon_ai_attack.h" #include "dungeon_ai_items.h" #include "dungeon_capabilities.h" #include "dungeon_capabilities_1.h" @@ -24,6 +26,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 +35,8 @@ 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 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++; + } +} |