Source:NetHack 3.4.3/src/trap.c

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

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

Top of file[edit]

  1. /*	SCCS Id: @(#)trap.c	3.4	2003/10/20	*/
  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. extern const char * const destroy_strings[];	/* from zap.c */
  4.  
  5. STATIC_DCL void FDECL(dofiretrap, (struct obj *));
  6. STATIC_DCL void NDECL(domagictrap);
  7. STATIC_DCL boolean FDECL(emergency_disrobe,(boolean *));
  8. STATIC_DCL int FDECL(untrap_prob, (struct trap *ttmp));
  9. STATIC_DCL void FDECL(cnv_trap_obj, (int, int, struct trap *));
  10. STATIC_DCL void FDECL(move_into_trap, (struct trap *));
  11. STATIC_DCL int FDECL(try_disarm, (struct trap *,BOOLEAN_P));
  12. STATIC_DCL void FDECL(reward_untrap, (struct trap *, struct monst *));
  13. STATIC_DCL int FDECL(disarm_holdingtrap, (struct trap *));
  14. STATIC_DCL int FDECL(disarm_landmine, (struct trap *));
  15. STATIC_DCL int FDECL(disarm_squeaky_board, (struct trap *));
  16. STATIC_DCL int FDECL(disarm_shooting_trap, (struct trap *, int));
  17. STATIC_DCL int FDECL(try_lift, (struct monst *, struct trap *, int, BOOLEAN_P));
  18. STATIC_DCL int FDECL(help_monster_out, (struct monst *, struct trap *));
  19. STATIC_DCL boolean FDECL(thitm, (int,struct monst *,struct obj *,int,BOOLEAN_P));
  20. STATIC_DCL int FDECL(mkroll_launch,
  21. 			(struct trap *,XCHAR_P,XCHAR_P,SHORT_P,long));
  22. STATIC_DCL boolean FDECL(isclearpath,(coord *, int, SCHAR_P, SCHAR_P));
  23. #ifdef STEED
  24. STATIC_OVL int FDECL(steedintrap, (struct trap *, struct obj *));
  25. STATIC_OVL boolean FDECL(keep_saddle_with_steedcorpse,
  26. 			(unsigned, struct obj *, struct obj *));
  27. #endif
  28.  
  29. #ifndef OVLB
  30. STATIC_VAR const char *a_your[2];
  31. STATIC_VAR const char *A_Your[2];
  32. STATIC_VAR const char tower_of_flame[];
  33. STATIC_VAR const char *A_gush_of_water_hits;
  34. STATIC_VAR const char * const blindgas[6];
  35.  
  36. #else
  37.  
  38. STATIC_VAR const char * const a_your[2] = { "a", "your" };
  39. STATIC_VAR const char * const A_Your[2] = { "A", "Your" };
  40. STATIC_VAR const char tower_of_flame[] = "tower of flame";
  41. STATIC_VAR const char * const A_gush_of_water_hits = "A gush of water hits";
  42. STATIC_VAR const char * const blindgas[6] = 
  43. 	{"humid", "odorless", "pungent", "chilling", "acrid", "biting"};
  44.  
  45. #endif /* OVLB */
  46.  
  47. #ifdef OVLB

burnarmor[edit]

  1. /* called when you're hit by fire (dofiretrap,buzz,zapyourself,explode) */
  2. boolean			/* returns TRUE if hit on torso */
  3. burnarmor(victim)
  4. struct monst *victim;
  5. {
  6. struct obj *item;
  7. char buf[BUFSZ];
  8. int mat_idx;
  9.  
  10. if (!victim) return 0;
  11. #define burn_dmg(obj,descr) rust_dmg(obj, descr, 0, FALSE, victim)
  12. while (1) {
  13. 	switch (rn2(5)) {
  14. 	case 0:
  15. 	    item = (victim == &youmonst) ? uarmh : which_armor(victim, W_ARMH);
  16. 	    if (item) {
  17. 		mat_idx = objects[item->otyp].oc_material;
  18. 	    	Sprintf(buf,"%s helmet", materialnm[mat_idx] );
  19. 	    }
  20. 	    if (!burn_dmg(item, item ? buf : "helmet")) continue;
  21. 	    break;
  22. 	case 1:
  23. 	    item = (victim == &youmonst) ? uarmc : which_armor(victim, W_ARMC);
  24. 	    if (item) {
  25. 		(void) burn_dmg(item, cloak_simple_name(item));
  26. 		return TRUE;
  27. 	    }
  28. 	    item = (victim == &youmonst) ? uarm : which_armor(victim, W_ARM);
  29. 	    if (item) {
  30. 		(void) burn_dmg(item, xname(item));
  31. 		return TRUE;
  32. 	    }
  33. #ifdef TOURIST
  34. 	    item = (victim == &youmonst) ? uarmu : which_armor(victim, W_ARMU);
  35. 	    if (item)
  36. 		(void) burn_dmg(item, "shirt");
  37. #endif
  38. 	    return TRUE;
  39. 	case 2:
  40. 	    item = (victim == &youmonst) ? uarms : which_armor(victim, W_ARMS);
  41. 	    if (!burn_dmg(item, "wooden shield")) continue;
  42. 	    break;
  43. 	case 3:
  44. 	    item = (victim == &youmonst) ? uarmg : which_armor(victim, W_ARMG);
  45. 	    if (!burn_dmg(item, "gloves")) continue;
  46. 	    break;
  47. 	case 4:
  48. 	    item = (victim == &youmonst) ? uarmf : which_armor(victim, W_ARMF);
  49. 	    if (!burn_dmg(item, "boots")) continue;
  50. 	    break;
  51. 	}
  52. 	break; /* Out of while loop */
  53. }
  54. return FALSE;
  55. #undef burn_dmg
  56. }

rust_dmg[edit]

  1. /* Generic rust-armor function.  Returns TRUE if a message was printed;
  2. * "print", if set, means to print a message (and thus to return TRUE) even
  3. * if the item could not be rusted; otherwise a message is printed and TRUE is
  4. * returned only for rustable items.
  5. */
  6. boolean
  7. rust_dmg(otmp, ostr, type, print, victim)
  8. register struct obj *otmp;
  9. register const char *ostr;
  10. int type;
  11. boolean print;
  12. struct monst *victim;
  13. {
  14. 	static NEARDATA const char * const action[] = { "smoulder", "rust", "rot", "corrode" };
  15. 	static NEARDATA const char * const msg[] =  { "burnt", "rusted", "rotten", "corroded" };
  16. 	boolean vulnerable = FALSE;
  17. 	boolean grprot = FALSE;
  18. 	boolean is_primary = TRUE;
  19. 	boolean vismon = (victim != &youmonst) && canseemon(victim);
  20. 	int erosion;
  21.  
  22. 	if (!otmp) return(FALSE);
  23. 	switch(type) {
  24. 		case 0: vulnerable = is_flammable(otmp);
  25. 			break;
  26. 		case 1: vulnerable = is_rustprone(otmp);
  27. 			grprot = TRUE;
  28. 			break;
  29. 		case 2: vulnerable = is_rottable(otmp);
  30. 			is_primary = FALSE;
  31. 			break;
  32. 		case 3: vulnerable = is_corrodeable(otmp);
  33. 			grprot = TRUE;
  34. 			is_primary = FALSE;
  35. 			break;
  36. 	}
  37. 	erosion = is_primary ? otmp->oeroded : otmp->oeroded2;
  38.  
  39. 	if (!print && (!vulnerable || otmp->oerodeproof || erosion == MAX_ERODE))
  40. 		return FALSE;
  41.  
  42. 	if (!vulnerable) {
  43. 	    if (flags.verbose) {
  44. 		if (victim == &youmonst)
  45. 		    Your("%s %s not affected.", ostr, vtense(ostr, "are"));
  46. 		else if (vismon)
  47. 		    pline("%s's %s %s not affected.", Monnam(victim), ostr,
  48. 			  vtense(ostr, "are"));
  49. 	    }
  50. 	} else if (erosion < MAX_ERODE) {
  51. 	    if (grprot && otmp->greased) {
  52. 		grease_protect(otmp,ostr,victim);
  53. 	    } else if (otmp->oerodeproof || (otmp->blessed && !rnl(4))) {
  54. 		if (flags.verbose) {
  55. 		    if (victim == &youmonst)
  56. 			pline("Somehow, your %s %s not affected.",
  57. 			      ostr, vtense(ostr, "are"));
  58. 		    else if (vismon)
  59. 			pline("Somehow, %s's %s %s not affected.",
  60. 			      mon_nam(victim), ostr, vtense(ostr, "are"));
  61. 		}
  62. 	    } else {
  63. 		if (victim == &youmonst)
  64. 		    Your("%s %s%s!", ostr,
  65. 			 vtense(ostr, action[type]),
  66. 			 erosion+1 == MAX_ERODE ? " completely" :
  67. 			    erosion ? " further" : "");
  68. 		else if (vismon)
  69. 		    pline("%s's %s %s%s!", Monnam(victim), ostr,
  70. 			vtense(ostr, action[type]),
  71. 			erosion+1 == MAX_ERODE ? " completely" :
  72. 			  erosion ? " further" : "");
  73. 		if (is_primary)
  74. 		    otmp->oeroded++;
  75. 		else
  76. 		    otmp->oeroded2++;
  77. 		update_inventory();
  78. 	    }
  79. 	} else {
  80. 	    if (flags.verbose) {
  81. 		if (victim == &youmonst)
  82. 		    Your("%s %s completely %s.", ostr,
  83. 			 vtense(ostr, Blind ? "feel" : "look"),
  84. 			 msg[type]);
  85. 		else if (vismon)
  86. 		    pline("%s's %s %s completely %s.",
  87. 			  Monnam(victim), ostr,
  88. 			  vtense(ostr, "look"), msg[type]);
  89. 	    }
  90. 	}
  91. 	return(TRUE);
  92. }

grease_protect[edit]

  1. void
  2. grease_protect(otmp,ostr,victim)
  3. register struct obj *otmp;
  4. register const char *ostr;
  5. struct monst *victim;
  6. {
  7. 	static const char txt[] = "protected by the layer of grease!";
  8. 	boolean vismon = victim && (victim != &youmonst) && canseemon(victim);
  9.  
  10. 	if (ostr) {
  11. 	    if (victim == &youmonst)
  12. 		Your("%s %s %s", ostr, vtense(ostr, "are"), txt);
  13. 	    else if (vismon)
  14. 		pline("%s's %s %s %s", Monnam(victim),
  15. 		    ostr, vtense(ostr, "are"), txt);
  16. 	} else {
  17. 	    if (victim == &youmonst)
  18. 		Your("%s %s",aobjnam(otmp,"are"), txt);
  19. 	    else if (vismon)
  20. 		pline("%s's %s %s", Monnam(victim), aobjnam(otmp,"are"), txt);
  21. 	}
  22. 	if (!rn2(2)) {
  23. 	    otmp->greased = 0;
  24. 	    if (carried(otmp)) {
  25. 		pline_The("grease dissolves.");
  26. 		update_inventory();
  27. 	    }
  28. 	}
  29. }

maketrap[edit]

maketrap() takes three parameters, an x,y coordinate and a trap type macro, and creates a new trap at (x,y) and returns a pointer to it.

  1. struct trap *
  2. maketrap(x,y,typ)
  3. register int x, y, typ;
  4. {
  5. 	register struct trap *ttmp;
  6. 	register struct rm *lev;
  7. 	register boolean oldplace;
  8.  
  9. 	if ((ttmp = t_at(x,y)) != 0) {
  10. 	    if (ttmp->ttyp == MAGIC_PORTAL) return (struct trap *)0;
  11. 	    oldplace = TRUE;
  12. 	    if (u.utrap && (x == u.ux) && (y == u.uy) &&
  13. 	      ((u.utraptype == TT_BEARTRAP && typ != BEAR_TRAP) ||
  14. 	      (u.utraptype == TT_WEB && typ != WEB) ||
  15. 	      (u.utraptype == TT_PIT && typ != PIT && typ != SPIKED_PIT)))
  16. 		    u.utrap = 0;
  17. 	} else {
  18. 	    oldplace = FALSE;
  19. 	    ttmp = newtrap();
  20. 	    ttmp->tx = x;
  21. 	    ttmp->ty = y;
  22. 	    ttmp->launch.x = -1;	/* force error if used before set */
  23. 	    ttmp->launch.y = -1;
  24. 	}
  25. 	ttmp->ttyp = typ;
  26. 	switch(typ) {
  27. 	    case STATUE_TRAP:	    /* create a "living" statue */
  28. 	      { struct monst *mtmp;
  29. 		struct obj *otmp, *statue;
  30.  
  31. 		statue = mkcorpstat(STATUE, (struct monst *)0,
  32. 					&mons[rndmonnum()], x, y, FALSE);
  33. 		mtmp = makemon(&mons[statue->corpsenm], 0, 0, NO_MM_FLAGS);
  34. 		if (!mtmp) break; /* should never happen */
  35. 		while(mtmp->minvent) {
  36. 		    otmp = mtmp->minvent;
  37. 		    otmp->owornmask = 0;
  38. 		    obj_extract_self(otmp);
  39. 		    (void) add_to_container(statue, otmp);
  40. 		}
  41. 		statue->owt = weight(statue);
  42. 		mongone(mtmp);
  43. 		break;
  44. 	      }
  45. 	    case ROLLING_BOULDER_TRAP:	/* boulder will roll towards trigger */
  46. 		(void) mkroll_launch(ttmp, x, y, BOULDER, 1L);
  47. 		break;
  48. 	    case HOLE:
  49. 	    case PIT:
  50. 	    case SPIKED_PIT:
  51. 	    case TRAPDOOR:
  52. 		lev = &levl[x][y];
  53. 		if (*in_rooms(x, y, SHOPBASE) &&
  54. 			((typ == HOLE || typ == TRAPDOOR) ||
  55. 			 IS_DOOR(lev->typ) || IS_WALL(lev->typ)))
  56. 		    add_damage(x, y,		/* schedule repair */
  57. 			       ((IS_DOOR(lev->typ) || IS_WALL(lev->typ))
  58. 				&& !flags.mon_moving) ? 200L : 0L);
  59. 		lev->doormask = 0;	/* subsumes altarmask, icedpool... */
  60. 		if (IS_ROOM(lev->typ)) /* && !IS_AIR(lev->typ) */
  61. 		    lev->typ = ROOM;
  62.  
  63. 		/*
  64. 		 * some cases which can happen when digging
  65. 		 * down while phazing thru solid areas
  66. 		 */
  67. 		else if (lev->typ == STONE || lev->typ == SCORR)
  68. 		    lev->typ = CORR;
  69. 		else if (IS_WALL(lev->typ) || lev->typ == SDOOR)
  70. 		    lev->typ = level.flags.is_maze_lev ? ROOM :
  71. 			       level.flags.is_cavernous_lev ? CORR : DOOR;
  72.  
  73. 		unearth_objs(x, y);
  74. 		break;
  75. 	}
  76. 	if (ttmp->ttyp == HOLE) ttmp->tseen = 1;  /* You can't hide a hole */
  77. 	else ttmp->tseen = 0;
  78. 	ttmp->once = 0;
  79. 	ttmp->madeby_u = 0;
  80. 	ttmp->dst.dnum = -1;
  81. 	ttmp->dst.dlevel = -1;
  82. 	if (!oldplace) {
  83. 	    ttmp->ntrap = ftrap;
  84. 	    ftrap = ttmp;
  85. 	}
  86. 	return(ttmp);
  87. }

fall_through[edit]

  1. void
  2. fall_through(td)
  3. boolean td;	/* td == TRUE : trap door or hole */
  4. {
  5. 	d_level dtmp;
  6. 	char msgbuf[BUFSZ];
  7. 	const char *dont_fall = 0;
  8. 	register int newlevel = dunlev(&u.uz);
  9.  
  10. 	/* KMH -- You can't escape the Sokoban level traps */
  11. 	if(Blind && Levitation && !In_sokoban(&u.uz)) return;
  12.  
  13. 	do {
  14. 	    newlevel++;
  15. 	} while(!rn2(4) && newlevel < dunlevs_in_dungeon(&u.uz));
  16.  
  17. 	if(td) {
  18. 	    struct trap *t=t_at(u.ux,u.uy);
  19. 	    seetrap(t);
  20. 	    if (!In_sokoban(&u.uz)) {
  21. 		if (t->ttyp == TRAPDOOR)
  22. 			pline("A trap door opens up under you!");
  23. 		else 
  24. 			pline("There's a gaping hole under you!");
  25. 	    }
  26. 	} else pline_The("%s opens up under you!", surface(u.ux,u.uy));
  27.  
  28. 	if (In_sokoban(&u.uz) && Can_fall_thru(&u.uz))
  29. 	    ;	/* KMH -- You can't escape the Sokoban level traps */
  30. 	else if(Levitation || u.ustuck || !Can_fall_thru(&u.uz)
  31. 	   || Flying || is_clinger(youmonst.data)
  32. 	   || (Inhell && !u.uevent.invoked &&
  33. 					newlevel == dunlevs_in_dungeon(&u.uz))
  34. 		) {
  35. 	    dont_fall = "don't fall in.";
  36. 	} else if (youmonst.data->msize >= MZ_HUGE) {
  37. 	    dont_fall = "don't fit through.";
  38. 	} else if (!next_to_u()) {
  39. 	    dont_fall = "are jerked back by your pet!";
  40. 	}
  41. 	if (dont_fall) {
  42. 	    You(dont_fall);
  43. 	    /* hero didn't fall through, but any objects here might */
  44. 	    impact_drop((struct obj *)0, u.ux, u.uy, 0);
  45. 	    if (!td) {
  46. 		display_nhwindow(WIN_MESSAGE, FALSE);
  47. 		pline_The("opening under you closes up.");
  48. 	    }
  49. 	    return;
  50. 	}
  51.  
  52. 	if(*u.ushops) shopdig(1);
  53. 	if (Is_stronghold(&u.uz)) {
  54. 	    find_hell(&dtmp);
  55. 	} else {
  56. 	    dtmp.dnum = u.uz.dnum;
  57. 	    dtmp.dlevel = newlevel;
  58. 	}
  59. 	if (!td)
  60. 	    Sprintf(msgbuf, "The hole in the %s above you closes up.",
  61. 		    ceiling(u.ux,u.uy));
  62. 	schedule_goto(&dtmp, FALSE, TRUE, 0,
  63. 		      (char *)0, !td ? msgbuf : (char *)0);
  64. }

animate_statue[edit]

  1. /*
  2. * Animate the given statue.  May have been via shatter attempt, trap,
  3. * or stone to flesh spell.  Return a monster if successfully animated.
  4. * If the monster is animated, the object is deleted.  If fail_reason
  5. * is non-null, then fill in the reason for failure (or success).
  6. *
  7. * The cause of animation is:
  8. *
  9. *	ANIMATE_NORMAL  - hero "finds" the monster
  10. *	ANIMATE_SHATTER - hero tries to destroy the statue
  11. *	ANIMATE_SPELL   - stone to flesh spell hits the statue
  12. *
  13. * Perhaps x, y is not needed if we can use get_obj_location() to find
  14. * the statue's location... ???
  15. */
  16. struct monst *
  17. animate_statue(statue, x, y, cause, fail_reason)
  18. struct obj *statue;
  19. xchar x, y;
  20. int cause;
  21. int *fail_reason;
  22. {
  23. 	struct permonst *mptr;
  24. 	struct monst *mon = 0;
  25. 	struct obj *item;
  26. 	coord cc;
  27. 	boolean historic = (Role_if(PM_ARCHEOLOGIST) && !flags.mon_moving && (statue->spe & STATUE_HISTORIC));
  28. 	char statuename[BUFSZ];
  29.  
  30. 	Strcpy(statuename,the(xname(statue)));
  31.  
  32. 	if (statue->oxlth && statue->oattached == OATTACHED_MONST) {
  33. 	    cc.x = x,  cc.y = y;
  34. 	    mon = montraits(statue, &cc);
  35. 	    if (mon && mon->mtame && !mon->isminion)
  36. 		wary_dog(mon, TRUE);
  37. 	} else {
  38. 	    /* statue of any golem hit with stone-to-flesh becomes flesh golem */
  39. 	    if (is_golem(&mons[statue->corpsenm]) && cause == ANIMATE_SPELL)
  40. 	    	mptr = &mons[PM_FLESH_GOLEM];
  41. 	    else
  42. 		mptr = &mons[statue->corpsenm];
  43. 	    /*
  44. 	     * Guard against someone wishing for a statue of a unique monster
  45. 	     * (which is allowed in normal play) and then tossing it onto the
  46. 	     * [detected or guessed] location of a statue trap.  Normally the
  47. 	     * uppermost statue is the one which would be activated.
  48. 	     */
  49. 	    if ((mptr->geno & G_UNIQ) && cause != ANIMATE_SPELL) {
  50. 	        if (fail_reason) *fail_reason = AS_MON_IS_UNIQUE;
  51. 	        return (struct monst *)0;
  52. 	    }
  53. 	    if (cause == ANIMATE_SPELL &&
  54. 		((mptr->geno & G_UNIQ) || mptr->msound == MS_GUARDIAN)) {
  55. 		/* Statues of quest guardians or unique monsters
  56. 		 * will not stone-to-flesh as the real thing.
  57. 		 */
  58. 		mon = makemon(&mons[PM_DOPPELGANGER], x, y,
  59. 			NO_MINVENT|MM_NOCOUNTBIRTH|MM_ADJACENTOK);
  60. 		if (mon) {
  61. 			/* makemon() will set mon->cham to
  62. 			 * CHAM_ORDINARY if hero is wearing
  63. 			 * ring of protection from shape changers
  64. 			 * when makemon() is called, so we have to
  65. 			 * check the field before calling newcham().
  66. 			 */
  67. 			if (mon->cham == CHAM_DOPPELGANGER)
  68. 				(void) newcham(mon, mptr, FALSE, FALSE);
  69. 		}
  70. 	    } else
  71. 		mon = makemon(mptr, x, y, (cause == ANIMATE_SPELL) ?
  72. 			(NO_MINVENT | MM_ADJACENTOK) : NO_MINVENT);
  73. 	}
  74.  
  75. 	if (!mon) {
  76. 	    if (fail_reason) *fail_reason = AS_NO_MON;
  77. 	    return (struct monst *)0;
  78. 	}
  79.  
  80. 	/* in case statue is wielded and hero zaps stone-to-flesh at self */
  81. 	if (statue->owornmask) remove_worn_item(statue, TRUE);
  82.  
  83. 	/* allow statues to be of a specific gender */
  84. 	if (statue->spe & STATUE_MALE)
  85. 	    mon->female = FALSE;
  86. 	else if (statue->spe & STATUE_FEMALE)
  87. 	    mon->female = TRUE;
  88. 	/* if statue has been named, give same name to the monster */
  89. 	if (statue->onamelth)
  90. 	    mon = christen_monst(mon, ONAME(statue));
  91. 	/* transfer any statue contents to monster's inventory */
  92. 	while ((item = statue->cobj) != 0) {
  93. 	    obj_extract_self(item);
  94. 	    (void) add_to_minv(mon, item);
  95. 	}
  96. 	m_dowear(mon, TRUE);
  97. 	delobj(statue);
  98.  
  99. 	/* mimic statue becomes seen mimic; other hiders won't be hidden */
  100. 	if (mon->m_ap_type) seemimic(mon);
  101. 	else mon->mundetected = FALSE;
  102. 	if ((x == u.ux && y == u.uy) || cause == ANIMATE_SPELL) {
  103. 	    const char *comes_to_life = nonliving(mon->data) ?
  104. 					"moves" : "comes to life"; 
  105. 	    if (cause == ANIMATE_SPELL)
  106. 	    	pline("%s %s!", upstart(statuename),
  107. 	    		canspotmon(mon) ? comes_to_life : "disappears");
  108. 	    else
  109. 		pline_The("statue %s!",
  110. 			canspotmon(mon) ? comes_to_life : "disappears");
  111. 	    if (historic) {
  112. 		    You_feel("guilty that the historic statue is now gone.");
  113. 		    adjalign(-1);
  114. 	    }
  115. 	} else if (cause == ANIMATE_SHATTER)
  116. 	    pline("Instead of shattering, the statue suddenly %s!",
  117. 		canspotmon(mon) ? "comes to life" : "disappears");
  118. 	else { /* cause == ANIMATE_NORMAL */
  119. 	    You("find %s posing as a statue.",
  120. 		canspotmon(mon) ? a_monnam(mon) : something);
  121. 	    stop_occupation();
  122. 	}
  123. 	/* avoid hiding under nothing */
  124. 	if (x == u.ux && y == u.uy &&
  125. 		Upolyd && hides_under(youmonst.data) && !OBJ_AT(x, y))
  126. 	    u.uundetected = 0;
  127.  
  128. 	if (fail_reason) *fail_reason = AS_OK;
  129. 	return mon;
  130. }

