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