home · contact · privacy
Fixed bug that led to endless loop in nearest_enemy_dir().
[plomrogue] / src / yx_uint16.c
index a0b89406614673dd79110c1aa75129059e1e8abb..c980693b998bf3156ea70e1f3f5a8df8fc36402b 100644 (file)
@@ -1,15 +1,38 @@
+/* yx_uint16.c */
+
 #include "yx_uint16.h"
+#include <stdint.h> /* for uint8_t, uint16_t */
+
+
+
+extern uint8_t yx_uint16_cmp(struct yx_uint16 * a, struct yx_uint16 * b)
+{
+    if (a->y == b->y && a->x == b->x)
+    {
+        return 1;
+    }
+    return 0;
+}
 
-extern char yx_uint16_cmp (struct yx_uint16 a, struct yx_uint16 b) {
-// Compare two coordinates of type yx_uint16.
-  if (a.y == b.y && a.x == b.x) return 1;
-  else                          return 0; }
 
-extern struct yx_uint16 mv_yx_in_dir (enum dir d, struct yx_uint16 yx) {
-// Return yx coordinates one step to the direction d of yx.
-  if      (d == NORTH) yx.y--;
-  else if (d == EAST)  yx.x++;
-  else if (d == SOUTH) yx.y++;
-  else if (d == WEST)  yx.x--;
-  return yx; }
 
+extern struct yx_uint16 mv_yx_in_dir(char d, struct yx_uint16 yx)
+{
+    if      (d == 'N' && yx.y > 0)
+    {
+        yx.y--;
+    }
+    else if (d == 'E' && yx.x < UINT16_MAX)
+    {
+        yx.x++;
+    }
+    else if (d == 'S' && yx.y < UINT16_MAX)
+    {
+        yx.y++;
+    }
+    else if (d == 'W' && yx.x > 0)
+    {
+        yx.x--;
+    }
+    return yx;
+}