X-Git-Url: https://plomlompom.com/repos/?a=blobdiff_plain;f=src%2Fmisc.h;h=bc3e274a5c2c3a181396a630f60f574123a2d889;hb=2ee362765a142ed12df2de1b7c337b46d6674395;hp=6257b122fe45d600d4049bd1aa413f4ed84aabe0;hpb=7b6558a08527dc27995af156e43734be3da950a0;p=plomrogue diff --git a/src/misc.h b/src/misc.h index 6257b12..bc3e274 100644 --- a/src/misc.h +++ b/src/misc.h @@ -7,106 +7,69 @@ #ifndef MISC_H #define MISC_H - - -#include /* for uint16_t, uint32_t */ -#include /* for FILE typedef */ +#include /* for size_t */ +#include /* for uint16_t */ #include "yx_uint16.h" /* for yx_uint16 coordinates */ -struct World; -struct WinMeta; -struct Win; struct Map; -/* Reset terminal (end ncurses), clean up memory and exit. */ -extern void exit_game(struct World * world, struct Map * map); - - - -/* Learn from "file" the largest line length (pointed to by "linemax_p") and - * (pointed to by "n_lines_p" if it is not set to NULL) the number of lines. +/* Return 16-bit number pseudo-randomly generated via Linear Congruential + * Generator algorithm with some proven constants. Use instead of rand() to + * ensure portability of the same pseudo-randomness across systems. */ -extern void textfile_sizes(FILE * file, uint16_t * linemax_p, - uint16_t * n_lines_p); - +extern uint16_t rrand(); +/* Returns message: "Trouble in ".parent." with ".child."." (try_*() helper) */ +extern char * trouble_msg(char * parent, char * child); -/* Pseudo-random number generator using a Linear Congruential Generator - * algorithm with some proven constants. Used instead of rand() to ensure - * portable pseudo-randomness predictability. Set "use_seed" to !0 to seed it - * with "new_seed". - * - * TODO: Write a wrapper for all non-seeding uses that demands no input. +/* Wrappers to malloc(), calloc() from function called "f" calling exit_err() + * with trouble_msg() error message if necessary. */ -extern uint16_t rrand(char use_seed, uint32_t new_seed); +extern void * try_malloc(size_t size, char * f); +extern void * try_calloc(size_t nmemb, size_t size, char * f); + +/* Check if tempfile "path" exists, and if so, exit with explanation that. */ +extern void check_tempfile(char * path); +/* If one and only one of files at "p1", "p2" exists, fail with explanation. */ +extern void check_files_xor(char * p1, char * p2); +/* Save / load / unload (free) / reload interface configuration data. */ +extern void save_interface_conf(); +extern void load_interface_conf(); +extern void unload_interface_conf(); +extern void reload_interface_conf(); /* Update game log by appending "text", or by appending a "." if "text" is the * same as the last one passed. */ -extern void update_log(struct World * world, char * text); +extern void update_log(char * text); - - -/* Return the offset necessary to center "map" on position "pos" in a frame of - * "framesize. +/* Return the offset necessary to center a map of "mapsize" on position "pos" in + * a frame of "framesize. */ -extern uint16_t center_offset(uint16_t pos, uint16_t mapsize, - uint16_t framesize); - - +extern uint16_t center_offset(uint16_t pos, + uint16_t mapsize, uint16_t framesize); /* Record last player "action" in game record file "record, increment the game * turn and trigger enemy movement. */ -extern void turn_over(struct World * world, char action); - - - -/* Save current game data to file "savefile". */ -extern void save_game(struct World * world); - - - -/* Toggle display of a window "win". */ -extern void toggle_window(struct WinMeta * win_meta, struct Win * win); - - - -/* Try to scroll virtual screen left ("dir" = "-") or right ("dir" = "+"), - * subject to the limitations provided by the window manager via - * reset_pad_offset(). - */ -extern void scroll_pad(struct WinMeta * win_meta, char dir); - - - -/* Try to grow or shrink the active window horizontally ("change" = "*"/"_") or - * vertically ("change = "+"/"-") by one cell size, subject to the limitations - * provided by the window manager via resize_active_win(). - */ -extern void growshrink_active_window(struct WinMeta * win_meta, char change); - +extern void turn_over(char action); +/* Save or load current game data to / from file "savefile". */ +extern void save_game(); +extern void load_game(); /* Return a random position on the map "map" that is passable (as determined by * is_passable(). */ extern struct yx_uint16 find_passable_pos(struct Map * map); - - -/* Call some meta game / window management actions dependent on key. If the - * "quit" action is called, return 1 only instead of doing anything directly. +/* Navigate (as far as possible) up (dir=='u') or (else) down in player's + * inventory selection. */ -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 void nav_inventory(char dir);