summaryrefslogtreecommitdiff
path: root/src/game-server/map.h
diff options
context:
space:
mode:
authorErik Schilling <ablu.erikschilling@googlemail.com>2011-10-08 11:19:44 +0200
committerThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2011-10-15 00:10:22 +0200
commit1e6b7a30b7232dce7b8240441bed04912e06f666 (patch)
treeb5aa2d893c2bee4268a3cfc8172dc6ae7ea6ce09 /src/game-server/map.h
parent9cd09f012ff7c01fbd51b972f9b716cfc8246b2c (diff)
downloadmanaserv-1e6b7a30b7232dce7b8240441bed04912e06f666.tar.gz
manaserv-1e6b7a30b7232dce7b8240441bed04912e06f666.tar.bz2
manaserv-1e6b7a30b7232dce7b8240441bed04912e06f666.tar.xz
manaserv-1e6b7a30b7232dce7b8240441bed04912e06f666.zip
Added script bindings for reading map objects
map_get_objects([string filter]): returns all object of the current map optionally filtered by type. map_get_object_property(handle object, string key): returns the value of the property of the object. map_get_object_bounds(handle object): returns x, y, width, height of an object. map_get_object_name(handle object): returns name of an object. map_get_object_type(handle object): returns type of an object. Mantis-issue: 397 Reviewed-by: Thorbjørn Lindeijer
Diffstat (limited to 'src/game-server/map.h')
-rw-r--r--src/game-server/map.h60
1 files changed, 58 insertions, 2 deletions
diff --git a/src/game-server/map.h b/src/game-server/map.h
index 7c58d005..f1180a77 100644
--- a/src/game-server/map.h
+++ b/src/game-server/map.h
@@ -26,11 +26,12 @@
#include <string>
#include <vector>
+#include "utils/logger.h"
#include "utils/point.h"
+#include "utils/string.h"
typedef std::list<Point> Path;
typedef Path::iterator PathIterator;
-
enum BlockType
{
BLOCKTYPE_NONE = -1,
@@ -59,6 +60,46 @@ class MetaTile
char blockmask; /**< walkability bitfield */
};
+class MapObject
+{
+ public:
+ MapObject(const Rectangle &bounds,
+ const std::string &name,
+ const std::string &type)
+ : mBounds(bounds),
+ mName(name),
+ mType(type)
+ { }
+
+ void addProperty(const std::string &key, const std::string &value)
+ {
+ if (mProperties.contains(key))
+ LOG_WARN("Duplicate property " << key <<
+ " of object " << mName);
+ else
+ mProperties.insert(key, value);
+ }
+
+ std::string getProperty(const std::string &key) const
+ { return mProperties.find(key); }
+
+ const std::string &getName() const
+ { return mName; }
+
+ const std::string &getType() const
+ { return mType; }
+
+ const Rectangle &getBounds() const
+ { return mBounds; }
+
+ private:
+ Rectangle mBounds;
+ std::string mName;
+ std::string mType;
+ utils::NameMap<std::string> mProperties;
+};
+
+
/**
* A tile map.
*/
@@ -71,6 +112,8 @@ class Map
Map(int width, int height,
int tileWidth, int tileHeight);
+ ~Map();
+
/**
* Sets the size of the map. This will destroy any existing map data.
*/
@@ -129,9 +172,21 @@ class Map
/**
* Sets a map property
*/
- void setProperty(const std::string& key, const std::string& val)
+ void setProperty(const std::string &key, const std::string &val)
{ mProperties[key] = val; }
+ /**
+ * Adds an object.
+ */
+ void addObject(MapObject *object)
+ { mMapObjects.push_back(object); }
+
+ /**
+ * Returns the objects of the map.
+ */
+ const std::vector<MapObject*> &getObjects() const
+ { return mMapObjects; }
+
/**
* Find a path from one location to the next.
*/
@@ -154,6 +209,7 @@ class Map
std::map<std::string, std::string> mProperties;
std::vector<MetaTile> mMetaTiles;
+ std::vector<MapObject*> mMapObjects;
};
#endif