Source:NetHack 3.4.3/src/do.c

From NetHackWiki
Jump to: navigation, search

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

Top of file[edit]

  1. /*	SCCS Id: @(#)do.c	3.4	2003/12/02	*/
  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. /* Contains code for 'd', 'D' (drop), '>', '<' (up, down) */
  2.  
  3. #include "hack.h"
  4. #include "lev.h"
  5.  
  6. #ifdef SINKS
  7. # ifdef OVLB
  8. STATIC_DCL void FDECL(trycall, (struct obj *));
  9. # endif /* OVLB */
  10. STATIC_DCL void FDECL(dosinkring, (struct obj *));
  11. #endif /* SINKS */
  12.  
  13. STATIC_PTR int FDECL(drop, (struct obj *));
  14. STATIC_PTR int NDECL(wipeoff);
  15.  
  16. #ifdef OVL0
  17. STATIC_DCL int FDECL(menu_drop, (int));
  18. #endif
  19. #ifdef OVL2
  20. STATIC_DCL int NDECL(currentlevel_rewrite);
  21. STATIC_DCL void NDECL(final_level);
  22. /* static boolean FDECL(badspot, (XCHAR_P,XCHAR_P)); */
  23. #endif
  24.  
  25. #ifdef OVLB
  26.  
  27. static NEARDATA const char drop_types[] =
  28. 	{ ALLOW_COUNT, COIN_CLASS, ALL_CLASSES, 0 };

dodrop[edit]

  1. /* 'd' command: drop one inventory item */
  2. int
  3. dodrop()
  4. {
  5. #ifndef GOLDOBJ
  6. 	int result, i = (invent || u.ugold) ? 0 : (SIZE(drop_types) - 1);
  7. #else
  8. 	int result, i = (invent) ? 0 : (SIZE(drop_types) - 1);
  9. #endif
  10.  
  11. 	if (*u.ushops) sellobj_state(SELL_DELIBERATE);
  12. 	result = drop(getobj(&drop_types[i], "drop"));
  13. 	if (*u.ushops) sellobj_state(SELL_NORMAL);
  14. 	reset_occupations();
  15.  
  16. 	return result;
  17. }
  18.  
  19. #endif /* OVLB */

boulder_hits_pool[edit]

  1. #ifdef OVL0
  2.  
  3. /* Called when a boulder is dropped, thrown, or pushed.  If it ends up
  4. * in a pool, it either fills the pool up or sinks away.  In either case,
  5. * it's gone for good...  If the destination is not a pool, returns FALSE.
  6. */
  7. boolean
  8. boulder_hits_pool(otmp, rx, ry, pushing)
  9. struct obj *otmp;
  10. register int rx, ry;
  11. boolean pushing;
  12. {
  13. 	if (!otmp || otmp->otyp != BOULDER)
  14. 	    impossible("Not a boulder?");
  15. 	else if (!Is_waterlevel(&u.uz) && (is_pool(rx,ry) || is_lava(rx,ry))) {
  16. 	    boolean lava = is_lava(rx,ry), fills_up;
  17. 	    const char *what = waterbody_name(rx,ry);
  18. 	    schar ltyp = levl[rx][ry].typ;
  19. 	    int chance = rn2(10);		/* water: 90%; lava: 10% */
  20. 	    fills_up = lava ? chance == 0 : chance != 0;
  21.  
  22. 	    if (fills_up) {
  23. 		struct trap *ttmp = t_at(rx, ry);
  24.  
  25. 		if (ltyp == DRAWBRIDGE_UP) {
  26. 		    levl[rx][ry].drawbridgemask &= ~DB_UNDER; /* clear lava */
  27. 		    levl[rx][ry].drawbridgemask |= DB_FLOOR;
  28. 		} else
  29. 		    levl[rx][ry].typ = ROOM;
  30.  
  31. 		if (ttmp) (void) delfloortrap(ttmp);
  32. 		bury_objs(rx, ry);
  33.  
  34. 		newsym(rx,ry);
  35. 		if (pushing) {
  36. 		    You("push %s into the %s.", the(xname(otmp)), what);
  37. 		    if (flags.verbose && !Blind)
  38. 			pline("Now you can cross it!");
  39. 		    /* no splashing in this case */
  40. 		}
  41. 	    }
  42. 	    if (!fills_up || !pushing) {	/* splashing occurs */
  43. 		if (!u.uinwater) {
  44. 		    if (pushing ? !Blind : cansee(rx,ry)) {
  45. 			There("is a large splash as %s %s the %s.",
  46. 			      the(xname(otmp)), fills_up? "fills":"falls into",
  47. 			      what);
  48. 		    } else if (flags.soundok)
  49. 			You_hear("a%s splash.", lava ? " sizzling" : "");
  50. 		    wake_nearto(rx, ry, 40);
  51. 		}
  52.  
  53. 		if (fills_up && u.uinwater && distu(rx,ry) == 0) {
  54. 		    u.uinwater = 0;
  55. 		    docrt();
  56. 		    vision_full_recalc = 1;
  57. 		    You("find yourself on dry land again!");
  58. 		} else if (lava && distu(rx,ry) <= 2) {
  59. 		    You("are hit by molten lava%c",
  60. 			Fire_resistance ? '.' : '!');
  61. 			burn_away_slime();
  62. 		    losehp(d((Fire_resistance ? 1 : 3), 6),
  63. 			   "molten lava", KILLED_BY);
  64. 		} else if (!fills_up && flags.verbose &&
  65. 			   (pushing ? !Blind : cansee(rx,ry)))
  66. 		    pline("It sinks without a trace!");
  67. 	    }
  68.  
  69. 	    /* boulder is now gone */
  70. 	    if (pushing) delobj(otmp);
  71. 	    else obfree(otmp, (struct obj *)0);
  72. 	    return TRUE;
  73. 	}
  74. 	return FALSE;
  75. }

flooreffects[edit]

  1. /* Used for objects which sometimes do special things when dropped; must be
  2. * called with the object not in any chain.  Returns TRUE if the object goes
  3. * away.
  4. */
  5. boolean
  6. flooreffects(obj,x,y,verb)
  7. struct obj *obj;
  8. int x,y;
  9. const char *verb;
  10. {
  11. 	struct trap *t;
  12. 	struct monst *mtmp;
  13.  
  14. 	if (obj->where != OBJ_FREE)
  15. 	    panic("flooreffects: obj not free");
  16.  
  17. 	/* make sure things like water_damage() have no pointers to follow */
  18. 	obj->nobj = obj->nexthere = (struct obj *)0;
  19.  
  20. 	if (obj->otyp == BOULDER && boulder_hits_pool(obj, x, y, FALSE))
  21. 		return TRUE;
  22. 	else if (obj->otyp == BOULDER && (t = t_at(x,y)) != 0 &&
  23. 		 (t->ttyp==PIT || t->ttyp==SPIKED_PIT
  24. 			|| t->ttyp==TRAPDOOR || t->ttyp==HOLE)) {
  25. 		if (((mtmp = m_at(x, y)) && mtmp->mtrapped) ||
  26. 			(u.utrap && u.ux == x && u.uy == y)) {
  27. 		    if (*verb)
  28. 			pline_The("boulder %s into the pit%s.",
  29. 				vtense((const char *)0, verb),
  30. 				(mtmp) ? "" : " with you");
  31. 		    if (mtmp) {
  32. 			if (!passes_walls(mtmp->data) &&
  33. 				!throws_rocks(mtmp->data)) {
  34. 			    if (hmon(mtmp, obj, TRUE) && !is_whirly(mtmp->data))
  35. 				return FALSE;	/* still alive */
  36. 			}
  37. 			mtmp->mtrapped = 0;
  38. 		    } else {
  39. 			if (!Passes_walls && !throws_rocks(youmonst.data)) {
  40. 			    losehp(rnd(15), "squished under a boulder",
  41. 				   NO_KILLER_PREFIX);
  42. 			    return FALSE;	/* player remains trapped */
  43. 			} else u.utrap = 0;
  44. 		    }
  45. 		}
  46. 		if (*verb) {
  47. 			if (Blind) {
  48. 				if ((x == u.ux) && (y == u.uy))
  49. 					You_hear("a CRASH! beneath you.");
  50. 				else
  51. 					You_hear("the boulder %s.", verb);
  52. 			} else if (cansee(x, y)) {
  53. 				pline_The("boulder %s%s.",
  54. 				    t->tseen ? "" : "triggers and ",
  55. 				    t->ttyp == TRAPDOOR ? "plugs a trap door" :
  56. 				    t->ttyp == HOLE ? "plugs a hole" :
  57. 				    "fills a pit");
  58. 			}
  59. 		}
  60. 		deltrap(t);
  61. 		obfree(obj, (struct obj *)0);
  62. 		bury_objs(x, y);
  63. 		newsym(x,y);
  64. 		return TRUE;
  65. 	} else if (is_lava(x, y)) {
  66. 		return fire_damage(obj, FALSE, FALSE, x, y);
  67. 	} else if (is_pool(x, y)) {
  68. 		/* Reasonably bulky objects (arbitrary) splash when dropped.
  69. 		 * If you're floating above the water even small things make noise.
  70. 		 * Stuff dropped near fountains always misses */
  71. 		if ((Blind || (Levitation || Flying)) && flags.soundok &&
  72. 		    ((x == u.ux) && (y == u.uy))) {
  73. 		    if (!Underwater) {
  74. 			if (weight(obj) > 9) {
  75. 				pline("Splash!");
  76. 		        } else if (Levitation || Flying) {
  77. 				pline("Plop!");
  78. 		        }
  79. 		    }
  80. 		    map_background(x, y, 0);
  81. 		    newsym(x, y);
  82. 		}
  83. 		water_damage(obj, FALSE, FALSE);
  84. 	} else if (u.ux == x && u.uy == y &&
  85. 		(!u.utrap || u.utraptype != TT_PIT) &&
  86. 		(t = t_at(x,y)) != 0 && t->tseen &&
  87. 			(t->ttyp==PIT || t->ttyp==SPIKED_PIT)) {
  88. 		/* you escaped a pit and are standing on the precipice */
  89. 		if (Blind && flags.soundok)
  90. 			You_hear("%s %s downwards.",
  91. 				The(xname(obj)), otense(obj, "tumble"));
  92. 		else
  93. 			pline("%s %s into %s pit.",
  94. 				The(xname(obj)), otense(obj, "tumble"),
  95. 				the_your[t->madeby_u]);
  96. 	}
  97. 	return FALSE;
  98. }
  99.  
  100. #endif /* OVL0 */

doaltarobj[edit]

  1. #ifdef OVLB
  2.  
  3. void
  4. doaltarobj(obj)  /* obj is an object dropped on an altar */
  5. 	register struct obj *obj;
  6. {
  7. 	if (Blind)
  8. 		return;
  9.  
  10. 	/* KMH, conduct */
  11. 	u.uconduct.gnostic++;
  12.  
  13. 	if ((obj->blessed || obj->cursed) && obj->oclass != COIN_CLASS) {
  14. 		There("is %s flash as %s %s the altar.",
  15. 			an(hcolor(obj->blessed ? NH_AMBER : NH_BLACK)),
  16. 			doname(obj), otense(obj, "hit"));
  17. 		if (!Hallucination) obj->bknown = 1;
  18. 	} else {
  19. 		pline("%s %s on the altar.", Doname2(obj),
  20. 			otense(obj, "land"));
  21. 		obj->bknown = 1;
  22. 	}
  23. }

trycall[edit]

  1. #ifdef SINKS
  2. STATIC_OVL
  3. void
  4. trycall(obj)
  5. register struct obj *obj;
  6. {
  7. 	if(!objects[obj->otyp].oc_name_known &&
  8. 	   !objects[obj->otyp].oc_uname)
  9. 	   docall(obj);
  10. }

dosinkring[edit]

  1. STATIC_OVL
  2. void
  3. dosinkring(obj)  /* obj is a ring being dropped over a kitchen sink */
  4. register struct obj *obj;
  5. {
  6. 	register struct obj *otmp,*otmp2;
  7. 	register boolean ideed = TRUE;
  8.  
  9. 	You("drop %s down the drain.", doname(obj));
  10. 	obj->in_use = TRUE;	/* block free identification via interrupt */
  11. 	switch(obj->otyp) {	/* effects that can be noticed without eyes */
  12. 	    case RIN_SEARCHING:
  13. 		You("thought your %s got lost in the sink, but there it is!",
  14. 			xname(obj));
  15. 		goto giveback;
  16. 	    case RIN_SLOW_DIGESTION:
  17. 		pline_The("ring is regurgitated!");
  18. giveback:
  19. 		obj->in_use = FALSE;
  20. 		dropx(obj);
  21. 		trycall(obj);
  22. 		return;
  23. 	    case RIN_LEVITATION:
  24. 		pline_The("sink quivers upward for a moment.");
  25. 		break;
  26. 	    case RIN_POISON_RESISTANCE:
  27. 		You("smell rotten %s.", makeplural(fruitname(FALSE)));
  28. 		break;
  29. 	    case RIN_AGGRAVATE_MONSTER:
  30. 		pline("Several flies buzz angrily around the sink.");
  31. 		break;
  32. 	    case RIN_SHOCK_RESISTANCE:
  33. 		pline("Static electricity surrounds the sink.");
  34. 		break;
  35. 	    case RIN_CONFLICT:
  36. 		You_hear("loud noises coming from the drain.");
  37. 		break;
  38. 	    case RIN_SUSTAIN_ABILITY:	/* KMH */
  39. 		pline_The("water flow seems fixed.");
  40. 		break;
  41. 	    case RIN_GAIN_STRENGTH:
  42. 		pline_The("water flow seems %ser now.",
  43. 			(obj->spe<0) ? "weak" : "strong");
  44. 		break;
  45. 	    case RIN_GAIN_CONSTITUTION:
  46. 		pline_The("water flow seems %ser now.",
  47. 			(obj->spe<0) ? "less" : "great");
  48. 		break;
  49. 	    case RIN_INCREASE_ACCURACY:	/* KMH */
  50. 		pline_The("water flow %s the drain.",
  51. 			(obj->spe<0) ? "misses" : "hits");
  52. 		break;
  53. 	    case RIN_INCREASE_DAMAGE:
  54. 		pline_The("water's force seems %ser now.",
  55. 			(obj->spe<0) ? "small" : "great");
  56. 		break;
  57. 	    case RIN_HUNGER:
  58. 		ideed = FALSE;
  59. 		for(otmp = level.objects[u.ux][u.uy]; otmp; otmp = otmp2) {
  60. 		    otmp2 = otmp->nexthere;
  61. 		    if (otmp != uball && otmp != uchain &&
  62. 			    !obj_resists(otmp, 1, 99)) {
  63. 			if (!Blind) {
  64. 			    pline("Suddenly, %s %s from the sink!",
  65. 				  doname(otmp), otense(otmp, "vanish"));
  66. 			    ideed = TRUE;
  67. 			}
  68. 			delobj(otmp);
  69. 		    }
  70. 		}
  71. 		break;
  72. 	    case MEAT_RING:
  73. 		/* Not the same as aggravate monster; besides, it's obvious. */
  74. 		pline("Several flies buzz around the sink.");
  75. 		break;
  76. 	    default:
  77. 		ideed = FALSE;
  78. 		break;
  79. 	}
  80. 	if(!Blind && !ideed && obj->otyp != RIN_HUNGER) {
  81. 	    ideed = TRUE;
  82. 	    switch(obj->otyp) {		/* effects that need eyes */
  83. 		case RIN_ADORNMENT:
  84. 		    pline_The("faucets flash brightly for a moment.");
  85. 		    break;
  86. 		case RIN_REGENERATION:
  87. 		    pline_The("sink looks as good as new.");
  88. 		    break;
  89. 		case RIN_INVISIBILITY:
  90. 		    You("don't see anything happen to the sink.");
  91. 		    break;
  92. 		case RIN_FREE_ACTION:
  93. 		    You("see the ring slide right down the drain!");
  94. 		    break;
  95. 		case RIN_SEE_INVISIBLE:
  96. 		    You("see some air in the sink.");
  97. 		    break;
  98. 		case RIN_STEALTH:
  99. 		pline_The("sink seems to blend into the floor for a moment.");
  100. 		    break;
  101. 		case RIN_FIRE_RESISTANCE:
  102. 		pline_The("hot water faucet flashes brightly for a moment.");
  103. 		    break;
  104. 		case RIN_COLD_RESISTANCE:
  105. 		pline_The("cold water faucet flashes brightly for a moment.");
  106. 		    break;
  107. 		case RIN_PROTECTION_FROM_SHAPE_CHAN:
  108. 		    pline_The("sink looks nothing like a fountain.");
  109. 		    break;
  110. 		case RIN_PROTECTION:
  111. 		    pline_The("sink glows %s for a moment.",
  112. 			    hcolor((obj->spe<0) ? NH_BLACK : NH_SILVER));
  113. 		    break;
  114. 		case RIN_WARNING:
  115. 		    pline_The("sink glows %s for a moment.", hcolor(NH_WHITE));
  116. 		    break;
  117. 		case RIN_TELEPORTATION:
  118. 		    pline_The("sink momentarily vanishes.");
  119. 		    break;
  120. 		case RIN_TELEPORT_CONTROL:
  121. 	    pline_The("sink looks like it is being beamed aboard somewhere.");
  122. 		    break;
  123. 		case RIN_POLYMORPH:
  124. 		    pline_The("sink momentarily looks like a fountain.");
  125. 		    break;
  126. 		case RIN_POLYMORPH_CONTROL:
  127. 	pline_The("sink momentarily looks like a regularly erupting geyser.");
  128. 		    break;
  129. 	    }
  130. 	}
  131. 	if(ideed)
  132. 	    trycall(obj);
  133. 	else
  134. 	    You_hear("the ring bouncing down the drainpipe.");
  135. 	if (!rn2(20)) {
  136. 		pline_The("sink backs up, leaving %s.", doname(obj));
  137. 		obj->in_use = FALSE;
  138. 		dropx(obj);
  139. 	} else
  140. 		useup(obj);
  141. }
  142. #endif
  143.  
  144. #endif /* OVLB */

