summaryrefslogtreecommitdiff
path: root/src/z_pack.pkg
blob: 5a46b3b22e95329522495374381f3a2126995daa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
/* File: z_pack.pkg */

/*
 * Purpose: Lua interface defitions for z-*.c
 * To be processed by tolua to generate C source code.
 */

$#include "angband.h"

/** @typedef cptr
 * @note String
 */
typedef char* cptr;
/** @typedef errr
 * @note Number
 */
typedef int errr;
/** @typedef bool
 * @note Boolean
 */
typedef unsigned char bool;
/** @typedef byte
 * @note Number
 */
typedef unsigned char byte;
/** @typedef s16b
 * @note Number
 */
typedef signed short s16b;
/** @typedef u16b
 * @note Number
 */
typedef unsigned short u16b;
/** @typedef s32b
 * @note Number
 */
typedef signed int s32b;
/** @typedef u32b
 * @note Number
 */
typedef unsigned int u32b;

/** @name Terminal actions
 * @{ */
/** @def TERM_XTRA_EVENT
 * @note Process some pending events 
 */
#define TERM_XTRA_EVENT	1	
/** @def TERM_XTRA_FLUSH
 * @note Flush all pending events 
 */
#define TERM_XTRA_FLUSH 2	
/** @def TERM_XTRA_CLEAR
 * @note Clear the entire window 
 */
#define TERM_XTRA_CLEAR 3	
/** @def TERM_XTRA_SHAPE
 * @note Set cursor shape (optional) 
 */
#define TERM_XTRA_SHAPE 4	
/** @def TERM_XTRA_FROSH
 * @note Flush one row (optional) 
 */
#define TERM_XTRA_FROSH 5	
/** @def TERM_XTRA_FRESH
 * @note Flush all rows (optional) 
 */
#define TERM_XTRA_FRESH 6	
/** @def TERM_XTRA_NOISE
 * @note Make a noise (optional) 
 */
#define TERM_XTRA_NOISE 7	
/** @def TERM_XTRA_SOUND
 * @note Make a sound (optional) 
 */
#define TERM_XTRA_SOUND 8	
/** @def TERM_XTRA_BORED
 * @note Handle stuff when bored (optional) 
 */
#define TERM_XTRA_BORED 9	
/** @def TERM_XTRA_REACT
 * @note React to global changes (optional) 
 */
#define TERM_XTRA_REACT 10	
/** @def TERM_XTRA_ALIVE
 * @note Change the "hard" level (optional) 
 */
#define TERM_XTRA_ALIVE 11	
/** @def TERM_XTRA_LEVEL
 * @note Change the "soft" level (optional) 
 */
#define TERM_XTRA_LEVEL 12	
/** @def TERM_XTRA_DELAY
 * @note Delay some milliseconds (optional) 
 */
#define TERM_XTRA_DELAY 13	
/** @def TERM_XTRA_GET_DELAY
 * @note Get the cuyrrent time in milliseconds (optional) 
 */
#define TERM_XTRA_GET_DELAY 14	
/** @def TERM_XTRA_SCANSUBDIR
 * @note Scan for subdir in a dir 
 */
#define TERM_XTRA_SCANSUBDIR 15 
/** @} */

/** @var Term_xtra_long
 * @brief Number
 */
extern long Term_xtra_long;

/** @var scansubdir_dir[1024]
 * @brief String
 * @note The directory which is scanned for sub-directories.
 */
char scansubdir_dir[1024];

/** @var scansubdir_max
 * @brief Number
 * @note The number of entries in the scansubdir_result array.
 */
int scansubdir_max;

/** @var scansubdir_result[scansubdir_max]
 * @brief String
 * @note The sub-directories of scansubdir_dir directory.
 */
cptr scansubdir_result[scansubdir_max];

/** @fn Term_xtra(int n, int v)
 * @brief Generic function to perform system dependant terminal actions.\n
 * @param n Number \n a terminal action (see TERM_XTRA fields).
 * @brief Terminal action
 * @param v Number \n variable depending on the terminal action.
 * @brief Variable
 * @return Number \n Result of the terminal action.
 * @note
 * The "Term->xtra_hook" hook provides a variety of different functions,
 * based on the first parameter (which should be taken from the various
 * TERM_XTRA_* defines) and the second parameter (which may make sense
 * only for some first parameters).  It is available to the program via
 * the "Term_xtra()" function, though some first parameters are only
 * "legal" when called from inside this package.
 * @note (see file z-term.c)
 */
extern errr Term_xtra(int n, int v);

