Source:NetHack 3.4.3/src/monmove.c

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

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

Top of file

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

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

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

  1. #include "hack.h"
  2. #include "mfndpos.h"
  3. #include "artifact.h"
  4. #include "epri.h"
  5.  
  6. extern boolean notonhead;
  7.  
  8. #ifdef OVL0
  9.  
  10. STATIC_DCL int FDECL(disturb,(struct monst *));
  11. STATIC_DCL void FDECL(distfleeck,(struct monst *,int *,int *,int *));
  12. STATIC_DCL int FDECL(m_arrival, (struct monst *));
  13. STATIC_DCL void FDECL(watch_on_duty,(struct monst *));
  14.  
  15. #endif /* OVL0 */
  16. #ifdef OVLB

mb_trapped

  1. boolean /* TRUE : mtmp died */
  2. mb_trapped(mtmp)
  3. register struct monst *mtmp;
  4. {
  5. 	if (flags.verbose) {
  6. 	    if (cansee(mtmp->mx, mtmp->my))
  7. 		pline("KABOOM!!  You see a door explode.");
  8. 	    else if (flags.soundok)
  9. 		You_hear("a distant explosion.");
  10. 	}
  11. 	wake_nearto(mtmp->mx, mtmp->my, 7*7);
  12. 	mtmp->mstun = 1;
  13. 	mtmp->mhp -= rnd(15);
  14. 	if(mtmp->mhp <= 0) {
  15. 		mondied(mtmp);
  16. 		if (mtmp->mhp > 0) /* lifesaved */
  17. 			return(FALSE);
  18. 		else
  19. 			return(TRUE);
  20. 	}
  21. 	return(FALSE);
  22. }
  23.  
  24. #endif /* OVLB */
  25. #ifdef OVL0

watch_on_duty

  1. STATIC_OVL void
  2. watch_on_duty(mtmp)
  3. register struct monst *mtmp;
  4. {
  5. 	int	x, y;
  6.  
  7. 	if(mtmp->mpeaceful && in_town(u.ux+u.dx, u.uy+u.dy) &&
  8. 	   mtmp->mcansee && m_canseeu(mtmp) && !rn2(3)) {
  9.  
  10. 	    if(picking_lock(&x, &y) && IS_DOOR(levl[x][y].typ) &&
  11. 	       (levl[x][y].doormask & D_LOCKED)) {
  12.  
  13. 		if(couldsee(mtmp->mx, mtmp->my)) {
  14.  
  15. 		  pline("%s yells:", Amonnam(mtmp));
  16. 		  if(levl[x][y].looted & D_WARNED) {
  17. 			verbalize("Halt, thief!  You're under arrest!");
  18. 			(void) angry_guards(!(flags.soundok));
  19. 		  } else {
  20. 			verbalize("Hey, stop picking that lock!");
  21. 			levl[x][y].looted |=  D_WARNED;
  22. 		  }
  23. 		  stop_occupation();
  24. 		}
  25. 	    } else if (is_digging()) {
  26. 		/* chewing, wand/spell of digging are checked elsewhere */
  27. 		watch_dig(mtmp, digging.pos.x, digging.pos.y, FALSE);
  28. 	    }
  29. 	}
  30. }
  31.  
  32. #endif /* OVL0 */
  33. #ifdef OVL1

dochugw

  1. int
  2. dochugw(mtmp)
  3. 	register struct monst *mtmp;
  4. {
  5. 	register int x = mtmp->mx, y = mtmp->my;
  6. 	boolean already_saw_mon = !occupation ? 0 : canspotmon(mtmp);
  7. 	int rd = dochug(mtmp);
  8. #if 0
  9. 	/* part of the original warning code which was replaced in 3.3.1 */
  10. 	int dd;
  11.  
  12. 	if(Warning && !rd && !mtmp->mpeaceful &&
  13. 			(dd = distu(mtmp->mx,mtmp->my)) < distu(x,y) &&
  14. 			dd < 100 && !canseemon(mtmp)) {
  15. 	    /* Note: this assumes we only want to warn against the monster to
  16. 	     * which the weapon does extra damage, as there is no "monster
  17. 	     * which the weapon warns against" field.
  18. 	     */
  19. 	    if (spec_ability(uwep, SPFX_WARN) && spec_dbon(uwep, mtmp, 1))
  20. 		warnlevel = 100;
  21. 	    else if ((int) (mtmp->m_lev / 4) > warnlevel)
  22. 		warnlevel = (mtmp->m_lev / 4);
  23. 	}
  24. #endif /* 0 */
  25.  
  26. 	/* a similar check is in monster_nearby() in hack.c */
  27. 	/* check whether hero notices monster and stops current activity */
  28. 	if (occupation && !rd && !Confusion &&
  29. 	    (!mtmp->mpeaceful || Hallucination) &&
  30. 	    /* it's close enough to be a threat */
  31. 	    distu(mtmp->mx,mtmp->my) <= (BOLT_LIM+1)*(BOLT_LIM+1) &&
  32. 	    /* and either couldn't see it before, or it was too far away */
  33. 	    (!already_saw_mon || !couldsee(x,y) ||
  34. 		distu(x,y) > (BOLT_LIM+1)*(BOLT_LIM+1)) &&
  35. 	    /* can see it now, or sense it and would normally see it */
  36. 	    (canseemon(mtmp) ||
  37. 		(sensemon(mtmp) && couldsee(mtmp->mx,mtmp->my))) &&
  38. 	    mtmp->mcanmove &&
  39. 	    !noattacks(mtmp->data) && !onscary(u.ux, u.uy, mtmp))
  40. 		stop_occupation();
  41.  
  42. 	return(rd);
  43. }
  44.  
  45. #endif /* OVL1 */
  46. #ifdef OVL2

onscary

  1. boolean
  2. onscary(x, y, mtmp)
  3. int x, y;
  4. struct monst *mtmp;
  5. {
  6. 	if (mtmp->isshk || mtmp->isgd || mtmp->iswiz || !mtmp->mcansee ||
  7. 	    mtmp->mpeaceful || mtmp->data->mlet == S_HUMAN ||
  8. 	    is_lminion(mtmp) || mtmp->data == &mons[PM_ANGEL] ||
  9. 	    is_rider(mtmp->data) || mtmp->data == &mons[PM_MINOTAUR])
  10. 		return(FALSE);
  11.  
  12. 	return (boolean)(sobj_at(SCR_SCARE_MONSTER, x, y)
  13. #ifdef ELBERETH
  14. 			 || sengr_at("Elbereth", x, y)
  15. #endif
  16. 			 || (mtmp->data->mlet == S_VAMPIRE
  17. 			     && IS_ALTAR(levl[x][y].typ)));
  18. }
  19.  
  20. #endif /* OVL2 */
  21. #ifdef OVL0

mon_regen

  1. /* regenerate lost hit points */
  2. void
  3. mon_regen(mon, digest_meal)
  4. struct monst *mon;
  5. boolean digest_meal;
  6. {
  7. 	if (mon->mhp < mon->mhpmax &&
  8. 	    (moves % 20 == 0 || regenerates(mon->data))) mon->mhp++;
  9. 	if (mon->mspec_used) mon->mspec_used--;
  10. 	if (digest_meal) {
  11. 	    if (mon->meating) mon->meating--;
  12. 	}
  13. }

disturb

  1. /*
  2. * Possibly awaken the given monster.  Return a 1 if the monster has been
  3. * jolted awake.
  4. */
  5. STATIC_OVL int
  6. disturb(mtmp)
  7. 	register struct monst *mtmp;
  8. {
  9. 	/*
  10. 	 * + Ettins are hard to surprise.

This is from Dungeons & Dragons, where ettins have two heads (and so presumably can see anyone sneaking up on them).

  1. 	 * + Nymphs, jabberwocks, and leprechauns do not easily wake up.
  2. 	 *
  3. 	 * Wake up if:
  4. 	 *	in direct LOS						AND
  5. 	 *	within 10 squares					AND
  6. 	 *	not stealthy or (mon is an ettin and 9/10)		AND
  7. 	 *	(mon is not a nymph, jabberwock, or leprechaun) or 1/50	AND
  8. 	 *	Aggravate or mon is (dog or human) or
  9. 	 *	    (1/7 and mon is not mimicing furniture or object)
  10. 	 */
  11. 	if(couldsee(mtmp->mx,mtmp->my) &&
  12. 		distu(mtmp->mx,mtmp->my) <= 100 &&
  13. 		(!Stealth || (mtmp->data == &mons[PM_ETTIN] && rn2(10))) &&

The 9-in-10 chance of an ettin waking up is also taken directly from D&D.

  1. 		(!(mtmp->data->mlet == S_NYMPH
  2. 			|| mtmp->data == &mons[PM_JABBERWOCK]
  3. #if 0	/* DEFERRED */
  4. 			|| mtmp->data == &mons[PM_VORPAL_JABBERWOCK]
  5. #endif
  6. 			|| mtmp->data->mlet == S_LEPRECHAUN) || !rn2(50)) &&
  7. 		(Aggravate_monster
  8. 			|| (mtmp->data->mlet == S_DOG ||
  9. 				mtmp->data->mlet == S_HUMAN)
  10. 			|| (!rn2(7) && mtmp->m_ap_type != M_AP_FURNITURE &&
  11. 				mtmp->m_ap_type != M_AP_OBJECT) )) {
  12. 		mtmp->msleeping = 0;
  13. 		return(1);
  14. 	}
  15. 	return(0);
  16. }

