X-Git-Url: https://plomlompom.com/repos/foo.html?a=blobdiff_plain;f=src%2Fmisc.c;h=cfa43caf14b7054e682d631a20b85e328a1bfbd9;hb=6ba18516a602b3d4ad95981887ad9c5eb40a335a;hp=0bb50a76fa4c7831ccfece4f41bab471c30b46ae;hpb=7bebc9943d1648d56968146b17c9459affb183c6;p=plomrogue diff --git a/src/misc.c b/src/misc.c index 0bb50a7..cfa43ca 100644 --- a/src/misc.c +++ b/src/misc.c @@ -3,6 +3,7 @@ #include "misc.h" #include /* for calloc(), free() */ #include /* for strlen(), strcmp(), memcpy() */ +#include /* for uint8_t */ #include "windows.h" /* for suspend_win(), append_win(), reset_pad_offset(), * resize_active_win(), cycle_active_win(), * shift_active_win(), struct Win, struct WinMeta @@ -10,15 +11,14 @@ #include "keybindings.h" /* for get_action_key(), save_keybindings(), * keyswin_move_selection(), keyswin_mod_key() */ -#include "readwrite.h" /* for write_uint16_bigendian(), write_uint32_bigendian() - */ +#include "readwrite.h" /* for [read/write]_uint[8/16/32][_bigendian]() */ #include "map_objects.h" /* for struct Monster, write_map_objects(), */ #include "map_object_actions.h" /* for is_passable(), move_monster() */ #include "map.h" /* for map_scroll(),map_center_player(), Map struct,dir enum */ #include "main.h" /* for World struct */ #include "yx_uint16.h" /* for yx_uint16 */ #include "rrand.h" /* for rrand(), rrand_seed() */ - +#include "rexit.h" /* for exit_err() */ extern void textfile_sizes(FILE * file, uint16_t * linemax_p, @@ -115,7 +115,7 @@ extern void turn_over(struct World * world, char action) if (1 == world->interactive) { FILE * file = fopen("record", "a"); - fputc(action, file); + exit_err(write_uint8(action, file), world, "Record writing failure."); fclose(file); } world->turn++; @@ -133,14 +133,16 @@ extern void turn_over(struct World * world, char action) extern void save_game(struct World * world) { + uint8_t err; FILE * file = fopen("savefile", "w"); - write_uint32_bigendian(world->seed, file); - write_uint32_bigendian(world->turn, file); - write_uint16_bigendian(world->player->pos.y + 1, file); - write_uint16_bigendian(world->player->pos.x + 1, file); - fputc(world->player->hitpoints, file); - write_map_objects(world, world->monster, file); - write_map_objects(world, world->item, file); + err = write_uint32_bigendian(world->seed, file); + err = err | write_uint32_bigendian(world->turn, file); + err = err | write_uint16_bigendian(world->player->pos.y + 1, file); + err = err | write_uint16_bigendian(world->player->pos.x + 1, file); + err = err | write_uint8(world->player->hitpoints, file); + err = err | write_map_objects(world, world->monster, file); + err = err | write_map_objects(world, world->item, file); + exit_err(err, world, "Error saving game."); fclose(file); } @@ -214,12 +216,10 @@ extern struct yx_uint16 find_passable_pos(struct Map * map) -extern unsigned char meta_keys(int key, struct World * world, - struct WinMeta * win_meta, - struct Win * win_keys, - struct Win * win_map, - struct Win * win_info, - struct Win * win_log) +extern uint8_t meta_keys(int key, struct World * world, + struct WinMeta * win_meta, struct Win * win_keys, + struct Win * win_map, struct Win * win_info, + struct Win * win_log) { if (key == get_action_key(world->keybindings, "quit")) {