comparison rogue4/init.c @ 12:9535a08ddc39

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