monflee

  1. /* monster begins fleeing for the specified time, 0 means untimed flee
  2. * if first, only adds fleetime if monster isn't already fleeing
  3. * if fleemsg, prints a message about new flight, otherwise, caller should */
  4. void
  5. monflee(mtmp, fleetime, first, fleemsg)
  6. struct monst *mtmp;
  7. int fleetime;
  8. boolean first;
  9. boolean fleemsg;
  10. {
  11. 	if (u.ustuck == mtmp) {
  12. 	    if (u.uswallow)
  13. 		expels(mtmp, mtmp->data, TRUE);
  14. 	    else if (!sticks(youmonst.data)) {
  15. 		unstuck(mtmp);	/* monster lets go when fleeing */
  16. 		You("get released!");
  17. 	    }
  18. 	}
  19.  
  20. 	if (!first || !mtmp->mflee) {
  21. 	    /* don't lose untimed scare */
  22. 	    if (!fleetime)
  23. 		mtmp->mfleetim = 0;
  24. 	    else if (!mtmp->mflee || mtmp->mfleetim) {
  25. 		fleetime += mtmp->mfleetim;
  26. 		/* ensure monster flees long enough to visibly stop fighting */
  27. 		if (fleetime == 1) fleetime++;
  28. 		mtmp->mfleetim = min(fleetime, 127);
  29. 	    }
  30. 	    if (!mtmp->mflee && fleemsg && canseemon(mtmp) && !mtmp->mfrozen)
  31. 		pline("%s turns to flee!", (Monnam(mtmp)));
  32. 	    mtmp->mflee = 1;
  33. 	}
  34. }

distfleeck

  1. STATIC_OVL void
  2. distfleeck(mtmp,inrange,nearby,scared)
  3. register struct monst *mtmp;
  4. int *inrange, *nearby, *scared;
  5. {
  6. 	int seescaryx, seescaryy;
  7.  
  8. 	*inrange = (dist2(mtmp->mx, mtmp->my, mtmp->mux, mtmp->muy) <=
  9. 							(BOLT_LIM * BOLT_LIM));
  10. 	*nearby = *inrange && monnear(mtmp, mtmp->mux, mtmp->muy);
  11.  
  12. 	/* Note: if your image is displaced, the monster sees the Elbereth
  13. 	 * at your displaced position, thus never attacking your displaced
  14. 	 * position, but possibly attacking you by accident.  If you are
  15. 	 * invisible, it sees the Elbereth at your real position, thus never
  16. 	 * running into you by accident but possibly attacking the spot
  17. 	 * where it guesses you are.
  18. 	 */
  19. 	if (!mtmp->mcansee || (Invis && !perceives(mtmp->data))) {
  20. 		seescaryx = mtmp->mux;
  21. 		seescaryy = mtmp->muy;
  22. 	} else {
  23. 		seescaryx = u.ux;
  24. 		seescaryy = u.uy;
  25. 	}
  26. 	*scared = (*nearby && (onscary(seescaryx, seescaryy, mtmp) ||
  27. 			       (!mtmp->mpeaceful &&
  28. 				    in_your_sanctuary(mtmp, 0, 0))));
  29.  
  30. 	if(*scared) {
  31. 		if (rn2(7))
  32. 		    monflee(mtmp, rnd(10), TRUE, TRUE);
  33. 		else
  34. 		    monflee(mtmp, rnd(100), TRUE, TRUE);
  35. 	}
  36.  
  37. }

m_arrival

  1. /* perform a special one-time action for a monster; returns -1 if nothing
  2. special happened, 0 if monster uses up its turn, 1 if monster is killed */
  3. STATIC_OVL int
  4. m_arrival(mon)
  5. struct monst *mon;
  6. {
  7. 	mon->mstrategy &= ~STRAT_ARRIVE;	/* always reset */
  8.  
  9. 	return -1;
  10. }

