Move cleanupSummonedCreature to the mechanics manager (Bug #3439)

pull/1/head
scrawl 9 years ago
parent 910ad76e29
commit 4acfe1a7e4

@ -229,6 +229,8 @@ namespace MWBase
/// Sets the NPC's Acrobatics skill to match the fWerewolfAcrobatics GMST. /// Sets the NPC's Acrobatics skill to match the fWerewolfAcrobatics GMST.
/// It only applies to the current form the NPC is in. /// It only applies to the current form the NPC is in.
virtual void applyWerewolfAcrobatics(const MWWorld::Ptr& actor) = 0; virtual void applyWerewolfAcrobatics(const MWWorld::Ptr& actor) = 0;
virtual void cleanupSummonedCreature(const MWWorld::Ptr& caster, int creatureActorId) = 0;
}; };
} }

@ -688,9 +688,7 @@ namespace MWMechanics
creatureStats.getActiveSpells().visitEffectSources(updateSummonedCreatures); creatureStats.getActiveSpells().visitEffectSources(updateSummonedCreatures);
if (ptr.getClass().hasInventoryStore(ptr)) if (ptr.getClass().hasInventoryStore(ptr))
ptr.getClass().getInventoryStore(ptr).visitEffectSources(updateSummonedCreatures); ptr.getClass().getInventoryStore(ptr).visitEffectSources(updateSummonedCreatures);
std::set<int> deleted = updateSummonedCreatures.process(); updateSummonedCreatures.process();
for (std::set<int>::const_iterator it = deleted.begin(); it != deleted.end(); ++it)
purgeSpellEffects(*it);
} }
void Actors::calculateNpcStatModifiers (const MWWorld::Ptr& ptr, float duration) void Actors::calculateNpcStatModifiers (const MWWorld::Ptr& ptr, float duration)
@ -1259,6 +1257,30 @@ namespace MWMechanics
} }
} }
void Actors::cleanupSummonedCreature (MWMechanics::CreatureStats& casterStats, int creatureActorId)
{
MWWorld::Ptr ptr = MWBase::Environment::get().getWorld()->searchPtrViaActorId(creatureActorId);
if (!ptr.isEmpty())
{
MWBase::Environment::get().getWorld()->deleteObject(ptr);
const ESM::Static* fx = MWBase::Environment::get().getWorld()->getStore().get<ESM::Static>()
.search("VFX_Summon_End");
if (fx)
MWBase::Environment::get().getWorld()->spawnEffect("meshes\\" + fx->mModel,
"", ptr.getRefData().getPosition().asVec3());
}
else if (creatureActorId != -1)
{
// We didn't find the creature. It's probably in an inactive cell.
// Add to graveyard so we can delete it when the cell becomes active.
std::vector<int>& graveyard = casterStats.getSummonedCreatureGraveyard();
graveyard.push_back(creatureActorId);
}
purgeSpellEffects(creatureActorId);
}
void Actors::purgeSpellEffects(int casterActorId) void Actors::purgeSpellEffects(int casterActorId)
{ {
for (PtrActorMap::iterator iter(mActors.begin());iter != mActors.end();++iter) for (PtrActorMap::iterator iter(mActors.begin());iter != mActors.end();++iter)

@ -19,6 +19,7 @@ namespace MWWorld
namespace MWMechanics namespace MWMechanics
{ {
class Actor; class Actor;
class CreatureStats;
class Actors class Actors
{ {
@ -113,6 +114,8 @@ namespace MWMechanics
void getObjectsInRange(const osg::Vec3f& position, float radius, std::vector<MWWorld::Ptr>& out); void getObjectsInRange(const osg::Vec3f& position, float radius, std::vector<MWWorld::Ptr>& out);
void cleanupSummonedCreature (CreatureStats& casterStats, int creatureActorId);
///Returns the list of actors which are siding with the given actor in fights ///Returns the list of actors which are siding with the given actor in fights
/**ie AiFollow or AiEscort is active and the target is the actor **/ /**ie AiFollow or AiEscort is active and the target is the actor **/
std::list<MWWorld::Ptr> getActorsSidingWith(const MWWorld::Ptr& actor); std::list<MWWorld::Ptr> getActorsSidingWith(const MWWorld::Ptr& actor);

@ -1700,4 +1700,9 @@ namespace MWMechanics
stats.getSkill(ESM::Skill::Acrobatics).setBase(gmst.find("fWerewolfAcrobatics")->getInt()); stats.getSkill(ESM::Skill::Acrobatics).setBase(gmst.find("fWerewolfAcrobatics")->getInt());
} }
void MechanicsManager::cleanupSummonedCreature(const MWWorld::Ptr &caster, int creatureActorId)
{
mActors.cleanupSummonedCreature(caster.getClass().getCreatureStats(caster), creatureActorId);
}
} }

@ -189,6 +189,8 @@ namespace MWMechanics
virtual void setWerewolf(const MWWorld::Ptr& actor, bool werewolf); virtual void setWerewolf(const MWWorld::Ptr& actor, bool werewolf);
virtual void applyWerewolfAcrobatics(const MWWorld::Ptr& actor); virtual void applyWerewolfAcrobatics(const MWWorld::Ptr& actor);
virtual void cleanupSummonedCreature(const MWWorld::Ptr& caster, int creatureActorId);
private: private:
void reportCrime (const MWWorld::Ptr& ptr, const MWWorld::Ptr& victim, void reportCrime (const MWWorld::Ptr& ptr, const MWWorld::Ptr& victim,
OffenseType type, int arg=0); OffenseType type, int arg=0);

@ -26,7 +26,6 @@
#include "magiceffects.hpp" #include "magiceffects.hpp"
#include "npcstats.hpp" #include "npcstats.hpp"
#include "summoning.hpp"
#include "actorutil.hpp" #include "actorutil.hpp"
namespace namespace
@ -510,7 +509,7 @@ namespace MWMechanics
std::map<CreatureStats::SummonKey, int>::iterator found = targetStats.getSummonedCreatureMap().find(std::make_pair(effectIt->mEffectID, mId)); std::map<CreatureStats::SummonKey, int>::iterator found = targetStats.getSummonedCreatureMap().find(std::make_pair(effectIt->mEffectID, mId));
if (found != targetStats.getSummonedCreatureMap().end()) if (found != targetStats.getSummonedCreatureMap().end())
{ {
cleanupSummonedCreature(targetStats, found->second); MWBase::Environment::get().getMechanicsManager()->cleanupSummonedCreature(target, found->second);
targetStats.getSummonedCreatureMap().erase(found); targetStats.getSummonedCreatureMap().erase(found);
} }
} }

