diff --git a/asm/code_8071518.s b/asm/code_8071518.s deleted file mode 100644 index f33352f40..000000000 --- a/asm/code_8071518.s +++ /dev/null @@ -1,54 +0,0 @@ - #include "asm/constants/gba_constants.inc" - #include "asm/macros.inc" - - .syntax unified - - .text - - thumb_func_start CheckRunAwayVisualFlag -CheckRunAwayVisualFlag: - push {r4-r7,lr} - adds r5, r0, 0 - lsls r1, 24 - lsrs r7, r1, 24 - ldr r4, [r5, 0x70] - adds r6, r4, 0 - ldrb r0, [r4, 0x7] - cmp r0, 0 - bne _08071590 - adds r0, r5, 0 - movs r1, 0x2B - bl HasAbility - lsls r0, 24 - cmp r0, 0 - beq _08071590 - movs r2, 0 - movs r1, 0x10 - ldrsh r0, [r4, r1] - lsrs r1, r0, 31 - adds r0, r1 - movs r3, 0xE - ldrsh r1, [r4, r3] - asrs r0, 1 - cmp r1, r0 - bgt _08071576 - movs r2, 0x1 -_08071576: - adds r0, r6, 0 - movs r1, 0x4 - bl SetVisualFlags - lsls r0, 24 - lsrs r0, 24 - cmp r7, 0 - beq _08071590 - cmp r0, 0 - beq _08071590 - adds r0, r5, 0 - bl ShowVisualFlags -_08071590: - pop {r4-r7} - pop {r0} - bx r0 - thumb_func_end CheckRunAwayVisualFlag - - .align 2, 0 \ No newline at end of file diff --git a/asm/code_807167C.s b/asm/code_807167C.s index ee3263149..ca8dda25a 100644 --- a/asm/code_807167C.s +++ b/asm/code_807167C.s @@ -5,72 +5,5 @@ .text - thumb_func_start sub_807167C -sub_807167C: - push {lr} - ldr r2, [r0, 0x70] - ldr r1, [r1, 0x70] - adds r0, r2, 0 - adds r0, 0xA4 - ldrb r0, [r0] - cmp r0, 0x1 - beq _080716D2 - adds r0, r2, 0 - adds r0, 0x40 - ldrb r0, [r0] - cmp r0, 0x4A - beq _0807169A - cmp r0, 0x47 - bne _0807169E -_0807169A: - movs r0, 0x1 - b _080716A0 -_0807169E: - movs r0, 0 -_080716A0: - cmp r0, 0 - bne _080716D2 - ldrb r0, [r2, 0x8] - cmp r0, 0 - bne _080716D2 - adds r0, r1, 0 - adds r0, 0xA4 - ldrb r0, [r0] - cmp r0, 0x1 - beq _080716D2 - adds r0, r1, 0 - adds r0, 0x40 - ldrb r0, [r0] - cmp r0, 0x4A - beq _080716C2 - cmp r0, 0x47 - bne _080716C6 -_080716C2: - movs r0, 0x1 - b _080716C8 -_080716C6: - movs r0, 0 -_080716C8: - cmp r0, 0 - bne _080716D2 - ldrb r0, [r1, 0x8] - cmp r0, 0 - beq _080716D6 -_080716D2: - movs r0, 0x2 - b _080716E4 -_080716D6: - ldrb r0, [r2, 0x6] - ldrb r1, [r1, 0x6] - cmp r0, r1 - bne _080716E2 - movs r0, 0 - b _080716E4 -_080716E2: - movs r0, 0x1 -_080716E4: - pop {r1} - bx r1 - thumb_func_end sub_807167C .align 2, 0 diff --git a/include/dungeon_ai_targeting_1.h b/include/dungeon_ai_targeting_1.h index d59a0ee98..cf40ae71b 100644 --- a/include/dungeon_ai_targeting_1.h +++ b/include/dungeon_ai_targeting_1.h @@ -3,7 +3,12 @@ #include "dungeon_entity.h" +bool8 IsAtJunction(struct DungeonEntity *pokemon); +bool8 ShouldAvoidFirstHit(struct DungeonEntity *pokemon, bool8 forceAvoid); bool8 ShouldAvoidEnemies(struct DungeonEntity *pokemon); bool8 ShouldAvoidEnemiesAndShowEffect(struct DungeonEntity *pokemon, bool8 showRunAwayEffect); +void CheckRunAwayVisualFlag(struct DungeonEntity *pokemon, bool8 showRunAwayEffect); +u8 CanTarget(struct DungeonEntity *pokemon, struct DungeonEntity *targetPokemon, bool8 ignoreInvisible, bool8 checkPetrified); +u8 sub_807167C(struct DungeonEntity * pokemon, struct DungeonEntity * target); #endif diff --git a/include/dungeon_ai_targeting_2.h b/include/dungeon_ai_targeting_2.h deleted file mode 100644 index 5fe43a313..000000000 --- a/include/dungeon_ai_targeting_2.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef GUARD_DUNGEON_AI_TARGETING_2_H -#define GUARD_DUNGEON_AI_TARGETING_2_H - -#include "dungeon_entity.h" - -u8 CanTarget(struct DungeonEntity *pokemon, struct DungeonEntity *targetPokemon, bool8 ignoreInvisible, bool8 checkPetrified); - -#endif diff --git a/ld_script.txt b/ld_script.txt index c84db68b6..eb761ddc2 100755 --- a/ld_script.txt +++ b/ld_script.txt @@ -234,9 +234,6 @@ SECTIONS { src/dungeon_ai_targeting.o(.text); asm/code_8071214.o(.text); src/dungeon_ai_targeting_1.o(.text); - asm/code_8071518.o(.text); - src/dungeon_ai_targeting_2.o(.text); - asm/code_807167C.o(.text); src/dungeon_pokemon_attributes.o(.text); asm/code_80718D8.o(.text); src/dungeon_ai_items.o(.text); @@ -452,7 +449,7 @@ SECTIONS { data/data_8106FB5.o(.rodata); src/dungeon_ai_targeting.o(.rodata); data/data_8106FDD.o(.rodata); - src/dungeon_ai_targeting_2.o(.rodata); + src/dungeon_ai_targeting_1.o(.rodata); data/data_8107010.o(.rodata); src/friend_area.o(.rodata); data/data_810AC60.o(.rodata); diff --git a/src/dungeon_ai_attack.c b/src/dungeon_ai_attack.c index a6f8f77bc..8980822df 100644 --- a/src/dungeon_ai_attack.c +++ b/src/dungeon_ai_attack.c @@ -13,7 +13,6 @@ #include "dungeon_action.h" #include "dungeon_ai_targeting.h" #include "dungeon_ai_targeting_1.h" -#include "dungeon_ai_targeting_2.h" #include "dungeon_capabilities_1.h" #include "dungeon_global_data.h" #include "dungeon_map_access.h" diff --git a/src/dungeon_ai_item_weight.c b/src/dungeon_ai_item_weight.c index ce79ad467..224e25d73 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_targeting_2.h" +#include "dungeon_ai_targeting_1.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 564738f29..1a55eb0a7 100644 --- a/src/dungeon_ai_items.c +++ b/src/dungeon_ai_items.c @@ -9,7 +9,7 @@ #include "dungeon_ai_attack.h" #include "dungeon_ai_item_weight.h" #include "dungeon_ai_items.h" -#include "dungeon_ai_targeting_2.h" +#include "dungeon_ai_targeting_1.h" #include "dungeon_capabilities.h" #include "dungeon_capabilities_1.h" #include "dungeon_entity.h" diff --git a/src/dungeon_ai_targeting_1.c b/src/dungeon_ai_targeting_1.c index 84ee68d79..4d96c1cd7 100644 --- a/src/dungeon_ai_targeting_1.c +++ b/src/dungeon_ai_targeting_1.c @@ -2,9 +2,11 @@ #include "dungeon_ai_targeting_1.h" #include "constants/ability.h" +#include "constants/dungeon.h" #include "constants/iq_skill.h" #include "constants/status.h" #include "constants/tactic.h" +#include "constants/targeting.h" #include "dungeon_engine.h" #include "dungeon_global_data.h" @@ -16,30 +18,67 @@ #include "dungeon_util.h" #include "tile_types.h" -extern void CheckRunAwayVisualFlag(struct DungeonEntity *, bool8 showRunAwayEffect); + extern u8 gDungeonWaterType[]; -bool8 IsAtJunction(struct DungeonEntity *param_1) +extern bool8 SetVisualFlags(struct DungeonEntityData *, u32, bool8); +extern void ShowVisualFlags(struct DungeonEntity *r0); + +const u8 gTargetingData[3][2][2][2] = { + { + { + {TARGET_CAPABILITY_CANNOT_ATTACK, TARGET_CAPABILITY_CAN_ATTACK_NOT_TARGET}, + {TARGET_CAPABILITY_CAN_TARGET, TARGET_CAPABILITY_CAN_ATTACK_NOT_TARGET} + }, + { + {TARGET_CAPABILITY_CAN_TARGET, TARGET_CAPABILITY_CAN_ATTACK_NOT_TARGET}, + {TARGET_CAPABILITY_CANNOT_ATTACK, TARGET_CAPABILITY_CAN_ATTACK_NOT_TARGET} + } + }, + { + { + {TARGET_CAPABILITY_CANNOT_ATTACK, TARGET_CAPABILITY_CAN_ATTACK_NOT_TARGET}, + {TARGET_CAPABILITY_CAN_TARGET, TARGET_CAPABILITY_CAN_ATTACK_NOT_TARGET} + }, + { + {TARGET_CAPABILITY_CAN_ATTACK_NOT_TARGET, TARGET_CAPABILITY_CAN_TARGET}, + {TARGET_CAPABILITY_CAN_ATTACK_NOT_TARGET, TARGET_CAPABILITY_CAN_TARGET} + } + }, + { + { + {TARGET_CAPABILITY_CAN_ATTACK_NOT_TARGET, TARGET_CAPABILITY_CAN_TARGET}, + {TARGET_CAPABILITY_CAN_ATTACK_NOT_TARGET, TARGET_CAPABILITY_CAN_TARGET} + }, + { + {TARGET_CAPABILITY_CAN_TARGET, TARGET_CAPABILITY_CAN_ATTACK_NOT_TARGET}, + {TARGET_CAPABILITY_CANNOT_ATTACK, TARGET_CAPABILITY_CAN_ATTACK_NOT_TARGET} + } + } +}; + + +bool8 IsAtJunction(struct DungeonEntity *pokemon) { char cVar2; u32 crossableTerrain; struct MapTile *mapTile; struct DungeonEntityData *iVar7; - crossableTerrain = GetCrossableTerrain(param_1->entityData->entityID); + crossableTerrain = GetCrossableTerrain(pokemon->entityData->entityID); if (!IsFixedDungeon()) { - if ((param_1->entityData->transformStatus == TRANSFORM_STATUS_MOBILE) || (HasItem(param_1, ITEM_ID_MOBILE_SCARF))) { + if ((pokemon->entityData->transformStatus == TRANSFORM_STATUS_MOBILE) || (HasItem(pokemon, ITEM_ID_MOBILE_SCARF))) { crossableTerrain = CROSSABLE_TERRAIN_WALL; } - else if (HasIQSkill(param_1, IQ_SKILL_ALL_TERRAIN_HIKER)) { + else if (HasIQSkill(pokemon, IQ_SKILL_ALL_TERRAIN_HIKER)) { crossableTerrain = CROSSABLE_TERRAIN_CREVICE; } - else if (HasIQSkill(param_1, IQ_SKILL_SUPER_MOBILE)) { + else if (HasIQSkill(pokemon, IQ_SKILL_SUPER_MOBILE)) { crossableTerrain = CROSSABLE_TERRAIN_WALL; } } if (crossableTerrain == CROSSABLE_TERRAIN_WALL) { - iVar7 = param_1->entityData; + iVar7 = pokemon->entityData; iVar7->mobileTurnTimer += DungeonRandomCapped(100); if (iVar7->mobileTurnTimer < 200) { return FALSE; @@ -50,10 +89,10 @@ bool8 IsAtJunction(struct DungeonEntity *param_1) else { if ((gDungeonWaterType[gDungeonGlobalData->tileset] == DUNGEON_WATER_TYPE_LAVA) && (crossableTerrain == CROSSABLE_TERRAIN_LIQUID) - && (HasIQSkill(param_1, IQ_SKILL_LAVA_EVADER))) { + && (HasIQSkill(pokemon, IQ_SKILL_LAVA_EVADER))) { crossableTerrain = CROSSABLE_TERRAIN_REGULAR; } - mapTile = GetMapTile_1(param_1->posWorld.x, param_1->posWorld.y); + mapTile = GetMapTile_1(pokemon->posWorld.x, pokemon->posWorld.y); cVar2 = mapTile->canMoveAdjacent[crossableTerrain]; if ((cVar2 != 0x54) && (cVar2 != 0x51) && (cVar2 != 0x45) && (cVar2 != 0x15) && (cVar2 != 0x55)) return FALSE; } @@ -112,3 +151,128 @@ bool8 ShouldAvoidEnemiesAndShowEffect(struct DungeonEntity *pokemon, bool8 showR } return FALSE; } + +void CheckRunAwayVisualFlag(struct DungeonEntity *pokemon, bool8 showRunAwayEffect) +{ + bool8 cVar1; + struct DungeonEntityData *iVar2; + struct DungeonEntityData *iVar3; + + iVar2 = pokemon->entityData; + iVar3 = iVar2; + + if (((!iVar2->isLeader) && HasAbility(pokemon,ABILITY_RUN_AWAY) && + (cVar1 = SetVisualFlags(iVar3,4,iVar2->HP <= iVar2->maxHP / 2), showRunAwayEffect)) && + (cVar1)) { + ShowVisualFlags(pokemon); + } +} + +u8 CanTarget(struct DungeonEntity *pokemon, struct DungeonEntity *targetPokemon, bool8 ignoreInvisible, bool8 checkPetrified) +{ + struct DungeonEntityData *pokemonData = pokemon->entityData; + struct DungeonEntityData *targetData = targetPokemon->entityData; + u8 targetingDecoy; + u8 pokemonTargetingDecoy; + bool8 pokemonIsEnemy; + bool8 targetIsEnemy; + bool8 targetIsDecoy; + if (pokemon == targetPokemon) + { + return TARGET_CAPABILITY_CANNOT_ATTACK; + } + if (pokemonData->shopkeeperMode == SHOPKEEPER_FRIENDLY || + targetData->shopkeeperMode == SHOPKEEPER_FRIENDLY || + pokemonData->clientType == CLIENT_TYPE_DONT_MOVE || + targetData->clientType == CLIENT_TYPE_DONT_MOVE || + pokemonData->clientType == CLIENT_TYPE_CLIENT || + targetData->clientType == CLIENT_TYPE_CLIENT || + (checkPetrified && !pokemonData->isEnemy && targetData->immobilizeStatus == IMMOBILIZE_STATUS_PETRIFIED) || + (!ignoreInvisible && targetData->transformStatus == TRANSFORM_STATUS_INVISIBLE && !CanSeeInvisible(pokemon))) + { + return TARGET_CAPABILITY_CAN_ATTACK_NOT_TARGET; + } + pokemonTargetingDecoy = pokemonData->targetingDecoy; + targetingDecoy = TARGETING_DECOY_NONE; + if (pokemonTargetingDecoy != TARGETING_DECOY_NONE) + { + targetingDecoy = TARGETING_DECOY_WILD; + if (pokemonTargetingDecoy == TARGETING_DECOY_TEAM) + { + targetingDecoy = TARGETING_DECOY_TEAM; + } + } + if (pokemonData->shopkeeperMode != SHOPKEEPER_NONE) + { + pokemonIsEnemy = FALSE; + if (pokemonData->shopkeeperMode == SHOPKEEPER_AGGRESSIVE_TO_PLAYER) + { + pokemonIsEnemy = TRUE; + } + } + else + { + pokemonIsEnemy = pokemonData->isEnemy ? TRUE : FALSE; + } + if (targetData->shopkeeperMode != SHOPKEEPER_NONE) + { + targetIsEnemy = FALSE; + if (targetData->shopkeeperMode == SHOPKEEPER_AGGRESSIVE_TO_PLAYER) + { + targetIsEnemy = TRUE; + } + } + else + { + targetIsEnemy = targetData->isEnemy ? TRUE : FALSE; + } + targetIsDecoy = FALSE; + if (targetData->waitingStatus == WAITING_STATUS_DECOY) + { + targetIsDecoy = TRUE; + } + return gTargetingData[targetingDecoy][pokemonIsEnemy][targetIsEnemy][targetIsDecoy]; +} + +static inline bool8 JoinLocationCannotUseItems_1(struct DungeonEntityData *pokemonData) +{ + if (pokemonData->joinLocation == DUNGEON_JOIN_LOCATION_CLIENT_POKEMON) + { + return TRUE; + } + if (pokemonData->joinLocation == DUNGEON_RESCUE_TEAM_BASE) + { + return TRUE; + } + return FALSE; +} + +u8 sub_807167C(struct DungeonEntity * pokemon, struct DungeonEntity * target) +{ + bool8 bVar1; + struct DungeonEntityData * iVar3; + struct DungeonEntityData * iVar4; + + iVar4 = pokemon->entityData; + iVar3 = target->entityData; + if (iVar4->clientType != CLIENT_TYPE_CLIENT) { + bVar1 = JoinLocationCannotUseItems_1(iVar4); + if (!bVar1 && (iVar4->shopkeeperMode == SHOPKEEPER_NONE) && (iVar3->clientType != CLIENT_TYPE_CLIENT)) { + bVar1 = JoinLocationCannotUseItems_1(iVar3); + if (bVar1 || (iVar3->shopkeeperMode != SHOPKEEPER_NONE)) { +error: + return TARGET_CAPABILITY_CAN_ATTACK_NOT_TARGET; + } + else + { + if ((iVar4->isEnemy) != (iVar3->isEnemy)) { + return TARGET_CAPABILITY_CAN_TARGET; + } + else { + return TARGET_CAPABILITY_CANNOT_ATTACK; + } + } + } + } + goto error; +} diff --git a/src/dungeon_ai_targeting_2.c b/src/dungeon_ai_targeting_2.c deleted file mode 100644 index 83319e15d..000000000 --- a/src/dungeon_ai_targeting_2.c +++ /dev/null @@ -1,105 +0,0 @@ -#include "global.h" -#include "dungeon_ai_targeting_2.h" - -#include "constants/status.h" -#include "constants/targeting.h" -#include "dungeon_pokemon_attributes.h" - -const u8 gTargetingData[3][2][2][2] = { - { - { - {TARGET_CAPABILITY_CANNOT_ATTACK, TARGET_CAPABILITY_CAN_ATTACK_NOT_TARGET}, - {TARGET_CAPABILITY_CAN_TARGET, TARGET_CAPABILITY_CAN_ATTACK_NOT_TARGET} - }, - { - {TARGET_CAPABILITY_CAN_TARGET, TARGET_CAPABILITY_CAN_ATTACK_NOT_TARGET}, - {TARGET_CAPABILITY_CANNOT_ATTACK, TARGET_CAPABILITY_CAN_ATTACK_NOT_TARGET} - } - }, - { - { - {TARGET_CAPABILITY_CANNOT_ATTACK, TARGET_CAPABILITY_CAN_ATTACK_NOT_TARGET}, - {TARGET_CAPABILITY_CAN_TARGET, TARGET_CAPABILITY_CAN_ATTACK_NOT_TARGET} - }, - { - {TARGET_CAPABILITY_CAN_ATTACK_NOT_TARGET, TARGET_CAPABILITY_CAN_TARGET}, - {TARGET_CAPABILITY_CAN_ATTACK_NOT_TARGET, TARGET_CAPABILITY_CAN_TARGET} - } - }, - { - { - {TARGET_CAPABILITY_CAN_ATTACK_NOT_TARGET, TARGET_CAPABILITY_CAN_TARGET}, - {TARGET_CAPABILITY_CAN_ATTACK_NOT_TARGET, TARGET_CAPABILITY_CAN_TARGET} - }, - { - {TARGET_CAPABILITY_CAN_TARGET, TARGET_CAPABILITY_CAN_ATTACK_NOT_TARGET}, - {TARGET_CAPABILITY_CANNOT_ATTACK, TARGET_CAPABILITY_CAN_ATTACK_NOT_TARGET} - } - } -}; - -u8 CanTarget(struct DungeonEntity *pokemon, struct DungeonEntity *targetPokemon, bool8 ignoreInvisible, bool8 checkPetrified) -{ - struct DungeonEntityData *pokemonData = pokemon->entityData; - struct DungeonEntityData *targetData = targetPokemon->entityData; - u8 targetingDecoy; - u8 pokemonTargetingDecoy; - bool8 pokemonIsEnemy; - bool8 targetIsEnemy; - bool8 targetIsDecoy; - if (pokemon == targetPokemon) - { - return TARGET_CAPABILITY_CANNOT_ATTACK; - } - if (pokemonData->shopkeeperMode == SHOPKEEPER_FRIENDLY || - targetData->shopkeeperMode == SHOPKEEPER_FRIENDLY || - pokemonData->clientType == CLIENT_TYPE_DONT_MOVE || - targetData->clientType == CLIENT_TYPE_DONT_MOVE || - pokemonData->clientType == CLIENT_TYPE_CLIENT || - targetData->clientType == CLIENT_TYPE_CLIENT || - (checkPetrified && !pokemonData->isEnemy && targetData->immobilizeStatus == IMMOBILIZE_STATUS_PETRIFIED) || - (!ignoreInvisible && targetData->transformStatus == TRANSFORM_STATUS_INVISIBLE && !CanSeeInvisible(pokemon))) - { - return TARGET_CAPABILITY_CAN_ATTACK_NOT_TARGET; - } - pokemonTargetingDecoy = pokemonData->targetingDecoy; - targetingDecoy = TARGETING_DECOY_NONE; - if (pokemonTargetingDecoy != TARGETING_DECOY_NONE) - { - targetingDecoy = TARGETING_DECOY_WILD; - if (pokemonTargetingDecoy == TARGETING_DECOY_TEAM) - { - targetingDecoy = TARGETING_DECOY_TEAM; - } - } - if (pokemonData->shopkeeperMode != SHOPKEEPER_NONE) - { - pokemonIsEnemy = FALSE; - if (pokemonData->shopkeeperMode == SHOPKEEPER_AGGRESSIVE_TO_PLAYER) - { - pokemonIsEnemy = TRUE; - } - } - else - { - pokemonIsEnemy = pokemonData->isEnemy ? TRUE : FALSE; - } - if (targetData->shopkeeperMode != SHOPKEEPER_NONE) - { - targetIsEnemy = FALSE; - if (targetData->shopkeeperMode == SHOPKEEPER_AGGRESSIVE_TO_PLAYER) - { - targetIsEnemy = TRUE; - } - } - else - { - targetIsEnemy = targetData->isEnemy ? TRUE : FALSE; - } - targetIsDecoy = FALSE; - if (targetData->waitingStatus == WAITING_STATUS_DECOY) - { - targetIsDecoy = TRUE; - } - return gTargetingData[targetingDecoy][pokemonIsEnemy][targetIsEnemy][targetIsDecoy]; -}