Source:NetHack 3.4.3/src/makemon.c

From NetHackWiki
(Redirected from Source:Ref/rndmonst)
Jump to: navigation, search

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

Top of file[edit]

  1. /*	SCCS Id: @(#)makemon.c	3.4	2003/09/06	*/
  2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  3. /* NetHack may be freely redistributed.  See license for details. */

The NetHack General Public License applies to screenshots, source code and other content from NetHack.

This content was modified from the original NetHack source code distribution (by splitting up NetHack content between wiki pages, and possibly further editing). See the page history for a list of who changed it, and on what dates.

  1. #include "hack.h"
  2. #include "epri.h"
  3. #include "emin.h"
  4. #include "edog.h"
  5. #ifdef REINCARNATION
  6. #include <ctype.h>
  7. #endif
  8.  
  9. STATIC_VAR NEARDATA struct monst zeromonst;
  10.  
  11. /* this assumes that a human quest leader or nemesis is an archetype
  12. of the corresponding role; that isn't so for some roles (tourist
  13. for instance) but is for the priests and monks we use it for... */
  14. #define quest_mon_represents_role(mptr,role_pm) \
  15. 		(mptr->mlet == S_HUMAN && Role_if(role_pm) && \
  16. 		  (mptr->msound == MS_LEADER || mptr->msound == MS_NEMESIS))
  17.  
  18. #ifdef OVL0
  19. STATIC_DCL boolean FDECL(uncommon, (int));
  20. STATIC_DCL int FDECL(align_shift, (struct permonst *));
  21. #endif /* OVL0 */
  22. STATIC_DCL boolean FDECL(wrong_elem_type, (struct permonst *));
  23. STATIC_DCL void FDECL(m_initgrp,(struct monst *,int,int,int));
  24. STATIC_DCL void FDECL(m_initthrow,(struct monst *,int,int));
  25. STATIC_DCL void FDECL(m_initweap,(struct monst *));
  26. #ifdef OVL1
  27. STATIC_DCL void FDECL(m_initinv,(struct monst *));
  28. #endif /* OVL1 */
  29.  
  30. extern const int monstr[];
  31.  
  32. #define m_initsgrp(mtmp, x, y)	m_initgrp(mtmp, x, y, 3)
  33. #define m_initlgrp(mtmp, x, y)	m_initgrp(mtmp, x, y, 10)
  34. #define toostrong(monindx, lev) (monstr[monindx] > lev)
  35. #define tooweak(monindx, lev)	(monstr[monindx] < lev)

is_home_elemental[edit]

  1. #ifdef OVLB
  2. boolean
  3. is_home_elemental(ptr)
  4. register struct permonst *ptr;
  5. {
  6. 	if (ptr->mlet == S_ELEMENTAL)
  7. 	    switch (monsndx(ptr)) {
  8. 		case PM_AIR_ELEMENTAL: return Is_airlevel(&u.uz);
  9. 		case PM_FIRE_ELEMENTAL: return Is_firelevel(&u.uz);
  10. 		case PM_EARTH_ELEMENTAL: return Is_earthlevel(&u.uz);
  11. 		case PM_WATER_ELEMENTAL: return Is_waterlevel(&u.uz);
  12. 	    }
  13. 	return FALSE;
  14. }

wrong_elem_type[edit]

  1. /*
  2. * Return true if the given monster cannot exist on this elemental level.
  3. */
  4. STATIC_OVL boolean
  5. wrong_elem_type(ptr)
  6. register struct permonst *ptr;
  7. {
  8. if (ptr->mlet == S_ELEMENTAL) {
  9. 	return((boolean)(!is_home_elemental(ptr)));
  10. } else if (Is_earthlevel(&u.uz)) {
  11. 	/* no restrictions? */
  12. } else if (Is_waterlevel(&u.uz)) {
  13. 	/* just monsters that can swim */
  14. 	if(!is_swimmer(ptr)) return TRUE;
  15. } else if (Is_firelevel(&u.uz)) {
  16. 	if (!pm_resistance(ptr,MR_FIRE)) return TRUE;
  17. } else if (Is_airlevel(&u.uz)) {
  18. 	if(!(is_flyer(ptr) && ptr->mlet != S_TRAPPER) && !is_floater(ptr)
  19. 	   && !amorphous(ptr) && !noncorporeal(ptr) && !is_whirly(ptr))
  20. 	    return TRUE;
  21. }
  22. return FALSE;
  23. }

m_initgrp[edit]

  1. STATIC_OVL void
  2. m_initgrp(mtmp, x, y, n)	/* make a group just like mtmp */
  3. register struct monst *mtmp;
  4. register int x, y, n;
  5. {
  6. 	coord mm;
  7. 	register int cnt = rnd(n);
  8. 	struct monst *mon;
  9. #if defined(__GNUC__) && (defined(HPUX) || defined(DGUX))
  10. 	/* There is an unresolved problem with several people finding that
  11. 	 * the game hangs eating CPU; if interrupted and restored, the level
  12. 	 * will be filled with monsters.  Of those reports giving system type,
  13. 	 * there were two DG/UX and two HP-UX, all using gcc as the compiler.
  14. 	 * hcroft@hpopb1.cern.ch, using gcc 2.6.3 on HP-UX, says that the
  15. 	 * problem went away for him and another reporter-to-newsgroup
  16. 	 * after adding this debugging code.  This has almost got to be a
  17. 	 * compiler bug, but until somebody tracks it down and gets it fixed,
  18. 	 * might as well go with the "but it went away when I tried to find
  19. 	 * it" code.
  20. 	 */
  21. 	int cnttmp,cntdiv;
  22.  
  23. 	cnttmp = cnt;
  24. # ifdef DEBUG
  25. 	pline("init group call x=%d,y=%d,n=%d,cnt=%d.", x, y, n, cnt);
  26. # endif
  27. 	cntdiv = ((u.ulevel < 3) ? 4 : (u.ulevel < 5) ? 2 : 1);
  28. #endif
  29. 	/* Tuning: cut down on swarming at low character levels [mrs] */
  30. 	cnt /= (u.ulevel < 3) ? 4 : (u.ulevel < 5) ? 2 : 1;
  31. #if defined(__GNUC__) && (defined(HPUX) || defined(DGUX))
  32. 	if (cnt != (cnttmp/cntdiv)) {
  33. 		pline("cnt=%d using %d, cnttmp=%d, cntdiv=%d", cnt,
  34. 			(u.ulevel < 3) ? 4 : (u.ulevel < 5) ? 2 : 1,
  35. 			cnttmp, cntdiv);
  36. 	}
  37. #endif
  38. 	if(!cnt) cnt++;
  39. #if defined(__GNUC__) && (defined(HPUX) || defined(DGUX))
  40. 	if (cnt < 0) cnt = 1;
  41. 	if (cnt > 10) cnt = 10;
  42. #endif
  43.  
  44. 	mm.x = x;
  45. 	mm.y = y;
  46. 	while(cnt--) {
  47. 		if (peace_minded(mtmp->data)) continue;
  48. 		/* Don't create groups of peaceful monsters since they'll get
  49. 		 * in our way.  If the monster has a percentage chance so some
  50. 		 * are peaceful and some are not, the result will just be a
  51. 		 * smaller group.
  52. 		 */
  53. 		if (enexto(&mm, mm.x, mm.y, mtmp->data)) {
  54. 		    mon = makemon(mtmp->data, mm.x, mm.y, NO_MM_FLAGS);
  55. 		    mon->mpeaceful = FALSE;
  56. 		    mon->mavenge = 0;
  57. 		    set_malign(mon);
  58. 		    /* Undo the second peace_minded() check in makemon(); if the
  59. 		     * monster turned out to be peaceful the first time we
  60. 		     * didn't create it at all; we don't want a second check.
  61. 		     */
  62. 		}
  63. 	}
  64. }

m_initthrow[edit]

  1. STATIC_OVL
  2. void
  3. m_initthrow(mtmp,otyp,oquan)
  4. struct monst *mtmp;
  5. int otyp,oquan;
  6. {
  7. 	register struct obj *otmp;
  8.  
  9. 	otmp = mksobj(otyp, TRUE, FALSE);
  10. 	otmp->quan = (long) rn1(oquan, 3);
  11. 	otmp->owt = weight(otmp);
  12. 	if (otyp == ORCISH_ARROW) otmp->opoisoned = TRUE;
  13. 	(void) mpickobj(mtmp, otmp);
  14. }
  15.  
  16. #endif /* OVLB */

