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

Use C++11-style loops in the game world instead of iterators

This commit is contained in:
Andrei Kortunov 2019-03-07 12:38:55 +04:00
parent 8bd7effae1
commit d23a0ce2ae
14 changed files with 133 additions and 139 deletions

View file

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

View file

@ -79,10 +79,9 @@ namespace
void remove() 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 // FIXME: a Drawable might have more than one parent
osg::Node* node = *it;
if (node->getNumParents()) if (node->getNumParents())
node->getParent(0)->removeChild(node); node->getParent(0)->removeChild(node);
} }

View file

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

View file

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

View file

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

View file

@ -118,21 +118,22 @@ RippleSimulation::~RippleSimulation()
void RippleSimulation::update(float dt) void RippleSimulation::update(float dt)
{ {
const MWBase::World* world = MWBase::Environment::get().getWorld(); 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) // fetch a new ptr (to handle cell change etc)
// for non-player actors this is done in updateObjectCell // 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); bool shouldEmit = (world->isUnderwater(ptr.getCell(), currentPos) && !world->isSubmerged(ptr)) || world->isWalkingOnWater(ptr);
if ( shouldEmit && (currentPos - it->mLastEmitPosition).length() > 10 ) if (shouldEmit && (currentPos - emitter.mLastEmitPosition).length() > 10)
{ {
it->mLastEmitPosition = currentPos; emitter.mLastEmitPosition = currentPos;
currentPos.z() = mParticleNode->getPosition().z(); currentPos.z() = mParticleNode->getPosition().z();

View file

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

View file

@ -72,9 +72,9 @@ namespace MWWorld
const std::vector<std::string>& objectIds = cell->getPreloadedIds(); 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 // 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()); std::string model = ref.getPtr().getClass().getModel(ref.getPtr());
if (!model.empty()) if (!model.empty())
mMeshes.push_back(model); 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) if (mAbort)
break; break;
try try
{ {
std::string mesh = *it;
mesh = Misc::ResourceHelpers::correctActorModelPath(mesh, mSceneManager->getVFS()); mesh = Misc::ResourceHelpers::correctActorModelPath(mesh, mSceneManager->getVFS());
if (mPreloadInstances) if (mPreloadInstances)

View file

@ -37,10 +37,9 @@ namespace MWWorld
const MWWorld::Store<ESM::Global>& globals = store.get<ESM::Global>(); const MWWorld::Store<ESM::Global>& globals = store.get<ESM::Global>();
for (MWWorld::Store<ESM::Global>::iterator iter = globals.begin(); iter!=globals.end(); for (const ESM::Global& esmGlobal : globals)
++iter)
{ {
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); iter->getClass().getEquipmentSlots (*iter);
// checking if current item pointed by iter can be equipped // checking if current item pointed by iter can be equipped
for (std::vector<int>::const_iterator iter2 (itemsSlots.first.begin()); for (int slot : itemsSlots.first)
iter2!=itemsSlots.first.end(); ++iter2)
{ {
// if true then it means slot is equipped already // if true then it means slot is equipped already
// check if slot may require swapping if current item is more valuable // 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) 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) else if (iter.getType() == ContainerStore::Type_Clothing)
{ {
// if left ring is equipped // 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 there is a place for right ring dont swap it
if (slots_.at(Slot_RightRing) == end()) 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 // if we are here it means item can be equipped or swapped
slots_[*iter2] = iter; slots_[slot] = iter;
break; break;
} }
} }
@ -645,10 +644,9 @@ void MWWorld::InventoryStore::updateMagicEffects(const Ptr& actor)
// Try resisting each effect // Try resisting each effect
int i=0; int i=0;
for (std::vector<ESM::ENAMstruct>::const_iterator effectIt (enchantment.mEffects.mList.begin()); for (const ESM::ENAMstruct& effect : enchantment.mEffects.mList)
effectIt!=enchantment.mEffects.mList.end(); ++effectIt)
{ {
params[i].mMultiplier = MWMechanics::getEffectMultiplier(effectIt->mEffectID, actor, actor); params[i].mMultiplier = MWMechanics::getEffectMultiplier(effect.mEffectID, actor, actor);
++i; ++i;
} }
@ -662,18 +660,20 @@ void MWWorld::InventoryStore::updateMagicEffects(const Ptr& actor)
params = mPermanentMagicEffectMagnitudes[(**iter).getCellRef().getRefId()]; params = mPermanentMagicEffectMagnitudes[(**iter).getCellRef().getRefId()];
int i=0; int i=0;
for (std::vector<ESM::ENAMstruct>::const_iterator effectIt (enchantment.mEffects.mList.begin()); for (const ESM::ENAMstruct& effect : enchantment.mEffects.mList)
effectIt!=enchantment.mEffects.mList.end(); ++effectIt, ++i)
{ {
const ESM::MagicEffect *magicEffect = const ESM::MagicEffect *magicEffect =
MWBase::Environment::get().getWorld()->getStore().get<ESM::MagicEffect>().find ( MWBase::Environment::get().getWorld()->getStore().get<ESM::MagicEffect>().find (
effectIt->mEffectID); effect.mEffectID);
// Fully resisted or can't be applied to target? // 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; 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; magnitude *= params[i].mMultiplier;
if (!existed) if (!existed)
@ -685,7 +685,9 @@ void MWWorld::InventoryStore::updateMagicEffects(const Ptr& actor)
} }
if (magnitude) if (magnitude)
mMagicEffects.add (*effectIt, magnitude); mMagicEffects.add (effect, magnitude);
i++;
} }
} }
} }
@ -949,17 +951,17 @@ void MWWorld::InventoryStore::visitEffectSources(MWMechanics::EffectSourceVisito
continue; continue;
int i=0; int i=0;
for (std::vector<ESM::ENAMstruct>::const_iterator effectIt (enchantment.mEffects.mList.begin()); for (const ESM::ENAMstruct& effect : enchantment.mEffects.mList)
effectIt!=enchantment.mEffects.mList.end(); ++effectIt, ++i)
{ {
i++;
// Don't get spell icon display information for enchantments that weren't actually applied // 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; continue;
const EffectParams& params = mPermanentMagicEffectMagnitudes[(**iter).getCellRef().getRefId()][i]; const EffectParams& params = mPermanentMagicEffectMagnitudes[(**iter).getCellRef().getRefId()][i-1];
float magnitude = effectIt->mMagnMin + (effectIt->mMagnMax - effectIt->mMagnMin) * params.mRandom; float magnitude = effect.mMagnMin + (effect.mMagnMax - effect.mMagnMin) * params.mRandom;
magnitude *= params.mMultiplier; magnitude *= params.mMultiplier;
if (magnitude > 0) 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> template <class AddObject>
void InsertVisitor::insert(AddObject&& 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 (mRescale)
{ {
if (ptr.getCellRef().getScale()<0.5) 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) void Scene::preloadTeleportDoorDestinations(const osg::Vec3f& playerPos, const osg::Vec3f& predictedPos, std::vector<osg::Vec3f>& exteriorPositions)
{ {
std::vector<MWWorld::ConstPtr> teleportDoors; std::vector<MWWorld::ConstPtr> teleportDoors;
for (CellStoreCollection::const_iterator iter (mActiveCells.begin()); for (const MWWorld::CellStore* cellStore : mActiveCells)
iter!=mActiveCells.end(); ++iter)
{ {
const MWWorld::CellStore* cellStore = *iter;
typedef MWWorld::CellRefList<ESM::Door>::List DoorList; typedef MWWorld::CellRefList<ESM::Door>::List DoorList;
const DoorList &doors = cellStore->getReadOnlyDoors().mList; 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; 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(); float sqrDistToPlayer = (playerPos - door.getRefData().getPosition().asVec3()).length2();
sqrDistToPlayer = std::min(sqrDistToPlayer, (predictedPos - 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(); const MWWorld::ConstPtr player = MWBase::Environment::get().getWorld()->getPlayerPtr();
ListFastTravelDestinationsVisitor listVisitor(mPreloadDistance, player.getRefData().getPosition().asVec3()); 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::NPC>(listVisitor);
cellStore->forEachType<ESM::Creature>(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()) if (!dest.mCellName.empty())
preloadCell(MWBase::Environment::get().getWorld()->getInterior(it->mCellName)); preloadCell(MWBase::Environment::get().getWorld()->getInterior(dest.mCellName));
else else
{ {
osg::Vec3f pos = it->mPos.asVec3(); osg::Vec3f pos = dest.mPos.asVec3();
int x,y; int x,y;
MWBase::Environment::get().getWorld()->positionToIndex( pos.x(), pos.y(), x, y); MWBase::Environment::get().getWorld()->positionToIndex( pos.x(), pos.y(), x, y);
preloadCell(MWBase::Environment::get().getWorld()->getExterior(x,y), true); preloadCell(MWBase::Environment::get().getWorld()->getExterior(x,y), true);

View file

@ -420,10 +420,9 @@ namespace MWWorld
//========================================================================= //=========================================================================
Store<ESM::Land>::~Store() Store<ESM::Land>::~Store()
{ {
for (std::vector<ESM::Land *>::const_iterator it = for (const ESM::Land* staticLand : mStatic)
mStatic.begin(); it != mStatic.end(); ++it)
{ {
delete *it; delete staticLand;
} }
} }
@ -737,15 +736,16 @@ namespace MWWorld
} }
const ESM::Cell *Store<ESM::Cell>::searchExtByName(const std::string &id) const const ESM::Cell *Store<ESM::Cell>::searchExtByName(const std::string &id) const
{ {
ESM::Cell *cell = 0; const ESM::Cell *cell = nullptr;
std::vector<ESM::Cell *>::const_iterator it = mSharedExt.begin(); for (const ESM::Cell *sharedCell : mSharedExt)
for (; it != mSharedExt.end(); ++it) { {
if (Misc::StringUtils::ciEqual((*it)->mName, id)) { if (Misc::StringUtils::ciEqual(sharedCell->mName, id))
if ( cell == 0 || {
( (*it)->mData.mX > cell->mData.mX ) || if (cell == 0 ||
( (*it)->mData.mX == cell->mData.mX && (*it)->mData.mY > cell->mData.mY ) ) (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 const ESM::Cell *Store<ESM::Cell>::searchExtByRegion(const std::string &id) const
{ {
ESM::Cell *cell = 0; const ESM::Cell *cell = nullptr;
std::vector<ESM::Cell *>::const_iterator it = mSharedExt.begin(); for (const ESM::Cell *sharedCell : mSharedExt)
for (; it != mSharedExt.end(); ++it) { {
if (Misc::StringUtils::ciEqual((*it)->mRegion, id)) { if (Misc::StringUtils::ciEqual(sharedCell->mRegion, id))
if ( cell == 0 || {
( (*it)->mData.mX > cell->mData.mX ) || if (cell == nullptr ||
( (*it)->mData.mX == cell->mData.mX && (*it)->mData.mY > cell->mData.mY ) ) (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()); list.reserve(list.size() + mSharedInt.size());
std::vector<ESM::Cell *>::const_iterator it = mSharedInt.begin(); for (const ESM::Cell *sharedCell : mSharedInt)
for (; it != mSharedInt.end(); ++it) { {
list.push_back((*it)->mName); list.push_back(sharedCell->mName);
} }
} }
ESM::Cell *Store<ESM::Cell>::insert(const ESM::Cell &cell) 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()); mChances.reserve(chances.size());
} }
std::vector<char>::const_iterator it = chances.begin(); int i = 0;
for(size_t i = 0; it != chances.end(); ++it, ++i) for(char chance : chances)
{ {
mChances[i] = *it; mChances[i] = chance;
i++;
} }
// Regional weather no longer supports the current type, select a new weather pattern. // 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() inline void WeatherManager::importRegions()
{ {
Store<ESM::Region>::iterator it = mStore.get<ESM::Region>().begin(); for(const ESM::Region& region : mStore.get<ESM::Region>())
for(; it != mStore.get<ESM::Region>().end(); ++it)
{ {
std::string regionID = Misc::StringUtils::lowerCase(it->mId); std::string regionID = Misc::StringUtils::lowerCase(region.mId);
mRegions.insert(std::make_pair(regionID, RegionWeather(*it))); mRegions.insert(std::make_pair(regionID, RegionWeather(region)));
} }
} }

View file

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