From 85adf50cbde1415311fbef11ae52349d41a8192e Mon Sep 17 00:00:00 2001 From: AnonymousRandomPerson Date: Wed, 5 Mar 2025 23:11:04 -0500 Subject: [PATCH] Decomped CanSeeInvisibleMonsters --- asm/include/overlay_29_02301D78.inc | 3 +-- asm/overlay_29_02301D78.s | 17 ----------------- include/dungeon_ai_targeting_1.h | 10 +++++----- include/dungeon_pokemon_attributes_1.h | 6 +++++- src/dungeon_ai_targeting_1.c | 15 +++++++-------- src/dungeon_pokemon_attributes_1.c | 17 +++++++++++++++-- 6 files changed, 33 insertions(+), 35 deletions(-) diff --git a/asm/include/overlay_29_02301D78.inc b/asm/include/overlay_29_02301D78.inc index 96d00ea0..625aaec3 100644 --- a/asm/include/overlay_29_02301D78.inc +++ b/asm/include/overlay_29_02301D78.inc @@ -1,8 +1,7 @@ #pragma once .public AbilityIsActive -.public DefenderAbilityIsActive__02301A0C .public DUNGEON_PTR +.public DefenderAbilityIsActive__02301A0C .public EntityIsValid__023000E4 .public GravityIsActive -.public ItemIsActive__022FF898 .public ov29_022FAFD4 diff --git a/asm/overlay_29_02301D78.s b/asm/overlay_29_02301D78.s index 94fc9eee..147266a7 100644 --- a/asm/overlay_29_02301D78.s +++ b/asm/overlay_29_02301D78.s @@ -166,20 +166,3 @@ _02301ED4: bl IsTypeAffectedByGravity ldmia sp!, {r3, pc} arm_func_end HasTypeAffectedByGravity - - arm_func_start CanSeeInvisibleMonsters -CanSeeInvisibleMonsters: ; 0x02301EEC - stmdb sp!, {r3, lr} - ldr r1, [r0, #0xb4] - ldrb r1, [r1, #0xf1] - cmp r1, #3 - moveq r0, #1 - ldmeqia sp!, {r3, pc} - mov r1, #0x21 - bl ItemIsActive__022FF898 - cmp r0, #0 - movne r0, #1 - moveq r0, #0 - and r0, r0, #0xff - ldmia sp!, {r3, pc} - arm_func_end CanSeeInvisibleMonsters diff --git a/include/dungeon_ai_targeting_1.h b/include/dungeon_ai_targeting_1.h index 0f91a71d..e26abe23 100644 --- a/include/dungeon_ai_targeting_1.h +++ b/include/dungeon_ai_targeting_1.h @@ -7,11 +7,11 @@ // Called to check if a monster should treat another as an ally, enemy, or ignore it. // (Examples of the "ignore" case: target is a shopkeeper, there is a decoy on the floor, etc.) // -// r0: Pointer to entity 1 -// r1: Pointer to entity 2 -// r2: If false, return TREATMENT_IGNORE if entity 2 is invisible and entity 1 cannot see invisible monsters -// r3: If true, return TREATMENT_IGNORE if entity 1 is a team member and entity 2 has the STATUS_PETRIFIED status +// entity1: Pointer to entity 1 +// entity2: Pointer to entity 2 +// see_invisible_targets: If false, return TREATMENT_IGNORE if entity 2 is invisible and entity 1 cannot see invisible monsters +// ignore_petrified_targets: If true, return TREATMENT_IGNORE if entity 1 is a team member and entity 2 has the STATUS_PETRIFIED status // return: Treatment that monster 1 should apply to monster 2 -enum monster_treatment GetTreatmentBetweenMonsters(struct entity *pokemon, struct entity *target_pokemon, bool8 ignore_invisible, bool8 check_petrified); +enum monster_treatment GetTreatmentBetweenMonsters(struct entity *entity1, struct entity *entity2, bool8 see_invisible_targets, bool8 ignore_petrified_targets); #endif //PMDSKY_DUNGEON_AI_TARGETING_1_H diff --git a/include/dungeon_pokemon_attributes_1.h b/include/dungeon_pokemon_attributes_1.h index 7bbfb7b0..475bb636 100644 --- a/include/dungeon_pokemon_attributes_1.h +++ b/include/dungeon_pokemon_attributes_1.h @@ -3,6 +3,10 @@ #include "dungeon_mode.h" -bool8 IsTacticSet(struct entity *pokemon, enum tactic_id tactic_id); +// Returns whether a certain monster can see other invisible monsters. +// To be precise, this function returns true if the monster is holding Goggle Specs or if it has the status status::STATUS_EYEDROPS. +bool8 CanSeeInvisibleMonsters(struct entity *entity); +// Returns whether a monster is set to use a specific tactic. +bool8 IsTacticSet(struct entity *entity, enum tactic_id tactic_id); #endif //PMDSKY_DUNGEON_POKEMON_ATTRIBUTES_1_H diff --git a/src/dungeon_ai_targeting_1.c b/src/dungeon_ai_targeting_1.c index d1b9e93a..a742f289 100644 --- a/src/dungeon_ai_targeting_1.c +++ b/src/dungeon_ai_targeting_1.c @@ -1,4 +1,5 @@ #include "dungeon_ai_targeting_1.h" +#include "dungeon_pokemon_attributes_1.h" #include "dungeon_util_static.h" const enum monster_treatment MONSTER_TREATMENT_DATA[4][2][2][2] = { @@ -52,13 +53,11 @@ enum decoy_ai_treatment DECOY_AI_TREATMENT_WILD = 3, }; -extern bool8 CanSeeInvisibleMonsters(struct entity *pokemon); - -enum monster_treatment GetTreatmentBetweenMonsters(struct entity *pokemon, struct entity *target_pokemon, bool8 ignore_invisible, bool8 check_petrified) +enum monster_treatment GetTreatmentBetweenMonsters(struct entity *entity1, struct entity *entity2, bool8 see_invisible_targets, bool8 ignore_petrified_targets) { - struct monster *pokemon_info = GetEntInfo(pokemon); - struct monster *target_data = GetEntInfo(target_pokemon); - if (pokemon == target_pokemon) + struct monster *pokemon_info = GetEntInfo(entity1); + struct monster *target_data = GetEntInfo(entity2); + if (entity1 == entity2) return TREATMENT_TREAT_AS_ALLY; if (pokemon_info->shopkeeper == SHOPKEEPER_MODE_SHOPKEEPER || target_data->shopkeeper == SHOPKEEPER_MODE_SHOPKEEPER) @@ -67,10 +66,10 @@ enum monster_treatment GetTreatmentBetweenMonsters(struct entity *pokemon, struc if (pokemon_info->monster_behavior == BEHAVIOR_RESCUE_TARGET || target_data->monster_behavior == BEHAVIOR_RESCUE_TARGET) return TREATMENT_IGNORE; - if (check_petrified && !pokemon_info->is_not_team_member && target_data->frozen_class_status.freeze == STATUS_FROZEN_PETRIFIED) + if (ignore_petrified_targets && !pokemon_info->is_not_team_member && target_data->frozen_class_status.freeze == STATUS_FROZEN_PETRIFIED) return TREATMENT_IGNORE; - if (!ignore_invisible && target_data->invisible_class_status.status == STATUS_INVISIBLE_INVISIBLE && !CanSeeInvisibleMonsters(pokemon)) + if (!see_invisible_targets && target_data->invisible_class_status.status == STATUS_INVISIBLE_INVISIBLE && !CanSeeInvisibleMonsters(entity1)) return TREATMENT_IGNORE; u8 pokemon_targeting_decoy = pokemon_info->decoy_ai_tracker; diff --git a/src/dungeon_pokemon_attributes_1.c b/src/dungeon_pokemon_attributes_1.c index d2bcb476..073e1601 100644 --- a/src/dungeon_pokemon_attributes_1.c +++ b/src/dungeon_pokemon_attributes_1.c @@ -1,9 +1,22 @@ #include "dungeon_pokemon_attributes_1.h" #include "dungeon_util_static.h" -bool8 IsTacticSet(struct entity *pokemon, enum tactic_id tactic_id) +extern bool8 ItemIsActive__022FF898(struct entity *entity, enum item_id item_id); + +bool8 CanSeeInvisibleMonsters(struct entity *entity) { - struct monster *pokemon_info = GetEntInfo(pokemon); + if (GetEntInfo(entity)->blinker_class_status.blinded == STATUS_BLINKER_EYEDROPS) + return TRUE; + + if (ItemIsActive__022FF898(entity, ITEM_GOGGLE_SPECS)) + return TRUE; + + return FALSE; +} + +bool8 IsTacticSet(struct entity *entity, enum tactic_id tactic_id) +{ + struct monster *pokemon_info = GetEntInfo(entity); if (pokemon_info->is_team_leader) return tactic_id == TACTIC_YOU_GO_THE_OTHER_WAY;