summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGuillaume Melquiond <guillaume.melquiond@gmail.com>2007-08-10 14:17:38 +0000
committerGuillaume Melquiond <guillaume.melquiond@gmail.com>2007-08-10 14:17:38 +0000
commitf990980f80ab1523086edba1bed222741d716fa0 (patch)
tree0ce0257ca854ea06949f543227a301a7f553e1a9 /src
parentcb45a65e1020bf129225dd20c57bf64314cef2c8 (diff)
downloadmanaserv-f990980f80ab1523086edba1bed222741d716fa0.tar.gz
manaserv-f990980f80ab1523086edba1bed222741d716fa0.tar.bz2
manaserv-f990980f80ab1523086edba1bed222741d716fa0.tar.xz
manaserv-f990980f80ab1523086edba1bed222741d716fa0.zip
Improved helper functions for Lua scripts. Associated scripts to maps.
Diffstat (limited to 'src')
-rw-r--r--src/game-server/mapcomposite.cpp11
-rw-r--r--src/game-server/mapcomposite.hpp23
-rw-r--r--src/game-server/state.cpp5
-rw-r--r--src/game-server/testing.cpp1
4 files changed, 32 insertions, 8 deletions
diff --git a/src/game-server/mapcomposite.cpp b/src/game-server/mapcomposite.cpp
index 6fea9488..eeb65a10 100644
--- a/src/game-server/mapcomposite.cpp
+++ b/src/game-server/mapcomposite.cpp
@@ -28,7 +28,7 @@
#include "game-server/map.hpp"
#include "game-server/mapcomposite.hpp"
#include "game-server/character.hpp"
-
+#include "scripting/script.hpp"
#include "utils/logger.h"
/* TODO: Implement overlapping map zones instead of strict partitioning.
@@ -452,10 +452,17 @@ void MapComposite::setMap(Map *m)
mContent = new MapContent(m);
}
+
+MapComposite::MapComposite(int id, std::string const &name):
+ mMap(NULL), mContent(NULL), mScript(NULL), mName(name), mID(id)
+{
+}
+
MapComposite::~MapComposite()
{
delete mMap;
delete mContent;
+ delete mScript;
}
bool MapContent::allocate(MovingObject *obj)
@@ -658,5 +665,3 @@ std::vector< Thing * > const &MapComposite::getEverything() const
{
return mContent->things;
}
-
-
diff --git a/src/game-server/mapcomposite.hpp b/src/game-server/mapcomposite.hpp
index 00d52173..fb86ee85 100644
--- a/src/game-server/mapcomposite.hpp
+++ b/src/game-server/mapcomposite.hpp
@@ -34,6 +34,7 @@ class Object;
class Character;
class Point;
class Rectangle;
+class Script;
class Thing;
struct MapContent;
@@ -129,8 +130,7 @@ class MapComposite
/**
* Constructor.
*/
- MapComposite(int id, std::string const &name)
- : mMap(NULL), mContent(NULL), mName(name), mID(id) {}
+ MapComposite(int id, std::string const &name);
/**
* Destructor.
@@ -150,6 +150,18 @@ class MapComposite
{ return mMap; }
/**
+ * Sets the associated script.
+ */
+ void setScript(Script *s)
+ { mScript = s; }
+
+ /**
+ * Gets the associated script.
+ */
+ Script *getScript() const
+ { return mScript; }
+
+ /**
* Returns whether the map is active on this server or not.
*/
bool isActive() const
@@ -217,10 +229,11 @@ class MapComposite
private:
MapComposite(MapComposite const &);
- Map *mMap; /**< Actual map. */
+ Map *mMap; /**< Actual map. */
MapContent *mContent; /**< Entities on the map. */
- std::string mName; /**< Name of the map. */
- unsigned short mID; /**< ID of the map. */
+ Script *mScript; /**< Script associated to this map. */
+ std::string mName; /**< Name of the map. */
+ unsigned short mID; /**< ID of the map. */
};
#endif
diff --git a/src/game-server/state.cpp b/src/game-server/state.cpp
index 513f7e6e..9262798f 100644
--- a/src/game-server/state.cpp
+++ b/src/game-server/state.cpp
@@ -39,6 +39,7 @@
#include "game-server/npc.hpp"
#include "game-server/trade.hpp"
#include "net/messageout.hpp"
+#include "scripting/script.hpp"
#include "utils/logger.h"
typedef std::map< Object *, DelayedEvent > DelayedEvents;
@@ -88,6 +89,10 @@ static void updateMap(MapComposite *map)
}
// 5. update the map itself.
+ if (Script *s = map->getScript())
+ {
+ s->update();
+ }
map->update();
}
diff --git a/src/game-server/testing.cpp b/src/game-server/testing.cpp
index d08f2ee6..7b34d79a 100644
--- a/src/game-server/testing.cpp
+++ b/src/game-server/testing.cpp
@@ -39,6 +39,7 @@ void testingMap(MapComposite *map)
Script *s = Script::create("lua", "test.lua");
if (s)
{
+ map->setScript(s);
s->setMap(map);
s->prepare("initialize");
s->execute();