comparison srogue/init.c @ 36:2128c7dc8a40

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