activate_statue_trap[edit]

  1. /*
  2. * You've either stepped onto a statue trap's location or you've triggered a
  3. * statue trap by searching next to it or by trying to break it with a wand
  4. * or pick-axe.
  5. */
  6. struct monst *
  7. activate_statue_trap(trap, x, y, shatter)
  8. struct trap *trap;
  9. xchar x, y;
  10. boolean shatter;
  11. {
  12. 	struct monst *mtmp = (struct monst *)0;
  13. 	struct obj *otmp = sobj_at(STATUE, x, y);
  14. 	int fail_reason;
  15.  
  16. 	/*
  17. 	 * Try to animate the first valid statue.  Stop the loop when we
  18. 	 * actually create something or the failure cause is not because
  19. 	 * the mon was unique.
  20. 	 */
  21. 	deltrap(trap);
  22. 	while (otmp) {
  23. 	    mtmp = animate_statue(otmp, x, y,
  24. 		    shatter ? ANIMATE_SHATTER : ANIMATE_NORMAL, &fail_reason);
  25. 	    if (mtmp || fail_reason != AS_MON_IS_UNIQUE) break;
  26.  
  27. 	    while ((otmp = otmp->nexthere) != 0)
  28. 		if (otmp->otyp == STATUE) break;
  29. 	}
  30.  
  31. 	if (Blind) feel_location(x, y);
  32. 	else newsym(x, y);
  33. 	return mtmp;
  34. }
  35.  
  36. #ifdef STEED

keep_saddle_with_steedcorpse[edit]

  1. STATIC_OVL boolean
  2. keep_saddle_with_steedcorpse(steed_mid, objchn, saddle)
  3. unsigned steed_mid;
  4. struct obj *objchn, *saddle;
  5. {
  6. 	if (!saddle) return FALSE;
  7. 	while(objchn) {
  8. 		if(objchn->otyp == CORPSE &&
  9. 		   objchn->oattached == OATTACHED_MONST && objchn->oxlth) {
  10. 			struct monst *mtmp = (struct monst *)objchn->oextra;
  11. 			if (mtmp->m_id == steed_mid) {
  12. 				/* move saddle */
  13. 				xchar x,y;
  14. 				if (get_obj_location(objchn, &x, &y, 0)) {
  15. 					obj_extract_self(saddle);
  16. 					place_object(saddle, x, y);
  17. 					stackobj(saddle);
  18. 				}
  19. 				return TRUE;
  20. 			}
  21. 		}
  22. 		if (Has_contents(objchn) &&
  23. 		    keep_saddle_with_steedcorpse(steed_mid, objchn->cobj, saddle))
  24. 			return TRUE;
  25. 		objchn = objchn->nobj;
  26. 	}
  27. 	return FALSE;
  28. }
  29. #endif /*STEED*/

dotrap[edit]

  1. void
  2. dotrap(trap, trflags)
  3. register struct trap *trap;
  4. unsigned trflags;
  5. {
  6. 	register int ttype = trap->ttyp;
  7. 	register struct obj *otmp;
  8. 	boolean already_seen = trap->tseen;
  9. 	boolean webmsgok = (!(trflags & NOWEBMSG));
  10. 	boolean forcebungle = (trflags & FORCEBUNGLE);
  11.  
  12. 	nomul(0);
  13.  
  14. 	/* KMH -- You can't escape the Sokoban level traps */
  15. 	if (In_sokoban(&u.uz) &&
  16. 			(ttype == PIT || ttype == SPIKED_PIT || ttype == HOLE ||
  17. 			ttype == TRAPDOOR)) {
  18. 	    /* The "air currents" message is still appropriate -- even when
  19. 	     * the hero isn't flying or levitating -- because it conveys the
  20. 	     * reason why the player cannot escape the trap with a dexterity
  21. 	     * check, clinging to the ceiling, etc.
  22. 	     */
  23. 	    pline("Air currents pull you down into %s %s!",
  24. 	    	a_your[trap->madeby_u],
  25. 	    	defsyms[trap_to_defsym(ttype)].explanation);
  26. 	    /* then proceed to normal trap effect */
  27. 	} else if (already_seen) {
  28. 	    if ((Levitation || Flying) &&
  29. 		    (ttype == PIT || ttype == SPIKED_PIT || ttype == HOLE ||
  30. 		    ttype == BEAR_TRAP)) {
  31. 		You("%s over %s %s.",
  32. 		    Levitation ? "float" : "fly",
  33. 		    a_your[trap->madeby_u],
  34. 		    defsyms[trap_to_defsym(ttype)].explanation);
  35. 		return;
  36. 	    }
  37. 	    if(!Fumbling && ttype != MAGIC_PORTAL &&
  38. 		ttype != ANTI_MAGIC && !forcebungle &&
  39. 		(!rn2(5) ||
  40. 	    ((ttype == PIT || ttype == SPIKED_PIT) && is_clinger(youmonst.data)))) {
  41. 		You("escape %s %s.",
  42. 		    (ttype == ARROW_TRAP && !trap->madeby_u) ? "an" :
  43. 			a_your[trap->madeby_u],
  44. 		    defsyms[trap_to_defsym(ttype)].explanation);
  45. 		return;
  46. 	    }
  47. 	}
  48.  
  49. #ifdef STEED
  50. 	if (u.usteed) u.usteed->mtrapseen |= (1 << (ttype-1));
  51. #endif
  52.  
  53. 	switch(ttype) {
  54. 	    case ARROW_TRAP:
  55. 		if (trap->once && trap->tseen && !rn2(15)) {
  56. 		    You_hear("a loud click!");
  57. 		    deltrap(trap);
  58. 		    newsym(u.ux,u.uy);
  59. 		    break;
  60. 		}
  61. 		trap->once = 1;
  62. 		seetrap(trap);
  63. 		pline("An arrow shoots out at you!");
  64. 		otmp = mksobj(ARROW, TRUE, FALSE);
  65. 		otmp->quan = 1L;
  66. 		otmp->owt = weight(otmp);
  67. 		otmp->opoisoned = 0;
  68. #ifdef STEED
  69. 		if (u.usteed && !rn2(2) && steedintrap(trap, otmp)) /* nothing */;
  70. 		else
  71. #endif
  72. 		if (thitu(8, dmgval(otmp, &youmonst), otmp, "arrow")) {
  73. 		    obfree(otmp, (struct obj *)0);
  74. 		} else {
  75. 		    place_object(otmp, u.ux, u.uy);
  76. 		    if (!Blind) otmp->dknown = 1;
  77. 		    stackobj(otmp);
  78. 		    newsym(u.ux, u.uy);
  79. 		}
  80. 		break;
  81. 	    case DART_TRAP:
  82. 		if (trap->once && trap->tseen && !rn2(15)) {
  83. 		    You_hear("a soft click.");
  84. 		    deltrap(trap);
  85. 		    newsym(u.ux,u.uy);
  86. 		    break;
  87. 		}
  88. 		trap->once = 1;
  89. 		seetrap(trap);
  90. 		pline("A little dart shoots out at you!");
  91. 		otmp = mksobj(DART, TRUE, FALSE);
  92. 		otmp->quan = 1L;
  93. 		otmp->owt = weight(otmp);
  94. 		if (!rn2(6)) otmp->opoisoned = 1;
  95. #ifdef STEED
  96. 		if (u.usteed && !rn2(2) && steedintrap(trap, otmp)) /* nothing */;
  97. 		else
  98. #endif
  99. 		if (thitu(7, dmgval(otmp, &youmonst), otmp, "little dart")) {
  100. 		    if (otmp->opoisoned)
  101. 			poisoned("dart", A_CON, "little dart", -10);
  102. 		    obfree(otmp, (struct obj *)0);
  103. 		} else {
  104. 		    place_object(otmp, u.ux, u.uy);
  105. 		    if (!Blind) otmp->dknown = 1;
  106. 		    stackobj(otmp);
  107. 		    newsym(u.ux, u.uy);
  108. 		}
  109. 		break;
  110. 	    case ROCKTRAP:
  111. 		if (trap->once && trap->tseen && !rn2(15)) {
  112. 		    pline("A trap door in %s opens, but nothing falls out!",
  113. 			  the(ceiling(u.ux,u.uy)));
  114. 		    deltrap(trap);
  115. 		    newsym(u.ux,u.uy);
  116. 		} else {
  117. 		    int dmg = d(2,6); /* should be std ROCK dmg? */
  118.  
  119. 		    trap->once = 1;
  120. 		    seetrap(trap);
  121. 		    otmp = mksobj_at(ROCK, u.ux, u.uy, TRUE, FALSE);
  122. 		    otmp->quan = 1L;
  123. 		    otmp->owt = weight(otmp);
  124.  
  125. 		    pline("A trap door in %s opens and %s falls on your %s!",
  126. 			  the(ceiling(u.ux,u.uy)),
  127. 			  an(xname(otmp)),
  128. 			  body_part(HEAD));
  129.  
  130. 		    if (uarmh) {
  131. 			if(is_metallic(uarmh)) {
  132. 			    pline("Fortunately, you are wearing a hard helmet.");
  133. 			    dmg = 2;
  134. 			} else if (flags.verbose) {
  135. 			    Your("%s does not protect you.", xname(uarmh));
  136. 			}
  137. 		    }
  138.  
  139. 		    if (!Blind) otmp->dknown = 1;
  140. 		    stackobj(otmp);
  141. 		    newsym(u.ux,u.uy);	/* map the rock */
  142.  
  143. 		    losehp(dmg, "falling rock", KILLED_BY_AN);
  144. 		    exercise(A_STR, FALSE);
  145. 		}
  146. 		break;
  147.  
  148. 	    case SQKY_BOARD:	    /* stepped on a squeaky board */
  149. 		if (Levitation || Flying) {
  150. 		    if (!Blind) {
  151. 			seetrap(trap);
  152. 			if (Hallucination)
  153. 				You("notice a crease in the linoleum.");
  154. 			else
  155. 				You("notice a loose board below you.");
  156. 		    }
  157. 		} else {
  158. 		    seetrap(trap);
  159. 		    pline("A board beneath you squeaks loudly.");
  160. 		    wake_nearby();
  161. 		}
  162. 		break;
  163.  
  164. 	    case BEAR_TRAP:
  165. 		if(Levitation || Flying) break;
  166. 		seetrap(trap);
  167. 		if(amorphous(youmonst.data) || is_whirly(youmonst.data) ||
  168. 						    unsolid(youmonst.data)) {
  169. 		    pline("%s bear trap closes harmlessly through you.",
  170. 			    A_Your[trap->madeby_u]);
  171. 		    break;
  172. 		}
  173. 		if(
  174. #ifdef STEED
  175. 		   !u.usteed &&
  176. #endif
  177. 		   youmonst.data->msize <= MZ_SMALL) {
  178. 		    pline("%s bear trap closes harmlessly over you.",
  179. 			    A_Your[trap->madeby_u]);
  180. 		    break;
  181. 		}
  182. 		u.utrap = rn1(4, 4);
  183. 		u.utraptype = TT_BEARTRAP;
  184. #ifdef STEED
  185. 		if (u.usteed) {
  186. 		    pline("%s bear trap closes on %s %s!",
  187. 			A_Your[trap->madeby_u], s_suffix(mon_nam(u.usteed)),
  188. 			mbodypart(u.usteed, FOOT));
  189. 		} else
  190. #endif
  191. 		{
  192. 		    pline("%s bear trap closes on your %s!",
  193. 			    A_Your[trap->madeby_u], body_part(FOOT));
  194. 		    if(u.umonnum == PM_OWLBEAR || u.umonnum == PM_BUGBEAR)
  195. 			You("howl in anger!");
  196. 		}
  197. 		exercise(A_DEX, FALSE);
  198. 		break;
  199.  
  200. 	    case SLP_GAS_TRAP:
  201. 		seetrap(trap);
  202. 		if(Sleep_resistance || breathless(youmonst.data)) {
  203. 		    You("are enveloped in a cloud of gas!");
  204. 		    break;
  205. 		}
  206. 		pline("A cloud of gas puts you to sleep!");
  207. 		fall_asleep(-rnd(25), TRUE);
  208. #ifdef STEED
  209. 		(void) steedintrap(trap, (struct obj *)0);
  210. #endif
  211. 		break;
  212.  
  213. 	    case RUST_TRAP:
  214. 		seetrap(trap);
  215. 		if (u.umonnum == PM_IRON_GOLEM) {
  216. 		    int dam = u.mhmax;
  217.  
  218. 		    pline("%s you!", A_gush_of_water_hits);
  219. 		    You("are covered with rust!");
  220. 		    if (Half_physical_damage) dam = (dam+1) / 2;
  221. 		    losehp(dam, "rusting away", KILLED_BY);
  222. 		    break;
  223. 		} else if (u.umonnum == PM_GREMLIN && rn2(3)) {
  224. 		    pline("%s you!", A_gush_of_water_hits);
  225. 		    (void)split_mon(&youmonst, (struct monst *)0);
  226. 		    break;
  227. 		}
  228.  
  229. 	    /* Unlike monsters, traps cannot aim their rust attacks at
  230. 	     * you, so instead of looping through and taking either the
  231. 	     * first rustable one or the body, we take whatever we get,
  232. 	     * even if it is not rustable.
  233. 	     */
  234. 		switch (rn2(5)) {
  235. 		    case 0:
  236. 			pline("%s you on the %s!", A_gush_of_water_hits,
  237. 				    body_part(HEAD));
  238. 			(void) rust_dmg(uarmh, "helmet", 1, TRUE, &youmonst);
  239. 			break;
  240. 		    case 1:
  241. 			pline("%s your left %s!", A_gush_of_water_hits,
  242. 				    body_part(ARM));
  243. 			if (rust_dmg(uarms, "shield", 1, TRUE, &youmonst))
  244. 			    break;
  245. 			if (u.twoweap || (uwep && bimanual(uwep)))
  246. 			    erode_obj(u.twoweap ? uswapwep : uwep, FALSE, TRUE);
  247. glovecheck:		(void) rust_dmg(uarmg, "gauntlets", 1, TRUE, &youmonst);
  248. 			/* Not "metal gauntlets" since it gets called
  249. 			 * even if it's leather for the message
  250. 			 */
  251. 			break;
  252. 		    case 2:
  253. 			pline("%s your right %s!", A_gush_of_water_hits,
  254. 				    body_part(ARM));
  255. 			erode_obj(uwep, FALSE, TRUE);
  256. 			goto glovecheck;
  257. 		    default:
  258. 			pline("%s you!", A_gush_of_water_hits);
  259. 			for (otmp=invent; otmp; otmp = otmp->nobj)
  260. 				    (void) snuff_lit(otmp);
  261. 			if (uarmc)
  262. 			    (void) rust_dmg(uarmc, cloak_simple_name(uarmc),
  263. 						1, TRUE, &youmonst);
  264. 			else if (uarm)
  265. 			    (void) rust_dmg(uarm, "armor", 1, TRUE, &youmonst);
  266. #ifdef TOURIST
  267. 			else if (uarmu)
  268. 			    (void) rust_dmg(uarmu, "shirt", 1, TRUE, &youmonst);
  269. #endif
  270. 		}
  271. 		update_inventory();
  272. 		break;
  273.  
  274. 	    case FIRE_TRAP:
  275. 		seetrap(trap);
  276. 		dofiretrap((struct obj *)0);
  277. 		break;
  278.  
  279. 	    case PIT:
  280. 	    case SPIKED_PIT:
  281. 		/* KMH -- You can't escape the Sokoban level traps */
  282. 		if (!In_sokoban(&u.uz) && (Levitation || Flying)) break;
  283. 		seetrap(trap);
  284. 		if (!In_sokoban(&u.uz) && is_clinger(youmonst.data)) {
  285. 		    if(trap->tseen) {
  286. 			You("see %s %spit below you.", a_your[trap->madeby_u],
  287. 			    ttype == SPIKED_PIT ? "spiked " : "");
  288. 		    } else {
  289. 			pline("%s pit %sopens up under you!",
  290. 			    A_Your[trap->madeby_u],
  291. 			    ttype == SPIKED_PIT ? "full of spikes " : "");
  292. 			You("don't fall in!");
  293. 		    }
  294. 		    break;
  295. 		}
  296. 		if (!In_sokoban(&u.uz)) {
  297. 		    char verbbuf[BUFSZ];
  298. #ifdef STEED
  299. 		    if (u.usteed) {
  300. 		    	if ((trflags & RECURSIVETRAP) != 0)
  301. 			    Sprintf(verbbuf, "and %s fall",
  302. 				x_monnam(u.usteed,
  303. 				    u.usteed->mnamelth ? ARTICLE_NONE : ARTICLE_THE,
  304. 				    (char *)0, SUPPRESS_SADDLE, FALSE));
  305. 			else
  306. 			    Sprintf(verbbuf,"lead %s",
  307. 				x_monnam(u.usteed,
  308. 					 u.usteed->mnamelth ? ARTICLE_NONE : ARTICLE_THE,
  309. 				 	 "poor", SUPPRESS_SADDLE, FALSE));
  310. 		    } else
  311. #endif
  312. 		    Strcpy(verbbuf,"fall");
  313. 		    You("%s into %s pit!", verbbuf, a_your[trap->madeby_u]);
  314. 		}
  315. 		/* wumpus reference */
  316. 		if (Role_if(PM_RANGER) && !trap->madeby_u && !trap->once &&
  317. 			In_quest(&u.uz) && Is_qlocate(&u.uz)) {
  318. 		    pline("Fortunately it has a bottom after all...");
  319. 		    trap->once = 1;
  320. 		} else if (u.umonnum == PM_PIT_VIPER ||
  321. 			u.umonnum == PM_PIT_FIEND)
  322. 		    pline("How pitiful.  Isn't that the pits?");
  323. 		if (ttype == SPIKED_PIT) {
  324. 		    const char *predicament = "on a set of sharp iron spikes";
  325. #ifdef STEED
  326. 		    if (u.usteed) {
  327. 			pline("%s lands %s!",
  328. 				upstart(x_monnam(u.usteed,
  329. 					 u.usteed->mnamelth ? ARTICLE_NONE : ARTICLE_THE,
  330. 					 "poor", SUPPRESS_SADDLE, FALSE)),
  331. 			      predicament);
  332. 		    } else
  333. #endif
  334. 		    You("land %s!", predicament);
  335. 		}
  336. 		if (!Passes_walls)
  337. 		    u.utrap = rn1(6,2);
  338. 		u.utraptype = TT_PIT;
  339. #ifdef STEED
  340. 		if (!steedintrap(trap, (struct obj *)0)) {
  341. #endif
  342. 		if (ttype == SPIKED_PIT) {
  343. 		    losehp(rnd(10),"fell into a pit of iron spikes",
  344. 			NO_KILLER_PREFIX);
  345. 		    if (!rn2(6))
  346. 			poisoned("spikes", A_STR, "fall onto poison spikes", 8);
  347. 		} else
  348. 		    losehp(rnd(6),"fell into a pit", NO_KILLER_PREFIX);
  349. 		if (Punished && !carried(uball)) {
  350. 		    unplacebc();
  351. 		    ballfall();
  352. 		    placebc();
  353. 		}
  354. 		selftouch("Falling, you");
  355. 		vision_full_recalc = 1;	/* vision limits change */
  356. 		exercise(A_STR, FALSE);
  357. 		exercise(A_DEX, FALSE);
  358. #ifdef STEED
  359. 		}
  360. #endif
  361. 		break;
  362. 	    case HOLE:
  363. 	    case TRAPDOOR:
  364. 		if (!Can_fall_thru(&u.uz)) {
  365. 		    seetrap(trap);	/* normally done in fall_through */
  366. 		    impossible("dotrap: %ss cannot exist on this level.",
  367. 			       defsyms[trap_to_defsym(ttype)].explanation);
  368. 		    break;		/* don't activate it after all */
  369. 		}
  370. 		fall_through(TRUE);
  371. 		break;
  372.  
  373. 	    case TELEP_TRAP:
  374. 		seetrap(trap);
  375. 		tele_trap(trap);
  376. 		break;
  377. 	    case LEVEL_TELEP:
  378. 		seetrap(trap);
  379. 		level_tele_trap(trap);
  380. 		break;
  381.  
  382. 	    case WEB: /* Our luckless player has stumbled into a web. */
  383. 		seetrap(trap);
  384. 		if (amorphous(youmonst.data) || is_whirly(youmonst.data) ||
  385. 						    unsolid(youmonst.data)) {
  386. 		    if (acidic(youmonst.data) || u.umonnum == PM_GELATINOUS_CUBE ||
  387. 			u.umonnum == PM_FIRE_ELEMENTAL) {
  388. 			if (webmsgok)
  389. 			    You("%s %s spider web!",
  390. 				(u.umonnum == PM_FIRE_ELEMENTAL) ? "burn" : "dissolve",
  391. 				a_your[trap->madeby_u]);
  392. 			deltrap(trap);
  393. 			newsym(u.ux,u.uy);
  394. 			break;
  395. 		    }
  396. 		    if (webmsgok) You("flow through %s spider web.",
  397. 			    a_your[trap->madeby_u]);
  398. 		    break;
  399. 		}
  400. 		if (webmaker(youmonst.data)) {
  401. 		    if (webmsgok)
  402. 		    	pline(trap->madeby_u ? "You take a walk on your web."
  403. 					 : "There is a spider web here.");
  404. 		    break;
  405. 		}
  406. 		if (webmsgok) {
  407. 		    char verbbuf[BUFSZ];
  408. 		    verbbuf[0] = '\0';
  409. #ifdef STEED
  410. 		    if (u.usteed)
  411. 		   	Sprintf(verbbuf,"lead %s",
  412. 				x_monnam(u.usteed,
  413. 					 u.usteed->mnamelth ? ARTICLE_NONE : ARTICLE_THE,
  414. 				 	 "poor", SUPPRESS_SADDLE, FALSE));
  415. 		    else
  416. #endif
  417.  
  418. 		    Sprintf(verbbuf, "%s", Levitation ? (const char *)"float" :
  419. 		      		locomotion(youmonst.data, "stumble"));
  420. 		    You("%s into %s spider web!",
  421. 			verbbuf, a_your[trap->madeby_u]);
  422. 		}
  423. 		u.utraptype = TT_WEB;
  424.  
  425. 		/* Time stuck in the web depends on your/steed strength. */
  426. 		{
  427. 		    register int str = ACURR(A_STR);
  428.  
  429. #ifdef STEED
  430. 		    /* If mounted, the steed gets trapped.  Use mintrap
  431. 		     * to do all the work.  If mtrapped is set as a result,
  432. 		     * unset it and set utrap instead.  In the case of a
  433. 		     * strongmonst and mintrap said it's trapped, use a
  434. 		     * short but non-zero trap time.  Otherwise, monsters
  435. 		     * have no specific strength, so use player strength.
  436. 		     * This gets skipped for webmsgok, which implies that
  437. 		     * the steed isn't a factor.
  438. 		     */
  439. 		    if (u.usteed && webmsgok) {
  440. 			/* mtmp location might not be up to date */
  441. 			u.usteed->mx = u.ux;
  442. 			u.usteed->my = u.uy;
  443.  
  444. 			/* mintrap currently does not return 2(died) for webs */
  445. 			if (mintrap(u.usteed)) {
  446. 			    u.usteed->mtrapped = 0;
  447. 			    if (strongmonst(u.usteed->data)) str = 17;
  448. 			} else {
  449. 			    break;
  450. 			}
  451.  
  452. 			webmsgok = FALSE; /* mintrap printed the messages */
  453. 		    }
  454. #endif
  455. 		    if (str <= 3) u.utrap = rn1(6,6);
  456. 		    else if (str < 6) u.utrap = rn1(6,4);
  457. 		    else if (str < 9) u.utrap = rn1(4,4);
  458. 		    else if (str < 12) u.utrap = rn1(4,2);
  459. 		    else if (str < 15) u.utrap = rn1(2,2);
  460. 		    else if (str < 18) u.utrap = rnd(2);
  461. 		    else if (str < 69) u.utrap = 1;
  462. 		    else {
  463. 			u.utrap = 0;
  464. 			if (webmsgok)
  465. 			    You("tear through %s web!", a_your[trap->madeby_u]);
  466. 			deltrap(trap);
  467. 			newsym(u.ux,u.uy);	/* get rid of trap symbol */
  468. 		    }
  469. 		}
  470. 		break;
  471.  
  472. 	    case STATUE_TRAP:
  473. 		(void) activate_statue_trap(trap, u.ux, u.uy, FALSE);
  474. 		break;
  475.  
  476. 	    case MAGIC_TRAP:	    /* A magic trap. */
  477. 		seetrap(trap);
  478. 		if (!rn2(30)) {
  479. 		    deltrap(trap);
  480. 		    newsym(u.ux,u.uy);	/* update position */
  481. 		    You("are caught in a magical explosion!");
  482. 		    losehp(rnd(10), "magical explosion", KILLED_BY_AN);
  483. 		    Your("body absorbs some of the magical energy!");
  484. 		    u.uen = (u.uenmax += 2);
  485. 		} else domagictrap();
  486. #ifdef STEED
  487. 		(void) steedintrap(trap, (struct obj *)0);
  488. #endif
  489. 		break;
  490.  
  491. 	    case ANTI_MAGIC:
  492. 		seetrap(trap);
  493. 		if(Antimagic) {
  494. 		    shieldeff(u.ux, u.uy);
  495. 		    You_feel("momentarily lethargic.");
  496. 		} else drain_en(rnd(u.ulevel) + 1);
  497. 		break;
  498.  
  499. 	    case POLY_TRAP: {
  500. 	        char verbbuf[BUFSZ];
  501. 		seetrap(trap);
  502. #ifdef STEED
  503. 		if (u.usteed)
  504. 			Sprintf(verbbuf, "lead %s",
  505. 				x_monnam(u.usteed,
  506. 					 u.usteed->mnamelth ? ARTICLE_NONE : ARTICLE_THE,
  507. 				 	 (char *)0, SUPPRESS_SADDLE, FALSE));
  508. 		else
  509. #endif
  510. 		 Sprintf(verbbuf,"%s",
  511. 		    Levitation ? (const char *)"float" :
  512. 		    locomotion(youmonst.data, "step"));
  513. 		You("%s onto a polymorph trap!", verbbuf);
  514. 		if(Antimagic || Unchanging) {
  515. 		    shieldeff(u.ux, u.uy);
  516. 		    You_feel("momentarily different.");
  517. 		    /* Trap did nothing; don't remove it --KAA */
  518. 		} else {
  519. #ifdef STEED
  520. 		    (void) steedintrap(trap, (struct obj *)0);
  521. #endif
  522. 		    deltrap(trap);	/* delete trap before polymorph */
  523. 		    newsym(u.ux,u.uy);	/* get rid of trap symbol */
  524. 		    You_feel("a change coming over you.");
  525. 		    polyself(FALSE);
  526. 		}
  527. 		break;
  528. 	    }
  529. 	    case LANDMINE: {
  530. #ifdef STEED
  531. 		unsigned steed_mid = 0;
  532. 		struct obj *saddle = 0;
  533. #endif
  534. 		if (Levitation || Flying) {
  535. 		    if (!already_seen && rn2(3)) break;
  536. 		    seetrap(trap);
  537. 		    pline("%s %s in a pile of soil below you.",
  538. 			    already_seen ? "There is" : "You discover",
  539. 			    trap->madeby_u ? "the trigger of your mine" :
  540. 					     "a trigger");
  541. 		    if (already_seen && rn2(3)) break;
  542. 		    pline("KAABLAMM!!!  %s %s%s off!",
  543. 			  forcebungle ? "Your inept attempt sets" :
  544. 					"The air currents set",
  545. 			    already_seen ? a_your[trap->madeby_u] : "",
  546. 			    already_seen ? " land mine" : "it");
  547. 		} else {
  548. #ifdef STEED
  549. 		    /* prevent landmine from killing steed, throwing you to
  550. 		     * the ground, and you being affected again by the same
  551. 		     * mine because it hasn't been deleted yet
  552. 		     */
  553. 		    static boolean recursive_mine = FALSE;
  554.  
  555. 		    if (recursive_mine) break;
  556. #endif
  557. 		    seetrap(trap);
  558. 		    pline("KAABLAMM!!!  You triggered %s land mine!",
  559. 					    a_your[trap->madeby_u]);
  560. #ifdef STEED
  561. 		    if (u.usteed) steed_mid = u.usteed->m_id;
  562. 		    recursive_mine = TRUE;
  563. 		    (void) steedintrap(trap, (struct obj *)0);
  564. 		    recursive_mine = FALSE;
  565. 		    saddle = sobj_at(SADDLE,u.ux, u.uy);
  566. #endif
  567. 		    set_wounded_legs(LEFT_SIDE, rn1(35, 41));
  568. 		    set_wounded_legs(RIGHT_SIDE, rn1(35, 41));
  569. 		    exercise(A_DEX, FALSE);
  570. 		}
  571. 		blow_up_landmine(trap);
  572. #ifdef STEED
  573. 		if (steed_mid && saddle && !u.usteed)
  574. 			(void)keep_saddle_with_steedcorpse(steed_mid, fobj, saddle);
  575. #endif
  576. 		newsym(u.ux,u.uy);		/* update trap symbol */
  577. 		losehp(rnd(16), "land mine", KILLED_BY_AN);
  578. 		/* fall recursively into the pit... */
  579. 		if ((trap = t_at(u.ux, u.uy)) != 0) dotrap(trap, RECURSIVETRAP);
  580. 		fill_pit(u.ux, u.uy);
  581. 		break;
  582. 	    }
  583. 	    case ROLLING_BOULDER_TRAP: {
  584. 		int style = ROLL | (trap->tseen ? LAUNCH_KNOWN : 0);
  585.  
  586. 		seetrap(trap);
  587. 		pline("Click! You trigger a rolling boulder trap!");
  588. 		if(!launch_obj(BOULDER, trap->launch.x, trap->launch.y,
  589. 		      trap->launch2.x, trap->launch2.y, style)) {
  590. 		    deltrap(trap);
  591. 		    newsym(u.ux,u.uy);	/* get rid of trap symbol */
  592. 		    pline("Fortunately for you, no boulder was released.");
  593. 		}
  594. 		break;
  595. 	    }
  596. 	    case MAGIC_PORTAL:
  597. 		seetrap(trap);
  598. 		domagicportal(trap);
  599. 		break;
  600.  
  601. 	    default:
  602. 		seetrap(trap);
  603. 		impossible("You hit a trap of type %u", trap->ttyp);
  604. 	}
  605. }
  606.  
  607. #ifdef STEED

