mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-30 22:15:32 +00:00
Many additions to 900bc06d2c
:
- Fix indentation - Consider any kind of light, not just torch_infinite_time - Hostile NPCs should also wear lights, if they have nothing else that could use the slot (or a twohanded weapon) - Remove redundant code and don't add additional lights to the inventory - World::isDark returns false for interiors which are unaffected by weather
This commit is contained in:
parent
f3a7321a43
commit
79a440e94a
9 changed files with 59 additions and 36 deletions
|
@ -428,7 +428,8 @@ namespace MWBase
|
||||||
|
|
||||||
virtual void breakInvisibility (const MWWorld::Ptr& actor) = 0;
|
virtual void breakInvisibility (const MWWorld::Ptr& actor) = 0;
|
||||||
|
|
||||||
virtual bool isNight() const = 0;
|
// Are we in an exterior or pseudo-exterior cell and it's night?
|
||||||
|
virtual bool isDark() const = 0;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -448,36 +448,57 @@ namespace MWMechanics
|
||||||
/**
|
/**
|
||||||
* Automatically equip NPCs torches at night and unequip them at day
|
* Automatically equip NPCs torches at night and unequip them at day
|
||||||
*/
|
*/
|
||||||
if (!isPlayer && !MWWorld::Class::get (ptr).getCreatureStats (ptr).isHostile())
|
if (!isPlayer)
|
||||||
{
|
{
|
||||||
if (mTorchPtr.isEmpty())
|
MWWorld::ContainerStoreIterator torch = inventoryStore.end();
|
||||||
|
for (MWWorld::ContainerStoreIterator it = inventoryStore.begin(); it != inventoryStore.end(); ++it)
|
||||||
{
|
{
|
||||||
mTorchPtr = inventoryStore.search("torch_infinite_time");
|
if (it->getTypeName() == typeid(ESM::Light).name())
|
||||||
|
{
|
||||||
|
torch = it;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (MWBase::Environment::get().getWorld()->isNight())
|
if (MWBase::Environment::get().getWorld()->isDark())
|
||||||
{
|
{
|
||||||
|
if (torch != inventoryStore.end())
|
||||||
|
{
|
||||||
|
if (!MWWorld::Class::get (ptr).getCreatureStats (ptr).isHostile())
|
||||||
|
{
|
||||||
|
// For non-hostile NPCs, unequip whatever is in the left slot in favor of a light.
|
||||||
if (heldIter != inventoryStore.end() && heldIter->getTypeName() != typeid(ESM::Light).name())
|
if (heldIter != inventoryStore.end() && heldIter->getTypeName() != typeid(ESM::Light).name())
|
||||||
{
|
|
||||||
inventoryStore.unequipItem(*heldIter, ptr);
|
inventoryStore.unequipItem(*heldIter, ptr);
|
||||||
|
|
||||||
|
// Also unequip twohanded weapons which conflict with anything in CarriedLeft
|
||||||
|
if (torch->getClass().canBeEquipped(*torch, ptr).first == 3)
|
||||||
|
inventoryStore.unequipSlot(MWWorld::InventoryStore::Slot_CarriedRight, ptr);
|
||||||
}
|
}
|
||||||
else if (heldIter == inventoryStore.end() && !mTorchPtr.isEmpty())
|
|
||||||
|
heldIter = inventoryStore.getSlot(MWWorld::InventoryStore::Slot_CarriedLeft);
|
||||||
|
|
||||||
|
// If we have a torch and can equip it (left slot free, no
|
||||||
|
// twohanded weapon in right slot), then equip it now.
|
||||||
|
if (heldIter == inventoryStore.end()
|
||||||
|
&& torch->getClass().canBeEquipped(*torch, ptr).first == 1)
|
||||||
{
|
{
|
||||||
heldIter = inventoryStore.add(mTorchPtr, ptr);
|
inventoryStore.equip(MWWorld::InventoryStore::Slot_CarriedLeft, torch, ptr);
|
||||||
inventoryStore.equip(MWWorld::InventoryStore::Slot_CarriedLeft, heldIter, ptr);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (heldIter != inventoryStore.end() && heldIter->getTypeName() == typeid(ESM::Light).name())
|
if (heldIter != inventoryStore.end() && heldIter->getTypeName() == typeid(ESM::Light).name())
|
||||||
{
|
{
|
||||||
inventoryStore.unequipItem(*heldIter, ptr);
|
// At day, unequip lights and auto equip shields or other suitable items
|
||||||
inventoryStore.add(*heldIter, ptr);
|
// (Note: autoEquip will ignore lights)
|
||||||
inventoryStore.autoEquip(ptr);
|
inventoryStore.autoEquip(ptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
heldIter = inventoryStore.getSlot(MWWorld::InventoryStore::Slot_CarriedLeft);
|
||||||
|
|
||||||
//If holding a light...
|
//If holding a light...
|
||||||
if(heldIter.getType() == MWWorld::ContainerStore::Type_Light)
|
if(heldIter.getType() == MWWorld::ContainerStore::Type_Light)
|
||||||
{
|
{
|
||||||
|
|
|
@ -29,7 +29,6 @@ namespace MWMechanics
|
||||||
PtrControllerMap mActors;
|
PtrControllerMap mActors;
|
||||||
|
|
||||||
std::map<std::string, int> mDeathCount;
|
std::map<std::string, int> mDeathCount;
|
||||||
MWWorld::Ptr mTorchPtr;
|
|
||||||
|
|
||||||
void updateNpc(const MWWorld::Ptr &ptr, float duration, bool paused);
|
void updateNpc(const MWWorld::Ptr &ptr, float duration, bool paused);
|
||||||
|
|
||||||
|
|
|
@ -36,8 +36,6 @@
|
||||||
#include "../mwworld/player.hpp"
|
#include "../mwworld/player.hpp"
|
||||||
#include "../mwworld/class.hpp"
|
#include "../mwworld/class.hpp"
|
||||||
#include "../mwworld/inventorystore.hpp"
|
#include "../mwworld/inventorystore.hpp"
|
||||||
#include "../mwworld/actionequip.hpp"
|
|
||||||
#include "../mwworld/actiontake.hpp"
|
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
|
|
@ -708,7 +708,9 @@ float WeatherManager::getWindSpeed() const
|
||||||
return mWindSpeed;
|
return mWindSpeed;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WeatherManager::isNight() const
|
bool WeatherManager::isDark() const
|
||||||
{
|
{
|
||||||
return (mHour < mSunriseTime || mHour > mNightStart - 1);
|
bool exterior = (MWBase::Environment::get().getWorld()->isCellExterior()
|
||||||
|
|| MWBase::Environment::get().getWorld()->isCellQuasiExterior());
|
||||||
|
return exterior && (mHour < mSunriseTime || mHour > mNightStart - 1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -152,7 +152,8 @@ namespace MWWorld
|
||||||
|
|
||||||
void modRegion(const std::string ®ionid, const std::vector<char> &chances);
|
void modRegion(const std::string ®ionid, const std::vector<char> &chances);
|
||||||
|
|
||||||
bool isNight() const;
|
/// @see World::isDark
|
||||||
|
bool isDark() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
float mHour;
|
float mHour;
|
||||||
|
|
|
@ -2286,8 +2286,8 @@ namespace MWWorld
|
||||||
actor.getClass().getInventoryStore(actor).purgeEffect(ESM::MagicEffect::Invisibility);
|
actor.getClass().getInventoryStore(actor).purgeEffect(ESM::MagicEffect::Invisibility);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool World::isNight() const
|
bool World::isDark() const
|
||||||
{
|
{
|
||||||
return mWeatherManager->isNight();
|
return mWeatherManager->isDark();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -516,7 +516,8 @@ namespace MWWorld
|
||||||
const MWWorld::Ptr& actor, const std::string& sourceName);
|
const MWWorld::Ptr& actor, const std::string& sourceName);
|
||||||
|
|
||||||
virtual void breakInvisibility (const MWWorld::Ptr& actor);
|
virtual void breakInvisibility (const MWWorld::Ptr& actor);
|
||||||
virtual bool isNight() const;
|
// Are we in an exterior or pseudo-exterior cell and it's night?
|
||||||
|
virtual bool isDark() const;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue