Source:NetHack 3.2.0/mplayer.c

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

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

1.   /*	SCCS Id: @(#)mplayer.c	3.2	96/02/27	*/ 2.   /*	Copyright (c) Izchak Miller, 1992. */ 3.    /* NetHack may be freely redistributed. See license for details. */ 4.     5.    #include "hack.h"  6. 7.   static const char *NDECL(dev_name); 8.   static void FDECL(get_mplname, (struct monst *, char *)); 9.   static void FDECL(mk_mplayer_armor, (struct monst *, int, int)); 10.   11.   /* These are the names of those who 12.   * contributed to the development of NetHack 3.2. 13.   *  14.    * Keep in alphabetical order within teams. 15.   * Same first name is entered once within each team. 16.   */  17.   static const char *developers[] = { 18.  	/* devteam */ 19.  	"Dave", "Dean", "Eric", "Izchak", "Janet", "Jessie", 20.  	"Ken", "Kevin", "Michael", "Mike", "Pat", "Paul", "Steve", "Timo", 21.  	/* PC team */ 22.  	"Bill", "Eric", "Ken", "Kevin", "Michael", "Mike", "Paul", 23.  	"Stephen", "Steve", "Timo", "Yamamoto", "Yitzhak", 24.  	/* Amiga team */ 25.  	"Andy", "Gregg", "Keni", "Mike", "Olaf", "Richard", 26.  	/* Mac team */ 27.  	"Andy", "Chris", "Dean", "Jon", "Jonathan", "Wang", 28.  	/* Atari team */ 29.  	"Eric", "Warwick", 30.  	/* NT team */ 31.  	"Michael", 32.  	/* OS/2 team */ 33.  	"Timo", 34.  	/* VMS team */ 35.  	"Joshua", "Pat", 36.  	""};  37.    38.    39.   /* return a randomly chosen developer name */ 40.  static const char * 41.  dev_name 42.  {  43.   	register int i, m = 0, n = SIZE(developers); 44.  	register struct monst *mtmp; 45.  	register boolean match; 46.   47.   	do { 48.  	    match = FALSE; 49.  	    i = rn2(n); 50.  	    for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { 51.  		if(!is_mplayer(mtmp->data)) continue; 52.  		if(!strncmp(developers[i], NAME(mtmp), 53.  			               strlen(developers[i]))) { 54.  		    match = TRUE; 55.  		    break; 56.  	        }  57.   	    }  58.   	    m++; 59.  	} while (match && m < 100); /* m for insurance */ 60.   61.   	if (match) return (const char *)0; 62.  	return(developers[i]); 63.  }  64.    65.   static void 66.  get_mplname(mtmp, nam) 67.  register struct monst *mtmp; 68.  char *nam; 69.  {  70.   	boolean fmlkind = is_female(mtmp->data); 71.  	const char *devnam; 72.   73.   	devnam = dev_name; 74.  	if (!devnam) 75.  	    Strcpy(nam, fmlkind ? "Eve" : "Adam"); 76.  	else if (fmlkind && !!strcmp(devnam, "Janet")) 77.  	    Strcpy(nam, rn2(2) ? "Maud" : "Eve"); 78.  	else Strcpy(nam, devnam); 79.   80.   	if (fmlkind || !strcmp(nam, "Janet")) 81.  	    mtmp->female = 1; 82.  	else 83.  	    mtmp->female = 0; 84.  	Strcat(nam, " the "); 85.  	Strcat(nam, rank_of(rn1(11, 20), 86.  			    highc(mtmp->data->mname[0]), 87.  			    (boolean)mtmp->female)); 88.  }  89.    90.   static void 91.  mk_mplayer_armor(mon, range1, range2) 92.  struct monst *mon; 93.  int range1, range2; 94.  {  95.   	struct obj *obj; 96.   97.   	obj = mksobj(rnd_class(range1, range2), FALSE, FALSE); 98.  	if (!rn2(3)) obj->oerodeproof = 1; 99.  	if (!rn2(3)) curse(obj); 100. 	if (!rn2(3)) bless(obj); 101. 	/* Most players who get to the endgame who have cursed equipment 102. 	 * have it because the wizard or other monsters cursed it, so its 103. 	 * chances of having plusses is the same as usual....  104. */ 105.  	obj->spe = rn2(10) ? (rn2(3) ? rn2(5) : rn1(4,4)) : -rnd(3); 106. 	mpickobj(mon, obj); 107. }  108.   109.  struct monst * 110. mk_mplayer(ptr, x, y, special) 111. register struct permonst *ptr; 112. xchar x, y;  113. register boolean special; 114. {  115.  	register struct monst *mtmp; 116. 	char nam[PL_NSIZ]; 117.  118.  	if(!is_mplayer(ptr)) 119. 		return((struct monst *)0); 120.  121.  	if(MON_AT(x, y)) 122. 		rloc(m_at(x, y)); /* insurance */ 123.  124.  	if(!In_endgame(&u.uz)) special = FALSE; 125.  126.  	if ((mtmp = makemon(ptr, x, y)) != 0) { 127. 	    int weapon, quan; 128. 	    struct obj *otmp; 129.  130.  	    mtmp->m_lev = (special ? rn1(8,12) : rnd(16)); 131. 	    mtmp->mhp = mtmp->mhpmax = d((int)mtmp->m_lev,10) + 132. 					(special ? (30 + rnd(30)) : 30); 133. 	    if(special) { 134. 	        get_mplname(mtmp, nam); 135. 	        mtmp = christen_monst(mtmp, nam); 136. 		/* that's why they are "stuck" in the endgame :-) */  137.  		(void)mongets(mtmp, FAKE_AMULET_OF_YENDOR);  138.  	    }  139.  	    mtmp->mpeaceful = 0;  140.  	    set_malign(mtmp); /* peaceful may have changed again */  141.   142.  	    switch(monsndx(ptr)) {  143.  		case PM_ARCHEOLOGIST:  144.  		    weapon = BULLWHIP;  145.  		    break;  146.  		case PM_BARBARIAN:  147.  		    weapon = rn2(2) ? TWO_HANDED_SWORD : BATTLE_AXE;  148.  		    break;  149.  		case PM_CAVEMAN:  150.  		case PM_CAVEWOMAN:  151.  		    weapon = CLUB;  152.  		    break;  153.  		case PM_ELF:  154.  		    weapon = ELVEN_SHORT_SWORD;  155.  		    break;  156.  		case PM_HEALER:  157.  		    weapon = SCALPEL;  158.  		    break;  159.  		case PM_KNIGHT:  160.  		    weapon = LONG_SWORD;  161.  		    break;  162.  		case PM_PRIEST:  163.  		case PM_PRIESTESS:  164.  		    weapon = MACE;  165.  		    break; 166. 		case PM_ROGUE: 167. 		    weapon = SHORT_SWORD; 168. 		    break; 169. 		case PM_SAMURAI: 170. 		    weapon = KATANA; 171. 		    break; 172. #ifdef TOURIST 173. 		case PM_TOURIST: 174. 		    weapon = 0; 175. 		    break; 176. #endif 177. 		case PM_VALKYRIE: 178. 		    weapon = LONG_SWORD; 179. 		    break; 180. 		case PM_WIZARD: 181. 		    weapon = ATHAME; 182. 		    break; 183. 		default: impossible("bad mplayer monster"); 184. 		    weapon = 0; 185. 		    break; 186. 	    }  187.  	    if (rn2(2) && weapon) 188. 		otmp = mksobj(weapon, TRUE, FALSE); 189. 	    else 190. 		otmp = mksobj(rn2(2) ? LONG_SWORD :  191.  			      rnd_class(SPEAR, BULLWHIP), TRUE, FALSE); 192. 	    otmp->spe = (special ? rn1(5,4) : rn2(4)); 193. 	    if (!rn2(3)) otmp->oerodeproof = 1; 194. 	    else if (!rn2(2)) otmp->greased = 1; 195. 	    if (special && rn2(2)) 196. 		otmp = mk_artifact(otmp, A_NONE); 197. 	    mpickobj(mtmp, otmp); 198.  199.  	    if(special) { 200. 	        if (!rn2(10)) 201. 		    (void) mongets(mtmp, rn2(3) ? LUCKSTONE : LOADSTONE); 202. 	        if (rn2(8)) 203. 	        mk_mplayer_armor(mtmp, ELVEN_LEATHER_HELM, HELM_OF_TELEPATHY); 204. 	        if (!rn2(3)) 205. 		    mk_mplayer_armor(mtmp, GRAY_DRAGON_SCALE_MAIL,  206.  			YELLOW_DRAGON_SCALE_MAIL); 207. 	        else if (rn2(15)) 208. 		    mk_mplayer_armor(mtmp, PLATE_MAIL, CHAIN_MAIL); 209. 	        if (rn2(8)) 210. 		    mk_mplayer_armor(mtmp, ELVEN_SHIELD,  211.  				               SHIELD_OF_REFLECTION); 212. 	        if (rn2(8)) 213. 		    mk_mplayer_armor(mtmp, LEATHER_GLOVES,  214.  				               GAUNTLETS_OF_DEXTERITY); 215. 	        if (rn2(8)) 216. 		    mk_mplayer_armor(mtmp, LOW_BOOTS, LEVITATION_BOOTS); 217. 	        m_dowear(mtmp, TRUE); 218.  219.  	        quan = rn2(3) ? rn2(3) : rn2(16); 220. 	        while(quan--) 221. 		    (void)mongets(mtmp, rnd_class(DILITHIUM_CRYSTAL, JADE)); 222. 	        /* To get the gold "right" would mean a player can double his */ 223. 	        /* gold supply by killing one mplayer. Not good. */ 224.  	        mtmp->mgold = rn2(1000); 225. 	        quan = rn2(10); 226. 	        while(quan--) 227. 		    mpickobj(mtmp, mkobj(RANDOM_CLASS, FALSE)); 228. 	    }  229.  	    quan = rnd(3); 230. 	    while(quan--) 231. 		(void)mongets(mtmp, rnd_offensive_item(mtmp)); 232. 	    quan = rnd(3); 233. 	    while(quan--) 234. 		(void)mongets(mtmp, rnd_defensive_item(mtmp)); 235. 	    quan = rnd(3); 236. 	    while(quan--) 237. 		(void)mongets(mtmp, rnd_misc_item(mtmp)); 238. 	}  239.   240.  	return(mtmp); 241. }  242.   243.  /* create the indicated number (num) of monster-players, 244.  * randomly chosen, and in randomly chosen (free) locations 245.  * on the level. If "special", the size of num should not 246.  * be bigger than the number of _non-repeated_ names in the 247.  * developers array, otherwise a bunch of Adams and Eves will 248.  * fill up the overflow. 249.  */  250.  void 251. create_mplayers(num, special) 252. register int num; 253. boolean special; 254. {  255.  	register int pm, x, y;  256. 257. 	while(num) { 258. 		int tryct = 0; 259.  260.  		/* roll for character class */ 261. 		pm = PM_ARCHEOLOGIST + rn2(PM_WIZARD - PM_ARCHEOLOGIST + 1); 262.  263.  		/* roll for an available location */ 264. 		do { 265. 		    x = rn1(COLNO-4, 2); 266. 		    y = rnd(ROWNO-2); 267. 		} while(!goodpos(x, y, (struct monst *)0, &mons[pm]) ||  268.  			 tryct++ >= 50); 269.  270.  		/* if pos not found in 50 tries, don't bother to continue */ 271. 		if(tryct > 50) return; 272.  273.  		(void) mk_mplayer(&mons[pm], (xchar)x, (xchar)y, special); 274. 		num--; 275. 	}  276.  }  277.   278.  void 279. mplayer_talk(mtmp) 280. register struct monst *mtmp; 281. {  282.  	static const char *same_class_msg[3] = { 283. 		"I can't win, and neither will you!", 284. 		"You don't deserve to win!", 285. 		"Mine should be the honor, not yours!", 286. 	},		  *other_class_msg[3] = { 287. 		"The low-life wants to talk, eh?", 288. 		"Fight, scum!", 289. 		"Here is what I have to say!", 290. 	};  291.   292.  	if(mtmp->mpeaceful) return; /* will drop to humanoid talk */ 293.  294.  	pline("Talk? -- %s", u.role == highc(*mtmp->data->mname) ?  295.  		same_class_msg[rn2(3)] : other_class_msg[rn2(3)]); 296. }  297.   298.  /*mplayer.c*/