Source:NetHack 3.4.0/makemon.c

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

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

1.   /*	SCCS Id: @(#)makemon.c	3.4	2002/02/07	*/ 2.   /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ 3.    /* NetHack may be freely redistributed. See license for details. */ 4.     5.    #include "hack.h"  6.    #include "epri.h"  7.    #include "emin.h"  8.    #include "edog.h"  9.    #ifdef REINCARNATION 10.  #include   11. #endif 12.   13.   STATIC_VAR NEARDATA struct monst zeromonst; 14.   15.   /* this assumes that a human quest leader or nemesis is an archetype 16.     of the corresponding role; that isn't so for some roles (tourist  17.      for instance) but is for the priests and monks we use it for... */ 18.   #define quest_mon_represents_role(mptr,role_pm) \ 19.  		(mptr->mlet == S_HUMAN && Role_if(role_pm) && \  20.   		  (mptr->msound == MS_LEADER || mptr->msound == MS_NEMESIS)) 21.   22.   #ifdef OVL0 23.  STATIC_DCL boolean FDECL(uncommon, (int)); 24.  STATIC_DCL int FDECL(align_shift, (struct permonst *)); 25.  #endif /* OVL0 */ 26.  STATIC_DCL boolean FDECL(wrong_elem_type, (struct permonst *)); 27.  STATIC_DCL void FDECL(m_initgrp,(struct monst *,int,int,int)); 28.  STATIC_DCL void FDECL(m_initthrow,(struct monst *,int,int)); 29.  STATIC_DCL void FDECL(m_initweap,(struct monst *)); 30.  #ifdef OVL1 31.  STATIC_DCL void FDECL(m_initinv,(struct monst *)); 32.  #endif /* OVL1 */ 33.   34.   extern const int monstr[]; 35.   36.   #define m_initsgrp(mtmp, x, y)	m_initgrp(mtmp, x, y, 3) 37.  #define m_initlgrp(mtmp, x, y)	m_initgrp(mtmp, x, y, 10) 38.  #define toostrong(monindx, lev) (monstr[monindx] > lev) 39.  #define tooweak(monindx, lev)	(monstr[monindx] < lev) 40.   41.   #ifdef OVLB 42.  boolean 43.  is_home_elemental(ptr) 44.  register struct permonst *ptr; 45.  {  46.   	if (ptr->mlet == S_ELEMENTAL) 47.  	    switch (monsndx(ptr)) { 48.  		case PM_AIR_ELEMENTAL: return Is_airlevel(&u.uz); 49.  		case PM_FIRE_ELEMENTAL: return Is_firelevel(&u.uz); 50.  		case PM_EARTH_ELEMENTAL: return Is_earthlevel(&u.uz); 51.  		case PM_WATER_ELEMENTAL: return Is_waterlevel(&u.uz); 52.  	    }  53.   	return FALSE; 54.  }  55.    56.   /*  57.    * Return true if the given monster cannot exist on this elemental level. 58.   */  59.   STATIC_OVL boolean 60.  wrong_elem_type(ptr) 61.      register struct permonst *ptr; 62.  {  63.       if (ptr->mlet == S_ELEMENTAL) { 64.  	return((boolean)(!is_home_elemental(ptr))); 65.      } else if (Is_earthlevel(&u.uz)) { 66.  	/* no restrictions? */ 67.       } else if (Is_waterlevel(&u.uz)) { 68.  	/* just monsters that can swim */ 69.  	if(!is_swimmer(ptr)) return TRUE; 70.      } else if (Is_firelevel(&u.uz)) { 71.  	if (!pm_resistance(ptr,MR_FIRE)) return TRUE; 72.      } else if (Is_airlevel(&u.uz)) { 73.  	if(!(is_flyer(ptr) && ptr->mlet != S_TRAPPER) && !is_floater(ptr)  74.   	   && !amorphous(ptr) && !noncorporeal(ptr) && !is_whirly(ptr)) 75.  	    return TRUE; 76.      }  77.       return FALSE; 78.  }  79.    80.   STATIC_OVL void 81.  m_initgrp(mtmp, x, y, n)	/* make a group just like mtmp */ 82.  register struct monst *mtmp; 83.  register int x, y, n;  84. { 85.   	coord mm; 86.  	register int cnt = rnd(n); 87.  	struct monst *mon; 88.  #if defined(__GNUC__) && (defined(HPUX) || defined(DGUX)) 89.  	/* There is an unresolved problem with several people finding that 90.  	 * the game hangs eating CPU; if interrupted and restored, the level 91.  	 * will be filled with monsters. Of those reports giving system type, 92.  	 * there were two DG/UX and two HP-UX, all using gcc as the compiler. 93.  	 * hcroft@hpopb1.cern.ch, using gcc 2.6.3 on HP-UX, says that the 94.  	 * problem went away for him and another reporter-to-newsgroup 95.  	 * after adding this debugging code. This has almost got to be a 96. * compiler bug, but until somebody tracks it down and gets it fixed, 97.  	 * might as well go with the "but it went away when I tried to find  98.   	 * it" code. 99.  	 */  100.  	int cnttmp,cntdiv; 101.  102.  	cnttmp = cnt; 103. # ifdef DEBUG 104. 	pline("init group call x=%d,y=%d,n=%d,cnt=%d.", x, y, n, cnt); 105. # endif 106. 	cntdiv = ((u.ulevel < 3) ? 4 : (u.ulevel < 5) ? 2 : 1); 107. #endif 108. 	/* Tuning: cut down on swarming at low character levels [mrs] */ 109. 	cnt /= (u.ulevel < 3) ? 4 : (u.ulevel < 5) ? 2 : 1; 110.  #if defined(__GNUC__) && (defined(HPUX) || defined(DGUX)) 111. 	if (cnt != (cnttmp/cntdiv)) { 112. 		pline("cnt=%d using %d, cnttmp=%d, cntdiv=%d", cnt,  113.  			(u.ulevel < 3) ? 4 : (u.ulevel < 5) ? 2 : 1,  114.  			cnttmp, cntdiv); 115. 	}  116.  #endif 117. 	if(!cnt) cnt++; 118. #if defined(__GNUC__) && (defined(HPUX) || defined(DGUX)) 119. 	if (cnt < 0) cnt = 1; 120. 	if (cnt > 10) cnt = 10; 121. #endif 122.  123.  	mm.x = x;  124. mm.y = y; 125. while(cnt--) { 126. 		if (peace_minded(mtmp->data)) continue; 127. 		/* Don't create groups of peaceful monsters since they'll get 128. 		 * in our way. If the monster has a percentage chance so some 129. 		 * are peaceful and some are not, the result will just be a  130. * smaller group. 131. 		 */  132.  		if (enexto(&mm, mm.x, mm.y, mtmp->data)) { 133. 		    mon = makemon(mtmp->data, mm.x, mm.y, NO_MM_FLAGS); 134. 		    mon->mpeaceful = FALSE; 135. 		    mon->mavenge = 0; 136. 		    set_malign(mon); 137. 		    /* Undo the second peace_minded check in makemon; if the 138. 		     * monster turned out to be peaceful the first time we  139. * didn't create it at all; we don't want a second check. 140. 		     */  141.  		}  142.  	}  143.  }  144.   145.  STATIC_OVL 146. void 147. m_initthrow(mtmp,otyp,oquan) 148. struct monst *mtmp; 149. int otyp,oquan; 150. {  151.  	register struct obj *otmp; 152.  153.  	otmp = mksobj(otyp, TRUE, FALSE); 154. 	otmp->quan = (long) rn1(oquan, 3); 155. 	otmp->owt = weight(otmp); 156. 	if (otyp == ORCISH_ARROW) otmp->opoisoned = TRUE; 157. 	(void) mpickobj(mtmp, otmp); 158. }  159.   160.  #endif /* OVLB */ 161. #ifdef OVL2 162.  163.  STATIC_OVL void 164. m_initweap(mtmp) 165. register struct monst *mtmp; 166. {  167.  	register struct permonst *ptr = mtmp->data; 168. 	register int mm = monsndx(ptr); 169. 	struct obj *otmp; 170.  171.  #ifdef REINCARNATION 172. 	if (Is_rogue_level(&u.uz)) return; 173. #endif 174. /*  175.   *	first a few special cases: 176.  *  177.   *		giants get a boulder to throw sometimes. 178.  *		ettins get clubs 179.  *		kobolds get darts to throw 180.  *		centaurs get some sort of bow & arrows or bolts 181.  *		soldiers get all sorts of things. 182.  *		kops get clubs & cream pies. 183.  */  184.  	switch (ptr->mlet) { 185. 	    case S_GIANT: 186. 		if (rn2(2)) (void)mongets(mtmp, (mm != PM_ETTIN) ?  187.  				    BOULDER : CLUB); 188. 		break; 189. 	    case S_HUMAN: 190. 		if(is_mercenary(ptr)) { 191. 		    int w1 = 0, w2 = 0; 192. 		    switch (mm) { 193.  194.  			case PM_WATCHMAN: 195. 			case PM_SOLDIER: 196. 			  if (!rn2(3)) { 197. 			      w1 = rn1(BEC_DE_CORBIN - PARTISAN + 1, PARTISAN); 198. 			      w2 = rn2(2) ? DAGGER : KNIFE; 199. 			  } else w1 = rn2(2) ? SPEAR : SHORT_SWORD; 200. 			  break; 201. 			case PM_SERGEANT: 202. 			  w1 = rn2(2) ? FLAIL : MACE; 203. 			  break; 204. 			case PM_LIEUTENANT: 205. 			  w1 = rn2(2) ? BROADSWORD : LONG_SWORD; 206. 			  break; 207. 			case PM_CAPTAIN: 208. 			case PM_WATCH_CAPTAIN: 209. 			  w1 = rn2(2) ? LONG_SWORD : SILVER_SABER; 210. 			  break; 211. 			default: 212. 			  if (!rn2(4)) w1 = DAGGER; 213. 			  if (!rn2(7)) w2 = SPEAR; 214. 			  break; 215. 		    }  216.  		    if (w1) (void)mongets(mtmp, w1); 217. 		    if (!w2 && w1 != DAGGER && !rn2(4)) w2 = KNIFE; 218. 		    if (w2) (void)mongets(mtmp, w2); 219. 		} else if (is_elf(ptr)) { 220. 		    if (rn2(2)) 221. 			(void) mongets(mtmp,  222.  				   rn2(2) ? ELVEN_MITHRIL_COAT : ELVEN_CLOAK); 223. 		    if (rn2(2)) (void)mongets(mtmp, ELVEN_LEATHER_HELM); 224. 		    else if (!rn2(4)) (void)mongets(mtmp, ELVEN_BOOTS); 225. 		    if (rn2(2)) (void)mongets(mtmp, ELVEN_DAGGER); 226. 		    switch (rn2(3)) { 227. 			case 0: 228. 			    if (!rn2(4)) (void)mongets(mtmp, ELVEN_SHIELD); 229. 			    if (rn2(3)) (void)mongets(mtmp, ELVEN_SHORT_SWORD); 230. 			    (void)mongets(mtmp, ELVEN_BOW); 231. 			    m_initthrow(mtmp, ELVEN_ARROW, 12); 232. 			    break; 233. 			case 1: 234. 			    (void)mongets(mtmp, ELVEN_BROADSWORD); 235. 			    if (rn2(2)) (void)mongets(mtmp, ELVEN_SHIELD); 236. 			    break; 237. 			case 2: 238. 			    if (rn2(2)) { 239. 				(void)mongets(mtmp, ELVEN_SPEAR); 240. 				(void)mongets(mtmp, ELVEN_SHIELD); 241. 			    }  242.  			    break; 243. 		    }  244.  		    if (mm == PM_ELVENKING) { 245. 			if (rn2(3) || (in_mklev && Is_earthlevel(&u.uz))) 246. 			    (void)mongets(mtmp, PICK_AXE); 247. 			if (!rn2(50)) (void)mongets(mtmp, CRYSTAL_BALL); 248. 		    }  249.  		} else if (ptr->msound == MS_PRIEST ||  250.  			quest_mon_represents_role(ptr,PM_PRIEST)) { 251. 		    otmp = mksobj(MACE, FALSE, FALSE); 252. 		    if(otmp) { 253. 			otmp->spe = rnd(3); 254. 			if(!rn2(2)) curse(otmp); 255. 			(void) mpickobj(mtmp, otmp); 256. 		    }  257.  		}  258.  		break; 259.  260.  	    case S_ANGEL: 261. 		{  262.  		    int spe2; 263.  264.  		    /* create minion stuff; can't use mongets */ 265. 		    otmp = mksobj(LONG_SWORD, FALSE, FALSE); 266.  267.  		    /* maybe make it special */ 268. 		    if (!rn2(20) || is_lord(ptr)) 269. 			otmp = oname(otmp, artiname( 270. 				rn2(2) ? ART_DEMONBANE : ART_SUNSWORD)); 271. 		    bless(otmp); 272. 		    otmp->oerodeproof = TRUE; 273. 		    spe2 = rn2(4); 274. 		    otmp->spe = max(otmp->spe, spe2); 275. 		    (void) mpickobj(mtmp, otmp); 276.  277.  		    otmp = mksobj(!rn2(4) || is_lord(ptr) ?  278.  				  SHIELD_OF_REFLECTION : LARGE_SHIELD,  279.  				  FALSE, FALSE); 280. 		    otmp->cursed = FALSE; 281. 		    otmp->oerodeproof = TRUE; 282. 		    otmp->spe = 0; 283. 		    (void) mpickobj(mtmp, otmp); 284. 		}  285.  		break; 286.  287.  	    case S_HUMANOID: 288. 		if (mm == PM_HOBBIT) { 289. 		    switch (rn2(3)) { 290. 			case 0: 291. 			    (void)mongets(mtmp, DAGGER); 292. 			    break; 293. 			case 1: 294. 			    (void)mongets(mtmp, ELVEN_DAGGER); 295. 			    break; 296. 			case 2: 297. 			    (void)mongets(mtmp, SLING); 298. 			    break; 299. 		      }  300.  		    if (!rn2(10)) (void)mongets(mtmp, ELVEN_MITHRIL_COAT); 301. 		    if (!rn2(10)) (void)mongets(mtmp, DWARVISH_CLOAK); 302. 		} else if (is_dwarf(ptr)) { 303. 		    if (rn2(7)) (void)mongets(mtmp, DWARVISH_CLOAK); 304. 		    if (rn2(7)) (void)mongets(mtmp, IRON_SHOES); 305. 		    if (!rn2(4)) { 306. 			(void)mongets(mtmp, DWARVISH_SHORT_SWORD); 307. 			/* note: you can't use a mattock with a shield */ 308. 			if (rn2(2)) (void)mongets(mtmp, DWARVISH_MATTOCK); 309. 			else { 310. 				(void)mongets(mtmp, AXE); 311. 				(void)mongets(mtmp, DWARVISH_ROUNDSHIELD); 312. 			}  313.  			(void)mongets(mtmp, DWARVISH_IRON_HELM); 314. 			if (!rn2(3)) 315. 			    (void)mongets(mtmp, DWARVISH_MITHRIL_COAT); 316. 		    } else { 317. 			(void)mongets(mtmp, !rn2(3) ? PICK_AXE : DAGGER); 318. 		    }  319.  		}  320.  		break; 321. # ifdef KOPS 322. 	    case S_KOP:		/* create Keystone Kops with cream pies to  323. * throw. As suggested by KAA. [MRS] 324. 				 */  325.  		if (!rn2(4)) m_initthrow(mtmp, CREAM_PIE, 2); 326. 		if (!rn2(3)) (void)mongets(mtmp,(rn2(2)) ? CLUB : RUBBER_HOSE); 327. 		break; 328. # endif 329. 	    case S_ORC: 330. 		if(rn2(2)) (void)mongets(mtmp, ORCISH_HELM); 331. 		switch (mm != PM_ORC_CAPTAIN ? mm :  332.  			rn2(2) ? PM_MORDOR_ORC : PM_URUK_HAI) { 333. 		    case PM_MORDOR_ORC: 334. 			if(!rn2(3)) (void)mongets(mtmp, SCIMITAR); 335. 			if(!rn2(3)) (void)mongets(mtmp, ORCISH_SHIELD); 336. 			if(!rn2(3)) (void)mongets(mtmp, KNIFE); 337. 			if(!rn2(3)) (void)mongets(mtmp, ORCISH_CHAIN_MAIL); 338. 			break; 339. 		    case PM_URUK_HAI: 340. 			if(!rn2(3)) (void)mongets(mtmp, ORCISH_CLOAK); 341. 			if(!rn2(3)) (void)mongets(mtmp, ORCISH_SHORT_SWORD); 342. 			if(!rn2(3)) (void)mongets(mtmp, IRON_SHOES); 343. 			if(!rn2(3)) { 344. 			    (void)mongets(mtmp, ORCISH_BOW); 345. 			    m_initthrow(mtmp, ORCISH_ARROW, 12); 346. 			}  347.  			if(!rn2(3)) (void)mongets(mtmp, URUK_HAI_SHIELD); 348. 			break; 349. 		    default: 350. 			if (mm != PM_ORC_SHAMAN && rn2(2)) 351. 			  (void)mongets(mtmp, (mm == PM_GOBLIN || rn2(2) == 0)  352.  						   ? ORCISH_DAGGER : SCIMITAR); 353. 		}  354.  		break; 355. 	    case S_OGRE: 356. 		if (!rn2(mm == PM_OGRE_KING ? 3 : mm == PM_OGRE_LORD ? 6 : 12)) 357.  		    (void) mongets(mtmp, BATTLE_AXE); 358. 		else 359. 		    (void) mongets(mtmp, CLUB); 360. 		break; 361. 	    case S_TROLL: 362. 		if (!rn2(2)) switch (rn2(4)) { 363. 		    case 0: (void)mongets(mtmp, RANSEUR); break; 364. 		    case 1: (void)mongets(mtmp, PARTISAN); break; 365. 		    case 2: (void)mongets(mtmp, GLAIVE); break; 366. 		    case 3: (void)mongets(mtmp, SPETUM); break; 367. 		}  368.  		break; 369. 	    case S_KOBOLD: 370. 		if (!rn2(4)) m_initthrow(mtmp, DART, 12); 371. 		break; 372.  373.  	    case S_CENTAUR: 374. 		if (rn2(2)) { 375. 		    if(ptr == &mons[PM_FOREST_CENTAUR]) { 376. 			(void)mongets(mtmp, BOW); 377. 			m_initthrow(mtmp, ARROW, 12); 378. 		    } else { 379. 			(void)mongets(mtmp, CROSSBOW); 380. 			m_initthrow(mtmp, CROSSBOW_BOLT, 12); 381. 		    }  382.  		}  383.  		break; 384. 	    case S_WRAITH: 385. 		(void)mongets(mtmp, KNIFE); 386. 		(void)mongets(mtmp, LONG_SWORD); 387. 		break; 388. 	    case S_ZOMBIE: 389. 		if (!rn2(4)) (void)mongets(mtmp, LEATHER_ARMOR); 390. 		if (!rn2(4)) 391. 			(void)mongets(mtmp, (rn2(3) ? KNIFE : SHORT_SWORD)); 392. 		break; 393. 	    case S_LIZARD: 394. 		if (mm == PM_SALAMANDER) 395. 			(void)mongets(mtmp, (rn2(7) ? SPEAR : rn2(3) ? 396. 					     TRIDENT : STILETTO)); 397. 		break; 398. 	    case S_DEMON: 399. 		switch (mm) { 400. 		    case PM_BALROG: 401. 			(void)mongets(mtmp, BULLWHIP); 402. 			(void)mongets(mtmp, BROADSWORD); 403. 			break; 404. 		    case PM_ORCUS: 405. 			(void)mongets(mtmp, WAN_DEATH); /* the Wand of Orcus */ 406. 			break; 407. 		    case PM_HORNED_DEVIL: 408. 			(void)mongets(mtmp, rn2(4) ? TRIDENT : BULLWHIP); 409. 			break; 410. 		    case PM_ICE_DEVIL: 411. 			if (!rn2(4)) (void)mongets(mtmp, SPEAR); 412. 			break; 413. 		    case PM_ASMODEUS: 414. 			(void)mongets(mtmp, WAN_COLD); 415. 			(void)mongets(mtmp, WAN_FIRE); 416. 			break; 417. 		    case PM_DISPATER: 418. 			(void)mongets(mtmp, WAN_STRIKING); 419. 			break; 420. 		    case PM_YEENOGHU: 421. 			(void)mongets(mtmp, FLAIL); 422. 			break; 423. 		}  424.  		/* prevent djinnis and mail daemons from leaving objects when 425. 		 * they vanish 426. 		 */  427.  		if (!is_demon(ptr)) break; 428. 		/* fall thru */ 429. /*  430.   *	Now the general case, Some chance of getting some type 431.  *	of weapon for "normal" monsters. Certain special types 432.  *	of monsters will get a bonus chance or different selections. 433.  */  434.  	    default: 435. 	      {  436.  		int bias; 437.  438.  		bias = is_lord(ptr) + is_prince(ptr) * 2 + extra_nasty(ptr); 439. 		switch(rnd(14 - (2 * bias))) { 440. 		    case 1: 441. 			if(strongmonst(ptr)) (void) mongets(mtmp, BATTLE_AXE); 442. 			else m_initthrow(mtmp, DART, 12); 443. 			break; 444. 		    case 2: 445. 			if(strongmonst(ptr)) 446. 			    (void) mongets(mtmp, TWO_HANDED_SWORD); 447. 			else { 448. 			    (void) mongets(mtmp, CROSSBOW); 449. 			    m_initthrow(mtmp, CROSSBOW_BOLT, 12); 450. 			}  451.  			break; 452. 		    case 3: 453. 			(void) mongets(mtmp, BOW); 454. 			m_initthrow(mtmp, ARROW, 12); 455. 			break; 456. 		    case 4: 457. 			if(strongmonst(ptr)) (void) mongets(mtmp, LONG_SWORD); 458. 			else m_initthrow(mtmp, DAGGER, 3); 459. 			break; 460. 		    case 5: 461. 			if(strongmonst(ptr)) 462. 			    (void) mongets(mtmp, LUCERN_HAMMER); 463. 			else (void) mongets(mtmp, AKLYS); 464. 			break; 465. 		    default: 466. 			break; 467. 		}  468.  	      }  469.  	      break; 470. 	}  471.  	if ((int) mtmp->m_lev > rn2(75)) 472. 		(void) mongets(mtmp, rnd_offensive_item(mtmp)); 473. }  474.   475.  #endif /* OVL2 */ 476. #ifdef OVL1 477.  478.  #ifdef GOLDOBJ 479. /*  480.   *   Makes up money for monster's inventory. 481.  *   This will change with silver & copper coins 482.  */  483.  void 484. mkmonmoney(mtmp, amount) 485. struct monst *mtmp; 486. long amount; 487. {  488.      struct obj *gold = mksobj(GOLD_PIECE, FALSE, FALSE); 489.     gold->quan = amount; 490.     add_to_minv(mtmp, gold); 491. }  492.  #endif 493.  494.  STATIC_OVL void 495. m_initinv(mtmp) 496. register struct	monst	*mtmp; 497. {  498.  	register int cnt; 499. 	register struct obj *otmp; 500. 	register struct permonst *ptr = mtmp->data; 501. #ifdef REINCARNATION 502. 	if (Is_rogue_level(&u.uz)) return; 503. #endif 504. /*  505.   *	Soldiers get armour & rations - armour approximates their ac. 506.  *	Nymphs may get mirror or potion of object detection. 507.  */  508.  	switch(ptr->mlet) { 509.  510.  	    case S_HUMAN: 511. 		if(is_mercenary(ptr)) { 512. 		    register int mac; 513.  514.  		    switch(monsndx(ptr)) { 515. 			case PM_GUARD: mac = -1; break; 516. 			case PM_SOLDIER: mac = 3; break; 517. 			case PM_SERGEANT: mac = 0; break; 518. 			case PM_LIEUTENANT: mac = -2; break; 519. 			case PM_CAPTAIN: mac = -3; break; 520. 			case PM_WATCHMAN: mac = 3; break; 521. 			case PM_WATCH_CAPTAIN: mac = -2; break; 522. 			default: impossible("odd mercenary %d?", monsndx(ptr)); 523. 				mac = 0; 524. 				break; 525. 		    }  526.   527.  		    if (mac < -1 && rn2(5)) 528. 			mac += 7 + mongets(mtmp, (rn2(5)) ?  529.  					   PLATE_MAIL : CRYSTAL_PLATE_MAIL); 530. 		    else if (mac < 3 && rn2(5)) 531. 			mac += 6 + mongets(mtmp, (rn2(3)) ?  532.  					   SPLINT_MAIL : BANDED_MAIL); 533. 		    else if (rn2(5)) 534. 			mac += 3 + mongets(mtmp, (rn2(3)) ?  535.  					   RING_MAIL : STUDDED_LEATHER_ARMOR); 536. 		    else 537. 			mac += 2 + mongets(mtmp, LEATHER_ARMOR); 538.  539.  		    if (mac < 10 && rn2(3)) 540. 			mac += 1 + mongets(mtmp, HELMET); 541. 		    else if (mac < 10 && rn2(2)) 542. 			mac += 1 + mongets(mtmp, DENTED_POT); 543. 		    if (mac < 10 && rn2(3)) 544. 			mac += 1 + mongets(mtmp, SMALL_SHIELD); 545. 		    else if (mac < 10 && rn2(2)) 546. 			mac += 2 + mongets(mtmp, LARGE_SHIELD); 547. 		    if (mac < 10 && rn2(3)) 548. 			mac += 1 + mongets(mtmp, LOW_BOOTS); 549. 		    else if (mac < 10 && rn2(2)) 550. 			mac += 2 + mongets(mtmp, HIGH_BOOTS); 551. 		    if (mac < 10 && rn2(3)) 552. 			mac += 1 + mongets(mtmp, LEATHER_GLOVES); 553. 		    else if (mac < 10 && rn2(2)) 554. 			mac += 1 + mongets(mtmp, LEATHER_CLOAK); 555.  556.  		    if(ptr != &mons[PM_GUARD] &&  557.  			ptr != &mons[PM_WATCHMAN] &&  558.  			ptr != &mons[PM_WATCH_CAPTAIN]) { 559. 			if (!rn2(3)) (void) mongets(mtmp, K_RATION); 560. 			if (!rn2(2)) (void) mongets(mtmp, C_RATION); 561. 			if (ptr != &mons[PM_SOLDIER] && !rn2(3)) 562. 				(void) mongets(mtmp, BUGLE); 563. 		    } else 564. 			   if (ptr == &mons[PM_WATCHMAN] && rn2(3)) 565. 				(void) mongets(mtmp, TIN_WHISTLE); 566. 		} else if (ptr == &mons[PM_SHOPKEEPER]) { 567. 		    (void) mongets(mtmp,SKELETON_KEY); 568. 		    switch (rn2(4)) { 569. 		    /* MAJOR fall through ... */ 570.  		    case 0: (void) mongets(mtmp, WAN_MAGIC_MISSILE); 571. 		    case 1: (void) mongets(mtmp, POT_EXTRA_HEALING); 572. 		    case 2: (void) mongets(mtmp, POT_HEALING); 573. 		    case 3: (void) mongets(mtmp, WAN_STRIKING); 574. 		    }  575.  		} else if (ptr->msound == MS_PRIEST ||  576.  			quest_mon_represents_role(ptr,PM_PRIEST)) { 577. 		    (void) mongets(mtmp, rn2(7) ? ROBE :  578.  					     rn2(3) ? CLOAK_OF_PROTECTION :  579.  						 CLOAK_OF_MAGIC_RESISTANCE); 580. 		    (void) mongets(mtmp, SMALL_SHIELD); 581. #ifndef GOLDOBJ 582. 		    mtmp->mgold = (long)rn1(10,20); 583. #else 584. 		    mkmonmoney(mtmp,(long)rn1(10,20)); 585. #endif 586. 		} else if (quest_mon_represents_role(ptr,PM_MONK)) { 587. 		    (void) mongets(mtmp, rn2(11) ? ROBE :  588.  					     CLOAK_OF_MAGIC_RESISTANCE); 589. 		}  590.  		break; 591. 	    case S_NYMPH: 592. 		if(!rn2(2)) (void) mongets(mtmp, MIRROR); 593. 		if(!rn2(2)) (void) mongets(mtmp, POT_OBJECT_DETECTION); 594. 		break; 595. 	    case S_GIANT: 596. 		if (ptr == &mons[PM_MINOTAUR]) { 597. 		    if (!rn2(3) || (in_mklev && Is_earthlevel(&u.uz))) 598. 			(void) mongets(mtmp, WAN_DIGGING); 599. 		} else if (is_giant(ptr)) { 600. 		    for (cnt = rn2((int)(mtmp->m_lev / 2)); cnt; cnt--) { 601. 			otmp = mksobj(rnd_class(DILITHIUM_CRYSTAL,LUCKSTONE-1),  602.  				      FALSE, FALSE); 603. 			otmp->quan = (long) rn1(2, 3); 604. 			otmp->owt = weight(otmp); 605. 			(void) mpickobj(mtmp, otmp); 606. 		    }  607.  		}  608.  		break; 609. 	    case S_WRAITH: 610. 		if (ptr == &mons[PM_NAZGUL]) { 611. 			otmp = mksobj(RIN_INVISIBILITY, FALSE, FALSE); 612. 			curse(otmp); 613. 			(void) mpickobj(mtmp, otmp); 614. 		}  615.  		break; 616. 	    case S_LICH: 617. 		if (ptr == &mons[PM_MASTER_LICH] && !rn2(13)) 618. 			(void)mongets(mtmp, (rn2(7) ? ATHAME : WAN_NOTHING)); 619. 		else if (ptr == &mons[PM_ARCH_LICH] && !rn2(3)) { 620. 			otmp = mksobj(rn2(3) ? ATHAME : QUARTERSTAFF,  621.  				      TRUE, rn2(13) ? FALSE : TRUE); 622. 			if (otmp->spe < 2) otmp->spe = rnd(3); 623. 			if (!rn2(4)) otmp->oerodeproof = 1; 624. 			(void) mpickobj(mtmp, otmp); 625. 		}  626.  		break; 627. 	    case S_MUMMY: 628. 		if (rn2(7)) (void)mongets(mtmp, MUMMY_WRAPPING); 629. 		break; 630. 	    case S_QUANTMECH: 631. 		if (!rn2(20)) { 632. 			otmp = mksobj(LARGE_BOX, FALSE, FALSE); 633. 			otmp->spe = 1; /* flag for special box */ 634. 			otmp->owt = weight(otmp); 635. 			(void) mpickobj(mtmp, otmp); 636. 		}  637.  		break; 638. 	    case S_LEPRECHAUN: 639. #ifndef GOLDOBJ 640. 		mtmp->mgold = (long) d(level_difficulty, 30); 641. #else 642. 		mkmonmoney(mtmp, (long) d(level_difficulty, 30)); 643. #endif 644. 		break; 645. 	    default: 646. 		break; 647. 	}  648.   649.  	/* ordinary soldiers rarely have access to magic (or gold :-) */ 650. 	if (ptr == &mons[PM_SOLDIER] && rn2(13)) return; 651.  652.  	if ((int) mtmp->m_lev > rn2(50)) 653. 		(void) mongets(mtmp, rnd_defensive_item(mtmp)); 654. 	if ((int) mtmp->m_lev > rn2(100)) 655. 		(void) mongets(mtmp, rnd_misc_item(mtmp)); 656. #ifndef GOLDOBJ 657. 	if (likes_gold(ptr) && !mtmp->mgold && !rn2(5)) 658. 		mtmp->mgold = 659. 		      (long) d(level_difficulty, mtmp->minvent ? 5 : 10); 660. #else 661. 	if (likes_gold(ptr) && !findgold(mtmp->minvent) && !rn2(5)) 662. 		mkmonmoney(mtmp, (long) d(level_difficulty, mtmp->minvent ? 5 : 10)); 663.  #endif 664. }  665.   666.  struct monst * 667. clone_mon(mon) 668. struct monst *mon; 669. {  670.  	coord mm; 671. 	struct monst *m2; 672.  673.  	/* may be too weak or have been extinguished for population control */ 674. 	if (mon->mhp <= 1 || (mvitals[monsndx(mon->data)].mvflags & G_EXTINCT)) 675. 	    return (struct monst *)0; 676.  677.  	mm.x = mon->mx; 678. 	mm.y = mon->my; 679. 	if (!enexto(&mm, mm.x, mm.y, mon->data) || MON_AT(mm.x, mm.y)) 680. 	    return (struct monst *)0; 681. 	m2 = newmonst(0); 682. 	*m2 = *mon;			/* copy condition of old monster */ 683. 	m2->nmon = fmon; 684. 	fmon = m2; 685. 	m2->m_id = flags.ident++; 686. 	if (!m2->m_id) m2->m_id = flags.ident++;	/* ident overflowed */ 687. 	m2->mx = mm.x;  688. m2->my = mm.y; 689. 690. 	m2->minvent = (struct obj *) 0; /* objects don't clone */ 691. 	m2->mleashed = FALSE; 692. #ifndef GOLDOBJ 693. 	m2->mgold = 0L; 694. #endif 695. 	/* Max HP the same, but current HP halved for both. The caller 696. 	 * might want to override this by halving the max HP also. 697. 	 * When current HP is odd, the original keeps the extra point. 698. 	 */  699.  	m2->mhpmax = mon->mhpmax; 700. 	m2->mhp = mon->mhp / 2; 701. 	mon->mhp -= m2->mhp; 702.  703.  	/* since shopkeepers and guards will only be cloned if they've been 704. 	 * polymorphed away from their original forms, the clone doesn't have 705. 	 * room for the extra information. we also don't want two shopkeepers 706. 	 * around for the same shop. 707. 	 */  708.  	if (mon->isshk) m2->isshk = FALSE; 709. 	if (mon->isgd) m2->isgd = FALSE; 710. 	if (mon->ispriest) m2->ispriest = FALSE; 711. 	m2->mxlth = 0; 712. 	place_monster(m2, m2->mx, m2->my); 713. 	if (emits_light(m2->data)) 714. 	    new_light_source(m2->mx, m2->my, emits_light(m2->data),  715.  			     LS_MONSTER, (genericptr_t)m2); 716. 	if (m2->mnamelth) { 717. 	    m2->mnamelth = 0; /* or it won't get allocated */ 718. 	    m2 = christen_monst(m2, NAME(mon)); 719. 	}  720.  	newsym(m2->mx,m2->my);	/* display the new monster */ 721. 	if (mon->mtame) { 722. 	    struct monst *m3; 723.  724.  	    if (mon->isminion) { 725. 		m3 = newmonst(sizeof(struct epri) + mon->mnamelth); 726. 		*m3 = *m2; 727. 		m3->mxlth = sizeof(struct epri); 728. 		if (m2->mnamelth) Strcpy(NAME(m3), NAME(m2)); 729. 		*(EPRI(m3)) = *(EPRI(mon)); 730. 		replmon(m2, m3); 731. 		m2 = m3; 732. 	    } else { 733. 		/* because m2 is a copy of mon it is tame but not init'ed. 734. 		 * however, tamedog will not re-tame a tame dog, so m2  735. * must be made non-tame to get initialized properly. 736. 		 */  737.  		m2->mtame = 0; 738. 		if ((m3 = tamedog(m2, (struct obj *)0)) != 0) { 739. 		    m2 = m3; 740. 		    *(EDOG(m2)) = *(EDOG(mon)); 741. 		}  742.  	    }  743.  	}  744.  	return m2; 745. }  746.   747.  /*  748.   * called with [x,y] = coordinates; 749.  *	[0,0] means anyplace 750.  *	[u.ux,u.uy] means: near player (if !in_mklev) 751.  *  752.   *	In case we make a monster group, only return the one at [x,y]. 753.  */  754.  struct monst * 755. makemon(ptr, x, y, mmflags) 756. register struct permonst *ptr; 757. register int	x, y;  758. register int	mmflags; 759. {  760.  	register struct monst *mtmp; 761. 	int mndx, mcham, ct, mitem, xlth; 762. 	boolean anymon = (!ptr); 763. 	boolean byyou = (x == u.ux && y == u.uy); 764. 	boolean allow_minvent = ((mmflags & NO_MINVENT) == 0); 765. 	boolean countbirth = ((mmflags & MM_NOCOUNTBIRTH) == 0); 766. 	uchar lim; 767.  768.  	/* if caller wants random location, do it here */ 769. 	if(x == 0 && y == 0) { 770. 		int tryct = 0;	/* careful with bigrooms */ 771. 		struct monst fakemon; 772.  773.  		fakemon.data = ptr;	/* set up for goodpos */ 774. 		do { 775. 			x = rn1(COLNO-3,2); 776. 			y = rn2(ROWNO); 777. 		} while(!goodpos(x, y, ptr ? &fakemon : (struct monst *)0) || 778.  			(!in_mklev && tryct++ < 50 && cansee(x, y))); 779. 	} else if (byyou && !in_mklev) { 780. 		coord bypos; 781.  782.  		if(enexto(&bypos, u.ux, u.uy, ptr)) { 783. 			x = bypos.x;  784. y = bypos.y; 785. } else 786. 			return((struct monst *)0); 787. 	}  788.   789.  	/* if a monster already exists at the position, return */ 790. 	if(MON_AT(x, y)) 791. 		return((struct monst *) 0); 792.  793.  	if(ptr){ 794. 		mndx = monsndx(ptr); 795. 		/* if you are to make a specific monster and it has 796. 		   already been genocided, return */ 797. 		if (mvitals[mndx].mvflags & G_GENOD) return((struct monst *) 0); 798. #ifdef DEBUG 799. 		if (wizard && (mvitals[mndx].mvflags & G_EXTINCT)) 800. 		    pline("Explicitly creating extinct monster %s.",  801.  			mons[mndx].mname); 802. #endif 803. 	} else { 804. 		/* make a random (common) monster that can survive here. 805. 		 * (the special levels ask for random monsters at specific  806.  		 * positions, causing mass drowning on the medusa level,  807.  		 * for instance.) 808. 		 */  809.  		int tryct = 0;	/* maybe there are no good choices */ 810. 		struct monst fakemon; 811. 		do { 812. 			if(!(ptr = rndmonst)) { 813. #ifdef DEBUG 814. 			    pline("Warning: no monster."); 815. #endif 816. 			    return((struct monst *) 0);	/* no more monsters! */ 817.  			}  818.  			fakemon.data = ptr;	/* set up for goodpos */ 819. 		} while(!goodpos(x, y, &fakemon) && tryct++ < 50); 820. 		mndx = monsndx(ptr); 821. 	}  822.  	/* if it's unique, don't ever make it again */ 823. 	if (ptr->geno & G_UNIQ) mvitals[mndx].mvflags |= G_EXTINCT; 824.  825.  	/* Once a certain number of monsters are created, don't create any more 826. 	 * at random (i.e. make them extinct). The previous (3.2) behavior was 827. 	 * to do this when a certain number had _died_, which didn't make 828. 	 * much sense. 829. 	 * This version makes a little more sense but still requires that 830. 	 * the caller manually decrement mvitals if the monster is created 831. 	 * under circumstances where one would not logically expect the 832. 	 * creation to reduce the supply of wild monsters. Monster cloning 833.  	 * might be one such case, but we go against logic there in order to  834. * reduce the possibility of abuse. 835. 	 */  836.  	if (mvitals[mndx].born < 255 && countbirth) mvitals[mndx].born++; 837. 	lim = mbirth_limit(mndx); 838. 	if ((int) mvitals[mndx].born >= lim && !(mons[mndx].geno & G_NOGEN) &&  839.  		!(mvitals[mndx].mvflags & G_EXTINCT)) { 840. #ifdef DEBUG 841. 		pline("Automatically extinguished %s.",  842.  					makeplural(mons[mndx].mname)); 843. #endif 844. 		mvitals[mndx].mvflags |= G_EXTINCT; 845. 		reset_rndmonst(mndx); 846. 	}  847.   848.  	xlth = ptr->pxlth; 849. 	if (mmflags & MM_EDOG) xlth += sizeof(struct edog); 850. 	else if (mmflags & MM_EMIN) xlth += sizeof(struct emin); 851. 	mtmp = newmonst(xlth); 852. 	*mtmp = zeromonst;		/* clear all entries in structure */ 853. 	(void)memset((genericptr_t)mtmp->mextra, 0, xlth); 854. 	mtmp->nmon = fmon; 855. 	fmon = mtmp; 856. 	mtmp->m_id = flags.ident++; 857. 	if (!mtmp->m_id) mtmp->m_id = flags.ident++;	/* ident overflowed */ 858. 	set_mon_data(mtmp, ptr, 0); 859. 	if (mtmp->data->msound == MS_LEADER) 860. 	    quest_status.leader_m_id = mtmp->m_id; 861. 	mtmp->mxlth = xlth; 862. 	mtmp->mnum = mndx; 863.  864.  	mtmp->m_lev = adj_lev(ptr); 865. 	if (is_golem(ptr)) { 866. 	    mtmp->mhpmax = mtmp->mhp = golemhp(mndx); 867. 	} else if (is_rider(ptr)) { 868. 	    /* We want low HP, but a high mlevel so they can attack well */ 869. 	    mtmp->mhpmax = mtmp->mhp = d(10,8); 870. 	} else if (ptr->mlevel > 49) { 871. 	    /* "special" fixed hp monster 872. 	     * the hit points are encoded in the mlevel in a somewhat strange 873. 	     * way to fit in the 50..127 positive range of a signed character 874. 	     * above the 1..49 that indicate "normal" monster levels */ 875. 	    mtmp->mhpmax = mtmp->mhp = 2*(ptr->mlevel - 6); 876. 	    mtmp->m_lev = mtmp->mhp / 4;	/* approximation */ 877. 	} else if (ptr->mlet == S_DRAGON && mndx >= PM_GRAY_DRAGON) { 878. 	    /* adult dragons */ 879. 	    mtmp->mhpmax = mtmp->mhp = (int) (In_endgame(&u.uz) ?  880.  		(8 * mtmp->m_lev) : (4 * mtmp->m_lev + d((int)mtmp->m_lev, 4))); 881. 	} else if (!mtmp->m_lev) { 882. 	    mtmp->mhpmax = mtmp->mhp = rnd(4); 883. 	} else { 884. 	    mtmp->mhpmax = mtmp->mhp = d((int)mtmp->m_lev, 8); 885. 	    if (is_home_elemental(ptr)) 886. 		mtmp->mhpmax = (mtmp->mhp *= 3); 887. 	}  888.   889.  	if (is_female(ptr)) mtmp->female = TRUE; 890. 	else if (is_male(ptr)) mtmp->female = FALSE; 891. 	else mtmp->female = rn2(2);	/* ignored for neuters */ 892.  893.  	if (In_sokoban(&u.uz) && !mindless(ptr))  /* know about traps here */ 894. 	    mtmp->mtrapseen = (1L << (PIT - 1)) | (1L << (HOLE - 1)); 895. 	if (ptr->msound == MS_LEADER)		/* leader knows about portal */ 896. 	    mtmp->mtrapseen |= (1 << (MAGIC_PORTAL-1)); 897.  898.  	place_monster(mtmp, x, y); 899. 	mtmp->mcansee = mtmp->mcanmove = TRUE; 900. 	mtmp->mpeaceful = (mmflags & MM_ANGRY) ? FALSE : peace_minded(ptr); 901.  902.  	switch(ptr->mlet) { 903. 		case S_MIMIC: 904. 			set_mimic_sym(mtmp); 905. 			break; 906. 		case S_SPIDER: 907. 		case S_SNAKE: 908. 			if(in_mklev) 909. 			    if(x && y)  910. (void) mkobj_at(0, x, y, TRUE); 911. 			if(hides_under(ptr) && OBJ_AT(x, y)) 912. 			    mtmp->mundetected = TRUE; 913. 			break; 914. 		case S_LIGHT: 915. 		case S_ELEMENTAL: 916. 			if (mndx == PM_STALKER || mndx == PM_BLACK_LIGHT) { 917. 			    mtmp->perminvis = TRUE; 918. 			    mtmp->minvis = TRUE; 919. 			}  920.  			break; 921. 		case S_EEL: 922. 			if (is_pool(x, y)) 923. 			    mtmp->mundetected = TRUE; 924. 			break; 925. 		case S_LEPRECHAUN: 926. 			mtmp->msleeping = 1; 927. 			break; 928. 		case S_JABBERWOCK: 929. 		case S_NYMPH: 930. 			if (rn2(5) && !u.uhave.amulet) mtmp->msleeping = 1; 931. 			break; 932. 		case S_ORC: 933. 			if (Race_if(PM_ELF)) mtmp->mpeaceful = FALSE; 934. 			break; 935. 		case S_UNICORN: 936. 			if (is_unicorn(ptr) &&  937.  					sgn(u.ualign.type) == sgn(ptr->maligntyp)) 938. 				mtmp->mpeaceful = TRUE; 939. 			break; 940. 		case S_BAT: 941. 			if (Inhell && is_bat(ptr)) 942. 			    mon_adjust_speed(mtmp, 2, (struct obj *)0); 943. 			break; 944. 	}  945.  	if ((ct = emits_light(mtmp->data)) > 0) 946. 		new_light_source(mtmp->mx, mtmp->my, ct,  947.  				 LS_MONSTER, (genericptr_t)mtmp); 948. 	mitem = 0;	/* extra inventory item for this monster */ 949.  950.  	if ((mcham = pm_to_cham(mndx)) != CHAM_ORDINARY) { 951. 		/* If you're protected with a ring, don't create 952. 		 * any shape-changing chameleons -dgk 953. 		 */  954.  		if (Protection_from_shape_changers) 955. 			mtmp->cham = CHAM_ORDINARY; 956. 		else { 957. 			mtmp->cham = mcham; 958. 			(void) newcham(mtmp, rndmonst, FALSE); 959. 		}  960.  	} else if (mndx == PM_WIZARD_OF_YENDOR) { 961. 		mtmp->iswiz = TRUE; 962. 		flags.no_of_wizards++; 963. 		if (flags.no_of_wizards == 1 && Is_earthlevel(&u.uz)) 964. 			mitem = SPE_DIG; 965. 	} else if (mndx == PM_DJINNI) { 966. 		flags.djinni_count++; 967. 	} else if (mndx == PM_GHOST) { 968. 		flags.ghost_count++; 969. 		if (!(mmflags & MM_NONAME)) 970. 			mtmp = christen_monst(mtmp, rndghostname); 971. 	} else if (mndx == PM_VLAD_THE_IMPALER) { 972. 		mitem = CANDELABRUM_OF_INVOCATION; 973. 	} else if (mndx == PM_CROESUS) { 974. 		mitem = TWO_HANDED_SWORD; 975. 	} else if (ptr->msound == MS_NEMESIS) { 976. 		mitem = BELL_OF_OPENING; 977. 	} else if (mndx == PM_PESTILENCE) { 978. 		mitem = POT_SICKNESS; 979. 	}  980.  	if (mitem && allow_minvent) (void) mongets(mtmp, mitem); 981.  982.  	if(in_mklev) { 983. 		if(((is_ndemon(ptr)) || 984. 		    (mndx == PM_WUMPUS) || 985. 		    (mndx == PM_LONG_WORM) || 986. 		    (mndx == PM_GIANT_EEL)) && !u.uhave.amulet && rn2(5)) 987. 			mtmp->msleeping = TRUE; 988. 	} else { 989. 		if(byyou) { 990. 			newsym(mtmp->mx,mtmp->my); 991. 			set_apparxy(mtmp); 992. 		}  993.  	}  994.  	if(is_dprince(ptr) && ptr->msound == MS_BRIBE) { 995. 	    mtmp->mpeaceful = mtmp->minvis = mtmp->perminvis = 1; 996. 	    mtmp->mavenge = 0; 997. 	    if (uwep && uwep->oartifact == ART_EXCALIBUR) 998. 		mtmp->mpeaceful = mtmp->mtame = FALSE; 999. 	}  1000. #ifndef DCC30_BUG 1001. 	if (mndx == PM_LONG_WORM && (mtmp->wormno = get_wormno) != 0) 1002. #else 1003. 	/* DICE 3.0 doesn't like assigning and comparing mtmp->wormno in the 1004. 	 * same expression. 1005. 	 */ 1006. 	if (mndx == PM_LONG_WORM &&  1007. 		(mtmp->wormno = get_wormno, mtmp->wormno != 0)) 1008. #endif 1009. 	{ 1010. 	    /* we can now create worms with tails - 11/91 */ 1011. 	   initworm(mtmp, rn2(5)); 1012. 	   if (count_wsegs(mtmp)) place_worm_tail_randomly(mtmp, x, y); 1013. 	} 1014. 	set_malign(mtmp);		/* having finished peaceful changes */ 1015. 	if(anymon) { 1016. 	   if ((ptr->geno & G_SGROUP) && rn2(2)) { 1017. 		m_initsgrp(mtmp, mtmp->mx, mtmp->my); 1018. 	   } else if (ptr->geno & G_LGROUP) { 1019. 		if(rn2(3)) m_initlgrp(mtmp, mtmp->mx, mtmp->my); 1020. 		else	   m_initsgrp(mtmp, mtmp->mx, mtmp->my); 1021. 	   }  1022. 	}  1023.  1024. 	if (allow_minvent) { 1025. 	   if(is_armed(ptr)) 1026. 		m_initweap(mtmp);	/* equip with weapons / armor */ 1027. 	   m_initinv(mtmp);  /* add on a few special items incl. more armor */ 1028. 	   m_dowear(mtmp, TRUE); 1029. 	} else { 1030. 	   /* no initial inventory is allowed */ 1031. 	   if (mtmp->minvent) discard_minvent(mtmp); 1032. 	   mtmp->minvent = (struct obj *)0;    /* caller expects this */ 1033. 	} 1034. 	if ((ptr->mflags3 & M3_WAITMASK) && !(mmflags & MM_NOWAIT)) { 1035. 		if (ptr->mflags3 & M3_WAITFORU) 1036. 			mtmp->mstrategy |= STRAT_WAITFORU; 1037. 		if (ptr->mflags3 & M3_CLOSE) 1038. 			mtmp->mstrategy |= STRAT_CLOSE; 1039. 	} 1040.  1041. 	if (!in_mklev) 1042. 	   newsym(mtmp->mx,mtmp->my);	/* make sure the mon shows up */ 1043. 1044. 	return(mtmp); 1045. } 1046.  1047. int 1048. mbirth_limit(mndx) 1049. int mndx; 1050. { 1051. 	return (mndx == PM_NAZGUL ? 9 : mndx == PM_ERINYS ? 3 : MAXMONNO); 1052. } 1053.  1054. /* used for wand/scroll/spell of create monster */ 1055. /* returns TRUE iff you know monsters have been created */ 1056. boolean 1057. create_critters(cnt, mptr) 1058. int cnt; 1059. struct permonst *mptr;		/* usually null; used for confused reading */ 1060. { 1061. 	coord c;  1062. int x, y; 1063. struct monst *mon; 1064. 	boolean known = FALSE; 1065. #ifdef WIZARD 1066. 	boolean ask = wizard; 1067. #endif 1068. 1069. 	while (cnt--) { 1070. #ifdef WIZARD 1071. 	   if (ask) { 1072. 		if (create_particular) { 1073. 		   known = TRUE; 1074. 		   continue; 1075. 		} 1076. 		else ask = FALSE;	/* ESC will shut off prompting */ 1077. 	   }  1078. #endif 1079. 	   x = u.ux,  y = u.uy; 1080. 	   /* if in water, try to encourage an aquatic monster 1081. 	      by finding and then specifying another wet location */ 1082. 	   if (!mptr && u.uinwater && enexto(&c, x, y, &mons[PM_GIANT_EEL])) 1083. 		x = c.x, y = c.y;  1084. 1085. 	   mon = makemon(mptr, x, y, NO_MM_FLAGS); 1086. 	   if (mon && canspotmon(mon)) known = TRUE; 1087. 	} 1088. 	return known; 1089. } 1090.  1091. #endif /* OVL1 */ 1092. #ifdef OVL0 1093. 1094. STATIC_OVL boolean 1095. uncommon(mndx) 1096. int mndx; 1097. { 1098. 	if (mons[mndx].geno & (G_NOGEN | G_UNIQ)) return TRUE; 1099. 	if (mvitals[mndx].mvflags & G_GONE) return TRUE; 1100. 	if (Inhell) 1101. 		return(mons[mndx].maligntyp > A_NEUTRAL); 1102. 	else 1103. 		return((mons[mndx].geno & G_HELL) != 0); 1104. } 1105.  1106. /*  1107.  *	shift the probability of a monster's generation by  1108. *	comparing the dungeon alignment and monster alignment. 1109. *	return an integer in the range of 0-5. 1110. */  1111. STATIC_OVL int 1112. align_shift(ptr) 1113. register struct permonst *ptr; 1114. { 1115.     static NEARDATA long oldmoves = 0L;	/* != 1, starting value of moves */ 1116.    static NEARDATA s_level *lev; 1117.    register int alshift; 1118. 1119.     if(oldmoves != moves) { 1120. 	lev = Is_special(&u.uz); 1121. 	oldmoves = moves; 1122.    }  1123.     switch((lev) ? lev->flags.align : dungeons[u.uz.dnum].flags.align) { 1124.    default:	/* just in case */ 1125.    case AM_NONE:	alshift = 0; 1126. 			break; 1127.    case AM_LAWFUL:	alshift = (ptr->maligntyp+20)/(2*ALIGNWEIGHT); 1128. 			break; 1129.    case AM_NEUTRAL:	alshift = (20 - abs(ptr->maligntyp))/ALIGNWEIGHT; 1130. 			break; 1131.    case AM_CHAOTIC:	alshift = (-(ptr->maligntyp-20))/(2*ALIGNWEIGHT); 1132. 			break; 1133.    }  1134.     return alshift; 1135. } 1136.  1137. static NEARDATA struct { 1138. 	int choice_count; 1139. 	char mchoices[SPECIAL_PM];	/* value range is 0..127 */ 1140. } rndmonst_state = { -1, {0} }; 1141. 1142. /* select a random monster type */ 1143. struct permonst * 1144. rndmonst 1145. { 1146. 	register struct permonst *ptr; 1147. 	register int mndx, ct; 1148. 1149. 	if (u.uz.dnum == quest_dnum && rn2(7) && (ptr = qt_montype) != 0) 1150. 	   return ptr; 1151. 1152. 	if (rndmonst_state.choice_count < 0) {	/* need to recalculate */ 1153. 	   int zlevel, minmlev, maxmlev; 1154. 	   boolean elemlevel; 1155. #ifdef REINCARNATION 1156. 	   boolean upper; 1157. #endif 1158. 1159. 	    rndmonst_state.choice_count = 0; 1160. 	   /* look for first common monster */ 1161. 	   for (mndx = LOW_PM; mndx < SPECIAL_PM; mndx++) 1162. 		if (!uncommon(mndx)) break; 1163. 	   if (mndx == SPECIAL_PM) { 1164. 		/* evidently they've all been exterminated */ 1165. #ifdef DEBUG 1166. 		pline("rndmonst: no common mons!"); 1167. #endif 1168. 		return (struct permonst *)0; 1169. 	   } /* else `mndx' now ready for use below */ 1170. 	   zlevel = level_difficulty; 1171. 	   /* determine the level of the weakest monster to make. */ 1172. 	    minmlev = zlevel / 6; 1173. 	   /* determine the level of the strongest monster to make. */ 1174. 	    maxmlev = (zlevel + u.ulevel) / 2; 1175. #ifdef REINCARNATION 1176. 	   upper = Is_rogue_level(&u.uz); 1177. #endif 1178. 	   elemlevel = In_endgame(&u.uz) && !Is_astralevel(&u.uz); 1179. 1180. /*  1181.  *	Find out how many monsters exist in the range we have selected. 1182. */  1183. 	    /* (`mndx' initialized above) */ 1184. 	   for (mndx < SPECIAL_PM; mndx++) { 1185. 		ptr = &mons[mndx]; 1186. 		rndmonst_state.mchoices[mndx] = 0; 1187. 		if (tooweak(mndx, minmlev) || toostrong(mndx, maxmlev)) 1188. 		   continue; 1189. #ifdef REINCARNATION 1190. 		if (upper && !isupper(def_monsyms[(int)(ptr->mlet)])) continue; 1191. #endif 1192. 		if (elemlevel && wrong_elem_type(ptr)) continue; 1193. 		if (uncommon(mndx)) continue; 1194. 		if (Inhell && (ptr->geno & G_NOHELL)) continue; 1195. 		ct = (int)(ptr->geno & G_FREQ) + align_shift(ptr); 1196. 		if (ct < 0 || ct > 127) 1197. 		   panic("rndmonst: bad count [#%d: %d]", mndx, ct); 1198. 		rndmonst_state.choice_count += ct; 1199. 		rndmonst_state.mchoices[mndx] = (char)ct; 1200. 	   }  1201. /*  1202.  *	    Possible modification:  if choice_count is "too low", 1203. *	    expand minmlev..maxmlev range and try again. 1204. */  1205. 	} /* choice_count+mchoices[] recalc */ 1206. 1207. 	if (rndmonst_state.choice_count <= 0) { 1208. 	   /* maybe no common mons left, or all are too weak or too strong */ 1209. #ifdef DEBUG 1210. 	   Norep("rndmonst: choice_count=%d", rndmonst_state.choice_count); 1211. #endif 1212. 	   return (struct permonst *)0; 1213. 	} 1214.  1215. /*  1216.  *	Now, select a monster at random. 1217. */  1218. 	ct = rnd(rndmonst_state.choice_count); 1219. 	for (mndx = LOW_PM; mndx < SPECIAL_PM; mndx++) 1220. 	   if ((ct -= (int)rndmonst_state.mchoices[mndx]) <= 0) break; 1221. 1222. 	if (mndx == SPECIAL_PM || uncommon(mndx)) {	/* shouldn't happen */ 1223. 	   impossible("rndmonst: bad `mndx' [#%d]", mndx); 1224. 	   return (struct permonst *)0; 1225. 	} 1226. 	return &mons[mndx]; 1227. } 1228.  1229. /* called when you change level (experience or dungeon depth) or when 1230.   monster species can no longer be created (genocide or extinction) */ 1231. void 1232. reset_rndmonst(mndx) 1233. int mndx;	/* particular species that can no longer be created */ 1234. { 1235. 	/* cached selection info is out of date */ 1236. 	if (mndx == NON_PM) { 1237. 	   rndmonst_state.choice_count = -1;	/* full recalc needed */ 1238. 	} else if (mndx < SPECIAL_PM) { 1239. 	   rndmonst_state.choice_count -= rndmonst_state.mchoices[mndx]; 1240. 	   rndmonst_state.mchoices[mndx] = 0; 1241. 	} /* note: safe to ignore extinction of unique monsters */ 1242. } 1243.  1244. #endif /* OVL0 */ 1245. #ifdef OVL1 1246. 1247. /*	The routine below is used to make one of the multiple types 1248. *	of a given monster class. The second parameter specifies a 1249. *	special casing bit mask to allow the normal genesis 1250. *	masks to be deactivated. Returns 0 if no monsters 1251. *	in that class can be made. 1252. */  1253.  1254. struct permonst * 1255. mkclass(class,spc) 1256. char	class; 1257. int	spc; 1258. { 1259. 	register int	first, last, num = 0; 1260. 	int maxmlev, mask = (G_NOGEN | G_UNIQ) & ~spc; 1261. 1262. 	maxmlev = level_difficulty >> 1; 1263. 	if(class < 1 || class >= MAXMCLASSES) { 1264. 	   impossible("mkclass called with bad class!"); 1265. 	   return((struct permonst *) 0); 1266. 	} 1267. /*	Assumption #1:	monsters of a given class are contiguous in the 1268. *			mons[] array. 1269. */  1270. 	for (first = LOW_PM; first < SPECIAL_PM; first++) 1271. 	   if (mons[first].mlet == class) break; 1272. 	if (first == SPECIAL_PM) return (struct permonst *) 0; 1273. 1274. 	for (last = first;  1275. 		last < SPECIAL_PM && mons[last].mlet == class; last++) 1276. 	   if (!(mvitals[last].mvflags & G_GONE) && !(mons[last].geno & mask)  1277. 					&& !is_placeholder(&mons[last])) { 1278. 		/* consider it */ 1279. 		if(num && toostrong(last, maxmlev) && 1280. 		   monstr[last] != monstr[last-1] && rn2(2)) break; 1281. 		num += mons[last].geno & G_FREQ; 1282. 	   }  1283.  1284. 	if(!num) return((struct permonst *) 0); 1285. 1286. /*	Assumption #2:	monsters of a given class are presented in ascending 1287. *			order of strength. 1288. */  1289. 	for(num = rnd(num); num > 0; first++) 1290. 	   if (!(mvitals[first].mvflags & G_GONE) && !(mons[first].geno & mask)  1291. 					&& !is_placeholder(&mons[first])) { 1292. 		/* skew towards lower value monsters at lower exp. levels */ 1293. 		num -= mons[first].geno & G_FREQ; 1294. 		if (num && adj_lev(&mons[first]) > (u.ulevel*2)) { 1295. 		   /* but not when multiple monsters are same level */ 1296. 		   if (mons[first].mlevel != mons[first+1].mlevel) 1297. 			num--; 1298. 		} 1299. 	    }  1300. 	first--; /* correct an off-by-one error */ 1301. 1302. 	return(&mons[first]); 1303. } 1304.  1305. int 1306. adj_lev(ptr)	/* adjust strength of monsters based on u.uz and u.ulevel */ 1307. register struct permonst *ptr; 1308. { 1309. 	int	tmp, tmp2; 1310. 1311. 	if (ptr == &mons[PM_WIZARD_OF_YENDOR]) { 1312. 		/* does not depend on other strengths, but does get stronger 1313. 		 * every time he is killed 1314. 		 */ 1315. 		tmp = ptr->mlevel + mvitals[PM_WIZARD_OF_YENDOR].died; 1316. 		if (tmp > 49) tmp = 49; 1317. 		return tmp; 1318. 	} 1319.  1320. 	if((tmp = ptr->mlevel) > 49) return(50); /* "special" demons/devils */ 1321. 	tmp2 = (level_difficulty - tmp); 1322. 	if(tmp2 < 0) tmp--;		/* if mlevel > u.uz decrement tmp */ 1323. 	else tmp += (tmp2 / 5);		/* else increment 1 per five diff */ 1324. 1325. 	tmp2 = (u.ulevel - ptr->mlevel);	/* adjust vs. the player */ 1326. 	if(tmp2 > 0) tmp += (tmp2 / 4);		/* level as well */ 1327. 1328. 	tmp2 = (3 * ((int) ptr->mlevel))/ 2;	/* crude upper limit */ 1329. 	if (tmp2 > 49) tmp2 = 49;		/* hard upper limit */ 1330. 	return((tmp > tmp2) ? tmp2 : (tmp > 0 ? tmp : 0)); /* 0 lower limit */ 1331. } 1332.  1333. #endif /* OVL1 */ 1334. #ifdef OVLB 1335. 1336. struct permonst * 1337. grow_up(mtmp, victim)	/* `mtmp' might "grow up" into a bigger version */ 1338. struct monst *mtmp, *victim; 1339. { 1340. 	int oldtype, newtype, max_increase, cur_increase, 1341. 	   lev_limit, hp_threshold; 1342. 	struct permonst *ptr = mtmp->data; 1343. 1344. 	/* monster died after killing enemy but before calling this function */ 1345. 	/* currently possible if killing a gas spore */ 1346. 	if (mtmp->mhp <= 0) 1347. 	   return ((struct permonst *)0); 1348. 1349. 	/* growth limits differ depending on method of advancement */ 1350. 	if (victim) {		/* killed a monster */ 1351. 	   /*  1352. 	     * The HP threshold is the maximum number of hit points for the 1353. 	    * current level; once exceeded, a level will be gained. 1354. 	    * Possible bug: if somehow the hit points are already higher 1355. 	    * than that, monster will gain a level without any increase in HP. 1356. 	    */  1357. 	    hp_threshold = mtmp->m_lev * 8;		/* normal limit */ 1358. 	   if (!mtmp->m_lev) 1359. 		hp_threshold = 4; 1360. 	   else if (is_golem(ptr))	/* strange creatures */ 1361. 		hp_threshold = ((mtmp->mhpmax / 10) + 1) * 10 - 1; 1362. 	   else if (is_home_elemental(ptr)) 1363. 		hp_threshold *= 3; 1364. 	   lev_limit = 3 * (int)ptr->mlevel / 2;	/* same as adj_lev */ 1365. 	   /* number of hit points to gain; unlike for the player, we put 1366. 	      the limit at the bottom of the next level rather than the top */ 1367. 	   max_increase = rnd((int)victim->m_lev + 1); 1368. 	   if (mtmp->mhpmax + max_increase > hp_threshold + 1) 1369. 		max_increase = max((hp_threshold + 1) - mtmp->mhpmax, 0); 1370. 	   cur_increase = (max_increase > 1) ? rn2(max_increase) : 0; 1371. 	} else { 1372. 	   /* a gain level potion or wraith corpse; always go up a level 1373. 	      unless already at maximum (49 is hard upper limit except  1374. 	       for demon lords, who start at 50 and can't go any higher) */ 1375. 	   max_increase = cur_increase = rnd(8); 1376. 	   hp_threshold = 0;	/* smaller than `mhpmax + max_increase' */ 1377. 	   lev_limit = 50;		/* recalc below */ 1378. 	} 1379.  1380. 	mtmp->mhpmax += max_increase; 1381. 	mtmp->mhp += cur_increase; 1382. 	if (mtmp->mhpmax <= hp_threshold) 1383. 	   return ptr;		/* doesn't gain a level */ 1384. 1385. 	if (is_mplayer(ptr)) lev_limit = 30;	/* same as player */ 1386. 	else if (lev_limit < 5) lev_limit = 5;	/* arbitrary */ 1387. 	else if (lev_limit > 49) lev_limit = (ptr->mlevel > 49 ? 50 : 49); 1388. 1389. 	/* note:  none of the monsters with special hit point calculations 1390. 	  have both little and big forms */ 1391. 	oldtype = monsndx(ptr); 1392. 	newtype = little_to_big(oldtype); 1393. 	if (newtype == PM_PRIEST && mtmp->female) newtype = PM_PRIESTESS; 1394. 	if ((int)++mtmp->m_lev >= mons[newtype].mlevel && newtype != oldtype) { 1395. 	   ptr = &mons[newtype]; 1396. 	   if (mvitals[newtype].mvflags & G_GENOD) {	/* allow G_EXTINCT */ 1397. 		if (sensemon(mtmp)) 1398. 		   pline("As %s grows up into %s, %s %s!", mon_nam(mtmp),  1399. 			an(ptr->mname), mhe(mtmp),  1400. 			nonliving(ptr) ? "expires" : "dies"); 1401. 		set_mon_data(mtmp, ptr, -1);	/* keep mvitals[] accurate */ 1402. 		mondied(mtmp); 1403. 		return (struct permonst *)0; 1404. 	   }  1405. 	    set_mon_data(mtmp, ptr, 1);		/* preserve intrinsics */ 1406. 	   newsym(mtmp->mx, mtmp->my);		/* color may change */ 1407. 	   lev_limit = (int)mtmp->m_lev;	/* never undo increment */ 1408. 	} 1409. 	/* sanity checks */ 1410. 	if ((int)mtmp->m_lev > lev_limit) { 1411. 	   mtmp->m_lev--;	/* undo increment */ 1412. 	   /* HP might have been allowed to grow when it shouldn't */ 1413. 	   if (mtmp->mhpmax == hp_threshold + 1) mtmp->mhpmax--; 1414. 	} 1415. 	if (mtmp->mhpmax > 50*8) mtmp->mhpmax = 50*8;	  /* absolute limit */ 1416. 	if (mtmp->mhp > mtmp->mhpmax) mtmp->mhp = mtmp->mhpmax; 1417. 1418. 	return ptr; 1419. } 1420.  1421. #endif /* OVLB */ 1422. #ifdef OVL1 1423. 1424. int 1425. mongets(mtmp, otyp) 1426. register struct monst *mtmp; 1427. register int otyp; 1428. { 1429. 	register struct obj *otmp; 1430. 	int spe; 1431. 1432. 	if (!otyp) return 0; 1433. 	otmp = mksobj(otyp, TRUE, FALSE); 1434. 	if (otmp) { 1435. 	   if (mtmp->data->mlet == S_DEMON) { 1436. 		/* demons never get blessed objects */ 1437. 		if (otmp->blessed) curse(otmp); 1438. 	   } else if(is_lminion(mtmp->data)) { 1439. 		/* lawful minions don't get cursed, bad, or rusting objects */ 1440. 		otmp->cursed = FALSE; 1441. 		if(otmp->spe < 0) otmp->spe = 0; 1442. 		otmp->oerodeproof = TRUE; 1443. 	   } else if(is_mplayer(mtmp->data) && is_sword(otmp)) { 1444. 		otmp->spe = (3 + rn2(4)); 1445. 	   }  1446.  1447. 	    if(otmp->otyp == CANDELABRUM_OF_INVOCATION) { 1448. 		otmp->spe = 0; 1449. 		otmp->age = 0L; 1450. 		otmp->lamplit = FALSE; 1451. 		otmp->blessed = otmp->cursed = FALSE; 1452. 	   } else if (otmp->otyp == BELL_OF_OPENING) { 1453. 		otmp->blessed = otmp->cursed = FALSE; 1454. 	   } else if (otmp->otyp == SPE_BOOK_OF_THE_DEAD) { 1455. 		otmp->blessed = FALSE; 1456. 		otmp->cursed = TRUE; 1457. 	   }  1458.  1459. 	    /* leaders don't tolerate inferior quality battle gear */ 1460. 	   if (is_prince(mtmp->data)) { 1461. 		if (otmp->oclass == WEAPON_CLASS && otmp->spe < 1) 1462. 		   otmp->spe = 1; 1463. 		else if (otmp->oclass == ARMOR_CLASS && otmp->spe < 0) 1464. 		   otmp->spe = 0; 1465. 	   }  1466.  1467. 	    spe = otmp->spe; 1468. 	   (void) mpickobj(mtmp, otmp);	/* might free otmp */ 1469. 	   return(spe); 1470. 	} else return(0); 1471. } 1472.  1473. #endif /* OVL1 */ 1474. #ifdef OVLB 1475. 1476. int 1477. golemhp(type) 1478. int type; 1479. { 1480. 	switch(type) { 1481. 		case PM_STRAW_GOLEM: return 20; 1482. 		case PM_PAPER_GOLEM: return 20; 1483. 		case PM_ROPE_GOLEM: return 30; 1484. 		case PM_LEATHER_GOLEM: return 40; 1485. 		case PM_GOLD_GOLEM: return 40; 1486. 		case PM_WOOD_GOLEM: return 50; 1487. 		case PM_FLESH_GOLEM: return 40; 1488. 		case PM_CLAY_GOLEM: return 50; 1489. 		case PM_STONE_GOLEM: return 60; 1490. 		case PM_GLASS_GOLEM: return 60; 1491. 		case PM_IRON_GOLEM: return 80; 1492. 		default: return 0; 1493. 	} 1494. }  1495.  1496. #endif /* OVLB */ 1497. #ifdef OVL1 1498. 1499. /*  1500.  *	Alignment vs. yours determines monster's attitude to you. 1501. *	( some "animal" types are co-aligned, but also hungry ) 1502. */  1503. boolean 1504. peace_minded(ptr) 1505. register struct permonst *ptr; 1506. { 1507. 	aligntyp mal = ptr->maligntyp, ual = u.ualign.type; 1508. 1509. 	if (always_peaceful(ptr)) return TRUE; 1510. 	if (always_hostile(ptr)) return FALSE; 1511. 	if (ptr->msound == MS_LEADER || ptr->msound == MS_GUARDIAN) 1512. 		return TRUE; 1513. 	if (ptr->msound == MS_NEMESIS)	return FALSE; 1514. 1515. 	if (race_peaceful(ptr)) return TRUE; 1516. 	if (race_hostile(ptr)) return FALSE; 1517. 1518. 	/* the monster is hostile if its alignment is different from the 1519. 	 * player's */ 1520. 	if (sgn(mal) != sgn(ual)) return FALSE; 1521. 1522. 	/* Negative monster hostile to player with Amulet. */ 1523. 	if (mal < A_NEUTRAL && u.uhave.amulet) return FALSE; 1524. 1525. 	/* minions are hostile to players that have strayed at all */ 1526. 	if (is_minion(ptr)) return((boolean)(u.ualign.record >= 0)); 1527. 1528. 	/* Last case:  a chance of a co-aligned monster being 1529. 	 * hostile. This chance is greater if the player has strayed 1530. 	 * (u.ualign.record negative) or the monster is not strongly aligned. 1531. 	 */ 1532. 	return((boolean)(!!rn2(16 + (u.ualign.record < -15 ? -15 : u.ualign.record)) && 1533. 		!!rn2(2 + abs(mal)))); 1534. } 1535.  1536. /* Set malign to have the proper effect on player alignment if monster is  1537. * killed. Negative numbers mean it's bad to kill this monster; positive 1538. * numbers mean it's good. Since there are more hostile monsters than 1539. * peaceful monsters, the penalty for killing a peaceful monster should be  1540. * greater than the bonus for killing a hostile monster to maintain balance. 1541. * Rules: 1542. *   it's bad to kill peaceful monsters, potentially worse to kill always- 1543. *	peaceful monsters 1544. *   it's never bad to kill a hostile monster, although it may not be good 1545. */  1546. void 1547. set_malign(mtmp) 1548. struct monst *mtmp; 1549. { 1550. 	schar mal = mtmp->data->maligntyp; 1551. 	boolean coaligned; 1552. 1553. 	if (mtmp->ispriest || mtmp->isminion) { 1554. 		/* some monsters have individual alignments; check them */ 1555. 		if (mtmp->ispriest) 1556. 			mal = EPRI(mtmp)->shralign; 1557. 		else if (mtmp->isminion) 1558. 			mal = EMIN(mtmp)->min_align; 1559. 		/* unless alignment is none, set mal to -5,0,5 */ 1560. 		/* (see align.h for valid aligntyp values)    */ 1561. 		if(mal != A_NONE) 1562. 			mal *= 5; 1563. 	} 1564.  1565. 	coaligned = (sgn(mal) == sgn(u.ualign.type)); 1566. 	if (mtmp->data->msound == MS_LEADER) { 1567. 		mtmp->malign = -20; 1568. 	} else if (mal == A_NONE) { 1569. 		if (mtmp->mpeaceful) 1570. 			mtmp->malign = 0; 1571. 		else 1572. 			mtmp->malign = 20;	/* really hostile */ 1573. 	} else if (always_peaceful(mtmp->data)) { 1574. 		int absmal = abs(mal); 1575. 		if (mtmp->mpeaceful) 1576. 			mtmp->malign = -3*max(5,absmal); 1577. 		else 1578. 			mtmp->malign = 3*max(5,absmal); /* renegade */ 1579. 	} else if (always_hostile(mtmp->data)) { 1580. 		int absmal = abs(mal); 1581. 		if (coaligned) 1582. 			mtmp->malign = 0; 1583. 		else 1584. 			mtmp->malign = max(5,absmal); 1585. 	} else if (coaligned) { 1586. 		int absmal = abs(mal); 1587. 		if (mtmp->mpeaceful) 1588. 			mtmp->malign = -3*max(3,absmal); 1589. 		else	/* renegade */ 1590. 			mtmp->malign = max(3,absmal); 1591. 	} else	/* not coaligned and therefore hostile */ 1592. 		mtmp->malign = abs(mal); 1593. } 1594.  1595. #endif /* OVL1 */ 1596. #ifdef OVLB 1597. 1598. static NEARDATA char syms[] = { 1599. 	MAXOCLASSES, MAXOCLASSES+1, RING_CLASS, WAND_CLASS, WEAPON_CLASS, 1600. 	FOOD_CLASS, GOLD_CLASS, SCROLL_CLASS, POTION_CLASS, ARMOR_CLASS, 1601. 	AMULET_CLASS, TOOL_CLASS, ROCK_CLASS, GEM_CLASS, SPBOOK_CLASS, 1602. 	S_MIMIC_DEF, S_MIMIC_DEF, S_MIMIC_DEF, 1603. }; 1604.  1605. void 1606. set_mimic_sym(mtmp)		/* KAA, modified by ERS */ 1607. register struct monst *mtmp; 1608. { 1609. 	int typ, roomno, rt; 1610. 	unsigned appear, ap_type; 1611. 	int s_sym; 1612. 	struct obj *otmp; 1613. 	int mx, my; 1614. 1615. 	if (!mtmp) return; 1616. 	mx = mtmp->mx; my = mtmp->my; 1617. 	typ = levl[mx][my].typ; 1618. 					/* only valid for INSIDE of room */ 1619. 	roomno = levl[mx][my].roomno - ROOMOFFSET; 1620. 	if (roomno >= 0) 1621. 		rt = rooms[roomno].rtype; 1622. #ifdef SPECIALIZATION 1623. 	else if (IS_ROOM(typ)) 1624. 		rt = OROOM, roomno = 0; 1625. #endif 1626. 	else	rt = 0;	/* roomno < 0 case for GCC_WARN */ 1627. 1628. 	if (OBJ_AT(mx, my)) { 1629. 		ap_type = M_AP_OBJECT; 1630. 		appear = level.objects[mx][my]->otyp; 1631. 	} else if (IS_DOOR(typ) || IS_WALL(typ) || 1632. 		   typ == SDOOR || typ == SCORR) { 1633. 		ap_type = M_AP_FURNITURE; 1634. 		/* 1635. 		 *  If there is a wall to the left that connects to this 1636. 		 * location, then the mimic mimics a horizontal closed door. 1637. 		 * This does not allow doors to be in corners of rooms. 1638. 		 */ 1639. 		if (mx != 0 &&  1640. 			(levl[mx-1][my].typ == HWALL    || 1641. 			 levl[mx-1][my].typ == TLCORNER || 1642. 			 levl[mx-1][my].typ == TRWALL  || 1643. 			 levl[mx-1][my].typ == BLCORNER || 1644. 			 levl[mx-1][my].typ == TDWALL  || 1645. 			 levl[mx-1][my].typ == CROSSWALL|| 1646. 			 levl[mx-1][my].typ == TUWALL   )) 1647. 		   appear = S_hcdoor; 1648. 		else 1649. 		   appear = S_vcdoor; 1650. 1651. 		if(!mtmp->minvis || See_invisible) 1652. 		   block_point(mx,my);	/* vision */ 1653. 	} else if (level.flags.is_maze_lev && rn2(2)) { 1654. 		ap_type = M_AP_OBJECT; 1655. 		appear = STATUE; 1656. 	} else if (roomno < 0) { 1657. 		ap_type = M_AP_OBJECT; 1658. 		appear = BOULDER; 1659. 		if(!mtmp->minvis || See_invisible) 1660. 		   block_point(mx,my);	/* vision */ 1661. 	} else if (rt == ZOO || rt == VAULT) { 1662. 		ap_type = M_AP_OBJECT; 1663. 		appear = GOLD_PIECE; 1664. 	} else if (rt == DELPHI) { 1665. 		if (rn2(2)) { 1666. 			ap_type = M_AP_OBJECT; 1667. 			appear = STATUE; 1668. 		} else { 1669. 			ap_type = M_AP_FURNITURE; 1670. 			appear = S_fountain; 1671. 		} 1672. 	} else if (rt == TEMPLE) { 1673. 		ap_type = M_AP_FURNITURE; 1674. 		appear = S_altar; 1675. 	/* 1676. 	 * We won't bother with beehives, morgues, barracks, throne rooms 1677. 	 * since they shouldn't contain too many mimics anyway... 1678. */ 1679. 	} else if (rt >= SHOPBASE) { 1680. 		s_sym = get_shop_item(rt - SHOPBASE); 1681. 		if (s_sym < 0) { 1682. 			ap_type = M_AP_OBJECT; 1683. 			appear = -s_sym; 1684. 		} else { 1685. 			if (s_sym == RANDOM_CLASS) 1686. 				s_sym = syms[rn2((int)sizeof(syms)-2) + 2]; 1687. 			goto assign_sym; 1688. 		} 1689. 	} else { 1690. 		s_sym = syms[rn2((int)sizeof(syms))]; 1691. assign_sym: 1692. 		if (s_sym >= MAXOCLASSES) { 1693. 			ap_type = M_AP_FURNITURE; 1694. 			appear = s_sym == MAXOCLASSES ? S_upstair : S_dnstair; 1695. 		} else if (s_sym == GOLD_CLASS) { 1696. 			ap_type = M_AP_OBJECT; 1697. 			appear = GOLD_PIECE; 1698. 		} else { 1699. 			ap_type = M_AP_OBJECT; 1700. 			if (s_sym == S_MIMIC_DEF) { 1701. 				appear = STRANGE_OBJECT; 1702. 			} else { 1703. 				otmp = mkobj( (char) s_sym, FALSE ); 1704. 				appear = otmp->otyp; 1705. 				/* make sure container contents are free'ed */ 1706. 				obfree(otmp, (struct obj *) 0); 1707. 			} 1708. 		}  1709. 	}  1710. 	mtmp->m_ap_type = ap_type; 1711. 	mtmp->mappearance = appear; 1712. } 1713.  1714. #endif /* OVLB */ 1715. 1716. /*makemon.c*/