1 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ 2 /* hack.u_init.c - version 1.0.3 */ 3 /* $FreeBSD: src/games/hack/hack.u_init.c,v 1.4 1999/11/16 02:57:13 billf Exp $ */ 4 5 #include "hack.h" 6 #include <stdio.h> 7 #include <signal.h> 8 #include <stdlib.h> 9 #define Strcpy (void) strcpy 10 #define Strcat (void) strcat 11 #define UNDEF_TYP 0 12 #define UNDEF_SPE '\177' 13 extern struct obj *addinv(); 14 extern char *eos(); 15 extern char plname[]; 16 17 struct you zerou; 18 char pl_character[PL_CSIZ]; 19 char *(roles[]) = { /* must all have distinct first letter */ 20 /* roles[4] may be changed to -man */ 21 "Tourist", "Speleologist", "Fighter", "Knight", 22 "Cave-man", "Wizard" 23 }; 24 #define NR_OF_ROLES SIZE(roles) 25 char rolesyms[NR_OF_ROLES + 1]; /* filled by u_init() */ 26 27 struct trobj { 28 uchar trotyp; 29 schar trspe; 30 char trolet; 31 Bitfield(trquan,6); 32 Bitfield(trknown,1); 33 }; 34 35 #ifdef WIZARD 36 struct trobj Extra_objs[] = { 37 { 0, 0, 0, 0, 0 }, 38 { 0, 0, 0, 0, 0 } 39 }; 40 #endif WIZARD 41 42 struct trobj Cave_man[] = { 43 { MACE, 1, WEAPON_SYM, 1, 1 }, 44 { BOW, 1, WEAPON_SYM, 1, 1 }, 45 { ARROW, 0, WEAPON_SYM, 25, 1 }, /* quan is variable */ 46 { LEATHER_ARMOR, 0, ARMOR_SYM, 1, 1 }, 47 { 0, 0, 0, 0, 0} 48 }; 49 50 struct trobj Fighter[] = { 51 { TWO_HANDED_SWORD, 0, WEAPON_SYM, 1, 1 }, 52 { RING_MAIL, 0, ARMOR_SYM, 1, 1 }, 53 { 0, 0, 0, 0, 0 } 54 }; 55 56 struct trobj Knight[] = { 57 { LONG_SWORD, 0, WEAPON_SYM, 1, 1 }, 58 { SPEAR, 2, WEAPON_SYM, 1, 1 }, 59 { RING_MAIL, 1, ARMOR_SYM, 1, 1 }, 60 { HELMET, 0, ARMOR_SYM, 1, 1 }, 61 { SHIELD, 0, ARMOR_SYM, 1, 1 }, 62 { PAIR_OF_GLOVES, 0, ARMOR_SYM, 1, 1 }, 63 { 0, 0, 0, 0, 0 } 64 }; 65 66 struct trobj Speleologist[] = { 67 { STUDDED_LEATHER_ARMOR, 0, ARMOR_SYM, 1, 1 }, 68 { UNDEF_TYP, 0, POTION_SYM, 2, 0 }, 69 { FOOD_RATION, 0, FOOD_SYM, 3, 1 }, 70 { PICK_AXE, UNDEF_SPE, TOOL_SYM, 1, 0 }, 71 { ICE_BOX, 0, TOOL_SYM, 1, 0 }, 72 { 0, 0, 0, 0, 0} 73 }; 74 75 struct trobj Tinopener[] = { 76 { CAN_OPENER, 0, TOOL_SYM, 1, 1 }, 77 { 0, 0, 0, 0, 0 } 78 }; 79 80 struct trobj Tourist[] = { 81 { UNDEF_TYP, 0, FOOD_SYM, 10, 1 }, 82 { POT_EXTRA_HEALING, 0, POTION_SYM, 2, 0 }, 83 { EXPENSIVE_CAMERA, 0, TOOL_SYM, 1, 1 }, 84 { DART, 2, WEAPON_SYM, 25, 1 }, /* quan is variable */ 85 { 0, 0, 0, 0, 0 } 86 }; 87 88 struct trobj Wizard[] = { 89 { ELVEN_CLOAK, 0, ARMOR_SYM, 1, 1 }, 90 { UNDEF_TYP, UNDEF_SPE, WAND_SYM, 2, 0 }, 91 { UNDEF_TYP, UNDEF_SPE, RING_SYM, 2, 0 }, 92 { UNDEF_TYP, UNDEF_SPE, POTION_SYM, 2, 0 }, 93 { UNDEF_TYP, UNDEF_SPE, SCROLL_SYM, 3, 0 }, 94 { 0, 0, 0, 0, 0 } 95 }; 96 97 u_init(){ 98 int i; 99 char exper = 'y', pc; 100 extern char readchar(); 101 if(flags.female) /* should have been set in HACKOPTIONS */ 102 roles[4] = "Cave-woman"; 103 for(i = 0; i < NR_OF_ROLES; i++) 104 rolesyms[i] = roles[i][0]; 105 rolesyms[i] = 0; 106 107 if(pc = pl_character[0]) { 108 if('a' <= pc && pc <= 'z') pc += 'A'-'a'; 109 if((i = role_index(pc)) >= 0) 110 goto got_suffix; /* implies experienced */ 111 printf("\nUnknown role: %c\n", pc); 112 pl_character[0] = pc = 0; 113 } 114 115 printf("\nAre you an experienced player? [ny] "); 116 117 while(!index("ynYN \n\004", (exper = readchar()))) 118 bell(); 119 if(exper == '\004') /* Give him an opportunity to get out */ 120 end_of_input(); 121 printf("%c\n", exper); /* echo */ 122 if(index("Nn \n", exper)) { 123 exper = 0; 124 goto beginner; 125 } 126 127 printf("\nTell me what kind of character you are:\n"); 128 printf("Are you"); 129 for(i = 0; i < NR_OF_ROLES; i++) { 130 printf(" a %s", roles[i]); 131 if(i == 2) /* %% */ 132 printf(",\n\t"); 133 else if(i < NR_OF_ROLES - 2) 134 printf(","); 135 else if(i == NR_OF_ROLES - 2) 136 printf(" or"); 137 } 138 printf("? [%s] ", rolesyms); 139 140 while(pc = readchar()) { 141 if('a' <= pc && pc <= 'z') pc += 'A'-'a'; 142 if((i = role_index(pc)) >= 0) { 143 printf("%c\n", pc); /* echo */ 144 (void) fflush(stdout); /* should be seen */ 145 break; 146 } 147 if(pc == '\n') 148 break; 149 if(pc == '\004') /* Give him the opportunity to get out */ 150 end_of_input(); 151 bell(); 152 } 153 if(pc == '\n') 154 pc = 0; 155 156 beginner: 157 if(!pc) { 158 printf("\nI'll choose a character for you.\n"); 159 i = rn2(NR_OF_ROLES); 160 pc = rolesyms[i]; 161 printf("This game you will be a%s %s.\n", 162 exper ? "n experienced" : "", 163 roles[i]); 164 getret(); 165 /* give him some feedback in case mklev takes much time */ 166 (void) putchar('\n'); 167 (void) fflush(stdout); 168 } 169 if(exper) { 170 roles[i][0] = pc; 171 } 172 173 got_suffix: 174 175 (void) strncpy(pl_character, roles[i], PL_CSIZ-1); 176 pl_character[PL_CSIZ-1] = 0; 177 flags.beginner = 1; 178 u = zerou; 179 u.usym = '@'; 180 u.ulevel = 1; 181 init_uhunger(); 182 #ifdef QUEST 183 u.uhorizon = 6; 184 #endif QUEST 185 uarm = uarm2 = uarmh = uarms = uarmg = uwep = uball = uchain = 186 uleft = uright = 0; 187 188 switch(pc) { 189 case 'c': 190 case 'C': 191 Cave_man[2].trquan = 12 + rnd(9)*rnd(9); 192 u.uhp = u.uhpmax = 16; 193 u.ustr = u.ustrmax = 18; 194 ini_inv(Cave_man); 195 break; 196 case 't': 197 case 'T': 198 Tourist[3].trquan = 20 + rnd(20); 199 u.ugold = u.ugold0 = rnd(1000); 200 u.uhp = u.uhpmax = 10; 201 u.ustr = u.ustrmax = 8; 202 ini_inv(Tourist); 203 if(!rn2(25)) ini_inv(Tinopener); 204 break; 205 case 'w': 206 case 'W': 207 for(i=1; i<=4; i++) if(!rn2(5)) 208 Wizard[i].trquan += rn2(3) - 1; 209 u.uhp = u.uhpmax = 15; 210 u.ustr = u.ustrmax = 16; 211 ini_inv(Wizard); 212 break; 213 case 's': 214 case 'S': 215 Fast = INTRINSIC; 216 Stealth = INTRINSIC; 217 u.uhp = u.uhpmax = 12; 218 u.ustr = u.ustrmax = 10; 219 ini_inv(Speleologist); 220 if(!rn2(10)) ini_inv(Tinopener); 221 break; 222 case 'k': 223 case 'K': 224 u.uhp = u.uhpmax = 12; 225 u.ustr = u.ustrmax = 10; 226 ini_inv(Knight); 227 break; 228 case 'f': 229 case 'F': 230 u.uhp = u.uhpmax = 14; 231 u.ustr = u.ustrmax = 17; 232 ini_inv(Fighter); 233 break; 234 default: /* impossible */ 235 u.uhp = u.uhpmax = 12; 236 u.ustr = u.ustrmax = 16; 237 } 238 find_ac(); 239 if(!rn2(20)) { 240 int d = rn2(7) - 2; /* biased variation */ 241 u.ustr += d; 242 u.ustrmax += d; 243 } 244 245 #ifdef WIZARD 246 if(wizard) wiz_inv(); 247 #endif WIZARD 248 249 /* make sure he can carry all he has - especially for T's */ 250 while(inv_weight() > 0 && u.ustr < 118) 251 u.ustr++, u.ustrmax++; 252 } 253 254 ini_inv(trop) struct trobj *trop; { 255 struct obj *obj; 256 extern struct obj *mkobj(); 257 while(trop->trolet) { 258 obj = mkobj(trop->trolet); 259 obj->known = trop->trknown; 260 /* not obj->dknown = 1; - let him look at it at least once */ 261 obj->cursed = 0; 262 if(obj->olet == WEAPON_SYM){ 263 obj->quan = trop->trquan; 264 trop->trquan = 1; 265 } 266 if(trop->trspe != UNDEF_SPE) 267 obj->spe = trop->trspe; 268 if(trop->trotyp != UNDEF_TYP) 269 obj->otyp = trop->trotyp; 270 else 271 if(obj->otyp == WAN_WISHING) /* gitpyr!robert */ 272 obj->otyp = WAN_DEATH; 273 obj->owt = weight(obj); /* defined after setting otyp+quan */ 274 obj = addinv(obj); 275 if(obj->olet == ARMOR_SYM){ 276 switch(obj->otyp){ 277 case SHIELD: 278 if(!uarms) setworn(obj, W_ARMS); 279 break; 280 case HELMET: 281 if(!uarmh) setworn(obj, W_ARMH); 282 break; 283 case PAIR_OF_GLOVES: 284 if(!uarmg) setworn(obj, W_ARMG); 285 break; 286 case ELVEN_CLOAK: 287 if(!uarm2) 288 setworn(obj, W_ARM); 289 break; 290 default: 291 if(!uarm) setworn(obj, W_ARM); 292 } 293 } 294 if(obj->olet == WEAPON_SYM) 295 if(!uwep) setuwep(obj); 296 #ifndef PYRAMID_BUG 297 if(--trop->trquan) continue; /* make a similar object */ 298 #else 299 if(trop->trquan) { /* check if zero first */ 300 --trop->trquan; 301 if(trop->trquan) 302 continue; /* make a similar object */ 303 } 304 #endif PYRAMID_BUG 305 trop++; 306 } 307 } 308 309 #ifdef WIZARD 310 wiz_inv(){ 311 struct trobj *trop = &Extra_objs[0]; 312 char *ep = getenv("INVENT"); 313 int type; 314 while(ep && *ep) { 315 type = atoi(ep); 316 ep = index(ep, ','); 317 if(ep) while(*ep == ',' || *ep == ' ') ep++; 318 if(type <= 0 || type > NROFOBJECTS) continue; 319 trop->trotyp = type; 320 trop->trolet = objects[type].oc_olet; 321 trop->trspe = 4; 322 trop->trknown = 1; 323 trop->trquan = 1; 324 ini_inv(trop); 325 } 326 /* give him a wand of wishing by default */ 327 trop->trotyp = WAN_WISHING; 328 trop->trolet = WAND_SYM; 329 trop->trspe = 20; 330 trop->trknown = 1; 331 trop->trquan = 1; 332 ini_inv(trop); 333 } 334 #endif WIZARD 335 336 plnamesuffix() { 337 char *p; 338 if(p = rindex(plname, '-')) { 339 *p = 0; 340 pl_character[0] = p[1]; 341 pl_character[1] = 0; 342 if(!plname[0]) { 343 askname(); 344 plnamesuffix(); 345 } 346 } 347 } 348 349 role_index(pc) 350 char pc; 351 { /* must be called only from u_init() */ 352 /* so that rolesyms[] is defined */ 353 char *cp; 354 355 if(cp = index(rolesyms, pc)) 356 return(cp - rolesyms); 357 return(-1); 358 } 359