From ab7ef9fabb4a4862192d34ec5374da00363fb077 Mon Sep 17 00:00:00 2001 From: AnonymousRandomPerson Date: Sun, 21 Sep 2025 22:56:51 -0400 Subject: [PATCH] Moved AI attack BSS vars to C --- asm/overlay_29_bss_0237CA18.s | 9 +++------ include/dungeon_ai_attack.h | 9 +++++++++ include/dungeon_ai_items.h | 3 +++ main.lsf | 2 +- src/dungeon_ai_attack.c | 12 ++++++++---- 5 files changed, 24 insertions(+), 11 deletions(-) diff --git a/asm/overlay_29_bss_0237CA18.s b/asm/overlay_29_bss_0237CA18.s index 25ad1cb6..6867eabd 100644 --- a/asm/overlay_29_bss_0237CA18.s +++ b/asm/overlay_29_bss_0237CA18.s @@ -2,12 +2,8 @@ .include "overlay_29_bss_0237CA18.inc" .bss - .global AI_CAN_ATTACK_IN_DIRECTION -AI_CAN_ATTACK_IN_DIRECTION: - .space 0x8 - .global AI_POTENTIAL_ATTACK_TARGET_DIRECTIONS -AI_POTENTIAL_ATTACK_TARGET_DIRECTIONS: - .space 0x8 +; AI_POTENTIAL_ATTACK_TARGET_WEIGHTS is defined twice within AiConsiderMove, so it needs two separates globals until the function is matched. +#ifndef NONMATCHING .global AI_POTENTIAL_ATTACK_TARGET_WEIGHTS AI_POTENTIAL_ATTACK_TARGET_WEIGHTS: .global AI_POTENTIAL_ATTACK_TARGET_WEIGHTS_2 @@ -16,6 +12,7 @@ AI_POTENTIAL_ATTACK_TARGET_WEIGHTS_2: .global AI_POTENTIAL_ATTACK_TARGETS AI_POTENTIAL_ATTACK_TARGETS: .space 0x20 +#endif .global ov29_0237CA68 ov29_0237CA68: .space 0x1 diff --git a/include/dungeon_ai_attack.h b/include/dungeon_ai_attack.h index 5ec90007..94eccb80 100644 --- a/include/dungeon_ai_attack.h +++ b/include/dungeon_ai_attack.h @@ -12,6 +12,15 @@ struct ai_possible_move s32 weight; }; +// Stores whether the AI can use an attack in each direction. +extern bool8 AI_CAN_ATTACK_IN_DIRECTION[NUM_DIRECTIONS]; +// Stores the directions that the AI can use an attack in. Parallel to AI_POTENTIAL_ATTACK_TARGET_WEIGHTS and AI_POTENTIAL_ATTACK_TARGETS. +extern u8 AI_POTENTIAL_ATTACK_TARGET_DIRECTIONS[NUM_DIRECTIONS]; +// Stores the targeting weights for each direction the AI can use an attack in. Parallel to AI_POTENTIAL_ATTACK_TARGET_DIRECTIONS and AI_POTENTIAL_ATTACK_TARGETS. +extern s32 AI_POTENTIAL_ATTACK_TARGET_WEIGHTS[NUM_DIRECTIONS]; +// Stores the target entity for each direction the AI can use an attack in. Parallel to AI_POTENTIAL_ATTACK_TARGET_DIRECTIONS and AI_POTENTIAL_ATTACK_TARGET_DIRECTIONS. +extern struct entity *AI_POTENTIAL_ATTACK_TARGETS[NUM_DIRECTIONS]; + // Sets all values in AI_CAN_ATTACK_IN_DIRECTION to false. void ResetAiCanAttackInDirection(); // The AI uses this function to check if a move has any potential targets, to calculate the list of potential targets and to calculate the move's special weight. The weight is calculated using WeightMoveWithIqSkills. diff --git a/include/dungeon_ai_items.h b/include/dungeon_ai_items.h index 9d64574a..391fb1f4 100644 --- a/include/dungeon_ai_items.h +++ b/include/dungeon_ai_items.h @@ -3,8 +3,11 @@ #include "dungeon_mode.h" +// Used in GetPossibleAiThrownItemDirections to indicate whether a certain direction enum value is already being used or not. extern bool8 AI_THROWN_ITEM_DIRECTION_IS_USED[NUM_DIRECTIONS]; +// Used to store the probabilities matching the directions in THROWN_ITEM_DIRECTIONS. extern u32 AI_THROWN_ITEM_PROBABILITIES[NUM_DIRECTIONS]; +// Used to store the directions output by GetPossibleAiThrownItemDirections. extern u32 AI_THROWN_ITEM_DIRECTIONS[NUM_DIRECTIONS]; // Checks if an entity pointer points to a valid entity (not entity type 0, which represents no entity). diff --git a/main.lsf b/main.lsf index bd424023..81415ea9 100644 --- a/main.lsf +++ b/main.lsf @@ -492,7 +492,6 @@ Overlay OVY_29 Object src/dungeon_ai_items.o Object src/dungeon_ai_items_1.o Object asm/overlay_29_data_02353700.o - Object asm/overlay_29_bss_0237CA18.o Object asm/overlay_29_0230F02C.o Object src/overlay_29_0230F810.o Object asm/overlay_29_0230F840.o @@ -524,6 +523,7 @@ Overlay OVY_29 Object asm/overlay_29_02318E70.o Object src/inflict_status.o Object src/dungeon_ai_attack.o + Object asm/overlay_29_bss_0237CA18.o Object asm/overlay_29_0231A460.o Object src/dungeon_ai_attack_1.o Object asm/overlay_29_0231A7A0.o diff --git a/src/dungeon_ai_attack.c b/src/dungeon_ai_attack.c index 84e46fd5..7aaae414 100644 --- a/src/dungeon_ai_attack.c +++ b/src/dungeon_ai_attack.c @@ -25,10 +25,14 @@ #include "overlay_29_0231ACAC.h" #include "position_util.h" -extern bool8 AI_CAN_ATTACK_IN_DIRECTION[NUM_DIRECTIONS]; -extern u8 AI_POTENTIAL_ATTACK_TARGET_DIRECTIONS[NUM_DIRECTIONS]; -extern s32 AI_POTENTIAL_ATTACK_TARGET_WEIGHTS[NUM_DIRECTIONS]; -extern struct entity *AI_POTENTIAL_ATTACK_TARGETS[NUM_DIRECTIONS]; +bool8 AI_CAN_ATTACK_IN_DIRECTION[NUM_DIRECTIONS] = {0}; +u8 AI_POTENTIAL_ATTACK_TARGET_DIRECTIONS[NUM_DIRECTIONS] = {0}; + +// AI_POTENTIAL_ATTACK_TARGET_WEIGHTS is defined twice within AiConsiderMove, so it needs two separate symbols in ASM until the function is matched. +#ifdef NONMATCHING +s32 AI_POTENTIAL_ATTACK_TARGET_WEIGHTS[NUM_DIRECTIONS] = {0}; +struct entity *AI_POTENTIAL_ATTACK_TARGETS[NUM_DIRECTIONS] = {0}; +#endif void ResetAiCanAttackInDirection() {