Fixed drowning widget initialization

This commit is contained in:
Andrei Kortunov 2017-04-16 22:15:25 +04:00
parent f63b1e81cd
commit c3fd327bb2
3 changed files with 16 additions and 6 deletions

View file

@ -803,6 +803,12 @@ namespace MWMechanics
CharacterController* ctrl = it->second->getCharacterController(); CharacterController* ctrl = it->second->getCharacterController();
NpcStats &stats = ptr.getClass().getNpcStats(ptr); NpcStats &stats = ptr.getClass().getNpcStats(ptr);
// When npc stats are just initialized, mTimeToStartDrowning == -1 and we should get value from GMST
static const int fHoldBreathTime = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find("fHoldBreathTime")->getFloat();
if (stats.getTimeToStartDrowning() == -1.f)
stats.setTimeToStartDrowning(fHoldBreathTime);
MWBase::World *world = MWBase::Environment::get().getWorld(); MWBase::World *world = MWBase::Environment::get().getWorld();
bool knockedOutUnderwater = (ctrl->isKnockedOut() && world->isUnderwater(ptr.getCell(), osg::Vec3f(ptr.getRefData().getPosition().asVec3()))); bool knockedOutUnderwater = (ctrl->isKnockedOut() && world->isUnderwater(ptr.getCell(), osg::Vec3f(ptr.getRefData().getPosition().asVec3())));
if((world->isSubmerged(ptr) || knockedOutUnderwater) if((world->isSubmerged(ptr) || knockedOutUnderwater)

View file

@ -328,12 +328,16 @@ namespace MWMechanics
winMgr->setValue(fbar, stats.getFatigue()); winMgr->setValue(fbar, stats.getFatigue());
} }
if(stats.getTimeToStartDrowning() != mWatchedTimeToStartDrowning) static const float fHoldBreathTime = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>()
{
const float fHoldBreathTime = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>()
.find("fHoldBreathTime")->getFloat(); .find("fHoldBreathTime")->getFloat();
mWatchedTimeToStartDrowning = stats.getTimeToStartDrowning();
if(stats.getTimeToStartDrowning() >= fHoldBreathTime) float timeToDrown = stats.getTimeToStartDrowning();
if(timeToDrown != mWatchedTimeToStartDrowning)
{
mWatchedTimeToStartDrowning = timeToDrown;
if(timeToDrown >= fHoldBreathTime || timeToDrown == -1.0) // -1.0 is a special value during initialization
winMgr->setDrowningBarVisibility(false); winMgr->setDrowningBarVisibility(false);
else else
{ {

View file

@ -30,7 +30,7 @@ MWMechanics::NpcStats::NpcStats()
, mBounty(0) , mBounty(0)
, mWerewolfKills (0) , mWerewolfKills (0)
, mLevelProgress(0) , mLevelProgress(0)
, mTimeToStartDrowning(20.0) , mTimeToStartDrowning(-1.0) // set breath to special value, it will be replaced during actor update
, mIsWerewolf(false) , mIsWerewolf(false)
{ {
mSkillIncreases.resize (ESM::Attribute::Length, 0); mSkillIncreases.resize (ESM::Attribute::Length, 0);