Source:NetHack 3.4.3/src/hack.c

From NetHackWiki
(Redirected from Source:Hack.c)
Jump to: navigation, search

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

Top of file[edit]

  1. /*	SCCS Id: @(#)hack.c	3.4	2003/04/30	*/
  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. #ifdef OVL1
  4. STATIC_DCL void NDECL(maybe_wail);
  5. #endif /*OVL1*/
  6. STATIC_DCL int NDECL(moverock);
  7. STATIC_DCL int FDECL(still_chewing,(XCHAR_P,XCHAR_P));
  8. #ifdef SINKS
  9. STATIC_DCL void NDECL(dosinkfall);
  10. #endif
  11. STATIC_DCL boolean FDECL(findtravelpath, (BOOLEAN_P));
  12. STATIC_DCL boolean FDECL(monstinroom, (struct permonst *,int));
  13.  
  14. STATIC_DCL void FDECL(move_update, (BOOLEAN_P));
  15.  
  16. #define IS_SHOP(x)	(rooms[x].rtype >= SHOPBASE)

revive_nasty[edit]

  1. #ifdef OVL2
  2.  
  3. boolean
  4. revive_nasty(x, y, msg)
  5. int x,y;
  6. const char *msg;
  7. {
  8. register struct obj *otmp, *otmp2;
  9. struct monst *mtmp;
  10. coord cc;
  11. boolean revived = FALSE;
  12.  
  13. for(otmp = level.objects[x][y]; otmp; otmp = otmp2) {
  14. 	otmp2 = otmp->nexthere;
  15. 	if (otmp->otyp == CORPSE &&
  16. 	    (is_rider(&mons[otmp->corpsenm]) ||
  17. 	     otmp->corpsenm == PM_WIZARD_OF_YENDOR)) {
  18. 	    /* move any living monster already at that location */
  19. 	    if((mtmp = m_at(x,y)) && enexto(&cc, x, y, mtmp->data))
  20. 		rloc_to(mtmp, cc.x, cc.y);
  21. 	    if(msg) Norep("%s", msg);
  22. 	    revived = revive_corpse(otmp);
  23. 	}
  24. }
  25.  
  26. /* this location might not be safe, if not, move revived monster */
  27. if (revived) {
  28. 	mtmp = m_at(x,y);
  29. 	if (mtmp && !goodpos(x, y, mtmp, 0) &&
  30. 	    enexto(&cc, x, y, mtmp->data)) {
  31. 	    rloc_to(mtmp, cc.x, cc.y);
  32. 	}
  33. 	/* else impossible? */
  34. }
  35.  
  36. return (revived);
  37. }

moverock[edit]

Called when the player attempts to move into a space occupied by a boulder. The player may push the boulder, fail to move the boulder, or squeeze into the same space as the boulder.

  1. STATIC_OVL int
  2. moverock()
  3. {
  4. register xchar rx, ry, sx, sy;
  5. register struct obj *otmp;
  6. register struct trap *ttmp;
  7. register struct monst *mtmp;
  8.  
  9. sx = u.ux + u.dx,  sy = u.uy + u.dy;	/* boulder starting position */
  10. while ((otmp = sobj_at(BOULDER, sx, sy)) != 0) {
  11. 	/* make sure that this boulder is visible as the top object */
  12. 	if (otmp != level.objects[sx][sy]) movobj(otmp, sx, sy);
  13.  
  14. 	rx = u.ux + 2 * u.dx;	/* boulder destination position */
  15. 	ry = u.uy + 2 * u.dy;
  16. 	nomul(0);
  17. 	if (Levitation || Is_airlevel(&u.uz)) {
  18. 	    if (Blind) feel_location(sx, sy);
  19. 	    You("don't have enough leverage to push %s.", the(xname(otmp)));
  20. 	    /* Give them a chance to climb over it? */
  21. 	    return -1;
  22. 	}

You can't push boulders while levitating or on the Plane of Air.

  1. 	if (verysmall(youmonst.data)
  2. #ifdef STEED
  3. 		 && !u.usteed
  4. #endif
  5. 				    ) {
  6. 	    if (Blind) feel_location(sx, sy);
  7. 	    pline("You're too small to push that %s.", xname(otmp));
  8. 	    goto cannot_push;
  9. 	}

If you are polymorphed into a very small monster and are not riding a steed, you cannot push boulders.

  1. 	if (isok(rx,ry) && !IS_ROCK(levl[rx][ry].typ) &&
  2. 	    levl[rx][ry].typ != IRONBARS &&
  3. 	    (!IS_DOOR(levl[rx][ry].typ) || !(u.dx && u.dy) || (
  4. #ifdef REINCARNATION
  5. 		!Is_rogue_level(&u.uz) &&
  6. #endif
  7. 		(levl[rx][ry].doormask & ~D_BROKEN) == D_NODOOR)) &&
  8. 	    !sobj_at(BOULDER, rx, ry)) {
  9. 	    ttmp = t_at(rx, ry);
  10. 	    mtmp = m_at(rx, ry);

Pushing the boulder may be successful if the destination is on the map, you are not trying to push into rock or iron bars, not trying to push diagonally through a door or Rogue level doorway, and not trying to push into a space already containing a boulder. If you may be successful, we store the trap and the monster at the destination, for the following sections of code.

  1. 		/* KMH -- Sokoban doesn't let you push boulders diagonally */
  2. 	    if (In_sokoban(&u.uz) && u.dx && u.dy) {
  3. 	    	if (Blind) feel_location(sx,sy);
  4. 	    	pline("%s won't roll diagonally on this %s.",
  5. 	        		The(xname(otmp)), surface(sx, sy));
  6. 	    	goto cannot_push;
  7. 	    }

You can't push boulders diagonally in Sokoban.

  1. 	    if (revive_nasty(rx, ry, "You sense movement on the other side."))
  2. 		return (-1);

Try to revive a nasty corpse, such as a Rider on the other side. If so, the corpse comes back to life and you can't push the boulder.

  1. 	    if (mtmp && !noncorporeal(mtmp->data) &&
  2. 		    (!mtmp->mtrapped ||
  3. 			 !(ttmp && ((ttmp->ttyp == PIT) ||
  4. 				    (ttmp->ttyp == SPIKED_PIT))))) {
  5. 		if (Blind) feel_location(sx, sy);
  6. 		if (canspotmon(mtmp))
  7. 		    pline("There's %s on the other side.", a_monnam(mtmp));
  8. 		else {
  9. 		    You_hear("a monster behind %s.", the(xname(otmp)));
  10. 		    map_invisible(rx, ry);
  11. 		}
  12. 		if (flags.verbose)
  13. 		    pline("Perhaps that's why %s cannot move it.",
  14. #ifdef STEED
  15. 				u.usteed ? y_monnam(u.usteed) :
  16. #endif
  17. 				"you");
  18. 		goto cannot_push;
  19. 	    }

If there is a monster with a body that is not trapped in a pit or spiked pit at the destination square, you can't push the boulder.

  1. 	    if (ttmp)
  2. 		switch(ttmp->ttyp) {

The following code handles any traps on the destination square.

  1. 		case LANDMINE:
  2. 		    if (rn2(10)) {
  3. 			obj_extract_self(otmp);
  4. 			place_object(otmp, rx, ry);
  5. 			unblock_point(sx, sy);
  6. 			newsym(sx, sy);
  7. 			pline("KAABLAMM!!!  %s %s land mine.",
  8. 			      Tobjnam(otmp, "trigger"),
  9. 			      ttmp->madeby_u ? "your" : "a");
  10. 			blow_up_landmine(ttmp);
  11. 			/* if the boulder remains, it should fill the pit */
  12. 			fill_pit(u.ux, u.uy);
  13. 			if (cansee(rx,ry)) newsym(rx,ry);
  14. 			continue;
  15. 		    }
  16. 		    break;

If you push into a landmine, it will trigger the landmine with 90% probability. If the boulder is not broken or destroyed by the resulting explosion, it will fill the resulting pit.

  1. 		case SPIKED_PIT:
  2. 		case PIT:
  3. 		    obj_extract_self(otmp);
  4. 		    /* vision kludge to get messages right;
  5. 		       the pit will temporarily be seen even
  6. 		       if this is one among multiple boulders */
  7. 		    if (!Blind) viz_array[ry][rx] |= IN_SIGHT;
  8. 		    if (!flooreffects(otmp, rx, ry, "fall")) {
  9. 			place_object(otmp, rx, ry);
  10. 		    }
  11. 		    if (mtmp && !Blind) newsym(rx, ry);
  12. 		    continue;

Pushing a boulder into a pit or spiked pit will cause damage to a trapped monster. If the monster dies, the boulder will fill the pit, removing the trap.

  1. 		case HOLE:
  2. 		case TRAPDOOR:
  3. 		    if (Blind)
  4. 			pline("Kerplunk!  You no longer feel %s.",
  5. 				the(xname(otmp)));
  6. 		    else
  7. 			pline("%s%s and %s a %s in the %s!",
  8. 			  Tobjnam(otmp,
  9. 			   (ttmp->ttyp == TRAPDOOR) ? "trigger" : "fall"),
  10. 			  (ttmp->ttyp == TRAPDOOR) ? nul : " into",
  11. 			  otense(otmp, "plug"),
  12. 			  (ttmp->ttyp == TRAPDOOR) ? "trap door" : "hole",
  13. 			  surface(rx, ry));
  14. 		    deltrap(ttmp);
  15. 		    delobj(otmp);
  16. 		    bury_objs(rx, ry);
  17. 		    if (cansee(rx,ry)) newsym(rx,ry);
  18. 		    continue;

Pushing a boulder into a hole or trapdoor will remove the trap and the boulder.

  1. 		case LEVEL_TELEP:
  2. 		case TELEP_TRAP:
  3. #ifdef STEED
  4. 		    if (u.usteed)
  5. 			pline("%s pushes %s and suddenly it disappears!",
  6. 			      upstart(y_monnam(u.usteed)), the(xname(otmp)));
  7. 		    else
  8. #endif
  9. 		    You("push %s and suddenly it disappears!",
  10. 			the(xname(otmp)));
  11. 		    if (ttmp->ttyp == TELEP_TRAP)
  12. 			rloco(otmp);
  13. 		    else {
  14. 			int newlev = random_teleport_level();
  15. 			d_level dest;
  16.  
  17. 			if (newlev == depth(&u.uz) || In_endgame(&u.uz))
  18. 			    continue;
  19. 			obj_extract_self(otmp);
  20. 			add_to_migration(otmp);
  21. 			get_level(&dest, newlev);
  22. 			otmp->ox = dest.dnum;
  23. 			otmp->oy = dest.dlevel;
  24. 			otmp->owornmask = (long)MIGR_RANDOM;
  25. 		    }
  26. 		    seetrap(ttmp);
  27. 		    continue;

If you push the boulder into a teleportation or level teleportation trap, the boulder will teleport.

  1. 		}
  2. 	    if (closed_door(rx, ry))
  3. 		goto nopushmsg;

You can't push a boulder into a closed door.

  1. 	    if (boulder_hits_pool(otmp, rx, ry, TRUE))
  2. 		continue;

If the boulder is being pushed into water or lava, it will be consumed and may or may not fill the space.

  1. 	    /*
  2. 	     * Re-link at top of fobj chain so that pile order is preserved
  3. 	     * when level is restored.
  4. 	     */
  5. 	    if (otmp != fobj) {
  6. 		remove_object(otmp);
  7. 		place_object(otmp, otmp->ox, otmp->oy);
  8. 	    }
  9.  
  10. 	    {
  11. #ifdef LINT /* static long lastmovetime; */
  12. 		long lastmovetime;
  13. 		lastmovetime = 0;
  14. #else
  15. 		/* note: reset to zero after save/restore cycle */
  16. 		static NEARDATA long lastmovetime;
  17. #endif

Designed to prevent consecutive "With great effort you move the boulder" messages from appearing.

  1. #ifdef STEED
  2. 		if (!u.usteed) {
  3. #endif
  4. 		  if (moves > lastmovetime+2 || moves < lastmovetime)
  5. 		    pline("With %s effort you move %s.",
  6. 			  throws_rocks(youmonst.data) ? "little" : "great",
  7. 			  the(xname(otmp)));

The message will only appear if you haven't pushed a boulder within the past three turns.

  1. 		  exercise(A_STR, TRUE);

Pushing boulders exercises strength.

  1. #ifdef STEED
  2. 		} else 
  3. 		    pline("%s moves %s.",
  4. 			  upstart(y_monnam(u.usteed)), the(xname(otmp)));
  5. #endif
  6. 		lastmovetime = moves;
  7. 	    }
  8.  
  9. 	    /* Move the boulder *after* the message. */
  10. 	    if (glyph_is_invisible(levl[rx][ry].glyph))
  11. 		unmap_object(rx, ry);
  12. 	    movobj(otmp, rx, ry);	/* does newsym(rx,ry) */
  13. 	    if (Blind) {
  14. 		feel_location(rx,ry);
  15. 		feel_location(sx, sy);
  16. 	    } else {
  17. 		newsym(sx, sy);
  18. 	    }
  19. 	} else {

This code moves the boulder, then updates the map and has you feel the square the boulder was originally on (if you were blind).

  1. 	nopushmsg:
  2. #ifdef STEED
  3. 	  if (u.usteed)
  4. 	    pline("%s tries to move %s, but cannot.",
  5. 		  upstart(y_monnam(u.usteed)), the(xname(otmp)));
  6. 	  else
  7. #endif
  8. 	    You("try to move %s, but in vain.", the(xname(otmp)));
  9. 	    if (Blind) feel_location(sx, sy);
  10. 	cannot_push:

If you were not able to push the boulder for some reason, the following code happens.

  1. 	    if (throws_rocks(youmonst.data)) {
  2. #ifdef STEED
  3. 		if (u.usteed && P_SKILL(P_RIDING) < P_BASIC) {
  4. 		    You("aren't skilled enough to %s %s from %s.",
  5. 			(flags.pickup && !In_sokoban(&u.uz))
  6. 			    ? "pick up" : "push aside",
  7. 			the(xname(otmp)), y_monnam(u.usteed));
  8. 		} else
  9. #endif
  10. 		{
  11. 		    pline("However, you can easily %s.",
  12. 			(flags.pickup && !In_sokoban(&u.uz))
  13. 			    ? "pick it up" : "push it aside");
  14. 		    if (In_sokoban(&u.uz))
  15. 			change_luck(-1);	/* Sokoban guilt */
  16. 		    break;
  17. 		}

If you can throw rocks are are not riding a steed unskilled, you can pick up the boulder or move into its space. If you do that in Sokoban, there is a luck penalty.

  1. 		break;
  2. 	    }
  3.  
  4. 	    if (
  5. #ifdef STEED
  6. 		!u.usteed &&
  7. #endif	    
  8. 		(((!invent || inv_weight() <= -850) &&
  9. 		 (!u.dx || !u.dy || (IS_ROCK(levl[u.ux][sy].typ)
  10. 				     && IS_ROCK(levl[sx][u.uy].typ))))
  11. 		|| verysmall(youmonst.data))) {
  12. 		pline("However, you can squeeze yourself into a small opening.");
  13. 		if (In_sokoban(&u.uz))
  14. 		    change_luck(-1);	/* Sokoban guilt */
  15. 		break;
  16. 	    } else
  17. 		return (-1);

If you are not on a steed and either are very small, carrying nothing or your inventory is 850 or more units below your carrying capacity, you can occupy the same space as the boulder. Again, this incurs a luck penalty in Sokoban.

  1. 	}
  2. }
  3. return (0);
  4. }

