00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef _TMWSERV_SCRIPTING_SCRIPT_HPP
00023 #define _TMWSERV_SCRIPTING_SCRIPT_HPP
00024
00025 #include <string>
00026
00027 #include "game-server/eventlistener.hpp"
00028
00029 class MapComposite;
00030 class Thing;
00031
00035 class Script
00036 {
00037 public:
00038
00039 typedef Script *(*Factory)();
00040
00044 static void registerEngine(const std::string &, Factory);
00045
00049 static Script *create(const std::string &engine);
00050
00054 Script();
00055
00059 virtual ~Script() {}
00060
00065 virtual void load(const char *) = 0;
00066
00071 virtual bool loadFile(const std::string &);
00072
00077 virtual void loadNPC(const std::string &name, int id, int x, int y,
00078 const char *);
00079
00084 virtual void update();
00085
00090 virtual void prepare(const std::string &name) = 0;
00091
00095 virtual void push(int) = 0;
00096
00100 virtual void push(const std::string &) = 0;
00101
00108 virtual void push(Thing *) = 0;
00109
00114 virtual int execute() = 0;
00115
00119 void setMap(MapComposite *m)
00120 { mMap = m; }
00121
00125 MapComposite *getMap() const
00126 { return mMap; }
00127
00128 EventListener *getScriptListener()
00129 { return &mEventListener; }
00130
00131 virtual void processDeathEvent(Being* thing) = 0;
00132
00133 virtual void processRemoveEvent(Thing* thing) = 0;
00134
00135 protected:
00136 std::string mScriptFile;
00137
00138 private:
00139 MapComposite *mMap;
00140 EventListener mEventListener;
00142 friend struct ScriptEventDispatch;
00143 };
00144
00145 struct ScriptEventDispatch: EventDispatch
00146 {
00147 ScriptEventDispatch()
00148 {
00149 typedef EventListenerFactory< Script, &Script::mEventListener > Factory;
00150 died = &Factory::create< Being, &Script::processDeathEvent >::function;
00151 removed = &Factory::create< Thing, &Script::processRemoveEvent >::function;
00152 }
00153 };
00154
00155 static ScriptEventDispatch scriptEventDispatch;
00156
00157 #endif