/** @fn Term_set_cursor(int v)
 * @brief Set the cursor visibility.\n
 * @param v Number \n v is the visibility.
 * @brief Visibility
 * @return Number \n 1 if visibility was unchanged, otherwise 0.
 * @note
 * Cursor visibility (field "cv") is defined as a boolean, so take care what
 * value is assigned to "v".
 * @note (see file z-term.c)
 */
extern errr Term_set_cursor(int v);

/** @fn Term_gotoxy(int x, int y)
 * @brief Place the cursor at a given location.\n
 * @param x Number \n x-coordinate of target location.
 * @brief X-coordinate
 * @param y Number \n y-coordinate of target location.
 * @brief Y-coordinate
 * @return Number \n -1 if cursor could not be placed at given location,
 * otherwise 0.
 * @note
 * Note -- "illegal" requests do not move the cursor.\n\n
 * The cursor is flagged as useful if it placed okay.
 * @note (see file z-term.c)
 */
extern errr Term_gotoxy(int x, int y);

/** @fn Term_putch(int x, int y, byte a, char c)
 * @brief Move to a location and, using an attr, add a char.\n
 * @param x Number \n x-coordinate of target location.
 * @brief X-coordinate
 * @param y Number \n y-coordinate of target location.
 * @brief Y-coordinate
 * @param a Number \n attribute of character.
 * @brief Attribute
 * @param c String \n the character.
 * @brief Character
 * @return Number \n <0 if error, 0 if success, 1 if success but cursor is
 * useless.
 * @note
 * We return "-2" if the character is "illegal". XXX XXX\n\n
 * We return "-1" if the cursor is currently unusable.\n\n
 * We queue the given attr/char for display at the current
 * cursor location, and advance the cursor to the right,
 * marking it as unuable and returning "1" if it leaves
 * the screen, and otherwise returning "0".\n\n
 * So when this function returns a positive value, future calls to this
 * function will return negative ones.
 * @note (see file z-term.c)
 */
extern errr Term_putch(int x, int y, byte a, char c);

/** @fn Term_putstr(int x, int y, int n, byte a, cptr s)
 * @brief Move to a location and, using an attr, add a string.\n
 * @param x Number \n x-coordinate of target location.
 * @brief X-coordinate
 * @param y Number \n y-coordinate of target location.
 * @brief Y-coordinate
 * @param n Number \n length of string.
 * @brief Length
 * @param a Number \n attribute of string.
 * @brief Attribute
 * @param s String \n the string.
 * @brief String
 * @return Number \n <0 if error, 0 if success, 1 if success but cursor is
 * useless.
 * @note
 * For length "n", using negative values to imply the largest possible value,
 * and then we use the minimum of this length and the "actual" length of the
 * string as the actual number of characters to attempt to display, never
 * displaying more characters than will actually fit, since we do NOT attempt
 * to "wrap" the cursor at the screen edge.\n\n
 * We return "-1" if the cursor is currently unusable.\n
 * We return "N" if we were "only" able to write "N" chars, even if all of the
 * given characters fit on the screen, and mark the cursor as unusable for
 * future attempts.\n\n
 * So when this function, returns a positive value, future calls to this
 * function will return negative ones.
 * @note (see file z-term.c)
 */
extern errr Term_putstr(int x, int y, int n, byte a, cptr s);

/** @fn Term_clear(void)
 * @brief Clear the entire window, and move to the top left corner.
 * @return Number \n 0 (always).
 * @note
 * Note the use of the special "total_erase" code
 * @note (see file z-term.c)
 */
extern errr Term_clear(void);

/** @fn Term_redraw(void)
 * @brief Redraw (and refresh) the whole window.
 * @return Number \n 0 (always).
 * @note (see file z-term.c)
 */
extern errr Term_redraw(void);

/** @fn Term_redraw_section(int x1, int y1, int x2, int y2)
 * @brief Redraw part of a window.\n
 * @param x1 Number \n x-coordinate of top-left location.
 * @brief X-coordinate (top left)
 * @param y1 Number \n y-coordinate of top-left location.
 * @brief Y-coordinate (top left)
 * @param x2 Number \n x-coordinate of bottom-right location.
 * @brief X-coordinate (bottom right)
 * @param y2 Number \n y-coordinate of bottom-right location.
 * @brief Y-coordinate (bottom right)
 * @return Number \n 0 (always).
 * @note (see file z-term.c)
 */
extern errr Term_redraw_section(int x1, int y1, int x2, int y2);