dochug

  1. /* returns 1 if monster died moving, 0 otherwise */
  2. /* The whole dochugw/m_move/distfleeck/mfndpos section is serious spaghetti
  3. * code. --KAA
  4. */
  5. int
  6. dochug(mtmp)
  7. register struct monst *mtmp;
  8. {
  9. 	register struct permonst *mdat;
  10. 	register int tmp=0;
  11. 	int inrange, nearby, scared;
  12. #ifdef GOLDOBJ
  13. struct obj *ygold = 0, *lepgold = 0;
  14. #endif
  15.  
  16. /*	Pre-movement adjustments	*/
  17.  
  18. 	mdat = mtmp->data;
  19.  
  20. 	if (mtmp->mstrategy & STRAT_ARRIVE) {
  21. 	    int res = m_arrival(mtmp);
  22. 	    if (res >= 0) return res;
  23. 	}
  24.  
  25. 	/* check for waitmask status change */
  26. 	if ((mtmp->mstrategy & STRAT_WAITFORU) &&
  27. 		(m_canseeu(mtmp) || mtmp->mhp < mtmp->mhpmax))
  28. 	    mtmp->mstrategy &= ~STRAT_WAITFORU;
  29.  
  30. 	/* update quest status flags */
  31. 	quest_stat_check(mtmp);
  32.  
  33. 	if (!mtmp->mcanmove || (mtmp->mstrategy & STRAT_WAITMASK)) {
  34. 	    if (Hallucination) newsym(mtmp->mx,mtmp->my);
  35. 	    if (mtmp->mcanmove && (mtmp->mstrategy & STRAT_CLOSE) &&
  36. 	       !mtmp->msleeping && monnear(mtmp, u.ux, u.uy))
  37. 		quest_talk(mtmp);	/* give the leaders a chance to speak */
  38. 	    return(0);	/* other frozen monsters can't do anything */
  39. 	}
  40.  
  41. 	/* there is a chance we will wake it */
  42. 	if (mtmp->msleeping && !disturb(mtmp)) {
  43. 		if (Hallucination) newsym(mtmp->mx,mtmp->my);
  44. 		return(0);
  45. 	}
  46.  
  47. 	/* not frozen or sleeping: wipe out texts written in the dust */
  48. 	wipe_engr_at(mtmp->mx, mtmp->my, 1);
  49.  
  50. 	/* confused monsters get unconfused with small probability */
  51. 	if (mtmp->mconf && !rn2(50)) mtmp->mconf = 0;
  52.  
  53. 	/* stunned monsters get un-stunned with larger probability */
  54. 	if (mtmp->mstun && !rn2(10)) mtmp->mstun = 0;
  55.  
  56. 	/* some monsters teleport */
  57. 	if (mtmp->mflee && !rn2(40) && can_teleport(mdat) && !mtmp->iswiz &&
  58. 	    !level.flags.noteleport) {
  59. 		(void) rloc(mtmp, FALSE);
  60. 		return(0);
  61. 	}
  62. 	if (mdat->msound == MS_SHRIEK && !um_dist(mtmp->mx, mtmp->my, 1))
  63. 	    m_respond(mtmp);
  64. 	if (mdat == &mons[PM_MEDUSA] && couldsee(mtmp->mx, mtmp->my))
  65. 	    m_respond(mtmp);
  66. 	if (mtmp->mhp <= 0) return(1); /* m_respond gaze can kill medusa */
  67.  
  68. 	/* fleeing monsters might regain courage */
  69. 	if (mtmp->mflee && !mtmp->mfleetim
  70. 	   && mtmp->mhp == mtmp->mhpmax && !rn2(25)) mtmp->mflee = 0;
  71.  
  72. 	set_apparxy(mtmp);
  73. 	/* Must be done after you move and before the monster does.  The
  74. 	 * set_apparxy() call in m_move() doesn't suffice since the variables
  75. 	 * inrange, etc. all depend on stuff set by set_apparxy().
  76. 	 */
  77.  
  78. 	/* Monsters that want to acquire things */
  79. 	/* may teleport, so do it before inrange is set */
  80. 	if(is_covetous(mdat)) (void) tactics(mtmp);
  81.  
  82. 	/* check distance and scariness of attacks */
  83. 	distfleeck(mtmp,&inrange,&nearby,&scared);
  84.  
  85. 	if(find_defensive(mtmp)) {
  86. 		if (use_defensive(mtmp) != 0)
  87. 			return 1;
  88. 	} else if(find_misc(mtmp)) {
  89. 		if (use_misc(mtmp) != 0)
  90. 			return 1;
  91. 	}
  92.  
  93. 	/* Demonic Blackmail! */
  94. 	if(nearby && mdat->msound == MS_BRIBE &&
  95. 	   mtmp->mpeaceful && !mtmp->mtame && !u.uswallow) {
  96. 		if (mtmp->mux != u.ux || mtmp->muy != u.uy) {
  97. 			pline("%s whispers at thin air.",
  98. 			    cansee(mtmp->mux, mtmp->muy) ? Monnam(mtmp) : "It");
  99.  
  100. 			if (is_demon(youmonst.data)) {
  101. 			  /* "Good hunting, brother" */
  102. 			    if (!tele_restrict(mtmp)) (void) rloc(mtmp, FALSE);
  103. 			} else {
  104. 			    mtmp->minvis = mtmp->perminvis = 0;
  105. 			    /* Why?  For the same reason in real demon talk */
  106. 			    pline("%s gets angry!", Amonnam(mtmp));
  107. 			    mtmp->mpeaceful = 0;
  108. 			    /* since no way is an image going to pay it off */
  109. 			}
  110. 		} else if(demon_talk(mtmp)) return(1);	/* you paid it off */
  111. 	}
  112.  
  113. 	/* the watch will look around and see if you are up to no good :-) */
  114. 	if (mdat == &mons[PM_WATCHMAN] || mdat == &mons[PM_WATCH_CAPTAIN])
  115. 		watch_on_duty(mtmp);
  116.  
  117. 	else if (is_mind_flayer(mdat) && !rn2(20)) {
  118. 		struct monst *m2, *nmon = (struct monst *)0;
  119.  
  120. 		if (canseemon(mtmp))
  121. 			pline("%s concentrates.", Monnam(mtmp));
  122. 		if (distu(mtmp->mx, mtmp->my) > BOLT_LIM * BOLT_LIM) {
  123. 			You("sense a faint wave of psychic energy.");
  124. 			goto toofar;
  125. 		}
  126. 		pline("A wave of psychic energy pours over you!");
  127. 		if (mtmp->mpeaceful &&
  128. 		    (!Conflict || resist(mtmp, RING_CLASS, 0, 0)))
  129. 			pline("It feels quite soothing.");
  130. 		else {
  131. 			register boolean m_sen = sensemon(mtmp);
  132.  
  133. 			if (m_sen || (Blind_telepat && rn2(2)) || !rn2(10)) {
  134. 				int dmg;
  135. 				pline("It locks on to your %s!",
  136. 					m_sen ? "telepathy" :
  137. 					Blind_telepat ? "latent telepathy" : "mind");
  138. 				dmg = rnd(15);
  139. 				if (Half_spell_damage) dmg = (dmg+1) / 2;
  140. 				losehp(dmg, "psychic blast", KILLED_BY_AN);
  141. 			}
  142. 		}
  143. 		for(m2=fmon; m2; m2 = nmon) {
  144. 			nmon = m2->nmon;
  145. 			if (DEADMONSTER(m2)) continue;
  146. 			if (m2->mpeaceful == mtmp->mpeaceful) continue;
  147. 			if (mindless(m2->data)) continue;
  148. 			if (m2 == mtmp) continue;
  149. 			if ((telepathic(m2->data) &&
  150. 			    (rn2(2) || m2->mblinded)) || !rn2(10)) {
  151. 				if (cansee(m2->mx, m2->my))
  152. 				    pline("It locks on to %s.", mon_nam(m2));
  153. 				m2->mhp -= rnd(15);
  154. 				if (m2->mhp <= 0)
  155. 				    monkilled(m2, "", AD_DRIN);
  156. 				else
  157. 				    m2->msleeping = 0;
  158. 			}
  159. 		}
  160. 	}
  161. toofar:
  162.  
  163. 	/* If monster is nearby you, and has to wield a weapon, do so.   This
  164. 	 * costs the monster a move, of course.
  165. 	 */
  166. 	if((!mtmp->mpeaceful || Conflict) && inrange &&
  167. 	   dist2(mtmp->mx, mtmp->my, mtmp->mux, mtmp->muy) <= 8
  168. 	   && attacktype(mdat, AT_WEAP)) {
  169. 	    struct obj *mw_tmp;
  170.  
  171. 	    /* The scared check is necessary.  Otherwise a monster that is
  172. 	     * one square near the player but fleeing into a wall would keep	
  173. 	     * switching between pick-axe and weapon.  If monster is stuck
  174. 	     * in a trap, prefer ranged weapon (wielding is done in thrwmu).
  175. 	     * This may cost the monster an attack, but keeps the monster
  176. 	     * from switching back and forth if carrying both.
  177. 	     */
  178. 	    mw_tmp = MON_WEP(mtmp);
  179. 	    if (!(scared && mw_tmp && is_pick(mw_tmp)) &&
  180. 		mtmp->weapon_check == NEED_WEAPON &&
  181. 		!(mtmp->mtrapped && !nearby && select_rwep(mtmp))) {
  182. 		mtmp->weapon_check = NEED_HTH_WEAPON;
  183. 		if (mon_wield_item(mtmp) != 0) return(0);
  184. 	    }
  185. 	}
  186.  
  187. /*	Now the actual movement phase	*/
  188.  
  189. #ifndef GOLDOBJ
  190. 	if(!nearby || mtmp->mflee || scared ||
  191. 	   mtmp->mconf || mtmp->mstun || (mtmp->minvis && !rn2(3)) ||
  192. 	   (mdat->mlet == S_LEPRECHAUN && !u.ugold && (mtmp->mgold || rn2(2))) ||
  193. #else
  194. if (mdat->mlet == S_LEPRECHAUN) {
  195. 	    ygold = findgold(invent);
  196. 	    lepgold = findgold(mtmp->minvent);
  197. 	}
  198.  
  199. 	if(!nearby || mtmp->mflee || scared ||
  200. 	   mtmp->mconf || mtmp->mstun || (mtmp->minvis && !rn2(3)) ||
  201. 	   (mdat->mlet == S_LEPRECHAUN && !ygold && (lepgold || rn2(2))) ||
  202. #endif
  203. 	   (is_wanderer(mdat) && !rn2(4)) || (Conflict && !mtmp->iswiz) ||
  204. 	   (!mtmp->mcansee && !rn2(4)) || mtmp->mpeaceful) {
  205. 		/* Possibly cast an undirected spell if not attacking you */
  206. 		/* note that most of the time castmu() will pick a directed
  207. 		   spell and do nothing, so the monster moves normally */
  208. 		/* arbitrary distance restriction to keep monster far away
  209. 		   from you from having cast dozens of sticks-to-snakes
  210. 		   or similar spells by the time you reach it */
  211. 		if (dist2(mtmp->mx, mtmp->my, u.ux, u.uy) <= 49 && !mtmp->mspec_used) {
  212. 		    struct attack *a;
  213.  
  214. 		    for (a = &mdat->mattk[0]; a < &mdat->mattk[NATTK]; a++) {
  215. 			if (a->aatyp == AT_MAGC && (a->adtyp == AD_SPEL || a->adtyp == AD_CLRC)) {
  216. 			    if (castmu(mtmp, a, FALSE, FALSE)) {
  217. 				tmp = 3;
  218. 				break;
  219. 			    }
  220. 			}
  221. 		    }
  222. 		}
  223.  
  224. 		tmp = m_move(mtmp, 0);
  225. 		distfleeck(mtmp,&inrange,&nearby,&scared);	/* recalc */
  226.  
  227. 		switch (tmp) {
  228. 		    case 0:	/* no movement, but it can still attack you */
  229. 		    case 3:	/* absolutely no movement */
  230. 				/* for pets, case 0 and 3 are equivalent */
  231. 			/* vault guard might have vanished */
  232. 			if (mtmp->isgd && (mtmp->mhp < 1 ||
  233. 					    (mtmp->mx == 0 && mtmp->my == 0)))
  234. 			    return 1;	/* behave as if it died */
  235. 			/* During hallucination, monster appearance should
  236. 			 * still change - even if it doesn't move.
  237. 			 */
  238. 			if(Hallucination) newsym(mtmp->mx,mtmp->my);
  239. 			break;
  240. 		    case 1:	/* monster moved */
  241. 			/* Maybe it stepped on a trap and fell asleep... */
  242. 			if (mtmp->msleeping || !mtmp->mcanmove) return(0);
  243. 			if(!nearby &&
  244. 			  (ranged_attk(mdat) || find_offensive(mtmp)))
  245. 			    break;
  246. 			else if(u.uswallow && mtmp == u.ustuck) {
  247. 			    /* a monster that's digesting you can move at the
  248. 			     * same time -dlc
  249. 			     */
  250. 			    return(mattacku(mtmp));
  251. 			} else
  252. 				return(0);
  253. 			/*NOTREACHED*/
  254. 			break;
  255. 		    case 2:	/* monster died */
  256. 			return(1);
  257. 		}
  258. 	}
  259.  
  260. /*	Now, attack the player if possible - one attack set per monst	*/
  261.  
  262. 	if (!mtmp->mpeaceful ||
  263. 	    (Conflict && !resist(mtmp, RING_CLASS, 0, 0))) {
  264. 	    if(inrange && !noattacks(mdat) && u.uhp > 0 && !scared && tmp != 3)
  265. 		if(mattacku(mtmp)) return(1); /* monster died (e.g. exploded) */
  266.  
  267. 	    if(mtmp->wormno) wormhitu(mtmp);
  268. 	}
  269. 	/* special speeches for quest monsters */
  270. 	if (!mtmp->msleeping && mtmp->mcanmove && nearby)
  271. 	    quest_talk(mtmp);
  272. 	/* extra emotional attack for vile monsters */
  273. 	if (inrange && mtmp->data->msound == MS_CUSS && !mtmp->mpeaceful &&
  274. 		couldsee(mtmp->mx, mtmp->my) && !mtmp->minvis && !rn2(5))
  275. 	    cuss(mtmp);
  276.  
  277. 	return(tmp == 2);
  278. }
  279.  
  280. static NEARDATA const char practical[] = { WEAPON_CLASS, ARMOR_CLASS, GEM_CLASS, FOOD_CLASS, 0 };
  281. static NEARDATA const char magical[] = {
  282. 	AMULET_CLASS, POTION_CLASS, SCROLL_CLASS, WAND_CLASS, RING_CLASS,
  283. 	SPBOOK_CLASS, 0 };
  284. static NEARDATA const char indigestion[] = { BALL_CLASS, ROCK_CLASS, 0 };
  285. static NEARDATA const char boulder_class[] = { ROCK_CLASS, 0 };
  286. static NEARDATA const char gem_class[] = { GEM_CLASS, 0 };

itsstuck

  1. boolean
  2. itsstuck(mtmp)
  3. register struct monst *mtmp;
  4. {
  5. 	if (sticks(youmonst.data) && mtmp==u.ustuck && !u.uswallow) {
  6. 		pline("%s cannot escape from you!", Monnam(mtmp));
  7. 		return(TRUE);
  8. 	}
  9. 	return(FALSE);
  10. }

m_move

  1. /* Return values:
  2. * 0: did not move, but can still attack and do other stuff.
  3. * 1: moved, possibly can attack.
  4. * 2: monster died.
  5. * 3: did not move, and can't do anything else either.
  6. */
  7. int
  8. m_move(mtmp, after)
  9. register struct monst *mtmp;
  10. register int after;
  11. {
  12. 	register int appr;
  13. 	xchar gx,gy,nix,niy,chcnt;
  14. 	int chi;	/* could be schar except for stupid Sun-2 compiler */
  15. 	boolean likegold=0, likegems=0, likeobjs=0, likemagic=0, conceals=0;
  16. 	boolean likerock=0, can_tunnel=0;
  17. 	boolean can_open=0, can_unlock=0, doorbuster=0;
  18. 	boolean uses_items=0, setlikes=0;
  19. 	boolean avoid=FALSE;
  20. 	struct permonst *ptr;
  21. 	struct monst *mtoo;
  22. 	schar mmoved = 0;	/* not strictly nec.: chi >= 0 will do */
  23. 	long info[9];
  24. 	long flag;
  25. 	int  omx = mtmp->mx, omy = mtmp->my;
  26. 	struct obj *mw_tmp;
  27.  
  28. 	if(mtmp->mtrapped) {
  29. 	    int i = mintrap(mtmp);
  30. 	    if(i >= 2) { newsym(mtmp->mx,mtmp->my); return(2); }/* it died */
  31. 	    if(i == 1) return(0);	/* still in trap, so didn't move */
  32. 	}
  33. 	ptr = mtmp->data; /* mintrap() can change mtmp->data -dlc */
  34.  
  35. 	if (mtmp->meating) {
  36. 	    mtmp->meating--;
  37. 	    return 3;			/* still eating */
  38. 	}
  39. 	if (hides_under(ptr) && OBJ_AT(mtmp->mx, mtmp->my) && rn2(10))
  40. 	    return 0;		/* do not leave hiding place */
  41.  
  42. 	set_apparxy(mtmp);
  43. 	/* where does mtmp think you are? */
  44. 	/* Not necessary if m_move called from this file, but necessary in
  45. 	 * other calls of m_move (ex. leprechauns dodging)
  46. 	 */
  47. #ifdef REINCARNATION
  48. 	if (!Is_rogue_level(&u.uz))
  49. #endif
  50. 	    can_tunnel = tunnels(ptr);
  51. 	can_open = !(nohands(ptr) || verysmall(ptr));
  52. 	can_unlock = ((can_open && m_carrying(mtmp, SKELETON_KEY)) ||
  53. 		      mtmp->iswiz || is_rider(ptr));
  54. 	doorbuster = is_giant(ptr);
  55. 	if(mtmp->wormno) goto not_special;
  56. 	/* my dog gets special treatment */
  57. 	if(mtmp->mtame) {
  58. 	    mmoved = dog_move(mtmp, after);
  59. 	    goto postmov;
  60. 	}
  61.  
  62. 	/* likewise for shopkeeper */
  63. 	if(mtmp->isshk) {
  64. 	    mmoved = shk_move(mtmp);
  65. 	    if(mmoved == -2) return(2);
  66. 	    if(mmoved >= 0) goto postmov;
  67. 	    mmoved = 0;		/* follow player outside shop */
  68. 	}
  69.  
  70. 	/* and for the guard */
  71. 	if(mtmp->isgd) {
  72. 	    mmoved = gd_move(mtmp);
  73. 	    if(mmoved == -2) return(2);
  74. 	    if(mmoved >= 0) goto postmov;
  75. 	    mmoved = 0;
  76. 	}
  77.  
  78. 	/* and the acquisitive monsters get special treatment */
  79. 	if(is_covetous(ptr)) {
  80. 	    xchar tx = STRAT_GOALX(mtmp->mstrategy),
  81. 		  ty = STRAT_GOALY(mtmp->mstrategy);
  82. 	    struct monst *intruder = m_at(tx, ty);
  83. 	    /*
  84. 	     * if there's a monster on the object or in possesion of it,
  85. 	     * attack it.
  86. 	     */
  87. 	    if((dist2(mtmp->mx, mtmp->my, tx, ty) < 2) &&
  88. 	       intruder && (intruder != mtmp)) {
  89.  
  90. 		notonhead = (intruder->mx != tx || intruder->my != ty);
  91. 		if(mattackm(mtmp, intruder) == 2) return(2);
  92. 		mmoved = 1;
  93. 	    } else mmoved = 0;
  94. 	    goto postmov;
  95. 	}
  96.  
  97. 	/* and for the priest */
  98. 	if(mtmp->ispriest) {
  99. 	    mmoved = pri_move(mtmp);
  100. 	    if(mmoved == -2) return(2);
  101. 	    if(mmoved >= 0) goto postmov;
  102. 	    mmoved = 0;
  103. 	}
  104.  
  105. #ifdef MAIL
  106. 	if(ptr == &mons[PM_MAIL_DAEMON]) {
  107. 	    if(flags.soundok && canseemon(mtmp))
  108. 		verbalize("I'm late!");
  109. 	    mongone(mtmp);
  110. 	    return(2);
  111. 	}
  112. #endif
  113.  
  114. 	/* teleport if that lies in our nature */
  115. 	if(ptr == &mons[PM_TENGU] && !rn2(5) && !mtmp->mcan &&
  116. 	   !tele_restrict(mtmp)) {
  117. 	    if(mtmp->mhp < 7 || mtmp->mpeaceful || rn2(2))
  118. 		(void) rloc(mtmp, FALSE);
  119. 	    else
  120. 		mnexto(mtmp);
  121. 	    mmoved = 1;
  122. 	    goto postmov;
  123. 	}
  124. not_special:
  125. 	if(u.uswallow && !mtmp->mflee && u.ustuck != mtmp) return(1);
  126. 	omx = mtmp->mx;
  127. 	omy = mtmp->my;
  128. 	gx = mtmp->mux;
  129. 	gy = mtmp->muy;
  130. 	appr = mtmp->mflee ? -1 : 1;
  131. 	if (mtmp->mconf || (u.uswallow && mtmp == u.ustuck))
  132. 		appr = 0;
  133. 	else {
  134. #ifdef GOLDOBJ
  135. 		struct obj *lepgold, *ygold;
  136. #endif
  137. 		boolean should_see = (couldsee(omx, omy) &&
  138. 				      (levl[gx][gy].lit ||
  139. 				       !levl[omx][omy].lit) &&
  140. 				      (dist2(omx, omy, gx, gy) <= 36));
  141.  
  142. 		if (!mtmp->mcansee ||
  143. 		    (should_see && Invis && !perceives(ptr) && rn2(11)) ||
  144. 		    (youmonst.m_ap_type == M_AP_OBJECT && youmonst.mappearance == STRANGE_OBJECT) || u.uundetected ||
  145. 		    (youmonst.m_ap_type == M_AP_OBJECT && youmonst.mappearance == GOLD_PIECE && !likes_gold(ptr)) ||
  146. 		    (mtmp->mpeaceful && !mtmp->isshk) ||  /* allow shks to follow */
  147. 		    ((monsndx(ptr) == PM_STALKER || ptr->mlet == S_BAT ||
  148. 		      ptr->mlet == S_LIGHT) && !rn2(3)))
  149. 			appr = 0;
  150.  
  151. 		if(monsndx(ptr) == PM_LEPRECHAUN && (appr == 1) &&
  152. #ifndef GOLDOBJ
  153. 		   (mtmp->mgold > u.ugold))
  154. #else
  155. 		   ( (lepgold = findgold(mtmp->minvent)) && 
  156. (lepgold->quan > ((ygold = findgold(invent)) ? ygold->quan : 0L)) ))
  157. #endif
  158. 			appr = -1;
  159.  
  160. 		if (!should_see && can_track(ptr)) {
  161. 			register coord *cp;
  162.  
  163. 			cp = gettrack(omx,omy);
  164. 			if (cp) {
  165. 				gx = cp->x;
  166. 				gy = cp->y;
  167. 			}
  168. 		}
  169. 	}
  170.  
  171. 	if ((!mtmp->mpeaceful || !rn2(10))
  172. #ifdef REINCARNATION
  173. 				    && (!Is_rogue_level(&u.uz))
  174. #endif
  175. 							    ) {
  176. 	    boolean in_line = lined_up(mtmp) &&
  177. 		(distmin(mtmp->mx, mtmp->my, mtmp->mux, mtmp->muy) <=
  178. 		    (throws_rocks(youmonst.data) ? 20 : ACURRSTR/2+1)
  179. 		);
  180.  
  181. 	    if (appr != 1 || !in_line) {
  182. 		/* Monsters in combat won't pick stuff up, avoiding the
  183. 		 * situation where you toss arrows at it and it has nothing
  184. 		 * better to do than pick the arrows up.
  185. 		 */
  186. 		register int pctload = (curr_mon_load(mtmp) * 100) /
  187. 			max_mon_load(mtmp);
  188.  
  189. 		/* look for gold or jewels nearby */
  190. 		likegold = (likes_gold(ptr) && pctload < 95);
  191. 		likegems = (likes_gems(ptr) && pctload < 85);
  192. 		uses_items = (!mindless(ptr) && !is_animal(ptr)
  193. 			&& pctload < 75);
  194. 		likeobjs = (likes_objs(ptr) && pctload < 75);
  195. 		likemagic = (likes_magic(ptr) && pctload < 85);
  196. 		likerock = (throws_rocks(ptr) && pctload < 50 && !In_sokoban(&u.uz));
  197. 		conceals = hides_under(ptr);
  198. 		setlikes = TRUE;
  199. 	    }
  200. 	}
  201.  
  202. #define SQSRCHRADIUS	5
  203.  
  204. { register int minr = SQSRCHRADIUS;	/* not too far away */
  205. 	register struct obj *otmp;
  206. 	register int xx, yy;
  207. 	int oomx, oomy, lmx, lmy;
  208.  
  209. 	/* cut down the search radius if it thinks character is closer. */
  210. 	if(distmin(mtmp->mux, mtmp->muy, omx, omy) < SQSRCHRADIUS &&
  211. 	    !mtmp->mpeaceful) minr--;
  212. 	/* guards shouldn't get too distracted */
  213. 	if(!mtmp->mpeaceful && is_mercenary(ptr)) minr = 1;
  214.  
  215. 	if((likegold || likegems || likeobjs || likemagic || likerock || conceals)
  216. 	      && (!*in_rooms(omx, omy, SHOPBASE) || (!rn2(25) && !mtmp->isshk))) {
  217. 	look_for_obj:
  218. 	    oomx = min(COLNO-1, omx+minr);
  219. 	    oomy = min(ROWNO-1, omy+minr);
  220. 	    lmx = max(1, omx-minr);
  221. 	    lmy = max(0, omy-minr);
  222. 	    for(otmp = fobj; otmp; otmp = otmp->nobj) {
  223. 		/* monsters may pick rocks up, but won't go out of their way
  224. 		   to grab them; this might hamper sling wielders, but it cuts
  225. 		   down on move overhead by filtering out most common item */
  226. 		if (otmp->otyp == ROCK) continue;
  227. 		xx = otmp->ox;
  228. 		yy = otmp->oy;
  229. 		/* Nymphs take everything.  Most other creatures should not
  230. 		 * pick up corpses except as a special case like in
  231. 		 * searches_for_item().  We need to do this check in
  232. 		 * mpickstuff() as well.
  233. 		 */
  234. 		if(xx >= lmx && xx <= oomx && yy >= lmy && yy <= oomy) {
  235. 		    /* don't get stuck circling around an object that's underneath
  236. 		       an immobile or hidden monster; paralysis victims excluded */
  237. 		    if ((mtoo = m_at(xx,yy)) != 0 &&
  238. 			(mtoo->msleeping || mtoo->mundetected ||
  239. 			 (mtoo->mappearance && !mtoo->iswiz) ||
  240. 			 !mtoo->data->mmove)) continue;
  241.  
  242. 		    if(((likegold && otmp->oclass == COIN_CLASS) ||
  243. 		       (likeobjs && index(practical, otmp->oclass) &&
  244. 			(otmp->otyp != CORPSE || (ptr->mlet == S_NYMPH
  245. 			   && !is_rider(&mons[otmp->corpsenm])))) ||
  246. 		       (likemagic && index(magical, otmp->oclass)) ||
  247. 		       (uses_items && searches_for_item(mtmp, otmp)) ||
  248. 		       (likerock && otmp->otyp == BOULDER) ||
  249. 		       (likegems && otmp->oclass == GEM_CLASS &&
  250. 			objects[otmp->otyp].oc_material != MINERAL) ||
  251. 		       (conceals && !cansee(otmp->ox,otmp->oy)) ||
  252. 		       (ptr == &mons[PM_GELATINOUS_CUBE] &&
  253. 			!index(indigestion, otmp->oclass) &&
  254. 			!(otmp->otyp == CORPSE &&
  255. 			  touch_petrifies(&mons[otmp->corpsenm])))
  256. 		      ) && touch_artifact(otmp,mtmp)) {
  257. 			if(can_carry(mtmp,otmp) &&
  258. 			   (throws_rocks(ptr) ||
  259. 				!sobj_at(BOULDER,xx,yy)) &&
  260. 			   (!is_unicorn(ptr) ||
  261. 			    objects[otmp->otyp].oc_material == GEMSTONE) &&
  262. 			   /* Don't get stuck circling an Elbereth */
  263. 			   !(onscary(xx, yy, mtmp))) {
  264. 			    minr = distmin(omx,omy,xx,yy);
  265. 			    oomx = min(COLNO-1, omx+minr);
  266. 			    oomy = min(ROWNO-1, omy+minr);
  267. 			    lmx = max(1, omx-minr);
  268. 			    lmy = max(0, omy-minr);
  269. 			    gx = otmp->ox;
  270. 			    gy = otmp->oy;
  271. 			    if (gx == omx && gy == omy) {
  272. 				mmoved = 3; /* actually unnecessary */
  273. 				goto postmov;
  274. 			    }
  275. 			}
  276. 		    }
  277. 		}
  278. 	    }
  279. 	} else if(likegold) {
  280. 	    /* don't try to pick up anything else, but use the same loop */
  281. 	    uses_items = 0;
  282. 	    likegems = likeobjs = likemagic = likerock = conceals = 0;
  283. 	    goto look_for_obj;
  284. 	}
  285.  
  286. 	if(minr < SQSRCHRADIUS && appr == -1) {
  287. 	    if(distmin(omx,omy,mtmp->mux,mtmp->muy) <= 3) {
  288. 		gx = mtmp->mux;
  289. 		gy = mtmp->muy;
  290. 	    } else
  291. 		appr = 1;
  292. 	}
  293. }
  294.  
  295. 	/* don't tunnel if hostile and close enough to prefer a weapon */
  296. 	if (can_tunnel && needspick(ptr) &&
  297. 	    ((!mtmp->mpeaceful || Conflict) &&
  298. 	     dist2(mtmp->mx, mtmp->my, mtmp->mux, mtmp->muy) <= 8))
  299. 	    can_tunnel = FALSE;
  300.  
  301. 	nix = omx;
  302. 	niy = omy;
  303. 	flag = 0L;
  304. 	if (mtmp->mpeaceful && (!Conflict || resist(mtmp, RING_CLASS, 0, 0)))
  305. 	    flag |= (ALLOW_SANCT | ALLOW_SSM);
  306. 	else flag |= ALLOW_U;
  307. 	if (is_minion(ptr) || is_rider(ptr)) flag |= ALLOW_SANCT;
  308. 	/* unicorn may not be able to avoid hero on a noteleport level */
  309. 	if (is_unicorn(ptr) && !level.flags.noteleport) flag |= NOTONL;
  310. 	if (passes_walls(ptr)) flag |= (ALLOW_WALL | ALLOW_ROCK);
  311. 	if (passes_bars(ptr)) flag |= ALLOW_BARS;
  312. 	if (can_tunnel) flag |= ALLOW_DIG;
  313. 	if (is_human(ptr) || ptr == &mons[PM_MINOTAUR]) flag |= ALLOW_SSM;
  314. 	if (is_undead(ptr) && ptr->mlet != S_GHOST) flag |= NOGARLIC;
  315. 	if (throws_rocks(ptr)) flag |= ALLOW_ROCK;
  316. 	if (can_open) flag |= OPENDOOR;
  317. 	if (can_unlock) flag |= UNLOCKDOOR;
  318. 	if (doorbuster) flag |= BUSTDOOR;
  319. 	{
  320. 	    register int i, j, nx, ny, nearer;
  321. 	    int jcnt, cnt;
  322. 	    int ndist, nidist;
  323. 	    register coord *mtrk;
  324. 	    coord poss[9];
  325.  
  326. 	    cnt = mfndpos(mtmp, poss, info, flag);
  327. 	    chcnt = 0;
  328. 	    jcnt = min(MTSZ, cnt-1);
  329. 	    chi = -1;
  330. 	    nidist = dist2(nix,niy,gx,gy);
  331. 	    /* allow monsters be shortsighted on some levels for balance */
  332. 	    if(!mtmp->mpeaceful && level.flags.shortsighted &&
  333. 	       nidist > (couldsee(nix,niy) ? 144 : 36) && appr == 1) appr = 0;
  334. 	    if (is_unicorn(ptr) && level.flags.noteleport) {
  335. 		/* on noteleport levels, perhaps we cannot avoid hero */
  336. 		for(i = 0; i < cnt; i++)
  337. 		    if(!(info[i] & NOTONL)) avoid=TRUE;
  338. 	    }

Monsters have only approximately 25% chance of retracing their last step. This code is responsible for the bug that "fleeing" monsters get stuck to you in corridors.

  1. 	    for(i=0; i < cnt; i++) {
  2. 		if (avoid && (info[i] & NOTONL)) continue;
  3. 		nx = poss[i].x;
  4. 		ny = poss[i].y;
  5.  
  6. 		if (appr != 0) {
  7. 		    mtrk = &mtmp->mtrack[0];
  8. 		    for(j=0; j < jcnt; mtrk++, j++)
  9. 			if(nx == mtrk->x && ny == mtrk->y)
  10. 			    if(rn2(4*(cnt-j)))
  11. 				goto nxti;
  12. 		}
  13.  
  14. 		nearer = ((ndist = dist2(nx,ny,gx,gy)) < nidist);
  15.  
  16. 		if((appr == 1 && nearer) || (appr == -1 && !nearer) ||
  17. 		   (!appr && !rn2(++chcnt)) || !mmoved) {
  18. 		    nix = nx;
  19. 		    niy = ny;
  20. 		    nidist = ndist;
  21. 		    chi = i;
  22. 		    mmoved = 1;
  23. 		}
  24. 	    nxti:	;
  25. 	    }
  26. 	}
  27.  
  28. 	if(mmoved) {
  29. 	    register int j;
  30.  
  31. 	    if (mmoved==1 && (u.ux != nix || u.uy != niy) && itsstuck(mtmp))
  32. 		return(3);
  33.  
  34. 	    if (((IS_ROCK(levl[nix][niy].typ) && may_dig(nix,niy)) ||
  35. 		 closed_door(nix, niy)) &&
  36. 		mmoved==1 && can_tunnel && needspick(ptr)) {
  37. 		if (closed_door(nix, niy)) {
  38. 		    if (!(mw_tmp = MON_WEP(mtmp)) ||
  39. 			!is_pick(mw_tmp) || !is_axe(mw_tmp))
  40. 			mtmp->weapon_check = NEED_PICK_OR_AXE;
  41. 		} else if (IS_TREE(levl[nix][niy].typ)) {
  42. 		    if (!(mw_tmp = MON_WEP(mtmp)) || !is_axe(mw_tmp))
  43. 			mtmp->weapon_check = NEED_AXE;
  44. 		} else if (!(mw_tmp = MON_WEP(mtmp)) || !is_pick(mw_tmp)) {
  45. 		    mtmp->weapon_check = NEED_PICK_AXE;
  46. 		}
  47. 		if (mtmp->weapon_check >= NEED_PICK_AXE && mon_wield_item(mtmp))
  48. 		    return(3);
  49. 	    }
  50. 	    /* If ALLOW_U is set, either it's trying to attack you, or it
  51. 	     * thinks it is.  In either case, attack this spot in preference to
  52. 	     * all others.
  53. 	     */
  54. 	/* Actually, this whole section of code doesn't work as you'd expect.
  55. 	 * Most attacks are handled in dochug().  It calls distfleeck(), which
  56. 	 * among other things sets nearby if the monster is near you--and if
  57. 	 * nearby is set, we never call m_move unless it is a special case
  58. 	 * (confused, stun, etc.)  The effect is that this ALLOW_U (and
  59. 	 * mfndpos) has no effect for normal attacks, though it lets a confused
  60. 	 * monster attack you by accident.
  61. 	 */
  62. 	    if(info[chi] & ALLOW_U) {
  63. 		nix = mtmp->mux;
  64. 		niy = mtmp->muy;
  65. 	    }
  66. 	    if (nix == u.ux && niy == u.uy) {
  67. 		mtmp->mux = u.ux;
  68. 		mtmp->muy = u.uy;
  69. 		return(0);
  70. 	    }
  71. 	    /* The monster may attack another based on 1 of 2 conditions:
  72. 	     * 1 - It may be confused.
  73. 	     * 2 - It may mistake the monster for your (displaced) image.
  74. 	     * Pets get taken care of above and shouldn't reach this code.
  75. 	     * Conflict gets handled even farther away (movemon()).
  76. 	     */
  77. 	    if((info[chi] & ALLOW_M) ||
  78. 		   (nix == mtmp->mux && niy == mtmp->muy)) {
  79. 		struct monst *mtmp2;
  80. 		int mstatus;
  81. 		mtmp2 = m_at(nix,niy);
  82.  
  83. 		notonhead = mtmp2 && (nix != mtmp2->mx || niy != mtmp2->my);
  84. 		/* note: mstatus returns 0 if mtmp2 is nonexistent */
  85. 		mstatus = mattackm(mtmp, mtmp2);
  86.  
  87. 		if (mstatus & MM_AGR_DIED)		/* aggressor died */
  88. 		    return 2;
  89.  
  90. 		if ((mstatus & MM_HIT) && !(mstatus & MM_DEF_DIED)  &&
  91. 		    rn2(4) && mtmp2->movement >= NORMAL_SPEED) {
  92. 		    mtmp2->movement -= NORMAL_SPEED;
  93. 		    notonhead = 0;
  94. 		    mstatus = mattackm(mtmp2, mtmp);	/* return attack */
  95. 		    if (mstatus & MM_DEF_DIED)
  96. 			return 2;
  97. 		}
  98. 		return 3;
  99. 	    }
  100.  
  101. 	    if (!m_in_out_region(mtmp,nix,niy))
  102. 	        return 3;
  103. 	    remove_monster(omx, omy);
  104. 	    place_monster(mtmp, nix, niy);
  105. 	    for(j = MTSZ-1; j > 0; j--)
  106. 		mtmp->mtrack[j] = mtmp->mtrack[j-1];
  107. 	    mtmp->mtrack[0].x = omx;
  108. 	    mtmp->mtrack[0].y = omy;
  109. 	    /* Place a segment at the old position. */
  110. 	    if (mtmp->wormno) worm_move(mtmp);
  111. 	} else {
  112. 	    if(is_unicorn(ptr) && rn2(2) && !tele_restrict(mtmp)) {
  113. 		(void) rloc(mtmp, FALSE);
  114. 		return(1);
  115. 	    }
  116. 	    if(mtmp->wormno) worm_nomove(mtmp);
  117. 	}
  118. postmov:
  119. 	if(mmoved == 1 || mmoved == 3) {
  120. 	    boolean canseeit = cansee(mtmp->mx, mtmp->my);
  121.  
  122. 	    if(mmoved == 1) {
  123. 		newsym(omx,omy);		/* update the old position */
  124. 		if (mintrap(mtmp) >= 2) {
  125. 		    if(mtmp->mx) newsym(mtmp->mx,mtmp->my);
  126. 		    return(2);	/* it died */
  127. 		}
  128. 		ptr = mtmp->data;
  129.  
  130. 		/* open a door, or crash through it, if you can */
  131. 		if(IS_DOOR(levl[mtmp->mx][mtmp->my].typ)
  132. 			&& !passes_walls(ptr) /* doesn't need to open doors */
  133. 			&& !can_tunnel /* taken care of below */
  134. 		      ) {
  135. 		    struct rm *here = &levl[mtmp->mx][mtmp->my];
  136. 		    boolean btrapped = (here->doormask & D_TRAPPED);
  137.  
  138. 		    if(here->doormask & (D_LOCKED|D_CLOSED) && amorphous(ptr)) {
  139. 			if (flags.verbose && canseemon(mtmp))
  140. 			    pline("%s %s under the door.", Monnam(mtmp),
  141. 				  (ptr == &mons[PM_FOG_CLOUD] ||
  142. 				   ptr == &mons[PM_YELLOW_LIGHT])
  143. 				  ? "flows" : "oozes");
  144. 		    } else if(here->doormask & D_LOCKED && can_unlock) {
  145. 			if(btrapped) {
  146. 			    here->doormask = D_NODOOR;
  147. 			    newsym(mtmp->mx, mtmp->my);
  148. 			    unblock_point(mtmp->mx,mtmp->my); /* vision */
  149. 			    if(mb_trapped(mtmp)) return(2);
  150. 			} else {
  151. 			    if (flags.verbose) {
  152. 				if (canseeit)
  153. 				   You("see a door unlock and open.");
  154. 				else if (flags.soundok)
  155. 				   You_hear("a door unlock and open.");
  156. 			    }
  157. 			    here->doormask = D_ISOPEN;
  158. 			    /* newsym(mtmp->mx, mtmp->my); */
  159. 			    unblock_point(mtmp->mx,mtmp->my); /* vision */
  160. 			}
  161. 		    } else if (here->doormask == D_CLOSED && can_open) {
  162. 			if(btrapped) {
  163. 			    here->doormask = D_NODOOR;
  164. 			    newsym(mtmp->mx, mtmp->my);
  165. 			    unblock_point(mtmp->mx,mtmp->my); /* vision */
  166. 			    if(mb_trapped(mtmp)) return(2);
  167. 			} else {
  168. 			    if (flags.verbose) {
  169. 				if (canseeit)
  170. 				     You("see a door open.");
  171. 				else if (flags.soundok)
  172. 				     You_hear("a door open.");
  173. 			    }
  174. 			    here->doormask = D_ISOPEN;
  175. 			    /* newsym(mtmp->mx, mtmp->my); */  /* done below */
  176. 			    unblock_point(mtmp->mx,mtmp->my); /* vision */
  177. 			}
  178. 		    } else if (here->doormask & (D_LOCKED|D_CLOSED)) {
  179. 			/* mfndpos guarantees this must be a doorbuster */
  180. 			if(btrapped) {
  181. 			    here->doormask = D_NODOOR;
  182. 			    newsym(mtmp->mx, mtmp->my);
  183. 			    unblock_point(mtmp->mx,mtmp->my); /* vision */
  184. 			    if(mb_trapped(mtmp)) return(2);
  185. 			} else {
  186. 			    if (flags.verbose) {
  187. 				if (canseeit)
  188. 				    You("see a door crash open.");
  189. 				else if (flags.soundok)
  190. 				    You_hear("a door crash open.");
  191. 			    }
  192. 			    if (here->doormask & D_LOCKED && !rn2(2))
  193. 				    here->doormask = D_NODOOR;
  194. 			    else here->doormask = D_BROKEN;
  195. 			    /* newsym(mtmp->mx, mtmp->my); */ /* done below */
  196. 			    unblock_point(mtmp->mx,mtmp->my); /* vision */
  197. 			}
  198. 			/* if it's a shop door, schedule repair */
  199. 			if (*in_rooms(mtmp->mx, mtmp->my, SHOPBASE))
  200. 			    add_damage(mtmp->mx, mtmp->my, 0L);
  201. 		    }
  202. 		} else if (levl[mtmp->mx][mtmp->my].typ == IRONBARS) {
  203. 			if (flags.verbose && canseemon(mtmp))
  204. 			    Norep("%s %s %s the iron bars.", Monnam(mtmp),
  205. 				  /* pluralization fakes verb conjugation */
  206. 				  makeplural(locomotion(ptr, "pass")),
  207. 				  passes_walls(ptr) ? "through" : "between");
  208. 		}
  209.  
  210. 		/* possibly dig */
  211. 		if (can_tunnel && mdig_tunnel(mtmp))
  212. 			return(2);  /* mon died (position already updated) */
  213.  
  214. 		/* set also in domove(), hack.c */
  215. 		if (u.uswallow && mtmp == u.ustuck &&
  216. 					(mtmp->mx != omx || mtmp->my != omy)) {
  217. 		    /* If the monster moved, then update */
  218. 		    u.ux0 = u.ux;
  219. 		    u.uy0 = u.uy;
  220. 		    u.ux = mtmp->mx;
  221. 		    u.uy = mtmp->my;
  222. 		    swallowed(0);
  223. 		} else
  224. 		newsym(mtmp->mx,mtmp->my);
  225. 	    }
  226. 	    if(OBJ_AT(mtmp->mx, mtmp->my) && mtmp->mcanmove) {
  227. 		/* recompute the likes tests, in case we polymorphed
  228. 		 * or if the "likegold" case got taken above */
  229. 		if (setlikes) {
  230. 		    register int pctload = (curr_mon_load(mtmp) * 100) /
  231. 			max_mon_load(mtmp);
  232.  
  233. 		    /* look for gold or jewels nearby */
  234. 		    likegold = (likes_gold(ptr) && pctload < 95);
  235. 		    likegems = (likes_gems(ptr) && pctload < 85);
  236. 		    uses_items = (!mindless(ptr) && !is_animal(ptr)
  237. 				  && pctload < 75);
  238. 		    likeobjs = (likes_objs(ptr) && pctload < 75);
  239. 		    likemagic = (likes_magic(ptr) && pctload < 85);
  240. 		    likerock = (throws_rocks(ptr) && pctload < 50 &&
  241. 				!In_sokoban(&u.uz));
  242. 		    conceals = hides_under(ptr);
  243. 		}
  244.  
  245. 		/* Maybe a rock mole just ate some metal object */
  246. 		if (metallivorous(ptr)) {
  247. 		    if (meatmetal(mtmp) == 2) return 2;	/* it died */
  248. 		}
  249.  
  250. 		if(g_at(mtmp->mx,mtmp->my) && likegold) mpickgold(mtmp);
  251.  
  252. 		/* Maybe a cube ate just about anything */
  253. 		if (ptr == &mons[PM_GELATINOUS_CUBE]) {
  254. 		    if (meatobj(mtmp) == 2) return 2;	/* it died */
  255. 		}
  256.  
  257. 		if(!*in_rooms(mtmp->mx, mtmp->my, SHOPBASE) || !rn2(25)) {
  258. 		    boolean picked = FALSE;
  259.  
  260. 		    if(likeobjs) picked |= mpickstuff(mtmp, practical);
  261. 		    if(likemagic) picked |= mpickstuff(mtmp, magical);
  262. 		    if(likerock) picked |= mpickstuff(mtmp, boulder_class);
  263. 		    if(likegems) picked |= mpickstuff(mtmp, gem_class);
  264. 		    if(uses_items) picked |= mpickstuff(mtmp, (char *)0);
  265. 		    if(picked) mmoved = 3;
  266. 		}
  267.  
  268. 		if(mtmp->minvis) {
  269. 		    newsym(mtmp->mx, mtmp->my);
  270. 		    if (mtmp->wormno) see_wsegs(mtmp);
  271. 		}
  272. 	    }
  273.  
  274. 	    if(hides_under(ptr) || ptr->mlet == S_EEL) {
  275. 		/* Always set--or reset--mundetected if it's already hidden
  276. 		   (just in case the object it was hiding under went away);
  277. 		   usually set mundetected unless monster can't move.  */
  278. 		if (mtmp->mundetected ||
  279. 			(mtmp->mcanmove && !mtmp->msleeping && rn2(5)))
  280. 		    mtmp->mundetected = (ptr->mlet != S_EEL) ?
  281. 			OBJ_AT(mtmp->mx, mtmp->my) :
  282. 			(is_pool(mtmp->mx, mtmp->my) && !Is_waterlevel(&u.uz));
  283. 		newsym(mtmp->mx, mtmp->my);
  284. 	    }
  285. 	    if (mtmp->isshk) {
  286. 		after_shk_move(mtmp);
  287. 	    }
  288. 	}
  289. 	return(mmoved);
  290. }
  291.  
  292. #endif /* OVL0 */
  293. #ifdef OVL2