canletgo[edit]

  1. #ifdef OVL0
  2.  
  3. /* some common tests when trying to drop or throw items */
  4. boolean
  5. canletgo(obj,word)
  6. register struct obj *obj;
  7. register const char *word;
  8. {
  9. 	if(obj->owornmask & (W_ARMOR | W_RING | W_AMUL | W_TOOL)){
  10. 		if (*word)
  11. 			Norep("You cannot %s %s you are wearing.",word,
  12. 				something);
  13. 		return(FALSE);
  14. 	}
  15. 	if (obj->otyp == LOADSTONE && obj->cursed) {
  16. 		/* getobj() kludge sets corpsenm to user's specified count
  17. 		   when refusing to split a stack of cursed loadstones */
  18. 		if (*word) {
  19. 			/* getobj() ignores a count for throwing since that is
  20. 			   implicitly forced to be 1; replicate its kludge... */
  21. 			if (!strcmp(word, "throw") && obj->quan > 1L)
  22. 			    obj->corpsenm = 1;
  23. 			pline("For some reason, you cannot %s%s the stone%s!",
  24. 			      word, obj->corpsenm ? " any of" : "",
  25. 			      plur(obj->quan));
  26. 		}
  27. 		obj->corpsenm = 0;		/* reset */
  28. 		obj->bknown = 1;
  29. 		return(FALSE);
  30. 	}
  31. 	if (obj->otyp == LEASH && obj->leashmon != 0) {
  32. 		if (*word)
  33. 			pline_The("leash is tied around your %s.",
  34. 					body_part(HAND));
  35. 		return(FALSE);
  36. 	}
  37. #ifdef STEED
  38. 	if (obj->owornmask & W_SADDLE) {
  39. 		if (*word)
  40. 			You("cannot %s %s you are sitting on.", word,
  41. 				something);
  42. 		return (FALSE);
  43. 	}
  44. #endif
  45. 	return(TRUE);
  46. }

drop[edit]

  1. STATIC_PTR
  2. int
  3. drop(obj)
  4. register struct obj *obj;
  5. {
  6. 	if(!obj) return(0);
  7. 	if(!canletgo(obj,"drop"))
  8. 		return(0);
  9. 	if(obj == uwep) {
  10. 		if(welded(uwep)) {
  11. 			weldmsg(obj);
  12. 			return(0);
  13. 		}
  14. 		setuwep((struct obj *)0);
  15. 	}
  16. 	if(obj == uquiver) {
  17. 		setuqwep((struct obj *)0);
  18. 	}
  19. 	if (obj == uswapwep) {
  20. 		setuswapwep((struct obj *)0);
  21. 	}
  22.  
  23. 	if (u.uswallow) {
  24. 		/* barrier between you and the floor */
  25. 		if(flags.verbose)
  26. 		{
  27. 			char buf[BUFSZ];
  28.  
  29. 			/* doname can call s_suffix, reusing its buffer */
  30. 			Strcpy(buf, s_suffix(mon_nam(u.ustuck)));
  31. 			You("drop %s into %s %s.", doname(obj), buf,
  32. 				mbodypart(u.ustuck, STOMACH));
  33. 		}
  34. 	} else {
  35. #ifdef SINKS
  36. 	    if((obj->oclass == RING_CLASS || obj->otyp == MEAT_RING) &&
  37. 			IS_SINK(levl[u.ux][u.uy].typ)) {
  38. 		dosinkring(obj);
  39. 		return(1);
  40. 	    }
  41. #endif
  42. 	    if (!can_reach_floor()) {
  43. 		if(flags.verbose) You("drop %s.", doname(obj));
  44. #ifndef GOLDOBJ
  45. 		if (obj->oclass != COIN_CLASS || obj == invent) freeinv(obj);
  46. #else
  47. 		/* Ensure update when we drop gold objects */
  48. 		if (obj->oclass == COIN_CLASS) flags.botl = 1;
  49. 		freeinv(obj);
  50. #endif
  51. 		hitfloor(obj);
  52. 		return(1);
  53. 	    }
  54. 	    if (!IS_ALTAR(levl[u.ux][u.uy].typ) && flags.verbose)
  55. 		You("drop %s.", doname(obj));
  56. 	}
  57. 	dropx(obj);
  58. 	return(1);
  59. }

dropx[edit]

  1. /* Called in several places - may produce output */
  2. /* eg ship_object() and dropy() -> sellobj() both produce output */
  3. void
  4. dropx(obj)
  5. register struct obj *obj;
  6. {
  7. #ifndef GOLDOBJ
  8. 	if (obj->oclass != COIN_CLASS || obj == invent) freeinv(obj);
  9. #else
  10. /* Ensure update when we drop gold objects */
  11. if (obj->oclass == COIN_CLASS) flags.botl = 1;
  12. freeinv(obj);
  13. #endif
  14. 	if (!u.uswallow) {
  15. 	    if (ship_object(obj, u.ux, u.uy, FALSE)) return;
  16. 	    if (IS_ALTAR(levl[u.ux][u.uy].typ))
  17. 		doaltarobj(obj); /* set bknown */
  18. 	}
  19. 	dropy(obj);
  20. }

dropy[edit]

  1. void
  2. dropy(obj)
  3. register struct obj *obj;
  4. {
  5. 	if (obj == uwep) setuwep((struct obj *)0);
  6. 	if (obj == uquiver) setuqwep((struct obj *)0);
  7. 	if (obj == uswapwep) setuswapwep((struct obj *)0);
  8.  
  9. 	if (!u.uswallow && flooreffects(obj,u.ux,u.uy,"drop")) return;
  10. 	/* uswallow check done by GAN 01/29/87 */
  11. 	if(u.uswallow) {
  12. 	    boolean could_petrify = FALSE;
  13. 	    boolean could_poly = FALSE;
  14. 	    boolean could_slime = FALSE;
  15. 	    boolean could_grow = FALSE;
  16. 	    boolean could_heal = FALSE;
  17.  
  18. 	    if (obj != uball) {		/* mon doesn't pick up ball */
  19. 		if (obj->otyp == CORPSE) {
  20. 		    could_petrify = touch_petrifies(&mons[obj->corpsenm]);
  21. 		    could_poly = polyfodder(obj);
  22. 		    could_slime = (obj->corpsenm == PM_GREEN_SLIME);
  23. 		    could_grow = (obj->corpsenm == PM_WRAITH);
  24. 		    could_heal = (obj->corpsenm == PM_NURSE);
  25. 		}
  26. 		(void) mpickobj(u.ustuck,obj);
  27. 		if (is_animal(u.ustuck->data)) {
  28. 		    if (could_poly || could_slime) {
  29. 			(void) newcham(u.ustuck,
  30. 				       could_poly ? (struct permonst *)0 :
  31. 				       &mons[PM_GREEN_SLIME],
  32. 				       FALSE, could_slime);
  33. 			delobj(obj);	/* corpse is digested */
  34. 		    } else if (could_petrify) {
  35. 			minstapetrify(u.ustuck, TRUE);
  36. 			/* Don't leave a cockatrice corpse in a statue */
  37. 			if (!u.uswallow) delobj(obj);
  38. 		    } else if (could_grow) {
  39. 			(void) grow_up(u.ustuck, (struct monst *)0);
  40. 			delobj(obj);	/* corpse is digested */
  41. 		    } else if (could_heal) {
  42. 			u.ustuck->mhp = u.ustuck->mhpmax;
  43. 			delobj(obj);	/* corpse is digested */
  44. 		    }
  45. 		}
  46. 	    }
  47. 	} else  {
  48. 	    place_object(obj, u.ux, u.uy);
  49. 	    if (obj == uball)
  50. 		drop_ball(u.ux,u.uy);
  51. 	    else
  52. 		sellobj(obj, u.ux, u.uy);
  53. 	    stackobj(obj);
  54. 	    if(Blind && Levitation)
  55. 		map_object(obj, 0);
  56. 	    newsym(u.ux,u.uy);	/* remap location under self */
  57. 	}
  58. }

obj_no_longer_held[edit]

  1. /* things that must change when not held; recurse into containers.
  2. Called for both player and monsters */
  3. void
  4. obj_no_longer_held(obj)
  5. struct obj *obj;
  6. {
  7. 	if (!obj) {
  8. 	    return;
  9. 	} else if ((Is_container(obj) || obj->otyp == STATUE) && obj->cobj) {
  10. 	    struct obj *contents;
  11. 	    for(contents=obj->cobj; contents; contents=contents->nobj)
  12. 		obj_no_longer_held(contents);
  13. 	}
  14. 	switch(obj->otyp) {
  15. 	case CRYSKNIFE:
  16. 	    /* KMH -- Fixed crysknives have only 10% chance of reverting */
  17. 	    /* only changes when not held by player or monster */
  18. 	    if (!obj->oerodeproof || !rn2(10)) {
  19. 		obj->otyp = WORM_TOOTH;
  20. 		obj->oerodeproof = 0;
  21. 	    }
  22. 	    break;
  23. 	}
  24. }

doddrop[edit]

  1. /* 'D' command: drop several things */
  2. int
  3. doddrop()
  4. {
  5. 	int result = 0;
  6.  
  7. 	add_valid_menu_class(0); /* clear any classes already there */
  8. 	if (*u.ushops) sellobj_state(SELL_DELIBERATE);
  9. 	if (flags.menu_style != MENU_TRADITIONAL ||
  10. 		(result = ggetobj("drop", drop, 0, FALSE, (unsigned *)0)) < -1)
  11. 	    result = menu_drop(result);
  12. 	if (*u.ushops) sellobj_state(SELL_NORMAL);
  13. 	reset_occupations();
  14.  
  15. 	return result;
  16. }

