Source:NetHack 3.4.3/src/teleport.c

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

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

Top of file[edit]

  1. /*	SCCS Id: @(#)teleport.c	3.4	2003/08/11	*/
  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.  
  3. STATIC_DCL boolean FDECL(tele_jump_ok, (int,int,int,int));
  4. STATIC_DCL boolean FDECL(teleok, (int,int,BOOLEAN_P));
  5. STATIC_DCL void NDECL(vault_tele);
  6. STATIC_DCL boolean FDECL(rloc_pos_ok, (int,int,struct monst *));
  7. STATIC_DCL void FDECL(mvault_tele, (struct monst *));

goodpos[edit]

  1. /*
  2. * Is (x,y) a good position of mtmp?  If mtmp is NULL, then is (x,y) good
  3. * for an object?
  4. *
  5. * This function will only look at mtmp->mdat, so makemon, mplayer, etc can
  6. * call it to generate new monster positions with fake monster structures.
  7. */
  8. boolean
  9. goodpos(x, y, mtmp, gpflags)
  10. int x,y;
  11. struct monst *mtmp;
  12. unsigned gpflags;
  13. {
  14. 	struct permonst *mdat = NULL;
  15. 	boolean ignorewater = ((gpflags & MM_IGNOREWATER) != 0);
  16.  
  17. 	if (!isok(x, y)) return FALSE;
  18.  
  19. 	/* in many cases, we're trying to create a new monster, which
  20. 	 * can't go on top of the player or any existing monster.
  21. 	 * however, occasionally we are relocating engravings or objects,
  22. 	 * which could be co-located and thus get restricted a bit too much.
  23. 	 * oh well.
  24. 	 */
  25. 	if (mtmp != &youmonst && x == u.ux && y == u.uy
  26. #ifdef STEED
  27. 			&& (!u.usteed || mtmp != u.usteed)
  28. #endif
  29. 			)
  30. 		return FALSE;
  31.  
  32. 	if (mtmp) {
  33. 	    struct monst *mtmp2 = m_at(x,y);
  34.  
  35. 	    /* Be careful with long worms.  A monster may be placed back in
  36. 	     * its own location.  Normally, if m_at() returns the same monster
  37. 	     * that we're trying to place, the monster is being placed in its
  38. 	     * own location.  However, that is not correct for worm segments,
  39. 	     * because all the segments of the worm return the same m_at().
  40. 	     * Actually we overdo the check a little bit--a worm can't be placed
  41. 	     * in its own location, period.  If we just checked for mtmp->mx
  42. 	     * != x || mtmp->my != y, we'd miss the case where we're called
  43. 	     * to place the worm segment and the worm's head is at x,y.
  44. 	     */
  45. 	    if (mtmp2 && (mtmp2 != mtmp || mtmp->wormno))
  46. 		return FALSE;
  47.  
  48. 	    mdat = mtmp->data;
  49. 	    if (is_pool(x,y) && !ignorewater) {
  50. 		if (mtmp == &youmonst)
  51. 			return !!(HLevitation || Flying || Wwalking ||
  52. 					Swimming || Amphibious);
  53. 		else	return (is_flyer(mdat) || is_swimmer(mdat) ||
  54. 							is_clinger(mdat));
  55. 	    } else if (mdat->mlet == S_EEL && rn2(13) && !ignorewater) {
  56. 		return FALSE;
  57. 	    } else if (is_lava(x,y)) {
  58. 		if (mtmp == &youmonst)
  59. 		    return !!HLevitation;
  60. 		else
  61. 		    return (is_flyer(mdat) || likes_lava(mdat));
  62. 	    }
  63. 	    if (passes_walls(mdat) && may_passwall(x,y)) return TRUE;
  64. 	}
  65. 	if (!ACCESSIBLE(levl[x][y].typ)) {
  66. 		if (!(is_pool(x,y) && ignorewater)) return FALSE;
  67. 	}
  68.  
  69. 	if (closed_door(x, y) && (!mdat || !amorphous(mdat)))
  70. 		return FALSE;
  71. 	if (sobj_at(BOULDER, x, y) && (!mdat || !throws_rocks(mdat)))
  72. 		return FALSE;
  73. 	return TRUE;
  74. }

enexto[edit]

  1. /*
  2. * "entity next to"
  3. *
  4. * Attempt to find a good place for the given monster type in the closest
  5. * position to (xx,yy).  Do so in successive square rings around (xx,yy).
  6. * If there is more than one valid positon in the ring, choose one randomly.
  7. * Return TRUE and the position chosen when successful, FALSE otherwise.
  8. */
  9. boolean
  10. enexto(cc, xx, yy, mdat)
  11. coord *cc;
  12. register xchar xx, yy;
  13. struct permonst *mdat;
  14. {
  15. 	return enexto_core(cc, xx, yy, mdat, 0);
  16. }

enexto_core[edit]

  1. boolean
  2. enexto_core(cc, xx, yy, mdat, entflags)
  3. coord *cc;
  4. register xchar xx, yy;
  5. struct permonst *mdat;
  6. unsigned entflags;
  7. {
  8. #define MAX_GOOD 15
  9. coord good[MAX_GOOD], *good_ptr;
  10. int x, y, range, i;
  11. int xmin, xmax, ymin, ymax;
  12. struct monst fakemon;	/* dummy monster */
  13.  
  14. if (!mdat) {
  15. #ifdef DEBUG
  16. 	pline("enexto() called with mdat==0");
  17. #endif
  18. 	/* default to player's original monster type */
  19. 	mdat = &mons[u.umonster];
  20. }
  21. fakemon.data = mdat;	/* set up for goodpos */
  22. good_ptr = good;
  23. range = 1;
  24. /*
  25. * Walk around the border of the square with center (xx,yy) and
  26. * radius range.  Stop when we find at least one valid position.
  27. */
  28. do {
  29. 	xmin = max(1, xx-range);
  30. 	xmax = min(COLNO-1, xx+range);
  31. 	ymin = max(0, yy-range);
  32. 	ymax = min(ROWNO-1, yy+range);
  33.  
  34. 	for (x = xmin; x <= xmax; x++)
  35. 	    if (goodpos(x, ymin, &fakemon, entflags)) {
  36. 		good_ptr->x = x;
  37. 		good_ptr->y = ymin ;
  38. 		/* beware of accessing beyond segment boundaries.. */
  39. 		if (good_ptr++ == &good[MAX_GOOD-1]) goto full;
  40. 	    }
  41. 	for (x = xmin; x <= xmax; x++)
  42. 	    if (goodpos(x, ymax, &fakemon, entflags)) {
  43. 		good_ptr->x = x;
  44. 		good_ptr->y = ymax ;
  45. 		/* beware of accessing beyond segment boundaries.. */
  46. 		if (good_ptr++ == &good[MAX_GOOD-1]) goto full;
  47. 	    }
  48. 	for (y = ymin+1; y < ymax; y++)
  49. 	    if (goodpos(xmin, y, &fakemon, entflags)) {
  50. 		good_ptr->x = xmin;
  51. 		good_ptr-> y = y ;
  52. 		/* beware of accessing beyond segment boundaries.. */
  53. 		if (good_ptr++ == &good[MAX_GOOD-1]) goto full;
  54. 	    }
  55. 	for (y = ymin+1; y < ymax; y++)
  56. 	    if (goodpos(xmax, y, &fakemon, entflags)) {
  57. 		good_ptr->x = xmax;
  58. 		good_ptr->y = y ;
  59. 		/* beware of accessing beyond segment boundaries.. */
  60. 		if (good_ptr++ == &good[MAX_GOOD-1]) goto full;
  61. 	    }
  62. 	range++;
  63.  
  64. 	/* return if we've grown too big (nothing is valid) */
  65. 	if (range > ROWNO && range > COLNO) return FALSE;
  66. } while (good_ptr == good);
  67.  
  68. full:
  69. i = rn2((int)(good_ptr - good));
  70. cc->x = good[i].x;
  71. cc->y = good[i].y;
  72. return TRUE;
  73. }

