diff options
author | Erik Schilling <ablu.erikschilling@googlemail.com> | 2013-02-21 07:29:58 +0100 |
---|---|---|
committer | Erik Schilling <ablu.erikschilling@googlemail.com> | 2013-02-21 07:29:58 +0100 |
commit | f93b4c25242370982715e1a83c11e667b17f20af (patch) | |
tree | 07b392040bd858e205d12cf8f0977cf82fcc2c90 /src/scripting/script.h | |
parent | bcb3f283bda155bec33c83c4627f59acb4616dd8 (diff) | |
parent | 4559ca444daacfd02ebb05f1657148a2b4cf3d8b (diff) | |
download | manaserv-f93b4c25242370982715e1a83c11e667b17f20af.tar.gz manaserv-f93b4c25242370982715e1a83c11e667b17f20af.tar.bz2 manaserv-f93b4c25242370982715e1a83c11e667b17f20af.tar.xz manaserv-f93b4c25242370982715e1a83c11e667b17f20af.zip |
Merge branch 'master' into lpc2012
Diffstat (limited to 'src/scripting/script.h')
-rw-r--r-- | src/scripting/script.h | 50 |
1 files changed, 35 insertions, 15 deletions
diff --git a/src/scripting/script.h b/src/scripting/script.h index 8dee23a9..574d1b9b 100644 --- a/src/scripting/script.h +++ b/src/scripting/script.h @@ -27,6 +27,7 @@ #include <list> #include <string> #include <vector> +#include <stack> #include <sigc++/trackable.h> @@ -40,6 +41,15 @@ class Entity; class Script : public sigc::trackable { public: + struct Context + { + MapComposite *map; + + Context() + : map(0) + {} + }; + /** * Defines a function that creates a Script instance. */ @@ -87,9 +97,12 @@ class Script : public sigc::trackable Thread(Script *script); virtual ~Thread(); + Context &getContext() + { return mContext; } + Script * const mScript; ThreadState mState; - MapComposite *mMap; + Context mContext; }; Script(); @@ -102,14 +115,18 @@ class Script : public sigc::trackable * * @param prog the program text to load * @param name the name of the text, used for error reporting + * @param context the context that is supposed to be used for loading */ - virtual void load(const char *prog, const char *name) = 0; + virtual void load(const char *prog, + const char *name, + const Context &context = Context()) = 0; /** * Loads a text file into script context and executes its global * statements. */ - virtual bool loadFile(const std::string &); + virtual bool loadFile(const std::string &, + const Context &context = Context()); /** * Loads a chunk of text and considers it as an NPC handler. This @@ -119,7 +136,8 @@ class Script : public sigc::trackable int id, ManaServ::BeingGender gender, int x, int y, - const char *); + const char *, + MapComposite *map); /** * Called every tick for the script to manage its data. @@ -174,9 +192,17 @@ class Script : public sigc::trackable /** * Executes the function being prepared. + * @param context the context that is supposed to be used for executing * @return the value returned by the script. */ - virtual int execute() = 0; + virtual int execute(const Context &context = Context()) = 0; + + /** + * Executes the function being prepared. + * @param the map which is set as context + * @return the value returned by the script. + */ + int execute(MapComposite *map); /** * Starts or resumes the current thread. Deletes the thread when it is @@ -207,16 +233,10 @@ class Script : public sigc::trackable { return mCurrentThread; } /** - * Sets associated map. - */ - void setMap(MapComposite *m) - { mMap = m; } - - /** - * Gets associated map. + * Returns the current context. */ - MapComposite *getMap() const - { return mMap; } + const Context *getContext() const + { return mContext; } virtual void processDeathEvent(Being *entity) = 0; @@ -231,9 +251,9 @@ class Script : public sigc::trackable protected: std::string mScriptFile; Thread *mCurrentThread; + const Context *mContext; private: - MapComposite *mMap; std::vector<Thread*> mThreads; static Ref mCreateNpcDelayedCallback; |