|
|
@ -50,27 +50,36 @@ bool isConscious(const MWWorld::Ptr& ptr)
|
|
|
|
return !stats.isDead() && !stats.getKnockedDown();
|
|
|
|
return !stats.isDead() && !stats.getKnockedDown();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void adjustBoundItem (const std::string& item, bool bound, const MWWorld::Ptr& actor)
|
|
|
|
int getBoundItemSlot (const std::string& itemId)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (bound)
|
|
|
|
static std::map<std::string, int> boundItemsMap;
|
|
|
|
|
|
|
|
if (boundItemsMap.empty())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (actor.getClass().getContainerStore(actor).count(item) == 0)
|
|
|
|
std::string boundId = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find("sMagicBoundBootsID")->getString();
|
|
|
|
{
|
|
|
|
boundItemsMap[boundId] = MWWorld::InventoryStore::Slot_Boots;
|
|
|
|
MWWorld::InventoryStore& store = actor.getClass().getInventoryStore(actor);
|
|
|
|
|
|
|
|
MWWorld::Ptr newPtr = *store.MWWorld::ContainerStore::add(item, 1, actor);
|
|
|
|
boundId = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find("sMagicBoundCuirassID")->getString();
|
|
|
|
MWWorld::ActionEquip action(newPtr);
|
|
|
|
boundItemsMap[boundId] = MWWorld::InventoryStore::Slot_Cuirass;
|
|
|
|
action.execute(actor);
|
|
|
|
|
|
|
|
MWWorld::ConstContainerStoreIterator rightHand = store.getSlot(MWWorld::InventoryStore::Slot_CarriedRight);
|
|
|
|
boundId = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find("sMagicBoundLeftGauntletID")->getString();
|
|
|
|
// change draw state only if the item is in player's right hand
|
|
|
|
boundItemsMap[boundId] = MWWorld::InventoryStore::Slot_LeftGauntlet;
|
|
|
|
if (actor == MWMechanics::getPlayer()
|
|
|
|
|
|
|
|
&& rightHand != store.end() && newPtr == *rightHand)
|
|
|
|
boundId = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find("sMagicBoundRightGauntletID")->getString();
|
|
|
|
{
|
|
|
|
boundItemsMap[boundId] = MWWorld::InventoryStore::Slot_RightGauntlet;
|
|
|
|
MWBase::Environment::get().getWorld()->getPlayer().setDrawState(MWMechanics::DrawState_Weapon);
|
|
|
|
|
|
|
|
}
|
|
|
|
boundId = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find("sMagicBoundHelmID")->getString();
|
|
|
|
}
|
|
|
|
boundItemsMap[boundId] = MWWorld::InventoryStore::Slot_Helmet;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
boundId = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find("sMagicBoundShieldID")->getString();
|
|
|
|
|
|
|
|
boundItemsMap[boundId] = MWWorld::InventoryStore::Slot_CarriedLeft;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
|
|
|
|
actor.getClass().getInventoryStore(actor).remove(item, 1, actor, true);
|
|
|
|
int slot = MWWorld::InventoryStore::Slot_CarriedRight;
|
|
|
|
|
|
|
|
std::map<std::string, int>::iterator it = boundItemsMap.find(itemId);
|
|
|
|
|
|
|
|
if (it != boundItemsMap.end())
|
|
|
|
|
|
|
|
slot = it->second;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return slot;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class CheckActorCommanded : public MWMechanics::EffectSourceVisitor
|
|
|
|
class CheckActorCommanded : public MWMechanics::EffectSourceVisitor
|
|
|
@ -139,7 +148,6 @@ void getRestorationPerHourOfSleep (const MWWorld::Ptr& ptr, float& health, float
|
|
|
|
|
|
|
|
|
|
|
|
namespace MWMechanics
|
|
|
|
namespace MWMechanics
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
const float aiProcessingDistance = 7168;
|
|
|
|
const float aiProcessingDistance = 7168;
|
|
|
|
const float sqrAiProcessingDistance = aiProcessingDistance*aiProcessingDistance;
|
|
|
|
const float sqrAiProcessingDistance = aiProcessingDistance*aiProcessingDistance;
|
|
|
|
|
|
|
|
|
|
|
@ -227,6 +235,83 @@ namespace MWMechanics
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Actors::addBoundItem (const std::string& itemId, const MWWorld::Ptr& actor)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
MWWorld::InventoryStore& store = actor.getClass().getInventoryStore(actor);
|
|
|
|
|
|
|
|
int slot = getBoundItemSlot(itemId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (actor.getClass().getContainerStore(actor).count(itemId) != 0)
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MWWorld::ContainerStoreIterator prevItem = store.getSlot(slot);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MWWorld::Ptr boundPtr = *store.MWWorld::ContainerStore::add(itemId, 1, actor);
|
|
|
|
|
|
|
|
MWWorld::ActionEquip action(boundPtr);
|
|
|
|
|
|
|
|
action.execute(actor);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (actor != MWMechanics::getPlayer())
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MWWorld::Ptr newItem = *store.getSlot(slot);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (newItem.isEmpty() || boundPtr != newItem)
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MWWorld::Player& player = MWBase::Environment::get().getWorld()->getPlayer();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// change draw state only if the item is in player's right hand
|
|
|
|
|
|
|
|
if (slot == MWWorld::InventoryStore::Slot_CarriedRight)
|
|
|
|
|
|
|
|
player.setDrawState(MWMechanics::DrawState_Weapon);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (prevItem != store.end())
|
|
|
|
|
|
|
|
player.setPreviousItem(itemId, prevItem->getCellRef().getRefId());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Actors::removeBoundItem (const std::string& itemId, const MWWorld::Ptr& actor)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
MWWorld::InventoryStore& store = actor.getClass().getInventoryStore(actor);
|
|
|
|
|
|
|
|
int slot = getBoundItemSlot(itemId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MWWorld::ContainerStoreIterator currentItem = store.getSlot(slot);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool wasEquipped = currentItem != store.end() && Misc::StringUtils::ciEqual(currentItem->getCellRef().getRefId(), itemId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
store.remove(itemId, 1, actor, true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (actor != MWMechanics::getPlayer())
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MWWorld::Player& player = MWBase::Environment::get().getWorld()->getPlayer();
|
|
|
|
|
|
|
|
std::string prevItemId = player.getPreviousItem(itemId);
|
|
|
|
|
|
|
|
player.erasePreviousItem(itemId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (prevItemId.empty())
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Find the item by id
|
|
|
|
|
|
|
|
MWWorld::Ptr item;
|
|
|
|
|
|
|
|
for (MWWorld::ContainerStoreIterator iter = store.begin(); iter != store.end(); ++iter)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (Misc::StringUtils::ciEqual(iter->getCellRef().getRefId(), prevItemId))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (item.isEmpty() ||
|
|
|
|
|
|
|
|
// Prefer the stack with the lowest remaining uses
|
|
|
|
|
|
|
|
!item.getClass().hasItemHealth(*iter) ||
|
|
|
|
|
|
|
|
iter->getClass().getItemHealth(*iter) < item.getClass().getItemHealth(item))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
item = *iter;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// we should equip previous item only if expired bound item was equipped.
|
|
|
|
|
|
|
|
if (item.isEmpty() || !wasEquipped)
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MWWorld::ActionEquip action(item);
|
|
|
|
|
|
|
|
action.execute(actor);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Actors::updateActor (const MWWorld::Ptr& ptr, float duration)
|
|
|
|
void Actors::updateActor (const MWWorld::Ptr& ptr, float duration)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// magic effects
|
|
|
|
// magic effects
|
|
|
@ -756,25 +841,23 @@ namespace MWMechanics
|
|
|
|
float magnitude = effects.get(it->first).getMagnitude();
|
|
|
|
float magnitude = effects.get(it->first).getMagnitude();
|
|
|
|
if (found != (magnitude > 0))
|
|
|
|
if (found != (magnitude > 0))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
if (magnitude > 0)
|
|
|
|
|
|
|
|
creatureStats.mBoundItems.insert(it->first);
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
creatureStats.mBoundItems.erase(it->first);
|
|
|
|
|
|
|
|
|
|
|
|
std::string itemGmst = it->second;
|
|
|
|
std::string itemGmst = it->second;
|
|
|
|
std::string item = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find(
|
|
|
|
std::string item = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find(
|
|
|
|
itemGmst)->getString();
|
|
|
|
itemGmst)->getString();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
magnitude > 0 ? addBoundItem(item, ptr) : removeBoundItem(item, ptr);
|
|
|
|
|
|
|
|
|
|
|
|
if (it->first == ESM::MagicEffect::BoundGloves)
|
|
|
|
if (it->first == ESM::MagicEffect::BoundGloves)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
item = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find(
|
|
|
|
|
|
|
|
"sMagicBoundLeftGauntletID")->getString();
|
|
|
|
|
|
|
|
adjustBoundItem(item, magnitude > 0, ptr);
|
|
|
|
|
|
|
|
item = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find(
|
|
|
|
item = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find(
|
|
|
|
"sMagicBoundRightGauntletID")->getString();
|
|
|
|
"sMagicBoundRightGauntletID")->getString();
|
|
|
|
adjustBoundItem(item, magnitude > 0, ptr);
|
|
|
|
magnitude > 0 ? addBoundItem(item, ptr) : removeBoundItem(item, ptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
|
|
|
|
adjustBoundItem(item, magnitude > 0, ptr);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (magnitude > 0)
|
|
|
|
|
|
|
|
creatureStats.mBoundItems.insert(it->first);
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
creatureStats.mBoundItems.erase(it->first);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|