menu_drop[edit]

  1. /* Drop things from the hero's inventory, using a menu. */
  2. STATIC_OVL int
  3. menu_drop(retry)
  4. int retry;
  5. {
  6. int n, i, n_dropped = 0;
  7. long cnt;
  8. struct obj *otmp, *otmp2;
  9. #ifndef GOLDOBJ
  10. struct obj *u_gold = 0;
  11. #endif
  12. menu_item *pick_list;
  13. boolean all_categories = TRUE;
  14. boolean drop_everything = FALSE;
  15.  
  16. #ifndef GOLDOBJ
  17. if (u.ugold) {
  18. 	/* Hack: gold is not in the inventory, so make a gold object
  19. 	   and put it at the head of the inventory list. */
  20. 	u_gold = mkgoldobj(u.ugold);	/* removes from u.ugold */
  21. 	u_gold->in_use = TRUE;
  22. 	u.ugold = u_gold->quan;		/* put the gold back */
  23. 	assigninvlet(u_gold);		/* might end up as NOINVSYM */
  24. 	u_gold->nobj = invent;
  25. 	invent = u_gold;
  26. }
  27. #endif
  28. if (retry) {
  29. 	all_categories = (retry == -2);
  30. } else if (flags.menu_style == MENU_FULL) {
  31. 	all_categories = FALSE;
  32. 	n = query_category("Drop what type of items?",
  33. 			invent,
  34. 			UNPAID_TYPES | ALL_TYPES | CHOOSE_ALL |
  35. 			BUC_BLESSED | BUC_CURSED | BUC_UNCURSED | BUC_UNKNOWN,
  36. 			&pick_list, PICK_ANY);
  37. 	if (!n) goto drop_done;
  38. 	for (i = 0; i < n; i++) {
  39. 	    if (pick_list[i].item.a_int == ALL_TYPES_SELECTED)
  40. 		all_categories = TRUE;
  41. 	    else if (pick_list[i].item.a_int == 'A')
  42. 		drop_everything = TRUE;
  43. 	    else
  44. 		add_valid_menu_class(pick_list[i].item.a_int);
  45. 	}
  46. 	free((genericptr_t) pick_list);
  47. } else if (flags.menu_style == MENU_COMBINATION) {
  48. 	unsigned ggoresults = 0;
  49. 	all_categories = FALSE;
  50. 	/* Gather valid classes via traditional NetHack method */
  51. 	i = ggetobj("drop", drop, 0, TRUE, &ggoresults);
  52. 	if (i == -2) all_categories = TRUE;
  53. 	if (ggoresults & ALL_FINISHED) {
  54. 		n_dropped = i;
  55. 		goto drop_done;
  56. 	}
  57. }
  58.  
  59. if (drop_everything) {
  60. 	for(otmp = invent; otmp; otmp = otmp2) {
  61. 	    otmp2 = otmp->nobj;
  62. 	    n_dropped += drop(otmp);
  63. 	}
  64. } else {
  65. 	/* should coordinate with perm invent, maybe not show worn items */
  66. 	n = query_objlist("What would you like to drop?", invent,
  67. 			USE_INVLET|INVORDER_SORT, &pick_list,
  68. 			PICK_ANY, all_categories ? allow_all : allow_category);
  69. 	if (n > 0) {
  70. 	    for (i = 0; i < n; i++) {
  71. 		otmp = pick_list[i].item.a_obj;
  72. 		cnt = pick_list[i].count;
  73. 		if (cnt < otmp->quan) {
  74. 		    if (welded(otmp)) {
  75. 			;	/* don't split */
  76. 		    } else if (otmp->otyp == LOADSTONE && otmp->cursed) {
  77. 			/* same kludge as getobj(), for canletgo()'s use */
  78. 			otmp->corpsenm = (int) cnt;	/* don't split */
  79. 		    } else {
  80. #ifndef GOLDOBJ
  81. 			if (otmp->oclass == COIN_CLASS)
  82. 			    (void) splitobj(otmp, otmp->quan - cnt);
  83. 			else
  84. #endif
  85. 			    otmp = splitobj(otmp, cnt);
  86. 		    }
  87. 		}
  88. 		n_dropped += drop(otmp);
  89. 	    }
  90. 	    free((genericptr_t) pick_list);
  91. 	}
  92. }
  93.  
  94. drop_done:
  95. #ifndef GOLDOBJ
  96. if (u_gold && invent && invent->oclass == COIN_CLASS) {
  97. 	/* didn't drop [all of] it */
  98. 	u_gold = invent;
  99. 	invent = u_gold->nobj;
  100. 	u_gold->in_use = FALSE;
  101. 	dealloc_obj(u_gold);
  102. 	update_inventory();
  103. }
  104. #endif
  105. return n_dropped;
  106. }
  107.  
  108. #endif /* OVL0 */

dodown[edit]

  1. #ifdef OVL2
  2.  
  3. /* on a ladder, used in goto_level */
  4. static NEARDATA boolean at_ladder = FALSE;
  5.  
  6. int
  7. dodown()
  8. {
  9. 	struct trap *trap = 0;
  10. 	boolean stairs_down = ((u.ux == xdnstair && u.uy == ydnstair) ||
  11. 		    (u.ux == sstairs.sx && u.uy == sstairs.sy && !sstairs.up)),
  12. 		ladder_down = (u.ux == xdnladder && u.uy == ydnladder);
  13.  
  14. #ifdef STEED
  15. 	if (u.usteed && !u.usteed->mcanmove) {
  16. 		pline("%s won't move!", Monnam(u.usteed));
  17. 		return(0);
  18. 	} else if (u.usteed && u.usteed->meating) {
  19. 		pline("%s is still eating.", Monnam(u.usteed));
  20. 		return(0);
  21. 	} else
  22. #endif
  23. 	if (Levitation) {
  24. 	    if ((HLevitation & I_SPECIAL) || (ELevitation & W_ARTI)) {
  25. 		/* end controlled levitation */
  26. 		if (ELevitation & W_ARTI) {
  27. 		    struct obj *obj;
  28.  
  29. 		    for(obj = invent; obj; obj = obj->nobj) {
  30. 			if (obj->oartifact &&
  31. 					artifact_has_invprop(obj,LEVITATION)) {
  32. 			    if (obj->age < monstermoves)
  33. 				obj->age = monstermoves + rnz(100);
  34. 			    else
  35. 				obj->age += rnz(100);
  36. 			}
  37. 		    }
  38. 		}
  39. 		if (float_down(I_SPECIAL|TIMEOUT, W_ARTI))
  40. 		    return (1);   /* came down, so moved */
  41. 	    }
  42. 	    floating_above(stairs_down ? "stairs" : ladder_down ?
  43. 			   "ladder" : surface(u.ux, u.uy));
  44. 	    return (0);   /* didn't move */
  45. 	}
  46. 	if (!stairs_down && !ladder_down) {
  47. 		if (!(trap = t_at(u.ux,u.uy)) ||
  48. 			(trap->ttyp != TRAPDOOR && trap->ttyp != HOLE)
  49. 			|| !Can_fall_thru(&u.uz) || !trap->tseen) {
  50.  
  51. 			if (flags.autodig && !flags.nopick &&
  52. 				uwep && is_pick(uwep)) {
  53. 				return use_pick_axe2(uwep);
  54. 			} else {
  55. 				You_cant("go down here.");
  56. 				return(0);
  57. 			}
  58. 		}
  59. 	}
  60. 	if(u.ustuck) {
  61. 		You("are %s, and cannot go down.",
  62. 			!u.uswallow ? "being held" : is_animal(u.ustuck->data) ?
  63. 			"swallowed" : "engulfed");
  64. 		return(1);
  65. 	}
  66. 	if (on_level(&valley_level, &u.uz) && !u.uevent.gehennom_entered) {
  67. 		You("are standing at the gate to Gehennom.");
  68. 		pline("Unspeakable cruelty and harm lurk down there.");
  69. 		if (yn("Are you sure you want to enter?") != 'y')
  70. 			return(0);
  71. 		else pline("So be it.");
  72. 		u.uevent.gehennom_entered = 1;	/* don't ask again */
  73. 	}
  74.  
  75. 	if(!next_to_u()) {
  76. 		You("are held back by your pet!");
  77. 		return(0);
  78. 	}
  79.  
  80. 	if (trap)
  81. 	    You("%s %s.", locomotion(youmonst.data, "jump"),
  82. 		trap->ttyp == HOLE ? "down the hole" : "through the trap door");
  83.  
  84. 	if (trap && Is_stronghold(&u.uz)) {
  85. 		goto_hell(FALSE, TRUE);
  86. 	} else {
  87. 		at_ladder = (boolean) (levl[u.ux][u.uy].typ == LADDER);
  88. 		next_level(!trap);
  89. 		at_ladder = FALSE;
  90. 	}
  91. 	return(1);
  92. }

