void Level::placeCreature(Creature* creature, Vec2 pos) { creature->setPosition(Position(pos, this)); bucketMap->addElement(pos, creature); getSafeSquare(pos)->putCreature(creature); if (creature->isDarknessSource()) addDarknessSource(pos, darknessRadius, 1); }
void Level::updateVisibility(Vec2 changedSquare) { for (Vec2 pos : getVisibleTilesNoDarkness(changedSquare, VisionId::NORMAL)) { addLightSource(pos, squares[pos]->getLightEmission(), -1); if (Creature* c = squares[pos]->getCreature()) if (c->isDarknessSource()) addDarknessSource(pos, darknessRadius, -1); } for (VisionId vision : ENUM_ALL(VisionId)) fieldOfView[vision].squareChanged(changedSquare); for (Vec2 pos : getVisibleTilesNoDarkness(changedSquare, VisionId::NORMAL)) { addLightSource(pos, squares[pos]->getLightEmission(), 1); if (Creature* c = squares[pos]->getCreature()) if (c->isDarknessSource()) addDarknessSource(pos, darknessRadius, 1); } }
void Level::putCreature(Vec2 position, Creature* c) { CHECK(inBounds(position)); creatures.push_back(c); CHECK(getSafeSquare(position)->getCreature() == nullptr); bucketMap->addElement(position, c); c->setLevel(this); c->setPosition(position); getSafeSquare(position)->putCreature(c); if (c->isDarknessSource()) addDarknessSource(c->getPosition(), darknessRadius); }
void Level::putCreature(Vec2 position, Creature* c) { CHECK(inBounds(position)); insertCreature(c); CHECK(getSafeSquare(position)->getCreature() == nullptr); bucketMap->addElement(position, c); c->setPosition(Position(position, this)); getSafeSquare(position)->putCreature(c); if (c->isDarknessSource()) addDarknessSource(position, darknessRadius); if (c->isPlayer()) player = c; }
void Level::swapCreatures(Creature* c1, Creature* c2) { Vec2 position1 = c1->getPosition(); Vec2 position2 = c2->getPosition(); bucketMap->moveElement(position1, position2, c1); bucketMap->moveElement(position2, position1, c2); Square* square1 = getSafeSquare(position1); Square* square2 = getSafeSquare(position2); square1->removeCreature(); square2->removeCreature(); c1->setPosition(position2); c2->setPosition(position1); square1->putCreature(c2); square2->putCreature(c1); if (c1->isAffected(LastingEffect::DARKNESS_SOURCE)) { addDarknessSource(position2, darknessRadius); removeDarknessSource(position1, darknessRadius); } if (c2->isAffected(LastingEffect::DARKNESS_SOURCE)) { addDarknessSource(position1, darknessRadius); removeDarknessSource(position2, darknessRadius); } }
void Level::moveCreature(Creature* creature, Vec2 direction) { CHECK(canMoveCreature(creature, direction)); Vec2 position = creature->getPosition(); bucketMap->moveElement(position, position + direction, creature); Square* nextSquare = getSafeSquare(position + direction); Square* thisSquare = getSafeSquare(position); thisSquare->removeCreature(); creature->setPosition(position + direction); nextSquare->putCreature(creature); if (creature->isAffected(LastingEffect::DARKNESS_SOURCE)) { addDarknessSource(position + direction, darknessRadius); removeDarknessSource(position, darknessRadius); } }
void Level::removeDarknessSource(Vec2 pos, double radius) { addDarknessSource(pos, radius, -1); }
void Level::addDarknessSource(Vec2 pos, double radius) { addDarknessSource(pos, radius, 1); }
void Level::unplaceCreature(Creature* creature, Vec2 pos) { bucketMap->removeElement(pos, creature); getSafeSquare(pos)->removeCreature(); if (creature->isDarknessSource()) addDarknessSource(pos, darknessRadius, -1); }