summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Cline <zelgadis@sourceforge.net>2009-11-01 19:19:11 -0800
committerMatthew Cline <zelgadis@sourceforge.net>2009-11-01 19:19:11 -0800
commit60df59bb213b7c2c3c6bc69ac9c87d28378db1ff (patch)
tree149f0d25fbb38a4f9c704587a520009097a93395
parentf4ea5b334d55165960885be4416cecf179391ae0 (diff)
downloadcrawl-ref-60df59bb213b7c2c3c6bc69ac9c87d28378db1ff.tar.gz
crawl-ref-60df59bb213b7c2c3c6bc69ac9c87d28378db1ff.zip
Use lm_trig.lua instead of lm_func. lua for msgs
Start of triggerable/function_machine merger: use triggerable class TriggerableMessage for messages instead of message_machine.
-rw-r--r--crawl-ref/source/dat/clua/lm_func.lua10
-rw-r--r--crawl-ref/source/dat/clua/lm_trig.lua66
-rw-r--r--crawl-ref/source/dat/float.des8
-rw-r--r--crawl-ref/source/dat/ossuary.des6
4 files changed, 74 insertions, 16 deletions
diff --git a/crawl-ref/source/dat/clua/lm_func.lua b/crawl-ref/source/dat/clua/lm_func.lua
index 692990f2de..c1ea82e6d2 100644
--- a/crawl-ref/source/dat/clua/lm_func.lua
+++ b/crawl-ref/source/dat/clua/lm_func.lua
@@ -175,13 +175,3 @@ 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 (position, mtable)
- crawl.mpr(mtable.message, mtable.channel)
- end
- pars.marker_params = mtable
- return FunctionMachine:new(pars)
-end
diff --git a/crawl-ref/source/dat/clua/lm_trig.lua b/crawl-ref/source/dat/clua/lm_trig.lua
index 29eb14519e..b4b1ef52b8 100644
--- a/crawl-ref/source/dat/clua/lm_trig.lua
+++ b/crawl-ref/source/dat/clua/lm_trig.lua
@@ -176,6 +176,72 @@ function Triggerable:read(marker, th)
return self
end
+--------------------------
+
+-- A simple class to give out messages. Should be split out into own
+-- file if/when it becomes more complex.
+
+TriggerableMessage = util.subclass(Triggerable)
+TriggerableMessage.CLASS = "TriggerableMessage"
+
+function TriggerableMessage:new(pars)
+ pars = pars or { }
+
+ local tm = self.super.new(self)
+
+ if not pars.msg then
+ error("Must provide msg to TriggerableMessage")
+ elseif type(pars.msg) ~= "string" then
+ error("TriggerableMessage msg must be string, not " .. type(pars.msg))
+ end
+
+ pars.channel = pars.channel or "plain"
+ pars.repeated = pars.repeated
+
+ tm.msg = pars.msg
+ tm.channel = pars.channel
+ tm.repeated = pars.repeated
+
+ return tm
+end
+
+function TriggerableMessage:on_trigger(triggerer, marker, ev)
+ crawl.mpr(self.msg, self.channel)
+
+ if not self.repeated then
+ self:remove(marker)
+ end
+end
+
+function TriggerableMessage:write(marker, th)
+ TriggerableMessage.super.write(self, marker, th)
+
+ file.marshall(th, self.msg)
+ file.marshall(th, self.channel)
+ file.marshall_meta(th, self.repeated)
+end
+
+function TriggerableMessage:read(marker, th)
+ TriggerableMessage.super.read(self, marker, th)
+
+ self.msg = file.unmarshall_string(th)
+ self.channel = file.unmarshall_string(th)
+ self.repeated = file.unmarshall_meta(th)
+
+ setmetatable(self, TriggerableMessage)
+
+ return self
+end
+
+function message_at_spot(msg, channel, repeated)
+ local tm = TriggerableMessage:new
+ { msg = msg, channel = channel, repeated = repeated }
+
+ tm:add_triggerer( DgnTriggerer:new { type = "player_move" } )
+
+ return tm
+end
+
-------------------------------------------------------------------------------
-- NOTE: The CLASS string of a triggerer class *MUST* be exactly the same as
-- the triggerer class name, or it won't be able to deserialize properly.
diff --git a/crawl-ref/source/dat/float.des b/crawl-ref/source/dat/float.des
index f2a6dcbedf..9cb0f17552 100644
--- a/crawl-ref/source/dat/float.des
+++ b/crawl-ref/source/dat/float.des
@@ -729,9 +729,9 @@ COLOUR: _ : yellow
SUBST: _ : .
SUBST: T = T F:1
KMASK: + = no_secret_doors
-MARKER: ! = lua:message_machine({marker_type="player_at", message="You almost \
- think you hear a voice: \"Seek not undue power, mortal.\"", \
- channel="warning" })
+MARKER: ! = lua:message_at_spot ( "You almost think you hear a voice: \
+ \"Seek not undue power, mortal.\"", \
+ "warning" )
SUBST: ! : .
MAP
xxxxxxxxxxx
@@ -830,4 +830,4 @@ cc..!1.!1c...c.6..6..cc
cc.c...+.cc
c+ccccccc
@
-ENDMAP \ No newline at end of file
+ENDMAP
diff --git a/crawl-ref/source/dat/ossuary.des b/crawl-ref/source/dat/ossuary.des
index 7de16ae765..1047e3e907 100644
--- a/crawl-ref/source/dat/ossuary.des
+++ b/crawl-ref/source/dat/ossuary.des
@@ -651,8 +651,10 @@ SUBST: z = c:20 o:4
SUBST: y = c:20 o:1
SUBST: $ = 1:10 2:1
KFEAT: L = =
-MARKER: L = lua:message_machine({marker_type="player_at", message="Something \
- ancient and evil stirs ahead...", channel="warning" })
+MARKER: L = lua:message_at_spot ( \
+ "Something ancient and evil stirs ahead...", \
+ "warning" \
+ )
: ossuary_setup_features(_G)
: ossuary_milestone(_G)
MAP