doup[edit]

  1. int
  2. doup()
  3. {
  4. 	if( (u.ux != xupstair || u.uy != yupstair)
  5. 	     && (!xupladder || u.ux != xupladder || u.uy != yupladder)
  6. 	     && (!sstairs.sx || u.ux != sstairs.sx || u.uy != sstairs.sy
  7. 			|| !sstairs.up)
  8. 	  ) {
  9. 		You_cant("go up here.");
  10. 		return(0);
  11. 	}
  12. #ifdef STEED
  13. 	if (u.usteed && !u.usteed->mcanmove) {
  14. 		pline("%s won't move!", Monnam(u.usteed));
  15. 		return(0);
  16. 	} else if (u.usteed && u.usteed->meating) {
  17. 		pline("%s is still eating.", Monnam(u.usteed));
  18. 		return(0);
  19. 	} else
  20. #endif
  21. 	if(u.ustuck) {
  22. 		You("are %s, and cannot go up.",
  23. 			!u.uswallow ? "being held" : is_animal(u.ustuck->data) ?
  24. 			"swallowed" : "engulfed");
  25. 		return(1);
  26. 	}
  27. 	if(near_capacity() > SLT_ENCUMBER) {
  28. 		/* No levitation check; inv_weight() already allows for it */
  29. 		Your("load is too heavy to climb the %s.",
  30. 			levl[u.ux][u.uy].typ == STAIRS ? "stairs" : "ladder");
  31. 		return(1);
  32. 	}
  33. 	if(ledger_no(&u.uz) == 1) {
  34. 		if (yn("Beware, there will be no return! Still climb?") != 'y')
  35. 			return(0);
  36. 	}
  37. 	if(!next_to_u()) {
  38. 		You("are held back by your pet!");
  39. 		return(0);
  40. 	}
  41. 	at_ladder = (boolean) (levl[u.ux][u.uy].typ == LADDER);
  42. 	prev_level(TRUE);
  43. 	at_ladder = FALSE;
  44. 	return(1);
  45. }

currentlevel_rewrite[edit]

  1. d_level save_dlevel = {0, 0};
  2.  
  3. /* check that we can write out the current level */
  4. STATIC_OVL int
  5. currentlevel_rewrite()
  6. {
  7. 	register int fd;
  8. 	char whynot[BUFSZ];
  9.  
  10. 	/* since level change might be a bit slow, flush any buffered screen
  11. 	 *  output (like "you fall through a trap door") */
  12. 	mark_synch();
  13.  
  14. 	fd = create_levelfile(ledger_no(&u.uz), whynot);
  15. 	if (fd < 0) {
  16. 		/*
  17. 		 * This is not quite impossible: e.g., we may have
  18. 		 * exceeded our quota. If that is the case then we
  19. 		 * cannot leave this level, and cannot save either.
  20. 		 * Another possibility is that the directory was not
  21. 		 * writable.
  22. 		 */
  23. 		pline("%s", whynot);
  24. 		return -1;
  25. 	}
  26.  
  27. #ifdef MFLOPPY
  28. 	if (!savelev(fd, ledger_no(&u.uz), COUNT_SAVE)) {
  29. 		(void) close(fd);
  30. 		delete_levelfile(ledger_no(&u.uz));
  31. 		pline("NetHack is out of disk space for making levels!");
  32. 		You("can save, quit, or continue playing.");
  33. 		return -1;
  34. 	}
  35. #endif
  36. 	return fd;
  37. }

save_currentstate[edit]

  1. #ifdef INSURANCE
  2. void
  3. save_currentstate()
  4. {
  5. 	int fd;
  6.  
  7. 	if (flags.ins_chkpt) {
  8. 		/* write out just-attained level, with pets and everything */
  9. 		fd = currentlevel_rewrite();
  10. 		if(fd < 0) return;
  11. 		bufon(fd);
  12. 		savelev(fd,ledger_no(&u.uz), WRITE_SAVE);
  13. 		bclose(fd);
  14. 	}
  15.  
  16. 	/* write out non-level state */
  17. 	savestateinlock();
  18. }
  19. #endif

badspot[edit]

  1. /*
  2. static boolean
  3. badspot(x, y)
  4. register xchar x, y;
  5. {
  6. 	return((levl[x][y].typ != ROOM && levl[x][y].typ != AIR &&
  7. 			 levl[x][y].typ != CORR) || MON_AT(x, y));
  8. }
  9. */

goto_level[edit]

  1. void
  2. goto_level(newlevel, at_stairs, falling, portal)
  3. d_level *newlevel;
  4. boolean at_stairs, falling, portal;
  5. {
  6. 	int fd, l_idx;
  7. 	xchar new_ledger;
  8. 	boolean cant_go_back,
  9. 		up = (depth(newlevel) < depth(&u.uz)),
  10. 		newdungeon = (u.uz.dnum != newlevel->dnum),
  11. 		was_in_W_tower = In_W_tower(u.ux, u.uy, &u.uz),
  12. 		familiar = FALSE;
  13. 	boolean new = FALSE;	/* made a new level? */
  14. 	struct monst *mtmp;
  15. 	char whynot[BUFSZ];
  16.  
  17. 	if (dunlev(newlevel) > dunlevs_in_dungeon(newlevel))
  18. 		newlevel->dlevel = dunlevs_in_dungeon(newlevel);
  19. 	if (newdungeon && In_endgame(newlevel)) { /* 1st Endgame Level !!! */
  20. 		if (u.uhave.amulet)
  21. 		    assign_level(newlevel, &earth_level);
  22. 		else return;
  23. 	}
  24. 	new_ledger = ledger_no(newlevel);
  25. 	if (new_ledger <= 0)
  26. 		done(ESCAPED);	/* in fact < 0 is impossible */
  27.  
  28. 	/* If you have the amulet and are trying to get out of Gehennom, going
  29. 	 * up a set of stairs sometimes does some very strange things!
  30. 	 * Biased against law and towards chaos, but not nearly as strongly
  31. 	 * as it used to be (prior to 3.2.0).
  32. 	 * Odds:	    old				    new
  33. 	 *	"up"    L      N      C		"up"    L      N      C
  34. 	 *	 +1   75.0   75.0   75.0	 +1   75.0   75.0   75.0
  35. 	 *	  0    0.0   12.5   25.0	  0    6.25   8.33  12.5
  36. 	 *	 -1    8.33   4.17   0.0	 -1    6.25   8.33  12.5
  37. 	 *	 -2    8.33   4.17   0.0	 -2    6.25   8.33   0.0
  38. 	 *	 -3    8.33   4.17   0.0	 -3    6.25   0.0    0.0
  39. 	 */
  40. 	if (Inhell && up && u.uhave.amulet && !newdungeon && !portal &&
  41. 				(dunlev(&u.uz) < dunlevs_in_dungeon(&u.uz)-3)) {
  42. 		if (!rn2(4)) {
  43. 		    int odds = 3 + (int)u.ualign.type,		/* 2..4 */
  44. 			diff = odds <= 1 ? 0 : rn2(odds);	/* paranoia */
  45.  
  46. 		    if (diff != 0) {
  47. 			assign_rnd_level(newlevel, &u.uz, diff);
  48. 			/* if inside the tower, stay inside */
  49. 			if (was_in_W_tower &&
  50. 			    !On_W_tower_level(newlevel)) diff = 0;
  51. 		    }
  52. 		    if (diff == 0)
  53. 			assign_level(newlevel, &u.uz);
  54.  
  55. 		    new_ledger = ledger_no(newlevel);
  56.  
  57. 		    pline("A mysterious force momentarily surrounds you...");
  58. 		    if (on_level(newlevel, &u.uz)) {
  59. 			(void) safe_teleds(FALSE);
  60. 			(void) next_to_u();
  61. 			return;
  62. 		    } else
  63. 			at_stairs = at_ladder = FALSE;
  64. 		}
  65. 	}
  66.  
  67. 	/* Prevent the player from going past the first quest level unless
  68. 	 * (s)he has been given the go-ahead by the leader.
  69. 	 */
  70. 	if (on_level(&u.uz, &qstart_level) && !newdungeon && !ok_to_quest()) {
  71. 		pline("A mysterious force prevents you from descending.");
  72. 		return;
  73. 	}
  74.  
  75. 	if (on_level(newlevel, &u.uz)) return;		/* this can happen */
  76.  
  77. 	fd = currentlevel_rewrite();
  78. 	if (fd < 0) return;
  79.  
  80. 	if (falling) /* assuming this is only trap door or hole */
  81. 	    impact_drop((struct obj *)0, u.ux, u.uy, newlevel->dlevel);
  82.  
  83. 	check_special_room(TRUE);		/* probably was a trap door */
  84. 	if (Punished) unplacebc();
  85. 	u.utrap = 0;				/* needed in level_tele */
  86. 	fill_pit(u.ux, u.uy);
  87. 	u.ustuck = 0;				/* idem */
  88. 	u.uinwater = 0;
  89. 	u.uundetected = 0;	/* not hidden, even if means are available */
  90. 	keepdogs(FALSE);
  91. 	if (u.uswallow)				/* idem */
  92. 		u.uswldtim = u.uswallow = 0;
  93. 	/*
  94. 	 *  We no longer see anything on the level.  Make sure that this
  95. 	 *  follows u.uswallow set to null since uswallow overrides all
  96. 	 *  normal vision.
  97. 	 */
  98. 	vision_recalc(2);
  99.  
  100. 	/*
  101. 	 * Save the level we're leaving.  If we're entering the endgame,
  102. 	 * we can get rid of all existing levels because they cannot be
  103. 	 * reached any more.  We still need to use savelev()'s cleanup
  104. 	 * for the level being left, to recover dynamic memory in use and
  105. 	 * to avoid dangling timers and light sources.
  106. 	 */
  107. 	cant_go_back = (newdungeon && In_endgame(newlevel));
  108. 	if (!cant_go_back) {
  109. 	    update_mlstmv();	/* current monsters are becoming inactive */
  110. 	    bufon(fd);		/* use buffered output */
  111. 	}
  112. 	savelev(fd, ledger_no(&u.uz),
  113. 		cant_go_back ? FREE_SAVE : (WRITE_SAVE | FREE_SAVE));
  114. 	bclose(fd);
  115. 	if (cant_go_back) {
  116. 	    /* discard unreachable levels; keep #0 */
  117. 	    for (l_idx = maxledgerno(); l_idx > 0; --l_idx)
  118. 		delete_levelfile(l_idx);
  119. 	}
  120.  
  121. #ifdef REINCARNATION
  122. 	if (Is_rogue_level(newlevel) || Is_rogue_level(&u.uz))
  123. 		assign_rogue_graphics(Is_rogue_level(newlevel));
  124. #endif
  125. #ifdef USE_TILES
  126. 	substitute_tiles(newlevel);
  127. #endif
  128. 	assign_level(&u.uz0, &u.uz);
  129. 	assign_level(&u.uz, newlevel);
  130. 	assign_level(&u.utolev, newlevel);
  131. 	u.utotype = 0;
  132. 	if (dunlev_reached(&u.uz) < dunlev(&u.uz))
  133. 		dunlev_reached(&u.uz) = dunlev(&u.uz);
  134. 	reset_rndmonst(NON_PM);   /* u.uz change affects monster generation */
  135.  
  136. 	/* set default level change destination areas */
  137. 	/* the special level code may override these */
  138. 	(void) memset((genericptr_t) &updest, 0, sizeof updest);
  139. 	(void) memset((genericptr_t) &dndest, 0, sizeof dndest);
  140.  
  141. 	if (!(level_info[new_ledger].flags & LFILE_EXISTS)) {
  142. 		/* entering this level for first time; make it now */
  143. 		if (level_info[new_ledger].flags & (FORGOTTEN|VISITED)) {
  144. 		    impossible("goto_level: returning to discarded level?");
  145. 		    level_info[new_ledger].flags &= ~(FORGOTTEN|VISITED);
  146. 		}
  147. 		mklev();
  148. 		new = TRUE;	/* made the level */
  149. 	} else {
  150. 		/* returning to previously visited level; reload it */
  151. 		fd = open_levelfile(new_ledger, whynot);
  152. 		if (fd < 0) {
  153. 			pline("%s", whynot);
  154. 			pline("Probably someone removed it.");
  155. 			killer = whynot;
  156. 			done(TRICKED);
  157. 			/* we'll reach here if running in wizard mode */
  158. 			error("Cannot continue this game.");
  159. 		}
  160. 		minit();	/* ZEROCOMP */
  161. 		getlev(fd, hackpid, new_ledger, FALSE);
  162. 		(void) close(fd);
  163. 	}
  164. 	/* do this prior to level-change pline messages */
  165. 	vision_reset();		/* clear old level's line-of-sight */
  166. 	vision_full_recalc = 0;	/* don't let that reenable vision yet */
  167. 	flush_screen(-1);	/* ensure all map flushes are postponed */
  168.  
  169. 	if (portal && !In_endgame(&u.uz)) {
  170. 	    /* find the portal on the new level */
  171. 	    register struct trap *ttrap;
  172.  
  173. 	    for (ttrap = ftrap; ttrap; ttrap = ttrap->ntrap)
  174. 		if (ttrap->ttyp == MAGIC_PORTAL) break;
  175.  
  176. 	    if (!ttrap) panic("goto_level: no corresponding portal!");
  177. 	    seetrap(ttrap);
  178. 	    u_on_newpos(ttrap->tx, ttrap->ty);
  179. 	} else if (at_stairs && !In_endgame(&u.uz)) {
  180. 	    if (up) {
  181. 		if (at_ladder) {
  182. 		    u_on_newpos(xdnladder, ydnladder);
  183. 		} else {
  184. 		    if (newdungeon) {
  185. 			if (Is_stronghold(&u.uz)) {
  186. 			    register xchar x, y;
  187.  
  188. 			    do {
  189. 				x = (COLNO - 2 - rnd(5));
  190. 				y = rn1(ROWNO - 4, 3);
  191. 			    } while(occupied(x, y) ||
  192. 				    IS_WALL(levl[x][y].typ));
  193. 			    u_on_newpos(x, y);
  194. 			} else u_on_sstairs();
  195. 		    } else u_on_dnstairs();
  196. 		}
  197. 		/* Remove bug which crashes with levitation/punishment  KAA */
  198. 		if (Punished && !Levitation) {
  199. 			pline("With great effort you climb the %s.",
  200. 				at_ladder ? "ladder" : "stairs");
  201. 		} else if (at_ladder)
  202. 		    You("climb up the ladder.");
  203. 	    } else {	/* down */
  204. 		if (at_ladder) {
  205. 		    u_on_newpos(xupladder, yupladder);
  206. 		} else {
  207. 		    if (newdungeon) u_on_sstairs();
  208. 		    else u_on_upstairs();
  209. 		}
  210. 		if (u.dz && Flying)
  211. 		    You("fly down along the %s.",
  212. 			at_ladder ? "ladder" : "stairs");
  213. 		else if (u.dz &&
  214. 		    (near_capacity() > UNENCUMBERED || Punished || Fumbling)) {
  215. 		    You("fall down the %s.", at_ladder ? "ladder" : "stairs");
  216. 		    if (Punished) {
  217. 			drag_down();
  218. 			if (carried(uball)) {
  219. 			    if (uwep == uball)
  220. 				setuwep((struct obj *)0);
  221. 			    if (uswapwep == uball)
  222. 				setuswapwep((struct obj *)0);
  223. 			    if (uquiver == uball)
  224. 				setuqwep((struct obj *)0);
  225. 			    freeinv(uball);
  226. 			}
  227. 		    }
  228. #ifdef STEED
  229. 		    /* falling off steed has its own losehp() call */
  230. 		    if (u.usteed)
  231. 			dismount_steed(DISMOUNT_FELL);
  232. 		    else
  233. #endif
  234. 			losehp(rnd(3), "falling downstairs", KILLED_BY);
  235. 		    selftouch("Falling, you");
  236. 		} else if (u.dz && at_ladder)
  237. 		    You("climb down the ladder.");
  238. 	    }
  239. 	} else {	/* trap door or level_tele or In_endgame */
  240. 	    if (was_in_W_tower && On_W_tower_level(&u.uz))
  241. 		/* Stay inside the Wizard's tower when feasible.	*/
  242. 		/* Note: up vs down doesn't really matter in this case. */
  243. 		place_lregion(dndest.nlx, dndest.nly,
  244. 				dndest.nhx, dndest.nhy,
  245. 				0,0, 0,0, LR_DOWNTELE, (d_level *) 0);
  246. 	    else if (up)
  247. 		place_lregion(updest.lx, updest.ly,
  248. 				updest.hx, updest.hy,
  249. 				updest.nlx, updest.nly,
  250. 				updest.nhx, updest.nhy,
  251. 				LR_UPTELE, (d_level *) 0);
  252. 	    else
  253. 		place_lregion(dndest.lx, dndest.ly,
  254. 				dndest.hx, dndest.hy,
  255. 				dndest.nlx, dndest.nly,
  256. 				dndest.nhx, dndest.nhy,
  257. 				LR_DOWNTELE, (d_level *) 0);
  258. 	    if (falling) {
  259. 		if (Punished) ballfall();
  260. 		selftouch("Falling, you");
  261. 	    }
  262. 	}
  263.  
  264. 	if (Punished) placebc();
  265. 	obj_delivery();		/* before killing geno'd monsters' eggs */
  266. 	losedogs();
  267. 	kill_genocided_monsters();  /* for those wiped out while in limbo */
  268. 	/*
  269. 	 * Expire all timers that have gone off while away.  Must be
  270. 	 * after migrating monsters and objects are delivered
  271. 	 * (losedogs and obj_delivery).
  272. 	 */
  273. 	run_timers();
  274.  
  275. 	initrack();
  276.  
  277. 	if ((mtmp = m_at(u.ux, u.uy)) != 0
  278. #ifdef STEED
  279. 		&& mtmp != u.usteed
  280. #endif
  281. 		) {
  282. 	    /* There's a monster at your target destination; it might be one
  283. 	       which accompanied you--see mon_arrive(dogmove.c)--or perhaps
  284. 	       it was already here.  Randomly move you to an adjacent spot
  285. 	       or else the monster to any nearby location.  Prior to 3.3.0
  286. 	       the latter was done unconditionally. */
  287. 	    coord cc;
  288.  
  289. 	    if (!rn2(2) &&
  290. 		    enexto(&cc, u.ux, u.uy, youmonst.data) &&
  291. 		    distu(cc.x, cc.y) <= 2)
  292. 		u_on_newpos(cc.x, cc.y);	/*[maybe give message here?]*/
  293. 	    else
  294. 		mnexto(mtmp);
  295.  
  296. 	    if ((mtmp = m_at(u.ux, u.uy)) != 0) {
  297. 		impossible("mnexto failed (do.c)?");
  298. 		(void) rloc(mtmp, FALSE);
  299. 	    }
  300. 	}
  301.  
  302. 	/* initial movement of bubbles just before vision_recalc */
  303. 	if (Is_waterlevel(&u.uz))
  304. 		movebubbles();
  305.  
  306. 	if (level_info[new_ledger].flags & FORGOTTEN) {
  307. 	    forget_map(ALL_MAP);	/* forget the map */
  308. 	    forget_traps();		/* forget all traps too */
  309. 	    familiar = TRUE;
  310. 	    level_info[new_ledger].flags &= ~FORGOTTEN;
  311. 	}
  312.  
  313. 	/* Reset the screen. */
  314. 	vision_reset();		/* reset the blockages */
  315. 	docrt();		/* does a full vision recalc */
  316. 	flush_screen(-1);
  317.  
  318. 	/*
  319. 	 *  Move all plines beyond the screen reset.
  320. 	 */
  321.  
  322. 	/* give room entrance message, if any */
  323. 	check_special_room(FALSE);
  324.  
  325. 	/* Check whether we just entered Gehennom. */
  326. 	if (!In_hell(&u.uz0) && Inhell) {
  327. 	    if (Is_valley(&u.uz)) {
  328. 		You("arrive at the Valley of the Dead...");
  329. 		pline_The("odor of burnt flesh and decay pervades the air.");
  330. #ifdef MICRO
  331. 		display_nhwindow(WIN_MESSAGE, FALSE);
  332. #endif
  333. 		You_hear("groans and moans everywhere.");
  334. 	    } else pline("It is hot here.  You smell smoke...");
  335. 	}
  336.  
  337. 	if (familiar) {
  338. 	    static const char * const fam_msgs[4] = {
  339. 		"You have a sense of deja vu.",
  340. 		"You feel like you've been here before.",
  341. 		"This place %s familiar...",
  342. 		0	/* no message */
  343. 	    };
  344. 	    static const char * const halu_fam_msgs[4] = {
  345. 		"Whoa!  Everything %s different.",
  346. 		"You are surrounded by twisty little passages, all alike.",
  347. 		"Gee, this %s like uncle Conan's place...",
  348. 		0	/* no message */
  349. 	    };
  350. 	    const char *mesg;
  351. 	    char buf[BUFSZ];
  352. 	    int which = rn2(4);
  353.  
  354. 	    if (Hallucination)
  355. 		mesg = halu_fam_msgs[which];
  356. 	    else
  357. 		mesg = fam_msgs[which];
  358. 	    if (mesg && index(mesg, '%')) {
  359. 		Sprintf(buf, mesg, !Blind ? "looks" : "seems");
  360. 		mesg = buf;
  361. 	    }
  362. 	    if (mesg) pline(mesg);
  363. 	}
  364.  
  365. #ifdef REINCARNATION
  366. 	if (new && Is_rogue_level(&u.uz))
  367. 	    You("enter what seems to be an older, more primitive world.");
  368. #endif
  369. 	/* Final confrontation */
  370. 	if (In_endgame(&u.uz) && newdungeon && u.uhave.amulet)
  371. 		resurrect();
  372. 	if (newdungeon && In_V_tower(&u.uz) && In_hell(&u.uz0))
  373. 		pline_The("heat and smoke are gone.");
  374.  
  375. 	/* the message from your quest leader */
  376. 	if (!In_quest(&u.uz0) && at_dgn_entrance("The Quest") &&
  377. 		!(u.uevent.qexpelled || u.uevent.qcompleted || quest_status.leader_is_dead)) {
  378.  
  379. 		if (u.uevent.qcalled) {
  380. 			com_pager(Role_if(PM_ROGUE) ? 4 : 3);
  381. 		} else {
  382. 			com_pager(2);
  383. 			u.uevent.qcalled = TRUE;
  384. 		}
  385. 	}
  386.  
  387. 	/* once Croesus is dead, his alarm doesn't work any more */
  388. 	if (Is_knox(&u.uz) && (new || !mvitals[PM_CROESUS].died)) {
  389. 		You("penetrated a high security area!");
  390. 		pline("An alarm sounds!");
  391. 		for(mtmp = fmon; mtmp; mtmp = mtmp->nmon)
  392. 		    if (!DEADMONSTER(mtmp) && mtmp->msleeping) mtmp->msleeping = 0;
  393. 	}
  394.  
  395. 	if (on_level(&u.uz, &astral_level))
  396. 	    final_level();
  397. 	else
  398. 	    onquest();
  399. 	assign_level(&u.uz0, &u.uz); /* reset u.uz0 */
  400.  
  401. #ifdef INSURANCE
  402. 	save_currentstate();
  403. #endif
  404.  
  405. 	/* assume this will always return TRUE when changing level */
  406. 	(void) in_out_region(u.ux, u.uy);
  407. 	(void) pickup(1);
  408. }

