void Level::updateVisibility(Vec2 changedSquare) { for (Vec2 pos : getVisibleTilesNoDarkness(changedSquare, VisionInfo::NORMAL)) addLightSource(pos, squares[pos]->getLightEmission(), -1); for (auto& elem : fieldOfView) elem.squareChanged(changedSquare); for (Vec2 pos : getVisibleTilesNoDarkness(changedSquare, VisionInfo::NORMAL)) addLightSource(pos, squares[pos]->getLightEmission(), 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::addLightSource(Vec2 pos, double radius, int numLight) { if (radius > 0) { for (Vec2 v : getVisibleTilesNoDarkness(pos, VisionId::NORMAL)) { double dist = (v - pos).lengthD(); if (dist <= radius) lightAmount[v] += min(1.0, 1 - (dist) / radius) * numLight; } } }
void Level::addLightSource(Vec2 pos, double radius, int numLight) { if (radius > 0) { for (Vec2 v : getVisibleTilesNoDarkness(pos, VisionInfo::NORMAL)) { double dist = (v - pos).lengthD(); if (dist <= radius) squares[v]->addLight(min(1.0, 1 - (dist) / radius) * numLight); } } }
void Level::addDarknessSource(Vec2 pos, double radius, int numDarkness) { if (radius > 0) { for (Vec2 v : getVisibleTilesNoDarkness(pos, VisionId::NORMAL)) { double dist = (v - pos).lengthD(); if (dist <= radius) lightCapAmount[v] -= min(1.0, 1 - (dist) / radius) * numDarkness; squares[v]->updateSunlightMovement(isInSunlight(v)); updateConnectivity(v); } } }