diff --git a/src/items/tile.hpp b/src/items/tile.hpp index ba3834d9914..a719f5dcef3 100644 --- a/src/items/tile.hpp +++ b/src/items/tile.hpp @@ -288,6 +288,8 @@ class DynamicTile : public Tile { CreatureVector creatures; public: + explicit DynamicTile(const Position &position) : + Tile(position.x, position.y, position.z) { } DynamicTile(uint16_t x, uint16_t y, uint8_t z) : Tile(x, y, z) { } @@ -323,6 +325,8 @@ class StaticTile final : public Tile { std::unique_ptr creatures; public: + explicit StaticTile(const Position &position) : + Tile(position.x, position.y, position.z) { } StaticTile(uint16_t x, uint16_t y, uint8_t z) : Tile(x, y, z) { } diff --git a/src/map/house/housetile.cpp b/src/map/house/housetile.cpp index ce9229ce42c..71d6ee241ed 100644 --- a/src/map/house/housetile.cpp +++ b/src/map/house/housetile.cpp @@ -17,6 +17,9 @@ #include "map/house/house.hpp" #include "utils/tools.hpp" +HouseTile::HouseTile(const Position &position, std::shared_ptr newHouse) : + DynamicTile(position.x, position.y, position.z), house(std::move(newHouse)) { } + HouseTile::HouseTile(int32_t initX, int32_t initY, int32_t initZ, std::shared_ptr initHouse) : DynamicTile(initX, initY, initZ), house(std::move(initHouse)) { } diff --git a/src/map/house/housetile.hpp b/src/map/house/housetile.hpp index 6a191d0f84d..293fc0074ee 100644 --- a/src/map/house/housetile.hpp +++ b/src/map/house/housetile.hpp @@ -17,6 +17,7 @@ class HouseTile final : public DynamicTile { public: using Tile::addThing; + HouseTile(const Position &position, std::shared_ptr house); HouseTile(int32_t x, int32_t y, int32_t z, std::shared_ptr house); // cylinder implementations diff --git a/src/map/mapcache.cpp b/src/map/mapcache.cpp index 79a9683cfca..f505c544fe2 100644 --- a/src/map/mapcache.cpp +++ b/src/map/mapcache.cpp @@ -120,18 +120,23 @@ std::shared_ptr MapCache::getOrCreateTileFromCache(const std::shared_ptr tile = nullptr; + auto pos = Position(x, y, z); + if (cachedTile->isHouse()) { - const auto &house = map->houses.getHouse(cachedTile->houseId); - tile = std::make_shared(x, y, z, house); - house->addTile(std::static_pointer_cast(tile)); + if (const auto &house = map->houses.getHouse(cachedTile->houseId)) { + tile = std::make_shared(pos, house); + tile->safeCall([tile] { + tile->getHouse()->addTile(tile->static_self_cast()); + }); + } else { + g_logger().error("[{}] house not found for houseId {}", std::source_location::current().function_name(), cachedTile->houseId); + } } else if (cachedTile->isStatic) { - tile = std::make_shared(x, y, z); + tile = std::make_shared(pos); } else { - tile = std::make_shared(x, y, z); + tile = std::make_shared(pos); } - auto pos = Position(x, y, z); - if (cachedTile->ground != nullptr) { tile->internalAddThing(createItem(cachedTile->ground, pos)); }