From 0f779d7b62ab133933fd92a2bd1b04c5a2f21500 Mon Sep 17 00:00:00 2001 From: haranp Date: Thu, 2 Oct 2008 20:10:33 +0000 Subject: Fix 2142643: bugs in net traps that I introduced in the trap revamp (noted by dolorous.) Net traps can now trigger outside of your line of sight. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@7084 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/traps.cc | 59 +++++++++++++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 23 deletions(-) (limited to 'crawl-ref/source/traps.cc') diff --git a/crawl-ref/source/traps.cc b/crawl-ref/source/traps.cc index e43e01289d..07661af0dc 100644 --- a/crawl-ref/source/traps.cc +++ b/crawl-ref/source/traps.cc @@ -350,6 +350,10 @@ void trap_def::trigger(actor& triggerer, bool flat_footed) const bool you_trigger = (triggerer.atype() == ACT_PLAYER); const bool in_sight = see_grid(this->pos); + // If set, the trap will be removed at the end of the + // triggering process. + bool trap_destroyed = false; + monsters* m = NULL; if (triggerer.atype() == ACT_MONSTER) m = static_cast(&triggerer); @@ -498,21 +502,26 @@ void trap_def::trigger(actor& triggerer, bool flat_footed) if (you.attribute[ATTR_HELD]) mark_net_trapping(you.pos()); - this->destroy(); + trap_destroyed = true; } } else if (m) { - bool triggered = true; + bool triggered = false; if (one_chance_in(3) || (trig_knows && coinflip())) { + // Not triggered, trap stays. triggered = false; if (you_know) simple_monster_message(m, " fails to trigger a net trap."); + else + this->hide(); } - if (random2(m->ev) > 8 - || (trig_knows && random2(m->ev) > 8)) + else if (random2(m->ev) > 8 || (trig_knows && random2(m->ev) > 8)) { + // Triggered but evaded. + triggered = true; + if (in_sight) { if (!simple_monster_message(m, @@ -522,24 +531,25 @@ void trap_def::trigger(actor& triggerer, bool flat_footed) mpr("A large net falls down!"); } } - else + } + else + { + // Triggered and hit. + triggered = true; + + if (in_sight) { - // FIXME: net traps don't trigger unless you can see - // them? Preserving old behaviour here. - if (in_sight) - { - msg::stream << "A large net falls down"; - if (player_monster_visible(m)) - msg::stream << " onto " << m->name(DESC_NOCAP_THE); - msg::stream << "!" << std::endl; - } - // FIXME: Fake a beam for monster_caught_in_net. - bolt beam; - beam.flavour = BEAM_MISSILE; - beam.thrower = KILL_MISC; - beam.beam_source = NON_MONSTER; - monster_caught_in_net(m, beam); + msg::stream << "A large net falls down"; + if (player_monster_visible(m)) + msg::stream << " onto " << m->name(DESC_NOCAP_THE); + msg::stream << "!" << std::endl; } + // FIXME: Fake a beam for monster_caught_in_net. + bolt beam; + beam.flavour = BEAM_MISSILE; + beam.thrower = KILL_MISC; + beam.beam_source = NON_MONSTER; + monster_caught_in_net(m, beam); } if (triggered) @@ -549,8 +559,8 @@ void trap_def::trigger(actor& triggerer, bool flat_footed) if (mons_is_caught(m)) mark_net_trapping(m->pos()); - - this->destroy(); + + trap_destroyed = true; } } break; @@ -623,7 +633,7 @@ void trap_def::trigger(actor& triggerer, bool flat_footed) if (you_know && in_sight) mpr("The shaft disappears in a puff of logic!"); - this->destroy(); + trap_destroyed = true; } else { @@ -646,6 +656,9 @@ void trap_def::trigger(actor& triggerer, bool flat_footed) if (!you_know && this->is_known()) exercise(SK_TRAPS_DOORS, ((coinflip()) ? 2 : 1)); } + + if (trap_destroyed) + this->destroy(); } int trap_def::shot_damage(actor& act) -- cgit v1.2.3-54-g00ecf