diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/code_80983D8.c | 52 | ||||
-rw-r--r-- | src/dungeon_ai_items.c | 2 | ||||
-rw-r--r-- | src/position_util.c | 65 |
3 files changed, 66 insertions, 53 deletions
diff --git a/src/code_80983D8.c b/src/code_80983D8.c deleted file mode 100644 index 25c57d2..0000000 --- a/src/code_80983D8.c +++ /dev/null @@ -1,52 +0,0 @@ -#include "global.h" - -extern u32 gUnknown_8115E94[5][3]; // NOTE: Factor of two difference in array sizes - -s32 CalculateFacingDir(short *param_1,short *param_2) -{ - s32 uVar1; - s32 uVar2; - s32 uVar3; - - uVar3 = param_2[0] - param_1[0]; - uVar2 = param_2[1] - param_1[1]; - if ((uVar3 == 0) && (uVar2 == 0)) { - uVar1 = 0; - } - else { - if (0 < uVar3) { - uVar3 = 1; - } - if (0 < uVar2) { - uVar2 = 1; - } - if (-1 >= uVar3) { - uVar3 = -1; - } - if (-1 >= uVar2) { - uVar2 = -1; - } - uVar1 = gUnknown_8115E94[(uVar2 + 1)][(uVar3 + 1)]; - } - return uVar1; -} - -s32 GetMaxPositionDifference(short param_1[],short param_2[]) -{ - s32 diff_index1; - s32 diff_index0; - - diff_index0 = param_1[0] - param_2[0]; - if (diff_index0 < 0) { - diff_index0 = -diff_index0; - } - diff_index1 = param_1[1] - param_2[1]; - if (diff_index1 < 0) { - diff_index1 = -diff_index1; - } - if (diff_index1 < diff_index0) { - diff_index1 = diff_index0; - } - return diff_index1; -} - diff --git a/src/dungeon_ai_items.c b/src/dungeon_ai_items.c index 8751eb1..d515ebb 100644 --- a/src/dungeon_ai_items.c +++ b/src/dungeon_ai_items.c @@ -22,6 +22,7 @@ #include "dungeon_visibility.h" #include "item.h" #include "position.h" +#include "position_util.h" #include "team_inventory.h" #define NUM_POTENTIAL_ROCK_TARGETS 20 @@ -35,7 +36,6 @@ enum ItemTargetFlag ITEM_TARGET_ALLY = 1 << 1 }; -extern s32 CalculateFacingDir(struct Position*, struct Position*); extern void sub_8077274(struct DungeonEntity *, struct DungeonEntity *); extern s32 gNumPotentialTargets; diff --git a/src/position_util.c b/src/position_util.c new file mode 100644 index 0000000..26a8c51 --- /dev/null +++ b/src/position_util.c @@ -0,0 +1,65 @@ +#include "global.h" +#include "position_util.h" + +#include "constants/direction.h" + +const s32 gFacingDirMapping[3][3] = { + {DIRECTION_NORTHWEST, DIRECTION_NORTH, DIRECTION_NORTHEAST}, + {DIRECTION_WEST, DIRECTION_SOUTH, DIRECTION_EAST}, + {DIRECTION_SOUTHWEST, DIRECTION_SOUTH, DIRECTION_SOUTHEAST} +}; + +s32 CalculateFacingDir(struct Position *originPos, struct Position *targetPos) +{ + s32 facingDir; + s32 yDiff; + s32 xDiff; + + xDiff = targetPos->x - originPos->x; + yDiff = targetPos->y - originPos->y; + if (xDiff == 0 && yDiff == 0) + { + facingDir = DIRECTION_SOUTH; + } + else + { + if (xDiff > 0) + { + xDiff = 1; + } + if (yDiff > 0) + { + yDiff = 1; + } + if (xDiff <= -1) + { + xDiff = -1; + } + if (yDiff <= -1) + { + yDiff = -1; + } + facingDir = gFacingDirMapping[yDiff + 1][xDiff + 1]; + } + return facingDir; +} + +s32 GetMaxPositionDifference(short param_1[],short param_2[]) +{ + s32 diff_index1; + s32 diff_index0; + + diff_index0 = param_1[0] - param_2[0]; + if (diff_index0 < 0) { + diff_index0 = -diff_index0; + } + diff_index1 = param_1[1] - param_2[1]; + if (diff_index1 < 0) { + diff_index1 = -diff_index1; + } + if (diff_index1 < diff_index0) { + diff_index1 = diff_index0; + } + return diff_index1; +} + |