Compatibility with old-but-newer-than-C89 compilers.
[rogue-pphs.git] / rogue.h
1 /*
2 * Rogue definitions and variable declarations
3 *
4 * @(#)rogue.h 3.38 (Berkeley) 6/15/81
5 *
6 * Rogue: Exploring the Cavern of Cuties
7 * Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman
8 * All rights reserved.
9 *
10 * See the file LICENSE.TXT for full copyright and licensing information.
11 */
12
13 #define NULL ((void *)0)
14 #define TRUE 1
15 #define FALSE 0
16
17 /*
18 * Maximum number of different things
19 */
20 #define MAXROOMS 9
21 #define MAXTHINGS 9
22 #define MAXOBJ 9
23 #define MAXPACK 23
24 #define MAXTRAPS 10
25 #define NUMTHINGS 7 /* number of types of things (scrolls, rings, etc.) */
26
27 /*
28 * return values for get functions
29 */
30 #define NORM 0 /* normal exit */
31 #define QUIT 1 /* quit option setting */
32 #define MINUS 2 /* back up one option */
33
34 /*
35 * All the fun defines
36 */
37 #define next(ptr) (*ptr).l_next
38 #define prev(ptr) (*ptr).l_prev
39 #define ldata(ptr) (*ptr).l_data
40 #define inroom(rp, cp) (\
41 (cp)->x <= (rp)->r_pos.x + ((rp)->r_max.x - 1) && (rp)->r_pos.x <= (cp)->x \
42 && (cp)->y <= (rp)->r_pos.y + ((rp)->r_max.y - 1) && (rp)->r_pos.y <= (cp)->y)
43 #define winat(y, x) (mvwinch(mw,y,x)==' '?mvwinch(stdscr,y,x):winch(mw))
44 #define debug if (wizard) msg
45 #define RN (((seed = seed*11109+13849) & 0x7fff) >> 1)
46 #define unc(cp) (cp).y, (cp).x
47 #define cmov(xy) move((xy).y, (xy).x)
48 #define DISTANCE(y1, x1, y2, x2) ((x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1))
49 #define OBJPTR(what) (struct object *)((*what).l_data)
50 #define THINGPTR(what) (struct thing *)((*what).l_data)
51 #define when break;case
52 #define otherwise break;default
53 #define until(expr) while(!(expr))
54 #define ce(a, b) ((a).x == (b).x && (a).y == (b).y)
55 #define draw(window) (wrefresh(window),usleep(20000))
56 #define hero player.t_pos
57 #define pstats player.t_stats
58 #define pack player.t_pack
59 #define attach(a,b) _attach(&a,b)
60 #define detach(a,b) _detach(&a,b)
61 #define free_list(a) _free_list(&a)
62 #ifndef max
63 #define max(a, b) ((a) > (b) ? (a) : (b))
64 #endif
65 #define on(thing, flag) (((thing).t_flags & flag) != 0)
66 #define off(thing, flag) (((thing).t_flags & flag) == 0)
67 #undef CTRL
68 #define CTRL(ch) (ch & 037)
69 #define ALLOC(x) malloc((unsigned int) x)
70 #define FREE(x) free((char *) x)
71 #define EQSTR(a, b, c) (strncmp(a, b, c) == 0)
72 #define GOLDCALC (rnd(50 + 10 * level) + 2)
73 #define ISRING(h,r) (cur_ring[h] != NULL && cur_ring[h]->o_which == r)
74 #define ISWEARING(r) (ISRING(LEFT, r) || ISRING(RIGHT, r))
75 #define newgrp() ++group
76 #define o_charges o_ac
77 #define ISMULT(type) (type == POTION || type == SCROLL || type == FOOD)
78 #define rndchoice(a) (a[rnd(sizeof(a)/sizeof((a)[0]))])
79 #define hash(i) ((unsigned)(i)*2654435761u)
80
81 /*
82 * Things that appear on the screens
83 */
84 #define PASSAGE '#'
85 #define DOOR '+'
86 #define FLOOR '.'
87 #define PLAYER '@'
88 #define TRAP '^'
89 #define TRAPDOOR '>'
90 #define ARROWTRAP '{'
91 #define SLEEPTRAP '$'
92 #define BEARTRAP '}'
93 #define TELTRAP '~'
94 #define DARTTRAP '`'
95 #define SECRETDOOR '&'
96 #define STAIRS '%'
97 #define GOLD '*'
98 #define POTION '!'
99 #define SCROLL '?'
100 #define MAGIC '$'
101 #define FOOD ':'
102 #define WEAPON ')'
103 #define ARMOR ']'
104 #define AMULET ','
105 #define RING '='
106 #define STICK '/'
107 #define CALLABLE -1
108
109 /*
110 * Various constants
111 */
112 #define PASSWD "mTBellIQOsLNA"
113 #define BEARTIME 3
114 #define SLEEPTIME 5
115 #define HEALTIME 30
116 #define HOLDTIME 2
117 #define STPOS 0
118 #define WANDERTIME 70
119 #define BEFORE 1
120 #define AFTER 2
121 #define HUHDURATION 20
122 #define SEEDURATION 850
123 #define HUNGERTIME 1300
124 #define MORETIME 150
125 #define STOMACHSIZE 2000
126 #define ESCAPE 27
127 #define LEFT 0
128 #define RIGHT 1
129 #define BOLT_LENGTH 6
130
131 /*
132 * Save against things
133 */
134 #define VS_POISON 00
135 #define VS_PARALYZATION 00
136 #define VS_DEATH 00
137 #define VS_PETRIFICATION 01
138 #define VS_BREATH 02
139 #define VS_MAGIC 03
140
141 /*
142 * Various flag bits
143 */
144 #define ISDARK 0000001
145 #define ISCURSED 000001
146 #define ISBLIND 0000001
147 #define ISGONE 0000002
148 #define ISKNOW 0000002
149 #define ISRUN 0000004
150 #define ISFOUND 0000010
151 #define ISINVIS 0000020
152 #define ISMEAN 0000040
153 #define ISGREED 0000100
154 #define ISBLOCK 0000200
155 #define ISHELD 0000400
156 #define ISHUH 0001000
157 #define ISREGEN 0002000
158 #define CANHUH 0004000
159 #define CANSEE 0010000
160 #define ISMISL 0020000
161 #define ISCANC 0020000
162 #define ISMANY 0040000
163 #define ISSLOW 0040000
164 #define ISHASTE 0100000
165
166 /*
167 * Potion types
168 */
169 #define P_CONFUSE 0
170 #define P_PARALYZE 1
171 #define P_POISON 2
172 #define P_STRENGTH 3
173 #define P_SEEINVIS 4
174 #define P_HEALING 5
175 #define P_MFIND 6
176 #define P_TFIND 7
177 #define P_RAISE 8
178 #define P_XHEAL 9
179 #define P_HASTE 10
180 #define P_RESTORE 11
181 #define P_BLIND 12
182 #define P_NOP 13
183 #define MAXPOTIONS 14
184
185 /*
186 * Scroll types
187 */
188 #define S_CONFUSE 0
189 #define S_MAP 1
190 #define S_LIGHT 2
191 #define S_HOLD 3
192 #define S_SLEEP 4
193 #define S_ARMOR 5
194 #define S_IDENT 6
195 #define S_SCARE 7
196 #define S_GFIND 8
197 #define S_TELEP 9
198 #define S_ENCH 10
199 #define S_CREATE 11
200 #define S_REMOVE 12
201 #define S_AGGR 13
202 #define S_NOP 14
203 #define S_GENOCIDE 15
204 #define MAXSCROLLS 16
205
206 /*
207 * Weapon types
208 */
209 #define MACE 0
210 #define SWORD 1
211 #define BOW 2
212 #define ARROW 3
213 #define DAGGER 4
214 #define ROCK 5
215 #define TWOSWORD 6
216 #define SLING 7
217 #define DART 8
218 #define CROSSBOW 9
219 #define BOLT 10
220 #define SPEAR 11
221 #define MAXWEAPONS 12
222
223 /*
224 * Armor types
225 */
226 #define LEATHER 0
227 #define RING_MAIL 1
228 #define STUDDED_LEATHER 2
229 #define SCALE_MAIL 3
230 #define CHAIN_MAIL 4
231 #define SPLINT_MAIL 5
232 #define BANDED_MAIL 6
233 #define PLATE_MAIL 7
234 #define MAXARMORS 8
235
236 /*
237 * Ring types
238 */
239 #define R_PROTECT 0
240 #define R_ADDSTR 1
241 #define R_SUSTSTR 2
242 #define R_SEARCH 3
243 #define R_SEEINVIS 4
244 #define R_NOP 5
245 #define R_AGGR 6
246 #define R_ADDHIT 7
247 #define R_ADDDAM 8
248 #define R_REGEN 9
249 #define R_DIGEST 10
250 #define R_TELEPORT 11
251 #define R_STEALTH 12
252 #define MAXRINGS 13
253
254 /*
255 * Rod/Wand/Staff types
256 */
257
258 #define WS_LIGHT 0
259 #define WS_HIT 1
260 #define WS_ELECT 2
261 #define WS_FIRE 3
262 #define WS_COLD 4
263 #define WS_POLYMORPH 5
264 #define WS_MISSILE 6
265 #define WS_HASTE_M 7
266 #define WS_SLOW_M 8
267 #define WS_DRAIN 9
268 #define WS_NOP 10
269 #define WS_TELAWAY 11
270 #define WS_TELTO 12
271 #define WS_CANCEL 13
272 #define MAXSTICKS 14
273
274 /*
275 * Now we define the structures and types
276 */
277
278 /*
279 * Help list
280 */
281
282 struct h_list {
283 char h_ch;
284 char *h_desc;
285 };
286
287 extern struct h_list helpstr[];
288
289 /*
290 * Coordinate data type
291 */
292 typedef struct {
293 int x;
294 int y;
295 } coord;
296
297 typedef struct {
298 short st_str;
299 short st_add;
300 } str_t;
301
302 /*
303 * Linked list data type
304 */
305 struct linked_list {
306 struct linked_list *l_next;
307 struct linked_list *l_prev;
308 char *l_data; /* Various structure pointers */
309 };
310
311 /*
312 * Stuff about magic items
313 */
314
315 struct magic_item {
316 char mi_name[30];
317 int mi_prob;
318 int mi_worth;
319 };
320
321 /*
322 * Room structure
323 */
324 struct room {
325 coord r_pos; /* Upper left corner */
326 coord r_max; /* Size of room */
327 coord r_gold; /* Where the gold is */
328 int r_goldval; /* How much the gold is worth */
329 int r_flags; /* Info about the room */
330 int r_nexits; /* Number of exits */
331 coord r_exit[4]; /* Where the exits are */
332 };
333
334 /*
335 * Array of all traps on this level
336 */
337 struct trap {
338 coord tr_pos; /* Where trap is */
339 char tr_type; /* What kind of trap */
340 int tr_flags; /* Info about trap (i.e. ISFOUND) */
341 };
342
343 extern struct trap traps[MAXTRAPS];
344
345 #define NUM_FEATURES 6
346 #define MAYBE_INTERESTED 1
347 #define INTERESTED 40
348 #define READY 100
349
350 /*
351 * Structure describing a fighting being
352 */
353 struct stats {
354 str_t s_str; /* Strength */
355 long s_exp; /* Experience */
356 int s_lvl; /* Level of mastery */
357 int s_arm; /* Armor class */
358 int s_hpt; /* Hit points */
359 char s_dmg[30]; /* String describing damage done */
360 int s_ont; /* Orientation flags */
361 int s_int; /* Level of interest in rogue */
362 };
363
364 /*
365 * Structure for monsters and player
366 */
367 struct thing {
368 coord t_pos; /* Position */
369 bool t_turn; /* If slowed, is it a turn to move */
370 char t_type; /* What it is */
371 char t_disguise; /* What mimic looks like */
372 char t_oldch; /* Character that was where it was */
373 coord *t_dest; /* Where it is running to */
374 short t_flags; /* State word */
375 struct stats t_stats; /* Physical description */
376 struct linked_list *t_pack; /* What the thing is carrying */
377 int t_reserved; /* reserved for save/restore code */
378 };
379
380 /*
381 * Array containing information on all the various types of mosnters
382 */
383 struct monster {
384 char m_name[20]; /* What to call the monster */
385 short m_carry; /* Probability of carrying something */
386 short m_flags; /* Things about the monster */
387 struct stats m_stats; /* Initial stats */
388 };
389
390 /*
391 * Structure for a thing that the rogue can carry
392 */
393
394 struct object {
395 int o_type; /* What kind of object it is */
396 coord o_pos; /* Where it lives on the screen */
397 char o_launch; /* What you need to launch it */
398 char o_damage[8]; /* Damage if used like sword */
399 char o_hurldmg[8]; /* Damage if thrown */
400 int o_count; /* Count for plural objects */
401 int o_which; /* Which object of a type it is */
402 int o_hplus; /* Plusses to hit */
403 int o_dplus; /* Plusses to damage */
404 int o_ac; /* Armor class */
405 int o_flags; /* Information about objects */
406 int o_group; /* Group number for this object */
407 };
408
409 struct delayed_action {
410 int d_type;
411 int (*d_func)();
412 int d_arg;
413 int d_time;
414 };
415
416 /*
417 * Now all the global variables
418 */
419
420 extern struct room rooms[MAXROOMS]; /* One for each room -- A level */
421 extern struct room *oldrp; /* Roomin(&oldpos) */
422 extern struct linked_list *mlist; /* List of monsters on the level */
423 extern struct thing player; /* The rogue */
424 extern struct stats max_stats; /* The maximum for the player */
425 extern struct monster monsters[26]; /* The initial monster states */
426 extern struct linked_list *lvl_obj; /* List of objects on this level */
427 extern struct object *cur_weapon; /* Which weapon he is weilding */
428 extern struct object *cur_armor; /* What a well dresssed rogue wears */
429 extern struct object *cur_ring[2]; /* Which rings are being worn */
430 extern struct magic_item things[NUMTHINGS]; /* Chances for each type of item */
431 extern struct magic_item s_magic[MAXSCROLLS]; /* Names and chances for scrolls */
432 extern struct magic_item p_magic[MAXPOTIONS]; /* Names and chances for potions */
433 extern struct magic_item r_magic[MAXRINGS]; /* Names and chances for rings */
434 extern struct magic_item ws_magic[MAXSTICKS]; /* Names and chances for sticks */
435
436 extern int level; /* What level rogue is on */
437 extern int purse; /* How much gold the rogue has */
438 extern int mpos; /* Where cursor is on top line */
439 extern int ntraps; /* Number of traps on this level */
440 extern int no_move; /* Number of turns held in place */
441 extern int no_command; /* Number of turns asleep */
442 extern int inpack; /* Number of things in pack */
443 extern int max_hp; /* Player's max hit points */
444 extern int total; /* Total dynamic memory bytes */
445 extern int a_chances[MAXARMORS]; /* Probabilities for armor */
446 extern int a_class[MAXARMORS]; /* Armor class for various armors */
447 extern int lastscore; /* Score before this turn */
448 extern int no_food; /* Number of levels without food */
449 extern int seed; /* Random number seed */
450 extern int count; /* Number of times to repeat command */
451 extern int dnum; /* Cavern number */
452 extern int fung_hit; /* Number of time fungi has hit */
453 extern int quiet; /* Number of quiet turns */
454 extern int max_level; /* Deepest player has gone */
455 extern int food_left; /* Amount of food in hero's stomach */
456 extern int group; /* Current group number */
457 extern int hungry_state; /* How hungry is he */
458
459 extern char take; /* Thing the rogue is taking */
460 extern char prbuf[80]; /* Buffer for sprintfs */
461 extern char runch; /* Direction player is running */
462 extern char *s_names[MAXSCROLLS]; /* Names of the scrolls */
463 extern char *p_colors[MAXPOTIONS]; /* Colors of the potions */
464 extern char *r_stones[MAXRINGS]; /* Stone settings of the rings */
465 extern char *w_names[MAXWEAPONS]; /* Names of the various weapons */
466 extern char *a_names[MAXARMORS]; /* Names of armor types */
467 extern char *ws_made[MAXSTICKS]; /* What sticks are made of */
468 extern char *release; /* Release number of rogue */
469 extern char whoami[80]; /* Name of player */
470 extern char fruit[80]; /* Favorite fruit */
471 extern char huh[80]; /* The last message printed */
472 extern char *s_guess[MAXSCROLLS]; /* Players guess at what scroll is */
473 extern char *p_guess[MAXPOTIONS]; /* Players guess at what potion is */
474 extern char *r_guess[MAXRINGS]; /* Players guess at what ring is */
475 extern char *ws_guess[MAXSTICKS]; /* Players guess at what wand is */
476 extern char *ws_type[MAXSTICKS]; /* Is it a wand or a staff */
477 extern char file_name[80]; /* Save file name */
478 extern char home[80]; /* User's home directory */
479
480 extern WINDOW *cw; /* Window that the player sees */
481 extern WINDOW *hw; /* Used for the help command */
482 extern WINDOW *mw; /* Used to store mosnters */
483
484 extern bool running; /* True if player is running */
485 extern bool playing; /* True until he quits */
486 extern bool wizard; /* True if allows wizard commands */
487 extern bool after; /* True if we want after daemons */
488 extern bool notify; /* True if player wants to know */
489 extern bool fight_flush; /* True if toilet input */
490 extern bool terse; /* True if we should be short */
491 extern bool door_stop; /* Stop running when we pass a door */
492 extern bool jump; /* Show running as series of jumps */
493 extern bool slow_invent; /* Inventory one line at a time */
494 extern bool firstmove; /* First move after setting door_stop */
495 extern bool waswizard; /* Was a wizard sometime */
496 extern bool askme; /* Ask about unidentified things */
497 extern bool s_know[MAXSCROLLS]; /* Does he know what a scroll does */
498 extern bool p_know[MAXPOTIONS]; /* Does he know what a potion does */
499 extern bool r_know[MAXRINGS]; /* Does he know what a ring does */
500 extern bool ws_know[MAXSTICKS]; /* Does he know what a stick does */
501 extern bool amulet; /* He found the amulet */
502 extern bool in_shell; /* True if executing a shell */
503
504 extern coord oldpos; /* Position before last look() call */
505 extern coord delta; /* Change indicated to get_dir() */
506
507 extern coord ch_ret;
508 extern char countch,direction,newcount;
509 extern struct delayed_action d_list[20];
510 extern int between;
511 extern int num_checks;
512 extern char lvl_mons[27],wand_mons[27];
513 extern coord nh;
514
515 struct linked_list *find_mons(), *find_obj(), *get_item(), *new_item();
516 struct linked_list *new_thing(), *wake_monster();
517
518 char *tr_name(), *new();
519 char *charge_str(),*vowelstr(), *inv_name();
520 char *ctime(), *num(), *ring_num();
521
522 int readchar(WINDOW *win);
523 int md_readchar(WINDOW *win);
524 int wait_for(WINDOW *win, register char ch);
525 char *killname(register char monst);
526
527 struct room *roomin();
528
529 coord *rndmove();
530
531 void auto_save(int p), endit(int p), quit(int p), tstp(), checkout();
532 int nohaste(), doctor(), runners(), swander();
533 int unconfuse(), unsee(), rollwand(), stomach(), sight();
534
535 struct trap *trap_at();
536
537 extern char *rainbow[];
538 extern char *stones[];
539 extern char *wood[];
540 extern char *metal[];
541
542 extern const int cNCOLORS;
543 extern const int cNSTONES;
544 extern const int cNWOOD;
545 extern const int cNMETAL;