Lights extinguish underwater

pull/37/head
Alex "rainChu" Haddad 11 years ago
parent 30ee3c5cf6
commit 2643214ca6

@ -201,10 +201,8 @@ namespace MWClass
{ {
ensureCustomData(ptr); ensureCustomData(ptr);
float &timeCharge = dynamic_cast<CustomData&> (*ptr.getRefData().getCustomData()).mTime; float &timeRemaining = dynamic_cast<CustomData&> (*ptr.getRefData().getCustomData()).mTime;
timeRemaining = duration;
// TODO time it in vanilla, see if 1 second is really one unit.
timeCharge = duration;
} }
float Light::getRemainingUsageTime (const MWWorld::Ptr& ptr) const float Light::getRemainingUsageTime (const MWWorld::Ptr& ptr) const

@ -44,10 +44,7 @@ namespace MWMechanics
if(!paused) if(!paused)
{ {
updateDrowning(ptr, duration); updateDrowning(ptr, duration);
updateEquippedLight(ptr, duration);
// Only update the light of the player.
if(ptr.getRefData().getHandle()=="player")
updateEquippedLight(ptr, duration);
} }
} }
@ -211,19 +208,36 @@ namespace MWMechanics
if(heldIter.getType() == MWWorld::ContainerStore::Type_Light) if(heldIter.getType() == MWWorld::ContainerStore::Type_Light)
{ {
// ... then use some "fuel" from the timer // Use time from the player's light
float timeRemaining = heldIter->getClass().getRemainingUsageTime(*heldIter); bool isPlayer = ptr.getRefData().getHandle()=="player";
if(isPlayer)
{
float timeRemaining = heldIter->getClass().getRemainingUsageTime(*heldIter);
// -1 is infinite light source. Other negative values are treated as 0.
if(timeRemaining != -1.0f)
{
timeRemaining -= duration;
if(timeRemaining > 0.0f)
heldIter->getClass().setRemainingUsageTime(*heldIter, timeRemaining);
else
{
heldIter->getRefData().setCount(0); // remove it
return;
}
}
}
// If it's already -1, then it should be an infinite light. // Both NPC and player lights extinguish in water.
// TODO see what happens for other negative values. if(MWBase::Environment::get().getWorld()->isSwimming(ptr))
if(timeRemaining >= 0.0f)
{ {
timeRemaining -= duration; heldIter->getRefData().setCount(0); // remove it
if(timeRemaining > 0.0f) // ...But, only the player makes a sound.
heldIter->getClass().setRemainingUsageTime(*heldIter, timeRemaining); if(isPlayer)
else MWBase::Environment::get().getSoundManager()->playSound("torch out",
heldIter->getRefData().setCount(0); // remove it 1.0, 1.0, MWBase::SoundManager::Play_TypeSfx, MWBase::SoundManager::Play_NoEnv);
} }
} }
} }

Loading…
Cancel
Save