Annotation of early-roguelike/srogue/init.c, Revision 1.1.1.1
1.1 rubenllo 1: /*
2: * initializate various things
3: *
4: * @(#)init.c 9.0 (rdk) 7/17/84
5: *
6: * Super-Rogue
7: * Copyright (C) 1984 Robert D. Kindelberger
8: * All rights reserved.
9: *
10: * Based on "Rogue: Exploring the Dungeons of Doom"
11: * Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman
12: * All rights reserved.
13: *
14: * See the file LICENSE.TXT for full copyright and licensing information.
15: */
16:
17: #include <ctype.h>
18: #include <string.h>
19: #include "rogue.h"
20: #include "rogue.ext"
21:
22: int pinit(void);
23: void badcheck(char *name, struct magic_item *magic);
24:
25: char *rainbow[NCOLORS] = {
26: "Red", "Blue", "Green", "Yellow",
27: "Black", "Brown", "Orange", "Pink",
28: "Purple", "Grey", "White", "Silver",
29: "Gold", "Violet", "Clear", "Vermilion",
30: "Ecru", "Turquoise","Magenta", "Amber",
31: "Topaz", "Plaid", "Tan", "Tangerine",
32: "Aquamarine", "Scarlet","Khaki", "Crimson",
33: "Indigo", "Beige", "Lavender", "Saffron",
34: };
35:
36: char *sylls[NSYLS] = {
37: "a", "ab", "ag", "aks", "ala", "an", "ankh", "app", "arg", "arze",
38: "ash", "ban", "bar", "bat", "bek", "bie", "bin", "bit", "bjor",
39: "blu", "bot", "bu", "byt", "comp", "con", "cos", "cre", "dalf",
40: "dan", "den", "do", "e", "eep", "el", "eng", "er", "ere", "erk",
41: "esh", "evs", "fa", "fid", "for", "fri", "fu", "gan", "gar",
42: "glen", "gop", "gre", "ha", "he", "hyd", "i", "ing", "ion", "ip",
43: "ish", "it", "ite", "iv", "jo", "kho", "kli", "klis", "la", "lech",
44: "man", "mar", "me", "mi", "mic", "mik", "mon", "mung", "mur",
45: "nej", "nelg", "nep", "ner", "nes", "nes", "nih", "nin", "o", "od",
46: "ood", "org", "orn", "ox", "oxy", "pay", "pet", "ple", "plu", "po",
47: "pot","prok","re", "rea", "rhov", "ri", "ro", "rog", "rok", "rol",
48: "sa", "san", "sat", "see", "sef", "seh", "shu", "ski", "sna",
49: "sne", "snik", "sno", "so", "sol", "sri", "sta", "sun", "ta",
50: "tab", "tem", "ther", "ti", "tox", "trol", "tue", "turs", "u",
51: "ulk", "um", "un", "uni", "ur", "val", "viv", "vly", "vom", "wah",
52: "wed", "werg", "wex", "whon", "wun", "xo", "y", "yot", "yu",
53: "zant", "zap", "zeb", "zim", "zok", "zon", "zum",
54: };
55:
56: char *stones[] = {
57: "Agate", "Alexandrite", "Amethyst",
58: "Azurite", "Carnelian", "Chrysoberyl",
59: "Chrysoprase", "Citrine", "Diamond",
60: "Emerald", "Garnet", "Hematite",
61: "Jacinth", "Jade", "Kryptonite",
62: "Lapus lazuli", "Malachite", "Moonstone",
63: "Obsidian", "Olivine", "Onyx",
64: "Opal", "Pearl", "Peridot",
65: "Quartz", "Rhodochrosite","Ruby",
66: "Sapphire", "Sardonyx", "Serpintine",
67: "Spinel", "Tiger eye", "Topaz",
68: "Tourmaline", "Turquoise",
69: };
70:
71: char *wood[NWOOD] = {
72: "Avocado wood", "Balsa", "Banyan", "Birch",
73: "Cedar", "Cherry", "Cinnibar", "Dogwood",
74: "Driftwood", "Ebony", "Eucalyptus", "Hemlock",
75: "Ironwood", "Mahogany", "Manzanita", "Maple",
76: "Oak", "Pine", "Redwood", "Rosewood",
77: "Teak", "Walnut", "Zebra wood", "Persimmon wood",
78: };
79:
80: char *metal[NMETAL] = {
81: "Aluminium", "Bone", "Brass", "Bronze",
82: "Copper", "Chromium", "Iron", "Lead",
83: "Magnesium", "Pewter", "Platinum", "Steel",
84: "Tin", "Titanium", "Zinc",
85: };
86:
87: /*
88: * init_things:
89: * Initialize the probabilities for types of things
90: */
91: void
92: init_things(void)
93: {
94: struct magic_item *mi;
95:
96: /*
97: * init general things
98: */
99: for (mi = &things[1]; mi < &things[NUMTHINGS]; mi++)
100: mi->mi_prob += (mi-1)->mi_prob;
101: badcheck("things", things);
102: /*
103: * init armor things
104: */
105: for (mi = &a_magic[1]; mi < &a_magic[MAXARMORS]; mi++)
106: mi->mi_prob += (mi-1)->mi_prob;
107: badcheck("armor", a_magic);
108: /*
109: * init weapon stuff
110: */
111: for (mi = &w_magic[1]; mi < &w_magic[MAXWEAPONS]; mi++)
112: mi->mi_prob += (mi-1)->mi_prob;
113: badcheck("weapon", w_magic);
114: }
115:
116:
117: /*
118: * init_colors:
119: * Initialize the potion color scheme for this time
120: */
121: void
122: init_colors(void)
123: {
124: reg int i, j;
125: reg char *str;
126: bool used[NCOLORS];
127:
128: for (i = 0; i < NCOLORS; i++)
129: used[i] = FALSE;
130: for (i = 0; i < MAXPOTIONS; i++) {
131: do {
132: j = rnd(NCOLORS);
133: } until (!used[j]);
134: used[j] = TRUE;
135: p_colors[i] = rainbow[j];
136: p_know[i] = FALSE;
137: p_guess[i] = NULL;
138: if (i > 0)
139: p_magic[i].mi_prob += p_magic[i-1].mi_prob;
140: }
141: badcheck("potions", p_magic);
142: }
143:
144:
145: /*
146: * init_names:
147: * Generate the names of the various scrolls
148: */
149: void
150: init_names(void)
151: {
152: reg int nsyl;
153: reg char *cp, *sp;
154: reg int i, nwords;
155:
156: for (i = 0; i < MAXSCROLLS; i++) {
157: cp = prbuf;
158: nwords = rnd(3)+1;
159: while(nwords--) {
160: nsyl = rnd(3)+2;
161: while(nsyl--) {
162: sp = sylls[rnd(NSYLS)];
163: while(*sp)
164: *cp++ = *sp++;
165: }
166: *cp++ = ' ';
167: }
168: *--cp = '\0';
169: s_names[i] = new(strlen(prbuf)+1);
170: s_know[i] = FALSE;
171: s_guess[i] = NULL;
172: strcpy(s_names[i], prbuf);
173: if (i > 0)
174: s_magic[i].mi_prob += s_magic[i-1].mi_prob;
175: }
176: badcheck("scrolls", s_magic);
177: }
178:
179: /*
180: * init_stones:
181: * Initialize the ring stone setting scheme for this time
182: */
183:
184: void
185: init_stones(void)
186: {
187: reg int i, j;
188: reg char *str;
189: bool used[NSTONES];
190:
191: for (i = 0; i < NSTONES; i++)
192: used[i] = FALSE;
193:
194: for (i = 0; i < MAXRINGS; i++) {
195: do {
196: j = rnd(NSTONES);
197: } until (!used[j]);
198: used[j] = TRUE;
199: r_stones[i] = stones[j];
200: r_know[i] = FALSE;
201: r_guess[i] = NULL;
202: if (i > 0)
203: r_magic[i].mi_prob += r_magic[i-1].mi_prob;
204: }
205: badcheck("rings", r_magic);
206: }
207:
208: /*
209: * init_materials:
210: * Initialize the construction materials for wands and staffs
211: */
212:
213: void
214: init_materials(void)
215: {
216: int i, j;
217: char *str;
218: struct rod *rd;
219: bool metused[NMETAL], woodused[NWOOD];
220:
221: for (i = 0; i < NWOOD; i++)
222: woodused[i] = FALSE;
223: for (i = 0; i < NMETAL; i++)
224: metused[i] = FALSE;
225:
226: for (i = 0; i < MAXSTICKS; i++) {
227: rd = &ws_stuff[i];
228: for (;;) {
229: if (rnd(100) > 50) {
230: j = rnd(NMETAL);
231: if (!metused[j]) {
232: str = metal[j];
233: rd->ws_type = "wand";
234: rd->ws_vol = V_WS_WAND;
235: rd->ws_wght = W_WS_WAND;
236: metused[j] = TRUE;
237: break;
238: }
239: }
240: else {
241: j = rnd(NWOOD);
242: if (!woodused[j]) {
243: str = wood[j];
244: rd->ws_type = "staff";
245: rd->ws_vol = V_WS_STAFF;
246: rd->ws_wght = W_WS_WAND;
247: woodused[j] = TRUE;
248: break;
249: }
250: }
251: }
252: ws_stuff[i].ws_made = str;
253: ws_know[i] = FALSE;
254: ws_guess[i] = NULL;
255: if (i > 0)
256: ws_magic[i].mi_prob += ws_magic[i-1].mi_prob;
257: }
258: badcheck("sticks", ws_magic);
259: }
260:
261: void
262: badcheck(char *name, struct magic_item *magic)
263: {
264: struct magic_item *mg;
265:
266: for (mg = magic; mg->mi_name != NULL; mg++)
267: ;
268: if ((mg - 1)->mi_prob == 1000)
269: return;
270: printf("\nBad percentages for %s:\n", name);
271: for (mg = magic; mg->mi_name != NULL; mg++)
272: printf("%4d%% %s\n", mg->mi_prob, mg->mi_name);
273: printf("%s", retstr);
274: fflush(stdout);
275: while (getchar() != '\n')
276: continue;
277: }
278:
279:
280: /*
281: * init_player:
282: * roll up the rogue
283: */
284:
285: void
286: init_player(void)
287: {
288: player.t_nomove = 0;
289: player.t_nocmd = 0;
290: him = &player.t_stats;
291: him->s_lvl = 1;
292: him->s_exp = 0L;
293: him->s_maxhp = him->s_hpt = pinit(); /* hit points */
294: him->s_re.a_str = pinit(); /* strength */
295: him->s_re.a_dex = pinit(); /* dexterity */
296: him->s_re.a_wis = pinit(); /* wisdom */
297: him->s_re.a_con = pinit(); /* constitution */
298: him->s_ef = him->s_re; /* effective = real */
299: strcpy(him->s_dmg, "1d4");
300: him->s_arm = NORMAC;
301: him->s_carry = totalenc();
302: him->s_pack = 0;
303: pack = NULL; /* empty pack so far */
304: max_stats = *him;
305: }
306:
307:
308: /*
309: * pinit:
310: * Returns the best 3 of 4 on a 6-sided die
311: */
312: int
313: pinit(void)
314: {
315: int best[4];
316: reg int i, min, minind, dicetot;
317:
318: for (i = 0 ; i < 4 ; i++)
319: best[i] = roll(1,6); /* populate array */
320: min = best[0]; /* assume that 1st entry */
321: minind = 0; /* is the lowest */
322: for (i = 1 ; i < 4 ; i++) { /* find the lowest */
323: if (best[i] < min) { /* if < minimum then update */
324: min = best[i];
325: minind = i; /* point to lowest value */
326: }
327: }
328: dicetot = 0; /* start with nothing */
329: for (i = 0 ; i < 4 ; i++) {
330: if (i != minind) /* if not minimum, then add it */
331: dicetot += best[i];
332: }
333: return(dicetot);
334: }
335:
336: /*
337: * init_everything:
338: * Set up all important stuff.
339: */
340: void
341: init_everything(void)
342: {
343: init_player(); /* Roll up the rogue */
344: init_things(); /* Set up probabilities */
345: init_names(); /* Set up names of scrolls */
346: init_colors(); /* Set up colors of potions */
347: init_stones(); /* Set up stones in rings */
348: init_materials(); /* Set up materials of wands */
349: }
CVSweb