steedintrap[edit]

  1. STATIC_OVL int
  2. steedintrap(trap, otmp)
  3. struct trap *trap;
  4. struct obj *otmp;
  5. {
  6. 	struct monst *mtmp = u.usteed;
  7. 	struct permonst *mptr;
  8. 	int tt;
  9. 	boolean in_sight;
  10. 	boolean trapkilled = FALSE;
  11. 	boolean steedhit = FALSE;
  12.  
  13. 	if (!u.usteed || !trap) return 0;
  14. 	mptr = mtmp->data;
  15. 	tt = trap->ttyp;
  16. 	mtmp->mx = u.ux;
  17. 	mtmp->my = u.uy;
  18.  
  19. 	in_sight = !Blind;
  20. 	switch (tt) {
  21. 		case ARROW_TRAP:
  22. 			if(!otmp) {
  23. 				impossible("steed hit by non-existant arrow?");
  24. 				return 0;
  25. 			}
  26. 			if (thitm(8, mtmp, otmp, 0, FALSE)) trapkilled = TRUE;
  27. 			steedhit = TRUE;
  28. 			break;
  29. 		case DART_TRAP:
  30. 			if(!otmp) {
  31. 				impossible("steed hit by non-existant dart?");
  32. 				return 0;
  33. 			}
  34. 			if (thitm(7, mtmp, otmp, 0, FALSE)) trapkilled = TRUE;
  35. 			steedhit = TRUE;
  36. 			break;
  37. 		case SLP_GAS_TRAP:
  38. 		    if (!resists_sleep(mtmp) && !breathless(mptr) &&
  39. 				!mtmp->msleeping && mtmp->mcanmove) {
  40. 			    mtmp->mcanmove = 0;
  41. 			    mtmp->mfrozen = rnd(25);
  42. 			    if (in_sight) {
  43. 				pline("%s suddenly falls asleep!",
  44. 				      Monnam(mtmp));
  45. 			    }
  46. 			}
  47. 			steedhit = TRUE;
  48. 			break;
  49. 		case LANDMINE:
  50. 			if (thitm(0, mtmp, (struct obj *)0, rnd(16), FALSE))
  51. 			    trapkilled = TRUE;
  52. 			steedhit = TRUE;
  53. 			break;
  54. 		case PIT:
  55. 		case SPIKED_PIT:
  56. 			if (mtmp->mhp <= 0 ||
  57. 				thitm(0, mtmp, (struct obj *)0,
  58. 				      rnd((tt == PIT) ? 6 : 10), FALSE))
  59. 			    trapkilled = TRUE;
  60. 			steedhit = TRUE;
  61. 			break;
  62. 		case POLY_TRAP: 
  63. 		    if (!resists_magm(mtmp)) {
  64. 			if (!resist(mtmp, WAND_CLASS, 0, NOTELL)) {
  65. 			(void) newcham(mtmp, (struct permonst *)0,
  66. 				       FALSE, FALSE);
  67. 			if (!can_saddle(mtmp) || !can_ride(mtmp)) {
  68. 				dismount_steed(DISMOUNT_POLY);
  69. 			} else {
  70. 				You("have to adjust yourself in the saddle on %s.",
  71. 					x_monnam(mtmp,
  72. 					 mtmp->mnamelth ? ARTICLE_NONE : ARTICLE_A,
  73. 				 	 (char *)0, SUPPRESS_SADDLE, FALSE));
  74. 			}
  75.  
  76. 		    }
  77. 		    steedhit = TRUE;
  78. 		    break;
  79. 		default:
  80. 			return 0;
  81. 	    }
  82. 	}
  83. 	if(trapkilled) {
  84. 		dismount_steed(DISMOUNT_POLY);
  85. 		return 2;
  86. 	}
  87. 	else if(steedhit) return 1;
  88. 	else return 0;
  89. }
  90. #endif /*STEED*/

blow_up_landmine[edit]

  1. /* some actions common to both player and monsters for triggered landmine */
  2. void
  3. blow_up_landmine(trap)
  4. struct trap *trap;
  5. {
  6. 	(void)scatter(trap->tx, trap->ty, 4,
  7. 		MAY_DESTROY | MAY_HIT | MAY_FRACTURE | VIS_EFFECTS,
  8. 		(struct obj *)0);
  9. 	del_engr_at(trap->tx, trap->ty);
  10. 	wake_nearto(trap->tx, trap->ty, 400);
  11. 	if (IS_DOOR(levl[trap->tx][trap->ty].typ))
  12. 	    levl[trap->tx][trap->ty].doormask = D_BROKEN;
  13. 	/* TODO: destroy drawbridge if present */
  14. 	/* caller may subsequently fill pit, e.g. with a boulder */
  15. 	trap->ttyp = PIT;		/* explosion creates a pit */
  16. 	trap->madeby_u = FALSE;		/* resulting pit isn't yours */
  17. 	seetrap(trap);			/* and it isn't concealed */
  18. }
  19.  
  20. #endif /* OVLB */
  21. #ifdef OVL3

launch_obj[edit]

  1. /*
  2. * Move obj from (x1,y1) to (x2,y2)
  3. *
  4. * Return 0 if no object was launched.
  5. *        1 if an object was launched and placed somewhere.
  6. *        2 if an object was launched, but used up.
  7. */
  8. int
  9. launch_obj(otyp, x1, y1, x2, y2, style)
  10. short otyp;
  11. register int x1,y1,x2,y2;
  12. int style;
  13. {
  14. 	register struct monst *mtmp;
  15. 	register struct obj *otmp, *otmp2;
  16. 	register int dx,dy;
  17. 	struct obj *singleobj;
  18. 	boolean used_up = FALSE;
  19. 	boolean otherside = FALSE;
  20. 	int dist;
  21. 	int tmp;
  22. 	int delaycnt = 0;
  23.  
  24. 	otmp = sobj_at(otyp, x1, y1);
  25. 	/* Try the other side too, for rolling boulder traps */
  26. 	if (!otmp && otyp == BOULDER) {
  27. 		otherside = TRUE;
  28. 		otmp = sobj_at(otyp, x2, y2);
  29. 	}
  30. 	if (!otmp) return 0;
  31. 	if (otherside) {	/* swap 'em */
  32. 		int tx, ty;
  33.  
  34. 		tx = x1; ty = y1;
  35. 		x1 = x2; y1 = y2;
  36. 		x2 = tx; y2 = ty;
  37. 	}
  38.  
  39. 	if (otmp->quan == 1L) {
  40. 	    obj_extract_self(otmp);
  41. 	    singleobj = otmp;
  42. 	    otmp = (struct obj *) 0;
  43. 	} else {
  44. 	    singleobj = splitobj(otmp, 1L);
  45. 	    obj_extract_self(singleobj);
  46. 	}
  47. 	newsym(x1,y1);
  48. 	/* in case you're using a pick-axe to chop the boulder that's being
  49. 	   launched (perhaps a monster triggered it), destroy context so that
  50. 	   next dig attempt never thinks you're resuming previous effort */
  51. 	if ((otyp == BOULDER || otyp == STATUE) &&
  52. 	    singleobj->ox == digging.pos.x && singleobj->oy == digging.pos.y)
  53. 	    (void) memset((genericptr_t)&digging, 0, sizeof digging);
  54.  
  55. 	dist = distmin(x1,y1,x2,y2);
  56. 	bhitpos.x = x1;
  57. 	bhitpos.y = y1;
  58. 	dx = sgn(x2 - x1);
  59. 	dy = sgn(y2 - y1);
  60. 	switch (style) {
  61. 	    case ROLL|LAUNCH_UNSEEN:
  62. 			if (otyp == BOULDER) {
  63. 			    You_hear(Hallucination ?
  64. 				     "someone bowling." :
  65. 				     "rumbling in the distance.");
  66. 			}
  67. 			style &= ~LAUNCH_UNSEEN;
  68. 			goto roll;
  69. 	    case ROLL|LAUNCH_KNOWN:
  70. 			/* use otrapped as a flag to ohitmon */
  71. 			singleobj->otrapped = 1;
  72. 			style &= ~LAUNCH_KNOWN;
  73. 			/* fall through */
  74. 	    roll:
  75. 	    case ROLL:
  76. 			delaycnt = 2;
  77. 			/* fall through */
  78. 	    default:
  79. 			if (!delaycnt) delaycnt = 1;
  80. 			if (!cansee(bhitpos.x,bhitpos.y)) curs_on_u();
  81. 			tmp_at(DISP_FLASH, obj_to_glyph(singleobj));
  82. 			tmp_at(bhitpos.x, bhitpos.y);
  83. 	}
  84.  
  85. 	/* Set the object in motion */
  86. 	while(dist-- > 0 && !used_up) {
  87. 		struct trap *t;
  88. 		tmp_at(bhitpos.x, bhitpos.y);
  89. 		tmp = delaycnt;
  90.  
  91. 		/* dstage@u.washington.edu -- Delay only if hero sees it */
  92. 		if (cansee(bhitpos.x, bhitpos.y))
  93. 			while (tmp-- > 0) delay_output();
  94.  
  95. 		bhitpos.x += dx;
  96. 		bhitpos.y += dy;
  97. 		t = t_at(bhitpos.x, bhitpos.y);
  98.  
  99. 		if ((mtmp = m_at(bhitpos.x, bhitpos.y)) != 0) {
  100. 			if (otyp == BOULDER && throws_rocks(mtmp->data)) {
  101. 			    if (rn2(3)) {
  102. 				pline("%s snatches the boulder.",
  103. 					Monnam(mtmp));
  104. 				singleobj->otrapped = 0;
  105. 				(void) mpickobj(mtmp, singleobj);
  106. 				used_up = TRUE;
  107. 				break;
  108. 			    }
  109. 			}
  110. 			if (ohitmon(mtmp,singleobj,
  111. 					(style==ROLL) ? -1 : dist, FALSE)) {
  112. 				used_up = TRUE;
  113. 				break;
  114. 			}
  115. 		} else if (bhitpos.x == u.ux && bhitpos.y == u.uy) {
  116. 			if (multi) nomul(0);
  117. 			if (thitu(9 + singleobj->spe,
  118. 				  dmgval(singleobj, &youmonst),
  119. 				  singleobj, (char *)0))
  120. 			    stop_occupation();
  121. 		}
  122. 		if (style == ROLL) {
  123. 		    if (down_gate(bhitpos.x, bhitpos.y) != -1) {
  124. 		        if(ship_object(singleobj, bhitpos.x, bhitpos.y, FALSE)){
  125. 				used_up = TRUE;
  126. 				break;
  127. 			}
  128. 		    }
  129. 		    if (t && otyp == BOULDER) {
  130. 			switch(t->ttyp) {
  131. 			case LANDMINE:
  132. 			    if (rn2(10) > 2) {
  133. 			  	pline(
  134. 				  "KAABLAMM!!!%s",
  135. 				  cansee(bhitpos.x, bhitpos.y) ?
  136. 					" The rolling boulder triggers a land mine." : "");
  137. 				deltrap(t);
  138. 				del_engr_at(bhitpos.x,bhitpos.y);
  139. 				place_object(singleobj, bhitpos.x, bhitpos.y);
  140. 				singleobj->otrapped = 0;
  141. 				fracture_rock(singleobj);
  142. 				(void)scatter(bhitpos.x,bhitpos.y, 4,
  143. 					MAY_DESTROY|MAY_HIT|MAY_FRACTURE|VIS_EFFECTS,
  144. 					(struct obj *)0);
  145. 				if (cansee(bhitpos.x,bhitpos.y))
  146. 					newsym(bhitpos.x,bhitpos.y);
  147. 			        used_up = TRUE;
  148. 			    }
  149. 			    break;		
  150. 			case LEVEL_TELEP:
  151. 			case TELEP_TRAP:
  152. 			    if (cansee(bhitpos.x, bhitpos.y))
  153. 			    	pline("Suddenly the rolling boulder disappears!");
  154. 			    else
  155. 			    	You_hear("a rumbling stop abruptly.");
  156. 			    singleobj->otrapped = 0;
  157. 			    if (t->ttyp == TELEP_TRAP)
  158. 				rloco(singleobj);
  159. 			    else {
  160. 				int newlev = random_teleport_level();
  161. 				d_level dest;
  162.  
  163. 				if (newlev == depth(&u.uz) || In_endgame(&u.uz))
  164. 				    continue;
  165. 				add_to_migration(singleobj);
  166. 				get_level(&dest, newlev);
  167. 				singleobj->ox = dest.dnum;
  168. 				singleobj->oy = dest.dlevel;
  169. 				singleobj->owornmask = (long)MIGR_RANDOM;
  170. 			    }
  171. 		    	    seetrap(t);
  172. 			    used_up = TRUE;
  173. 			    break;
  174. 			case PIT:
  175. 			case SPIKED_PIT:
  176. 			case HOLE:
  177. 			case TRAPDOOR:
  178. 			    /* the boulder won't be used up if there is a
  179. 			       monster in the trap; stop rolling anyway */
  180. 			    x2 = bhitpos.x,  y2 = bhitpos.y;  /* stops here */
  181. 			    if (flooreffects(singleobj, x2, y2, "fall"))
  182. 				used_up = TRUE;
  183. 			    dist = -1;	/* stop rolling immediately */
  184. 			    break;
  185. 			}
  186. 			if (used_up || dist == -1) break;
  187. 		    }
  188. 		    if (flooreffects(singleobj, bhitpos.x, bhitpos.y, "fall")) {
  189. 			used_up = TRUE;
  190. 			break;
  191. 		    }
  192. 		    if (otyp == BOULDER &&
  193. 		       (otmp2 = sobj_at(BOULDER, bhitpos.x, bhitpos.y)) != 0) {
  194. 			const char *bmsg =
  195. 				     " as one boulder sets another in motion";
  196.  
  197. 			if (!isok(bhitpos.x + dx, bhitpos.y + dy) || !dist ||
  198. 			    IS_ROCK(levl[bhitpos.x + dx][bhitpos.y + dy].typ))
  199. 			    bmsg = " as one boulder hits another";
  200.  
  201. 			You_hear("a loud crash%s!",
  202. 				cansee(bhitpos.x, bhitpos.y) ? bmsg : "");
  203. 			obj_extract_self(otmp2);
  204. 			/* pass off the otrapped flag to the next boulder */
  205. 			otmp2->otrapped = singleobj->otrapped;
  206. 			singleobj->otrapped = 0;
  207. 			place_object(singleobj, bhitpos.x, bhitpos.y);
  208. 			singleobj = otmp2;
  209. 			otmp2 = (struct obj *)0;
  210. 			wake_nearto(bhitpos.x, bhitpos.y, 10*10);
  211. 		    }
  212. 		}
  213. 		if (otyp == BOULDER && closed_door(bhitpos.x,bhitpos.y)) {
  214. 			if (cansee(bhitpos.x, bhitpos.y))
  215. 				pline_The("boulder crashes through a door.");
  216. 			levl[bhitpos.x][bhitpos.y].doormask = D_BROKEN;
  217. 			if (dist) unblock_point(bhitpos.x, bhitpos.y);
  218. 		}
  219.  
  220. 		/* if about to hit iron bars, do so now */
  221. 		if (dist > 0 && isok(bhitpos.x + dx,bhitpos.y + dy) &&
  222. 			levl[bhitpos.x + dx][bhitpos.y + dy].typ == IRONBARS) {
  223. 		    x2 = bhitpos.x,  y2 = bhitpos.y;	/* object stops here */
  224. 		    if (hits_bars(&singleobj, x2, y2, !rn2(20), 0)) {
  225. 			if (!singleobj) used_up = TRUE;
  226. 			break;
  227. 		    }
  228. 		}
  229. 	}
  230. 	tmp_at(DISP_END, 0);
  231. 	if (!used_up) {
  232. 		singleobj->otrapped = 0;
  233. 		place_object(singleobj, x2,y2);
  234. 		newsym(x2,y2);
  235. 		return 1;
  236. 	} else
  237. 		return 2;
  238. }
  239.  
  240. #endif /* OVL3 */
  241. #ifdef OVLB

