home · contact · privacy
Maps are always squares, therefore define only their edge lengths.
[plomrogue] / src / server / io.c
index 7fbb511055b2e30842a24b713bcfb5502dbf42ae..488f92bd34ac8a2923b1a500f2c3d8f1c9d94a98 100644 (file)
                                   */
 #include "../common/try_malloc.h" /* try_malloc() */
 #include "cleanup.h" /* set_cleanup_flag() */
-#include "field_of_view.h" /* VISIBLE, build_fov_map() */
+#include "field_of_view.h" /* VISIBLE */
 #include "map.h" /* yx_to_map_pos() */
-#include "map_objects.h" /* structs MapObj, MapObjDef, get_map_obj_def() */
+#include "map_objects.h" /* structs MapObj, MapObjDef, get_map_obj_def(),
+                          * get_player()
+                          */
 #include "world.h" /* global world  */
 
 
@@ -142,8 +144,7 @@ static void update_worldstate_file()
     write_inventory(player, file);
     write_value_as_line(player->pos.y, file);
     write_value_as_line(player->pos.x, file);
-    write_value_as_line(world.map.size.y, file);
-    write_value_as_line(world.map.size.x, file);
+    write_value_as_line(world.map.length, file);
     write_map(player, file);
     if (world.log)
     {
@@ -197,14 +198,13 @@ static void write_inventory(struct MapObj * player, FILE * file)
 static char * build_visible_map(struct MapObj * player)
 {
     char * f_name = "build_visible_map()";
-    uint8_t * fov_map = build_fov_map(player);
-    uint32_t map_size = world.map.size.y * world.map.size.x;
+    uint32_t map_size = world.map.length * world.map.length;
     char * visible_map = try_malloc(map_size, f_name);
     memset(visible_map, ' ', map_size);
     uint16_t pos_i;
     for (pos_i = 0; pos_i < map_size; pos_i++)
     {
-        if (fov_map[pos_i] & VISIBLE)
+        if (player->fov_map[pos_i] & VISIBLE)
         {
             visible_map[pos_i] = world.map.cells[pos_i];
         }
@@ -217,7 +217,7 @@ static char * build_visible_map(struct MapObj * player)
     {
         for (o = world.map_objs; o != 0; o = o->next)
         {
-            if (   fov_map[yx_to_map_pos(&o->pos)] & VISIBLE
+            if (   player->fov_map[yx_to_map_pos(&o->pos)] & VISIBLE
                 && (   (0 == i && 0 == o->lifepoints)
                     || (1 == i && 0 < o->lifepoints)))
             {
@@ -227,7 +227,6 @@ static char * build_visible_map(struct MapObj * player)
             }
         }
     }
-    free(fov_map);
     return visible_map;
 }
 
@@ -238,11 +237,11 @@ static void write_map(struct MapObj * player, FILE * file)
     char * f_name = "write_map()";
     char * visible_map = build_visible_map(player);
     uint16_t x, y;
-    for (y = 0; y < world.map.size.y; y++)
+    for (y = 0; y < world.map.length; y++)
     {
-        for (x = 0; x < world.map.size.x; x++)
+        for (x = 0; x < world.map.length; x++)
         {
-            try_fputc(visible_map[(y * world.map.size.x) + x], file, f_name);
+            try_fputc(visible_map[(y * world.map.length) + x], file, f_name);
         }
         try_fputc('\n', file, f_name);
     }