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