Rename the dungeons.
[rogue-pphs.git] / init.c
1 /*
2 * global variable initializaton
3 *
4 * @(#)init.c 3.33 (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 #include "curses.h"
14 #include <ctype.h>
15 #include <string.h>
16 #include "rogue.h"
17
18 bool playing = TRUE, running = FALSE, wizard = FALSE;
19 bool notify = TRUE, fight_flush = FALSE, terse = FALSE, door_stop = FALSE;
20 bool jump = FALSE, slow_invent = FALSE, firstmove = FALSE, askme = FALSE;
21 bool amulet = FALSE, in_shell = FALSE;
22 struct linked_list *lvl_obj = NULL, *mlist = NULL;
23 struct object *cur_weapon = NULL;
24 int mpos = 0, no_move = 0, no_command = 0, level = 1, purse = 0, inpack = 0;
25 int total = 0, no_food = 0, count = 0, fung_hit = 0, quiet = 0;
26 int food_left = HUNGERTIME, group = 1, hungry_state = 0;
27 int lastscore = -1;
28
29 struct thing player;
30 struct room rooms[MAXROOMS];
31 struct room *oldrp;
32 struct stats max_stats;
33 struct object *cur_armor;
34 struct object *cur_ring[2];
35 bool after;
36 bool waswizard;
37 coord oldpos; /* Position before last look() call */
38 coord delta; /* Change indicated to get_dir() */
39
40 bool s_know[MAXSCROLLS]; /* Does he know what a scroll does */
41 bool p_know[MAXPOTIONS]; /* Does he know what a potion does */
42 bool r_know[MAXRINGS]; /* Does he know what a ring does
43 */
44 bool ws_know[MAXSTICKS]; /* Does he know what a stick does */
45
46 char take; /* Thing the rogue is taking */
47 char runch; /* Direction player is running */
48 char whoami[80]; /* Name of player */
49 char fruit[80]; /* Favorite fruit */
50 char huh[80]; /* The last message printed */
51 int dnum; /* Cavern number */
52 char *s_names[MAXSCROLLS]; /* Names of the scrolls */
53 char *p_colors[MAXPOTIONS]; /* Colors of the potions */
54 char *r_stones[MAXRINGS]; /* Stone settings of the rings */
55 char *a_names[MAXARMORS]; /* Names of armor types */
56 char *ws_made[MAXSTICKS]; /* What sticks are made of */
57 char *s_guess[MAXSCROLLS]; /* Players guess at what scroll is */
58 char *p_guess[MAXPOTIONS]; /* Players guess at what potion is */
59 char *r_guess[MAXRINGS]; /* Players guess at what ring is */
60 char *ws_guess[MAXSTICKS]; /* Players guess at what wand is */
61 char *ws_type[MAXSTICKS]; /* Is it a wand or a staff */
62 char file_name[80]; /* Save file name */
63 char home[80]; /* User's home directory */
64 char prbuf[80]; /* Buffer for sprintfs */
65 int max_hp; /* Player's max hit points */
66 int ntraps; /* Number of traps on this level */
67 int max_level; /* Deepest player has gone */
68 int seed; /* Random number seed */
69
70 struct trap traps[MAXTRAPS];
71
72
73 #define ___ 1
74 #define _x {1,1}
75 struct monster monsters[26] = {
76 /* Name CARRY FLAG str, exp, lvl, amr, hpt, dmg */
77 { "giant ant", 0, ISMEAN, { _x, 10, 2, 3, ___, "1d6" } },
78 { "bat", 0, 0, { _x, 1, 1, 3, ___, "1d2" } },
79 { "centaur", 15, 0, { _x, 15, 4, 4, ___, "1d6/1d6" } },
80 { "dragon", 100, ISGREED,{ _x,9000, 10, -1, ___, "1d8/1d8/3d10" } },
81 { "floating eye",0, 0, { _x, 5, 1, 9, ___, "0d0" } },
82 { "violet fungi",0, ISMEAN, { _x, 85, 8, 3, ___, "000d0" } },
83 { "gnome", 10, 0, { _x, 8, 1, 5, ___, "1d6" } },
84 { "hobgoblin", 0, ISMEAN, { _x, 3, 1, 5, ___, "1d8" } },
85 { "invisible stalker",0,ISINVIS,{ _x,120, 8, 3, ___, "4d4" } },
86 { "jackal", 0, ISMEAN, { _x, 2, 1, 7, ___, "1d2" } },
87 { "kobold", 0, ISMEAN, { _x, 1, 1, 7, ___, "1d4" } },
88 { "leprechaun", 0, 0, { _x, 10, 3, 8, ___, "1d1" } },
89 { "mimic", 30, 0, { _x,140, 7, 7, ___, "3d4" } },
90 { "nymph", 100, 0, { _x, 40, 3, 9, ___, "0d0" } },
91 { "orc", 15, ISBLOCK,{ _x, 5, 1, 6, ___, "1d8" } },
92 { "purple worm", 70, 0, { _x,7000, 15, 6, ___, "2d12/2d4" } },
93 { "quasit", 30, ISMEAN, { _x, 35, 3, 2, ___, "1d2/1d2/1d4" } },
94 { "rust monster",0, ISMEAN, { _x, 25, 5, 2, ___, "0d0/0d0" } },
95 { "snake", 0, ISMEAN, { _x, 3, 1, 5, ___, "1d3" } },
96 { "troll", 50, ISREGEN|ISMEAN,{ _x, 55, 6, 4, ___, "1d8/1d8/2d6" } },
97 { "umber hulk", 40, ISMEAN, { _x,130, 8, 2, ___, "3d4/3d4/2d5" } },
98 { "vampire", 20, ISREGEN|ISMEAN,{ _x,380, 8, 1, ___, "1d10" } },
99 { "wraith", 0, 0, { _x, 55, 5, 4, ___, "1d6" } },
100 { "xorn", 0, ISMEAN, { _x,120, 7, -2, ___, "1d3/1d3/1d3/4d6" } },
101 { "yeti", 30, 0, { _x, 50, 4, 6, ___, "1d6/1d6" } },
102 { "zombie", 0, ISMEAN, { _x, 7, 2, 8, ___, "1d8" } }
103 };
104 #undef ___
105
106 /*
107 * init_player:
108 * roll up the rogue
109 */
110
111 init_player()
112 {
113 pstats.s_lvl = 1;
114 pstats.s_exp = 0L;
115 pstats.s_ont = rnd(1 << NUM_FEATURES);
116 max_hp = pstats.s_hpt = 12;
117 if (rnd(100) == 7)
118 {
119 pstats.s_str.st_str = 18;
120 pstats.s_str.st_add = rnd(100) + 1;
121 }
122 else
123 {
124 pstats.s_str.st_str = 16;
125 pstats.s_str.st_add = 0;
126 }
127 strcpy(pstats.s_dmg,"1d4");
128 pstats.s_arm = 10;
129 max_stats = pstats;
130 pack = NULL;
131 }
132
133 /*
134 * Contains defintions and functions for dealing with things like
135 * potions and scrolls
136 */
137
138 char *rainbow[] = {
139 "red",
140 "blue",
141 "green",
142 "yellow",
143 "black",
144 "brown",
145 "orange",
146 "pink",
147 "purple",
148 "grey",
149 "white",
150 "silver",
151 "gold",
152 "violet",
153 "clear",
154 "vermilion",
155 "ecru",
156 "turquoise",
157 "magenta",
158 "amber",
159 "topaz",
160 "plaid",
161 "tan",
162 "tangerine"
163 };
164
165 #define NCOLORS (sizeof rainbow / sizeof (char *))
166 const int cNCOLORS = NCOLORS;
167
168 char *sylls[] = {
169 "a", "ab", "ag", "aks", "ala", "an", "ankh", "app", "arg", "arze",
170 "ash", "ban", "bar", "bat", "bek", "bie", "bin", "bit", "bjor",
171 "blu", "bot", "bu", "byt", "comp", "con", "cos", "cre", "dalf",
172 "dan", "den", "do", "e", "eep", "el", "eng", "er", "ere", "erk",
173 "esh", "evs", "fa", "fid", "for", "fri", "fu", "gan", "gar",
174 "glen", "gop", "gre", "ha", "he", "hyd", "i", "ing", "ion", "ip",
175 "ish", "it", "ite", "iv", "jo", "kho", "kli", "klis", "la", "lech",
176 "man", "mar", "me", "mi", "mic", "mik", "mon", "mung", "mur",
177 "nej", "nelg", "nep", "ner", "nes", "nes", "nih", "nin", "o", "od",
178 "ood", "org", "orn", "ox", "oxy", "pay", "pet", "ple", "plu", "po",
179 "pot", "prok", "re", "rea", "rhov", "ri", "ro", "rog", "rok", "rol",
180 "sa", "san", "sat", "see", "sef", "seh", "shu", "ski", "sna",
181 "sne", "snik", "sno", "so", "sol", "sri", "sta", "sun", "ta",
182 "tab", "tem", "ther", "ti", "tox", "trol", "tue", "turs", "u",
183 "ulk", "um", "un", "uni", "ur", "val", "viv", "vly", "vom", "wah",
184 "wed", "werg", "wex", "whon", "wun", "xo", "y", "yot", "yu",
185 "zant", "zap", "zeb", "zim", "zok", "zon", "zum",
186 };
187
188 char *stones[] = {
189 "agate",
190 "alexandrite",
191 "amethyst",
192 "carnelian",
193 "diamond",
194 "emerald",
195 "granite",
196 "jade",
197 "kryptonite",
198 "lapus lazuli",
199 "moonstone",
200 "obsidian",
201 "onyx",
202 "opal",
203 "pearl",
204 "ruby",
205 "saphire",
206 "tiger eye",
207 "topaz",
208 "turquoise",
209 };
210
211 #define NSTONES (sizeof stones / sizeof (char *))
212 const int cNSTONES = NSTONES;
213
214 char *wood[] = {
215 "avocado wood",
216 "balsa",
217 "banyan",
218 "birch",
219 "cedar",
220 "cherry",
221 "cinnibar",
222 "driftwood",
223 "ebony",
224 "eucalyptus",
225 "hemlock",
226 "ironwood",
227 "mahogany",
228 "manzanita",
229 "maple",
230 "oak",
231 "persimmon wood",
232 "redwood",
233 "rosewood",
234 "teak",
235 "walnut",
236 "zebra wood",
237 };
238
239 #define NWOOD (sizeof wood / sizeof (char *))
240 const int cNWOOD = NWOOD;
241
242 char *metal[] = {
243 "aluminium",
244 "bone",
245 "brass",
246 "bronze",
247 "copper",
248 "iron",
249 "lead",
250 "pewter",
251 "steel",
252 "tin",
253 "zinc",
254 };
255
256 #define NMETAL (sizeof metal / sizeof (char *))
257 const int cNMETAL = NMETAL;
258
259 struct magic_item things[NUMTHINGS] = {
260 { "", 27 }, /* potion */
261 { "", 27 }, /* scroll */
262 { "", 18 }, /* food */
263 { "", 9 }, /* weapon */
264 { "", 9 }, /* armor */
265 { "", 5 }, /* ring */
266 { "", 5 }, /* stick */
267 };
268
269 struct magic_item s_magic[MAXSCROLLS] = {
270 { "monster confusion", 8, 170 },
271 { "magic mapping", 5, 180 },
272 { "light", 10, 100 },
273 { "hold monster", 2, 200 },
274 { "sleep", 5, 50 },
275 { "enchant armor", 8, 130 },
276 { "identify", 21, 100 },
277 { "scare monster", 4, 180 },
278 { "gold detection", 4, 110 },
279 { "teleportation", 7, 175 },
280 { "enchant weapon", 10, 150 },
281 { "create monster", 5, 75 },
282 { "remove curse", 8, 105 },
283 { "aggravate monsters", 1, 60 },
284 { "blank paper", 1, 50 },
285 { "genocide", 1, 200 },
286 };
287
288 struct magic_item p_magic[MAXPOTIONS] = {
289 { "confusion", 8, 50 },
290 { "paralysis", 10, 50 },
291 { "poison", 8, 50 },
292 { "gain strength", 15, 150 },
293 { "see invisible", 2, 170 },
294 { "healing", 15, 130 },
295 { "monster detection", 6, 120 },
296 { "magic detection", 6, 105 },
297 { "raise level", 2, 220 },
298 { "extra healing", 5, 180 },
299 { "haste self", 4, 200 },
300 { "restore strength", 14, 120 },
301 { "blindness", 4, 50 },
302 { "thirst quenching", 1, 50 },
303 };
304
305 struct magic_item r_magic[MAXRINGS] = {
306 { "protection", 9, 200 },
307 { "add strength", 9, 200 },
308 { "sustain strength", 5, 180 },
309 { "searching", 10, 200 },
310 { "see invisible", 10, 175 },
311 { "adornment", 1, 100 },
312 { "aggravate monster", 11, 100 },
313 { "dexterity", 8, 220 },
314 { "increase damage", 8, 220 },
315 { "regeneration", 4, 260 },
316 { "slow digestion", 9, 240 },
317 { "teleportation", 9, 100 },
318 { "stealth", 7, 100 },
319 };
320
321 struct magic_item ws_magic[MAXSTICKS] = {
322 { "light", 12, 120 },
323 { "striking", 9, 115 },
324 { "lightning", 3, 200 },
325 { "fire", 3, 200 },
326 { "cold", 3, 200 },
327 { "polymorph", 15, 210 },
328 { "magic missile", 10, 170 },
329 { "haste monster", 9, 50 },
330 { "slow monster", 11, 220 },
331 { "drain life", 9, 210 },
332 { "nothing", 1, 70 },
333 { "teleport away", 5, 140 },
334 { "teleport to", 5, 60 },
335 { "cancellation", 5, 130 },
336 };
337
338 int a_class[MAXARMORS] = {
339 8,
340 7,
341 7,
342 6,
343 5,
344 4,
345 4,
346 3,
347 };
348
349 char *a_names[MAXARMORS] = {
350 "leather armor",
351 "ring mail",
352 "studded leather armor",
353 "scale mail",
354 "chain mail",
355 "splint mail",
356 "banded mail",
357 "plate mail",
358 };
359
360 int a_chances[MAXARMORS] = {
361 20,
362 35,
363 50,
364 63,
365 75,
366 85,
367 95,
368 100
369 };
370
371 #define MAX3(a,b,c) (a > b ? (a > c ? a : c) : (b > c ? b : c))
372 static bool used[MAX3(NCOLORS, NSTONES, NWOOD)];
373
374 /*
375 * init_things
376 * Initialize the probabilities for types of things
377 */
378 init_things()
379 {
380 register struct magic_item *mp;
381
382 for (mp = &things[1]; mp <= &things[NUMTHINGS-1]; mp++)
383 mp->mi_prob += (mp-1)->mi_prob;
384 badcheck("things", things, NUMTHINGS);
385 }
386
387 /*
388 * init_colors:
389 * Initialize the potion color scheme for this time
390 */
391
392 init_colors()
393 {
394 register int i, j;
395
396 for (i = 0; i < NCOLORS; i++)
397 used[i] = 0;
398 for (i = 0; i < MAXPOTIONS; i++)
399 {
400 do
401 j = rnd(NCOLORS);
402 until (!used[j]);
403 used[j] = TRUE;
404 p_colors[i] = rainbow[j];
405 p_know[i] = FALSE;
406 p_guess[i] = NULL;
407 if (i > 0)
408 p_magic[i].mi_prob += p_magic[i-1].mi_prob;
409 }
410 badcheck("potions", p_magic, MAXPOTIONS);
411 }
412
413 /*
414 * init_names:
415 * Generate the names of the various scrolls
416 */
417
418 init_names()
419 {
420 register int nsyl;
421 register char *cp, *sp;
422 register int i, nwords;
423
424 for (i = 0; i < MAXSCROLLS; i++)
425 {
426 cp = prbuf;
427 nwords = rnd(4)+2;
428 while(nwords--)
429 {
430 nsyl = rnd(3)+1;
431 while(nsyl--)
432 {
433 sp = sylls[rnd((sizeof sylls) / (sizeof (char *)))];
434 while(*sp)
435 *cp++ = *sp++;
436 }
437 *cp++ = ' ';
438 }
439 *--cp = '\0';
440 s_names[i] = (char *) new(strlen(prbuf)+1);
441 s_know[i] = FALSE;
442 s_guess[i] = NULL;
443 strcpy(s_names[i], prbuf);
444 if (i > 0)
445 s_magic[i].mi_prob += s_magic[i-1].mi_prob;
446 }
447 badcheck("scrolls", s_magic, MAXSCROLLS);
448 }
449
450 /*
451 * init_stones:
452 * Initialize the ring stone setting scheme for this time
453 */
454
455 init_stones()
456 {
457 register int i, j;
458
459 for (i = 0; i < NSTONES; i++)
460 used[i] = FALSE;
461 for (i = 0; i < MAXRINGS; i++)
462 {
463 do
464 j = rnd(NSTONES);
465 until (!used[j]);
466 used[j] = TRUE;
467 r_stones[i] = stones[j];
468 r_know[i] = FALSE;
469 r_guess[i] = NULL;
470 if (i > 0)
471 r_magic[i].mi_prob += r_magic[i-1].mi_prob;
472 }
473 badcheck("rings", r_magic, MAXRINGS);
474 }
475
476 /*
477 * init_materials:
478 * Initialize the construction materials for wands and staffs
479 */
480
481 init_materials()
482 {
483 register int i, j;
484 static bool metused[NMETAL];
485
486 for (i = 0; i < NWOOD; i++)
487 used[i] = FALSE;
488 for (i = 0; i < NMETAL; i++)
489 metused[i] = FALSE;
490
491 for (i = 0; i < MAXSTICKS; i++)
492 {
493 for (;;)
494 if (rnd(100) > 50)
495 {
496 j = rnd(NMETAL);
497 if (!metused[j])
498 {
499 metused[j] = TRUE;
500 ws_made[i] = metal[j];
501 ws_type[i] = "wand";
502 break;
503 }
504 }
505 else
506 {
507 j = rnd(NWOOD);
508 if (!used[j])
509 {
510 used[j] = TRUE;
511 ws_made[i] = wood[j];
512 ws_type[i] = "staff";
513 break;
514 }
515 }
516
517 ws_know[i] = FALSE;
518 ws_guess[i] = NULL;
519 if (i > 0)
520 ws_magic[i].mi_prob += ws_magic[i-1].mi_prob;
521 }
522 badcheck("sticks", ws_magic, MAXSTICKS);
523 }
524
525 badcheck(name, magic, bound)
526 char *name;
527 register struct magic_item *magic;
528 register int bound;
529 {
530 register struct magic_item *end;
531
532 if (magic[bound - 1].mi_prob == 100)
533 return;
534 printf("\nBad percentages for %s:\n", name);
535 for (end = &magic[bound]; magic < end; magic++)
536 printf("%3d%% %s\n", magic->mi_prob, magic->mi_name);
537 printf("[hit RETURN to continue]");
538 fflush(stdout);
539 while (getchar() != '\n')
540 continue;
541 }
542
543 struct h_list helpstr[] = {
544 '?', " prints help",
545 '/', " identify object",
546 'h', " left",
547 'j', " down",
548 'k', " up",
549 'l', " right",
550 'y', " up & left",
551 'u', " up & right",
552 'b', " down & left",
553 'n', " down & right",
554 'H', " run left",
555 'J', " run down",
556 'K', " run up",
557 'L', " run right",
558 'Y', " run up & left",
559 'U', " run up & right",
560 'B', " run down & left",
561 'N', " run down & right",
562 't', "<dir> throw something",
563 'p', "<dir> zap a wand in a direction",
564 'z', " zap a wand or staff",
565 '>', " go down a staircase",
566 's', " search for trap/secret door",
567 ' ', " (space) rest for a while",
568 'i', " inventory",
569 'I', " inventory single item",
570 'q', " quaff potion",
571 'r', " read paper",
572 'e', " eat food",
573 'w', " wield a weapon",
574 'W', " wear armor",
575 'T', " take armor off",
576 'P', " put on ring",
577 'R', " remove ring",
578 'd', " drop object",
579 'c', " call object",
580 'f', "<dir> flirt with someone",
581 'g', "<dir> give an item as a gift",
582 'E', " embrace",
583 'o', " examine/set options",
584 CTRL('L'), " redraw screen",
585 CTRL('R'), " repeat last message",
586 ESCAPE, " cancel command",
587 'v', " print program version number",
588 'S', " save game",
589 'Q', " quit",
590 0, 0
591 };