still_chewing[edit]

  1. /*
  2. *  still_chewing()
  3. *
  4. *  Chew on a wall, door, or boulder.  Returns TRUE if still eating, FALSE
  5. *  when done.
  6. */
  7. STATIC_OVL int
  8. still_chewing(x,y)
  9. xchar x, y;
  10. {
  11. struct rm *lev = &levl[x][y];
  12. struct obj *boulder = sobj_at(BOULDER,x,y);
  13. const char *digtxt = (char *)0, *dmgtxt = (char *)0;
  14.  
  15. if (digging.down)		/* not continuing previous dig (w/ pick-axe) */
  16. 	(void) memset((genericptr_t)&digging, 0, sizeof digging);
  17.  
  18. if (!boulder && IS_ROCK(lev->typ) && !may_dig(x,y)) {
  19. 	You("hurt your teeth on the %s.",
  20. 	    IS_TREE(lev->typ) ? "tree" : "hard stone");
  21. 	nomul(0);
  22. 	return 1;
  23. } else if (digging.pos.x != x || digging.pos.y != y ||
  24. 		!on_level(&digging.level, &u.uz)) {
  25. 	digging.down = FALSE;
  26. 	digging.chew = TRUE;
  27. 	digging.warned = FALSE;
  28. 	digging.pos.x = x;
  29. 	digging.pos.y = y;
  30. 	assign_level(&digging.level, &u.uz);
  31. 	/* solid rock takes more work & time to dig through */
  32. 	digging.effort =
  33. 	    (IS_ROCK(lev->typ) && !IS_TREE(lev->typ) ? 30 : 60) + u.udaminc;
  34. 	You("start chewing %s %s.",
  35. 	    (boulder || IS_TREE(lev->typ)) ? "on a" : "a hole in the",
  36. 	    boulder ? "boulder" :
  37. 	    IS_TREE(lev->typ) ? "tree" : IS_ROCK(lev->typ) ? "rock" : "door");
  38. 	watch_dig((struct monst *)0, x, y, FALSE);
  39. 	return 1;
  40. } else if ((digging.effort += (30 + u.udaminc)) <= 100)  {
  41. 	if (flags.verbose)
  42. 	    You("%s chewing on the %s.",
  43. 		digging.chew ? "continue" : "begin",
  44. 		boulder ? "boulder" :
  45. 		IS_TREE(lev->typ) ? "tree" :
  46. 		IS_ROCK(lev->typ) ? "rock" : "door");
  47. 	digging.chew = TRUE;
  48. 	watch_dig((struct monst *)0, x, y, FALSE);
  49. 	return 1;
  50. }
  51.  
  52. /* Okay, you've chewed through something */
  53. u.uconduct.food++;
  54. u.uhunger += rnd(20);
  55.  
  56. if (boulder) {
  57. 	delobj(boulder);		/* boulder goes bye-bye */
  58. 	You("eat the boulder.");	/* yum */
  59.  
  60. 	/*
  61. 	 *  The location could still block because of
  62. 	 *	1. More than one boulder
  63. 	 *	2. Boulder stuck in a wall/stone/door.
  64. 	 *
  65. 	 *  [perhaps use does_block() below (from vision.c)]
  66. 	 */
  67. 	if (IS_ROCK(lev->typ) || closed_door(x,y) || sobj_at(BOULDER,x,y)) {
  68. 	    block_point(x,y);	/* delobj will unblock the point */
  69. 	    /* reset dig state */
  70. 	    (void) memset((genericptr_t)&digging, 0, sizeof digging);
  71. 	    return 1;
  72. 	}
  73.  
  74. } else if (IS_WALL(lev->typ)) {
  75. 	if (*in_rooms(x, y, SHOPBASE)) {
  76. 	    add_damage(x, y, 10L * ACURRSTR);
  77. 	    dmgtxt = "damage";
  78. 	}
  79. 	digtxt = "chew a hole in the wall.";
  80. 	if (level.flags.is_maze_lev) {
  81. 	    lev->typ = ROOM;
  82. 	} else if (level.flags.is_cavernous_lev && !in_town(x, y)) {
  83. 	    lev->typ = CORR;
  84. 	} else {
  85. 	    lev->typ = DOOR;
  86. 	    lev->doormask = D_NODOOR;
  87. 	}
  88. } else if (IS_TREE(lev->typ)) {
  89. 	digtxt = "chew through the tree.";
  90. 	lev->typ = ROOM;
  91. } else if (lev->typ == SDOOR) {
  92. 	if (lev->doormask & D_TRAPPED) {
  93. 	    lev->doormask = D_NODOOR;
  94. 	    b_trapped("secret door", 0);
  95. 	} else {
  96. 	    digtxt = "chew through the secret door.";
  97. 	    lev->doormask = D_BROKEN;
  98. 	}
  99. 	lev->typ = DOOR;
  100.  
  101. } else if (IS_DOOR(lev->typ)) {
  102. 	if (*in_rooms(x, y, SHOPBASE)) {
  103. 	    add_damage(x, y, 400L);
  104. 	    dmgtxt = "break";
  105. 	}
  106. 	if (lev->doormask & D_TRAPPED) {
  107. 	    lev->doormask = D_NODOOR;
  108. 	    b_trapped("door", 0);
  109. 	} else {
  110. 	    digtxt = "chew through the door.";
  111. 	    lev->doormask = D_BROKEN;
  112. 	}
  113.  
  114. } else { /* STONE or SCORR */
  115. 	digtxt = "chew a passage through the rock.";
  116. 	lev->typ = CORR;
  117. }
  118.  
  119. unblock_point(x, y);	/* vision */
  120. newsym(x, y);
  121. if (digtxt) You(digtxt);	/* after newsym */
  122. if (dmgtxt) pay_for_damage(dmgtxt, FALSE);
  123. (void) memset((genericptr_t)&digging, 0, sizeof digging);
  124. return 0;
  125. }
  126.  
  127. #endif /* OVL2 */

movobj[edit]

  1. #ifdef OVLB
  2.  
  3. void
  4. movobj(obj, ox, oy)
  5. register struct obj *obj;
  6. register xchar ox, oy;
  7. {
  8. 	/* optimize by leaving on the fobj chain? */
  9. 	remove_object(obj);
  10. 	newsym(obj->ox, obj->oy);
  11. 	place_object(obj, ox, oy);
  12. 	newsym(ox, oy);
  13. }

dosinkfall[edit]

  1. #ifdef SINKS
  2. static NEARDATA const char fell_on_sink[] = "fell onto a sink";
  3.  
  4. STATIC_OVL void
  5. dosinkfall()
  6. {
  7. 	register struct obj *obj;
  8.  
  9. 	if (is_floater(youmonst.data) || (HLevitation & FROMOUTSIDE)) {
  10. 	    You("wobble unsteadily for a moment.");
  11. 	} else {
  12. 	    long save_ELev = ELevitation, save_HLev = HLevitation;
  13.  
  14. 	    /* fake removal of levitation in advance so that final
  15. 	       disclosure will be right in case this turns out to
  16. 	       be fatal; fortunately the fact that rings and boots
  17. 	       are really still worn has no effect on bones data */
  18. 	    ELevitation = HLevitation = 0L;
  19. 	    You("crash to the floor!");
  20. 	    losehp(rn1(8, 25 - (int)ACURR(A_CON)),
  21. 		   fell_on_sink, NO_KILLER_PREFIX);
  22. 	    exercise(A_DEX, FALSE);
  23. 	    selftouch("Falling, you");
  24. 	    for (obj = level.objects[u.ux][u.uy]; obj; obj = obj->nexthere)
  25. 		if (obj->oclass == WEAPON_CLASS || is_weptool(obj)) {
  26. 		    You("fell on %s.", doname(obj));
  27. 		    losehp(rnd(3), fell_on_sink, NO_KILLER_PREFIX);
  28. 		    exercise(A_CON, FALSE);
  29. 		}
  30. 	    ELevitation = save_ELev;
  31. 	    HLevitation = save_HLev;
  32. 	}
  33.  
  34. 	ELevitation &= ~W_ARTI;
  35. 	HLevitation &= ~(I_SPECIAL|TIMEOUT);
  36. 	HLevitation++;
  37. 	if(uleft && uleft->otyp == RIN_LEVITATION) {
  38. 	    obj = uleft;
  39. 	    Ring_off(obj);
  40. 	    off_msg(obj);
  41. 	}
  42. 	if(uright && uright->otyp == RIN_LEVITATION) {
  43. 	    obj = uright;
  44. 	    Ring_off(obj);
  45. 	    off_msg(obj);
  46. 	}
  47. 	if(uarmf && uarmf->otyp == LEVITATION_BOOTS) {
  48. 	    obj = uarmf;
  49. 	    (void)Boots_off();
  50. 	    off_msg(obj);
  51. 	}
  52. 	HLevitation--;
  53. }
  54. #endif

may_dig[edit]

  1. boolean
  2. may_dig(x,y)
  3. register xchar x,y;
  4. /* intended to be called only on ROCKs */
  5. {
  6. return (boolean)(!(IS_STWALL(levl[x][y].typ) &&
  7. 			(levl[x][y].wall_info & W_NONDIGGABLE)));
  8. }

may_passwall[edit]

  1. boolean
  2. may_passwall(x,y)
  3. register xchar x,y;
  4. {
  5. return (boolean)(!(IS_STWALL(levl[x][y].typ) &&
  6. 			(levl[x][y].wall_info & W_NONPASSWALL)));
  7. }
  8.  
  9. #endif /* OVLB */

bad_rock[edit]

  1. #ifdef OVL1
  2.  
  3. boolean
  4. bad_rock(mdat,x,y)
  5. struct permonst *mdat;
  6. register xchar x,y;
  7. {
  8. 	return((boolean) ((In_sokoban(&u.uz) && sobj_at(BOULDER,x,y)) ||
  9. 	       (IS_ROCK(levl[x][y].typ)
  10. 		    && (!tunnels(mdat) || needspick(mdat) || !may_dig(x,y))
  11. 		    && !(passes_walls(mdat) && may_passwall(x,y)))));
  12. }

invocation_pos[edit]

  1. boolean
  2. invocation_pos(x, y)
  3. xchar x, y;
  4. {
  5. 	return((boolean)(Invocation_lev(&u.uz) && x == inv_pos.x && y == inv_pos.y));
  6. }
  7.  
  8. #endif /* OVL1 */

