diff options
author | zelgadis <zelgadis@c06c8d41-db1a-0410-9941-cceddc491573> | 2007-12-03 06:54:53 +0000 |
---|---|---|
committer | zelgadis <zelgadis@c06c8d41-db1a-0410-9941-cceddc491573> | 2007-12-03 06:54:53 +0000 |
commit | 38e77f4ea4395ed90f12e880224e5bd378113602 (patch) | |
tree | 87a0ca74f0fc77d59a32fd1317f739cf9ddb1530 /crawl-ref/source/traps.cc | |
parent | cca6195c042a64fed711dba3ea0d94bc78b410df (diff) | |
download | crawl-ref-38e77f4ea4395ed90f12e880224e5bd378113602.tar.gz crawl-ref-38e77f4ea4395ed90f12e880224e5bd378113602.zip |
Items can now fall through shaft traps (trap doors). The code is rather
simplistic, and it's not currently possible to make a "baited" shaft;
also, there is no threshold weight, so even a single dart will open up
(and thus reveal) a shaft trap. Breaks savefile compatibility.
Monsters which fall through a shaft now show up 100% of the time on the
player's next visit to the shaft's destination level. Also, the monster is
placed close to the spot where the player would end up if s/he went through
the same shaft.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@2988 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/traps.cc')
-rw-r--r-- | crawl-ref/source/traps.cc | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/crawl-ref/source/traps.cc b/crawl-ref/source/traps.cc index db6d7b1f49..78bfa5c997 100644 --- a/crawl-ref/source/traps.cc +++ b/crawl-ref/source/traps.cc @@ -25,6 +25,7 @@ #include "misc.h" #include "mon-util.h" #include "monstuff.h" +#include "mtransit.h" #include "ouch.h" #include "place.h" #include "player.h" @@ -960,6 +961,89 @@ bool is_valid_shaft_level(const level_id &place) return ((branch.depth - place.depth) >= min_delta); } +level_id generic_shaft_dest(level_pos lpos) +{ + level_id lid = lpos.id; + coord_def pos = lpos.pos; + + if (lid.level_type != LEVEL_DUNGEON) + return lid; + + int curr_depth = lid.depth; + Branch &branch = branches[lid.branch]; + + lid.depth += ((pos.x + pos.y) % 3) + 1; + + if (lid.depth > branch.depth) + lid.depth = branch.depth; + + if (lid.depth == curr_depth) + return lid; + + // Only shafts on the level immediately above a dangerous branch + // bottom will take you to that dangerous bottom, and shafts can't + // be created during level generation time. + if (branch.dangerous_bottom_level + && lid.depth == branch.depth + && (branch.depth - curr_depth) > 1) + { + lid.depth--; + } + + return lid; +} + +level_id generic_shaft_dest(coord_def pos) +{ + return generic_shaft_dest(level_pos(level_id::current(), pos)); +} + +void handle_items_on_shaft(int x, int y, bool open_shaft) +{ + if (!is_valid_shaft_level()) + return; + + coord_def pos(x, y); + level_id dest = generic_shaft_dest(pos); + + if (dest == level_id::current()) + return; + + int o = igrd(pos); + + if (o == NON_ITEM) + return; + + igrd(pos) = NON_ITEM; + + if (is_terrain_seen(pos) && open_shaft) + { + mpr("A shaft opens up in the floor!"); + grd(pos) = DNGN_TRAP_NATURAL; + } + + while (o != NON_ITEM) + { + int next = mitm[o].link; + + if (is_valid_item( mitm[o] )) + { + if (is_terrain_seen(pos)) + { + mprf("%s falls through the shaft.", + mitm[o].name(DESC_INVENTORY).c_str()); + } + add_item_to_transit(dest, mitm[o]); + + mitm[o].base_type = OBJ_UNASSIGNED; + mitm[o].quantity = 0; + mitm[o].props.clear(); + } + + o = next; + } +} + static int num_traps_default(int level_number, const level_id &place) { return random2avg(9, 2); |