X-Git-Url: https://plomlompom.com/repos/?a=blobdiff_plain;ds=sidebyside;f=src%2Fmisc.c;h=cb650a0436b648cfd61c6f3bcb810bcd4a6044e8;hb=27cee0624f3dc430199c99f000179a3385e4d7c5;hp=83ed263a4ff3891925d76f10c3061dc7f7fcb22c;hpb=d165f8ae619c78fd1ef98a9ba2abdaeeceff853e;p=plomrogue diff --git a/src/misc.c b/src/misc.c index 83ed263..cb650a0 100644 --- a/src/misc.c +++ b/src/misc.c @@ -5,8 +5,42 @@ #include "keybindings.h" #include "readwrite.h" #include "map_objects.h" +#include "map_object_actions.h" #include "map.h" #include "main.h" +#include "yx_uint16.h" + +extern void exit_game(struct World * world, struct Map * map) { +// Clean up and exit. + endwin(); + free(map->cells); + uint16_t key; + for (key = 0; key <= world->keyswindata->max; key++) + free(world->keybindings[key].name); + free(world->keybindings); + free(world->keyswindata); + free(world->log); + exit (EXIT_SUCCESS); } + +extern void textfile_sizes (FILE * file, uint16_t * linemax_p, uint16_t * n_lines_p) { +// Learn largest line length (linemax_p) and (n_lines_p if not set to NULL) number of lines. + uint16_t n_lines = 0; + int c = 0; + uint16_t linemax = 0; + uint16_t c_count = 0; + while (EOF != c) { + c_count++; + c = getc(file); + if ('\n' == c) { + if (c_count > linemax) + linemax = c_count + 1; + c_count = 0; + if (n_lines_p) + n_lines++; } } + fseek(file, 0, SEEK_SET); + * linemax_p = linemax; + if (n_lines_p) + * n_lines_p = n_lines; } extern uint16_t rrand(char use_seed, uint32_t new_seed) { // Pseudo-random number generator (LGC algorithm). Use instead of rand() to ensure portable predictability. @@ -71,7 +105,7 @@ extern void save_game(struct World * world) { write_uint16_bigendian(world->player->pos.x + 1, file); fputc(world->player->hitpoints, file); write_map_objects (world->monster, file, write_map_objects_monsterdata); - write_map_objects (world->item, file, readwrite_map_objects_dummy); + write_map_objects (world->item, file, NULL); fclose(file); } extern void toggle_window (struct WinMeta * win_meta, struct Win * win) { @@ -98,6 +132,14 @@ extern void growshrink_active_window (struct WinMeta * win_meta, char change) { else if (change == '*') size.x++; resize_active_win (win_meta, size); } } +extern struct yx_uint16 find_passable_pos (struct Map * map) { +// Return a random passable position on map. + struct yx_uint16 pos; + for (pos.y = pos.x = 0; 0 == is_passable(map, pos);) { + pos.y = rrand(0, 0) % map->size.y; + pos.x = rrand(0, 0) % map->size.x; } + return pos; } + 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) {