comparison rogue3/init.c @ 0:527e2150eaf0

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