m_initweap[edit]

  1. #ifdef OVL2
  2.  
  3. STATIC_OVL void
  4. m_initweap(mtmp)
  5. register struct monst *mtmp;
  6. {
  7. 	register struct permonst *ptr = mtmp->data;
  8. 	register int mm = monsndx(ptr);
  9. 	struct obj *otmp;
  10.  
  11. #ifdef REINCARNATION
  12. 	if (Is_rogue_level(&u.uz)) return;
  13. #endif
  14. /*
  15. *	first a few special cases:
  16. *
  17. *		giants get a boulder to throw sometimes.
  18. *		ettins get clubs
  19. *		kobolds get darts to throw
  20. *		centaurs get some sort of bow & arrows or bolts
  21. *		soldiers get all sorts of things.
  22. *		kops get clubs & cream pies.
  23. */
  24. 	switch (ptr->mlet) {
  25. 	    case S_GIANT:
  26. 		if (rn2(2)) (void)mongets(mtmp, (mm != PM_ETTIN) ?
  27. 				    BOULDER : CLUB);
  28. 		break;
  29. 	    case S_HUMAN:
  30. 		if(is_mercenary(ptr)) {
  31. 		    int w1 = 0, w2 = 0;
  32. 		    switch (mm) {
  33.  
  34. 			case PM_WATCHMAN:
  35. 			case PM_SOLDIER:
  36. 			  if (!rn2(3)) {
  37. 			      w1 = rn1(BEC_DE_CORBIN - PARTISAN + 1, PARTISAN);
  38. 			      w2 = rn2(2) ? DAGGER : KNIFE;
  39. 			  } else w1 = rn2(2) ? SPEAR : SHORT_SWORD;
  40. 			  break;
  41. 			case PM_SERGEANT:
  42. 			  w1 = rn2(2) ? FLAIL : MACE;
  43. 			  break;
  44. 			case PM_LIEUTENANT:
  45. 			  w1 = rn2(2) ? BROADSWORD : LONG_SWORD;
  46. 			  break;
  47. 			case PM_CAPTAIN:
  48. 			case PM_WATCH_CAPTAIN:
  49. 			  w1 = rn2(2) ? LONG_SWORD : SILVER_SABER;
  50. 			  break;
  51. 			default:
  52. 			  if (!rn2(4)) w1 = DAGGER;
  53. 			  if (!rn2(7)) w2 = SPEAR;
  54. 			  break;
  55. 		    }
  56. 		    if (w1) (void)mongets(mtmp, w1);
  57. 		    if (!w2 && w1 != DAGGER && !rn2(4)) w2 = KNIFE;
  58. 		    if (w2) (void)mongets(mtmp, w2);
  59. 		} else if (is_elf(ptr)) {
  60. 		    if (rn2(2))
  61. 			(void) mongets(mtmp,
  62. 				   rn2(2) ? ELVEN_MITHRIL_COAT : ELVEN_CLOAK);
  63. 		    if (rn2(2)) (void)mongets(mtmp, ELVEN_LEATHER_HELM);
  64. 		    else if (!rn2(4)) (void)mongets(mtmp, ELVEN_BOOTS);
  65. 		    if (rn2(2)) (void)mongets(mtmp, ELVEN_DAGGER);
  66. 		    switch (rn2(3)) {
  67. 			case 0:
  68. 			    if (!rn2(4)) (void)mongets(mtmp, ELVEN_SHIELD);
  69. 			    if (rn2(3)) (void)mongets(mtmp, ELVEN_SHORT_SWORD);
  70. 			    (void)mongets(mtmp, ELVEN_BOW);
  71. 			    m_initthrow(mtmp, ELVEN_ARROW, 12);
  72. 			    break;
  73. 			case 1:
  74. 			    (void)mongets(mtmp, ELVEN_BROADSWORD);
  75. 			    if (rn2(2)) (void)mongets(mtmp, ELVEN_SHIELD);
  76. 			    break;
  77. 			case 2:
  78. 			    if (rn2(2)) {
  79. 				(void)mongets(mtmp, ELVEN_SPEAR);
  80. 				(void)mongets(mtmp, ELVEN_SHIELD);
  81. 			    }
  82. 			    break;
  83. 		    }
  84. 		    if (mm == PM_ELVENKING) {
  85. 			if (rn2(3) || (in_mklev && Is_earthlevel(&u.uz)))
  86. 			    (void)mongets(mtmp, PICK_AXE);
  87. 			if (!rn2(50)) (void)mongets(mtmp, CRYSTAL_BALL);
  88. 		    }
  89. 		} else if (ptr->msound == MS_PRIEST ||
  90. 			quest_mon_represents_role(ptr,PM_PRIEST)) {
  91. 		    otmp = mksobj(MACE, FALSE, FALSE);
  92. 		    if(otmp) {
  93. 			otmp->spe = rnd(3);
  94. 			if(!rn2(2)) curse(otmp);
  95. 			(void) mpickobj(mtmp, otmp);
  96. 		    }
  97. 		}
  98. 		break;
  99.  
  100. 	    case S_ANGEL:
  101. 		{
  102. 		    int spe2;
  103.  
  104. 		    /* create minion stuff; can't use mongets */
  105. 		    otmp = mksobj(LONG_SWORD, FALSE, FALSE);
  106.  
  107. 		    /* maybe make it special */
  108. 		    if (!rn2(20) || is_lord(ptr))
  109. 			otmp = oname(otmp, artiname(
  110. 				rn2(2) ? ART_DEMONBANE : ART_SUNSWORD));
  111. 		    bless(otmp);
  112. 		    otmp->oerodeproof = TRUE;
  113. 		    spe2 = rn2(4);
  114. 		    otmp->spe = max(otmp->spe, spe2);
  115. 		    (void) mpickobj(mtmp, otmp);
  116.  
  117. 		    otmp = mksobj(!rn2(4) || is_lord(ptr) ?
  118. 				  SHIELD_OF_REFLECTION : LARGE_SHIELD,
  119. 				  FALSE, FALSE);
  120. 		    otmp->cursed = FALSE;
  121. 		    otmp->oerodeproof = TRUE;
  122. 		    otmp->spe = 0;
  123. 		    (void) mpickobj(mtmp, otmp);
  124. 		}
  125. 		break;
  126.  
  127. 	    case S_HUMANOID:
  128. 		if (mm == PM_HOBBIT) {
  129. 		    switch (rn2(3)) {
  130. 			case 0:
  131. 			    (void)mongets(mtmp, DAGGER);
  132. 			    break;
  133. 			case 1:
  134. 			    (void)mongets(mtmp, ELVEN_DAGGER);
  135. 			    break;
  136. 			case 2:
  137. 			    (void)mongets(mtmp, SLING);
  138. 			    break;
  139. 		      }
  140. 		    if (!rn2(10)) (void)mongets(mtmp, ELVEN_MITHRIL_COAT);
  141. 		    if (!rn2(10)) (void)mongets(mtmp, DWARVISH_CLOAK);
  142. 		} else if (is_dwarf(ptr)) {
  143. 		    if (rn2(7)) (void)mongets(mtmp, DWARVISH_CLOAK);
  144. 		    if (rn2(7)) (void)mongets(mtmp, IRON_SHOES);
  145. 		    if (!rn2(4)) {
  146. 			(void)mongets(mtmp, DWARVISH_SHORT_SWORD);
  147. 			/* note: you can't use a mattock with a shield */
  148. 			if (rn2(2)) (void)mongets(mtmp, DWARVISH_MATTOCK);
  149. 			else {
  150. 				(void)mongets(mtmp, AXE);
  151. 				(void)mongets(mtmp, DWARVISH_ROUNDSHIELD);
  152. 			}
  153. 			(void)mongets(mtmp, DWARVISH_IRON_HELM);
  154. 			if (!rn2(3))
  155. 			    (void)mongets(mtmp, DWARVISH_MITHRIL_COAT);
  156. 		    } else {
  157. 			(void)mongets(mtmp, !rn2(3) ? PICK_AXE : DAGGER);
  158. 		    }
  159. 		}
  160. 		break;
  161. # ifdef KOPS
  162. 	    case S_KOP:		/* create Keystone Kops with cream pies to
  163. 				 * throw. As suggested by KAA.	   [MRS]
  164. 				 */
  165. 		if (!rn2(4)) m_initthrow(mtmp, CREAM_PIE, 2);
  166. 		if (!rn2(3)) (void)mongets(mtmp,(rn2(2)) ? CLUB : RUBBER_HOSE);
  167. 		break;
  168. # endif
  169. 	    case S_ORC:
  170. 		if(rn2(2)) (void)mongets(mtmp, ORCISH_HELM);
  171. 		switch (mm != PM_ORC_CAPTAIN ? mm :
  172. 			rn2(2) ? PM_MORDOR_ORC : PM_URUK_HAI) {
  173. 		    case PM_MORDOR_ORC:
  174. 			if(!rn2(3)) (void)mongets(mtmp, SCIMITAR);
  175. 			if(!rn2(3)) (void)mongets(mtmp, ORCISH_SHIELD);
  176. 			if(!rn2(3)) (void)mongets(mtmp, KNIFE);
  177. 			if(!rn2(3)) (void)mongets(mtmp, ORCISH_CHAIN_MAIL);
  178. 			break;
  179. 		    case PM_URUK_HAI:
  180. 			if(!rn2(3)) (void)mongets(mtmp, ORCISH_CLOAK);
  181. 			if(!rn2(3)) (void)mongets(mtmp, ORCISH_SHORT_SWORD);
  182. 			if(!rn2(3)) (void)mongets(mtmp, IRON_SHOES);
  183. 			if(!rn2(3)) {
  184. 			    (void)mongets(mtmp, ORCISH_BOW);
  185. 			    m_initthrow(mtmp, ORCISH_ARROW, 12);
  186. 			}
  187. 			if(!rn2(3)) (void)mongets(mtmp, URUK_HAI_SHIELD);
  188. 			break;
  189. 		    default:
  190. 			if (mm != PM_ORC_SHAMAN && rn2(2))
  191. 			  (void)mongets(mtmp, (mm == PM_GOBLIN || rn2(2) == 0)
  192. 						   ? ORCISH_DAGGER : SCIMITAR);
  193. 		}
  194. 		break;
  195. 	    case S_OGRE:
  196. 		if (!rn2(mm == PM_OGRE_KING ? 3 : mm == PM_OGRE_LORD ? 6 : 12))
  197. 		    (void) mongets(mtmp, BATTLE_AXE);
  198. 		else
  199. 		    (void) mongets(mtmp, CLUB);
  200. 		break;
  201. 	    case S_TROLL:
  202. 		if (!rn2(2)) switch (rn2(4)) {
  203. 		    case 0: (void)mongets(mtmp, RANSEUR); break;
  204. 		    case 1: (void)mongets(mtmp, PARTISAN); break;
  205. 		    case 2: (void)mongets(mtmp, GLAIVE); break;
  206. 		    case 3: (void)mongets(mtmp, SPETUM); break;
  207. 		}
  208. 		break;
  209. 	    case S_KOBOLD:
  210. 		if (!rn2(4)) m_initthrow(mtmp, DART, 12);
  211. 		break;
  212.  
  213. 	    case S_CENTAUR:
  214. 		if (rn2(2)) {
  215. 		    if(ptr == &mons[PM_FOREST_CENTAUR]) {
  216. 			(void)mongets(mtmp, BOW);
  217. 			m_initthrow(mtmp, ARROW, 12);
  218. 		    } else {
  219. 			(void)mongets(mtmp, CROSSBOW);
  220. 			m_initthrow(mtmp, CROSSBOW_BOLT, 12);
  221. 		    }
  222. 		}
  223. 		break;
  224. 	    case S_WRAITH:
  225. 		(void)mongets(mtmp, KNIFE);
  226. 		(void)mongets(mtmp, LONG_SWORD);
  227. 		break;
  228. 	    case S_ZOMBIE:
  229. 		if (!rn2(4)) (void)mongets(mtmp, LEATHER_ARMOR);
  230. 		if (!rn2(4))
  231. 			(void)mongets(mtmp, (rn2(3) ? KNIFE : SHORT_SWORD));
  232. 		break;
  233. 	    case S_LIZARD:
  234. 		if (mm == PM_SALAMANDER)
  235. 			(void)mongets(mtmp, (rn2(7) ? SPEAR : rn2(3) ?
  236. 					     TRIDENT : STILETTO));
  237. 		break;
  238. 	    case S_DEMON:
  239. 		switch (mm) {
  240. 		    case PM_BALROG:
  241. 			(void)mongets(mtmp, BULLWHIP);
  242. 			(void)mongets(mtmp, BROADSWORD);
  243. 			break;
  244. 		    case PM_ORCUS:
  245. 			(void)mongets(mtmp, WAN_DEATH); /* the Wand of Orcus */
  246. 			break;
  247. 		    case PM_HORNED_DEVIL:
  248. 			(void)mongets(mtmp, rn2(4) ? TRIDENT : BULLWHIP);
  249. 			break;
  250. 		    case PM_DISPATER:
  251. 			(void)mongets(mtmp, WAN_STRIKING);
  252. 			break;
  253. 		    case PM_YEENOGHU:
  254. 			(void)mongets(mtmp, FLAIL);
  255. 			break;
  256. 		}
  257. 		/* prevent djinnis and mail daemons from leaving objects when
  258. 		 * they vanish
  259. 		 */
  260. 		if (!is_demon(ptr)) break;
  261. 		/* fall thru */
  262. /*
  263. *	Now the general case, Some chance of getting some type
  264. *	of weapon for "normal" monsters.  Certain special types
  265. *	of monsters will get a bonus chance or different selections.
  266. */
  267. 	    default:
  268. 	      {
  269. 		int bias;
  270.  
  271. 		bias = is_lord(ptr) + is_prince(ptr) * 2 + extra_nasty(ptr);
  272. 		switch(rnd(14 - (2 * bias))) {
  273. 		    case 1:
  274. 			if(strongmonst(ptr)) (void) mongets(mtmp, BATTLE_AXE);
  275. 			else m_initthrow(mtmp, DART, 12);
  276. 			break;
  277. 		    case 2:
  278. 			if(strongmonst(ptr))
  279. 			    (void) mongets(mtmp, TWO_HANDED_SWORD);
  280. 			else {
  281. 			    (void) mongets(mtmp, CROSSBOW);
  282. 			    m_initthrow(mtmp, CROSSBOW_BOLT, 12);
  283. 			}
  284. 			break;
  285. 		    case 3:
  286. 			(void) mongets(mtmp, BOW);
  287. 			m_initthrow(mtmp, ARROW, 12);
  288. 			break;
  289. 		    case 4:
  290. 			if(strongmonst(ptr)) (void) mongets(mtmp, LONG_SWORD);
  291. 			else m_initthrow(mtmp, DAGGER, 3);
  292. 			break;
  293. 		    case 5:
  294. 			if(strongmonst(ptr))
  295. 			    (void) mongets(mtmp, LUCERN_HAMMER);
  296. 			else (void) mongets(mtmp, AKLYS);
  297. 			break;
  298. 		    default:
  299. 			break;
  300. 		}
  301. 	      }
  302. 	      break;
  303. 	}
  304. 	if ((int) mtmp->m_lev > rn2(75))
  305. 		(void) mongets(mtmp, rnd_offensive_item(mtmp));
  306. }
  307.  
  308. #endif /* OVL2 */

