summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Athay <ko2fan@gmail.com>2009-01-28 14:24:22 +0000
committerDavid Athay <ko2fan@gmail.com>2009-01-28 14:24:22 +0000
commit2141fae61af1fd3f81d792910ffa35d672835523 (patch)
treef1b9f5fc1be9c16b8770341b551bff0d83d12736
parentfa5469bd27d117abd98ca58dad61a6378fe8215c (diff)
downloadmanaserv-2141fae61af1fd3f81d792910ffa35d672835523.tar.gz
manaserv-2141fae61af1fd3f81d792910ffa35d672835523.tar.bz2
manaserv-2141fae61af1fd3f81d792910ffa35d672835523.tar.xz
manaserv-2141fae61af1fd3f81d792910ffa35d672835523.zip
Moved MapContent into header file.
-rw-r--r--gameserver.cbp4
-rw-r--r--src/game-server/mapcomposite.cpp142
-rw-r--r--src/game-server/mapcomposite.hpp97
3 files changed, 125 insertions, 118 deletions
diff --git a/gameserver.cbp b/gameserver.cbp
index 64bfb8a1..a2de9765 100644
--- a/gameserver.cbp
+++ b/gameserver.cbp
@@ -130,6 +130,10 @@
<Unit filename="src/net/netcomputer.hpp" />
<Unit filename="src/point.h" />
<Unit filename="src/scripting/lua.cpp" />
+ <Unit filename="src/scripting/luascript.cpp" />
+ <Unit filename="src/scripting/luascript.hpp" />
+ <Unit filename="src/scripting/luautil.cpp" />
+ <Unit filename="src/scripting/luautil.hpp" />
<Unit filename="src/scripting/script.cpp" />
<Unit filename="src/scripting/script.hpp" />
<Unit filename="src/utils/base64.cpp" />
diff --git a/src/game-server/mapcomposite.cpp b/src/game-server/mapcomposite.cpp
index 333d5ae7..b9e4b863 100644
--- a/src/game-server/mapcomposite.cpp
+++ b/src/game-server/mapcomposite.cpp
@@ -43,104 +43,6 @@
in dealing with zone changes. */
static int const zoneDiam = 256;
-/**
- * Part of a map.
- */
-struct MapZone
-{
- unsigned short nbCharacters, nbMovingObjects;
- /**
- * Objects present in this zone.
- * Characters are stored first, then the remaining MovingObjects, then the
- * remaining Objects.
- */
- std::vector< Object * > objects;
-
- /**
- * Destinations of the objects that left this zone.
- * This is necessary in order to have an accurate iterator around moving
- * objects.
- */
- MapRegion destinations;
-
- MapZone(): nbCharacters(0), nbMovingObjects(0) {}
- void insert(Object *);
- void remove(Object *);
-};
-
-/**
- * Pool of public IDs for MovingObjects on a map. By maintaining public ID
- * availability using bits, it can locate an available public ID fast while
- * using minimal memory access.
- */
-struct ObjectBucket
-{
- static int const int_bitsize = sizeof(unsigned) * 8;
- unsigned bitmap[256 / int_bitsize]; /**< Bitmap of free locations. */
- short free; /**< Number of empty places. */
- short next_object; /**< Next object to look at. */
- MovingObject *objects[256];
-
- ObjectBucket();
- int allocate();
- void deallocate(int);
-};
-
-/**
- * Entities on a map.
- */
-struct MapContent
-{
- MapContent(Map *);
- ~MapContent();
-
- /**
- * Allocates a unique ID for a moving object on this map.
- */
- bool allocate(MovingObject *);
-
- /**
- * Deallocates an ID.
- */
- void deallocate(MovingObject *);
-
- /**
- * Fills a region of zones within the range of a point.
- */
- void fillRegion(MapRegion &, Point const &, int) const;
-
- /**
- * Fills a region of zones inside a rectangle.
- */
- void fillRegion(MapRegion &, Rectangle const &) const;
-
- /**
- * Gets zone at given position.
- */
- MapZone &getZone(Point const &pos) const
- { return zones[(pos.x / zoneDiam) + (pos.y / zoneDiam) * mapWidth]; }
-
- /**
- * Things (items, characters, monsters, etc) located on the map.
- */
- std::vector< Thing * > things;
-
- /**
- * Buckets of MovingObjects located on the map, referenced by ID.
- */
- ObjectBucket *buckets[256];
-
- int last_bucket; /**< Last bucket acted upon. */
-
- /**
- * Partition of the Objects, depending on their position on the map.
- */
- MapZone *zones;
-
- unsigned short mapWidth; /**< Width with respect to zones. */
- unsigned short mapHeight; /**< Height with respect to zones. */
-};
-
void MapZone::insert(Object *obj)
{
int type = obj->getType();
@@ -443,26 +345,6 @@ MapContent::~MapContent()
delete[] zones;
}
-void MapComposite::setMap(Map *m)
-{
- assert(!mMap && m);
- mMap = 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)
{
// First, try allocating from the last used bucket.
@@ -538,6 +420,23 @@ void MapContent::fillRegion(MapRegion &r, Rectangle const &p) const
}
}
+MapZone& MapContent::getZone(Point const &pos) const
+{
+ return zones[(pos.x / zoneDiam) + (pos.y / zoneDiam) * mapWidth];
+}
+
+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;
+}
+
ZoneIterator MapComposite::getAroundPointIterator(Point const &p, int radius) const
{
MapRegion r;
@@ -628,6 +527,13 @@ void MapComposite::remove(Thing *ptr)
assert(false);
}
+void MapComposite::setMap(Map *m)
+{
+ assert(!mMap && m);
+ mMap = m;
+ mContent = new MapContent(m);
+}
+
void MapComposite::update()
{
for (int i = 0; i < mContent->mapHeight * mContent->mapWidth; ++i)
diff --git a/src/game-server/mapcomposite.hpp b/src/game-server/mapcomposite.hpp
index 3f1225f0..078842d6 100644
--- a/src/game-server/mapcomposite.hpp
+++ b/src/game-server/mapcomposite.hpp
@@ -120,6 +120,103 @@ struct ObjectIterator
};
/**
+ * Part of a map.
+ */
+struct MapZone
+{
+ unsigned short nbCharacters, nbMovingObjects;
+ /**
+ * Objects present in this zone.
+ * Characters are stored first, then the remaining MovingObjects, then the
+ * remaining Objects.
+ */
+ std::vector< Object * > objects;
+
+ /**
+ * Destinations of the objects that left this zone.
+ * This is necessary in order to have an accurate iterator around moving
+ * objects.
+ */
+ MapRegion destinations;
+
+ MapZone(): nbCharacters(0), nbMovingObjects(0) {}
+ void insert(Object *);
+ void remove(Object *);
+};
+
+/**
+ * Pool of public IDs for MovingObjects on a map. By maintaining public ID
+ * availability using bits, it can locate an available public ID fast while
+ * using minimal memory access.
+ */
+struct ObjectBucket
+{
+ static int const int_bitsize = sizeof(unsigned) * 8;
+ unsigned bitmap[256 / int_bitsize]; /**< Bitmap of free locations. */
+ short free; /**< Number of empty places. */
+ short next_object; /**< Next object to look at. */
+ MovingObject *objects[256];
+
+ ObjectBucket();
+ int allocate();
+ void deallocate(int);
+};
+
+/**
+ * Entities on a map.
+ */
+struct MapContent
+{
+ MapContent(Map *);
+ ~MapContent();
+
+ /**
+ * Allocates a unique ID for a moving object on this map.
+ */
+ bool allocate(MovingObject *);
+
+ /**
+ * Deallocates an ID.
+ */
+ void deallocate(MovingObject *);
+
+ /**
+ * Fills a region of zones within the range of a point.
+ */
+ void fillRegion(MapRegion &, Point const &, int) const;
+
+ /**
+ * Fills a region of zones inside a rectangle.
+ */
+ void fillRegion(MapRegion &, Rectangle const &) const;
+
+ /**
+ * Gets zone at given position.
+ */
+ MapZone &getZone(Point const &pos) const;
+
+ /**
+ * Things (items, characters, monsters, etc) located on the map.
+ */
+ std::vector< Thing * > things;
+
+ /**
+ * Buckets of MovingObjects located on the map, referenced by ID.
+ */
+ ObjectBucket *buckets[256];
+
+ int last_bucket; /**< Last bucket acted upon. */
+
+ /**
+ * Partition of the Objects, depending on their position on the map.
+ */
+ MapZone *zones;
+
+ unsigned short mapWidth; /**< Width with respect to zones. */
+ unsigned short mapHeight; /**< Height with respect to zones. */
+};
+
+/**
* Combined map/entity structure.
*/
class MapComposite