test_move[edit]

  1. #ifdef OVL3
  2.  
  3. /* return TRUE if (dx,dy) is an OK place to move
  4. * mode is one of DO_MOVE, TEST_MOVE or TEST_TRAV
  5. */
  6. boolean 
  7. test_move(ux, uy, dx, dy, mode)
  8. int ux, uy, dx, dy;
  9. int mode;
  10. {
  11. int x = ux+dx;
  12. int y = uy+dy;
  13. register struct rm *tmpr = &levl[x][y];
  14. register struct rm *ust;
  15.  
  16. /*
  17. *  Check for physical obstacles.  First, the place we are going.
  18. */
  19. if (IS_ROCK(tmpr->typ) || tmpr->typ == IRONBARS) {
  20. 	if (Blind && mode == DO_MOVE) feel_location(x,y);
  21. 	if (Passes_walls && may_passwall(x,y)) {
  22. 	    ;	/* do nothing */
  23. 	} else if (tmpr->typ == IRONBARS) {
  24. 	    if (!(Passes_walls || passes_bars(youmonst.data)))
  25. 		return FALSE;
  26. 	} else if (tunnels(youmonst.data) && !needspick(youmonst.data)) {
  27. 	    /* Eat the rock. */
  28. 	    if (mode == DO_MOVE && still_chewing(x,y)) return FALSE;
  29. 	} else if (flags.autodig && !flags.run && !flags.nopick &&
  30. 		   uwep && is_pick(uwep)) {
  31. 	/* MRKR: Automatic digging when wielding the appropriate tool */
  32. 	    if (mode == DO_MOVE)
  33. 		(void) use_pick_axe2(uwep);
  34. 	    return FALSE;
  35. 	} else {
  36. 	    if (mode == DO_MOVE) {
  37. 		if (Is_stronghold(&u.uz) && is_db_wall(x,y))
  38. 		    pline_The("drawbridge is up!");
  39. 		if (Passes_walls && !may_passwall(x,y) && In_sokoban(&u.uz))
  40. 		    pline_The("Sokoban walls resist your ability.");
  41. 	    }
  42. 	    return FALSE;
  43. 	}
  44. } else if (IS_DOOR(tmpr->typ)) {
  45. 	if (closed_door(x,y)) {
  46. 	    if (Blind && mode == DO_MOVE) feel_location(x,y);
  47. 	    if (Passes_walls)
  48. 		;	/* do nothing */
  49. 	    else if (can_ooze(&youmonst)) {
  50. 		if (mode == DO_MOVE) You("ooze under the door.");
  51. 	    } else if (tunnels(youmonst.data) && !needspick(youmonst.data)) {
  52. 		/* Eat the door. */
  53. 		if (mode == DO_MOVE && still_chewing(x,y)) return FALSE;
  54. 	    } else {
  55. 		if (mode == DO_MOVE) {
  56. 		    if (amorphous(youmonst.data))
  57. 			You("try to ooze under the door, but can't squeeze your possessions through.");
  58. 		    else if (x == ux || y == uy) {
  59. 			if (Blind || Stunned || ACURR(A_DEX) < 10 || Fumbling) {
  60. #ifdef STEED
  61. 			    if (u.usteed) {
  62. 				You_cant("lead %s through that closed door.",
  63. 				         y_monnam(u.usteed));
  64. 			    } else
  65. #endif
  66. 			    {
  67. 			        pline("Ouch!  You bump into a door.");
  68. 			        exercise(A_DEX, FALSE);
  69. 			    }
  70. 			} else pline("That door is closed.");
  71. 		    }
  72. 		} else if (mode == TEST_TRAV) goto testdiag;
  73. 		return FALSE;
  74. 	    }
  75. 	} else {
  76. 	testdiag:
  77. 	    if (dx && dy && !Passes_walls
  78. 		&& ((tmpr->doormask & ~D_BROKEN)
  79. #ifdef REINCARNATION
  80. 		    || Is_rogue_level(&u.uz)
  81. #endif
  82. 		    || block_door(x,y))) {
  83. 		/* Diagonal moves into a door are not allowed. */
  84. 		if (Blind && mode == DO_MOVE)
  85. 		    feel_location(x,y);
  86. 		return FALSE;
  87. 	    }
  88. 	}
  89. }
  90. if (dx && dy
  91. 	    && bad_rock(youmonst.data,ux,y) && bad_rock(youmonst.data,x,uy)) {
  92. 	/* Move at a diagonal. */
  93. 	if (In_sokoban(&u.uz)) {
  94. 	    if (mode == DO_MOVE)
  95. 		You("cannot pass that way.");
  96. 	    return FALSE;
  97. 	}
  98. 	if (bigmonst(youmonst.data)) {
  99. 	    if (mode == DO_MOVE)
  100. 		Your("body is too large to fit through.");
  101. 	    return FALSE;
  102. 	}
  103. 	if (invent && (inv_weight() + weight_cap() > 600)) {
  104. 	    if (mode == DO_MOVE)
  105. 		You("are carrying too much to get through.");
  106. 	    return FALSE;
  107. 	}
  108. }
  109. /* Pick travel path that does not require crossing a trap.
  110. * Avoid water and lava using the usual running rules.
  111. * (but not u.ux/u.uy because findtravelpath walks toward u.ux/u.uy) */
  112. if (flags.run == 8 && mode != DO_MOVE && (x != u.ux || y != u.uy)) {
  113. 	struct trap* t = t_at(x, y);
  114.  
  115. 	if ((t && t->tseen) ||
  116. 	    (!Levitation && !Flying &&
  117. 	     !is_clinger(youmonst.data) &&
  118. 	     (is_pool(x, y) || is_lava(x, y)) && levl[x][y].seenv))
  119. 	    return FALSE;
  120. }
  121.  
  122. ust = &levl[ux][uy];
  123.  
  124. /* Now see if other things block our way . . */
  125. if (dx && dy && !Passes_walls
  126. 		     && (IS_DOOR(ust->typ) && ((ust->doormask & ~D_BROKEN)
  127. #ifdef REINCARNATION
  128. 			     || Is_rogue_level(&u.uz)
  129. #endif
  130. 			     || block_entry(x, y))
  131. 			 )) {
  132. 	/* Can't move at a diagonal out of a doorway with door. */
  133. 	return FALSE;
  134. }
  135.  
  136. if (sobj_at(BOULDER,x,y) && (In_sokoban(&u.uz) || !Passes_walls)) {
  137. 	if (!(Blind || Hallucination) && (flags.run >= 2) && mode != TEST_TRAV)
  138. 	    return FALSE;
  139. 	if (mode == DO_MOVE) {
  140. 	    /* tunneling monsters will chew before pushing */
  141. 	    if (tunnels(youmonst.data) && !needspick(youmonst.data) &&
  142. 		!In_sokoban(&u.uz)) {
  143. 		if (still_chewing(x,y)) return FALSE;
  144. 	    } else
  145. 		if (moverock() < 0) return FALSE;
  146. 	} else if (mode == TEST_TRAV) {
  147. 	    struct obj* obj;
  148.  
  149. 	    /* don't pick two boulders in a row, unless there's a way thru */
  150. 	    if (sobj_at(BOULDER,ux,uy) && !In_sokoban(&u.uz)) {
  151. 		if (!Passes_walls &&
  152. 		    !(tunnels(youmonst.data) && !needspick(youmonst.data)) &&
  153. 		    !carrying(PICK_AXE) && !carrying(DWARVISH_MATTOCK) &&
  154. 		    !((obj = carrying(WAN_DIGGING)) &&
  155. 		      !objects[obj->otyp].oc_name_known))
  156. 		    return FALSE;
  157. 	    }
  158. 	}
  159. 	/* assume you'll be able to push it when you get there... */
  160. }
  161.  
  162. /* OK, it is a legal place to move. */
  163. return TRUE;
  164. }

findtravelpath[edit]

  1. /*
  2. * Find a path from the destination (u.tx,u.ty) back to (u.ux,u.uy).
  3. * A shortest path is returned.  If guess is TRUE, consider various
  4. * inaccessible locations as valid intermediate path points.
  5. * Returns TRUE if a path was found.
  6. */
  7. static boolean
  8. findtravelpath(guess)
  9. boolean guess;
  10. {
  11. /* if travel to adjacent, reachable location, use normal movement rules */
  12. if (!guess && iflags.travel1 && distmin(u.ux, u.uy, u.tx, u.ty) == 1) {
  13. 	flags.run = 0;
  14. 	if (test_move(u.ux, u.uy, u.tx-u.ux, u.ty-u.uy, TEST_MOVE)) {
  15. 	    u.dx = u.tx-u.ux;
  16. 	    u.dy = u.ty-u.uy;
  17. 	    nomul(0);
  18. 	    iflags.travelcc.x = iflags.travelcc.y = -1;
  19. 	    return TRUE;
  20. 	}
  21. 	flags.run = 8;
  22. }
  23. if (u.tx != u.ux || u.ty != u.uy) {
  24. 	xchar travel[COLNO][ROWNO];
  25. 	xchar travelstepx[2][COLNO*ROWNO];
  26. 	xchar travelstepy[2][COLNO*ROWNO];
  27. 	xchar tx, ty, ux, uy;
  28. 	int n = 1;			/* max offset in travelsteps */
  29. 	int set = 0;			/* two sets current and previous */
  30. 	int radius = 1;			/* search radius */
  31. 	int i;
  32.  
  33. 	/* If guessing, first find an "obvious" goal location.  The obvious
  34. 	 * goal is the position the player knows of, or might figure out
  35. 	 * (couldsee) that is closest to the target on a straight path.
  36. 	 */
  37. 	if (guess) {
  38. 	    tx = u.ux; ty = u.uy; ux = u.tx; uy = u.ty;
  39. 	} else {
  40. 	    tx = u.tx; ty = u.ty; ux = u.ux; uy = u.uy;
  41. 	}
  42.  
  43. noguess:
  44. 	(void) memset((genericptr_t)travel, 0, sizeof(travel));
  45. 	travelstepx[0][0] = tx;
  46. 	travelstepy[0][0] = ty;
  47.  
  48. 	while (n != 0) {
  49. 	    int nn = 0;
  50.  
  51. 	    for (i = 0; i < n; i++) {
  52. 		int dir;
  53. 		int x = travelstepx[set][i];
  54. 		int y = travelstepy[set][i];
  55. 		static int ordered[] = { 0, 2, 4, 6, 1, 3, 5, 7 };
  56. 		/* no diagonal movement for grid bugs */
  57. 		int dirmax = u.umonnum == PM_GRID_BUG ? 4 : 8;
  58.  
  59. 		for (dir = 0; dir < dirmax; ++dir) {
  60. 		    int nx = x+xdir[ordered[dir]];
  61. 		    int ny = y+ydir[ordered[dir]];
  62.  
  63. 		    if (!isok(nx, ny)) continue;
  64. 		    if ((!Passes_walls && !can_ooze(&youmonst) &&
  65. 			closed_door(x, y)) || sobj_at(BOULDER, x, y)) {
  66. 			/* closed doors and boulders usually
  67. 			 * cause a delay, so prefer another path */
  68. 			if (travel[x][y] > radius-3) {
  69. 			    travelstepx[1-set][nn] = x;
  70. 			    travelstepy[1-set][nn] = y;
  71. 			    /* don't change travel matrix! */
  72. 			    nn++;
  73. 			    continue;
  74. 			}
  75. 		    }
  76. 		    if (test_move(x, y, nx-x, ny-y, TEST_TRAV) &&
  77. 			(levl[nx][ny].seenv || (!Blind && couldsee(nx, ny)))) {
  78. 			if (nx == ux && ny == uy) {
  79. 			    if (!guess) {
  80. 				u.dx = x-ux;
  81. 				u.dy = y-uy;
  82. 				if (x == u.tx && y == u.ty) {
  83. 				    nomul(0);
  84. 				    /* reset run so domove run checks work */
  85. 				    flags.run = 8;
  86. 				    iflags.travelcc.x = iflags.travelcc.y = -1;
  87. 				}
  88. 				return TRUE;
  89. 			    }
  90. 			} else if (!travel[nx][ny]) {
  91. 			    travelstepx[1-set][nn] = nx;
  92. 			    travelstepy[1-set][nn] = ny;
  93. 			    travel[nx][ny] = radius;
  94. 			    nn++;
  95. 			}
  96. 		    }
  97. 		}
  98. 	    }
  99.  
  100. 	    n = nn;
  101. 	    set = 1-set;
  102. 	    radius++;
  103. 	}
  104.  
  105. 	/* if guessing, find best location in travel matrix and go there */
  106. 	if (guess) {
  107. 	    int px = tx, py = ty;	/* pick location */
  108. 	    int dist, nxtdist, d2, nd2;
  109.  
  110. 	    dist = distmin(ux, uy, tx, ty);
  111. 	    d2 = dist2(ux, uy, tx, ty);
  112. 	    for (tx = 1; tx < COLNO; ++tx)
  113. 		for (ty = 0; ty < ROWNO; ++ty)
  114. 		    if (travel[tx][ty]) {
  115. 			nxtdist = distmin(ux, uy, tx, ty);
  116. 			if (nxtdist == dist && couldsee(tx, ty)) {
  117. 			    nd2 = dist2(ux, uy, tx, ty);
  118. 			    if (nd2 < d2) {
  119. 				/* prefer non-zigzag path */
  120. 				px = tx; py = ty;
  121. 				d2 = nd2;
  122. 			    }
  123. 			} else if (nxtdist < dist && couldsee(tx, ty)) {
  124. 			    px = tx; py = ty;
  125. 			    dist = nxtdist;
  126. 			    d2 = dist2(ux, uy, tx, ty);
  127. 			}
  128. 		    }
  129.  
  130. 	    if (px == u.ux && py == u.uy) {
  131. 		/* no guesses, just go in the general direction */
  132. 		u.dx = sgn(u.tx - u.ux);
  133. 		u.dy = sgn(u.ty - u.uy);
  134. 		if (test_move(u.ux, u.uy, u.dx, u.dy, TEST_MOVE))
  135. 		    return TRUE;
  136. 		goto found;
  137. 	    }
  138. 	    tx = px;
  139. 	    ty = py;
  140. 	    ux = u.ux;
  141. 	    uy = u.uy;
  142. 	    set = 0;
  143. 	    n = radius = 1;
  144. 	    guess = FALSE;
  145. 	    goto noguess;
  146. 	}
  147. 	return FALSE;
  148. }
  149.  
  150. found:
  151. u.dx = 0;
  152. u.dy = 0;
  153. nomul(0);
  154. return FALSE;
  155. }

