1 1.13 dholland /* $NetBSD: hack.u_init.c,v 1.13 2011/08/06 19:32:58 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.13 dholland __RCSID("$NetBSD: hack.u_init.c,v 1.13 2011/08/06 19:32:58 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.11 dholland char pl_character[PL_CSIZ]; 81 1.11 dholland 82 1.11 dholland static const struct you zerou; 83 1.11 dholland static const char *(roles[]) = { /* must all have distinct first letter */ 84 1.5 christos /* roles[4] may be changed to -woman */ 85 1.1 cgd "Tourist", "Speleologist", "Fighter", "Knight", 86 1.1 cgd "Cave-man", "Wizard" 87 1.1 cgd }; 88 1.1 cgd #define NR_OF_ROLES SIZE(roles) 89 1.11 dholland static char rolesyms[NR_OF_ROLES + 1]; /* filled by u_init() */ 90 1.1 cgd 91 1.1 cgd struct trobj { 92 1.5 christos uchar trotyp; 93 1.5 christos schar trspe; 94 1.5 christos char trolet; 95 1.5 christos Bitfield(trquan, 6); 96 1.5 christos Bitfield(trknown, 1); 97 1.1 cgd }; 98 1.1 cgd 99 1.1 cgd #ifdef WIZARD 100 1.11 dholland static struct trobj Extra_objs[] = { 101 1.5 christos {0, 0, 0, 0, 0}, 102 1.5 christos {0, 0, 0, 0, 0} 103 1.1 cgd }; 104 1.5 christos #endif /* WIZARD */ 105 1.1 cgd 106 1.11 dholland static struct trobj Cave_man[] = { 107 1.5 christos {MACE, 1, WEAPON_SYM, 1, 1}, 108 1.5 christos {BOW, 1, WEAPON_SYM, 1, 1}, 109 1.5 christos {ARROW, 0, WEAPON_SYM, 25, 1}, /* quan is variable */ 110 1.5 christos {LEATHER_ARMOR, 0, ARMOR_SYM, 1, 1}, 111 1.5 christos {0, 0, 0, 0, 0} 112 1.1 cgd }; 113 1.1 cgd 114 1.11 dholland static struct trobj Fighter[] = { 115 1.5 christos {TWO_HANDED_SWORD, 0, WEAPON_SYM, 1, 1}, 116 1.5 christos {RING_MAIL, 0, ARMOR_SYM, 1, 1}, 117 1.5 christos {0, 0, 0, 0, 0} 118 1.1 cgd }; 119 1.1 cgd 120 1.11 dholland static struct trobj Knight[] = { 121 1.5 christos {LONG_SWORD, 0, WEAPON_SYM, 1, 1}, 122 1.5 christos {SPEAR, 2, WEAPON_SYM, 1, 1}, 123 1.5 christos {RING_MAIL, 1, ARMOR_SYM, 1, 1}, 124 1.5 christos {HELMET, 0, ARMOR_SYM, 1, 1}, 125 1.5 christos {SHIELD, 0, ARMOR_SYM, 1, 1}, 126 1.5 christos {PAIR_OF_GLOVES, 0, ARMOR_SYM, 1, 1}, 127 1.5 christos {0, 0, 0, 0, 0} 128 1.1 cgd }; 129 1.1 cgd 130 1.11 dholland static struct trobj Speleologist[] = { 131 1.5 christos {STUDDED_LEATHER_ARMOR, 0, ARMOR_SYM, 1, 1}, 132 1.5 christos {UNDEF_TYP, 0, POTION_SYM, 2, 0}, 133 1.5 christos {FOOD_RATION, 0, FOOD_SYM, 3, 1}, 134 1.5 christos {PICK_AXE, UNDEF_SPE, TOOL_SYM, 1, 0}, 135 1.5 christos {ICE_BOX, 0, TOOL_SYM, 1, 0}, 136 1.5 christos {0, 0, 0, 0, 0} 137 1.1 cgd }; 138 1.1 cgd 139 1.11 dholland static struct trobj Tinopener[] = { 140 1.5 christos {CAN_OPENER, 0, TOOL_SYM, 1, 1}, 141 1.5 christos {0, 0, 0, 0, 0} 142 1.1 cgd }; 143 1.1 cgd 144 1.11 dholland static struct trobj Tourist[] = { 145 1.5 christos {UNDEF_TYP, 0, FOOD_SYM, 10, 1}, 146 1.5 christos {POT_EXTRA_HEALING, 0, POTION_SYM, 2, 0}, 147 1.5 christos {EXPENSIVE_CAMERA, 0, TOOL_SYM, 1, 1}, 148 1.5 christos {DART, 2, WEAPON_SYM, 25, 1}, /* quan is variable */ 149 1.5 christos {0, 0, 0, 0, 0} 150 1.1 cgd }; 151 1.1 cgd 152 1.11 dholland static struct trobj Wizard[] = { 153 1.5 christos {ELVEN_CLOAK, 0, ARMOR_SYM, 1, 1}, 154 1.5 christos {UNDEF_TYP, UNDEF_SPE, WAND_SYM, 2, 0}, 155 1.5 christos {UNDEF_TYP, UNDEF_SPE, RING_SYM, 2, 0}, 156 1.5 christos {UNDEF_TYP, UNDEF_SPE, POTION_SYM, 2, 0}, 157 1.5 christos {UNDEF_TYP, UNDEF_SPE, SCROLL_SYM, 3, 0}, 158 1.5 christos {0, 0, 0, 0, 0} 159 1.1 cgd }; 160 1.1 cgd 161 1.11 dholland static void ini_inv(struct trobj *); 162 1.11 dholland static void wiz_inv(void); 163 1.11 dholland static int role_index(int); 164 1.11 dholland 165 1.5 christos void 166 1.10 dholland u_init(void) 167 1.5 christos { 168 1.5 christos int i; 169 1.5 christos char exper = 'y', pc; 170 1.5 christos if (flags.female) /* should have been set in HACKOPTIONS */ 171 1.1 cgd roles[4] = "Cave-woman"; 172 1.5 christos for (i = 0; i < NR_OF_ROLES; i++) 173 1.1 cgd rolesyms[i] = roles[i][0]; 174 1.1 cgd rolesyms[i] = 0; 175 1.1 cgd 176 1.5 christos if ((pc = pl_character[0]) != '\0') { 177 1.8 dsl if (islower((unsigned char)pc)) 178 1.8 dsl pc = toupper((unsigned char)pc); 179 1.5 christos if ((i = role_index(pc)) >= 0) 180 1.1 cgd goto got_suffix; /* implies experienced */ 181 1.1 cgd printf("\nUnknown role: %c\n", pc); 182 1.1 cgd pl_character[0] = pc = 0; 183 1.1 cgd } 184 1.1 cgd printf("\nAre you an experienced player? [ny] "); 185 1.1 cgd 186 1.5 christos while (!strchr("ynYN \n\004", (exper = readchar()))) 187 1.12 roy sound_bell(); 188 1.5 christos if (exper == '\004') /* Give him an opportunity to get out */ 189 1.1 cgd end_of_input(); 190 1.5 christos printf("%c\n", exper); /* echo */ 191 1.5 christos if (strchr("Nn \n", exper)) { 192 1.1 cgd exper = 0; 193 1.1 cgd goto beginner; 194 1.1 cgd } 195 1.1 cgd printf("\nTell me what kind of character you are:\n"); 196 1.1 cgd printf("Are you"); 197 1.5 christos for (i = 0; i < NR_OF_ROLES; i++) { 198 1.1 cgd printf(" a %s", roles[i]); 199 1.5 christos if (i == 2) /* %% */ 200 1.1 cgd printf(",\n\t"); 201 1.5 christos else if (i < NR_OF_ROLES - 2) 202 1.1 cgd printf(","); 203 1.5 christos else if (i == NR_OF_ROLES - 2) 204 1.1 cgd printf(" or"); 205 1.1 cgd } 206 1.1 cgd printf("? [%s] ", rolesyms); 207 1.1 cgd 208 1.5 christos while ((pc = readchar()) != '\0') { 209 1.8 dsl if (islower((unsigned char)pc)) 210 1.8 dsl pc = toupper((unsigned char)pc); 211 1.5 christos if ((i = role_index(pc)) >= 0) { 212 1.1 cgd printf("%c\n", pc); /* echo */ 213 1.1 cgd (void) fflush(stdout); /* should be seen */ 214 1.1 cgd break; 215 1.1 cgd } 216 1.5 christos if (pc == '\n') 217 1.1 cgd break; 218 1.5 christos if (pc == '\004') /* Give him the opportunity to get 219 1.5 christos * out */ 220 1.1 cgd end_of_input(); 221 1.12 roy sound_bell(); 222 1.1 cgd } 223 1.5 christos if (pc == '\n') 224 1.1 cgd pc = 0; 225 1.1 cgd 226 1.1 cgd beginner: 227 1.5 christos if (!pc) { 228 1.1 cgd printf("\nI'll choose a character for you.\n"); 229 1.1 cgd i = rn2(NR_OF_ROLES); 230 1.1 cgd pc = rolesyms[i]; 231 1.1 cgd printf("This game you will be a%s %s.\n", 232 1.5 christos exper ? "n experienced" : "", 233 1.5 christos roles[i]); 234 1.1 cgd getret(); 235 1.1 cgd /* give him some feedback in case mklev takes much time */ 236 1.1 cgd (void) putchar('\n'); 237 1.1 cgd (void) fflush(stdout); 238 1.1 cgd } 239 1.2 mycroft #if 0 240 1.5 christos /* 241 1.5 christos * Given the above code, I can't see why this would ever change 242 1.5 christos * anything; it does core pretty well, though. - cmh 4/20/93 243 1.5 christos */ 244 1.5 christos if (exper) { 245 1.1 cgd roles[i][0] = pc; 246 1.1 cgd } 247 1.2 mycroft #endif 248 1.1 cgd 249 1.1 cgd got_suffix: 250 1.1 cgd 251 1.5 christos (void) strncpy(pl_character, roles[i], PL_CSIZ - 1); 252 1.5 christos pl_character[PL_CSIZ - 1] = 0; 253 1.1 cgd flags.beginner = 1; 254 1.1 cgd u = zerou; 255 1.1 cgd u.usym = '@'; 256 1.1 cgd u.ulevel = 1; 257 1.1 cgd init_uhunger(); 258 1.1 cgd #ifdef QUEST 259 1.1 cgd u.uhorizon = 6; 260 1.5 christos #endif /* QUEST */ 261 1.1 cgd uarm = uarm2 = uarmh = uarms = uarmg = uwep = uball = uchain = 262 1.5 christos uleft = uright = 0; 263 1.1 cgd 264 1.5 christos switch (pc) { 265 1.1 cgd case 'c': 266 1.1 cgd case 'C': 267 1.5 christos Cave_man[2].trquan = 12 + rnd(9) * rnd(9); 268 1.1 cgd u.uhp = u.uhpmax = 16; 269 1.1 cgd u.ustr = u.ustrmax = 18; 270 1.1 cgd ini_inv(Cave_man); 271 1.1 cgd break; 272 1.1 cgd case 't': 273 1.1 cgd case 'T': 274 1.1 cgd Tourist[3].trquan = 20 + rnd(20); 275 1.1 cgd u.ugold = u.ugold0 = rnd(1000); 276 1.1 cgd u.uhp = u.uhpmax = 10; 277 1.1 cgd u.ustr = u.ustrmax = 8; 278 1.1 cgd ini_inv(Tourist); 279 1.5 christos if (!rn2(25)) 280 1.5 christos ini_inv(Tinopener); 281 1.1 cgd break; 282 1.1 cgd case 'w': 283 1.1 cgd case 'W': 284 1.5 christos for (i = 1; i <= 4; i++) 285 1.5 christos if (!rn2(5)) 286 1.5 christos Wizard[i].trquan += rn2(3) - 1; 287 1.1 cgd u.uhp = u.uhpmax = 15; 288 1.1 cgd u.ustr = u.ustrmax = 16; 289 1.1 cgd ini_inv(Wizard); 290 1.1 cgd break; 291 1.1 cgd case 's': 292 1.1 cgd case 'S': 293 1.1 cgd Fast = INTRINSIC; 294 1.1 cgd Stealth = INTRINSIC; 295 1.1 cgd u.uhp = u.uhpmax = 12; 296 1.1 cgd u.ustr = u.ustrmax = 10; 297 1.1 cgd ini_inv(Speleologist); 298 1.5 christos if (!rn2(10)) 299 1.5 christos ini_inv(Tinopener); 300 1.1 cgd break; 301 1.1 cgd case 'k': 302 1.1 cgd case 'K': 303 1.1 cgd u.uhp = u.uhpmax = 12; 304 1.1 cgd u.ustr = u.ustrmax = 10; 305 1.1 cgd ini_inv(Knight); 306 1.1 cgd break; 307 1.1 cgd case 'f': 308 1.1 cgd case 'F': 309 1.1 cgd u.uhp = u.uhpmax = 14; 310 1.1 cgd u.ustr = u.ustrmax = 17; 311 1.1 cgd ini_inv(Fighter); 312 1.1 cgd break; 313 1.5 christos default: /* impossible */ 314 1.1 cgd u.uhp = u.uhpmax = 12; 315 1.1 cgd u.ustr = u.ustrmax = 16; 316 1.1 cgd } 317 1.1 cgd find_ac(); 318 1.5 christos if (!rn2(20)) { 319 1.9 dholland int dr = rn2(7) - 2; /* biased variation */ 320 1.9 dholland u.ustr += dr; 321 1.9 dholland u.ustrmax += dr; 322 1.1 cgd } 323 1.1 cgd #ifdef WIZARD 324 1.5 christos if (wizard) 325 1.5 christos wiz_inv(); 326 1.5 christos #endif /* WIZARD */ 327 1.1 cgd 328 1.1 cgd /* make sure he can carry all he has - especially for T's */ 329 1.5 christos while (inv_weight() > 0 && u.ustr < 118) 330 1.1 cgd u.ustr++, u.ustrmax++; 331 1.1 cgd } 332 1.1 cgd 333 1.5 christos void 334 1.10 dholland ini_inv(struct trobj *trop) 335 1.5 christos { 336 1.5 christos struct obj *obj; 337 1.5 christos while (trop->trolet) { 338 1.1 cgd obj = mkobj(trop->trolet); 339 1.1 cgd obj->known = trop->trknown; 340 1.1 cgd /* not obj->dknown = 1; - let him look at it at least once */ 341 1.1 cgd obj->cursed = 0; 342 1.5 christos if (obj->olet == WEAPON_SYM) { 343 1.1 cgd obj->quan = trop->trquan; 344 1.1 cgd trop->trquan = 1; 345 1.1 cgd } 346 1.5 christos if (trop->trspe != UNDEF_SPE) 347 1.1 cgd obj->spe = trop->trspe; 348 1.5 christos if (trop->trotyp != UNDEF_TYP) 349 1.1 cgd obj->otyp = trop->trotyp; 350 1.5 christos else if (obj->otyp == WAN_WISHING) /* gitpyr!robert */ 351 1.5 christos obj->otyp = WAN_DEATH; 352 1.1 cgd obj->owt = weight(obj); /* defined after setting otyp+quan */ 353 1.1 cgd obj = addinv(obj); 354 1.5 christos if (obj->olet == ARMOR_SYM) { 355 1.5 christos switch (obj->otyp) { 356 1.1 cgd case SHIELD: 357 1.5 christos if (!uarms) 358 1.5 christos setworn(obj, W_ARMS); 359 1.1 cgd break; 360 1.1 cgd case HELMET: 361 1.5 christos if (!uarmh) 362 1.5 christos setworn(obj, W_ARMH); 363 1.1 cgd break; 364 1.1 cgd case PAIR_OF_GLOVES: 365 1.5 christos if (!uarmg) 366 1.5 christos setworn(obj, W_ARMG); 367 1.1 cgd break; 368 1.1 cgd case ELVEN_CLOAK: 369 1.5 christos if (!uarm2) 370 1.1 cgd setworn(obj, W_ARM); 371 1.1 cgd break; 372 1.1 cgd default: 373 1.5 christos if (!uarm) 374 1.5 christos setworn(obj, W_ARM); 375 1.1 cgd } 376 1.1 cgd } 377 1.5 christos if (obj->olet == WEAPON_SYM) 378 1.5 christos if (!uwep) 379 1.5 christos setuwep(obj); 380 1.5 christos if (--trop->trquan) 381 1.5 christos continue; /* make a similar object */ 382 1.1 cgd trop++; 383 1.1 cgd } 384 1.1 cgd } 385 1.1 cgd 386 1.1 cgd #ifdef WIZARD 387 1.5 christos void 388 1.10 dholland wiz_inv(void) 389 1.5 christos { 390 1.5 christos struct trobj *trop = &Extra_objs[0]; 391 1.5 christos char *ep = getenv("INVENT"); 392 1.5 christos int type; 393 1.5 christos while (ep && *ep) { 394 1.1 cgd type = atoi(ep); 395 1.5 christos ep = strchr(ep, ','); 396 1.5 christos if (ep) 397 1.5 christos while (*ep == ',' || *ep == ' ') 398 1.5 christos ep++; 399 1.5 christos if (type <= 0 || type > NROFOBJECTS) 400 1.5 christos continue; 401 1.1 cgd trop->trotyp = type; 402 1.1 cgd trop->trolet = objects[type].oc_olet; 403 1.1 cgd trop->trspe = 4; 404 1.1 cgd trop->trknown = 1; 405 1.1 cgd trop->trquan = 1; 406 1.1 cgd ini_inv(trop); 407 1.1 cgd } 408 1.1 cgd /* give him a wand of wishing by default */ 409 1.1 cgd trop->trotyp = WAN_WISHING; 410 1.1 cgd trop->trolet = WAND_SYM; 411 1.1 cgd trop->trspe = 20; 412 1.1 cgd trop->trknown = 1; 413 1.1 cgd trop->trquan = 1; 414 1.1 cgd ini_inv(trop); 415 1.1 cgd } 416 1.5 christos #endif /* WIZARD */ 417 1.1 cgd 418 1.5 christos void 419 1.10 dholland plnamesuffix(void) 420 1.5 christos { 421 1.5 christos char *p; 422 1.5 christos if ((p = strrchr(plname, '-')) != NULL) { 423 1.1 cgd *p = 0; 424 1.1 cgd pl_character[0] = p[1]; 425 1.1 cgd pl_character[1] = 0; 426 1.5 christos if (!plname[0]) { 427 1.1 cgd askname(); 428 1.1 cgd plnamesuffix(); 429 1.1 cgd } 430 1.1 cgd } 431 1.1 cgd } 432 1.1 cgd 433 1.5 christos int 434 1.10 dholland role_index(int pc) 435 1.5 christos { /* must be called only from u_init() */ 436 1.5 christos /* so that rolesyms[] is defined */ 437 1.5 christos char *cp; 438 1.5 christos 439 1.5 christos if ((cp = strchr(rolesyms, pc)) != NULL) 440 1.5 christos return (cp - rolesyms); 441 1.5 christos return (-1); 442 1.1 cgd } 443