summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/shout.cc
diff options
context:
space:
mode:
authorMatthew Cline <zelgadis@sourceforge.net>2009-12-07 03:04:10 -0800
committerMatthew Cline <zelgadis@sourceforge.net>2009-12-07 03:04:10 -0800
commite0d592b0a5e032d7d35551907c4af69014e48b10 (patch)
tree8d8d3f1c0d1e75b05b184a04815b66b2ef709139 /crawl-ref/source/shout.cc
parenta2285dbfa468cca31b2d724db38ccb102c487675 (diff)
downloadcrawl-ref-e0d592b0a5e032d7d35551907c4af69014e48b10.tar.gz
crawl-ref-e0d592b0a5e032d7d35551907c4af69014e48b10.zip
New monster props "speech_func" and "shout_func"
MonPropsMarker can be used to set "speech_func" and "shout_func" on a monster, functions which return a string to be used as the monster's speech/shout message.
Diffstat (limited to 'crawl-ref/source/shout.cc')
-rw-r--r--crawl-ref/source/shout.cc34
1 files changed, 33 insertions, 1 deletions
diff --git a/crawl-ref/source/shout.cc b/crawl-ref/source/shout.cc
index e4167278ba..d7d21af7a4 100644
--- a/crawl-ref/source/shout.cc
+++ b/crawl-ref/source/shout.cc
@@ -7,8 +7,10 @@
#include "shout.h"
+#include "cluautil.h"
#include "coord.h"
#include "database.h"
+#include "dlua.h"
#include "env.h"
#include "ghost.h"
#include "jobs.h"
@@ -148,7 +150,37 @@ void handle_monster_shouts(monsters* monster, bool force)
else
suffix = " unseen";
- msg = getShoutString(key, suffix);
+ if (monster->props.exists("shout_func"))
+ {
+ lua_stack_cleaner clean(dlua);
+
+ dlua_chunk &chunk = monster->props["shout_func"];
+
+ if (!chunk.load(dlua))
+ {
+ push_monster(dlua, monster);
+ clua_pushcxxstring(dlua, suffix);
+ dlua.callfn(NULL, 2, 1);
+ dlua.fnreturns(">s", &msg);
+
+ // __NONE means to be silent, and __NEXT or __DEFAULT means to try
+ // the next method of getting a shout message.
+ if (msg == "__NONE")
+ return;
+ if (msg == "__DEFAULT" || msg == "__NEXT")
+ msg.clear();
+ }
+ else
+ {
+ mprf(MSGCH_ERROR,
+ "Lua shout function for monster '%s' didn't load: %s",
+ monster->full_name(DESC_PLAIN).c_str(),
+ dlua.error.c_str());
+ }
+ }
+
+ if (msg.empty())
+ msg = getShoutString(key, suffix);
if (msg == "__DEFAULT" || msg == "__NEXT")
msg = getShoutString(default_msg_key, suffix);