diff options
author | dshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573> | 2008-11-25 14:06:58 +0000 |
---|---|---|
committer | dshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573> | 2008-11-25 14:06:58 +0000 |
commit | ad382c58bd22273fdcb13759bf35e1c89d573e97 (patch) | |
tree | b5c6c0bc9d7d1eeccceb26f9df38e2ac2323489b | |
parent | e7c403614a215df6ba9074c5b0805ec3052d426e (diff) | |
download | crawl-ref-ad382c58bd22273fdcb13759bf35e1c89d573e97.tar.gz crawl-ref-ad382c58bd22273fdcb13759bf35e1c89d573e97.zip |
Clean up TimedMarker to inherit from OneWayStair. Breaks saves.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@7608 c06c8d41-db1a-0410-9941-cceddc491573
-rw-r--r-- | crawl-ref/source/dat/clua/lm_1way.lua | 20 | ||||
-rw-r--r-- | crawl-ref/source/dat/clua/lm_pdesc.lua | 1 | ||||
-rw-r--r-- | crawl-ref/source/dat/clua/lm_timed.lua | 89 | ||||
-rw-r--r-- | crawl-ref/source/dat/clua/luamark.lua | 12 | ||||
-rw-r--r-- | crawl-ref/source/dat/clua/util.lua | 9 | ||||
-rw-r--r-- | crawl-ref/source/dat/clua/ziggurat.lua | 11 |
6 files changed, 67 insertions, 75 deletions
diff --git a/crawl-ref/source/dat/clua/lm_1way.lua b/crawl-ref/source/dat/clua/lm_1way.lua index f390d0dd84..185295c476 100644 --- a/crawl-ref/source/dat/clua/lm_1way.lua +++ b/crawl-ref/source/dat/clua/lm_1way.lua @@ -3,20 +3,19 @@ -- One-way stair marker. ------------------------------------------------------------------------------ -OneWayStair = PortalDescriptor:new() -OneWayStair.__index = OneWayStair - -function OneWayStair:new(props) - local ows = PortalDescriptor.new(self, props) - setmetatable(ows, self) - return ows -end +OneWayStair = util.subclass(PortalDescriptor) function OneWayStair:activate(marker) local ev = dgn.dgn_event_type('player_climb') dgn.register_listener(ev, marker, marker:pos()) end +function OneWayStair:disappear(marker, affect_player, x, y) + dgn.terrain_changed(x, y, self.props.floor or 'floor', affect_player, false) + dgn.remove_listener(marker, x, y) + dgn.remove_marker(marker) +end + function OneWayStair:event(marker, ev) if ev:type() == dgn.dgn_event_type('player_climb') then local x, y = ev:pos() @@ -26,9 +25,8 @@ function OneWayStair:event(marker, ev) self.props.onclimb(self, marker, ev) end - dgn.terrain_changed(x, y, self.props.floor or 'floor', false, false) - dgn.remove_listener(marker, ev:pos()) - dgn.remove_marker(marker) + self:disappear(marker, false, x, y) + return true end end diff --git a/crawl-ref/source/dat/clua/lm_pdesc.lua b/crawl-ref/source/dat/clua/lm_pdesc.lua index a704004872..f2e5cff9b2 100644 --- a/crawl-ref/source/dat/clua/lm_pdesc.lua +++ b/crawl-ref/source/dat/clua/lm_pdesc.lua @@ -9,6 +9,7 @@ PortalDescriptor.__index = PortalDescriptor function PortalDescriptor:new(properties) local pd = { } setmetatable(pd, self) + self.__index = self pd.props = properties return pd end diff --git a/crawl-ref/source/dat/clua/lm_timed.lua b/crawl-ref/source/dat/clua/lm_timed.lua index 71d26bdad2..a70ec69156 100644 --- a/crawl-ref/source/dat/clua/lm_timed.lua +++ b/crawl-ref/source/dat/clua/lm_timed.lua @@ -3,51 +3,45 @@ -- Lua timed map feature markers. ------------------------------------------------------------------------------ -dofile('clua/lm_tmsg.lua') +require('clua/lm_tmsg.lua') +require('clua/lm_1way.lua') -TimedMarker = PortalDescriptor:new() -TimedMarker.__index = TimedMarker +TimedMarker = util.subclass(OneWayStair) -function TimedMarker:_new() - local marker = { } - setmetatable(marker, self) - self.__index = self - return marker -end +function TimedMarker:new(props) + props = props or { } + + local tmarker = self.super.new(self, props) -function TimedMarker:new(pars) - pars = pars or { } - if not pars.msg then + if not props.msg then error("No messaging object provided (msg = nil)") end - pars.high = pars.high or pars.low or pars.turns or 1 - pars.low = pars.low or pars.high or pars.turns or 1 - local dur = crawl.random_range(pars.low, pars.high, pars.navg or 1) - local feat = pars.floor or 'floor' - local fnum = dgn.feature_number(feat) + + props.high = props.high or props.low or props.turns or 1 + props.low = props.low or props.high or props.turns or 1 + + local dur = crawl.random_range(props.low, props.high, props.navg or 1) if fnum == dgn.feature_number('unseen') then error("Bad feature name: " .. feat) end - local tmarker = self:_new() - tmarker.dur = dur * 10 - tmarker.fnum = fnum - tmarker.feat = feat - tmarker.msg = pars.msg - tmarker.disappear = pars.disappear + tmarker.dur = dur * 10 + tmarker.msg = props.msg + + props.msg = nil - if pars.props then - tmarker.props = pars.props - end return tmarker end function TimedMarker:activate(marker, verbose) + self.super.activate(self, marker, verbose) self.msg:init(self, marker, verbose) - dgn.register_listener(dgn.dgn_event_type('turn'), marker) - dgn.register_listener(dgn.dgn_event_type('player_climb'), - marker, marker:pos()) +end + +function TimedMarker:disappear(marker, affect_player, x, y) + dgn.remove_listener(marker) + self.super.disappear(self, marker, affect_player, x, y) end function TimedMarker:timeout(marker, verbose, affect_player) @@ -63,62 +57,51 @@ function TimedMarker:timeout(marker, verbose, affect_player) if verbose then if you.see_grid(marker:pos()) then - crawl.mpr( self.disappear or + crawl.mpr( self.props.disappear or dgn.feature_desc_at(x, y, "The") .. " disappears!") else crawl.mpr("The walls and floor vibrate strangely for a moment.") end end - dgn.terrain_changed(x, y, self.fnum, affect_player, false) - dgn.remove_listener(marker) - dgn.remove_listener(marker, marker:pos()) - dgn.remove_marker(marker) + + self:disappear(marker, affect_player, x, y) end function TimedMarker:event(marker, ev) - self.ticktype = self.ticktype or dgn.dgn_event_type('turn') - self.stairtype = self.stairtype or dgn.dgn_event_type('player_climb') - - if ev:type() == self.stairtype then - local mx, my = marker:pos() - local ex, ey = ev:pos() - if mx == ex and my == ey then - self:timeout(marker, false, false) - end - return + if self.super.event(self, marker, ev) then + return true end + self.ticktype = self.ticktype or dgn.dgn_event_type('turn') + if ev:type() ~= self.ticktype then return end + self.dur = self.dur - ev:ticks() self.msg:event(self, marker, ev) if self.dur <= 0 then self:timeout(marker, true, true) + return true end end function TimedMarker:describe(marker) - return self.feat .. "/" .. tostring(self.dur) + local feat = self.props.floor or 'floor' + return feat .. "/" .. tostring(self.dur) end function TimedMarker:read(marker, th) - PortalDescriptor.read(self, marker, th) + TimedMarker.super.read(self, marker, th) self.dur = file.unmarshall_number(th) - self.fnum = file.unmarshall_number(th) - self.feat = file.unmarshall_string(th) - self.disappear = file.unmarshall_meta(th) self.msg = file.unmarshall_fn(th)(th) setmetatable(self, TimedMarker) return self end function TimedMarker:write(marker, th) - PortalDescriptor.write(self, marker, th) + TimedMarker.super.write(self, marker, th) file.marshall(th, self.dur) - file.marshall(th, self.fnum) - file.marshall(th, self.feat) - file.marshall_meta(th, self.disappear) file.marshall(th, self.msg.read) self.msg:write(th) end diff --git a/crawl-ref/source/dat/clua/luamark.lua b/crawl-ref/source/dat/clua/luamark.lua index af92aaebd8..cd9083e32d 100644 --- a/crawl-ref/source/dat/clua/luamark.lua +++ b/crawl-ref/source/dat/clua/luamark.lua @@ -3,12 +3,12 @@ -- Lua map marker handling. ------------------------------------------------------------------------------ -dofile('clua/lm_pdesc.lua') -dofile('clua/lm_1way.lua') -dofile('clua/lm_timed.lua') -dofile('clua/lm_flags.lua') -dofile('clua/lm_fog.lua') -dofile('clua/lm_props.lua') +require('clua/lm_pdesc.lua') +require('clua/lm_1way.lua') +require('clua/lm_timed.lua') +require('clua/lm_flags.lua') +require('clua/lm_fog.lua') +require('clua/lm_props.lua') function dlua_marker_function(table, name) return table[name] diff --git a/crawl-ref/source/dat/clua/util.lua b/crawl-ref/source/dat/clua/util.lua index 950449f94e..a272cf2339 100644 --- a/crawl-ref/source/dat/clua/util.lua +++ b/crawl-ref/source/dat/clua/util.lua @@ -5,6 +5,15 @@ util = { } +function util.subclass(parent) + -- parent should have no-arg constructor. + local subclass = parent:new() + subclass.super = parent + -- Not strictly necessary - parent constructor should do this. + subclass.__index = subclass + return subclass +end + function util.catlist(...) local res = { } local tables = { ... } diff --git a/crawl-ref/source/dat/clua/ziggurat.lua b/crawl-ref/source/dat/clua/ziggurat.lua index 23df58a59a..9b00eab380 100644 --- a/crawl-ref/source/dat/clua/ziggurat.lua +++ b/crawl-ref/source/dat/clua/ziggurat.lua @@ -57,13 +57,11 @@ local function random_floor_colour() return ziggurat_wall_colour() end --- Returns a function that changes the depth in the ziggurat to the depth --- specified. +-- Increments the depth in the ziggurat when the player takes a +-- downstair in the ziggurat. function zig_depth_increment() zig().depth = zig().depth + 1 zig().level = { } - dgn.set_level_type_name ("Ziggurat:" .. zig().depth) - dgn.set_level_type_origin("on level " .. zig().depth .. " of a ziggurat") end -- Returns the current depth in the ziggurat. @@ -120,8 +118,11 @@ end -- Creates a Lua marker table that increments ziggurat depth. local function zig_go_deeper() + local newdepth = zig().depth + 1 return one_way_stair { - onclimb = zig_depth_increment + onclimb = zig_depth_increment, + dstname = "Ziggurat:" .. newdepth, + dstorigin = "on level " .. newdepth .. " of a ziggurat" } end |