Fandom

Wikihack

Source:SLASH'EM 0.0.7E7F2/makemon.c

2,034pages on
this wiki
Add New Page
Talk0

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

Below is the full text to makemon.c from the source code of SLASH'EM 0.0.7E7F2. To link to a particular line, write [[SLASH'EM 0.0.7E7F2/makemon.c#line123]], for example.

The latest source code for vanilla NetHack is at Source code.


The NetHack General Public License applies to screenshots, source code and other content from NetHack.
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. */
4.    
5.    #include "hack.h"
6.    #include "epri.h"
7.    #include "emin.h"
8.    #include "edog.h"
9.    #ifdef REINCARNATION
10.   #include <ctype.h>
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.   STATIC_DCL void FDECL(m_initweap_normal,(struct monst *));
31.   #ifdef OVL1
32.   STATIC_DCL void FDECL(m_initinv,(struct monst *));
33.   #endif /* OVL1 */
34.   
35.   extern const int monstr[];
36.   
37.   #define m_initsgrp(mtmp, x, y)	m_initgrp(mtmp, x, y, 3)
38.   #define m_initlgrp(mtmp, x, y)	m_initgrp(mtmp, x, y, 10)
39.   #define m_initvlgrp(mtmp, x, y)  m_initgrp(mtmp, x, y, 20)
40.   #define toostrong(monindx, lev) (monstr[monindx] > lev)
41.   #define tooweak(monindx, lev)	(monstr[monindx] < lev)
42.   
43.   #ifdef OVLB
44.   boolean
45.   is_home_elemental(ptr)
46.   register struct permonst *ptr;
47.   {
48.   	if (ptr->mlet == S_ELEMENTAL)
49.   	    switch (monsndx(ptr)) {
50.   		case PM_AIR_ELEMENTAL: return Is_airlevel(&u.uz);
51.   		case PM_FIRE_ELEMENTAL: return Is_firelevel(&u.uz);
52.   		case PM_EARTH_ELEMENTAL: return Is_earthlevel(&u.uz);
53.   		case PM_WATER_ELEMENTAL: return Is_waterlevel(&u.uz);
54.   	    }
55.   	return FALSE;
56.   }
57.   
58.   /*
59.    * Return true if the given monster cannot exist on this elemental level.
60.    */
61.   STATIC_OVL boolean
62.   wrong_elem_type(ptr)
63.       register struct permonst *ptr;
64.   {
65.       if (ptr->mlet == S_ELEMENTAL) {
66.   	return((boolean)(!is_home_elemental(ptr)));
67.       } else if (Is_earthlevel(&u.uz)) {
68.   	/* no restrictions? */
69.       } else if (Is_waterlevel(&u.uz)) {
70.   	/* just monsters that can swim */
71.   	if(!is_swimmer(ptr)) return TRUE;
72.       } else if (Is_firelevel(&u.uz)) {
73.   	if (!pm_resistance(ptr,MR_FIRE)) return TRUE;
74.       } else if (Is_airlevel(&u.uz)) {
75.   	if(!(is_flyer(ptr) && ptr->mlet != S_TRAPPER) && !is_floater(ptr)
76.   	   && !amorphous(ptr) && !noncorporeal(ptr) && !is_whirly(ptr))
77.   	    return TRUE;
78.       }
79.       return FALSE;
80.   }
81.   
82.   STATIC_OVL void
83.   m_initgrp(mtmp, x, y, n)	/* make a group just like mtmp */
84.   register struct monst *mtmp;
85.   register int x, y, n;
86.   {
87.   	coord mm;
88.   	register int cnt = rnd(n);
89.   	struct monst *mon;
90.   #if defined(__GNUC__) && (defined(HPUX) || defined(DGUX))
91.   	/* There is an unresolved problem with several people finding that
92.   	 * the game hangs eating CPU; if interrupted and restored, the level
93.   	 * will be filled with monsters.  Of those reports giving system type,
94.   	 * there were two DG/UX and two HP-UX, all using gcc as the compiler.
95.   	 * hcroft@hpopb1.cern.ch, using gcc 2.6.3 on HP-UX, says that the
96.   	 * problem went away for him and another reporter-to-newsgroup
97.   	 * after adding this debugging code.  This has almost got to be a
98.   	 * compiler bug, but until somebody tracks it down and gets it fixed,
99.   	 * might as well go with the "but it went away when I tried to find
100.  	 * it" code.
101.  	 */
102.  	int cnttmp,cntdiv;
103.  
104.  	cnttmp = cnt;
105.  # ifdef DEBUG
106.  	pline("init group call x=%d,y=%d,n=%d,cnt=%d.", x, y, n, cnt);
107.  # endif
108.  	cntdiv = ((u.ulevel < 3) ? 4 : (u.ulevel < 5) ? 2 : 1);
109.  #endif
110.  	/* Tuning: cut down on swarming at low character levels [mrs] */
111.  	if (u.ulevel < 5) cnt /= 2;
112.  #if defined(__GNUC__) && (defined(HPUX) || defined(DGUX))
113.  	if (cnt != (cnttmp/cntdiv)) {
114.  		pline("cnt=%d using %d, cnttmp=%d, cntdiv=%d", cnt,
115.  			(u.ulevel < 3) ? 4 : (u.ulevel < 5) ? 2 : 1,
116.  			cnttmp, cntdiv);
117.  	}
118.  #endif
119.  	if(!cnt) cnt++;
120.  #if defined(__GNUC__) && (defined(HPUX) || defined(DGUX))
121.  	if (cnt < 0) cnt = 1;
122.  	if (cnt > 10) cnt = 10;
123.  #endif
124.  
125.  	mm.x = x;
126.  	mm.y = y;
127.  	while(cnt--) {
128.  		if (peace_minded(mtmp->data)) continue;
129.  		/* Don't create groups of peaceful monsters since they'll get
130.  		 * in our way.  If the monster has a percentage chance so some
131.  		 * are peaceful and some are not, the result will just be a
132.  		 * smaller group.
133.  		 */
134.  		if (enexto(&mm, mm.x, mm.y, mtmp->data)) {
135.  		    mon = makemon(mtmp->data, mm.x, mm.y, NO_MM_FLAGS);
136.  		    mon->mpeaceful = FALSE;
137.  		    mon->mavenge = 0;
138.  		    set_malign(mon);
139.  		    /* Undo the second peace_minded() check in makemon(); if the
140.  		     * monster turned out to be peaceful the first time we
141.  		     * didn't create it at all; we don't want a second check.
142.  		     */
143.  		}
144.  	}
145.  }
146.  
147.  STATIC_OVL
148.  void
149.  m_initthrow(mtmp,otyp,oquan)
150.  struct monst *mtmp;
151.  int otyp,oquan;
152.  {
153.  	register struct obj *otmp;
154.  
155.  	otmp = mksobj(otyp, TRUE, FALSE);
156.  	otmp->quan = (long) rn1(oquan, 3);
157.  	otmp->owt = weight(otmp);
158.  	if (otyp == ORCISH_ARROW) otmp->opoisoned = TRUE;
159.  	(void) mpickobj(mtmp, otmp);
160.  }
161.  
162.  #endif /* OVLB */
163.  #ifdef OVL2
164.  
165.  STATIC_OVL void
166.  m_initweap_normal(mtmp)
167.  register struct monst *mtmp;
168.  {
169.  	register struct permonst *ptr = mtmp->data;
170.  	int bias;
171.  
172.  	bias = is_lord(ptr) + is_prince(ptr) * 2 + extra_nasty(ptr);
173.  	switch(rnd(14 - (2 * bias))) {
174.  	    case 1:
175.  		if(strongmonst(ptr)) (void) mongets(mtmp, BATTLE_AXE);
176.  		else m_initthrow(mtmp, DART, 12);
177.  		break;
178.  	    case 2:
179.  		if(strongmonst(ptr))
180.  		    (void) mongets(mtmp, TWO_HANDED_SWORD);
181.  		else {
182.  		    (void) mongets(mtmp, CROSSBOW);
183.  		    m_initthrow(mtmp, CROSSBOW_BOLT, 12);
184.  		}
185.  		break;
186.  	    case 3:
187.  		(void) mongets(mtmp, BOW);
188.  		m_initthrow(mtmp, ARROW, 12);
189.  		break;
190.  	    case 4:
191.  		if(strongmonst(ptr)) (void) mongets(mtmp, LONG_SWORD);
192.  		else m_initthrow(mtmp, DAGGER, 3);
193.  		break;
194.  	    case 5:
195.  		if(strongmonst(ptr))
196.  		    (void) mongets(mtmp, LUCERN_HAMMER);
197.  		else (void) mongets(mtmp, AKLYS);
198.  		break;
199.  	    /* [Tom] added some more */
200.  	    case 6:
201.  		if(strongmonst(ptr))
202.  		    (void) mongets(mtmp, AXE);
203.  		else (void) mongets(mtmp, SHORT_SWORD);
204.  		break;
205.  	    case 7:
206.  		if(strongmonst(ptr))
207.  		    (void) mongets(mtmp, MACE);
208.  		else (void) mongets(mtmp, CLUB);
209.  		break;
210.  	    default:
211.  		break;
212.  	}
213.  
214.  	return;
215.  }
216.  
217.  STATIC_OVL void
218.  m_initweap(mtmp)
219.  register struct monst *mtmp;
220.  {
221.  	register struct permonst *ptr = mtmp->data;
222.  	register int mm = monsndx(ptr);
223.  	struct obj *otmp;
224.  
225.  #ifdef REINCARNATION
226.  	if (Is_rogue_level(&u.uz)) return;
227.  #endif
228.  /*
229.   *	first a few special cases:
230.   *
231.   *		giants get a boulder to throw sometimes.
232.   *		ettins get clubs
233.   *		kobolds get darts to throw
234.   *		centaurs get some sort of bow & arrows or bolts
235.   *		soldiers get all sorts of things.
236.   *		kops get clubs & cream pies.
237.   */
238.  	switch (ptr->mlet) {
239.  	    case S_GIANT:
240.  		if (rn2(2)) (void)mongets(mtmp, (mm != PM_ETTIN) ?
241.  				    BOULDER : CLUB);
242.  		break;
243.  	    case S_HUMAN:
244.  		if(is_mercenary(ptr) || mm == PM_SHOPKEEPER
245.  #ifdef YEOMAN
246.  				|| mm == PM_CHIEF_YEOMAN_WARDER || mm == PM_YEOMAN_WARDER
247.  #endif
248.  		) {
249.  		    int w1 = 0, w2 = 0;
250.  		    switch (mm) {
251.  			case PM_SOLDIER:
252.  #ifdef FIREARMS
253.  			  w1 = rn2(2) ? RIFLE : SUBMACHINE_GUN;
254.  		  	  m_initthrow(mtmp, BULLET, 25);
255.  		  	  m_initthrow(mtmp, BULLET, 25);
256.  			  w2 = rn2(2) ? KNIFE : DAGGER;
257.  			  (void) mongets(mtmp, FRAG_GRENADE);
258.  			  break;
259.  #endif
260.  			case PM_WATCHMAN:
261.  			  if (!rn2(3)) {
262.  			      w1 = rn1(BEC_DE_CORBIN - PARTISAN + 1, PARTISAN);
263.  			      w2 = rn2(2) ? DAGGER : KNIFE;
264.  			  } else w1 = rn2(2) ? SPEAR : SHORT_SWORD;
265.  			  break;
266.  			case PM_WATCH_CAPTAIN:
267.  			  w1 = rn2(2) ? LONG_SWORD : SILVER_SABER;
268.  			  break;
269.  			case PM_LIEUTENANT:
270.  #ifdef FIREARMS
271.  			  if (rn2(2)) {
272.  			  	w1 = HEAVY_MACHINE_GUN;
273.  			  	m_initthrow(mtmp, BULLET, 50);
274.  			  	m_initthrow(mtmp, BULLET, 50);
275.  			  	m_initthrow(mtmp, BULLET, 50);
276.  			  } else {
277.  			  	w1 = SUBMACHINE_GUN;
278.  			  	m_initthrow(mtmp, BULLET, 30);
279.  			  	m_initthrow(mtmp, BULLET, 30);
280.  			  }
281.  			  w2 = rn2(2) ? KNIFE : DAGGER;
282.  			  if (rn2(2)) {
283.  			  	(void) mongets(mtmp, FRAG_GRENADE);
284.  			  	(void) mongets(mtmp, FRAG_GRENADE);
285.  			  } else {
286.  			  	(void) mongets(mtmp, GAS_GRENADE);
287.  			  	(void) mongets(mtmp, GAS_GRENADE);
288.  			  }
289.  			  break;
290.  #endif
291.  			case PM_SERGEANT:
292.  #ifdef FIREARMS
293.  			  if (rn2(2)) {
294.  			  	w1 = AUTO_SHOTGUN;
295.  			  	m_initthrow(mtmp, SHOTGUN_SHELL, 10);
296.  			  	m_initthrow(mtmp, SHOTGUN_SHELL, 10);
297.  			  } else {
298.  			  	w1 = ASSAULT_RIFLE;
299.  			  	m_initthrow(mtmp, BULLET, 30);
300.  			  	m_initthrow(mtmp, BULLET, 30);
301.  			  }
302.  			  w2= rn2(2) ? DAGGER : KNIFE;
303.  			  if (rn2(2)) {
304.  			  	m_initthrow(mtmp, FRAG_GRENADE, 5);
305.  			  } else {
306.  			  	m_initthrow(mtmp, GAS_GRENADE, 5);
307.  			  }
308.  			  if (!rn2(5)) (void) mongets(mtmp, GRENADE_LAUNCHER);
309.  			  break;
310.  #endif
311.  #ifdef YEOMAN
312.  			case PM_YEOMAN_WARDER:
313.  #endif
314.  			  w1 = rn2(2) ? FLAIL : MACE;
315.  			  break;
316.  			case PM_CAPTAIN:
317.  #ifdef FIREARMS
318.  			  if (rn2(2)) {
319.  			  	w1 = AUTO_SHOTGUN;
320.  			  	m_initthrow(mtmp, SHOTGUN_SHELL, 20);
321.  			  	m_initthrow(mtmp, SHOTGUN_SHELL, 20);
322.  			  } else if (rn2(2)) {
323.  			  	w1 = HEAVY_MACHINE_GUN;
324.  			  	m_initthrow(mtmp, BULLET, 60);
325.  			  	m_initthrow(mtmp, BULLET, 60);
326.  			  	m_initthrow(mtmp, BULLET, 60);
327.  			  } else {
328.  			  	w1 = ASSAULT_RIFLE;
329.  			  	m_initthrow(mtmp, BULLET, 60);
330.  			  	m_initthrow(mtmp, BULLET, 60);
331.  			  }
332.  			  if (rn2(2)) {
333.  				  w2 = ROCKET_LAUNCHER;
334.  			  	  m_initthrow(mtmp, ROCKET, 5);
335.  			  } else if (rn2(2)) {
336.  				  (void) mongets(mtmp, GRENADE_LAUNCHER);			  
337.  			  	  m_initthrow(mtmp, 
338.  			  	  	(rn2(2) ? FRAG_GRENADE : GAS_GRENADE), 
339.  			  	  	5);
340.  			  } else {
341.  				  w2 = rn2(2) ? SILVER_SABER : DAGGER;
342.  			  }
343.  			  break;
344.  #endif
345.  #ifdef YEOMAN
346.  			case PM_CHIEF_YEOMAN_WARDER:
347.  #endif
348.  			  w1 = rn2(2) ? BROADSWORD : LONG_SWORD;
349.  			  break;
350.  			case PM_SHOPKEEPER:
351.  #ifdef FIREARMS
352.  			  (void) mongets(mtmp,SHOTGUN);
353.  			  m_initthrow(mtmp, SHOTGUN_SHELL, 20);
354.  			  m_initthrow(mtmp, SHOTGUN_SHELL, 20);
355.  			  m_initthrow(mtmp, SHOTGUN_SHELL, 20);
356.  #endif
357.  			  /* Fallthrough */
358.  			default:
359.  			  if (!rn2(4)) w1 = DAGGER;
360.  			  if (!rn2(7)) w2 = SPEAR;
361.  			  break;
362.  		    }
363.  		    if (w1) (void)mongets(mtmp, w1);
364.  		    if (!w2 && w1 != DAGGER && !rn2(4)) w2 = KNIFE;
365.  		    if (w2) (void)mongets(mtmp, w2);
366.  		} else if (is_elf(ptr)) {
367.  		    if (mm == PM_DROW) {
368.  			(void) mongets(mtmp, DARK_ELVEN_MITHRIL_COAT);
369.  			(void) mongets(mtmp, DARK_ELVEN_SHORT_SWORD);
370.  			(void) mongets(mtmp, DARK_ELVEN_BOW);
371.  			m_initthrow(mtmp, DARK_ELVEN_ARROW, 12);
372.  		    } else {
373.  		    if (rn2(2))
374.  			(void) mongets(mtmp,
375.  				   !rn2(4) ? ELVEN_MITHRIL_COAT : ELVEN_CLOAK);
376.  		      if (!rn2(3)) (void)mongets(mtmp, ELVEN_LEATHER_HELM);
377.  		    else if (!rn2(4)) (void)mongets(mtmp, ELVEN_BOOTS);
378.  		      if (!rn2(3)) (void)mongets(mtmp, ELVEN_DAGGER);
379.  		    switch (rn2(3)) {
380.  			case 0:
381.  			    if (!rn2(4)) (void)mongets(mtmp, ELVEN_SHIELD);
382.  			    if (rn2(3)) (void)mongets(mtmp, ELVEN_SHORT_SWORD);
383.  			    (void)mongets(mtmp, ELVEN_BOW);
384.  			    m_initthrow(mtmp, ELVEN_ARROW, 12);
385.  			    break;
386.  			case 1:
387.  			    (void)mongets(mtmp, ELVEN_BROADSWORD);
388.  			    if (rn2(2)) (void)mongets(mtmp, ELVEN_SHIELD);
389.  			    break;
390.  			case 2:
391.  			    if (rn2(2)) {
392.  				(void)mongets(mtmp, ELVEN_SPEAR);
393.  				(void)mongets(mtmp, ELVEN_SHIELD);
394.  			    }
395.  			    break;
396.  		    }
397.  		    if (mm == PM_ELVENKING) {
398.  			if (rn2(3) || (in_mklev && Is_earthlevel(&u.uz)))
399.  			    (void)mongets(mtmp, PICK_AXE);
400.  			if (!rn2(50)) (void)mongets(mtmp, CRYSTAL_BALL);
401.  		    }
402.  		    } /* normal elves */                
403.  		} else /* enemy characters! */
404.  		 if (mm >= PM_ARCHEOLOGIST && mm <= PM_WIZARD && rn2(4)) {
405.  		  switch (mm) {
406.  		   case PM_ARCHEOLOGIST:
407.  		     (void)mongets(mtmp, BULLWHIP);
408.  		     (void)mongets(mtmp, LEATHER_JACKET);
409.  		     (void)mongets(mtmp, FEDORA);
410.  		     if (rn2(2)) (void)mongets(mtmp, PICK_AXE);
411.  #ifndef GOLDOBJ
412.  		     mtmp->mgold = (long) d(mtmp->m_lev, 15);
413.  #else
414.  		     mkmonmoney(mtmp, (long) d(mtmp->m_lev, 15));
415.  #endif
416.  		   break;
417.  		   case PM_BARBARIAN:
418.  		     (void)mongets(mtmp, BATTLE_AXE);
419.  		     if (!rn2(2)) (void)mongets(mtmp, TWO_HANDED_SWORD);
420.  		     (void)mongets(mtmp, RING_MAIL);
421.  #ifndef GOLDOBJ
422.  		     mtmp->mgold = (long) d(mtmp->m_lev, 15);
423.  #else
424.  		     mkmonmoney(mtmp, (long) d(mtmp->m_lev, 15));
425.  #endif
426.  		   break;
427.  		   case PM_CAVEMAN: case PM_CAVEWOMAN:
428.  		     (void)mongets(mtmp, CLUB);
429.  		     if (rn2(3)) {
430.  			(void)mongets(mtmp, BOW);
431.  			 m_initthrow(mtmp, ARROW, 18);
432.  		     }
433.  		     (void)mongets(mtmp, LEATHER_ARMOR);
434.  #ifndef GOLDOBJ
435.  		     mtmp->mgold = (long) d(mtmp->m_lev, 15);
436.  #else
437.  		     mkmonmoney(mtmp, (long) d(mtmp->m_lev, 15));
438.  #endif
439.  		   break;
440.  		   case PM_DOPPELGANGER:
441.  		     (void)mongets(mtmp, SILVER_DAGGER);
442.  #ifndef GOLDOBJ
443.  		     mtmp->mgold = (long) d(mtmp->m_lev, 15);
444.  #else
445.  		     mkmonmoney(mtmp, (long) d(mtmp->m_lev, 15));
446.  #endif
447.  		   break;
448.  		   case PM_ELF:
449.  		     /* gets taken care of later... */
450.  		     /*(void)mongets(mtmp, ELVEN_SHORT_SWORD);
451.  		     if (rn2(3)) {
452.  			(void)mongets(mtmp, ELVEN_BOW);
453.  			 m_initthrow(mtmp, ELVEN_ARROW, 18);
454.  		     }
455.  		     if (rn2(3)) (void)mongets(mtmp, ELVEN_CLOAK);
456.  		     else (void)mongets(mtmp, ELVEN_MITHRIL_COAT);*/
457.  #ifndef GOLDOBJ
458.  		     mtmp->mgold = (long) d(mtmp->m_lev, 15);
459.  #else
460.  		     mkmonmoney(mtmp, (long) d(mtmp->m_lev, 15));
461.  #endif
462.  		   break;
463.  		   case PM_FLAME_MAGE:
464.  		     (void)mongets(mtmp, QUARTERSTAFF);
465.  		     (void)mongets(mtmp, STUDDED_LEATHER_ARMOR);
466.  		     (void)mongets(mtmp, WAN_FIRE);
467.  #ifndef GOLDOBJ
468.  		     mtmp->mgold = (long) d(mtmp->m_lev, 15);
469.  #else
470.  		     mkmonmoney(mtmp, (long) d(mtmp->m_lev, 15));
471.  #endif
472.  		   break;
473.  		   case PM_HEALER:
474.  		     (void)mongets(mtmp, SCALPEL);
475.  		     (void)mongets(mtmp, LEATHER_GLOVES);
476.  		     (void)mongets(mtmp, WAN_HEALING);
477.  		     (void)mongets(mtmp, WAN_SLEEP);
478.  #ifndef GOLDOBJ
479.  		     mtmp->mgold = (long) d(mtmp->m_lev, 20);
480.  #else
481.  		     mkmonmoney(mtmp, (long) d(mtmp->m_lev, 20));
482.  #endif
483.  		   break;
484.  		   case PM_ICE_MAGE:
485.  		     (void)mongets(mtmp, QUARTERSTAFF);
486.  		     (void)mongets(mtmp, STUDDED_LEATHER_ARMOR);
487.  		     (void)mongets(mtmp, WAN_COLD);
488.  #ifndef GOLDOBJ
489.  		     mtmp->mgold = (long) d(mtmp->m_lev, 15);
490.  #else
491.  		     mkmonmoney(mtmp, (long) d(mtmp->m_lev, 15));
492.  #endif
493.  		   break;
494.  #ifdef YEOMAN
495.  		   case PM_YEOMAN:
496.  #endif
497.  		   case PM_KNIGHT:
498.  		     (void)mongets(mtmp, LONG_SWORD);
499.  		     (void)mongets(mtmp, PLATE_MAIL);
500.  		     (void)mongets(mtmp, LARGE_SHIELD);
501.  		     (void)mongets(mtmp, HELMET);
502.  		     (void)mongets(mtmp, LEATHER_GLOVES);
503.  #ifndef GOLDOBJ
504.  		     mtmp->mgold = (long) d(mtmp->m_lev, 15);
505.  #else
506.  		     mkmonmoney(mtmp, (long) d(mtmp->m_lev, 15));
507.  #endif
508.  		     break;
509.  		   case PM_MONK:
510.  #ifndef GOLDOBJ
511.  		     mtmp->mgold = (long) d(mtmp->m_lev, 5);
512.  #else
513.  		     mkmonmoney(mtmp, (long) d(mtmp->m_lev, 5));
514.  #endif
515.  		   break;
516.  		   case PM_NECROMANCER:
517.  		     (void)mongets(mtmp, ATHAME);
518.  		     if (!rn2(4)) (void)mongets(mtmp, PICK_AXE);
519.  		     (void) mongets(mtmp, rnd_offensive_item(mtmp));
520.  		     (void) mongets(mtmp, rnd_defensive_item(mtmp));
521.  #ifndef GOLDOBJ
522.  		     mtmp->mgold = (long) d(mtmp->m_lev, 15);
523.  #else
524.  		     mkmonmoney(mtmp, (long) d(mtmp->m_lev, 15));
525.  #endif
526.  		   break;
527.  		   case PM_PRIEST:
528.  		   case PM_PRIESTESS:
529.  		     (void)mongets(mtmp, MACE);
530.  		     (void)mongets(mtmp, rn1(ROBE_OF_WEAKNESS - ROBE + 1, ROBE));
531.  		     (void)mongets(mtmp, SMALL_SHIELD);
532.  		     if (!rn2(4)) {
533.  			int v,vials;
534.  			vials = rn2(4)+1;
535.  			for (v=0;v<vials;v++) {
536.  			  otmp = mksobj(POT_WATER, FALSE, FALSE);
537.  			  bless(otmp);
538.  			  mpickobj(mtmp, otmp);
539.  			}
540.  		     }
541.  #ifndef GOLDOBJ
542.  		     mtmp->mgold = (long) d(mtmp->m_lev, 15);
543.  #else
544.  		     mkmonmoney(mtmp, (long) d(mtmp->m_lev, 15));
545.  #endif
546.  		   break;
547.  		   case PM_ROGUE:
548.  		     (void)mongets(mtmp, SHORT_SWORD);
549.  		     (void)mongets(mtmp, LEATHER_ARMOR);
550.  #ifndef GOLDOBJ
551.  		     mtmp->mgold = (long) d(mtmp->m_lev, 25);
552.  #else
553.  		     mkmonmoney(mtmp, (long) d(mtmp->m_lev, 25));
554.  #endif
555.  		   break;
556.  		   case PM_SAMURAI:
557.  		     (void)mongets(mtmp, KATANA);
558.  		     if (rn2(2)) (void)mongets(mtmp, SHORT_SWORD);
559.  		     if (rn2(3)) {
560.  			(void)mongets(mtmp, YUMI);
561.  			m_initthrow(mtmp, YA, 18);
562.  		     }
563.  		     (void)mongets(mtmp, SPLINT_MAIL);
564.  #ifndef GOLDOBJ
565.  		     mtmp->mgold = (long) d(mtmp->m_lev, 15);
566.  #else
567.  		     mkmonmoney(mtmp, (long) d(mtmp->m_lev, 15));
568.  #endif
569.  		   break;
570.  #ifdef TOURIST
571.  		   case PM_TOURIST:
572.  		     m_initthrow(mtmp, DART, 18);
573.  		     (void)mongets(mtmp, HAWAIIAN_SHIRT);
574.  		     if (rn2(2)) (void)mongets(mtmp, EXPENSIVE_CAMERA);
575.  #ifndef GOLDOBJ
576.  		     mtmp->mgold = (long) d(mtmp->m_lev, 20);
577.  #else
578.  		     mkmonmoney(mtmp, (long) d(mtmp->m_lev, 20));
579.  #endif
580.  		   break;
581.  #endif
582.  		   case PM_UNDEAD_SLAYER:
583.  		     (void)mongets(mtmp, SILVER_SPEAR);
584.  		     (void)mongets(mtmp, CHAIN_MAIL);
585.  #ifndef GOLDOBJ
586.  		     mtmp->mgold = (long) d(mtmp->m_lev, 15);
587.  #else
588.  		     mkmonmoney(mtmp, (long) d(mtmp->m_lev, 15));
589.  #endif
590.  		   break;
591.  		   case PM_VALKYRIE:
592.  		     (void)mongets(mtmp, LONG_SWORD);
593.  		     if (!rn2(3)) m_initthrow(mtmp, DAGGER, 4);
594.  		     (void)mongets(mtmp, SMALL_SHIELD);
595.  #ifndef GOLDOBJ
596.  		     mtmp->mgold = (long) d(mtmp->m_lev, 15);
597.  #else
598.  		     mkmonmoney(mtmp, (long) d(mtmp->m_lev, 15));
599.  #endif
600.  		   break;
601.  		   case PM_WIZARD:
602.  		     (void)mongets(mtmp, ATHAME);
603.  		     (void) mongets(mtmp, rnd_offensive_item(mtmp));
604.  		     (void) mongets(mtmp, rnd_offensive_item(mtmp));
605.  		     (void) mongets(mtmp, rnd_defensive_item(mtmp));
606.  #ifndef GOLDOBJ
607.  		     mtmp->mgold = (long) d(mtmp->m_lev, 15);
608.  #else
609.  		     mkmonmoney(mtmp, (long) d(mtmp->m_lev, 15));
610.  #endif
611.  		   break;
612.  		   default:
613.  		   break;
614.  		  } 
615.  		  if ((int) mtmp->m_lev > rn2(40))
616.  		     (void) mongets(mtmp, rnd_offensive_item(mtmp));
617.  		  if ((int) mtmp->m_lev > rn2(40))
618.  		     (void) mongets(mtmp, rnd_offensive_item(mtmp));
619.  		  if ((int) mtmp->m_lev > rn2(40))
620.  		     (void) mongets(mtmp, rnd_defensive_item(mtmp));
621.  		  if ((int) mtmp->m_lev > rn2(40))
622.  		     (void) mongets(mtmp, rnd_defensive_item(mtmp));
623.  		  if ((int) mtmp->m_lev > rn2(40))
624.  		     (void) mongets(mtmp, rnd_misc_item(mtmp));
625.  		  if ((int) mtmp->m_lev > rn2(40))
626.  		     (void) mongets(mtmp, rnd_misc_item(mtmp));
627.  		 } /* end of other characters */
628.  	       /*break;*/
629.  		else if (ptr->msound == MS_PRIEST ||
630.  			quest_mon_represents_role(ptr,PM_PRIEST)) {
631.  		    otmp = mksobj(MACE, FALSE, FALSE);
632.  		    if(otmp) {
633.  			otmp->spe = rnd(3);
634.  			if(!rn2(2)) curse(otmp);
635.  			(void) mpickobj(mtmp, otmp);
636.  		    }
637.  
638.  		    /* MRKR: Dwarves in the Mines sometimes carry torches */
639.  
640.  		    if (In_mines(&u.uz)) {
641.  		      if (!rn2(4)) {	
642.  			otmp = mksobj(TORCH, TRUE, FALSE);
643.  			otmp->quan = 1;
644.  			(void) mpickobj(mtmp, otmp);
645.  
646.  			/* If this spot is unlit, light the torch */
647.  
648.  			if (!levl[mtmp->mx][mtmp->my].lit) {
649.  			  begin_burn(otmp, FALSE);
650.  			}		      
651.  		      }
652.  		    }
653.  		}
654.  		break;
655.  
656.  	    case S_ANGEL:
657.  		{
658.  		    int spe2;
659.  
660.  		    /* create minion stuff; can't use mongets */
661.  		    otmp = mksobj(LONG_SWORD, FALSE, FALSE);
662.  
663.  		    /* maybe make it special */
664.  		    if (!rn2(20) || is_lord(ptr))
665.  			otmp = oname(otmp, artiname(
666.  				rn2(2) ? ART_DEMONBANE : ART_SUNSWORD));
667.  		    bless(otmp);
668.  		    otmp->oerodeproof = TRUE;
669.  		    spe2 = rn2(4);
670.  		    otmp->spe = max(otmp->spe, spe2);
671.  		    (void) mpickobj(mtmp, otmp);
672.  
673.  		    otmp = mksobj(!rn2(4) || is_lord(ptr) ?
674.  				  SHIELD_OF_REFLECTION : LARGE_SHIELD,
675.  				  FALSE, FALSE);
676.  		    otmp->cursed = FALSE;
677.  		    otmp->oerodeproof = TRUE;
678.  		    otmp->spe = 0;
679.  		    (void) mpickobj(mtmp, otmp);
680.  		}
681.  		break;
682.  	    case S_GNOME:
683.  		switch (mm) {
684.  		    case PM_GNOLL:
685.  			if(!rn2(3)) (void) mongets(mtmp, ORCISH_HELM);
686.  			if(!rn2(3)) (void) mongets(mtmp, STUDDED_LEATHER_ARMOR);
687.  			if(!rn2(3)) (void) mongets(mtmp, ORCISH_SHIELD);
688.  			if(!rn2(4)) (void) mongets(mtmp, SPEAR);
689.  			break;
690.  
691.  		    case PM_GNOLL_WARRIOR:
692.  			if(!rn2(2)) (void) mongets(mtmp, ORCISH_HELM);
693.  
694.  			if (!rn2(20))
695.  			    (void) mongets(mtmp, ORANGE_DRAGON_SCALE_MAIL);
696.  			else if (rn2(3))
697.  			    (void) mongets(mtmp, SCALE_MAIL);
698.  			else
699.  			    (void) mongets(mtmp, SPLINT_MAIL);
700.  
701.  			if(!rn2(2)) (void) mongets(mtmp, ORCISH_SHIELD);
702.  			if(!rn2(3)) (void) mongets(mtmp, KATANA);
703.  			break;
704.  
705.  		    case PM_GNOLL_CHIEFTAIN:
706.  			(void) mongets(mtmp, ORCISH_HELM);
707.  
708.  			if (!rn2(10))
709.  			    (void) mongets(mtmp, BLUE_DRAGON_SCALE_MAIL);
710.  			else
711.  			    (void) mongets(mtmp, CRYSTAL_PLATE_MAIL);
712.  
713.  			(void) mongets(mtmp, ORCISH_SHIELD);
714.  			(void) mongets(mtmp, KATANA);
715.  			(void) mongets(mtmp, rnd_offensive_item(mtmp));
716.  			break;
717.  
718.  		    case PM_GNOLL_SHAMAN:
719.  			if (!rn2(10))
720.  			    (void) mongets(mtmp, SILVER_DRAGON_SCALE_MAIL);
721.  			else if (rn2(5))
722.  			    (void) mongets(mtmp, CRYSTAL_PLATE_MAIL);
723.  			else
724.  			    (void) mongets(mtmp, RED_DRAGON_SCALE_MAIL);
725.  
726.  			(void) mongets(mtmp, ATHAME);
727.  			m_initthrow(mtmp, SHURIKEN, 12);
728.  			(void) mongets(mtmp, rnd_offensive_item(mtmp));
729.  			(void) mongets(mtmp, rnd_offensive_item(mtmp));
730.  			break;
731.  
732.  		    default:
733.  			m_initweap_normal(mtmp);
734.  			break;
735.  		}	
736.  		break;
737.  	    case S_HUMANOID:
738.  		if (is_dwarf(ptr)) {
739.  		    if (rn2(7)) (void)mongets(mtmp, DWARVISH_CLOAK);
740.  		    if (rn2(7)) (void)mongets(mtmp, IRON_SHOES);
741.  		    if (!rn2(4)) {
742.  			(void)mongets(mtmp, DWARVISH_SHORT_SWORD);
743.  			/* note: you can't use a mattock with a shield */
744.  			if (rn2(2)) (void)mongets(mtmp, DWARVISH_MATTOCK);
745.  			else {
746.  				(void)mongets(mtmp, AXE);
747.  				(void)mongets(mtmp, DWARVISH_ROUNDSHIELD);
748.  			}
749.  			(void)mongets(mtmp, DWARVISH_IRON_HELM);
750.  			if (!rn2(4))
751.  			    (void)mongets(mtmp, DWARVISH_MITHRIL_COAT);
752.  		    } else {
753.  			(void)mongets(mtmp, !rn2(3) ? PICK_AXE : DAGGER);
754.  		    }
755.  		} else if (is_hobbit(ptr)) {
756.  			    switch (rn2(3)) {
757.  			        case 0:
758.  				    (void)mongets(mtmp, DAGGER);
759.  				    break;
760.  				case 1:
761.  				    (void)mongets(mtmp, ELVEN_DAGGER);
762.  				    break;
763.  				case 2:
764.  			            (void)mongets(mtmp, SLING);
765.  			            /* WAC give them some rocks to throw */
766.  			            m_initthrow(mtmp, ROCK, 2); 
767.  						break;
768.  			      }
769.  				/* WAC add 50% chance of leather */
770.  			    if (!rn2(10)) (void)mongets(mtmp, ELVEN_MITHRIL_COAT);
771.  				else if (!rn2(2)) (void)mongets(mtmp, LEATHER_ARMOR);
772.  				if (!rn2(10)) (void)mongets(mtmp, DWARVISH_CLOAK);
773.  		} else switch(mm) {
774.            /* Mind flayers get robes */
775.            case PM_MIND_FLAYER:
776.              if (!rn2(2)) (void)mongets(mtmp, ROBE);
777.              break;
778.            case PM_MASTER_MIND_FLAYER:
779.              if (!rn2(10)) (void)mongets(mtmp, ROBE_OF_PROTECTION);
780.  			else if (!rn2(10)) (void)mongets(mtmp, ROBE_OF_POWER);
781.  			else (void)mongets(mtmp, ROBE);
782.              break;
783.  		  case PM_GNOLL:
784.  			if (!rn2(2)) switch (rn2(3)) {
785.  				case 0: (void)mongets(mtmp, BARDICHE); break;
786.  				case 1: (void)mongets(mtmp, VOULGE); break;
787.  				case 2: (void)mongets(mtmp, HALBERD); break;
788.  			}
789.  			if (!rn2(2)) (void)mongets(mtmp, LEATHER_ARMOR);
790.  			break;
791.            default:
792.  	          break;                     
793.  		}
794.  		break;
795.  # ifdef KOPS
796.  	    case S_KOP:		/* create Keystone Kops with cream pies to
797.  				 * throw. As suggested by KAA.	   [MRS]
798.  				 */
799.  		if (!rn2(4)) m_initthrow(mtmp, CREAM_PIE, 2);
800.  		if (!rn2(3)) (void)mongets(mtmp,(rn2(2)) ? CLUB : RUBBER_HOSE);
801.  		break;
802.  # endif
803.  	    case S_ORC:
804.                  /* All orcs will get at least an orcish dagger*/
805.  		if(rn2(2)) (void)mongets(mtmp, ORCISH_HELM);
806.  		switch (mm != PM_ORC_CAPTAIN ? mm :
807.  			rn2(2) ? PM_MORDOR_ORC : PM_URUK_HAI) {
808.  		    case PM_MORDOR_ORC:
809.  			if(!rn2(3)) (void)mongets(mtmp, SCIMITAR);
810.                              else (void)mongets(mtmp, ORCISH_DAGGER);
811.  			if(!rn2(3)) (void)mongets(mtmp, ORCISH_SHIELD);
812.  			if(!rn2(3)) (void)mongets(mtmp, KNIFE);
813.                          /* WAC add possible orcish spear */
814.                          if (!rn2(4)) m_initthrow(mtmp, ORCISH_SPEAR, 1);
815.  			if(!rn2(3)) (void)mongets(mtmp, KNIFE);
816.  			if(!rn2(3)) (void)mongets(mtmp, ORCISH_CHAIN_MAIL);
817.  			break;
818.  		    case PM_URUK_HAI:
819.  			if(!rn2(3)) (void)mongets(mtmp, ORCISH_CLOAK);
820.  			if(!rn2(3)) (void)mongets(mtmp, ORCISH_SHORT_SWORD);
821.                              else (void)mongets(mtmp, ORCISH_DAGGER);
822.  			if(!rn2(3)) (void)mongets(mtmp, IRON_SHOES);
823.  			if(!rn2(3)) {
824.  			    (void)mongets(mtmp, ORCISH_BOW);
825.  			    m_initthrow(mtmp, ORCISH_ARROW, 12);
826.  			}
827.  			if(!rn2(3)) (void)mongets(mtmp, URUK_HAI_SHIELD);
828.  			break;
829.                      case PM_GOBLIN:
830.                          if(!rn2(3)) (void)mongets(mtmp, ORCISH_SHORT_SWORD);
831.                              else (void)mongets(mtmp, ORCISH_DAGGER);
832.  			break;
833.                      case PM_HOBGOBLIN:
834.                          if(!rn2(3)) (void)mongets(mtmp, MORNING_STAR);
835.                              else if(!rn2(3)) (void)mongets(mtmp, ORCISH_SHORT_SWORD);
836.                              else (void)mongets(mtmp, ORCISH_DAGGER);
837.  			break;
838.  		    default:
839.  			if (mm != PM_ORC_SHAMAN && rn2(2))
840.  /*                          (void)mongets(mtmp, (mm == PM_GOBLIN || rn2(2) == 0)*/
841.                            (void)mongets(mtmp, (rn2(2) == 0)
842.  						   ? ORCISH_DAGGER : SCIMITAR);
843.  		}
844.  		break;
845.  	    case S_OGRE:
846.  		if (!rn2(mm == PM_OGRE_KING ? 3 : mm == PM_OGRE_LORD ? 6 : 12))
847.  		    (void) mongets(mtmp, BATTLE_AXE);
848.  		else
849.  		    (void) mongets(mtmp, CLUB);
850.  		break;
851.  	    case S_KOBOLD:
852.                  /* WAC gets orcish 1:4, otherwise darts
853.                          (used to be darts 1:4)
854.                     gets orcish short sword 1:4, otherwise orcish dagger */
855.                  if (!rn2(4)) m_initthrow(mtmp, ORCISH_SPEAR, 1);
856.                     else m_initthrow(mtmp, DART, 12);
857.                  if (!rn2(4)) mongets(mtmp, ORCISH_SHORT_SWORD);
858.                     else mongets(mtmp, ORCISH_DAGGER);
859.  		break;
860.  
861.  	    case S_CENTAUR:
862.  		if (rn2(2)) {
863.  		    if(ptr == &mons[PM_FOREST_CENTAUR]) {
864.  			(void)mongets(mtmp, BOW);
865.  			m_initthrow(mtmp, ARROW, 12);
866.  		    } else {
867.  			(void)mongets(mtmp, CROSSBOW);
868.  			m_initthrow(mtmp, CROSSBOW_BOLT, 12);
869.  		    }
870.  		}
871.  		break;
872.  	    case S_WRAITH:
873.  		(void)mongets(mtmp, KNIFE);
874.  		(void)mongets(mtmp, LONG_SWORD);
875.  		break;
876.  	    case S_ZOMBIE:
877.  		if (!rn2(4)) (void)mongets(mtmp, LEATHER_ARMOR);
878.  		if (!rn2(4))
879.  			(void)mongets(mtmp, (rn2(3) ? KNIFE : SHORT_SWORD));
880.  		break;
881.  	    case S_LIZARD:
882.  		if (mm == PM_SALAMANDER)
883.  			(void)mongets(mtmp, (rn2(7) ? SPEAR : rn2(3) ?
884.  					     TRIDENT : STILETTO));
885.  		break;
886.  	    case S_TROLL:
887.  		if (!rn2(2)) switch (rn2(4)) {
888.  		    case 0: (void)mongets(mtmp, RANSEUR); break;
889.  		    case 1: (void)mongets(mtmp, PARTISAN); break;
890.  		    case 2: (void)mongets(mtmp, GLAIVE); break;
891.  		    case 3: (void)mongets(mtmp, SPETUM); break;
892.  		}
893.  		break;
894.  	    case S_DEMON:
895.  		switch (mm) {
896.  		    case PM_BALROG:
897.  			(void)mongets(mtmp, BULLWHIP);
898.  			(void)mongets(mtmp, BROADSWORD);
899.  			break;
900.  		    case PM_ORCUS:
901.  			(void)mongets(mtmp, WAN_DEATH); /* the Wand of Orcus */
902.  			break;
903.  		    case PM_HORNED_DEVIL:
904.  			(void)mongets(mtmp, rn2(4) ? TRIDENT : BULLWHIP);
905.  			break;
906.  		    case PM_DISPATER:
907.  			(void)mongets(mtmp, WAN_STRIKING);
908.  			break;
909.  		    case PM_YEENOGHU:
910.  			(void)mongets(mtmp, FLAIL);
911.  			break;
912.  		}
913.  		/* prevent djinnis and mail daemons from leaving objects when
914.  		 * they vanish
915.  		 */
916.  		if (!is_demon(ptr)) break;
917.  		/* fall thru */
918.  /*
919.   *	Now the general case, Some chance of getting some type
920.   *	of weapon for "normal" monsters.  Certain special types
921.   *	of monsters will get a bonus chance or different selections.
922.   */
923.  	    default:
924.  	      m_initweap_normal(mtmp);
925.  	      break;
926.  	}
927.  /*    if ((int) mtmp->m_lev > rn2(120)) */        
928.        if ((int) mtmp->m_lev > rn2(200))
929.  		(void) mongets(mtmp, rnd_offensive_item(mtmp));
930.  }
931.  
932.  #endif /* OVL2 */
933.  #ifdef OVL1
934.  
935.  #ifdef GOLDOBJ
936.  /*
937.   *   Makes up money for monster's inventory.
938.   *   This will change with silver & copper coins
939.   */
940.  void 
941.  mkmonmoney(mtmp, amount)
942.  struct monst *mtmp;
943.  long amount;
944.  {
945.      struct obj *gold = mksobj(GOLD_PIECE, FALSE, FALSE);
946.      gold->quan = amount;
947.      add_to_minv(mtmp, gold);
948.  }
949.  #endif
950.  
951.  STATIC_OVL void
952.  m_initinv(mtmp)
953.  register struct	monst	*mtmp;
954.  {
955.  	register int cnt;
956.  	register struct obj *otmp;
957.  	register struct permonst *ptr = mtmp->data;
958.  /* 	char *opera_cloak = "opera cloak";*/
959.  	int i;
960.  
961.  #ifdef REINCARNATION
962.  	if (Is_rogue_level(&u.uz)) return;
963.  #endif
964.  
965.  /*
966.   *	Soldiers get armour & rations - armour approximates their ac.
967.   *	Nymphs may get mirror or potion of object detection.
968.   */
969.  	switch(ptr->mlet) {
970.  	    case S_HUMAN:
971.  		if(is_mercenary(ptr)
972.  #ifdef YEOMAN
973.  				|| ptr == &mons[PM_CHIEF_YEOMAN_WARDER]
974.  				|| ptr == &mons[PM_YEOMAN_WARDER]
975.  #endif
976.  		) {
977.  		    register int mac;
978.  
979.  		    switch(monsndx(ptr)) {
980.  			case PM_GUARD: mac = -1; break;
981.  			case PM_SOLDIER: mac = 3; break;
982.  			case PM_SERGEANT: mac = 0; break;
983.  			case PM_LIEUTENANT: mac = -2; break;
984.  			case PM_CAPTAIN: mac = -3; break;
985.  #ifdef YEOMAN
986.  			case PM_YEOMAN_WARDER:
987.  #endif
988.  			case PM_WATCHMAN: mac = 3; break;
989.  #ifdef YEOMAN
990.  			case PM_CHIEF_YEOMAN_WARDER:
991.  				mongets(mtmp, TALLOW_CANDLE);
992.  #endif
993.  			case PM_WATCH_CAPTAIN: mac = -2; break;
994.  			default: impossible("odd mercenary %d?", monsndx(ptr));
995.  				mac = 0;
996.  				break;
997.  		    }
998.  
999.  		    if (mac < -1 && rn2(5))
1000. 			mac += 7 + mongets(mtmp, (rn2(5)) ?
1001. 					   PLATE_MAIL : CRYSTAL_PLATE_MAIL);
1002. 		    else if (mac < 3 && rn2(5))
1003. 			mac += 6 + mongets(mtmp, (rn2(3)) ?
1004. 					   SPLINT_MAIL : BANDED_MAIL);
1005. 		    else if (rn2(5))
1006. 			mac += 3 + mongets(mtmp, (rn2(3)) ?
1007. 					   RING_MAIL : STUDDED_LEATHER_ARMOR);
1008. 		    else
1009. 			mac += 2 + mongets(mtmp, LEATHER_ARMOR);
1010. 
1011. 		    if (mac < 10 && rn2(3))
1012. 			mac += 1 + mongets(mtmp, HELMET);
1013. 		    else if (mac < 10 && rn2(2))
1014. 			mac += 1 + mongets(mtmp, DENTED_POT);
1015. 		    if (mac < 10 && rn2(3))
1016. 			mac += 1 + mongets(mtmp, SMALL_SHIELD);
1017. 		    else if (mac < 10 && rn2(2))
1018. 			mac += 2 + mongets(mtmp, LARGE_SHIELD);
1019. 		    if (mac < 10 && rn2(3))
1020. 			mac += 1 + mongets(mtmp, LOW_BOOTS);
1021. 		    else if (mac < 10 && rn2(2))
1022. 			mac += 2 + mongets(mtmp, HIGH_BOOTS);
1023. 		    if (mac < 10 && rn2(3))
1024. 			mac += 1 + mongets(mtmp, LEATHER_GLOVES);
1025. 		    else if (mac < 10 && rn2(2))
1026. 			mac += 1 + mongets(mtmp, LEATHER_CLOAK);
1027. 
1028. 		    if(ptr != &mons[PM_GUARD] &&
1029. 			ptr != &mons[PM_WATCHMAN] &&
1030. 			ptr != &mons[PM_WATCH_CAPTAIN]) {
1031. 			if (!rn2(3)) (void) mongets(mtmp, K_RATION);
1032. 			if (!rn2(2)) (void) mongets(mtmp, C_RATION);
1033. 			if (ptr != &mons[PM_SOLDIER] && !rn2(3))
1034. 				(void) mongets(mtmp, BUGLE);
1035. 		    } else
1036. 			   if (ptr == &mons[PM_WATCHMAN] && rn2(3))
1037. 				(void) mongets(mtmp, TIN_WHISTLE);
1038. 		} else if (ptr == &mons[PM_SHOPKEEPER]) {
1039. 		    (void) mongets(mtmp,SKELETON_KEY);
1040. 		    /* STEPHEN WHITE'S NEW CODE                
1041. 		     *
1042. 		     * "Were here to pump *clap* YOU up!"  -Hans and Frans
1043. 		     *                                      Saterday Night Live
1044. 		     */
1045. #ifndef FIREARMS
1046. 		    switch (rn2(4)) {
1047. 		    /* MAJOR fall through ... */
1048. 		    case 0: (void) mongets(mtmp, WAN_MAGIC_MISSILE);
1049. 		    case 1: (void) mongets(mtmp, POT_EXTRA_HEALING);
1050. 		    case 2: (void) mongets(mtmp, POT_HEALING);
1051. 		    case 3: (void) mongets(mtmp, WAN_STRIKING);
1052. 		    }
1053. #endif
1054. 		    switch (rnd(4)) {
1055. 			/* MAJOR fall through ... */
1056. 			case 1: (void) mongets(mtmp,POT_HEALING);
1057. 			case 2: (void) mongets(mtmp,POT_EXTRA_HEALING);
1058. 			case 3: (void) mongets(mtmp,SCR_TELEPORTATION);
1059. 			case 4: (void) mongets(mtmp,WAN_TELEPORTATION);
1060. 			default:
1061. 				break;
1062. 		    }
1063. 		} else if (ptr->msound == MS_PRIEST ||
1064. 			quest_mon_represents_role(ptr,PM_PRIEST)) {
1065. 		    (void) mongets(mtmp,
1066. 			    rn2(7) ? rn1(ROBE_OF_WEAKNESS - ROBE + 1, ROBE) :
1067. 					     rn2(3) ? CLOAK_OF_PROTECTION :
1068. 						 CLOAK_OF_MAGIC_RESISTANCE);
1069. 		    (void) mongets(mtmp, SMALL_SHIELD);
1070. #ifndef GOLDOBJ
1071. 		    mtmp->mgold = (long)rn1(10,20);
1072. #else
1073. 		    mkmonmoney(mtmp,(long)rn1(10,20));
1074. #endif
1075. 		} else if (quest_mon_represents_role(ptr,PM_MONK)) {
1076. 		    (void) mongets(mtmp, rn2(11) ? ROBE :
1077. 					     CLOAK_OF_MAGIC_RESISTANCE);
1078. 		}
1079. 		break;
1080. 	    case S_NYMPH:
1081. 		if(!rn2(2)) (void) mongets(mtmp, MIRROR);
1082. 		if(!rn2(2)) (void) mongets(mtmp, POT_OBJECT_DETECTION);
1083. 		break;
1084. 	    case S_GIANT:
1085. 		if (ptr == &mons[PM_MINOTAUR]) {
1086. 		    if (!rn2(3) || (in_mklev && Is_earthlevel(&u.uz)))
1087. 			(void) mongets(mtmp, WAN_DIGGING);
1088. 		} else if (is_giant(ptr)) {
1089. 		    for (cnt = rn2((int)(mtmp->m_lev / 2)); cnt; cnt--) {
1090. 			otmp = mksobj(rnd_class(DILITHIUM_CRYSTAL,LUCKSTONE-1),
1091. 				      FALSE, FALSE);
1092. 			otmp->quan = (long) rn1(2, 3);
1093. 			otmp->owt = weight(otmp);
1094. 			(void) mpickobj(mtmp, otmp);
1095. 		    }
1096. 		}
1097. 		break;
1098. 	    case S_WRAITH:
1099. 	    if (!rn2(2)) (void)mongets(mtmp, ROBE);
1100. 		if (ptr == &mons[PM_NAZGUL]) {
1101. 			otmp = mksobj(RIN_INVISIBILITY, FALSE, FALSE);
1102. 			curse(otmp);
1103. 			(void) mpickobj(mtmp, otmp);
1104. 		}
1105. 		break;
1106. 	    case S_LICH:
1107. 		if (ptr == &mons[PM_MASTER_LICH] && !rn2(13))
1108. 			(void)mongets(mtmp, (rn2(7) ? ATHAME : WAN_NOTHING));
1109. 		else if (ptr == &mons[PM_ARCH_LICH] && !rn2(3)) {
1110. 			otmp = mksobj(rn2(3) ? ATHAME : QUARTERSTAFF,
1111. 				      TRUE, rn2(13) ? FALSE : TRUE);
1112. 			if (otmp->spe < 2) otmp->spe = rnd(3);
1113. 			if (!rn2(4)) otmp->oerodeproof = 1;
1114. 			(void) mpickobj(mtmp, otmp);
1115. 		}
1116. 		break;
1117. 	    case S_MUMMY:
1118. 		if (rn2(7)) (void)mongets(mtmp, MUMMY_WRAPPING);
1119. 		break;
1120. 	    case S_QUANTMECH:
1121. 		if (monsndx(ptr) == PM_QUANTUM_MECHANIC && !rn2(20)) {
1122. 			otmp = mksobj(LARGE_BOX, FALSE, FALSE);
1123. 			otmp->spe = 1; /* flag for special box */
1124. 			otmp->owt = weight(otmp);
1125. 			(void) mpickobj(mtmp, otmp);
1126. 		}
1127. 		if (monsndx(ptr) == PM_DOCTOR_FRANKENSTEIN) {
1128. 			(void)mongets(mtmp, LAB_COAT);
1129. 			(void)mongets(mtmp, WAN_POLYMORPH);
1130. 			(void)mongets(mtmp, SPE_POLYMORPH);
1131. 		}
1132. 		break;
1133. 	    case S_LEPRECHAUN:
1134. #ifndef GOLDOBJ
1135. 		mtmp->mgold = (long) d(level_difficulty(), 30);
1136. #else
1137. 		mkmonmoney(mtmp, (long) d(level_difficulty(), 30));
1138. #endif
1139. 		break;
1140. 	    case S_ELEMENTAL:        
1141.   /*            if(ptr == &mons[PM_WATER_WEIRD]){
1142. 			otmp = mksobj(WAN_WISHING,TRUE,FALSE);
1143. 			otmp->spe=3;
1144. 			otmp->blessed=0;
1145. 			mpickobj(mtmp, otmp);
1146. 		}*/
1147. 		break;	
1148. 	    case S_VAMPIRE:
1149. 		/* [Lethe] Star and fire vampires don't get this stuff */
1150. 		if (ptr == &mons[PM_STAR_VAMPIRE] || 
1151. 				ptr == &mons[PM_FIRE_VAMPIRE])
1152. 		    break;
1153. 	    	/* Get opera cloak */
1154. /*	    	otmp = readobjnam(opera_cloak);
1155. 		if (otmp && otmp != &zeroobj) mpickobj(mtmp, otmp);*/
1156. 		for (i = STRANGE_OBJECT; i < NUM_OBJECTS; i++) {
1157. 			register const char *zn;
1158. 			if ((zn = OBJ_DESCR(objects[i])) && !strcmpi(zn, "opera cloak")) {
1159. 				if (!OBJ_NAME(objects[i])) i = STRANGE_OBJECT;
1160. 				break;
1161. 			}
1162. 		}
1163. 		if (i != NUM_OBJECTS) (void)mongets(mtmp, i);
1164. 		if (rn2(2)) {
1165. 		    if ((int) mtmp->m_lev > rn2(30))
1166. 			(void)mongets(mtmp, POT_VAMPIRE_BLOOD);
1167. 		    else
1168. 			(void)mongets(mtmp, POT_BLOOD);
1169. 		}
1170. 		break;
1171. 	    case S_DEMON:
1172. 		/* moved here from m_initweap() because these don't
1173. 		   have AT_WEAP so m_initweap() is not called for them */
1174. 		if (ptr == &mons[PM_ICE_DEVIL] && !rn2(4)) {
1175. 			(void)mongets(mtmp, SPEAR);
1176. 		/* [DS] Cthulhu isn't fully integrated yet, and he won't be
1177. 		 *      until Moloch's Sanctum is rearranged */
1178. 		} else if (ptr == &mons[PM_CTHULHU]) {
1179. 			(void)mongets(mtmp, AMULET_OF_YENDOR);
1180. 			(void)mongets(mtmp, WAN_DEATH);
1181. 			(void)mongets(mtmp, POT_FULL_HEALING);
1182. 		} else if (ptr == &mons[PM_ASMODEUS]) {
1183. 			(void)mongets(mtmp, WAN_COLD);
1184. 			(void)mongets(mtmp, WAN_FIRE);
1185. 		}
1186. 		break;
1187. 	    default:
1188. 		break;
1189. 	}
1190. 
1191. 	/* ordinary soldiers rarely have access to magic (or gold :-) */
1192. 	if (ptr == &mons[PM_SOLDIER] && rn2(15)) return;
1193. 
1194. 	if ((int) mtmp->m_lev > rn2(200))
1195. 		(void) mongets(mtmp, rnd_defensive_item(mtmp));
1196. 	if ((int) mtmp->m_lev > rn2(200))
1197. 		(void) mongets(mtmp, rnd_misc_item(mtmp));
1198. #ifndef GOLDOBJ
1199. 	if (likes_gold(ptr) && !mtmp->mgold && !rn2(5))
1200. 		mtmp->mgold =
1201. 		      (long) d(level_difficulty(), mtmp->minvent ? 5 : 10);
1202. #else
1203. 	if (likes_gold(ptr) && !findgold(mtmp->minvent) && !rn2(5))
1204. 		mkmonmoney(mtmp, (long) d(level_difficulty(), mtmp->minvent ? 5 : 10));
1205. #endif
1206. }
1207. 
1208. /* Note: for long worms, always call cutworm (cutworm calls clone_mon) */
1209. struct monst *
1210. clone_mon(mon, x, y)
1211. struct monst *mon;
1212. xchar x, y;	/* clone's preferred location or 0 (near mon) */
1213. {
1214. 	coord mm;
1215. 	struct monst *m2;
1216. 
1217. 	/* may be too weak or have been extinguished for population control */
1218. 	if (mon->mhp <= 1 || (mvitals[monsndx(mon->data)].mvflags & G_EXTINCT))
1219. 	    return (struct monst *)0;
1220. 
1221. 	if (x == 0) {
1222. 	    mm.x = mon->mx;
1223. 	    mm.y = mon->my;
1224. 	    if (!enexto(&mm, mm.x, mm.y, mon->data) || MON_AT(mm.x, mm.y))
1225. 		return (struct monst *)0;
1226. 	} else if (!isok(x, y)) {
1227. 	    return (struct monst *)0;	/* paranoia */
1228. 	} else {
1229. 	    mm.x = x;
1230. 	    mm.y = y;
1231. 	    if (MON_AT(mm.x, mm.y)) {
1232. 		if (!enexto(&mm, mm.x, mm.y, mon->data) || MON_AT(mm.x, mm.y))
1233. 		    return (struct monst *)0;
1234. 	    }
1235. 	}
1236. 	m2 = newmonst(0);
1237. 	*m2 = *mon;			/* copy condition of old monster */
1238. 	m2->nmon = fmon;
1239. 	fmon = m2;
1240. 	m2->m_id = flags.ident++;
1241. 	if (!m2->m_id) m2->m_id = flags.ident++;	/* ident overflowed */
1242. 	m2->mx = mm.x;
1243. 	m2->my = mm.y;
1244. 
1245. 	m2->minvent = (struct obj *) 0; /* objects don't clone */
1246. 	m2->mleashed = FALSE;
1247. #ifndef GOLDOBJ
1248. 	m2->mgold = 0L;
1249. #endif
1250. 	/* Max HP the same, but current HP halved for both.  The caller
1251. 	 * might want to override this by halving the max HP also.
1252. 	 * When current HP is odd, the original keeps the extra point.
1253. 	 */
1254. 	m2->mhpmax = mon->mhpmax;
1255. 	m2->mhp = mon->mhp / 2;
1256. 	mon->mhp -= m2->mhp;
1257. 
1258. 	/* Same for the power */
1259. 	m2->m_enmax = mon->m_enmax;
1260. 	m2->m_en = mon->m_en /= 2;
1261. 
1262. 	/* since shopkeepers and guards will only be cloned if they've been
1263. 	 * polymorphed away from their original forms, the clone doesn't have
1264. 	 * room for the extra information.  we also don't want two shopkeepers
1265. 	 * around for the same shop.
1266. 	 */
1267. 	if (mon->isshk) m2->isshk = FALSE;
1268. 	if (mon->isgd) m2->isgd = FALSE;
1269. 	if (mon->ispriest) m2->ispriest = FALSE;
1270. 	if (mon->isgyp) m2->isgyp = FALSE;
1271. 	m2->mxlth = 0;
1272. 	place_monster(m2, m2->mx, m2->my);
1273. 	if (emits_light(m2->data))
1274. 	    new_light_source(m2->mx, m2->my, emits_light(m2->data),
1275. 			     LS_MONSTER, (genericptr_t)m2);
1276. 	if (m2->mnamelth) {
1277. 	    m2->mnamelth = 0; /* or it won't get allocated */
1278. 	    m2 = christen_monst(m2, NAME(mon));
1279. 	} else if (mon->isshk) {
1280. 	    m2 = christen_monst(m2, shkname(mon));
1281. 	}
1282. 
1283. 	/* not all clones caused by player are tame or peaceful */
1284. 	if (!flags.mon_moving) {
1285. 	    if (mon->mtame)
1286. 		m2->mtame = rn2(max(2 + u.uluck, 2)) ? mon->mtame : 0;
1287. 	    else if (mon->mpeaceful)
1288. 		m2->mpeaceful = rn2(max(2 + u.uluck, 2)) ? 1 : 0;
1289. 	}
1290. 
1291. 	newsym(m2->mx,m2->my);	/* display the new monster */
1292. 	if (m2->mtame) {
1293. 	    struct monst *m3;
1294. 
1295. 	    if (mon->isminion) {
1296. 		m3 = newmonst(sizeof(struct epri) + mon->mnamelth);
1297. 		*m3 = *m2;
1298. 		m3->mxlth = sizeof(struct epri);
1299. 		if (m2->mnamelth) Strcpy(NAME(m3), NAME(m2));
1300. 		*(EPRI(m3)) = *(EPRI(mon));
1301. 		replmon(m2, m3);
1302. 		m2 = m3;
1303. 	    } else {
1304. 		/* because m2 is a copy of mon it is tame but not init'ed.
1305. 		 * however, tamedog will not re-tame a tame dog, so m2
1306. 		 * must be made non-tame to get initialized properly.
1307. 		 */
1308. 		m2->mtame = 0;
1309. 		if ((m3 = tamedog(m2, (struct obj *)0)) != 0) {
1310. 		    m2 = m3;
1311. 		    *(EDOG(m2)) = *(EDOG(mon));
1312. 		}
1313. 	    }
1314. 	}
1315. 	set_malign(m2);
1316. 
1317. 	return m2;
1318. }
1319. 
1320. /*
1321.  * Propagate a species
1322.  *
1323.  * Once a certain number of monsters are created, don't create any more
1324.  * at random (i.e. make them extinct).  The previous (3.2) behavior was
1325.  * to do this when a certain number had _died_, which didn't make
1326.  * much sense.
1327.  *
1328.  * Returns FALSE propagation unsuccessful
1329.  *         TRUE  propagation successful
1330.  */
1331. boolean
1332. propagate(mndx, tally, ghostly)
1333. int mndx;
1334. boolean tally;
1335. boolean ghostly;
1336. {
1337. 	boolean result;
1338. 	uchar lim = mbirth_limit(mndx);
1339. 	boolean gone = (mvitals[mndx].mvflags & G_GONE); /* genocided or extinct */
1340. 
1341. 	result = (((int) mvitals[mndx].born < lim) && !gone) ? TRUE : FALSE;
1342. 
1343. 	/* if it's unique, don't ever make it again */
1344. 	if (mons[mndx].geno & G_UNIQ) mvitals[mndx].mvflags |= G_EXTINCT;
1345. 
1346. 	if (mvitals[mndx].born < 255 && tally && (!ghostly || (ghostly && result)))
1347. 		 mvitals[mndx].born++;
1348. 	if ((int) mvitals[mndx].born >= lim && !(mons[mndx].geno & G_NOGEN) &&
1349. 		!(mvitals[mndx].mvflags & G_EXTINCT)) {
1350. #if defined(DEBUG) && defined(WIZARD)
1351. 		if (wizard) pline("Automatically extinguished %s.",
1352. 					makeplural(mons[mndx].mname));
1353. #endif
1354. 		mvitals[mndx].mvflags |= G_EXTINCT;
1355. 		reset_rndmonst(mndx);
1356. 	}
1357. 	return result;
1358. }
1359. 
1360. /*
1361.  * called with [x,y] = coordinates;
1362.  *	[0,0] means anyplace
1363.  *	[u.ux,u.uy] means: near player (if !in_mklev)
1364.  *
1365.  *	In case we make a monster group, only return the one at [x,y].
1366.  */
1367. struct monst *
1368. makemon(ptr, x, y, mmflags)
1369. register struct permonst *ptr;
1370. register int	x, y;
1371. register int	mmflags;
1372. {
1373. 	register struct monst *mtmp;
1374. 	int mndx, mcham, ct, mitem, xlth;
1375. 	boolean anymon = (!ptr);
1376. 	boolean byyou = (x == u.ux && y == u.uy);
1377. 	boolean allow_minvent = ((mmflags & NO_MINVENT) == 0);
1378. 	boolean countbirth = ((mmflags & MM_NOCOUNTBIRTH) == 0);
1379. 	unsigned gpflags = (mmflags & MM_IGNOREWATER) ? MM_IGNOREWATER : 0;
1380. 
1381. 	/* if caller wants random location, do it here */
1382. 	if(x == 0 && y == 0) {
1383. 		int tryct = 0;	/* careful with bigrooms */
1384. 		struct monst fakemon;
1385. 
1386. 		fakemon.data = ptr;	/* set up for goodpos */
1387. 		do {
1388. 			x = rn1(COLNO-3,2);
1389. 			y = rn2(ROWNO);
1390. 		} while(!goodpos(x, y, ptr ? &fakemon : (struct monst *)0, gpflags) ||
1391. 			(!in_mklev && tryct++ < 50 && cansee(x, y)));
1392. 	} else if (byyou && !in_mklev) {
1393. 		coord bypos;
1394. 
1395. 		if(enexto_core(&bypos, u.ux, u.uy, ptr, gpflags)) {
1396. 			x = bypos.x;
1397. 			y = bypos.y;
1398. 		} else
1399. 			return((struct monst *)0);
1400. 	}
1401. 
1402. 	/* Does monster already exist at the position? */
1403. 	if(MON_AT(x, y)) {
1404. 		if ((mmflags & MM_ADJACENTOK) != 0) {
1405. 			coord bypos;
1406. 			if(enexto_core(&bypos, x, y, ptr, gpflags)) {
1407. 				x = bypos.x;
1408. 				y = bypos.y;
1409. 			} else
1410. 				return((struct monst *) 0);
1411. 		} else 
1412. 			return((struct monst *) 0);
1413. 	}
1414. 
1415. 	if(ptr){
1416. 		mndx = monsndx(ptr);
1417. 		/* if you are to make a specific monster and it has
1418. 		   already been genocided, return */
1419. 		if (mvitals[mndx].mvflags & G_GENOD) return((struct monst *) 0);
1420. #if defined(WIZARD) && defined(DEBUG)
1421. 		if (wizard && (mvitals[mndx].mvflags & G_EXTINCT))
1422. 		    pline("Explicitly creating extinct monster %s.",
1423. 			mons[mndx].mname);
1424. #endif
1425. 	} else {
1426. 		/* make a random (common) monster that can survive here.
1427. 		 * (the special levels ask for random monsters at specific
1428. 		 * positions, causing mass drowning on the medusa level,
1429. 		 * for instance.)
1430. 		 */
1431. 		int tryct = 0;	/* maybe there are no good choices */
1432. 		struct monst fakemon;
1433. 		do {
1434. 			if(!(ptr = rndmonst())) {
1435. #ifdef DEBUG
1436. 			    pline("Warning: no monster.");
1437. #endif
1438. 			    return((struct monst *) 0);	/* no more monsters! */
1439. 			}
1440. 			fakemon.data = ptr;	/* set up for goodpos */
1441. 		} while(!goodpos(x, y, &fakemon, gpflags) && tryct++ < 50);
1442. 		mndx = monsndx(ptr);
1443. 	}
1444. 	(void) propagate(mndx, countbirth, FALSE);
1445. 	xlth = ptr->pxlth;
1446. 	if (mmflags & MM_EDOG) xlth += sizeof(struct edog);
1447. 	else if (mmflags & MM_EMIN) xlth += sizeof(struct emin);
1448. 	mtmp = newmonst(xlth);
1449. 	*mtmp = zeromonst;		/* clear all entries in structure */
1450. 	(void)memset((genericptr_t)mtmp->mextra, 0, xlth);
1451. 	mtmp->nmon = fmon;
1452. 	fmon = mtmp;
1453. 	mtmp->m_id = flags.ident++;
1454. 	if (!mtmp->m_id) mtmp->m_id = flags.ident++;	/* ident overflowed */
1455. 	set_mon_data(mtmp, ptr, 0);
1456. 	if (mtmp->data->msound == MS_LEADER)
1457. 	    quest_status.leader_m_id = mtmp->m_id;
1458. 	mtmp->mxlth = xlth;
1459. 	mtmp->mnum = mndx;
1460. 
1461. 	mtmp->m_lev = adj_lev(ptr);
1462. 	
1463. 	/* WAC set oldmonnm */
1464. 	mtmp->oldmonnm = monsndx(ptr);
1465. 	
1466. 	if (ptr >= &mons[PM_ARCHEOLOGIST] && ptr <= &mons[PM_WIZARD]) {
1467. 	   /* enemy characters are of varying level */
1468. 	   int base_you, base_lev;
1469. 	   base_you = (u.ulevel / 2)+1;
1470. 	   base_lev = level_difficulty()+1;
1471. 	   if (base_you < 1) base_you = 1;
1472. 	   if (base_lev < 1) base_lev = 1;
1473. 	   mtmp->m_lev = (1 + rn2(base_you) + rn2(base_lev) / 2)+1;
1474. 	}
1475. 
1476. 	/* Set HP, HPmax */	
1477. 	if (is_golem(ptr)) {
1478. 	    mtmp->mhpmax = mtmp->mhp = golemhp(mndx);
1479. 	} else if (is_rider(ptr)) {
1480. 	    /* We want low HP, but a high mlevel so they can attack well */
1481. 		mtmp->mhpmax = mtmp->mhp = d(10,8) + 20;
1482. 	} else if (ptr->mlevel > 49) {
1483. 	    /* "special" fixed hp monster
1484. 	     * the hit points are encoded in the mlevel in a somewhat strange
1485. 	     * way to fit in the 50..127 positive range of a signed character
1486. 	     * above the 1..49 that indicate "normal" monster levels */
1487. 	    mtmp->mhpmax = mtmp->mhp = 2*(ptr->mlevel - 6);
1488. 	    mtmp->m_lev = mtmp->mhp / 4;	/* approximation */
1489. 	} else if (ptr->mlet == S_DRAGON && mndx >= PM_GRAY_DRAGON) {
1490. 	    /* adult dragons */
1491. 	    mtmp->mhpmax = mtmp->mhp = (int) (In_endgame(&u.uz) ?
1492. 		(8 * mtmp->m_lev) : (4 * mtmp->m_lev + d((int)mtmp->m_lev, 4)));
1493. 	} else if (!mtmp->m_lev) {
1494. 	    mtmp->mhpmax = mtmp->mhp = rnd(4);
1495. 	} else {
1496. 	    mtmp->mhpmax = mtmp->mhp = d((int)mtmp->m_lev, 8);
1497. 	    
1498. 	    if (is_home_elemental(ptr))
1499. 		mtmp->mhpmax = (mtmp->mhp *= 3);
1500. 	    else mtmp->mhpmax = mtmp->mhp = 
1501. 		d((int)mtmp->m_lev, 8) + (mtmp->m_lev*rnd(2));
1502. 	}
1503. 
1504. 	/* Assign power */
1505. 	if (mindless(ptr)) {
1506. 	    mtmp->m_enmax = mtmp->m_en = 0;
1507. 	} else {
1508. 	    /* This is actually quite similar to hit dice,  
1509. 	     * but with more randomness 
1510. 	     */
1511. 	    mtmp->m_enmax = mtmp->m_en =
1512. 		d((int)mtmp->m_lev * 2, 4) + (mtmp->m_lev*rnd(2));
1513. 	}
1514. 	if (is_female(ptr)) mtmp->female = TRUE;
1515. 	else if (is_male(ptr)) mtmp->female = FALSE;
1516. 	else mtmp->female = rn2(2);	/* ignored for neuters */
1517. 
1518. 	if (In_sokoban(&u.uz) && !mindless(ptr))  /* know about traps here */
1519. 	    mtmp->mtrapseen = (1L << (PIT - 1)) | (1L << (HOLE - 1));
1520. 	if (ptr->msound == MS_LEADER)		/* leader knows about portal */
1521. 	    mtmp->mtrapseen |= (1L << (MAGIC_PORTAL-1));
1522. 
1523. 	place_monster(mtmp, x, y);
1524. 	mtmp->mcansee = mtmp->mcanmove = TRUE;
1525. 	mtmp->mpeaceful = (mmflags & MM_ANGRY) ? FALSE : peace_minded(ptr);
1526. 	mtmp->mtraitor  = FALSE;
1527. 
1528. 	switch(ptr->mlet) {
1529. 		case S_MIMIC:
1530. 			set_mimic_sym(mtmp);
1531. 			break;
1532. 		case S_SPIDER:
1533. 		case S_SNAKE:
1534. 			if(in_mklev)
1535. 			    if(x && y)
1536. 				(void) mkobj_at(0, x, y, TRUE);
1537. 			if(hides_under(ptr) && OBJ_AT(x, y))
1538. 			    mtmp->mundetected = TRUE;
1539. 			break;
1540. 		case S_LIGHT:
1541. 		case S_ELEMENTAL:
1542. 			if (mndx == PM_STALKER || mndx == PM_BLACK_LIGHT) {
1543. 			    mtmp->perminvis = TRUE;
1544. 			    mtmp->minvis = TRUE;
1545. 			}
1546. 			break;
1547. 		case S_EEL:
1548. 			if (is_pool(x, y))
1549. 			    mtmp->mundetected = TRUE;
1550. 			break;
1551. 		case S_LEPRECHAUN:
1552. 			mtmp->msleeping = 1;
1553. 			break;
1554. 		case S_JABBERWOCK:
1555. 		case S_NYMPH:
1556. 			if (rn2(5) && !u.uhave.amulet) mtmp->msleeping = 1;
1557. 			if (mndx == PM_PIXIE) {        
1558. /*  			    mtmp->perminvis = TRUE;*/
1559.   			    mtmp->minvis = TRUE;
1560. 			}
1561. 			break;
1562. 		case S_ORC:
1563. 			if (Race_if(PM_ELF)) mtmp->mpeaceful = FALSE;
1564. 			break;
1565. 		case S_UNICORN:
1566. 			if (is_unicorn(ptr) &&
1567. 					sgn(u.ualign.type) == sgn(ptr->maligntyp))
1568. 				mtmp->mpeaceful = TRUE;
1569. 			break;
1570. 		case S_BAT:
1571. 			if (Inhell && is_bat(ptr))
1572. 			    mon_adjust_speed(mtmp, 2, (struct obj *)0);
1573. 			break;
1574. 		case S_VAMPIRE:
1575. 			/* [DS] Star vampires are invisible until they feed */
1576. 			if (mndx == PM_STAR_VAMPIRE) {
1577. 			    mtmp->perminvis = TRUE;
1578. 			    mtmp->minvis = TRUE;
1579. 			}
1580. 			break;
1581. 	}
1582. 	if ((ct = emits_light(mtmp->data)) > 0)
1583. 		new_light_source(mtmp->mx, mtmp->my, ct,
1584. 				 LS_MONSTER, (genericptr_t)mtmp);
1585. 
1586. 	mitem = 0;	/* extra inventory item for this monster */
1587. 
1588. 	if ((mcham = pm_to_cham(mndx)) != CHAM_ORDINARY) {
1589. 		/* If you're protected with a ring, don't create
1590. 		 * any shape-changing chameleons -dgk
1591. 		 */
1592. 		if (Protection_from_shape_changers)
1593. 			mtmp->cham = CHAM_ORDINARY;
1594. 		else {
1595. 			mtmp->cham = mcham;
1596. 			(void) mon_spec_poly(mtmp, rndmonst(), 0L, FALSE, FALSE, FALSE, FALSE);
1597. 		}
1598. 	} else if (mndx == PM_WIZARD_OF_YENDOR) {
1599. 		mtmp->iswiz = TRUE;
1600. 		flags.no_of_wizards++;
1601. 		if (flags.no_of_wizards == 1 && Is_earthlevel(&u.uz))
1602. 			mitem = SPE_DIG;
1603. 	} else if (mndx == PM_DJINNI) {
1604. 		flags.djinni_count++;
1605. 	} else if (mndx == PM_GHOST) {
1606. 		flags.ghost_count++;
1607. 		if (!(mmflags & MM_NONAME))
1608. 			mtmp = christen_monst(mtmp, rndghostname());
1609. 	} else if (mndx == PM_NIGHTMARE) {
1610. 		struct obj *otmp;
1611. 
1612. 		otmp = oname(mksobj(SKELETON_KEY, TRUE, FALSE),
1613. 				artiname(ART_KEY_OF_LAW));
1614. 		if (otmp) {
1615. 			otmp->blessed = otmp->cursed = 0;
1616. 			mpickobj(mtmp, otmp);
1617. 		}
1618. 	} else if (mndx == PM_BEHOLDER) {
1619. 		struct obj *otmp;
1620. 
1621. 		otmp = oname(mksobj(SKELETON_KEY, TRUE, FALSE),
1622. 				artiname(ART_KEY_OF_NEUTRALITY));
1623. 		if (otmp) {
1624. 			otmp->blessed = otmp->cursed = 0;
1625. 			mpickobj(mtmp, otmp);
1626. 		}
1627. 	} else if (mndx == PM_VECNA) {
1628. 		struct obj *otmp;
1629. 
1630. 		otmp = oname(mksobj(SKELETON_KEY, TRUE, FALSE),
1631. 				artiname(ART_KEY_OF_CHAOS));
1632. 		if (otmp) {
1633. 			otmp->blessed = otmp->cursed = 0;
1634. 			mpickobj(mtmp, otmp);
1635. 		}
1636. 	} else if (mndx == PM_GYPSY) {
1637. 		/* KMH -- Gypsies are randomly generated; initialize them here */
1638. 		gypsy_init(mtmp);
1639. 	} else if (mndx == PM_VLAD_THE_IMPALER) {
1640. 		mitem = CANDELABRUM_OF_INVOCATION;
1641. 	} else if (mndx == PM_CROESUS) {
1642. 		mitem = TWO_HANDED_SWORD;
1643. 	} else if (ptr->msound == MS_NEMESIS) {
1644. 		mitem = BELL_OF_OPENING;
1645. 	} else if (mndx == PM_PESTILENCE) {
1646. 		mitem = POT_SICKNESS;
1647. 	}
1648. 	if (mitem && allow_minvent) (void) mongets(mtmp, mitem);
1649. 
1650. 	if(in_mklev) {
1651. 		if(((is_ndemon(ptr)) ||
1652. 		    (mndx == PM_WUMPUS) ||
1653. 		    (mndx == PM_LONG_WORM) ||
1654. 		    (mndx == PM_GIANT_EEL)) && !u.uhave.amulet && rn2(5))
1655. 			mtmp->msleeping = 1;
1656. 	} else {
1657. 		if(byyou) {
1658. 			newsym(mtmp->mx,mtmp->my);
1659. 			set_apparxy(mtmp);
1660. 		}
1661. 	}
1662. 	if(is_dprince(ptr) && ptr->msound == MS_BRIBE) {
1663. 	    mtmp->mpeaceful = mtmp->minvis = mtmp->perminvis = 1;
1664. 	    mtmp->mavenge = 0;
1665. 	    if (uwep && uwep->oartifact == ART_EXCALIBUR)
1666. 		mtmp->mpeaceful = mtmp->mtame = FALSE;
1667. 	}
1668. #ifndef DCC30_BUG
1669. 	if (mndx == PM_LONG_WORM && (mtmp->wormno = get_wormno()) != 0)
1670. #else
1671. 	/* DICE 3.0 doesn't like assigning and comparing mtmp->wormno in the
1672. 	 * same expression.
1673. 	 */
1674. 	if (mndx == PM_LONG_WORM &&
1675. 		(mtmp->wormno = get_wormno(), mtmp->wormno != 0))
1676. #endif
1677. 	{
1678. 	    /* we can now create worms with tails - 11/91 */
1679. 	    initworm(mtmp, rn2(5));
1680. 	    if (count_wsegs(mtmp)) place_worm_tail_randomly(mtmp, x, y);
1681. 	}
1682. 	set_malign(mtmp);		/* having finished peaceful changes */
1683. 	if(anymon) {
1684. 	    if ((ptr->geno & G_SGROUP) && rn2(2)) {
1685. 		m_initsgrp(mtmp, mtmp->mx, mtmp->my);
1686. 	    } else if (ptr->geno & G_LGROUP) {
1687. 		if(rn2(3))  m_initlgrp(mtmp, mtmp->mx, mtmp->my);
1688. 		else	    m_initsgrp(mtmp, mtmp->mx, mtmp->my);
1689. 	    }
1690. 	    else if(ptr->geno & G_VLGROUP) {
1691. 			if(rn2(3))  m_initvlgrp(mtmp, mtmp->mx, mtmp->my);
1692. 			else if(rn2(3))  m_initlgrp(mtmp, mtmp->mx, mtmp->my);
1693. 			else        m_initsgrp(mtmp, mtmp->mx, mtmp->my);
1694. 	    }
1695. 	}
1696. 
1697. 	if (allow_minvent) {
1698. 	    if(is_armed(ptr))
1699. 		m_initweap(mtmp);	/* equip with weapons / armor */
1700. 	    m_initinv(mtmp);  /* add on a few special items incl. more armor */
1701. 	    m_dowear(mtmp, TRUE);
1702. 	} else {
1703. 	    if (mtmp->minvent) discard_minvent(mtmp);
1704. 	    mtmp->minvent = (struct obj *)0;    /* caller expects this */
1705. 	    mtmp->minvent = (struct obj *)0;    /* caller expects this */
1706. 	}
1707. 	if ((ptr->mflags3 & M3_WAITMASK) && !(mmflags & MM_NOWAIT)) {
1708. 		if (ptr->mflags3 & M3_WAITFORU)
1709. 			mtmp->mstrategy |= STRAT_WAITFORU;
1710. 		if (ptr->mflags3 & M3_CLOSE)
1711. 			mtmp->mstrategy |= STRAT_CLOSE;
1712. 	}
1713. 	if (!in_mklev)
1714. 	    newsym(mtmp->mx,mtmp->my);	/* make sure the mon shows up */
1715. 
1716. 	return(mtmp);
1717. }
1718. 
1719. int
1720. mbirth_limit(mndx)
1721. int mndx;
1722. {
1723. 	/* assert(MAXMONNO < 255); */
1724. 	return (mndx == PM_NAZGUL ? 9 : mndx == PM_ERINYS ? 3 : MAXMONNO); 
1725. }
1726. 
1727. /* used for wand/scroll/spell of create monster */
1728. /* returns TRUE iff you know monsters have been created */
1729. 
1730. boolean
1731. create_critters(cnt, mptr)
1732. int cnt;
1733. struct permonst *mptr;		/* usually null; used for confused reading */
1734. {
1735. 	coord c;
1736. 	int x, y;
1737. 	struct monst *mon;
1738. 	boolean known = FALSE;
1739. #ifdef WIZARD
1740. 	boolean ask = wizard;
1741. #endif
1742. 
1743. 	while (cnt--) {
1744. #ifdef WIZARD
1745. 	    if (ask) {
1746. 		if (create_particular()) {
1747. 		    known = TRUE;
1748. 		    continue;
1749. 		}
1750. 		else ask = FALSE;	/* ESC will shut off prompting */
1751. 	    }
1752. #endif
1753. 	    x = u.ux,  y = u.uy;
1754. 	    /* if in water, try to encourage an aquatic monster
1755. 	       by finding and then specifying another wet location */
1756. 	    if (!mptr && u.uinwater && enexto(&c, x, y, &mons[PM_GIANT_EEL]))
1757. 		x = c.x,  y = c.y;
1758. 
1759. 	    mon = makemon(mptr, x, y, NO_MM_FLAGS);
1760. 	    if (mon && canspotmon(mon)) known = TRUE;
1761. 	}
1762. 	return known;
1763. }
1764. 
1765. #endif /* OVL1 */
1766. #ifdef OVL0
1767. 
1768. STATIC_OVL boolean
1769. uncommon(mndx)
1770. int mndx;
1771. {
1772. 	if (mons[mndx].geno & (G_NOGEN | G_UNIQ)) return TRUE;
1773. 	if (mvitals[mndx].mvflags & G_GONE) return TRUE;
1774. 	if (Inhell)
1775. 		return(mons[mndx].maligntyp > A_NEUTRAL);
1776. 	else
1777. 		return((mons[mndx].geno & G_HELL) != 0);
1778. }
1779. 
1780. /*
1781.  *	shift the probability of a monster's generation by
1782.  *	comparing the dungeon alignment and monster alignment.
1783.  *	return an integer in the range of 0-5.
1784.  */
1785. STATIC_OVL int
1786. align_shift(ptr)
1787. register struct permonst *ptr;
1788. {
1789.     static NEARDATA long oldmoves = 0L;	/* != 1, starting value of moves */
1790.     static NEARDATA s_level *lev;
1791.     register int alshift;
1792. 
1793.     if(oldmoves != moves) {
1794. 	lev = Is_special(&u.uz);
1795. 	oldmoves = moves;
1796.     }
1797.     switch((lev) ? lev->flags.align : dungeons[u.uz.dnum].flags.align) {
1798.     default:	/* just in case */
1799.     case AM_NONE:	alshift = 0;
1800. 			break;
1801.     case AM_LAWFUL:	alshift = (ptr->maligntyp+20)/(2*ALIGNWEIGHT);
1802. 			break;
1803.     case AM_NEUTRAL:	alshift = (20 - abs(ptr->maligntyp))/ALIGNWEIGHT;
1804. 			break;
1805.     case AM_CHAOTIC:	alshift = (-(ptr->maligntyp-20))/(2*ALIGNWEIGHT);
1806. 			break;
1807.     }
1808.     return alshift;
1809. }
1810. 
1811. static NEARDATA struct {
1812. 	int choice_count;
1813. 	char mchoices[SPECIAL_PM];	/* value range is 0..127 */
1814. } rndmonst_state = { -1, {0} };
1815. 
1816. /* select a random monster type */
1817. struct permonst *
1818. rndmonst()
1819. {
1820. 	register struct permonst *ptr;
1821. 	register int mndx, ct;
1822. 
1823. /* [Tom] this was locking up priest quest... who knows why? */
1824. /* fixed it! no 'W' class monsters with corpses! oops! */
1825. /*    if(u.uz.dnum == quest_dnum && (ptr = qt_montype())) return(ptr); */
1826. 	if(u.uz.dnum == quest_dnum) {
1827. 		if ((ptr = qt_montype())) {
1828. 			return(ptr);
1829. 		}
1830. 	}
1831. 
1832. 	/* KMH -- February 2 is Groundhog Day! */
1833. 	if (Is_oracle_level(&u.uz) && (!!flags.groundhogday ^ !rn2(20)))
1834. 		return (&mons[PM_WOODCHUCK]);
1835. 
1836. /*      if (u.uz.dnum == quest_dnum && rn2(7) && (ptr = qt_montype()) != 0)
1837. 	    return ptr; */
1838. 
1839. 	if (rndmonst_state.choice_count < 0) {	/* need to recalculate */
1840. 	    int zlevel, minmlev, maxmlev;
1841. 	    boolean elemlevel;
1842. #ifdef REINCARNATION
1843. 	    boolean upper;
1844. #endif
1845. 	    rndmonst_state.choice_count = 0;
1846. 	    /* look for first common monster */
1847. 	    for (mndx = LOW_PM; mndx < SPECIAL_PM; mndx++) {
1848. 		if (!uncommon(mndx)) break;
1849. 		rndmonst_state.mchoices[mndx] = 0;
1850. 	    }		
1851. 	    if (mndx == SPECIAL_PM) {
1852. 		/* evidently they've all been exterminated */
1853. #ifdef DEBUG
1854. 		pline("rndmonst: no common mons!");
1855. #endif
1856. 		return (struct permonst *)0;
1857. 	    } /* else `mndx' now ready for use below */
1858. 	    zlevel = level_difficulty();
1859. 	    /* determine the level of the weakest monster to make. */
1860. 	    minmlev = zlevel / 6;
1861. 	    /* determine the level of the strongest monster to make. */
1862. 	    maxmlev = (zlevel + u.ulevel + 1)>>1;
1863. #ifdef REINCARNATION
1864. 	    upper = Is_rogue_level(&u.uz);
1865. #endif
1866. 	    elemlevel = In_endgame(&u.uz) && !Is_astralevel(&u.uz);
1867. 
1868. /*
1869.  *	Find out how many monsters exist in the range we have selected.
1870.  */
1871. 	     
1872. loopback:
1873. 	    /* (`mndx' initialized above) */
1874. 	    for ( ; mndx < SPECIAL_PM; mndx++) {
1875. 		ptr = &mons[mndx];
1876. 		rndmonst_state.mchoices[mndx] = 0;
1877. 		if (tooweak(mndx, minmlev) || toostrong(mndx, maxmlev))
1878. 		    continue;
1879. #ifdef REINCARNATION
1880. 		if (upper && !isupper((int)def_monsyms[(int)(ptr->mlet)])) continue;
1881. #endif
1882. 		if (elemlevel && wrong_elem_type(ptr)) continue;
1883. 		if (uncommon(mndx)) continue;
1884. 		if (Inhell && (ptr->geno & G_NOHELL)) continue;
1885. 		ct = (int)(ptr->geno & G_FREQ) + align_shift(ptr);
1886. 		if (ct < 0 || ct > 127)
1887. 		    panic("rndmonst: bad count [#%d: %d]", mndx, ct);
1888. 		rndmonst_state.choice_count += ct;
1889. 		rndmonst_state.mchoices[mndx] = (char)ct;
1890. 	    }
1891. /*
1892.  *	    Possible modification:  if choice_count is "too low",
1893.  *	    expand minmlev..maxmlev range and try again.
1894.  */
1895. 	} /* choice_count+mchoices[] recalc */
1896. 
1897. 	if (rndmonst_state.choice_count <= 0) {
1898. 	    /* maybe no common mons left, or all are too weak or too strong */
1899. #ifdef DEBUG
1900. 	    Norep("rndmonst: choice_count=%d", rndmonst_state.choice_count);
1901. #endif
1902. 	    return (struct permonst *)0;
1903. 	}
1904. 
1905. /*
1906.  *	Now, select a monster at random.
1907.  */
1908. 	ct = rnd(rndmonst_state.choice_count);
1909. 	for (mndx = LOW_PM; mndx < SPECIAL_PM; mndx++)
1910. 	    if ((ct -= (int)rndmonst_state.mchoices[mndx]) <= 0) break;
1911. 
1912. 	if (mndx == SPECIAL_PM || uncommon(mndx)) {	/* shouldn't happen */
1913. 	    impossible("rndmonst: bad `mndx' [#%d]", mndx);
1914. 	    return (struct permonst *)0;
1915. 	}
1916. 	return &mons[mndx];
1917. 
1918. /*
1919.  * [Tom] Your rival adventurers are a special case:
1920.  *       - They have varying levels, and thus can always appear
1921.  *       - But they need to be sorta rare or else they're a large
1922.  *         percentage of the dungeon inhabitants.
1923.  */
1924. 	      if ((monsndx(ptr-1) >= PM_ARCHEOLOGIST) &&
1925. 		  (monsndx(ptr-1) <= PM_WIZARD)
1926. 		   && (rn2(4))) goto loopback;
1927. }
1928. 
1929. /* called when you change level (experience or dungeon depth) or when
1930.    monster species can no longer be created (genocide or extinction) */
1931. void
1932. reset_rndmonst(mndx)
1933. int mndx;	/* particular species that can no longer be created */
1934. {
1935. 	/* cached selection info is out of date */
1936. 	if (mndx == NON_PM) {
1937. 	    rndmonst_state.choice_count = -1;	/* full recalc needed */
1938. 	} else if (mndx < SPECIAL_PM) {
1939. 	    rndmonst_state.choice_count -= rndmonst_state.mchoices[mndx];
1940. 	    rndmonst_state.mchoices[mndx] = 0;
1941. 	} /* note: safe to ignore extinction of unique monsters */
1942. }
1943. 
1944. #endif /* OVL0 */
1945. #ifdef OVL1
1946. 
1947. /*	The routine below is used to make one of the multiple types
1948.  *	of a given monster class.  The second parameter specifies a
1949.  *	special casing bit mask to allow the normal genesis
1950.  *	masks to be deactivated.  Returns 0 if no monsters
1951.  *	in that class can be made.
1952.  */
1953. 
1954. struct permonst *
1955. mkclass(class,spc)
1956. char	class;
1957. int	spc;
1958. {
1959. 	register int    first;
1960. 
1961. 	first = pm_mkclass(class,spc);
1962. 	
1963. 	if (first == -1) return((struct permonst *) 0);
1964. 
1965. 	return(&mons[first]);
1966. }
1967. 
1968. /* Called by mkclass() - returns the pm of the monster 
1969.  * Returns -1 (PM_PLAYERMON) if can't find monster of the class
1970.  *
1971.  * spc may have G_UNIQ and/or G_NOGEN set to allow monsters of
1972.  * this type (otherwise they will be ignored). It may also have
1973.  * MKC_ULIMIT set to place an upper limit on the difficulty of
1974.  * the monster returned.
1975.  */
1976. int
1977. pm_mkclass(class,spc)
1978. char    class;
1979. int     spc;
1980. {
1981. 	register int	first, last, num = 0;
1982. 	int maxmlev, mask = (G_NOGEN | G_UNIQ) & ~spc;
1983. 
1984. 	maxmlev = level_difficulty() >> 1;
1985. 	if(class < 1 || class >= MAXMCLASSES) {
1986. 	    impossible("mkclass called with bad class!");
1987. 	    return(-1);
1988. 	}
1989. /*	Assumption #1:	monsters of a given class are contiguous in the
1990.  *			mons[] array.
1991.  */
1992. 	for (first = LOW_PM; first < SPECIAL_PM; first++)
1993. 	    if (mons[first].mlet == class) break;
1994. 	if (first == SPECIAL_PM) return (-1);
1995. 
1996. 	for (last = first;
1997. 		last < SPECIAL_PM && mons[last].mlet == class; last++)
1998. 	    if (!(mvitals[last].mvflags & G_GONE) && !(mons[last].geno & mask)
1999. 					&& !is_placeholder(&mons[last])) {
2000. 		/* consider it */
2001. 		if(spc & MKC_ULIMIT && toostrong(last, 4 * maxmlev)) break;
2002. 		if(num && toostrong(last, maxmlev) &&
2003. 		   monstr[last] != monstr[last-1] && rn2(2)) break;
2004. 		num += mons[last].geno & G_FREQ;
2005. 	    }
2006. 
2007. 	if(!num) return(-1);
2008. 
2009. /*	Assumption #2:	monsters of a given class are presented in ascending
2010.  *			order of strength.
2011.  */
2012. 	for(num = rnd(num); num > 0; first++)
2013. 	    if (!(mvitals[first].mvflags & G_GONE) && !(mons[first].geno & mask)
2014. 					&& !is_placeholder(&mons[first])) {
2015. 		/* skew towards lower value monsters at lower exp. levels */
2016. 		num -= mons[first].geno & G_FREQ;
2017. 		if (num && adj_lev(&mons[first]) > (u.ulevel*2)) {
2018. 		    /* but not when multiple monsters are same level */
2019. 		    if (mons[first].mlevel != mons[first+1].mlevel)
2020. 			num--;
2021. 		}
2022. 	    }
2023. 	first--; /* correct an off-by-one error */
2024. 
2025. 	return(first);
2026. }
2027. 
2028. int
2029. adj_lev(ptr)	/* adjust strength of monsters based on u.uz and u.ulevel */
2030. register struct permonst *ptr;
2031. {
2032. 	int	tmp, tmp2;
2033. 
2034. 	if (ptr == &mons[PM_WIZARD_OF_YENDOR]) {
2035. 		/* does not depend on other strengths, but does get stronger
2036. 		 * every time he is killed
2037. 		 */
2038. 		tmp = ptr->mlevel + mvitals[PM_WIZARD_OF_YENDOR].died;
2039. 		if (tmp > 49) tmp = 49;
2040. 		return tmp;
2041. 	}
2042. 
2043. 	if((tmp = ptr->mlevel) > 49) return(50); /* "special" demons/devils */
2044. 	tmp2 = (level_difficulty() - tmp);
2045. 	if(tmp2 < 0) tmp--;		/* if mlevel > u.uz decrement tmp */
2046. 	else tmp += (tmp2 / 5);		/* else increment 1 per five diff */
2047. 
2048. 	tmp2 = (u.ulevel - ptr->mlevel);	/* adjust vs. the player */
2049. 	if(tmp2 > 0) tmp += (tmp2 / 4);		/* level as well */
2050. 
2051. 	tmp2 = (3 * ((int) ptr->mlevel))/ 2;	/* crude upper limit */
2052. 	if (tmp2 > 49) tmp2 = 49;		/* hard upper limit */
2053. 	return((tmp > tmp2) ? tmp2 : (tmp > 0 ? tmp : 0)); /* 0 lower limit */
2054. }
2055. 
2056. #endif /* OVL1 */
2057. #ifdef OVLB
2058. 
2059. struct permonst *
2060. grow_up(mtmp, victim)	/* `mtmp' might "grow up" into a bigger version */
2061. struct monst *mtmp, *victim;
2062. {
2063. 	int oldtype, newtype, max_increase, cur_increase,
2064. 	    lev_limit, hp_threshold;
2065. 	struct permonst *ptr = mtmp->data;
2066. 
2067. 	/* monster died after killing enemy but before calling this function */
2068. 	/* currently possible if killing a gas spore */
2069. 	if (mtmp->mhp <= 0)
2070. 	    return ((struct permonst *)0);
2071. 
2072. 	if (mtmp->oldmonnm != monsndx(ptr))
2073. 	    return ptr;		/* No effect if polymorphed */
2074. 
2075. 	/* note:  none of the monsters with special hit point calculations
2076. 	   have both little and big forms */
2077. 	oldtype = monsndx(ptr);
2078. 	newtype = little_to_big(oldtype);
2079. 	if (newtype == PM_PRIEST && mtmp->female) newtype = PM_PRIESTESS;
2080. 
2081. 	/* growth limits differ depending on method of advancement */
2082. 	if (victim) {		/* killed a monster */
2083. 	    /*
2084. 	     * The HP threshold is the maximum number of hit points for the
2085. 	     * current level; once exceeded, a level will be gained.
2086. 	     * Possible bug: if somehow the hit points are already higher
2087. 	     * than that, monster will gain a level without any increase in HP.
2088. 	     */
2089. 	    hp_threshold = mtmp->m_lev * 8;		/* normal limit */
2090. 	    if (!mtmp->m_lev)
2091. 		hp_threshold = 4;
2092. 	    else if (is_golem(ptr))	/* strange creatures */
2093. 		hp_threshold = ((mtmp->mhpmax / 10) + 1) * 10 - 1;
2094. 	    else if (is_home_elemental(ptr))
2095. 		hp_threshold *= 3;
2096. 	    lev_limit = 3 * (int)ptr->mlevel / 2;	/* same as adj_lev() */
2097. 	    /* If they can grow up, be sure the level is high enough for that */
2098. 	    if (oldtype != newtype && mons[newtype].mlevel > lev_limit)
2099. 		lev_limit = (int)mons[newtype].mlevel;
2100. 	    /* number of hit points to gain; unlike for the player, we put
2101. 	       the limit at the bottom of the next level rather than the top */
2102. 	    max_increase = rnd((int)victim->m_lev + 1);
2103. 	    if (mtmp->mhpmax + max_increase > hp_threshold + 1)
2104. 		max_increase = max((hp_threshold + 1) - mtmp->mhpmax, 0);
2105. 	    cur_increase = (max_increase > 1) ? rn2(max_increase) : 0;
2106. 	} else {
2107. 	    /* a gain level potion or wraith corpse; always go up a level
2108. 	       unless already at maximum (49 is hard upper limit except
2109. 	       for demon lords, who start at 50 and can't go any higher) */
2110. 	    max_increase = cur_increase = rnd(8) + rnd(2);
2111. 	    hp_threshold = 0;	/* smaller than `mhpmax + max_increase' */
2112. 	    lev_limit = 50;		/* recalc below */
2113. 	}
2114. 
2115. 	mtmp->mhpmax += max_increase;
2116. 	mtmp->mhp += cur_increase;
2117. 
2118. 	mtmp->m_enmax += max_increase;
2119. 	mtmp->m_en += cur_increase;
2120. 	
2121. 	if (mtmp->mhpmax <= hp_threshold)
2122. 	    return ptr;		/* doesn't gain a level */
2123. 
2124. 	/* Allow to grow up even if grown up form would normally be
2125. 	 * out of range */
2126. 	if (lev_limit < mons[newtype].mlevel)
2127. 	    lev_limit = mons[newtype].mlevel;
2128. 
2129. 	if (is_mplayer(ptr)) lev_limit = 30;    /* same as player */
2130. 	else if (lev_limit < 5) lev_limit = 5;  /* arbitrary */
2131. 	else if (lev_limit > 49) lev_limit = (ptr->mlevel > 49 ? 50 : 49);
2132. 
2133. 	if ((int)++mtmp->m_lev >= mons[newtype].mlevel && newtype != oldtype) {
2134. 	    ptr = &mons[newtype];
2135. 	    if (mvitals[newtype].mvflags & G_GENOD) {	/* allow G_EXTINCT */
2136. 		if (sensemon(mtmp))
2137. 		    pline("As %s grows up into %s, %s %s!", mon_nam(mtmp),
2138. 			an(ptr->mname), mhe(mtmp),
2139. 			nonliving(ptr) ? "expires" : "dies");
2140. 		set_mon_data(mtmp, ptr, -1);	/* keep mvitals[] accurate */
2141. 		mondied(mtmp);
2142. 		return (struct permonst *)0;
2143. 	    }
2144. 	    set_mon_data(mtmp, ptr, 1);		/* preserve intrinsics */
2145. 	    newsym(mtmp->mx, mtmp->my);		/* color may change */
2146. 	    lev_limit = (int)mtmp->m_lev;	/* never undo increment */
2147. 	}
2148. 	/* sanity checks */
2149. 	if ((int)mtmp->m_lev > lev_limit) {
2150. 	    mtmp->m_lev--;	/* undo increment */
2151. 	    /* HP might have been allowed to grow when it shouldn't */
2152. 	    if (mtmp->mhpmax == hp_threshold + 1) mtmp->mhpmax--;
2153. 	}
2154. 	if (mtmp->mhpmax > 50*8) mtmp->mhpmax = 50*8;	  /* absolute limit */
2155. 	if (mtmp->mhp > mtmp->mhpmax) mtmp->mhp = mtmp->mhpmax;
2156. 
2157. 	if (mtmp->m_enmax > 50*8) mtmp->m_enmax = 50*8;     /* absolute limit */
2158. 	if (mtmp->m_en > mtmp->m_enmax) mtmp->m_en = mtmp->m_enmax;
2159. 
2160. 	if (mtmp->oldmonnm != monsndx(ptr)) mtmp->oldmonnm = monsndx(ptr);
2161. 	return ptr;
2162. }
2163. 
2164. #endif /* OVLB */
2165. #ifdef OVL1
2166. 
2167. int
2168. mongets(mtmp, otyp)
2169. register struct monst *mtmp;
2170. register int otyp;
2171. {
2172. 	register struct obj *otmp;
2173. 	int spe;
2174. 
2175. 	if (!otyp) return 0;
2176. 	otmp = mksobj(otyp, TRUE, FALSE);
2177. 	if (otmp) {
2178. 	    if (mtmp->data->mlet == S_DEMON) {
2179. 		/* demons never get blessed objects */
2180. 		if (otmp->blessed) curse(otmp);
2181. 	    } else if(is_lminion(mtmp)) {
2182. 		/* lawful minions don't get cursed, bad, or rusting objects */
2183. 		otmp->cursed = FALSE;
2184. 		if(otmp->spe < 0) otmp->spe = 0;
2185. 		otmp->oerodeproof = TRUE;
2186. 	    } else if(In_endgame(&u.uz) && is_mplayer(mtmp->data) && is_sword(otmp)) {
2187. 		otmp->spe = (3 + rn2(3));
2188. 	    }
2189. /*
2190.  *      This seems to be covered under mkobj.c ...
2191.  *
2192.  *          * STEPHEN WHITE'S NEW CODE *
2193.  *
2194.  *          if ((otmp->otyp == ORCISH_DAGGER      && !rn2(8))  ||
2195.  *              (otmp->otyp == ORCISH_SPEAR       && !rn2(10)) ||
2196.  *              (otmp->otyp == ORCISH_SHORT_SWORD && !rn2(12)))
2197.  *                      otmp->opoisoned = TRUE;
2198.  *
2199.  *           * It could be alread immune to rust ... *
2200.  *          if (!otmp->oerodeproof && !is_rustprone(otmp) &&
2201.  *              ((otmp->otyp >= SPEAR && otmp->otyp <= BULLWHIP) ||
2202.  *               (otmp->otyp >= ELVEN_LEATHER_HELM &&
2203.  *                otmp->otyp <= LEVITATION_BOOTS))) {
2204.  *                   if (!rn2(10-otmp->spe)) otmp->oerodeproof = TRUE;
2205.  *              else if (!rn2(10+otmp->spe)) otmp->oeroded = rn2(3);
2206.  *          }
2207.  */
2208. 
2209. 	    if(otmp->otyp == CANDELABRUM_OF_INVOCATION) {
2210. 		otmp->spe = 0;
2211. 		otmp->age = 0L;
2212. 		otmp->lamplit = FALSE;
2213. 		otmp->blessed = otmp->cursed = FALSE;
2214. 	    } else if (otmp->otyp == BELL_OF_OPENING) {
2215. 		otmp->blessed = otmp->cursed = FALSE;
2216. 	    } else if (otmp->otyp == SPE_BOOK_OF_THE_DEAD) {
2217. 		otmp->blessed = FALSE;
2218. 		otmp->cursed = TRUE;
2219. 	    }
2220. 
2221. 	    /* leaders don't tolerate inferior quality battle gear */
2222. 	    if (is_prince(mtmp->data)) {
2223. 		if (otmp->oclass == WEAPON_CLASS && otmp->spe < 1)
2224. 		    otmp->spe = 1;
2225. 		else if (otmp->oclass == ARMOR_CLASS && otmp->spe < 0)
2226. 		    otmp->spe = 0;
2227. 	    }
2228. 
2229. 	    spe = otmp->spe;
2230. 	    (void) mpickobj(mtmp, otmp);	/* might free otmp */
2231. 	    return(spe);
2232. 	} else return(0);
2233. }
2234. 
2235. #endif /* OVL1 */
2236. #ifdef OVLB
2237. 
2238. int
2239. golemhp(type)
2240. int type;
2241. {
2242. 	switch(type) {
2243. 		case PM_PAPER_GOLEM: return 36;
2244. 		case PM_STRAW_GOLEM: return 40;
2245. 		case PM_GARGOYLE: return 46;
2246. 		case PM_ROPE_GOLEM: return 60;
2247. 		case PM_LEATHER_GOLEM: return 80;
2248. 		case PM_GOLD_GOLEM: return 80;
2249. 		case PM_WOOD_GOLEM: return 100;
2250. 		case PM_FLESH_GOLEM: return 120;
2251. 		case PM_STATUE_GARGOYLE: return 140;
2252. 		case PM_CLAY_GOLEM: return 150;
2253. 		case PM_STONE_GOLEM: return 180;
2254. 		case PM_GLASS_GOLEM: return 140;
2255. 		case PM_IRON_GOLEM: return 240;
2256. 		case PM_RUBY_GOLEM: return 250;
2257. 		case PM_DIAMOND_GOLEM: return 270;
2258. 		case PM_SAPPHIRE_GOLEM: return 280;
2259. 		case PM_STEEL_GOLEM: return 290;
2260. 		case PM_CRYSTAL_GOLEM: return 300;
2261. 		case PM_FRANKENSTEIN_S_MONSTER: return 400;
2262. 		case PM_WAX_GOLEM: return 40;
2263. 		case PM_PLASTIC_GOLEM: return 60;
2264. 		default: return 0;
2265. 	}
2266. }
2267. 
2268. #endif /* OVLB */
2269. #ifdef OVL1
2270. 
2271. /*
2272.  *	Alignment vs. yours determines monster's attitude to you.
2273.  *	( some "animal" types are co-aligned, but also hungry )
2274.  */
2275. 
2276. boolean
2277. peace_minded(ptr)
2278. register struct permonst *ptr;
2279. {
2280. 	aligntyp mal = ptr->maligntyp, ual = u.ualign.type;
2281. 
2282. 	if (always_peaceful(ptr)) return TRUE;
2283. 
2284. 	if (always_hostile(ptr)) return FALSE;
2285. 	if (ptr->msound == MS_LEADER || ptr->msound == MS_GUARDIAN)
2286. 		return TRUE;
2287. 	if (ptr->msound == MS_NEMESIS)	return FALSE;
2288. 
2289. 	if (is_elf(ptr) && is_elf(youmonst.data)) {
2290. 		/* Light and dark elves are always hostile to each other.
2291. 		 * Suggested by Dr. Eva R. Myers.
2292. 		 */
2293. 		 if (ual > A_NEUTRAL && mal < A_NEUTRAL ||
2294. 		   ual < A_NEUTRAL && mal > A_NEUTRAL)
2295. 			return FALSE;
2296. 	}
2297. 
2298. 	if (race_peaceful(ptr)) return TRUE;
2299. 	if (race_hostile(ptr)) return FALSE;
2300. 
2301. 	/* the monster is hostile if its alignment is different from the
2302. 	 * player's */
2303. 	if (sgn(mal) != sgn(ual)) return FALSE;
2304. 
2305. 	/* Negative monster hostile to player with Amulet. */
2306. 	if (mal < A_NEUTRAL && u.uhave.amulet) return FALSE;
2307. 
2308. 	/* minions are hostile to players that have strayed at all */
2309. 	if (is_minion(ptr)) return((boolean)(u.ualign.record >= 0));
2310. 
2311. 	/* Last case:  a chance of a co-aligned monster being
2312. 	 * hostile.  This chance is greater if the player has strayed
2313. 	 * (u.ualign.record negative) or the monster is not strongly aligned.
2314. 	 */
2315. 	return((boolean)(!!rn2(16 + (u.ualign.record < -15 ? -15 : u.ualign.record)) &&
2316. 		!!rn2(2 + abs(mal))));
2317. }
2318. 
2319. /* Set malign to have the proper effect on player alignment if monster is
2320.  * killed.  Negative numbers mean it's bad to kill this monster; positive
2321.  * numbers mean it's good.  Since there are more hostile monsters than
2322.  * peaceful monsters, the penalty for killing a peaceful monster should be
2323.  * greater than the bonus for killing a hostile monster to maintain balance.
2324.  * Rules:
2325.  *   it's bad to kill peaceful monsters, potentially worse to kill always-
2326.  *	peaceful monsters
2327.  *   it's never bad to kill a hostile monster, although it may not be good
2328.  */
2329. void
2330. set_malign(mtmp)
2331. struct monst *mtmp;
2332. {
2333. 	schar mal = mtmp->data->maligntyp;
2334. 	boolean coaligned;
2335. 
2336. 	if (mtmp->ispriest || mtmp->isminion) {
2337. 		/* some monsters have individual alignments; check them */
2338. 		if (mtmp->ispriest)
2339. 			mal = EPRI(mtmp)->shralign;
2340. 		else if (mtmp->isminion)
2341. 			mal = EMIN(mtmp)->min_align;
2342. 		/* unless alignment is none, set mal to -5,0,5 */
2343. 		/* (see align.h for valid aligntyp values)     */
2344. 		if(mal != A_NONE)
2345. 			mal *= 5;
2346. 		/* make priests of Moloch hostile */
2347. 		if (mal == A_NONE) mtmp->mpeaceful = 0;
2348. 	}
2349. 
2350. 
2351. 	coaligned = (sgn(mal) == sgn(u.ualign.type));
2352. 	if (mtmp->data->msound == MS_LEADER) {
2353. 		mtmp->malign = -20;
2354. 	} else if (mal == A_NONE) {
2355. 		if (mtmp->mpeaceful)
2356. 			mtmp->malign = 0;
2357. 		else
2358. 			mtmp->malign = 20;	/* really hostile */
2359. 	} else if (always_peaceful(mtmp->data)) {
2360. 		int absmal = abs(mal);
2361. 		if (mtmp->mpeaceful)
2362. 			mtmp->malign = -3*max(5,absmal);
2363. 		else
2364. 			mtmp->malign = 3*max(5,absmal); /* renegade */
2365. 	} else if (always_hostile(mtmp->data)) {
2366. 		int absmal = abs(mal);
2367. 		if (coaligned)
2368. 			mtmp->malign = 0;
2369. 		else
2370. 			mtmp->malign = max(5,absmal);
2371. 	} else if (coaligned) {
2372. 		int absmal = abs(mal);
2373. 		if (mtmp->mpeaceful)
2374. 			mtmp->malign = -3*max(3,absmal);
2375. 		else	/* renegade */
2376. 			mtmp->malign = max(3,absmal);
2377. 	} else	/* not coaligned and therefore hostile */
2378. 		mtmp->malign = abs(mal);
2379. }
2380. 
2381. #endif /* OVL1 */
2382. #ifdef OVLB
2383. 
2384. static NEARDATA char syms[] = {
2385. 	MAXOCLASSES, MAXOCLASSES+1, RING_CLASS, WAND_CLASS, WEAPON_CLASS,
2386. 	FOOD_CLASS, COIN_CLASS, SCROLL_CLASS, POTION_CLASS, ARMOR_CLASS,
2387. 	AMULET_CLASS, TOOL_CLASS, ROCK_CLASS, GEM_CLASS, SPBOOK_CLASS,
2388. 	S_MIMIC_DEF, S_MIMIC_DEF, S_MIMIC_DEF,
2389. };
2390. 
2391. void
2392. set_mimic_sym(mtmp)		/* KAA, modified by ERS */
2393. register struct monst *mtmp;
2394. {
2395. 	int typ, roomno, rt;
2396. 	unsigned appear, ap_type;
2397. 	int s_sym;
2398. 	struct obj *otmp;
2399. 	int mx, my;
2400. 
2401. 	if (!mtmp) return;
2402. 	mx = mtmp->mx; my = mtmp->my;
2403. 	typ = levl[mx][my].typ;
2404. 					/* only valid for INSIDE of room */
2405. 	roomno = levl[mx][my].roomno - ROOMOFFSET;
2406. 	if (roomno >= 0)
2407. 		rt = rooms[roomno].rtype;
2408. #ifdef SPECIALIZATION
2409. 	else if (IS_ROOM(typ))
2410. 		rt = OROOM,  roomno = 0;
2411. #endif
2412. 	else	rt = 0;	/* roomno < 0 case for GCC_WARN */
2413. 
2414. 	if (OBJ_AT(mx, my)) {
2415. 		ap_type = M_AP_OBJECT;
2416. 		appear = level.objects[mx][my]->otyp;
2417. 	} else if (IS_DOOR(typ) || IS_WALL(typ) ||
2418. 		   typ == SDOOR || typ == SCORR) {
2419. 		ap_type = M_AP_FURNITURE;
2420. 		/*
2421. 		 *  If there is a wall to the left that connects to this
2422. 		 *  location, then the mimic mimics a horizontal closed door.
2423. 		 *  This does not allow doors to be in corners of rooms.
2424. 		 */
2425. 		if (mx != 0 &&
2426. 			(levl[mx-1][my].typ == HWALL    ||
2427. 			 levl[mx-1][my].typ == TLCORNER ||
2428. 			 levl[mx-1][my].typ == TRWALL   ||
2429. 			 levl[mx-1][my].typ == BLCORNER ||
2430. 			 levl[mx-1][my].typ == TDWALL   ||
2431. 			 levl[mx-1][my].typ == CROSSWALL||
2432. 			 levl[mx-1][my].typ == TUWALL    ))
2433. 		    appear = S_hcdoor;
2434. 		else
2435. 		    appear = S_vcdoor;
2436. 
2437. 		if(!mtmp->minvis || See_invisible)
2438. 		    block_point(mx,my);	/* vision */
2439. 	} else if (level.flags.is_maze_lev && rn2(2)) {
2440. 		ap_type = M_AP_OBJECT;
2441. 		appear = STATUE;
2442. 	} else if (roomno < 0) {
2443. 		ap_type = M_AP_OBJECT;
2444. 		appear = BOULDER;
2445. 		if(!mtmp->minvis || See_invisible)
2446. 		    block_point(mx,my);	/* vision */
2447. 	} else if (rt == ZOO || rt == VAULT) {
2448. 		ap_type = M_AP_OBJECT;
2449. 		appear = GOLD_PIECE;
2450. 	} else if (rt == DELPHI) {
2451. 		if (rn2(2)) {
2452. 			ap_type = M_AP_OBJECT;
2453. 			appear = STATUE;
2454. 		} else {
2455. 			ap_type = M_AP_FURNITURE;
2456. 			appear = S_fountain;
2457. 		}
2458. 	} else if (rt == TEMPLE) {
2459. 		ap_type = M_AP_FURNITURE;
2460. 		appear = S_altar;
2461. 	/*
2462. 	 * We won't bother with beehives, morgues, barracks, throne rooms
2463. 	 * since they shouldn't contain too many mimics anyway...
2464. 	 */
2465. 	} else if (rt >= SHOPBASE) {
2466. 		s_sym = get_shop_item(rt - SHOPBASE);
2467. 		if (s_sym < 0) {
2468. 			ap_type = M_AP_OBJECT;
2469. 			appear = -s_sym;
2470. 		} else {
2471. 			if (s_sym == RANDOM_CLASS)
2472. 				s_sym = syms[rn2((int)sizeof(syms)-2) + 2];
2473. 			goto assign_sym;
2474. 		}
2475. 	} else {
2476. 		s_sym = syms[rn2((int)sizeof(syms))];
2477. assign_sym:
2478. 		if (s_sym >= MAXOCLASSES) {
2479. 			ap_type = M_AP_FURNITURE;
2480. 			appear = s_sym == MAXOCLASSES ? S_upstair : S_dnstair;
2481. 		} else if (s_sym == COIN_CLASS) {
2482. 			ap_type = M_AP_OBJECT;
2483. 			appear = GOLD_PIECE;
2484. 		} else {
2485. 			ap_type = M_AP_OBJECT;
2486. 			if (s_sym == S_MIMIC_DEF) {
2487. 				appear = STRANGE_OBJECT;
2488. 			} else {
2489. 				otmp = mkobj( (char) s_sym, FALSE );
2490. 				appear = otmp->otyp;
2491. 				/* make sure container contents are free'ed */
2492. 				if (Has_contents(otmp))
2493. 					delete_contents(otmp);
2494. 				obfree(otmp, (struct obj *) 0);
2495. 			}
2496. 		}
2497. 	}
2498. 	mtmp->m_ap_type = ap_type;
2499. 	mtmp->mappearance = appear;
2500. }
2501. 
2502. /* release a monster from a bag of tricks */
2503. void
2504. bagotricks(bag)
2505. struct obj *bag;
2506. {
2507.     if (!bag || bag->otyp != BAG_OF_TRICKS) {
2508. 	impossible("bad bag o' tricks");
2509.     } else if (bag->spe < 1) {
2510. 	pline(nothing_happens);
2511.     } else {
2512. 	boolean gotone = FALSE;
2513. 	int cnt = 1;
2514. 
2515. 	consume_obj_charge(bag, TRUE);
2516. 
2517. 	if (!rn2(23)) cnt += rn1(7, 1);
2518. 	while (cnt-- > 0) {
2519. 	    if (makemon((struct permonst *)0, u.ux, u.uy, NO_MM_FLAGS))
2520. 		gotone = TRUE;
2521. 	}
2522. 	if (gotone) makeknown(BAG_OF_TRICKS);
2523.     }
2524. }
2525. 
2526. #endif /* OVLB */
2527. 
2528. /*makemon.c*/

Also on Fandom

Random Wiki