mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-16 17:59:56 +00:00
Merge remote-tracking branch 'lgro/issue845_NPCs_hold_torches_whole_day'
Conflicts: apps/openmw/mwmechanics/character.cpp
This commit is contained in:
commit
6de39a7329
9 changed files with 71 additions and 15 deletions
|
@ -427,6 +427,8 @@ namespace MWBase
|
||||||
const MWWorld::Ptr& actor, const std::string& sourceName) = 0;
|
const MWWorld::Ptr& actor, const std::string& sourceName) = 0;
|
||||||
|
|
||||||
virtual void breakInvisibility (const MWWorld::Ptr& actor) = 0;
|
virtual void breakInvisibility (const MWWorld::Ptr& actor) = 0;
|
||||||
|
|
||||||
|
virtual bool isNight() const = 0;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -440,15 +440,48 @@ namespace MWMechanics
|
||||||
|
|
||||||
void Actors::updateEquippedLight (const MWWorld::Ptr& ptr, float duration)
|
void Actors::updateEquippedLight (const MWWorld::Ptr& ptr, float duration)
|
||||||
{
|
{
|
||||||
//If holding a light...
|
bool isPlayer = ptr.getRefData().getHandle()=="player";
|
||||||
|
|
||||||
MWWorld::InventoryStore &inventoryStore = MWWorld::Class::get(ptr).getInventoryStore(ptr);
|
MWWorld::InventoryStore &inventoryStore = MWWorld::Class::get(ptr).getInventoryStore(ptr);
|
||||||
MWWorld::ContainerStoreIterator heldIter =
|
MWWorld::ContainerStoreIterator heldIter =
|
||||||
inventoryStore.getSlot(MWWorld::InventoryStore::Slot_CarriedLeft);
|
inventoryStore.getSlot(MWWorld::InventoryStore::Slot_CarriedLeft);
|
||||||
|
/**
|
||||||
|
* Automatically equip NPCs torches at night and unequip them at day
|
||||||
|
*/
|
||||||
|
if (!isPlayer && !MWWorld::Class::get (ptr).getCreatureStats (ptr).isHostile())
|
||||||
|
{
|
||||||
|
if (mTorchPtr.isEmpty())
|
||||||
|
{
|
||||||
|
mTorchPtr = inventoryStore.search("torch_infinite_time");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (MWBase::Environment::get().getWorld()->isNight())
|
||||||
|
{
|
||||||
|
if (heldIter != inventoryStore.end() && heldIter->getTypeName() != typeid(ESM::Light).name())
|
||||||
|
{
|
||||||
|
inventoryStore.unequipItem(*heldIter, ptr);
|
||||||
|
}
|
||||||
|
else if (heldIter == inventoryStore.end() && !mTorchPtr.isEmpty())
|
||||||
|
{
|
||||||
|
heldIter = inventoryStore.add(mTorchPtr, ptr);
|
||||||
|
inventoryStore.equip(MWWorld::InventoryStore::Slot_CarriedLeft, heldIter, ptr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (heldIter != inventoryStore.end() && heldIter->getTypeName() == typeid(ESM::Light).name())
|
||||||
|
{
|
||||||
|
inventoryStore.unequipItem(*heldIter, ptr);
|
||||||
|
inventoryStore.add(*heldIter, ptr);
|
||||||
|
inventoryStore.autoEquip(ptr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//If holding a light...
|
||||||
if(heldIter.getType() == MWWorld::ContainerStore::Type_Light)
|
if(heldIter.getType() == MWWorld::ContainerStore::Type_Light)
|
||||||
{
|
{
|
||||||
// Use time from the player's light
|
// Use time from the player's light
|
||||||
bool isPlayer = ptr.getRefData().getHandle()=="player";
|
|
||||||
if(isPlayer)
|
if(isPlayer)
|
||||||
{
|
{
|
||||||
float timeRemaining = heldIter->getClass().getRemainingUsageTime(*heldIter);
|
float timeRemaining = heldIter->getClass().getRemainingUsageTime(*heldIter);
|
||||||
|
|
|
@ -25,14 +25,13 @@ namespace MWMechanics
|
||||||
{
|
{
|
||||||
class Actors
|
class Actors
|
||||||
{
|
{
|
||||||
typedef std::map<MWWorld::Ptr,CharacterController*> PtrControllerMap;
|
typedef std::map<MWWorld::Ptr,CharacterController*> PtrControllerMap;
|
||||||
PtrControllerMap mActors;
|
PtrControllerMap mActors;
|
||||||
|
|
||||||
std::map<std::string, int> mDeathCount;
|
|
||||||
|
|
||||||
void updateNpc(const MWWorld::Ptr &ptr, float duration, bool paused);
|
|
||||||
|
|
||||||
|
std::map<std::string, int> mDeathCount;
|
||||||
|
MWWorld::Ptr mTorchPtr;
|
||||||
|
|
||||||
|
void updateNpc(const MWWorld::Ptr &ptr, float duration, bool paused);
|
||||||
|
|
||||||
void adjustMagicEffects (const MWWorld::Ptr& creature);
|
void adjustMagicEffects (const MWWorld::Ptr& creature);
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,8 @@
|
||||||
#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
|
||||||
{
|
{
|
||||||
|
@ -717,18 +719,18 @@ bool CharacterController::updateNpcState(bool onground, bool inwater, bool isrun
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
MWWorld::ContainerStoreIterator torch = inv.getSlot(MWWorld::InventoryStore::Slot_CarriedLeft);
|
MWWorld::ContainerStoreIterator torch = inv.getSlot(MWWorld::InventoryStore::Slot_CarriedLeft);
|
||||||
if(torch != inv.end() && torch->getTypeName() == typeid(ESM::Light).name()
|
if(torch != inv.end() && torch->getTypeName() == typeid(ESM::Light).name()
|
||||||
&& mWeaponType != WeapType_Spell && mWeaponType != WeapType_HandToHand)
|
&& mWeaponType != WeapType_Spell && mWeaponType != WeapType_HandToHand)
|
||||||
|
|
||||||
{
|
{
|
||||||
if(!mAnimation->isPlaying("torch"))
|
mAnimation->play("torch", Priority_Torch, MWRender::Animation::Group_LeftArm,
|
||||||
mAnimation->play("torch", Priority_Torch,
|
false, 1.0f, "start", "stop", 0.0f, (~(size_t)0));
|
||||||
MWRender::Animation::Group_LeftArm, false,
|
}
|
||||||
1.0f, "start", "stop", 0.0f, (~(size_t)0));
|
else if (mAnimation->isPlaying("torch"))
|
||||||
|
{
|
||||||
|
mAnimation->disable("torch");
|
||||||
}
|
}
|
||||||
else if(mAnimation->isPlaying("torch"))
|
|
||||||
mAnimation->disable("torch");
|
|
||||||
|
|
||||||
return forcestateupdate;
|
return forcestateupdate;
|
||||||
}
|
}
|
||||||
|
|
|
@ -175,6 +175,13 @@ void MWWorld::InventoryStore::autoEquip (const MWWorld::Ptr& actor)
|
||||||
for (ContainerStoreIterator iter (begin()); iter!=end(); ++iter)
|
for (ContainerStoreIterator iter (begin()); iter!=end(); ++iter)
|
||||||
{
|
{
|
||||||
Ptr test = *iter;
|
Ptr test = *iter;
|
||||||
|
|
||||||
|
// Don't autoEquip lights
|
||||||
|
if (test.getTypeName() == typeid(ESM::Light).name())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
int testSkill = MWWorld::Class::get (test).getEquipmentSkill (test);
|
int testSkill = MWWorld::Class::get (test).getEquipmentSkill (test);
|
||||||
|
|
||||||
std::pair<std::vector<int>, bool> itemsSlots =
|
std::pair<std::vector<int>, bool> itemsSlots =
|
||||||
|
|
|
@ -707,3 +707,8 @@ float WeatherManager::getWindSpeed() const
|
||||||
{
|
{
|
||||||
return mWindSpeed;
|
return mWindSpeed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool WeatherManager::isNight() const
|
||||||
|
{
|
||||||
|
return (mHour < mSunriseTime || mHour > mNightStart - 1);
|
||||||
|
}
|
||||||
|
|
|
@ -152,6 +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;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
float mHour;
|
float mHour;
|
||||||
int mDay, mMonth;
|
int mDay, mMonth;
|
||||||
|
|
|
@ -2285,4 +2285,9 @@ namespace MWWorld
|
||||||
actor.getClass().getCreatureStats(actor).getActiveSpells().purgeEffect(ESM::MagicEffect::Invisibility);
|
actor.getClass().getCreatureStats(actor).getActiveSpells().purgeEffect(ESM::MagicEffect::Invisibility);
|
||||||
actor.getClass().getInventoryStore(actor).purgeEffect(ESM::MagicEffect::Invisibility);
|
actor.getClass().getInventoryStore(actor).purgeEffect(ESM::MagicEffect::Invisibility);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool World::isNight() const
|
||||||
|
{
|
||||||
|
return mWeatherManager->isNight();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -516,6 +516,7 @@ 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;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue