extracted common sub-expressions.

pull/735/head
dteviot 10 years ago
parent ff5ef7055e
commit 0ee7407101

@ -603,11 +603,9 @@ namespace MWClass
{
float weight = getContainerStore (ptr).getWeight();
const MWMechanics::CreatureStats& stats = getCreatureStats (ptr);
weight -= stats.getMagicEffects().get (MWMechanics::EffectKey (ESM::MagicEffect::Feather)).getMagnitude();
weight += stats.getMagicEffects().get (MWMechanics::EffectKey (ESM::MagicEffect::Burden)).getMagnitude();
const MWMechanics::MagicEffects& effects = getCreatureStats(ptr).getMagicEffects();
weight -= effects.get(ESM::MagicEffect::Feather).getMagnitude();
weight += effects.get(ESM::MagicEffect::Burden).getMagnitude();
if (weight<0)
weight = 0;

@ -538,19 +538,19 @@ namespace MWMechanics
if (!creature || ptr.get<ESM::Creature>()->mBase->mData.mType == ESM::Creature::Creatures)
{
Stat<int> stat = creatureStats.getAiSetting(CreatureStats::AI_Fight);
stat.setModifier(static_cast<int>(creatureStats.getMagicEffects().get(ESM::MagicEffect::FrenzyHumanoid + creature).getMagnitude()
- creatureStats.getMagicEffects().get(ESM::MagicEffect::CalmHumanoid+creature).getMagnitude()));
stat.setModifier(static_cast<int>(effects.get(ESM::MagicEffect::FrenzyHumanoid + creature).getMagnitude()
- effects.get(ESM::MagicEffect::CalmHumanoid+creature).getMagnitude()));
creatureStats.setAiSetting(CreatureStats::AI_Fight, stat);
stat = creatureStats.getAiSetting(CreatureStats::AI_Flee);
stat.setModifier(static_cast<int>(creatureStats.getMagicEffects().get(ESM::MagicEffect::DemoralizeHumanoid + creature).getMagnitude()
- creatureStats.getMagicEffects().get(ESM::MagicEffect::RallyHumanoid+creature).getMagnitude()));
stat.setModifier(static_cast<int>(effects.get(ESM::MagicEffect::DemoralizeHumanoid + creature).getMagnitude()
- effects.get(ESM::MagicEffect::RallyHumanoid+creature).getMagnitude()));
creatureStats.setAiSetting(CreatureStats::AI_Flee, stat);
}
if (creature && ptr.get<ESM::Creature>()->mBase->mData.mType == ESM::Creature::Undead)
{
Stat<int> stat = creatureStats.getAiSetting(CreatureStats::AI_Flee);
stat.setModifier(static_cast<int>(creatureStats.getMagicEffects().get(ESM::MagicEffect::TurnUndead).getMagnitude()));
stat.setModifier(static_cast<int>(effects.get(ESM::MagicEffect::TurnUndead).getMagnitude()));
creatureStats.setAiSetting(CreatureStats::AI_Flee, stat);
}
@ -596,8 +596,8 @@ namespace MWMechanics
// TODO: dirty flag for magic effects to avoid some unnecessary work below?
// any value of calm > 0 will stop the actor from fighting
if ((creatureStats.getMagicEffects().get(ESM::MagicEffect::CalmHumanoid).getMagnitude() > 0 && ptr.getClass().isNpc())
|| (creatureStats.getMagicEffects().get(ESM::MagicEffect::CalmCreature).getMagnitude() > 0 && !ptr.getClass().isNpc()))
if ((effects.get(ESM::MagicEffect::CalmHumanoid).getMagnitude() > 0 && ptr.getClass().isNpc())
|| (effects.get(ESM::MagicEffect::CalmCreature).getMagnitude() > 0 && !ptr.getClass().isNpc()))
{
for (std::list<AiPackage*>::const_iterator it = creatureStats.getAiSequence().begin(); it != creatureStats.getAiSequence().end(); )
{
@ -630,7 +630,7 @@ namespace MWMechanics
for (std::map<int, std::string>::iterator it = boundItemsMap.begin(); it != boundItemsMap.end(); ++it)
{
bool found = creatureStats.mBoundItems.find(it->first) != creatureStats.mBoundItems.end();
float magnitude = creatureStats.getMagicEffects().get(it->first).getMagnitude();
float magnitude = effects.get(it->first).getMagnitude();
if (found != (magnitude > 0))
{
std::string itemGmst = it->second;

@ -147,9 +147,9 @@ namespace MWMechanics
void resistNormalWeapon(const MWWorld::Ptr &actor, const MWWorld::Ptr& attacker, const MWWorld::Ptr &weapon, float &damage)
{
MWMechanics::CreatureStats& stats = actor.getClass().getCreatureStats(actor);
float resistance = std::min(100.f, stats.getMagicEffects().get(ESM::MagicEffect::ResistNormalWeapons).getMagnitude()
- stats.getMagicEffects().get(ESM::MagicEffect::WeaknessToNormalWeapons).getMagnitude());
const MWMechanics::MagicEffects& effects = actor.getClass().getCreatureStats(actor).getMagicEffects();
float resistance = std::min(100.f, effects.get(ESM::MagicEffect::ResistNormalWeapons).getMagnitude()
- effects.get(ESM::MagicEffect::WeaknessToNormalWeapons).getMagnitude());
float multiplier = 1.f - resistance / 100.f;
@ -242,9 +242,9 @@ namespace MWMechanics
const MWWorld::Store<ESM::GameSetting> &gmst = world->getStore().get<ESM::GameSetting>();
float defenseTerm = 0;
if (victim.getClass().getCreatureStats(victim).getFatigue().getCurrent() >= 0)
MWMechanics::CreatureStats& victimStats = victim.getClass().getCreatureStats(victim);
if (victimStats.getFatigue().getCurrent() >= 0)
{
MWMechanics::CreatureStats& victimStats = victim.getClass().getCreatureStats(victim);
// Maybe we should keep an aware state for actors updated every so often instead of testing every time
bool unaware = (!victimStats.getAiSequence().isInCombat())
&& (attacker == MWBase::Environment::get().getWorld()->getPlayerPtr())

@ -1310,11 +1310,12 @@ namespace MWMechanics
return false;
std::list<MWWorld::Ptr> followers = getActorsFollowing(attacker);
MWMechanics::CreatureStats& targetStats = ptr.getClass().getCreatureStats(ptr);
if (std::find(followers.begin(), followers.end(), ptr) != followers.end())
{
ptr.getClass().getCreatureStats(ptr).friendlyHit();
targetStats.friendlyHit();
if (ptr.getClass().getCreatureStats(ptr).getFriendlyHits() < 4)
if (targetStats.getFriendlyHits() < 4)
{
MWBase::Environment::get().getDialogueManager()->say(ptr, "hit");
return false;
@ -1322,7 +1323,7 @@ namespace MWMechanics
}
// Attacking an NPC that is already in combat with any other NPC is not a crime
AiSequence& seq = ptr.getClass().getCreatureStats(ptr).getAiSequence();
AiSequence& seq = targetStats.getAiSequence();
bool isFightingNpc = false;
for (std::list<AiPackage*>::const_iterator it = seq.begin(); it != seq.end(); ++it)
{
@ -1334,13 +1335,13 @@ namespace MWMechanics
}
}
if (ptr.getClass().isNpc() && !attacker.isEmpty() && !ptr.getClass().getCreatureStats(ptr).getAiSequence().isInCombat(attacker)
if (ptr.getClass().isNpc() && !attacker.isEmpty() && !seq.isInCombat(attacker)
&& !isAggressive(ptr, attacker) && !isFightingNpc)
commitCrime(attacker, ptr, MWBase::MechanicsManager::OT_Assault);
if (!attacker.isEmpty() && (attacker.getClass().getCreatureStats(attacker).getAiSequence().isInCombat(ptr)
|| attacker == MWBase::Environment::get().getWorld()->getPlayerPtr())
&& !ptr.getClass().getCreatureStats(ptr).getAiSequence().isInCombat(attacker))
&& !seq.isInCombat(attacker))
{
// Attacker is in combat with us, but we are not in combat with the attacker yet. Time to fight back.
// Note: accidental or collateral damage attacks are ignored.

@ -332,9 +332,10 @@ namespace MWMechanics
const ESM::Spell* spell = MWBase::Environment::get().getWorld()->getStore().get<ESM::Spell>().search (mId);
if (spell && (spell->mData.mType == ESM::Spell::ST_Disease || spell->mData.mType == ESM::Spell::ST_Blight))
{
float x = (spell->mData.mType == ESM::Spell::ST_Disease) ?
target.getClass().getCreatureStats(target).getMagicEffects().get(ESM::MagicEffect::ResistCommonDisease).getMagnitude()
: target.getClass().getCreatureStats(target).getMagicEffects().get(ESM::MagicEffect::ResistBlightDisease).getMagnitude();
int requiredResistance = (spell->mData.mType == ESM::Spell::ST_Disease) ?
ESM::MagicEffect::ResistCommonDisease
: ESM::MagicEffect::ResistBlightDisease;
float x = target.getClass().getCreatureStats(target).getMagicEffects().get(requiredResistance).getMagnitude();
if (Misc::Rng::roll0to99() <= x)
{

@ -1159,10 +1159,10 @@ namespace MWScript
{
MWWorld::Ptr ptr = R()(runtime);
MWMechanics::CreatureStats& stats = ptr.getClass().getCreatureStats(ptr);
float currentValue = stats.getMagicEffects().get(mPositiveEffect).getMagnitude();
const MWMechanics::MagicEffects& effects = ptr.getClass().getCreatureStats(ptr).getMagicEffects();
float currentValue = effects.get(mPositiveEffect).getMagnitude();
if (mNegativeEffect != -1)
currentValue -= stats.getMagicEffects().get(mNegativeEffect).getMagnitude();
currentValue -= effects.get(mNegativeEffect).getMagnitude();
int ret = static_cast<int>(currentValue);
runtime.push(ret);
@ -1185,14 +1185,14 @@ namespace MWScript
virtual void execute(Interpreter::Runtime &runtime)
{
MWWorld::Ptr ptr = R()(runtime);
MWMechanics::CreatureStats& stats = ptr.getClass().getCreatureStats(ptr);
float currentValue = stats.getMagicEffects().get(mPositiveEffect).getMagnitude();
MWMechanics::MagicEffects& effects = ptr.getClass().getCreatureStats(ptr).getMagicEffects();
float currentValue = effects.get(mPositiveEffect).getMagnitude();
if (mNegativeEffect != -1)
currentValue -= stats.getMagicEffects().get(mNegativeEffect).getMagnitude();
currentValue -= effects.get(mNegativeEffect).getMagnitude();
int arg = runtime[0].mInteger;
runtime.pop();
stats.getMagicEffects().modifyBase(mPositiveEffect, (arg - static_cast<int>(currentValue)));
effects.modifyBase(mPositiveEffect, (arg - static_cast<int>(currentValue)));
}
};

Loading…
Cancel
Save