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