@ -4,6 +4,7 @@
#include "../mwbase/environment.hpp" #include "../mwbase/environment.hpp"
#include "../mwbase/world.hpp" #include "../mwbase/world.hpp"
#include "../mwbase/mechanicsmanager.hpp"
#include "../mwmechanics/spellcasting.hpp" #include "../mwmechanics/spellcasting.hpp"
@ -21,28 +22,6 @@
namespace MWMechanics namespace MWMechanics
{ {
void cleanupSummonedCreature (MWMechanics::CreatureStats& casterStats, int creatureActorId)
{
MWWorld::Ptr ptr = MWBase::Environment::get().getWorld()->searchPtrViaActorId(creatureActorId);
if (!ptr.isEmpty())
{
MWBase::Environment::get().getWorld()->deleteObject(ptr);
const ESM::Static* fx = MWBase::Environment::get().getWorld()->getStore().get<ESM::Static>()
.search("VFX_Summon_End");
if (fx)
MWBase::Environment::get().getWorld()->spawnEffect("meshes\\" + fx->mModel,
"", ptr.getRefData().getPosition().asVec3());
}
else if (creatureActorId != -1)
{
// We didn't find the creature. It's probably in an inactive cell.
// Add to graveyard so we can delete it when the cell becomes active.
std::vector<int>& graveyard = casterStats.getSummonedCreatureGraveyard();
graveyard.push_back(creatureActorId);
}
}
UpdateSummonedCreatures::UpdateSummonedCreatures(const MWWorld::Ptr &actor) UpdateSummonedCreatures::UpdateSummonedCreatures(const MWWorld::Ptr &actor)
: mActor(actor) : mActor(actor)
{ {
@ -61,10 +40,8 @@ namespace MWMechanics
} }
} }
std::set<int> UpdateSummonedCreatures::process() void UpdateSummonedCreatures::process()
{ {
std::set<int> deletedCreatures;
static std::map<int, std::string> summonMap; static std::map<int, std::string> summonMap;
if (summonMap.empty()) if (summonMap.empty())
{ {
@ -102,8 +79,7 @@ namespace MWMechanics
if (!found) if (!found)
{ {
// Effect has ended // Effect has ended
cleanupSummonedCreature(creatureStats, it->second); MWBase::Environment::get().getMechanicsManager()->cleanupSummonedCreature(mActor, it->second);
deletedCreatures.insert(it->second);
creatureMap.erase(it++); creatureMap.erase(it++);
continue; continue;
} }
@ -165,7 +141,7 @@ namespace MWMechanics
if (mActor.getClass().hasInventoryStore(ptr)) if (mActor.getClass().hasInventoryStore(ptr))
mActor.getClass().getInventoryStore(mActor).purgeEffect(it->first.first, it->first.second); mActor.getClass().getInventoryStore(mActor).purgeEffect(it->first.first, it->first.second);
cleanupSummonedCreature(creatureStats, it->second); MWBase::Environment::get().getMechanicsManager()->cleanupSummonedCreature(mActor, it->second);
creatureMap.erase(it++); creatureMap.erase(it++);
} }
else else
@ -191,8 +167,6 @@ namespace MWMechanics
else else
++it; ++it;
} }
return deletedCreatures;
} }
} }

@ -21,8 +21,7 @@ namespace MWMechanics
float magnitude, float remainingTime = -1, float totalTime = -1); float magnitude, float remainingTime = -1, float totalTime = -1);
/// To call after all effect sources have been visited /// To call after all effect sources have been visited
/// Returns list of actorIds for creatures that have been deleted due to the magic effect having expired void process();
std::set<int> process();
private: private:
MWWorld::Ptr mActor; MWWorld::Ptr mActor;
@ -30,8 +29,6 @@ namespace MWMechanics
std::set<std::pair<int, std::string> > mActiveEffects; std::set<std::pair<int, std::string> > mActiveEffects;
}; };
void cleanupSummonedCreature (MWMechanics::CreatureStats& casterStats, int creatureActorId);
} }
#endif #endif

Loading…
Cancel
Save