From b829b761f67113aa688318eded9e1b2f949c20d7 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Sun, 30 Mar 2025 22:59:59 +0200 Subject: [PATCH] pokemon attributes, moveement, ai targeting into dungeon_logic.c --- include/dungeon_ai_targeting.h | 28 - include/dungeon_logic.h | 59 ++ include/dungeon_movement.h | 19 - include/dungeon_pokemon_attributes.h | 21 - ld_script.txt | 6 +- src/code_803E724.c | 2 +- src/code_8041AD0.c | 2 +- src/code_8066D04.c | 4 +- src/code_8069E0C.c | 4 +- src/code_806CD90.c | 4 +- src/code_806E8B0.c | 4 +- src/code_806FDF4.c | 2 +- src/code_80718D8.c | 4 +- src/code_8072B78.c | 4 +- src/code_8073CF0.c | 6 +- src/code_8075708.c | 4 +- src/code_8077274_1.c | 6 +- src/code_807CD9C.c | 4 +- src/code_807E1A0.c | 2 +- src/code_807E5AC.c | 8 +- src/code_808417C.c | 2 +- src/code_80848F0.c | 2 +- src/dungeon_8067A80.c | 4 +- src/dungeon_action.c | 2 +- src/dungeon_ai.c | 4 +- src/dungeon_ai_attack.c | 4 +- src/dungeon_ai_item_weight.c | 4 +- src/dungeon_ai_items.c | 4 +- src/dungeon_ai_leader.c | 6 +- src/dungeon_ai_movement.c | 6 +- src/dungeon_cutscenes.c | 2 +- src/dungeon_engine.c | 4 +- src/dungeon_item_action.c | 4 +- src/dungeon_items.c | 2 +- ...dungeon_ai_targeting.c => dungeon_logic.c} | 613 +++++++++++++++++- src/dungeon_main.c | 6 +- src/dungeon_map_access.c | 2 +- src/dungeon_menu_items.c | 4 +- src/dungeon_menu_moves.c | 4 +- src/dungeon_menu_team.c | 6 +- src/dungeon_misc.c | 6 +- src/dungeon_move.c | 4 +- src/dungeon_move_util.c | 4 +- src/dungeon_movement.c | 348 ---------- src/dungeon_music.c | 2 +- src/dungeon_pokemon_attributes.c | 275 -------- src/dungeon_serializer.c | 2 +- src/dungeon_util.c | 4 +- src/move_checks.c | 4 +- src/move_effects_target.c | 4 +- src/move_orb_actions_1.c | 6 +- src/move_orb_actions_2.c | 6 +- src/move_orb_actions_3.c | 6 +- src/move_orb_actions_4.c | 4 +- src/status.c | 6 +- src/status_checks.c | 2 +- src/targeting_flags.c | 2 +- src/trap.c | 2 +- src/type_effectiveness.c | 2 +- sym_ewram.txt | 2 +- 60 files changed, 758 insertions(+), 811 deletions(-) delete mode 100644 include/dungeon_ai_targeting.h create mode 100644 include/dungeon_logic.h delete mode 100644 include/dungeon_movement.h delete mode 100644 include/dungeon_pokemon_attributes.h rename src/{dungeon_ai_targeting.c => dungeon_logic.c} (62%) delete mode 100644 src/dungeon_movement.c delete mode 100644 src/dungeon_pokemon_attributes.c diff --git a/include/dungeon_ai_targeting.h b/include/dungeon_ai_targeting.h deleted file mode 100644 index b79b5ad3e..000000000 --- a/include/dungeon_ai_targeting.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef GUARD_DUNGEON_AI_TARGETING_H -#define GUARD_DUNGEON_AI_TARGETING_H - -#include "structs/dungeon_entity.h" - -void SetMessageArgument_2(u8 *buffer, EntityInfo *param_2, s32 colorNum); -bool8 HasNegativeStatus(Entity *pokemon); -bool8 IsSleeping(Entity *pokemon); -bool8 HasLowHealth(Entity *pokemon); -s32 sub_8070828(Entity *pokemon, bool8 displayMessage); -void sub_80709C8(u8 *buffer, EntityInfo *entityInfo); -bool8 CheckVariousStatuses2(Entity *pokemon, bool8 checkBlinker); -bool8 sub_8070BC0(Entity* entity); -bool8 CheckVariousConditions(Entity *pokemon); -bool8 CheckVariousStatuses(Entity *pokemon); -bool8 CannotAttack(Entity *pokemon, bool8 skipSleep); -bool8 CanMoveInDirection(Entity *pokemon, u32 direction); -bool8 CanAttackInDirection(Entity *pokemon, s32 direction); -bool8 CanAIMonsterMoveInDirection(Entity *pokemon, s32 direction, bool8 *pokemonInFront); -bool8 IsAtJunction(Entity *pokemon); -bool8 ShouldAvoidFirstHit(Entity *pokemon, bool8 forceAvoid); -bool8 ShouldMonsterRunAway(Entity *pokemon); -bool8 ShouldMonsterRunAwayAndShowEffect(Entity *pokemon, bool8 showRunAwayEffect); -void CheckRunAwayVisualFlag(Entity *pokemon, bool8 showRunAwayEffect); -u8 GetTreatmentBetweenMonsters(Entity *pokemon, Entity *targetPokemon, bool8 ignoreInvisible, bool8 checkPetrified); -u8 sub_807167C(Entity * pokemon, Entity * target); - -#endif diff --git a/include/dungeon_logic.h b/include/dungeon_logic.h new file mode 100644 index 000000000..5d4ca3e0b --- /dev/null +++ b/include/dungeon_logic.h @@ -0,0 +1,59 @@ +#ifndef GUARD_DUNGEON_LOGIC_H +#define GUARD_DUNGEON_LOGIC_H + +#include "structs/map.h" +#include "structs/dungeon_entity.h" + +extern u8 gWalkableTileToCrossableTerrain[8]; + +u8 GetCrossableTerrain(s16 species); +u8 sub_807034C(s32 id, const Tile *tile); +u8 sub_80703A0(Entity *pokemon, DungeonPos *pos); +bool8 CanCrossWalls(Entity *pokemon); +bool8 sub_807049C(Entity *pokemon, DungeonPos *pos); +bool8 sub_8070564(Entity *pokemon, DungeonPos *pos); +bool8 sub_80705F0(Entity *pokemon, DungeonPos *pos); +bool8 sub_80706A4(Entity *pokemon, DungeonPos *pos); +s32 CalcSpeedStage(Entity *pokemon); +s32 sub_8070828(Entity *pokemon, bool8 displayMessage); +void SetMessageArgument_2(u8 *buffer, EntityInfo *param_2, s32 colorNum); +void sub_8070968(u8 *buffer, EntityInfo *entityInfo, s32 colorNum); +void sub_80709C8(u8 *buffer, EntityInfo *entityInfo); +bool8 HasNegativeStatus(Entity *pokemon); +bool8 IsSleeping(Entity *pokemon); +bool8 HasLowHealth(Entity *pokemon); +bool8 CheckVariousStatuses2(Entity *pokemon, bool8 checkBlinker); +bool8 sub_8070BC0(Entity* entity); +bool8 CheckVariousConditions(Entity *pokemon); +bool8 CheckVariousStatuses(Entity *pokemon); +bool8 CannotAttack(Entity *pokemon, bool8 skipSleep); +bool8 CanMoveInDirection(Entity *pokemon, u32 direction); +bool8 sub_8070F3C(Entity * pokemon, DungeonPos *pos, s32 direction); +bool8 sub_8070F14(Entity * pokemon, s32 direction); +bool8 sub_8070F80(Entity * pokemon, s32 direction); +bool8 CanAttackInDirection(Entity *pokemon, s32 direction); +bool8 CanAIMonsterMoveInDirection(Entity *pokemon, s32 direction, bool8 *pokemonInFront); +bool8 IsAtJunction(Entity *pokemon); +bool8 ShouldAvoidFirstHit(Entity *pokemon, bool8 forceAvoid); +bool8 ShouldMonsterRunAway(Entity *pokemon); +bool8 ShouldMonsterRunAwayAndShowEffect(Entity *pokemon, bool8 showRunAwayEffect); +void CheckRunAwayVisualFlag(Entity *pokemon, bool8 showRunAwayEffect); +u8 GetTreatmentBetweenMonsters(Entity *pokemon, Entity *targetPokemon, bool8 ignoreInvisible, bool8 checkPetrified); +u8 sub_807167C(Entity * pokemon, Entity * target); +bool8 HasSafeguardStatus(Entity * pokemon, Entity * target, bool8 displayMessage); +bool8 sub_8071728(Entity * pokemon, Entity * target, bool8 displayMessage); +bool8 sub_80717A4(Entity *pokemon, u16 moveID); +bool8 AbilityIsActive(Entity *pokemon, u8 ability); +bool8 MonsterIsType(Entity *pokemon, u8 type); +bool8 CanSeeInvisibleMonsters(Entity *pokemon); +bool8 IsTacticSet(Entity *pokemon, u8 tactic); +bool8 IQSkillIsEnabled(Entity *pokemon, u8 IQSkill); +void LoadIQSkills(Entity *pokemon); +bool8 CanSeeTeammate(Entity * pokemon); +u8 GetMoveTypeForMonster(Entity *pokemon, Move *pokeMove); +s32 GetMovePower(Entity *pokemon, Move *pokeMove); +bool8 MonsterCanThrowItems(EntityInfo *pokemon); +bool8 sub_8071A8C(Entity *pokemon); +bool8 SetVisualFlags(EntityInfo *entityInfo, u16 newFlag, bool8 param_3); + +#endif diff --git a/include/dungeon_movement.h b/include/dungeon_movement.h deleted file mode 100644 index b98e5e2a8..000000000 --- a/include/dungeon_movement.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef GUARD_DUNGEON_MOVEMENT -#define GUARD_DUNGEON_MOVEMENT - -#include "structs/dungeon_entity.h" -#include "structs/map.h" - -extern u8 gWalkableTileToCrossableTerrain[8]; - -u8 GetCrossableTerrain(s16 species); -u8 sub_807034C(s32 id, const Tile *tile); -u8 sub_80703A0(Entity *pokemon, DungeonPos *pos); -bool8 CanCrossWalls(Entity *pokemon); -bool8 sub_807049C(Entity *pokemon, DungeonPos *pos); -bool8 sub_8070564(Entity *pokemon, DungeonPos *pos); -bool8 sub_80705F0(Entity *pokemon, DungeonPos *pos); -bool8 sub_80706A4(Entity *pokemon, DungeonPos *pos); -s32 CalcSpeedStage(Entity *pokemon); - -#endif diff --git a/include/dungeon_pokemon_attributes.h b/include/dungeon_pokemon_attributes.h deleted file mode 100644 index 018d2201c..000000000 --- a/include/dungeon_pokemon_attributes.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef GUARD_DUNGEON_POKEMON_ATTRIBUTES_H -#define GUARD_DUNGEON_POKEMON_ATTRIBUTES_H - -#include "structs/dungeon_entity.h" - -bool8 HasSafeguardStatus(Entity * param_1, Entity * param_2, bool8 displayMessage); -bool8 sub_8071728(Entity * pokemon, Entity * target, bool8 displayMessage); -bool8 sub_80717A4(Entity *pokemon, u16 moveID); -bool8 AbilityIsActive(Entity *pokemon, u8 ability); -bool8 MonsterIsType(Entity *pokemon, u8 type); -bool8 CanSeeInvisibleMonsters(Entity *pokemon); -bool8 IsTacticSet(Entity *pokemon, u8 tactic); -bool8 IQSkillIsEnabled(Entity *pokemon, u8 IQSkill); -void LoadIQSkills(Entity *pokemon); -bool8 CanSeeTeammate(Entity * pokemon); -u8 GetMoveTypeForMonster(Entity *pokemon, Move *pokeMove); -s32 GetMovePower(Entity *pokemon, Move *pokeMove); -bool8 MonsterCanThrowItems(EntityInfo *pokemon); -bool8 SetVisualFlags(EntityInfo *entityInfo, u16 newFlag, bool8 param_3); - -#endif diff --git a/ld_script.txt b/ld_script.txt index 0352b60ea..4239c9d11 100755 --- a/ld_script.txt +++ b/ld_script.txt @@ -243,9 +243,7 @@ SECTIONS { src/code_806E8B0.o(.text); src/code_806FDF4.o(.text); src/status_checks.o(.text); - src/dungeon_movement.o(.text); - src/dungeon_ai_targeting.o(.text); - src/dungeon_pokemon_attributes.o(.text); + src/dungeon_logic.o(.text); src/code_80718D8.o(.text); asm/code_80718D8.o(.text); src/code_8072B78.o(.text); @@ -580,7 +578,7 @@ SECTIONS { src/code_806CD90.o(.rodata); src/type_effectiveness.o(.data); data/data_8106F7C.o(.rodata); - src/dungeon_ai_targeting.o(.rodata); + src/dungeon_logic.o(.rodata); data/data_8107010.o(.rodata); src/dungeon_serializer.o(.rodata); data/data_8107224.o(.rodata); diff --git a/src/code_803E724.c b/src/code_803E724.c index fa8883ac3..90fad0fbb 100644 --- a/src/code_803E724.c +++ b/src/code_803E724.c @@ -18,7 +18,7 @@ #include "dungeon_map_access.h" #include "dungeon_message.h" #include "dungeon_music.h" -#include "dungeon_pokemon_attributes.h" +#include "dungeon_logic.h" #include "dungeon_range.h" #include "dungeon_util.h" #include "game_options.h" diff --git a/src/code_8041AD0.c b/src/code_8041AD0.c index 44d33aaed..7241971f4 100644 --- a/src/code_8041AD0.c +++ b/src/code_8041AD0.c @@ -16,7 +16,7 @@ #include "code_804267C.h" #include "code_806CD90.h" #include "dungeon_config.h" -#include "dungeon_pokemon_attributes.h" +#include "dungeon_logic.h" #include "dungeon_util.h" #include "items.h" #include "math.h" diff --git a/src/code_8066D04.c b/src/code_8066D04.c index e451f63df..30c4ea857 100644 --- a/src/code_8066D04.c +++ b/src/code_8066D04.c @@ -12,7 +12,7 @@ #include "code_8077274_1.h" #include "code_807CD9C.h" #include "code_8084778.h" -#include "dungeon_ai_targeting.h" +#include "dungeon_logic.h" #include "run_dungeon.h" #include "dungeon_items.h" #include "dungeon_leader.h" @@ -21,7 +21,7 @@ #include "dungeon_misc.h" #include "dungeon_move.h" #include "dungeon_move_util.h" -#include "dungeon_movement.h" +#include "dungeon_logic.h" #include "dungeon_music.h" #include "dungeon_random.h" #include "dungeon_strings.h" diff --git a/src/code_8069E0C.c b/src/code_8069E0C.c index ec075b0e7..858d33d5d 100644 --- a/src/code_8069E0C.c +++ b/src/code_8069E0C.c @@ -22,8 +22,8 @@ #include "dungeon_leader.h" #include "dungeon_map_access.h" #include "dungeon_misc.h" -#include "dungeon_movement.h" -#include "dungeon_pokemon_attributes.h" +#include "dungeon_logic.h" +#include "dungeon_logic.h" #include "dungeon_random.h" #include "dungeon_message.h" #include "dungeon_util.h" diff --git a/src/code_806CD90.c b/src/code_806CD90.c index cf8ed6473..f0dcd6d2d 100644 --- a/src/code_806CD90.c +++ b/src/code_806CD90.c @@ -13,12 +13,12 @@ #include "code_805D8C8.h" #include "code_806CD90.h" #include "code_8077274_1.h" -#include "dungeon_ai_targeting.h" +#include "dungeon_logic.h" #include "dungeon_config.h" #include "dungeon_items.h" #include "dungeon_map_access.h" #include "dungeon_message.h" -#include "dungeon_pokemon_attributes.h" +#include "dungeon_logic.h" #include "dungeon_random.h" #include "dungeon_misc.h" #include "dungeon_util.h" diff --git a/src/code_806E8B0.c b/src/code_806E8B0.c index 2845cc0a4..6c50e3088 100644 --- a/src/code_806E8B0.c +++ b/src/code_806E8B0.c @@ -1,7 +1,7 @@ #include "global.h" #include "constants/ability.h" #include "structs/str_dungeon.h" -#include "dungeon_pokemon_attributes.h" +#include "dungeon_logic.h" #include "text_util.h" #include "dungeon_message.h" #include "string_format.h" @@ -19,7 +19,7 @@ #include "structs/str_damage.h" #include "dungeon_util.h" #include "dungeon_config.h" -#include "dungeon_ai_targeting.h" +#include "dungeon_logic.h" void sub_8042940(Entity *r0); void sub_80428B0(Entity *r0); diff --git a/src/code_806FDF4.c b/src/code_806FDF4.c index a8eb8dece..e25471264 100644 --- a/src/code_806FDF4.c +++ b/src/code_806FDF4.c @@ -11,7 +11,7 @@ #include "code_8097670.h" #include "dungeon.h" #include "dungeon_items.h" -#include "dungeon_pokemon_attributes.h" +#include "dungeon_logic.h" #include "dungeon_random.h" #include "dungeon_util.h" #include "friend_area.h" diff --git a/src/code_80718D8.c b/src/code_80718D8.c index 112b1f45d..59fa2502b 100644 --- a/src/code_80718D8.c +++ b/src/code_80718D8.c @@ -1,7 +1,7 @@ #include "global.h" #include "constants/tactic.h" #include "dungeon_config.h" -#include "dungeon_pokemon_attributes.h" +#include "dungeon_logic.h" #include "dungeon_leader.h" #include "dungeon_message.h" #include "code_8041AD0.h" @@ -14,7 +14,7 @@ #include "pokemon_3.h" #include "code_805D8C8.h" #include "structs/str_806B7F8.h" -#include "dungeon_ai_targeting.h" +#include "dungeon_logic.h" EWRAM_DATA s32 gUnknown_202F31C[2] = {0, 0}; EWRAM_DATA s32 gUnknown_202F324[2] = {0, 0}; diff --git a/src/code_8072B78.c b/src/code_8072B78.c index ff1f91a18..177cc2f54 100644 --- a/src/code_8072B78.c +++ b/src/code_8072B78.c @@ -3,7 +3,7 @@ #include "code_806CD90.h" #include "dungeon_map_access.h" #include "dungeon_message.h" -#include "dungeon_movement.h" +#include "dungeon_logic.h" #include "dungeon_random.h" #include "dungeon_util.h" #include "moves.h" @@ -12,7 +12,7 @@ #include "structs/map.h" #include "structs/str_pokemon.h" #include "structs/str_806B7F8.h" -#include "dungeon_ai_targeting.h" +#include "dungeon_logic.h" extern u8 *gUnknown_80FE2EC[]; diff --git a/src/code_8073CF0.c b/src/code_8073CF0.c index 3ff9de11b..8b60dcd9d 100644 --- a/src/code_8073CF0.c +++ b/src/code_8073CF0.c @@ -3,7 +3,7 @@ #include "items.h" #include "status.h" #include "weather.h" -#include "dungeon_ai_targeting.h" +#include "dungeon_logic.h" #include "structs/dungeon_entity.h" #include "structs/map.h" #include "structs/str_moves.h" @@ -12,7 +12,7 @@ #include "dungeon_map_access.h" #include "code_803E46C.h" #include "code_806CD90.h" -#include "dungeon_movement.h" +#include "dungeon_logic.h" #include "game_options.h" #include "dungeon_items.h" #include "moves.h" @@ -28,7 +28,7 @@ #include "number_util.h" #include "dungeon_message.h" #include "code_8077274_1.h" -#include "dungeon_pokemon_attributes.h" +#include "dungeon_logic.h" #include "math.h" #include "dungeon_config.h" diff --git a/src/code_8075708.c b/src/code_8075708.c index 25e5b5e86..31fb05282 100644 --- a/src/code_8075708.c +++ b/src/code_8075708.c @@ -7,12 +7,12 @@ #include "code_806CD90.h" #include "dungeon_items.h" #include "dungeon_map_access.h" -#include "dungeon_pokemon_attributes.h" +#include "dungeon_logic.h" #include "dungeon_util.h" #include "structs/str_dungeon.h" #include "position_util.h" #include "trap.h" -#include "dungeon_ai_targeting.h" +#include "dungeon_logic.h" extern void sub_8073D14(Entity *); diff --git a/src/code_8077274_1.c b/src/code_8077274_1.c index 64b9996cd..307e78119 100644 --- a/src/code_8077274_1.c +++ b/src/code_8077274_1.c @@ -11,8 +11,8 @@ #include "constants/status.h" #include "constants/type.h" #include "dungeon_items.h" -#include "dungeon_movement.h" -#include "dungeon_pokemon_attributes.h" +#include "dungeon_logic.h" +#include "dungeon_logic.h" #include "dungeon_random.h" #include "dungeon_util.h" #include "move_effects_target.h" @@ -26,7 +26,7 @@ #include "dungeon_map_access.h" #include "structs/str_806B7F8.h" #include "dungeon_config.h" -#include "dungeon_ai_targeting.h" +#include "dungeon_logic.h" extern u8 *gUnknown_80FA8BC[]; extern u8 *gUnknown_80FA824[]; diff --git a/src/code_807CD9C.c b/src/code_807CD9C.c index 070c73ffc..0041ed73a 100644 --- a/src/code_807CD9C.c +++ b/src/code_807CD9C.c @@ -10,8 +10,8 @@ #include "dungeon_ai.h" #include "run_dungeon.h" #include "dungeon_generation.h" -#include "dungeon_movement.h" -#include "dungeon_pokemon_attributes.h" +#include "dungeon_logic.h" +#include "dungeon_logic.h" #include "dungeon_map.h" #include "dungeon_map_access.h" #include "dungeon_util.h" diff --git a/src/code_807E1A0.c b/src/code_807E1A0.c index b33ae19b6..6bc7ff57f 100644 --- a/src/code_807E1A0.c +++ b/src/code_807E1A0.c @@ -7,7 +7,7 @@ #include "dungeon_ai.h" #include "dungeon_leader.h" #include "dungeon_map_access.h" -#include "dungeon_pokemon_attributes.h" +#include "dungeon_logic.h" #include "dungeon_util.h" #include "dungeon_config.h" #include "move_util.h" diff --git a/src/code_807E5AC.c b/src/code_807E5AC.c index 110c0052b..5929469f9 100644 --- a/src/code_807E5AC.c +++ b/src/code_807E5AC.c @@ -10,12 +10,12 @@ #include "pokemon.h" #include "structs/map.h" #include "dungeon_message.h" -#include "dungeon_pokemon_attributes.h" +#include "dungeon_logic.h" #include "string_format.h" -#include "dungeon_movement.h" +#include "dungeon_logic.h" #include "dungeon_map_access.h" -#include "dungeon_movement.h" -#include "dungeon_ai_targeting.h" +#include "dungeon_logic.h" +#include "dungeon_logic.h" #include "position_util.h" #include "dungeon_ai.h" #include "code_806CD90.h" diff --git a/src/code_808417C.c b/src/code_808417C.c index 20c78b8cd..78ce3099a 100644 --- a/src/code_808417C.c +++ b/src/code_808417C.c @@ -2,7 +2,7 @@ #include "constants/ability.h" #include "constants/iq_skill.h" #include "structs/dungeon_entity.h" -#include "dungeon_pokemon_attributes.h" +#include "dungeon_logic.h" #include "dungeon_random.h" #include "dungeon_util.h" diff --git a/src/code_80848F0.c b/src/code_80848F0.c index c96ed81b1..c9b47a2b3 100644 --- a/src/code_80848F0.c +++ b/src/code_80848F0.c @@ -4,7 +4,7 @@ #include "structs/str_dungeon.h" #include "dungeon_cutscenes.h" #include "dungeon_music.h" -#include "dungeon_movement.h" +#include "dungeon_logic.h" #include "dungeon_util_1.h" #include "exclusive_pokemon.h" #include "weather.h" diff --git a/src/dungeon_8067A80.c b/src/dungeon_8067A80.c index 5bee38fa2..54c6bfaf3 100644 --- a/src/dungeon_8067A80.c +++ b/src/dungeon_8067A80.c @@ -12,7 +12,7 @@ #include "code_8077274_1.h" #include "code_807CD9C.h" #include "code_8084778.h" -#include "dungeon_ai_targeting.h" +#include "dungeon_logic.h" #include "run_dungeon.h" #include "dungeon_items.h" #include "dungeon_leader.h" @@ -21,7 +21,7 @@ #include "dungeon_misc.h" #include "dungeon_move.h" #include "dungeon_move_util.h" -#include "dungeon_movement.h" +#include "dungeon_logic.h" #include "dungeon_music.h" #include "dungeon_random.h" #include "dungeon_strings.h" diff --git a/src/dungeon_action.c b/src/dungeon_action.c index 725006daa..da4dad368 100644 --- a/src/dungeon_action.c +++ b/src/dungeon_action.c @@ -7,7 +7,7 @@ #include "structs/dungeon_entity.h" #include "structs/str_dungeon.h" #include "dungeon_leader.h" -#include "dungeon_movement.h" +#include "dungeon_logic.h" #include "dungeon_generation.h" #include "dungeon_util.h" #include "dungeon_strings.h" diff --git a/src/dungeon_ai.c b/src/dungeon_ai.c index 6a30ab2b1..b06e63e64 100644 --- a/src/dungeon_ai.c +++ b/src/dungeon_ai.c @@ -17,11 +17,11 @@ #include "dungeon_ai_attack.h" #include "dungeon_ai_items.h" #include "dungeon_ai_movement.h" -#include "dungeon_ai_targeting.h" +#include "dungeon_logic.h" #include "dungeon_items.h" #include "dungeon_leader.h" #include "dungeon_map_access.h" -#include "dungeon_pokemon_attributes.h" +#include "dungeon_logic.h" #include "dungeon_random.h" #include "dungeon_util_1.h" #include "dungeon_util.h" diff --git a/src/dungeon_ai_attack.c b/src/dungeon_ai_attack.c index acfd0444c..ff7babc70 100644 --- a/src/dungeon_ai_attack.c +++ b/src/dungeon_ai_attack.c @@ -12,12 +12,12 @@ #include "constants/targeting.h" #include "constants/type.h" #include "dungeon_action.h" -#include "dungeon_ai_targeting.h" +#include "dungeon_logic.h" #include "dungeon_ai.h" #include "dungeon_config.h" #include "run_dungeon.h" #include "dungeon_map_access.h" -#include "dungeon_pokemon_attributes.h" +#include "dungeon_logic.h" #include "dungeon_random.h" #include "dungeon_util.h" #include "items.h" diff --git a/src/dungeon_ai_item_weight.c b/src/dungeon_ai_item_weight.c index 3c6183e3b..f87412f90 100644 --- a/src/dungeon_ai_item_weight.c +++ b/src/dungeon_ai_item_weight.c @@ -3,9 +3,9 @@ #include "dungeon_ai_item_weight.h" #include "constants/status.h" #include "constants/targeting.h" -#include "dungeon_ai_targeting.h" +#include "dungeon_logic.h" #include "dungeon_map_access.h" -#include "dungeon_pokemon_attributes.h" +#include "dungeon_logic.h" #include "dungeon_util.h" #include "moves.h" #include "number_util.h" diff --git a/src/dungeon_ai_items.c b/src/dungeon_ai_items.c index 73cdcb657..378cc3ae0 100644 --- a/src/dungeon_ai_items.c +++ b/src/dungeon_ai_items.c @@ -9,11 +9,11 @@ #include "dungeon_ai_attack.h" #include "dungeon_ai_item_weight.h" #include "dungeon_ai_items.h" -#include "dungeon_ai_targeting.h" +#include "dungeon_logic.h" #include "structs/dungeon_entity.h" #include "structs/str_dungeon.h" #include "dungeon_map_access.h" -#include "dungeon_pokemon_attributes.h" +#include "dungeon_logic.h" #include "dungeon_random.h" #include "dungeon_util.h" #include "items.h" diff --git a/src/dungeon_ai_leader.c b/src/dungeon_ai_leader.c index 8b318c9c2..14d960d8f 100644 --- a/src/dungeon_ai_leader.c +++ b/src/dungeon_ai_leader.c @@ -15,11 +15,11 @@ #include "constants/move_id.h" #include "constants/status.h" #include "constants/targeting.h" -#include "dungeon_ai_targeting.h" +#include "dungeon_logic.h" #include "dungeon_items.h" #include "dungeon_leader.h" -#include "dungeon_movement.h" -#include "dungeon_pokemon_attributes.h" +#include "dungeon_logic.h" +#include "dungeon_logic.h" #include "dungeon_random.h" #include "dungeon_util.h" #include "move_util.h" diff --git a/src/dungeon_ai_movement.c b/src/dungeon_ai_movement.c index b241d1ce7..383bb8308 100644 --- a/src/dungeon_ai_movement.c +++ b/src/dungeon_ai_movement.c @@ -8,11 +8,11 @@ #include "constants/tactic.h" #include "dungeon_action.h" #include "dungeon_ai_leader.h" -#include "dungeon_ai_targeting.h" +#include "dungeon_logic.h" #include "structs/str_dungeon.h" #include "dungeon_map_access.h" -#include "dungeon_movement.h" -#include "dungeon_pokemon_attributes.h" +#include "dungeon_logic.h" +#include "dungeon_logic.h" #include "dungeon_random.h" #include "dungeon_range.h" #include "dungeon_util.h" diff --git a/src/dungeon_cutscenes.c b/src/dungeon_cutscenes.c index dd49fa554..bd98fcc6d 100644 --- a/src/dungeon_cutscenes.c +++ b/src/dungeon_cutscenes.c @@ -18,7 +18,7 @@ #include "dungeon_message.h" #include "dungeon_music.h" #include "dungeon_misc.h" -#include "dungeon_pokemon_attributes.h" +#include "dungeon_logic.h" #include "dungeon_random.h" #include "dungeon_util_1.h" #include "dungeon_util.h" diff --git a/src/dungeon_engine.c b/src/dungeon_engine.c index def054e53..e7075b19e 100644 --- a/src/dungeon_engine.c +++ b/src/dungeon_engine.c @@ -6,12 +6,12 @@ #include "dungeon_ai_leader.h" #include "dungeon_ai.h" #include "dungeon_leader.h" -#include "dungeon_movement.h" +#include "dungeon_logic.h" #include "dungeon_util.h" #include "structs/dungeon_entity.h" #include "structs/str_dungeon.h" #include "constants/ability.h" -#include "dungeon_pokemon_attributes.h" +#include "dungeon_logic.h" extern bool8 sub_8044B28(void); extern void TrySpawnMonsterAndActivatePlusMinus(void); diff --git a/src/dungeon_item_action.c b/src/dungeon_item_action.c index 351347a54..3e5330a50 100644 --- a/src/dungeon_item_action.c +++ b/src/dungeon_item_action.c @@ -14,7 +14,7 @@ #include "dungeon_action.h" #include "dungeon_items.h" #include "dungeon_music.h" -#include "dungeon_pokemon_attributes.h" +#include "dungeon_logic.h" #include "dungeon_random.h" #include "dungeon_util.h" #include "move_effects_target.h" @@ -31,7 +31,7 @@ #include "dungeon_misc.h" #include "code_803E724.h" #include "dungeon_data.h" -#include "dungeon_ai_targeting.h" +#include "dungeon_logic.h" extern u8 *gUnknown_80F89F4[]; extern u8 *gUnknown_80FB580[]; diff --git a/src/dungeon_items.c b/src/dungeon_items.c index 11cfb8a1c..15420c01d 100644 --- a/src/dungeon_items.c +++ b/src/dungeon_items.c @@ -16,7 +16,7 @@ #include "dungeon_music.h" #include "dungeon_map.h" #include "dungeon_strings.h" -#include "dungeon_ai_targeting.h" +#include "dungeon_logic.h" #include "string_format.h" #include "items.h" #include "structs/map.h" diff --git a/src/dungeon_ai_targeting.c b/src/dungeon_logic.c similarity index 62% rename from src/dungeon_ai_targeting.c rename to src/dungeon_logic.c index 4681f7852..e1aa6e1b9 100644 --- a/src/dungeon_ai_targeting.c +++ b/src/dungeon_logic.c @@ -1,36 +1,44 @@ #include "global.h" -#include "dungeon_ai_targeting.h" +#include "dungeon_logic.h" +#include "structs/map.h" +#include "constants/item.h" +#include "constants/iq_skill.h" +#include "constants/status.h" +#include "constants/type.h" +#include "constants/weather.h" +#include "run_dungeon.h" +#include "dungeon_items.h" +#include "structs/str_dungeon.h" +#include "dungeon_map_access.h" +#include "dungeon_logic.h" +#include "dungeon_util.h" +#include "pokemon.h" +#include "weather.h" #include "constants/ability.h" #include "constants/dungeon.h" -#include "constants/iq_skill.h" -#include "constants/item.h" -#include "constants/status.h" #include "constants/tactic.h" #include "constants/targeting.h" -#include "run_dungeon.h" -#include "structs/str_dungeon.h" -#include "dungeon_items.h" -#include "dungeon_map_access.h" -#include "dungeon_movement.h" -#include "dungeon_pokemon_attributes.h" #include "dungeon_random.h" -#include "dungeon_util.h" -#include "structs/map.h" #include "dungeon_move_util.h" #include "code_800D090.h" #include "dungeon_message.h" -#include "constants/weather.h" #include "pokemon_mid.h" -#include "pokemon.h" -#include "structs/str_dungeon.h" -#include "weather.h" #include "dungeon_strings.h" +#include "constants/move_id.h" +#include "moves.h" +#include "pokemon_3.h" +#include "pokemon.h" +#include "dungeon_config.h" + +// This file deals with things like controlling movement, walkable tiles, ai targeting, status checks and pokemon attributes. extern const u8 gUnknown_8106FA4[]; extern void sub_80429B4(Entity *r0); extern void ShowVisualFlags(Entity *r0); +EWRAM_DATA u8 gWalkableTileToCrossableTerrain[8] = {0}; + const u8 gDirectionBitMasks_1[] = {0x1, 0x2, 0x4, 0x8, 0x10, 0x20, 0x40, 0x80}; const u8 gDirectionBitMasks_2[] = {0x1, 0x2, 0x4, 0x8, 0x10, 0x20, 0x40, 0x80}; const u8 gDirectionBitMasks_3[] = {0x1, 0x2, 0x4, 0x8, 0x10, 0x20, 0x40, 0x80}; @@ -72,6 +80,335 @@ const u8 gTreatmentData[3][2][2][2] = { } }; +u8 GetCrossableTerrain(s16 species) +{ + u8 walkableTiles = GetMovementType(species); + if (walkableTiles >= NUM_CROSSABLE_TERRAIN) + { + // Pokémon that can cross water or lava have a walkable tile value of 4 (MOVEMENT_TYPE_LAVA) or 5 (MOVEMENT_TYPE_WATER), respectively. + // Indices 4 and 5 in this array are assigned either CROSSABLE_TERRAIN_REGULAR or CROSSABLE_TERRAIN_LIQUID + // depending on whether the dungeon's liquid is water or lava. + // For example, a lava dungeon like Mt. Blaze would have these values: + // gWalkableTileToCrossableTerrain[MOVEMENT_TYPE_LAVA]: CROSSABLE_TERRAIN_LIQUID + // gWalkableTileToCrossableTerrain[MOVEMENT_TYPE_WATER]: CROSSABLE_TERRAIN_REGULAR + // This means a Fire-type can cross the dungeon's liquid, while a Water-type cannot. + return gWalkableTileToCrossableTerrain[walkableTiles]; + } + else + { + return walkableTiles; + } +} + +u8 sub_807034C(s32 id, const Tile *tile) +{ + s32 crossableTerrain; + u16 tileFlags; + s32 id_s32; + + id_s32 = SpeciesId(id); + + if ((tile->monster == NULL) && ((tile->terrainType & TERRAIN_TYPE_IMPASSABLE_WALL) == 0)) { + crossableTerrain = GetCrossableTerrain(id_s32); + tileFlags = tile->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY); + switch(crossableTerrain) + { + case CROSSABLE_TERRAIN_LIQUID: + if(tileFlags == TERRAIN_TYPE_SECONDARY) return FALSE; + case CROSSABLE_TERRAIN_REGULAR: + if(tileFlags == TERRAIN_TYPE_NORMAL) return FALSE; + break; + case CROSSABLE_TERRAIN_WALL: + default: + return FALSE; + case CROSSABLE_TERRAIN_CREVICE: + if(tileFlags != 0) return FALSE; + } + } + return TRUE; +} + +u8 sub_80703A0(Entity *pokemon, DungeonPos *pos) +{ + const Tile *tile; + u8 crossableTerrain; + u16 tileFlags; + EntityInfo *entityInfo; + + entityInfo = GetEntInfo(pokemon); + tile = GetTile(pos->x,pos->y); + if (pos->x < 0 || pos->y < 0) + return TRUE; + if (pos->x >= DUNGEON_MAX_SIZE_X || pos->y >= DUNGEON_MAX_SIZE_Y) + return TRUE; + if (tile->monster != NULL) + return TRUE; + if (tile->terrainType & TERRAIN_TYPE_IMPASSABLE_WALL) + return TRUE; + + if ((IsCurrentFixedRoomBossFight()) || ((entityInfo->invisibleClassStatus.status != STATUS_MOBILE && (!HasHeldItem(pokemon, ITEM_MOBILE_SCARF))))) { + crossableTerrain = GetCrossableTerrain(entityInfo->id); + tileFlags = tile->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY); + if (IQSkillIsEnabled(pokemon, IQ_ALL_TERRAIN_HIKER)) { + crossableTerrain = CROSSABLE_TERRAIN_CREVICE; + } + if (IQSkillIsEnabled(pokemon, IQ_SUPER_MOBILE)) { + crossableTerrain = CROSSABLE_TERRAIN_WALL; + } + switch(crossableTerrain) + { + case CROSSABLE_TERRAIN_LIQUID: + if(tileFlags == TERRAIN_TYPE_SECONDARY) return FALSE; + case CROSSABLE_TERRAIN_REGULAR: + if(tileFlags == TERRAIN_TYPE_NORMAL) return FALSE; + break; + case CROSSABLE_TERRAIN_WALL: + default: + return FALSE; + case CROSSABLE_TERRAIN_CREVICE: + if(tileFlags != 0) return FALSE; + } + } + else { + return FALSE; + } + + return TRUE; +} + +bool8 CanCrossWalls(Entity *pokemon) +{ + EntityInfo *pokemonInfo = GetEntInfo(pokemon); + if (pokemonInfo->invisibleClassStatus.status == STATUS_MOBILE) + { + return TRUE; + } + if (HasHeldItem(pokemon, ITEM_MOBILE_SCARF)) + { + return TRUE; + } + if (GetCrossableTerrain(pokemonInfo->id) == CROSSABLE_TERRAIN_WALL) + { + return TRUE; + } + return FALSE; +} + +bool8 sub_807049C(Entity *pokemon, DungeonPos *pos) +{ + s32 crossableTerrain; + const Tile *tile; + u16 tileFlags; + EntityInfo *entityInfo; + + entityInfo = GetEntInfo(pokemon); + tile = GetTile(pos->x,pos->y); + if (pos->x < 0 || pos->y < 0) + return TRUE; + if (pos->x >= DUNGEON_MAX_SIZE_X || pos->y >= DUNGEON_MAX_SIZE_Y) + return TRUE; + if (tile->terrainType & TERRAIN_TYPE_IMPASSABLE_WALL) + return TRUE; + if (tile->monster != NULL && GetEntityType(tile->monster) != ENTITY_MONSTER) + return TRUE; + + if (IsCurrentFixedRoomBossFight() || (entityInfo->invisibleClassStatus.status != STATUS_MOBILE && !HasHeldItem(pokemon, ITEM_MOBILE_SCARF))) { + crossableTerrain = GetCrossableTerrain(entityInfo->id); + tileFlags = tile->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY); + if (IQSkillIsEnabled(pokemon, IQ_ALL_TERRAIN_HIKER)) { + crossableTerrain = CROSSABLE_TERRAIN_CREVICE; + } + if (IQSkillIsEnabled(pokemon, IQ_SUPER_MOBILE)) { + crossableTerrain = CROSSABLE_TERRAIN_WALL; + } + switch(crossableTerrain) + { + case CROSSABLE_TERRAIN_LIQUID: + if(tileFlags == TERRAIN_TYPE_SECONDARY) return FALSE; + case CROSSABLE_TERRAIN_REGULAR: + if(tileFlags == TERRAIN_TYPE_NORMAL) return FALSE; + break; + case CROSSABLE_TERRAIN_WALL: + default: + return FALSE; + case CROSSABLE_TERRAIN_CREVICE: + if(tileFlags != 0) return FALSE; + } + } + else { + return FALSE; + } + + return TRUE; +} + +bool8 sub_8070564(Entity *pokemon, DungeonPos *pos) +{ + u16 crossableTerrain; + u32 tileFlags; + + EntityInfo *entityInfo = GetEntInfo(pokemon); + const Tile *tile = GetTile(pos->x,pos->y); + + if (pos->x < 0 || pos->y < 0) + return TRUE; + if (pos->x >= DUNGEON_MAX_SIZE_X || pos->y >= DUNGEON_MAX_SIZE_Y) + return TRUE; + if (tile->terrainType & TERRAIN_TYPE_IMPASSABLE_WALL) + return TRUE; + if (tile->monster != NULL && GetEntityType(tile->monster) != ENTITY_MONSTER) + return TRUE; + + crossableTerrain = GetCrossableTerrain(entityInfo->id); + tileFlags = GetTerrainType(tile); + + switch (crossableTerrain) + { + default: + return FALSE; + case CROSSABLE_TERRAIN_WALL: + case CROSSABLE_TERRAIN_CREVICE: + if (tileFlags != TERRAIN_TYPE_WALL) return FALSE; + break; + case CROSSABLE_TERRAIN_REGULAR: + if (tileFlags == TERRAIN_TYPE_NORMAL) return FALSE; + break; + case CROSSABLE_TERRAIN_LIQUID: + if (tileFlags == TERRAIN_TYPE_SECONDARY) return FALSE; + if (tileFlags == TERRAIN_TYPE_NORMAL) return FALSE; + break; + } + + return TRUE; +} + +bool8 sub_80705F0(Entity *pokemon, DungeonPos *pos) +{ + s32 crossableTerrain; + const Tile *tile; + u16 tileFlags; + EntityInfo *entityInfo; + + entityInfo = GetEntInfo(pokemon); + tile = GetTile(pos->x,pos->y); + if (pos->x < 0 || pos->y < 0) + return TRUE; + if (pos->x >= DUNGEON_MAX_SIZE_X || pos->y >= DUNGEON_MAX_SIZE_Y) + return TRUE; + if (((tile->terrainType & TERRAIN_TYPE_IMPASSABLE_WALL) == 0) && (tile->monster == NULL || (GetEntityType(tile->monster) == ENTITY_MONSTER))) { + if (IsCurrentFixedRoomBossFight() || (entityInfo->invisibleClassStatus.status != STATUS_MOBILE && !HasHeldItem(pokemon, ITEM_MOBILE_SCARF))) { + crossableTerrain = GetCrossableTerrain(entityInfo->id); + tileFlags = tile->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY); + if (IQSkillIsEnabled(pokemon, IQ_ALL_TERRAIN_HIKER)) { + crossableTerrain = CROSSABLE_TERRAIN_CREVICE; + } + if (IQSkillIsEnabled(pokemon, IQ_SUPER_MOBILE)) { + crossableTerrain = CROSSABLE_TERRAIN_WALL; + } + + switch(crossableTerrain) + { + case CROSSABLE_TERRAIN_WALL: + default: + return FALSE; + case CROSSABLE_TERRAIN_REGULAR: + case CROSSABLE_TERRAIN_LIQUID: + case CROSSABLE_TERRAIN_CREVICE: + if(tileFlags != 0) return FALSE; + } + } + else return FALSE; + } + return TRUE; +} + +bool8 sub_80706A4(Entity *pokemon, DungeonPos *pos) +{ + s32 crossableTerrain; + const Tile *tile; + u16 tileFlags; + EntityInfo *entityInfo; + + entityInfo = GetEntInfo(pokemon); + tile = GetTile(pos->x,pos->y); + if (pos->x < 0 || pos->y < 0) + return TRUE; + if (pos->x >= DUNGEON_MAX_SIZE_X || pos->y >= DUNGEON_MAX_SIZE_Y) + return TRUE; + if ((((tile->terrainType & TERRAIN_TYPE_IMPASSABLE_WALL) == 0)) + && (tile->monster == NULL || ((GetEntityType(tile->monster) == ENTITY_MONSTER) && (GetEntInfo(tile->monster) == entityInfo)))) { + if (IsCurrentFixedRoomBossFight() || (entityInfo->invisibleClassStatus.status != STATUS_MOBILE && !HasHeldItem(pokemon, ITEM_MOBILE_SCARF))) { + crossableTerrain = GetCrossableTerrain(entityInfo->id); + tileFlags = tile->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY); + if (IQSkillIsEnabled(pokemon, IQ_ALL_TERRAIN_HIKER)) { + crossableTerrain = CROSSABLE_TERRAIN_CREVICE; + } + if (IQSkillIsEnabled(pokemon, IQ_SUPER_MOBILE)) { + crossableTerrain = CROSSABLE_TERRAIN_WALL; + } + switch(crossableTerrain) + { + case CROSSABLE_TERRAIN_LIQUID: + if(tileFlags == TERRAIN_TYPE_SECONDARY) return FALSE; + case CROSSABLE_TERRAIN_REGULAR: + if(tileFlags == TERRAIN_TYPE_NORMAL) return FALSE; + break; + case CROSSABLE_TERRAIN_WALL: + default: + return FALSE; + case CROSSABLE_TERRAIN_CREVICE: + if(tileFlags != 0) return FALSE; + } + } + else return FALSE; + } + return TRUE; +} + +s32 CalcSpeedStage(Entity *pokemon) +{ + s32 index; + s32 speed; + EntityInfo * entityInfo; + + entityInfo = GetEntInfo(pokemon); + speed = 0; + + for(index = 0; index < NUM_SPEED_COUNTERS; index++) + { + if (entityInfo->speedUpCounters[index + NUM_SPEED_COUNTERS] != 0) { + speed--; + } + if (entityInfo->speedUpCounters[index] != 0) { + speed++; + } + } + + if (entityInfo->burnClassStatus.status == STATUS_PARALYSIS) { + speed--; + } + + speed += GetMovementSpeed(entityInfo->id); + if ((MonsterIsType(pokemon, TYPE_ICE)) && (GetApparentWeather(pokemon) == WEATHER_SNOW)) { + speed++; + } + if (entityInfo->apparentID == MONSTER_DEOXYS_SPEED) { + speed++; + } + if ((entityInfo->id == MONSTER_KECLEON) && entityInfo->isNotTeamMember && + gDungeon->unk644.unk2A) { + speed++; + } + if (speed < 0) { + speed = 0; + } + if (MAX_SPEED_STAGE < speed) { + speed = MAX_SPEED_STAGE; + } + entityInfo->speedStage = speed; + return speed; +} + s32 sub_8070828(Entity *pokemon, bool8 displayMessage) { bool8 flag; @@ -867,3 +1204,247 @@ error: } goto error; } + +bool8 HasSafeguardStatus(Entity * pokemon, Entity * target, bool8 displayMessage) +{ + if (GetEntInfo(target)->reflectClassStatus.status == STATUS_SAFEGUARD) { + if (displayMessage) { + SubstitutePlaceholderStringTags(gFormatBuffer_Monsters[0],target,0); + TryDisplayDungeonLoggableMessage3(pokemon,target,gUnknown_80FC2FC); + } + return TRUE; + } + return FALSE; +} + +bool8 sub_8071728(Entity * pokemon, Entity * target, bool8 displayMessage) +{ + if (GetEntInfo(target)->reflectClassStatus.status == STATUS_MIST) { + if (displayMessage) { + SubstitutePlaceholderStringTags(gFormatBuffer_Monsters[0], target, 0); + TryDisplayDungeonLoggableMessage3(pokemon, target, gUnknown_80FC31C); + } + return TRUE; + } + else { + if (AbilityIsActive(target, ABILITY_CLEAR_BODY) || AbilityIsActive(target, ABILITY_WHITE_SMOKE)) { + if (displayMessage) { + SubstitutePlaceholderStringTags(gFormatBuffer_Monsters[0], target, 0); + TryDisplayDungeonLoggableMessage3(pokemon, target, gUnknown_80FCEFC); + } + return TRUE; + } + } + return FALSE; +} + +bool8 sub_80717A4(Entity *pokemon, u16 moveID) +{ + EntityInfo * entityInfo; + s32 i; + + entityInfo = GetEntInfo(pokemon); + if ((entityInfo->sleepClassStatus.status != STATUS_SLEEP) && (entityInfo->sleepClassStatus.status != STATUS_NAPPING) && (entityInfo->sleepClassStatus.status != STATUS_NIGHTMARE)) { + return FALSE; + } + else { + for (i = 0; i < MAX_MON_MOVES; i++) { + Move *move = &entityInfo->moves.moves[i]; + if (MoveFlagExists(move) + && (entityInfo->isTeamLeader || (move->moveFlags & MOVE_FLAG_ENABLED_FOR_AI)) + && sub_805744C(pokemon, move, TRUE) + && move->PP != 0 + && move->id == moveID) + { + return TRUE; + } + } + } + + return FALSE; +} + +bool8 AbilityIsActive(Entity *pokemon, u8 ability) +{ + if (!EntityIsValid(pokemon)) + { + return FALSE; + } + else + { + EntityInfo *pokemonInfo = GetEntInfo(pokemon); + if (pokemonInfo->abilities[0] == ability || pokemonInfo->abilities[1] == ability) + { + return TRUE; + } + return FALSE; + } +} + +bool8 MonsterIsType(Entity *pokemon, u8 type) +{ + EntityInfo *pokemonInfo = pokemonInfo = GetEntInfo(pokemon); + if (type == TYPE_NONE) + { + return FALSE; + } + if (pokemonInfo->types[0] == type) + { + return TRUE; + } + if (pokemonInfo->types[1] == type) + { + return TRUE; + } + return FALSE; +} + +bool8 CanSeeInvisibleMonsters(Entity *pokemon) +{ + EntityInfo *pokemonInfo = GetEntInfo(pokemon); + if (pokemonInfo->blinkerClassStatus.status != STATUS_EYEDROPS) + { + if (!HasHeldItem(pokemon, ITEM_GOGGLE_SPECS)) + return FALSE; + else + return TRUE; + } + else + return TRUE; +} + +bool8 IsTacticSet(Entity *pokemon, u8 tactic) +{ + EntityInfo *pokemonInfo = GetEntInfo(pokemon); + if (pokemonInfo->isTeamLeader) + { + bool8 isGoTheOtherWay = tactic == TACTIC_GO_THE_OTHER_WAY; + return isGoTheOtherWay; + } + return pokemonInfo->tactic == tactic; +} + +bool8 IQSkillIsEnabled(Entity *pokemon, u8 IQSkill) +{ + return IsIQSkillSet(&GetEntInfo(pokemon)->IQSkillFlags, 1 << IQSkill); +} + +UNUSED static bool8 IQSkillPairIsEnabled(Entity *pokemon, u8 IQSkill1, u8 IQSkill2) +{ + return IsIQSkillSet(&GetEntInfo(pokemon)->IQSkillFlags, 1 << IQSkill1 | 1 << IQSkill2); +} + +void LoadIQSkills(Entity *pokemon) +{ + s32 IQSkill; + EntityInfo *pokemonInfo; + + pokemonInfo = GetEntInfo(pokemon); + if (pokemonInfo->isNotTeamMember) { + IqSkillFlags *iqSkills = &pokemonInfo->IQSkillFlags; + SetIQSkill(iqSkills, IQ_STATUS_CHECKER); + SetIQSkill(iqSkills, IQ_PP_CHECKER); + SetIQSkill(iqSkills, IQ_ITEM_CATCHER); + if (pokemonInfo->bossFlag) + SetIQSkill(iqSkills, IQ_SELF_CURER); + if (pokemonInfo->level >= gIqItemMasterMinWildLevel) + SetIQSkill(iqSkills, IQ_ITEM_MASTER); + pokemonInfo->tactic = TACTIC_GO_AFTER_FOES; + } + else { + pokemonInfo->IQSkillFlags.flags[0] = 0; + pokemonInfo->IQSkillFlags.flags[1] = 0; + pokemonInfo->IQSkillFlags.flags[2] = 0; + for(IQSkill = IQ_TYPE_ADVANTAGE_MASTER; IQSkill < NUM_IQ_SKILLS; IQSkill++) + { + if (HasIQForSkill(pokemonInfo->IQ,IQSkill) && + IsIQSkillSet(&pokemonInfo->IQSkillMenuFlags, 1 << IQSkill)) + { + SetIQSkill(&pokemonInfo->IQSkillFlags,IQSkill); + } + } + } +} + +bool8 CanSeeTeammate(Entity * pokemon) +{ + Entity *teamMember; + s32 memberIdx; + + if (GetEntInfo(pokemon)->isNotTeamMember) { + return FALSE; + } + else + { + for(memberIdx = 0; memberIdx < MAX_TEAM_MEMBERS; memberIdx++) + { + teamMember = gDungeon->teamPokemon[memberIdx]; + if (EntityIsValid(pokemon) && (pokemon != teamMember) && (CanSeeTarget(pokemon,teamMember))) + { + return TRUE; + } + } + return FALSE; + } +} + +u8 GetMoveTypeForMonster(Entity *pokemon, Move *pokeMove) +{ + if (pokeMove->id == MOVE_HIDDEN_POWER) + return GetEntInfo(pokemon)->hiddenPower.hiddenPowerType; + else + return GetMoveType(pokeMove); +} + +s32 GetMovePower(Entity *pokemon, Move *pokeMove) +{ + if(pokeMove->id == MOVE_HIDDEN_POWER) + return (GetEntInfo(pokemon)->hiddenPower.hiddenPowerBasePower + pokeMove->ginseng); + else + return (GetMoveBasePower(pokeMove) + pokeMove->ginseng); +} + +bool8 MonsterCanThrowItems(EntityInfo *pokemon) +{ + if(!MonsterIDCanThrowItems(pokemon->id)) + return FALSE; + return TRUE; +} + +bool8 sub_8071A8C(Entity *pokemon) +{ + EntityInfo *pokemonInfo; + if(EntityIsValid(pokemon)) + { + pokemonInfo = GetEntInfo(pokemon); + if(pokemonInfo->monsterBehavior != BEHAVIOR_RESCUE_TARGET) + { + if(!IsExperienceLocked(pokemonInfo->joinedAt.id)) + return TRUE; + } + } + return FALSE; +} + +bool8 SetVisualFlags(EntityInfo *entityInfo, u16 newFlag, bool8 param_3) +{ + if ((entityInfo->visualFlags & newFlag)) { + entityInfo->previousVisualFlags = newFlag | entityInfo->previousVisualFlags; + } + else { + entityInfo->previousVisualFlags = entityInfo->previousVisualFlags & ~newFlag; + } + + if (param_3) { + entityInfo->visualFlags = newFlag | entityInfo->visualFlags; + } + else { + entityInfo->visualFlags = entityInfo->visualFlags & ~newFlag; + } + if ( ((entityInfo->previousVisualFlags & newFlag) == 0) && ((entityInfo->visualFlags & newFlag)) ) { + return TRUE; + } + else { + return FALSE; + } +} diff --git a/src/dungeon_main.c b/src/dungeon_main.c index 6bf3ddaf5..f32d5d3ee 100644 --- a/src/dungeon_main.c +++ b/src/dungeon_main.c @@ -21,7 +21,7 @@ #include "code_806CD90.h" #include "dungeon_action.h" #include "dungeon_ai_movement.h" -#include "dungeon_ai_targeting.h" +#include "dungeon_logic.h" #include "dungeon_items.h" #include "dungeon_leader.h" #include "dungeon_main.h" @@ -36,9 +36,9 @@ #include "dungeon_message.h" #include "dungeon_message_log.h" #include "dungeon_misc.h" -#include "dungeon_movement.h" +#include "dungeon_logic.h" #include "dungeon_music.h" -#include "dungeon_pokemon_attributes.h" +#include "dungeon_logic.h" #include "dungeon_random.h" #include "dungeon_util.h" #include "game_options.h" diff --git a/src/dungeon_map_access.c b/src/dungeon_map_access.c index 3b8a1341f..4519c8fa5 100644 --- a/src/dungeon_map_access.c +++ b/src/dungeon_map_access.c @@ -11,7 +11,7 @@ #include "run_dungeon.h" #include "dungeon_leader.h" #include "dungeon_map.h" -#include "dungeon_movement.h" +#include "dungeon_logic.h" #include "dungeon_util.h" #include "game_options.h" #include "random.h" diff --git a/src/dungeon_menu_items.c b/src/dungeon_menu_items.c index 5ca5e1eec..7137029fa 100644 --- a/src/dungeon_menu_items.c +++ b/src/dungeon_menu_items.c @@ -9,7 +9,7 @@ #include "dungeon_main.h" #include "dungeon_message.h" #include "dungeon_action.h" -#include "dungeon_pokemon_attributes.h" +#include "dungeon_logic.h" #include "dungeon_util.h" #include "pokemon.h" #include "items.h" @@ -26,7 +26,7 @@ #include "text_1.h" #include "code_8044CC8.h" #include "code_801B3C0.h" -#include "dungeon_ai_targeting.h" +#include "dungeon_logic.h" extern void PlayDungeonCancelSE(void); extern void PlayDungeonConfirmationSE(void); diff --git a/src/dungeon_menu_moves.c b/src/dungeon_menu_moves.c index 1a359a4a2..874cb4d2d 100644 --- a/src/dungeon_menu_moves.c +++ b/src/dungeon_menu_moves.c @@ -11,7 +11,7 @@ #include "dungeon_menu_moves.h" #include "dungeon_menu_team.h" #include "dungeon_message.h" -#include "dungeon_movement.h" +#include "dungeon_logic.h" #include "dungeon_music.h" #include "dungeon_random.h" #include "dungeon_submenu.h" @@ -27,7 +27,7 @@ #include "text_1.h" #include "text_2.h" #include "text_3.h" -#include "dungeon_ai_targeting.h" +#include "dungeon_logic.h" extern void PlayDungeonCancelSE(void); extern void PlayDungeonConfirmationSE(void); diff --git a/src/dungeon_menu_team.c b/src/dungeon_menu_team.c index cbb4e9b65..5cfeff2cb 100644 --- a/src/dungeon_menu_team.c +++ b/src/dungeon_menu_team.c @@ -23,9 +23,9 @@ #include "dungeon_menu_team.h" #include "dungeon_message.h" #include "dungeon_misc.h" -#include "dungeon_movement.h" +#include "dungeon_logic.h" #include "dungeon_music.h" -#include "dungeon_pokemon_attributes.h" +#include "dungeon_logic.h" #include "dungeon_random.h" #include "dungeon_submenu.h" #include "dungeon_util.h" @@ -42,7 +42,7 @@ #include "string_format.h" #include "text_2.h" #include "weather.h" -#include "dungeon_ai_targeting.h" +#include "dungeon_logic.h" extern bool8 sub_8048A68(Entity *param_1,Item *item); extern bool8 sub_8048950(Entity *param_1,Item *item); diff --git a/src/dungeon_misc.c b/src/dungeon_misc.c index d49aa4a4a..4129df4f0 100644 --- a/src/dungeon_misc.c +++ b/src/dungeon_misc.c @@ -19,7 +19,7 @@ #include "dungeon_leader.h" #include "dungeon_message.h" #include "dungeon_message_log.h" -#include "dungeon_pokemon_attributes.h" +#include "dungeon_logic.h" #include "constants/dungeon.h" #include "constants/friend_area.h" #include "constants/status.h" @@ -29,8 +29,8 @@ #include "constants/weather.h" #include "code_806CD90.h" #include "code_8077274_1.h" -#include "dungeon_ai_targeting.h" -#include "dungeon_movement.h" +#include "dungeon_logic.h" +#include "dungeon_logic.h" #include "dungeon_util.h" #include "exclusive_pokemon.h" #include "dungeon_config.h" diff --git a/src/dungeon_move.c b/src/dungeon_move.c index fb01c7196..328789f38 100644 --- a/src/dungeon_move.c +++ b/src/dungeon_move.c @@ -19,14 +19,14 @@ #include "code_8077274_1.h" #include "code_807CD9C.h" #include "code_808417C.h" -#include "dungeon_ai_targeting.h" +#include "dungeon_logic.h" #include "dungeon_config.h" #include "run_dungeon.h" #include "dungeon_items.h" #include "dungeon_map_access.h" #include "dungeon_message.h" #include "dungeon_misc.h" -#include "dungeon_pokemon_attributes.h" +#include "dungeon_logic.h" #include "dungeon_random.h" #include "dungeon_strings.h" #include "dungeon_util.h" diff --git a/src/dungeon_move_util.c b/src/dungeon_move_util.c index 3f86cc53d..0f79023f8 100644 --- a/src/dungeon_move_util.c +++ b/src/dungeon_move_util.c @@ -18,7 +18,7 @@ #include "code_8077274_1.h" #include "code_807CD9C.h" #include "code_808417C.h" -#include "dungeon_ai_targeting.h" +#include "dungeon_logic.h" #include "dungeon_config.h" #include "run_dungeon.h" #include "dungeon_items.h" @@ -26,7 +26,7 @@ #include "dungeon_message.h" #include "dungeon_misc.h" #include "dungeon_move.h" -#include "dungeon_pokemon_attributes.h" +#include "dungeon_logic.h" #include "dungeon_random.h" #include "dungeon_strings.h" #include "dungeon_util.h" diff --git a/src/dungeon_movement.c b/src/dungeon_movement.c deleted file mode 100644 index 37d35f689..000000000 --- a/src/dungeon_movement.c +++ /dev/null @@ -1,348 +0,0 @@ -#include "global.h" -#include "structs/map.h" -#include "dungeon_movement.h" - -#include "constants/item.h" -#include "constants/iq_skill.h" -#include "constants/status.h" -#include "constants/type.h" -#include "constants/weather.h" -#include "run_dungeon.h" -#include "dungeon_items.h" -#include "structs/str_dungeon.h" -#include "dungeon_map_access.h" -#include "dungeon_pokemon_attributes.h" -#include "dungeon_util.h" -#include "pokemon.h" -#include "weather.h" - -EWRAM_DATA u8 gWalkableTileToCrossableTerrain[8] = {0}; - -u8 GetCrossableTerrain(s16 species) -{ - u8 walkableTiles = GetMovementType(species); - if (walkableTiles >= NUM_CROSSABLE_TERRAIN) - { - // Pokémon that can cross water or lava have a walkable tile value of 4 (MOVEMENT_TYPE_LAVA) or 5 (MOVEMENT_TYPE_WATER), respectively. - // Indices 4 and 5 in this array are assigned either CROSSABLE_TERRAIN_REGULAR or CROSSABLE_TERRAIN_LIQUID - // depending on whether the dungeon's liquid is water or lava. - // For example, a lava dungeon like Mt. Blaze would have these values: - // gWalkableTileToCrossableTerrain[MOVEMENT_TYPE_LAVA]: CROSSABLE_TERRAIN_LIQUID - // gWalkableTileToCrossableTerrain[MOVEMENT_TYPE_WATER]: CROSSABLE_TERRAIN_REGULAR - // This means a Fire-type can cross the dungeon's liquid, while a Water-type cannot. - return gWalkableTileToCrossableTerrain[walkableTiles]; - } - else - { - return walkableTiles; - } -} - -u8 sub_807034C(s32 id, const Tile *tile) -{ - s32 crossableTerrain; - u16 tileFlags; - s32 id_s32; - - id_s32 = SpeciesId(id); - - if ((tile->monster == NULL) && ((tile->terrainType & TERRAIN_TYPE_IMPASSABLE_WALL) == 0)) { - crossableTerrain = GetCrossableTerrain(id_s32); - tileFlags = tile->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY); - switch(crossableTerrain) - { - case CROSSABLE_TERRAIN_LIQUID: - if(tileFlags == TERRAIN_TYPE_SECONDARY) return FALSE; - case CROSSABLE_TERRAIN_REGULAR: - if(tileFlags == TERRAIN_TYPE_NORMAL) return FALSE; - break; - case CROSSABLE_TERRAIN_WALL: - default: - return FALSE; - case CROSSABLE_TERRAIN_CREVICE: - if(tileFlags != 0) return FALSE; - } - } - return TRUE; -} - -u8 sub_80703A0(Entity *pokemon, DungeonPos *pos) -{ - const Tile *tile; - u8 crossableTerrain; - u16 tileFlags; - EntityInfo *entityInfo; - - entityInfo = GetEntInfo(pokemon); - tile = GetTile(pos->x,pos->y); - if (pos->x < 0 || pos->y < 0) - return TRUE; - if (pos->x >= DUNGEON_MAX_SIZE_X || pos->y >= DUNGEON_MAX_SIZE_Y) - return TRUE; - if (tile->monster != NULL) - return TRUE; - if (tile->terrainType & TERRAIN_TYPE_IMPASSABLE_WALL) - return TRUE; - - if ((IsCurrentFixedRoomBossFight()) || ((entityInfo->invisibleClassStatus.status != STATUS_MOBILE && (!HasHeldItem(pokemon, ITEM_MOBILE_SCARF))))) { - crossableTerrain = GetCrossableTerrain(entityInfo->id); - tileFlags = tile->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY); - if (IQSkillIsEnabled(pokemon, IQ_ALL_TERRAIN_HIKER)) { - crossableTerrain = CROSSABLE_TERRAIN_CREVICE; - } - if (IQSkillIsEnabled(pokemon, IQ_SUPER_MOBILE)) { - crossableTerrain = CROSSABLE_TERRAIN_WALL; - } - switch(crossableTerrain) - { - case CROSSABLE_TERRAIN_LIQUID: - if(tileFlags == TERRAIN_TYPE_SECONDARY) return FALSE; - case CROSSABLE_TERRAIN_REGULAR: - if(tileFlags == TERRAIN_TYPE_NORMAL) return FALSE; - break; - case CROSSABLE_TERRAIN_WALL: - default: - return FALSE; - case CROSSABLE_TERRAIN_CREVICE: - if(tileFlags != 0) return FALSE; - } - } - else { - return FALSE; - } - - return TRUE; -} - -bool8 CanCrossWalls(Entity *pokemon) -{ - EntityInfo *pokemonInfo = GetEntInfo(pokemon); - if (pokemonInfo->invisibleClassStatus.status == STATUS_MOBILE) - { - return TRUE; - } - if (HasHeldItem(pokemon, ITEM_MOBILE_SCARF)) - { - return TRUE; - } - if (GetCrossableTerrain(pokemonInfo->id) == CROSSABLE_TERRAIN_WALL) - { - return TRUE; - } - return FALSE; -} - -bool8 sub_807049C(Entity *pokemon, DungeonPos *pos) -{ - s32 crossableTerrain; - const Tile *tile; - u16 tileFlags; - EntityInfo *entityInfo; - - entityInfo = GetEntInfo(pokemon); - tile = GetTile(pos->x,pos->y); - if (pos->x < 0 || pos->y < 0) - return TRUE; - if (pos->x >= DUNGEON_MAX_SIZE_X || pos->y >= DUNGEON_MAX_SIZE_Y) - return TRUE; - if (tile->terrainType & TERRAIN_TYPE_IMPASSABLE_WALL) - return TRUE; - if (tile->monster != NULL && GetEntityType(tile->monster) != ENTITY_MONSTER) - return TRUE; - - if (IsCurrentFixedRoomBossFight() || (entityInfo->invisibleClassStatus.status != STATUS_MOBILE && !HasHeldItem(pokemon, ITEM_MOBILE_SCARF))) { - crossableTerrain = GetCrossableTerrain(entityInfo->id); - tileFlags = tile->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY); - if (IQSkillIsEnabled(pokemon, IQ_ALL_TERRAIN_HIKER)) { - crossableTerrain = CROSSABLE_TERRAIN_CREVICE; - } - if (IQSkillIsEnabled(pokemon, IQ_SUPER_MOBILE)) { - crossableTerrain = CROSSABLE_TERRAIN_WALL; - } - switch(crossableTerrain) - { - case CROSSABLE_TERRAIN_LIQUID: - if(tileFlags == TERRAIN_TYPE_SECONDARY) return FALSE; - case CROSSABLE_TERRAIN_REGULAR: - if(tileFlags == TERRAIN_TYPE_NORMAL) return FALSE; - break; - case CROSSABLE_TERRAIN_WALL: - default: - return FALSE; - case CROSSABLE_TERRAIN_CREVICE: - if(tileFlags != 0) return FALSE; - } - } - else { - return FALSE; - } - - return TRUE; -} - -bool8 sub_8070564(Entity *pokemon, DungeonPos *pos) -{ - u16 crossableTerrain; - u32 tileFlags; - - EntityInfo *entityInfo = GetEntInfo(pokemon); - const Tile *tile = GetTile(pos->x,pos->y); - - if (pos->x < 0 || pos->y < 0) - return TRUE; - if (pos->x >= DUNGEON_MAX_SIZE_X || pos->y >= DUNGEON_MAX_SIZE_Y) - return TRUE; - if (tile->terrainType & TERRAIN_TYPE_IMPASSABLE_WALL) - return TRUE; - if (tile->monster != NULL && GetEntityType(tile->monster) != ENTITY_MONSTER) - return TRUE; - - crossableTerrain = GetCrossableTerrain(entityInfo->id); - tileFlags = GetTerrainType(tile); - - switch (crossableTerrain) - { - default: - return FALSE; - case CROSSABLE_TERRAIN_WALL: - case CROSSABLE_TERRAIN_CREVICE: - if (tileFlags != TERRAIN_TYPE_WALL) return FALSE; - break; - case CROSSABLE_TERRAIN_REGULAR: - if (tileFlags == TERRAIN_TYPE_NORMAL) return FALSE; - break; - case CROSSABLE_TERRAIN_LIQUID: - if (tileFlags == TERRAIN_TYPE_SECONDARY) return FALSE; - if (tileFlags == TERRAIN_TYPE_NORMAL) return FALSE; - break; - } - - return TRUE; -} - -bool8 sub_80705F0(Entity *pokemon, DungeonPos *pos) -{ - s32 crossableTerrain; - const Tile *tile; - u16 tileFlags; - EntityInfo *entityInfo; - - entityInfo = GetEntInfo(pokemon); - tile = GetTile(pos->x,pos->y); - if (pos->x < 0 || pos->y < 0) - return TRUE; - if (pos->x >= DUNGEON_MAX_SIZE_X || pos->y >= DUNGEON_MAX_SIZE_Y) - return TRUE; - if (((tile->terrainType & TERRAIN_TYPE_IMPASSABLE_WALL) == 0) && (tile->monster == NULL || (GetEntityType(tile->monster) == ENTITY_MONSTER))) { - if (IsCurrentFixedRoomBossFight() || (entityInfo->invisibleClassStatus.status != STATUS_MOBILE && !HasHeldItem(pokemon, ITEM_MOBILE_SCARF))) { - crossableTerrain = GetCrossableTerrain(entityInfo->id); - tileFlags = tile->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY); - if (IQSkillIsEnabled(pokemon, IQ_ALL_TERRAIN_HIKER)) { - crossableTerrain = CROSSABLE_TERRAIN_CREVICE; - } - if (IQSkillIsEnabled(pokemon, IQ_SUPER_MOBILE)) { - crossableTerrain = CROSSABLE_TERRAIN_WALL; - } - - switch(crossableTerrain) - { - case CROSSABLE_TERRAIN_WALL: - default: - return FALSE; - case CROSSABLE_TERRAIN_REGULAR: - case CROSSABLE_TERRAIN_LIQUID: - case CROSSABLE_TERRAIN_CREVICE: - if(tileFlags != 0) return FALSE; - } - } - else return FALSE; - } - return TRUE; -} - -bool8 sub_80706A4(Entity *pokemon, DungeonPos *pos) -{ - s32 crossableTerrain; - const Tile *tile; - u16 tileFlags; - EntityInfo *entityInfo; - - entityInfo = GetEntInfo(pokemon); - tile = GetTile(pos->x,pos->y); - if (pos->x < 0 || pos->y < 0) - return TRUE; - if (pos->x >= DUNGEON_MAX_SIZE_X || pos->y >= DUNGEON_MAX_SIZE_Y) - return TRUE; - if ((((tile->terrainType & TERRAIN_TYPE_IMPASSABLE_WALL) == 0)) - && (tile->monster == NULL || ((GetEntityType(tile->monster) == ENTITY_MONSTER) && (GetEntInfo(tile->monster) == entityInfo)))) { - if (IsCurrentFixedRoomBossFight() || (entityInfo->invisibleClassStatus.status != STATUS_MOBILE && !HasHeldItem(pokemon, ITEM_MOBILE_SCARF))) { - crossableTerrain = GetCrossableTerrain(entityInfo->id); - tileFlags = tile->terrainType & (TERRAIN_TYPE_NORMAL | TERRAIN_TYPE_SECONDARY); - if (IQSkillIsEnabled(pokemon, IQ_ALL_TERRAIN_HIKER)) { - crossableTerrain = CROSSABLE_TERRAIN_CREVICE; - } - if (IQSkillIsEnabled(pokemon, IQ_SUPER_MOBILE)) { - crossableTerrain = CROSSABLE_TERRAIN_WALL; - } - switch(crossableTerrain) - { - case CROSSABLE_TERRAIN_LIQUID: - if(tileFlags == TERRAIN_TYPE_SECONDARY) return FALSE; - case CROSSABLE_TERRAIN_REGULAR: - if(tileFlags == TERRAIN_TYPE_NORMAL) return FALSE; - break; - case CROSSABLE_TERRAIN_WALL: - default: - return FALSE; - case CROSSABLE_TERRAIN_CREVICE: - if(tileFlags != 0) return FALSE; - } - } - else return FALSE; - } - return TRUE; -} - -s32 CalcSpeedStage(Entity *pokemon) -{ - s32 index; - s32 speed; - EntityInfo * entityInfo; - - entityInfo = GetEntInfo(pokemon); - speed = 0; - - for(index = 0; index < NUM_SPEED_COUNTERS; index++) - { - if (entityInfo->speedUpCounters[index + NUM_SPEED_COUNTERS] != 0) { - speed--; - } - if (entityInfo->speedUpCounters[index] != 0) { - speed++; - } - } - - if (entityInfo->burnClassStatus.status == STATUS_PARALYSIS) { - speed--; - } - - speed += GetMovementSpeed(entityInfo->id); - if ((MonsterIsType(pokemon, TYPE_ICE)) && (GetApparentWeather(pokemon) == WEATHER_SNOW)) { - speed++; - } - if (entityInfo->apparentID == MONSTER_DEOXYS_SPEED) { - speed++; - } - if ((entityInfo->id == MONSTER_KECLEON) && entityInfo->isNotTeamMember && - gDungeon->unk644.unk2A) { - speed++; - } - if (speed < 0) { - speed = 0; - } - if (MAX_SPEED_STAGE < speed) { - speed = MAX_SPEED_STAGE; - } - entityInfo->speedStage = speed; - return speed; -} diff --git a/src/dungeon_music.c b/src/dungeon_music.c index 30a883443..ff857b99e 100644 --- a/src/dungeon_music.c +++ b/src/dungeon_music.c @@ -8,7 +8,7 @@ #include "dungeon_util.h" #include "music.h" #include "text_util.h" -#include "dungeon_ai_targeting.h" +#include "dungeon_logic.h" extern MenuInputStruct gDungeonMenu; diff --git a/src/dungeon_pokemon_attributes.c b/src/dungeon_pokemon_attributes.c deleted file mode 100644 index 3f1a47773..000000000 --- a/src/dungeon_pokemon_attributes.c +++ /dev/null @@ -1,275 +0,0 @@ -#include "global.h" -#include "dungeon_pokemon_attributes.h" -#include "dungeon_message.h" -#include "constants/ability.h" -#include "constants/dungeon.h" -#include "constants/iq_skill.h" -#include "constants/move_id.h" -#include "constants/status.h" -#include "constants/tactic.h" -#include "constants/type.h" -#include "dungeon_items.h" -#include "dungeon_util.h" -#include "moves.h" -#include "pokemon_3.h" -#include "pokemon.h" -#include "dungeon_config.h" -#include "structs/str_dungeon.h" - -extern const u8 *gUnknown_80FC31C; -extern const u8 * gUnknown_80FCEFC; -extern const u8 * gUnknown_80FC2FC; -extern bool8 sub_805744C(Entity *, Move *, u32); - -bool8 HasSafeguardStatus(Entity * pokemon, Entity * target, bool8 displayMessage) -{ - if (GetEntInfo(target)->reflectClassStatus.status == STATUS_SAFEGUARD) { - if (displayMessage) { - SubstitutePlaceholderStringTags(gFormatBuffer_Monsters[0],target,0); - TryDisplayDungeonLoggableMessage3(pokemon,target,gUnknown_80FC2FC); - } - return TRUE; - } - return FALSE; -} - -bool8 sub_8071728(Entity * pokemon, Entity * target, bool8 displayMessage) -{ - if (GetEntInfo(target)->reflectClassStatus.status == STATUS_MIST) { - if (displayMessage) { - SubstitutePlaceholderStringTags(gFormatBuffer_Monsters[0], target, 0); - TryDisplayDungeonLoggableMessage3(pokemon, target, gUnknown_80FC31C); - } - return TRUE; - } - else { - if (AbilityIsActive(target, ABILITY_CLEAR_BODY) || AbilityIsActive(target, ABILITY_WHITE_SMOKE)) { - if (displayMessage) { - SubstitutePlaceholderStringTags(gFormatBuffer_Monsters[0], target, 0); - TryDisplayDungeonLoggableMessage3(pokemon, target, gUnknown_80FCEFC); - } - return TRUE; - } - } - return FALSE; -} - -bool8 sub_80717A4(Entity *pokemon, u16 moveID) -{ - EntityInfo * entityInfo; - s32 i; - - entityInfo = GetEntInfo(pokemon); - if ((entityInfo->sleepClassStatus.status != STATUS_SLEEP) && (entityInfo->sleepClassStatus.status != STATUS_NAPPING) && (entityInfo->sleepClassStatus.status != STATUS_NIGHTMARE)) { - return FALSE; - } - else { - for (i = 0; i < MAX_MON_MOVES; i++) { - Move *move = &entityInfo->moves.moves[i]; - if (MoveFlagExists(move) - && (entityInfo->isTeamLeader || (move->moveFlags & MOVE_FLAG_ENABLED_FOR_AI)) - && sub_805744C(pokemon, move, TRUE) - && move->PP != 0 - && move->id == moveID) - { - return TRUE; - } - } - } - - return FALSE; -} - -bool8 AbilityIsActive(Entity *pokemon, u8 ability) -{ - if (!EntityIsValid(pokemon)) - { - return FALSE; - } - else - { - EntityInfo *pokemonInfo = GetEntInfo(pokemon); - if (pokemonInfo->abilities[0] == ability || pokemonInfo->abilities[1] == ability) - { - return TRUE; - } - return FALSE; - } -} - -bool8 MonsterIsType(Entity *pokemon, u8 type) -{ - EntityInfo *pokemonInfo = pokemonInfo = GetEntInfo(pokemon); - if (type == TYPE_NONE) - { - return FALSE; - } - if (pokemonInfo->types[0] == type) - { - return TRUE; - } - if (pokemonInfo->types[1] == type) - { - return TRUE; - } - return FALSE; -} - -bool8 CanSeeInvisibleMonsters(Entity *pokemon) -{ - EntityInfo *pokemonInfo = GetEntInfo(pokemon); - if (pokemonInfo->blinkerClassStatus.status != STATUS_EYEDROPS) - { - if (!HasHeldItem(pokemon, ITEM_GOGGLE_SPECS)) - return FALSE; - else - return TRUE; - } - else - return TRUE; -} - -bool8 IsTacticSet(Entity *pokemon, u8 tactic) -{ - EntityInfo *pokemonInfo = GetEntInfo(pokemon); - if (pokemonInfo->isTeamLeader) - { - bool8 isGoTheOtherWay = tactic == TACTIC_GO_THE_OTHER_WAY; - return isGoTheOtherWay; - } - return pokemonInfo->tactic == tactic; -} - -bool8 IQSkillIsEnabled(Entity *pokemon, u8 IQSkill) -{ - return IsIQSkillSet(&GetEntInfo(pokemon)->IQSkillFlags, 1 << IQSkill); -} - -bool8 IQSkillPairIsEnabled(Entity *pokemon, u8 IQSkill1, u8 IQSkill2) -{ - return IsIQSkillSet(&GetEntInfo(pokemon)->IQSkillFlags, 1 << IQSkill1 | 1 << IQSkill2); -} - -void LoadIQSkills(Entity *pokemon) -{ - s32 IQSkill; - EntityInfo *pokemonInfo; - - pokemonInfo = GetEntInfo(pokemon); - if (pokemonInfo->isNotTeamMember) { - IqSkillFlags *iqSkills = &pokemonInfo->IQSkillFlags; - SetIQSkill(iqSkills, IQ_STATUS_CHECKER); - SetIQSkill(iqSkills, IQ_PP_CHECKER); - SetIQSkill(iqSkills, IQ_ITEM_CATCHER); - if (pokemonInfo->bossFlag) - SetIQSkill(iqSkills, IQ_SELF_CURER); - if (pokemonInfo->level >= gIqItemMasterMinWildLevel) - SetIQSkill(iqSkills, IQ_ITEM_MASTER); - pokemonInfo->tactic = TACTIC_GO_AFTER_FOES; - } - else { - pokemonInfo->IQSkillFlags.flags[0] = 0; - pokemonInfo->IQSkillFlags.flags[1] = 0; - pokemonInfo->IQSkillFlags.flags[2] = 0; - for(IQSkill = IQ_TYPE_ADVANTAGE_MASTER; IQSkill < NUM_IQ_SKILLS; IQSkill++) - { - if (HasIQForSkill(pokemonInfo->IQ,IQSkill) && - IsIQSkillSet(&pokemonInfo->IQSkillMenuFlags, 1 << IQSkill)) - { - SetIQSkill(&pokemonInfo->IQSkillFlags,IQSkill); - } - } - } -} - -bool8 CanSeeTeammate(Entity * pokemon) -{ - Entity *teamMember; - s32 memberIdx; - - if (GetEntInfo(pokemon)->isNotTeamMember) { - return FALSE; - } - else - { - for(memberIdx = 0; memberIdx < MAX_TEAM_MEMBERS; memberIdx++) - { - teamMember = gDungeon->teamPokemon[memberIdx]; - if (EntityIsValid(pokemon) && (pokemon != teamMember) && (CanSeeTarget(pokemon,teamMember))) - { - return TRUE; - } - } - return FALSE; - } -} - -u8 GetMoveTypeForMonster(Entity *pokemon, Move *pokeMove) -{ - if (pokeMove->id == MOVE_HIDDEN_POWER) - return GetEntInfo(pokemon)->hiddenPower.hiddenPowerType; - else - return GetMoveType(pokeMove); -} - -s32 GetMovePower(Entity *pokemon, Move *pokeMove) -{ - if(pokeMove->id == MOVE_HIDDEN_POWER) - return (GetEntInfo(pokemon)->hiddenPower.hiddenPowerBasePower + pokeMove->ginseng); - else - return (GetMoveBasePower(pokeMove) + pokeMove->ginseng); -} - -bool8 MonsterCanThrowItems(EntityInfo *pokemon) -{ - if(!MonsterIDCanThrowItems(pokemon->id)) - return FALSE; - return TRUE; -} - -static inline bool8 sub_8071A8C_sub(EntityInfo *pokemonInfo) -{ - if(pokemonInfo->joinedAt.id == DUNGEON_JOIN_LOCATION_CLIENT_POKEMON || - pokemonInfo->joinedAt.id == DUNGEON_RESCUE_TEAM_BASE) - return TRUE; - else - return FALSE; -} - -bool8 sub_8071A8C(Entity *pokemon) -{ - EntityInfo *pokemonInfo; - if(EntityIsValid(pokemon)) - { - pokemonInfo = GetEntInfo(pokemon); - if(pokemonInfo->monsterBehavior != BEHAVIOR_RESCUE_TARGET) - { - if(!sub_8071A8C_sub(pokemonInfo)) - return TRUE; - } - } - return FALSE; -} - -bool8 SetVisualFlags(EntityInfo *entityInfo, u16 newFlag, bool8 param_3) -{ - if ((entityInfo->visualFlags & newFlag)) { - entityInfo->previousVisualFlags = newFlag | entityInfo->previousVisualFlags; - } - else { - entityInfo->previousVisualFlags = entityInfo->previousVisualFlags & ~newFlag; - } - - if (param_3) { - entityInfo->visualFlags = newFlag | entityInfo->visualFlags; - } - else { - entityInfo->visualFlags = entityInfo->visualFlags & ~newFlag; - } - if ( ((entityInfo->previousVisualFlags & newFlag) == 0) && ((entityInfo->visualFlags & newFlag)) ) { - return TRUE; - } - else { - return FALSE; - } -} diff --git a/src/dungeon_serializer.c b/src/dungeon_serializer.c index e15bcf6e3..b7d9caefb 100644 --- a/src/dungeon_serializer.c +++ b/src/dungeon_serializer.c @@ -6,7 +6,7 @@ #include "code_806CD90.h" #include "dungeon_items.h" #include "dungeon_map_access.h" -#include "dungeon_pokemon_attributes.h" +#include "dungeon_logic.h" #include "dungeon_serializer.h" #include "dungeon_util.h" #include "pokemon.h" diff --git a/src/dungeon_util.c b/src/dungeon_util.c index 4a4e36f06..9a9147779 100644 --- a/src/dungeon_util.c +++ b/src/dungeon_util.c @@ -16,14 +16,14 @@ #include "code_805D8C8.h" #include "constants/status.h" #include "constants/item.h" -#include "dungeon_pokemon_attributes.h" +#include "dungeon_logic.h" #include "dungeon_random.h" #include "dungeon_util.h" #include "dungeon_leader.h" #include "dungeon_message.h" #include "dungeon_music.h" #include "dungeon_map.h" -#include "dungeon_ai_targeting.h" +#include "dungeon_logic.h" #include "string_format.h" #include "items.h" #include "trap.h" diff --git a/src/move_checks.c b/src/move_checks.c index 4692f779b..6c2ac79cb 100644 --- a/src/move_checks.c +++ b/src/move_checks.c @@ -8,7 +8,7 @@ #include "structs/str_dungeon.h" #include "dungeon_items.h" #include "dungeon_map_access.h" -#include "dungeon_pokemon_attributes.h" +#include "dungeon_logic.h" #include "dungeon_util.h" #include "move_checks.h" #include "moves.h" @@ -19,7 +19,7 @@ #include "trap.h" #include "weather.h" #include "dungeon_config.h" -#include "dungeon_ai_targeting.h" +#include "dungeon_logic.h" bool8 CanUseOnSelfWithStatusChecker(Entity *pokemon, Move *move) { diff --git a/src/move_effects_target.c b/src/move_effects_target.c index e35dc2763..5993401d4 100644 --- a/src/move_effects_target.c +++ b/src/move_effects_target.c @@ -16,11 +16,11 @@ #include "dungeon_ai_attack.h" #include "dungeon_ai_items.h" #include "dungeon_ai_movement.h" -#include "dungeon_ai_targeting.h" +#include "dungeon_logic.h" #include "dungeon_items.h" #include "dungeon_leader.h" #include "dungeon_map_access.h" -#include "dungeon_pokemon_attributes.h" +#include "dungeon_logic.h" #include "dungeon_random.h" #include "dungeon_util_1.h" #include "dungeon_util.h" diff --git a/src/move_orb_actions_1.c b/src/move_orb_actions_1.c index e0fc97eb5..ef4274958 100644 --- a/src/move_orb_actions_1.c +++ b/src/move_orb_actions_1.c @@ -12,12 +12,12 @@ #include "constants/targeting.h" #include "constants/type.h" #include "constants/weather.h" -#include "dungeon_ai_targeting.h" +#include "dungeon_logic.h" #include "dungeon_items.h" #include "dungeon_map_access.h" #include "dungeon_message.h" -#include "dungeon_movement.h" -#include "dungeon_pokemon_attributes.h" +#include "dungeon_logic.h" +#include "dungeon_logic.h" #include "dungeon_random.h" #include "dungeon_util.h" #include "dungeon_move.h" diff --git a/src/move_orb_actions_2.c b/src/move_orb_actions_2.c index 215b57d99..f6f310b4a 100644 --- a/src/move_orb_actions_2.c +++ b/src/move_orb_actions_2.c @@ -12,12 +12,12 @@ #include "constants/targeting.h" #include "constants/type.h" #include "constants/weather.h" -#include "dungeon_ai_targeting.h" +#include "dungeon_logic.h" #include "dungeon_items.h" #include "dungeon_map_access.h" #include "dungeon_message.h" -#include "dungeon_movement.h" -#include "dungeon_pokemon_attributes.h" +#include "dungeon_logic.h" +#include "dungeon_logic.h" #include "dungeon_random.h" #include "dungeon_util.h" #include "dungeon_move.h" diff --git a/src/move_orb_actions_3.c b/src/move_orb_actions_3.c index 0a8ea45d0..6d7f26eca 100644 --- a/src/move_orb_actions_3.c +++ b/src/move_orb_actions_3.c @@ -12,7 +12,7 @@ #include "constants/targeting.h" #include "constants/type.h" #include "constants/weather.h" -#include "dungeon_ai_targeting.h" +#include "dungeon_logic.h" #include "dungeon_config.h" #include "run_dungeon.h" #include "dungeon_items.h" @@ -20,9 +20,9 @@ #include "dungeon_message.h" #include "dungeon_misc.h" #include "dungeon_move.h" -#include "dungeon_movement.h" +#include "dungeon_logic.h" #include "dungeon_move_util.h" -#include "dungeon_pokemon_attributes.h" +#include "dungeon_logic.h" #include "dungeon_random.h" #include "dungeon_strings.h" #include "dungeon_util.h" diff --git a/src/move_orb_actions_4.c b/src/move_orb_actions_4.c index 41da2a6f5..0d519ac82 100644 --- a/src/move_orb_actions_4.c +++ b/src/move_orb_actions_4.c @@ -14,12 +14,12 @@ #include "constants/targeting.h" #include "constants/type.h" #include "constants/weather.h" -#include "dungeon_ai_targeting.h" +#include "dungeon_logic.h" #include "run_dungeon.h" #include "dungeon_items.h" #include "dungeon_map_access.h" #include "dungeon_misc.h" -#include "dungeon_pokemon_attributes.h" +#include "dungeon_logic.h" #include "dungeon_util.h" #include "move_util.h" #include "moves.h" diff --git a/src/status.c b/src/status.c index 5ea9fb340..5af867a37 100644 --- a/src/status.c +++ b/src/status.c @@ -8,12 +8,12 @@ #include "constants/status.h" #include "constants/type.h" #include "dungeon_ai_movement.h" -#include "dungeon_ai_targeting.h" +#include "dungeon_logic.h" #include "dungeon_items.h" #include "dungeon_map_access.h" #include "dungeon_message.h" -#include "dungeon_movement.h" -#include "dungeon_pokemon_attributes.h" +#include "dungeon_logic.h" +#include "dungeon_logic.h" #include "dungeon_util.h" #include "math.h" #include "move_effects_target.h" diff --git a/src/status_checks.c b/src/status_checks.c index 5b7ad4d56..42b133f0b 100644 --- a/src/status_checks.c +++ b/src/status_checks.c @@ -10,7 +10,7 @@ #include "dungeon_action.h" #include "dungeon_ai_attack.h" #include "dungeon_random.h" -#include "dungeon_ai_targeting.h" +#include "dungeon_logic.h" extern const char *gPtrFrozenMessage[]; extern const char *gPtrWrappedAroundMessage[]; diff --git a/src/targeting_flags.c b/src/targeting_flags.c index e55617ecf..1d8830a95 100644 --- a/src/targeting_flags.c +++ b/src/targeting_flags.c @@ -3,7 +3,7 @@ #include "constants/move_id.h" #include "constants/type.h" -#include "dungeon_pokemon_attributes.h" +#include "dungeon_logic.h" #include "moves.h" s16 GetMoveTargetAndRangeForPokemon(Entity *pokemon, Move *move, bool32 isAI) diff --git a/src/trap.c b/src/trap.c index 0e1466c6c..297bee977 100644 --- a/src/trap.c +++ b/src/trap.c @@ -14,7 +14,7 @@ #include "dungeon_items.h" #include "dungeon_map.h" #include "dungeon_map_access.h" -#include "dungeon_pokemon_attributes.h" +#include "dungeon_logic.h" #include "dungeon_random.h" #include "dungeon_util.h" #include "items.h" diff --git a/src/type_effectiveness.c b/src/type_effectiveness.c index e43b46c60..217227b8b 100644 --- a/src/type_effectiveness.c +++ b/src/type_effectiveness.c @@ -5,7 +5,7 @@ #include "constants/weather.h" #include "structs/str_dungeon.h" #include "dungeon_message.h" -#include "dungeon_pokemon_attributes.h" +#include "dungeon_logic.h" #include "dungeon_util.h" #include "math.h" #include "status.h" diff --git a/sym_ewram.txt b/sym_ewram.txt index d49c963e2..d6d6fb0d7 100644 --- a/sym_ewram.txt +++ b/sym_ewram.txt @@ -152,7 +152,7 @@ gUnknown_202EE76: /* 202EE76 (sub_804513C - sub_8082A08) */ .include "src/dungeon_menu_recruitment.o" .include "src/code_8066D04.o" .include "src/dungeon_8067A80.o" - .include "src/dungeon_movement.o" + .include "src/dungeon_logic.o" .include "src/code_80718D8.o" gUnknown_202F32C: /* 202F32C (xxx_dungeon_8042F6C - sub_8072CF4) */