domove[edit]

  1. void
  2. domove()
  3. {
  4. 	register struct monst *mtmp;
  5. 	register struct rm *tmpr;
  6. 	register xchar x,y;
  7. 	struct trap *trap;
  8. 	int wtcap;
  9. 	boolean on_ice;
  10. 	xchar chainx, chainy, ballx, bally;	/* ball&chain new positions */
  11. 	int bc_control;				/* control for ball&chain */
  12. 	boolean cause_delay = FALSE;	/* dragging ball will skip a move */
  13. 	const char *predicament;
  14.  
  15. 	u_wipe_engr(rnd(5));
  16.  
  17. 	if (flags.travel) {
  18. 	    if (!findtravelpath(FALSE))
  19. 		(void) findtravelpath(TRUE);
  20. 	    iflags.travel1 = 0;
  21. 	}
  22.  
  23. 	if(((wtcap = near_capacity()) >= OVERLOADED
  24. 	    || (wtcap > SLT_ENCUMBER &&
  25. 		(Upolyd ? (u.mh < 5 && u.mh != u.mhmax)
  26. 			: (u.uhp < 10 && u.uhp != u.uhpmax))))
  27. 	   && !Is_airlevel(&u.uz)) {
  28. 	    if(wtcap < OVERLOADED) {
  29. 		You("don't have enough stamina to move.");
  30. 		exercise(A_CON, FALSE);
  31. 	    } else
  32. 		You("collapse under your load.");
  33. 	    nomul(0);
  34. 	    return;
  35. 	}
  36. 	if(u.uswallow) {
  37. 		u.dx = u.dy = 0;
  38. 		u.ux = x = u.ustuck->mx;
  39. 		u.uy = y = u.ustuck->my;
  40. 		mtmp = u.ustuck;
  41. 	} else {
  42. 		if (Is_airlevel(&u.uz) && rn2(4) &&
  43. 			!Levitation && !Flying) {
  44. 		    switch(rn2(3)) {
  45. 		    case 0:
  46. 			You("tumble in place.");
  47. 			exercise(A_DEX, FALSE);
  48. 			break;
  49. 		    case 1:
  50. 			You_cant("control your movements very well."); break;
  51. 		    case 2:
  52. 			pline("It's hard to walk in thin air.");
  53. 			exercise(A_DEX, TRUE);
  54. 			break;
  55. 		    }
  56. 		    return;
  57. 		}
  58.  
  59. 		/* check slippery ice */
  60. 		on_ice = !Levitation && is_ice(u.ux, u.uy);
  61. 		if (on_ice) {
  62. 		    static int skates = 0;
  63. 		    if (!skates) skates = find_skates();
  64. 		    if ((uarmf && uarmf->otyp == skates)
  65. 			    || resists_cold(&youmonst) || Flying
  66. 			    || is_floater(youmonst.data) || is_clinger(youmonst.data)
  67. 			    || is_whirly(youmonst.data))
  68. 			on_ice = FALSE;
  69. 		    else if (!rn2(Cold_resistance ? 3 : 2)) {
  70. 			HFumbling |= FROMOUTSIDE;
  71. 			HFumbling &= ~TIMEOUT;
  72. 			HFumbling += 1;  /* slip on next move */
  73. 		    }
  74. 		}
  75. 		if (!on_ice && (HFumbling & FROMOUTSIDE))
  76. 		    HFumbling &= ~FROMOUTSIDE;
  77.  
  78. 		x = u.ux + u.dx;
  79. 		y = u.uy + u.dy;
  80. 		if(Stunned || (Confusion && !rn2(5))) {
  81. 			register int tries = 0;
  82.  
  83. 			do {
  84. 				if(tries++ > 50) {
  85. 					nomul(0);
  86. 					return;
  87. 				}
  88. 				confdir();
  89. 				x = u.ux + u.dx;
  90. 				y = u.uy + u.dy;
  91. 			} while(!isok(x, y) || bad_rock(youmonst.data, x, y));
  92. 		}
  93. 		/* turbulence might alter your actual destination */
  94. 		if (u.uinwater) {
  95. 			water_friction();
  96. 			if (!u.dx && !u.dy) {
  97. 				nomul(0);
  98. 				return;
  99. 			}
  100. 			x = u.ux + u.dx;
  101. 			y = u.uy + u.dy;
  102. 		}
  103. 		if(!isok(x, y)) {
  104. 			nomul(0);
  105. 			return;
  106. 		}
  107. 		if (((trap = t_at(x, y)) && trap->tseen) ||
  108. 		    (Blind && !Levitation && !Flying &&
  109. 		     !is_clinger(youmonst.data) &&
  110. 		     (is_pool(x, y) || is_lava(x, y)) && levl[x][y].seenv)) {
  111. 			if(flags.run >= 2) {
  112. 				nomul(0);
  113. 				flags.move = 0;
  114. 				return;
  115. 			} else
  116. 				nomul(0);
  117. 		}
  118.  
  119. 		if (u.ustuck && (x != u.ustuck->mx || y != u.ustuck->my)) {
  120. 		    if (distu(u.ustuck->mx, u.ustuck->my) > 2) {
  121. 			/* perhaps it fled (or was teleported or ... ) */
  122. 			u.ustuck = 0;
  123. 		    } else if (sticks(youmonst.data)) {
  124. 			/* When polymorphed into a sticking monster,
  125. 			 * u.ustuck means it's stuck to you, not you to it.
  126. 			 */
  127. 			You("release %s.", mon_nam(u.ustuck));
  128. 			u.ustuck = 0;
  129. 		    } else {
  130. 			/* If holder is asleep or paralyzed:
  131. 			 *	37.5% chance of getting away,
  132. 			 *	12.5% chance of waking/releasing it;
  133. 			 * otherwise:
  134. 			 *	 7.5% chance of getting away.
  135. 			 * [strength ought to be a factor]
  136. 			 * If holder is tame and there is no conflict,
  137. 			 * guaranteed escape.
  138. 			 */
  139. 			switch (rn2(!u.ustuck->mcanmove ? 8 : 40)) {
  140. 			case 0: case 1: case 2:
  141. 			pull_free:
  142. 			    You("pull free from %s.", mon_nam(u.ustuck));
  143. 			    u.ustuck = 0;
  144. 			    break;
  145. 			case 3:
  146. 			    if (!u.ustuck->mcanmove) {
  147. 				/* it's free to move on next turn */
  148. 				u.ustuck->mfrozen = 1;
  149. 				u.ustuck->msleeping = 0;
  150. 			    }
  151. 			    /*FALLTHRU*/
  152. 			default:
  153. 			    if (u.ustuck->mtame &&
  154. 				!Conflict && !u.ustuck->mconf)
  155. 				goto pull_free;
  156. 			    You("cannot escape from %s!", mon_nam(u.ustuck));
  157. 			    nomul(0);
  158. 			    return;
  159. 			}
  160. 		    }
  161. 		}
  162.  
  163. 		mtmp = m_at(x,y);
  164. 		if (mtmp) {
  165. 			/* Don't attack if you're running, and can see it */
  166. 			/* We should never get here if forcefight */
  167. 			if (flags.run &&
  168. 			    ((!Blind && mon_visible(mtmp) &&
  169. 			      ((mtmp->m_ap_type != M_AP_FURNITURE &&
  170. 				mtmp->m_ap_type != M_AP_OBJECT) ||
  171. 			       Protection_from_shape_changers)) ||
  172. 			     sensemon(mtmp))) {
  173. 				nomul(0);
  174. 				flags.move = 0;
  175. 				return;
  176. 			}
  177. 		}
  178. 	}
  179.  
  180. 	u.ux0 = u.ux;
  181. 	u.uy0 = u.uy;
  182. 	bhitpos.x = x;
  183. 	bhitpos.y = y;
  184. 	tmpr = &levl[x][y];
  185.  
  186. 	/* attack monster */
  187. 	if(mtmp) {
  188. 	    nomul(0);
  189. 	    /* only attack if we know it's there */
  190. 	    /* or if we used the 'F' command to fight blindly */
  191. 	    /* or if it hides_under, in which case we call attack() to print
  192. 	     * the Wait! message.
  193. 	     * This is different from ceiling hiders, who aren't handled in
  194. 	     * attack().
  195. 	     */
  196.  
  197. 	    /* If they used a 'm' command, trying to move onto a monster
  198. 	     * prints the below message and wastes a turn.  The exception is
  199. 	     * if the monster is unseen and the player doesn't remember an
  200. 	     * invisible monster--then, we fall through to attack() and
  201. 	     * attack_check(), which still wastes a turn, but prints a
  202. 	     * different message and makes the player remember the monster.		     */
  203. 	    if(flags.nopick &&
  204. 		  (canspotmon(mtmp) || glyph_is_invisible(levl[x][y].glyph))){
  205. 		if(mtmp->m_ap_type && !Protection_from_shape_changers
  206. 						    && !sensemon(mtmp))
  207. 		    stumble_onto_mimic(mtmp);
  208. 		else if (mtmp->mpeaceful && !Hallucination)
  209. 		    pline("Pardon me, %s.", m_monnam(mtmp));
  210. 		else
  211. 		    You("move right into %s.", mon_nam(mtmp));
  212. 		return;
  213. 	    }
  214. 	    if(flags.forcefight || !mtmp->mundetected || sensemon(mtmp) ||
  215. 		    ((hides_under(mtmp->data) || mtmp->data->mlet == S_EEL) &&
  216. 			!is_safepet(mtmp))){
  217. 		gethungry();
  218. 		if(wtcap >= HVY_ENCUMBER && moves%3) {
  219. 		    if (Upolyd && u.mh > 1) {
  220. 			u.mh--;
  221. 		    } else if (!Upolyd && u.uhp > 1) {
  222. 			u.uhp--;
  223. 		    } else {
  224. 			You("pass out from exertion!");
  225. 			exercise(A_CON, FALSE);
  226. 			fall_asleep(-10, FALSE);
  227. 		    }
  228. 		}
  229. 		if(multi < 0) return;	/* we just fainted */
  230.  
  231. 		/* try to attack; note that it might evade */
  232. 		/* also, we don't attack tame when _safepet_ */
  233. 		if(attack(mtmp)) return;
  234. 	    }
  235. 	}
  236.  
  237. 	/* specifying 'F' with no monster wastes a turn */
  238. 	if (flags.forcefight ||
  239. 	    /* remembered an 'I' && didn't use a move command */
  240. 	    (glyph_is_invisible(levl[x][y].glyph) && !flags.nopick)) {
  241. 		boolean expl = (Upolyd && attacktype(youmonst.data, AT_EXPL));
  242. 	    	char buf[BUFSZ];
  243. 		Sprintf(buf,"a vacant spot on the %s", surface(x,y));
  244. 		You("%s %s.",
  245. 		    expl ? "explode at" : "attack",
  246. 		    !Underwater ? "thin air" :
  247. 		    is_pool(x,y) ? "empty water" : buf);
  248. 		unmap_object(x, y); /* known empty -- remove 'I' if present */
  249. 		newsym(x, y);
  250. 		nomul(0);
  251. 		if (expl) {
  252. 		    u.mh = -1;		/* dead in the current form */
  253. 		    rehumanize();
  254. 		}
  255. 		return;
  256. 	}
  257. 	if (glyph_is_invisible(levl[x][y].glyph)) {
  258. 	    unmap_object(x, y);
  259. 	    newsym(x, y);
  260. 	}
  261. 	/* not attacking an animal, so we try to move */
  262. #ifdef STEED
  263. 	if (u.usteed && !u.usteed->mcanmove && (u.dx || u.dy)) {
  264. 		pline("%s won't move!", upstart(y_monnam(u.usteed)));
  265. 		nomul(0);
  266. 		return;
  267. 	} else
  268. #endif
  269. 	if(!youmonst.data->mmove) {
  270. 		You("are rooted %s.",
  271. 		    Levitation || Is_airlevel(&u.uz) || Is_waterlevel(&u.uz) ?
  272. 		    "in place" : "to the ground");
  273. 		nomul(0);
  274. 		return;
  275. 	}
  276. 	if(u.utrap) {
  277. 		if(u.utraptype == TT_PIT) {
  278. 		    if (!rn2(2) && sobj_at(BOULDER, u.ux, u.uy)) {
  279. 			Your("%s gets stuck in a crevice.", body_part(LEG));
  280. 			display_nhwindow(WIN_MESSAGE, FALSE);
  281. 			clear_nhwindow(WIN_MESSAGE);
  282. 			You("free your %s.", body_part(LEG));
  283. 		    } else if (!(--u.utrap)) {
  284. 			You("%s to the edge of the pit.",
  285. 				(In_sokoban(&u.uz) && Levitation) ?
  286. 				"struggle against the air currents and float" :
  287. #ifdef STEED
  288. 				u.usteed ? "ride" :
  289. #endif
  290. 				"crawl");
  291. 			fill_pit(u.ux, u.uy);
  292. 			vision_full_recalc = 1;	/* vision limits change */
  293. 		    } else if (flags.verbose) {
  294. #ifdef STEED
  295. 			if (u.usteed)
  296. 			    Norep("%s is still in a pit.",
  297. 				  upstart(y_monnam(u.usteed)));
  298. 			else
  299. #endif
  300. 			Norep( (Hallucination && !rn2(5)) ?
  301. 				"You've fallen, and you can't get up." :
  302. 				"You are still in a pit." );
  303. 		    }
  304. 		} else if (u.utraptype == TT_LAVA) {
  305. 		    if(flags.verbose) {
  306. 			predicament = "stuck in the lava";
  307. #ifdef STEED
  308. 			if (u.usteed)
  309. 			    Norep("%s is %s.", upstart(y_monnam(u.usteed)),
  310. 				  predicament);
  311. 			else
  312. #endif
  313. 			Norep("You are %s.", predicament);
  314. 		    }
  315. 		    if(!is_lava(x,y)) {
  316. 			u.utrap--;
  317. 			if((u.utrap & 0xff) == 0) {
  318. #ifdef STEED
  319. 			    if (u.usteed)
  320. 				You("lead %s to the edge of the lava.",
  321. 				    y_monnam(u.usteed));
  322. 			    else
  323. #endif
  324. 			     You("pull yourself to the edge of the lava.");
  325. 			    u.utrap = 0;
  326. 			}
  327. 		    }
  328. 		    u.umoved = TRUE;
  329. 		} else if (u.utraptype == TT_WEB) {
  330. 		    if(uwep && uwep->oartifact == ART_STING) {
  331. 			u.utrap = 0;
  332. 			pline("Sting cuts through the web!");
  333. 			return;
  334. 		    }
  335. 		    if(--u.utrap) {
  336. 			if(flags.verbose) {
  337. 			    predicament = "stuck to the web";
  338. #ifdef STEED
  339. 			    if (u.usteed)
  340. 				Norep("%s is %s.", upstart(y_monnam(u.usteed)),
  341. 				      predicament);
  342. 			    else
  343. #endif
  344. 			    Norep("You are %s.", predicament);
  345. 			}
  346. 		    } else {
  347. #ifdef STEED
  348. 			if (u.usteed)
  349. 			    pline("%s breaks out of the web.",
  350. 				  upstart(y_monnam(u.usteed)));
  351. 			else
  352. #endif
  353. 			You("disentangle yourself.");
  354. 		    }
  355. 		} else if (u.utraptype == TT_INFLOOR) {
  356. 		    if(--u.utrap) {
  357. 			if(flags.verbose) {
  358. 			    predicament = "stuck in the";
  359. #ifdef STEED
  360. 			    if (u.usteed)
  361. 				Norep("%s is %s %s.",
  362. 				      upstart(y_monnam(u.usteed)),
  363. 				      predicament, surface(u.ux, u.uy));
  364. 			    else
  365. #endif
  366. 			    Norep("You are %s %s.", predicament,
  367. 				  surface(u.ux, u.uy));
  368. 			}
  369. 		    } else {
  370. #ifdef STEED
  371. 			if (u.usteed)
  372. 			    pline("%s finally wiggles free.",
  373. 				  upstart(y_monnam(u.usteed)));
  374. 			else
  375. #endif
  376. 			You("finally wiggle free.");
  377. 		    }
  378. 		} else {
  379. 		    if(flags.verbose) {
  380. 			predicament = "caught in a bear trap";
  381. #ifdef STEED
  382. 			if (u.usteed)
  383. 			    Norep("%s is %s.", upstart(y_monnam(u.usteed)),
  384. 				  predicament);
  385. 			else
  386. #endif
  387. 			Norep("You are %s.", predicament);
  388. 		    }
  389. 		    if((u.dx && u.dy) || !rn2(5)) u.utrap--;
  390. 		}
  391. 		return;
  392. 	}
  393.  
  394. 	if (!test_move(u.ux, u.uy, x-u.ux, y-u.uy, DO_MOVE)) {
  395. 	    flags.move = 0;
  396. 	    nomul(0);
  397. 	    return;
  398. 	}
  399.  
  400. 	/* Move ball and chain.  */
  401. 	if (Punished)
  402. 	    if (!drag_ball(x,y, &bc_control, &ballx, &bally, &chainx, &chainy,
  403. 			&cause_delay, TRUE))
  404. 		return;
  405.  
  406. 	/* Check regions entering/leaving */
  407. 	if (!in_out_region(x,y))
  408. 	    return;
  409.  
  410. 	/* now move the hero */
  411. 	mtmp = m_at(x, y);
  412. 	u.ux += u.dx;
  413. 	u.uy += u.dy;
  414. #ifdef STEED
  415. 	/* Move your steed, too */
  416. 	if (u.usteed) {
  417. 		u.usteed->mx = u.ux;
  418. 		u.usteed->my = u.uy;
  419. 		exercise_steed();
  420. 	}
  421. #endif
  422.  
  423. 	/*
  424. 	 * If safepet at destination then move the pet to the hero's
  425. 	 * previous location using the same conditions as in attack().
  426. 	 * there are special extenuating circumstances:
  427. 	 * (1) if the pet dies then your god angers,
  428. 	 * (2) if the pet gets trapped then your god may disapprove,
  429. 	 * (3) if the pet was already trapped and you attempt to free it
  430. 	 * not only do you encounter the trap but you may frighten your
  431. 	 * pet causing it to go wild!  moral: don't abuse this privilege.
  432. 	 *
  433. 	 * Ceiling-hiding pets are skipped by this section of code, to
  434. 	 * be caught by the normal falling-monster code.
  435. 	 */
  436. 	if (is_safepet(mtmp) && !(is_hider(mtmp->data) && mtmp->mundetected)) {
  437. 	    /* if trapped, there's a chance the pet goes wild */
  438. 	    if (mtmp->mtrapped) {
  439. 		if (!rn2(mtmp->mtame)) {
  440. 		    mtmp->mtame = mtmp->mpeaceful = mtmp->msleeping = 0;
  441. 		    if (mtmp->mleashed) m_unleash(mtmp, TRUE);
  442. 		    growl(mtmp);
  443. 		} else {
  444. 		    yelp(mtmp);
  445. 		}
  446. 	    }
  447. 	    mtmp->mundetected = 0;
  448. 	    if (mtmp->m_ap_type) seemimic(mtmp);
  449. 	    else if (!mtmp->mtame) newsym(mtmp->mx, mtmp->my);
  450.  
  451. 	    if (mtmp->mtrapped &&
  452. 		    (trap = t_at(mtmp->mx, mtmp->my)) != 0 &&
  453. 		    (trap->ttyp == PIT || trap->ttyp == SPIKED_PIT) &&
  454. 		    sobj_at(BOULDER, trap->tx, trap->ty)) {
  455. 		/* can't swap places with pet pinned in a pit by a boulder */
  456. 		u.ux = u.ux0,  u.uy = u.uy0;	/* didn't move after all */
  457. 	    } else if (u.ux0 != x && u.uy0 != y &&
  458. 		       bad_rock(mtmp->data, x, u.uy0) &&
  459. 		       bad_rock(mtmp->data, u.ux0, y) &&
  460. 		       (bigmonst(mtmp->data) || (curr_mon_load(mtmp) > 600))) {
  461. 		/* can't swap places when pet won't fit thru the opening */
  462. 		u.ux = u.ux0,  u.uy = u.uy0;	/* didn't move after all */
  463. 		You("stop.  %s won't fit through.", upstart(y_monnam(mtmp)));
  464. 	    } else {
  465. 		char pnambuf[BUFSZ];
  466.  
  467. 		/* save its current description in case of polymorph */
  468. 		Strcpy(pnambuf, y_monnam(mtmp));
  469. 		mtmp->mtrapped = 0;
  470. 		remove_monster(x, y);
  471. 		place_monster(mtmp, u.ux0, u.uy0);
  472.  
  473. 		/* check for displacing it into pools and traps */
  474. 		switch (minliquid(mtmp) ? 2 : mintrap(mtmp)) {
  475. 		case 0:
  476. 		    You("%s %s.", mtmp->mtame ? "displaced" : "frightened",
  477. 			pnambuf);
  478. 		    break;
  479. 		case 1:		/* trapped */
  480. 		case 3:		/* changed levels */
  481. 		    /* there's already been a trap message, reinforce it */
  482. 		    abuse_dog(mtmp);
  483. 		    adjalign(-3);
  484. 		    break;
  485. 		case 2:
  486. 		    /* it may have drowned or died.  that's no way to
  487. 		     * treat a pet!  your god gets angry.
  488. 		     */
  489. 		    if (rn2(4)) {
  490. 			You_feel("guilty about losing your pet like this.");
  491. 			u.ugangr++;
  492. 			adjalign(-15);
  493. 		    }
  494.  
  495. 		    /* you killed your pet by direct action.
  496. 		     * minliquid and mintrap don't know to do this
  497. 		     */
  498. 		    u.uconduct.killer++;
  499. 		    break;
  500. 		default:
  501. 		    pline("that's strange, unknown mintrap result!");
  502. 		    break;
  503. 		}
  504. 	    }
  505. 	}
  506.  
  507. 	reset_occupations();
  508. 	if (flags.run) {
  509. 	    if ( flags.run < 8 )
  510. 		if (IS_DOOR(tmpr->typ) || IS_ROCK(tmpr->typ) ||
  511. 			IS_FURNITURE(tmpr->typ))
  512. 		    nomul(0);
  513. 	}
  514.  
  515. 	if (hides_under(youmonst.data))
  516. 	    u.uundetected = OBJ_AT(u.ux, u.uy);
  517. 	else if (youmonst.data->mlet == S_EEL)
  518. 	    u.uundetected = is_pool(u.ux, u.uy) && !Is_waterlevel(&u.uz);
  519. 	else if (u.dx || u.dy)
  520. 	    u.uundetected = 0;
  521.  
  522. 	/*
  523. 	 * Mimics (or whatever) become noticeable if they move and are
  524. 	 * imitating something that doesn't move.  We could extend this
  525. 	 * to non-moving monsters...
  526. 	 */
  527. 	if ((u.dx || u.dy) && (youmonst.m_ap_type == M_AP_OBJECT
  528. 				|| youmonst.m_ap_type == M_AP_FURNITURE))
  529. 	    youmonst.m_ap_type = M_AP_NOTHING;
  530.  
  531. 	check_leash(u.ux0,u.uy0);
  532.  
  533. 	if(u.ux0 != u.ux || u.uy0 != u.uy) {
  534. 	    u.umoved = TRUE;
  535. 	    /* Clean old position -- vision_recalc() will print our new one. */
  536. 	    newsym(u.ux0,u.uy0);
  537. 	    /* Since the hero has moved, adjust what can be seen/unseen. */
  538. 	    vision_recalc(1);	/* Do the work now in the recover time. */
  539. 	    invocation_message();
  540. 	}
  541.  
  542. 	if (Punished)				/* put back ball and chain */
  543. 	    move_bc(0,bc_control,ballx,bally,chainx,chainy);
  544.  
  545. 	spoteffects(TRUE);
  546.  
  547. 	/* delay next move because of ball dragging */
  548. 	/* must come after we finished picking up, in spoteffects() */
  549. 	if (cause_delay) {
  550. 	    nomul(-2);
  551. 	    nomovemsg = "";
  552. 	}
  553.  
  554. 	if (flags.run && iflags.runmode != RUN_TPORT) {
  555. 	    /* display every step or every 7th step depending upon mode */
  556. 	    if (iflags.runmode != RUN_LEAP || !(moves % 7L)) {
  557. 		if (flags.time) flags.botl = 1;
  558. 		curs_on_u();
  559. 		delay_output();
  560. 		if (iflags.runmode == RUN_CRAWL) {
  561. 		    delay_output();
  562. 		    delay_output();
  563. 		    delay_output();
  564. 		    delay_output();
  565. 		}
  566. 	    }
  567. 	}
  568. }

invocation_message[edit]

  1. void
  2. invocation_message()
  3. {
  4. 	/* a special clue-msg when on the Invocation position */
  5. 	if(invocation_pos(u.ux, u.uy) && !On_stairs(u.ux, u.uy)) {
  6. 	    char buf[BUFSZ];
  7. 	    struct obj *otmp = carrying(CANDELABRUM_OF_INVOCATION);
  8.  
  9. 	    nomul(0);		/* stop running or travelling */
  10. #ifdef STEED
  11. 	    if (u.usteed) Sprintf(buf, "beneath %s", y_monnam(u.usteed));
  12. 	    else
  13. #endif
  14. 	    if (Levitation || Flying) Strcpy(buf, "beneath you");
  15. 	    else Sprintf(buf, "under your %s", makeplural(body_part(FOOT)));
  16.  
  17. 	    You_feel("a strange vibration %s.", buf);
  18. 	    if (otmp && otmp->spe == 7 && otmp->lamplit)
  19. 		pline("%s %s!", The(xname(otmp)),
  20. 		    Blind ? "throbs palpably" : "glows with a strange light");
  21. 	}
  22. }
  23.  
  24. #endif /* OVL3 */

spoteffects[edit]

  1. #ifdef OVL2
  2.  
  3. void
  4. spoteffects(pick)
  5. boolean pick;
  6. {
  7. 	register struct monst *mtmp;
  8.  
  9. 	if(u.uinwater) {
  10. 		int was_underwater;
  11.  
  12. 		if (!is_pool(u.ux,u.uy)) {
  13. 			if (Is_waterlevel(&u.uz))
  14. 				You("pop into an air bubble.");
  15. 			else if (is_lava(u.ux, u.uy))
  16. 				You("leave the water...");	/* oops! */
  17. 			else
  18. 				You("are on solid %s again.",
  19. 				    is_ice(u.ux, u.uy) ? "ice" : "land");
  20. 		}
  21. 		else if (Is_waterlevel(&u.uz))
  22. 			goto stillinwater;
  23. 		else if (Levitation)
  24. 			You("pop out of the water like a cork!");
  25. 		else if (Flying)
  26. 			You("fly out of the water.");
  27. 		else if (Wwalking)
  28. 			You("slowly rise above the surface.");
  29. 		else
  30. 			goto stillinwater;
  31. 		was_underwater = Underwater && !Is_waterlevel(&u.uz);
  32. 		u.uinwater = 0;		/* leave the water */
  33. 		if (was_underwater) {	/* restore vision */
  34. 			docrt();
  35. 			vision_full_recalc = 1;
  36. 		}
  37. 	}
  38. stillinwater:;
  39. 	if (!Levitation && !u.ustuck && !Flying) {
  40. 	    /* limit recursive calls through teleds() */
  41. 	    if (is_pool(u.ux, u.uy) || is_lava(u.ux, u.uy)) {
  42. #ifdef STEED
  43. 		if (u.usteed && !is_flyer(u.usteed->data) &&
  44. 			!is_floater(u.usteed->data) &&
  45. 			!is_clinger(u.usteed->data)) {
  46. 		    dismount_steed(Underwater ?
  47. 			    DISMOUNT_FELL : DISMOUNT_GENERIC);
  48. 		    /* dismount_steed() -> float_down() -> pickup() */
  49. 		    if (!Is_airlevel(&u.uz) && !Is_waterlevel(&u.uz))
  50. 			pick = FALSE;
  51. 		} else
  52. #endif
  53. 		if (is_lava(u.ux, u.uy)) {
  54. 		    if (lava_effects()) return;
  55. 		} else if (!Wwalking && drown())
  56. 		    return;
  57. 	    }
  58. 	}
  59. 	check_special_room(FALSE);
  60. #ifdef SINKS
  61. 	if(IS_SINK(levl[u.ux][u.uy].typ) && Levitation)
  62. 		dosinkfall();
  63. #endif
  64. 	if (!in_steed_dismounting) { /* if dismounting, we'll check again later */
  65. 		struct trap *trap = t_at(u.ux, u.uy);
  66. 		boolean pit;
  67. 		pit = (trap && (trap->ttyp == PIT || trap->ttyp == SPIKED_PIT));
  68. 		if (trap && pit)
  69. 			dotrap(trap, 0);	/* fall into pit */
  70. 		if (pick) (void) pickup(1);
  71. 		if (trap && !pit)
  72. 			dotrap(trap, 0);	/* fall into arrow trap, etc. */
  73. 	}
  74. 	if((mtmp = m_at(u.ux, u.uy)) && !u.uswallow) {
  75. 		mtmp->mundetected = mtmp->msleeping = 0;
  76. 		switch(mtmp->data->mlet) {
  77. 		    case S_PIERCER:
  78. 			pline("%s suddenly drops from the %s!",
  79. 			      Amonnam(mtmp), ceiling(u.ux,u.uy));
  80. 			if(mtmp->mtame) /* jumps to greet you, not attack */
  81. 			    ;
  82. 			else if(uarmh && is_metallic(uarmh))
  83. 			    pline("Its blow glances off your helmet.");
  84. 			else if (u.uac + 3 <= rnd(20))
  85. 			    You("are almost hit by %s!",
  86. 				x_monnam(mtmp, ARTICLE_A, "falling", 0, TRUE));
  87. 			else {
  88. 			    int dmg;
  89. 			    You("are hit by %s!",
  90. 				x_monnam(mtmp, ARTICLE_A, "falling", 0, TRUE));
  91. 			    dmg = d(4,6);
  92. 			    if(Half_physical_damage) dmg = (dmg+1) / 2;
  93. 			    mdamageu(mtmp, dmg);
  94. 			}
  95. 			break;
  96. 		    default:	/* monster surprises you. */
  97. 			if(mtmp->mtame)
  98. 			    pline("%s jumps near you from the %s.",
  99. 					Amonnam(mtmp), ceiling(u.ux,u.uy));
  100. 			else if(mtmp->mpeaceful) {
  101. 				You("surprise %s!",
  102. 				    Blind && !sensemon(mtmp) ?
  103. 				    something : a_monnam(mtmp));
  104. 				mtmp->mpeaceful = 0;
  105. 			} else
  106. 			    pline("%s attacks you by surprise!",
  107. 					Amonnam(mtmp));
  108. 			break;
  109. 		}
  110. 		mnexto(mtmp); /* have to move the monster */
  111. 	}
  112. }

monstinroom[edit]

  1. STATIC_OVL boolean
  2. monstinroom(mdat,roomno)
  3. struct permonst *mdat;
  4. int roomno;
  5. {
  6. 	register struct monst *mtmp;
  7.  
  8. 	for(mtmp = fmon; mtmp; mtmp = mtmp->nmon)
  9. 		if(!DEADMONSTER(mtmp) && mtmp->data == mdat &&
  10. 		   index(in_rooms(mtmp->mx, mtmp->my, 0), roomno + ROOMOFFSET))
  11. 			return(TRUE);
  12. 	return(FALSE);
  13. }

in_rooms[edit]

in_rooms() takes three parameters, an x,y coordinate and a room type, and returns a string of chars, which will contain indexes to rooms-array (adjusted by ROOMOFFSET). The x,y location is in the rooms pointed to by those characters. If the location is not in any room, a zero-length string is returned.

For example, the following code tells the player the size of one of the shops he is in:

char roomlst = *in_rooms(u.ux, u.uy, SHOPBASE);
if (roomlst && roomlst[0] >= ROOMOFFSET) {
  int rmno = roomlst[0] - ROOMOFFSET;
  pline("Shop size: %i,%i", rooms[rmno].hx - rooms[rmno].lx + 1, rooms[rmno].hy - rooms[rmno].ly + 1);
}
  1. char *
  2. in_rooms(x, y, typewanted)
  3. register xchar x, y;
  4. register int typewanted;
  5. {
  6. 	static char buf[5];
  7. 	char rno, *ptr = &buf[4];
  8. 	int typefound, min_x, min_y, max_x, max_y_offset, step;
  9. 	register struct rm *lev;
  10.  
  11. #define goodtype(rno) (!typewanted || \
  12. 	     ((typefound = rooms[rno - ROOMOFFSET].rtype) == typewanted) || \
  13. 	     ((typewanted == SHOPBASE) && (typefound > SHOPBASE))) \
  14.  
  15. 	switch (rno = levl[x][y].roomno) {
  16. 		case NO_ROOM:
  17. 			return(ptr);
  18. 		case SHARED:
  19. 			step = 2;
  20. 			break;
  21. 		case SHARED_PLUS:
  22. 			step = 1;
  23. 			break;
  24. 		default:			/* i.e. a regular room # */
  25. 			if (goodtype(rno))
  26. 				*(--ptr) = rno;
  27. 			return(ptr);
  28. 	}
  29.  
  30. 	min_x = x - 1;
  31. 	max_x = x + 1;
  32. 	if (x < 1)
  33. 		min_x += step;
  34. 	else
  35. 	if (x >= COLNO)
  36. 		max_x -= step;
  37.  
  38. 	min_y = y - 1;
  39. 	max_y_offset = 2;
  40. 	if (min_y < 0) {
  41. 		min_y += step;
  42. 		max_y_offset -= step;
  43. 	} else
  44. 	if ((min_y + max_y_offset) >= ROWNO)
  45. 		max_y_offset -= step;
  46.  
  47. 	for (x = min_x; x <= max_x; x += step) {
  48. 		lev = &levl[x][min_y];
  49. 		y = 0;
  50. 		if (((rno = lev[y].roomno) >= ROOMOFFSET) &&
  51. 		    !index(ptr, rno) && goodtype(rno))
  52. 			*(--ptr) = rno;
  53. 		y += step;
  54. 		if (y > max_y_offset)
  55. 			continue;
  56. 		if (((rno = lev[y].roomno) >= ROOMOFFSET) &&
  57. 		    !index(ptr, rno) && goodtype(rno))
  58. 			*(--ptr) = rno;
  59. 		y += step;
  60. 		if (y > max_y_offset)
  61. 			continue;
  62. 		if (((rno = lev[y].roomno) >= ROOMOFFSET) &&
  63. 		    !index(ptr, rno) && goodtype(rno))
  64. 			*(--ptr) = rno;
  65. 	}
  66. 	return(ptr);
  67. }

in_town[edit]

  1. /* is (x,y) in a town? */
  2. boolean
  3. in_town(x, y)
  4. register int x, y;
  5. {
  6. 	s_level *slev = Is_special(&u.uz);
  7. 	register struct mkroom *sroom;
  8. 	boolean has_subrooms = FALSE;
  9.  
  10. 	if (!slev || !slev->flags.town) return FALSE;
  11.  
  12. 	/*
  13. 	 * See if (x,y) is in a room with subrooms, if so, assume it's the
  14. 	 * town.  If there are no subrooms, the whole level is in town.
  15. 	 */
  16. 	for (sroom = &rooms[0]; sroom->hx > 0; sroom++) {
  17. 	    if (sroom->nsubrooms > 0) {
  18. 		has_subrooms = TRUE;
  19. 		if (inside_room(sroom, x, y)) return TRUE;
  20. 	    }
  21. 	}
  22.  
  23. 	return !has_subrooms;
  24. }

move_update[edit]

  1. STATIC_OVL void
  2. move_update(newlev)
  3. register boolean newlev;
  4. {
  5. 	char *ptr1, *ptr2, *ptr3, *ptr4;
  6.  
  7. 	Strcpy(u.urooms0, u.urooms);
  8. 	Strcpy(u.ushops0, u.ushops);
  9. 	if (newlev) {
  10. 		u.urooms[0] = '\0';
  11. 		u.uentered[0] = '\0';
  12. 		u.ushops[0] = '\0';
  13. 		u.ushops_entered[0] = '\0';
  14. 		Strcpy(u.ushops_left, u.ushops0);
  15. 		return;
  16. 	}
  17. 	Strcpy(u.urooms, in_rooms(u.ux, u.uy, 0));
  18.  
  19. 	for (ptr1 = &u.urooms[0],
  20. 	     ptr2 = &u.uentered[0],
  21. 	     ptr3 = &u.ushops[0],
  22. 	     ptr4 = &u.ushops_entered[0];
  23. 	     *ptr1; ptr1++) {
  24. 		if (!index(u.urooms0, *ptr1))
  25. 			*(ptr2++) = *ptr1;
  26. 		if (IS_SHOP(*ptr1 - ROOMOFFSET)) {
  27. 			*(ptr3++) = *ptr1;
  28. 			if (!index(u.ushops0, *ptr1))
  29. 				*(ptr4++) = *ptr1;
  30. 		}
  31. 	}
  32. 	*ptr2 = '\0';
  33. 	*ptr3 = '\0';
  34. 	*ptr4 = '\0';
  35.  
  36. 	/* filter u.ushops0 -> u.ushops_left */
  37. 	for (ptr1 = &u.ushops0[0], ptr2 = &u.ushops_left[0]; *ptr1; ptr1++)
  38. 		if (!index(u.ushops, *ptr1))
  39. 			*(ptr2++) = *ptr1;
  40. 	*ptr2 = '\0';
  41. }

