home · contact · privacy
Server: Refactor yx_uint8 moving; handle actors hitting the map edge.
[plomrogue] / src / server / map.c
index 059a7133134cea14f0c4343241f05fba373daf84..50c7bf1560105c5e6b3f2af12971637492ae2ac5 100644 (file)
@@ -7,6 +7,7 @@
 #include "../common/try_malloc.h" /* try_malloc() */
 #include "../common/yx_uint8.h" /* struct yx_uint8 */
 #include "rrand.h" /* rrand() */
+#include "yx_uint8.h" /* mv_yx_in_dir_wrap() */
 #include "world.h" /* global world */
 
 
@@ -139,9 +140,8 @@ static void make_trees()
 
 extern void remake_map()
 {
-    char * f_name = "init_map()";
     free(world.map.cells);
-    world.map.cells = try_malloc(world.map.length * world.map.length, f_name);
+    world.map.cells = try_malloc(world.map.length * world.map.length, __func__);
     uint32_t store_seed = world.seed;
     world.seed = world.seed_map;
     make_sea();
@@ -164,7 +164,12 @@ extern uint8_t is_passable(struct yx_uint8 pos)
 
 
 
-extern uint16_t yx_to_map_pos(struct yx_uint8 * yx)
+extern uint8_t mv_yx_in_dir_legal(char dir, struct yx_uint8 * yx)
 {
-    return (yx->y * world.map.length) + yx->x;
+    uint8_t wraptest = mv_yx_in_dir_wrap(dir, yx, 0);
+    if (!wraptest && yx->x < world.map.length && yx->y < world.map.length)
+    {
+        return 1;
+    }
+    return 0;
 }