seetrap[edit]

  1. void
  2. seetrap(trap)
  3. 	register struct trap *trap;
  4. {
  5. 	if(!trap->tseen) {
  6. 	    trap->tseen = 1;
  7. 	    newsym(trap->tx, trap->ty);
  8. 	}
  9. }
  10.  
  11. #endif /* OVLB */
  12. #ifdef OVL3

mkroll_launch[edit]

  1. STATIC_OVL int
  2. mkroll_launch(ttmp, x, y, otyp, ocount)
  3. struct trap *ttmp;
  4. xchar x,y;
  5. short otyp;
  6. long ocount;
  7. {
  8. 	struct obj *otmp;
  9. 	register int tmp;
  10. 	schar dx,dy;
  11. 	int distance;
  12. 	coord cc;
  13. 	coord bcc;
  14. 	int trycount = 0;
  15. 	boolean success = FALSE;
  16. 	int mindist = 4;
  17.  
  18. 	if (ttmp->ttyp == ROLLING_BOULDER_TRAP) mindist = 2;
  19. 	distance = rn1(5,4);    /* 4..8 away */
  20. 	tmp = rn2(8);		/* randomly pick a direction to try first */
  21. 	while (distance >= mindist) {
  22. 		dx = xdir[tmp];
  23. 		dy = ydir[tmp];
  24. 		cc.x = x; cc.y = y;
  25. 		/* Prevent boulder from being placed on water */
  26. 		if (ttmp->ttyp == ROLLING_BOULDER_TRAP
  27. 				&& is_pool(x+distance*dx,y+distance*dy))
  28. 			success = FALSE;
  29. 		else success = isclearpath(&cc, distance, dx, dy);
  30. 		if (ttmp->ttyp == ROLLING_BOULDER_TRAP) {
  31. 			boolean success_otherway;
  32. 			bcc.x = x; bcc.y = y;
  33. 			success_otherway = isclearpath(&bcc, distance,
  34. 						-(dx), -(dy));
  35. 			if (!success_otherway) success = FALSE;
  36. 		}
  37. 		if (success) break;
  38. 		if (++tmp > 7) tmp = 0;
  39. 		if ((++trycount % 8) == 0) --distance;
  40. 	}
  41. 	if (!success) {
  42. 	    /* create the trap without any ammo, launch pt at trap location */
  43. 		cc.x = bcc.x = x;
  44. 		cc.y = bcc.y = y;
  45. 	} else {
  46. 		otmp = mksobj(otyp, TRUE, FALSE);
  47. 		otmp->quan = ocount;
  48. 		otmp->owt = weight(otmp);
  49. 		place_object(otmp, cc.x, cc.y);
  50. 		stackobj(otmp);
  51. 	}
  52. 	ttmp->launch.x = cc.x;
  53. 	ttmp->launch.y = cc.y;
  54. 	if (ttmp->ttyp == ROLLING_BOULDER_TRAP) {
  55. 		ttmp->launch2.x = bcc.x;
  56. 		ttmp->launch2.y = bcc.y;
  57. 	} else
  58. 		ttmp->launch_otyp = otyp;
  59. 	newsym(ttmp->launch.x, ttmp->launch.y);
  60. 	return 1;
  61. }

isclearpath[edit]

  1. STATIC_OVL boolean
  2. isclearpath(cc,distance,dx,dy)
  3. coord *cc;
  4. int distance;
  5. schar dx,dy;
  6. {
  7. 	uchar typ;
  8. 	xchar x, y;
  9.  
  10. 	x = cc->x;
  11. 	y = cc->y;
  12. 	while (distance-- > 0) {
  13. 		x += dx;
  14. 		y += dy;
  15. 		typ = levl[x][y].typ;
  16. 		if (!isok(x,y) || !ZAP_POS(typ) || closed_door(x,y))
  17. 			return FALSE;
  18. 	}
  19. 	cc->x = x;
  20. 	cc->y = y;
  21. 	return TRUE;
  22. }
  23. #endif /* OVL3 */
  24. #ifdef OVL1

mintrap[edit]

  1. int
  2. mintrap(mtmp)
  3. register struct monst *mtmp;
  4. {
  5. 	register struct trap *trap = t_at(mtmp->mx, mtmp->my);
  6. 	boolean trapkilled = FALSE;
  7. 	struct permonst *mptr = mtmp->data;
  8. 	struct obj *otmp;
  9.  
  10. 	if (!trap) {
  11. 	    mtmp->mtrapped = 0;	/* perhaps teleported? */
  12. 	} else if (mtmp->mtrapped) {	/* is currently in the trap */
  13. 	    if (!trap->tseen &&
  14. 		cansee(mtmp->mx, mtmp->my) && canseemon(mtmp) &&
  15. 		(trap->ttyp == SPIKED_PIT || trap->ttyp == BEAR_TRAP ||
  16. 		 trap->ttyp == HOLE || trap->ttyp == PIT ||
  17. 		 trap->ttyp == WEB)) {
  18. 		/* If you come upon an obviously trapped monster, then
  19. 		 * you must be able to see the trap it's in too.
  20. 		 */
  21. 		seetrap(trap);
  22. 	    }
  23.  
  24. 	    if (!rn2(40)) {
  25. 		if (sobj_at(BOULDER, mtmp->mx, mtmp->my) &&
  26. 			(trap->ttyp == PIT || trap->ttyp == SPIKED_PIT)) {
  27. 		    if (!rn2(2)) {
  28. 			mtmp->mtrapped = 0;
  29. 			if (canseemon(mtmp))
  30. 			    pline("%s pulls free...", Monnam(mtmp));
  31. 			fill_pit(mtmp->mx, mtmp->my);
  32. 		    }
  33. 		} else {
  34. 		    mtmp->mtrapped = 0;
  35. 		}
  36. 	    } else if (metallivorous(mptr)) {
  37. 		if (trap->ttyp == BEAR_TRAP) {
  38. 		    if (canseemon(mtmp))
  39. 			pline("%s eats a bear trap!", Monnam(mtmp));
  40. 		    deltrap(trap);
  41. 		    mtmp->meating = 5;
  42. 		    mtmp->mtrapped = 0;
  43. 		} else if (trap->ttyp == SPIKED_PIT) {
  44. 		    if (canseemon(mtmp))
  45. 			pline("%s munches on some spikes!", Monnam(mtmp));
  46. 		    trap->ttyp = PIT;
  47. 		    mtmp->meating = 5;
  48. 		}
  49. 	    }
  50. 	} else {
  51. 	    register int tt = trap->ttyp;
  52. 	    boolean in_sight, tear_web, see_it,
  53. 		    inescapable = ((tt == HOLE || tt == PIT) &&
  54. 				   In_sokoban(&u.uz) && !trap->madeby_u);
  55. 	    const char *fallverb;
  56.  
  57. #ifdef STEED
  58. 	    /* true when called from dotrap, inescapable is not an option */
  59. 	    if (mtmp == u.usteed) inescapable = TRUE;
  60. #endif
  61. 	    if (!inescapable &&
  62. 		    ((mtmp->mtrapseen & (1 << (tt-1))) != 0 ||
  63. 			(tt == HOLE && !mindless(mtmp->data)))) {
  64. 		/* it has been in such a trap - perhaps it escapes */
  65. 		if(rn2(4)) return(0);
  66. 	    } else {
  67. 		mtmp->mtrapseen |= (1 << (tt-1));
  68. 	    }
  69. 	    /* Monster is aggravated by being trapped by you.
  70. 	       Recognizing who made the trap isn't completely
  71. 	       unreasonable; everybody has their own style. */
  72. 	    if (trap->madeby_u && rnl(5)) setmangry(mtmp);
  73.  
  74. 	    in_sight = canseemon(mtmp);
  75. 	    see_it = cansee(mtmp->mx, mtmp->my);
  76. #ifdef STEED
  77. 	    /* assume hero can tell what's going on for the steed */
  78. 	    if (mtmp == u.usteed) in_sight = TRUE;
  79. #endif
  80. 	    switch (tt) {
  81. 		case ARROW_TRAP:
  82. 			if (trap->once && trap->tseen && !rn2(15)) {
  83. 			    if (in_sight && see_it)
  84. 				pline("%s triggers a trap but nothing happens.",
  85. 				      Monnam(mtmp));
  86. 			    deltrap(trap);
  87. 			    newsym(mtmp->mx, mtmp->my);
  88. 			    break;
  89. 			}
  90. 			trap->once = 1;
  91. 			otmp = mksobj(ARROW, TRUE, FALSE);
  92. 			otmp->quan = 1L;
  93. 			otmp->owt = weight(otmp);
  94. 			otmp->opoisoned = 0;
  95. 			if (in_sight) seetrap(trap);
  96. 			if (thitm(8, mtmp, otmp, 0, FALSE)) trapkilled = TRUE;
  97. 			break;
  98. 		case DART_TRAP:
  99. 			if (trap->once && trap->tseen && !rn2(15)) {
  100. 			    if (in_sight && see_it)
  101. 				pline("%s triggers a trap but nothing happens.",
  102. 				      Monnam(mtmp));
  103. 			    deltrap(trap);
  104. 			    newsym(mtmp->mx, mtmp->my);
  105. 			    break;
  106. 			}
  107. 			trap->once = 1;
  108. 			otmp = mksobj(DART, TRUE, FALSE);
  109. 			otmp->quan = 1L;
  110. 			otmp->owt = weight(otmp);
  111. 			if (!rn2(6)) otmp->opoisoned = 1;
  112. 			if (in_sight) seetrap(trap);
  113. 			if (thitm(7, mtmp, otmp, 0, FALSE)) trapkilled = TRUE;
  114. 			break;
  115. 		case ROCKTRAP:
  116. 			if (trap->once && trap->tseen && !rn2(15)) {
  117. 			    if (in_sight && see_it)
  118. 				pline("A trap door above %s opens, but nothing falls out!",
  119. 				      mon_nam(mtmp));
  120. 			    deltrap(trap);
  121. 			    newsym(mtmp->mx, mtmp->my);
  122. 			    break;
  123. 			}
  124. 			trap->once = 1;
  125. 			otmp = mksobj(ROCK, TRUE, FALSE);
  126. 			otmp->quan = 1L;
  127. 			otmp->owt = weight(otmp);
  128. 			if (in_sight) seetrap(trap);
  129. 			if (thitm(0, mtmp, otmp, d(2, 6), FALSE))
  130. 			    trapkilled = TRUE;
  131. 			break;
  132.  
  133. 		case SQKY_BOARD:
  134. 			if(is_flyer(mptr)) break;
  135. 			/* stepped on a squeaky board */
  136. 			if (in_sight) {
  137. 			    pline("A board beneath %s squeaks loudly.", mon_nam(mtmp));
  138. 			    seetrap(trap);
  139. 			} else
  140. 			   You_hear("a distant squeak.");
  141. 			/* wake up nearby monsters */
  142. 			wake_nearto(mtmp->mx, mtmp->my, 40);
  143. 			break;
  144.  
  145. 		case BEAR_TRAP:
  146. 			if(mptr->msize > MZ_SMALL &&
  147. 				!amorphous(mptr) && !is_flyer(mptr) &&
  148. 				!is_whirly(mptr) && !unsolid(mptr)) {
  149. 			    mtmp->mtrapped = 1;
  150. 			    if(in_sight) {
  151. 				pline("%s is caught in %s bear trap!",
  152. 				      Monnam(mtmp), a_your[trap->madeby_u]);
  153. 				seetrap(trap);
  154. 			    } else {
  155. 				if((mptr == &mons[PM_OWLBEAR]
  156. 				    || mptr == &mons[PM_BUGBEAR])
  157. 				   && flags.soundok)
  158. 				    You_hear("the roaring of an angry bear!");
  159. 			    }
  160. 			}
  161. 			break;
  162.  
  163. 		case SLP_GAS_TRAP:
  164. 		    if (!resists_sleep(mtmp) && !breathless(mptr) &&
  165. 				!mtmp->msleeping && mtmp->mcanmove) {
  166. 			    mtmp->mcanmove = 0;
  167. 			    mtmp->mfrozen = rnd(25);
  168. 			    if (in_sight) {
  169. 				pline("%s suddenly falls asleep!",
  170. 				      Monnam(mtmp));
  171. 				seetrap(trap);
  172. 			    }
  173. 			}
  174. 			break;
  175.  
  176. 		case RUST_TRAP:
  177. 		    {
  178. 			struct obj *target;
  179.  
  180. 			if (in_sight)
  181. 			    seetrap(trap);
  182. 			switch (rn2(5)) {
  183. 			case 0:
  184. 			    if (in_sight)
  185. 				pline("%s %s on the %s!", A_gush_of_water_hits,
  186. 				    mon_nam(mtmp), mbodypart(mtmp, HEAD));
  187. 			    target = which_armor(mtmp, W_ARMH);
  188. 			    (void) rust_dmg(target, "helmet", 1, TRUE, mtmp);
  189. 			    break;
  190. 			case 1:
  191. 			    if (in_sight)
  192. 				pline("%s %s's left %s!", A_gush_of_water_hits,
  193. 				    mon_nam(mtmp), mbodypart(mtmp, ARM));
  194. 			    target = which_armor(mtmp, W_ARMS);
  195. 			    if (rust_dmg(target, "shield", 1, TRUE, mtmp))
  196. 				break;
  197. 			    target = MON_WEP(mtmp);
  198. 			    if (target && bimanual(target))
  199. 				erode_obj(target, FALSE, TRUE);
  200. glovecheck:		    target = which_armor(mtmp, W_ARMG);
  201. 			    (void) rust_dmg(target, "gauntlets", 1, TRUE, mtmp);
  202. 			    break;
  203. 			case 2:
  204. 			    if (in_sight)
  205. 				pline("%s %s's right %s!", A_gush_of_water_hits,
  206. 				    mon_nam(mtmp), mbodypart(mtmp, ARM));
  207. 			    erode_obj(MON_WEP(mtmp), FALSE, TRUE);
  208. 			    goto glovecheck;
  209. 			default:
  210. 			    if (in_sight)
  211. 				pline("%s %s!", A_gush_of_water_hits,
  212. 				    mon_nam(mtmp));
  213. 			    for (otmp=mtmp->minvent; otmp; otmp = otmp->nobj)
  214. 				(void) snuff_lit(otmp);
  215. 			    target = which_armor(mtmp, W_ARMC);
  216. 			    if (target)
  217. 				(void) rust_dmg(target, cloak_simple_name(target),
  218. 						 1, TRUE, mtmp);
  219. 			    else {
  220. 				target = which_armor(mtmp, W_ARM);
  221. 				if (target)
  222. 				    (void) rust_dmg(target, "armor", 1, TRUE, mtmp);
  223. #ifdef TOURIST
  224. 				else {
  225. 				    target = which_armor(mtmp, W_ARMU);
  226. 				    (void) rust_dmg(target, "shirt", 1, TRUE, mtmp);
  227. 				}
  228. #endif
  229. 			    }
  230. 			}
  231. 			if (mptr == &mons[PM_IRON_GOLEM]) {
  232. 				if (in_sight)
  233. 				    pline("%s falls to pieces!", Monnam(mtmp));
  234. 				else if(mtmp->mtame)
  235. 				    pline("May %s rust in peace.",
  236. 								mon_nam(mtmp));
  237. 				mondied(mtmp);
  238. 				if (mtmp->mhp <= 0)
  239. 					trapkilled = TRUE;
  240. 			} else if (mptr == &mons[PM_GREMLIN] && rn2(3)) {
  241. 				(void)split_mon(mtmp, (struct monst *)0);
  242. 			}
  243. 			break;
  244. 		    }
  245. 		case FIRE_TRAP:
  246. mfiretrap:
  247. 			if (in_sight)
  248. 			    pline("A %s erupts from the %s under %s!",
  249. 				  tower_of_flame,
  250. 				  surface(mtmp->mx,mtmp->my), mon_nam(mtmp));
  251. 			else if (see_it)  /* evidently `mtmp' is invisible */
  252. 			    You("see a %s erupt from the %s!",
  253. 				tower_of_flame, surface(mtmp->mx,mtmp->my));
  254.  
  255. 			if (resists_fire(mtmp)) {
  256. 			    if (in_sight) {
  257. 				shieldeff(mtmp->mx,mtmp->my);
  258. 				pline("%s is uninjured.", Monnam(mtmp));
  259. 			    }
  260. 			} else {
  261. 			    int num = d(2,4), alt;
  262. 			    boolean immolate = FALSE;
  263.  
  264. 			    /* paper burns very fast, assume straw is tightly
  265. 			     * packed and burns a bit slower */
  266. 			    switch (monsndx(mtmp->data)) {
  267. 			    case PM_PAPER_GOLEM:   immolate = TRUE;
  268. 						   alt = mtmp->mhpmax; break;
  269. 			    case PM_STRAW_GOLEM:   alt = mtmp->mhpmax / 2; break;
  270. 			    case PM_WOOD_GOLEM:    alt = mtmp->mhpmax / 4; break;
  271. 			    case PM_LEATHER_GOLEM: alt = mtmp->mhpmax / 8; break;
  272. 			    default: alt = 0; break;
  273. 			    }
  274. 			    if (alt > num) num = alt;
  275.  
  276. 			    if (thitm(0, mtmp, (struct obj *)0, num, immolate))
  277. 				trapkilled = TRUE;
  278. 			    else
  279. 				/* we know mhp is at least `num' below mhpmax,
  280. 				   so no (mhp > mhpmax) check is needed here */
  281. 				mtmp->mhpmax -= rn2(num + 1);
  282. 			}
  283. 			if (burnarmor(mtmp) || rn2(3)) {
  284. 			    (void) destroy_mitem(mtmp, SCROLL_CLASS, AD_FIRE);
  285. 			    (void) destroy_mitem(mtmp, SPBOOK_CLASS, AD_FIRE);
  286. 			    (void) destroy_mitem(mtmp, POTION_CLASS, AD_FIRE);
  287. 			}
  288. 			if (burn_floor_paper(mtmp->mx, mtmp->my, see_it, FALSE) &&
  289. 				!see_it && distu(mtmp->mx, mtmp->my) <= 3*3)
  290. 			    You("smell smoke.");
  291. 			if (is_ice(mtmp->mx,mtmp->my))
  292. 			    melt_ice(mtmp->mx,mtmp->my);
  293. 			if (see_it) seetrap(trap);
  294. 			break;
  295.  
  296. 		case PIT:
  297. 		case SPIKED_PIT:
  298. 			fallverb = "falls";
  299. 			if (is_flyer(mptr) || is_floater(mptr) ||
  300. 				(mtmp->wormno && count_wsegs(mtmp) > 5) ||
  301. 				is_clinger(mptr)) {
  302. 			    if (!inescapable) break;	/* avoids trap */
  303. 			    fallverb = "is dragged";	/* sokoban pit */
  304. 			}
  305. 			if (!passes_walls(mptr))
  306. 			    mtmp->mtrapped = 1;
  307. 			if (in_sight) {
  308. 			    pline("%s %s into %s pit!",
  309. 				  Monnam(mtmp), fallverb,
  310. 				  a_your[trap->madeby_u]);
  311. 			    if (mptr == &mons[PM_PIT_VIPER] || mptr == &mons[PM_PIT_FIEND])
  312. 				pline("How pitiful.  Isn't that the pits?");
  313. 			    seetrap(trap);
  314. 			}
  315. 			mselftouch(mtmp, "Falling, ", FALSE);
  316. 			if (mtmp->mhp <= 0 ||
  317. 				thitm(0, mtmp, (struct obj *)0,
  318. 				      rnd((tt == PIT) ? 6 : 10), FALSE))
  319. 			    trapkilled = TRUE;
  320. 			break;
  321. 		case HOLE:
  322. 		case TRAPDOOR:
  323. 			if (!Can_fall_thru(&u.uz)) {
  324. 			 impossible("mintrap: %ss cannot exist on this level.",
  325. 				    defsyms[trap_to_defsym(tt)].explanation);
  326. 			    break;	/* don't activate it after all */
  327. 			}
  328. 			if (is_flyer(mptr) || is_floater(mptr) ||
  329. 				mptr == &mons[PM_WUMPUS] ||
  330. 				(mtmp->wormno && count_wsegs(mtmp) > 5) ||
  331. 				mptr->msize >= MZ_HUGE) {
  332. 			    if (inescapable) {	/* sokoban hole */
  333. 				if (in_sight) {
  334. 				    pline("%s seems to be yanked down!",
  335. 					  Monnam(mtmp));
  336. 				    /* suppress message in mlevel_tele_trap() */
  337. 				    in_sight = FALSE;
  338. 				    seetrap(trap);
  339. 				}
  340. 			    } else
  341. 				break;
  342. 			}
  343. 			/* Fall through */
  344. 		case LEVEL_TELEP:
  345. 		case MAGIC_PORTAL:
  346. 			{
  347. 			    int mlev_res;
  348. 			    mlev_res = mlevel_tele_trap(mtmp, trap,
  349. 							inescapable, in_sight);
  350. 			    if (mlev_res) return(mlev_res);
  351. 			}
  352. 			break;
  353.  
  354. 		case TELEP_TRAP:
  355. 			mtele_trap(mtmp, trap, in_sight);
  356. 			break;
  357.  
  358. 		case WEB:
  359. 			/* Monster in a web. */
  360. 			if (webmaker(mptr)) break;
  361. 			if (amorphous(mptr) || is_whirly(mptr) || unsolid(mptr)){
  362. 			    if(acidic(mptr) ||
  363. 			       mptr == &mons[PM_GELATINOUS_CUBE] ||
  364. 			       mptr == &mons[PM_FIRE_ELEMENTAL]) {
  365. 				if (in_sight)
  366. 				    pline("%s %s %s spider web!",
  367. 					  Monnam(mtmp),
  368. 					  (mptr == &mons[PM_FIRE_ELEMENTAL]) ?
  369. 					    "burns" : "dissolves",
  370. 					  a_your[trap->madeby_u]);
  371. 				deltrap(trap);
  372. 				newsym(mtmp->mx, mtmp->my);
  373. 				break;
  374. 			    }
  375. 			    if (in_sight) {
  376. 				pline("%s flows through %s spider web.",
  377. 				      Monnam(mtmp),
  378. 				      a_your[trap->madeby_u]);
  379. 				seetrap(trap);
  380. 			    }
  381. 			    break;
  382. 			}
  383. 			tear_web = FALSE;
  384. 			switch (monsndx(mptr)) {
  385. 			    case PM_OWLBEAR: /* Eric Backus */
  386. 			    case PM_BUGBEAR:
  387. 				if (!in_sight) {
  388. 				    You_hear("the roaring of a confused bear!");
  389. 				    mtmp->mtrapped = 1;
  390. 				    break;
  391. 				}
  392. 				/* fall though */
  393. 			    default:
  394. 				if (mptr->mlet == S_GIANT ||
  395. 				    (mptr->mlet == S_DRAGON &&
  396. 					extra_nasty(mptr)) || /* excl. babies */
  397. 				    (mtmp->wormno && count_wsegs(mtmp) > 5)) {
  398. 				    tear_web = TRUE;
  399. 				} else if (in_sight) {
  400. 				    pline("%s is caught in %s spider web.",
  401. 					  Monnam(mtmp),
  402. 					  a_your[trap->madeby_u]);
  403. 				    seetrap(trap);
  404. 				}
  405. 				mtmp->mtrapped = tear_web ? 0 : 1;
  406. 				break;
  407. 			    /* this list is fairly arbitrary; it deliberately
  408. 			       excludes wumpus & giant/ettin zombies/mummies */
  409. 			    case PM_TITANOTHERE:
  410. 			    case PM_BALUCHITHERIUM:
  411. 			    case PM_PURPLE_WORM:
  412. 			    case PM_JABBERWOCK:
  413. 			    case PM_IRON_GOLEM:
  414. 			    case PM_BALROG:
  415. 			    case PM_KRAKEN:
  416. 			    case PM_MASTODON:
  417. 				tear_web = TRUE;
  418. 				break;
  419. 			}
  420. 			if (tear_web) {
  421. 			    if (in_sight)
  422. 				pline("%s tears through %s spider web!",
  423. 				      Monnam(mtmp), a_your[trap->madeby_u]);
  424. 			    deltrap(trap);
  425. 			    newsym(mtmp->mx, mtmp->my);
  426. 			}
  427. 			break;
  428.  
  429. 		case STATUE_TRAP:
  430. 			break;
  431.  
  432. 		case MAGIC_TRAP:
  433. 			/* A magic trap.  Monsters usually immune. */
  434. 			if (!rn2(21)) goto mfiretrap;
  435. 			break;
  436. 		case ANTI_MAGIC:
  437. 			break;
  438.  
  439. 		case LANDMINE:
  440. 			if(rn2(3))
  441. 				break; /* monsters usually don't set it off */
  442. 			if(is_flyer(mptr)) {
  443. 				boolean already_seen = trap->tseen;
  444. 				if (in_sight && !already_seen) {
  445. 	pline("A trigger appears in a pile of soil below %s.", mon_nam(mtmp));
  446. 					seetrap(trap);
  447. 				}
  448. 				if (rn2(3)) break;
  449. 				if (in_sight) {
  450. 					newsym(mtmp->mx, mtmp->my);
  451. 					pline_The("air currents set %s off!",
  452. 					  already_seen ? "a land mine" : "it");
  453. 				}
  454. 			} else if(in_sight) {
  455. 			    newsym(mtmp->mx, mtmp->my);
  456. 			    pline("KAABLAMM!!!  %s triggers %s land mine!",
  457. 				Monnam(mtmp), a_your[trap->madeby_u]);
  458. 			}
  459. 			if (!in_sight)
  460. 				pline("Kaablamm!  You hear an explosion in the distance!");
  461. 			blow_up_landmine(trap);
  462. 			if (thitm(0, mtmp, (struct obj *)0, rnd(16), FALSE))
  463. 				trapkilled = TRUE;
  464. 			else {
  465. 				/* monsters recursively fall into new pit */
  466. 				if (mintrap(mtmp) == 2) trapkilled=TRUE;
  467. 			}
  468. 			/* a boulder may fill the new pit, crushing monster */
  469. 			fill_pit(trap->tx, trap->ty);
  470. 			if (mtmp->mhp <= 0) trapkilled = TRUE;
  471. 			if (unconscious()) {
  472. 				multi = -1;
  473. 				nomovemsg="The explosion awakens you!";
  474. 			}
  475. 			break;
  476.  
  477. 		case POLY_TRAP:
  478. 		    if (resists_magm(mtmp)) {
  479. 			shieldeff(mtmp->mx, mtmp->my);
  480. 		    } else if (!resist(mtmp, WAND_CLASS, 0, NOTELL)) {
  481. 			(void) newcham(mtmp, (struct permonst *)0,
  482. 				       FALSE, FALSE);
  483. 			if (in_sight) seetrap(trap);
  484. 		    }
  485. 		    break;
  486.  
  487. 		case ROLLING_BOULDER_TRAP:
  488. 		    if (!is_flyer(mptr)) {
  489. 			int style = ROLL | (in_sight ? 0 : LAUNCH_UNSEEN);
  490.  
  491. 		        newsym(mtmp->mx,mtmp->my);
  492. 			if (in_sight)
  493. 			    pline("Click! %s triggers %s.", Monnam(mtmp),
  494. 				  trap->tseen ?
  495. 				  "a rolling boulder trap" :
  496. 				  something);
  497. 			if (launch_obj(BOULDER, trap->launch.x, trap->launch.y,
  498. 				trap->launch2.x, trap->launch2.y, style)) {
  499. 			    if (in_sight) trap->tseen = TRUE;
  500. 			    if (mtmp->mhp <= 0) trapkilled = TRUE;
  501. 			} else {
  502. 			    deltrap(trap);
  503. 			    newsym(mtmp->mx,mtmp->my);
  504. 			}
  505. 		    }
  506. 		    break;
  507.  
  508. 		default:
  509. 			impossible("Some monster encountered a strange trap of type %d.", tt);
  510. 	    }
  511. 	}
  512. 	if(trapkilled) return 2;
  513. 	return mtmp->mtrapped;
  514. }
  515.  
  516. #endif /* OVL1 */
  517. #ifdef OVLB

