AI: hide torches during bad weather (bug #4334)

0.6.3
Andrei Kortunov 7 years ago
parent bd6c7de579
commit a0a30cdbf5

@ -495,8 +495,8 @@ namespace MWBase
virtual void breakInvisibility (const MWWorld::Ptr& actor) = 0; virtual void breakInvisibility (const MWWorld::Ptr& actor) = 0;
// Are we in an exterior or pseudo-exterior cell and it's night? // Allow NPCs to use torches?
virtual bool isDark() const = 0; virtual bool useTorches() const = 0;
virtual bool findInteriorPositionInWorldSpace(const MWWorld::CellStore* cell, osg::Vec3f& result) = 0; virtual bool findInteriorPositionInWorldSpace(const MWWorld::CellStore* cell, osg::Vec3f& result) = 0;

@ -900,7 +900,7 @@ namespace MWMechanics
stats.setTimeToStartDrowning(fHoldBreathTime); stats.setTimeToStartDrowning(fHoldBreathTime);
} }
void Actors::updateEquippedLight (const MWWorld::Ptr& ptr, float duration) void Actors::updateEquippedLight (const MWWorld::Ptr& ptr, float duration, bool mayEquip)
{ {
bool isPlayer = (ptr == getPlayer()); bool isPlayer = (ptr == getPlayer());
@ -922,7 +922,7 @@ namespace MWMechanics
} }
} }
if (MWBase::Environment::get().getWorld()->isDark()) if (mayEquip)
{ {
if (torch != inventoryStore.end()) if (torch != inventoryStore.end())
{ {
@ -1199,6 +1199,9 @@ namespace MWMechanics
if (mTimerDisposeSummonsCorpses >= 0.2f) mTimerDisposeSummonsCorpses = 0; if (mTimerDisposeSummonsCorpses >= 0.2f) mTimerDisposeSummonsCorpses = 0;
if (timerUpdateEquippedLight >= updateEquippedLightInterval) timerUpdateEquippedLight = 0; if (timerUpdateEquippedLight >= updateEquippedLightInterval) timerUpdateEquippedLight = 0;
// show torches only when there are darkness and no precipitations
bool showTorches = MWBase::Environment::get().getWorld()->useTorches();
MWWorld::Ptr player = getPlayer(); MWWorld::Ptr player = getPlayer();
/// \todo move update logic to Actor class where appropriate /// \todo move update logic to Actor class where appropriate
@ -1297,7 +1300,7 @@ namespace MWMechanics
updateNpc(iter->first, duration); updateNpc(iter->first, duration);
if (timerUpdateEquippedLight == 0) if (timerUpdateEquippedLight == 0)
updateEquippedLight(iter->first, updateEquippedLightInterval); updateEquippedLight(iter->first, updateEquippedLightInterval, showTorches);
} }
} }
} }

@ -39,7 +39,7 @@ namespace MWMechanics
void updateDrowning (const MWWorld::Ptr& ptr, float duration); void updateDrowning (const MWWorld::Ptr& ptr, float duration);
void updateEquippedLight (const MWWorld::Ptr& ptr, float duration); void updateEquippedLight (const MWWorld::Ptr& ptr, float duration, bool mayEquip);
void updateCrimePersuit (const MWWorld::Ptr& ptr, float duration); void updateCrimePersuit (const MWWorld::Ptr& ptr, float duration);

