diff options
author | Jude Brown <bookofjude@users.sourceforge.net> | 2009-10-26 19:55:51 +1000 |
---|---|---|
committer | Darshan Shaligram <dshaligram@users.sourceforge.net> | 2009-10-26 15:33:56 +0530 |
commit | 771f91f2670c31b340188c8083e9ef218215dd4f (patch) | |
tree | 0cd93861a1262270064479a15d068117be53ea09 /crawl-ref | |
parent | 32994d1ea7d6158027c5f40de5ec1eedcdfb770d (diff) | |
download | crawl-ref-771f91f2670c31b340188c8083e9ef218215dd4f.tar.gz crawl-ref-771f91f2670c31b340188c8083e9ef218215dd4f.zip |
Persistent table for FunctionMachines. A single table can be passed to multiple markers, allowing for shared access, using the marker_params option (which defaults to a blank table). The table is passed as a second parameter each time the function is called.
Add a message_machine wrapper around function_machine, providing simplified message functionality; change ossuary.des to use this.
Signed-off-by: Darshan Shaligram <dshaligram@users.sourceforge.net>
Diffstat (limited to 'crawl-ref')
-rw-r--r-- | crawl-ref/source/dat/clua/lm_func.lua | 19 | ||||
-rw-r--r-- | crawl-ref/source/dat/ossuary.des | 5 |
2 files changed, 18 insertions, 6 deletions
diff --git a/crawl-ref/source/dat/clua/lm_func.lua b/crawl-ref/source/dat/clua/lm_func.lua index 7326a6125c..7f993b5cf1 100644 --- a/crawl-ref/source/dat/clua/lm_func.lua +++ b/crawl-ref/source/dat/clua/lm_func.lua @@ -21,10 +21,12 @@ -- * "player_at": Calls the function whenever the player is at the -- same position as the marker. Takes the same "repeated" -- parameter as "in_los". +-- marker_table: Table to be passed to the function when called. Defaults to {}. -- -- Specific markers take specific parameters, as listed under marker_type. -- --- The function will be called with the "marker" object as its only parameter. +-- The function will be called with the "marker" object and the table +-- marker_params. -- ------------------------------------------------------------------------------ @@ -78,6 +80,7 @@ function FunctionMachine:new(pars) m.turns_min = pars.turns_min or pars.turns or 0 m.turns_max = pars.turns_max or pars.turns or 0 m.repeated = pars.repeated or false + m.marker_params = pars.marker_params or {} -- Some arithmetic to make these make sense in terms of actual turns -- versus ticks. @@ -89,13 +92,13 @@ end function FunctionMachine:do_function(marker) local _x, _y = marker:pos() - self.func(marker) + self.func(marker, self.marker_params) end function FunctionMachine:activate(marker, verbose) local _x, _y = marker:pos() dgn.register_listener(dgn.dgn_event_type('turn'), marker) - dgn.register_listener(dgn.dgn_event_type('entered_level'), marker) + --dgn.register_listener(dgn.dgn_event_type('entered_level'), marker) end function FunctionMachine:event(marker, ev) @@ -137,6 +140,7 @@ function FunctionMachine:write(marker, th) file.marshall_meta(th, self.turns_min) file.marshall_meta(th, self.turns_max) file.marshall_meta(th, self.repeated) + lmark.marshall_table(th, self.marker_params) end function FunctionMachine:read(marker, th) @@ -147,6 +151,7 @@ function FunctionMachine:read(marker, th) self.turns_min = file.unmarshall_meta(th) self.turns_max = file.unmarshall_meta(th) self.repeated = file.unmarshall_meta(th) + self.marker_params = lmark.unmarshall_table(th) setmetatable(self, FunctionMachine) @@ -156,3 +161,11 @@ end function function_machine(pars) return FunctionMachine:new(pars) end + +function message_machine (pars) + local channel = pars.channel or false + local mtable = {message = pars.message, channel = pars.channel} + pars.func = (function(marker, mtable) crawl.mpr(mtable.message, mtable.channel) end) + pars.marker_params = mtable + return FunctionMachine:new(pars) +end diff --git a/crawl-ref/source/dat/ossuary.des b/crawl-ref/source/dat/ossuary.des index f99732907c..7de16ae765 100644 --- a/crawl-ref/source/dat/ossuary.des +++ b/crawl-ref/source/dat/ossuary.des @@ -651,9 +651,8 @@ SUBST: z = c:20 o:4 SUBST: y = c:20 o:1 SUBST: $ = 1:10 2:1 KFEAT: L = = -MARKER: L = lua:function_machine( {marker_type="player_at", \ - func=(function(marker) crawl.mpr("Something ancient and \ - evil stirs ahead...", "warning") end) } ) +MARKER: L = lua:message_machine({marker_type="player_at", message="Something \ + ancient and evil stirs ahead...", channel="warning" }) : ossuary_setup_features(_G) : ossuary_milestone(_G) MAP |