1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-02-01 02:45:32 +00:00

update NpcAnimation inventory reference on cell change

This commit is contained in:
greye 2013-02-21 23:56:34 +04:00
parent 868916a9a2
commit 9659b4a95e
3 changed files with 36 additions and 28 deletions

View file

@ -163,7 +163,9 @@ void Actors::updateObjectCell(const MWWorld::Ptr &ptr)
{ {
/// \note Update key (Ptr's are compared only with refdata so mCell /// \note Update key (Ptr's are compared only with refdata so mCell
/// on key is outdated), maybe redundant /// on key is outdated), maybe redundant
Animation *anim = iter->second; NpcAnimation *anim = static_cast<NpcAnimation *>(iter->second);
anim->updateParts(MWWorld::Class::get(ptr).getInventoryStore(ptr));
mAllActors.erase(iter); mAllActors.erase(iter);
mAllActors[ptr] = anim; mAllActors[ptr] = anim;
} }

View file

@ -48,21 +48,21 @@ NpcAnimation::~NpcAnimation()
NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, Ogre::SceneNode* node, MWWorld::InventoryStore& inv, int visibilityFlags) NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, Ogre::SceneNode* node, MWWorld::InventoryStore& inv, int visibilityFlags)
: Animation(), : Animation(),
mStateID(-1), mStateID(-1),
mInv(inv), mInv(&inv),
mTimeToChange(0), mTimeToChange(0),
mVisibilityFlags(visibilityFlags), mVisibilityFlags(visibilityFlags),
mRobe(mInv.end()), mRobe(mInv->end()),
mHelmet(mInv.end()), mHelmet(mInv->end()),
mShirt(mInv.end()), mShirt(mInv->end()),
mCuirass(mInv.end()), mCuirass(mInv->end()),
mGreaves(mInv.end()), mGreaves(mInv->end()),
mPauldronL(mInv.end()), mPauldronL(mInv->end()),
mPauldronR(mInv.end()), mPauldronR(mInv->end()),
mBoots(mInv.end()), mBoots(mInv->end()),
mPants(mInv.end()), mPants(mInv->end()),
mGloveL(mInv.end()), mGloveL(mInv->end()),
mGloveR(mInv.end()), mGloveR(mInv->end()),
mSkirtIter(mInv.end()) mSkirtIter(mInv->end())
{ {
mNpc = ptr.get<ESM::NPC>()->mBase; mNpc = ptr.get<ESM::NPC>()->mBase;
@ -160,7 +160,7 @@ void NpcAnimation::updateParts()
}; };
for(size_t i = 0;i < sizeof(slotlist)/sizeof(slotlist[0]);i++) for(size_t i = 0;i < sizeof(slotlist)/sizeof(slotlist[0]);i++)
{ {
MWWorld::ContainerStoreIterator iter = mInv.getSlot(slotlist[i].slot); MWWorld::ContainerStoreIterator iter = mInv->getSlot(slotlist[i].slot);
if(*slotlist[i].iter != iter) if(*slotlist[i].iter != iter)
{ {
*slotlist[i].iter = iter; *slotlist[i].iter = iter;
@ -171,7 +171,7 @@ void NpcAnimation::updateParts()
if(apparelChanged) if(apparelChanged)
{ {
if(mRobe != mInv.end()) if(mRobe != mInv->end())
{ {
MWWorld::Ptr ptr = *mRobe; MWWorld::Ptr ptr = *mRobe;
@ -191,7 +191,7 @@ void NpcAnimation::updateParts()
reserveIndividualPart(ESM::PRT_RPauldron, MWWorld::InventoryStore::Slot_Robe, 5); reserveIndividualPart(ESM::PRT_RPauldron, MWWorld::InventoryStore::Slot_Robe, 5);
reserveIndividualPart(ESM::PRT_LPauldron, MWWorld::InventoryStore::Slot_Robe, 5); reserveIndividualPart(ESM::PRT_LPauldron, MWWorld::InventoryStore::Slot_Robe, 5);
} }
if(mSkirtIter != mInv.end()) if(mSkirtIter != mInv->end())
{ {
MWWorld::Ptr ptr = *mSkirtIter; MWWorld::Ptr ptr = *mSkirtIter;
@ -203,39 +203,39 @@ void NpcAnimation::updateParts()
reserveIndividualPart(ESM::PRT_LLeg, MWWorld::InventoryStore::Slot_Skirt, 4); reserveIndividualPart(ESM::PRT_LLeg, MWWorld::InventoryStore::Slot_Skirt, 4);
} }
if(mHelmet != mInv.end()) if(mHelmet != mInv->end())
{ {
removeIndividualPart(ESM::PRT_Hair); removeIndividualPart(ESM::PRT_Hair);
const ESM::Armor *armor = (mHelmet->get<ESM::Armor>())->mBase; const ESM::Armor *armor = (mHelmet->get<ESM::Armor>())->mBase;
std::vector<ESM::PartReference> parts = armor->mParts.mParts; std::vector<ESM::PartReference> parts = armor->mParts.mParts;
addPartGroup(MWWorld::InventoryStore::Slot_Helmet, 3, parts); addPartGroup(MWWorld::InventoryStore::Slot_Helmet, 3, parts);
} }
if(mCuirass != mInv.end()) if(mCuirass != mInv->end())
{ {
const ESM::Armor *armor = (mCuirass->get<ESM::Armor>())->mBase; const ESM::Armor *armor = (mCuirass->get<ESM::Armor>())->mBase;
std::vector<ESM::PartReference> parts = armor->mParts.mParts; std::vector<ESM::PartReference> parts = armor->mParts.mParts;
addPartGroup(MWWorld::InventoryStore::Slot_Cuirass, 3, parts); addPartGroup(MWWorld::InventoryStore::Slot_Cuirass, 3, parts);
} }
if(mGreaves != mInv.end()) if(mGreaves != mInv->end())
{ {
const ESM::Armor *armor = (mGreaves->get<ESM::Armor>())->mBase; const ESM::Armor *armor = (mGreaves->get<ESM::Armor>())->mBase;
std::vector<ESM::PartReference> parts = armor->mParts.mParts; std::vector<ESM::PartReference> parts = armor->mParts.mParts;
addPartGroup(MWWorld::InventoryStore::Slot_Greaves, 3, parts); addPartGroup(MWWorld::InventoryStore::Slot_Greaves, 3, parts);
} }
if(mPauldronL != mInv.end()) if(mPauldronL != mInv->end())
{ {
const ESM::Armor *armor = (mPauldronL->get<ESM::Armor>())->mBase; const ESM::Armor *armor = (mPauldronL->get<ESM::Armor>())->mBase;
std::vector<ESM::PartReference> parts = armor->mParts.mParts; std::vector<ESM::PartReference> parts = armor->mParts.mParts;
addPartGroup(MWWorld::InventoryStore::Slot_LeftPauldron, 3, parts); addPartGroup(MWWorld::InventoryStore::Slot_LeftPauldron, 3, parts);
} }
if(mPauldronR != mInv.end()) if(mPauldronR != mInv->end())
{ {
const ESM::Armor *armor = (mPauldronR->get<ESM::Armor>())->mBase; const ESM::Armor *armor = (mPauldronR->get<ESM::Armor>())->mBase;
std::vector<ESM::PartReference> parts = armor->mParts.mParts; std::vector<ESM::PartReference> parts = armor->mParts.mParts;
addPartGroup(MWWorld::InventoryStore::Slot_RightPauldron, 3, parts); addPartGroup(MWWorld::InventoryStore::Slot_RightPauldron, 3, parts);
} }
if(mBoots != mInv.end()) if(mBoots != mInv->end())
{ {
if(mBoots->getTypeName() == typeid(ESM::Clothing).name()) if(mBoots->getTypeName() == typeid(ESM::Clothing).name())
{ {
@ -250,7 +250,7 @@ void NpcAnimation::updateParts()
addPartGroup(MWWorld::InventoryStore::Slot_Boots, 3, parts); addPartGroup(MWWorld::InventoryStore::Slot_Boots, 3, parts);
} }
} }
if(mGloveL != mInv.end()) if(mGloveL != mInv->end())
{ {
if(mGloveL->getTypeName() == typeid(ESM::Clothing).name()) if(mGloveL->getTypeName() == typeid(ESM::Clothing).name())
{ {
@ -265,7 +265,7 @@ void NpcAnimation::updateParts()
addPartGroup(MWWorld::InventoryStore::Slot_LeftGauntlet, 3, parts); addPartGroup(MWWorld::InventoryStore::Slot_LeftGauntlet, 3, parts);
} }
} }
if(mGloveR != mInv.end()) if(mGloveR != mInv->end())
{ {
if(mGloveR->getTypeName() == typeid(ESM::Clothing).name()) if(mGloveR->getTypeName() == typeid(ESM::Clothing).name())
{ {
@ -282,13 +282,13 @@ void NpcAnimation::updateParts()
} }
if(mShirt != mInv.end()) if(mShirt != mInv->end())
{ {
const ESM::Clothing *clothes = (mShirt->get<ESM::Clothing>())->mBase; const ESM::Clothing *clothes = (mShirt->get<ESM::Clothing>())->mBase;
std::vector<ESM::PartReference> parts = clothes->mParts.mParts; std::vector<ESM::PartReference> parts = clothes->mParts.mParts;
addPartGroup(MWWorld::InventoryStore::Slot_Shirt, 2, parts); addPartGroup(MWWorld::InventoryStore::Slot_Shirt, 2, parts);
} }
if(mPants != mInv.end()) if(mPants != mInv->end())
{ {
const ESM::Clothing *clothes = (mPants->get<ESM::Clothing>())->mBase; const ESM::Clothing *clothes = (mPants->get<ESM::Clothing>())->mBase;
std::vector<ESM::PartReference> parts = clothes->mParts.mParts; std::vector<ESM::PartReference> parts = clothes->mParts.mParts;

View file

@ -17,7 +17,7 @@ namespace MWRender{
class NpcAnimation: public Animation{ class NpcAnimation: public Animation{
private: private:
MWWorld::InventoryStore& mInv; MWWorld::InventoryStore *mInv;
int mStateID; int mStateID;
int mPartslots[27]; //Each part slot is taken by clothing, armor, or is empty int mPartslots[27]; //Each part slot is taken by clothing, armor, or is empty
@ -78,7 +78,13 @@ public:
virtual ~NpcAnimation(); virtual ~NpcAnimation();
NifOgre::EntityList insertBoundedPart(const std::string &mesh, int group, const std::string &bonename); NifOgre::EntityList insertBoundedPart(const std::string &mesh, int group, const std::string &bonename);
virtual void runAnimation(float timepassed); virtual void runAnimation(float timepassed);
void updateParts(); void updateParts();
void updateParts(MWWorld::InventoryStore &inventory) {
mInv = &inventory;
updateParts();
}
void removeEntities(NifOgre::EntityList &entities); void removeEntities(NifOgre::EntityList &entities);
void removeIndividualPart(int type); void removeIndividualPart(int type);
void reserveIndividualPart(int type, int group, int priority); void reserveIndividualPart(int type, int group, int priority);