void Level::replaceSquare(Vec2 pos, PSquare square) { if (contains(tickingSquares, getSquare(pos))) removeElement(tickingSquares, getSquare(pos)); Creature* c = squares[pos]->getCreature(); for (Item* it : squares[pos]->getItems()) square->dropItem(squares[pos]->removeItem(it)); squares[pos]->onConstructNewSquare(square.get()); addLightSource(pos, squares[pos]->getLightEmission(), -1); square->setCovered(squares[pos]->isCovered()); square->addLight(squares[pos]->getTotalLight()); square->setBackground(squares[pos].get()); squares[pos] = std::move(square); squares[pos]->setPosition(pos); squares[pos]->setLevel(this); if (c) { squares[pos]->putCreatureSilently(c); } addLightSource(pos, squares[pos]->getLightEmission(), 1); updateVisibility(pos); }