tele_jump_ok[edit]

  1. /*
  2. * Check for restricted areas present in some special levels.  (This might
  3. * need to be augmented to allow deliberate passage in wizard mode, but
  4. * only for explicitly chosen destinations.)
  5. */
  6. STATIC_OVL boolean
  7. tele_jump_ok(x1, y1, x2, y2)
  8. int x1, y1, x2, y2;
  9. {
  10. 	if (dndest.nlx > 0) {
  11. 	    /* if inside a restricted region, can't teleport outside */
  12. 	    if (within_bounded_area(x1, y1, dndest.nlx, dndest.nly,
  13. 						dndest.nhx, dndest.nhy) &&
  14. 		!within_bounded_area(x2, y2, dndest.nlx, dndest.nly,
  15. 						dndest.nhx, dndest.nhy))
  16. 		return FALSE;
  17. 	    /* and if outside, can't teleport inside */
  18. 	    if (!within_bounded_area(x1, y1, dndest.nlx, dndest.nly,
  19. 						dndest.nhx, dndest.nhy) &&
  20. 		within_bounded_area(x2, y2, dndest.nlx, dndest.nly,
  21. 						dndest.nhx, dndest.nhy))
  22. 		return FALSE;
  23. 	}
  24. 	if (updest.nlx > 0) {		/* ditto */
  25. 	    if (within_bounded_area(x1, y1, updest.nlx, updest.nly,
  26. 						updest.nhx, updest.nhy) &&
  27. 		!within_bounded_area(x2, y2, updest.nlx, updest.nly,
  28. 						updest.nhx, updest.nhy))
  29. 		return FALSE;
  30. 	    if (!within_bounded_area(x1, y1, updest.nlx, updest.nly,
  31. 						updest.nhx, updest.nhy) &&
  32. 		within_bounded_area(x2, y2, updest.nlx, updest.nly,
  33. 						updest.nhx, updest.nhy))
  34. 		return FALSE;
  35. 	}
  36. 	return TRUE;
  37. }

teleok[edit]

  1. STATIC_OVL boolean
  2. teleok(x, y, trapok)
  3. register int x, y;
  4. boolean trapok;
  5. {
  6. 	if (!trapok && t_at(x, y)) return FALSE;
  7. 	if (!goodpos(x, y, &youmonst, 0)) return FALSE;
  8. 	if (!tele_jump_ok(u.ux, u.uy, x, y)) return FALSE;
  9. 	if (!in_out_region(x, y)) return FALSE;
  10. 	return TRUE;
  11. }

teleds[edit]

  1. void
  2. teleds(nux, nuy, allow_drag)
  3. register int nux,nuy;
  4. boolean allow_drag;
  5. {
  6. 	boolean ball_active = (Punished && uball->where != OBJ_FREE),
  7. 		ball_still_in_range = FALSE;
  8.  
  9. 	/* If they have to move the ball, then drag if allow_drag is true;
  10. 	 * otherwise they are teleporting, so unplacebc().  
  11. 	 * If they don't have to move the ball, then always "drag" whether or
  12. 	 * not allow_drag is true, because we are calling that function, not
  13. 	 * to drag, but to move the chain.  *However* there are some dumb
  14. 	 * special cases:
  15. 	 *    0				 0
  16. 	 *   _X  move east       ----->  X_
  17. 	 *    @				  @
  18. 	 * These are permissible if teleporting, but not if dragging.  As a
  19. 	 * result, drag_ball() needs to know about allow_drag and might end
  20. 	 * up dragging the ball anyway.  Also, drag_ball() might find that
  21. 	 * dragging the ball is completely impossible (ball in range but there's
  22. 	 * rock in the way), in which case it teleports the ball on its own.
  23. 	 */
  24. 	if (ball_active) {
  25. 	    if (!carried(uball) && distmin(nux, nuy, uball->ox, uball->oy) <= 2)
  26. 		ball_still_in_range = TRUE; /* don't have to move the ball */
  27. 	    else {
  28. 		/* have to move the ball */
  29. 		if (!allow_drag || distmin(u.ux, u.uy, nux, nuy) > 1) {
  30. 		    /* we should not have dist > 1 and allow_drag at the same
  31. 		     * time, but just in case, we must then revert to teleport.
  32. 		     */
  33. 		    allow_drag = FALSE;
  34. 		    unplacebc();
  35. 		}
  36. 	    }
  37. 	}
  38. 	u.utrap = 0;
  39. 	u.ustuck = 0;
  40. 	u.ux0 = u.ux;
  41. 	u.uy0 = u.uy;
  42.  
  43. 	if (hides_under(youmonst.data))
  44. 		u.uundetected = OBJ_AT(nux, nuy);
  45. 	else if (youmonst.data->mlet == S_EEL)
  46. 		u.uundetected = is_pool(nux, nuy);
  47. 	else {
  48. 		u.uundetected = 0;
  49. 		/* mimics stop being unnoticed */
  50. 		if (youmonst.data->mlet == S_MIMIC)
  51. 		    youmonst.m_ap_type = M_AP_NOTHING;
  52. 	}
  53.  
  54. 	if (u.uswallow) {
  55. 		u.uswldtim = u.uswallow = 0;
  56. 		if (Punished && !ball_active) {
  57. 		    /* ensure ball placement, like unstuck */
  58. 		    ball_active = TRUE;
  59. 		    allow_drag = FALSE;
  60. 		}
  61. 		docrt();
  62. 	}
  63. 	if (ball_active) {
  64. 	    if (ball_still_in_range || allow_drag) {
  65. 		int bc_control;
  66. 		xchar ballx, bally, chainx, chainy;
  67. 		boolean cause_delay;
  68.  
  69. 		if (drag_ball(nux, nuy, &bc_control, &ballx, &bally,
  70. 				    &chainx, &chainy, &cause_delay, allow_drag))
  71. 		    move_bc(0, bc_control, ballx, bally, chainx, chainy);
  72. 	    }
  73. 	}
  74. 	/* must set u.ux, u.uy after drag_ball(), which may need to know
  75. 	   the old position if allow_drag is true... */
  76. 	u.ux = nux;
  77. 	u.uy = nuy;
  78. 	fill_pit(u.ux0, u.uy0);
  79. 	if (ball_active) {
  80. 	    if (!ball_still_in_range && !allow_drag)
  81. 		placebc();
  82. 	}
  83. 	initrack(); /* teleports mess up tracking monsters without this */
  84. 	update_player_regions();
  85. #ifdef STEED
  86. 	/* Move your steed, too */
  87. 	if (u.usteed) {
  88. 		u.usteed->mx = nux;
  89. 		u.usteed->my = nuy;
  90. 	}
  91. #endif
  92. 	/*
  93. 	 *  Make sure the hero disappears from the old location.  This will
  94. 	 *  not happen if she is teleported within sight of her previous
  95. 	 *  location.  Force a full vision recalculation because the hero
  96. 	 *  is now in a new location.
  97. 	 */
  98. 	newsym(u.ux0,u.uy0);
  99. 	see_monsters();
  100. 	vision_full_recalc = 1;
  101. 	nomul(0);
  102. 	vision_recalc(0);	/* vision before effects */
  103. 	spoteffects(TRUE);
  104. 	invocation_message();
  105. }

safe_teleds[edit]

  1. boolean
  2. safe_teleds(allow_drag)
  3. boolean allow_drag;
  4. {
  5. 	register int nux, nuy, tcnt = 0;
  6.  
  7. 	do {
  8. 		nux = rnd(COLNO-1);
  9. 		nuy = rn2(ROWNO);
  10. 	} while (!teleok(nux, nuy, (boolean)(tcnt > 200)) && ++tcnt <= 400);
  11.  
  12. 	if (tcnt <= 400) {
  13. 		teleds(nux, nuy, allow_drag);
  14. 		return TRUE;
  15. 	} else
  16. 		return FALSE;
  17. }

vault_tele[edit]

  1. STATIC_OVL void
  2. vault_tele()
  3. {
  4. 	register struct mkroom *croom = search_special(VAULT);
  5. 	coord c;
  6.  
  7. 	if (croom && somexy(croom, &c) && teleok(c.x,c.y,FALSE)) {
  8. 		teleds(c.x,c.y,FALSE);
  9. 		return;
  10. 	}
  11. 	tele();
  12. }

teleport_pet[edit]

  1. boolean
  2. teleport_pet(mtmp, force_it)
  3. register struct monst *mtmp;
  4. boolean force_it;
  5. {
  6. 	register struct obj *otmp;
  7.  
  8. #ifdef STEED
  9. 	if (mtmp == u.usteed)
  10. 		return (FALSE);
  11. #endif
  12.  
  13. 	if (mtmp->mleashed) {
  14. 	    otmp = get_mleash(mtmp);
  15. 	    if (!otmp) {
  16. 		impossible("%s is leashed, without a leash.", Monnam(mtmp));
  17. 		goto release_it;
  18. 	    }
  19. 	    if (otmp->cursed && !force_it) {
  20. 		yelp(mtmp);
  21. 		return FALSE;
  22. 	    } else {
  23. 		Your("leash goes slack.");
  24. release_it:
  25. 		m_unleash(mtmp, FALSE);
  26. 		return TRUE;
  27. 	    }
  28. 	}
  29. 	return TRUE;
  30. }

tele[edit]

  1. void
  2. tele()
  3. {
  4. 	coord cc;
  5.  
  6. 	/* Disable teleportation in stronghold && Vlad's Tower */
  7. 	if (level.flags.noteleport) {
  8. #ifdef WIZARD
  9. 		if (!wizard) {
  10. #endif
  11. 		    pline("A mysterious force prevents you from teleporting!");
  12. 		    return;
  13. #ifdef WIZARD
  14. 		}
  15. #endif
  16. 	}
  17.  
  18. 	/* don't show trap if "Sorry..." */
  19. 	if (!Blinded) make_blinded(0L,FALSE);
  20.  
  21. 	if ((u.uhave.amulet || On_W_tower_level(&u.uz)) && !rn2(3)) {
  22. 	    You_feel("disoriented for a moment.");
  23. 	    return;
  24. 	}
  25. 	if ((Teleport_control && !Stunned)
  26. #ifdef WIZARD
  27. 			    || wizard
  28. #endif
  29. 					) {
  30. 	    if (unconscious()) {
  31. 		pline("Being unconscious, you cannot control your teleport.");
  32. 	    } else {
  33. #ifdef STEED
  34. 		    char buf[BUFSZ];
  35. 		    if (u.usteed) Sprintf(buf," and %s", mon_nam(u.usteed));
  36. #endif
  37. 		    pline("To what position do you%s want to be teleported?",
  38. #ifdef STEED
  39. 				u.usteed ? buf :
  40. #endif
  41. 			   "");
  42. 		    cc.x = u.ux;
  43. 		    cc.y = u.uy;
  44. 		    if (getpos(&cc, TRUE, "the desired position") < 0)
  45. 			return;	/* abort */
  46. 		    /* possible extensions: introduce a small error if
  47. 		       magic power is low; allow transfer to solid rock */
  48. 		    if (teleok(cc.x, cc.y, FALSE)) {
  49. 			teleds(cc.x, cc.y, FALSE);
  50. 			return;
  51. 		    }
  52. 		    pline("Sorry...");
  53. 		}
  54. 	}
  55.  
  56. 	(void) safe_teleds(FALSE);
  57. }

