hack.u_init.c revision 1.10 1 1.10 dholland /* $NetBSD: hack.u_init.c,v 1.10 2009/06/07 18:30:39 dholland Exp $ */
2 1.5 christos
3 1.3 mycroft /*
4 1.7 jsm * Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
5 1.7 jsm * Amsterdam
6 1.7 jsm * All rights reserved.
7 1.7 jsm *
8 1.7 jsm * Redistribution and use in source and binary forms, with or without
9 1.7 jsm * modification, are permitted provided that the following conditions are
10 1.7 jsm * met:
11 1.7 jsm *
12 1.7 jsm * - Redistributions of source code must retain the above copyright notice,
13 1.7 jsm * this list of conditions and the following disclaimer.
14 1.7 jsm *
15 1.7 jsm * - Redistributions in binary form must reproduce the above copyright
16 1.7 jsm * notice, this list of conditions and the following disclaimer in the
17 1.7 jsm * documentation and/or other materials provided with the distribution.
18 1.7 jsm *
19 1.7 jsm * - Neither the name of the Stichting Centrum voor Wiskunde en
20 1.7 jsm * Informatica, nor the names of its contributors may be used to endorse or
21 1.7 jsm * promote products derived from this software without specific prior
22 1.7 jsm * written permission.
23 1.7 jsm *
24 1.7 jsm * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
25 1.7 jsm * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
26 1.7 jsm * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
27 1.7 jsm * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
28 1.7 jsm * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29 1.7 jsm * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30 1.7 jsm * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
31 1.7 jsm * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32 1.7 jsm * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33 1.7 jsm * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34 1.7 jsm * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 1.7 jsm */
36 1.7 jsm
37 1.7 jsm /*
38 1.7 jsm * Copyright (c) 1982 Jay Fenlason <hack (at) gnu.org>
39 1.7 jsm * All rights reserved.
40 1.7 jsm *
41 1.7 jsm * Redistribution and use in source and binary forms, with or without
42 1.7 jsm * modification, are permitted provided that the following conditions
43 1.7 jsm * are met:
44 1.7 jsm * 1. Redistributions of source code must retain the above copyright
45 1.7 jsm * notice, this list of conditions and the following disclaimer.
46 1.7 jsm * 2. Redistributions in binary form must reproduce the above copyright
47 1.7 jsm * notice, this list of conditions and the following disclaimer in the
48 1.7 jsm * documentation and/or other materials provided with the distribution.
49 1.7 jsm * 3. The name of the author may not be used to endorse or promote products
50 1.7 jsm * derived from this software without specific prior written permission.
51 1.7 jsm *
52 1.7 jsm * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
53 1.7 jsm * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
54 1.7 jsm * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
55 1.7 jsm * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
56 1.7 jsm * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
57 1.7 jsm * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
58 1.7 jsm * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
59 1.7 jsm * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
60 1.7 jsm * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
61 1.7 jsm * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
62 1.3 mycroft */
63 1.3 mycroft
64 1.5 christos #include <sys/cdefs.h>
65 1.3 mycroft #ifndef lint
66 1.10 dholland __RCSID("$NetBSD: hack.u_init.c,v 1.10 2009/06/07 18:30:39 dholland Exp $");
67 1.5 christos #endif /* not lint */
68 1.1 cgd
69 1.5 christos #include <ctype.h>
70 1.5 christos #include <signal.h>
71 1.5 christos #include <stdlib.h>
72 1.1 cgd #include "hack.h"
73 1.5 christos #include "extern.h"
74 1.5 christos
75 1.1 cgd #define Strcpy (void) strcpy
76 1.1 cgd #define Strcat (void) strcat
77 1.1 cgd #define UNDEF_TYP 0
78 1.1 cgd #define UNDEF_SPE '\177'
79 1.5 christos
80 1.5 christos struct you zerou;
81 1.5 christos char pl_character[PL_CSIZ];
82 1.6 jsm const char *(roles[]) = { /* must all have distinct first letter */
83 1.5 christos /* roles[4] may be changed to -woman */
84 1.1 cgd "Tourist", "Speleologist", "Fighter", "Knight",
85 1.1 cgd "Cave-man", "Wizard"
86 1.1 cgd };
87 1.1 cgd #define NR_OF_ROLES SIZE(roles)
88 1.5 christos char rolesyms[NR_OF_ROLES + 1]; /* filled by u_init() */
89 1.1 cgd
90 1.1 cgd struct trobj {
91 1.5 christos uchar trotyp;
92 1.5 christos schar trspe;
93 1.5 christos char trolet;
94 1.5 christos Bitfield(trquan, 6);
95 1.5 christos Bitfield(trknown, 1);
96 1.1 cgd };
97 1.1 cgd
98 1.1 cgd #ifdef WIZARD
99 1.5 christos struct trobj Extra_objs[] = {
100 1.5 christos {0, 0, 0, 0, 0},
101 1.5 christos {0, 0, 0, 0, 0}
102 1.1 cgd };
103 1.5 christos #endif /* WIZARD */
104 1.1 cgd
105 1.5 christos struct trobj Cave_man[] = {
106 1.5 christos {MACE, 1, WEAPON_SYM, 1, 1},
107 1.5 christos {BOW, 1, WEAPON_SYM, 1, 1},
108 1.5 christos {ARROW, 0, WEAPON_SYM, 25, 1}, /* quan is variable */
109 1.5 christos {LEATHER_ARMOR, 0, ARMOR_SYM, 1, 1},
110 1.5 christos {0, 0, 0, 0, 0}
111 1.1 cgd };
112 1.1 cgd
113 1.5 christos struct trobj Fighter[] = {
114 1.5 christos {TWO_HANDED_SWORD, 0, WEAPON_SYM, 1, 1},
115 1.5 christos {RING_MAIL, 0, ARMOR_SYM, 1, 1},
116 1.5 christos {0, 0, 0, 0, 0}
117 1.1 cgd };
118 1.1 cgd
119 1.5 christos struct trobj Knight[] = {
120 1.5 christos {LONG_SWORD, 0, WEAPON_SYM, 1, 1},
121 1.5 christos {SPEAR, 2, WEAPON_SYM, 1, 1},
122 1.5 christos {RING_MAIL, 1, ARMOR_SYM, 1, 1},
123 1.5 christos {HELMET, 0, ARMOR_SYM, 1, 1},
124 1.5 christos {SHIELD, 0, ARMOR_SYM, 1, 1},
125 1.5 christos {PAIR_OF_GLOVES, 0, ARMOR_SYM, 1, 1},
126 1.5 christos {0, 0, 0, 0, 0}
127 1.1 cgd };
128 1.1 cgd
129 1.5 christos struct trobj Speleologist[] = {
130 1.5 christos {STUDDED_LEATHER_ARMOR, 0, ARMOR_SYM, 1, 1},
131 1.5 christos {UNDEF_TYP, 0, POTION_SYM, 2, 0},
132 1.5 christos {FOOD_RATION, 0, FOOD_SYM, 3, 1},
133 1.5 christos {PICK_AXE, UNDEF_SPE, TOOL_SYM, 1, 0},
134 1.5 christos {ICE_BOX, 0, TOOL_SYM, 1, 0},
135 1.5 christos {0, 0, 0, 0, 0}
136 1.1 cgd };
137 1.1 cgd
138 1.5 christos struct trobj Tinopener[] = {
139 1.5 christos {CAN_OPENER, 0, TOOL_SYM, 1, 1},
140 1.5 christos {0, 0, 0, 0, 0}
141 1.1 cgd };
142 1.1 cgd
143 1.5 christos struct trobj Tourist[] = {
144 1.5 christos {UNDEF_TYP, 0, FOOD_SYM, 10, 1},
145 1.5 christos {POT_EXTRA_HEALING, 0, POTION_SYM, 2, 0},
146 1.5 christos {EXPENSIVE_CAMERA, 0, TOOL_SYM, 1, 1},
147 1.5 christos {DART, 2, WEAPON_SYM, 25, 1}, /* quan is variable */
148 1.5 christos {0, 0, 0, 0, 0}
149 1.1 cgd };
150 1.1 cgd
151 1.5 christos struct trobj Wizard[] = {
152 1.5 christos {ELVEN_CLOAK, 0, ARMOR_SYM, 1, 1},
153 1.5 christos {UNDEF_TYP, UNDEF_SPE, WAND_SYM, 2, 0},
154 1.5 christos {UNDEF_TYP, UNDEF_SPE, RING_SYM, 2, 0},
155 1.5 christos {UNDEF_TYP, UNDEF_SPE, POTION_SYM, 2, 0},
156 1.5 christos {UNDEF_TYP, UNDEF_SPE, SCROLL_SYM, 3, 0},
157 1.5 christos {0, 0, 0, 0, 0}
158 1.1 cgd };
159 1.1 cgd
160 1.5 christos void
161 1.10 dholland u_init(void)
162 1.5 christos {
163 1.5 christos int i;
164 1.5 christos char exper = 'y', pc;
165 1.5 christos if (flags.female) /* should have been set in HACKOPTIONS */
166 1.1 cgd roles[4] = "Cave-woman";
167 1.5 christos for (i = 0; i < NR_OF_ROLES; i++)
168 1.1 cgd rolesyms[i] = roles[i][0];
169 1.1 cgd rolesyms[i] = 0;
170 1.1 cgd
171 1.5 christos if ((pc = pl_character[0]) != '\0') {
172 1.8 dsl if (islower((unsigned char)pc))
173 1.8 dsl pc = toupper((unsigned char)pc);
174 1.5 christos if ((i = role_index(pc)) >= 0)
175 1.1 cgd goto got_suffix; /* implies experienced */
176 1.1 cgd printf("\nUnknown role: %c\n", pc);
177 1.1 cgd pl_character[0] = pc = 0;
178 1.1 cgd }
179 1.1 cgd printf("\nAre you an experienced player? [ny] ");
180 1.1 cgd
181 1.5 christos while (!strchr("ynYN \n\004", (exper = readchar())))
182 1.1 cgd bell();
183 1.5 christos if (exper == '\004') /* Give him an opportunity to get out */
184 1.1 cgd end_of_input();
185 1.5 christos printf("%c\n", exper); /* echo */
186 1.5 christos if (strchr("Nn \n", exper)) {
187 1.1 cgd exper = 0;
188 1.1 cgd goto beginner;
189 1.1 cgd }
190 1.1 cgd printf("\nTell me what kind of character you are:\n");
191 1.1 cgd printf("Are you");
192 1.5 christos for (i = 0; i < NR_OF_ROLES; i++) {
193 1.1 cgd printf(" a %s", roles[i]);
194 1.5 christos if (i == 2) /* %% */
195 1.1 cgd printf(",\n\t");
196 1.5 christos else if (i < NR_OF_ROLES - 2)
197 1.1 cgd printf(",");
198 1.5 christos else if (i == NR_OF_ROLES - 2)
199 1.1 cgd printf(" or");
200 1.1 cgd }
201 1.1 cgd printf("? [%s] ", rolesyms);
202 1.1 cgd
203 1.5 christos while ((pc = readchar()) != '\0') {
204 1.8 dsl if (islower((unsigned char)pc))
205 1.8 dsl pc = toupper((unsigned char)pc);
206 1.5 christos if ((i = role_index(pc)) >= 0) {
207 1.1 cgd printf("%c\n", pc); /* echo */
208 1.1 cgd (void) fflush(stdout); /* should be seen */
209 1.1 cgd break;
210 1.1 cgd }
211 1.5 christos if (pc == '\n')
212 1.1 cgd break;
213 1.5 christos if (pc == '\004') /* Give him the opportunity to get
214 1.5 christos * out */
215 1.1 cgd end_of_input();
216 1.1 cgd bell();
217 1.1 cgd }
218 1.5 christos if (pc == '\n')
219 1.1 cgd pc = 0;
220 1.1 cgd
221 1.1 cgd beginner:
222 1.5 christos if (!pc) {
223 1.1 cgd printf("\nI'll choose a character for you.\n");
224 1.1 cgd i = rn2(NR_OF_ROLES);
225 1.1 cgd pc = rolesyms[i];
226 1.1 cgd printf("This game you will be a%s %s.\n",
227 1.5 christos exper ? "n experienced" : "",
228 1.5 christos roles[i]);
229 1.1 cgd getret();
230 1.1 cgd /* give him some feedback in case mklev takes much time */
231 1.1 cgd (void) putchar('\n');
232 1.1 cgd (void) fflush(stdout);
233 1.1 cgd }
234 1.2 mycroft #if 0
235 1.5 christos /*
236 1.5 christos * Given the above code, I can't see why this would ever change
237 1.5 christos * anything; it does core pretty well, though. - cmh 4/20/93
238 1.5 christos */
239 1.5 christos if (exper) {
240 1.1 cgd roles[i][0] = pc;
241 1.1 cgd }
242 1.2 mycroft #endif
243 1.1 cgd
244 1.1 cgd got_suffix:
245 1.1 cgd
246 1.5 christos (void) strncpy(pl_character, roles[i], PL_CSIZ - 1);
247 1.5 christos pl_character[PL_CSIZ - 1] = 0;
248 1.1 cgd flags.beginner = 1;
249 1.1 cgd u = zerou;
250 1.1 cgd u.usym = '@';
251 1.1 cgd u.ulevel = 1;
252 1.1 cgd init_uhunger();
253 1.1 cgd #ifdef QUEST
254 1.1 cgd u.uhorizon = 6;
255 1.5 christos #endif /* QUEST */
256 1.1 cgd uarm = uarm2 = uarmh = uarms = uarmg = uwep = uball = uchain =
257 1.5 christos uleft = uright = 0;
258 1.1 cgd
259 1.5 christos switch (pc) {
260 1.1 cgd case 'c':
261 1.1 cgd case 'C':
262 1.5 christos Cave_man[2].trquan = 12 + rnd(9) * rnd(9);
263 1.1 cgd u.uhp = u.uhpmax = 16;
264 1.1 cgd u.ustr = u.ustrmax = 18;
265 1.1 cgd ini_inv(Cave_man);
266 1.1 cgd break;
267 1.1 cgd case 't':
268 1.1 cgd case 'T':
269 1.1 cgd Tourist[3].trquan = 20 + rnd(20);
270 1.1 cgd u.ugold = u.ugold0 = rnd(1000);
271 1.1 cgd u.uhp = u.uhpmax = 10;
272 1.1 cgd u.ustr = u.ustrmax = 8;
273 1.1 cgd ini_inv(Tourist);
274 1.5 christos if (!rn2(25))
275 1.5 christos ini_inv(Tinopener);
276 1.1 cgd break;
277 1.1 cgd case 'w':
278 1.1 cgd case 'W':
279 1.5 christos for (i = 1; i <= 4; i++)
280 1.5 christos if (!rn2(5))
281 1.5 christos Wizard[i].trquan += rn2(3) - 1;
282 1.1 cgd u.uhp = u.uhpmax = 15;
283 1.1 cgd u.ustr = u.ustrmax = 16;
284 1.1 cgd ini_inv(Wizard);
285 1.1 cgd break;
286 1.1 cgd case 's':
287 1.1 cgd case 'S':
288 1.1 cgd Fast = INTRINSIC;
289 1.1 cgd Stealth = INTRINSIC;
290 1.1 cgd u.uhp = u.uhpmax = 12;
291 1.1 cgd u.ustr = u.ustrmax = 10;
292 1.1 cgd ini_inv(Speleologist);
293 1.5 christos if (!rn2(10))
294 1.5 christos ini_inv(Tinopener);
295 1.1 cgd break;
296 1.1 cgd case 'k':
297 1.1 cgd case 'K':
298 1.1 cgd u.uhp = u.uhpmax = 12;
299 1.1 cgd u.ustr = u.ustrmax = 10;
300 1.1 cgd ini_inv(Knight);
301 1.1 cgd break;
302 1.1 cgd case 'f':
303 1.1 cgd case 'F':
304 1.1 cgd u.uhp = u.uhpmax = 14;
305 1.1 cgd u.ustr = u.ustrmax = 17;
306 1.1 cgd ini_inv(Fighter);
307 1.1 cgd break;
308 1.5 christos default: /* impossible */
309 1.1 cgd u.uhp = u.uhpmax = 12;
310 1.1 cgd u.ustr = u.ustrmax = 16;
311 1.1 cgd }
312 1.1 cgd find_ac();
313 1.5 christos if (!rn2(20)) {
314 1.9 dholland int dr = rn2(7) - 2; /* biased variation */
315 1.9 dholland u.ustr += dr;
316 1.9 dholland u.ustrmax += dr;
317 1.1 cgd }
318 1.1 cgd #ifdef WIZARD
319 1.5 christos if (wizard)
320 1.5 christos wiz_inv();
321 1.5 christos #endif /* WIZARD */
322 1.1 cgd
323 1.1 cgd /* make sure he can carry all he has - especially for T's */
324 1.5 christos while (inv_weight() > 0 && u.ustr < 118)
325 1.1 cgd u.ustr++, u.ustrmax++;
326 1.1 cgd }
327 1.1 cgd
328 1.5 christos void
329 1.10 dholland ini_inv(struct trobj *trop)
330 1.5 christos {
331 1.5 christos struct obj *obj;
332 1.5 christos while (trop->trolet) {
333 1.1 cgd obj = mkobj(trop->trolet);
334 1.1 cgd obj->known = trop->trknown;
335 1.1 cgd /* not obj->dknown = 1; - let him look at it at least once */
336 1.1 cgd obj->cursed = 0;
337 1.5 christos if (obj->olet == WEAPON_SYM) {
338 1.1 cgd obj->quan = trop->trquan;
339 1.1 cgd trop->trquan = 1;
340 1.1 cgd }
341 1.5 christos if (trop->trspe != UNDEF_SPE)
342 1.1 cgd obj->spe = trop->trspe;
343 1.5 christos if (trop->trotyp != UNDEF_TYP)
344 1.1 cgd obj->otyp = trop->trotyp;
345 1.5 christos else if (obj->otyp == WAN_WISHING) /* gitpyr!robert */
346 1.5 christos obj->otyp = WAN_DEATH;
347 1.1 cgd obj->owt = weight(obj); /* defined after setting otyp+quan */
348 1.1 cgd obj = addinv(obj);
349 1.5 christos if (obj->olet == ARMOR_SYM) {
350 1.5 christos switch (obj->otyp) {
351 1.1 cgd case SHIELD:
352 1.5 christos if (!uarms)
353 1.5 christos setworn(obj, W_ARMS);
354 1.1 cgd break;
355 1.1 cgd case HELMET:
356 1.5 christos if (!uarmh)
357 1.5 christos setworn(obj, W_ARMH);
358 1.1 cgd break;
359 1.1 cgd case PAIR_OF_GLOVES:
360 1.5 christos if (!uarmg)
361 1.5 christos setworn(obj, W_ARMG);
362 1.1 cgd break;
363 1.1 cgd case ELVEN_CLOAK:
364 1.5 christos if (!uarm2)
365 1.1 cgd setworn(obj, W_ARM);
366 1.1 cgd break;
367 1.1 cgd default:
368 1.5 christos if (!uarm)
369 1.5 christos setworn(obj, W_ARM);
370 1.1 cgd }
371 1.1 cgd }
372 1.5 christos if (obj->olet == WEAPON_SYM)
373 1.5 christos if (!uwep)
374 1.5 christos setuwep(obj);
375 1.1 cgd #ifndef PYRAMID_BUG
376 1.5 christos if (--trop->trquan)
377 1.5 christos continue; /* make a similar object */
378 1.1 cgd #else
379 1.5 christos if (trop->trquan) { /* check if zero first */
380 1.1 cgd --trop->trquan;
381 1.5 christos if (trop->trquan)
382 1.1 cgd continue; /* make a similar object */
383 1.1 cgd }
384 1.5 christos #endif /* PYRAMID_BUG */
385 1.1 cgd trop++;
386 1.1 cgd }
387 1.1 cgd }
388 1.1 cgd
389 1.1 cgd #ifdef WIZARD
390 1.5 christos void
391 1.10 dholland wiz_inv(void)
392 1.5 christos {
393 1.5 christos struct trobj *trop = &Extra_objs[0];
394 1.5 christos char *ep = getenv("INVENT");
395 1.5 christos int type;
396 1.5 christos while (ep && *ep) {
397 1.1 cgd type = atoi(ep);
398 1.5 christos ep = strchr(ep, ',');
399 1.5 christos if (ep)
400 1.5 christos while (*ep == ',' || *ep == ' ')
401 1.5 christos ep++;
402 1.5 christos if (type <= 0 || type > NROFOBJECTS)
403 1.5 christos continue;
404 1.1 cgd trop->trotyp = type;
405 1.1 cgd trop->trolet = objects[type].oc_olet;
406 1.1 cgd trop->trspe = 4;
407 1.1 cgd trop->trknown = 1;
408 1.1 cgd trop->trquan = 1;
409 1.1 cgd ini_inv(trop);
410 1.1 cgd }
411 1.1 cgd /* give him a wand of wishing by default */
412 1.1 cgd trop->trotyp = WAN_WISHING;
413 1.1 cgd trop->trolet = WAND_SYM;
414 1.1 cgd trop->trspe = 20;
415 1.1 cgd trop->trknown = 1;
416 1.1 cgd trop->trquan = 1;
417 1.1 cgd ini_inv(trop);
418 1.1 cgd }
419 1.5 christos #endif /* WIZARD */
420 1.1 cgd
421 1.5 christos void
422 1.10 dholland plnamesuffix(void)
423 1.5 christos {
424 1.5 christos char *p;
425 1.5 christos if ((p = strrchr(plname, '-')) != NULL) {
426 1.1 cgd *p = 0;
427 1.1 cgd pl_character[0] = p[1];
428 1.1 cgd pl_character[1] = 0;
429 1.5 christos if (!plname[0]) {
430 1.1 cgd askname();
431 1.1 cgd plnamesuffix();
432 1.1 cgd }
433 1.1 cgd }
434 1.1 cgd }
435 1.1 cgd
436 1.5 christos int
437 1.10 dholland role_index(int pc)
438 1.5 christos { /* must be called only from u_init() */
439 1.5 christos /* so that rolesyms[] is defined */
440 1.5 christos char *cp;
441 1.5 christos
442 1.5 christos if ((cp = strchr(rolesyms, pc)) != NULL)
443 1.5 christos return (cp - rolesyms);
444 1.5 christos return (-1);
445 1.1 cgd }
446