home · contact · privacy
Transformed trouble_msg() into exit_err() wrapper exit_trouble(), eliminating some...
[plomrogue] / src / misc.h
1 /* misc.h
2  *
3  * Miscellaneous routines that have not yet found a proper parent module. Having
4  * LOTS of stuff in here is a sure sign that better modularization is in order.
5  */
6
7 #ifndef MISC_H
8 #define MISC_H
9
10 #include <stdlib.h>    /* for size_t */
11 #include <stdint.h>    /* for uint16_t */
12 #include "yx_uint16.h" /* for yx_uint16 coordinates */
13 struct Map;
14
15
16
17 /* Return 16-bit number pseudo-randomly generated via Linear Congruential
18  * Generator algorithm with some proven constants. Use instead of rand() to
19  * ensure portability of the same pseudo-randomness across systems.
20  */
21 extern uint16_t rrand();
22
23 /* Do exit_err() with message: "Trouble in ".parent." with ".child."." */
24 extern void exit_trouble(uint8_t test, char * parent, char * child);
25
26 /* Wrappers to malloc(), calloc() from function called "f" calling exit_err()
27  * with trouble_msg() error message if necessary.
28  */
29 extern void * try_malloc(size_t size, char * f);
30 extern void * try_calloc(size_t nmemb, size_t size, char * f);
31
32 /* Check if tempfile "path" exists, and if so, exit with explanation that. */
33 extern void check_tempfile(char * path);
34
35 /* If one and only one of files at "p1", "p2" exists, fail with explanation. */
36 extern void check_files_xor(char * p1, char * p2);
37
38 /* Save / load / unload (free) / reload interface configuration data. */
39 extern void save_interface_conf();
40 extern void load_interface_conf();
41 extern void unload_interface_conf();
42 extern void reload_interface_conf();
43
44 /* Update game log by appending "text", or by appending a "." if "text" is the
45  * same as the last one passed.
46  */
47 extern void update_log(char * text);
48
49 /* Return the offset necessary to center a map of "mapsize" on position "pos" in
50  * a frame of "framesize.
51  */
52 extern uint16_t center_offset(uint16_t pos,
53                               uint16_t mapsize, uint16_t framesize);
54
55 /* Record last player "action" in game record file "record, increment the game
56  * turn and trigger enemy movement.
57  */
58 extern void turn_over(char action);
59
60 /* Save or load current game data to / from file "savefile". */
61 extern void save_game();
62 extern void load_game();
63
64 /* Return a random position on the map "map" that is passable (as determined by
65  * is_passable().
66  */
67 extern struct yx_uint16 find_passable_pos(struct Map * map);
68
69 /* Navigate (as far as possible) up (dir=='u') or (else) down in player's
70  * inventory selection.
71  */
72 extern void nav_inventory(char dir);
73
74
75
76 #endif