dotele[edit]

  1. int
  2. dotele()
  3. {
  4. 	struct trap *trap;
  5.  
  6. 	trap = t_at(u.ux, u.uy);
  7. 	if (trap && (!trap->tseen || trap->ttyp != TELEP_TRAP))
  8. 		trap = 0;
  9.  
  10. 	if (trap) {
  11. 		if (trap->once) {
  12. 			pline("This is a vault teleport, usable once only.");
  13. 			if (yn("Jump in?") == 'n')
  14. 				trap = 0;
  15. 			else {
  16. 				deltrap(trap);
  17. 				newsym(u.ux, u.uy);
  18. 			}
  19. 		}
  20. 		if (trap)
  21. 			You("%s onto the teleportation trap.",
  22. 			    locomotion(youmonst.data, "jump"));
  23. 	}
  24. 	if (!trap) {
  25. 	    boolean castit = FALSE;
  26. 	    register int sp_no = 0, energy = 0;
  27.  
  28. 	    if (!Teleportation || (u.ulevel < (Role_if(PM_WIZARD) ? 8 : 12)
  29. 					&& !can_teleport(youmonst.data))) {
  30. 		/* Try to use teleport away spell. */
  31. 		if (objects[SPE_TELEPORT_AWAY].oc_name_known && !Confusion)
  32. 		    for (sp_no = 0; sp_no < MAXSPELL; sp_no++)
  33. 			if (spl_book[sp_no].sp_id == SPE_TELEPORT_AWAY) {
  34. 				castit = TRUE;
  35. 				break;
  36. 			}
  37. #ifdef WIZARD
  38. 		if (!wizard) {
  39. #endif
  40. 		    if (!castit) {
  41. 			if (!Teleportation)
  42. 			    You("don't know that spell.");
  43. 			else You("are not able to teleport at will.");
  44. 			return(0);
  45. 		    }
  46. #ifdef WIZARD
  47. 		}
  48. #endif
  49. 	    }
  50.  
  51. 	    if (u.uhunger <= 100 || ACURR(A_STR) < 6) {
  52. #ifdef WIZARD
  53. 		if (!wizard) {
  54. #endif
  55. 			You("lack the strength %s.",
  56. 			    castit ? "for a teleport spell" : "to teleport");
  57. 			return 1;
  58. #ifdef WIZARD
  59. 		}
  60. #endif
  61. 	    }
  62.  
  63. 	    energy = objects[SPE_TELEPORT_AWAY].oc_level * 7 / 2 - 2;
  64. 	    if (u.uen <= energy) {
  65. #ifdef WIZARD
  66. 		if (wizard)
  67. 			energy = u.uen;
  68. 		else
  69. #endif
  70. 		{
  71. 			You("lack the energy %s.",
  72. 			    castit ? "for a teleport spell" : "to teleport");
  73. 			return 1;
  74. 		}
  75. 	    }
  76.  
  77. 	    if (check_capacity(
  78. 			"Your concentration falters from carrying so much."))
  79. 		return 1;
  80.  
  81. 	    if (castit) {
  82. 		exercise(A_WIS, TRUE);
  83. 		if (spelleffects(sp_no, TRUE))
  84. 			return(1);
  85. 		else
  86. #ifdef WIZARD
  87. 		    if (!wizard)
  88. #endif
  89. 			return(0);
  90. 	    } else {
  91. 		u.uen -= energy;
  92. 		flags.botl = 1;
  93. 	    }
  94. 	}
  95.  
  96. 	if (next_to_u()) {
  97. 		if (trap && trap->once) vault_tele();
  98. 		else tele();
  99. 		(void) next_to_u();
  100. 	} else {
  101. 		You(shudder_for_moment);
  102. 		return(0);
  103. 	}
  104. 	if (!trap) morehungry(100);
  105. 	return(1);
  106. }

