X-Git-Url: https://plomlompom.com/repos/foo.html?a=blobdiff_plain;f=src%2Fserver%2Finit.c;h=c06619fc46cffc682480923d0bebd8140152fcbb;hb=bf8ae37ed027803ebbf0d71add8b1aff24a7896d;hp=f6b56a631dfa8199642ba674c2e9ced14c1b8738;hpb=dd9d65ee727ac7e95801da0f8b5bae7009811802;p=plomrogue diff --git a/src/server/init.c b/src/server/init.c index f6b56a6..c06619f 100644 --- a/src/server/init.c +++ b/src/server/init.c @@ -1,12 +1,13 @@ /* src/server/init.c */ #include "init.h" +#include /* NULL */ #include /* uint32_t */ #include /* exit(), free() */ #include /* atoi() */ #include /* time() */ -#include /* optarg, getopt(), access() */ -#include "../common/readwrite.h" /* try_fopen(), try_fclose(), textfile_sizes(), +#include /* optarg, getopt(), access(), unlink() */ +#include "../common/readwrite.h" /* try_fopen(), try_fclose(), textfile_width(), * try_fgets() */ #include "../common/rexit.h" /* exit_err() */ @@ -47,18 +48,14 @@ 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; + world.log = NULL; /* map_object_action.c's update_log() checks for this. */ world.seed = seed; world.map_obj_count = 0; - world.score = 0; free(world.map.cells); - if (world.map_objs) - { - free_map_objects(world.map_objs); - } + 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); @@ -67,6 +64,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; } @@ -77,7 +79,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))