mkmonmoney[edit]

  1. #ifdef OVL1
  2.  
  3. #ifdef GOLDOBJ
  4. /*
  5. *   Makes up money for monster's inventory.
  6. *   This will change with silver & copper coins
  7. */
  8. void 
  9. mkmonmoney(mtmp, amount)
  10. struct monst *mtmp;
  11. long amount;
  12. {
  13. struct obj *gold = mksobj(GOLD_PIECE, FALSE, FALSE);
  14. gold->quan = amount;
  15. add_to_minv(mtmp, gold);
  16. }
  17. #endif

m_initinv[edit]

  1. STATIC_OVL void
  2. m_initinv(mtmp)
  3. register struct	monst	*mtmp;
  4. {
  5. 	register int cnt;
  6. 	register struct obj *otmp;
  7. 	register struct permonst *ptr = mtmp->data;
  8. #ifdef REINCARNATION
  9. 	if (Is_rogue_level(&u.uz)) return;
  10. #endif
  11. /*
  12. *	Soldiers get armour & rations - armour approximates their ac.
  13. *	Nymphs may get mirror or potion of object detection.
  14. */
  15. 	switch(ptr->mlet) {
  16.  
  17. 	    case S_HUMAN:
  18. 		if(is_mercenary(ptr)) {
  19. 		    register int mac;
  20.  
  21. 		    switch(monsndx(ptr)) {
  22. 			case PM_GUARD: mac = -1; break;
  23. 			case PM_SOLDIER: mac = 3; break;
  24. 			case PM_SERGEANT: mac = 0; break;
  25. 			case PM_LIEUTENANT: mac = -2; break;
  26. 			case PM_CAPTAIN: mac = -3; break;
  27. 			case PM_WATCHMAN: mac = 3; break;
  28. 			case PM_WATCH_CAPTAIN: mac = -2; break;
  29. 			default: impossible("odd mercenary %d?", monsndx(ptr));
  30. 				mac = 0;
  31. 				break;
  32. 		    }
  33.  
  34. 		    if (mac < -1 && rn2(5))
  35. 			mac += 7 + mongets(mtmp, (rn2(5)) ?
  36. 					   PLATE_MAIL : CRYSTAL_PLATE_MAIL);
  37. 		    else if (mac < 3 && rn2(5))
  38. 			mac += 6 + mongets(mtmp, (rn2(3)) ?
  39. 					   SPLINT_MAIL : BANDED_MAIL);
  40. 		    else if (rn2(5))
  41. 			mac += 3 + mongets(mtmp, (rn2(3)) ?
  42. 					   RING_MAIL : STUDDED_LEATHER_ARMOR);
  43. 		    else
  44. 			mac += 2 + mongets(mtmp, LEATHER_ARMOR);
  45.  
  46. 		    if (mac < 10 && rn2(3))
  47. 			mac += 1 + mongets(mtmp, HELMET);
  48. 		    else if (mac < 10 && rn2(2))
  49. 			mac += 1 + mongets(mtmp, DENTED_POT);
  50. 		    if (mac < 10 && rn2(3))
  51. 			mac += 1 + mongets(mtmp, SMALL_SHIELD);
  52. 		    else if (mac < 10 && rn2(2))
  53. 			mac += 2 + mongets(mtmp, LARGE_SHIELD);
  54. 		    if (mac < 10 && rn2(3))
  55. 			mac += 1 + mongets(mtmp, LOW_BOOTS);
  56. 		    else if (mac < 10 && rn2(2))
  57. 			mac += 2 + mongets(mtmp, HIGH_BOOTS);
  58. 		    if (mac < 10 && rn2(3))
  59. 			mac += 1 + mongets(mtmp, LEATHER_GLOVES);
  60. 		    else if (mac < 10 && rn2(2))
  61. 			mac += 1 + mongets(mtmp, LEATHER_CLOAK);
  62.  
  63. 		    if(ptr != &mons[PM_GUARD] &&
  64. 			ptr != &mons[PM_WATCHMAN] &&
  65. 			ptr != &mons[PM_WATCH_CAPTAIN]) {
  66. 			if (!rn2(3)) (void) mongets(mtmp, K_RATION);
  67. 			if (!rn2(2)) (void) mongets(mtmp, C_RATION);
  68. 			if (ptr != &mons[PM_SOLDIER] && !rn2(3))
  69. 				(void) mongets(mtmp, BUGLE);
  70. 		    } else
  71. 			   if (ptr == &mons[PM_WATCHMAN] && rn2(3))
  72. 				(void) mongets(mtmp, TIN_WHISTLE);
  73. 		} else if (ptr == &mons[PM_SHOPKEEPER]) {
  74. 		    (void) mongets(mtmp,SKELETON_KEY);
  75. 		    switch (rn2(4)) {
  76. 		    /* MAJOR fall through ... */
  77. 		    case 0: (void) mongets(mtmp, WAN_MAGIC_MISSILE);
  78. 		    case 1: (void) mongets(mtmp, POT_EXTRA_HEALING);
  79. 		    case 2: (void) mongets(mtmp, POT_HEALING);
  80. 		    case 3: (void) mongets(mtmp, WAN_STRIKING);
  81. 		    }
  82. 		} else if (ptr->msound == MS_PRIEST ||
  83. 			quest_mon_represents_role(ptr,PM_PRIEST)) {
  84. 		    (void) mongets(mtmp, rn2(7) ? ROBE :
  85. 					     rn2(3) ? CLOAK_OF_PROTECTION :
  86. 						 CLOAK_OF_MAGIC_RESISTANCE);
  87. 		    (void) mongets(mtmp, SMALL_SHIELD);
  88. #ifndef GOLDOBJ
  89. 		    mtmp->mgold = (long)rn1(10,20);
  90. #else
  91. 		    mkmonmoney(mtmp,(long)rn1(10,20));
  92. #endif
  93. 		} else if (quest_mon_represents_role(ptr,PM_MONK)) {
  94. 		    (void) mongets(mtmp, rn2(11) ? ROBE :
  95. 					     CLOAK_OF_MAGIC_RESISTANCE);
  96. 		}
  97. 		break;
  98. 	    case S_NYMPH:
  99. 		if(!rn2(2)) (void) mongets(mtmp, MIRROR);
  100. 		if(!rn2(2)) (void) mongets(mtmp, POT_OBJECT_DETECTION);
  101. 		break;
  102. 	    case S_GIANT:
  103. 		if (ptr == &mons[PM_MINOTAUR]) {
  104. 		    if (!rn2(3) || (in_mklev && Is_earthlevel(&u.uz)))
  105. 			(void) mongets(mtmp, WAN_DIGGING);
  106. 		} else if (is_giant(ptr)) {
  107. 		    for (cnt = rn2((int)(mtmp->m_lev / 2)); cnt; cnt--) {
  108. 			otmp = mksobj(rnd_class(DILITHIUM_CRYSTAL,LUCKSTONE-1),
  109. 				      FALSE, FALSE);
  110. 			otmp->quan = (long) rn1(2, 3);
  111. 			otmp->owt = weight(otmp);
  112. 			(void) mpickobj(mtmp, otmp);
  113. 		    }
  114. 		}
  115. 		break;
  116. 	    case S_WRAITH:
  117. 		if (ptr == &mons[PM_NAZGUL]) {
  118. 			otmp = mksobj(RIN_INVISIBILITY, FALSE, FALSE);
  119. 			curse(otmp);
  120. 			(void) mpickobj(mtmp, otmp);
  121. 		}
  122. 		break;
  123. 	    case S_LICH:
  124. 		if (ptr == &mons[PM_MASTER_LICH] && !rn2(13))
  125. 			(void)mongets(mtmp, (rn2(7) ? ATHAME : WAN_NOTHING));
  126. 		else if (ptr == &mons[PM_ARCH_LICH] && !rn2(3)) {
  127. 			otmp = mksobj(rn2(3) ? ATHAME : QUARTERSTAFF,
  128. 				      TRUE, rn2(13) ? FALSE : TRUE);
  129. 			if (otmp->spe < 2) otmp->spe = rnd(3);
  130. 			if (!rn2(4)) otmp->oerodeproof = 1;
  131. 			(void) mpickobj(mtmp, otmp);
  132. 		}
  133. 		break;
  134. 	    case S_MUMMY:
  135. 		if (rn2(7)) (void)mongets(mtmp, MUMMY_WRAPPING);
  136. 		break;
  137. 	    case S_QUANTMECH:
  138. 		if (!rn2(20)) {
  139. 			otmp = mksobj(LARGE_BOX, FALSE, FALSE);
  140. 			otmp->spe = 1; /* flag for special box */
  141. 			otmp->owt = weight(otmp);
  142. 			(void) mpickobj(mtmp, otmp);
  143. 		}
  144. 		break;
  145. 	    case S_LEPRECHAUN:
  146. #ifndef GOLDOBJ
  147. 		mtmp->mgold = (long) d(level_difficulty(), 30);
  148. #else
  149. 		mkmonmoney(mtmp, (long) d(level_difficulty(), 30));
  150. #endif
  151. 		break;
  152. 	    case S_DEMON:
  153. 	    	/* moved here from m_initweap() because these don't
  154. 		   have AT_WEAP so m_initweap() is not called for them */
  155. 		if (ptr == &mons[PM_ICE_DEVIL] && !rn2(4)) {
  156. 			(void)mongets(mtmp, SPEAR);
  157. 		} else if (ptr == &mons[PM_ASMODEUS]) {
  158. 			(void)mongets(mtmp, WAN_COLD);
  159. 			(void)mongets(mtmp, WAN_FIRE);
  160. 		}
  161. 		break;
  162. 	    default:
  163. 		break;
  164. 	}
  165.  
  166. 	/* ordinary soldiers rarely have access to magic (or gold :-) */
  167. 	if (ptr == &mons[PM_SOLDIER] && rn2(13)) return;
  168.  
  169. 	if ((int) mtmp->m_lev > rn2(50))
  170. 		(void) mongets(mtmp, rnd_defensive_item(mtmp));
  171. 	if ((int) mtmp->m_lev > rn2(100))
  172. 		(void) mongets(mtmp, rnd_misc_item(mtmp));
  173. #ifndef GOLDOBJ
  174. 	if (likes_gold(ptr) && !mtmp->mgold && !rn2(5))
  175. 		mtmp->mgold =
  176. 		      (long) d(level_difficulty(), mtmp->minvent ? 5 : 10);
  177. #else
  178. 	if (likes_gold(ptr) && !findgold(mtmp->minvent) && !rn2(5))
  179. 		mkmonmoney(mtmp, (long) d(level_difficulty(), mtmp->minvent ? 5 : 10));
  180. #endif
  181. }

Spoilers on this function go here: Monster_starting_inventory

clone_mon[edit]

  1. /* Note: for long worms, always call cutworm (cutworm calls clone_mon) */
  2. struct monst *
  3. clone_mon(mon, x, y)
  4. struct monst *mon;
  5. xchar x, y;	/* clone's preferred location or 0 (near mon) */
  6. {
  7. 	coord mm;
  8. 	struct monst *m2;
  9.  
  10. 	/* may be too weak or have been extinguished for population control */
  11. 	if (mon->mhp <= 1 || (mvitals[monsndx(mon->data)].mvflags & G_EXTINCT))
  12. 	    return (struct monst *)0;
  13.  
  14. 	if (x == 0) {
  15. 	    mm.x = mon->mx;
  16. 	    mm.y = mon->my;
  17. 	    if (!enexto(&mm, mm.x, mm.y, mon->data) || MON_AT(mm.x, mm.y))
  18. 		return (struct monst *)0;
  19. 	} else if (!isok(x, y)) {
  20. 	    return (struct monst *)0;	/* paranoia */
  21. 	} else {
  22. 	    mm.x = x;
  23. 	    mm.y = y;
  24. 	    if (MON_AT(mm.x, mm.y)) {
  25. 		if (!enexto(&mm, mm.x, mm.y, mon->data) || MON_AT(mm.x, mm.y))
  26. 		    return (struct monst *)0;
  27. 	    }
  28. 	}
  29. 	m2 = newmonst(0);
  30. 	*m2 = *mon;			/* copy condition of old monster */
  31. 	m2->nmon = fmon;
  32. 	fmon = m2;
  33. 	m2->m_id = flags.ident++;
  34. 	if (!m2->m_id) m2->m_id = flags.ident++;	/* ident overflowed */
  35. 	m2->mx = mm.x;
  36. 	m2->my = mm.y;
  37.  
  38. 	m2->minvent = (struct obj *) 0; /* objects don't clone */
  39. 	m2->mleashed = FALSE;
  40. #ifndef GOLDOBJ
  41. 	m2->mgold = 0L;
  42. #endif
  43. 	/* Max HP the same, but current HP halved for both.  The caller
  44. 	 * might want to override this by halving the max HP also.
  45. 	 * When current HP is odd, the original keeps the extra point.
  46. 	 */
  47. 	m2->mhpmax = mon->mhpmax;
  48. 	m2->mhp = mon->mhp / 2;
  49. 	mon->mhp -= m2->mhp;
  50.  
  51. 	/* since shopkeepers and guards will only be cloned if they've been
  52. 	 * polymorphed away from their original forms, the clone doesn't have
  53. 	 * room for the extra information.  we also don't want two shopkeepers
  54. 	 * around for the same shop.
  55. 	 */
  56. 	if (mon->isshk) m2->isshk = FALSE;
  57. 	if (mon->isgd) m2->isgd = FALSE;
  58. 	if (mon->ispriest) m2->ispriest = FALSE;
  59. 	m2->mxlth = 0;
  60. 	place_monster(m2, m2->mx, m2->my);
  61. 	if (emits_light(m2->data))
  62. 	    new_light_source(m2->mx, m2->my, emits_light(m2->data),
  63. 			     LS_MONSTER, (genericptr_t)m2);
  64. 	if (m2->mnamelth) {
  65. 	    m2->mnamelth = 0; /* or it won't get allocated */
  66. 	    m2 = christen_monst(m2, NAME(mon));
  67. 	} else if (mon->isshk) {
  68. 	    m2 = christen_monst(m2, shkname(mon));
  69. 	}
  70.  
  71. 	/* not all clones caused by player are tame or peaceful */
  72. 	if (!flags.mon_moving) {
  73. 	    if (mon->mtame)
  74. 		m2->mtame = rn2(max(2 + u.uluck, 2)) ? mon->mtame : 0;
  75. 	    else if (mon->mpeaceful)
  76. 		m2->mpeaceful = rn2(max(2 + u.uluck, 2)) ? 1 : 0;
  77. 	}
  78.  
  79. 	newsym(m2->mx,m2->my);	/* display the new monster */
  80. 	if (m2->mtame) {
  81. 	    struct monst *m3;
  82.  
  83. 	    if (mon->isminion) {
  84. 		m3 = newmonst(sizeof(struct epri) + mon->mnamelth);
  85. 		*m3 = *m2;
  86. 		m3->mxlth = sizeof(struct epri);
  87. 		if (m2->mnamelth) Strcpy(NAME(m3), NAME(m2));
  88. 		*(EPRI(m3)) = *(EPRI(mon));
  89. 		replmon(m2, m3);
  90. 		m2 = m3;
  91. 	    } else {
  92. 		/* because m2 is a copy of mon it is tame but not init'ed.
  93. 		 * however, tamedog will not re-tame a tame dog, so m2
  94. 		 * must be made non-tame to get initialized properly.
  95. 		 */
  96. 		m2->mtame = 0;
  97. 		if ((m3 = tamedog(m2, (struct obj *)0)) != 0) {
  98. 		    m2 = m3;
  99. 		    *(EDOG(m2)) = *(EDOG(mon));
  100. 		}
  101. 	    }
  102. 	}
  103. 	set_malign(m2);
  104.  
  105. 	return m2;
  106. }

propagate[edit]

  1. /*
  2. * Propagate a species
  3. *
  4. * Once a certain number of monsters are created, don't create any more
  5. * at random (i.e. make them extinct).  The previous (3.2) behavior was
  6. * to do this when a certain number had _died_, which didn't make
  7. * much sense.
  8. *
  9. * Returns FALSE propagation unsuccessful
  10. *         TRUE  propagation successful
  11. */
  12. boolean
  13. propagate(mndx, tally, ghostly)
  14. int mndx;
  15. boolean tally;
  16. boolean ghostly;
  17. {
  18. 	boolean result;
  19. 	uchar lim = mbirth_limit(mndx);
  20. 	boolean gone = (mvitals[mndx].mvflags & G_GONE); /* genocided or extinct */
  21.  
  22. 	result = (((int) mvitals[mndx].born < lim) && !gone) ? TRUE : FALSE;
  23.  
  24. 	/* if it's unique, don't ever make it again */
  25. 	if (mons[mndx].geno & G_UNIQ) mvitals[mndx].mvflags |= G_EXTINCT;
  26.  
  27. 	if (mvitals[mndx].born < 255 && tally && (!ghostly || (ghostly && result)))
  28. 		 mvitals[mndx].born++;
  29. 	if ((int) mvitals[mndx].born >= lim && !(mons[mndx].geno & G_NOGEN) &&
  30. 		!(mvitals[mndx].mvflags & G_EXTINCT)) {
  31. #if defined(DEBUG) && defined(WIZARD)
  32. 		if (wizard) pline("Automatically extinguished %s.",
  33. 					makeplural(mons[mndx].mname));
  34. #endif
  35. 		mvitals[mndx].mvflags |= G_EXTINCT;
  36. 		reset_rndmonst(mndx);
  37. 	}
  38. 	return result;
  39. }

makemon[edit]

makemon() takes 4 parameters: pointer to permonst struct, x and y coordinates and special flags, and returns a monster structure. makemon creates a new monster at the coordinates. The type of monster created depends on what permonst struct you give it. The special flags are defined in hack.h. For example, the following will create an angry djinni next to the hero:

struct monst *mtmp = makemon(&mons[PM_DJINNI], u.ux, u.uy, MM_ANGRY);


  1. /*
  2. * called with [x,y] = coordinates;
  3. *	[0,0] means anyplace
  4. *	[u.ux,u.uy] means: near player (if !in_mklev)
  5. *
  6. *	In case we make a monster group, only return the one at [x,y].
  7. */
  8. struct monst *
  9. makemon(ptr, x, y, mmflags)
  10. register struct permonst *ptr;
  11. register int	x, y;
  12. register int	mmflags;
  13. {
  14. 	register struct monst *mtmp;
  15. 	int mndx, mcham, ct, mitem, xlth;
  16. 	boolean anymon = (!ptr);
  17. 	boolean byyou = (x == u.ux && y == u.uy);
  18. 	boolean allow_minvent = ((mmflags & NO_MINVENT) == 0);
  19. 	boolean countbirth = ((mmflags & MM_NOCOUNTBIRTH) == 0);
  20. 	unsigned gpflags = (mmflags & MM_IGNOREWATER) ? MM_IGNOREWATER : 0;
  21.  
  22. 	/* if caller wants random location, do it here */
  23. 	if(x == 0 && y == 0) {
  24. 		int tryct = 0;	/* careful with bigrooms */
  25. 		struct monst fakemon;
  26.  
  27. 		fakemon.data = ptr;	/* set up for goodpos */
  28. 		do {
  29. 			x = rn1(COLNO-3,2);
  30. 			y = rn2(ROWNO);
  31. 		} while(!goodpos(x, y, ptr ? &fakemon : (struct monst *)0, gpflags) ||
  32. 			(!in_mklev && tryct++ < 50 && cansee(x, y)));
  33. 	} else if (byyou && !in_mklev) {
  34. 		coord bypos;
  35.  
  36. 		if(enexto_core(&bypos, u.ux, u.uy, ptr, gpflags)) {
  37. 			x = bypos.x;
  38. 			y = bypos.y;
  39. 		} else
  40. 			return((struct monst *)0);
  41. 	}
  42.  
  43. 	/* Does monster already exist at the position? */
  44. 	if(MON_AT(x, y)) {
  45. 		if ((mmflags & MM_ADJACENTOK) != 0) {
  46. 			coord bypos;
  47. 			if(enexto_core(&bypos, x, y, ptr, gpflags)) {
  48. 				x = bypos.x;
  49. 				y = bypos.y;
  50. 			} else
  51. 				return((struct monst *) 0);
  52. 		} else 
  53. 			return((struct monst *) 0);
  54. 	}
  55.  
  56. 	if(ptr){
  57. 		mndx = monsndx(ptr);
  58. 		/* if you are to make a specific monster and it has
  59. 		   already been genocided, return */
  60. 		if (mvitals[mndx].mvflags & G_GENOD) return((struct monst *) 0);
  61. #if defined(WIZARD) && defined(DEBUG)
  62. 		if (wizard && (mvitals[mndx].mvflags & G_EXTINCT))
  63. 		    pline("Explicitly creating extinct monster %s.",
  64. 			mons[mndx].mname);
  65. #endif
  66. 	} else {
  67. 		/* make a random (common) monster that can survive here.
  68. 		 * (the special levels ask for random monsters at specific
  69. 		 * positions, causing mass drowning on the medusa level,
  70. 		 * for instance.)
  71. 		 */
  72. 		int tryct = 0;	/* maybe there are no good choices */
  73. 		struct monst fakemon;
  74. 		do {
  75. 			if(!(ptr = rndmonst())) {
  76. #ifdef DEBUG
  77. 			    pline("Warning: no monster.");
  78. #endif
  79. 			    return((struct monst *) 0);	/* no more monsters! */
  80. 			}
  81. 			fakemon.data = ptr;	/* set up for goodpos */
  82. 		} while(!goodpos(x, y, &fakemon, gpflags) && tryct++ < 50);
  83. 		mndx = monsndx(ptr);
  84. 	}
  85. 	(void) propagate(mndx, countbirth, FALSE);
  86. 	xlth = ptr->pxlth;
  87. 	if (mmflags & MM_EDOG) xlth += sizeof(struct edog);
  88. 	else if (mmflags & MM_EMIN) xlth += sizeof(struct emin);
  89. 	mtmp = newmonst(xlth);
  90. 	*mtmp = zeromonst;		/* clear all entries in structure */
  91. 	(void)memset((genericptr_t)mtmp->mextra, 0, xlth);
  92. 	mtmp->nmon = fmon;
  93. 	fmon = mtmp;
  94. 	mtmp->m_id = flags.ident++;
  95. 	if (!mtmp->m_id) mtmp->m_id = flags.ident++;	/* ident overflowed */
  96. 	set_mon_data(mtmp, ptr, 0);
  97. 	if (mtmp->data->msound == MS_LEADER)
  98. 	    quest_status.leader_m_id = mtmp->m_id;
  99. 	mtmp->mxlth = xlth;
  100. 	mtmp->mnum = mndx;
  101.  
  102. 	mtmp->m_lev = adj_lev(ptr);
  103. 	if (is_golem(ptr)) {
  104. 	    mtmp->mhpmax = mtmp->mhp = golemhp(mndx);
  105. 	} else if (is_rider(ptr)) {
  106. 	    /* We want low HP, but a high mlevel so they can attack well */
  107. 	    mtmp->mhpmax = mtmp->mhp = d(10,8);
  108. 	} else if (ptr->mlevel > 49) {
  109. 	    /* "special" fixed hp monster
  110. 	     * the hit points are encoded in the mlevel in a somewhat strange
  111. 	     * way to fit in the 50..127 positive range of a signed character
  112. 	     * above the 1..49 that indicate "normal" monster levels */
  113. 	    mtmp->mhpmax = mtmp->mhp = 2*(ptr->mlevel - 6);
  114. 	    mtmp->m_lev = mtmp->mhp / 4;	/* approximation */
  115. 	} else if (ptr->mlet == S_DRAGON && mndx >= PM_GRAY_DRAGON) {
  116. 	    /* adult dragons */
  117. 	    mtmp->mhpmax = mtmp->mhp = (int) (In_endgame(&u.uz) ?
  118. 		(8 * mtmp->m_lev) : (4 * mtmp->m_lev + d((int)mtmp->m_lev, 4)));
  119. 	} else if (!mtmp->m_lev) {
  120. 	    mtmp->mhpmax = mtmp->mhp = rnd(4);
  121. 	} else {
  122. 	    mtmp->mhpmax = mtmp->mhp = d((int)mtmp->m_lev, 8);
  123. 	    if (is_home_elemental(ptr))
  124. 		mtmp->mhpmax = (mtmp->mhp *= 3);
  125. 	}
  126.  
  127. 	if (is_female(ptr)) mtmp->female = TRUE;
  128. 	else if (is_male(ptr)) mtmp->female = FALSE;
  129. 	else mtmp->female = rn2(2);	/* ignored for neuters */
  130.  
  131. 	if (In_sokoban(&u.uz) && !mindless(ptr))  /* know about traps here */
  132. 	    mtmp->mtrapseen = (1L << (PIT - 1)) | (1L << (HOLE - 1));
  133. 	if (ptr->msound == MS_LEADER)		/* leader knows about portal */
  134. 	    mtmp->mtrapseen |= (1L << (MAGIC_PORTAL-1));
  135.  
  136. 	place_monster(mtmp, x, y);
  137. 	mtmp->mcansee = mtmp->mcanmove = TRUE;
  138. 	mtmp->mpeaceful = (mmflags & MM_ANGRY) ? FALSE : peace_minded(ptr);
  139.  
  140. 	switch(ptr->mlet) {
  141. 		case S_MIMIC:
  142. 			set_mimic_sym(mtmp);
  143. 			break;
  144. 		case S_SPIDER:
  145. 		case S_SNAKE:
  146. 			if(in_mklev)
  147. 			    if(x && y)
  148. 				(void) mkobj_at(0, x, y, TRUE);
  149. 			if(hides_under(ptr) && OBJ_AT(x, y))
  150. 			    mtmp->mundetected = TRUE;
  151. 			break;
  152. 		case S_LIGHT:
  153. 		case S_ELEMENTAL:
  154. 			if (mndx == PM_STALKER || mndx == PM_BLACK_LIGHT) {
  155. 			    mtmp->perminvis = TRUE;
  156. 			    mtmp->minvis = TRUE;
  157. 			}
  158. 			break;
  159. 		case S_EEL:
  160. 			if (is_pool(x, y))
  161. 			    mtmp->mundetected = TRUE;
  162. 			break;
  163. 		case S_LEPRECHAUN:
  164. 			mtmp->msleeping = 1;
  165. 			break;
  166. 		case S_JABBERWOCK:
  167. 		case S_NYMPH:
  168. 			if (rn2(5) && !u.uhave.amulet) mtmp->msleeping = 1;
  169. 			break;
  170. 		case S_ORC:
  171. 			if (Race_if(PM_ELF)) mtmp->mpeaceful = FALSE;
  172. 			break;
  173. 		case S_UNICORN:
  174. 			if (is_unicorn(ptr) &&
  175. 					sgn(u.ualign.type) == sgn(ptr->maligntyp))
  176. 				mtmp->mpeaceful = TRUE;
  177. 			break;
  178. 		case S_BAT:
  179. 			if (Inhell && is_bat(ptr))
  180. 			    mon_adjust_speed(mtmp, 2, (struct obj *)0);
  181. 			break;
  182. 	}
  183. 	if ((ct = emits_light(mtmp->data)) > 0)
  184. 		new_light_source(mtmp->mx, mtmp->my, ct,
  185. 				 LS_MONSTER, (genericptr_t)mtmp);
  186. 	mitem = 0;	/* extra inventory item for this monster */
  187.  
  188. 	if ((mcham = pm_to_cham(mndx)) != CHAM_ORDINARY) {
  189. 		/* If you're protected with a ring, don't create
  190. 		 * any shape-changing chameleons -dgk
  191. 		 */
  192. 		if (Protection_from_shape_changers)
  193. 			mtmp->cham = CHAM_ORDINARY;
  194. 		else {
  195. 			mtmp->cham = mcham;
  196. 			(void) newcham(mtmp, rndmonst(), FALSE, FALSE);
  197. 		}
  198. 	} else if (mndx == PM_WIZARD_OF_YENDOR) {
  199. 		mtmp->iswiz = TRUE;
  200. 		flags.no_of_wizards++;
  201. 		if (flags.no_of_wizards == 1 && Is_earthlevel(&u.uz))
  202. 			mitem = SPE_DIG;
  203. 	} else if (mndx == PM_DJINNI) {
  204. 		flags.djinni_count++;
  205. 	} else if (mndx == PM_GHOST) {
  206. 		flags.ghost_count++;
  207. 		if (!(mmflags & MM_NONAME))
  208. 			mtmp = christen_monst(mtmp, rndghostname());
  209. 	} else if (mndx == PM_VLAD_THE_IMPALER) {
  210. 		mitem = CANDELABRUM_OF_INVOCATION;
  211. 	} else if (mndx == PM_CROESUS) {
  212. 		mitem = TWO_HANDED_SWORD;
  213. 	} else if (ptr->msound == MS_NEMESIS) {
  214. 		mitem = BELL_OF_OPENING;
  215. 	} else if (mndx == PM_PESTILENCE) {
  216. 		mitem = POT_SICKNESS;
  217. 	}
  218. 	if (mitem && allow_minvent) (void) mongets(mtmp, mitem);
  219.  
  220. 	if(in_mklev) {
  221. 		if(((is_ndemon(ptr)) ||
  222. 		    (mndx == PM_WUMPUS) ||
  223. 		    (mndx == PM_LONG_WORM) ||
  224. 		    (mndx == PM_GIANT_EEL)) && !u.uhave.amulet && rn2(5))
  225. 			mtmp->msleeping = TRUE;
  226. 	} else {
  227. 		if(byyou) {
  228. 			newsym(mtmp->mx,mtmp->my);
  229. 			set_apparxy(mtmp);
  230. 		}
  231. 	}
  232. 	if(is_dprince(ptr) && ptr->msound == MS_BRIBE) {
  233. 	    mtmp->mpeaceful = mtmp->minvis = mtmp->perminvis = 1;
  234. 	    mtmp->mavenge = 0;
  235. 	    if (uwep && uwep->oartifact == ART_EXCALIBUR)
  236. 		mtmp->mpeaceful = mtmp->mtame = FALSE;
  237. 	}
  238. #ifndef DCC30_BUG
  239. 	if (mndx == PM_LONG_WORM && (mtmp->wormno = get_wormno()) != 0)
  240. #else
  241. 	/* DICE 3.0 doesn't like assigning and comparing mtmp->wormno in the
  242. 	 * same expression.
  243. 	 */
  244. 	if (mndx == PM_LONG_WORM &&
  245. 		(mtmp->wormno = get_wormno(), mtmp->wormno != 0))
  246. #endif
  247. 	{
  248. 	    /* we can now create worms with tails - 11/91 */
  249. 	    initworm(mtmp, rn2(5));
  250. 	    if (count_wsegs(mtmp)) place_worm_tail_randomly(mtmp, x, y);
  251. 	}
  252. 	set_malign(mtmp);		/* having finished peaceful changes */
  253. 	if(anymon) {
  254. 	    if ((ptr->geno & G_SGROUP) && rn2(2)) {
  255. 		m_initsgrp(mtmp, mtmp->mx, mtmp->my);
  256. 	    } else if (ptr->geno & G_LGROUP) {
  257. 		if(rn2(3))  m_initlgrp(mtmp, mtmp->mx, mtmp->my);
  258. 		else	    m_initsgrp(mtmp, mtmp->mx, mtmp->my);
  259. 	    }
  260. 	}
  261.  
  262. 	if (allow_minvent) {
  263. 	    if(is_armed(ptr))
  264. 		m_initweap(mtmp);	/* equip with weapons / armor */
  265. 	    m_initinv(mtmp);  /* add on a few special items incl. more armor */
  266. 	    m_dowear(mtmp, TRUE);
  267. 	} else {
  268. 	    /* no initial inventory is allowed */
  269. 	    if (mtmp->minvent) discard_minvent(mtmp);
  270. 	    mtmp->minvent = (struct obj *)0;    /* caller expects this */
  271. 	}
  272. 	if ((ptr->mflags3 & M3_WAITMASK) && !(mmflags & MM_NOWAIT)) {
  273. 		if (ptr->mflags3 & M3_WAITFORU)
  274. 			mtmp->mstrategy |= STRAT_WAITFORU;
  275. 		if (ptr->mflags3 & M3_CLOSE)
  276. 			mtmp->mstrategy |= STRAT_CLOSE;
  277. 	}
  278.  
  279. 	if (!in_mklev)
  280. 	    newsym(mtmp->mx,mtmp->my);	/* make sure the mon shows up */
  281.  
  282. 	return(mtmp);
  283. }

mbirth_limit[edit]

  1. int
  2. mbirth_limit(mndx)
  3. int mndx;
  4. {
  5. 	/* assert(MAXMONNO < 255); */
  6. 	return (mndx == PM_NAZGUL ? 9 : mndx == PM_ERINYS ? 3 : MAXMONNO); 
  7. }

create_critters[edit]

  1. /* used for wand/scroll/spell of create monster */
  2. /* returns TRUE iff you know monsters have been created */
  3. boolean
  4. create_critters(cnt, mptr)
  5. int cnt;
  6. struct permonst *mptr;		/* usually null; used for confused reading */
  7. {
  8. 	coord c;
  9. 	int x, y;
  10. 	struct monst *mon;
  11. 	boolean known = FALSE;
  12. #ifdef WIZARD
  13. 	boolean ask = wizard;
  14. #endif
  15.  
  16. 	while (cnt--) {
  17. #ifdef WIZARD
  18. 	    if (ask) {
  19. 		if (create_particular()) {
  20. 		    known = TRUE;
  21. 		    continue;
  22. 		}
  23. 		else ask = FALSE;	/* ESC will shut off prompting */
  24. 	    }
  25. #endif
  26. 	    x = u.ux,  y = u.uy;
  27. 	    /* if in water, try to encourage an aquatic monster
  28. 	       by finding and then specifying another wet location */
  29. 	    if (!mptr && u.uinwater && enexto(&c, x, y, &mons[PM_GIANT_EEL]))
  30. 		x = c.x,  y = c.y;
  31.  
  32. 	    mon = makemon(mptr, x, y, NO_MM_FLAGS);
  33. 	    if (mon && canspotmon(mon)) known = TRUE;
  34. 	}
  35. 	return known;
  36. }
  37.  
  38. #endif /* OVL1 */

uncommon[edit]

  1. #ifdef OVL0
  2.  
  3. STATIC_OVL boolean
  4. uncommon(mndx)
  5. int mndx;
  6. {
  7. 	if (mons[mndx].geno & (G_NOGEN | G_UNIQ)) return TRUE;
  8. 	if (mvitals[mndx].mvflags & G_GONE) return TRUE;
  9. 	if (Inhell)
  10. 		return(mons[mndx].maligntyp > A_NEUTRAL);
  11. 	else
  12. 		return((mons[mndx].geno & G_HELL) != 0);
  13. }

align_shift[edit]

  1. /*
  2. *	shift the probability of a monster's generation by
  3. *	comparing the dungeon alignment and monster alignment.
  4. *	return an integer in the range of 0-5.
  5. */
  6. STATIC_OVL int
  7. align_shift(ptr)
  8. register struct permonst *ptr;
  9. {
  10. static NEARDATA long oldmoves = 0L;	/* != 1, starting value of moves */
  11. static NEARDATA s_level *lev;
  12. register int alshift;
  13.  
  14. if(oldmoves != moves) {
  15. 	lev = Is_special(&u.uz);
  16. 	oldmoves = moves;
  17. }
  18. switch((lev) ? lev->flags.align : dungeons[u.uz.dnum].flags.align) {
  19. default:	/* just in case */
  20. case AM_NONE:	alshift = 0;
  21. 			break;
  22. case AM_LAWFUL:	alshift = (ptr->maligntyp+20)/(2*ALIGNWEIGHT);
  23. 			break;
  24. case AM_NEUTRAL:	alshift = (20 - abs(ptr->maligntyp))/ALIGNWEIGHT;
  25. 			break;
  26. case AM_CHAOTIC:	alshift = (-(ptr->maligntyp-20))/(2*ALIGNWEIGHT);
  27. 			break;
  28. }
  29. return alshift;
  30. }

rndmonst[edit]

  1. static NEARDATA struct {
  2. 	int choice_count;
  3. 	char mchoices[SPECIAL_PM];	/* value range is 0..127 */
  4. } rndmonst_state = { -1, {0} };
  5.  
  6. /* select a random monster type */
  7. struct permonst *
  8. rndmonst()
  9. {
  10. 	register struct permonst *ptr;
  11. 	register int mndx, ct;
  12.  
  13. 	if (u.uz.dnum == quest_dnum && rn2(7) && (ptr = qt_montype()) != 0)
  14. 	    return ptr;
  15.  
  16. 	if (rndmonst_state.choice_count < 0) {	/* need to recalculate */
  17. 	    int zlevel, minmlev, maxmlev;
  18. 	    boolean elemlevel;
  19. #ifdef REINCARNATION
  20. 	    boolean upper;
  21. #endif
  22.  
  23. 	    rndmonst_state.choice_count = 0;
  24. 	    /* look for first common monster */
  25. 	    for (mndx = LOW_PM; mndx < SPECIAL_PM; mndx++) {
  26. 		if (!uncommon(mndx)) break;
  27. 		rndmonst_state.mchoices[mndx] = 0;
  28. 	    }		
  29. 	    if (mndx == SPECIAL_PM) {
  30. 		/* evidently they've all been exterminated */
  31. #ifdef DEBUG
  32. 		pline("rndmonst: no common mons!");
  33. #endif
  34. 		return (struct permonst *)0;
  35. 	    } /* else `mndx' now ready for use below */
  36. 	    zlevel = level_difficulty();
  37. 	    /* determine the level of the weakest monster to make. */
  38. 	    minmlev = zlevel / 6;
  39. 	    /* determine the level of the strongest monster to make. */
  40. 	    maxmlev = (zlevel + u.ulevel) / 2;
  41. #ifdef REINCARNATION
  42. 	    upper = Is_rogue_level(&u.uz);
  43. #endif
  44. 	    elemlevel = In_endgame(&u.uz) && !Is_astralevel(&u.uz);
  45.  
  46. /*
  47. *	Find out how many monsters exist in the range we have selected.
  48. */
  49. 	    /* (`mndx' initialized above) */
  50. 	    for ( ; mndx < SPECIAL_PM; mndx++) {
  51. 		ptr = &mons[mndx];
  52. 		rndmonst_state.mchoices[mndx] = 0;
  53. 		if (tooweak(mndx, minmlev) || toostrong(mndx, maxmlev))
  54. 		    continue;
  55. #ifdef REINCARNATION
  56. 		if (upper && !isupper(def_monsyms[(int)(ptr->mlet)])) continue;
  57. #endif
  58. 		if (elemlevel && wrong_elem_type(ptr)) continue;
  59. 		if (uncommon(mndx)) continue;
  60. 		if (Inhell && (ptr->geno & G_NOHELL)) continue;
  61. 		ct = (int)(ptr->geno & G_FREQ) + align_shift(ptr);
  62. 		if (ct < 0 || ct > 127)
  63. 		    panic("rndmonst: bad count [#%d: %d]", mndx, ct);
  64. 		rndmonst_state.choice_count += ct;
  65. 		rndmonst_state.mchoices[mndx] = (char)ct;
  66. 	    }
  67. /*
  68. *	    Possible modification:  if choice_count is "too low",
  69. *	    expand minmlev..maxmlev range and try again.
  70. */
  71. 	} /* choice_count+mchoices[] recalc */
  72.  
  73. 	if (rndmonst_state.choice_count <= 0) {
  74. 	    /* maybe no common mons left, or all are too weak or too strong */
  75. #ifdef DEBUG
  76. 	    Norep("rndmonst: choice_count=%d", rndmonst_state.choice_count);
  77. #endif
  78. 	    return (struct permonst *)0;
  79. 	}
  80.  
  81. /*
  82. *	Now, select a monster at random.
  83. */
  84. 	ct = rnd(rndmonst_state.choice_count);
  85. 	for (mndx = LOW_PM; mndx < SPECIAL_PM; mndx++)
  86. 	    if ((ct -= (int)rndmonst_state.mchoices[mndx]) <= 0) break;
  87.  
  88. 	if (mndx == SPECIAL_PM || uncommon(mndx)) {	/* shouldn't happen */
  89. 	    impossible("rndmonst: bad `mndx' [#%d]", mndx);
  90. 	    return (struct permonst *)0;
  91. 	}
  92. 	return &mons[mndx];
  93. }

reset_rndmonst[edit]

  1. /* called when you change level (experience or dungeon depth) or when
  2. monster species can no longer be created (genocide or extinction) */
  3. void
  4. reset_rndmonst(mndx)
  5. int mndx;	/* particular species that can no longer be created */
  6. {
  7. 	/* cached selection info is out of date */
  8. 	if (mndx == NON_PM) {
  9. 	    rndmonst_state.choice_count = -1;	/* full recalc needed */
  10. 	} else if (mndx < SPECIAL_PM) {
  11. 	    rndmonst_state.choice_count -= rndmonst_state.mchoices[mndx];
  12. 	    rndmonst_state.mchoices[mndx] = 0;
  13. 	} /* note: safe to ignore extinction of unique monsters */
  14. }
  15.  
  16. #endif /* OVL0 */

mkclass[edit]

  1. #ifdef OVL1
  2.  
  3. /*	The routine below is used to make one of the multiple types
  4. *	of a given monster class.  The second parameter specifies a
  5. *	special casing bit mask to allow the normal genesis
  6. *	masks to be deactivated.  Returns 0 if no monsters
  7. *	in that class can be made.
  8. */
  9.  
  10. struct permonst *
  11. mkclass(class,spc)
  12. char	class;
  13. int	spc;
  14. {
  15. 	register int	first, last, num = 0;
  16. 	int maxmlev, mask = (G_NOGEN | G_UNIQ) & ~spc;
  17.  
  18. 	maxmlev = level_difficulty() >> 1;
  19. 	if(class < 1 || class >= MAXMCLASSES) {
  20. 	    impossible("mkclass called with bad class!");
  21. 	    return((struct permonst *) 0);
  22. 	}
  23. /*	Assumption #1:	monsters of a given class are contiguous in the
  24. *			mons[] array.
  25. */
  26. 	for (first = LOW_PM; first < SPECIAL_PM; first++)
  27. 	    if (mons[first].mlet == class) break;
  28. 	if (first == SPECIAL_PM) return (struct permonst *) 0;
  29.  
  30. 	for (last = first;
  31. 		last < SPECIAL_PM && mons[last].mlet == class; last++)
  32. 	    if (!(mvitals[last].mvflags & G_GONE) && !(mons[last].geno & mask)
  33. 					&& !is_placeholder(&mons[last])) {
  34. 		/* consider it */
  35. 		if(num && toostrong(last, maxmlev) &&
  36. 		   monstr[last] != monstr[last-1] && rn2(2)) break;
  37. 		num += mons[last].geno & G_FREQ;
  38. 	    }
  39.  
  40. 	if(!num) return((struct permonst *) 0);
  41.  
  42. /*	Assumption #2:	monsters of a given class are presented in ascending
  43. *			order of strength.
  44. */
  45. 	for(num = rnd(num); num > 0; first++)
  46. 	    if (!(mvitals[first].mvflags & G_GONE) && !(mons[first].geno & mask)
  47. 					&& !is_placeholder(&mons[first])) {
  48. 		/* skew towards lower value monsters at lower exp. levels */
  49. 		num -= mons[first].geno & G_FREQ;
  50. 		if (num && adj_lev(&mons[first]) > (u.ulevel*2)) {
  51. 		    /* but not when multiple monsters are same level */
  52. 		    if (mons[first].mlevel != mons[first+1].mlevel)
  53. 			num--;
  54. 		}
  55. 	    }
  56. 	first--; /* correct an off-by-one error */
  57.  
  58. 	return(&mons[first]);
  59. }