/** @fn Term_get_size(int *w, int *h)
 * @brief Extract the current window size.\n
 * @param *w Number
 * @brief Screen width
 * @param *h Number
 * @brief Screen height
 * @return Number \n 0 (always).
 * @return *w Number \n The width of the screen (in characters).
 * @return *h Number \n The height of the screen (in characters).
 * @note (see file z-term.c)
 */
extern errr Term_get_size(int *w, int *h);

/*
 * random numbers
 */
$static s32b lua_rand_int(s32b m) {return rand_int(m);}

/** @fn rand_int(s32b m);
 * @brief Generate a random integer between 0 and (m - 1).\n
 * @param m Number \n maximum value of random integer. The random integer
 * will be less than "m".
 * @brief Maximum
 * @return Number \n The random number.
 * @note (see file w_z_pack.c)
 */
static s32b lua_rand_int @ rand_int(s32b m);

/*
 * Generates a random long integer X where A<=X<=B
 * The integer X falls along a uniform distribution.
 * Note: rand_range(0,N-1) == rand_int(N)
 */
$static s32b lua_rand_range(s32b A, s32b B) {return ((A) + (rand_int(1+(B)-(A))));}

/** @fn  rand_range(s32b A, s32b B);
 * @brief Generate a random integer between A and B inclusive.\n
 * @param A Number \n minimum number.
 * @brief Minimum
 * @param B Number \n maximum number.
 * @brief Maximum
 * @return Number \n The random number.
 * @note (see file w_z_pack.c)
 */
static s32b lua_rand_range @ rand_range(s32b A, s32b B);

/*
 * Generate a random long integer X where A-D<=X<=A+D
 * The integer X falls along a uniform distribution.
 * Note: rand_spread(A,D) == rand_range(A-D,A+D)
 */
$static s32b lua_rand_spread(s32b A, s32b D) {return ((A) + (rand_int(1+(D)+(D))) - (D));}

/** @fn  rand_spread(s32b A, s32b D);
 * @brief Generate a radom integer between A-D and A+D inclusive.\n
 * @param A Number \n average number.
 * @brief Average
 * @param D Number \n deviation from average.
 * @brief Deviation
 * @return Number \n The random number.
 * @note (see file w_z_pack.c)
 */
static s32b lua_rand_spread @ rand_spread(s32b A, s32b D);


/*
 * Generate a random long integer X where 1<=X<=M
 * Also, "correctly" handle the case of M<=1
 */
$static s32b lua_randint(s32b m) {return rand_int(m) + 1;}

/** @fn  randint(s32b m);
 * @brief Generate a random integer between 1 and M inclusive.\n
 * @param m Number \n maximum value of random integer.
 * @brief Maximum
 * @return Number \n The random number.
 * @note (see file w_z_pack.c)
 */
static s32b lua_randint @ randint(s32b m);


/*
 * Evaluate to TRUE "P" percent of the time
 */
$static bool lua_magik(s32b P) {return (rand_int(100) < (P));}

/** @fn  magik(s32b P);
 * @brief Return TRUE "P" % of the time.
 * @param P Number \n percent chance the function returns TRUE.
 * @brief Percent true
 * @return Boolean \n TRUE if a random number from 0 to 99 is less than P,
 * otherwise FALSE.
 * @note (see file w_z_pack.c)
 */
static bool lua_magik @ magik(s32b P);


/**** Available Variables ****/
/** @var Rand_quick
 * @brief Boolean
 * @note
 * If this is TRUE, then use the "simple" Random Number Generator.\n
 * If this is FALSE, then use the "complex" Random Number Generator.
 */
extern bool Rand_quick;

/** @var Rand_value
 * @brief Number
 * @note
 * The current value (seed) of the simple Random Number Generator.
 */
extern u32b Rand_value;

/**** Available Functions ****/
/** @fn damroll(int num, int sides)
 * @brief Generates damage for "2d6" style dice rolls.\n
 * @param num Number \n the number of "dice" used.
 * @brief Number
 * @param sides Number \n the number of sides on each "die".
 * @brief Sides
 * @return Number \n The random number.
 * @note
 * The function simulates the rolling of "num" "sides"-sided dice. Each die
 * will result in a random number from 1 to "sides".
 * @note (see file z-rand.c)
 */
extern s16b damroll(int num, int sides);

/** @fn maxroll(int num, int sides)
 * @brief Generate the maximum damage for "num" dice with "sides" sides each.
 * @param num Number \n The number of "dice" used.
 * @brief Number
 * @param sides Number \n The number of sides on each "die".
 * @brief Sides
 * @return Number \n "num" * "sides".
 * @note (see file z-rand.c)
 */
extern s16b maxroll(int num, int sides);