diff --git a/src/framework/core/binarytree.cpp b/src/framework/core/binarytree.cpp index 5e07cd39..ea5a96bb 100644 --- a/src/framework/core/binarytree.cpp +++ b/src/framework/core/binarytree.cpp @@ -163,6 +163,23 @@ std::string BinaryTree::getString() return ret; } +Position BinaryTree::getPosition() +{ + Position ret; + ret.x = getU16(); + ret.y = getU16(); + ret.z = getU8(); + return ret; +} + +Point BinaryTree::getPoint() +{ + Point ret; + ret.x = getU8(); + ret.y = getU8(); + return ret; +} + BinaryTreePtr BinaryTree::makeChild(uint8 type) { BinaryTreePtr child(new BinaryTree(m_fin)); diff --git a/src/framework/core/binarytree.h b/src/framework/core/binarytree.h index 1e63c8ea..a0966bb6 100644 --- a/src/framework/core/binarytree.h +++ b/src/framework/core/binarytree.h @@ -49,8 +49,8 @@ public: uint32 getU32(); uint64 getU64(); std::string getString(); - Position getPosition() { return Position(getU16(), getU16(), getU8()); } - Point getPoint() { return Point(getU8(), getU8()); } + Position getPosition(); + Point getPoint(); void setType(uint8 type); void writeU8(uint8 u8); diff --git a/src/framework/xml/tinyxml.h b/src/framework/xml/tinyxml.h index e7658db4..0b93fea9 100644 --- a/src/framework/xml/tinyxml.h +++ b/src/framework/xml/tinyxml.h @@ -963,12 +963,19 @@ public: Position readPos(const std::string& base = std::string()) const { - return Position(readType(base + "x"), readType(base + "y"), readType(base + "z")); + Position ret; + ret.x = readType(base + "x"); + ret.y = readType(base + "y"); + ret.z = readType(base + "z"); + return ret; } Point readPoint() const { - return Point(readType("x"), readType("y")); + Point ret; + ret.x = readType("x"); + ret.y = readType("y"); + return ret; } /** Template form of the attribute query which will try to read the diff --git a/src/otclient/map.cpp b/src/otclient/map.cpp index 5698f3b0..a43ef985 100644 --- a/src/otclient/map.cpp +++ b/src/otclient/map.cpp @@ -36,9 +36,6 @@ #include #include -/// TODO: Move it to Position class if needed -static inline Position operator&(const Position& pos, int a) { return Position(pos.x & a, pos.y & a, pos.z); } - Map g_map; void Map::terminate() diff --git a/src/otclient/position.h b/src/otclient/position.h index 6326a577..1729d84d 100644 --- a/src/otclient/position.h +++ b/src/otclient/position.h @@ -164,12 +164,12 @@ public: Position& operator-=(const Position& other) { x-=other.x; y-=other.y; z-=other.z; return *this; } // Point conversion(s) Position operator+(const Point& other) const { return Position(x + other.x, y + other.y, z); } + Position operator&(int a) const { return Position(x & a, y & a, z); } Position& operator+=(const Point& other) { x += other.x; y += other.y; return *this; } Position& operator=(const Position& other) { x = other.x; y = other.y; z = other.z; return *this; } bool operator==(const Position& other) const { return other.x == x && other.y == y && other.z == z; } bool operator!=(const Position& other) const { return other.x!=x || other.y!=y || other.z!=z; } - bool isInRange(const Position& pos, int xRange, int yRange) const { return std::abs(x-pos.x) <= xRange && std::abs(y-pos.y) <= yRange && z == pos.z; } bool isInRange(const Position& pos, int minXRange, int maxXRange, int minYRange, int maxYRange) const { return (pos.x >= x-minXRange && pos.x <= x+maxXRange && pos.y >= y-minYRange && pos.y <= y+maxYRange && pos.z == z);