adj_lev[edit]

  1. int
  2. adj_lev(ptr)	/* adjust strength of monsters based on u.uz and u.ulevel */
  3. register struct permonst *ptr;
  4. {
  5. 	int	tmp, tmp2;
  6.  
  7. 	if (ptr == &mons[PM_WIZARD_OF_YENDOR]) {
  8. 		/* does not depend on other strengths, but does get stronger
  9. 		 * every time he is killed
  10. 		 */
  11. 		tmp = ptr->mlevel + mvitals[PM_WIZARD_OF_YENDOR].died;
  12. 		if (tmp > 49) tmp = 49;
  13. 		return tmp;
  14. 	}
  15.  
  16. 	if((tmp = ptr->mlevel) > 49) return(50); /* "special" demons/devils */
  17. 	tmp2 = (level_difficulty() - tmp);
  18. 	if(tmp2 < 0) tmp--;		/* if mlevel > u.uz decrement tmp */
  19. 	else tmp += (tmp2 / 5);		/* else increment 1 per five diff */
  20.  
  21. 	tmp2 = (u.ulevel - ptr->mlevel);	/* adjust vs. the player */
  22. 	if(tmp2 > 0) tmp += (tmp2 / 4);		/* level as well */
  23.  
  24. 	tmp2 = (3 * ((int) ptr->mlevel))/ 2;	/* crude upper limit */
  25. 	if (tmp2 > 49) tmp2 = 49;		/* hard upper limit */
  26. 	return((tmp > tmp2) ? tmp2 : (tmp > 0 ? tmp : 0)); /* 0 lower limit */
  27. }
  28.  
  29. #endif /* OVL1 */

grow_up[edit]

  1. #ifdef OVLB
  2.  
  3. struct permonst *
  4. grow_up(mtmp, victim)	/* `mtmp' might "grow up" into a bigger version */
  5. struct monst *mtmp, *victim;
  6. {
  7. 	int oldtype, newtype, max_increase, cur_increase,
  8. 	    lev_limit, hp_threshold;
  9. 	struct permonst *ptr = mtmp->data;
  10.  
  11. 	/* monster died after killing enemy but before calling this function */
  12. 	/* currently possible if killing a gas spore */
  13. 	if (mtmp->mhp <= 0)
  14. 	    return ((struct permonst *)0);
  15.  
  16. 	/* note:  none of the monsters with special hit point calculations
  17. 	   have both little and big forms */
  18. 	oldtype = monsndx(ptr);
  19. 	newtype = little_to_big(oldtype);
  20. 	if (newtype == PM_PRIEST && mtmp->female) newtype = PM_PRIESTESS;
  21.  
  22. 	/* growth limits differ depending on method of advancement */
  23. 	if (victim) {		/* killed a monster */
  24. 	    /*
  25. 	     * The HP threshold is the maximum number of hit points for the
  26. 	     * current level; once exceeded, a level will be gained.
  27. 	     * Possible bug: if somehow the hit points are already higher
  28. 	     * than that, monster will gain a level without any increase in HP.
  29. 	     */
  30. 	    hp_threshold = mtmp->m_lev * 8;		/* normal limit */
  31. 	    if (!mtmp->m_lev)
  32. 		hp_threshold = 4;
  33. 	    else if (is_golem(ptr))	/* strange creatures */
  34. 		hp_threshold = ((mtmp->mhpmax / 10) + 1) * 10 - 1;
  35. 	    else if (is_home_elemental(ptr))
  36. 		hp_threshold *= 3;
  37. 	    lev_limit = 3 * (int)ptr->mlevel / 2;	/* same as adj_lev() */
  38. 	    /* If they can grow up, be sure the level is high enough for that */
  39. 	    if (oldtype != newtype && mons[newtype].mlevel > lev_limit)
  40. 		lev_limit = (int)mons[newtype].mlevel;
  41. 	    /* number of hit points to gain; unlike for the player, we put
  42. 	       the limit at the bottom of the next level rather than the top */
  43. 	    max_increase = rnd((int)victim->m_lev + 1);
  44. 	    if (mtmp->mhpmax + max_increase > hp_threshold + 1)
  45. 		max_increase = max((hp_threshold + 1) - mtmp->mhpmax, 0);
  46. 	    cur_increase = (max_increase > 1) ? rn2(max_increase) : 0;
  47. 	} else {
  48. 	    /* a gain level potion or wraith corpse; always go up a level
  49. 	       unless already at maximum (49 is hard upper limit except
  50. 	       for demon lords, who start at 50 and can't go any higher) */
  51. 	    max_increase = cur_increase = rnd(8);
  52. 	    hp_threshold = 0;	/* smaller than `mhpmax + max_increase' */
  53. 	    lev_limit = 50;		/* recalc below */
  54. 	}
  55.  
  56. 	mtmp->mhpmax += max_increase;
  57. 	mtmp->mhp += cur_increase;
  58. 	if (mtmp->mhpmax <= hp_threshold)
  59. 	    return ptr;		/* doesn't gain a level */
  60.  
  61. 	if (is_mplayer(ptr)) lev_limit = 30;	/* same as player */
  62. 	else if (lev_limit < 5) lev_limit = 5;	/* arbitrary */
  63. 	else if (lev_limit > 49) lev_limit = (ptr->mlevel > 49 ? 50 : 49);
  64.  
  65. 	if ((int)++mtmp->m_lev >= mons[newtype].mlevel && newtype != oldtype) {
  66. 	    ptr = &mons[newtype];
  67. 	    if (mvitals[newtype].mvflags & G_GENOD) {	/* allow G_EXTINCT */
  68. 		if (sensemon(mtmp))
  69. 		    pline("As %s grows up into %s, %s %s!", mon_nam(mtmp),
  70. 			an(ptr->mname), mhe(mtmp),
  71. 			nonliving(ptr) ? "expires" : "dies");
  72. 		set_mon_data(mtmp, ptr, -1);	/* keep mvitals[] accurate */
  73. 		mondied(mtmp);
  74. 		return (struct permonst *)0;
  75. 	    }
  76. 	    set_mon_data(mtmp, ptr, 1);		/* preserve intrinsics */
  77. 	    newsym(mtmp->mx, mtmp->my);		/* color may change */
  78. 	    lev_limit = (int)mtmp->m_lev;	/* never undo increment */
  79. 	}
  80. 	/* sanity checks */
  81. 	if ((int)mtmp->m_lev > lev_limit) {
  82. 	    mtmp->m_lev--;	/* undo increment */
  83. 	    /* HP might have been allowed to grow when it shouldn't */
  84. 	    if (mtmp->mhpmax == hp_threshold + 1) mtmp->mhpmax--;
  85. 	}
  86. 	if (mtmp->mhpmax > 50*8) mtmp->mhpmax = 50*8;	  /* absolute limit */
  87. 	if (mtmp->mhp > mtmp->mhpmax) mtmp->mhp = mtmp->mhpmax;
  88.  
  89. 	return ptr;
  90. }
  91.  
  92. #endif /* OVLB */

mongets[edit]

mongets() takes two parameters, monster and an object name macro, and puts a randomly generated nonartifact object of the given type into the monster's inventory.

  1. #ifdef OVL1
  2.  
  3. int
  4. mongets(mtmp, otyp)
  5. register struct monst *mtmp;
  6. register int otyp;
  7. {
  8. 	register struct obj *otmp;
  9. 	int spe;
  10.  
  11. 	if (!otyp) return 0;
  12. 	otmp = mksobj(otyp, TRUE, FALSE);
  13. 	if (otmp) {
  14. 	    if (mtmp->data->mlet == S_DEMON) {
  15. 		/* demons never get blessed objects */
  16. 		if (otmp->blessed) curse(otmp);
  17. 	    } else if(is_lminion(mtmp)) {
  18. 		/* lawful minions don't get cursed, bad, or rusting objects */
  19. 		otmp->cursed = FALSE;
  20. 		if(otmp->spe < 0) otmp->spe = 0;
  21. 		otmp->oerodeproof = TRUE;
  22. 	    } else if(is_mplayer(mtmp->data) && is_sword(otmp)) {
  23. 		otmp->spe = (3 + rn2(4));
  24. 	    }
  25.  
  26. 	    if(otmp->otyp == CANDELABRUM_OF_INVOCATION) {
  27. 		otmp->spe = 0;
  28. 		otmp->age = 0L;
  29. 		otmp->lamplit = FALSE;
  30. 		otmp->blessed = otmp->cursed = FALSE;
  31. 	    } else if (otmp->otyp == BELL_OF_OPENING) {
  32. 		otmp->blessed = otmp->cursed = FALSE;
  33. 	    } else if (otmp->otyp == SPE_BOOK_OF_THE_DEAD) {
  34. 		otmp->blessed = FALSE;
  35. 		otmp->cursed = TRUE;
  36. 	    }
  37.  
  38. 	    /* leaders don't tolerate inferior quality battle gear */
  39. 	    if (is_prince(mtmp->data)) {
  40. 		if (otmp->oclass == WEAPON_CLASS && otmp->spe < 1)
  41. 		    otmp->spe = 1;
  42. 		else if (otmp->oclass == ARMOR_CLASS && otmp->spe < 0)
  43. 		    otmp->spe = 0;
  44. 	    }
  45.  
  46. 	    spe = otmp->spe;
  47. 	    (void) mpickobj(mtmp, otmp);	/* might free otmp */
  48. 	    return(spe);
  49. 	} else return(0);
  50. }
  51.  
  52. #endif /* OVL1 */

golemhp[edit]

  1. #ifdef OVLB
  2.  
  3. int
  4. golemhp(type)
  5. int type;
  6. {
  7. 	switch(type) {
  8. 		case PM_STRAW_GOLEM: return 20;
  9. 		case PM_PAPER_GOLEM: return 20;
  10. 		case PM_ROPE_GOLEM: return 30;
  11. 		case PM_LEATHER_GOLEM: return 40;
  12. 		case PM_GOLD_GOLEM: return 40;
  13. 		case PM_WOOD_GOLEM: return 50;
  14. 		case PM_FLESH_GOLEM: return 40;
  15. 		case PM_CLAY_GOLEM: return 50;
  16. 		case PM_STONE_GOLEM: return 60;
  17. 		case PM_GLASS_GOLEM: return 60;
  18. 		case PM_IRON_GOLEM: return 80;
  19. 		default: return 0;
  20. 	}
  21. }
  22.  
  23. #endif /* OVLB */

