mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-21 12:53:51 +00:00
Merge pull request #2973 from akortunov/refactoring
Use more C++11 loops in game mechanics code
This commit is contained in:
commit
21ee1ed317
9 changed files with 94 additions and 110 deletions
|
@ -60,13 +60,14 @@ bool MWMechanics::AiAvoidDoor::execute (const MWWorld::Ptr& actor, CharacterCont
|
||||||
// Make all nearby actors also avoid the door
|
// Make all nearby actors also avoid the door
|
||||||
std::vector<MWWorld::Ptr> actors;
|
std::vector<MWWorld::Ptr> actors;
|
||||||
MWBase::Environment::get().getMechanicsManager()->getActorsInRange(pos.asVec3(),100,actors);
|
MWBase::Environment::get().getMechanicsManager()->getActorsInRange(pos.asVec3(),100,actors);
|
||||||
for(std::vector<MWWorld::Ptr>::iterator it = actors.begin(); it != actors.end(); ++it) {
|
for(auto& actor : actors)
|
||||||
if(*it != getPlayer()) { //Not the player
|
{
|
||||||
MWMechanics::AiSequence& seq = it->getClass().getCreatureStats(*it).getAiSequence();
|
if (actor == getPlayer())
|
||||||
if(seq.getTypeId() != MWMechanics::AiPackageTypeId::AvoidDoor) { //Only add it once
|
continue;
|
||||||
seq.stack(MWMechanics::AiAvoidDoor(mDoorPtr),*it);
|
|
||||||
}
|
MWMechanics::AiSequence& seq = actor.getClass().getCreatureStats(actor).getAiSequence();
|
||||||
}
|
if (seq.getTypeId() != MWMechanics::AiPackageTypeId::AvoidDoor)
|
||||||
|
seq.stack(MWMechanics::AiAvoidDoor(mDoorPtr), actor);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -124,9 +124,9 @@ bool AiFollow::execute (const MWWorld::Ptr& actor, CharacterController& characte
|
||||||
followDistance = 313;
|
followDistance = 313;
|
||||||
short i = 0;
|
short i = 0;
|
||||||
followers.sort();
|
followers.sort();
|
||||||
for (std::list<int>::iterator it = followers.begin(); it != followers.end(); ++it)
|
for (int followIndex : followers)
|
||||||
{
|
{
|
||||||
if (*it == mFollowIndex)
|
if (followIndex == mFollowIndex)
|
||||||
followDistance += 130 * i;
|
followDistance += 130 * i;
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
|
|
|
@ -406,36 +406,36 @@ void AiSequence::fill(const ESM::AIPackageList &list)
|
||||||
if (!list.mList.empty() && list.mList.begin() != (list.mList.end()-1))
|
if (!list.mList.empty() && list.mList.begin() != (list.mList.end()-1))
|
||||||
mRepeat = true;
|
mRepeat = true;
|
||||||
|
|
||||||
for (std::vector<ESM::AIPackage>::const_iterator it = list.mList.begin(); it != list.mList.end(); ++it)
|
for (const auto& esmPackage : list.mList)
|
||||||
{
|
{
|
||||||
std::unique_ptr<MWMechanics::AiPackage> package;
|
std::unique_ptr<MWMechanics::AiPackage> package;
|
||||||
if (it->mType == ESM::AI_Wander)
|
if (esmPackage.mType == ESM::AI_Wander)
|
||||||
{
|
{
|
||||||
ESM::AIWander data = it->mWander;
|
ESM::AIWander data = esmPackage.mWander;
|
||||||
std::vector<unsigned char> idles;
|
std::vector<unsigned char> idles;
|
||||||
idles.reserve(8);
|
idles.reserve(8);
|
||||||
for (int i=0; i<8; ++i)
|
for (int i=0; i<8; ++i)
|
||||||
idles.push_back(data.mIdle[i]);
|
idles.push_back(data.mIdle[i]);
|
||||||
package = std::make_unique<MWMechanics::AiWander>(data.mDistance, data.mDuration, data.mTimeOfDay, idles, data.mShouldRepeat != 0);
|
package = std::make_unique<MWMechanics::AiWander>(data.mDistance, data.mDuration, data.mTimeOfDay, idles, data.mShouldRepeat != 0);
|
||||||
}
|
}
|
||||||
else if (it->mType == ESM::AI_Escort)
|
else if (esmPackage.mType == ESM::AI_Escort)
|
||||||
{
|
{
|
||||||
ESM::AITarget data = it->mTarget;
|
ESM::AITarget data = esmPackage.mTarget;
|
||||||
package = std::make_unique<MWMechanics::AiEscort>(data.mId.toString(), data.mDuration, data.mX, data.mY, data.mZ);
|
package = std::make_unique<MWMechanics::AiEscort>(data.mId.toString(), data.mDuration, data.mX, data.mY, data.mZ);
|
||||||
}
|
}
|
||||||
else if (it->mType == ESM::AI_Travel)
|
else if (esmPackage.mType == ESM::AI_Travel)
|
||||||
{
|
{
|
||||||
ESM::AITravel data = it->mTravel;
|
ESM::AITravel data = esmPackage.mTravel;
|
||||||
package = std::make_unique<MWMechanics::AiTravel>(data.mX, data.mY, data.mZ);
|
package = std::make_unique<MWMechanics::AiTravel>(data.mX, data.mY, data.mZ);
|
||||||
}
|
}
|
||||||
else if (it->mType == ESM::AI_Activate)
|
else if (esmPackage.mType == ESM::AI_Activate)
|
||||||
{
|
{
|
||||||
ESM::AIActivate data = it->mActivate;
|
ESM::AIActivate data = esmPackage.mActivate;
|
||||||
package = std::make_unique<MWMechanics::AiActivate>(data.mName.toString());
|
package = std::make_unique<MWMechanics::AiActivate>(data.mName.toString());
|
||||||
}
|
}
|
||||||
else //if (it->mType == ESM::AI_Follow)
|
else //if (esmPackage.mType == ESM::AI_Follow)
|
||||||
{
|
{
|
||||||
ESM::AITarget data = it->mTarget;
|
ESM::AITarget data = esmPackage.mTarget;
|
||||||
package = std::make_unique<MWMechanics::AiFollow>(data.mId.toString(), data.mDuration, data.mX, data.mY, data.mZ);
|
package = std::make_unique<MWMechanics::AiFollow>(data.mId.toString(), data.mDuration, data.mX, data.mY, data.mZ);
|
||||||
}
|
}
|
||||||
mPackages.push_back(std::move(package));
|
mPackages.push_back(std::move(package));
|
||||||
|
@ -457,10 +457,9 @@ void AiSequence::readState(const ESM::AiSequence::AiSequence &sequence)
|
||||||
|
|
||||||
// If there is more than one non-combat, non-pursue package in the list, enable repeating.
|
// If there is more than one non-combat, non-pursue package in the list, enable repeating.
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for (std::vector<ESM::AiSequence::AiPackageContainer>::const_iterator it = sequence.mPackages.begin();
|
for (auto& container : sequence.mPackages)
|
||||||
it != sequence.mPackages.end(); ++it)
|
|
||||||
{
|
{
|
||||||
if (isActualAiPackage(static_cast<AiPackageTypeId>(it->mType)))
|
if (isActualAiPackage(static_cast<AiPackageTypeId>(container.mType)))
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -468,20 +467,19 @@ void AiSequence::readState(const ESM::AiSequence::AiSequence &sequence)
|
||||||
mRepeat = true;
|
mRepeat = true;
|
||||||
|
|
||||||
// Load packages
|
// Load packages
|
||||||
for (std::vector<ESM::AiSequence::AiPackageContainer>::const_iterator it = sequence.mPackages.begin();
|
for (auto& container : sequence.mPackages)
|
||||||
it != sequence.mPackages.end(); ++it)
|
|
||||||
{
|
{
|
||||||
std::unique_ptr<MWMechanics::AiPackage> package;
|
std::unique_ptr<MWMechanics::AiPackage> package;
|
||||||
switch (it->mType)
|
switch (container.mType)
|
||||||
{
|
{
|
||||||
case ESM::AiSequence::Ai_Wander:
|
case ESM::AiSequence::Ai_Wander:
|
||||||
{
|
{
|
||||||
package.reset(new AiWander(static_cast<ESM::AiSequence::AiWander*>(it->mPackage)));
|
package.reset(new AiWander(static_cast<ESM::AiSequence::AiWander*>(container.mPackage)));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ESM::AiSequence::Ai_Travel:
|
case ESM::AiSequence::Ai_Travel:
|
||||||
{
|
{
|
||||||
const auto source = static_cast<const ESM::AiSequence::AiTravel*>(it->mPackage);
|
const auto source = static_cast<const ESM::AiSequence::AiTravel*>(container.mPackage);
|
||||||
if (source->mHidden)
|
if (source->mHidden)
|
||||||
package.reset(new AiInternalTravel(source));
|
package.reset(new AiInternalTravel(source));
|
||||||
else
|
else
|
||||||
|
@ -490,27 +488,27 @@ void AiSequence::readState(const ESM::AiSequence::AiSequence &sequence)
|
||||||
}
|
}
|
||||||
case ESM::AiSequence::Ai_Escort:
|
case ESM::AiSequence::Ai_Escort:
|
||||||
{
|
{
|
||||||
package.reset(new AiEscort(static_cast<ESM::AiSequence::AiEscort*>(it->mPackage)));
|
package.reset(new AiEscort(static_cast<ESM::AiSequence::AiEscort*>(container.mPackage)));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ESM::AiSequence::Ai_Follow:
|
case ESM::AiSequence::Ai_Follow:
|
||||||
{
|
{
|
||||||
package.reset(new AiFollow(static_cast<ESM::AiSequence::AiFollow*>(it->mPackage)));
|
package.reset(new AiFollow(static_cast<ESM::AiSequence::AiFollow*>(container.mPackage)));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ESM::AiSequence::Ai_Activate:
|
case ESM::AiSequence::Ai_Activate:
|
||||||
{
|
{
|
||||||
package.reset(new AiActivate(static_cast<ESM::AiSequence::AiActivate*>(it->mPackage)));
|
package.reset(new AiActivate(static_cast<ESM::AiSequence::AiActivate*>(container.mPackage)));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ESM::AiSequence::Ai_Combat:
|
case ESM::AiSequence::Ai_Combat:
|
||||||
{
|
{
|
||||||
package.reset(new AiCombat(static_cast<ESM::AiSequence::AiCombat*>(it->mPackage)));
|
package.reset(new AiCombat(static_cast<ESM::AiSequence::AiCombat*>(container.mPackage)));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ESM::AiSequence::Ai_Pursue:
|
case ESM::AiSequence::Ai_Pursue:
|
||||||
{
|
{
|
||||||
package.reset(new AiPursue(static_cast<ESM::AiSequence::AiPursue*>(it->mPackage)));
|
package.reset(new AiPursue(static_cast<ESM::AiSequence::AiPursue*>(container.mPackage)));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -809,11 +809,11 @@ namespace MWMechanics
|
||||||
void AiWander::AddNonPathGridAllowedPoints(osg::Vec3f npcPos, const ESM::Pathgrid * pathGrid, int pointIndex, AiWanderStorage& storage)
|
void AiWander::AddNonPathGridAllowedPoints(osg::Vec3f npcPos, const ESM::Pathgrid * pathGrid, int pointIndex, AiWanderStorage& storage)
|
||||||
{
|
{
|
||||||
storage.mAllowedNodes.push_back(PathFinder::makePathgridPoint(npcPos));
|
storage.mAllowedNodes.push_back(PathFinder::makePathgridPoint(npcPos));
|
||||||
for (std::vector<ESM::Pathgrid::Edge>::const_iterator it = pathGrid->mEdges.begin(); it != pathGrid->mEdges.end(); ++it)
|
for (auto& edge : pathGrid->mEdges)
|
||||||
{
|
{
|
||||||
if (it->mV0 == pointIndex)
|
if (edge.mV0 == pointIndex)
|
||||||
{
|
{
|
||||||
AddPointBetweenPathGridPoints(pathGrid->mPoints[it->mV0], pathGrid->mPoints[it->mV1], storage);
|
AddPointBetweenPathGridPoints(pathGrid->mPoints[edge.mV0], pathGrid->mPoints[edge.mV1], storage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,38 +61,36 @@ namespace MWMechanics
|
||||||
|
|
||||||
// Note: the algorithm heavily depends on the traversal order of the spells. For vanilla-compatible results the
|
// Note: the algorithm heavily depends on the traversal order of the spells. For vanilla-compatible results the
|
||||||
// Store must preserve the record ordering as it was in the content files.
|
// Store must preserve the record ordering as it was in the content files.
|
||||||
for (MWWorld::Store<ESM::Spell>::iterator iter = spells.begin(); iter != spells.end(); ++iter)
|
for (const ESM::Spell& spell : spells)
|
||||||
{
|
{
|
||||||
const ESM::Spell* spell = &*iter;
|
if (spell.mData.mType != ESM::Spell::ST_Spell)
|
||||||
|
|
||||||
if (spell->mData.mType != ESM::Spell::ST_Spell)
|
|
||||||
continue;
|
continue;
|
||||||
if (!(spell->mData.mFlags & ESM::Spell::F_Autocalc))
|
if (!(spell.mData.mFlags & ESM::Spell::F_Autocalc))
|
||||||
continue;
|
continue;
|
||||||
static const int iAutoSpellTimesCanCast = gmst.find("iAutoSpellTimesCanCast")->mValue.getInteger();
|
static const int iAutoSpellTimesCanCast = gmst.find("iAutoSpellTimesCanCast")->mValue.getInteger();
|
||||||
if (baseMagicka < iAutoSpellTimesCanCast * spell->mData.mCost)
|
if (baseMagicka < iAutoSpellTimesCanCast * spell.mData.mCost)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (race && race->mPowers.exists(spell->mId))
|
if (race && race->mPowers.exists(spell.mId))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!attrSkillCheck(spell, actorSkills, actorAttributes))
|
if (!attrSkillCheck(&spell, actorSkills, actorAttributes))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
int school;
|
int school;
|
||||||
float skillTerm;
|
float skillTerm;
|
||||||
calcWeakestSchool(spell, actorSkills, school, skillTerm);
|
calcWeakestSchool(&spell, actorSkills, school, skillTerm);
|
||||||
assert(school >= 0 && school < 6);
|
assert(school >= 0 && school < 6);
|
||||||
SchoolCaps& cap = schoolCaps[school];
|
SchoolCaps& cap = schoolCaps[school];
|
||||||
|
|
||||||
if (cap.mReachedLimit && spell->mData.mCost <= cap.mMinCost)
|
if (cap.mReachedLimit && spell.mData.mCost <= cap.mMinCost)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
static const float fAutoSpellChance = gmst.find("fAutoSpellChance")->mValue.getFloat();
|
static const float fAutoSpellChance = gmst.find("fAutoSpellChance")->mValue.getFloat();
|
||||||
if (calcAutoCastChance(spell, actorSkills, actorAttributes, school) < fAutoSpellChance)
|
if (calcAutoCastChance(&spell, actorSkills, actorAttributes, school) < fAutoSpellChance)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
selectedSpells.push_back(spell->mId);
|
selectedSpells.push_back(spell.mId);
|
||||||
|
|
||||||
if (cap.mReachedLimit)
|
if (cap.mReachedLimit)
|
||||||
{
|
{
|
||||||
|
@ -101,9 +99,9 @@ namespace MWMechanics
|
||||||
selectedSpells.erase(found);
|
selectedSpells.erase(found);
|
||||||
|
|
||||||
cap.mMinCost = std::numeric_limits<int>::max();
|
cap.mMinCost = std::numeric_limits<int>::max();
|
||||||
for (std::vector<std::string>::iterator weakIt = selectedSpells.begin(); weakIt != selectedSpells.end(); ++weakIt)
|
for (const std::string& testSpellName : selectedSpells)
|
||||||
{
|
{
|
||||||
const ESM::Spell* testSpell = spells.find(*weakIt);
|
const ESM::Spell* testSpell = spells.find(testSpellName);
|
||||||
|
|
||||||
//int testSchool;
|
//int testSchool;
|
||||||
//float dummySkillTerm;
|
//float dummySkillTerm;
|
||||||
|
@ -130,10 +128,10 @@ namespace MWMechanics
|
||||||
if (cap.mCount == cap.mLimit)
|
if (cap.mCount == cap.mLimit)
|
||||||
cap.mReachedLimit = true;
|
cap.mReachedLimit = true;
|
||||||
|
|
||||||
if (spell->mData.mCost < cap.mMinCost)
|
if (spell.mData.mCost < cap.mMinCost)
|
||||||
{
|
{
|
||||||
cap.mWeakestSpell = spell->mId;
|
cap.mWeakestSpell = spell.mId;
|
||||||
cap.mMinCost = spell->mData.mCost;
|
cap.mMinCost = spell.mData.mCost;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -154,32 +152,28 @@ namespace MWMechanics
|
||||||
|
|
||||||
std::vector<std::string> selectedSpells;
|
std::vector<std::string> selectedSpells;
|
||||||
|
|
||||||
|
const MWWorld::Store<ESM::Spell> &spells = esmStore.get<ESM::Spell>();
|
||||||
const MWWorld::Store<ESM::Spell> &spells =
|
for (const ESM::Spell& spell : spells)
|
||||||
esmStore.get<ESM::Spell>();
|
|
||||||
for (MWWorld::Store<ESM::Spell>::iterator iter = spells.begin(); iter != spells.end(); ++iter)
|
|
||||||
{
|
{
|
||||||
const ESM::Spell* spell = &*iter;
|
if (spell.mData.mType != ESM::Spell::ST_Spell)
|
||||||
|
|
||||||
if (spell->mData.mType != ESM::Spell::ST_Spell)
|
|
||||||
continue;
|
continue;
|
||||||
if (!(spell->mData.mFlags & ESM::Spell::F_PCStart))
|
if (!(spell.mData.mFlags & ESM::Spell::F_PCStart))
|
||||||
continue;
|
continue;
|
||||||
if (reachedLimit && spell->mData.mCost <= minCost)
|
if (reachedLimit && spell.mData.mCost <= minCost)
|
||||||
continue;
|
continue;
|
||||||
if (race && std::find(race->mPowers.mList.begin(), race->mPowers.mList.end(), spell->mId) != race->mPowers.mList.end())
|
if (race && std::find(race->mPowers.mList.begin(), race->mPowers.mList.end(), spell.mId) != race->mPowers.mList.end())
|
||||||
continue;
|
continue;
|
||||||
if (baseMagicka < spell->mData.mCost)
|
if (baseMagicka < spell.mData.mCost)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
static const float fAutoPCSpellChance = esmStore.get<ESM::GameSetting>().find("fAutoPCSpellChance")->mValue.getFloat();
|
static const float fAutoPCSpellChance = esmStore.get<ESM::GameSetting>().find("fAutoPCSpellChance")->mValue.getFloat();
|
||||||
if (calcAutoCastChance(spell, actorSkills, actorAttributes, -1) < fAutoPCSpellChance)
|
if (calcAutoCastChance(&spell, actorSkills, actorAttributes, -1) < fAutoPCSpellChance)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!attrSkillCheck(spell, actorSkills, actorAttributes))
|
if (!attrSkillCheck(&spell, actorSkills, actorAttributes))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
selectedSpells.push_back(spell->mId);
|
selectedSpells.push_back(spell.mId);
|
||||||
|
|
||||||
if (reachedLimit)
|
if (reachedLimit)
|
||||||
{
|
{
|
||||||
|
@ -188,9 +182,9 @@ namespace MWMechanics
|
||||||
selectedSpells.erase(it);
|
selectedSpells.erase(it);
|
||||||
|
|
||||||
minCost = std::numeric_limits<int>::max();
|
minCost = std::numeric_limits<int>::max();
|
||||||
for (std::vector<std::string>::iterator weakIt = selectedSpells.begin(); weakIt != selectedSpells.end(); ++weakIt)
|
for (const std::string& testSpellName : selectedSpells)
|
||||||
{
|
{
|
||||||
const ESM::Spell* testSpell = esmStore.get<ESM::Spell>().find(*weakIt);
|
const ESM::Spell* testSpell = esmStore.get<ESM::Spell>().find(testSpellName);
|
||||||
if (testSpell->mData.mCost < minCost)
|
if (testSpell->mData.mCost < minCost)
|
||||||
{
|
{
|
||||||
minCost = testSpell->mData.mCost;
|
minCost = testSpell->mData.mCost;
|
||||||
|
@ -200,9 +194,9 @@ namespace MWMechanics
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (spell->mData.mCost < minCost)
|
if (spell.mData.mCost < minCost)
|
||||||
{
|
{
|
||||||
weakestSpell = spell;
|
weakestSpell = &spell;
|
||||||
minCost = weakestSpell->mData.mCost;
|
minCost = weakestSpell->mData.mCost;
|
||||||
}
|
}
|
||||||
static const unsigned int iAutoPCSpellMax = esmStore.get<ESM::GameSetting>().find("iAutoPCSpellMax")->mValue.getInteger();
|
static const unsigned int iAutoPCSpellMax = esmStore.get<ESM::GameSetting>().find("iAutoPCSpellMax")->mValue.getInteger();
|
||||||
|
@ -216,23 +210,22 @@ namespace MWMechanics
|
||||||
|
|
||||||
bool attrSkillCheck (const ESM::Spell* spell, const int* actorSkills, const int* actorAttributes)
|
bool attrSkillCheck (const ESM::Spell* spell, const int* actorSkills, const int* actorAttributes)
|
||||||
{
|
{
|
||||||
const std::vector<ESM::ENAMstruct>& effects = spell->mEffects.mList;
|
for (const auto& spellEffect : spell->mEffects.mList)
|
||||||
for (std::vector<ESM::ENAMstruct>::const_iterator effectIt = effects.begin(); effectIt != effects.end(); ++effectIt)
|
|
||||||
{
|
{
|
||||||
const ESM::MagicEffect* magicEffect = MWBase::Environment::get().getWorld()->getStore().get<ESM::MagicEffect>().find(effectIt->mEffectID);
|
const ESM::MagicEffect* magicEffect = MWBase::Environment::get().getWorld()->getStore().get<ESM::MagicEffect>().find(spellEffect.mEffectID);
|
||||||
static const int iAutoSpellAttSkillMin = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find("iAutoSpellAttSkillMin")->mValue.getInteger();
|
static const int iAutoSpellAttSkillMin = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find("iAutoSpellAttSkillMin")->mValue.getInteger();
|
||||||
|
|
||||||
if ((magicEffect->mData.mFlags & ESM::MagicEffect::TargetSkill))
|
if ((magicEffect->mData.mFlags & ESM::MagicEffect::TargetSkill))
|
||||||
{
|
{
|
||||||
assert (effectIt->mSkill >= 0 && effectIt->mSkill < ESM::Skill::Length);
|
assert (spellEffect.mSkill >= 0 && spellEffect.mSkill < ESM::Skill::Length);
|
||||||
if (actorSkills[effectIt->mSkill] < iAutoSpellAttSkillMin)
|
if (actorSkills[spellEffect.mSkill] < iAutoSpellAttSkillMin)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((magicEffect->mData.mFlags & ESM::MagicEffect::TargetAttribute))
|
if ((magicEffect->mData.mFlags & ESM::MagicEffect::TargetAttribute))
|
||||||
{
|
{
|
||||||
assert (effectIt->mAttribute >= 0 && effectIt->mAttribute < ESM::Attribute::Length);
|
assert (spellEffect.mAttribute >= 0 && spellEffect.mAttribute < ESM::Attribute::Length);
|
||||||
if (actorAttributes[effectIt->mAttribute] < iAutoSpellAttSkillMin)
|
if (actorAttributes[spellEffect.mAttribute] < iAutoSpellAttSkillMin)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -244,11 +237,8 @@ namespace MWMechanics
|
||||||
{
|
{
|
||||||
// Morrowind for some reason uses a formula slightly different from magicka cost calculation
|
// Morrowind for some reason uses a formula slightly different from magicka cost calculation
|
||||||
float minChance = std::numeric_limits<float>::max();
|
float minChance = std::numeric_limits<float>::max();
|
||||||
|
for (const ESM::ENAMstruct& effect : spell->mEffects.mList)
|
||||||
const ESM::EffectList& effects = spell->mEffects;
|
|
||||||
for (std::vector<ESM::ENAMstruct>::const_iterator it = effects.mList.begin(); it != effects.mList.end(); ++it)
|
|
||||||
{
|
{
|
||||||
const ESM::ENAMstruct& effect = *it;
|
|
||||||
const ESM::MagicEffect* magicEffect = MWBase::Environment::get().getWorld()->getStore().get<ESM::MagicEffect>().find(effect.mEffectID);
|
const ESM::MagicEffect* magicEffect = MWBase::Environment::get().getWorld()->getStore().get<ESM::MagicEffect>().find(effect.mEffectID);
|
||||||
|
|
||||||
int minMagn = 1;
|
int minMagn = 1;
|
||||||
|
|
|
@ -2653,11 +2653,11 @@ void CharacterController::updateContinuousVfx()
|
||||||
std::vector<int> effects;
|
std::vector<int> effects;
|
||||||
mAnimation->getLoopingEffects(effects);
|
mAnimation->getLoopingEffects(effects);
|
||||||
|
|
||||||
for (std::vector<int>::iterator it = effects.begin(); it != effects.end(); ++it)
|
for (int effectId : effects)
|
||||||
{
|
{
|
||||||
if (mPtr.getClass().getCreatureStats(mPtr).isDeathAnimationFinished()
|
if (mPtr.getClass().getCreatureStats(mPtr).isDeathAnimationFinished()
|
||||||
|| mPtr.getClass().getCreatureStats(mPtr).getMagicEffects().get(MWMechanics::EffectKey(*it)).getMagnitude() <= 0)
|
|| mPtr.getClass().getCreatureStats(mPtr).getMagicEffects().get(MWMechanics::EffectKey(effectId)).getMagnitude() <= 0)
|
||||||
mAnimation->removeEffect(*it);
|
mAnimation->removeEffect(effectId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,10 +31,10 @@ namespace MWMechanics
|
||||||
|
|
||||||
std::vector<std::string> candidates;
|
std::vector<std::string> candidates;
|
||||||
int highestLevel = 0;
|
int highestLevel = 0;
|
||||||
for (std::vector<ESM::LevelledListBase::LevelItem>::const_iterator it = items.begin(); it != items.end(); ++it)
|
for (const auto& levelledItem : items)
|
||||||
{
|
{
|
||||||
if (it->mLevel > highestLevel && it->mLevel <= playerLevel)
|
if (levelledItem.mLevel > highestLevel && levelledItem.mLevel <= playerLevel)
|
||||||
highestLevel = it->mLevel;
|
highestLevel = levelledItem.mLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
// For levelled creatures, the flags are swapped. This file format just makes so much sense.
|
// For levelled creatures, the flags are swapped. This file format just makes so much sense.
|
||||||
|
@ -43,14 +43,14 @@ namespace MWMechanics
|
||||||
allLevels = levItem->mFlags & ESM::CreatureLevList::AllLevels;
|
allLevels = levItem->mFlags & ESM::CreatureLevList::AllLevels;
|
||||||
|
|
||||||
std::pair<int, std::string> highest = std::make_pair(-1, "");
|
std::pair<int, std::string> highest = std::make_pair(-1, "");
|
||||||
for (std::vector<ESM::LevelledListBase::LevelItem>::const_iterator it = items.begin(); it != items.end(); ++it)
|
for (const auto& levelledItem : items)
|
||||||
{
|
{
|
||||||
if (playerLevel >= it->mLevel
|
if (playerLevel >= levelledItem.mLevel
|
||||||
&& (allLevels || it->mLevel == highestLevel))
|
&& (allLevels || levelledItem.mLevel == highestLevel))
|
||||||
{
|
{
|
||||||
candidates.push_back(it->mId);
|
candidates.push_back(levelledItem.mId);
|
||||||
if (it->mLevel >= highest.first)
|
if (levelledItem.mLevel >= highest.first)
|
||||||
highest = std::make_pair(it->mLevel, it->mId);
|
highest = std::make_pair(levelledItem.mLevel, levelledItem.mId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (candidates.empty())
|
if (candidates.empty())
|
||||||
|
|
|
@ -19,11 +19,10 @@ Objects::Objects()
|
||||||
|
|
||||||
Objects::~Objects()
|
Objects::~Objects()
|
||||||
{
|
{
|
||||||
PtrControllerMap::iterator it(mObjects.begin());
|
for(auto& object : mObjects)
|
||||||
for (; it != mObjects.end();++it)
|
|
||||||
{
|
{
|
||||||
delete it->second;
|
delete object.second;
|
||||||
it->second = nullptr;
|
object.second = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,8 +76,8 @@ void Objects::update(float duration, bool paused)
|
||||||
{
|
{
|
||||||
if(!paused)
|
if(!paused)
|
||||||
{
|
{
|
||||||
for(PtrControllerMap::iterator iter(mObjects.begin());iter != mObjects.end();++iter)
|
for(auto& object : mObjects)
|
||||||
iter->second->update(duration);
|
object.second->update(duration);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -87,15 +86,15 @@ void Objects::update(float duration, bool paused)
|
||||||
if(mode != MWGui::GM_Container)
|
if(mode != MWGui::GM_Container)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for(PtrControllerMap::iterator iter(mObjects.begin());iter != mObjects.end();++iter)
|
for(auto& object : mObjects)
|
||||||
{
|
{
|
||||||
if (iter->first.getTypeName() != typeid(ESM::Container).name())
|
if (object.first.getTypeName() != typeid(ESM::Container).name())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (iter->second->isAnimPlaying("containeropen"))
|
if (object.second->isAnimPlaying("containeropen"))
|
||||||
{
|
{
|
||||||
iter->second->update(duration);
|
object.second->update(duration);
|
||||||
MWBase::Environment::get().getWorld()->updateAnimatedCollisionShape(iter->first);
|
MWBase::Environment::get().getWorld()->updateAnimatedCollisionShape(object.first);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,17 +36,13 @@ namespace MWMechanics
|
||||||
|
|
||||||
// Check all the doors in this cell
|
// Check all the doors in this cell
|
||||||
const MWWorld::CellRefList<ESM::Door>& doors = cell->getReadOnlyDoors();
|
const MWWorld::CellRefList<ESM::Door>& doors = cell->getReadOnlyDoors();
|
||||||
const MWWorld::CellRefList<ESM::Door>::List& refList = doors.mList;
|
|
||||||
MWWorld::CellRefList<ESM::Door>::List::const_iterator it = refList.begin();
|
|
||||||
osg::Vec3f pos(actor.getRefData().getPosition().asVec3());
|
osg::Vec3f pos(actor.getRefData().getPosition().asVec3());
|
||||||
pos.z() = 0;
|
pos.z() = 0;
|
||||||
|
|
||||||
osg::Vec3f actorDir = (actor.getRefData().getBaseNode()->getAttitude() * osg::Vec3f(0,1,0));
|
osg::Vec3f actorDir = (actor.getRefData().getBaseNode()->getAttitude() * osg::Vec3f(0,1,0));
|
||||||
|
|
||||||
for (; it != refList.end(); ++it)
|
for (const auto& ref : doors.mList)
|
||||||
{
|
{
|
||||||
const MWWorld::LiveCellRef<ESM::Door>& ref = *it;
|
|
||||||
|
|
||||||
osg::Vec3f doorPos(ref.mData.getPosition().asVec3());
|
osg::Vec3f doorPos(ref.mData.getPosition().asVec3());
|
||||||
|
|
||||||
// FIXME: cast
|
// FIXME: cast
|
||||||
|
|
Loading…
Reference in a new issue