diff options
author | Andrei Karas <akaras@inbox.ru> | 2015-10-16 00:32:58 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2015-10-16 00:32:58 +0300 |
commit | f672c7242dfa8d278d826f1e460af96265ca307c (patch) | |
tree | 623589aa9a104febeac4147ea349e05c76fb8c77 | |
parent | 6d44c69cb0cc9c2ac8a94c56c07ed45f63ab9726 (diff) | |
download | manaverse-f672c7242dfa8d278d826f1e460af96265ca307c.tar.gz manaverse-f672c7242dfa8d278d826f1e460af96265ca307c.tar.bz2 manaverse-f672c7242dfa8d278d826f1e460af96265ca307c.tar.xz manaverse-f672c7242dfa8d278d826f1e460af96265ca307c.zip |
Impliment packet SMSG_MAP_SET_TILES_TYPE (hercules)
This allow change collision types from server.
-rw-r--r-- | src/enums/resources/map/blocktype.h | 12 | ||||
-rw-r--r-- | src/net/eathena/maprecv.cpp | 33 | ||||
-rw-r--r-- | src/resources/map/map.cpp | 43 | ||||
-rw-r--r-- | src/resources/map/map.h | 8 |
4 files changed, 79 insertions, 17 deletions
diff --git a/src/enums/resources/map/blocktype.h b/src/enums/resources/map/blocktype.h index af8acdb79..9a866273c 100644 --- a/src/enums/resources/map/blocktype.h +++ b/src/enums/resources/map/blocktype.h @@ -27,12 +27,12 @@ enumStart(BlockType) { - NONE = -1, - WALL, - AIR, - WATER, - GROUND, - GROUNDTOP, + NONE = -1, + GROUND = 0, + WALL = 1, + AIR = 2, + WATER = 3, + GROUNDTOP = 4, NB_BLOCKTYPES } enumEnd(BlockType); diff --git a/src/net/eathena/maprecv.cpp b/src/net/eathena/maprecv.cpp index 06a039306..df43cac76 100644 --- a/src/net/eathena/maprecv.cpp +++ b/src/net/eathena/maprecv.cpp @@ -22,8 +22,14 @@ #include "logger.h" +#include "enums/resources/map/blocktype.h" + +#include "gui/viewport.h" + #include "net/messagein.h" +#include "resources/map/map.h" + #include "debug.h" namespace EAthena @@ -59,13 +65,26 @@ void MapRecv::processInstanceDelete(Net::MessageIn &msg) void MapRecv::processSetTilesType(Net::MessageIn &msg) { - UNIMPLIMENTEDPACKET; - msg.readInt16("x1"); - msg.readInt16("y1"); - msg.readInt16("x2"); - msg.readInt16("y2"); - msg.readInt32("mask"); - msg.readString(16, "map name"); + const int x1 = msg.readInt16("x1"); + const int y1 = msg.readInt16("y1"); + const int x2 = msg.readInt16("x2"); + const int y2 = msg.readInt16("y2"); + const BlockType mask = fromInt(msg.readInt32("mask"), BlockType); + const std::string name = msg.readString(16, "map name"); + + Map *const map = viewport->getMap(); +// logger->log("map test name: %s, mask %d", map->getGatName().c_str(), (int)mask); + if (map && map->getGatName() == name) + { + for (int y = y1; y <= y2; y ++) + { + for (int x = x1; x <= x2; x ++) + { + logger->log("set col %d,%d", x, y); + map->setBlockMask(x, y, mask); + } + } + } } } // namespace EAthena diff --git a/src/resources/map/map.cpp b/src/resources/map/map.cpp index 097a7a11d..de6090dc2 100644 --- a/src/resources/map/map.cpp +++ b/src/resources/map/map.cpp @@ -680,7 +680,7 @@ const Tileset *Map::getTilesetWithGid(const int gid) const } void Map::addBlockMask(const int x, const int y, - const BlockTypeT type) + const BlockTypeT type) { if (type == BlockType::NONE || !contains(x, y)) return; @@ -712,6 +712,39 @@ void Map::addBlockMask(const int x, const int y, } } +void Map::setBlockMask(const int x, const int y, + const BlockTypeT type) +{ + if (type == BlockType::NONE || !contains(x, y)) + return; + + const int tileNum = x + y * mWidth; + + switch (type) + { + case BlockType::WALL: + mMetaTiles[tileNum].blockmask = BlockMask::WALL; + break; + case BlockType::AIR: + mMetaTiles[tileNum].blockmask = BlockMask::AIR; + break; + case BlockType::WATER: + mMetaTiles[tileNum].blockmask = BlockMask::WATER; + break; + case BlockType::GROUND: + mMetaTiles[tileNum].blockmask = BlockMask::GROUND; + break; + case BlockType::GROUNDTOP: + mMetaTiles[tileNum].blockmask = BlockMask::GROUNDTOP; + break; + default: + case BlockType::NONE: + case BlockType::NB_BLOCKTYPES: + // Do nothing. + break; + } +} + bool Map::getWalk(const int x, const int y, const unsigned char blockWalkMask) const { @@ -781,6 +814,14 @@ const std::string Map::getFilename() const return fileName.substr(lastSlash, fileName.rfind(".") - lastSlash); } +const std::string Map::getGatName() const +{ + const std::string fileName = getProperty("_filename"); + const size_t lastSlash = fileName.rfind("/") + 1; + return fileName.substr(lastSlash, + fileName.rfind(".") - lastSlash).append(".gat"); +} + Path Map::findPath(const int startX, const int startY, const int destX, const int destY, const unsigned char blockWalkMask, diff --git a/src/resources/map/map.h b/src/resources/map/map.h index 9c74875d8..65fcb8f00 100644 --- a/src/resources/map/map.h +++ b/src/resources/map/map.h @@ -142,12 +142,12 @@ class Map final : public Properties, public ConfigListener const MetaTile *getMetaTile(const int x, const int y) const A_WARN_UNUSED; - /** - * Marks a tile as occupied. - */ void addBlockMask(const int x, const int y, const BlockTypeT type); + void setBlockMask(const int x, const int y, + const BlockTypeT type); + /** * Gets walkability for a tile with a blocking bitmask. When called * without walkmask, only blocks against colliding tiles. @@ -195,6 +195,8 @@ class Map final : public Properties, public ConfigListener */ const std::string getFilename() const A_WARN_UNUSED; + const std::string getGatName() const A_WARN_UNUSED; + /** * Find a path from one location to the next. */ |