From 74ecb4ad57ac84d6e8471a6d6aa2ac1030ef0dcb Mon Sep 17 00:00:00 2001 From: dshaligram Date: Tue, 25 Nov 2008 16:03:36 +0000 Subject: Ditch baroque dgnevent veto mechanism in favour of marker-property-based veto, which is trivial to extend. Also fix turn loss when trying to use a toll portal without enough gold. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@7611 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/acr.cc | 11 ++++++++++ crawl-ref/source/dat/clua/lm_toll.lua | 38 +++++++++++++++++++---------------- crawl-ref/source/dgnevent.h | 5 +---- crawl-ref/source/luadgn.cc | 3 --- crawl-ref/source/mapmark.cc | 7 +++++++ crawl-ref/source/mapmark.h | 2 ++ crawl-ref/source/misc.cc | 11 ++++++---- 7 files changed, 49 insertions(+), 28 deletions(-) (limited to 'crawl-ref/source') diff --git a/crawl-ref/source/acr.cc b/crawl-ref/source/acr.cc index 613ea17f5a..bce6474961 100644 --- a/crawl-ref/source/acr.cc +++ b/crawl-ref/source/acr.cc @@ -1678,6 +1678,11 @@ static bool _stairs_check_beheld() return (false); } +static bool _marker_vetoes_stair() +{ + return marker_vetoes_operation("veto_stair"); +} + static void _go_downstairs(); static void _go_upstairs() { @@ -1713,6 +1718,9 @@ static void _go_upstairs() if (!check_annotation_exclusion_warning()) return; + if (_marker_vetoes_stair()) + return; + tag_followers(); // Only those beside us right now can follow. start_delay( DELAY_ASCENDING_STAIRS, 1 + (you.burden_state > BS_UNENCUMBERED) ); @@ -1759,6 +1767,9 @@ static void _go_downstairs() } else { + if (_marker_vetoes_stair()) + return; + tag_followers(); // only those beside us right now can follow start_delay( DELAY_DESCENDING_STAIRS, 1 + (you.burden_state > BS_UNENCUMBERED), diff --git a/crawl-ref/source/dat/clua/lm_toll.lua b/crawl-ref/source/dat/clua/lm_toll.lua index 3e111e6dba..e48f555cc9 100644 --- a/crawl-ref/source/dat/clua/lm_toll.lua +++ b/crawl-ref/source/dat/clua/lm_toll.lua @@ -22,34 +22,38 @@ function TollStair:activate(marker) marker, marker:pos()) end -function TollStair:event(marker, ev) - if self.super.event(self, marker, ev) then - return true - end - - if ev:type() == dgn.dgn_event_type('v_leave_level') then - -- Have we enough gold? - local gold = you.gold() - local needed = self.props.amount +function TollStair:check_veto(marker, pname) + -- Have we enough gold? + local gold = you.gold() + local needed = self.props.amount - if gold < needed then - crawl.mpr("This portal charges " .. needed .. " gold for entry; " .. - "you have only " .. gold .. " gold.") - return false - end + if gold < needed then + crawl.mpr("This portal charges " .. needed .. " gold for entry; " .. + "you have only " .. gold .. " gold.") + return "veto" + end + if pname == "veto_stair" then -- Ok, ask if the player wants to spend the $$$. if not crawl.yesno("This portal charges " .. needed .. " gold for entry. Pay?", true, "n") then - return false + return "veto" end - + elseif pname == "veto_level_change" then -- Gold gold gold! Forget that gold! you.gold(you.gold() - needed) - return true + return end end +function TollStair:property(marker, pname) + if pname == 'veto_stair' or pname == 'veto_level_change' then + return self:check_veto(marker, pname) + end + + return self.super.property(self, marker, pname) +end + function TollStair:read(marker, th) TollStair.super.read(self, marker, th) setmetatable(self, TollStair) diff --git a/crawl-ref/source/dgnevent.h b/crawl-ref/source/dgnevent.h index 75a0174c06..cff604d2c1 100644 --- a/crawl-ref/source/dgnevent.h +++ b/crawl-ref/source/dgnevent.h @@ -29,10 +29,7 @@ enum dgn_event_type DET_MONSTER_DIED = 0x0100, DET_ITEM_PICKUP = 0x0200, DET_ITEM_MOVED = 0x0400, - DET_FEAT_CHANGE = 0x0800, - - // Vetoable events, usually fired before the corresponding (real) event. - DETV_LEAVE_LEVEL = 0x1000 + DET_FEAT_CHANGE = 0x0800 }; class dgn_event diff --git a/crawl-ref/source/luadgn.cc b/crawl-ref/source/luadgn.cc index 797e367f8c..c4da5054c1 100644 --- a/crawl-ref/source/luadgn.cc +++ b/crawl-ref/source/luadgn.cc @@ -1272,9 +1272,6 @@ 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", "item_moved", "feat_change", - - // vetoable events - "v_leave_level" }; static dgn_event_type dgn_event_type_by_name(const std::string &name) diff --git a/crawl-ref/source/mapmark.cc b/crawl-ref/source/mapmark.cc index 6e4e2f0907..62549b737b 100644 --- a/crawl-ref/source/mapmark.cc +++ b/crawl-ref/source/mapmark.cc @@ -797,3 +797,10 @@ void map_markers::read(reader &inf, int minorVersion) } } } + +///////////////////////////////////////////////////////////////////////// + +bool marker_vetoes_operation(const char *op) +{ + return env.markers.property_at(you.pos(), MAT_ANY, op) == "veto"; +} diff --git a/crawl-ref/source/mapmark.h b/crawl-ref/source/mapmark.h index 5b9862bffe..03be790910 100644 --- a/crawl-ref/source/mapmark.h +++ b/crawl-ref/source/mapmark.h @@ -24,6 +24,8 @@ class reader; class writer; +bool marker_vetoes_operation(const char *op); + class map_marker { public: diff --git a/crawl-ref/source/misc.cc b/crawl-ref/source/misc.cc index e70d5fa9e3..86e91cc8bb 100644 --- a/crawl-ref/source/misc.cc +++ b/crawl-ref/source/misc.cc @@ -1613,6 +1613,11 @@ static void _player_change_level_upstairs(dungeon_feature_type stair_find, } } +static bool _marker_vetoes_level_change() +{ + return (marker_vetoes_operation("veto_level_change")); +} + void up_stairs(dungeon_feature_type force_stair, entry_cause_type entry_cause) { @@ -1677,8 +1682,7 @@ void up_stairs(dungeon_feature_type force_stair, } // Bail if any markers veto the move. - if (!dungeon_events.fire_vetoable_position_event(DETV_LEAVE_LEVEL, - you.pos())) + if (_marker_vetoes_level_change()) return; // Checks are done, the character is committed to moving between levels. @@ -2062,8 +2066,7 @@ void down_stairs( int old_level, dungeon_feature_type force_stair, } // Bail if any markers veto the move. - if (!dungeon_events.fire_vetoable_position_event(DETV_LEAVE_LEVEL, - you.pos())) + if (_marker_vetoes_level_change()) return; const level_id destination_override(_stair_destination_override()); -- cgit v1.2.3-54-g00ecf