Annotation of early-roguelike/rogue4/init.c, Revision 1.1.1.1
1.1 rubenllo 1: /*
2: * global variable initializaton
3: *
4: * @(#)init.c 4.16 (Berkeley) 3/30/82
5: *
6: * Rogue: Exploring the Dungeons of Doom
7: * Copyright (C) 1980, 1981, 1982 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 <stdlib.h>
16: #include <string.h>
17: #include "rogue.h"
18:
19: #ifdef WIZARD
20: void badcheck(char *name, struct magic_item *magic, int bound);
21: #endif
22:
23: /*
24: * init_player:
25: * Roll up the rogue
26: */
27: void
28: init_player(void)
29: {
30: register THING *obj;
31:
32: pstats = max_stats;
33: food_left = HUNGERTIME;
34: /*
35: * Give the rogue his weaponry. First a mace.
36: */
37: obj = new_item();
38: obj->o_type = WEAPON;
39: obj->o_which = MACE;
40: init_weapon(obj, MACE);
41: obj->o_hplus = 1;
42: obj->o_dplus = 1;
43: obj->o_flags |= ISKNOW;
44: obj->o_count = 1;
45: obj->o_group = 0;
46: add_pack(obj, TRUE);
47: cur_weapon = obj;
48: /*
49: * Now a +1 bow
50: */
51: obj = new_item();
52: obj->o_type = WEAPON;
53: obj->o_which = BOW;
54: init_weapon(obj, BOW);
55: obj->o_hplus = 1;
56: obj->o_dplus = 0;
57: obj->o_count = 1;
58: obj->o_group = 0;
59: obj->o_flags |= ISKNOW;
60: add_pack(obj, TRUE);
61: /*
62: * Now some arrows
63: */
64: obj = new_item();
65: obj->o_type = WEAPON;
66: obj->o_which = ARROW;
67: init_weapon(obj, ARROW);
68: obj->o_count = rnd(15) + 25;
69: obj->o_hplus = obj->o_dplus = 0;
70: obj->o_flags |= ISKNOW;
71: add_pack(obj, TRUE);
72: /*
73: * And his suit of armor
74: */
75: obj = new_item();
76: obj->o_type = ARMOR;
77: obj->o_which = RING_MAIL;
78: obj->o_ac = a_class[RING_MAIL] - 1;
79: obj->o_flags |= ISKNOW;
80: obj->o_count = 1;
81: obj->o_group = 0;
82: cur_armor = obj;
83: add_pack(obj, TRUE);
84: /*
85: * Give him some food too
86: */
87: obj = new_item();
88: obj->o_type = FOOD;
89: obj->o_count = 1;
90: obj->o_which = 0;
91: obj->o_group = 0;
92: add_pack(obj, TRUE);
93: }
94:
95: /*
96: * Contains defintions and functions for dealing with things like
97: * potions and scrolls
98: */
99:
100: const char *rainbow[NCOLORS] = {
101: "amber",
102: "aquamarine",
103: "black",
104: "blue",
105: "brown",
106: "clear",
107: "crimson",
108: "cyan",
109: "ecru",
110: "gold",
111: "green",
112: "grey",
113: "magenta",
114: "orange",
115: "pink",
116: "plaid",
117: "purple",
118: "red",
119: "silver",
120: "tan",
121: "tangerine",
122: "topaz",
123: "turquoise",
124: "vermilion",
125: "violet",
126: "white",
127: "yellow",
128: };
129:
130: const char *sylls[NSYLLS] = {
131: "a", "ab", "ag", "aks", "ala", "an", "ankh","app", "arg", "arze",
132: "ash", "ban", "bar", "bat", "bek", "bie", "bin", "bit", "bjor",
133: "blu", "bot", "bu", "byt", "comp","con", "cos", "cre", "dalf",
134: "dan", "den", "do", "e", "eep", "el", "eng", "er", "ere", "erk",
135: "esh", "evs", "fa", "fid", "for", "fri", "fu", "gan", "gar",
136: "glen","gop", "gre", "ha", "he", "hyd", "i", "ing", "ion", "ip",
137: "ish", "it", "ite", "iv", "jo", "kho", "kli", "klis","la", "lech",
138: "man", "mar", "me", "mi", "mic", "mik", "mon", "mung","mur",
139: "nej", "nelg","nep", "ner", "nes", "nes", "nih", "nin", "o", "od",
140: "ood", "org", "orn", "ox", "oxy", "pay", "pet", "ple", "plu", "po",
141: "pot", "prok","re", "rea", "rhov","ri", "ro", "rog", "rok", "rol",
142: "sa", "san", "sat", "see", "sef", "seh", "shu", "ski", "sna",
143: "sne", "snik","sno", "so", "sol", "sri", "sta", "sun", "ta",
144: "tab", "tem", "ther","ti", "tox", "trol","tue", "turs","u",
145: "ulk", "um", "un", "uni", "ur", "val", "viv", "vly", "vom", "wah",
146: "wed", "werg","wex", "whon","wun", "xo", "y", "yot", "yu",
147: "zant","zap", "zeb", "zim", "zok", "zon", "zum",
148: };
149:
150: const STONE stones[NSTONES] = {
151: { "agate", 25},
152: { "alexandrite", 40},
153: { "amethyst", 50},
154: { "carnelian", 40},
155: { "diamond", 300},
156: { "emerald", 300},
157: { "germanium", 225},
158: { "granite", 5},
159: { "garnet", 50},
160: { "jade", 150},
161: { "kryptonite", 300},
162: { "lapis lazuli", 50},
163: { "moonstone", 50},
164: { "obsidian", 15},
165: { "onyx", 60},
166: { "opal", 200},
167: { "pearl", 220},
168: { "peridot", 63},
169: { "ruby", 350},
170: { "saphire", 285},
171: { "stibotantalite", 200},
172: { "tiger eye", 50},
173: { "topaz", 60},
174: { "turquoise", 70},
175: { "taaffeite", 300},
176: { "zircon", 80},
177: };
178:
179: const char *wood[NWOOD] = {
180: "avocado wood",
181: "balsa",
182: "bamboo",
183: "banyan",
184: "birch",
185: "cedar",
186: "cherry",
187: "cinnibar",
188: "cypress",
189: "dogwood",
190: "driftwood",
191: "ebony",
192: "elm",
193: "eucalyptus",
194: "fall",
195: "hemlock",
196: "holly",
197: "ironwood",
198: "kukui wood",
199: "mahogany",
200: "manzanita",
201: "maple",
202: "oaken",
203: "persimmon wood",
204: "pecan",
205: "pine",
206: "poplar",
207: "redwood",
208: "rosewood",
209: "spruce",
210: "teak",
211: "walnut",
212: "zebrawood",
213: };
214:
215: const char *metal[NMETAL] = {
216: "aluminum",
217: "beryllium",
218: "bone",
219: "brass",
220: "bronze",
221: "copper",
222: "electrum",
223: "gold",
224: "iron",
225: "lead",
226: "magnesium",
227: "mercury",
228: "nickel",
229: "pewter",
230: "platinum",
231: "steel",
232: "silver",
233: "silicon",
234: "tin",
235: "titanium",
236: "tungsten",
237: "zinc",
238: };
239:
240: /*
241: * init_things
242: * Initialize the probabilities for types of things
243: */
244: void
245: init_things(void)
246: {
247: register struct magic_item *mp;
248:
249: for (mp = &things[1]; mp <= &things[NUMTHINGS-1]; mp++)
250: mp->mi_prob += (mp-1)->mi_prob;
251: #ifdef WIZARD
252: badcheck("things", things, NUMTHINGS);
253: #endif
254: }
255:
256: /*
257: * init_colors:
258: * Initialize the potion color scheme for this time
259: */
260: void
261: init_colors(void)
262: {
263: register int i, j;
264: bool used[NCOLORS];
265:
266: for (i = 0; i < NCOLORS; i++)
267: used[i] = FALSE;
268: for (i = 0; i < MAXPOTIONS; i++)
269: {
270: do
271: j = rnd(NCOLORS);
272: until (!used[j]);
273: used[j] = TRUE;
274: p_colors[i] = rainbow[j];
275: p_know[i] = FALSE;
276: p_guess[i] = NULL;
277: if (i > 0)
278: p_magic[i].mi_prob += p_magic[i-1].mi_prob;
279: }
280: #ifdef WIZARD
281: badcheck("potions", p_magic, MAXPOTIONS);
282: #endif
283: }
284:
285: /*
286: * init_names:
287: * Generate the names of the various scrolls
288: */
289: #define MAXNAME 40 /* Max number of characters in a name */
290:
291: void
292: init_names(void)
293: {
294: register int nsyl;
295: register char *cp;
296: const char *sp;
297: register int i, nwords;
298:
299: for (i = 0; i < MAXSCROLLS; i++)
300: {
301: cp = prbuf;
302: nwords = rnd(4) + 2;
303: while (nwords--)
304: {
305: nsyl = rnd(3) + 1;
306: while (nsyl--)
307: {
308: sp = sylls[rnd((sizeof sylls) / (sizeof (char *)))];
309: if (&cp[strlen(sp)] > &prbuf[MAXNAME])
310: break;
311: while (*sp)
312: *cp++ = *sp++;
313: }
314: *cp++ = ' ';
315: }
316: *--cp = '\0';
317: s_names[i] = (char *) malloc((unsigned) strlen(prbuf)+1);
318: s_know[i] = FALSE;
319: s_guess[i] = NULL;
320: strcpy(s_names[i], prbuf);
321: if (i > 0)
322: s_magic[i].mi_prob += s_magic[i-1].mi_prob;
323: }
324: #ifdef WIZARD
325: badcheck("scrolls", s_magic, MAXSCROLLS);
326: #endif
327: }
328:
329: /*
330: * init_stones:
331: * Initialize the ring stone setting scheme for this time
332: */
333: void
334: init_stones(void)
335: {
336: register int i, j;
337: bool used[NSTONES];
338:
339: for (i = 0; i < NSTONES; i++)
340: used[i] = FALSE;
341: for (i = 0; i < MAXRINGS; i++)
342: {
343: do
344: j = rnd(NSTONES);
345: until (!used[j]);
346: used[j] = TRUE;
347: r_stones[i] = stones[j].st_name;
348: r_know[i] = FALSE;
349: r_guess[i] = NULL;
350: if (i > 0)
351: r_magic[i].mi_prob += r_magic[i-1].mi_prob;
352: r_magic[i].mi_worth += stones[j].st_value;
353: }
354: #ifdef WIZARD
355: badcheck("rings", r_magic, MAXRINGS);
356: #endif
357: }
358:
359: /*
360: * init_materials:
361: * Initialize the construction materials for wands and staffs
362: */
363: void
364: init_materials(void)
365: {
366: register int i, j;
367: register const char *str;
368: bool metused[NMETAL], woodused[NWOOD];
369:
370: for (i = 0; i < NWOOD; i++)
371: woodused[i] = FALSE;
372: for (i = 0; i < NMETAL; i++)
373: metused[i] = FALSE;
374: for (i = 0; i < MAXSTICKS; i++)
375: {
376: for (;;)
377: if (rnd(2) == 0)
378: {
379: j = rnd(NMETAL);
380: if (!metused[j])
381: {
382: ws_type[i] = "wand";
383: str = metal[j];
384: metused[j] = TRUE;
385: break;
386: }
387: }
388: else
389: {
390: j = rnd(NWOOD);
391: if (!woodused[j])
392: {
393: ws_type[i] = "staff";
394: str = wood[j];
395: woodused[j] = TRUE;
396: break;
397: }
398: }
399: ws_made[i] = str;
400: ws_know[i] = FALSE;
401: ws_guess[i] = NULL;
402: if (i > 0)
403: ws_magic[i].mi_prob += ws_magic[i-1].mi_prob;
404: }
405: #ifdef WIZARD
406: badcheck("sticks", ws_magic, MAXSTICKS);
407: #endif
408: }
409:
410: #ifdef WIZARD
411: /*
412: * badcheck:
413: * Check to see if a series of probabilities sums to 100
414: */
415: void
416: badcheck(char *name, struct magic_item *magic, int bound)
417: {
418: register struct magic_item *end;
419:
420: if (magic[bound - 1].mi_prob == 100)
421: return;
422: printf("\nBad percentages for %s:\n", name);
423: for (end = &magic[bound]; magic < end; magic++)
424: printf("%3d%% %s\n", magic->mi_prob, magic->mi_name);
425: printf("[hit RETURN to continue]");
426: fflush(stdout);
427: while (getchar() != '\n')
428: continue;
429: }
430: #endif
CVSweb