From: Christian Heller Date: Sat, 25 Jan 2014 20:46:59 +0000 (+0100) Subject: Fixed bug where record unlinking in remake_world() *always* unlinked *any* previously... X-Git-Tag: tce~860 X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/task?a=commitdiff_plain;h=273a2b16c82a26b8f6592cfe08162d5714738108;p=plomrogue Fixed bug where record unlinking in remake_world() *always* unlinked *any* previously existing record file. --- diff --git a/src/server/init.c b/src/server/init.c index 7ab5c9d..b63fbf9 100644 --- a/src/server/init.c +++ b/src/server/init.c @@ -1,7 +1,6 @@ /* src/server/init.c */ #include "init.h" -#include /* errno */ #include /* NULL */ #include /* uint32_t */ #include /* exit(), free() */ @@ -49,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; @@ -57,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); @@ -66,9 +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); - int test = unlink(world.path_record); - char * err = "remake_world() fails to unlink() record file."; - exit_err(test && errno != ENOENT, err); + if (world.turn) + { + exit_trouble(unlink(world.path_record), f_name, "unlink()"); + } + world.turn = 1; } diff --git a/src/server/init.h b/src/server/init.h index 12d0c08..bc5c76c 100644 --- a/src/server/init.h +++ b/src/server/init.h @@ -14,7 +14,8 @@ extern void obey_argv(int argc, char * argv[]); /* Dissolves old game world if it exists, and generates a new one from "seed". - * Unlinks any pre-existing file at world.path_record to re-start record. + * Unlinks a pre-existing file at world.path_record if called on a world.turn>0, + * i.e. if called after iterating through an already established game world. * * Map object (action) definitions read in from server config directory are not * affected. world.last_update_turn is set to 0 and world.turn to 1, so that