peace_minded[edit]

  1. #ifdef OVL1
  2.  
  3. /*
  4. *	Alignment vs. yours determines monster's attitude to you.
  5. *	( some "animal" types are co-aligned, but also hungry )
  6. */
  7. boolean
  8. peace_minded(ptr)
  9. register struct permonst *ptr;
  10. {
  11. 	aligntyp mal = ptr->maligntyp, ual = u.ualign.type;
  12.  
  13. 	if (always_peaceful(ptr)) return TRUE;
  14. 	if (always_hostile(ptr)) return FALSE;
  15. 	if (ptr->msound == MS_LEADER || ptr->msound == MS_GUARDIAN)
  16. 		return TRUE;
  17. 	if (ptr->msound == MS_NEMESIS)	return FALSE;
  18.  
  19. 	if (race_peaceful(ptr)) return TRUE;
  20. 	if (race_hostile(ptr)) return FALSE;
  21.  
  22. 	/* the monster is hostile if its alignment is different from the
  23. 	 * player's */
  24. 	if (sgn(mal) != sgn(ual)) return FALSE;
  25.  
  26. 	/* Negative monster hostile to player with Amulet. */
  27. 	if (mal < A_NEUTRAL && u.uhave.amulet) return FALSE;
  28.  
  29. 	/* minions are hostile to players that have strayed at all */
  30. 	if (is_minion(ptr)) return((boolean)(u.ualign.record >= 0));
  31.  
  32. 	/* Last case:  a chance of a co-aligned monster being
  33. 	 * hostile.  This chance is greater if the player has strayed
  34. 	 * (u.ualign.record negative) or the monster is not strongly aligned.
  35. 	 */
  36. 	return((boolean)(!!rn2(16 + (u.ualign.record < -15 ? -15 : u.ualign.record)) &&
  37. 		!!rn2(2 + abs(mal))));
  38. }

set_malign[edit]

  1. /* Set malign to have the proper effect on player alignment if monster is
  2. * killed.  Negative numbers mean it's bad to kill this monster; positive
  3. * numbers mean it's good.  Since there are more hostile monsters than
  4. * peaceful monsters, the penalty for killing a peaceful monster should be
  5. * greater than the bonus for killing a hostile monster to maintain balance.
  6. * Rules:
  7. *   it's bad to kill peaceful monsters, potentially worse to kill always-
  8. *	peaceful monsters
  9. *   it's never bad to kill a hostile monster, although it may not be good
  10. */
  11. void
  12. set_malign(mtmp)
  13. struct monst *mtmp;
  14. {
  15. 	schar mal = mtmp->data->maligntyp;
  16. 	boolean coaligned;
  17.  
  18. 	if (mtmp->ispriest || mtmp->isminion) {
  19. 		/* some monsters have individual alignments; check them */
  20. 		if (mtmp->ispriest)
  21. 			mal = EPRI(mtmp)->shralign;
  22. 		else if (mtmp->isminion)
  23. 			mal = EMIN(mtmp)->min_align;
  24. 		/* unless alignment is none, set mal to -5,0,5 */
  25. 		/* (see align.h for valid aligntyp values)     */
  26. 		if(mal != A_NONE)
  27. 			mal *= 5;
  28. 	}
  29.  
  30. 	coaligned = (sgn(mal) == sgn(u.ualign.type));
  31. 	if (mtmp->data->msound == MS_LEADER) {
  32. 		mtmp->malign = -20;
  33. 	} else if (mal == A_NONE) {
  34. 		if (mtmp->mpeaceful)
  35. 			mtmp->malign = 0;
  36. 		else
  37. 			mtmp->malign = 20;	/* really hostile */
  38. 	} else if (always_peaceful(mtmp->data)) {
  39. 		int absmal = abs(mal);
  40. 		if (mtmp->mpeaceful)
  41. 			mtmp->malign = -3*max(5,absmal);
  42. 		else
  43. 			mtmp->malign = 3*max(5,absmal); /* renegade */
  44. 	} else if (always_hostile(mtmp->data)) {
  45. 		int absmal = abs(mal);
  46. 		if (coaligned)
  47. 			mtmp->malign = 0;
  48. 		else
  49. 			mtmp->malign = max(5,absmal);
  50. 	} else if (coaligned) {
  51. 		int absmal = abs(mal);
  52. 		if (mtmp->mpeaceful)
  53. 			mtmp->malign = -3*max(3,absmal);
  54. 		else	/* renegade */
  55. 			mtmp->malign = max(3,absmal);
  56. 	} else	/* not coaligned and therefore hostile */
  57. 		mtmp->malign = abs(mal);
  58. }
  59.  
  60. #endif /* OVL1 */

set_mimic_sym[edit]

  1. #ifdef OVLB
  2.  
  3. static NEARDATA char syms[] = {
  4. 	MAXOCLASSES, MAXOCLASSES+1, RING_CLASS, WAND_CLASS, WEAPON_CLASS,
  5. 	FOOD_CLASS, COIN_CLASS, SCROLL_CLASS, POTION_CLASS, ARMOR_CLASS,
  6. 	AMULET_CLASS, TOOL_CLASS, ROCK_CLASS, GEM_CLASS, SPBOOK_CLASS,
  7. 	S_MIMIC_DEF, S_MIMIC_DEF, S_MIMIC_DEF,
  8. };
  9.  
  10. void
  11. set_mimic_sym(mtmp)		/* KAA, modified by ERS */
  12. register struct monst *mtmp;
  13. {
  14. 	int typ, roomno, rt;
  15. 	unsigned appear, ap_type;
  16. 	int s_sym;
  17. 	struct obj *otmp;
  18. 	int mx, my;
  19.  
  20. 	if (!mtmp) return;
  21. 	mx = mtmp->mx; my = mtmp->my;
  22. 	typ = levl[mx][my].typ;
  23. 					/* only valid for INSIDE of room */
  24. 	roomno = levl[mx][my].roomno - ROOMOFFSET;
  25. 	if (roomno >= 0)
  26. 		rt = rooms[roomno].rtype;
  27. #ifdef SPECIALIZATION
  28. 	else if (IS_ROOM(typ))
  29. 		rt = OROOM,  roomno = 0;
  30. #endif
  31. 	else	rt = 0;	/* roomno < 0 case for GCC_WARN */
  32.  
  33. 	if (OBJ_AT(mx, my)) {
  34. 		ap_type = M_AP_OBJECT;
  35. 		appear = level.objects[mx][my]->otyp;
  36. 	} else if (IS_DOOR(typ) || IS_WALL(typ) ||
  37. 		   typ == SDOOR || typ == SCORR) {
  38. 		ap_type = M_AP_FURNITURE;
  39. 		/*
  40. 		 *  If there is a wall to the left that connects to this
  41. 		 *  location, then the mimic mimics a horizontal closed door.
  42. 		 *  This does not allow doors to be in corners of rooms.
  43. 		 */
  44. 		if (mx != 0 &&
  45. 			(levl[mx-1][my].typ == HWALL    ||
  46. 			 levl[mx-1][my].typ == TLCORNER ||
  47. 			 levl[mx-1][my].typ == TRWALL   ||
  48. 			 levl[mx-1][my].typ == BLCORNER ||
  49. 			 levl[mx-1][my].typ == TDWALL   ||
  50. 			 levl[mx-1][my].typ == CROSSWALL||
  51. 			 levl[mx-1][my].typ == TUWALL    ))
  52. 		    appear = S_hcdoor;
  53. 		else
  54. 		    appear = S_vcdoor;
  55.  
  56. 		if(!mtmp->minvis || See_invisible)
  57. 		    block_point(mx,my);	/* vision */
  58. 	} else if (level.flags.is_maze_lev && rn2(2)) {
  59. 		ap_type = M_AP_OBJECT;
  60. 		appear = STATUE;
  61. 	} else if (roomno < 0) {
  62. 		ap_type = M_AP_OBJECT;
  63. 		appear = BOULDER;
  64. 		if(!mtmp->minvis || See_invisible)
  65. 		    block_point(mx,my);	/* vision */
  66. 	} else if (rt == ZOO || rt == VAULT) {
  67. 		ap_type = M_AP_OBJECT;
  68. 		appear = GOLD_PIECE;
  69. 	} else if (rt == DELPHI) {
  70. 		if (rn2(2)) {
  71. 			ap_type = M_AP_OBJECT;
  72. 			appear = STATUE;
  73. 		} else {
  74. 			ap_type = M_AP_FURNITURE;
  75. 			appear = S_fountain;
  76. 		}
  77. 	} else if (rt == TEMPLE) {
  78. 		ap_type = M_AP_FURNITURE;
  79. 		appear = S_altar;
  80. 	/*
  81. 	 * We won't bother with beehives, morgues, barracks, throne rooms
  82. 	 * since they shouldn't contain too many mimics anyway...
  83. 	 */
  84. 	} else if (rt >= SHOPBASE) {
  85. 		s_sym = get_shop_item(rt - SHOPBASE);
  86. 		if (s_sym < 0) {
  87. 			ap_type = M_AP_OBJECT;
  88. 			appear = -s_sym;
  89. 		} else {
  90. 			if (s_sym == RANDOM_CLASS)
  91. 				s_sym = syms[rn2((int)sizeof(syms)-2) + 2];
  92. 			goto assign_sym;
  93. 		}
  94. 	} else {
  95. 		s_sym = syms[rn2((int)sizeof(syms))];
  96. assign_sym:
  97. 		if (s_sym >= MAXOCLASSES) {
  98. 			ap_type = M_AP_FURNITURE;
  99. 			appear = s_sym == MAXOCLASSES ? S_upstair : S_dnstair;
  100. 		} else if (s_sym == COIN_CLASS) {
  101. 			ap_type = M_AP_OBJECT;
  102. 			appear = GOLD_PIECE;
  103. 		} else {
  104. 			ap_type = M_AP_OBJECT;
  105. 			if (s_sym == S_MIMIC_DEF) {
  106. 				appear = STRANGE_OBJECT;
  107. 			} else {
  108. 				otmp = mkobj( (char) s_sym, FALSE );
  109. 				appear = otmp->otyp;
  110. 				/* make sure container contents are free'ed */
  111. 				obfree(otmp, (struct obj *) 0);
  112. 			}
  113. 		}
  114. 	}
  115. 	mtmp->m_ap_type = ap_type;
  116. 	mtmp->mappearance = appear;
  117. }

bagotricks[edit]

  1. /* release a monster from a bag of tricks */
  2. void
  3. bagotricks(bag)
  4. struct obj *bag;
  5. {
  6. if (!bag || bag->otyp != BAG_OF_TRICKS) {
  7. 	impossible("bad bag o' tricks");
  8. } else if (bag->spe < 1) {
  9. 	pline(nothing_happens);
  10. } else {
  11. 	boolean gotone = FALSE;
  12. 	int cnt = 1;
  13.  
  14. 	consume_obj_charge(bag, TRUE);
  15.  
  16. 	if (!rn2(23)) cnt += rn1(7, 1);
  17. 	while (cnt-- > 0) {
  18. 	    if (makemon((struct permonst *)0, u.ux, u.uy, NO_MM_FLAGS))
  19. 		gotone = TRUE;
  20. 	}
  21. 	if (gotone) makeknown(BAG_OF_TRICKS);
  22. }
  23. }
  24.  
  25. #endif /* OVLB */
  26.  
  27. /*makemon.c*/