- char * f_name = "save_world()";
- char * path = s[S_PATH_SAVE];
- FILE * file = try_fopen(path, "w", f_name);
- write_key_value(file, s[S_CMD_DO_FOV], 0);
- try_fputc('\n', file, f_name);
- write_key_value(file, s[S_CMD_SEED_MAP], world.seed_map);
- write_key_value(file, s[S_CMD_SEED_RAND], world.seed);
- write_key_value(file, s[S_CMD_TURN], world.turn);
- try_fputc('\n', file, f_name);
+ char * path_tmp;
+ FILE * file = atomic_write_start(s[S_PATH_SAVE], &path_tmp);
+ write_key_space_value(file, s[S_CMD_MAPLENGTH], world.map.length);
+ write_key_space_value(file, s[S_CMD_PLAYTYPE], world.player_type);
+ try_fputc('\n', file, __func__);
+ struct ThingAction * ta;
+ for (ta = world.thing_actions; ta; ta = ta->next)
+ {
+ write_key_space_value(file, s[S_CMD_TA_ID], ta->id);
+ write_key_space_value(file, s[S_CMD_TA_EFFORT], ta->effort);
+ write_key_space_string(file, s[S_CMD_TA_NAME], ta->name);
+ try_fputc('\n', file, __func__);
+ }
+ struct ThingType * tt;
+ for (tt = world.thing_types; tt; tt = tt->next)
+ {
+ write_key_space_value(file, s[S_CMD_TT_ID], tt->id);
+ write_key_space_value(file, s[S_CMD_TT_STARTN], tt->start_n);
+ write_key_space_value(file, s[S_CMD_TT_HP], tt->lifepoints);
+ int test = fprintf(file, "%s %c\n", s[S_CMD_TT_SYMB], tt->char_on_map);
+ exit_trouble(test < 0, __func__, "fprintf");
+ write_key_space_string(file, s[S_CMD_TT_NAME], tt->name);
+ write_key_space_value(file, s[S_CMD_TT_CONSUM], tt->consumable);
+ write_key_space_value(file, s[S_CMD_TT_PROL], tt->proliferate);
+ try_fputc('\n', file, __func__);
+ }
+ for (tt = world.thing_types; tt; tt = tt->next)
+ {
+ write_key_space_value(file, s[S_CMD_TT_ID], tt->id);
+ write_key_space_value(file, s[S_CMD_TT_CORPS], tt->corpse_id);
+ }
+ try_fputc('\n', file, __func__);
+ write_key_space_value(file, s[S_CMD_SEED_MAP], world.seed_map);
+ write_key_space_value(file, s[S_CMD_SEED_RAND], world.seed);
+ write_key_space_value(file, s[S_CMD_TURN], world.turn);
+ try_fputc('\n', file, __func__);