2012-06-29 16:44:26 +02:00
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
|
// 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
|
2012-06-29 16:44:26 +02:00
|
|
|
// 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.
|
2016-09-29 19:24:45 -03:00
|
|
|
//
|
2020-07-30 11:42:28 -03:00
|
|
|
// Remere's Map Editor is distributed in the hope that it will be useful,
|
2012-06-29 16:44:26 +02:00
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2020-07-30 11:42:28 -03:00
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2012-06-29 16:44:26 +02:00
|
|
|
// GNU General Public License for more details.
|
2016-09-29 19:24:45 -03:00
|
|
|
//
|
2012-06-29 16:44:26 +02:00
|
|
|
// You should have received a copy of the GNU General Public License
|
2020-07-30 11:42:28 -03:00
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2012-06-29 16:44:26 +02:00
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
#include "main.h"
|
|
|
|
|
|
|
|
|
|
#include "brush.h"
|
|
|
|
|
|
|
|
|
|
#include "tile.h"
|
2021-05-25 00:29:12 -03:00
|
|
|
#include "monster.h"
|
2012-06-29 16:44:26 +02:00
|
|
|
#include "house.h"
|
|
|
|
|
#include "basemap.h"
|
2021-05-25 00:29:12 -03:00
|
|
|
#include "spawn_monster.h"
|
2012-06-29 16:44:26 +02:00
|
|
|
#include "ground_brush.h"
|
|
|
|
|
#include "wall_brush.h"
|
|
|
|
|
#include "carpet_brush.h"
|
|
|
|
|
#include "table_brush.h"
|
2021-05-25 00:29:12 -03:00
|
|
|
#include "npc.h"
|
|
|
|
|
#include "spawn_npc.h"
|
2012-06-29 16:44:26 +02:00
|
|
|
|
|
|
|
|
Tile::Tile(int x, int y, int z) :
|
2014-01-22 20:16:17 +01:00
|
|
|
location(nullptr),
|
|
|
|
|
ground(nullptr),
|
2021-05-25 00:29:12 -03:00
|
|
|
monster(nullptr),
|
|
|
|
|
spawnMonster(nullptr),
|
|
|
|
|
npc(nullptr),
|
|
|
|
|
spawnNpc(nullptr),
|
2012-06-29 16:44:26 +02:00
|
|
|
house_id(0),
|
|
|
|
|
mapflags(0),
|
2018-04-22 10:54:06 -03:00
|
|
|
statflags(0),
|
2023-10-09 19:12:16 -07:00
|
|
|
minimapColor(INVALID_MINIMAP_COLOR) {
|
2015-12-06 11:42:37 -03:00
|
|
|
////
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
|
|
|
|
|
2023-10-09 19:12:16 -07:00
|
|
|
Tile::Tile(TileLocation &loc) :
|
2012-06-29 16:44:26 +02:00
|
|
|
location(&loc),
|
2014-01-22 20:16:17 +01:00
|
|
|
ground(nullptr),
|
2021-05-25 00:29:12 -03:00
|
|
|
monster(nullptr),
|
|
|
|
|
spawnMonster(nullptr),
|
|
|
|
|
npc(nullptr),
|
|
|
|
|
spawnNpc(nullptr),
|
2012-06-29 16:44:26 +02:00
|
|
|
house_id(0),
|
|
|
|
|
mapflags(0),
|
2018-04-22 10:54:06 -03:00
|
|
|
statflags(0),
|
2023-10-09 19:12:16 -07:00
|
|
|
minimapColor(INVALID_MINIMAP_COLOR) {
|
2015-12-06 11:42:37 -03:00
|
|
|
////
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
|
|
|
|
|
2023-10-09 19:12:16 -07:00
|
|
|
Tile::~Tile() {
|
|
|
|
|
while (!items.empty()) {
|
2012-06-29 16:44:26 +02:00
|
|
|
delete items.back();
|
|
|
|
|
items.pop_back();
|
|
|
|
|
}
|
2021-05-25 00:29:12 -03:00
|
|
|
delete monster;
|
2023-10-09 19:12:16 -07:00
|
|
|
// printf("%d,%d,%d,%p\n", tilePos.x, tilePos.y, tilePos.z, ground);
|
2012-06-29 16:44:26 +02:00
|
|
|
delete ground;
|
2021-05-25 00:29:12 -03:00
|
|
|
delete spawnMonster;
|
|
|
|
|
delete npc;
|
|
|
|
|
delete spawnNpc;
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
|
|
|
|
|
2023-10-09 19:12:16 -07:00
|
|
|
Tile* Tile::deepCopy(BaseMap &map) const {
|
2012-06-29 16:44:26 +02:00
|
|
|
Tile* copy = map.allocator.allocateTile(location);
|
|
|
|
|
copy->flags = flags;
|
|
|
|
|
copy->house_id = house_id;
|
2023-10-09 19:12:16 -07:00
|
|
|
if (spawnMonster) {
|
|
|
|
|
copy->spawnMonster = spawnMonster->deepCopy();
|
|
|
|
|
}
|
|
|
|
|
if (spawnNpc) {
|
|
|
|
|
copy->spawnNpc = spawnNpc->deepCopy();
|
|
|
|
|
}
|
|
|
|
|
if (monster) {
|
|
|
|
|
copy->monster = monster->deepCopy();
|
|
|
|
|
}
|
|
|
|
|
if (npc) {
|
|
|
|
|
copy->npc = npc->deepCopy();
|
|
|
|
|
}
|
2012-06-29 16:44:26 +02:00
|
|
|
// Spawncount & exits are not transferred on copy!
|
2023-10-09 19:12:16 -07:00
|
|
|
if (ground) {
|
|
|
|
|
copy->ground = ground->deepCopy();
|
|
|
|
|
}
|
2012-06-29 16:44:26 +02:00
|
|
|
|
2023-10-09 19:12:16 -07:00
|
|
|
for (const Item* item : items) {
|
2023-10-09 23:02:37 -03:00
|
|
|
copy->items.push_back(item->deepCopy());
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
2023-11-08 17:04:13 -08:00
|
|
|
for (unsigned int zone : zones) {
|
|
|
|
|
copy->zones.insert(zone);
|
|
|
|
|
}
|
2012-06-29 16:44:26 +02:00
|
|
|
return copy;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-09 19:12:16 -07:00
|
|
|
uint32_t Tile::memsize() const {
|
2014-02-28 22:34:25 +01:00
|
|
|
uint32_t mem = sizeof(*this);
|
2023-10-09 19:12:16 -07:00
|
|
|
if (ground) {
|
|
|
|
|
mem += ground->memsize();
|
|
|
|
|
}
|
2012-06-29 16:44:26 +02:00
|
|
|
|
2023-10-09 19:12:16 -07:00
|
|
|
for (const Item* item : items) {
|
2023-10-09 23:02:37 -03:00
|
|
|
mem += item->memsize();
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mem += sizeof(Item*) * items.capacity();
|
|
|
|
|
|
|
|
|
|
return mem;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-09 19:12:16 -07:00
|
|
|
int Tile::size() const {
|
2012-06-29 16:44:26 +02:00
|
|
|
int sz = 0;
|
2023-10-09 19:12:16 -07:00
|
|
|
if (ground) {
|
|
|
|
|
++sz;
|
|
|
|
|
}
|
2012-06-29 16:44:26 +02:00
|
|
|
sz += items.size();
|
2023-10-09 19:12:16 -07:00
|
|
|
if (monster) {
|
|
|
|
|
++sz;
|
|
|
|
|
}
|
|
|
|
|
if (spawnMonster) {
|
|
|
|
|
++sz;
|
|
|
|
|
}
|
|
|
|
|
if (npc) {
|
|
|
|
|
++sz;
|
|
|
|
|
}
|
|
|
|
|
if (spawnNpc) {
|
|
|
|
|
++sz;
|
|
|
|
|
}
|
|
|
|
|
if (location) {
|
|
|
|
|
if (location->getHouseExits()) {
|
|
|
|
|
++sz;
|
|
|
|
|
}
|
|
|
|
|
if (location->getSpawnMonsterCount()) {
|
|
|
|
|
++sz;
|
|
|
|
|
}
|
|
|
|
|
if (location->getSpawnNpcCount()) {
|
|
|
|
|
++sz;
|
|
|
|
|
}
|
|
|
|
|
if (location->getWaypointCount()) {
|
|
|
|
|
++sz;
|
|
|
|
|
}
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
|
|
|
|
return sz;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Tile::merge(Tile* other) {
|
2023-10-09 23:02:37 -03:00
|
|
|
|
2023-10-09 19:12:16 -07:00
|
|
|
if (!other) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-10-09 23:02:37 -03:00
|
|
|
|
2023-10-09 19:12:16 -07:00
|
|
|
if (other->isPZ()) {
|
|
|
|
|
setPZ(true);
|
|
|
|
|
}
|
|
|
|
|
if (other->house_id) {
|
2012-06-29 16:44:26 +02:00
|
|
|
house_id = other->house_id;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-09 19:12:16 -07:00
|
|
|
if (other->ground) {
|
2012-06-29 16:44:26 +02:00
|
|
|
delete ground;
|
|
|
|
|
ground = other->ground;
|
2014-01-22 20:16:17 +01:00
|
|
|
other->ground = nullptr;
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
|
|
|
|
|
2023-10-09 19:12:16 -07:00
|
|
|
if (other->monster) {
|
2021-05-25 00:29:12 -03:00
|
|
|
delete monster;
|
|
|
|
|
monster = other->monster;
|
|
|
|
|
other->monster = nullptr;
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
|
|
|
|
|
2023-10-09 19:12:16 -07:00
|
|
|
if (other->spawnMonster) {
|
2021-05-25 00:29:12 -03:00
|
|
|
delete spawnMonster;
|
|
|
|
|
spawnMonster = other->spawnMonster;
|
|
|
|
|
other->spawnMonster = nullptr;
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
|
|
|
|
|
2023-10-09 19:12:16 -07:00
|
|
|
if (other->npc) {
|
2021-05-25 00:29:12 -03:00
|
|
|
delete npc;
|
|
|
|
|
npc = other->npc;
|
|
|
|
|
other->npc = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-09 19:12:16 -07:00
|
|
|
if (other->spawnNpc) {
|
2021-05-25 00:29:12 -03:00
|
|
|
delete spawnNpc;
|
|
|
|
|
spawnNpc = other->spawnNpc;
|
|
|
|
|
other->spawnNpc = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-09 19:12:16 -07:00
|
|
|
if (other->monster) {
|
2021-05-25 00:29:12 -03:00
|
|
|
delete monster;
|
|
|
|
|
monster = other->monster;
|
|
|
|
|
other->monster = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-09 19:12:16 -07:00
|
|
|
if (other->npc) {
|
2021-05-25 00:29:12 -03:00
|
|
|
delete npc;
|
|
|
|
|
npc = other->npc;
|
|
|
|
|
other->npc = nullptr;
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
|
|
|
|
|
2023-10-09 19:12:16 -07:00
|
|
|
for (Item* item : other->items) {
|
2023-10-09 23:02:37 -03:00
|
|
|
addItem(item);
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
|
|
|
|
other->items.clear();
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-09 19:12:16 -07:00
|
|
|
bool Tile::hasProperty(enum ITEMPROPERTY prop) const {
|
|
|
|
|
if (prop == PROTECTIONZONE && isPZ()) {
|
2012-06-29 16:44:26 +02:00
|
|
|
return true;
|
2023-10-09 19:12:16 -07:00
|
|
|
}
|
2012-06-29 16:44:26 +02:00
|
|
|
|
2023-10-09 19:12:16 -07:00
|
|
|
if (ground && ground->hasProperty(prop)) {
|
2012-06-29 16:44:26 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-09 19:12:16 -07:00
|
|
|
for (const Item* item : items) {
|
|
|
|
|
if (item->hasProperty(prop)) {
|
2012-06-29 16:44:26 +02:00
|
|
|
return true;
|
2023-10-09 19:12:16 -07:00
|
|
|
}
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-09 19:12:16 -07:00
|
|
|
uint16_t Tile::getGroundSpeed() const noexcept {
|
|
|
|
|
if (ground && !ground->isMetaItem()) {
|
2023-10-09 23:02:37 -03:00
|
|
|
return ground->getGroundSpeed();
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-09 19:12:16 -07:00
|
|
|
int Tile::getIndexOf(Item* item) const {
|
|
|
|
|
if (!item) {
|
2021-10-02 22:41:32 -03:00
|
|
|
return wxNOT_FOUND;
|
2023-10-09 19:12:16 -07:00
|
|
|
}
|
2021-10-02 22:41:32 -03:00
|
|
|
|
|
|
|
|
int index = 0;
|
2023-10-09 19:12:16 -07:00
|
|
|
if (ground) {
|
|
|
|
|
if (ground == item) {
|
2021-10-02 22:41:32 -03:00
|
|
|
return index;
|
2023-10-09 19:12:16 -07:00
|
|
|
}
|
2021-10-02 22:41:32 -03:00
|
|
|
index++;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-09 19:12:16 -07:00
|
|
|
if (!items.empty()) {
|
2021-10-02 22:41:32 -03:00
|
|
|
auto it = std::find(items.begin(), items.end(), item);
|
2023-10-09 19:12:16 -07:00
|
|
|
if (it != items.end()) {
|
2021-10-02 22:41:32 -03:00
|
|
|
index += (it - items.begin());
|
|
|
|
|
return index;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return wxNOT_FOUND;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-09 19:12:16 -07:00
|
|
|
Item* Tile::getTopItem() const {
|
|
|
|
|
if (!items.empty() && !items.back()->isMetaItem()) {
|
2012-06-29 16:44:26 +02:00
|
|
|
return items.back();
|
2023-10-09 19:12:16 -07:00
|
|
|
}
|
|
|
|
|
if (ground && !ground->isMetaItem()) {
|
2012-06-29 16:44:26 +02:00
|
|
|
return ground;
|
|
|
|
|
}
|
2014-01-22 20:16:17 +01:00
|
|
|
return nullptr;
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
|
|
|
|
|
2023-10-09 19:12:16 -07:00
|
|
|
Item* Tile::getItemAt(int index) const {
|
|
|
|
|
if (index < 0) {
|
2021-10-02 22:41:32 -03:00
|
|
|
return nullptr;
|
2023-10-09 19:12:16 -07:00
|
|
|
}
|
|
|
|
|
if (ground) {
|
|
|
|
|
if (index == 0) {
|
2021-10-02 22:41:32 -03:00
|
|
|
return ground;
|
2023-10-09 19:12:16 -07:00
|
|
|
}
|
2021-10-02 22:41:32 -03:00
|
|
|
index--;
|
|
|
|
|
}
|
2023-10-09 19:12:16 -07:00
|
|
|
if (!items.empty() && index >= 0 && index < items.size()) {
|
2023-10-09 23:02:37 -03:00
|
|
|
return items.at(index);
|
2021-10-02 22:41:32 -03:00
|
|
|
}
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-09 19:12:16 -07:00
|
|
|
void Tile::addItem(Item* item) {
|
|
|
|
|
if (!item) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (item->isGroundTile()) {
|
|
|
|
|
// printf("ADDING GROUND\n");
|
2012-06-29 16:44:26 +02:00
|
|
|
delete ground;
|
|
|
|
|
ground = item;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ItemVector::iterator it;
|
2016-09-29 19:24:45 -03:00
|
|
|
|
2012-06-29 16:44:26 +02:00
|
|
|
uint16_t gid = item->getGroundEquivalent();
|
2023-10-09 19:12:16 -07:00
|
|
|
if (gid != 0) {
|
2012-06-29 16:44:26 +02:00
|
|
|
delete ground;
|
|
|
|
|
ground = Item::Create(gid);
|
|
|
|
|
// At the very bottom!
|
|
|
|
|
it = items.begin();
|
|
|
|
|
} else {
|
2023-10-09 19:12:16 -07:00
|
|
|
if (item->isAlwaysOnBottom()) {
|
2012-06-29 16:44:26 +02:00
|
|
|
it = items.begin();
|
2023-10-09 19:12:16 -07:00
|
|
|
while (true) {
|
|
|
|
|
if (it == items.end()) {
|
2012-06-29 16:44:26 +02:00
|
|
|
break;
|
2023-10-09 19:12:16 -07:00
|
|
|
} else if ((*it)->isAlwaysOnBottom()) {
|
|
|
|
|
if (item->getTopOrder() < (*it)->getTopOrder()) {
|
2012-06-29 16:44:26 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
} else { // Always on top
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
++it;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
it = items.end();
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-09-29 19:24:45 -03:00
|
|
|
|
2012-06-29 16:44:26 +02:00
|
|
|
items.insert(it, item);
|
|
|
|
|
|
2023-10-09 19:12:16 -07:00
|
|
|
if (item->isSelected()) {
|
2012-06-29 16:44:26 +02:00
|
|
|
statflags |= TILESTATE_SELECTED;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-09 19:12:16 -07:00
|
|
|
void Tile::select() {
|
|
|
|
|
if (size() == 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (ground) {
|
|
|
|
|
ground->select();
|
|
|
|
|
}
|
|
|
|
|
if (spawnMonster) {
|
|
|
|
|
spawnMonster->select();
|
|
|
|
|
}
|
|
|
|
|
if (spawnNpc) {
|
|
|
|
|
spawnNpc->select();
|
|
|
|
|
}
|
|
|
|
|
if (monster) {
|
|
|
|
|
monster->select();
|
|
|
|
|
}
|
|
|
|
|
if (npc) {
|
|
|
|
|
npc->select();
|
|
|
|
|
}
|
2012-06-29 16:44:26 +02:00
|
|
|
|
2023-10-09 19:12:16 -07:00
|
|
|
for (Item* item : items) {
|
2023-10-09 23:02:37 -03:00
|
|
|
item->select();
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
2016-09-29 19:24:45 -03:00
|
|
|
|
2012-06-29 16:44:26 +02:00
|
|
|
statflags |= TILESTATE_SELECTED;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-09 19:12:16 -07:00
|
|
|
void Tile::deselect() {
|
|
|
|
|
if (ground) {
|
|
|
|
|
ground->deselect();
|
|
|
|
|
}
|
|
|
|
|
if (spawnMonster) {
|
|
|
|
|
spawnMonster->deselect();
|
|
|
|
|
}
|
|
|
|
|
if (spawnNpc) {
|
|
|
|
|
spawnNpc->deselect();
|
|
|
|
|
}
|
|
|
|
|
if (monster) {
|
|
|
|
|
monster->deselect();
|
|
|
|
|
}
|
|
|
|
|
if (npc) {
|
|
|
|
|
npc->deselect();
|
|
|
|
|
}
|
2012-06-29 16:44:26 +02:00
|
|
|
|
2023-10-09 19:12:16 -07:00
|
|
|
for (Item* item : items) {
|
2023-10-09 23:02:37 -03:00
|
|
|
item->deselect();
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
statflags &= ~TILESTATE_SELECTED;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-09 19:12:16 -07:00
|
|
|
Item* Tile::getTopSelectedItem() {
|
|
|
|
|
for (auto it = items.rbegin(); it != items.rend(); ++it) {
|
|
|
|
|
if ((*it)->isSelected() && !(*it)->isMetaItem()) {
|
2023-10-09 23:02:37 -03:00
|
|
|
return *it;
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
|
|
|
|
}
|
2023-10-09 19:12:16 -07:00
|
|
|
if (ground && ground->isSelected() && !ground->isMetaItem()) {
|
2012-06-29 16:44:26 +02:00
|
|
|
return ground;
|
|
|
|
|
}
|
2014-01-22 20:16:17 +01:00
|
|
|
return nullptr;
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
|
|
|
|
|
2023-10-09 19:12:16 -07:00
|
|
|
ItemVector Tile::popSelectedItems(bool ignoreTileSelected) {
|
2012-06-29 16:44:26 +02:00
|
|
|
ItemVector pop_items;
|
|
|
|
|
|
2023-10-09 19:12:16 -07:00
|
|
|
if (!ignoreTileSelected && !isSelected()) {
|
|
|
|
|
return pop_items;
|
|
|
|
|
}
|
2012-06-29 16:44:26 +02:00
|
|
|
|
2023-10-09 19:12:16 -07:00
|
|
|
if (ground && ground->isSelected()) {
|
2012-06-29 16:44:26 +02:00
|
|
|
pop_items.push_back(ground);
|
2014-01-22 20:16:17 +01:00
|
|
|
ground = nullptr;
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
|
|
|
|
|
2023-10-09 19:12:16 -07:00
|
|
|
for (auto it = items.begin(); it != items.end();) {
|
2023-10-09 23:02:37 -03:00
|
|
|
Item* item = (*it);
|
2023-10-09 19:12:16 -07:00
|
|
|
if (item->isSelected()) {
|
2023-10-09 23:02:37 -03:00
|
|
|
pop_items.push_back(item);
|
2012-06-29 16:44:26 +02:00
|
|
|
it = items.erase(it);
|
|
|
|
|
} else {
|
|
|
|
|
++it;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
statflags &= ~TILESTATE_SELECTED;
|
|
|
|
|
return pop_items;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-09 19:12:16 -07:00
|
|
|
ItemVector Tile::getSelectedItems() {
|
2012-06-29 16:44:26 +02:00
|
|
|
ItemVector selected_items;
|
2016-09-29 19:24:45 -03:00
|
|
|
|
2023-10-09 19:12:16 -07:00
|
|
|
if (!isSelected()) {
|
|
|
|
|
return selected_items;
|
|
|
|
|
}
|
2012-06-29 16:44:26 +02:00
|
|
|
|
2023-10-09 19:12:16 -07:00
|
|
|
if (ground && ground->isSelected()) {
|
2012-06-29 16:44:26 +02:00
|
|
|
selected_items.push_back(ground);
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-09 19:12:16 -07:00
|
|
|
for (Item* item : items) {
|
|
|
|
|
if (item->isSelected()) {
|
2023-10-09 23:02:37 -03:00
|
|
|
selected_items.push_back(item);
|
|
|
|
|
}
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
2016-09-29 19:24:45 -03:00
|
|
|
|
2012-06-29 16:44:26 +02:00
|
|
|
return selected_items;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-09 19:12:16 -07:00
|
|
|
uint8_t Tile::getMiniMapColor() const {
|
|
|
|
|
if (minimapColor != INVALID_MINIMAP_COLOR) {
|
2018-04-22 10:54:06 -03:00
|
|
|
return minimapColor;
|
2023-10-09 19:12:16 -07:00
|
|
|
}
|
2018-04-22 10:54:06 -03:00
|
|
|
|
2023-10-09 19:12:16 -07:00
|
|
|
for (auto it = items.rbegin(); it != items.rend(); ++it) {
|
2023-10-09 23:02:37 -03:00
|
|
|
uint8_t color = (*it)->getMiniMapColor();
|
2023-10-09 19:12:16 -07:00
|
|
|
if (color != 0) {
|
2023-10-09 23:02:37 -03:00
|
|
|
return color;
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
|
|
|
|
}
|
2018-04-22 10:54:06 -03:00
|
|
|
|
2012-06-29 16:44:26 +02:00
|
|
|
// check ground too
|
2023-10-09 19:12:16 -07:00
|
|
|
if (hasGround()) {
|
2012-06-29 16:44:26 +02:00
|
|
|
return ground->getMiniMapColor();
|
|
|
|
|
}
|
2018-04-22 10:54:06 -03:00
|
|
|
|
2012-06-29 16:44:26 +02:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-09 19:12:16 -07:00
|
|
|
void Tile::update() {
|
2012-06-29 16:44:26 +02:00
|
|
|
statflags &= TILESTATE_MODIFIED;
|
2016-09-29 19:24:45 -03:00
|
|
|
|
2023-10-09 19:12:16 -07:00
|
|
|
if (spawnMonster && spawnMonster->isSelected()) {
|
2021-05-25 00:29:12 -03:00
|
|
|
statflags |= TILESTATE_SELECTED;
|
|
|
|
|
}
|
2023-10-09 19:12:16 -07:00
|
|
|
if (spawnNpc && spawnNpc->isSelected()) {
|
2021-05-25 00:29:12 -03:00
|
|
|
statflags |= TILESTATE_SELECTED;
|
|
|
|
|
}
|
2023-10-09 19:12:16 -07:00
|
|
|
if (monster && monster->isSelected()) {
|
2012-06-29 16:44:26 +02:00
|
|
|
statflags |= TILESTATE_SELECTED;
|
|
|
|
|
}
|
2023-10-09 19:12:16 -07:00
|
|
|
if (npc && npc->isSelected()) {
|
2012-06-29 16:44:26 +02:00
|
|
|
statflags |= TILESTATE_SELECTED;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-09 19:12:16 -07:00
|
|
|
if (ground) {
|
|
|
|
|
if (ground->isSelected()) {
|
2012-06-29 16:44:26 +02:00
|
|
|
statflags |= TILESTATE_SELECTED;
|
|
|
|
|
}
|
2023-10-09 19:12:16 -07:00
|
|
|
if (ground->isBlocking()) {
|
2012-06-29 16:44:26 +02:00
|
|
|
statflags |= TILESTATE_BLOCKING;
|
|
|
|
|
}
|
2023-10-09 19:12:16 -07:00
|
|
|
if (ground->getUniqueID() != 0) {
|
2012-06-29 16:44:26 +02:00
|
|
|
statflags |= TILESTATE_UNIQUE;
|
|
|
|
|
}
|
2023-10-09 19:12:16 -07:00
|
|
|
if (ground->getMiniMapColor() != 0) {
|
2018-04-22 10:54:06 -03:00
|
|
|
minimapColor = ground->getMiniMapColor();
|
|
|
|
|
}
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
|
|
|
|
|
2023-10-09 19:12:16 -07:00
|
|
|
for (const Item* item : items) {
|
|
|
|
|
if (item->isSelected()) {
|
2012-06-29 16:44:26 +02:00
|
|
|
statflags |= TILESTATE_SELECTED;
|
|
|
|
|
}
|
2023-10-09 19:12:16 -07:00
|
|
|
if (item->getUniqueID() != 0) {
|
2012-06-29 16:44:26 +02:00
|
|
|
statflags |= TILESTATE_UNIQUE;
|
|
|
|
|
}
|
2023-10-09 19:12:16 -07:00
|
|
|
if (item->getMiniMapColor() != 0) {
|
2023-10-09 23:02:37 -03:00
|
|
|
minimapColor = item->getMiniMapColor();
|
2018-04-22 10:54:06 -03:00
|
|
|
}
|
2012-06-29 16:44:26 +02:00
|
|
|
|
2023-10-09 19:12:16 -07:00
|
|
|
const ItemType &type = g_items.getItemType(item->getID());
|
2023-10-09 23:02:37 -03:00
|
|
|
|
2023-10-09 19:12:16 -07:00
|
|
|
if (type.unpassable) {
|
2012-06-29 16:44:26 +02:00
|
|
|
statflags |= TILESTATE_BLOCKING;
|
|
|
|
|
}
|
2023-10-09 19:12:16 -07:00
|
|
|
if (type.isOptionalBorder) {
|
2012-06-29 16:44:26 +02:00
|
|
|
statflags |= TILESTATE_OP_BORDER;
|
|
|
|
|
}
|
2023-10-09 19:12:16 -07:00
|
|
|
if (type.isTable) {
|
2012-06-29 16:44:26 +02:00
|
|
|
statflags |= TILESTATE_HAS_TABLE;
|
|
|
|
|
}
|
2023-10-09 19:12:16 -07:00
|
|
|
if (type.isCarpet) {
|
2012-06-29 16:44:26 +02:00
|
|
|
statflags |= TILESTATE_HAS_CARPET;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-09 19:12:16 -07:00
|
|
|
if ((statflags & TILESTATE_BLOCKING) == 0) {
|
|
|
|
|
if (!ground && items.empty()) {
|
2012-06-29 16:44:26 +02:00
|
|
|
statflags |= TILESTATE_BLOCKING;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-09 19:12:16 -07:00
|
|
|
void Tile::borderize(BaseMap* parent) {
|
2012-06-29 16:44:26 +02:00
|
|
|
GroundBrush::doBorders(parent, this);
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-09 19:12:16 -07:00
|
|
|
void Tile::addBorderItem(Item* item) {
|
|
|
|
|
if (!item) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2012-06-29 16:44:26 +02:00
|
|
|
ASSERT(item->isBorder());
|
|
|
|
|
items.insert(items.begin(), item);
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-09 19:12:16 -07:00
|
|
|
GroundBrush* Tile::getGroundBrush() const {
|
|
|
|
|
if (ground && ground->getGroundBrush()) {
|
2023-10-09 23:02:37 -03:00
|
|
|
return ground->getGroundBrush();
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
2014-01-22 20:16:17 +01:00
|
|
|
return nullptr;
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
|
|
|
|
|
2023-10-09 19:12:16 -07:00
|
|
|
void Tile::cleanBorders() {
|
|
|
|
|
if (items.empty()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2012-06-29 16:44:26 +02:00
|
|
|
|
2023-10-09 19:12:16 -07:00
|
|
|
for (auto it = items.begin(); it != items.end();) {
|
2023-10-09 23:02:37 -03:00
|
|
|
Item* item = (*it);
|
|
|
|
|
// Borders should only be on the bottom, we can ignore the rest of the items
|
2023-10-09 19:12:16 -07:00
|
|
|
if (!item->isBorder()) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
2023-10-09 23:02:37 -03:00
|
|
|
|
|
|
|
|
delete item;
|
|
|
|
|
it = items.erase(it);
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-09 19:12:16 -07:00
|
|
|
void Tile::wallize(BaseMap* parent) {
|
2012-06-29 16:44:26 +02:00
|
|
|
WallBrush::doWalls(parent, this);
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-09 19:12:16 -07:00
|
|
|
Item* Tile::getWall() const {
|
|
|
|
|
for (Item* item : items) {
|
|
|
|
|
if (item->isWall()) {
|
2023-10-09 23:02:37 -03:00
|
|
|
return item;
|
|
|
|
|
}
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
2014-01-22 20:16:17 +01:00
|
|
|
return nullptr;
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
|
|
|
|
|
2023-10-09 19:12:16 -07:00
|
|
|
Item* Tile::getCarpet() const {
|
|
|
|
|
for (Item* item : items) {
|
|
|
|
|
if (item->isCarpet()) {
|
2023-10-09 23:02:37 -03:00
|
|
|
return item;
|
|
|
|
|
}
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
2014-01-22 20:16:17 +01:00
|
|
|
return nullptr;
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
|
|
|
|
|
2023-10-09 19:12:16 -07:00
|
|
|
Item* Tile::getTable() const {
|
|
|
|
|
for (Item* item : items) {
|
|
|
|
|
if (item->isTable()) {
|
2023-10-09 23:02:37 -03:00
|
|
|
return item;
|
|
|
|
|
}
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
2014-01-22 20:16:17 +01:00
|
|
|
return nullptr;
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
|
|
|
|
|
2023-10-09 19:12:16 -07:00
|
|
|
void Tile::addWallItem(Item* item) {
|
|
|
|
|
if (!item) {
|
2012-06-29 16:44:26 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
ASSERT(item->isWall());
|
|
|
|
|
|
|
|
|
|
addItem(item);
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-09 19:12:16 -07:00
|
|
|
void Tile::cleanWalls(bool dontdelete) {
|
|
|
|
|
if (items.empty()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2012-06-29 16:44:26 +02:00
|
|
|
|
2023-10-09 19:12:16 -07:00
|
|
|
for (auto it = items.begin(); it != items.end();) {
|
2023-10-09 23:02:37 -03:00
|
|
|
Item* item = (*it);
|
2023-10-09 19:12:16 -07:00
|
|
|
if (item && item->isWall()) {
|
|
|
|
|
if (!dontdelete) {
|
2023-10-09 23:02:37 -03:00
|
|
|
delete item;
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
|
|
|
|
it = items.erase(it);
|
2023-10-09 23:02:37 -03:00
|
|
|
} else {
|
2023-10-09 19:12:16 -07:00
|
|
|
++it;
|
2023-10-09 23:02:37 -03:00
|
|
|
}
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-09 19:12:16 -07:00
|
|
|
void Tile::cleanWalls(WallBrush* brush) {
|
2012-06-29 16:44:26 +02:00
|
|
|
ItemVector::iterator it;
|
|
|
|
|
|
2023-10-09 19:12:16 -07:00
|
|
|
for (auto it = items.begin(); it != items.end();) {
|
2023-10-09 23:02:37 -03:00
|
|
|
Item* item = (*it);
|
2023-10-09 19:12:16 -07:00
|
|
|
if (item && item->isWall() && brush->hasWall(item)) {
|
2023-10-09 23:02:37 -03:00
|
|
|
delete item;
|
2012-06-29 16:44:26 +02:00
|
|
|
it = items.erase(it);
|
2023-10-09 23:02:37 -03:00
|
|
|
} else {
|
|
|
|
|
++it;
|
|
|
|
|
}
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-09 19:12:16 -07:00
|
|
|
void Tile::cleanTables(bool dontdelete) {
|
|
|
|
|
if (items.empty()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2012-06-29 16:44:26 +02:00
|
|
|
|
2023-10-09 19:12:16 -07:00
|
|
|
for (auto it = items.begin(); it != items.end();) {
|
2023-10-09 23:02:37 -03:00
|
|
|
Item* item = (*it);
|
2023-10-09 19:12:16 -07:00
|
|
|
if (item && item->isTable()) {
|
|
|
|
|
if (!dontdelete) {
|
2023-10-09 23:02:37 -03:00
|
|
|
delete item;
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
|
|
|
|
it = items.erase(it);
|
2023-10-09 23:02:37 -03:00
|
|
|
} else {
|
|
|
|
|
++it;
|
|
|
|
|
}
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-09 19:12:16 -07:00
|
|
|
void Tile::tableize(BaseMap* parent) {
|
2012-06-29 16:44:26 +02:00
|
|
|
TableBrush::doTables(parent, this);
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-09 19:12:16 -07:00
|
|
|
void Tile::carpetize(BaseMap* parent) {
|
2012-06-29 16:44:26 +02:00
|
|
|
CarpetBrush::doCarpets(parent, this);
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-09 19:12:16 -07:00
|
|
|
void Tile::selectGround() {
|
2023-10-09 23:02:37 -03:00
|
|
|
bool selected = false;
|
2023-10-09 19:12:16 -07:00
|
|
|
if (ground) {
|
2012-06-29 16:44:26 +02:00
|
|
|
ground->select();
|
2023-10-09 23:02:37 -03:00
|
|
|
selected = true;
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
|
|
|
|
ItemVector::iterator it;
|
|
|
|
|
|
2023-10-09 19:12:16 -07:00
|
|
|
for (Item* item : items) {
|
|
|
|
|
if (!item->isBorder()) {
|
2012-06-29 16:44:26 +02:00
|
|
|
break;
|
2023-10-09 19:12:16 -07:00
|
|
|
}
|
2023-10-09 23:02:37 -03:00
|
|
|
item->select();
|
|
|
|
|
selected = true;
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
2023-10-09 23:02:37 -03:00
|
|
|
|
2023-10-09 19:12:16 -07:00
|
|
|
if (selected) {
|
|
|
|
|
statflags |= TILESTATE_SELECTED;
|
|
|
|
|
}
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
|
|
|
|
|
2023-10-09 19:12:16 -07:00
|
|
|
void Tile::deselectGround() {
|
|
|
|
|
if (ground) {
|
2012-06-29 16:44:26 +02:00
|
|
|
ground->deselect();
|
|
|
|
|
}
|
2023-10-09 19:12:16 -07:00
|
|
|
for (Item* item : items) {
|
|
|
|
|
if (!item->isBorder()) {
|
2012-06-29 16:44:26 +02:00
|
|
|
break;
|
2023-10-09 19:12:16 -07:00
|
|
|
}
|
2023-10-09 23:02:37 -03:00
|
|
|
|
|
|
|
|
item->deselect();
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-09 19:12:16 -07:00
|
|
|
void Tile::setHouse(House* house) {
|
2023-10-09 23:02:37 -03:00
|
|
|
house_id = (house ? house->id : 0);
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
|
|
|
|
|
2023-10-09 19:12:16 -07:00
|
|
|
void Tile::addHouseExit(House* house) {
|
|
|
|
|
if (!house) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-10-09 23:02:37 -03:00
|
|
|
|
|
|
|
|
HouseExitList* exits = location->createHouseExits();
|
|
|
|
|
exits->push_back(house->id);
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
|
|
|
|
|
2023-10-09 19:12:16 -07:00
|
|
|
void Tile::removeHouseExit(House* house) {
|
|
|
|
|
if (!house) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-12-06 11:42:37 -03:00
|
|
|
|
2023-10-09 23:02:37 -03:00
|
|
|
HouseExitList* exits = location->getHouseExits();
|
2023-10-09 19:12:16 -07:00
|
|
|
if (!exits || exits->empty()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2012-06-29 16:44:26 +02:00
|
|
|
|
2023-10-09 23:02:37 -03:00
|
|
|
auto it = std::find(exits->begin(), exits->end(), house->id);
|
2023-10-09 19:12:16 -07:00
|
|
|
if (it != exits->end()) {
|
2023-10-09 23:02:37 -03:00
|
|
|
exits->erase(it);
|
2023-10-09 19:12:16 -07:00
|
|
|
}
|
2012-06-29 16:44:26 +02:00
|
|
|
}
|
|
|
|
|
|
2023-10-09 19:12:16 -07:00
|
|
|
bool Tile::hasHouseExit(uint32_t houseId) const {
|
2023-10-09 23:02:37 -03:00
|
|
|
const HouseExitList* exits = getHouseExits();
|
2023-10-09 19:12:16 -07:00
|
|
|
if (!exits || exits->empty()) {
|
2023-10-09 23:02:37 -03:00
|
|
|
return false;
|
2023-10-09 19:12:16 -07:00
|
|
|
}
|
2023-10-09 23:02:37 -03:00
|
|
|
|
|
|
|
|
auto it = std::find(exits->begin(), exits->end(), houseId);
|
|
|
|
|
return it != exits->end();
|
|
|
|
|
}
|