level_tele[edit]

  1. void
  2. level_tele()
  3. {
  4. 	register int newlev;
  5. 	d_level newlevel;
  6. 	const char *escape_by_flying = 0;	/* when surviving dest of -N */
  7. 	char buf[BUFSZ];
  8. 	boolean force_dest = FALSE;
  9.  
  10. 	if ((u.uhave.amulet || In_endgame(&u.uz) || In_sokoban(&u.uz))
  11. #ifdef WIZARD
  12. 						&& !wizard
  13. #endif
  14. 							) {
  15. 	    You_feel("very disoriented for a moment.");
  16. 	    return;
  17. 	}
  18. 	if ((Teleport_control && !Stunned)
  19. #ifdef WIZARD
  20. 	   || wizard
  21. #endif
  22. 		) {
  23. 	    char qbuf[BUFSZ];
  24. 	    int trycnt = 0;
  25.  
  26. 	    Strcpy(qbuf, "To what level do you want to teleport?");
  27. 	    do {
  28. 		if (++trycnt == 2) {
  29. #ifdef WIZARD
  30. 			if (wizard) Strcat(qbuf, " [type a number or ? for a menu]");
  31. 			else
  32. #endif
  33. 			Strcat(qbuf, " [type a number]");
  34. 		}
  35. 		getlin(qbuf, buf);
  36. 		if (!strcmp(buf,"\033")) {	/* cancelled */
  37. 		    if (Confusion && rnl(5)) {
  38. 			pline("Oops...");
  39. 			goto random_levtport;
  40. 		    }
  41. 		    return;
  42. 		} else if (!strcmp(buf,"*")) {
  43. 		    goto random_levtport;
  44. 		} else if (Confusion && rnl(5)) {
  45. 		    pline("Oops...");
  46. 		    goto random_levtport;
  47. 		}
  48. #ifdef WIZARD
  49. 		if (wizard && !strcmp(buf,"?")) {
  50. 		    schar destlev = 0;
  51. 		    xchar destdnum = 0;
  52.  
  53. 		    if ((newlev = (int)print_dungeon(TRUE, &destlev, &destdnum))) {
  54. 			newlevel.dnum = destdnum;
  55. 			newlevel.dlevel = destlev;
  56. 			if (In_endgame(&newlevel) && !In_endgame(&u.uz)) {
  57. 				Sprintf(buf,
  58. 				    "Destination is earth level");
  59. 				if (!u.uhave.amulet) {
  60. 					struct obj *obj;
  61. 					obj = mksobj(AMULET_OF_YENDOR,
  62. 							TRUE, FALSE);
  63. 					if (obj) {
  64. 						obj = addinv(obj);
  65. 						Strcat(buf, " with the amulet");
  66. 					}
  67. 				}
  68. 				assign_level(&newlevel, &earth_level);
  69. 				pline("%s.", buf);
  70. 			}
  71. 			force_dest = TRUE;
  72. 		    } else return;
  73. 		} else
  74. #endif
  75. 		if ((newlev = lev_by_name(buf)) == 0) newlev = atoi(buf);
  76. 	    } while (!newlev && !digit(buf[0]) &&
  77. 		     (buf[0] != '-' || !digit(buf[1])) &&
  78. 		     trycnt < 10);
  79.  
  80. 	    /* no dungeon escape via this route */
  81. 	    if (newlev == 0) {
  82. 		if (trycnt >= 10)
  83. 		    goto random_levtport;
  84. 		if (ynq("Go to Nowhere.  Are you sure?") != 'y') return;
  85. 		You("%s in agony as your body begins to warp...",
  86. 		    is_silent(youmonst.data) ? "writhe" : "scream");
  87. 		display_nhwindow(WIN_MESSAGE, FALSE);
  88. 		You("cease to exist.");
  89. 		if (invent) Your("possessions land on the %s with a thud.",
  90. 				surface(u.ux, u.uy));
  91. 		killer_format = NO_KILLER_PREFIX;
  92. 		killer = "committed suicide";
  93. 		done(DIED);
  94. 		pline("An energized cloud of dust begins to coalesce.");
  95. 		Your("body rematerializes%s.", invent ?
  96. 			", and you gather up all your possessions" : "");
  97. 		return;
  98. 	    }
  99.  
  100. 	    /* if in Knox and the requested level > 0, stay put.
  101. 	     * we let negative values requests fall into the "heaven" loop.
  102. 	     */
  103. 	    if (Is_knox(&u.uz) && newlev > 0) {
  104. 		You(shudder_for_moment);
  105. 		return;
  106. 	    }
  107. 	    /* if in Quest, the player sees "Home 1", etc., on the status
  108. 	     * line, instead of the logical depth of the level.  controlled
  109. 	     * level teleport request is likely to be relativized to the
  110. 	     * status line, and consequently it should be incremented to
  111. 	     * the value of the logical depth of the target level.
  112. 	     *
  113. 	     * we let negative values requests fall into the "heaven" loop.
  114. 	     */
  115. 	    if (In_quest(&u.uz) && newlev > 0)
  116. 		newlev = newlev + dungeons[u.uz.dnum].depth_start - 1;
  117. 	} else { /* involuntary level tele */
  118. random_levtport:
  119. 	    newlev = random_teleport_level();
  120. 	    if (newlev == depth(&u.uz)) {
  121. 		You(shudder_for_moment);
  122. 		return;
  123. 	    }
  124. 	}
  125.  
  126. 	if (!next_to_u()) {
  127. 		You(shudder_for_moment);
  128. 		return;
  129. 	}
  130. #ifdef WIZARD
  131. 	if (In_endgame(&u.uz)) {	/* must already be wizard */
  132. 	    int llimit = dunlevs_in_dungeon(&u.uz);
  133.  
  134. 	    if (newlev >= 0 || newlev <= -llimit) {
  135. 		You_cant("get there from here.");
  136. 		return;
  137. 	    }
  138. 	    newlevel.dnum = u.uz.dnum;
  139. 	    newlevel.dlevel = llimit + newlev;
  140. 	    schedule_goto(&newlevel, FALSE, FALSE, 0, (char *)0, (char *)0);
  141. 	    return;
  142. 	}
  143. #endif
  144.  
  145. 	killer = 0;		/* still alive, so far... */
  146.  
  147. 	if (newlev < 0 && !force_dest) {
  148. 		if (*u.ushops0) {
  149. 		    /* take unpaid inventory items off of shop bills */
  150. 		    in_mklev = TRUE;	/* suppress map update */
  151. 		    u_left_shop(u.ushops0, TRUE);
  152. 		    /* you're now effectively out of the shop */
  153. 		    *u.ushops0 = *u.ushops = '\0';
  154. 		    in_mklev = FALSE;
  155. 		}
  156. 		if (newlev <= -10) {
  157. 			You("arrive in heaven.");
  158. 			verbalize("Thou art early, but we'll admit thee.");
  159. 			killer_format = NO_KILLER_PREFIX;
  160. 			killer = "went to heaven prematurely";
  161. 		} else if (newlev == -9) {
  162. 			You_feel("deliriously happy. ");
  163. 			pline("(In fact, you're on Cloud 9!) ");
  164. 			display_nhwindow(WIN_MESSAGE, FALSE);
  165. 		} else
  166. 			You("are now high above the clouds...");
  167.  
  168. 		if (killer) {
  169. 		    ;		/* arrival in heaven is pending */
  170. 		} else if (Levitation) {
  171. 		    escape_by_flying = "float gently down to earth";
  172. 		} else if (Flying) {
  173. 		    escape_by_flying = "fly down to the ground";
  174. 		} else {
  175. 		    pline("Unfortunately, you don't know how to fly.");
  176. 		    You("plummet a few thousand feet to your death.");
  177. 		    Sprintf(buf,
  178. 			  "teleported out of the dungeon and fell to %s death",
  179. 			    uhis());
  180. 		    killer = buf;
  181. 		    killer_format = NO_KILLER_PREFIX;
  182. 		}
  183. 	}
  184.  
  185. 	if (killer) {	/* the chosen destination was not survivable */
  186. 	    d_level lsav;
  187.  
  188. 	    /* set specific death location; this also suppresses bones */
  189. 	    lsav = u.uz;	/* save current level, see below */
  190. 	    u.uz.dnum = 0;	/* main dungeon */
  191. 	    u.uz.dlevel = (newlev <= -10) ? -10 : 0;	/* heaven or surface */
  192. 	    done(DIED);
  193. 	    /* can only get here via life-saving (or declining to die in
  194. 	       explore|debug mode); the hero has now left the dungeon... */
  195. 	    escape_by_flying = "find yourself back on the surface";
  196. 	    u.uz = lsav;	/* restore u.uz so escape code works */
  197. 	}
  198.  
  199. 	/* calls done(ESCAPED) if newlevel==0 */
  200. 	if (escape_by_flying) {
  201. 	    You("%s.", escape_by_flying);
  202. 	    newlevel.dnum = 0;		/* specify main dungeon */
  203. 	    newlevel.dlevel = 0;	/* escape the dungeon */
  204. 	    /* [dlevel used to be set to 1, but it doesn't make sense to
  205. 		teleport out of the dungeon and float or fly down to the
  206. 		surface but then actually arrive back inside the dungeon] */
  207. 	} else if (u.uz.dnum == medusa_level.dnum &&
  208. 	    newlev >= dungeons[u.uz.dnum].depth_start +
  209. 						dunlevs_in_dungeon(&u.uz)) {
  210. #ifdef WIZARD
  211. 	    if (!(wizard && force_dest))
  212. #endif
  213. 	    find_hell(&newlevel);
  214. 	} else {
  215. 	    /* if invocation did not yet occur, teleporting into
  216. 	     * the last level of Gehennom is forbidden.
  217. 	     */
  218. #ifdef WIZARD
  219. 		if (!wizard)
  220. #endif
  221. 	    if (Inhell && !u.uevent.invoked &&
  222. 			newlev >= (dungeons[u.uz.dnum].depth_start +
  223. 					dunlevs_in_dungeon(&u.uz) - 1)) {
  224. 		newlev = dungeons[u.uz.dnum].depth_start +
  225. 					dunlevs_in_dungeon(&u.uz) - 2;
  226. 		pline("Sorry...");
  227. 	    }
  228. 	    /* no teleporting out of quest dungeon */
  229. 	    if (In_quest(&u.uz) && newlev < depth(&qstart_level))
  230. 		newlev = depth(&qstart_level);
  231. 	    /* the player thinks of levels purely in logical terms, so
  232. 	     * we must translate newlev to a number relative to the
  233. 	     * current dungeon.
  234. 	     */
  235. #ifdef WIZARD
  236. 	    if (!(wizard && force_dest))
  237. #endif
  238. 	    get_level(&newlevel, newlev);
  239. 	}
  240. 	schedule_goto(&newlevel, FALSE, FALSE, 0, (char *)0, (char *)0);
  241. 	/* in case player just read a scroll and is about to be asked to
  242. 	   call it something, we can't defer until the end of the turn */
  243. 	if (u.utotype && !flags.mon_moving) deferred_goto();
  244. }

domagicportal[edit]

  1. void
  2. domagicportal(ttmp)
  3. register struct trap *ttmp;
  4. {
  5. 	struct d_level target_level;
  6.  
  7. 	if (!next_to_u()) {
  8. 		You(shudder_for_moment);
  9. 		return;
  10. 	}
  11.  
  12. 	/* if landed from another portal, do nothing */
  13. 	/* problem: level teleport landing escapes the check */
  14. 	if (!on_level(&u.uz, &u.uz0)) return;
  15.  
  16. 	You("activated a magic portal!");
  17.  
  18. 	/* prevent the poor shnook, whose amulet was stolen while in
  19. 	 * the endgame, from accidently triggering the portal to the
  20. 	 * next level, and thus losing the game
  21. 	 */
  22. 	if (In_endgame(&u.uz) && !u.uhave.amulet) {
  23. 	    You_feel("dizzy for a moment, but nothing happens...");
  24. 	    return;
  25. 	}
  26.  
  27. 	target_level = ttmp->dst;
  28. 	schedule_goto(&target_level, FALSE, FALSE, 1,
  29. 		      "You feel dizzy for a moment, but the sensation passes.",
  30. 		      (char *)0);
  31. }

tele_trap[edit]

  1. void
  2. tele_trap(trap)
  3. struct trap *trap;
  4. {
  5. 	if (In_endgame(&u.uz) || Antimagic) {
  6. 		if (Antimagic)
  7. 			shieldeff(u.ux, u.uy);
  8. 		You_feel("a wrenching sensation.");
  9. 	} else if (!next_to_u()) {
  10. 		You(shudder_for_moment);
  11. 	} else if (trap->once) {
  12. 		deltrap(trap);
  13. 		newsym(u.ux,u.uy);	/* get rid of trap symbol */
  14. 		vault_tele();
  15. 	} else
  16. 		tele();
  17. }

level_tele_trap[edit]

  1. void
  2. level_tele_trap(trap)
  3. struct trap *trap;
  4. {
  5. 	You("%s onto a level teleport trap!",
  6. 		      Levitation ? (const char *)"float" :
  7. 				  locomotion(youmonst.data, "step"));
  8. 	if (Antimagic) {
  9. 	    shieldeff(u.ux, u.uy);
  10. 	}
  11. 	if (Antimagic || In_endgame(&u.uz)) {
  12. 	    You_feel("a wrenching sensation.");
  13. 	    return;
  14. 	}
  15. 	if (!Blind)
  16. 	    You("are momentarily blinded by a flash of light.");
  17. 	else
  18. 	    You("are momentarily disoriented.");
  19. 	deltrap(trap);
  20. 	newsym(u.ux,u.uy);	/* get rid of trap symbol */
  21. 	level_tele();
  22. }

rloc_pos_ok[edit]

  1. /* check whether monster can arrive at location <x,y> via Tport (or fall) */
  2. STATIC_OVL boolean
  3. rloc_pos_ok(x, y, mtmp)
  4. register int x, y;		/* coordinates of candidate location */
  5. struct monst *mtmp;
  6. {
  7. 	register int xx, yy;
  8.  
  9. 	if (!goodpos(x, y, mtmp, 0)) return FALSE;
  10. 	/*
  11. 	 * Check for restricted areas present in some special levels.
  12. 	 *
  13. 	 * `xx' is current column; if 0, then `yy' will contain flag bits
  14. 	 * rather than row:  bit #0 set => moving upwards; bit #1 set =>
  15. 	 * inside the Wizard's tower.
  16. 	 */
  17. 	xx = mtmp->mx;
  18. 	yy = mtmp->my;
  19. 	if (!xx) {
  20. 	    /* no current location (migrating monster arrival) */
  21. 	    if (dndest.nlx && On_W_tower_level(&u.uz))
  22. 		return ((yy & 2) != 0) ^	/* inside xor not within */
  23. 		       !within_bounded_area(x, y, dndest.nlx, dndest.nly,
  24. 						  dndest.nhx, dndest.nhy);
  25. 	    if (updest.lx && (yy & 1) != 0)	/* moving up */
  26. 		return (within_bounded_area(x, y, updest.lx, updest.ly,
  27. 						  updest.hx, updest.hy) &&
  28. 		       (!updest.nlx ||
  29. 			!within_bounded_area(x, y, updest.nlx, updest.nly,
  30. 						   updest.nhx, updest.nhy)));
  31. 	    if (dndest.lx && (yy & 1) == 0)	/* moving down */
  32. 		return (within_bounded_area(x, y, dndest.lx, dndest.ly,
  33. 						  dndest.hx, dndest.hy) &&
  34. 		       (!dndest.nlx ||
  35. 			!within_bounded_area(x, y, dndest.nlx, dndest.nly,
  36. 						   dndest.nhx, dndest.nhy)));
  37. 	} else {
  38. 	    /* current location is <xx,yy> */
  39. 	    if (!tele_jump_ok(xx, yy, x, y)) return FALSE;
  40. 	}
  41. 	/* <x,y> is ok */
  42. 	return TRUE;
  43. }

rloc_to[edit]

  1. /*
  2. * rloc_to()
  3. *
  4. * Pulls a monster from its current position and places a monster at
  5. * a new x and y.  If oldx is 0, then the monster was not in the levels.monsters
  6. * array.  However, if oldx is 0, oldy may still have a value because mtmp is a
  7. * migrating_mon.  Worm tails are always placed randomly around the head of
  8. * the worm.
  9. */
  10. void
  11. rloc_to(mtmp, x, y)
  12. struct monst *mtmp;
  13. register int x, y;
  14. {
  15. 	register int oldx = mtmp->mx, oldy = mtmp->my;
  16. 	boolean resident_shk = mtmp->isshk && inhishop(mtmp);
  17.  
  18. 	if (x == mtmp->mx && y == mtmp->my)	/* that was easy */
  19. 		return;
  20.  
  21. 	if (oldx) {				/* "pick up" monster */
  22. 	    if (mtmp->wormno)
  23. 		remove_worm(mtmp);
  24. 	    else {
  25. 		remove_monster(oldx, oldy);
  26. 		newsym(oldx, oldy);		/* update old location */
  27. 	    }
  28. 	}
  29.  
  30. 	place_monster(mtmp, x, y);		/* put monster down */
  31. 	update_monster_region(mtmp);
  32.  
  33. 	if (mtmp->wormno)			/* now put down tail */
  34. 		place_worm_tail_randomly(mtmp, x, y);
  35.  
  36. 	if (u.ustuck == mtmp) {
  37. 		if (u.uswallow) {
  38. 			u.ux = x;
  39. 			u.uy = y;
  40. 			docrt();
  41. 		} else	u.ustuck = 0;
  42. 	}
  43.  
  44. 	newsym(x, y);				/* update new location */
  45. 	set_apparxy(mtmp);			/* orient monster */
  46.  
  47. 	/* shopkeepers will only teleport if you zap them with a wand of
  48. 	   teleportation or if they've been transformed into a jumpy monster;
  49. 	   the latter only happens if you've attacked them with polymorph */
  50. 	if (resident_shk && !inhishop(mtmp)) make_angry_shk(mtmp, oldx, oldy);
  51. }

