Source:NetHack 3.2.0/u init.c

Below is the full text to u_init.c from the source code of NetHack 3.2.0. To link to a particular line, write [[NetHack 3.2.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.2	95/12/16	*/ 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.   	short trotyp; 9.   	schar trspe; 10.  	char trclass; 11.  	Bitfield(trquan,6); 12.  	Bitfield(trbless,2); 13.  };  14.    15.   static void FDECL(ini_inv, (struct trobj *)); 16.  static void FDECL(knows_object,(int)); 17.  static void FDECL(knows_class,(CHAR_P)); 18.  static int FDECL(role_index,(CHAR_P)); 19.   20.   #define UNDEF_TYP	0 21.  #define UNDEF_SPE	'\177' 22.  #define UNDEF_BLESS	2 23.   24.   static boolean random_role = FALSE; 25.   26.   /* all roles must all have distinct first letter */ 27.  const char *roles[] = {	/* also used in options.c and winxxx.c */ 28.  			/* roles[2] and [6] are changed for females */ 29.  			/* in all cases, the corresponding male and female */ 30.  			/* roles must start with the same letter */ 31.  	"Archeologist", "Barbarian", "Caveman", "Elf", "Healer", "Knight", 32.  	"Priest", "Rogue", "Samurai", 33.  #ifdef TOURIST 34.  	"Tourist", 35.  #endif 36.  	"Valkyrie", "Wizard", 0 37.  };  38.    39.   /*  40.    *	Initial inventory for the various roles. 41.   */  42.    43.   static struct trobj Archeologist[] = { 44.  	/* if adventure has a name... idea from tan@uvm-gen */ 45.  	{ BULLWHIP, 2, WEAPON_CLASS, 1, UNDEF_BLESS }, 46.  	{ LEATHER_JACKET, 0, ARMOR_CLASS, 1, UNDEF_BLESS }, 47.  	{ FEDORA, 0, ARMOR_CLASS, 1, UNDEF_BLESS }, 48.  	{ FOOD_RATION, 0, FOOD_CLASS, 3, 0 }, 49.  	{ PICK_AXE, UNDEF_SPE, TOOL_CLASS, 1, UNDEF_BLESS }, 50.  	{ TINNING_KIT, 0, TOOL_CLASS, 1, UNDEF_BLESS }, 51.  	{ SACK, 0, TOOL_CLASS, 1, 0 }, 52.  	{ 0, 0, 0, 0, 0 }  53.   };  54.   static struct trobj Barbarian[] = { 55.  #define B_MAJOR	0	/* two-handed sword or battle-axe  */ 56.  #define B_MINOR	1	/* matched with axe or short sword */ 57.  	{ TWO_HANDED_SWORD, 0, WEAPON_CLASS, 1, UNDEF_BLESS }, 58.  	{ AXE, 0, WEAPON_CLASS, 1, UNDEF_BLESS }, 59.  	{ RING_MAIL, 0, ARMOR_CLASS, 1, UNDEF_BLESS }, 60.  	{ FOOD_RATION, 0, FOOD_CLASS, 1, 0 }, 61.  	{ 0, 0, 0, 0, 0 }  62.   };  63.   static struct trobj Cave_man[] = { 64.  #define C_ARROWS	2 65.  	{ CLUB, 1, WEAPON_CLASS, 1, UNDEF_BLESS }, 66.  	{ BOW, 1, WEAPON_CLASS, 1, UNDEF_BLESS }, 67.  	{ ARROW, 0, WEAPON_CLASS, 25, UNDEF_BLESS },	/* quan is variable */ 68.  	{ LEATHER_ARMOR, 0, ARMOR_CLASS, 1, UNDEF_BLESS }, 69.  	{ 0, 0, 0, 0, 0 }  70.   };  71.   static struct trobj Elf[] = { 72.  #define E_ARROWS	2 73.  #define E_ARMOR		3 74.  	{ ELVEN_SHORT_SWORD, 0, WEAPON_CLASS, 1, UNDEF_BLESS }, 75.  	{ ELVEN_BOW, 0, WEAPON_CLASS, 1, UNDEF_BLESS }, 76.  	{ ELVEN_ARROW, 0, WEAPON_CLASS, 25, UNDEF_BLESS }, 77.  	{ UNDEF_TYP, 0, ARMOR_CLASS, 1, UNDEF_BLESS }, 78.  	{ LEMBAS_WAFER, 0, FOOD_CLASS, 2, 0 }, 79.  	{ 0, 0, 0, 0, 0 }  80.   };  81.   static struct trobj Healer[] = { 82.  	{ SCALPEL, 0, WEAPON_CLASS, 1, UNDEF_BLESS }, 83.  	{ LEATHER_GLOVES, 1, ARMOR_CLASS, 1, UNDEF_BLESS }, 84.  	{ STETHOSCOPE, 0, TOOL_CLASS, 1, 0 }, 85.  	{ POT_HEALING, 0, POTION_CLASS, 4, UNDEF_BLESS }, 86.  	{ POT_EXTRA_HEALING, 0, POTION_CLASS, 4, UNDEF_BLESS }, 87.  	{ WAN_SLEEP, UNDEF_SPE, WAND_CLASS, 1, UNDEF_BLESS }, 88.  	/* always blessed, so it's guaranteed readable */ 89.  	{ SPE_HEALING, 0, SPBOOK_CLASS, 1, 1 }, 90.  	{ SPE_EXTRA_HEALING, 0, SPBOOK_CLASS, 1, 1 }, 91.  	{ APPLE, 0, FOOD_CLASS, 5, 0 }, 92.  	{ 0, 0, 0, 0, 0 }  93.   };  94.   static struct trobj Knight[] = { 95.  	{ LONG_SWORD, 0, WEAPON_CLASS, 1, UNDEF_BLESS }, 96.  	{ SPEAR, 2, WEAPON_CLASS, 1, UNDEF_BLESS }, 97.  	{ RING_MAIL, 1, ARMOR_CLASS, 1, UNDEF_BLESS }, 98.  	{ HELMET, 0, ARMOR_CLASS, 1, UNDEF_BLESS }, 99.  	{ SMALL_SHIELD, 0, ARMOR_CLASS, 1, UNDEF_BLESS }, 100. 	{ LEATHER_GLOVES, 0, ARMOR_CLASS, 1, UNDEF_BLESS }, 101. 	{ 0, 0, 0, 0, 0 }  102.  };  103.  static struct trobj Priest[] = { 104. 	{ MACE, 1, WEAPON_CLASS, 1, 1 }, 105. 	{ CHAIN_MAIL, 0, ARMOR_CLASS, 1, UNDEF_BLESS }, 106. 	{ SMALL_SHIELD, 0, ARMOR_CLASS, 1, UNDEF_BLESS }, 107. 	{ POT_WATER, 0, POTION_CLASS, 4, 1 },	/* holy water */ 108. 	{ CLOVE_OF_GARLIC, 0, FOOD_CLASS, 1, 0 }, 109. 	{ SPRIG_OF_WOLFSBANE, 0, FOOD_CLASS, 1, 0 }, 110. 	{ UNDEF_TYP, UNDEF_SPE, SPBOOK_CLASS, 2, UNDEF_BLESS }, 111. 	{ 0, 0, 0, 0, 0 }  112.  };  113.  static struct trobj Rogue[] = { 114. #define R_DAGGERS	1 115. 	{ SHORT_SWORD, 0, WEAPON_CLASS, 1, UNDEF_BLESS }, 116. 	{ DAGGER, 0, WEAPON_CLASS, 10, 0 },	/* quan is variable */ 117. 	{ LEATHER_ARMOR, 1, ARMOR_CLASS, 1, UNDEF_BLESS }, 118. 	{ POT_SICKNESS, 0, POTION_CLASS, 1, 0 }, 119. 	{ LOCK_PICK, 9, TOOL_CLASS, 1, 0 }, 120. 	{ SACK, 0, TOOL_CLASS, 1, 0 }, 121. 	{ 0, 0, 0, 0, 0 }  122.  };  123.  static struct trobj Samurai[] = { 124. #define S_ARROWS	3 125. 	{ KATANA, 0, WEAPON_CLASS, 1, UNDEF_BLESS }, 126. 	{ SHORT_SWORD, 0, WEAPON_CLASS, 1, UNDEF_BLESS }, /* wakizashi */ 127. 	{ YUMI, 0, WEAPON_CLASS, 1, UNDEF_BLESS }, 128. 	{ YA, 0, WEAPON_CLASS, 25, UNDEF_BLESS }, /* variable quan */ 129. 	{ SPLINT_MAIL, 0, ARMOR_CLASS, 1, UNDEF_BLESS }, 130. 	{ FORTUNE_COOKIE, 0, FOOD_CLASS, 3, 0 }, 131. 	{ 0, 0, 0, 0, 0 }  132.  };  133.  #ifdef TOURIST 134. static struct trobj Tourist[] = { 135. #define T_DARTS		0 136. 	{ DART, 2, WEAPON_CLASS, 25, UNDEF_BLESS },	/* quan is variable */ 137. 	{ UNDEF_TYP, UNDEF_SPE, FOOD_CLASS, 10, 0 }, 138. 	{ POT_EXTRA_HEALING, 0, POTION_CLASS, 2, UNDEF_BLESS }, 139. 	{ SCR_MAGIC_MAPPING, 0, SCROLL_CLASS, 4, UNDEF_BLESS }, 140. 	{ HAWAIIAN_SHIRT, 0, ARMOR_CLASS, 1, UNDEF_BLESS }, 141. 	{ EXPENSIVE_CAMERA, 0, TOOL_CLASS, 1, 0 }, 142. 	{ CREDIT_CARD, 0, TOOL_CLASS, 1, 0 }, 143. 	{ 0, 0, 0, 0, 0 }  144.  };  145.  #endif 146. static struct trobj Valkyrie[] = { 147. 	{ LONG_SWORD, 1, WEAPON_CLASS, 1, UNDEF_BLESS }, 148. 	{ DAGGER, 0, WEAPON_CLASS, 1, UNDEF_BLESS }, 149. 	{ SMALL_SHIELD, 3, ARMOR_CLASS, 1, UNDEF_BLESS }, 150. 	{ FOOD_RATION, 0, FOOD_CLASS, 1, 0 }, 151. 	{ 0, 0, 0, 0, 0 }  152.  };  153.  static struct trobj Wizard[] = { 154. #define W_MULTSTART	2 155. #define W_MULTEND	6 156. 	{ ATHAME, 1, WEAPON_CLASS, 1, 1 },	/* for dealing with ghosts */ 157. 	{ CLOAK_OF_MAGIC_RESISTANCE, 0, ARMOR_CLASS, 1, UNDEF_BLESS }, 158. 	{ UNDEF_TYP, UNDEF_SPE, WAND_CLASS, 1, UNDEF_BLESS }, 159. 	{ UNDEF_TYP, UNDEF_SPE, RING_CLASS, 2, UNDEF_BLESS }, 160. 	{ UNDEF_TYP, UNDEF_SPE, POTION_CLASS, 3, UNDEF_BLESS }, 161. 	{ UNDEF_TYP, UNDEF_SPE, SCROLL_CLASS, 3, UNDEF_BLESS }, 162. 	{ UNDEF_TYP, UNDEF_SPE, SPBOOK_CLASS, 1, UNDEF_BLESS }, 163. 	{ 0, 0, 0, 0, 0 }  164.  };  165.   166.  /*  167.   *	Optional extra inventory items. 168.  */  169.   170.  static struct trobj Tinopener[] = { 171. 	{ TIN_OPENER, 0, TOOL_CLASS, 1, 0 }, 172. 	{ 0, 0, 0, 0, 0 }  173.  };  174.  static struct trobj Magicmarker[] = { 175. 	{ MAGIC_MARKER, UNDEF_SPE, TOOL_CLASS, 1, 0 }, 176. 	{ 0, 0, 0, 0, 0 }  177.  };  178.  static struct trobj Lamp[] = { 179. 	{ OIL_LAMP, 1, TOOL_CLASS, 1, 0 }, 180. 	{ 0, 0, 0, 0, 0 }  181.  };  182.  static struct trobj Blindfold[] = { 183. 	{ BLINDFOLD, 0, TOOL_CLASS, 1, 0 }, 184. 	{ 0, 0, 0, 0, 0 }  185.  };  186.  static struct trobj Instrument[] = { 187. 	{ WOODEN_FLUTE, 0, TOOL_CLASS, 1, 0 }, 188. 	{ 0, 0, 0, 0, 0 }  189.  };  190.  #ifdef TOURIST 191. static struct trobj Leash[] = { 192. 	{ LEASH, 0, TOOL_CLASS, 1, 0 }, 193. 	{ 0, 0, 0, 0, 0 }  194.  };  195.  static struct trobj Towel[] = { 196. 	{ TOWEL, 0, TOOL_CLASS, 1, 0 }, 197. 	{ 0, 0, 0, 0, 0 }  198.  };  199.  #endif	/* TOURIST */ 200. static struct trobj Wishing[] = { 201. 	{ WAN_WISHING, 3, WAND_CLASS, 1, 0 }, 202. 	{ 0, 0, 0, 0, 0 }  203.  };  204.   205.  #ifdef WEAPON_SKILLS 206. static struct def_skill Skill_A[] = { 207.     { P_DAGGER, P_BASIC },		{ P_KNIFE,  P_BASIC }, 208.     { P_PICK_AXE, P_EXPERT },		{ P_SHORT_SWORD, P_BASIC }, 209.     { P_SCIMITAR, P_SKILLED },		{ P_SABER, P_EXPERT }, 210.     { P_CLUB, P_SKILLED },		{ P_QUARTERSTAFF, P_SKILLED }, 211.     { P_SLING, P_SKILLED },		{ P_DART, P_BASIC }, 212.     { P_BOOMERANG, P_EXPERT },		{ P_WHIP, P_EXPERT }, 213.     { P_UNICORN_HORN, P_SKILLED },	{ P_TWO_WEAPON_COMBAT, P_BASIC }, 214.     { P_BARE_HANDED_COMBAT, 4 }, 215.     { P_NO_TYPE, 0 } 216. };  217.   218.  static struct def_skill Skill_B[] = { 219.     { P_DAGGER, P_BASIC },		{ P_AXE, P_EXPERT }, 220.     { P_PICK_AXE, P_EXPERT },		{ P_SHORT_SWORD, P_BASIC }, 221.     { P_BROAD_SWORD, P_SKILLED },	{ P_LONG_SWORD, P_SKILLED }, 222.     { P_TWO_HANDED_SWORD, P_EXPERT },	{ P_SCIMITAR, P_SKILLED }, 223.     { P_SABER, P_BASIC },		{ P_CLUB, P_SKILLED }, 224.     { P_MACE, P_SKILLED },		{ P_MORNING_STAR, P_SKILLED }, 225.     { P_FLAIL, P_BASIC },               { P_HAMMER, P_EXPERT }, 226.     { P_QUARTERSTAFF, P_BASIC },	{ P_SPEAR, P_SKILLED }, 227.     { P_TRIDENT, P_SKILLED },		{ P_BOW, P_BASIC }, 228.     { P_TWO_WEAPON_COMBAT, P_BASIC },	{ P_BARE_HANDED_COMBAT, 6 }, 229.     { P_NO_TYPE, 0 } 230. };  231.   232.  static struct def_skill Skill_C[] = { 233.     { P_DAGGER, P_BASIC },		{ P_KNIFE,  P_SKILLED }, 234.     { P_AXE, P_SKILLED },		{ P_PICK_AXE, P_BASIC }, 235.     { P_CLUB, P_EXPERT },		{ P_MACE, P_EXPERT }, 236.     { P_MORNING_STAR, P_BASIC },	{ P_FLAIL, P_SKILLED }, 237.     { P_HAMMER, P_SKILLED },		{ P_QUARTERSTAFF, P_EXPERT }, 238.     { P_POLEARMS, P_SKILLED },		{ P_SPEAR, P_EXPERT }, 239.     { P_JAVELIN, P_SKILLED },		{ P_TRIDENT, P_SKILLED }, 240.     { P_BOW, P_EXPERT },		{ P_SLING, P_SKILLED }, 241.     { P_BOOMERANG, P_EXPERT },		{ P_UNICORN_HORN, P_BASIC }, 242.     { P_BARE_HANDED_COMBAT, 6 }, 243.     { P_NO_TYPE, 0 } 244. };  245.   246.  static struct def_skill Skill_E[] = { 247.     { P_DAGGER, P_EXPERT },		{ P_KNIFE, P_SKILLED }, 248.     { P_SHORT_SWORD, P_EXPERT },	{ P_BROAD_SWORD, P_EXPERT }, 249.     { P_LONG_SWORD, P_SKILLED },	{ P_TWO_HANDED_SWORD, P_BASIC }, 250.     { P_SCIMITAR, P_SKILLED },		{ P_SABER, P_SKILLED }, 251.     { P_SPEAR, P_EXPERT },		{ P_JAVELIN, P_BASIC }, 252.     { P_BOW, P_EXPERT },		{ P_SLING, P_BASIC }, 253.     { P_CROSSBOW, P_BASIC },		{ P_SHURIKEN, P_BASIC }, 254.     { P_TWO_WEAPON_COMBAT, P_EXPERT },	{ P_MARTIAL_ARTS, 2 }, 255.     { P_NO_TYPE, 0 } 256. };  257.   258.  static struct def_skill Skill_H[] = { 259.     { P_DAGGER, P_SKILLED },		{ P_KNIFE, P_EXPERT }, 260.     { P_SHORT_SWORD, P_SKILLED },	{ P_SCIMITAR, P_BASIC }, 261.     { P_SABER, P_BASIC },		{ P_CLUB, P_SKILLED }, 262.     { P_MACE, P_BASIC },		{ P_QUARTERSTAFF, P_EXPERT }, 263.     { P_POLEARMS, P_BASIC },		{ P_SPEAR, P_BASIC }, 264.     { P_JAVELIN, P_BASIC },		{ P_TRIDENT, P_BASIC }, 265.     { P_SLING, P_SKILLED },		{ P_DART, P_EXPERT }, 266.     { P_SHURIKEN, P_SKILLED },		{ P_UNICORN_HORN, P_EXPERT }, 267.     { P_BARE_HANDED_COMBAT, 2 }, 268.     { P_NO_TYPE, 0 } 269. };  270.   271.  static struct def_skill Skill_K[] = { 272.     { P_DAGGER, P_BASIC },		{ P_KNIFE, P_BASIC }, 273.     { P_AXE, P_SKILLED },		{ P_PICK_AXE, P_BASIC }, 274.     { P_SHORT_SWORD, P_SKILLED },	{ P_BROAD_SWORD, P_SKILLED }, 275.     { P_LONG_SWORD, P_EXPERT },	{ P_TWO_HANDED_SWORD, P_SKILLED }, 276.     { P_SCIMITAR, P_BASIC },		{ P_SABER, P_SKILLED }, 277.     { P_CLUB, P_BASIC },		{ P_MACE, P_SKILLED }, 278.     { P_MORNING_STAR, P_SKILLED },	{ P_FLAIL, P_BASIC }, 279.     { P_HAMMER, P_BASIC },		{ P_POLEARMS, P_SKILLED }, 280.     { P_SPEAR, P_SKILLED },		{ P_JAVELIN, P_SKILLED }, 281.     { P_TRIDENT, P_BASIC },		{ P_LANCE, P_EXPERT }, 282.     { P_BOW, P_BASIC },			{ P_CROSSBOW, P_SKILLED }, 283.     { P_TWO_WEAPON_COMBAT, P_SKILLED }, { P_BARE_HANDED_COMBAT, 4 }, 284.     { P_NO_TYPE, 0 } 285. };  286.   287.  static struct def_skill Skill_P[] = { 288.     { P_CLUB, P_EXPERT },		{ P_MACE, P_EXPERT }, 289.     { P_MORNING_STAR, P_EXPERT },	{ P_FLAIL, P_EXPERT }, 290.     { P_HAMMER, P_EXPERT },		{ P_QUARTERSTAFF, P_EXPERT }, 291.     { P_POLEARMS, P_SKILLED },		{ P_SPEAR, P_SKILLED }, 292.     { P_JAVELIN, P_SKILLED },		{ P_TRIDENT, P_SKILLED }, 293.     { P_LANCE, P_BASIC },		{ P_BOW, P_BASIC }, 294.     { P_SLING, P_BASIC },		{ P_CROSSBOW, P_BASIC }, 295.     { P_DART, P_BASIC },		{ P_SHURIKEN, P_BASIC }, 296.     { P_BOOMERANG, P_BASIC },		{ P_UNICORN_HORN, P_SKILLED }, 297.     { P_NO_TYPE, 0 } 298. };  299.   300.  static struct def_skill Skill_R[] = { 301.     { P_DAGGER, P_EXPERT },		{ P_KNIFE,  P_EXPERT }, 302.     { P_SHORT_SWORD, P_EXPERT },	{ P_BROAD_SWORD, P_SKILLED }, 303.     { P_LONG_SWORD, P_SKILLED },	{ P_TWO_HANDED_SWORD, P_BASIC }, 304.     { P_SCIMITAR, P_SKILLED },		{ P_SABER, P_SKILLED }, 305.     { P_CLUB, P_SKILLED },		{ P_MACE, P_SKILLED }, 306.     { P_MORNING_STAR, P_BASIC },	{ P_FLAIL, P_BASIC }, 307.     { P_HAMMER, P_BASIC },		{ P_POLEARMS, P_BASIC }, 308.     { P_SPEAR, P_BASIC },		{ P_CROSSBOW, P_EXPERT }, 309.     { P_DART, P_EXPERT },		{ P_SHURIKEN, P_SKILLED }, 310.     { P_TWO_WEAPON_COMBAT, P_EXPERT },	{ P_BARE_HANDED_COMBAT, 2 }, 311.     { P_NO_TYPE, 0 } 312. };  313.   314.  static struct def_skill Skill_S[] = { 315.     { P_DAGGER, P_BASIC },		{ P_KNIFE,  P_SKILLED }, 316.     { P_SHORT_SWORD, P_EXPERT },	{ P_BROAD_SWORD, P_SKILLED }, 317.     { P_LONG_SWORD, P_EXPERT },		{ P_TWO_HANDED_SWORD, P_EXPERT }, 318.     { P_SCIMITAR, P_BASIC },		{ P_SABER, P_BASIC }, 319.     { P_FLAIL, P_SKILLED },		{ P_QUARTERSTAFF, P_BASIC }, 320.     { P_POLEARMS, P_SKILLED },		{ P_SPEAR, P_BASIC }, 321.     { P_JAVELIN, P_BASIC },		{ P_LANCE, P_SKILLED }, 322.     { P_BOW, P_EXPERT },		{ P_SHURIKEN, P_EXPERT }, 323.     { P_TWO_WEAPON_COMBAT, P_EXPERT },	{ P_MARTIAL_ARTS, 6 }, 324.     { P_NO_TYPE, 0 } 325. };  326.   327.  #ifdef TOURIST 328. static struct def_skill Skill_T[] = { 329.     { P_DAGGER, P_EXPERT },		{ P_KNIFE,  P_SKILLED }, 330.     { P_AXE, P_BASIC },			{ P_PICK_AXE, P_BASIC }, 331.     { P_SHORT_SWORD, P_EXPERT },	{ P_BROAD_SWORD, P_BASIC }, 332.     { P_LONG_SWORD, P_BASIC },		{ P_TWO_HANDED_SWORD, P_BASIC }, 333.     { P_SCIMITAR, P_SKILLED },		{ P_SABER, P_SKILLED }, 334.     { P_MACE, P_BASIC },		{ P_MORNING_STAR, P_BASIC }, 335.     { P_FLAIL, P_BASIC },		{ P_HAMMER, P_BASIC }, 336.     { P_QUARTERSTAFF, P_BASIC },	{ P_POLEARMS, P_BASIC }, 337.     { P_SPEAR, P_BASIC },		{ P_JAVELIN, P_BASIC }, 338.     { P_TRIDENT, P_BASIC },		{ P_LANCE, P_BASIC }, 339.     { P_BOW, P_BASIC },			{ P_SLING, P_BASIC }, 340.     { P_CROSSBOW, P_BASIC },		{ P_DART, P_EXPERT }, 341.     { P_SHURIKEN, P_BASIC },		{ P_BOOMERANG, P_BASIC }, 342.     { P_WHIP, P_BASIC },		{ P_UNICORN_HORN, P_SKILLED }, 343.     { P_TWO_WEAPON_COMBAT, P_SKILLED }, { P_BARE_HANDED_COMBAT, 4 }, 344.     { P_NO_TYPE, 0 } 345. };  346.  #endif /* TOURIST */ 347.  348.  static struct def_skill Skill_V[] = { 349.     { P_DAGGER, P_EXPERT },		{ P_AXE, P_EXPERT }, 350.     { P_PICK_AXE, P_SKILLED },		{ P_SHORT_SWORD, P_SKILLED }, 351.     { P_BROAD_SWORD, P_SKILLED },	{ P_LONG_SWORD, P_EXPERT }, 352.     { P_TWO_HANDED_SWORD, P_EXPERT },	{ P_SCIMITAR, P_BASIC }, 353.     { P_SABER, P_BASIC },		{ P_HAMMER, P_EXPERT }, 354.     { P_QUARTERSTAFF, P_BASIC },	{ P_POLEARMS, P_SKILLED }, 355.     { P_SPEAR, P_SKILLED },		{ P_JAVELIN, P_BASIC }, 356.     { P_TRIDENT, P_BASIC },		{ P_LANCE, P_SKILLED }, 357.     { P_SLING, P_BASIC },		{ P_TWO_WEAPON_COMBAT, P_SKILLED }, 358.     { P_BARE_HANDED_COMBAT, 4 }, 359.     { P_NO_TYPE, 0 } 360. };  361.   362.  static struct def_skill Skill_W[] = { 363.     { P_DAGGER, P_EXPERT },		{ P_KNIFE,  P_SKILLED }, 364.     { P_AXE, P_SKILLED },		{ P_SHORT_SWORD, P_BASIC }, 365.     { P_CLUB, P_SKILLED },		{ P_MACE, P_BASIC }, 366.     { P_QUARTERSTAFF, P_EXPERT },	{ P_POLEARMS, P_SKILLED }, 367.     { P_SPEAR, P_BASIC },		{ P_JAVELIN, P_BASIC }, 368.     { P_TRIDENT, P_BASIC },		{ P_SLING, P_SKILLED }, 369.     { P_DART, P_EXPERT },		{ P_SHURIKEN, P_BASIC }, 370.     { P_BARE_HANDED_COMBAT, 2 }, 371.     { P_NO_TYPE, 0 } 372. };  373.  #endif /* WEAPON_SKILLS */ 374.  375.   376.  static void 377. knows_object(obj) 378. register int obj; 379. {  380.  	makeknown(obj); 381. 	objects[obj].oc_pre_discovered = 1;	/* not a "discovery" */ 382. }  383.   384.  /* Know ordinary (non-magical) objects of a certain class, 385.  * like all gems except the loadstone and luckstone. 386.  */  387.  static void 388. knows_class(sym) 389. register char sym; 390. {  391.  	register int ct; 392. 	for (ct = 1; ct < NUM_OBJECTS; ct++) 393. 		if (objects[ct].oc_class == sym && !objects[ct].oc_magic) 394. 			knows_object(ct); 395. }  396.   397.  static int 398. role_index(pc) 399. char pc; 400. {  401.  	register const char *cp; 402.  403.  	if ((cp = index(pl_classes, pc)) != 0) 404. 		return(cp - pl_classes); 405. 	return(-1); 406. }  407.   408.  void 409. u_init 410. {  411.  	register int i;  412. char pc; 413.  414.  	pc = pl_character[0]; 415. 	if(pc == '\0') { 416. 	    /* should be unnecessary now */ 417. 	    exit_nhwindows((char *)0); 418. 	    terminate(EXIT_SUCCESS); 419. 	}  420.  	i = role_index(pc); 421. 	if (random_role) { 422. 	    pline("This game you will be %s.", an(roles[i])); 423. 	    display_nhwindow(WIN_MESSAGE, TRUE); 424. 	}  425.   426.  	(void) strncpy(pl_character, roles[i], PL_CSIZ-1); 427. 	pl_character[PL_CSIZ-1] = 0; 428. 	flags.beginner = 1; 429.  430.  	/* zero u, including pointer values -- 431. 	 * necessary when aborting from a failed restore */ 432. 	(void) memset((genericptr_t)&u, 0, sizeof(u)); 433. 	u.ustuck = (struct monst *)0; 434.  435.  #if 0	/* documentation of more zero values as desirable */ 436. 	u.usick_cause[0] = 0; 437. 	u.uluck  = u.moreluck = 0; 438. # ifdef TOURIST 439. 	uarmu = 0; 440. # endif 441. 	uarm = uarmc = uarmh = uarms = uarmg = uarmf = 0; 442. 	uwep = uball = uchain = uleft = uright = 0; 443. 	u.ublessed = 0;				/* not worthy yet */ 444. 	u.ugangr   = 0;				/* gods not angry */ 445. # ifdef ELBERETH 446. 	u.uevent.uhand_of_elbereth = 0; 447. # endif 448. 	u.uevent.uheard_tune = 0; 449. 	u.uevent.uopened_dbridge = 0; 450. 	u.uevent.udemigod = 0;		/* not a demi-god yet... */ 451.  	u.udg_cnt = 0; 452. 	u.mh = u.mhmax = u.mtimedone = 0; 453. 	u.uz.dnum = u.uz0.dnum = 0; 454. 	u.utotype = 0; 455. #endif	/* 0 */ 456. 	u.uz.dlevel = 1; 457. 	u.uz0.dlevel = 0; 458. 	u.utolev = u.uz; 459.  460.  	u.role = pl_character[0]; 461. 	u.usym = S_HUMAN; 462. 	u.umoved = FALSE; 463. 	u.umortality = 0; 464. 	u.ugrave_arise = NON_PM; 465.  466.  	u.ulevel = 0;	/* set up some of the initial attributes */ 467. 	u.uhp = u.uhpmax = newhp; 468. 	adjabil(0,1); 469. 	u.ulevel = 1; 470.  471.  	init_uhunger; 472. 	u.uen = u.uenmax = 2; 473. 	for (i = 0; i <= MAXSPELL; i++) spl_book[i].sp_id = NO_SPELL; 474. 	u.ublesscnt = 300;			/* no prayers just yet */ 475. 	u.umonnum = PM_PLAYERMON; 476. 	u.ulycn = NON_PM; 477. 	set_uasmon; 478.  479.  #ifdef BSD 480. 	(void) time((long *)&u.ubirthday); 481. #else 482. 	(void) time(&u.ubirthday); 483. #endif 484.  485.  	/*  486.  	 *  For now, everyone starts out with a night vision range of 1 and 487. 	 *  their xray range disabled. 488. 	 */  489.  	u.nv_range   =  1; 490. 	u.xray_range = -1; 491.  492.   493.  	switch(pc) { 494. 	/* pc will always be in uppercase by this point */ 495. 	case 'A': 496. 		u.umonster = PM_ARCHEOLOGIST; 497. 		ini_inv(Archeologist); 498. 		if(!rn2(10)) ini_inv(Tinopener); 499. 		else if(!rn2(4)) ini_inv(Lamp); 500. 		else if(!rn2(10)) ini_inv(Magicmarker); 501. 		knows_class(GEM_CLASS); 502. 		knows_object(SACK); 503. #ifdef WEAPON_SKILLS 504. 		skill_init(Skill_A); 505. #endif /* WEAPON_SKILLS */ 506. 		break; 507. 	case 'B': 508. 		u.umonster = PM_BARBARIAN; 509. 		if (rn2(100) >= 50) {	/* see Elf comment */ 510. 		    Barbarian[B_MAJOR].trotyp = BATTLE_AXE; 511. 		    Barbarian[B_MINOR].trotyp = SHORT_SWORD; 512. 		}  513.  		ini_inv(Barbarian); 514. 		if(!rn2(6)) ini_inv(Lamp); 515. 		knows_class(WEAPON_CLASS); 516. 		knows_class(ARMOR_CLASS); 517. #ifdef WEAPON_SKILLS 518. 		skill_init(Skill_B); 519. #endif /* WEAPON_SKILLS */ 520. 		break; 521. 	case 'C': 522. 		u.umonster = flags.female ? PM_CAVEWOMAN : PM_CAVEMAN; 523. 		Cave_man[C_ARROWS].trquan = rn1(30, 13); 524. 		ini_inv(Cave_man); 525. #ifdef WEAPON_SKILLS 526. 		skill_init(Skill_C); 527. #endif /* WEAPON_SKILLS */ 528. 		break; 529. 	case 'E': 530. 		u.umonster = PM_ELF; 531. 		Elf[E_ARROWS].trquan = rn1(20, 16); 532. 		Elf[E_ARMOR].trotyp = ((rn2(100) >= 50)  533.  				 ? ELVEN_MITHRIL_COAT : ELVEN_CLOAK); 534. 			/* rn2(100) > 50 necessary because some random number 535. 			 * generators are bad enough to seriously skew the 536. 			 * results if we use rn2(2)... --KAA 537. 			 */  538.  		ini_inv(Elf); 539. 		/*  540.  		 * Elves are people of music and song, or they are warriors. 541. 		 * Warriors get mithril coats; non-warriors MAY get an  542. * instrument. We use a kludge to get only non-magic 543. 		 * instruments. 544. 		 */  545.  		if (Elf[E_ARMOR].trotyp == ELVEN_CLOAK && !rn2(5)) { 546. 		    static int trotyp[] = { 547. 			WOODEN_FLUTE, TOOLED_HORN, WOODEN_HARP, 548. 			BELL, BUGLE, LEATHER_DRUM 549. 		    };  550.  		    Instrument[0].trotyp = trotyp[rn2(SIZE(trotyp))]; 551. 		    ini_inv(Instrument); 552. 		}  553.  		if(!rn2(5)) ini_inv(Blindfold); 554. 		else if(!rn2(6)) ini_inv(Lamp); 555. 		knows_object(ELVEN_SHORT_SWORD); 556. 		knows_object(ELVEN_ARROW); 557. 		knows_object(ELVEN_BOW); 558. 		knows_object(ELVEN_SPEAR); 559. 		knows_object(ELVEN_DAGGER); 560. 		knows_object(ELVEN_BROADSWORD); 561. 		knows_object(ELVEN_MITHRIL_COAT); 562. 		knows_object(ELVEN_LEATHER_HELM); 563. 		knows_object(ELVEN_SHIELD); 564. 		knows_object(ELVEN_BOOTS); 565. 		knows_object(ELVEN_CLOAK); 566. #ifdef WEAPON_SKILLS 567. 		skill_init(Skill_E); 568. #endif /* WEAPON_SKILLS */ 569. 		break; 570. 	case 'H': 571. 		u.umonster = PM_HEALER; 572. 		u.uen = u.uenmax += rn1(4, 1); 573. 		u.ugold = u.ugold0 = rn1(1000, 1001); 574. 		ini_inv(Healer); 575. 		if(!rn2(25)) ini_inv(Lamp); 576. #ifdef WEAPON_SKILLS 577. 		skill_init(Skill_H); 578. #endif /* WEAPON_SKILLS */ 579. 		break; 580. 	case 'K': 581. 		u.umonster = PM_KNIGHT; 582. 		u.uen = u.uenmax += rn1(4, 1); 583. 		ini_inv(Knight); 584. 		knows_class(WEAPON_CLASS); 585. 		knows_class(ARMOR_CLASS); 586. 		/* give knights chess-like mobility 587. 		 * -- idea from wooledge@skybridge.scl.cwru.edu */ 588. 		Jumping |= FROMOUTSIDE; 589. #ifdef WEAPON_SKILLS 590. 		skill_init(Skill_K); 591. #endif /* WEAPON_SKILLS */ 592. 		break; 593. 	case 'P': 594. 		u.umonster = flags.female ? PM_PRIESTESS : PM_PRIEST; 595. 		u.uen = u.uenmax += rn1(3, 4); 596. 		ini_inv(Priest); 597. 		if(!rn2(10)) ini_inv(Magicmarker); 598. 		else if(!rn2(10)) ini_inv(Lamp); 599. 		knows_object(POT_WATER); 600. #ifdef WEAPON_SKILLS 601. 		skill_init(Skill_P); 602. #endif /* WEAPON_SKILLS */ 603. 		break; 604. 	case 'R': 605. 		u.umonster = PM_ROGUE; 606. 		Rogue[R_DAGGERS].trquan = rn1(10, 6); 607. 		u.ugold = u.ugold0 = 0; 608. 		ini_inv(Rogue); 609. 		if(!rn2(5)) ini_inv(Blindfold); 610. 		knows_object(SACK); 611. #ifdef WEAPON_SKILLS 612. 		skill_init(Skill_R); 613. #endif /* WEAPON_SKILLS */ 614. 		break; 615. 	case 'S': 616. 		u.umonster = PM_SAMURAI; 617. 		Samurai[S_ARROWS].trquan = rn1(20, 26); 618. 		ini_inv(Samurai); 619. 		if(!rn2(5)) ini_inv(Blindfold); 620. 		knows_class(WEAPON_CLASS); 621. 		knows_class(ARMOR_CLASS); 622. #ifdef WEAPON_SKILLS 623. 		skill_init(Skill_S); 624. #endif /* WEAPON_SKILLS */ 625. 		break; 626. #ifdef TOURIST 627. 	case 'T': 628. 		u.umonster = PM_TOURIST; 629. 		Tourist[T_DARTS].trquan = rn1(20, 21); 630. 		u.ugold = u.ugold0 = rnd(1000); 631. 		ini_inv(Tourist); 632. 		if(!rn2(25)) ini_inv(Tinopener); 633. 		else if(!rn2(25)) ini_inv(Leash); 634. 		else if(!rn2(25)) ini_inv(Towel); 635. 		else if(!rn2(25)) ini_inv(Magicmarker); 636. #ifdef WEAPON_SKILLS 637. 		skill_init(Skill_T); 638. #endif /* WEAPON_SKILLS */ 639. 		break; 640. #endif 641. 	case 'V': 642. 		u.umonster = PM_VALKYRIE; 643. 		flags.female = TRUE; 644. 		ini_inv(Valkyrie); 645. 		if(!rn2(6)) ini_inv(Lamp); 646. 		knows_class(WEAPON_CLASS); 647. 		knows_class(ARMOR_CLASS); 648. #ifdef WEAPON_SKILLS 649. 		skill_init(Skill_V); 650. #endif /* WEAPON_SKILLS */ 651. 		break; 652. 	case 'W': 653. 		u.umonster = PM_WIZARD; 654. 		u.uen = u.uenmax += rn1(3, 4); 655. 		ini_inv(Wizard); 656. 		if(!rn2(5)) ini_inv(Magicmarker); 657. 		if(!rn2(5)) ini_inv(Blindfold); 658. #ifdef WEAPON_SKILLS 659. 		skill_init(Skill_W); 660. #endif /* WEAPON_SKILLS */ 661. 		break; 662.  663.  	default:	/* impossible */ 664. 		break; 665. 	}  666.  	if (discover) 667. 		ini_inv(Wishing); 668.  669.  	u.ugold0 += hidden_gold;	/* in case sack has gold in it */ 670.  671.  	find_ac;			/* get initial ac value */ 672. 	init_attr(75);			/* init attribute values */ 673. 	max_rank_sz;			/* set max str size for class ranks */ 674. /*  675.   *	Do we really need this? 676.  */  677.  	for(i = 0; i < A_MAX; i++) 678. 	    if(!rn2(20)) { 679. 		register int xd = rn2(7) - 2;	/* biased variation */ 680. 		(void) adjattrib(i, xd, TRUE); 681. 		if (ABASE(i) < AMAX(i)) AMAX(i) = ABASE(i); 682. 	    }  683.   684.  	/* make sure you can carry all you have - especially for Tourists */ 685. 	while(inv_weight > 0 && ACURR(A_STR) < 118) 686. 		(void) adjattrib(A_STR, 1, TRUE); 687. 	/* undo exercise for wisdom due to `makeknown' of prediscovered items */ 688. 	AEXE(A_WIS) = 0; 689.  690.  	u.ualignbase[0] = u.ualignbase[1] = u.ualign.type; 691. }  692.   693.  static void 694. ini_inv(trop) 695. register struct trobj *trop; 696. {  697.  	struct obj *obj; 698. 	while(trop->trclass) { 699. 		boolean undefined = (trop->trotyp == UNDEF_TYP); 700.  701.  		if (!undefined) 702. 			obj = mksobj((int)trop->trotyp, TRUE, FALSE); 703. 		else obj = mkobj(trop->trclass,FALSE); 704.  705.  		/* For random objects, do not create certain overly powerful 706. 		 * items: wand of wishing, ring of levitation, or the 707. 		 * polymorph/polymorph control combination. Specific objects, 708. 		 * i.e. the discovery wishing, are still OK. 709. 		 * Also, don't get a couple of really useless items. (Note: 710.  		 * punishment isn't "useless".  Some players who start out with  711.  		 * one will immediately read it and use the iron ball as a  712.  		 * weapon.) 713. 		 */  714.  		if (undefined) { 715. 			static NEARDATA short nocreate = STRANGE_OBJECT; 716. 			static NEARDATA short nocreate2 = STRANGE_OBJECT; 717. 			static NEARDATA short nocreate3 = STRANGE_OBJECT; 718.  719.  			while(obj->otyp == WAN_WISHING  720.  				|| obj->otyp == nocreate  721.  				|| obj->otyp == nocreate2  722.  				|| obj->otyp == nocreate3  723.  #ifdef ELBERETH  724.  				|| obj->otyp == RIN_LEVITATION  725.  #endif  726.  				/* 'useless' items */  727.  				|| obj->otyp == POT_HALLUCINATION  728.  				|| obj->otyp == SCR_AMNESIA  729.  				|| obj->otyp == SCR_FIRE  730.  				|| obj->otyp == RIN_AGGRAVATE_MONSTER  731.  				|| obj->otyp == RIN_HUNGER  732.  				|| obj->otyp == WAN_NOTHING  733.  				/* powerful spells are either useless to  734.  				   low level players or unbalancing */  735.  				|| (obj->oclass == SPBOOK_CLASS && 736. 				    objects[obj->otyp].oc_level > 3)  737.  							) { 738. 				dealloc_obj(obj); 739. 				obj = mkobj(trop->trclass, FALSE); 740. 			}  741.   742.  			/* Don't start with +0 or negative rings */ 743. 			if(objects[obj->otyp].oc_charged && obj->spe <= 0) 744. 				obj->spe = rne(3); 745.  746.  			/* Heavily relies on the fact that 1) we create wands  747.  			 * before rings, 2) that we create rings before 748. 			 * spellbooks, and that 3) not more than 1 object of a  749.  			 * particular symbol is to be prohibited.  (For more 750. 			 * objects, we need more nocreate variables...)  751.  			 */  752.  			switch (obj->otyp) {  753.  			    case WAN_POLYMORPH:  754.  			    case RIN_POLYMORPH:  755.  				nocreate = RIN_POLYMORPH_CONTROL;  756.  				break;  757.  			    case RIN_POLYMORPH_CONTROL:  758.  				nocreate = RIN_POLYMORPH;  759.  				nocreate2 = SPE_POLYMORPH;  760.  			}  761.  			/* Don't have 2 of the same ring or spellbook */  762.  			if (obj->oclass == RING_CLASS || 763. 			    obj->oclass == SPBOOK_CLASS)  764.  				nocreate3 = obj->otyp;  765.  		}  766.   767.  		obj->dknown = obj->bknown = obj->rknown = 1;  768.  		if (objects[obj->otyp].oc_uses_known) obj->known = 1;  769.  		obj->cursed = 0;  770.  		if(obj->oclass == WEAPON_CLASS || obj->oclass == TOOL_CLASS) {  771.  			obj->quan = (long) trop->trquan;  772.  			trop->trquan = 1;  773.  		}  774.  		if(trop->trspe != UNDEF_SPE)  775.  			obj->spe = trop->trspe;  776.  		if(trop->trbless != UNDEF_BLESS)  777.  			obj->blessed = trop->trbless;  778.   779.  		/* defined after setting otyp+quan + blessedness */  780.  		obj->owt = weight(obj);  781.  		obj = addinv(obj);  782.   783.  		/* Make the type known if necessary */  784.  		if (OBJ_DESCR(objects[obj->otyp]) && obj->known)  785.  			makeknown(obj->otyp);  786.  		if (obj->otyp == OIL_LAMP)  787.  			knows_object(POT_OIL);  788.   789. if(obj->oclass == ARMOR_CLASS){ 790. 			if (is_shield(obj) && !uarms) 791. 				setworn(obj, W_ARMS); 792. 			else if (is_helmet(obj) && !uarmh) 793. 				setworn(obj, W_ARMH); 794. 			else if (is_gloves(obj) && !uarmg) 795. 				setworn(obj, W_ARMG); 796. #ifdef TOURIST 797. 			else if (is_shirt(obj) && !uarmu) 798. 				setworn(obj, W_ARMU); 799. #endif 800. 			else if (is_cloak(obj) && !uarmc) 801. 				setworn(obj, W_ARMC); 802. 			else if (is_boots(obj) && !uarmf) 803. 				setworn(obj, W_ARMF); 804. 			else if (!uarm) 805. 				setworn(obj, W_ARM); 806. 		}  807.  		/* below changed by GAN 01/09/87 to allow wielding of  808. * pick-axe or can-opener if there is no weapon 809. 		 */  810.  		if(obj->oclass == WEAPON_CLASS || obj->otyp == PICK_AXE ||  811.  		   obj->otyp == TIN_OPENER) 812. 			if(!uwep) setuwep(obj); 813. #if !defined(PYRAMID_BUG) && !defined(MAC) 814. 		if(--trop->trquan) continue;	/* make a similar object */ 815. #else 816. 		if(trop->trquan) {		/* check if zero first */ 817. 			--trop->trquan; 818. 			if(trop->trquan) 819. 				continue;	/* make a similar object */ 820. 		}  821.  #endif 822. 		trop++; 823. 	}  824.  }  825.   826.  void 827. plnamesuffix 828. {  829.  	register char *p; 830. 	if ((p = rindex(plname, '-')) != 0) { 831. 		*p = '\0'; 832. 		pl_character[0] = p[1]; 833. 		pl_character[1] = '\0'; 834. 		random_role = FALSE; 835. 		if(!plname[0]) { 836. 			askname; 837. 			plnamesuffix; 838. 		}  839.  	}  840.  	if (pl_character[0] == '@') {	/* explicit request for random class */ 841. 		int i = rn2((int)strlen(pl_classes)); 842. 		pl_character[0] = pl_classes[i]; 843. 		pl_character[1] = '\0'; 844. 		random_role = TRUE; 845. 	}  846.  }  847.   848.  /*u_init.c*/