final_level[edit]

  1. STATIC_OVL void
  2. final_level()
  3. {
  4. 	struct monst *mtmp;
  5. 	struct obj *otmp;
  6. 	coord mm;
  7. 	int i;
  8.  
  9. 	/* reset monster hostility relative to player */
  10. 	for (mtmp = fmon; mtmp; mtmp = mtmp->nmon)
  11. 	    if (!DEADMONSTER(mtmp)) reset_hostility(mtmp);
  12.  
  13. 	/* create some player-monsters */
  14. 	create_mplayers(rn1(4, 3), TRUE);
  15.  
  16. 	/* create a guardian angel next to player, if worthy */
  17. 	if (Conflict) {
  18. 	    pline(
  19. 	     "A voice booms: \"Thy desire for conflict shall be fulfilled!\"");
  20. 	    for (i = rnd(4); i > 0; --i) {
  21. 		mm.x = u.ux;
  22. 		mm.y = u.uy;
  23. 		if (enexto(&mm, mm.x, mm.y, &mons[PM_ANGEL]))
  24. 		    (void) mk_roamer(&mons[PM_ANGEL], u.ualign.type,
  25. 				     mm.x, mm.y, FALSE);
  26. 	    }
  27.  
  28. 	} else if (u.ualign.record > 8) {	/* fervent */
  29. 	    pline("A voice whispers: \"Thou hast been worthy of me!\"");
  30. 	    mm.x = u.ux;
  31. 	    mm.y = u.uy;
  32. 	    if (enexto(&mm, mm.x, mm.y, &mons[PM_ANGEL])) {
  33. 		if ((mtmp = mk_roamer(&mons[PM_ANGEL], u.ualign.type,
  34. 				      mm.x, mm.y, TRUE)) != 0) {
  35. 		    if (!Blind)
  36. 			pline("An angel appears near you.");
  37. 		    else
  38. 			You_feel("the presence of a friendly angel near you.");
  39. 		    /* guardian angel -- the one case mtame doesn't
  40. 		     * imply an edog structure, so we don't want to
  41. 		     * call tamedog().
  42. 		     */
  43. 		    mtmp->mtame = 10;
  44. 		    /* make him strong enough vs. endgame foes */
  45. 		    mtmp->m_lev = rn1(8,15);
  46. 		    mtmp->mhp = mtmp->mhpmax =
  47. 					d((int)mtmp->m_lev,10) + 30 + rnd(30);
  48. 		    if ((otmp = select_hwep(mtmp)) == 0) {
  49. 			otmp = mksobj(SILVER_SABER, FALSE, FALSE);
  50. 			if (mpickobj(mtmp, otmp))
  51. 			    panic("merged weapon?");
  52. 		    }
  53. 		    bless(otmp);
  54. 		    if (otmp->spe < 4) otmp->spe += rnd(4);
  55. 		    if ((otmp = which_armor(mtmp, W_ARMS)) == 0 ||
  56. 			    otmp->otyp != SHIELD_OF_REFLECTION) {
  57. 			(void) mongets(mtmp, AMULET_OF_REFLECTION);
  58. 			m_dowear(mtmp, TRUE);
  59. 		    }
  60. 		}
  61. 	    }
  62. 	}
  63. }

schedule_goto[edit]

  1. static char *dfr_pre_msg = 0,	/* pline() before level change */
  2. 	    *dfr_post_msg = 0;	/* pline() after level change */
  3.  
  4. /* change levels at the end of this turn, after monsters finish moving */
  5. void
  6. schedule_goto(tolev, at_stairs, falling, portal_flag, pre_msg, post_msg)
  7. d_level *tolev;
  8. boolean at_stairs, falling;
  9. int portal_flag;
  10. const char *pre_msg, *post_msg;
  11. {
  12. 	int typmask = 0100;		/* non-zero triggers `deferred_goto' */
  13.  
  14. 	/* destination flags (`goto_level' args) */
  15. 	if (at_stairs)	 typmask |= 1;
  16. 	if (falling)	 typmask |= 2;
  17. 	if (portal_flag) typmask |= 4;
  18. 	if (portal_flag < 0) typmask |= 0200;	/* flag for portal removal */
  19. 	u.utotype = typmask;
  20. 	/* destination level */
  21. 	assign_level(&u.utolev, tolev);
  22.  
  23. 	if (pre_msg)
  24. 	    dfr_pre_msg = strcpy((char *)alloc(strlen(pre_msg) + 1), pre_msg);
  25. 	if (post_msg)
  26. 	    dfr_post_msg = strcpy((char *)alloc(strlen(post_msg)+1), post_msg);
  27. }