rloc[edit]

  1. /* place a monster at a random location, typically due to teleport */
  2. /* return TRUE if successful, FALSE if not */
  3. boolean
  4. rloc(mtmp, suppress_impossible)
  5. struct monst *mtmp;	/* mx==0 implies migrating monster arrival */
  6. boolean suppress_impossible;
  7. {
  8. 	register int x, y, trycount;
  9.  
  10. #ifdef STEED
  11. 	if (mtmp == u.usteed) {
  12. 	    tele();
  13. 	    return TRUE;
  14. 	}
  15. #endif
  16.  
  17. 	if (mtmp->iswiz && mtmp->mx) {	/* Wizard, not just arriving */
  18. 	    if (!In_W_tower(u.ux, u.uy, &u.uz))
  19. 		x = xupstair,  y = yupstair;
  20. 	    else if (!xdnladder)	/* bottom level of tower */
  21. 		x = xupladder,  y = yupladder;
  22. 	    else
  23. 		x = xdnladder,  y = ydnladder;
  24. 	    /* if the wiz teleports away to heal, try the up staircase,
  25. 	       to block the player's escaping before he's healed
  26. 	       (deliberately use `goodpos' rather than `rloc_pos_ok' here) */
  27. 	    if (goodpos(x, y, mtmp, 0))
  28. 		goto found_xy;
  29. 	}
  30.  
  31. 	trycount = 0;
  32. 	do {
  33. 	    x = rn1(COLNO-3,2);
  34. 	    y = rn2(ROWNO);
  35. 	    if ((trycount < 500) ? rloc_pos_ok(x, y, mtmp)
  36. 				 : goodpos(x, y, mtmp, 0))
  37. 		goto found_xy;
  38. 	} while (++trycount < 1000);
  39.  
  40. 	/* last ditch attempt to find a good place */
  41. 	for (x = 2; x < COLNO - 1; x++)
  42. 	    for (y = 0; y < ROWNO; y++)
  43. 		if (goodpos(x, y, mtmp, 0))
  44. 		    goto found_xy;
  45.  
  46. 	/* level either full of monsters or somehow faulty */
  47. 	if (!suppress_impossible)
  48. 		impossible("rloc(): couldn't relocate monster");
  49. 	return FALSE;
  50.  
  51. found_xy:
  52. 	rloc_to(mtmp, x, y);
  53. 	return TRUE;
  54. }

mvault_tele[edit]

  1. STATIC_OVL void
  2. mvault_tele(mtmp)
  3. struct monst *mtmp;
  4. {
  5. 	register struct mkroom *croom = search_special(VAULT);
  6. 	coord c;
  7.  
  8. 	if (croom && somexy(croom, &c) &&
  9. 				goodpos(c.x, c.y, mtmp, 0)) {
  10. 		rloc_to(mtmp, c.x, c.y);
  11. 		return;
  12. 	}
  13. 	(void) rloc(mtmp, FALSE);
  14. }

tele_restrict[edit]

  1. boolean
  2. tele_restrict(mon)
  3. struct monst *mon;
  4. {
  5. 	if (level.flags.noteleport) {
  6. 		if (canseemon(mon))
  7. 		    pline("A mysterious force prevents %s from teleporting!",
  8. 			mon_nam(mon));
  9. 		return TRUE;
  10. 	}
  11. 	return FALSE;
  12. }

mtele_trap[edit]

  1. void
  2. mtele_trap(mtmp, trap, in_sight)
  3. struct monst *mtmp;
  4. struct trap *trap;
  5. int in_sight;
  6. {
  7. 	char *monname;
  8.  
  9. 	if (tele_restrict(mtmp)) return;
  10. 	if (teleport_pet(mtmp, FALSE)) {
  11. 	    /* save name with pre-movement visibility */
  12. 	    monname = Monnam(mtmp);
  13.  
  14. 	    /* Note: don't remove the trap if a vault.  Other-
  15. 	     * wise the monster will be stuck there, since
  16. 	     * the guard isn't going to come for it...
  17. 	     */
  18. 	    if (trap->once) mvault_tele(mtmp);
  19. 	    else (void) rloc(mtmp, FALSE);
  20.  
  21. 	    if (in_sight) {
  22. 		if (canseemon(mtmp))
  23. 		    pline("%s seems disoriented.", monname);
  24. 		else
  25. 		    pline("%s suddenly disappears!", monname);
  26. 		seetrap(trap);
  27. 	    }
  28. 	}
  29. }

mlevel_tele_trap[edit]

  1. /* return 0 if still on level, 3 if not */
  2. int
  3. mlevel_tele_trap(mtmp, trap, force_it, in_sight)
  4. struct monst *mtmp;
  5. struct trap *trap;
  6. boolean force_it;
  7. int in_sight;
  8. {
  9. 	int tt = trap->ttyp;
  10. 	struct permonst *mptr = mtmp->data;
  11.  
  12. 	if (mtmp == u.ustuck)	/* probably a vortex */
  13. 	    return 0;		/* temporary? kludge */
  14. 	if (teleport_pet(mtmp, force_it)) {
  15. 	    d_level tolevel;
  16. 	    int migrate_typ = MIGR_RANDOM;
  17.  
  18. 	    if ((tt == HOLE || tt == TRAPDOOR)) {
  19. 		if (Is_stronghold(&u.uz)) {
  20. 		    assign_level(&tolevel, &valley_level);
  21. 		} else if (Is_botlevel(&u.uz)) {
  22. 		    if (in_sight && trap->tseen)
  23. 			pline("%s avoids the %s.", Monnam(mtmp),
  24. 			(tt == HOLE) ? "hole" : "trap");
  25. 		    return 0;
  26. 		} else {
  27. 		    get_level(&tolevel, depth(&u.uz) + 1);
  28. 		}
  29. 	    } else if (tt == MAGIC_PORTAL) {
  30. 		if (In_endgame(&u.uz) &&
  31. 		    (mon_has_amulet(mtmp) || is_home_elemental(mptr))) {
  32. 		    if (in_sight && mptr->mlet != S_ELEMENTAL) {
  33. 			pline("%s seems to shimmer for a moment.",
  34. 							Monnam(mtmp));
  35. 			seetrap(trap);
  36. 		    }
  37. 		    return 0;
  38. 		} else {
  39. 		    assign_level(&tolevel, &trap->dst);
  40. 		    migrate_typ = MIGR_PORTAL;
  41. 		}
  42. 	    } else { /* (tt == LEVEL_TELEP) */
  43. 		int nlev;
  44.  
  45. 		if (mon_has_amulet(mtmp) || In_endgame(&u.uz)) {
  46. 		    if (in_sight)
  47. 			pline("%s seems very disoriented for a moment.",
  48. 				Monnam(mtmp));
  49. 		    return 0;
  50. 		}
  51. 		nlev = random_teleport_level();
  52. 		if (nlev == depth(&u.uz)) {
  53. 		    if (in_sight)
  54. 			pline("%s shudders for a moment.", Monnam(mtmp));
  55. 		    return 0;
  56. 		}
  57. 		get_level(&tolevel, nlev);
  58. 	    }
  59.  
  60. 	    if (in_sight) {
  61. 		pline("Suddenly, %s disappears out of sight.", mon_nam(mtmp));
  62. 		seetrap(trap);
  63. 	    }
  64. 	    migrate_to_level(mtmp, ledger_no(&tolevel),
  65. 			     migrate_typ, (coord *)0);
  66. 	    return 3;	/* no longer on this level */
  67. 	}
  68. 	return 0;
  69. }

