Source:NetHack 3.1.0/u init.c

Below is the full text to u_init.c from the source code of NetHack 3.1.0. To link to a particular line, write [[NetHack 3.1.0/u_init.c#line123 ]], for example.

Warning! This is the source code from an old release. For the latest release, see Source code

1.   /*	SCCS Id: @(#)u_init.c	3.1	92/11/13	*/ 2.   /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ 3.    /* NetHack may be freely redistributed. See license for details. */ 4.     5.    #include "hack.h"  6. 7.   struct trobj { 8.   	unsigned short int trotyp; 9.   	schar trspe; 10.  	char trclass; 11.  	Bitfield(trquan,6); 12.  	Bitfield(trknown,1); 13.  	Bitfield(trbless,2); 14.  };  15.    16.   static void FDECL(ini_inv, (struct trobj *)); 17.  static void FDECL(knows_object,(int)); 18.  static void FDECL(knows_class,(CHAR_P)); 19.  static int FDECL(role_index,(CHAR_P)); 20.   21.   #define	UNDEF_TYP	0 22.  #define	UNDEF_SPE	'\177' 23.  #define	UNDEF_BLESS	2 24.   25.   /* all roles must all have distinct first letter */ 26.  const char *roles[] = {	/* also used in options.c and winxxx.c */ 27.  			/* roles[2] and [6] are changed for females */ 28.  			/* in all cases, the corresponding male and female */ 29.  			/* roles must start with the same letter */ 30.  	"Archeologist", "Barbarian", "Caveman", "Elf", "Healer", "Knight", 31.  	"Priest", "Rogue", "Samurai", 32.  #ifdef TOURIST 33.  	"Tourist", 34.  #endif 35.  	"Valkyrie", "Wizard", 0 36.  };  37.    38.   static struct trobj Cave_man[] = { 39.  #define C_ARROWS	2 40.  	{ CLUB, 1, WEAPON_CLASS, 1, 1, UNDEF_BLESS }, 41.  	{ BOW, 1, WEAPON_CLASS, 1, 1, UNDEF_BLESS }, 42.  	{ ARROW, 0, WEAPON_CLASS, 25, 1, UNDEF_BLESS },	/* quan is variable */ 43.  	{ LEATHER_ARMOR, 0, ARMOR_CLASS, 1, 1, UNDEF_BLESS }, 44.  	{ 0, 0, 0, 0, 0, 0 }  45.   };  46.    47.   static struct trobj Barbarian[] = { 48.  #define B_MAJOR 0	/* two-handed sword or battle-axe  */ 49.  #define B_MINOR 1	/* matched with axe or short sword */ 50.  	{ TWO_HANDED_SWORD, 0, WEAPON_CLASS, 1, 1, UNDEF_BLESS }, 51.  	{ AXE, 0, WEAPON_CLASS, 1, 1, UNDEF_BLESS }, 52.  	{ RING_MAIL, 0, ARMOR_CLASS, 1, 1, UNDEF_BLESS }, 53.  	{ FOOD_RATION, 0, FOOD_CLASS, 1, 1, 0 }, 54.  	{ 0, 0, 0, 0, 0, 0 }  55.   };  56.    57.   static struct trobj Knight[] = { 58.  	{ LONG_SWORD, 0, WEAPON_CLASS, 1, 1, UNDEF_BLESS }, 59.  	{ SPEAR, 2, WEAPON_CLASS, 1, 1, UNDEF_BLESS }, 60.  	{ RING_MAIL, 1, ARMOR_CLASS, 1, 1, UNDEF_BLESS }, 61.  	{ HELMET, 0, ARMOR_CLASS, 1, 1, UNDEF_BLESS }, 62.  	{ SMALL_SHIELD, 0, ARMOR_CLASS, 1, 1, UNDEF_BLESS }, 63.  	{ LEATHER_GLOVES, 0, ARMOR_CLASS, 1, 1, UNDEF_BLESS }, 64.  	{ 0, 0, 0, 0, 0, 0 }  65.   };  66.    67.   static struct trobj Elf[] = { 68.  #define E_ARROWS	2 69.  #define E_ARMOR		3 70.  	{ ELVEN_SHORT_SWORD, 0, WEAPON_CLASS, 1, 1, UNDEF_BLESS }, 71.  	{ ELVEN_BOW, 0, WEAPON_CLASS, 1, 1, UNDEF_BLESS }, 72.  	{ ELVEN_ARROW, 0, WEAPON_CLASS, 25, 1, UNDEF_BLESS }, 73.  	{ UNDEF_TYP, 0, ARMOR_CLASS, 1, 1, UNDEF_BLESS }, 74.  	{ LEMBAS_WAFER, 0, FOOD_CLASS, 2, 1, 0 }, 75.  	{ 0, 0, 0, 0, 0, 0 }  76.   };  77.    78.   static struct trobj Valkyrie[] = { 79.  	{ LONG_SWORD, 1, WEAPON_CLASS, 1, 1, UNDEF_BLESS }, 80.  	{ DAGGER, 0, WEAPON_CLASS, 1, 1, UNDEF_BLESS }, 81.  	{ SMALL_SHIELD, 3, ARMOR_CLASS, 1, 1, UNDEF_BLESS }, 82.  	{ FOOD_RATION, 0, FOOD_CLASS, 1, 1, 0 }, 83.  	{ 0, 0, 0, 0, 0, 0 }  84.   };  85.    86.   static struct trobj Healer[] = { 87.  	{ SCALPEL, 0, WEAPON_CLASS, 1, 1, UNDEF_BLESS }, 88.  	{ LEATHER_GLOVES, 1, ARMOR_CLASS, 1, 1, UNDEF_BLESS }, 89.  	{ STETHOSCOPE, 0, TOOL_CLASS, 1, 1, 0 }, 90.  	{ POT_HEALING, 0, POTION_CLASS, 4, 1, UNDEF_BLESS }, 91.  	{ POT_EXTRA_HEALING, 0, POTION_CLASS, 4, 1, UNDEF_BLESS }, 92.  	{ WAN_SLEEP, UNDEF_SPE, WAND_CLASS, 1, 1, UNDEF_BLESS }, 93.  	/* always blessed, so it's guaranteed readable */ 94.  	{ SPE_HEALING, 0, SPBOOK_CLASS, 1, 1, 1 }, 95.  	{ SPE_EXTRA_HEALING, 0, SPBOOK_CLASS, 1, 1, 1 }, 96.  	{ APPLE, 0, FOOD_CLASS, 5, 1, 0 }, 97.  	{ 0, 0, 0, 0, 0, 0 }  98.   };  99.    100.  static struct trobj Archeologist[] = { 101. 	/* if adventure has a name... idea from tan@uvm-gen */ 102. 	{ BULLWHIP, 2, WEAPON_CLASS, 1, 1, UNDEF_BLESS }, 103. 	{ LEATHER_JACKET, 0, ARMOR_CLASS, 1, 1, UNDEF_BLESS }, 104. 	{ FEDORA, 0, ARMOR_CLASS, 1, 1, UNDEF_BLESS }, 105. 	{ FOOD_RATION, 0, FOOD_CLASS, 3, 1, 0 }, 106. 	{ PICK_AXE, UNDEF_SPE, TOOL_CLASS, 1, 1, UNDEF_BLESS }, 107. 	{ TINNING_KIT, 0, TOOL_CLASS, 1, 1, UNDEF_BLESS }, 108. 	{ SACK, 0, TOOL_CLASS, 1, 0, 0 }, 109. 	{ 0, 0, 0, 0, 0, 0 }  110.  };  111.   112.  static struct trobj Tinopener[] = { 113. 	{ TIN_OPENER, 0, TOOL_CLASS, 1, 1, 0 }, 114. 	{ 0, 0, 0, 0, 0, 0 }  115.  };  116.   117.  static struct trobj Magicmarker[] = { 118. 	{ MAGIC_MARKER, UNDEF_SPE, TOOL_CLASS, 1, 1, 0 }, 119. 	{ 0, 0, 0, 0, 0, 0 }  120.  };  121.   122.  static struct trobj Lamp[] = { 123. 	{ OIL_LAMP, 1, TOOL_CLASS, 1, 1, 0 }, 124. 	{ 0, 0, 0, 0, 0, 0 }  125.  };  126.   127.  #ifdef TOURIST 128. # ifdef WALKIES 129. static struct trobj Leash[] = { 130. 	{ LEASH, 0, TOOL_CLASS, 1, 1, 0 }, 131. 	{ 0, 0, 0, 0, 0, 0 }  132.  };  133.  # endif 134.  135.  static struct trobj Towel[] = { 136. 	{ TOWEL, 0, TOOL_CLASS, 1, 1, 0 }, 137. 	{ 0, 0, 0, 0, 0, 0 }  138.  };  139.  #endif 140.  141.  #ifdef EXPLORE_MODE 142. static struct trobj Wishing[] = { 143. 	{ WAN_WISHING, 3, WAND_CLASS, 1, 1, 0 }, 144. 	{ 0, 0, 0, 0, 0, 0 }  145.  };  146.  #endif 147.  148.  static struct trobj Instrument[] = { 149. 	{ WOODEN_FLUTE, 0, TOOL_CLASS, 1, 1, 0 }, 150. 	{ 0, 0, 0, 0, 0, 0 }  151.  };  152.   153.  static struct trobj Blindfold[] = { 154. 	{ BLINDFOLD, 0, TOOL_CLASS, 1, 1, 0 }, 155. 	{ 0, 0, 0, 0, 0, 0 }  156.  };  157.   158.  #ifdef TOURIST 159. static struct trobj Tourist[] = { 160. #define	T_DARTS		0 161. 	{ DART, 2, WEAPON_CLASS, 25, 1, UNDEF_BLESS },	/* quan is variable */ 162. 	{ UNDEF_TYP, UNDEF_SPE, FOOD_CLASS, 10, 1, 0 }, 163. 	{ POT_EXTRA_HEALING, 0, POTION_CLASS, 2, 1, UNDEF_BLESS }, 164. 	{ SCR_MAGIC_MAPPING, 0, SCROLL_CLASS, 4, 1, UNDEF_BLESS }, 165. 	{ HAWAIIAN_SHIRT, 0, ARMOR_CLASS, 1, 1, UNDEF_BLESS }, 166. 	{ EXPENSIVE_CAMERA, 0, TOOL_CLASS, 1, 1, 0 }, 167. 	{ CREDIT_CARD, 0, TOOL_CLASS, 1, 1, 0 }, 168. 	{ 0, 0, 0, 0, 0, 0 }  169.  };  170.  #endif 171.  172.  static struct trobj Rogue[] = { 173. #define R_DAGGERS	1 174. 	{ SHORT_SWORD, 0, WEAPON_CLASS, 1, 1, UNDEF_BLESS }, 175. 	{ DAGGER, 0, WEAPON_CLASS, 10, 1, 0 },	/* quan is variable */ 176. 	{ LEATHER_ARMOR, 1, ARMOR_CLASS, 1, 1, UNDEF_BLESS }, 177. 	{ POT_SICKNESS, 0, POTION_CLASS, 1, 1, 0 }, 178. 	{ LOCK_PICK, 9, TOOL_CLASS, 1, 1, 0 }, 179. 	{ SACK, 0, TOOL_CLASS, 1, 0, 0 }, 180. 	{ 0, 0, 0, 0, 0, 0 }  181.  };  182.   183.  static struct trobj Wizard[] = { 184. #define W_MULTSTART	2 185. #define W_MULTEND	6 186. 	{ ATHAME, 1, WEAPON_CLASS, 1, 1, 1 },	/* for dealing with ghosts */ 187. 	{ CLOAK_OF_MAGIC_RESISTANCE, 0, ARMOR_CLASS, 1, 1, UNDEF_BLESS }, 188. 	{ UNDEF_TYP, UNDEF_SPE, WAND_CLASS, 1, 1, UNDEF_BLESS }, 189. 	{ UNDEF_TYP, UNDEF_SPE, RING_CLASS, 2, 1, UNDEF_BLESS }, 190. 	{ UNDEF_TYP, UNDEF_SPE, POTION_CLASS, 3, 1, UNDEF_BLESS }, 191. 	{ UNDEF_TYP, UNDEF_SPE, SCROLL_CLASS, 3, 1, UNDEF_BLESS }, 192. 	{ UNDEF_TYP, UNDEF_SPE, SPBOOK_CLASS, 1, 1, UNDEF_BLESS }, 193. 	{ 0, 0, 0, 0, 0, 0 }  194.  };  195.   196.  static struct trobj Samurai[] = { 197. #define S_ARROWS	3 198. 	{ KATANA, 0, WEAPON_CLASS, 1, 1, UNDEF_BLESS }, 199. 	{ SHORT_SWORD, 0, WEAPON_CLASS, 1, 1, UNDEF_BLESS }, /* wakizashi */ 200. 	{ YUMI, 0, WEAPON_CLASS, 1, 1, UNDEF_BLESS }, 201. 	{ YA, 0, WEAPON_CLASS, 25, 1, UNDEF_BLESS }, /* variable quan */ 202. 	{ SPLINT_MAIL, 0, ARMOR_CLASS, 1, 1, UNDEF_BLESS }, 203. 	{ FORTUNE_COOKIE, 0, FOOD_CLASS, 3, 1, 0 }, 204. 	{ 0, 0, 0, 0, 0, 0 }  205.  };  206.   207.  static struct trobj Priest[] = { 208. 	{ MACE, 1, WEAPON_CLASS, 1, 1, 1 }, 209. 	{ CHAIN_MAIL, 0, ARMOR_CLASS, 1, 1, UNDEF_BLESS }, 210. 	{ SMALL_SHIELD, 0, ARMOR_CLASS, 1, 1, UNDEF_BLESS }, 211. 	{ POT_WATER, 0, POTION_CLASS, 4, 1, 1 },	/* holy water */ 212. 	{ CLOVE_OF_GARLIC, 0, FOOD_CLASS, 1, 1, 0 }, 213. 	{ SPRIG_OF_WOLFSBANE, 0, FOOD_CLASS, 1, 1, 0 }, 214. 	{ UNDEF_TYP, UNDEF_SPE, SPBOOK_CLASS, 2, 1, UNDEF_BLESS }, 215. 	{ 0, 0, 0, 0, 0, 0 }  216.  };  217.   218.  static void 219. knows_object(obj) 220. register int obj; 221. {  222.  	makeknown(obj); 223. 	objects[obj].oc_descr_idx = 0;		/* not a "discovery" */ 224. }  225.   226.  /* Know ordinary (non-magical) objects of a certain class, 227.  * like all gems except the loadstone and luckstone. 228.  */  229.  static void 230. knows_class(sym) 231. register char sym; 232. {  233.  	register int ct; 234. 	for (ct = 1; ct <= NROFOBJECTS; ct++) 235. 		if (objects[ct].oc_class == sym && !objects[ct].oc_magic) 236. 			knows_object(ct); 237. }  238.   239.  static int 240. role_index(pc) 241. char pc; 242. {  243.  	register const char *cp; 244.  245.  	if ((cp = index(pl_classes, pc)) != 0) 246. 		return(cp - pl_classes); 247. 	return(-1); 248. }  249.   250.  void 251. u_init 252. {  253.  	register int i;  254. char pc; 255.  256.  	pc = pl_character[0]; 257. 	if(pc == '\0') { 258. 	    /* should be unnecessary now */ 259. 	    exit_nhwindows(NULL); 260. 	    terminate(0); 261. 	}  262.  	i = role_index(pc); 263.  264.  	(void) strncpy(pl_character, roles[i], PL_CSIZ-1); 265. 	pl_character[PL_CSIZ-1] = 0; 266. 	flags.beginner = 1; 267.  268.  	/* zero u, including pointer values -- 269. 	 * necessary when aborting from a failed restore */ 270. 	(void) memset((genericptr_t)&u, 0, sizeof(u)); 271. 	for (i = 0; i < LAST_PROP+1; i++) u.uprops[i].p_tofn = 0; 272. 	u.ustuck = (struct monst *)0; 273.  274.  #if 0	/* documentation of more zero values as desirable */ 275. 	u.uluck  = u.moreluck = 0; 276. # ifdef TOURIST 277. 	uarmu = 0; 278. # endif 279. 	uarm = uarmc = uarmh = uarms = uarmg = uarmf = 0; 280. 	uwep = uball = uchain = uleft = uright = 0; 281. 	u.ublessed = 0;				/* not worthy yet */ 282. 	u.ugangr   = 0;				/* gods not angry */ 283. # ifdef ELBERETH 284. 	u.uevent.uhand_of_elbereth = 0; 285. # endif 286. 	u.uevent.uheard_tune = 0; 287. 	u.uevent.uopened_dbridge = 0; 288. 	u.uevent.udemigod = 0;		/* not a demi-god yet... */ 289.  	u.udg_cnt = 0; 290. # ifdef POLYSELF 291. 	u.mh = u.mhmax = u.mtimedone = 0; 292. # endif 293. 	u.uz.dnum = u.uz0.dnum = 0; 294. 	u.utotype = 0; 295. #endif	/* 0 */ 296. 	u.uz.dlevel = u.uz0.dlevel = 1; 297. 	u.utolev = u.uz; 298.  299.  	u.usym = S_HUMAN; 300. 	u.umoved = FALSE; 301. 	u.ugrave_arise = -1; 302.  303.  	u.ulevel = 0;	/* set up some of the initial attributes */ 304. 	u.uhp = u.uhpmax = newhp; 305. 	adjabil(0,1); 306. 	u.ulevel = 1; 307.  308.  	init_uhunger; 309. 	u.uen = u.uenmax = 1; 310. 	for (i = 0; i <= MAXSPELL; i++) spl_book[i].sp_id = NO_SPELL; 311. 	u.ublesscnt = 300;			/* no prayers just yet */ 312. #ifdef POLYSELF 313. 	u.umonnum = -1; 314. 	u.ulycn = -1; 315. 	set_uasmon; 316. #endif 317.  318.  	/*  319.  	 *  For now, everyone starts out with a night vision range of 1 and 320. 	 *  their xray range disabled. 321. 	 */  322.  	u.nv_range   =  1; 323. 	u.xray_range = -1; 324.  325.   326.  	switch(pc) { 327. 	/* pc will always be in uppercase by this point */ 328. 	case 'A': 329. 		u.umonster = PM_ARCHEOLOGIST; 330. 		ini_inv(Archeologist); 331. 		if(!rn2(10)) ini_inv(Tinopener); 332. 		else if(!rn2(4)) ini_inv(Lamp); 333. 		else if(!rn2(10)) ini_inv(Magicmarker); 334. 		knows_class(GEM_CLASS); 335. 		knows_object(SACK); 336. 		/* We can't set trknown for it, then it'd be "uncursed" 337. 		 * sack...  338. */ 339.  		break; 340. 	case 'B': 341. 		u.umonster = PM_BARBARIAN; 342. 		if (rn2(100) >= 50) {	/* see Elf comment */ 343. 		    Barbarian[B_MAJOR].trotyp = BATTLE_AXE; 344. 		    Barbarian[B_MINOR].trotyp = SHORT_SWORD; 345. 		}  346.  		ini_inv(Barbarian); 347. 		if(!rn2(6)) ini_inv(Lamp); 348. 		knows_class(WEAPON_CLASS); 349. 		knows_class(ARMOR_CLASS); 350. 		break; 351. 	case 'C': 352. 		u.umonster = PM_CAVEMAN; 353. 		Cave_man[C_ARROWS].trquan = rn1(30, 13); 354. 		ini_inv(Cave_man); 355. 		break; 356. 	case 'E': 357. 		u.umonster = PM_ELF; 358. 		Elf[E_ARROWS].trquan = rn1(20, 16); 359. 		Elf[E_ARMOR].trotyp = ((rn2(100) >= 50)  360.  				 ? ELVEN_MITHRIL_COAT : ELVEN_CLOAK); 361. 			/* rn2(100) > 50 necessary because some random number 362. 			 * generators are bad enough to seriously skew the 363. 			 * results if we use rn2(2)... --KAA 364. 			 */  365.   366.  		/*  367.  		 * Elves are people of music and song, or they are warriors. 368. 		 * Warriors get mithril coats; non-warriors MAY get an  369. * instrument. We use a kludge to get only non-magic 370. 		 * instruments. 371. 		 */  372.  		if (Elf[E_ARMOR].trotyp == ELVEN_CLOAK) { 373. 			if (!rn2(5)) { 374. 		    	static int trotyp[] = { 375. 					WOODEN_FLUTE, TOOLED_HORN, WOODEN_HARP, 376. 					BELL, BUGLE, LEATHER_DRUM 377. 				};  378.   379.  				Instrument[0].trotyp = trotyp[rn2(SIZE(trotyp))]; 380. #ifdef DEBUG 381. 				debugpline("Elf got instrument %d",  382.  					Instrument[0].trotyp); 383. #endif 384. 				ini_inv(Instrument); 385. 			}  386.  		}  387.  		ini_inv(Elf); 388. 		if(!rn2(5)) ini_inv(Blindfold); 389. 		else if(!rn2(6)) ini_inv(Lamp); 390. 		knows_object(ELVEN_SHORT_SWORD); 391. 		knows_object(ELVEN_ARROW); 392. 		knows_object(ELVEN_BOW); 393. 		knows_object(ELVEN_SPEAR); 394. 		knows_object(ELVEN_DAGGER); 395. 		knows_object(ELVEN_BROADSWORD); 396. 		knows_object(ELVEN_MITHRIL_COAT); 397. 		knows_object(ELVEN_LEATHER_HELM); 398. 		knows_object(ELVEN_SHIELD); 399. 		knows_object(ELVEN_BOOTS); 400. 		knows_object(ELVEN_CLOAK); 401. 		break; 402. 	case 'H': 403. 		u.umonster = PM_HEALER; 404. 		u.ugold = u.ugold0 = rn1(1000, 1001); 405. 		ini_inv(Healer); 406. 		if(!rn2(25)) ini_inv(Lamp); 407. 		break; 408. 	case 'K': 409. 		u.umonster = PM_KNIGHT; 410. 		ini_inv(Knight); 411. 		knows_class(WEAPON_CLASS); 412. 		knows_class(ARMOR_CLASS); 413. 		/* give knights chess-like mobility 414. 		 * -- idea from wooledge@skybridge.scl.cwru.edu */ 415. 		Jumping |= FROMOUTSIDE; 416. 		break; 417. 	case 'P': 418. 		u.umonster = PM_PRIEST; 419. 		u.uen = u.uenmax += rn2(4); 420. 		ini_inv(Priest); 421. 		if(!rn2(10)) ini_inv(Magicmarker); 422. 		else if(!rn2(10)) ini_inv(Lamp); 423. 		knows_object(POT_WATER); 424. 		break; 425. 	case 'R': 426. 		u.umonster = PM_ROGUE; 427. 		Rogue[R_DAGGERS].trquan = rn1(10, 6); 428. 		u.ugold = u.ugold0 = 0; 429. 		ini_inv(Rogue); 430. 		if(!rn2(5)) ini_inv(Blindfold); 431. 		knows_object(SACK); 432. 		break; 433. 	case 'S': 434. 		u.umonster = PM_SAMURAI; 435. 		Samurai[S_ARROWS].trquan = rn1(20, 26); 436. 		ini_inv(Samurai); 437. 		if(!rn2(5)) ini_inv(Blindfold); 438. 		knows_class(WEAPON_CLASS); 439. 		knows_class(ARMOR_CLASS); 440. 		break; 441. #ifdef TOURIST 442. 	case 'T': 443. 		u.umonster = PM_TOURIST; 444. 		Tourist[T_DARTS].trquan = rn1(20, 21); 445. 		u.ugold = u.ugold0 = rnd(1000); 446. 		ini_inv(Tourist); 447. 		if(!rn2(25)) ini_inv(Tinopener); 448. #ifdef WALKIES 449. 		else if(!rn2(25)) ini_inv(Leash); 450. #endif 451. 		else if(!rn2(25)) ini_inv(Towel); 452. 		else if(!rn2(25)) ini_inv(Magicmarker); 453. 		break; 454. #endif 455. 	case 'V': 456. 		u.umonster = PM_VALKYRIE; 457. 		flags.female = TRUE; 458. 		ini_inv(Valkyrie); 459. 		if(!rn2(6)) ini_inv(Lamp); 460. 		knows_class(WEAPON_CLASS); 461. 		knows_class(ARMOR_CLASS); 462. 		break; 463. 	case 'W': 464. 		u.umonster = PM_WIZARD; 465. 		u.uen = u.uenmax += rn2(4); 466. 		ini_inv(Wizard); 467. 		if(!rn2(5)) ini_inv(Magicmarker); 468. 		if(!rn2(5)) ini_inv(Blindfold); 469. 		break; 470.  471.  	default:	/* impossible */ 472. 		break; 473. 	}  474.  #ifdef EXPLORE_MODE 475. 	if (discover) 476. 		ini_inv(Wishing); 477. #endif 478. 	find_ac;			/* get initial ac value */ 479. 	init_attr(75);			/* init attribute values */ 480. 	max_rank_sz;			/* set max str size for class ranks */ 481. /*  482.   *	Do we really need this? 483.  */  484.  	for(i = 0; i < A_MAX; i++) 485. 	    if(!rn2(20)) { 486. 		register int xd = rn2(7) - 2;	/* biased variation */ 487. 		(void) adjattrib(i, xd, TRUE); 488. 		if (ABASE(i) < AMAX(i)) AMAX(i) = ABASE(i); 489. 	    }  490.   491.  	/* make sure you can carry all you have - especially for Tourists */ 492. 	while(inv_weight > 0 && ACURR(A_STR) < 118) 493. 		(void) adjattrib(A_STR, 1, TRUE); 494.  495.  	u.ualignbase[0] = u.ualignbase[1] = u.ualign.type; 496. }  497.   498.  static void 499. ini_inv(trop) 500. register struct trobj *trop; 501. {  502.  	struct obj *obj; 503. 	while(trop->trclass) { 504. 		boolean undefined = (trop->trotyp == UNDEF_TYP); 505.  506.  		if (!undefined) 507. 			obj = mksobj((int)trop->trotyp, TRUE, FALSE); 508. 		else obj = mkobj(trop->trclass,FALSE); 509.  510.  		/* For random objects, do not create certain overly powerful 511. 		 * items: wand of wishing, ring of levitation, or the 512. 		 * polymorph/polymorph control combination. Specific objects, 513. 		 * i.e. the discovery wishing, are still OK. 514. 		 * Also, don't get a couple of really useless items. (Note: 515.  		 * punishment isn't "useless".  Some players who start out with  516.  		 * one will immediately read it and use the iron ball as a  517.  		 * weapon.) 518. 		 */  519.  		if (undefined) { 520. #ifdef POLYSELF 521. 			static unsigned NEARDATA nocreate = STRANGE_OBJECT; 522. 			static unsigned NEARDATA nocreate2 = STRANGE_OBJECT; 523. #endif 524. 			static unsigned NEARDATA nocreate3 = STRANGE_OBJECT; 525.  526.  			while(obj->otyp == WAN_WISHING  527.  #ifdef POLYSELF  528.  				|| obj->otyp == nocreate  529.  				|| obj->otyp == nocreate2  530.  #endif  531.  				|| obj->otyp == nocreate3  532.  #ifdef ELBERETH  533.  				|| obj->otyp == RIN_LEVITATION  534.  #endif  535.  				/* 'useless' items */  536.  				|| obj->otyp == POT_HALLUCINATION  537.  				|| obj->otyp == SCR_AMNESIA  538.  				|| obj->otyp == SCR_FIRE  539.  				|| obj->otyp == RIN_AGGRAVATE_MONSTER  540.  				|| obj->otyp == RIN_HUNGER  541.  				|| obj->otyp == WAN_NOTHING  542.  				/* powerful spells are either useless to  543.  				   low level players or unbalancing */  544.  				|| (obj->oclass == SPBOOK_CLASS && 545. 				    objects[obj->otyp].oc_level > 3)  546.  							) { 547. 				dealloc_obj(obj); 548. 				obj = mkobj(trop->trclass, FALSE); 549. 			}  550.   551.  			/* Don't start with +0 or negative rings */ 552. 			if(objects[obj->otyp].oc_charged && obj->spe <= 0) 553. 				obj->spe = rne(3); 554.  555.  			/* Heavily relies on the fact that 1) we create wands  556.  			 * before rings, 2) that we create rings before 557. 			 * spellbooks, and that 3) not more than 1 object of a  558.  			 * particular symbol is to be prohibited.  (For more 559. 			 * objects, we need more nocreate variables...)  560.  			 */  561.  #ifdef POLYSELF  562.  			switch (obj->otyp) {  563.  			    case WAN_POLYMORPH:  564.  			    case RIN_POLYMORPH:  565.  				nocreate = RIN_POLYMORPH_CONTROL;  566.  				break;  567.  			    case RIN_POLYMORPH_CONTROL:  568.  				nocreate = RIN_POLYMORPH;  569.  				nocreate2 = SPE_POLYMORPH;  570.  			}  571.  #endif /* POLYSELF */  572.  			/* Don't have 2 of the same ring */  573.  			if (obj->oclass == RING_CLASS)  574.  				nocreate3 = obj->otyp;  575.  		}  576.   577.  		obj->bknown = trop->trknown;  578.  		if(objects[obj->otyp].oc_uses_known) obj->known = trop->trknown;  579.  		/* not obj->dknown = 1; - let him look at it at least once */  580.  		obj->cursed = 0;  581.  		if(obj->oclass == WEAPON_CLASS || obj->oclass == TOOL_CLASS) {  582.  			obj->quan = (long) trop->trquan;  583.  			trop->trquan = 1; 584. 		}  585.  		if(obj->oclass == FOOD_CLASS && undefined) { 586. 			obj->known = 1; 587. 			/* needed for tins and eggs; harmless otherwise */ 588. 			obj->bknown = 1; 589. 		}  590.  		/*  591.  		 * The below lines not needed because they don't correspond 592. 		 * to any actual inventory; nobody gets random tools. 593. 		else if(obj->oclass == TOOL_CLASS && undefined) { 594. 			obj->bknown = (obj->otyp != BAG_OF_TRICKS  595.  				&& obj->otyp != SACK  596.  				&& obj->otyp != CHEST  597.  				&& obj->otyp != LARGE_BOX  598.  				&& obj->otyp != ICE_BOX); 599. 		}  600.  		*/  601.  		if(trop->trspe != UNDEF_SPE) 602. 			obj->spe = trop->trspe; 603. 		if(trop->trbless != UNDEF_BLESS) 604. 			obj->blessed = trop->trbless; 605.  606.  		/* defined after setting otyp+quan + blessedness */ 607. 		obj->owt = weight(obj); 608. 		obj = addinv(obj); 609.  610.  		/* Make the type known if necessary */ 611. 		if (OBJ_DESCR(objects[obj->otyp]) && obj->known) 612. 			makeknown(obj->otyp); 613.  614.  		if(obj->oclass == ARMOR_CLASS){ 615. 			if (is_shield(obj) && !uarms) 616. 				setworn(obj, W_ARMS); 617. 			else if (is_helmet(obj) && !uarmh) 618. 				setworn(obj, W_ARMH); 619. 			else if (is_gloves(obj) && !uarmg) 620. 				setworn(obj, W_ARMG); 621. #ifdef TOURIST 622. 			else if (obj->otyp == HAWAIIAN_SHIRT && !uarmu) 623. 				setworn(obj, W_ARMU); 624. #endif 625. 			else if (is_cloak(obj) && !uarmc) 626. 				setworn(obj, W_ARMC); 627. 			else if (is_boots(obj) && !uarmf) 628. 				setworn(obj, W_ARMF); 629. 			else if (!uarm) 630. 				setworn(obj, W_ARM); 631. 		}  632.  		/* below changed by GAN 01/09/87 to allow wielding of  633. * pick-axe or can-opener if there is no weapon 634. 		 */  635.  		if(obj->oclass == WEAPON_CLASS || obj->otyp == PICK_AXE ||  636.  		   obj->otyp == TIN_OPENER) 637. 			if(!uwep) setuwep(obj); 638. #if !defined(PYRAMID_BUG) && !defined(MAC) 639. 		if(--trop->trquan) continue;	/* make a similar object */ 640. #else 641. 		if(trop->trquan) {		/* check if zero first */ 642. 			--trop->trquan; 643. 			if(trop->trquan) 644. 				continue;	/* make a similar object */ 645. 		}  646.  #endif 647. 		trop++; 648. 	}  649.  }  650.   651.  void 652. plnamesuffix { 653. 	register char *p; 654. 	if ((p = rindex(plname, '-')) != 0) { 655. 		*p = 0; 656. 		pl_character[0] = p[1]; 657. 		pl_character[1] = 0; 658. 		if(!plname[0]) { 659. 			askname; 660. 			plnamesuffix; 661. 		}  662.  	}  663.  }  664.   665.  /*u_init.c*/