Merge remote-tracking branch 'lgro/issue845_NPCs_hold_torches_whole_day'

Conflicts:
	apps/openmw/mwmechanics/character.cpp
actorid
Marc Zinnschlag 11 years ago
commit 6de39a7329

@ -427,6 +427,8 @@ namespace MWBase
const MWWorld::Ptr& actor, const std::string& sourceName) = 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)
{
//If holding a light...
bool isPlayer = ptr.getRefData().getHandle()=="player";
MWWorld::InventoryStore &inventoryStore = MWWorld::Class::get(ptr).getInventoryStore(ptr);
MWWorld::ContainerStoreIterator heldIter =
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)
{
// Use time from the player's light
bool isPlayer = ptr.getRefData().getHandle()=="player";
if(isPlayer)
{
float timeRemaining = heldIter->getClass().getRemainingUsageTime(*heldIter);

@ -25,14 +25,13 @@ namespace MWMechanics
{
class Actors
{
typedef std::map<MWWorld::Ptr,CharacterController*> PtrControllerMap;
PtrControllerMap mActors;
std::map<std::string, int> mDeathCount;
void updateNpc(const MWWorld::Ptr &ptr, float duration, bool paused);
typedef std::map<MWWorld::Ptr,CharacterController*> PtrControllerMap;
PtrControllerMap mActors;
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);

@ -36,6 +36,8 @@
#include "../mwworld/player.hpp"
#include "../mwworld/class.hpp"
#include "../mwworld/inventorystore.hpp"
#include "../mwworld/actionequip.hpp"
#include "../mwworld/actiontake.hpp"
namespace
{
@ -717,18 +719,18 @@ bool CharacterController::updateNpcState(bool onground, bool inwater, bool isrun
}
}
MWWorld::ContainerStoreIterator torch = inv.getSlot(MWWorld::InventoryStore::Slot_CarriedLeft);
if(torch != inv.end() && torch->getTypeName() == typeid(ESM::Light).name()
&& 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));
}
else if (mAnimation->isPlaying("torch"))
{
if(!mAnimation->isPlaying("torch"))
mAnimation->play("torch", Priority_Torch,
MWRender::Animation::Group_LeftArm, false,
1.0f, "start", "stop", 0.0f, (~(size_t)0));
mAnimation->disable("torch");
}
else if(mAnimation->isPlaying("torch"))
mAnimation->disable("torch");
return forcestateupdate;
}

@ -175,6 +175,13 @@ void MWWorld::InventoryStore::autoEquip (const MWWorld::Ptr& actor)
for (ContainerStoreIterator iter (begin()); iter!=end(); ++iter)
{
Ptr test = *iter;
// Don't autoEquip lights
if (test.getTypeName() == typeid(ESM::Light).name())
{
continue;
}
int testSkill = MWWorld::Class::get (test).getEquipmentSkill (test);
std::pair<std::vector<int>, bool> itemsSlots =

@ -707,3 +707,8 @@ float WeatherManager::getWindSpeed() const
{
return mWindSpeed;
}
bool WeatherManager::isNight() const
{
return (mHour < mSunriseTime || mHour > mNightStart - 1);
}

@ -152,6 +152,8 @@ namespace MWWorld
void modRegion(const std::string &regionid, const std::vector<char> &chances);
bool isNight() const;
private:
float mHour;
int mDay, mMonth;

@ -2285,4 +2285,9 @@ namespace MWWorld
actor.getClass().getCreatureStats(actor).getActiveSpells().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);
virtual void breakInvisibility (const MWWorld::Ptr& actor);
virtual bool isNight() const;
};
}

Loading…
Cancel
Save