rloco[edit]

  1. void
  2. rloco(obj)
  3. register struct obj *obj;
  4. {
  5. 	register xchar tx, ty, otx, oty;
  6. 	boolean restricted_fall;
  7. 	int try_limit = 4000;
  8.  
  9. 	if (obj->otyp == CORPSE && is_rider(&mons[obj->corpsenm])) {
  10. 	    if (revive_corpse(obj)) return;
  11. 	}
  12.  
  13. 	obj_extract_self(obj);
  14. 	otx = obj->ox;
  15. 	oty = obj->oy;
  16. 	restricted_fall = (otx == 0 && dndest.lx);
  17. 	do {
  18. 	    tx = rn1(COLNO-3,2);
  19. 	    ty = rn2(ROWNO);
  20. 	    if (!--try_limit) break;
  21. 	} while (!goodpos(tx, ty, (struct monst *)0, 0) ||
  22. 		/* bug: this lacks provision for handling the Wizard's tower */
  23. 		 (restricted_fall &&
  24. 		  (!within_bounded_area(tx, ty, dndest.lx, dndest.ly,
  25. 						dndest.hx, dndest.hy) ||
  26. 		   (dndest.nlx &&
  27. 		    within_bounded_area(tx, ty, dndest.nlx, dndest.nly,
  28. 						dndest.nhx, dndest.nhy)))));
  29.  
  30. 	if (flooreffects(obj, tx, ty, "fall")) {
  31. 	    return;
  32. 	} else if (otx == 0 && oty == 0) {
  33. 	    ;	/* fell through a trap door; no update of old loc needed */
  34. 	} else {
  35. 	    if (costly_spot(otx, oty)
  36. 	      && (!costly_spot(tx, ty) ||
  37. 		  !index(in_rooms(tx, ty, 0), *in_rooms(otx, oty, 0)))) {
  38. 		if (costly_spot(u.ux, u.uy) &&
  39. 			    index(u.urooms, *in_rooms(otx, oty, 0)))
  40. 		    addtobill(obj, FALSE, FALSE, FALSE);
  41. 		else (void)stolen_value(obj, otx, oty, FALSE, FALSE);
  42. 	    }
  43. 	    newsym(otx, oty);	/* update old location */
  44. 	}
  45. 	place_object(obj, tx, ty);
  46. 	newsym(tx, ty);
  47. }

random_teleport_level[edit]

  1. /* Returns an absolute depth */
  2. int
  3. random_teleport_level()
  4. {
  5. 	int nlev, max_depth, min_depth,
  6. 	    cur_depth = (int)depth(&u.uz);
  7.  
  8. 	if (!rn2(5) || Is_knox(&u.uz))
  9. 	    return cur_depth;
  10.  
  11. 	/* What I really want to do is as follows:
  12. 	 * -- If in a dungeon that goes down, the new level is to be restricted
  13. 	 *    to [top of parent, bottom of current dungeon]
  14. 	 * -- If in a dungeon that goes up, the new level is to be restricted
  15. 	 *    to [top of current dungeon, bottom of parent]
  16. 	 * -- If in a quest dungeon or similar dungeon entered by portals,
  17. 	 *    the new level is to be restricted to [top of current dungeon,
  18. 	 *    bottom of current dungeon]
  19. 	 * The current behavior is not as sophisticated as that ideal, but is
  20. 	 * still better what we used to do, which was like this for players
  21. 	 * but different for monsters for no obvious reason.  Currently, we
  22. 	 * must explicitly check for special dungeons.  We check for Knox
  23. 	 * above; endgame is handled in the caller due to its different
  24. 	 * message ("disoriented").
  25. 	 * --KAA
  26. 	 * 3.4.2: explicitly handle quest here too, to fix the problem of
  27. 	 * monsters sometimes level teleporting out of it into main dungeon.
  28. 	 * Also prevent monsters reaching the Sanctum prior to invocation.
  29. 	 */
  30. 	min_depth = In_quest(&u.uz) ? dungeons[u.uz.dnum].depth_start : 1;
  31. 	max_depth = dunlevs_in_dungeon(&u.uz) +
  32. 			(dungeons[u.uz.dnum].depth_start - 1);
  33. 	/* can't reach the Sanctum if the invocation hasn't been performed */
  34. 	if (Inhell && !u.uevent.invoked) max_depth -= 1;
  35.  
  36. 	/* Get a random value relative to the current dungeon */
  37. 	/* Range is 1 to current+3, current not counting */
  38. 	nlev = rn2(cur_depth + 3 - min_depth) + min_depth;
  39. 	if (nlev >= cur_depth) nlev++;
  40.  
  41. 	if (nlev > max_depth) {
  42. 	    nlev = max_depth;
  43. 	    /* teleport up if already on bottom */
  44. 	    if (Is_botlevel(&u.uz)) nlev -= rnd(3);
  45. 	}
  46. 	if (nlev < min_depth) {
  47. 	    nlev = min_depth;
  48. 	    if (nlev == cur_depth) {
  49. 	        nlev += rnd(3);
  50. 	        if (nlev > max_depth)
  51. 		    nlev = max_depth;
  52. 	    }
  53. 	}
  54. 	return nlev;
  55. }

u_teleport_mon[edit]

  1. /* you teleport a monster (via wand, spell, or poly'd q.mechanic attack);
  2. return false iff the attempt fails */
  3. boolean
  4. u_teleport_mon(mtmp, give_feedback)
  5. struct monst *mtmp;
  6. boolean give_feedback;
  7. {
  8. 	coord cc;
  9.  
  10. 	if (mtmp->ispriest && *in_rooms(mtmp->mx, mtmp->my, TEMPLE)) {
  11. 	    if (give_feedback)
  12. 		pline("%s resists your magic!", Monnam(mtmp));
  13. 	    return FALSE;
  14. 	} else if (level.flags.noteleport && u.uswallow && mtmp == u.ustuck) {
  15. 	    if (give_feedback)
  16. 		You("are no longer inside %s!", mon_nam(mtmp));
  17. 	    unstuck(mtmp);
  18. 	    (void) rloc(mtmp, FALSE);
  19. 	} else if (is_rider(mtmp->data) && rn2(13) &&
  20. 		   enexto(&cc, u.ux, u.uy, mtmp->data))
  21. 	    rloc_to(mtmp, cc.x, cc.y);
  22. 	else
  23. 	    (void) rloc(mtmp, FALSE);
  24. 	return TRUE;
  25. }
  26.  
  27. /*teleport.c*/