tibia-rme/source/map_region.cpp

266 lines
5.6 KiB
C++
Raw Permalink Normal View History

//////////////////////////////////////////////////////////////////////
// This file is part of Remere's Map Editor
//////////////////////////////////////////////////////////////////////
2020-07-30 11:42:28 -03:00
// Remere's Map Editor is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Remere's Map Editor is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//////////////////////////////////////////////////////////////////////
#include "main.h"
#include "map_region.h"
#include "basemap.h"
#include "position.h"
#include "tile.h"
//**************** Tile Location **********************
TileLocation::TileLocation() :
tile(nullptr),
position(0, 0, 0),
spawn_monster_count(0),
spawn_npc_count(0),
waypoint_count(0),
2023-10-09 19:12:16 -07:00
house_exits(nullptr) {
2015-12-06 11:42:37 -03:00
////
}
2023-10-09 19:12:16 -07:00
TileLocation::~TileLocation() {
delete tile;
delete house_exits;
}
2016-09-29 19:24:45 -03:00
2023-10-09 19:12:16 -07:00
int TileLocation::size() const {
if (tile) {
return tile->size();
2023-10-09 19:12:16 -07:00
}
return spawn_monster_count + spawn_npc_count + waypoint_count + (house_exits ? 1 : 0);
}
2023-10-09 19:12:16 -07:00
bool TileLocation::empty() const {
return size() == 0;
}
2023-10-09 19:12:16 -07:00
HouseExitList* TileLocation::createHouseExits() {
if (!house_exits) {
feat: synchronizing commits with the official rme repository (#36) * Show indicators for pickupable and moveable items * Fix: drawing always refreshing ui * Fix crash on invalid friend for wallbrush * Option to remove empty spawns * Draws position indicator, some code cleanup * Teleport copy/paste improvements * Fix flood fill * Add function to get minimap/8bit color * Small code cleanup * Cleanup Position * Code cleanup and small optimizations * Code cleanup * Code cleanup and small optimizations (#406) * Cleanup and cast functions. * Avoid adding a new Unique ID if it already exists * Code cleanup and small optimizations * More changes and cleanup * Changes and cleanup * Some changes * Fix copy position. * Only show uid/aid alert if it really changed * Add actions history panel * Does not draw tooltips on minimap mode * Use constexpr * Replace items fix (#408) * Draw grid small optimization * Small change in selection box and Fix #409 * Fix some xpm * Ingame box improvements, add lights support. * Fix go to previous position (#410) * Fix depot crash (#411) * Fix XPMs * Export minimap as .otmm (otclient format) or .png (#413) * Fix glitch after drawing secondary map * fix * Update about_window.cpp * sonar * fix Minimap and progress bar * fix erro load items.xml * fix * fix doodad brush * fix: slightly more accurate house size estimation * feat: update items.otb and items.xml * fix: bad merge * Revert "feat: update items.otb and items.xml" This reverts commit 40f1edc70f17c423282d546a41541a8fe9b92dcc. --------- Co-authored-by: Nailson <Mignari@users.noreply.github.com> Co-authored-by: wtver <51377408+maattch@users.noreply.github.com> Co-authored-by: Majesty <32709570+majestyotbr@users.noreply.github.com> Co-authored-by: Luan Santos <github@luan.sh>
2023-10-09 23:02:37 -03:00
house_exits = new HouseExitList();
2023-10-09 19:12:16 -07:00
}
feat: synchronizing commits with the official rme repository (#36) * Show indicators for pickupable and moveable items * Fix: drawing always refreshing ui * Fix crash on invalid friend for wallbrush * Option to remove empty spawns * Draws position indicator, some code cleanup * Teleport copy/paste improvements * Fix flood fill * Add function to get minimap/8bit color * Small code cleanup * Cleanup Position * Code cleanup and small optimizations * Code cleanup * Code cleanup and small optimizations (#406) * Cleanup and cast functions. * Avoid adding a new Unique ID if it already exists * Code cleanup and small optimizations * More changes and cleanup * Changes and cleanup * Some changes * Fix copy position. * Only show uid/aid alert if it really changed * Add actions history panel * Does not draw tooltips on minimap mode * Use constexpr * Replace items fix (#408) * Draw grid small optimization * Small change in selection box and Fix #409 * Fix some xpm * Ingame box improvements, add lights support. * Fix go to previous position (#410) * Fix depot crash (#411) * Fix XPMs * Export minimap as .otmm (otclient format) or .png (#413) * Fix glitch after drawing secondary map * fix * Update about_window.cpp * sonar * fix Minimap and progress bar * fix erro load items.xml * fix * fix doodad brush * fix: slightly more accurate house size estimation * feat: update items.otb and items.xml * fix: bad merge * Revert "feat: update items.otb and items.xml" This reverts commit 40f1edc70f17c423282d546a41541a8fe9b92dcc. --------- Co-authored-by: Nailson <Mignari@users.noreply.github.com> Co-authored-by: wtver <51377408+maattch@users.noreply.github.com> Co-authored-by: Majesty <32709570+majestyotbr@users.noreply.github.com> Co-authored-by: Luan Santos <github@luan.sh>
2023-10-09 23:02:37 -03:00
return house_exits;
}
//**************** Floor **********************
2023-10-09 19:12:16 -07:00
Floor::Floor(int sx, int sy, int z) {
sx = sx & ~3;
sy = sy & ~3;
2023-10-09 19:12:16 -07:00
for (int i = 0; i < rme::MapLayers; ++i) {
locs[i].position.x = sx + (i >> 2);
locs[i].position.y = sy + (i & 3);
locs[i].position.z = z;
}
}
//**************** QTreeNode **********************
2023-10-09 19:12:16 -07:00
QTreeNode::QTreeNode(BaseMap &map) :
map(map),
visible(0),
2023-10-09 19:12:16 -07:00
isLeaf(false) {
// Doesn't matter if we're leaf or node
2023-10-09 19:12:16 -07:00
for (int i = 0; i < rme::MapLayers; ++i) {
child[i] = nullptr;
2023-10-09 19:12:16 -07:00
}
}
2023-10-09 19:12:16 -07:00
QTreeNode::~QTreeNode() {
if (isLeaf) {
for (int i = 0; i < rme::MapLayers; ++i) {
2016-11-12 10:56:02 -03:00
delete array[i];
2023-10-09 19:12:16 -07:00
}
2015-12-06 11:42:37 -03:00
} else {
2023-10-09 19:12:16 -07:00
for (int i = 0; i < rme::MapLayers; ++i) {
2016-11-12 10:56:02 -03:00
delete child[i];
2023-10-09 19:12:16 -07:00
}
}
}
2023-10-09 19:12:16 -07:00
QTreeNode* QTreeNode::getLeaf(int x, int y) {
QTreeNode* node = this;
uint32_t cx = x, cy = y;
2023-10-09 19:12:16 -07:00
while (node) {
if (node->isLeaf) {
return node;
2015-12-06 11:42:37 -03:00
} else {
uint32_t index = ((cx & 0xC000) >> 14) | ((cy & 0xC000) >> 12);
2023-10-09 19:12:16 -07:00
if (node->child[index]) {
node = node->child[index];
cx <<= 2;
cy <<= 2;
2015-12-06 11:42:37 -03:00
} else {
return nullptr;
}
}
}
return nullptr;
}
2023-10-09 19:12:16 -07:00
QTreeNode* QTreeNode::getLeafForce(int x, int y) {
QTreeNode* node = this;
uint32_t cx = x, cy = y;
int level = 6;
2023-10-09 19:12:16 -07:00
while (node) {
uint32_t index = ((cx & 0xC000) >> 14) | ((cy & 0xC000) >> 12);
2023-10-09 19:12:16 -07:00
QTreeNode*&qt = node->child[index];
if (qt) {
if (qt->isLeaf) {
return qt;
2023-10-09 19:12:16 -07:00
}
2015-12-06 11:42:37 -03:00
} else {
2023-10-09 19:12:16 -07:00
if (level == 0) {
qt = newd QTreeNode(map);
qt->isLeaf = true;
return qt;
2015-12-06 11:42:37 -03:00
} else {
qt = newd QTreeNode(map);
}
}
node = node->child[index];
cx <<= 2;
cy <<= 2;
level -= 1;
}
return nullptr;
}
2023-10-09 19:12:16 -07:00
Floor* QTreeNode::createFloor(int x, int y, int z) {
ASSERT(isLeaf);
2023-10-09 19:12:16 -07:00
if (!array[z]) {
array[z] = newd Floor(x, y, z);
2023-10-09 19:12:16 -07:00
}
return array[z];
}
2023-10-09 19:12:16 -07:00
bool QTreeNode::isVisible(bool underground) {
return testFlags(visible, underground + 1);
}
2023-10-09 19:12:16 -07:00
bool QTreeNode::isRequested(bool underground) {
if (underground) {
return testFlags(visible, 4);
} else {
return testFlags(visible, 8);
}
}
2023-10-09 19:12:16 -07:00
void QTreeNode::clearVisible(uint32_t u) {
if (isLeaf) {
visible &= u;
2023-10-09 19:12:16 -07:00
} else {
for (int i = 0; i < rme::MapLayers; ++i) {
if (child[i]) {
child[i]->clearVisible(u);
2023-10-09 19:12:16 -07:00
}
}
}
}
2023-10-09 19:12:16 -07:00
bool QTreeNode::isVisible(uint32_t client, bool underground) {
if (underground) {
feat: synchronizing commits with the official rme repository (#36) * Show indicators for pickupable and moveable items * Fix: drawing always refreshing ui * Fix crash on invalid friend for wallbrush * Option to remove empty spawns * Draws position indicator, some code cleanup * Teleport copy/paste improvements * Fix flood fill * Add function to get minimap/8bit color * Small code cleanup * Cleanup Position * Code cleanup and small optimizations * Code cleanup * Code cleanup and small optimizations (#406) * Cleanup and cast functions. * Avoid adding a new Unique ID if it already exists * Code cleanup and small optimizations * More changes and cleanup * Changes and cleanup * Some changes * Fix copy position. * Only show uid/aid alert if it really changed * Add actions history panel * Does not draw tooltips on minimap mode * Use constexpr * Replace items fix (#408) * Draw grid small optimization * Small change in selection box and Fix #409 * Fix some xpm * Ingame box improvements, add lights support. * Fix go to previous position (#410) * Fix depot crash (#411) * Fix XPMs * Export minimap as .otmm (otclient format) or .png (#413) * Fix glitch after drawing secondary map * fix * Update about_window.cpp * sonar * fix Minimap and progress bar * fix erro load items.xml * fix * fix doodad brush * fix: slightly more accurate house size estimation * feat: update items.otb and items.xml * fix: bad merge * Revert "feat: update items.otb and items.xml" This reverts commit 40f1edc70f17c423282d546a41541a8fe9b92dcc. --------- Co-authored-by: Nailson <Mignari@users.noreply.github.com> Co-authored-by: wtver <51377408+maattch@users.noreply.github.com> Co-authored-by: Majesty <32709570+majestyotbr@users.noreply.github.com> Co-authored-by: Luan Santos <github@luan.sh>
2023-10-09 23:02:37 -03:00
return testFlags(visible >> rme::MapLayers, static_cast<uint64_t>(1) << client);
} else {
2020-01-28 10:00:30 +01:00
return testFlags(visible, static_cast<uint64_t>(1) << client);
}
}
2023-10-09 19:12:16 -07:00
void QTreeNode::setVisible(bool underground, bool value) {
if (underground) {
if (value) {
visible |= 2;
2023-10-09 19:12:16 -07:00
} else {
visible &= ~2;
2023-10-09 19:12:16 -07:00
}
2015-12-06 11:42:37 -03:00
} else { // overground
2023-10-09 19:12:16 -07:00
if (value) {
visible |= 1;
2023-10-09 19:12:16 -07:00
} else {
visible &= 1;
2023-10-09 19:12:16 -07:00
}
}
}
2023-10-09 19:12:16 -07:00
void QTreeNode::setRequested(bool underground, bool r) {
if (r) {
visible |= (underground ? 4 : 8);
} else {
visible &= ~(underground ? 4 : 8);
}
}
2023-10-09 19:12:16 -07:00
void QTreeNode::setVisible(uint32_t client, bool underground, bool value) {
if (value) {
feat: synchronizing commits with the official rme repository (#36) * Show indicators for pickupable and moveable items * Fix: drawing always refreshing ui * Fix crash on invalid friend for wallbrush * Option to remove empty spawns * Draws position indicator, some code cleanup * Teleport copy/paste improvements * Fix flood fill * Add function to get minimap/8bit color * Small code cleanup * Cleanup Position * Code cleanup and small optimizations * Code cleanup * Code cleanup and small optimizations (#406) * Cleanup and cast functions. * Avoid adding a new Unique ID if it already exists * Code cleanup and small optimizations * More changes and cleanup * Changes and cleanup * Some changes * Fix copy position. * Only show uid/aid alert if it really changed * Add actions history panel * Does not draw tooltips on minimap mode * Use constexpr * Replace items fix (#408) * Draw grid small optimization * Small change in selection box and Fix #409 * Fix some xpm * Ingame box improvements, add lights support. * Fix go to previous position (#410) * Fix depot crash (#411) * Fix XPMs * Export minimap as .otmm (otclient format) or .png (#413) * Fix glitch after drawing secondary map * fix * Update about_window.cpp * sonar * fix Minimap and progress bar * fix erro load items.xml * fix * fix doodad brush * fix: slightly more accurate house size estimation * feat: update items.otb and items.xml * fix: bad merge * Revert "feat: update items.otb and items.xml" This reverts commit 40f1edc70f17c423282d546a41541a8fe9b92dcc. --------- Co-authored-by: Nailson <Mignari@users.noreply.github.com> Co-authored-by: wtver <51377408+maattch@users.noreply.github.com> Co-authored-by: Majesty <32709570+majestyotbr@users.noreply.github.com> Co-authored-by: Luan Santos <github@luan.sh>
2023-10-09 23:02:37 -03:00
visible |= (1 << client << (underground ? rme::MapLayers : 0));
2023-10-09 19:12:16 -07:00
} else {
feat: synchronizing commits with the official rme repository (#36) * Show indicators for pickupable and moveable items * Fix: drawing always refreshing ui * Fix crash on invalid friend for wallbrush * Option to remove empty spawns * Draws position indicator, some code cleanup * Teleport copy/paste improvements * Fix flood fill * Add function to get minimap/8bit color * Small code cleanup * Cleanup Position * Code cleanup and small optimizations * Code cleanup * Code cleanup and small optimizations (#406) * Cleanup and cast functions. * Avoid adding a new Unique ID if it already exists * Code cleanup and small optimizations * More changes and cleanup * Changes and cleanup * Some changes * Fix copy position. * Only show uid/aid alert if it really changed * Add actions history panel * Does not draw tooltips on minimap mode * Use constexpr * Replace items fix (#408) * Draw grid small optimization * Small change in selection box and Fix #409 * Fix some xpm * Ingame box improvements, add lights support. * Fix go to previous position (#410) * Fix depot crash (#411) * Fix XPMs * Export minimap as .otmm (otclient format) or .png (#413) * Fix glitch after drawing secondary map * fix * Update about_window.cpp * sonar * fix Minimap and progress bar * fix erro load items.xml * fix * fix doodad brush * fix: slightly more accurate house size estimation * feat: update items.otb and items.xml * fix: bad merge * Revert "feat: update items.otb and items.xml" This reverts commit 40f1edc70f17c423282d546a41541a8fe9b92dcc. --------- Co-authored-by: Nailson <Mignari@users.noreply.github.com> Co-authored-by: wtver <51377408+maattch@users.noreply.github.com> Co-authored-by: Majesty <32709570+majestyotbr@users.noreply.github.com> Co-authored-by: Luan Santos <github@luan.sh>
2023-10-09 23:02:37 -03:00
visible &= ~(1 << client << (underground ? rme::MapLayers : 0));
2023-10-09 19:12:16 -07:00
}
}
2023-10-09 19:12:16 -07:00
TileLocation* QTreeNode::getTile(int x, int y, int z) {
ASSERT(isLeaf);
Floor* f = array[z];
2023-10-09 19:12:16 -07:00
if (!f) {
return nullptr;
2023-10-09 19:12:16 -07:00
}
return &f->locs[(x & 3) * 4 + (y & 3)];
}
2023-10-09 19:12:16 -07:00
TileLocation* QTreeNode::createTile(int x, int y, int z) {
ASSERT(isLeaf);
Floor* f = createFloor(x, y, z);
return &f->locs[(x & 3) * 4 + (y & 3)];
}
2023-10-09 19:12:16 -07:00
Tile* QTreeNode::setTile(int x, int y, int z, Tile* newtile) {
ASSERT(isLeaf);
Floor* f = createFloor(x, y, z);
2016-09-29 19:24:45 -03:00
int offset_x = x & 3;
int offset_y = y & 3;
2023-10-09 19:12:16 -07:00
TileLocation* tmp = &f->locs[offset_x * 4 + offset_y];
Tile* oldtile = tmp->tile;
tmp->tile = newtile;
2023-10-09 19:12:16 -07:00
if (newtile && !oldtile) {
++map.tilecount;
2023-10-09 19:12:16 -07:00
} else if (oldtile && !newtile) {
--map.tilecount;
2023-10-09 19:12:16 -07:00
}
return oldtile;
}
2023-10-09 19:12:16 -07:00
void QTreeNode::clearTile(int x, int y, int z) {
ASSERT(isLeaf);
Floor* f = createFloor(x, y, z);
2016-09-29 19:24:45 -03:00
int offset_x = x & 3;
int offset_y = y & 3;
2023-10-09 19:12:16 -07:00
TileLocation* tmp = &f->locs[offset_x * 4 + offset_y];
delete tmp->tile;
tmp->tile = map.allocator(tmp);
}