deferred_goto[edit]

  1. /* handle something like portal ejection */
  2. void
  3. deferred_goto()
  4. {
  5. 	if (!on_level(&u.uz, &u.utolev)) {
  6. 	    d_level dest;
  7. 	    int typmask = u.utotype; /* save it; goto_level zeroes u.utotype */
  8.  
  9. 	    assign_level(&dest, &u.utolev);
  10. 	    if (dfr_pre_msg) pline(dfr_pre_msg);
  11. 	    goto_level(&dest, !!(typmask&1), !!(typmask&2), !!(typmask&4));
  12. 	    if (typmask & 0200) {	/* remove portal */
  13. 		struct trap *t = t_at(u.ux, u.uy);
  14.  
  15. 		if (t) {
  16. 		    deltrap(t);
  17. 		    newsym(u.ux, u.uy);
  18. 		}
  19. 	    }
  20. 	    if (dfr_post_msg) pline(dfr_post_msg);
  21. 	}
  22. 	u.utotype = 0;		/* our caller keys off of this */
  23. 	if (dfr_pre_msg)
  24. 	    free((genericptr_t)dfr_pre_msg),  dfr_pre_msg = 0;
  25. 	if (dfr_post_msg)
  26. 	    free((genericptr_t)dfr_post_msg),  dfr_post_msg = 0;
  27. }
  28.  
  29. #endif /* OVL2 */

revive_corpse[edit]

  1. #ifdef OVL3
  2.  
  3. /*
  4. * Return TRUE if we created a monster for the corpse.  If successful, the
  5. * corpse is gone.
  6. */
  7. boolean
  8. revive_corpse(corpse)
  9. struct obj *corpse;
  10. {
  11. struct monst *mtmp, *mcarry;
  12. boolean is_uwep, chewed;
  13. xchar where;
  14. char *cname, cname_buf[BUFSZ];
  15. struct obj *container = (struct obj *)0;
  16. int container_where = 0;
  17.  
  18. where = corpse->where;
  19. is_uwep = corpse == uwep;
  20. cname = eos(strcpy(cname_buf, "bite-covered "));
  21. Strcpy(cname, corpse_xname(corpse, TRUE));
  22. mcarry = (where == OBJ_MINVENT) ? corpse->ocarry : 0;
  23.  
  24. if (where == OBJ_CONTAINED) {
  25. 	struct monst *mtmp2 = (struct monst *)0;
  26. 	container = corpse->ocontainer;
  27. 	mtmp2 = get_container_location(container, &container_where, (int *)0);
  28. 	/* container_where is the outermost container's location even if nested */
  29. 	if (container_where == OBJ_MINVENT && mtmp2) mcarry = mtmp2;
  30. }
  31. mtmp = revive(corpse);	/* corpse is gone if successful */
  32.  
  33. if (mtmp) {
  34. 	chewed = (mtmp->mhp < mtmp->mhpmax);
  35. 	if (chewed) cname = cname_buf;	/* include "bite-covered" prefix */
  36. 	switch (where) {
  37. 	    case OBJ_INVENT:
  38. 		if (is_uwep)
  39. 		    pline_The("%s writhes out of your grasp!", cname);
  40. 		else
  41. 		    You_feel("squirming in your backpack!");
  42. 		break;
  43.  
  44. 	    case OBJ_FLOOR:
  45. 		if (cansee(mtmp->mx, mtmp->my))
  46. 		    pline("%s rises from the dead!", chewed ?
  47. 			  Adjmonnam(mtmp, "bite-covered") : Monnam(mtmp));
  48. 		break;
  49.  
  50. 	    case OBJ_MINVENT:		/* probably a nymph's */
  51. 		if (cansee(mtmp->mx, mtmp->my)) {
  52. 		    if (canseemon(mcarry))
  53. 			pline("Startled, %s drops %s as it revives!",
  54. 			      mon_nam(mcarry), an(cname));
  55. 		    else
  56. 			pline("%s suddenly appears!", chewed ?
  57. 			      Adjmonnam(mtmp, "bite-covered") : Monnam(mtmp));
  58. 		}
  59. 		break;
  60. 	   case OBJ_CONTAINED:
  61. 	   	if (container_where == OBJ_MINVENT && cansee(mtmp->mx, mtmp->my) &&
  62. 		    mcarry && canseemon(mcarry) && container) {
  63. 		        char sackname[BUFSZ];
  64. 		        Sprintf(sackname, "%s %s", s_suffix(mon_nam(mcarry)),
  65. 				xname(container)); 
  66. 	   		pline("%s writhes out of %s!", Amonnam(mtmp), sackname);
  67. 	   	} else if (container_where == OBJ_INVENT && container) {
  68. 		        char sackname[BUFSZ];
  69. 		        Strcpy(sackname, an(xname(container)));
  70. 	   		pline("%s %s out of %s in your pack!",
  71. 	   			Blind ? Something : Amonnam(mtmp),
  72. 				locomotion(mtmp->data,"writhes"),
  73. 	   			sackname);
  74. 	   	} else if (container_where == OBJ_FLOOR && container &&
  75. 		            cansee(mtmp->mx, mtmp->my)) {
  76. 		        char sackname[BUFSZ];
  77. 		        Strcpy(sackname, an(xname(container)));
  78. 			pline("%s escapes from %s!", Amonnam(mtmp), sackname);
  79. 		}
  80. 		break;
  81. 	    default:
  82. 		/* we should be able to handle the other cases... */
  83. 		impossible("revive_corpse: lost corpse @ %d", where);
  84. 		break;
  85. 	}
  86. 	return TRUE;
  87. }
  88. return FALSE;
  89. }

revive_mon[edit]

  1. /* Revive the corpse via a timeout. */
  2. /*ARGSUSED*/
  3. void
  4. revive_mon(arg, timeout)
  5. genericptr_t arg;
  6. long timeout;
  7. {
  8. struct obj *body = (struct obj *) arg;
  9.  
  10. /* if we succeed, the corpse is gone, otherwise, rot it away */
  11. if (!revive_corpse(body)) {
  12. 	if (is_rider(&mons[body->corpsenm]))
  13. 	    You_feel("less hassled.");
  14. 	(void) start_timer(250L - (monstermoves-body->age),
  15. 					TIMER_OBJECT, ROT_CORPSE, arg);
  16. }
  17. }

donull[edit]

  1. int
  2. donull()
  3. {
  4. 	return(1);	/* Do nothing, but let other things happen */
  5. }
  6.  
  7. #endif /* OVL3 */

wipeoff[edit]

  1. #ifdef OVLB
  2.  
  3. STATIC_PTR int
  4. wipeoff()
  5. {
  6. 	if(u.ucreamed < 4)	u.ucreamed = 0;
  7. 	else			u.ucreamed -= 4;
  8. 	if (Blinded < 4)	Blinded = 0;
  9. 	else			Blinded -= 4;
  10. 	if (!Blinded) {
  11. 		pline("You've got the glop off.");
  12. 		u.ucreamed = 0;
  13. 		Blinded = 1;
  14. 		make_blinded(0L,TRUE);
  15. 		return(0);
  16. 	} else if (!u.ucreamed) {
  17. 		Your("%s feels clean now.", body_part(FACE));
  18. 		return(0);
  19. 	}
  20. 	return(1);		/* still busy */
  21. }

dowipe[edit]

  1. int
  2. dowipe()
  3. {
  4. 	if(u.ucreamed)  {
  5. 		static NEARDATA char buf[39];
  6.  
  7. 		Sprintf(buf, "wiping off your %s", body_part(FACE));
  8. 		set_occupation(wipeoff, buf, 0);
  9. 		/* Not totally correct; what if they change back after now
  10. 		 * but before they're finished wiping?
  11. 		 */
  12. 		return(1);
  13. 	}
  14. 	Your("%s is already clean.", body_part(FACE));
  15. 	return(1);
  16. }

set_wounded_legs[edit]

  1. void
  2. set_wounded_legs(side, timex)
  3. register long side;
  4. register int timex;
  5. {
  6. 	/* KMH -- STEED
  7. 	 * If you are riding, your steed gets the wounded legs instead.
  8. 	 * You still call this function, but don't lose hp.
  9. 	 * Caller is also responsible for adjusting messages.
  10. 	 */
  11.  
  12. 	if(!Wounded_legs) {
  13. 		ATEMP(A_DEX)--;
  14. 		flags.botl = 1;
  15. 	}
  16.  
  17. 	if(!Wounded_legs || (HWounded_legs & TIMEOUT))
  18. 		HWounded_legs = timex;
  19. 	EWounded_legs = side;
  20. 	(void)encumber_msg();
  21. }

heal_legs[edit]

  1. void
  2. heal_legs()
  3. {
  4. 	if(Wounded_legs) {
  5. 		if (ATEMP(A_DEX) < 0) {
  6. 			ATEMP(A_DEX)++;
  7. 			flags.botl = 1;
  8. 		}
  9.  
  10. #ifdef STEED
  11. 		if (!u.usteed)
  12. #endif
  13. 		{
  14. 			/* KMH, intrinsics patch */
  15. 			if((EWounded_legs & BOTH_SIDES) == BOTH_SIDES) {
  16. 			Your("%s feel somewhat better.",
  17. 				makeplural(body_part(LEG)));
  18. 		} else {
  19. 			Your("%s feels somewhat better.",
  20. 				body_part(LEG));
  21. 		}
  22. 		}
  23. 		HWounded_legs = EWounded_legs = 0;
  24. 	}
  25. 	(void)encumber_msg();
  26. }
  27.  
  28. #endif /* OVLB */
  29.  
  30. /*do.c*/