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