instapetrify[edit]

  1. /* Combine cockatrice checks into single functions to avoid repeating code. */
  2. void
  3. instapetrify(str)
  4. const char *str;
  5. {
  6. 	if (Stone_resistance) return;
  7. 	if (poly_when_stoned(youmonst.data) && polymon(PM_STONE_GOLEM))
  8. 	    return;
  9. 	You("turn to stone...");
  10. 	killer_format = KILLED_BY;
  11. 	killer = str;
  12. 	done(STONING);
  13. }

minstapetrify[edit]

  1. void
  2. minstapetrify(mon,byplayer)
  3. struct monst *mon;
  4. boolean byplayer;
  5. {
  6. 	if (resists_ston(mon)) return;
  7. 	if (poly_when_stoned(mon->data)) {
  8. 		mon_to_stone(mon);
  9. 		return;
  10. 	}
  11.  
  12. 	/* give a "<mon> is slowing down" message and also remove
  13. 	   intrinsic speed (comparable to similar effect on the hero) */
  14. 	mon_adjust_speed(mon, -3, (struct obj *)0);
  15.  
  16. 	if (cansee(mon->mx, mon->my))
  17. 		pline("%s turns to stone.", Monnam(mon));
  18. 	if (byplayer) {
  19. 		stoned = TRUE;
  20. 		xkilled(mon,0);
  21. 	} else monstone(mon);
  22. }

selftouch[edit]

  1. void
  2. selftouch(arg)
  3. const char *arg;
  4. {
  5. 	char kbuf[BUFSZ];
  6.  
  7. 	if(uwep && uwep->otyp == CORPSE && touch_petrifies(&mons[uwep->corpsenm])
  8. 			&& !Stone_resistance) {
  9. 		pline("%s touch the %s corpse.", arg,
  10. 		        mons[uwep->corpsenm].mname);
  11. 		Sprintf(kbuf, "%s corpse", an(mons[uwep->corpsenm].mname));
  12. 		instapetrify(kbuf);
  13. 	}
  14. 	/* Or your secondary weapon, if wielded */
  15. 	if(u.twoweap && uswapwep && uswapwep->otyp == CORPSE &&
  16. 			touch_petrifies(&mons[uswapwep->corpsenm]) && !Stone_resistance){
  17. 		pline("%s touch the %s corpse.", arg,
  18. 		        mons[uswapwep->corpsenm].mname);
  19. 		Sprintf(kbuf, "%s corpse", an(mons[uswapwep->corpsenm].mname));
  20. 		instapetrify(kbuf);
  21. 	}
  22. }

mselftouch[edit]

  1. void
  2. mselftouch(mon,arg,byplayer)
  3. struct monst *mon;
  4. const char *arg;
  5. boolean byplayer;
  6. {
  7. 	struct obj *mwep = MON_WEP(mon);
  8.  
  9. 	if (mwep && mwep->otyp == CORPSE && touch_petrifies(&mons[mwep->corpsenm])) {
  10. 		if (cansee(mon->mx, mon->my)) {
  11. 			pline("%s%s touches the %s corpse.",
  12. 			    arg ? arg : "", arg ? mon_nam(mon) : Monnam(mon),
  13. 			    mons[mwep->corpsenm].mname);
  14. 		}
  15. 		minstapetrify(mon, byplayer);
  16. 	}
  17. }

float_up[edit]

  1. void
  2. float_up()
  3. {
  4. 	if(u.utrap) {
  5. 		if(u.utraptype == TT_PIT) {
  6. 			u.utrap = 0;
  7. 			You("float up, out of the pit!");
  8. 			vision_full_recalc = 1;	/* vision limits change */
  9. 			fill_pit(u.ux, u.uy);
  10. 		} else if (u.utraptype == TT_INFLOOR) {
  11. 			Your("body pulls upward, but your %s are still stuck.",
  12. 			     makeplural(body_part(LEG)));
  13. 		} else {
  14. 			You("float up, only your %s is still stuck.",
  15. 				body_part(LEG));
  16. 		}
  17. 	}
  18. 	else if(Is_waterlevel(&u.uz))
  19. 		pline("It feels as though you've lost some weight.");
  20. 	else if(u.uinwater)
  21. 		spoteffects(TRUE);
  22. 	else if(u.uswallow)
  23. 		You(is_animal(u.ustuck->data) ?
  24. 			"float away from the %s."  :
  25. 			"spiral up into %s.",
  26. 		    is_animal(u.ustuck->data) ?
  27. 			surface(u.ux, u.uy) :
  28. 			mon_nam(u.ustuck));
  29. 	else if (Hallucination)
  30. 		pline("Up, up, and awaaaay!  You're walking on air!");
  31. 	else if(Is_airlevel(&u.uz))
  32. 		You("gain control over your movements.");
  33. 	else
  34. 		You("start to float in the air!");
  35. #ifdef STEED
  36. 	if (u.usteed && !is_floater(u.usteed->data) &&
  37. 						!is_flyer(u.usteed->data)) {
  38. 	    if (Lev_at_will)
  39. 	    	pline("%s magically floats up!", Monnam(u.usteed));
  40. 	    else {
  41. 	    	You("cannot stay on %s.", mon_nam(u.usteed));
  42. 	    	dismount_steed(DISMOUNT_GENERIC);
  43. 	    }
  44. 	}
  45. #endif
  46. 	return;
  47. }

fill_pit[edit]

  1. void
  2. fill_pit(x, y)
  3. int x, y;
  4. {
  5. 	struct obj *otmp;
  6. 	struct trap *t;
  7.  
  8. 	if ((t = t_at(x, y)) &&
  9. 	    ((t->ttyp == PIT) || (t->ttyp == SPIKED_PIT)) &&
  10. 	    (otmp = sobj_at(BOULDER, x, y))) {
  11. 		obj_extract_self(otmp);
  12. 		(void) flooreffects(otmp, x, y, "settle");
  13. 	}
  14. }

float_down[edit]

  1. int
  2. float_down(hmask, emask)
  3. long hmask, emask;     /* might cancel timeout */
  4. {
  5. 	register struct trap *trap = (struct trap *)0;
  6. 	d_level current_dungeon_level;
  7. 	boolean no_msg = FALSE;
  8.  
  9. 	HLevitation &= ~hmask;
  10. 	ELevitation &= ~emask;
  11. 	if(Levitation) return(0); /* maybe another ring/potion/boots */
  12. 	if(u.uswallow) {
  13. 	    You("float down, but you are still %s.",
  14. 		is_animal(u.ustuck->data) ? "swallowed" : "engulfed");
  15. 	    return(1);
  16. 	}
  17.  
  18. 	if (Punished && !carried(uball) &&
  19. 	    (is_pool(uball->ox, uball->oy) ||
  20. 	     ((trap = t_at(uball->ox, uball->oy)) &&
  21. 	      ((trap->ttyp == PIT) || (trap->ttyp == SPIKED_PIT) ||
  22. 	       (trap->ttyp == TRAPDOOR) || (trap->ttyp == HOLE))))) {
  23. 			u.ux0 = u.ux;
  24. 			u.uy0 = u.uy;
  25. 			u.ux = uball->ox;
  26. 			u.uy = uball->oy;
  27. 			movobj(uchain, uball->ox, uball->oy);
  28. 			newsym(u.ux0, u.uy0);
  29. 			vision_full_recalc = 1;	/* in case the hero moved. */
  30. 	}
  31. 	/* check for falling into pool - added by GAN 10/20/86 */
  32. 	if(!Flying) {
  33. 		if (!u.uswallow && u.ustuck) {
  34. 			if (sticks(youmonst.data))
  35. 				You("aren't able to maintain your hold on %s.",
  36. 					mon_nam(u.ustuck));
  37. 			else
  38. 				pline("Startled, %s can no longer hold you!",
  39. 					mon_nam(u.ustuck));
  40. 			u.ustuck = 0;
  41. 		}
  42. 		/* kludge alert:
  43. 		 * drown() and lava_effects() print various messages almost
  44. 		 * every time they're called which conflict with the "fall
  45. 		 * into" message below.  Thus, we want to avoid printing
  46. 		 * confusing, duplicate or out-of-order messages.
  47. 		 * Use knowledge of the two routines as a hack -- this
  48. 		 * should really be handled differently -dlc
  49. 		 */
  50. 		if(is_pool(u.ux,u.uy) && !Wwalking && !Swimming && !u.uinwater)
  51. 			no_msg = drown();
  52.  
  53. 		if(is_lava(u.ux,u.uy)) {
  54. 			(void) lava_effects();
  55. 			no_msg = TRUE;
  56. 		}
  57. 	}
  58. 	if (!trap) {
  59. 	    trap = t_at(u.ux,u.uy);
  60. 	    if(Is_airlevel(&u.uz))
  61. 		You("begin to tumble in place.");
  62. 	    else if (Is_waterlevel(&u.uz) && !no_msg)
  63. 		You_feel("heavier.");
  64. 	    /* u.uinwater msgs already in spoteffects()/drown() */
  65. 	    else if (!u.uinwater && !no_msg) {
  66. #ifdef STEED
  67. 		if (!(emask & W_SADDLE))
  68. #endif
  69. 		{
  70. 		    boolean sokoban_trap = (In_sokoban(&u.uz) && trap);
  71. 		    if (Hallucination)
  72. 			pline("Bummer!  You've %s.",
  73. 			      is_pool(u.ux,u.uy) ?
  74. 			      "splashed down" : sokoban_trap ? "crashed" :
  75. 			      "hit the ground");
  76. 		    else {
  77. 			if (!sokoban_trap)
  78. 			    You("float gently to the %s.",
  79. 				surface(u.ux, u.uy));
  80. 			else {
  81. 			    /* Justification elsewhere for Sokoban traps
  82. 			     * is based on air currents. This is
  83. 			     * consistent with that.
  84. 			     * The unexpected additional force of the
  85. 			     * air currents once leviation
  86. 			     * ceases knocks you off your feet.
  87. 			     */
  88. 			    You("fall over.");
  89. 			    losehp(rnd(2), "dangerous winds", KILLED_BY);
  90. #ifdef STEED
  91. 			    if (u.usteed) dismount_steed(DISMOUNT_FELL);
  92. #endif
  93. 			    selftouch("As you fall, you");
  94. 			}
  95. 		    }
  96. 		}
  97. 	    }
  98. 	}
  99.  
  100. 	/* can't rely on u.uz0 for detecting trap door-induced level change;
  101. 	   it gets changed to reflect the new level before we can check it */
  102. 	assign_level(&current_dungeon_level, &u.uz);
  103.  
  104. 	if(trap)
  105. 		switch(trap->ttyp) {
  106. 		case STATUE_TRAP:
  107. 			break;
  108. 		case HOLE:
  109. 		case TRAPDOOR:
  110. 			if(!Can_fall_thru(&u.uz) || u.ustuck)
  111. 				break;
  112. 			/* fall into next case */
  113. 		default:
  114. 			if (!u.utrap) /* not already in the trap */
  115. 				dotrap(trap, 0);
  116. 	}
  117.  
  118. 	if (!Is_airlevel(&u.uz) && !Is_waterlevel(&u.uz) && !u.uswallow &&
  119. 		/* falling through trap door calls goto_level,
  120. 		   and goto_level does its own pickup() call */
  121. 		on_level(&u.uz, &current_dungeon_level))
  122. 	    (void) pickup(1);
  123. 	return 1;
  124. }

dofiretrap[edit]

  1. STATIC_OVL void
  2. dofiretrap(box)
  3. struct obj *box;	/* null for floor trap */
  4. {
  5. 	boolean see_it = !Blind;
  6. 	int num, alt;
  7.  
  8. /* Bug: for box case, the equivalent of burn_floor_paper() ought
  9. * to be done upon its contents.
  10. */
  11.  
  12. 	if ((box && !carried(box)) ? is_pool(box->ox, box->oy) : Underwater) {
  13. 	    pline("A cascade of steamy bubbles erupts from %s!",
  14. 		    the(box ? xname(box) : surface(u.ux,u.uy)));
  15. 	    if (Fire_resistance) You("are uninjured.");
  16. 	    else losehp(rnd(3), "boiling water", KILLED_BY);
  17. 	    return;
  18. 	}
  19. 	pline("A %s %s from %s!", tower_of_flame,
  20. 	      box ? "bursts" : "erupts",
  21. 	      the(box ? xname(box) : surface(u.ux,u.uy)));
  22. 	if (Fire_resistance) {
  23. 	    shieldeff(u.ux, u.uy);
  24. 	    num = rn2(2);
  25. 	} else if (Upolyd) {
  26. 	    num = d(2,4);
  27. 	    switch (u.umonnum) {
  28. 	    case PM_PAPER_GOLEM:   alt = u.mhmax; break;
  29. 	    case PM_STRAW_GOLEM:   alt = u.mhmax / 2; break;
  30. 	    case PM_WOOD_GOLEM:    alt = u.mhmax / 4; break;
  31. 	    case PM_LEATHER_GOLEM: alt = u.mhmax / 8; break;
  32. 	    default: alt = 0; break;
  33. 	    }
  34. 	    if (alt > num) num = alt;
  35. 	    if (u.mhmax > mons[u.umonnum].mlevel)
  36. 		u.mhmax -= rn2(min(u.mhmax,num + 1)), flags.botl = 1;
  37. 	} else {
  38. 	    num = d(2,4);
  39. 	    if (u.uhpmax > u.ulevel)
  40. 		u.uhpmax -= rn2(min(u.uhpmax,num + 1)), flags.botl = 1;
  41. 	}
  42. 	if (!num)
  43. 	    You("are uninjured.");
  44. 	else
  45. 	    losehp(num, tower_of_flame, KILLED_BY_AN);
  46. 	burn_away_slime();
  47.  
  48. 	if (burnarmor(&youmonst) || rn2(3)) {
  49. 	    destroy_item(SCROLL_CLASS, AD_FIRE);
  50. 	    destroy_item(SPBOOK_CLASS, AD_FIRE);
  51. 	    destroy_item(POTION_CLASS, AD_FIRE);
  52. 	}
  53. 	if (!box && burn_floor_paper(u.ux, u.uy, see_it, TRUE) && !see_it)
  54. 	    You("smell paper burning.");
  55. 	if (is_ice(u.ux, u.uy))
  56. 	    melt_ice(u.ux, u.uy);
  57. }

domagictrap[edit]

  1. STATIC_OVL void
  2. domagictrap()
  3. {
  4. 	register int fate = rnd(20);
  5.  
  6. 	/* What happened to the poor sucker? */
  7.  
  8. 	if (fate < 10) {
  9. 	  /* Most of the time, it creates some monsters. */
  10. 	  register int cnt = rnd(4);
  11.  
  12. 	  if (!resists_blnd(&youmonst)) {
  13. 		You("are momentarily blinded by a flash of light!");
  14. 		make_blinded((long)rn1(5,10),FALSE);
  15. 		if (!Blind) Your(vision_clears);
  16. 	  } else if (!Blind) {
  17. 		You("see a flash of light!");
  18. 	  }  else
  19. 		You_hear("a deafening roar!");
  20. 	  while(cnt--)
  21. 		(void) makemon((struct permonst *) 0, u.ux, u.uy, NO_MM_FLAGS);
  22. 	}
  23. 	else
  24. 	  switch (fate) {
  25.  
  26. 	     case 10:
  27. 	     case 11:
  28. 		      /* sometimes nothing happens */
  29. 			break;
  30. 	     case 12: /* a flash of fire */
  31. 			dofiretrap((struct obj *)0);
  32. 			break;
  33.  
  34. 	     /* odd feelings */
  35. 	     case 13:	pline("A shiver runs up and down your %s!",
  36. 			      body_part(SPINE));
  37. 			break;
  38. 	     case 14:	You_hear(Hallucination ?
  39. 				"the moon howling at you." :
  40. 				"distant howling.");
  41. 			break;
  42. 	     case 15:	if (on_level(&u.uz, &qstart_level))
  43. 			    You_feel("%slike the prodigal son.",
  44. 			      (flags.female || (Upolyd && is_neuter(youmonst.data))) ?
  45. 				     "oddly " : "");
  46. 			else
  47. 			    You("suddenly yearn for %s.",
  48. 				Hallucination ? "Cleveland" :
  49. 			    (In_quest(&u.uz) || at_dgn_entrance("The Quest")) ?
  50. 						"your nearby homeland" :
  51. 						"your distant homeland");
  52. 			break;
  53. 	     case 16:   Your("pack shakes violently!");
  54. 			break;
  55. 	     case 17:	You(Hallucination ?
  56. 				"smell hamburgers." :
  57. 				"smell charred flesh.");
  58. 			break;
  59. 	     case 18:	You_feel("tired.");
  60. 			break;
  61.  
  62. 	     /* very occasionally something nice happens. */
  63.  
  64. 	     case 19:
  65. 		    /* tame nearby monsters */
  66. 		   {   register int i,j;
  67. 		       register struct monst *mtmp;
  68.  
  69. 		       (void) adjattrib(A_CHA,1,FALSE);
  70. 		       for(i = -1; i <= 1; i++) for(j = -1; j <= 1; j++) {
  71. 			   if(!isok(u.ux+i, u.uy+j)) continue;
  72. 			   mtmp = m_at(u.ux+i, u.uy+j);
  73. 			   if(mtmp)
  74. 			       (void) tamedog(mtmp, (struct obj *)0);
  75. 		       }
  76. 		       break;
  77. 		   }
  78.  
  79. 	     case 20:
  80. 		    /* uncurse stuff */
  81. 		   {	struct obj pseudo;
  82. 			long save_conf = HConfusion;
  83.  
  84. 			pseudo = zeroobj;   /* neither cursed nor blessed */
  85. 			pseudo.otyp = SCR_REMOVE_CURSE;
  86. 			HConfusion = 0L;
  87. 			(void) seffects(&pseudo);
  88. 			HConfusion = save_conf;
  89. 			break;
  90. 		   }
  91. 	     default: break;
  92. 	  }
  93. }

fire_damage[edit]

  1. /*
  2. * Scrolls, spellbooks, potions, and flammable items
  3. * may get affected by the fire.
  4. *
  5. * Return number of objects destroyed. --ALI
  6. */
  7. int
  8. fire_damage(chain, force, here, x, y)
  9. struct obj *chain;
  10. boolean force, here;
  11. xchar x, y;
  12. {
  13. int chance;
  14. struct obj *obj, *otmp, *nobj, *ncobj;
  15. int retval = 0;
  16. int in_sight = !Blind && couldsee(x, y);	/* Don't care if it's lit */
  17. int dindx;
  18.  
  19. for (obj = chain; obj; obj = nobj) {
  20. 	nobj = here ? obj->nexthere : obj->nobj;
  21.  
  22. 	/* object might light in a controlled manner */
  23. 	if (catch_lit(obj))
  24. 	    continue;
  25.  
  26. 	if (Is_container(obj)) {
  27. 	    switch (obj->otyp) {
  28. 	    case ICE_BOX:
  29. 		continue;		/* Immune */
  30. 		/*NOTREACHED*/
  31. 		break;
  32. 	    case CHEST:
  33. 		chance = 40;
  34. 		break;
  35. 	    case LARGE_BOX:
  36. 		chance = 30;
  37. 		break;
  38. 	    default:
  39. 		chance = 20;
  40. 		break;
  41. 	    }
  42. 	    if (!force && (Luck + 5) > rn2(chance))
  43. 		continue;
  44. 	    /* Container is burnt up - dump contents out */
  45. 	    if (in_sight) pline("%s catches fire and burns.", Yname2(obj));
  46. 	    if (Has_contents(obj)) {
  47. 		if (in_sight) pline("Its contents fall out.");
  48. 		for (otmp = obj->cobj; otmp; otmp = ncobj) {
  49. 		    ncobj = otmp->nobj;
  50. 		    obj_extract_self(otmp);
  51. 		    if (!flooreffects(otmp, x, y, ""))
  52. 			place_object(otmp, x, y);
  53. 		}
  54. 	    }
  55. 	    delobj(obj);
  56. 	    retval++;
  57. 	} else if (!force && (Luck + 5) > rn2(20)) {
  58. 	    /*  chance per item of sustaining damage:
  59. 	     *	max luck (full moon):	 5%
  60. 	     *	max luck (elsewhen):	10%
  61. 	     *	avg luck (Luck==0):	75%
  62. 	     *	awful luck (Luck<-4):  100%
  63. 	     */
  64. 	    continue;
  65. 	} else if (obj->oclass == SCROLL_CLASS || obj->oclass == SPBOOK_CLASS) {
  66. 	    if (obj->otyp == SCR_FIRE || obj->otyp == SPE_FIREBALL)
  67. 		continue;
  68. 	    if (obj->otyp == SPE_BOOK_OF_THE_DEAD) {
  69. 		if (in_sight) pline("Smoke rises from %s.", the(xname(obj)));
  70. 		continue;
  71. 	    }
  72. 	    dindx = (obj->oclass == SCROLL_CLASS) ? 2 : 3;
  73. 	    if (in_sight)
  74. 		pline("%s %s.", Yname2(obj), (obj->quan > 1) ?
  75. 		      destroy_strings[dindx*3 + 1] : destroy_strings[dindx*3]);
  76. 	    delobj(obj);
  77. 	    retval++;
  78. 	} else if (obj->oclass == POTION_CLASS) {
  79. 	    dindx = 1;
  80. 	    if (in_sight)
  81. 		pline("%s %s.", Yname2(obj), (obj->quan > 1) ?
  82. 		      destroy_strings[dindx*3 + 1] : destroy_strings[dindx*3]);
  83. 	    delobj(obj);
  84. 	    retval++;
  85. 	} else if (is_flammable(obj) && obj->oeroded < MAX_ERODE &&
  86. 		   !(obj->oerodeproof || (obj->blessed && !rnl(4)))) {
  87. 	    if (in_sight) {
  88. 		pline("%s %s%s.", Yname2(obj), otense(obj, "burn"),
  89. 		      obj->oeroded+1 == MAX_ERODE ? " completely" :
  90. 		      obj->oeroded ? " further" : "");
  91. 	    }
  92. 	    obj->oeroded++;
  93. 	}
  94. }
  95.  
  96. if (retval && !in_sight)
  97. 	You("smell smoke.");
  98. return retval;
  99. }

water_damage[edit]

  1. void
  2. water_damage(obj, force, here)
  3. register struct obj *obj;
  4. register boolean force, here;
  5. {
  6. 	struct obj *otmp;
  7.  
  8. 	/* Scrolls, spellbooks, potions, weapons and
  9. 	   pieces of armor may get affected by the water */
  10. 	for (; obj; obj = otmp) {
  11. 		otmp = here ? obj->nexthere : obj->nobj;
  12.  
  13. 		(void) snuff_lit(obj);
  14.  
  15. 		if(obj->otyp == CAN_OF_GREASE && obj->spe > 0) {
  16. 			continue;
  17. 		} else if(obj->greased) {
  18. 			if (force || !rn2(2)) obj->greased = 0;
  19. 		} else if(Is_container(obj) && !Is_box(obj) &&
  20. 			(obj->otyp != OILSKIN_SACK || (obj->cursed && !rn2(3)))) {
  21. 			water_damage(obj->cobj, force, FALSE);
  22. 		} else if (!force && (Luck + 5) > rn2(20)) {
  23. 			/*  chance per item of sustaining damage:
  24. 			 *	max luck (full moon):	 5%
  25. 			 *	max luck (elsewhen):	10%
  26. 			 *	avg luck (Luck==0):	75%
  27. 			 *	awful luck (Luck<-4):  100%
  28. 			 */
  29. 			continue;
  30. 		} else if (obj->oclass == SCROLL_CLASS) {
  31. #ifdef MAIL
  32. 		    if (obj->otyp != SCR_MAIL)
  33. #endif
  34. 		    {
  35. 			obj->otyp = SCR_BLANK_PAPER;
  36. 			obj->spe = 0;
  37. 		    }
  38. 		} else if (obj->oclass == SPBOOK_CLASS) {
  39. 			if (obj->otyp == SPE_BOOK_OF_THE_DEAD)
  40. 				pline("Steam rises from %s.", the(xname(obj)));
  41. 			else obj->otyp = SPE_BLANK_PAPER;
  42. 		} else if (obj->oclass == POTION_CLASS) {
  43. 			if (obj->otyp == POT_ACID) {
  44. 				/* damage player/monster? */
  45. 				pline("A potion explodes!");
  46. 				delobj(obj);
  47. 				continue;
  48. 			} else if (obj->odiluted) {
  49. 				obj->otyp = POT_WATER;
  50. 				obj->blessed = obj->cursed = 0;
  51. 				obj->odiluted = 0;
  52. 			} else if (obj->otyp != POT_WATER)
  53. 				obj->odiluted++;
  54. 		} else if (is_rustprone(obj) && obj->oeroded < MAX_ERODE &&
  55. 			  !(obj->oerodeproof || (obj->blessed && !rnl(4)))) {
  56. 			/* all metal stuff and armor except (body armor
  57. 			   protected by oilskin cloak) */
  58. 			if(obj->oclass != ARMOR_CLASS || obj != uarm ||
  59. 			   !uarmc || uarmc->otyp != OILSKIN_CLOAK ||
  60. 			   (uarmc->cursed && !rn2(3)))
  61. 				obj->oeroded++;
  62. 		}
  63. 	}
  64. }

emergency_disrobe[edit]

  1. /*
  2. * This function is potentially expensive - rolling
  3. * inventory list multiple times.  Luckily it's seldom needed.
  4. * Returns TRUE if disrobing made player unencumbered enough to
  5. * crawl out of the current predicament.
  6. */
  7. STATIC_OVL boolean
  8. emergency_disrobe(lostsome)
  9. boolean *lostsome;
  10. {
  11. 	int invc = inv_cnt();
  12.  
  13. 	while (near_capacity() > (Punished ? UNENCUMBERED : SLT_ENCUMBER)) {
  14. 	    register struct obj *obj, *otmp = (struct obj *)0;
  15. 	    register int i;
  16.  
  17. 	    /* Pick a random object */
  18. 	    if (invc > 0) {
  19. 		i = rn2(invc);
  20. 		for (obj = invent; obj; obj = obj->nobj) {
  21. 		    /*
  22. 		     * Undroppables are: body armor, boots, gloves,
  23. 		     * amulets, and rings because of the time and effort
  24. 		     * in removing them + loadstone and other cursed stuff
  25. 		     * for obvious reasons.
  26. 		     */
  27. 		    if (!((obj->otyp == LOADSTONE && obj->cursed) ||
  28. 			  obj == uamul || obj == uleft || obj == uright ||
  29. 			  obj == ublindf || obj == uarm || obj == uarmc ||
  30. 			  obj == uarmg || obj == uarmf ||
  31. #ifdef TOURIST
  32. 			  obj == uarmu ||
  33. #endif
  34. 			  (obj->cursed && (obj == uarmh || obj == uarms)) ||
  35. 			  welded(obj)))
  36. 			otmp = obj;
  37. 		    /* reached the mark and found some stuff to drop? */
  38. 		    if (--i < 0 && otmp) break;
  39.  
  40. 		    /* else continue */
  41. 		}
  42. 	    }
  43. #ifndef GOLDOBJ
  44. 	    if (!otmp) {
  45. 		/* Nothing available left to drop; try gold */
  46. 		if (u.ugold) {
  47. 		    pline("In desperation, you drop your purse.");
  48. 		    /* Hack: gold is not in the inventory, so make a gold object
  49. 		     * and put it at the head of the inventory list.
  50. 		     */
  51. 		    obj = mkgoldobj(u.ugold);    /* removes from u.ugold */
  52. 		    obj->in_use = TRUE;
  53. 		    u.ugold = obj->quan;         /* put the gold back */
  54. 		    assigninvlet(obj);           /* might end up as NOINVSYM */
  55. 		    obj->nobj = invent;
  56. 		    invent = obj;
  57. 		    *lostsome = TRUE;
  58. 		    dropx(obj);
  59. 		    continue;                    /* Try again */
  60. 		}
  61. 		/* We can't even drop gold! */
  62. 		return (FALSE);
  63. 	    }
  64. #else
  65. 	    if (!otmp) return (FALSE); /* nothing to drop! */	
  66. #endif
  67. 	    if (otmp->owornmask) remove_worn_item(otmp, FALSE);
  68. 	    *lostsome = TRUE;
  69. 	    dropx(otmp);
  70. 	    invc--;
  71. 	}
  72. 	return(TRUE);
  73. }

drown[edit]

  1. /*
  2. *  return(TRUE) == player relocated
  3. */
  4. boolean
  5. drown()
  6. {
  7. 	boolean inpool_ok = FALSE, crawl_ok;
  8. 	int i, x, y;
  9.  
  10. 	/* happily wading in the same contiguous pool */
  11. 	if (u.uinwater && is_pool(u.ux-u.dx,u.uy-u.dy) &&
  12. 	    (Swimming || Amphibious)) {
  13. 		/* water effects on objects every now and then */
  14. 		if (!rn2(5)) inpool_ok = TRUE;
  15. 		else return(FALSE);
  16. 	}
  17.  
  18. 	if (!u.uinwater) {
  19. 	    You("%s into the water%c",
  20. 		Is_waterlevel(&u.uz) ? "plunge" : "fall",
  21. 		Amphibious || Swimming ? '.' : '!');
  22. 	    if (!Swimming && !Is_waterlevel(&u.uz))
  23. 		    You("sink like %s.",
  24. 			Hallucination ? "the Titanic" : "a rock");
  25. 	}
  26.  
  27. 	water_damage(invent, FALSE, FALSE);
  28.  
  29. 	if (u.umonnum == PM_GREMLIN && rn2(3))
  30. 	    (void)split_mon(&youmonst, (struct monst *)0);
  31. 	else if (u.umonnum == PM_IRON_GOLEM) {
  32. 	    You("rust!");
  33. 	    i = d(2,6);
  34. 	    if (u.mhmax > i) u.mhmax -= i;
  35. 	    losehp(i, "rusting away", KILLED_BY);
  36. 	}
  37. 	if (inpool_ok) return(FALSE);
  38.  
  39. 	if ((i = number_leashed()) > 0) {
  40. 		pline_The("leash%s slip%s loose.",
  41. 			(i > 1) ? "es" : "",
  42. 			(i > 1) ? "" : "s");
  43. 		unleash_all();
  44. 	}
  45.  
  46. 	if (Amphibious || Swimming) {
  47. 		if (Amphibious) {
  48. 			if (flags.verbose)
  49. 				pline("But you aren't drowning.");
  50. 			if (!Is_waterlevel(&u.uz)) {
  51. 				if (Hallucination)
  52. 					Your("keel hits the bottom.");
  53. 				else
  54. 					You("touch bottom.");
  55. 			}
  56. 		}
  57. 		if (Punished) {
  58. 			unplacebc();
  59. 			placebc();
  60. 		}
  61. 		vision_recalc(2);	/* unsee old position */
  62. 		u.uinwater = 1;
  63. 		under_water(1);
  64. 		vision_full_recalc = 1;
  65. 		return(FALSE);
  66. 	}
  67. 	if ((Teleportation || can_teleport(youmonst.data)) &&
  68. 		    !u.usleep && (Teleport_control || rn2(3) < Luck+2)) {
  69. 		You("attempt a teleport spell.");	/* utcsri!carroll */
  70. 		if (!level.flags.noteleport) {
  71. 			(void) dotele();
  72. 			if(!is_pool(u.ux,u.uy))
  73. 				return(TRUE);
  74. 		} else pline_The("attempted teleport spell fails.");
  75. 	}
  76. #ifdef STEED
  77. 	if (u.usteed) {
  78. 		dismount_steed(DISMOUNT_GENERIC);
  79. 		if(!is_pool(u.ux,u.uy))
  80. 			return(TRUE);
  81. 	}
  82. #endif
  83. 	crawl_ok = FALSE;
  84. 	x = y = 0;		/* lint suppression */
  85. 	/* if sleeping, wake up now so that we don't crawl out of water
  86. 	   while still asleep; we can't do that the same way that waking
  87. 	   due to combat is handled; note unmul() clears u.usleep */
  88. 	if (u.usleep) unmul("Suddenly you wake up!");
  89. 	/* can't crawl if unable to move (crawl_ok flag stays false) */
  90. 	if (multi < 0 || (Upolyd && !youmonst.data->mmove)) goto crawl;
  91. 	/* look around for a place to crawl to */
  92. 	for (i = 0; i < 100; i++) {
  93. 		x = rn1(3,u.ux - 1);
  94. 		y = rn1(3,u.uy - 1);
  95. 		if (goodpos(x, y, &youmonst, 0)) {
  96. 			crawl_ok = TRUE;
  97. 			goto crawl;
  98. 		}
  99. 	}
  100. 	/* one more scan */
  101. 	for (x = u.ux - 1; x <= u.ux + 1; x++)
  102. 		for (y = u.uy - 1; y <= u.uy + 1; y++)
  103. 			if (goodpos(x, y, &youmonst, 0)) {
  104. 				crawl_ok = TRUE;
  105. 				goto crawl;
  106. 			}
  107. crawl:
  108. 	if (crawl_ok) {
  109. 		boolean lost = FALSE;
  110. 		/* time to do some strip-tease... */
  111. 		boolean succ = Is_waterlevel(&u.uz) ? TRUE :
  112. 				emergency_disrobe(&lost);
  113.  
  114. 		You("try to crawl out of the water.");
  115. 		if (lost)
  116. 			You("dump some of your gear to lose weight...");
  117. 		if (succ) {
  118. 			pline("Pheew!  That was close.");
  119. 			teleds(x,y,TRUE);
  120. 			return(TRUE);
  121. 		}
  122. 		/* still too much weight */
  123. 		pline("But in vain.");
  124. 	}
  125. 	u.uinwater = 1;
  126. 	You("drown.");
  127. 	killer_format = KILLED_BY_AN;
  128. 	killer = (levl[u.ux][u.uy].typ == POOL || Is_medusa_level(&u.uz)) ?
  129. 	    "pool of water" : "moat";
  130. 	done(DROWNING);
  131. 	/* oops, we're still alive.  better get out of the water. */
  132. 	while (!safe_teleds(TRUE)) {
  133. 		pline("You're still drowning.");
  134. 		done(DROWNING);
  135. 	}
  136. 	if (u.uinwater) {
  137. 	    u.uinwater = 0;
  138. 	    You("find yourself back %s.", Is_waterlevel(&u.uz) ?
  139. 		"in an air bubble" : "on land");
  140. 	}
  141. 	return(TRUE);
  142. }

drain_en[edit]

  1. void
  2. drain_en(n)
  3. register int n;
  4. {
  5. 	if (!u.uenmax) return;
  6. 	You_feel("your magical energy drain away!");
  7. 	u.uen -= n;
  8. 	if(u.uen < 0)  {
  9. 		u.uenmax += u.uen;
  10. 		if(u.uenmax < 0) u.uenmax = 0;
  11. 		u.uen = 0;
  12. 	}
  13. 	flags.botl = 1;
  14. }

dountrap[edit]

  1. int
  2. dountrap()	/* disarm a trap */
  3. {
  4. 	if (near_capacity() >= HVY_ENCUMBER) {
  5. 	    pline("You're too strained to do that.");
  6. 	    return 0;
  7. 	}
  8. 	if ((nohands(youmonst.data) && !webmaker(youmonst.data)) || !youmonst.data->mmove) {
  9. 	    pline("And just how do you expect to do that?");
  10. 	    return 0;
  11. 	} else if (u.ustuck && sticks(youmonst.data)) {
  12. 	    pline("You'll have to let go of %s first.", mon_nam(u.ustuck));
  13. 	    return 0;
  14. 	}
  15. 	if (u.ustuck || (welded(uwep) && bimanual(uwep))) {
  16. 	    Your("%s seem to be too busy for that.",
  17. 		 makeplural(body_part(HAND)));
  18. 	    return 0;
  19. 	}
  20. 	return untrap(FALSE);
  21. }
  22. #endif /* OVLB */
  23. #ifdef OVL2

untrap_prob[edit]

  1. /* Probability of disabling a trap.  Helge Hafting */
  2. STATIC_OVL int
  3. untrap_prob(ttmp)
  4. struct trap *ttmp;
  5. {
  6. 	int chance = 3;
  7.  
  8. 	/* Only spiders know how to deal with webs reliably */
  9. 	if (ttmp->ttyp == WEB && !webmaker(youmonst.data))
  10. 	 	chance = 30;
  11. 	if (Confusion || Hallucination) chance++;
  12. 	if (Blind) chance++;
  13. 	if (Stunned) chance += 2;
  14. 	if (Fumbling) chance *= 2;
  15. 	/* Your own traps are better known than others. */
  16. 	if (ttmp && ttmp->madeby_u) chance--;
  17. 	if (Role_if(PM_ROGUE)) {
  18. 	    if (rn2(2 * MAXULEV) < u.ulevel) chance--;
  19. 	    if (u.uhave.questart && chance > 1) chance--;
  20. 	} else if (Role_if(PM_RANGER) && chance > 1) chance--;
  21. 	return rn2(chance);
  22. }

cnv_trap_obj[edit]

  1. /* Replace trap with object(s).  Helge Hafting */
  2. STATIC_OVL void
  3. cnv_trap_obj(otyp, cnt, ttmp)
  4. int otyp;
  5. int cnt;
  6. struct trap *ttmp;
  7. {
  8. 	struct obj *otmp = mksobj(otyp, TRUE, FALSE);
  9. 	otmp->quan=cnt;
  10. 	otmp->owt = weight(otmp);
  11. 	/* Only dart traps are capable of being poisonous */
  12. 	if (otyp != DART)
  13. 	    otmp->opoisoned = 0;
  14. 	place_object(otmp, ttmp->tx, ttmp->ty);
  15. 	/* Sell your own traps only... */
  16. 	if (ttmp->madeby_u) sellobj(otmp, ttmp->tx, ttmp->ty);
  17. 	stackobj(otmp);
  18. 	newsym(ttmp->tx, ttmp->ty);
  19. 	deltrap(ttmp);
  20. }

move_into_trap[edit]

  1. /* while attempting to disarm an adjacent trap, we've fallen into it */
  2. STATIC_OVL void
  3. move_into_trap(ttmp)
  4. struct trap *ttmp;
  5. {
  6. 	int bc;
  7. 	xchar x = ttmp->tx, y = ttmp->ty, bx, by, cx, cy;
  8. 	boolean unused;
  9.  
  10. 	/* we know there's no monster in the way, and we're not trapped */
  11. 	if (!Punished || drag_ball(x, y, &bc, &bx, &by, &cx, &cy, &unused,
  12. 		TRUE)) {
  13. 	    u.ux0 = u.ux,  u.uy0 = u.uy;
  14. 	    u.ux = x,  u.uy = y;
  15. 	    u.umoved = TRUE;
  16. 	    newsym(u.ux0, u.uy0);
  17. 	    vision_recalc(1);
  18. 	    check_leash(u.ux0, u.uy0);
  19. 	    if (Punished) move_bc(0, bc, bx, by, cx, cy);
  20. 	    spoteffects(FALSE);	/* dotrap() */
  21. 	    exercise(A_WIS, FALSE);
  22. 	}
  23. }

try_disarm[edit]

  1. /* 0: doesn't even try
  2. * 1: tries and fails
  3. * 2: succeeds
  4. */
  5. STATIC_OVL int
  6. try_disarm(ttmp, force_failure)
  7. struct trap *ttmp;
  8. boolean force_failure;
  9. {
  10. 	struct monst *mtmp = m_at(ttmp->tx,ttmp->ty);
  11. 	int ttype = ttmp->ttyp;
  12. 	boolean under_u = (!u.dx && !u.dy);
  13. 	boolean holdingtrap = (ttype == BEAR_TRAP || ttype == WEB);
  14.  
  15. 	/* Test for monster first, monsters are displayed instead of trap. */
  16. 	if (mtmp && (!mtmp->mtrapped || !holdingtrap)) {
  17. 		pline("%s is in the way.", Monnam(mtmp));
  18. 		return 0;
  19. 	}
  20. 	/* We might be forced to move onto the trap's location. */
  21. 	if (sobj_at(BOULDER, ttmp->tx, ttmp->ty)
  22. 				&& !Passes_walls && !under_u) {
  23. 		There("is a boulder in your way.");
  24. 		return 0;
  25. 	}
  26. 	/* duplicate tight-space checks from test_move */
  27. 	if (u.dx && u.dy &&
  28. 	    bad_rock(youmonst.data,u.ux,ttmp->ty) &&
  29. 	    bad_rock(youmonst.data,ttmp->tx,u.uy)) {
  30. 	    if ((invent && (inv_weight() + weight_cap() > 600)) ||
  31. 		bigmonst(youmonst.data)) {
  32. 		/* don't allow untrap if they can't get thru to it */
  33. 		You("are unable to reach the %s!",
  34. 		    defsyms[trap_to_defsym(ttype)].explanation);
  35. 		return 0;
  36. 	    }
  37. 	}
  38. 	/* untrappable traps are located on the ground. */
  39. 	if (!can_reach_floor()) {
  40. #ifdef STEED
  41. 		if (u.usteed && P_SKILL(P_RIDING) < P_BASIC)
  42. 			You("aren't skilled enough to reach from %s.",
  43. 				mon_nam(u.usteed));
  44. 		else
  45. #endif
  46. 		You("are unable to reach the %s!",
  47. 			defsyms[trap_to_defsym(ttype)].explanation);
  48. 		return 0;
  49. 	}
  50.  
  51. 	/* Will our hero succeed? */
  52. 	if (force_failure || untrap_prob(ttmp)) {
  53. 		if (rnl(5)) {
  54. 		    pline("Whoops...");
  55. 		    if (mtmp) {		/* must be a trap that holds monsters */
  56. 			if (ttype == BEAR_TRAP) {
  57. 			    if (mtmp->mtame) abuse_dog(mtmp);
  58. 			    if ((mtmp->mhp -= rnd(4)) <= 0) killed(mtmp);
  59. 			} else if (ttype == WEB) {
  60. 			    if (!webmaker(youmonst.data)) {
  61. 				struct trap *ttmp2 = maketrap(u.ux, u.uy, WEB);
  62. 				if (ttmp2) {
  63. 				    pline_The("webbing sticks to you. You're caught too!");
  64. 				    dotrap(ttmp2, NOWEBMSG);
  65. #ifdef STEED
  66. 				    if (u.usteed && u.utrap) {
  67. 					/* you, not steed, are trapped */
  68. 					dismount_steed(DISMOUNT_FELL);
  69. 				    }
  70. #endif
  71. 				}
  72. 			    } else
  73. 				pline("%s remains entangled.", Monnam(mtmp));
  74. 			}
  75. 		    } else if (under_u) {
  76. 			dotrap(ttmp, 0);
  77. 		    } else {
  78. 			move_into_trap(ttmp);
  79. 		    }
  80. 		} else {
  81. 		    pline("%s %s is difficult to %s.",
  82. 			  ttmp->madeby_u ? "Your" : under_u ? "This" : "That",
  83. 			  defsyms[trap_to_defsym(ttype)].explanation,
  84. 			  (ttype == WEB) ? "remove" : "disarm");
  85. 		}
  86. 		return 1;
  87. 	}
  88. 	return 2;
  89. }

reward_untrap[edit]

  1. STATIC_OVL void
  2. reward_untrap(ttmp, mtmp)
  3. struct trap *ttmp;
  4. struct monst *mtmp;
  5. {
  6. 	if (!ttmp->madeby_u) {
  7. 	    if (rnl(10) < 8 && !mtmp->mpeaceful &&
  8. 		    !mtmp->msleeping && !mtmp->mfrozen &&
  9. 		    !mindless(mtmp->data) &&
  10. 		    mtmp->data->mlet != S_HUMAN) {
  11. 		mtmp->mpeaceful = 1;
  12. 		set_malign(mtmp);	/* reset alignment */
  13. 		pline("%s is grateful.", Monnam(mtmp));
  14. 	    }
  15. 	    /* Helping someone out of a trap is a nice thing to do,
  16. 	     * A lawful may be rewarded, but not too often.  */
  17. 	    if (!rn2(3) && !rnl(8) && u.ualign.type == A_LAWFUL) {
  18. 		adjalign(1);
  19. 		You_feel("that you did the right thing.");
  20. 	    }
  21. 	}
  22. }

disarm_holdingtrap[edit]

  1. STATIC_OVL int
  2. disarm_holdingtrap(ttmp) /* Helge Hafting */
  3. struct trap *ttmp;
  4. {
  5. 	struct monst *mtmp;
  6. 	int fails = try_disarm(ttmp, FALSE);
  7.  
  8. 	if (fails < 2) return fails;
  9.  
  10. 	/* ok, disarm it. */
  11.  
  12. 	/* untrap the monster, if any.
  13. 	   There's no need for a cockatrice test, only the trap is touched */
  14. 	if ((mtmp = m_at(ttmp->tx,ttmp->ty)) != 0) {
  15. 		mtmp->mtrapped = 0;
  16. 		You("remove %s %s from %s.", the_your[ttmp->madeby_u],
  17. 			(ttmp->ttyp == BEAR_TRAP) ? "bear trap" : "webbing",
  18. 			mon_nam(mtmp));
  19. 		reward_untrap(ttmp, mtmp);
  20. 	} else {
  21. 		if (ttmp->ttyp == BEAR_TRAP) {
  22. 			You("disarm %s bear trap.", the_your[ttmp->madeby_u]);
  23. 			cnv_trap_obj(BEARTRAP, 1, ttmp);
  24. 		} else /* if (ttmp->ttyp == WEB) */ {
  25. 			You("succeed in removing %s web.", the_your[ttmp->madeby_u]);
  26. 			deltrap(ttmp);
  27. 		}
  28. 	}
  29. 	newsym(u.ux + u.dx, u.uy + u.dy);
  30. 	return 1;
  31. }

disarm_landmine[edit]

  1. STATIC_OVL int
  2. disarm_landmine(ttmp) /* Helge Hafting */
  3. struct trap *ttmp;
  4. {
  5. 	int fails = try_disarm(ttmp, FALSE);
  6.  
  7. 	if (fails < 2) return fails;
  8. 	You("disarm %s land mine.", the_your[ttmp->madeby_u]);
  9. 	cnv_trap_obj(LAND_MINE, 1, ttmp);
  10. 	return 1;
  11. }
  1. /* getobj will filter down to cans of grease and known potions of oil */
  2. static NEARDATA const char oil[] = { ALL_CLASSES, TOOL_CLASS, POTION_CLASS, 0 };

disarm_squeaky_board[edit]

  1. /* it may not make much sense to use grease on floor boards, but so what? */
  2. STATIC_OVL int
  3. disarm_squeaky_board(ttmp)
  4. struct trap *ttmp;
  5. {
  6. 	struct obj *obj;
  7. 	boolean bad_tool;
  8. 	int fails;
  9.  
  10. 	obj = getobj(oil, "untrap with");
  11. 	if (!obj) return 0;
  12.  
  13. 	bad_tool = (obj->cursed ||
  14. 			((obj->otyp != POT_OIL || obj->lamplit) &&
  15. 			 (obj->otyp != CAN_OF_GREASE || !obj->spe)));
  16.  
  17. 	fails = try_disarm(ttmp, bad_tool);
  18. 	if (fails < 2) return fails;
  19.  
  20. 	/* successfully used oil or grease to fix squeaky board */
  21. 	if (obj->otyp == CAN_OF_GREASE) {
  22. 	    consume_obj_charge(obj, TRUE);
  23. 	} else {
  24. 	    useup(obj);	/* oil */
  25. 	    makeknown(POT_OIL);
  26. 	}
  27. 	You("repair the squeaky board.");	/* no madeby_u */
  28. 	deltrap(ttmp);
  29. 	newsym(u.ux + u.dx, u.uy + u.dy);
  30. 	more_experienced(1, 5);
  31. 	newexplevel();
  32. 	return 1;
  33. }

disarm_shooting_trap[edit]

  1. /* removes traps that shoot arrows, darts, etc. */
  2. STATIC_OVL int
  3. disarm_shooting_trap(ttmp, otyp)
  4. struct trap *ttmp;
  5. int otyp;
  6. {
  7. 	int fails = try_disarm(ttmp, FALSE);
  8.  
  9. 	if (fails < 2) return fails;
  10. 	You("disarm %s trap.", the_your[ttmp->madeby_u]);
  11. 	cnv_trap_obj(otyp, 50-rnl(50), ttmp);
  12. 	return 1;
  13. }

try_lift[edit]

  1. /* Is the weight too heavy?
  2. * Formula as in near_capacity() & check_capacity() */
  3. STATIC_OVL int
  4. try_lift(mtmp, ttmp, wt, stuff)
  5. struct monst *mtmp;
  6. struct trap *ttmp;
  7. int wt;
  8. boolean stuff;
  9. {
  10. 	int wc = weight_cap();
  11.  
  12. 	if (((wt * 2) / wc) >= HVY_ENCUMBER) {
  13. 	    pline("%s is %s for you to lift.", Monnam(mtmp),
  14. 		  stuff ? "carrying too much" : "too heavy");
  15. 	    if (!ttmp->madeby_u && !mtmp->mpeaceful && mtmp->mcanmove &&
  16. 		    !mindless(mtmp->data) &&
  17. 		    mtmp->data->mlet != S_HUMAN && rnl(10) < 3) {
  18. 		mtmp->mpeaceful = 1;
  19. 		set_malign(mtmp);		/* reset alignment */
  20. 		pline("%s thinks it was nice of you to try.", Monnam(mtmp));
  21. 	    }
  22. 	    return 0;
  23. 	}
  24. 	return 1;
  25. }

help_monster_out[edit]

  1. /* Help trapped monster (out of a (spiked) pit) */
  2. STATIC_OVL int
  3. help_monster_out(mtmp, ttmp)
  4. struct monst *mtmp;
  5. struct trap *ttmp;
  6. {
  7. 	int wt;
  8. 	struct obj *otmp;
  9. 	boolean uprob;
  10.  
  11. 	/*
  12. 	 * This works when levitating too -- consistent with the ability
  13. 	 * to hit monsters while levitating.
  14. 	 *
  15. 	 * Should perhaps check that our hero has arms/hands at the
  16. 	 * moment.  Helping can also be done by engulfing...
  17. 	 *
  18. 	 * Test the monster first - monsters are displayed before traps.
  19. 	 */
  20. 	if (!mtmp->mtrapped) {
  21. 		pline("%s isn't trapped.", Monnam(mtmp));
  22. 		return 0;
  23. 	}
  24. 	/* Do you have the necessary capacity to lift anything? */
  25. 	if (check_capacity((char *)0)) return 1;
  26.  
  27. 	/* Will our hero succeed? */
  28. 	if ((uprob = untrap_prob(ttmp)) && !mtmp->msleeping && mtmp->mcanmove) {
  29. 		You("try to reach out your %s, but %s backs away skeptically.",
  30. 			makeplural(body_part(ARM)),
  31. 			mon_nam(mtmp));
  32. 		return 1;
  33. 	}
  34.  
  35.  
  36. 	/* is it a cockatrice?... */
  37. 	if (touch_petrifies(mtmp->data) && !uarmg && !Stone_resistance) {
  38. 		You("grab the trapped %s using your bare %s.",
  39. 				mtmp->data->mname, makeplural(body_part(HAND)));
  40.  
  41. 		if (poly_when_stoned(youmonst.data) && polymon(PM_STONE_GOLEM))
  42. 			display_nhwindow(WIN_MESSAGE, FALSE);
  43. 		else {
  44. 			char kbuf[BUFSZ];
  45.  
  46. 			Sprintf(kbuf, "trying to help %s out of a pit",
  47. 					an(mtmp->data->mname));
  48. 			instapetrify(kbuf);
  49. 			return 1;
  50. 		}
  51. 	}
  52. 	/* need to do cockatrice check first if sleeping or paralyzed */
  53. 	if (uprob) {
  54. 	    You("try to grab %s, but cannot get a firm grasp.",
  55. 		mon_nam(mtmp));
  56. 	    if (mtmp->msleeping) {
  57. 		mtmp->msleeping = 0;
  58. 		pline("%s awakens.", Monnam(mtmp));
  59. 	    }
  60. 	    return 1;
  61. 	}
  62.  
  63. 	You("reach out your %s and grab %s.",
  64. 	    makeplural(body_part(ARM)), mon_nam(mtmp));
  65.  
  66. 	if (mtmp->msleeping) {
  67. 	    mtmp->msleeping = 0;
  68. 	    pline("%s awakens.", Monnam(mtmp));
  69. 	} else if (mtmp->mfrozen && !rn2(mtmp->mfrozen)) {
  70. 	    /* After such manhandling, perhaps the effect wears off */
  71. 	    mtmp->mcanmove = 1;
  72. 	    mtmp->mfrozen = 0;
  73. 	    pline("%s stirs.", Monnam(mtmp));
  74. 	}
  75.  
  76. 	/* is the monster too heavy? */
  77. 	wt = inv_weight() + mtmp->data->cwt;
  78. 	if (!try_lift(mtmp, ttmp, wt, FALSE)) return 1;
  79.  
  80. 	/* is the monster with inventory too heavy? */
  81. 	for (otmp = mtmp->minvent; otmp; otmp = otmp->nobj)
  82. 		wt += otmp->owt;
  83. 	if (!try_lift(mtmp, ttmp, wt, TRUE)) return 1;
  84.  
  85. 	You("pull %s out of the pit.", mon_nam(mtmp));
  86. 	mtmp->mtrapped = 0;
  87. 	fill_pit(mtmp->mx, mtmp->my);
  88. 	reward_untrap(ttmp, mtmp);
  89. 	return 1;
  90. }

untrap[edit]

  1. int
  2. untrap(force)
  3. boolean force;
  4. {
  5. 	register struct obj *otmp;
  6. 	register boolean confused = (Confusion > 0 || Hallucination > 0);
  7. 	register int x,y;
  8. 	int ch;
  9. 	struct trap *ttmp;
  10. 	struct monst *mtmp;
  11. 	boolean trap_skipped = FALSE;
  12. 	boolean box_here = FALSE;
  13. 	boolean deal_with_floor_trap = FALSE;
  14. 	char the_trap[BUFSZ], qbuf[QBUFSZ];
  15. 	int containercnt = 0;
  16.  
  17. 	if(!getdir((char *)0)) return(0);
  18. 	x = u.ux + u.dx;
  19. 	y = u.uy + u.dy;
  20.  
  21. 	for(otmp = level.objects[x][y]; otmp; otmp = otmp->nexthere) {
  22. 		if(Is_box(otmp) && !u.dx && !u.dy) {
  23. 			box_here = TRUE;
  24. 			containercnt++;
  25. 			if (containercnt > 1) break;
  26. 		}
  27. 	}
  28.  
  29. 	if ((ttmp = t_at(x,y)) && ttmp->tseen) {
  30. 		deal_with_floor_trap = TRUE;
  31. 		Strcpy(the_trap, the(defsyms[trap_to_defsym(ttmp->ttyp)].explanation));
  32. 		if (box_here) {
  33. 			if (ttmp->ttyp == PIT || ttmp->ttyp == SPIKED_PIT) {
  34. 			    You_cant("do much about %s%s.",
  35. 					the_trap, u.utrap ?
  36. 					" that you're stuck in" :
  37. 					" while standing on the edge of it");
  38. 			    trap_skipped = TRUE;
  39. 			    deal_with_floor_trap = FALSE;
  40. 			} else {
  41. 			    Sprintf(qbuf, "There %s and %s here. %s %s?",
  42. 				(containercnt == 1) ? "is a container" : "are containers",
  43. 				an(defsyms[trap_to_defsym(ttmp->ttyp)].explanation),
  44. 				ttmp->ttyp == WEB ? "Remove" : "Disarm", the_trap);
  45. 			    switch (ynq(qbuf)) {
  46. 				case 'q': return(0);
  47. 				case 'n': trap_skipped = TRUE;
  48. 					  deal_with_floor_trap = FALSE;
  49. 					  break;
  50. 			    }
  51. 			}
  52. 		}
  53. 		if (deal_with_floor_trap) {
  54. 		    if (u.utrap) {
  55. 			You("cannot deal with %s while trapped%s!", the_trap,
  56. 				(x == u.ux && y == u.uy) ? " in it" : "");
  57. 			return 1;
  58. 		    }
  59. 		    switch(ttmp->ttyp) {
  60. 			case BEAR_TRAP:
  61. 			case WEB:
  62. 				return disarm_holdingtrap(ttmp);
  63. 			case LANDMINE:
  64. 				return disarm_landmine(ttmp);
  65. 			case SQKY_BOARD:
  66. 				return disarm_squeaky_board(ttmp);
  67. 			case DART_TRAP:
  68. 				return disarm_shooting_trap(ttmp, DART);
  69. 			case ARROW_TRAP:
  70. 				return disarm_shooting_trap(ttmp, ARROW);
  71. 			case PIT:
  72. 			case SPIKED_PIT:
  73. 				if (!u.dx && !u.dy) {
  74. 				    You("are already on the edge of the pit.");
  75. 				    return 0;
  76. 				}
  77. 				if (!(mtmp = m_at(x,y))) {
  78. 				    pline("Try filling the pit instead.");
  79. 				    return 0;
  80. 				}
  81. 				return help_monster_out(mtmp, ttmp);
  82. 			default:
  83. 				You("cannot disable %s trap.", (u.dx || u.dy) ? "that" : "this");
  84. 				return 0;
  85. 		    }
  86. 		}
  87. 	} /* end if */
  88.  
  89. 	if(!u.dx && !u.dy) {
  90. 	    for(otmp = level.objects[x][y]; otmp; otmp = otmp->nexthere)
  91. 		if(Is_box(otmp)) {
  92. 		    Sprintf(qbuf, "There is %s here. Check it for traps?",
  93. 			safe_qbuf("", sizeof("There is  here. Check it for traps?"),
  94. 				doname(otmp), an(simple_typename(otmp->otyp)), "a box"));
  95. 		    switch (ynq(qbuf)) {
  96. 			case 'q': return(0);
  97. 			case 'n': continue;
  98. 		    }
  99. #ifdef STEED
  100. 		    if (u.usteed && P_SKILL(P_RIDING) < P_BASIC) {
  101. 			You("aren't skilled enough to reach from %s.",
  102. 				mon_nam(u.usteed));
  103. 			return(0);
  104. 		    }
  105. #endif
  106. 		    if((otmp->otrapped && (force || (!confused
  107. 				&& rn2(MAXULEV + 1 - u.ulevel) < 10)))
  108. 		       || (!force && confused && !rn2(3))) {
  109. 			You("find a trap on %s!", the(xname(otmp)));
  110. 			if (!confused) exercise(A_WIS, TRUE);
  111.  
  112. 			switch (ynq("Disarm it?")) {
  113. 			    case 'q': return(1);
  114. 			    case 'n': trap_skipped = TRUE;  continue;
  115. 			}
  116.  
  117. 			if(otmp->otrapped) {
  118. 			    exercise(A_DEX, TRUE);
  119. 			    ch = ACURR(A_DEX) + u.ulevel;
  120. 			    if (Role_if(PM_ROGUE)) ch *= 2;
  121. 			    if(!force && (confused || Fumbling ||
  122. 				rnd(75+level_difficulty()/2) > ch)) {
  123. 				(void) chest_trap(otmp, FINGER, TRUE);
  124. 			    } else {
  125. 				You("disarm it!");
  126. 				otmp->otrapped = 0;
  127. 			    }
  128. 			} else pline("That %s was not trapped.", xname(otmp));
  129. 			return(1);
  130. 		    } else {
  131. 			You("find no traps on %s.", the(xname(otmp)));
  132. 			return(1);
  133. 		    }
  134. 		}
  135.  
  136. 	    You(trap_skipped ? "find no other traps here."
  137. 			     : "know of no traps here.");
  138. 	    return(0);
  139. 	}
  140.  
  141. 	if ((mtmp = m_at(x,y))				&&
  142. 		mtmp->m_ap_type == M_AP_FURNITURE	&&
  143. 		(mtmp->mappearance == S_hcdoor ||
  144. 			mtmp->mappearance == S_vcdoor)	&&
  145. 		!Protection_from_shape_changers)	 {
  146.  
  147. 	    stumble_onto_mimic(mtmp);
  148. 	    return(1);
  149. 	}
  150.  
  151. 	if (!IS_DOOR(levl[x][y].typ)) {
  152. 	    if ((ttmp = t_at(x,y)) && ttmp->tseen)
  153. 		You("cannot disable that trap.");
  154. 	    else
  155. 		You("know of no traps there.");
  156. 	    return(0);
  157. 	}
  158.  
  159. 	switch (levl[x][y].doormask) {
  160. 	    case D_NODOOR:
  161. 		You("%s no door there.", Blind ? "feel" : "see");
  162. 		return(0);
  163. 	    case D_ISOPEN:
  164. 		pline("This door is safely open.");
  165. 		return(0);
  166. 	    case D_BROKEN:
  167. 		pline("This door is broken.");
  168. 		return(0);
  169. 	}
  170.  
  171. 	if ((levl[x][y].doormask & D_TRAPPED
  172. 	     && (force ||
  173. 		 (!confused && rn2(MAXULEV - u.ulevel + 11) < 10)))
  174. 	    || (!force && confused && !rn2(3))) {
  175. 		You("find a trap on the door!");
  176. 		exercise(A_WIS, TRUE);
  177. 		if (ynq("Disarm it?") != 'y') return(1);
  178. 		if (levl[x][y].doormask & D_TRAPPED) {
  179. 		    ch = 15 + (Role_if(PM_ROGUE) ? u.ulevel*3 : u.ulevel);
  180. 		    exercise(A_DEX, TRUE);
  181. 		    if(!force && (confused || Fumbling ||
  182. 				     rnd(75+level_difficulty()/2) > ch)) {
  183. 			You("set it off!");
  184. 			b_trapped("door", FINGER);
  185. 			levl[x][y].doormask = D_NODOOR;
  186. 			unblock_point(x, y);
  187. 			newsym(x, y);
  188. 			/* (probably ought to charge for this damage...) */
  189. 			if (*in_rooms(x, y, SHOPBASE)) add_damage(x, y, 0L);
  190. 		    } else {
  191. 			You("disarm it!");
  192. 			levl[x][y].doormask &= ~D_TRAPPED;
  193. 		    }
  194. 		} else pline("This door was not trapped.");
  195. 		return(1);
  196. 	} else {
  197. 		You("find no traps on the door.");
  198. 		return(1);
  199. 	}
  200. }
  201. #endif /* OVL2 */
  202. #ifdef OVLB

chest_trap[edit]

  1. /* only called when the player is doing something to the chest directly */
  2. boolean
  3. chest_trap(obj, bodypart, disarm)
  4. register struct obj *obj;
  5. register int bodypart;
  6. boolean disarm;
  7. {
  8. 	register struct obj *otmp = obj, *otmp2;
  9. 	char	buf[80];
  10. 	const char *msg;
  11. 	coord cc;
  12.  
  13. 	if (get_obj_location(obj, &cc.x, &cc.y, 0))	/* might be carried */
  14. 	    obj->ox = cc.x,  obj->oy = cc.y;
  15.  
  16. 	otmp->otrapped = 0;	/* trap is one-shot; clear flag first in case
  17. 				   chest kills you and ends up in bones file */
  18. 	You(disarm ? "set it off!" : "trigger a trap!");
  19. 	display_nhwindow(WIN_MESSAGE, FALSE);
  20. 	if (Luck > -13 && rn2(13+Luck) > 7) {	/* saved by luck */
  21. 	    /* trap went off, but good luck prevents damage */
  22. 	    switch (rn2(13)) {
  23. 		case 12:
  24. 		case 11:  msg = "explosive charge is a dud";  break;
  25. 		case 10:
  26. 		case  9:  msg = "electric charge is grounded";  break;
  27. 		case  8:
  28. 		case  7:  msg = "flame fizzles out";  break;
  29. 		case  6:
  30. 		case  5:
  31. 		case  4:  msg = "poisoned needle misses";  break;
  32. 		case  3:
  33. 		case  2:
  34. 		case  1:
  35. 		case  0:  msg = "gas cloud blows away";  break;
  36. 		default:  impossible("chest disarm bug");  msg = (char *)0;
  37. 			  break;
  38. 	    }
  39. 	    if (msg) pline("But luckily the %s!", msg);
  40. 	} else {
  41. 	    switch(rn2(20) ? ((Luck >= 13) ? 0 : rn2(13-Luck)) : rn2(26)) {
  42. 		case 25:
  43. 		case 24:
  44. 		case 23:
  45. 		case 22:
  46. 		case 21: {
  47. 			  struct monst *shkp = 0;
  48. 			  long loss = 0L;
  49. 			  boolean costly, insider;
  50. 			  register xchar ox = obj->ox, oy = obj->oy;
  51.  
  52. 			  /* the obj location need not be that of player */
  53. 			  costly = (costly_spot(ox, oy) &&
  54. 				   (shkp = shop_keeper(*in_rooms(ox, oy,
  55. 				    SHOPBASE))) != (struct monst *)0);
  56. 			  insider = (*u.ushops && inside_shop(u.ux, u.uy) &&
  57. 				    *in_rooms(ox, oy, SHOPBASE) == *u.ushops);
  58.  
  59. 			  pline("%s!", Tobjnam(obj, "explode"));
  60. 			  Sprintf(buf, "exploding %s", xname(obj));
  61.  
  62. 			  if(costly)
  63. 			      loss += stolen_value(obj, ox, oy,
  64. 						(boolean)shkp->mpeaceful, TRUE);
  65. 			  delete_contents(obj);
  66. 			  /* we're about to delete all things at this location,
  67. 			   * which could include the ball & chain.
  68. 			   * If we attempt to call unpunish() in the
  69. 			   * for-loop below we can end up with otmp2
  70. 			   * being invalid once the chain is gone.
  71. 			   * Deal with ball & chain right now instead.
  72. 			   */
  73. 			  if (Punished && !carried(uball) &&
  74. 				((uchain->ox == u.ux && uchain->oy == u.uy) ||
  75. 				 (uball->ox == u.ux && uball->oy == u.uy)))
  76. 				unpunish();
  77.  
  78. 			  for(otmp = level.objects[u.ux][u.uy];
  79. 							otmp; otmp = otmp2) {
  80. 			      otmp2 = otmp->nexthere;
  81. 			      if(costly)
  82. 				  loss += stolen_value(otmp, otmp->ox,
  83. 					  otmp->oy, (boolean)shkp->mpeaceful,
  84. 					  TRUE);
  85. 			      delobj(otmp);
  86. 			  }
  87. 			  wake_nearby();
  88. 			  losehp(d(6,6), buf, KILLED_BY_AN);
  89. 			  exercise(A_STR, FALSE);
  90. 			  if(costly && loss) {
  91. 			      if(insider)
  92. 			      You("owe %ld %s for objects destroyed.",
  93. 							loss, currency(loss));
  94. 			      else {
  95. 				  You("caused %ld %s worth of damage!",
  96. 							loss, currency(loss));
  97. 				  make_angry_shk(shkp, ox, oy);
  98. 			      }
  99. 			  }
  100. 			  return TRUE;
  101. 			}
  102. 		case 20:
  103. 		case 19:
  104. 		case 18:
  105. 		case 17:
  106. 			pline("A cloud of noxious gas billows from %s.",
  107. 							the(xname(obj)));
  108. 			poisoned("gas cloud", A_STR, "cloud of poison gas",15);
  109. 			exercise(A_CON, FALSE);
  110. 			break;
  111. 		case 16:
  112. 		case 15:
  113. 		case 14:
  114. 		case 13:
  115. 			You_feel("a needle prick your %s.",body_part(bodypart));
  116. 			poisoned("needle", A_CON, "poisoned needle",10);
  117. 			exercise(A_CON, FALSE);
  118. 			break;
  119. 		case 12:
  120. 		case 11:
  121. 		case 10:
  122. 		case 9:
  123. 			dofiretrap(obj);
  124. 			break;
  125. 		case 8:
  126. 		case 7:
  127. 		case 6: {
  128. 			int dmg;
  129.  
  130. 			You("are jolted by a surge of electricity!");
  131. 			if(Shock_resistance)  {
  132. 			    shieldeff(u.ux, u.uy);
  133. 			    You("don't seem to be affected.");
  134. 			    dmg = 0;
  135. 			} else
  136. 			    dmg = d(4, 4);
  137. 			destroy_item(RING_CLASS, AD_ELEC);
  138. 			destroy_item(WAND_CLASS, AD_ELEC);
  139. 			if (dmg) losehp(dmg, "electric shock", KILLED_BY_AN);
  140. 			break;
  141. 		      }
  142. 		case 5:
  143. 		case 4:
  144. 		case 3:
  145. 			if (!Free_action) {                        
  146. 			pline("Suddenly you are frozen in place!");
  147. 			nomul(-d(5, 6));
  148. 			exercise(A_DEX, FALSE);
  149. 			nomovemsg = You_can_move_again;
  150. 			} else You("momentarily stiffen.");
  151. 			break;
  152. 		case 2:
  153. 		case 1:
  154. 		case 0:
  155. 			pline("A cloud of %s gas billows from %s.",
  156. 				Blind ? blindgas[rn2(SIZE(blindgas))] :
  157. 				rndcolor(), the(xname(obj)));
  158. 			if(!Stunned) {
  159. 			    if (Hallucination)
  160. 				pline("What a groovy feeling!");
  161. 			    else if (Blind)
  162. 				You("%s and get dizzy...",
  163. 				    stagger(youmonst.data, "stagger"));
  164. 			    else
  165. 				You("%s and your vision blurs...",
  166. 				    stagger(youmonst.data, "stagger"));
  167. 			}
  168. 			make_stunned(HStun + rn1(7, 16),FALSE);
  169. 			(void) make_hallucinated(HHallucination + rn1(5, 16),FALSE,0L);
  170. 			break;
  171. 		default: impossible("bad chest trap");
  172. 			break;
  173. 	    }
  174. 	    bot();			/* to get immediate botl re-display */
  175. 	}
  176.  
  177. 	return FALSE;
  178. }
  179.  
  180. #endif /* OVLB */
  181. #ifdef OVL0

t_at[edit]

t_at() takes two parameters, an x,y coordinate, and returns a trap at that location, or NULL if no trap there.

  1. struct trap *
  2. t_at(x,y)
  3. register int x, y;
  4. {
  5. 	register struct trap *trap = ftrap;
  6. 	while(trap) {
  7. 		if(trap->tx == x && trap->ty == y) return(trap);
  8. 		trap = trap->ntrap;
  9. 	}
  10. 	return((struct trap *)0);
  11. }
  12.  
  13. #endif /* OVL0 */
  14. #ifdef OVLB

deltrap[edit]

  1. void
  2. deltrap(trap)
  3. register struct trap *trap;
  4. {
  5. 	register struct trap *ttmp;
  6.  
  7. 	if(trap == ftrap)
  8. 		ftrap = ftrap->ntrap;
  9. 	else {
  10. 		for(ttmp = ftrap; ttmp->ntrap != trap; ttmp = ttmp->ntrap) ;
  11. 		ttmp->ntrap = trap->ntrap;
  12. 	}
  13. 	dealloc_trap(trap);
  14. }

delfloortrap[edit]

  1. boolean
  2. delfloortrap(ttmp)
  3. register struct trap *ttmp;
  4. {
  5. 	/* Destroy a trap that emanates from the floor. */
  6. 	/* some of these are arbitrary -dlc */
  7. 	if (ttmp && ((ttmp->ttyp == SQKY_BOARD) ||
  8. 		     (ttmp->ttyp == BEAR_TRAP) ||
  9. 		     (ttmp->ttyp == LANDMINE) ||
  10. 		     (ttmp->ttyp == FIRE_TRAP) ||
  11. 		     (ttmp->ttyp == PIT) ||
  12. 		     (ttmp->ttyp == SPIKED_PIT) ||
  13. 		     (ttmp->ttyp == HOLE) ||
  14. 		     (ttmp->ttyp == TRAPDOOR) ||
  15. 		     (ttmp->ttyp == TELEP_TRAP) ||
  16. 		     (ttmp->ttyp == LEVEL_TELEP) ||
  17. 		     (ttmp->ttyp == WEB) ||
  18. 		     (ttmp->ttyp == MAGIC_TRAP) ||
  19. 		     (ttmp->ttyp == ANTI_MAGIC))) {
  20. 	    register struct monst *mtmp;
  21.  
  22. 	    if (ttmp->tx == u.ux && ttmp->ty == u.uy) {
  23. 		u.utrap = 0;
  24. 		u.utraptype = 0;
  25. 	    } else if ((mtmp = m_at(ttmp->tx, ttmp->ty)) != 0) {
  26. 		mtmp->mtrapped = 0;
  27. 	    }
  28. 	    deltrap(ttmp);
  29. 	    return TRUE;
  30. 	} else
  31. 	    return FALSE;
  32. }

b_trapped[edit]

  1. /* used for doors (also tins).  can be used for anything else that opens. */
  2. void
  3. b_trapped(item, bodypart)
  4. register const char *item;
  5. register int bodypart;
  6. {
  7. 	register int lvl = level_difficulty();
  8. 	int dmg = rnd(5 + (lvl < 5 ? lvl : 2+lvl/2));
  9.  
  10. 	pline("KABOOM!!  %s was booby-trapped!", The(item));
  11. 	wake_nearby();
  12. 	losehp(dmg, "explosion", KILLED_BY_AN);
  13. 	exercise(A_STR, FALSE);
  14. 	if (bodypart) exercise(A_CON, FALSE);
  15. 	make_stunned(HStun + dmg, TRUE);
  16. }

thitm[edit]

  1. /* Monster is hit by trap. */
  2. /* Note: doesn't work if both obj and d_override are null */
  3. STATIC_OVL boolean
  4. thitm(tlev, mon, obj, d_override, nocorpse)
  5. int tlev;
  6. struct monst *mon;
  7. struct obj *obj;
  8. int d_override;
  9. boolean nocorpse;
  10. {
  11. 	int strike;
  12. 	boolean trapkilled = FALSE;
  13.  
  14. 	if (d_override) strike = 1;
  15. 	else if (obj) strike = (find_mac(mon) + tlev + obj->spe <= rnd(20));
  16. 	else strike = (find_mac(mon) + tlev <= rnd(20));
  17.  
  18. 	/* Actually more accurate than thitu, which doesn't take
  19. 	 * obj->spe into account.
  20. 	 */
  21. 	if(!strike) {
  22. 		if (obj && cansee(mon->mx, mon->my))
  23. 		    pline("%s is almost hit by %s!", Monnam(mon), doname(obj));
  24. 	} else {
  25. 		int dam = 1;
  26.  
  27. 		if (obj && cansee(mon->mx, mon->my))
  28. 			pline("%s is hit by %s!", Monnam(mon), doname(obj));
  29. 		if (d_override) dam = d_override;
  30. 		else if (obj) {
  31. 			dam = dmgval(obj, mon);
  32. 			if (dam < 1) dam = 1;
  33. 		}
  34. 		if ((mon->mhp -= dam) <= 0) {
  35. 			int xx = mon->mx;
  36. 			int yy = mon->my;
  37.  
  38. 			monkilled(mon, "", nocorpse ? -AD_RBRE : AD_PHYS);
  39. 			if (mon->mhp <= 0) {
  40. 				newsym(xx, yy);
  41. 				trapkilled = TRUE;
  42. 			}
  43. 		}
  44. 	}
  45. 	if (obj && (!strike || d_override)) {
  46. 		place_object(obj, mon->mx, mon->my);
  47. 		stackobj(obj);
  48. 	} else if (obj) dealloc_obj(obj);
  49.  
  50. 	return trapkilled;
  51. }

unconscious[edit]

  1. boolean
  2. unconscious()
  3. {
  4. 	return((boolean)(multi < 0 && (!nomovemsg ||
  5. 		u.usleep ||
  6. 		!strncmp(nomovemsg,"You regain con", 14) ||
  7. 		!strncmp(nomovemsg,"You are consci", 14))));
  8. }

lava_effects[edit]

  1. static const char lava_killer[] = "molten lava";
  2.  
  3. boolean
  4. lava_effects()
  5. {
  6. register struct obj *obj, *obj2;
  7. int dmg;
  8. boolean usurvive;
  9.  
  10. burn_away_slime();
  11. if (likes_lava(youmonst.data)) return FALSE;
  12.  
  13. if (!Fire_resistance) {
  14. 	if(Wwalking) {
  15. 	    dmg = d(6,6);
  16. 	    pline_The("lava here burns you!");
  17. 	    if(dmg < u.uhp) {
  18. 		losehp(dmg, lava_killer, KILLED_BY);
  19. 		goto burn_stuff;
  20. 	    }
  21. 	} else
  22. 	    You("fall into the lava!");
  23.  
  24. 	usurvive = Lifesaved || discover;
  25. #ifdef WIZARD
  26. 	if (wizard) usurvive = TRUE;
  27. #endif
  28. 	for(obj = invent; obj; obj = obj2) {
  29. 	    obj2 = obj->nobj;
  30. 	    if(is_organic(obj) && !obj->oerodeproof) {
  31. 		if(obj->owornmask) {
  32. 		    if (usurvive)
  33. 			Your("%s into flame!", aobjnam(obj, "burst"));
  34.  
  35. 		    if(obj == uarm) (void) Armor_gone();
  36. 		    else if(obj == uarmc) (void) Cloak_off();
  37. 		    else if(obj == uarmh) (void) Helmet_off();
  38. 		    else if(obj == uarms) (void) Shield_off();
  39. 		    else if(obj == uarmg) (void) Gloves_off();
  40. 		    else if(obj == uarmf) (void) Boots_off();
  41. #ifdef TOURIST
  42. 		    else if(obj == uarmu) setnotworn(obj);
  43. #endif
  44. 		    else if(obj == uleft) Ring_gone(obj);
  45. 		    else if(obj == uright) Ring_gone(obj);
  46. 		    else if(obj == ublindf) Blindf_off(obj);
  47. 		    else if(obj == uamul) Amulet_off();
  48. 		    else if(obj == uwep) uwepgone();
  49. 		    else if (obj == uquiver) uqwepgone();
  50. 		    else if (obj == uswapwep) uswapwepgone();
  51. 		}
  52. 		useupall(obj);
  53. 	    }
  54. 	}
  55.  
  56. 	/* s/he died... */
  57. 	u.uhp = -1;
  58. 	killer_format = KILLED_BY;
  59. 	killer = lava_killer;
  60. 	You("burn to a crisp...");
  61. 	done(BURNING);
  62. 	while (!safe_teleds(TRUE)) {
  63. 		pline("You're still burning.");
  64. 		done(BURNING);
  65. 	}
  66. 	You("find yourself back on solid %s.", surface(u.ux, u.uy));
  67. 	return(TRUE);
  68. }
  69.  
  70. if (!Wwalking) {
  71. 	u.utrap = rn1(4, 4) + (rn1(4, 12) << 8);
  72. 	u.utraptype = TT_LAVA;
  73. 	You("sink into the lava, but it only burns slightly!");
  74. 	if (u.uhp > 1)
  75. 	    losehp(1, lava_killer, KILLED_BY);
  76. }
  77. /* just want to burn boots, not all armor; destroy_item doesn't work on
  78. armor anyway */
  79. burn_stuff:
  80. if(uarmf && !uarmf->oerodeproof && is_organic(uarmf)) {
  81. 	/* save uarmf value because Boots_off() sets uarmf to null */
  82. 	obj = uarmf;
  83. 	Your("%s bursts into flame!", xname(obj));
  84. 	(void) Boots_off();
  85. 	useup(obj);
  86. }
  87. destroy_item(SCROLL_CLASS, AD_FIRE);
  88. destroy_item(SPBOOK_CLASS, AD_FIRE);
  89. destroy_item(POTION_CLASS, AD_FIRE);
  90. return(FALSE);
  91. }
  92.  
  93. #endif /* OVLB */
  94.  
  95. /*trap.c*/