void Actors::updateDrowning(const MWWorld::Ptr& ptr, float duration) { MWBase::World *world = MWBase::Environment::get().getWorld(); NpcStats &stats = ptr.getClass().getNpcStats(ptr); if(world->isSubmerged(ptr) && stats.getMagicEffects().get(ESM::MagicEffect::WaterBreathing).mMagnitude == 0) { float timeLeft = 0.0f; if(stats.getFatigue().getCurrent() == 0) stats.setTimeToStartDrowning(0); else { timeLeft = stats.getTimeToStartDrowning() - duration; if(timeLeft < 0.0f) timeLeft = 0.0f; stats.setTimeToStartDrowning(timeLeft); } if(timeLeft == 0.0f) { // If drowning, apply 3 points of damage per second ptr.getClass().setActorHealth(ptr, stats.getHealth().getCurrent() - 3.0f*duration); // Play a drowning sound as necessary for the player if(ptr == world->getPlayer().getPlayer()) { MWBase::SoundManager *sndmgr = MWBase::Environment::get().getSoundManager(); if(!sndmgr->getSoundPlaying(MWWorld::Ptr(), "drown")) sndmgr->playSound("drown", 1.0f, 1.0f); } } } else stats.setTimeToStartDrowning(20); }