diff options
-rw-r--r-- | crawl-ref/source/dat/clua/lm_flags.lua | 16 | ||||
-rw-r--r-- | crawl-ref/source/dat/clua/lm_timed.lua | 2 | ||||
-rw-r--r-- | crawl-ref/source/dgnevent.h | 10 | ||||
-rw-r--r-- | crawl-ref/source/externs.h | 2 | ||||
-rw-r--r-- | crawl-ref/source/items.cc | 9 | ||||
-rw-r--r-- | crawl-ref/source/items.h | 2 | ||||
-rw-r--r-- | crawl-ref/source/luadgn.cc | 20 | ||||
-rw-r--r-- | crawl-ref/source/mapmark.cc | 14 | ||||
-rw-r--r-- | crawl-ref/source/spells4.cc | 2 |
9 files changed, 63 insertions, 14 deletions
diff --git a/crawl-ref/source/dat/clua/lm_flags.lua b/crawl-ref/source/dat/clua/lm_flags.lua index 770c80110e..5719ac85a0 100644 --- a/crawl-ref/source/dat/clua/lm_flags.lua +++ b/crawl-ref/source/dat/clua/lm_flags.lua @@ -312,6 +312,8 @@ end function ItemPickupChangeFlags:activate(marker) dgn.register_listener(dgn.dgn_event_type('item_pickup'), marker, marker:pos()) + dgn.register_listener(dgn.dgn_event_type('item_moved'), marker, + marker:pos()) end function ItemPickupChangeFlags:event(marker, ev) @@ -323,9 +325,17 @@ function ItemPickupChangeFlags:event(marker, ev) end if item.name(it) == self.item then - ChangeFlags.do_change(self, marker) - dgn.remove_listener(marker, marker:pos()) - dgn.remove_marker(marker) + local picked_up = ev:type() == dgn.dgn_event_type('item_pickup') + if picked_up then + ChangeFlags.do_change(self, marker) + dgn.remove_listener(marker, marker:pos()) + dgn.remove_marker(marker) + else + local x, y = ev:dest() + dgn.remove_listener(marker, marker:pos()) + marker:move(ev:dest()) + self:activate(marker) + end end end diff --git a/crawl-ref/source/dat/clua/lm_timed.lua b/crawl-ref/source/dat/clua/lm_timed.lua index 6ad010de75..048698ecbb 100644 --- a/crawl-ref/source/dat/clua/lm_timed.lua +++ b/crawl-ref/source/dat/clua/lm_timed.lua @@ -101,7 +101,7 @@ function TimedMarker:read(marker, th) self.disappear = file.unmarshall_meta(th) self.msg = file.unmarshall_fn(th)(th) setmetatable(self, TimedMarker) - return self + return self end function TimedMarker:write(marker, th) diff --git a/crawl-ref/source/dgnevent.h b/crawl-ref/source/dgnevent.h index df54c3d27b..168bdeaaa2 100644 --- a/crawl-ref/source/dgnevent.h +++ b/crawl-ref/source/dgnevent.h @@ -28,7 +28,8 @@ enum dgn_event_type DET_PLAYER_CLIMBS = 0x0080, // Player climbing stairs. DET_MONSTER_DIED = 0x0100, DET_ITEM_PICKUP = 0x0200, - DET_FEAT_CHANGE = 0x0400 + DET_ITEM_MOVED = 0x0400, + DET_FEAT_CHANGE = 0x0800 }; class dgn_event @@ -38,11 +39,14 @@ public: coord_def place; int elapsed_ticks; long arg1, arg2; + coord_def dest; public: dgn_event(dgn_event_type t, const coord_def &p = coord_def(), - int ticks = you.time_taken, long a1 = 0, long a2 = 0) - : type(t), place(p), elapsed_ticks(ticks), arg1(a1), arg2(a2) + int ticks = you.time_taken, long a1 = 0, long a2 = 0, + const coord_def &d = coord_def()) + : type(t), place(p), elapsed_ticks(ticks), arg1(a1), + arg2(a2), dest(d) { } }; diff --git a/crawl-ref/source/externs.h b/crawl-ref/source/externs.h index 166b1e82b9..4f2d73a671 100644 --- a/crawl-ref/source/externs.h +++ b/crawl-ref/source/externs.h @@ -1311,6 +1311,7 @@ public: map_marker *find(const coord_def &c, map_marker_type type = MAT_ANY); map_marker *find(map_marker_type type); void move(const coord_def &from, const coord_def &to); + void move_marker(map_marker *marker, const coord_def &to); std::vector<map_marker*> get_all(map_marker_type type = MAT_ANY); std::vector<map_marker*> get_all(const std::string &key, const std::string &val = ""); @@ -1327,6 +1328,7 @@ private: typedef std::pair<coord_def, map_marker *> dgn_pos_marker; void init_from(const map_markers &); + void unlink_marker(const map_marker *); private: dgn_marker_map markers; diff --git a/crawl-ref/source/items.cc b/crawl-ref/source/items.cc index 63f2ec5318..93c1d9dad8 100644 --- a/crawl-ref/source/items.cc +++ b/crawl-ref/source/items.cc @@ -1792,14 +1792,17 @@ bool copy_item_to_grid( const item_def &item, int x_plos, int y_plos, // location. // //--------------------------------------------------------------- -bool move_top_item( int src_x, int src_y, int dest_x, int dest_y ) +bool move_top_item( const coord_def &pos, const coord_def &dest ) { - int item = igrd[ src_x ][ src_y ]; + int item = igrd(pos); if (item == NON_ITEM) return (false); + dungeon_events.fire_position_event( + dgn_event(DET_ITEM_MOVED, pos, 0, item, -1, dest), pos); + // Now move the item to its new possition... - move_item_to_grid( &item, dest_x, dest_y ); + move_item_to_grid( &item, dest.x, dest.y ); return (true); } diff --git a/crawl-ref/source/items.h b/crawl-ref/source/items.h index 14bdb971a4..27d0e972da 100644 --- a/crawl-ref/source/items.h +++ b/crawl-ref/source/items.h @@ -101,7 +101,7 @@ bool copy_item_to_grid( const item_def &item, int x_plos, int y_plos, /* *********************************************************************** * called from: spells4.cc * *********************************************************************** */ -bool move_top_item( int src_x, int src_y, int dest_x, int dest_y ); +bool move_top_item( const coord_def &src, const coord_def &dest ); // last updated: 08jun2000 {dlb} /* *********************************************************************** diff --git a/crawl-ref/source/luadgn.cc b/crawl-ref/source/luadgn.cc index 8bd36c5fdc..0c5555dc27 100644 --- a/crawl-ref/source/luadgn.cc +++ b/crawl-ref/source/luadgn.cc @@ -1161,7 +1161,7 @@ static const char *dgn_event_type_names[] = { "none", "turn", "mons_move", "player_move", "leave_level", "entering_level", "entered_level", "player_los", "player_climb", - "monster_dies", "item_pickup", "feat_change" + "monster_dies", "item_pickup", "item_moved", "feat_change" }; static dgn_event_type dgn_event_type_by_name(const std::string &name) @@ -1872,6 +1872,14 @@ static int dgnevent_place(lua_State *ls) return (2); } +static int dgnevent_dest(lua_State *ls) +{ + DEVENT(ls, 1, dev); + lua_pushnumber(ls, dev->dest.x); + lua_pushnumber(ls, dev->dest.y); + return (2); +} + static int dgnevent_ticks(lua_State *ls) { DEVENT(ls, 1, dev); @@ -1894,6 +1902,7 @@ static const struct luaL_reg dgnevent_lib[] = { { "type", dgnevent_type }, { "pos", dgnevent_place }, + { "dest", dgnevent_dest }, { "ticks", dgnevent_ticks }, { "arg1", dgnevent_arg1 }, { "arg2", dgnevent_arg2 }, @@ -1929,9 +1938,18 @@ static int mapmarker_pos(lua_State *ls) return (2); } +static int mapmarker_move(lua_State *ls) +{ + MAPMARKER(ls, 1, mark); + const coord_def dest( luaL_checkint(ls, 2), luaL_checkint(ls, 3) ); + env.markers.move_marker(mark, dest); + return (0); +} + static const struct luaL_reg mapmarker_lib[] = { { "pos", mapmarker_pos }, + { "move", mapmarker_move }, { NULL, NULL } }; diff --git a/crawl-ref/source/mapmark.cc b/crawl-ref/source/mapmark.cc index 90a5dadf48..4cf22b4057 100644 --- a/crawl-ref/source/mapmark.cc +++ b/crawl-ref/source/mapmark.cc @@ -583,7 +583,7 @@ void map_markers::add(map_marker *marker) markers.insert(dgn_pos_marker(marker->pos, marker)); } -void map_markers::remove(map_marker *marker) +void map_markers::unlink_marker(const map_marker *marker) { std::pair<dgn_marker_map::iterator, dgn_marker_map::iterator> els = markers.equal_range(marker->pos); @@ -595,6 +595,11 @@ void map_markers::remove(map_marker *marker) break; } } +} + +void map_markers::remove(map_marker *marker) +{ + unlink_marker(marker); delete marker; } @@ -656,6 +661,13 @@ void map_markers::move(const coord_def &from, const coord_def &to) } } +void map_markers::move_marker(map_marker *marker, const coord_def &to) +{ + unlink_marker(marker); + marker->pos = to; + add(marker); +} + std::vector<map_marker*> map_markers::get_all(map_marker_type mat) { std::vector<map_marker*> rmarkers; diff --git a/crawl-ref/source/spells4.cc b/crawl-ref/source/spells4.cc index c4ee7a0b8c..1c8a86d255 100644 --- a/crawl-ref/source/spells4.cc +++ b/crawl-ref/source/spells4.cc @@ -2651,7 +2651,7 @@ int cast_apportation(int pow) // Failure should never really happen after all the above checking, // but we'll handle it anyways... - if (move_top_item( beam.tx, beam.ty, you.x_pos, you.y_pos )) + if (move_top_item( beam.target(), you.pos() )) { if (max_units < mitm[ item ].quantity) { |