check_special_room[edit]

  1. void
  2. check_special_room(newlev)
  3. register boolean newlev;
  4. {
  5. 	register struct monst *mtmp;
  6. 	char *ptr;
  7.  
  8. 	move_update(newlev);
  9.  
  10. 	if (*u.ushops0)
  11. 	    u_left_shop(u.ushops_left, newlev);
  12.  
  13. 	if (!*u.uentered && !*u.ushops_entered)		/* implied by newlev */
  14. 	    return;		/* no entrance messages necessary */
  15.  
  16. 	/* Did we just enter a shop? */
  17. 	if (*u.ushops_entered)
  18. 	    u_entered_shop(u.ushops_entered);
  19.  
  20. 	for (ptr = &u.uentered[0]; *ptr; ptr++) {
  21. 	    register int roomno = *ptr - ROOMOFFSET, rt = rooms[roomno].rtype;
  22.  
  23. 	    /* Did we just enter some other special room? */
  24. 	    /* vault.c insists that a vault remain a VAULT,
  25. 	     * and temples should remain TEMPLEs,
  26. 	     * but everything else gives a message only the first time */
  27. 	    switch (rt) {
  28. 		case ZOO:
  29. 		    pline("Welcome to David's treasure zoo!");
  30. 		    break;
  31. 		case SWAMP:
  32. 		    pline("It %s rather %s down here.",
  33. 			  Blind ? "feels" : "looks",
  34. 			  Blind ? "humid" : "muddy");
  35. 		    break;
  36. 		case COURT:
  37. 		    You("enter an opulent throne room!");
  38. 		    break;
  39. 		case LEPREHALL:
  40. 		    You("enter a leprechaun hall!");
  41. 		    break;
  42. 		case MORGUE:
  43. 		    if(midnight()) {
  44. 			const char *run = locomotion(youmonst.data, "Run");
  45. 			pline("%s away!  %s away!", run, run);
  46. 		    } else
  47. 			You("have an uncanny feeling...");
  48. 		    break;
  49. 		case BEEHIVE:
  50. 		    You("enter a giant beehive!");
  51. 		    break;
  52. 		case COCKNEST:
  53. 		    You("enter a disgusting nest!");
  54. 		    break;
  55. 		case ANTHOLE:
  56. 		    You("enter an anthole!");
  57. 		    break;
  58. 		case BARRACKS:
  59. 		    if(monstinroom(&mons[PM_SOLDIER], roomno) ||
  60. 			monstinroom(&mons[PM_SERGEANT], roomno) ||
  61. 			monstinroom(&mons[PM_LIEUTENANT], roomno) ||
  62. 			monstinroom(&mons[PM_CAPTAIN], roomno))
  63. 			You("enter a military barracks!");
  64. 		    else
  65. 			You("enter an abandoned barracks.");
  66. 		    break;
  67. 		case DELPHI:
  68. 		    if(monstinroom(&mons[PM_ORACLE], roomno))
  69. 			verbalize("%s, %s, welcome to Delphi!",
  70. 					Hello((struct monst *) 0), plname);
  71. 		    break;
  72. 		case TEMPLE:
  73. 		    intemple(roomno + ROOMOFFSET);
  74. 		    /* fall through */
  75. 		default:
  76. 		    rt = 0;
  77. 	    }
  78.  
  79. 	    if (rt != 0) {
  80. 		rooms[roomno].rtype = OROOM;
  81. 		if (!search_special(rt)) {
  82. 			/* No more room of that type */
  83. 			switch(rt) {
  84. 			    case COURT:
  85. 				level.flags.has_court = 0;
  86. 				break;
  87. 			    case SWAMP:
  88. 				level.flags.has_swamp = 0;
  89. 				break;
  90. 			    case MORGUE:
  91. 				level.flags.has_morgue = 0;
  92. 				break;
  93. 			    case ZOO:
  94. 				level.flags.has_zoo = 0;
  95. 				break;
  96. 			    case BARRACKS:
  97. 				level.flags.has_barracks = 0;
  98. 				break;
  99. 			    case TEMPLE:
  100. 				level.flags.has_temple = 0;
  101. 				break;
  102. 			    case BEEHIVE:
  103. 				level.flags.has_beehive = 0;
  104. 				break;
  105. 			}
  106. 		}
  107. 		if (rt == COURT || rt == SWAMP || rt == MORGUE || rt == ZOO)
  108. 		    for(mtmp = fmon; mtmp; mtmp = mtmp->nmon)
  109. 			if (!DEADMONSTER(mtmp) && !Stealth && !rn2(3)) mtmp->msleeping = 0;
  110. 	    }
  111. 	}
  112.  
  113. 	return;
  114. }
  115.  
  116. #endif /* OVL2 */

dopickup[edit]

  1. #ifdef OVLB
  2.  
  3. int
  4. dopickup()
  5. {
  6. 	int count;
  7. 	struct trap *traphere = t_at(u.ux, u.uy);
  8. 	/* awful kludge to work around parse()'s pre-decrement */
  9. 	count = (multi || (save_cm && *save_cm == ',')) ? multi + 1 : 0;
  10. 	multi = 0;	/* always reset */
  11. 	/* uswallow case added by GAN 01/29/87 */
  12. 	if(u.uswallow) {
  13. 	    if (!u.ustuck->minvent) {
  14. 		if (is_animal(u.ustuck->data)) {
  15. 		    You("pick up %s tongue.", s_suffix(mon_nam(u.ustuck)));
  16. 		    pline("But it's kind of slimy, so you drop it.");
  17. 		} else
  18. 		    You("don't %s anything in here to pick up.",
  19. 			  Blind ? "feel" : "see");
  20. 		return(1);
  21. 	    } else {
  22. 	    	int tmpcount = -count;
  23. 		return loot_mon(u.ustuck, &tmpcount, (boolean *)0);
  24. 	    }
  25. 	}
  26. 	if(is_pool(u.ux, u.uy)) {
  27. 	    if (Wwalking || is_floater(youmonst.data) || is_clinger(youmonst.data)
  28. 			|| (Flying && !Breathless)) {
  29. 		You("cannot dive into the water to pick things up.");
  30. 		return(0);
  31. 	    } else if (!Underwater) {
  32. 		You_cant("even see the bottom, let alone pick up %s.",
  33. 				something);
  34. 		return(0);
  35. 	    }
  36. 	}
  37. 	if (is_lava(u.ux, u.uy)) {
  38. 	    if (Wwalking || is_floater(youmonst.data) || is_clinger(youmonst.data)
  39. 			|| (Flying && !Breathless)) {
  40. 		You_cant("reach the bottom to pick things up.");
  41. 		return(0);
  42. 	    } else if (!likes_lava(youmonst.data)) {
  43. 		You("would burn to a crisp trying to pick things up.");
  44. 		return(0);
  45. 	    }
  46. 	}
  47. 	if(!OBJ_AT(u.ux, u.uy)) {
  48. 		There("is nothing here to pick up.");
  49. 		return(0);
  50. 	}
  51. 	if (!can_reach_floor()) {
  52. #ifdef STEED
  53. 		if (u.usteed && P_SKILL(P_RIDING) < P_BASIC)
  54. 		    You("aren't skilled enough to reach from %s.",
  55. 			y_monnam(u.usteed));
  56. 		else
  57. #endif
  58. 		You("cannot reach the %s.", surface(u.ux,u.uy));
  59. 		return(0);
  60. 	}
  61.  
  62. 	if (traphere && traphere->tseen) {
  63. 		/* Allow pickup from holes and trap doors that you escaped from
  64. 		 * because that stuff is teetering on the edge just like you, but
  65. 		 * not pits, because there is an elevation discrepancy with stuff
  66. 		 * in pits.
  67. 		 */
  68. 		if ((traphere->ttyp == PIT || traphere->ttyp == SPIKED_PIT) &&
  69. 		     (!u.utrap || (u.utrap && u.utraptype != TT_PIT))) {
  70. 			You("cannot reach the bottom of the pit.");
  71. 			return(0);
  72. 		}
  73. 	}
  74.  
  75. 	return (pickup(-count));
  76. }
  77.  
  78. #endif /* OVLB */

lookaround[edit]

  1. #ifdef OVL2
  2.  
  3. /* stop running if we see something interesting */
  4. /* turn around a corner if that is the only way we can proceed */
  5. /* do not turn left or right twice */
  6. void
  7. lookaround()
  8. {
  9. register int x, y, i, x0 = 0, y0 = 0, m0 = 1, i0 = 9;
  10. register int corrct = 0, noturn = 0;
  11. register struct monst *mtmp;
  12. register struct trap *trap;
  13.  
  14. /* Grid bugs stop if trying to move diagonal, even if blind.  Maybe */
  15. /* they polymorphed while in the middle of a long move. */
  16. if (u.umonnum == PM_GRID_BUG && u.dx && u.dy) {
  17. 	nomul(0);
  18. 	return;
  19. }
  20.  
  21. if(Blind || flags.run == 0) return;
  22. for(x = u.ux-1; x <= u.ux+1; x++) for(y = u.uy-1; y <= u.uy+1; y++) {
  23. 	if(!isok(x,y)) continue;
  24.  
  25. 	if(u.umonnum == PM_GRID_BUG && x != u.ux && y != u.uy) continue;
  26.  
  27. 	if(x == u.ux && y == u.uy) continue;
  28.  
  29. 	if((mtmp = m_at(x,y)) &&
  30. 		    mtmp->m_ap_type != M_AP_FURNITURE &&
  31. 		    mtmp->m_ap_type != M_AP_OBJECT &&
  32. 		    (!mtmp->minvis || See_invisible) && !mtmp->mundetected) {
  33. 	    if((flags.run != 1 && !mtmp->mtame)
  34. 					|| (x == u.ux+u.dx && y == u.uy+u.dy))
  35. 		goto stop;
  36. 	}
  37.  
  38. 	if (levl[x][y].typ == STONE) continue;
  39. 	if (x == u.ux-u.dx && y == u.uy-u.dy) continue;
  40.  
  41. 	if (IS_ROCK(levl[x][y].typ) || (levl[x][y].typ == ROOM) ||
  42. 	    IS_AIR(levl[x][y].typ))
  43. 	    continue;
  44. 	else if (closed_door(x,y) ||
  45. 		 (mtmp && mtmp->m_ap_type == M_AP_FURNITURE &&
  46. 		  (mtmp->mappearance == S_hcdoor ||
  47. 		   mtmp->mappearance == S_vcdoor))) {
  48. 	    if(x != u.ux && y != u.uy) continue;
  49. 	    if(flags.run != 1) goto stop;
  50. 	    goto bcorr;
  51. 	} else if (levl[x][y].typ == CORR) {
  52. bcorr:
  53. 	    if(levl[u.ux][u.uy].typ != ROOM) {
  54. 		if(flags.run == 1 || flags.run == 3 || flags.run == 8) {
  55. 		    i = dist2(x,y,u.ux+u.dx,u.uy+u.dy);
  56. 		    if(i > 2) continue;
  57. 		    if(corrct == 1 && dist2(x,y,x0,y0) != 1)
  58. 			noturn = 1;
  59. 		    if(i < i0) {
  60. 			i0 = i;
  61. 			x0 = x;
  62. 			y0 = y;
  63. 			m0 = mtmp ? 1 : 0;
  64. 		    }
  65. 		}
  66. 		corrct++;
  67. 	    }
  68. 	    continue;
  69. 	} else if ((trap = t_at(x,y)) && trap->tseen) {
  70. 	    if(flags.run == 1) goto bcorr;	/* if you must */
  71. 	    if(x == u.ux+u.dx && y == u.uy+u.dy) goto stop;
  72. 	    continue;
  73. 	} else if (is_pool(x,y) || is_lava(x,y)) {
  74. 	    /* water and lava only stop you if directly in front, and stop
  75. 	     * you even if you are running
  76. 	     */
  77. 	    if(!Levitation && !Flying && !is_clinger(youmonst.data) &&
  78. 				x == u.ux+u.dx && y == u.uy+u.dy)
  79. 			/* No Wwalking check; otherwise they'd be able
  80. 			 * to test boots by trying to SHIFT-direction
  81. 			 * into a pool and seeing if the game allowed it
  82. 			 */
  83. 			goto stop;
  84. 	    continue;
  85. 	} else {		/* e.g. objects or trap or stairs */
  86. 	    if(flags.run == 1) goto bcorr;
  87. 	    if(flags.run == 8) continue;
  88. 	    if(mtmp) continue;		/* d */
  89. 	    if(((x == u.ux - u.dx) && (y != u.uy + u.dy)) ||
  90. 	       ((y == u.uy - u.dy) && (x != u.ux + u.dx)))
  91. 	       continue;
  92. 	}
  93. stop:
  94. 	nomul(0);
  95. 	return;
  96. } /* end for loops */
  97.  
  98. if(corrct > 1 && flags.run == 2) goto stop;
  99. if((flags.run == 1 || flags.run == 3 || flags.run == 8) &&
  100. 	!noturn && !m0 && i0 && (corrct == 1 || (corrct == 2 && i0 == 1)))
  101. {
  102. 	/* make sure that we do not turn too far */
  103. 	if(i0 == 2) {
  104. 	    if(u.dx == y0-u.uy && u.dy == u.ux-x0)
  105. 		i = 2;		/* straight turn right */
  106. 	    else
  107. 		i = -2;		/* straight turn left */
  108. 	} else if(u.dx && u.dy) {
  109. 	    if((u.dx == u.dy && y0 == u.uy) || (u.dx != u.dy && y0 != u.uy))
  110. 		i = -1;		/* half turn left */
  111. 	    else
  112. 		i = 1;		/* half turn right */
  113. 	} else {
  114. 	    if((x0-u.ux == y0-u.uy && !u.dy) || (x0-u.ux != y0-u.uy && u.dy))
  115. 		i = 1;		/* half turn right */
  116. 	    else
  117. 		i = -1;		/* half turn left */
  118. 	}
  119.  
  120. 	i += u.last_str_turn;
  121. 	if(i <= 2 && i >= -2) {
  122. 	    u.last_str_turn = i;
  123. 	    u.dx = x0-u.ux;
  124. 	    u.dy = y0-u.uy;
  125. 	}
  126. }
  127. }