closed_door

  1. boolean
  2. closed_door(x, y)
  3. register int x, y;
  4. {
  5. 	return((boolean)(IS_DOOR(levl[x][y].typ) &&
  6. 			(levl[x][y].doormask & (D_LOCKED | D_CLOSED))));
  7. }

accessible

  1. boolean
  2. accessible(x, y)
  3. register int x, y;
  4. {
  5. 	return((boolean)(ACCESSIBLE(levl[x][y].typ) && !closed_door(x, y)));
  6. }
  7.  
  8. #endif /* OVL2 */
  9. #ifdef OVL0

set_apparxy

  1. /* decide where the monster thinks you are standing */
  2. void
  3. set_apparxy(mtmp)
  4. register struct monst *mtmp;
  5. {
  6. 	boolean notseen, gotu;
  7. 	register int disp, mx = mtmp->mux, my = mtmp->muy;
  8. #ifdef GOLDOBJ
  9. 	long umoney = money_cnt(invent);
  10. #endif
  11.  
  12. 	/*
  13. 	 * do cheapest and/or most likely tests first
  14. 	 */
  15.  
  16. 	/* pet knows your smell; grabber still has hold of you */
  17. 	if (mtmp->mtame || mtmp == u.ustuck) goto found_you;
  18.  
  19. 	/* monsters which know where you are don't suddenly forget,
  20. 	   if you haven't moved away */
  21. 	if (mx == u.ux && my == u.uy) goto found_you;
  22.  
  23. 	notseen = (!mtmp->mcansee || (Invis && !perceives(mtmp->data)));
  24. 	/* add cases as required.  eg. Displacement ... */
  25. 	if (notseen || Underwater) {
  26. 	    /* Xorns can smell valuable metal like gold, treat as seen */
  27. 	    if ((mtmp->data == &mons[PM_XORN]) &&
  28. #ifndef GOLDOBJ
  29. 			u.ugold
  30. #else
  31. 			umoney
  32. #endif
  33. 			&& !Underwater)
  34. 		disp = 0;
  35. 	    else
  36. 		disp = 1;
  37. 	} else if (Displaced) {
  38. 	    disp = couldsee(mx, my) ? 2 : 1;
  39. 	} else disp = 0;
  40. 	if (!disp) goto found_you;
  41.  
  42. 	/* without something like the following, invis. and displ.
  43. 	   are too powerful */
  44. 	gotu = notseen ? !rn2(3) : Displaced ? !rn2(4) : FALSE;
  45.  
  46. #if 0		/* this never worked as intended & isn't needed anyway */
  47. 	/* If invis but not displaced, staying around gets you 'discovered' */
  48. 	gotu |= (!Displaced && u.dx == 0 && u.dy == 0);
  49. #endif
  50.  
  51. 	if (!gotu) {
  52. 	    register int try_cnt = 0;
  53. 	    do {
  54. 		if (++try_cnt > 200) goto found_you;		/* punt */
  55. 		mx = u.ux - disp + rn2(2*disp+1);
  56. 		my = u.uy - disp + rn2(2*disp+1);
  57. 	    } while (!isok(mx,my)
  58. 		  || (disp != 2 && mx == mtmp->mx && my == mtmp->my)
  59. 		  || ((mx != u.ux || my != u.uy) &&
  60. 		      !passes_walls(mtmp->data) &&
  61. 		      (!ACCESSIBLE(levl[mx][my].typ) ||
  62. 		       (closed_door(mx, my) && !can_ooze(mtmp))))
  63. 		  || !couldsee(mx, my));
  64. 	} else {
  65. found_you:
  66. 	    mx = u.ux;
  67. 	    my = u.uy;
  68. 	}
  69.  
  70. 	mtmp->mux = mx;
  71. 	mtmp->muy = my;
  72. }

