Fandom

Wikihack

Source:NetHack 3.3.0/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 NetHack 3.3.0. To link to a particular line, write [[NetHack 3.3.0/makemon.c#line123]], for example.

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

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

Also on Fandom

Random Wiki