diff options
Diffstat (limited to 'crawl-ref/source')
-rw-r--r-- | crawl-ref/source/mon-speak.cc | 39 | ||||
-rw-r--r-- | crawl-ref/source/mon-stuff.cc | 6 | ||||
-rw-r--r-- | crawl-ref/source/shout.cc | 34 |
3 files changed, 77 insertions, 2 deletions
diff --git a/crawl-ref/source/mon-speak.cc b/crawl-ref/source/mon-speak.cc index a5424f117b..9d2d8ecc85 100644 --- a/crawl-ref/source/mon-speak.cc +++ b/crawl-ref/source/mon-speak.cc @@ -15,8 +15,10 @@ #include "externs.h" #include "beam.h" +#include "cluautil.h" #include "database.h" #include "debug.h" +#include "dlua.h" #include "ghost.h" #include "message.h" #include "mon-stuff.h" @@ -558,8 +560,43 @@ bool mons_speaks(monsters *monster) } else { + if (monster->props.exists("speech_func")) + { +#ifdef DEBUG_MONSPEAK + mpr("Trying Lua function for monster speech", MSGCH_DIAGNOSTICS); +#endif + lua_stack_cleaner clean(dlua); + + dlua_chunk &chunk = monster->props["speech_func"]; + + if (!chunk.load(dlua)) + { + push_monster(dlua, monster); + dlua.callfn(NULL, 1, 1); + dlua.fnreturns(">s", &msg); + + // __NONE means to be silent, and __NEXT means to try the next + // method of getting a speech message. + if (msg == "__NONE") + { +#ifdef DEBUG_MONSPEAK + mpr("result: \"__NONE\"!", MSGCH_DIAGNOSTICS); +#endif + return (false); + } + if (msg == "__NEXT") + msg.clear(); + } + else + { + mprf(MSGCH_ERROR, + "Lua speech function for monster '%s' didn't load: %s", + monster->full_name(DESC_PLAIN).c_str(), + dlua.error.c_str()); + } + } - if (monster->props.exists("speech_key")) + if (msg.empty() && monster->props.exists("speech_key")) { msg = _get_speak_string(prefixes, monster->props["speech_key"].get_string(), diff --git a/crawl-ref/source/mon-stuff.cc b/crawl-ref/source/mon-stuff.cc index 0d4c374ce2..fc109c5aee 100644 --- a/crawl-ref/source/mon-stuff.cc +++ b/crawl-ref/source/mon-stuff.cc @@ -2509,6 +2509,12 @@ bool monster_polymorph(monsters *monster, monster_type targetc, monster->flags = flags; monster->god = god; + // Forget various speech/shout Lua functions. + monster->props.erase("speech_key"); + monster->props.erase("speech_prefix"); + monster->props.erase("speech_func"); + monster->props.erase("shout_func"); + // Keep spells for named monsters, but don't override innate ones // for dragons and the like. This means that Sigmund polymorphed // into a goblin will still cast spells, but if he ends up as a 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); |