Bug #2326 - Bound Items

Join the team. This area is for people who want to participate in OpenMW's development in one way or another.
Post Reply
User avatar
Youth
Posts: 9
Joined: 19 Sep 2017, 19:19

Bug #2326 - Bound Items

Post by Youth »

I just started looking at the code last Friday. I've been looking at this bug because it seemed like it would be easy enough for someone new. I've hit a road block and instead of scratching my head for several more weeks and implementing something the wrong way, I thought I'd just ask.

The issue in question is that bound items do not re-equip after the spell expires. I checked, and in the released openmw version NPCs already requip their items, though Balmora's favorite Khajiit friend did not recast his devil weapon's bound effect after it expired. In the version of OpenMW I compiled from the github, however, he did recast it. Point being, actors already work (for weapons at least). I could not find an NPC that casts bound armor spells but if they don't work the code to run an autoequip is pretty simplistic and preferable from storing records for every NPC.

I have the following, with the red text being my (two) additions

Code: Select all

actors.cpp
void adjustBoundItem (const std::string& item, bool bound, const MWWorld::Ptr& actor)
{
    if (bound)
    {
        if (actor.getClass().getContainerStore(actor).count(item) == 0)
        {
            MWWorld::InventoryStore& store = actor.getClass().getInventoryStore(actor);
            MWWorld::Ptr newPtr = *store.MWWorld::ContainerStore::add(item, 1, actor);
					//Store pointer to previously equiped item
            				MWWorld::Ptr BoundPtr = *store.getSlot(newPtr.getContainerStore()->getType(newPtr));
            MWWorld::ActionEquip action(newPtr);
            action.execute(actor);
            MWWorld::ConstContainerStoreIterator rightHand = store.getSlot(MWWorld::InventoryStore::Slot_CarriedRight);
            // change draw state only if the item is in player's right hand
            if (actor == MWMechanics::getPlayer()
                    && rightHand != store.end() && newPtr == *rightHand)
            {
                MWBase::Environment::get().getWorld()->getPlayer().setDrawState(MWMechanics::DrawState_Weapon);
            }
        }
    }
    else
    {
        actor.getClass().getContainerStore(actor).remove(item, 1, actor);
 				//If actor is player, equip the player's previous item.
		 		if (actor == MWMechanics::getPlayer())
		 		{
 					//load pointer and actionequip it.
		 		}
    }
}
So all I've done so far (which I believe works) is get the previously equipped item in the same equipment slot as the new item and store it as a MWWorld::Ptr. Note that for gloves, it stores two (because there are two gloves). I need to store it into the save game but am unsure of how to do this. If anyone could point me in the right direction or find a similar situation for me to study, I would appreciate it.

edit: Color tags don't actually work in code tags (unfortunate) so I've just formatted my additions so they stand out.
kuyondo
Posts: 243
Joined: 29 Mar 2016, 17:45

Re: Bug #2326 - Bound Items

Post by kuyondo »

Maybe related to this?->https://bugs.openmw.org/issues/4050
Post Reply