@ -520,6 +520,7 @@ WeatherManager::WeatherManager(MWRender::RenderingManager& rendering, const Fall
, mSecunda("Secunda", fallback) , mSecunda("Secunda", fallback)
, mWindSpeed(0.f) , mWindSpeed(0.f)
, mIsStorm(false) , mIsStorm(false)
, mPrecipitation(false)
, mStormDirection(0,1,0) , mStormDirection(0,1,0)
, mCurrentRegion() , mCurrentRegion()
, mTimePassed(0) , mTimePassed(0)
@ -660,6 +661,10 @@ void WeatherManager::update(float duration, bool paused)
mWindSpeed = mResult.mWindSpeed; mWindSpeed = mResult.mWindSpeed;
mIsStorm = mResult.mIsStorm; mIsStorm = mResult.mIsStorm;
// For some reason Ash Storm is not considered as a precipitation weather in game
mPrecipitation = !(mResult.mParticleEffect.empty() && mResult.mRainEffect.empty())
&& mResult.mParticleEffect != "meshes\\ashcloud.nif";
if (mIsStorm) if (mIsStorm)
{ {
osg::Vec3f playerPos (player.getRefData().getPosition().asVec3()); osg::Vec3f playerPos (player.getRefData().getPosition().asVec3());
@ -777,12 +782,12 @@ unsigned int WeatherManager::getWeatherID() const
return mCurrentWeather; return mCurrentWeather;
} }
bool WeatherManager::isDark() const bool WeatherManager::useTorches() const
{ {
TimeStamp time = MWBase::Environment::get().getWorld()->getTimeStamp(); TimeStamp time = MWBase::Environment::get().getWorld()->getTimeStamp();
bool exterior = (MWBase::Environment::get().getWorld()->isCellExterior() bool isDark = time.getHour() < mSunriseTime || time.getHour() > mTimeSettings.mNightStart - 1;
|| MWBase::Environment::get().getWorld()->isCellQuasiExterior());
return exterior && (time.getHour() < mSunriseTime || time.getHour() > mTimeSettings.mNightStart - 1); return isDark && !mPrecipitation;
} }
void WeatherManager::write(ESM::ESMWriter& writer, Loading::Listener& progress) void WeatherManager::write(ESM::ESMWriter& writer, Loading::Listener& progress)

@ -240,8 +240,7 @@ namespace MWWorld
unsigned int getWeatherID() const; unsigned int getWeatherID() const;
/// @see World::isDark bool useTorches() const;
bool isDark() const;
void write(ESM::ESMWriter& writer, Loading::Listener& progress); void write(ESM::ESMWriter& writer, Loading::Listener& progress);
@ -275,6 +274,7 @@ namespace MWWorld
float mWindSpeed; float mWindSpeed;
bool mIsStorm; bool mIsStorm;
bool mPrecipitation;
osg::Vec3f mStormDirection; osg::Vec3f mStormDirection;
std::string mCurrentRegion; std::string mCurrentRegion;

@ -2847,11 +2847,13 @@ namespace MWWorld
MWBase::Environment::get().getMechanicsManager()->updateMagicEffects(actor); MWBase::Environment::get().getMechanicsManager()->updateMagicEffects(actor);
} }
bool World::isDark() const bool World::useTorches() const
{ {
// If we are in exterior, check the weather manager.
// In interiors there are no precipitations and sun, so check the ambient
MWWorld::CellStore* cell = mPlayer->getPlayer().getCell(); MWWorld::CellStore* cell = mPlayer->getPlayer().getCell();
if (cell->isExterior()) if (cell->isExterior())
return mWeatherManager->isDark(); return mWeatherManager->useTorches();
else else
{ {
uint32_t ambient = cell->getCell()->mAmbi.mAmbient; uint32_t ambient = cell->getCell()->mAmbi.mAmbient;

@ -604,12 +604,11 @@ namespace MWWorld
void launchProjectile (MWWorld::Ptr actor, MWWorld::ConstPtr projectile, void launchProjectile (MWWorld::Ptr actor, MWWorld::ConstPtr projectile,
const osg::Vec3f& worldPos, const osg::Quat& orient, MWWorld::Ptr bow, float speed, float attackStrength) override; const osg::Vec3f& worldPos, const osg::Quat& orient, MWWorld::Ptr bow, float speed, float attackStrength) override;
const std::vector<std::string>& getContentFiles() const override; const std::vector<std::string>& getContentFiles() const override;
void breakInvisibility (const MWWorld::Ptr& actor) override; void breakInvisibility (const MWWorld::Ptr& actor) override;
// Are we in an exterior or pseudo-exterior cell and it's night?
bool isDark() const override; // Allow NPCs to use torches?
bool useTorches() const override;
bool findInteriorPositionInWorldSpace(const MWWorld::CellStore* cell, osg::Vec3f& result) override; bool findInteriorPositionInWorldSpace(const MWWorld::CellStore* cell, osg::Vec3f& result) override;

Loading…
Cancel
Save