diff options
author | AnonymousRandomPerson <chenghanngan.us@gmail.com> | 2022-02-21 15:59:34 -0500 |
---|---|---|
committer | AnonymousRandomPerson <chenghanngan.us@gmail.com> | 2022-02-21 17:03:34 -0500 |
commit | 598a588589cb581b269f2e46373c657ec897a3a3 (patch) | |
tree | 7a7cc3f2b8fc689e764b2a09f20233897f8ada9c /src | |
parent | 33d2d6175067e75cd222b8f05234221ec2d2b82b (diff) |
Decomped CanAttackInFront()
Diffstat (limited to 'src')
-rw-r--r-- | src/dungeon_ai_attack.c | 8 | ||||
-rw-r--r-- | src/dungeon_ai_item_weight.c | 2 | ||||
-rw-r--r-- | src/dungeon_ai_items.c | 2 | ||||
-rw-r--r-- | src/dungeon_ai_targeting.c | 62 | ||||
-rw-r--r-- | src/dungeon_ai_targeting_1.c (renamed from src/dungeon_ai.c) | 2 | ||||
-rw-r--r-- | src/dungeon_ai_targeting_2.c (renamed from src/dungeon_ai_1.c) | 2 | ||||
-rw-r--r-- | src/dungeon_capabilities_1.c | 6 |
7 files changed, 73 insertions, 11 deletions
diff --git a/src/dungeon_ai_attack.c b/src/dungeon_ai_attack.c index 092bab5..7368e66 100644 --- a/src/dungeon_ai_attack.c +++ b/src/dungeon_ai_attack.c @@ -10,7 +10,8 @@ #include "constants/type.h" #include "charge_move.h" #include "dungeon_action.h" -#include "dungeon_ai.h" +#include "dungeon_ai_targeting.h" +#include "dungeon_ai_targeting_1.h" #include "dungeon_ai_attack_1.h" #include "dungeon_capabilities_1.h" #include "dungeon_global_data.h" @@ -37,9 +38,8 @@ extern s32 gPotentialTargetWeights_2[NUM_DIRECTIONS]; extern u8 gPotentialAttackTargetDirections[NUM_DIRECTIONS]; extern struct DungeonEntity *gPotentialTargets[NUM_DIRECTIONS]; -extern bool8 IsMoveUsable(struct DungeonEntity*, s32, bool8); +extern bool8 IsMoveUsable_1(struct DungeonEntity*, s32, bool8); extern bool8 TargetRegularAttack(struct DungeonEntity*, u32*, bool8); -extern bool8 CanAttackInFront(struct DungeonEntity*, s32); extern s32 WeightMoveIfUsable(s32, s32, struct DungeonEntity*, struct DungeonEntity*, struct PokemonMove*, bool8); extern bool8 IsTargetInLineRange(struct DungeonEntity*, struct DungeonEntity*, s32); extern bool8 CanUseStatusMove(s32, struct DungeonEntity*, struct DungeonEntity*, struct PokemonMove*, bool8); @@ -182,7 +182,7 @@ void DecideAttack(struct DungeonEntity *pokemon) move = &pokemonData->moves[i]; if (move->moveFlags & MOVE_FLAG_EXISTS && willNotUnlinkMove[i] && - IsMoveUsable(pokemon, i, hasPPChecker) && + IsMoveUsable_1(pokemon, i, hasPPChecker) && move->moveFlags & MOVE_FLAG_ENABLED) { moveTargetResults[i].moveUsable = TRUE; diff --git a/src/dungeon_ai_item_weight.c b/src/dungeon_ai_item_weight.c index 08652b2..ce79ad4 100644 --- a/src/dungeon_ai_item_weight.c +++ b/src/dungeon_ai_item_weight.c @@ -3,7 +3,7 @@ #include "constants/status.h" #include "constants/targeting.h" -#include "dungeon_ai_1.h" +#include "dungeon_ai_targeting_2.h" #include "dungeon_map_access.h" #include "dungeon_pokemon_attributes.h" #include "dungeon_util.h" diff --git a/src/dungeon_ai_items.c b/src/dungeon_ai_items.c index 52aacc4..0135c62 100644 --- a/src/dungeon_ai_items.c +++ b/src/dungeon_ai_items.c @@ -6,10 +6,10 @@ #include "constants/status.h" #include "constants/targeting.h" #include "dungeon_action.h" -#include "dungeon_ai_1.h" #include "dungeon_ai_attack_1.h" #include "dungeon_ai_item_weight.h" #include "dungeon_ai_items.h" +#include "dungeon_ai_targeting_2.h" #include "dungeon_capabilities.h" #include "dungeon_capabilities_1.h" #include "dungeon_entity.h" diff --git a/src/dungeon_ai_targeting.c b/src/dungeon_ai_targeting.c new file mode 100644 index 0000000..ec5abd9 --- /dev/null +++ b/src/dungeon_ai_targeting.c @@ -0,0 +1,62 @@ +#include "global.h" +#include "dungeon_ai_targeting.h" + +#include "constants/iq_skill.h" +#include "constants/item.h" +#include "constants/status.h" +#include "dungeon_engine.h" +#include "dungeon_items.h" +#include "dungeon_map_access.h" +#include "dungeon_movement.h" +#include "dungeon_pokemon_attributes.h" +#include "dungeon_util.h" +#include "map.h" + +const u8 gDirectionBitMasks_2[] = {0x1, 0x2, 0x4, 0x8, 0x10, 0x20, 0x40, 0x80}; + +bool8 CanAttackInFront(struct DungeonEntity *pokemon, s32 direction) +{ + u8 crossableTerrain = GetCrossableTerrain(pokemon->entityData->entityID); + struct MapTile *tile; + if (crossableTerrain < CROSSABLE_TERRAIN_CREVICE) + { + crossableTerrain = CROSSABLE_TERRAIN_CREVICE; + } + tile = GetMapTile_1(pokemon->posWorld.x + gAdjacentTileOffsets[direction].x, + pokemon->posWorld.y + gAdjacentTileOffsets[direction].y); + if (!(tile->tileType & TILE_TYPE_MAP_EDGE) && + (tile->pokemon == NULL || GetEntityType(tile->pokemon) == ENTITY_POKEMON)) + { + if (!IsFixedDungeon()) + { + if (pokemon->entityData->transformStatus == TRANSFORM_STATUS_MOBILE || + HasItem(pokemon, ITEM_ID_MOBILE_SCARF)) + { + crossableTerrain = CROSSABLE_TERRAIN_WALL; + } + else if (HasIQSkill(pokemon, IQ_SKILL_ALL_TERRAIN_HIKER)) + { + // BUG: If the Pokémon is a Ghost type that can normally attack through walls, + // All-Terrain Hiker/Super Mobile may make the AI think it can't attack through walls. + crossableTerrain = CROSSABLE_TERRAIN_CREVICE; + } + else if (HasIQSkill(pokemon, IQ_SKILL_SUPER_MOBILE)) + { + if ((direction & 1) != 0) + { + crossableTerrain = CROSSABLE_TERRAIN_CREVICE; + } + else + { + crossableTerrain = CROSSABLE_TERRAIN_WALL; + } + } + } + tile = GetMapTile_1(pokemon->posWorld.x, pokemon->posWorld.y); + if (tile->canMoveAdjacent[crossableTerrain] & gDirectionBitMasks_2[direction & DIRECTION_MASK]) + { + return TRUE; + } + } + return FALSE; +} diff --git a/src/dungeon_ai.c b/src/dungeon_ai_targeting_1.c index b2e3b2e..5ff76b0 100644 --- a/src/dungeon_ai.c +++ b/src/dungeon_ai_targeting_1.c @@ -1,5 +1,5 @@ #include "global.h" -#include "dungeon_ai.h" +#include "dungeon_ai_targeting_1.h" #include "constants/ability.h" #include "constants/tactic.h" diff --git a/src/dungeon_ai_1.c b/src/dungeon_ai_targeting_2.c index 78c899f..83319e1 100644 --- a/src/dungeon_ai_1.c +++ b/src/dungeon_ai_targeting_2.c @@ -1,5 +1,5 @@ #include "global.h" -#include "dungeon_ai_1.h" +#include "dungeon_ai_targeting_2.h" #include "constants/status.h" #include "constants/targeting.h" diff --git a/src/dungeon_capabilities_1.c b/src/dungeon_capabilities_1.c index 605f9e9..ef566fe 100644 --- a/src/dungeon_capabilities_1.c +++ b/src/dungeon_capabilities_1.c @@ -5,7 +5,7 @@ #include "constants/iq_skill.h" #include "constants/status.h" #include "charge_move.h" -#include "dungeon_ai.h" +#include "dungeon_ai_targeting_1.h" #include "dungeon_capabilities.h" #include "dungeon_engine.h" #include "dungeon_items.h" @@ -15,7 +15,7 @@ #include "dungeon_util.h" #include "map.h" -const u8 gDirectionBitMasks[] = {0x1, 0x2, 0x4, 0x8, 0x10, 0x20, 0x40, 0x80}; +const u8 gDirectionBitMasks_1[] = {0x1, 0x2, 0x4, 0x8, 0x10, 0x20, 0x40, 0x80}; static inline bool8 JoinLocationCannotUseItems(struct DungeonEntityData *pokemonData) { @@ -119,7 +119,7 @@ bool8 CanMoveInDirection(struct DungeonEntity *pokemon, u32 facingDir) } } currentMapTile = GetMapTile_1(pokemon->posWorld.x, pokemon->posWorld.y); - if (!(currentMapTile->canMoveAdjacent[crossableTerrain] & gDirectionBitMasks[facingDir & DIRECTION_MASK])) + if (!(currentMapTile->canMoveAdjacent[crossableTerrain] & gDirectionBitMasks_1[facingDir & DIRECTION_MASK])) { return FALSE; } |