home · contact · privacy
Applied new formatting and documentation rules to misc module.
[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
11
12 #include <stdint.h>    /* for uint16_t, uint32_t */
13 #include <stdio.h>     /* for FILE typedef */
14 #include "yx_uint16.h" /* for yx_uint16 coordinates */
15 struct World;
16 struct WinMeta;
17 struct Win;
18 struct Map;
19
20
21
22 /* Reset terminal (end ncurses), clean up memory and exit. */
23 extern void exit_game(struct World * world, struct Map * map);
24
25
26
27 /* Learn from "file" the largest line length (pointed to by "linemax_p") and
28  * (pointed to by "n_lines_p" if it is not set to NULL) the number of lines.
29  */
30 extern void textfile_sizes(FILE * file, uint16_t * linemax_p,
31                            uint16_t * n_lines_p);
32
33
34
35 /* Pseudo-random number generator using a Linear Congruential Generator
36  * algorithm with some proven constants. Used instead of rand() to ensure
37  * portable pseudo-randomness predictability. Set "use_seed" to !0 to seed it
38  * with "new_seed".
39  *
40  * TODO: Write a wrapper for all non-seeding uses that demands no input.
41  */
42 extern uint16_t rrand(char use_seed, uint32_t new_seed);
43
44
45
46 /* Update game log by appending "text", or by appending a "." if "text" is the
47  * same as the last one passed.
48  */
49 extern void update_log(struct World * world, char * text);
50
51
52
53 /* Return the offset necessary to center "map" on position "pos" in a frame of
54  * "framesize.
55  */
56 extern uint16_t center_offset(uint16_t pos, uint16_t mapsize,
57                               uint16_t framesize);
58
59
60
61 /* Record last player "action" in game record file "record, increment the game
62  * turn and trigger enemy movement.
63  */
64 extern void turn_over(struct World * world, char action);
65
66
67
68 /* Save current game data to file "savefile". */
69 extern void save_game(struct World * world);
70
71
72
73 /* Toggle display of a window "win". */
74 extern void toggle_window(struct WinMeta * win_meta, struct Win * win);
75
76
77
78 /* Try to scroll virtual screen left ("dir" = "-") or right ("dir" = "+"),
79  * subject to the limitations provided by the window manager via
80  * reset_pad_offset().
81  */
82 extern void scroll_pad(struct WinMeta * win_meta, char dir);
83
84
85
86 /* Try to grow or shrink the active window horizontally ("change" = "*"/"_") or
87  * vertically ("change = "+"/"-") by one cell size, subject to the limitations
88  * provided by the window manager via resize_active_win().
89  */
90 extern void growshrink_active_window(struct WinMeta * win_meta, char change);
91
92
93
94 /* Return a random position on the map "map" that is passable (as determined by
95  * is_passable().
96  */
97 extern struct yx_uint16 find_passable_pos(struct Map * map);
98
99
100
101 /* Call some meta game / window management actions dependent on key. If the
102  * "quit" action is called, return 1 only instead of doing anything directly.
103  */
104 extern unsigned char meta_keys(int key, struct World * world,
105                                struct WinMeta * win_meta,
106                                struct Win * win_keys,
107                                struct Win * win_map,
108                                struct Win * win_info,
109                                struct Win * win_log);
110
111
112
113 #endif