summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/mon-stuff.cc
diff options
context:
space:
mode:
authorMatthew Cline <zelgadis@sourceforge.net>2009-11-13 00:01:17 -0800
committerMatthew Cline <zelgadis@sourceforge.net>2009-11-13 01:44:02 -0800
commit5b564a802ed13eb54bd1b10221ef436d5001b8c4 (patch)
tree0a66eea286ec96c20b15abd284a77eef25760c3e /crawl-ref/source/mon-stuff.cc
parent6321ec9aeeb988b9833cca313b366d1b648c41ba (diff)
downloadcrawl-ref-5b564a802ed13eb54bd1b10221ef436d5001b8c4.tar.gz
crawl-ref-5b564a802ed13eb54bd1b10221ef436d5001b8c4.zip
mon-stuff.cc: monster_die() Lua callback
A Lua function can be stored in the monsters::props CrawlHashTable, which will be called when the monster dies.
Diffstat (limited to 'crawl-ref/source/mon-stuff.cc')
-rw-r--r--crawl-ref/source/mon-stuff.cc52
1 files changed, 52 insertions, 0 deletions
diff --git a/crawl-ref/source/mon-stuff.cc b/crawl-ref/source/mon-stuff.cc
index 0e8a3b436f..4d5dc0bbc3 100644
--- a/crawl-ref/source/mon-stuff.cc
+++ b/crawl-ref/source/mon-stuff.cc
@@ -20,6 +20,7 @@
#include "artefact.h"
#include "attitude-change.h"
#include "cloud.h"
+#include "cluautil.h"
#include "database.h"
#include "delay.h"
#include "dgnevent.h"
@@ -1478,6 +1479,33 @@ static int _destroy_tentacles(monsters *head)
return tent;
}
+static std::string _killer_type_name(killer_type killer)
+{
+ switch(killer)
+ {
+ case KILL_NONE:
+ return ("none");
+ case KILL_YOU:
+ return ("you");
+ case KILL_MON:
+ return ("mon");
+ case KILL_YOU_MISSILE:
+ return ("you_missile");
+ case KILL_MON_MISSILE:
+ return ("mon_missile");
+ case KILL_YOU_CONF:
+ return ("you_conf");
+ case KILL_MISC:
+ return ("misc");
+ case KILL_RESET:
+ return ("reset");
+ case KILL_DISMISSED:
+ return ("dismissed");
+ }
+ ASSERT(false);
+ return("");
+}
+
// Returns the slot of a possibly generated corpse or -1.
int monster_die(monsters *monster, killer_type killer,
int killer_index, bool silent, bool wizard)
@@ -1497,6 +1525,30 @@ int monster_die(monsters *monster, killer_type killer,
ASSERT(!( YOU_KILL(killer) && crawl_state.arena ));
+ if (monster->props.exists("monster_dies_lua_key"))
+ {
+ lua_stack_cleaner clean(dlua);
+
+ dlua_chunk &chunk = monster->props["monster_dies_lua_key"];
+
+ if (!chunk.load(dlua))
+ {
+ push_monster(dlua, monster);
+ clua_pushcxxstring(dlua, _killer_type_name(killer));
+ lua_pushnumber(dlua, killer_index);
+ lua_pushboolean(dlua, silent);
+ lua_pushboolean(dlua, wizard);
+ dlua.callfn(NULL, 5, 0);
+ }
+ else
+ {
+ mprf(MSGCH_ERROR,
+ "Lua death function for monster '%s' didn't load: %s",
+ monster->full_name(DESC_PLAIN).c_str(),
+ dlua.error.c_str());
+ }
+ }
+
mons_clear_trapping_net(monster);
you.remove_beholder(monster);