monster_nearby[edit]

  1. /* something like lookaround, but we are not running */
  2. /* react only to monsters that might hit us */
  3. int
  4. monster_nearby()
  5. {
  6. 	register int x,y;
  7. 	register struct monst *mtmp;
  8.  
  9. 	/* Also see the similar check in dochugw() in monmove.c */
  10. 	for(x = u.ux-1; x <= u.ux+1; x++)
  11. 	    for(y = u.uy-1; y <= u.uy+1; y++) {
  12. 		if(!isok(x,y)) continue;
  13. 		if(x == u.ux && y == u.uy) continue;
  14. 		if((mtmp = m_at(x,y)) &&
  15. 		   mtmp->m_ap_type != M_AP_FURNITURE &&
  16. 		   mtmp->m_ap_type != M_AP_OBJECT &&
  17. 		   (!mtmp->mpeaceful || Hallucination) &&
  18. 		   (!is_hider(mtmp->data) || !mtmp->mundetected) &&
  19. 		   !noattacks(mtmp->data) &&
  20. 		   mtmp->mcanmove && !mtmp->msleeping &&  /* aplvax!jcn */
  21. 		   !onscary(u.ux, u.uy, mtmp) &&
  22. 		   canspotmon(mtmp))
  23. 			return(1);
  24. 	}
  25. 	return(0);
  26. }

nomul[edit]

nomul() takes one parameter, a negative value, a number of turns to wait. This is used when the hero does some action that takes multiple turns to complete. For example, to wait 3 turns: nomul(-3);

If the parameter is 0, then the currently active multiturn action is "cancelled" and player will be able to act on the next turn.

  1. void
  2. nomul(nval)
  3. 	register int nval;
  4. {
  5. 	if(multi < nval) return;	/* This is a bug fix by ab@unido */
  6. 	u.uinvulnerable = FALSE;	/* Kludge to avoid ctrl-C bug -dlc */
  7. 	u.usleep = 0;
  8. 	multi = nval;
  9. 	flags.travel = iflags.travel1 = flags.mv = flags.run = 0;
  10. }

unmul[edit]

  1. /* called when a non-movement, multi-turn action has completed */
  2. void
  3. unmul(msg_override)
  4. const char *msg_override;
  5. {
  6. 	multi = 0;	/* caller will usually have done this already */
  7. 	if (msg_override) nomovemsg = msg_override;
  8. 	else if (!nomovemsg) nomovemsg = You_can_move_again;
  9. 	if (*nomovemsg) pline(nomovemsg);
  10. 	nomovemsg = 0;
  11. 	u.usleep = 0;
  12. 	if (afternmv) (*afternmv)();
  13. 	afternmv = 0;
  14. }
  15.  
  16. #endif /* OVL2 */

maybe_wail[edit]

  1. #ifdef OVL1
  2.  
  3. STATIC_OVL void
  4. maybe_wail()
  5. {
  6. static short powers[] = { TELEPORT, SEE_INVIS, POISON_RES, COLD_RES,
  7. 			      SHOCK_RES, FIRE_RES, SLEEP_RES, DISINT_RES,
  8. 			      TELEPORT_CONTROL, STEALTH, FAST, INVIS };
  9.  
  10. if (moves <= wailmsg + 50) return;
  11.  
  12. wailmsg = moves;
  13. if (Role_if(PM_WIZARD) || Race_if(PM_ELF) || Role_if(PM_VALKYRIE)) {
  14. 	const char *who;
  15. 	int i, powercnt;
  16.  
  17. 	who = (Role_if(PM_WIZARD) || Role_if(PM_VALKYRIE)) ?
  18. 		urole.name.m : "Elf";
  19. 	if (u.uhp == 1) {
  20. 	    pline("%s is about to die.", who);
  21. 	} else {
  22. 	    for (i = 0, powercnt = 0; i < SIZE(powers); ++i)
  23. 		if (u.uprops[powers[i]].intrinsic & INTRINSIC) ++powercnt;
  24.  
  25. 	    pline(powercnt >= 4 ? "%s, all your powers will be lost..."
  26. 				: "%s, your life force is running out.", who);
  27. 	}
  28. } else {
  29. 	You_hear(u.uhp == 1 ? "the wailing of the Banshee..."
  30. 			    : "the howling of the CwnAnnwn...");
  31. }
  32. }

losehp[edit]

losehp() takes 3 parameters, damage, killer string and killer format. damage is an integer value, and hero will be dealt that much damage. If this kills the hero, then the killer string will be used as the death reason, and killer format will define how the killer string is used. Killer string is one of KILLED_BY_AN, KILLED_BY or NO_KILLER_PREFIX. For example:

losehp(rnd(30), "system shock", KILLED_BY_AN);
  1. void
  2. losehp(n, knam, k_format)
  3. register int n;
  4. register const char *knam;
  5. boolean k_format;
  6. {
  7. 	if (Upolyd) {
  8. 		u.mh -= n;
  9. 		if (u.mhmax < u.mh) u.mhmax = u.mh;
  10. 		flags.botl = 1;
  11. 		if (u.mh < 1)
  12. 		    rehumanize();
  13. 		else if (n > 0 && u.mh*10 < u.mhmax && Unchanging)
  14. 		    maybe_wail();
  15. 		return;
  16. 	}
  17.  
  18. 	u.uhp -= n;
  19. 	if(u.uhp > u.uhpmax)
  20. 		u.uhpmax = u.uhp;	/* perhaps n was negative */
  21. 	flags.botl = 1;
  22. 	if(u.uhp < 1) {
  23. 		killer_format = k_format;
  24. 		killer = knam;		/* the thing that killed you */
  25. 		You("die...");
  26. 		done(DIED);
  27. 	} else if (n > 0 && u.uhp*10 < u.uhpmax) {
  28. 		maybe_wail();
  29. 	}
  30. }

weight_cap[edit]

  1. int
  2. weight_cap()
  3. {
  4. 	register long carrcap;
  5.  
  6. 	carrcap = 25*(ACURRSTR + ACURR(A_CON)) + 50;
  7. 	if (Upolyd) {
  8. 		/* consistent with can_carry() in mon.c */
  9. 		if (youmonst.data->mlet == S_NYMPH)
  10. 			carrcap = MAX_CARR_CAP;
  11. 		else if (!youmonst.data->cwt)
  12. 			carrcap = (carrcap * (long)youmonst.data->msize) / MZ_HUMAN;
  13. 		else if (!strongmonst(youmonst.data)
  14. 			|| (strongmonst(youmonst.data) && (youmonst.data->cwt > WT_HUMAN)))
  15. 			carrcap = (carrcap * (long)youmonst.data->cwt / WT_HUMAN);
  16. 	}
  17.  
  18. 	if (Levitation || Is_airlevel(&u.uz)    /* pugh@cornell */
  19. #ifdef STEED
  20. 			|| (u.usteed && strongmonst(u.usteed->data))
  21. #endif
  22. 	)
  23. 		carrcap = MAX_CARR_CAP;
  24. 	else {
  25. 		if(carrcap > MAX_CARR_CAP) carrcap = MAX_CARR_CAP;
  26. 		if (!Flying) {
  27. 			if(EWounded_legs & LEFT_SIDE) carrcap -= 100;
  28. 			if(EWounded_legs & RIGHT_SIDE) carrcap -= 100;
  29. 		}
  30. 		if (carrcap < 0) carrcap = 0;
  31. 	}
  32. 	return((int) carrcap);
  33. }

inv_weight[edit]

  1. static int wc;	/* current weight_cap(); valid after call to inv_weight() */
  2.  
  3. /* returns how far beyond the normal capacity the player is currently. */
  4. /* inv_weight() is negative if the player is below normal capacity. */
  5. int
  6. inv_weight()
  7. {
  8. 	register struct obj *otmp = invent;
  9. 	register int wt = 0;
  10.  
  11. #ifndef GOLDOBJ
  12. 	/* when putting stuff into containers, gold is inserted at the head
  13. 	   of invent for easier manipulation by askchain & co, but it's also
  14. 	   retained in u.ugold in order to keep the status line accurate; we
  15. 	   mustn't add its weight in twice under that circumstance */
  16. 	wt = (otmp && otmp->oclass == COIN_CLASS) ? 0 :
  17. 		(int)((u.ugold + 50L) / 100L);
  18. #endif
  19. 	while (otmp) {
  20. #ifndef GOLDOBJ
  21. 		if (otmp->otyp != BOULDER || !throws_rocks(youmonst.data))
  22. #else
  23. 		if (otmp->oclass == COIN_CLASS)
  24. 			wt += (int)(((long)otmp->quan + 50L) / 100L);
  25. 		else if (otmp->otyp != BOULDER || !throws_rocks(youmonst.data))
  26. #endif
  27. 			wt += otmp->owt;
  28. 		otmp = otmp->nobj;
  29. 	}
  30. 	wc = weight_cap();
  31. 	return (wt - wc);
  32. }

calc_capacity[edit]

  1. /*
  2. * Returns 0 if below normal capacity, or the number of "capacity units"
  3. * over the normal capacity the player is loaded.  Max is 5.
  4. */
  5. int
  6. calc_capacity(xtra_wt)
  7. int xtra_wt;
  8. {
  9. int cap, wt = inv_weight() + xtra_wt;
  10.  
  11. if (wt <= 0) return UNENCUMBERED;
  12. if (wc <= 1) return OVERLOADED;
  13. cap = (wt*2 / wc) + 1;
  14. return min(cap, OVERLOADED);
  15. }

near_capacity[edit]

  1. int
  2. near_capacity()
  3. {
  4. return calc_capacity(0);
  5. }

max_capacity[edit]

  1. int
  2. max_capacity()
  3. {
  4. int wt = inv_weight();
  5.  
  6. return (wt - (2 * wc));
  7. }

check_capacity[edit]

  1. boolean
  2. check_capacity(str)
  3. const char *str;
  4. {
  5. if(near_capacity() >= EXT_ENCUMBER) {
  6. 	if(str)
  7. 	    pline(str);
  8. 	else
  9. 	    You_cant("do that while carrying so much stuff.");
  10. 	return 1;
  11. }
  12. return 0;
  13. }
  14.  
  15. #endif /* OVL1 */

inv_cnt[edit]

  1. #ifdef OVLB
  2.  
  3. int
  4. inv_cnt()
  5. {
  6. 	register struct obj *otmp = invent;
  7. 	register int ct = 0;
  8.  
  9. 	while(otmp){
  10. 		ct++;
  11. 		otmp = otmp->nobj;
  12. 	}
  13. 	return(ct);
  14. }

money_cnt[edit]

  1. #ifdef GOLDOBJ
  2. /* Counts the money in an object chain. */
  3. /* Intended use is for your or some monsters inventory, */
  4. /* now that u.gold/m.gold is gone.*/
  5. /* Counting money in a container might be possible too. */
  6. long
  7. money_cnt(otmp)
  8. struct obj *otmp;
  9. {
  10. while(otmp) {
  11. 	        /* Must change when silver & copper is implemented: */
  12. 	        if (otmp->oclass == COIN_CLASS) return otmp->quan;
  13. 	        otmp = otmp->nobj;
  14. 	}
  15. 	return 0;
  16. }
  17. #endif
  18. #endif /* OVLB */
  19.  
  20. /*hack.c*/