diff --git a/apps/openmw/mwphysics/physicssystem.cpp b/apps/openmw/mwphysics/physicssystem.cpp index e3884afad0..df6d299d0e 100644 --- a/apps/openmw/mwphysics/physicssystem.cpp +++ b/apps/openmw/mwphysics/physicssystem.cpp @@ -707,11 +707,11 @@ namespace MWPhysics if (!targets.empty()) { - for (std::vector::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::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::iterator it = mAnimatedObjects.begin(); it != mAnimatedObjects.end(); ++it) - (*it)->animateCollisionShapes(mCollisionWorld); + for (Object* animatedObject : mAnimatedObjects) + animatedObject->animateCollisionShapes(mCollisionWorld); #ifndef BT_NO_PROFILE CProfileManager::Reset(); diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index f6df24358d..bde7a53218 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -79,10 +79,9 @@ namespace void remove() { - for (std::vector >::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); } diff --git a/apps/openmw/mwrender/globalmap.cpp b/apps/openmw/mwrender/globalmap.cpp index d1b6cd239f..5880396398 100644 --- a/apps/openmw/mwrender/globalmap.cpp +++ b/apps/openmw/mwrender/globalmap.cpp @@ -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(); diff --git a/apps/openmw/mwrender/localmap.cpp b/apps/openmw/mwrender/localmap.cpp index 1060a5c0b2..1650dc92c6 100644 --- a/apps/openmw/mwrender/localmap.cpp +++ b/apps/openmw/mwrender/localmap.cpp @@ -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 >& renderedGrid, std::set cells) { std::set > grid; - for (std::set::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::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(); } diff --git a/apps/openmw/mwrender/pathgrid.cpp b/apps/openmw/mwrender/pathgrid.cpp index 8a7bc8b5ee..7977944570 100644 --- a/apps/openmw/mwrender/pathgrid.cpp +++ b/apps/openmw/mwrender/pathgrid.cpp @@ -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) diff --git a/apps/openmw/mwrender/ripplesimulation.cpp b/apps/openmw/mwrender/ripplesimulation.cpp index 21bd48d9ae..a124870600 100644 --- a/apps/openmw/mwrender/ripplesimulation.cpp +++ b/apps/openmw/mwrender/ripplesimulation.cpp @@ -118,21 +118,22 @@ RippleSimulation::~RippleSimulation() void RippleSimulation::update(float dt) { const MWBase::World* world = MWBase::Environment::get().getWorld(); - for (std::vector::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(); diff --git a/apps/openmw/mwrender/sky.cpp b/apps/openmw/mwrender/sky.cpp index 194646f2aa..3b5f0a4fab 100644 --- a/apps/openmw/mwrender/sky.cpp +++ b/apps/openmw/mwrender/sky.cpp @@ -1813,8 +1813,8 @@ void SkyManager::setWeather(const WeatherResult& weather) if (mRainFader) mRainFader->setAlpha(weather.mEffectFade * 0.6); // * Rain_Threshold? - for (std::vector >::const_iterator it = mParticleFaders.begin(); it != mParticleFaders.end(); ++it) - (*it)->setAlpha(weather.mEffectFade); + for (AlphaFader* fader : mParticleFaders) + fader->setAlpha(weather.mEffectFade); } void SkyManager::sunEnable() diff --git a/apps/openmw/mwworld/cellpreloader.cpp b/apps/openmw/mwworld/cellpreloader.cpp index 96461c1178..65ba19b4ac 100644 --- a/apps/openmw/mwworld/cellpreloader.cpp +++ b/apps/openmw/mwworld/cellpreloader.cpp @@ -72,9 +72,9 @@ namespace MWWorld const std::vector& 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::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) diff --git a/apps/openmw/mwworld/globals.cpp b/apps/openmw/mwworld/globals.cpp index acc06b28a9..69ec5563bc 100644 --- a/apps/openmw/mwworld/globals.cpp +++ b/apps/openmw/mwworld/globals.cpp @@ -37,10 +37,9 @@ namespace MWWorld const MWWorld::Store& globals = store.get(); - for (MWWorld::Store::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)); } } diff --git a/apps/openmw/mwworld/inventorystore.cpp b/apps/openmw/mwworld/inventorystore.cpp index a0895a1538..a8fa916802 100644 --- a/apps/openmw/mwworld/inventorystore.cpp +++ b/apps/openmw/mwworld/inventorystore.cpp @@ -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::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::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::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().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::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); } } } diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index d06034e1dc..6655bef4be 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -230,9 +230,8 @@ namespace template void InsertVisitor::insert(AddObject&& addObject) { - for (std::vector::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& exteriorPositions) { std::vector 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::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::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(listVisitor); cellStore->forEachType(listVisitor); } - for (std::vector::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); diff --git a/apps/openmw/mwworld/store.cpp b/apps/openmw/mwworld/store.cpp index 631b6e0811..79d9174ed9 100644 --- a/apps/openmw/mwworld/store.cpp +++ b/apps/openmw/mwworld/store.cpp @@ -420,10 +420,9 @@ namespace MWWorld //========================================================================= Store::~Store() { - for (std::vector::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::searchExtByName(const std::string &id) const { - ESM::Cell *cell = 0; - std::vector::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::searchExtByRegion(const std::string &id) const { - ESM::Cell *cell = 0; - std::vector::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::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::insert(const ESM::Cell &cell) diff --git a/apps/openmw/mwworld/weather.cpp b/apps/openmw/mwworld/weather.cpp index 6ef9535e9f..c181b95cf6 100644 --- a/apps/openmw/mwworld/weather.cpp +++ b/apps/openmw/mwworld/weather.cpp @@ -298,10 +298,11 @@ void RegionWeather::setChances(const std::vector& chances) mChances.reserve(chances.size()); } - std::vector::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::iterator it = mStore.get().begin(); - for(; it != mStore.get().end(); ++it) + for(const ESM::Region& region : mStore.get()) { - 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))); } } diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 72e1433583..d8324476a2 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -1649,13 +1649,13 @@ namespace MWWorld /// \todo should use convexSweepTest here std::vector collisions = mPhysics->getCollisions(it->first, MWPhysics::CollisionType_Door, MWPhysics::CollisionType_Actor); - for (std::vector::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 > toApply; - for (std::vector::const_iterator effectIt = effects.mList.begin(); - effectIt != effects.mList.end(); ++effectIt) + for (const ESM::ENAMstruct& effectInfo : effects.mList) { - const ESM::MagicEffect* effect = mStore.get().find(effectIt->mEffectID); + const ESM::MagicEffect* effect = mStore.get().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(effectIt->mArea * 2)); + mRendering->spawnEffect("meshes\\" + areaStatic->mModel, texture, origin, static_cast(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 objects; MWBase::Environment::get().getMechanicsManager()->getObjectsInRange( - origin, feetToGameUnits(static_cast(effectIt->mArea)), objects); + origin, feetToGameUnits(static_cast(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 >::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::const_iterator it = effectList->mList.begin(); it != effectList->mList.end(); ++it) + for (const ESM::ENAMstruct& effectInfo : effectList->mList) { - const ESM::MagicEffect *effect = mStore.get().find(it->mEffectID); + const ESM::MagicEffect *effect = mStore.get().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); } }