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