summaryrefslogtreecommitdiff
path: root/src/position_util.c
diff options
context:
space:
mode:
authorSeth Barberee <seth.barberee@gmail.com>2022-01-20 15:26:19 -0800
committerGitHub <noreply@github.com>2022-01-20 15:26:19 -0800
commit408fe77d7b9440d7eb5d46eda5f920572d516d67 (patch)
tree38953616b74da130bd832635bed1c605d4b0e322 /src/position_util.c
parent3cdde2a92a187d437dc7d24273177b59ab5b9511 (diff)
parentc5cd6e137fbad180a21ec24a50fde76633db0c20 (diff)
Merge pull request #93 from AnonymousRandomPerson/master
More AI decomp
Diffstat (limited to 'src/position_util.c')
-rw-r--r--src/position_util.c65
1 files changed, 65 insertions, 0 deletions
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;
+}
+