#include #include #include "vars.h" #include "dice.h" #include "pline.h" #include "damage.h" #include "structs.h" #include "display.h" #include "trap.h" /* * Find a trap. */ void findtrap(LOC *lc) { if ((lc->trap & TRAP_KIND) == TRAP_KIND_NONE) panic("findtrap: nothing to find"); lc->trap |= TRAP_KNOWN; if (lc->flags & LF_VISIBLE) upddisp(lc); } /* * m has just moved onto a new location; see if this triggers a trap. * If so, implement it. * * The chance of you tripping it is one in four if it's known, two in * three if it's not (it's easier to avoid a trap if you know it's * there!). The chance of other monsters tripping it is only one in * eight (this is their land, but even they can make mistakes). */ void maybe_trap(MONST *m) { const char *verb; const char *noun; static char *bad = 0; DAMAGE dmg; if ((m->loc->trap & TRAP_KIND) == TRAP_KIND_NONE) return; if ( (m == you) ? (m->loc->trap & TRAP_KNOWN) ? onein(4) : !onein(3) : onein(8) ) { switch (m->loc->trap & TRAP_KIND) { case TRAP_KIND_ARROW: noun = "an arrow trap"; dmg = damage_simple(roll("2d2000"),DK_ORDINARY,0); break; default: free(bad); asprintf(&bad,"a peculiar trap (%d)",m->loc->trap&TRAP_KIND); dmg = damage_simple(1,DK_ORDINARY,0); noun = bad; break; } verb = (m == you) ? "trigger" : "triggers"; if ((m == you) || (m->loc->flags & LF_VISIBLE)) { pline("%s %s %s",(*m->ops->Name)(m),verb,noun); findtrap(m->loc); } if ( ((*m->ops->takedamage)(m,dmg).flags & TDRV_DIED) && (m->loc->flags & LF_VISIBLE) ) { pline("%s dies!",(*m->ops->Name)(m)); } } }