From 7d559cbae9c713e15ae0c943a4d571122bf29bc6 Mon Sep 17 00:00:00 2001 From: Philipp Sehmisch Date: Tue, 6 May 2008 18:49:04 +0000 Subject: Implemented script trigger areas which call a script function when an object steps into them. --- src/game-server/trigger.cpp | 13 +++++++++++++ src/game-server/trigger.hpp | 15 +++++++++++++++ 2 files changed, 28 insertions(+) (limited to 'src/game-server') diff --git a/src/game-server/trigger.cpp b/src/game-server/trigger.cpp index c0c9bd85..3309c754 100644 --- a/src/game-server/trigger.cpp +++ b/src/game-server/trigger.cpp @@ -28,6 +28,8 @@ #include "game-server/movingobject.hpp" #include "game-server/state.hpp" +#include "utils/logger.h" + void WarpAction::process(Object *obj) { if (obj->getType() == OBJECT_CHARACTER) @@ -36,6 +38,17 @@ void WarpAction::process(Object *obj) } } +void ScriptAction::process(Object *obj) +{ + LOG_DEBUG("Script trigger area activated: "<prepare(mFunction); + mScript->push(obj); + mScript->push(mArg); + mScript->execute(); +} + void TriggerArea::update() { for (MovingObjectIterator i(getMap()->getInsideRectangleIterator(mZone)); i; ++i) diff --git a/src/game-server/trigger.hpp b/src/game-server/trigger.hpp index d6e4d2c9..3ca52fba 100644 --- a/src/game-server/trigger.hpp +++ b/src/game-server/trigger.hpp @@ -26,6 +26,7 @@ #include "point.h" #include "game-server/thing.hpp" +#include "scripting/script.hpp" class Object; @@ -49,6 +50,20 @@ class WarpAction : public TriggerAction unsigned short mX, mY; }; +class ScriptAction : public TriggerAction +{ + public: + ScriptAction(Script *script, std::string function, int arg) + : mScript(script), mFunction(function), mArg(arg) {} + + virtual void process(Object *obj); + + private: + Script *mScript; //Script object to be called + std::string mFunction; //Name of the function called in the script object + int mArg; //Argument passed to script function (meaning is function-specific) +}; + class TriggerArea : public Thing { public: -- cgit v1.2.3-60-g2f50