can_ooze

  1. boolean
  2. can_ooze(mtmp)
  3. struct monst *mtmp;
  4. {
  5. 	struct obj *chain, *obj;
  6.  
  7. 	if (!amorphous(mtmp->data)) return FALSE;
  8. 	if (mtmp == &youmonst) {
  9. #ifndef GOLDOBJ
  10. 		if (u.ugold > 100L) return FALSE;
  11. #endif
  12. 		chain = invent;
  13. 	} else {
  14. #ifndef GOLDOBJ
  15. 		if (mtmp->mgold > 100L) return FALSE;
  16. #endif
  17. 		chain = mtmp->minvent;
  18. 	}
  19. 	for (obj = chain; obj; obj = obj->nobj) {
  20. 		int typ = obj->otyp;
  21.  
  22. #ifdef GOLDOBJ
  23. if (typ == COIN_CLASS && obj->quan > 100L) return FALSE;
  24. #endif
  25. 		if (obj->oclass != GEM_CLASS &&
  26. 		    !(typ >= ARROW && typ <= BOOMERANG) &&
  27. 		    !(typ >= DAGGER && typ <= CRYSKNIFE) &&
  28. 		    typ != SLING &&
  29. 		    !is_cloak(obj) && typ != FEDORA &&
  30. 		    !is_gloves(obj) && typ != LEATHER_JACKET &&
  31. #ifdef TOURIST
  32. 		    typ != CREDIT_CARD && !is_shirt(obj) &&
  33. #endif
  34. 		    !(typ == CORPSE && verysmall(&mons[obj->corpsenm])) &&
  35. 		    typ != FORTUNE_COOKIE && typ != CANDY_BAR &&
  36. 		    typ != PANCAKE && typ != LEMBAS_WAFER &&
  37. 		    typ != LUMP_OF_ROYAL_JELLY &&
  38. 		    obj->oclass != AMULET_CLASS &&
  39. 		    obj->oclass != RING_CLASS &&
  40. #ifdef WIZARD
  41. 		    obj->oclass != VENOM_CLASS &&
  42. #endif
  43. 		    typ != SACK && typ != BAG_OF_HOLDING &&
  44. 		    typ != BAG_OF_TRICKS && !Is_candle(obj) &&
  45. 		    typ != OILSKIN_SACK && typ != LEASH &&
  46. 		    typ != STETHOSCOPE && typ != BLINDFOLD && typ != TOWEL &&
  47. 		    typ != TIN_WHISTLE && typ != MAGIC_WHISTLE &&
  48. 		    typ != MAGIC_MARKER && typ != TIN_OPENER &&
  49. 		    typ != SKELETON_KEY && typ != LOCK_PICK
  50. 		) return FALSE;
  51. 		if (Is_container(obj) && obj->cobj) return FALSE;
  52.  
  53. 	}
  54. 	return TRUE;
  55. }
  56.  
  57. #endif /* OVL0 */
  58.  
  59. /*monmove.c*/