1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-21 06:23:53 +00:00

Merge pull request #2221 from akortunov/iter

Use C++11-style loops in the game world instead of iterators
This commit is contained in:
Bret Curtis 2019-03-07 16:53:18 +01:00 committed by GitHub
commit df6112aa35
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 133 additions and 139 deletions

View file

@ -707,11 +707,11 @@ namespace MWPhysics
if (!targets.empty())
{
for (std::vector<MWWorld::Ptr>::const_iterator it = targets.begin(); it != targets.end(); ++it)
for (MWWorld::Ptr& target : targets)
{
const Actor* physactor2 = getActor(*it);
if (physactor2)
targetCollisionObjects.push_back(physactor2->getCollisionObject());
const Actor* targetActor = getActor(target);
if (targetActor)
targetCollisionObjects.push_back(targetActor->getCollisionObject());
}
}
@ -811,9 +811,9 @@ namespace MWPhysics
if (!targets.empty())
{
for (std::vector<MWWorld::Ptr>::const_iterator it = targets.begin(); it != targets.end(); ++it)
for (MWWorld::Ptr& target : targets)
{
const Actor* actor = getActor(*it);
const Actor* actor = getActor(target);
if (actor)
targetCollisionObjects.push_back(actor->getCollisionObject());
}
@ -1320,8 +1320,8 @@ namespace MWPhysics
void PhysicsSystem::stepSimulation(float dt)
{
for (std::set<Object*>::iterator it = mAnimatedObjects.begin(); it != mAnimatedObjects.end(); ++it)
(*it)->animateCollisionShapes(mCollisionWorld);
for (Object* animatedObject : mAnimatedObjects)
animatedObject->animateCollisionShapes(mCollisionWorld);
#ifndef BT_NO_PROFILE
CProfileManager::Reset();

View file

@ -79,10 +79,9 @@ namespace
void remove()
{
for (std::vector<osg::ref_ptr<osg::Node> >::iterator it = mToRemove.begin(); it != mToRemove.end(); ++it)
for (osg::Node* node : mToRemove)
{
// FIXME: a Drawable might have more than one parent
osg::Node* node = *it;
if (node->getNumParents())
node->getParent(0)->removeChild(node);
}

View file

@ -234,10 +234,10 @@ namespace MWRender
GlobalMap::~GlobalMap()
{
for (CameraVector::iterator it = mCamerasPendingRemoval.begin(); it != mCamerasPendingRemoval.end(); ++it)
removeCamera(*it);
for (CameraVector::iterator it = mActiveCameras.begin(); it != mActiveCameras.end(); ++it)
removeCamera(*it);
for (auto& camera : mCamerasPendingRemoval)
removeCamera(camera);
for (auto& camera : mActiveCameras)
removeCamera(camera);
if (mWorkItem)
mWorkItem->waitTillDone();
@ -581,8 +581,8 @@ namespace MWRender
void GlobalMap::cleanupCameras()
{
for (CameraVector::iterator it = mCamerasPendingRemoval.begin(); it != mCamerasPendingRemoval.end(); ++it)
removeCamera(*it);
for (auto& camera : mCamerasPendingRemoval)
removeCamera(camera);
mCamerasPendingRemoval.clear();

View file

@ -92,10 +92,10 @@ LocalMap::LocalMap(osg::Group* root)
LocalMap::~LocalMap()
{
for (CameraVector::iterator it = mActiveCameras.begin(); it != mActiveCameras.end(); ++it)
removeCamera(*it);
for (CameraVector::iterator it = mCamerasPendingRemoval.begin(); it != mCamerasPendingRemoval.end(); ++it)
removeCamera(*it);
for (auto& camera : mActiveCameras)
removeCamera(camera);
for (auto& camera : mCamerasPendingRemoval)
removeCamera(camera);
}
const osg::Vec2f LocalMap::rotatePoint(const osg::Vec2f& point, const osg::Vec2f& center, const float angle)
@ -259,16 +259,14 @@ bool needUpdate(std::set<std::pair<int, int> >& renderedGrid, std::set<std::pair
void LocalMap::requestMap(std::set<const MWWorld::CellStore*> cells)
{
std::set<std::pair<int, int> > grid;
for (std::set<const MWWorld::CellStore*>::iterator it = cells.begin(); it != cells.end(); ++it)
for (const MWWorld::CellStore* cell : cells)
{
const MWWorld::CellStore* cell = *it;
if (cell->isExterior())
grid.insert(std::make_pair(cell->getCell()->getGridX(), cell->getCell()->getGridY()));
}
for (std::set<const MWWorld::CellStore*>::iterator it = cells.begin(); it != cells.end(); ++it)
for (const MWWorld::CellStore* cell : cells)
{
const MWWorld::CellStore* cell = *it;
if (cell->isExterior())
{
int cellX = cell->getCell()->getGridX();
@ -341,8 +339,8 @@ void LocalMap::cleanupCameras()
if (mCamerasPendingRemoval.empty())
return;
for (CameraVector::iterator it = mCamerasPendingRemoval.begin(); it != mCamerasPendingRemoval.end(); ++it)
removeCamera(*it);
for (auto& camera : mCamerasPendingRemoval)
removeCamera(camera);
mCamerasPendingRemoval.clear();
}

View file

@ -76,17 +76,17 @@ void Pathgrid::togglePathgrid()
mPathGridRoot->setNodeMask(Mask_Debug);
mRootNode->addChild(mPathGridRoot);
for(CellList::iterator it = mActiveCells.begin(); it != mActiveCells.end(); ++it)
for(const MWWorld::CellStore* cell : mActiveCells)
{
enableCellPathgrid(*it);
enableCellPathgrid(cell);
}
}
else
{
// remove path grid meshes from already loaded cells
for(CellList::iterator it = mActiveCells.begin(); it != mActiveCells.end(); ++it)
for(const MWWorld::CellStore* cell : mActiveCells)
{
disableCellPathgrid(*it);
disableCellPathgrid(cell);
}
if (mPathGridRoot)

View file

@ -118,21 +118,22 @@ RippleSimulation::~RippleSimulation()
void RippleSimulation::update(float dt)
{
const MWBase::World* world = MWBase::Environment::get().getWorld();
for (std::vector<Emitter>::iterator it=mEmitters.begin(); it !=mEmitters.end(); ++it)
for (Emitter& emitter : mEmitters)
{
if (it->mPtr == MWBase::Environment::get().getWorld ()->getPlayerPtr())
MWWorld::ConstPtr& ptr = emitter.mPtr;
if (ptr == MWBase::Environment::get().getWorld ()->getPlayerPtr())
{
// fetch a new ptr (to handle cell change etc)
// for non-player actors this is done in updateObjectCell
it->mPtr = MWBase::Environment::get().getWorld ()->getPlayerPtr();
ptr = MWBase::Environment::get().getWorld ()->getPlayerPtr();
}
osg::Vec3f currentPos (it->mPtr.getRefData().getPosition().asVec3());
osg::Vec3f currentPos (ptr.getRefData().getPosition().asVec3());
bool shouldEmit = ( world->isUnderwater (it->mPtr.getCell(), it->mPtr.getRefData().getPosition().asVec3()) && !world->isSubmerged(it->mPtr) ) || world->isWalkingOnWater(it->mPtr);
if ( shouldEmit && (currentPos - it->mLastEmitPosition).length() > 10 )
bool shouldEmit = (world->isUnderwater(ptr.getCell(), currentPos) && !world->isSubmerged(ptr)) || world->isWalkingOnWater(ptr);
if (shouldEmit && (currentPos - emitter.mLastEmitPosition).length() > 10)
{
it->mLastEmitPosition = currentPos;
emitter.mLastEmitPosition = currentPos;
currentPos.z() = mParticleNode->getPosition().z();

View file

@ -1813,8 +1813,8 @@ void SkyManager::setWeather(const WeatherResult& weather)
if (mRainFader)
mRainFader->setAlpha(weather.mEffectFade * 0.6); // * Rain_Threshold?
for (std::vector<osg::ref_ptr<AlphaFader> >::const_iterator it = mParticleFaders.begin(); it != mParticleFaders.end(); ++it)
(*it)->setAlpha(weather.mEffectFade);
for (AlphaFader* fader : mParticleFaders)
fader->setAlpha(weather.mEffectFade);
}
void SkyManager::sunEnable()

View file

@ -72,9 +72,9 @@ namespace MWWorld
const std::vector<std::string>& objectIds = cell->getPreloadedIds();
// could possibly build the model list in the worker thread if we manage to make the Store thread safe
for (std::vector<std::string>::const_iterator it = objectIds.begin(); it != objectIds.end(); ++it)
for (const std::string& id : objectIds)
{
MWWorld::ManualRef ref(MWBase::Environment::get().getWorld()->getStore(), *it);
MWWorld::ManualRef ref(MWBase::Environment::get().getWorld()->getStore(), id);
std::string model = ref.getPtr().getClass().getModel(ref.getPtr());
if (!model.empty())
mMeshes.push_back(model);
@ -102,14 +102,13 @@ namespace MWWorld
}
}
for (MeshList::const_iterator it = mMeshes.begin(); it != mMeshes.end(); ++it)
for (std::string& mesh: mMeshes)
{
if (mAbort)
break;
try
{
std::string mesh = *it;
mesh = Misc::ResourceHelpers::correctActorModelPath(mesh, mSceneManager->getVFS());
if (mPreloadInstances)

View file

@ -37,10 +37,9 @@ namespace MWWorld
const MWWorld::Store<ESM::Global>& globals = store.get<ESM::Global>();
for (MWWorld::Store<ESM::Global>::iterator iter = globals.begin(); iter!=globals.end();
++iter)
for (const ESM::Global& esmGlobal : globals)
{
mVariables.insert (std::make_pair (Misc::StringUtils::lowerCase (iter->mId), *iter));
mVariables.insert (std::make_pair (Misc::StringUtils::lowerCase (esmGlobal.mId), esmGlobal));
}
}

View file

@ -462,14 +462,13 @@ void MWWorld::InventoryStore::autoEquipArmor (const MWWorld::Ptr& actor, TSlots&
iter->getClass().getEquipmentSlots (*iter);
// checking if current item pointed by iter can be equipped
for (std::vector<int>::const_iterator iter2 (itemsSlots.first.begin());
iter2!=itemsSlots.first.end(); ++iter2)
for (int slot : itemsSlots.first)
{
// if true then it means slot is equipped already
// check if slot may require swapping if current item is more valuable
if (slots_.at (*iter2)!=end())
if (slots_.at (slot)!=end())
{
Ptr old = *slots_.at (*iter2);
Ptr old = *slots_.at (slot);
if (iter.getType() == ContainerStore::Type_Armor)
{
@ -490,7 +489,7 @@ void MWWorld::InventoryStore::autoEquipArmor (const MWWorld::Ptr& actor, TSlots&
else if (iter.getType() == ContainerStore::Type_Clothing)
{
// if left ring is equipped
if (*iter2 == Slot_LeftRing)
if (slot == Slot_LeftRing)
{
// if there is a place for right ring dont swap it
if (slots_.at(Slot_RightRing) == end())
@ -530,7 +529,7 @@ void MWWorld::InventoryStore::autoEquipArmor (const MWWorld::Ptr& actor, TSlots&
}
// if we are here it means item can be equipped or swapped
slots_[*iter2] = iter;
slots_[slot] = iter;
break;
}
}
@ -645,10 +644,9 @@ void MWWorld::InventoryStore::updateMagicEffects(const Ptr& actor)
// Try resisting each effect
int i=0;
for (std::vector<ESM::ENAMstruct>::const_iterator effectIt (enchantment.mEffects.mList.begin());
effectIt!=enchantment.mEffects.mList.end(); ++effectIt)
for (const ESM::ENAMstruct& effect : enchantment.mEffects.mList)
{
params[i].mMultiplier = MWMechanics::getEffectMultiplier(effectIt->mEffectID, actor, actor);
params[i].mMultiplier = MWMechanics::getEffectMultiplier(effect.mEffectID, actor, actor);
++i;
}
@ -662,18 +660,20 @@ void MWWorld::InventoryStore::updateMagicEffects(const Ptr& actor)
params = mPermanentMagicEffectMagnitudes[(**iter).getCellRef().getRefId()];
int i=0;
for (std::vector<ESM::ENAMstruct>::const_iterator effectIt (enchantment.mEffects.mList.begin());
effectIt!=enchantment.mEffects.mList.end(); ++effectIt, ++i)
for (const ESM::ENAMstruct& effect : enchantment.mEffects.mList)
{
const ESM::MagicEffect *magicEffect =
MWBase::Environment::get().getWorld()->getStore().get<ESM::MagicEffect>().find (
effectIt->mEffectID);
effect.mEffectID);
// Fully resisted or can't be applied to target?
if (params[i].mMultiplier == 0 || !MWMechanics::checkEffectTarget(effectIt->mEffectID, actor, actor, actor == MWMechanics::getPlayer()))
if (params[i].mMultiplier == 0 || !MWMechanics::checkEffectTarget(effect.mEffectID, actor, actor, actor == MWMechanics::getPlayer()))
{
i++;
continue;
}
float magnitude = effectIt->mMagnMin + (effectIt->mMagnMax - effectIt->mMagnMin) * params[i].mRandom;
float magnitude = effect.mMagnMin + (effect.mMagnMax - effect.mMagnMin) * params[i].mRandom;
magnitude *= params[i].mMultiplier;
if (!existed)
@ -685,7 +685,9 @@ void MWWorld::InventoryStore::updateMagicEffects(const Ptr& actor)
}
if (magnitude)
mMagicEffects.add (*effectIt, magnitude);
mMagicEffects.add (effect, magnitude);
i++;
}
}
}
@ -949,17 +951,17 @@ void MWWorld::InventoryStore::visitEffectSources(MWMechanics::EffectSourceVisito
continue;
int i=0;
for (std::vector<ESM::ENAMstruct>::const_iterator effectIt (enchantment.mEffects.mList.begin());
effectIt!=enchantment.mEffects.mList.end(); ++effectIt, ++i)
for (const ESM::ENAMstruct& effect : enchantment.mEffects.mList)
{
i++;
// Don't get spell icon display information for enchantments that weren't actually applied
if (mMagicEffects.get(MWMechanics::EffectKey(*effectIt)).getMagnitude() == 0)
if (mMagicEffects.get(MWMechanics::EffectKey(effect)).getMagnitude() == 0)
continue;
const EffectParams& params = mPermanentMagicEffectMagnitudes[(**iter).getCellRef().getRefId()][i];
float magnitude = effectIt->mMagnMin + (effectIt->mMagnMax - effectIt->mMagnMin) * params.mRandom;
const EffectParams& params = mPermanentMagicEffectMagnitudes[(**iter).getCellRef().getRefId()][i-1];
float magnitude = effect.mMagnMin + (effect.mMagnMax - effect.mMagnMin) * params.mRandom;
magnitude *= params.mMultiplier;
if (magnitude > 0)
visitor.visit(MWMechanics::EffectKey(*effectIt), (**iter).getClass().getName(**iter), (**iter).getCellRef().getRefId(), -1, magnitude);
visitor.visit(MWMechanics::EffectKey(effect), (**iter).getClass().getName(**iter), (**iter).getCellRef().getRefId(), -1, magnitude);
}
}
}

View file

@ -230,9 +230,8 @@ namespace
template <class AddObject>
void InsertVisitor::insert(AddObject&& addObject)
{
for (std::vector<MWWorld::Ptr>::iterator it = mToInsert.begin(); it != mToInsert.end(); ++it)
for (MWWorld::Ptr& ptr : mToInsert)
{
MWWorld::Ptr ptr = *it;
if (mRescale)
{
if (ptr.getCellRef().getScale()<0.5)
@ -905,24 +904,22 @@ namespace MWWorld
void Scene::preloadTeleportDoorDestinations(const osg::Vec3f& playerPos, const osg::Vec3f& predictedPos, std::vector<osg::Vec3f>& exteriorPositions)
{
std::vector<MWWorld::ConstPtr> teleportDoors;
for (CellStoreCollection::const_iterator iter (mActiveCells.begin());
iter!=mActiveCells.end(); ++iter)
for (const MWWorld::CellStore* cellStore : mActiveCells)
{
const MWWorld::CellStore* cellStore = *iter;
typedef MWWorld::CellRefList<ESM::Door>::List DoorList;
const DoorList &doors = cellStore->getReadOnlyDoors().mList;
for (DoorList::const_iterator doorIt = doors.begin(); doorIt != doors.end(); ++doorIt)
for (auto& door : doors)
{
if (!doorIt->mRef.getTeleport()) {
if (!door.mRef.getTeleport())
{
continue;
}
teleportDoors.push_back(MWWorld::ConstPtr(&*doorIt, cellStore));
teleportDoors.push_back(MWWorld::ConstPtr(&door, cellStore));
}
}
for (std::vector<MWWorld::ConstPtr>::iterator it = teleportDoors.begin(); it != teleportDoors.end(); ++it)
for (const MWWorld::ConstPtr& door : teleportDoors)
{
const MWWorld::ConstPtr& door = *it;
float sqrDistToPlayer = (playerPos - door.getRefData().getPosition().asVec3()).length2();
sqrDistToPlayer = std::min(sqrDistToPlayer, (predictedPos - door.getRefData().getPosition().asVec3()).length2());
@ -1046,20 +1043,19 @@ namespace MWWorld
const MWWorld::ConstPtr player = MWBase::Environment::get().getWorld()->getPlayerPtr();
ListFastTravelDestinationsVisitor listVisitor(mPreloadDistance, player.getRefData().getPosition().asVec3());
for (CellStoreCollection::const_iterator iter (mActiveCells.begin()); iter!=mActiveCells.end(); ++iter)
for (MWWorld::CellStore* cellStore : mActiveCells)
{
MWWorld::CellStore* cellStore = *iter;
cellStore->forEachType<ESM::NPC>(listVisitor);
cellStore->forEachType<ESM::Creature>(listVisitor);
}
for (std::vector<ESM::Transport::Dest>::const_iterator it = listVisitor.mList.begin(); it != listVisitor.mList.end(); ++it)
for (ESM::Transport::Dest& dest : listVisitor.mList)
{
if (!it->mCellName.empty())
preloadCell(MWBase::Environment::get().getWorld()->getInterior(it->mCellName));
if (!dest.mCellName.empty())
preloadCell(MWBase::Environment::get().getWorld()->getInterior(dest.mCellName));
else
{
osg::Vec3f pos = it->mPos.asVec3();
osg::Vec3f pos = dest.mPos.asVec3();
int x,y;
MWBase::Environment::get().getWorld()->positionToIndex( pos.x(), pos.y(), x, y);
preloadCell(MWBase::Environment::get().getWorld()->getExterior(x,y), true);

View file

@ -420,10 +420,9 @@ namespace MWWorld
//=========================================================================
Store<ESM::Land>::~Store()
{
for (std::vector<ESM::Land *>::const_iterator it =
mStatic.begin(); it != mStatic.end(); ++it)
for (const ESM::Land* staticLand : mStatic)
{
delete *it;
delete staticLand;
}
}
@ -737,15 +736,16 @@ namespace MWWorld
}
const ESM::Cell *Store<ESM::Cell>::searchExtByName(const std::string &id) const
{
ESM::Cell *cell = 0;
std::vector<ESM::Cell *>::const_iterator it = mSharedExt.begin();
for (; it != mSharedExt.end(); ++it) {
if (Misc::StringUtils::ciEqual((*it)->mName, id)) {
if ( cell == 0 ||
( (*it)->mData.mX > cell->mData.mX ) ||
( (*it)->mData.mX == cell->mData.mX && (*it)->mData.mY > cell->mData.mY ) )
const ESM::Cell *cell = nullptr;
for (const ESM::Cell *sharedCell : mSharedExt)
{
if (Misc::StringUtils::ciEqual(sharedCell->mName, id))
{
if (cell == 0 ||
(sharedCell->mData.mX > cell->mData.mX) ||
(sharedCell->mData.mX == cell->mData.mX && sharedCell->mData.mY > cell->mData.mY))
{
cell = *it;
cell = sharedCell;
}
}
}
@ -753,15 +753,16 @@ namespace MWWorld
}
const ESM::Cell *Store<ESM::Cell>::searchExtByRegion(const std::string &id) const
{
ESM::Cell *cell = 0;
std::vector<ESM::Cell *>::const_iterator it = mSharedExt.begin();
for (; it != mSharedExt.end(); ++it) {
if (Misc::StringUtils::ciEqual((*it)->mRegion, id)) {
if ( cell == 0 ||
( (*it)->mData.mX > cell->mData.mX ) ||
( (*it)->mData.mX == cell->mData.mX && (*it)->mData.mY > cell->mData.mY ) )
const ESM::Cell *cell = nullptr;
for (const ESM::Cell *sharedCell : mSharedExt)
{
if (Misc::StringUtils::ciEqual(sharedCell->mRegion, id))
{
if (cell == nullptr ||
(sharedCell->mData.mX > cell->mData.mX) ||
(sharedCell->mData.mX == cell->mData.mX && sharedCell->mData.mY > cell->mData.mY))
{
cell = *it;
cell = sharedCell;
}
}
}
@ -775,9 +776,9 @@ namespace MWWorld
{
list.reserve(list.size() + mSharedInt.size());
std::vector<ESM::Cell *>::const_iterator it = mSharedInt.begin();
for (; it != mSharedInt.end(); ++it) {
list.push_back((*it)->mName);
for (const ESM::Cell *sharedCell : mSharedInt)
{
list.push_back(sharedCell->mName);
}
}
ESM::Cell *Store<ESM::Cell>::insert(const ESM::Cell &cell)

View file

@ -298,10 +298,11 @@ void RegionWeather::setChances(const std::vector<char>& chances)
mChances.reserve(chances.size());
}
std::vector<char>::const_iterator it = chances.begin();
for(size_t i = 0; it != chances.end(); ++it, ++i)
int i = 0;
for(char chance : chances)
{
mChances[i] = *it;
mChances[i] = chance;
i++;
}
// Regional weather no longer supports the current type, select a new weather pattern.
@ -936,11 +937,10 @@ inline void WeatherManager::addWeather(const std::string& name,
inline void WeatherManager::importRegions()
{
Store<ESM::Region>::iterator it = mStore.get<ESM::Region>().begin();
for(; it != mStore.get<ESM::Region>().end(); ++it)
for(const ESM::Region& region : mStore.get<ESM::Region>())
{
std::string regionID = Misc::StringUtils::lowerCase(it->mId);
mRegions.insert(std::make_pair(regionID, RegionWeather(*it)));
std::string regionID = Misc::StringUtils::lowerCase(region.mId);
mRegions.insert(std::make_pair(regionID, RegionWeather(region)));
}
}

View file

@ -1649,13 +1649,13 @@ namespace MWWorld
/// \todo should use convexSweepTest here
std::vector<MWWorld::Ptr> collisions = mPhysics->getCollisions(it->first, MWPhysics::CollisionType_Door, MWPhysics::CollisionType_Actor);
for (std::vector<MWWorld::Ptr>::iterator cit = collisions.begin(); cit != collisions.end(); ++cit)
for (MWWorld::Ptr& ptr : collisions)
{
MWWorld::Ptr ptr = *cit;
if (ptr.getClass().isActor())
{
// Collided with actor, ask actor to try to avoid door
if(ptr != getPlayerPtr() ) {
if(ptr != getPlayerPtr() )
{
MWMechanics::AiSequence& seq = ptr.getClass().getCreatureStats(ptr).getAiSequence();
if(seq.getTypeId() != MWMechanics::AiPackage::TypeIdAvoidDoor) //Only add it once
seq.stack(MWMechanics::AiAvoidDoor(it->first),ptr);
@ -3606,18 +3606,17 @@ namespace MWWorld
const std::string& id, const std::string& sourceName, const bool fromProjectile)
{
std::map<MWWorld::Ptr, std::vector<ESM::ENAMstruct> > toApply;
for (std::vector<ESM::ENAMstruct>::const_iterator effectIt = effects.mList.begin();
effectIt != effects.mList.end(); ++effectIt)
for (const ESM::ENAMstruct& effectInfo : effects.mList)
{
const ESM::MagicEffect* effect = mStore.get<ESM::MagicEffect>().find(effectIt->mEffectID);
const ESM::MagicEffect* effect = mStore.get<ESM::MagicEffect>().find(effectInfo.mEffectID);
if (effectIt->mRange != rangeType || (effectIt->mArea <= 0 && !ignore.isEmpty() && ignore.getClass().isActor()))
if (effectInfo.mRange != rangeType || (effectInfo.mArea <= 0 && !ignore.isEmpty() && ignore.getClass().isActor()))
continue; // Not right range type, or not area effect and hit an actor
if (fromProjectile && effectIt->mArea <= 0)
if (fromProjectile && effectInfo.mArea <= 0)
continue; // Don't play explosion for projectiles with 0-area effects
if (!fromProjectile && effectIt->mRange == ESM::RT_Touch && (!ignore.isEmpty()) && (!ignore.getClass().isActor() && !ignore.getClass().canBeActivated(ignore)))
if (!fromProjectile && effectInfo.mRange == ESM::RT_Touch && (!ignore.isEmpty()) && (!ignore.getClass().isActor() && !ignore.getClass().canBeActivated(ignore)))
continue; // Don't play explosion for touch spells on non-activatable objects except when spell is from the projectile enchantment
// Spawn the explosion orb effect
@ -3629,14 +3628,14 @@ namespace MWWorld
std::string texture = effect->mParticle;
if (effectIt->mArea <= 0)
if (effectInfo.mArea <= 0)
{
if (effectIt->mRange == ESM::RT_Target)
if (effectInfo.mRange == ESM::RT_Target)
mRendering->spawnEffect("meshes\\" + areaStatic->mModel, texture, origin, 1.0f);
continue;
}
else
mRendering->spawnEffect("meshes\\" + areaStatic->mModel, texture, origin, static_cast<float>(effectIt->mArea * 2));
mRendering->spawnEffect("meshes\\" + areaStatic->mModel, texture, origin, static_cast<float>(effectInfo.mArea * 2));
// Play explosion sound (make sure to use NoTrack, since we will delete the projectile now)
static const std::string schools[] = {
@ -3652,40 +3651,40 @@ namespace MWWorld
// Get the actors in range of the effect
std::vector<MWWorld::Ptr> objects;
MWBase::Environment::get().getMechanicsManager()->getObjectsInRange(
origin, feetToGameUnits(static_cast<float>(effectIt->mArea)), objects);
origin, feetToGameUnits(static_cast<float>(effectInfo.mArea)), objects);
for (const Ptr& affected : objects)
{
// Ignore actors without collisions here, otherwise it will be possible to hit actors outside processing range.
if (affected.getClass().isActor() && !isActorCollisionEnabled(affected))
continue;
toApply[affected].push_back(*effectIt);
toApply[affected].push_back(effectInfo);
}
}
// Now apply the appropriate effects to each actor in range
for (std::map<MWWorld::Ptr, std::vector<ESM::ENAMstruct> >::iterator apply = toApply.begin(); apply != toApply.end(); ++apply)
for (auto& applyPair : toApply)
{
MWWorld::Ptr source = caster;
// Vanilla-compatible behaviour of never applying the spell to the caster
// (could be changed by mods later)
if (apply->first == caster)
if (applyPair.first == caster)
continue;
if (apply->first == ignore)
if (applyPair.first == ignore)
continue;
if (source.isEmpty())
source = apply->first;
source = applyPair.first;
MWMechanics::CastSpell cast(source, apply->first);
MWMechanics::CastSpell cast(source, applyPair.first);
cast.mHitPosition = origin;
cast.mId = id;
cast.mSourceName = sourceName;
cast.mStack = false;
ESM::EffectList effectsToApply;
effectsToApply.mList = apply->second;
cast.inflict(apply->first, caster, effectsToApply, rangeType, false, true);
effectsToApply.mList = applyPair.second;
cast.inflict(applyPair.first, caster, effectsToApply, rangeType, false, true);
}
}
@ -3769,22 +3768,22 @@ namespace MWWorld
void World::preloadEffects(const ESM::EffectList *effectList)
{
for (std::vector<ESM::ENAMstruct>::const_iterator it = effectList->mList.begin(); it != effectList->mList.end(); ++it)
for (const ESM::ENAMstruct& effectInfo : effectList->mList)
{
const ESM::MagicEffect *effect = mStore.get<ESM::MagicEffect>().find(it->mEffectID);
const ESM::MagicEffect *effect = mStore.get<ESM::MagicEffect>().find(effectInfo.mEffectID);
if (MWMechanics::isSummoningEffect(it->mEffectID))
if (MWMechanics::isSummoningEffect(effectInfo.mEffectID))
{
preload(mWorldScene.get(), mStore, "VFX_Summon_Start");
preload(mWorldScene.get(), mStore, MWMechanics::getSummonedCreature(it->mEffectID));
preload(mWorldScene.get(), mStore, MWMechanics::getSummonedCreature(effectInfo.mEffectID));
}
preload(mWorldScene.get(), mStore, effect->mCasting);
preload(mWorldScene.get(), mStore, effect->mHit);
if (it->mArea > 0)
if (effectInfo.mArea > 0)
preload(mWorldScene.get(), mStore, effect->mArea);
if (it->mRange == ESM::RT_Target)
if (effectInfo.mRange == ESM::RT_Target)
preload(mWorldScene.get(), mStore, effect->mBolt);
}
}