home · contact · privacy
Eliminated some potential problems for alternative game map sizes.
[plomrogue] / src / server / init.c
index 97ed0fa09c0af955b835a2bd773436f4805255eb..4e885fee3855a39293f9f764d9950e984de64117 100644 (file)
@@ -6,8 +6,8 @@
 #include <stdlib.h> /* exit(), free() */
 #include <string.h> /* atoi() */
 #include <time.h> /* time() */
-#include <unistd.h> /* optarg, getopt(), access() */
-#include "../common/readwrite.h" /* try_fopen(), try_fclose(), textfile_sizes(),
+#include <unistd.h> /* optarg, getopt(), access(), unlink() */
+#include "../common/readwrite.h" /* try_fopen(), try_fclose(), textfile_width(),
                                   * try_fgets()
                                   */
 #include "../common/rexit.h" /* exit_err() */
@@ -48,6 +48,7 @@ extern void obey_argv(int argc, char * argv[])
 
 extern void remake_world(uint32_t seed)
 {
+    char * f_name = "remake_world()";
     free(world.log);
     world.log = NULL;  /* map_object_action.c's update_log() checks for this. */
     world.seed = seed;
@@ -56,7 +57,6 @@ extern void remake_world(uint32_t seed)
     free(world.map.cells);
     free_map_objects(world.map_objs);
     world.last_update_turn = 0;
-    world.turn = 1;
     init_map();
     add_map_objects(0, 1);
     add_map_objects(1, 1 + rrand() % 27);
@@ -65,6 +65,11 @@ extern void remake_world(uint32_t seed)
     add_map_objects(4, 1 + rrand() % 3);
     add_map_objects(5, 1 + rrand() % 3);
     set_cleanup_flag(CLEANUP_MAP_OBJECTS);
+    if (world.turn)
+    {
+        exit_trouble(unlink(world.path_record), f_name, "unlink()");
+    }
+    world.turn = 1;
 }
 
 
@@ -75,7 +80,7 @@ extern void run_game()
     if (!access(world.path_record, F_OK))
     {
         FILE * file = try_fopen(world.path_record, "r", f_name);
-        uint32_t linemax = textfile_sizes(file, NULL);
+        uint32_t linemax = textfile_width(file);
         char line[linemax + 1];
         while (   (!world.replay || (world.turn < world.replay))
                && NULL != try_fgets(line, linemax + 1, file, f_name))