From 3dec609dc5f343547fad87dbbd3d7c7e2c59dde5 Mon Sep 17 00:00:00 2001 From: Philipp Sehmisch Date: Thu, 19 Mar 2009 20:10:27 +0100 Subject: Implemented the possibility to have maps with or without PvP combat. PvP is governed by the map property "pvp". Currently it can be either "none" for no PvP combat or "free" for unrestricted PvP combat. "none" is the default value which is used when pvp is undefined. Later addition of more sophisticated PvP modes is possible. --- src/game-server/being.cpp | 5 +++++ src/game-server/map.cpp | 8 ++++++++ src/game-server/map.hpp | 16 +++++++++++++++- src/game-server/mapcomposite.cpp | 6 ++++++ src/game-server/mapcomposite.hpp | 13 +++++++++++++ src/game-server/mapreader.cpp | 19 ++++++++++++++++--- 6 files changed, 63 insertions(+), 4 deletions(-) diff --git a/src/game-server/being.cpp b/src/game-server/being.cpp index cec2c4e6..ace30861 100644 --- a/src/game-server/being.cpp +++ b/src/game-server/being.cpp @@ -190,6 +190,11 @@ void Being::performAttack(Damage const &damage, AttackZone const *attackZone) int type = o->getType(); if (type != OBJECT_CHARACTER && type != OBJECT_MONSTER) continue; + if (getMap()->getPvP() == PVP_NONE && + type == OBJECT_CHARACTER && + getType() == OBJECT_CHARACTER) + continue; + LOG_DEBUG("Attack Zone:"<< attPos.x<<":"<::const_iterator i; + i = mProperties.find(key); + if (i == mProperties.end()) return ""; + return i->second; +} + void Map::blockTile(int x, int y, BlockType type) { if (type == BLOCKTYPE_NONE || x < 0 || y < 0 || x >= mWidth || y >= mHeight) diff --git a/src/game-server/map.hpp b/src/game-server/map.hpp index 3a9badf9..bbc33fea 100644 --- a/src/game-server/map.hpp +++ b/src/game-server/map.hpp @@ -154,6 +154,17 @@ class Map int getTileHeight() const { return tileHeight; } + /** + * Returns a general map property defined in the map file + */ + const std::string &getProperty(const std::string &key) const; + + /** + * Sets a map property + */ + void setProperty(const std::string& key, const std::string& val) + { mProperties[key] = val; } + /** * Find a path from one location to the next. */ @@ -170,11 +181,14 @@ class Map static const unsigned char BLOCKMASK_CHARACTER = 0x01;// = bin 0000 0001 static const unsigned char BLOCKMASK_MONSTER = 0x02; // = bin 0000 0010 int *mOccupation[NB_BLOCKTYPES]; + + // map properties int mWidth, mHeight; int tileWidth, tileHeight; - MetaTile *mMetaTiles; + std::map mProperties; // Pathfinding members + MetaTile *mMetaTiles; int onClosedList, onOpenList; }; diff --git a/src/game-server/mapcomposite.cpp b/src/game-server/mapcomposite.cpp index b9e4b863..e7267d08 100644 --- a/src/game-server/mapcomposite.cpp +++ b/src/game-server/mapcomposite.cpp @@ -532,6 +532,12 @@ void MapComposite::setMap(Map *m) assert(!mMap && m); mMap = m; mContent = new MapContent(m); + + std::string sPvP = m->getProperty ("pvp"); + if (sPvP == "free") mPvPRules = PVP_FREE; + else if (sPvP == "none") mPvPRules = PVP_NONE; + else mPvPRules = PVP_NONE; + } void MapComposite::update() diff --git a/src/game-server/mapcomposite.hpp b/src/game-server/mapcomposite.hpp index 078842d6..7242fad6 100644 --- a/src/game-server/mapcomposite.hpp +++ b/src/game-server/mapcomposite.hpp @@ -38,6 +38,12 @@ class Thing; struct MapContent; struct MapZone; +enum PvPRules +{ + PVP_NONE, // no PvP on this map + PVP_FREE // unrestricted PvP on this map + // [space for additional PvP modes] +}; /** * Ordered sets of zones of a map. */ @@ -289,6 +295,11 @@ class MapComposite */ void update(); + /** + * Gets the PvP rules on the map + */ + PvPRules getPvP() const { return mPvPRules; } + /** * Gets an iterator on the objects of the whole map. */ @@ -329,6 +340,8 @@ class MapComposite Script *mScript; /**< Script associated to this map. */ std::string mName; /**< Name of the map. */ unsigned short mID; /**< ID of the map. */ + + PvPRules mPvPRules; }; #endif diff --git a/src/game-server/mapreader.cpp b/src/game-server/mapreader.cpp index 9caddc24..758b37ee 100644 --- a/src/game-server/mapreader.cpp +++ b/src/game-server/mapreader.cpp @@ -114,7 +114,7 @@ void MapReader::readMap(const std::string &filename, MapComposite *composite) } } -Map* MapReader::readMap(xmlNodePtr node, std::string const &path, +Map* MapReader::readMap(xmlNodePtr node, std::string const &path, MapComposite *composite, std::vector &things) { // Take the filename off the path @@ -140,6 +140,19 @@ Map* MapReader::readMap(xmlNodePtr node, std::string const &path, ::tilesetFirstGids.push_back(XML::getProperty(node, "firstgid", 0)); } } + else if (xmlStrEqual(node->name, BAD_CAST "properties")) + { + for_each_xml_child_node(propNode, node) + { + if (xmlStrEqual(propNode->name, BAD_CAST "property")) + { + std::string key = XML::getProperty(propNode, "name", ""); + std::string val = XML::getProperty(propNode, "value", ""); + LOG_DEBUG(" "<setProperty(key, val); + } + } + } else if (xmlStrEqual(node->name, BAD_CAST "layer")) { // Layer 3 is collision layer. @@ -166,7 +179,7 @@ Map* MapReader::readMap(xmlNodePtr node, std::string const &path, int objW = XML::getProperty(objectNode, "width", 0); int objH = XML::getProperty(objectNode, "height", 0); Rectangle rect = { objX, objY, objW, objH }; - + if (objType == "WARP") { @@ -236,7 +249,7 @@ Map* MapReader::readMap(xmlNodePtr node, std::string const &path, { if (xmlStrEqual(propertyNode->name, BAD_CAST "property")) { - std::string value = XML::getProperty(propertyNode, "name", std::string()); + std::string value = XML::getProperty(propertyNode, "name", std::string()); value = utils::toupper(value); if (value == "MONSTER_ID") { -- cgit v1.2.3-60-g2f50