Merge pull request #1200 from Allofich/fix

Fix trying to access stats on non-actors
pull/147/head
scrawl 8 years ago committed by GitHub
commit ec5587ddd3

@ -328,7 +328,7 @@ namespace MWClass
MWMechanics::CreatureStats& stats = ptr.getClass().getCreatureStats(ptr);
// NOTE: 'object' and/or 'attacker' may be empty.
if (!attacker.isEmpty() && !stats.getAiSequence().isInCombat(attacker))
if (!attacker.isEmpty() && attacker.getClass().isActor() && !stats.getAiSequence().isInCombat(attacker))
stats.setAttacked(true);
// Self defense
@ -339,7 +339,7 @@ namespace MWClass
setOnPcHitMe = MWBase::Environment::get().getMechanicsManager()->actorAttacked(ptr, attacker);
// Attacker and target store each other as hitattemptactor if they have no one stored yet
if (!attacker.isEmpty() && !ptr.isEmpty())
if (!attacker.isEmpty() && attacker.getClass().isActor() && !ptr.isEmpty() && ptr.getClass().isActor())
{
MWMechanics::CreatureStats& statsAttacker = attacker.getClass().getCreatureStats(attacker);
// First handle the attacked actor

@ -661,14 +661,14 @@ namespace MWClass
bool setOnPcHitMe = true;
// NOTE: 'object' and/or 'attacker' may be empty.
if (!attacker.isEmpty() && !stats.getAiSequence().isInCombat(attacker))
if (!attacker.isEmpty() && attacker.getClass().isActor() && !stats.getAiSequence().isInCombat(attacker))
{
stats.setAttacked(true);
setOnPcHitMe = MWBase::Environment::get().getMechanicsManager()->actorAttacked(ptr, attacker);
}
// Attacker and target store each other as hitattemptactor if they have no one stored yet
if (!attacker.isEmpty() && !ptr.isEmpty())
if (!attacker.isEmpty() && attacker.getClass().isActor() && !ptr.isEmpty() && ptr.getClass().isActor())
{
MWMechanics::CreatureStats& statsAttacker = attacker.getClass().getCreatureStats(attacker);
// First handle the attacked actor

@ -1216,14 +1216,13 @@ namespace MWMechanics
bool MechanicsManager::actorAttacked(const MWWorld::Ptr &target, const MWWorld::Ptr &attacker)
{
if (target == getPlayer() || !attacker.getClass().isActor())
return false;
std::list<MWWorld::Ptr> followersAttacker = getActorsSidingWith(attacker);
std::list<MWWorld::Ptr> followersTarget = getActorsSidingWith(target);
MWMechanics::CreatureStats& statsTarget = target.getClass().getCreatureStats(target);
if (target == getPlayer())
return false;
if (std::find(followersAttacker.begin(), followersAttacker.end(), target) != followersAttacker.end())
{
statsTarget.friendlyHit();

Loading…
Cancel
Save