mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-25 06:35:30 +00:00
Many additions to 900bc06d2c236b:
- 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
@ -428,7 +428,8 @@ namespace MWBase
|
||||
|
||||
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
|
||||
*/
|
||||
if (!isPlayer && !MWWorld::Class::get (ptr).getCreatureStats (ptr).isHostile())
|
||||
if (!isPlayer)
|
||||
{
|
||||
if (mTorchPtr.isEmpty())
|
||||
{
|
||||
mTorchPtr = inventoryStore.search("torch_infinite_time");
|
||||
}
|
||||
MWWorld::ContainerStoreIterator torch = inventoryStore.end();
|
||||
for (MWWorld::ContainerStoreIterator it = inventoryStore.begin(); it != inventoryStore.end(); ++it)
|
||||
{
|
||||
if (it->getTypeName() == typeid(ESM::Light).name())
|
||||
{
|
||||
torch = it;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (MWBase::Environment::get().getWorld()->isNight())
|
||||
{
|
||||
if (heldIter != inventoryStore.end() && heldIter->getTypeName() != typeid(ESM::Light).name())
|
||||
if (MWBase::Environment::get().getWorld()->isDark())
|
||||
{
|
||||
inventoryStore.unequipItem(*heldIter, ptr);
|
||||
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())
|
||||
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);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
inventoryStore.equip(MWWorld::InventoryStore::Slot_CarriedLeft, torch, ptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (heldIter == inventoryStore.end() && !mTorchPtr.isEmpty())
|
||||
else
|
||||
{
|
||||
heldIter = inventoryStore.add(mTorchPtr, ptr);
|
||||
inventoryStore.equip(MWWorld::InventoryStore::Slot_CarriedLeft, heldIter, ptr);
|
||||
if (heldIter != inventoryStore.end() && heldIter->getTypeName() == typeid(ESM::Light).name())
|
||||
{
|
||||
// At day, unequip lights and auto equip shields or other suitable items
|
||||
// (Note: autoEquip will ignore lights)
|
||||
inventoryStore.autoEquip(ptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (heldIter != inventoryStore.end() && heldIter->getTypeName() == typeid(ESM::Light).name())
|
||||
{
|
||||
inventoryStore.unequipItem(*heldIter, ptr);
|
||||
inventoryStore.add(*heldIter, ptr);
|
||||
inventoryStore.autoEquip(ptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
heldIter = inventoryStore.getSlot(MWWorld::InventoryStore::Slot_CarriedLeft);
|
||||
|
||||
//If holding a light...
|
||||
if(heldIter.getType() == MWWorld::ContainerStore::Type_Light)
|
||||
{
|
||||
|
@ -29,7 +29,6 @@ namespace MWMechanics
|
||||
PtrControllerMap mActors;
|
||||
|
||||
std::map<std::string, int> mDeathCount;
|
||||
MWWorld::Ptr mTorchPtr;
|
||||
|
||||
void updateNpc(const MWWorld::Ptr &ptr, float duration, bool paused);
|
||||
|
||||
|
@ -36,8 +36,6 @@
|
||||
#include "../mwworld/player.hpp"
|
||||
#include "../mwworld/class.hpp"
|
||||
#include "../mwworld/inventorystore.hpp"
|
||||
#include "../mwworld/actionequip.hpp"
|
||||
#include "../mwworld/actiontake.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
@ -724,12 +722,12 @@ bool CharacterController::updateNpcState(bool onground, bool inwater, bool isrun
|
||||
&& mWeaponType != WeapType_Spell && mWeaponType != WeapType_HandToHand)
|
||||
|
||||
{
|
||||
mAnimation->play("torch", Priority_Torch, MWRender::Animation::Group_LeftArm,
|
||||
false, 1.0f, "start", "stop", 0.0f, (~(size_t)0));
|
||||
mAnimation->play("torch", Priority_Torch, MWRender::Animation::Group_LeftArm,
|
||||
false, 1.0f, "start", "stop", 0.0f, (~(size_t)0));
|
||||
}
|
||||
else if (mAnimation->isPlaying("torch"))
|
||||
{
|
||||
mAnimation->disable("torch");
|
||||
mAnimation->disable("torch");
|
||||
}
|
||||
|
||||
return forcestateupdate;
|
||||
|
@ -179,7 +179,7 @@ void MWWorld::InventoryStore::autoEquip (const MWWorld::Ptr& actor)
|
||||
// Don't autoEquip lights
|
||||
if (test.getTypeName() == typeid(ESM::Light).name())
|
||||
{
|
||||
continue;
|
||||
continue;
|
||||
}
|
||||
|
||||
int testSkill = MWWorld::Class::get (test).getEquipmentSkill (test);
|
||||
|
@ -708,7 +708,9 @@ float WeatherManager::getWindSpeed() const
|
||||
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);
|
||||
|
||||
bool isNight() const;
|
||||
/// @see World::isDark
|
||||
bool isDark() const;
|
||||
|
||||
private:
|
||||
float mHour;
|
||||
|
@ -2286,8 +2286,8 @@ namespace MWWorld
|
||||
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);
|
||||
|
||||
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…
x
Reference in New Issue
Block a user