summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPhilipp Sehmisch <crush@themanaworld.org>2009-01-31 21:49:58 +0100
committerPhilipp Sehmisch <crush@themanaworld.org>2009-01-31 22:01:39 +0100
commit393d066045fda5beee4748dc66754d70b4c82d36 (patch)
tree2ed309a5dba7595bc976762f9f625edebfcc4680 /src
parentc423c02890cfb4520da0ac75e00d1bd9f1663ce0 (diff)
downloadmanaserv-393d066045fda5beee4748dc66754d70b4c82d36.tar.gz
manaserv-393d066045fda5beee4748dc66754d70b4c82d36.tar.bz2
manaserv-393d066045fda5beee4748dc66754d70b4c82d36.tar.xz
manaserv-393d066045fda5beee4748dc66754d70b4c82d36.zip
Added on_remove callback to lua API
Diffstat (limited to 'src')
-rw-r--r--src/scripting/lua.cpp18
-rw-r--r--src/scripting/luascript.cpp11
-rw-r--r--src/scripting/luascript.hpp2
-rw-r--r--src/scripting/script.cpp2
-rw-r--r--src/scripting/script.hpp13
5 files changed, 31 insertions, 15 deletions
diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp
index b9f30f4e..f9d2021d 100644
--- a/src/scripting/lua.cpp
+++ b/src/scripting/lua.cpp
@@ -768,15 +768,16 @@ static int chr_get_post(lua_State *s)
}
/**
- * Makes the server call the lua function deathEvent
- * with the being ID when the being dies.
- * tmw.note_on_death (being)
+ * Makes the server call the lua functions deathEvent
+ * and removeEvent when the being dies or is removed
+ * from the map.
+ * tmw.being_register (being)
*/
-static int note_on_death(lua_State *s)
+static int being_register(lua_State *s)
{
if (!lua_islightuserdata(s, 1) || lua_gettop(s) != 1)
{
- raiseScriptError(s, "lua_noteOnDeath called with incorrect parameters.");
+ raiseScriptError(s, "being_register called with incorrect parameters.");
return 0;
}
@@ -786,14 +787,15 @@ static int note_on_death(lua_State *s)
Being *being = getBeing(s, 1);
if (!being)
{
- raiseScriptError(s, "lua_noteOnDeath called for nonexistent being.");
+ raiseScriptError(s, "being_register called for nonexistent being.");
return 0;
}
- being->addListener(t->getScriptDeathListener());
+ being->addListener(t->getScriptListener());
return 0;
}
+
/**
* Triggers a special effect from the clients effects.xml
* tmw.effect_create (id, x, y)
@@ -1006,7 +1008,7 @@ LuaScript::LuaScript():
{ "trigger_create", &trigger_create },
{ "chatmessage", &chatmessage },
{ "get_beings_in_circle", &get_beings_in_circle },
- { "note_on_death", &note_on_death },
+ { "being_register", &being_register },
{ "effect_create", &effect_create },
{ "test_tableget", &test_tableget },
{ "get_map_id", &get_map_id },
diff --git a/src/scripting/luascript.cpp b/src/scripting/luascript.cpp
index d2083952..c88b95fd 100644
--- a/src/scripting/luascript.cpp
+++ b/src/scripting/luascript.cpp
@@ -112,8 +112,17 @@ void LuaScript::processDeathEvent(Being *being)
//TODO: get and push a list of creatures who contributed to killing the
// being. This might be very interesting for scripting quests.
execute();
+}
+
+void LuaScript::processRemoveEvent(Thing *being)
+{
+ prepare("remove_notification");
+ push(being);
+ //TODO: get and push a list of creatures who contributed to killing the
+ // being. This might be very interesting for scripting quests.
+ execute();
- being->removeListener(getScriptDeathListener());
+ being->removeListener(getScriptListener());
}
/**
diff --git a/src/scripting/luascript.hpp b/src/scripting/luascript.hpp
index 9f1097f7..d4dc116e 100644
--- a/src/scripting/luascript.hpp
+++ b/src/scripting/luascript.hpp
@@ -65,6 +65,8 @@ class LuaScript: public Script
void processDeathEvent(Being* thing);
+ void processRemoveEvent(Thing* thing);
+
private:
lua_State *mState;
diff --git a/src/scripting/script.cpp b/src/scripting/script.cpp
index a20efb5c..f334eb19 100644
--- a/src/scripting/script.cpp
+++ b/src/scripting/script.cpp
@@ -33,7 +33,7 @@ static Engines *engines = NULL;
Script::Script():
mMap(NULL),
- mEventListener(&scriptDeathEventDispatch)
+ mEventListener(&scriptEventDispatch)
{}
void Script::registerEngine(std::string const &name, Factory f)
diff --git a/src/scripting/script.hpp b/src/scripting/script.hpp
index c87bf182..24a415ef 100644
--- a/src/scripting/script.hpp
+++ b/src/scripting/script.hpp
@@ -124,11 +124,13 @@ class Script
MapComposite *getMap() const
{ return mMap; }
- EventListener *getScriptDeathListener()
+ EventListener *getScriptListener()
{ return &mEventListener; }
virtual void processDeathEvent(Being* thing) = 0;
+ virtual void processRemoveEvent(Thing* thing) = 0;
+
protected:
std::string mScriptFile;
@@ -136,18 +138,19 @@ class Script
MapComposite *mMap;
EventListener mEventListener; /**< Tracking of being deaths. */
- friend struct ScriptDeathEventDispatch;
+ friend struct ScriptEventDispatch;
};
-struct ScriptDeathEventDispatch: EventDispatch
+struct ScriptEventDispatch: EventDispatch
{
- ScriptDeathEventDispatch()
+ ScriptEventDispatch()
{
typedef EventListenerFactory< Script, &Script::mEventListener > Factory;
died = &Factory::create< Being, &Script::processDeathEvent >::function;
+ removed = &Factory::create< Thing, &Script::processRemoveEvent >::function;
}
};
-static ScriptDeathEventDispatch scriptDeathEventDispatch;
+static ScriptEventDispatch scriptEventDispatch;
#endif