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