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