diff --git a/apps/bsatool/bsatool.cpp b/apps/bsatool/bsatool.cpp index 54e946cbc..ed86a3a42 100644 --- a/apps/bsatool/bsatool.cpp +++ b/apps/bsatool/bsatool.cpp @@ -183,19 +183,19 @@ int list(Bsa::BSAFile& bsa, Arguments& info) { // List all files const Bsa::BSAFile::FileList &files = bsa.getList(); - for(unsigned int i=0; iname; - - std::string extractPath (archivePath); + for (const auto &file : bsa.getList()) + { + std::string extractPath(file.name); replaceAll(extractPath, "\\", "/"); // Get the target path (the path the file will be extracted to) @@ -278,7 +273,7 @@ int extractAll(Bsa::BSAFile& bsa, Arguments& info) // Get a stream for the file to extract // (inefficient because getFile iter on the list again) - Files::IStreamPtr data = bsa.getFile(archivePath); + Files::IStreamPtr data = bsa.getFile(file.name); bfs::ofstream out(target, std::ios::binary); // Write the file to disk diff --git a/apps/esmtool/esmtool.cpp b/apps/esmtool/esmtool.cpp index 59095c1df..7618bbeb8 100644 --- a/apps/esmtool/esmtool.cpp +++ b/apps/esmtool/esmtool.cpp @@ -352,12 +352,12 @@ int load(Arguments& info) std::cout << "Author: " << esm.getAuthor() << std::endl << "Description: " << esm.getDesc() << std::endl << "File format version: " << esm.getFVer() << std::endl; - std::vector m = esm.getGameFiles(); - if (!m.empty()) + std::vector masterData = esm.getGameFiles(); + if (!masterData.empty()) { std::cout << "Masters:" << std::endl; - for(unsigned int i=0;imType = type; @@ -728,10 +728,9 @@ void Record::print() << " (" << mData.mData.mAttribute[0] << ")" << std::endl; std::cout << " Attribute2: " << attributeLabel(mData.mData.mAttribute[1]) << " (" << mData.mData.mAttribute[1] << ")" << std::endl; - for (int i = 0; i < 7; i++) - if (mData.mData.mSkills[i] != -1) - std::cout << " Skill: " << skillLabel(mData.mData.mSkills[i]) - << " (" << mData.mData.mSkills[i] << ")" << std::endl; + for (int skill : mData.mData.mSkills) + if (skill != -1) + std::cout << " Skill: " << skillLabel(skill) << " (" << skill << ")" << std::endl; for (int i = 0; i != 10; i++) if (!mData.mRanks[i].empty()) { diff --git a/apps/essimporter/converter.cpp b/apps/essimporter/converter.cpp index 900fbb05c..e0756602d 100644 --- a/apps/essimporter/converter.cpp +++ b/apps/essimporter/converter.cpp @@ -52,9 +52,7 @@ namespace // a dynamically created record e.g. player-enchanted weapon std::string index = indexedRefId.substr(indexedRefId.size()-8); - if(index.find_first_not_of("0123456789ABCDEF") == std::string::npos ) - return true; - return false; + return index.find_first_not_of("0123456789ABCDEF") == std::string::npos; } void splitIndexedRefId(const std::string& indexedRefId, int& refIndex, std::string& refId) @@ -139,12 +137,12 @@ namespace ESSImport image2->allocateImage(width, height, 1, GL_RGBA, GL_UNSIGNED_BYTE); memcpy(image2->data(), &data[0], data.size()); - for (std::set >::const_iterator it = mContext->mExploredCells.begin(); it != mContext->mExploredCells.end(); ++it) + for (const auto & exploredCell : mContext->mExploredCells) { - if (it->first > mContext->mGlobalMapState.mBounds.mMaxX - || it->first < mContext->mGlobalMapState.mBounds.mMinX - || it->second > mContext->mGlobalMapState.mBounds.mMaxY - || it->second < mContext->mGlobalMapState.mBounds.mMinY) + if (exploredCell.first > mContext->mGlobalMapState.mBounds.mMaxX + || exploredCell.first < mContext->mGlobalMapState.mBounds.mMinX + || exploredCell.second > mContext->mGlobalMapState.mBounds.mMaxY + || exploredCell.second < mContext->mGlobalMapState.mBounds.mMinY) { // out of bounds, I think this could happen, since the original engine had a fixed-size map continue; @@ -152,12 +150,12 @@ namespace ESSImport int imageLeftSrc = mGlobalMapImage->s()/2; int imageTopSrc = mGlobalMapImage->t()/2; - imageLeftSrc += it->first * cellSize; - imageTopSrc -= it->second * cellSize; + imageLeftSrc += exploredCell.first * cellSize; + imageTopSrc -= exploredCell.second * cellSize; int imageLeftDst = width/2; int imageTopDst = height/2; - imageLeftDst += it->first * cellSize; - imageTopDst -= it->second * cellSize; + imageLeftDst += exploredCell.first * cellSize; + imageTopDst -= exploredCell.second * cellSize; for (int x=0; x::const_iterator refIt = cell.mRefs.begin(); refIt != cell.mRefs.end(); ++refIt) + for (const auto & cellref : cell.mRefs) { - const CellRef& cellref = *refIt; ESM::CellRef out (cellref); // TODO: use mContext->mCreatures/mNpcs @@ -437,16 +434,16 @@ namespace ESSImport void ConvertCell::write(ESM::ESMWriter &esm) { - for (std::map::const_iterator it = mIntCells.begin(); it != mIntCells.end(); ++it) - writeCell(it->second, esm); + for (const auto & cell : mIntCells) + writeCell(cell.second, esm); - for (std::map, Cell>::const_iterator it = mExtCells.begin(); it != mExtCells.end(); ++it) - writeCell(it->second, esm); + for (const auto & cell : mExtCells) + writeCell(cell.second, esm); - for (std::vector::const_iterator it = mMarkers.begin(); it != mMarkers.end(); ++it) + for (const auto & marker : mMarkers) { esm.startRecord(ESM::REC_MARK); - it->save(esm); + marker.save(esm); esm.endRecord(ESM::REC_MARK); } } diff --git a/apps/essimporter/converter.hpp b/apps/essimporter/converter.hpp index 2694ea570..30d0236aa 100644 --- a/apps/essimporter/converter.hpp +++ b/apps/essimporter/converter.hpp @@ -127,8 +127,8 @@ public: ESM::SpellState::SpellParams empty; // FIXME: player start spells and birthsign spells aren't listed here, // need to fix openmw to account for this - for (std::vector::const_iterator it = npc.mSpells.mList.begin(); it != npc.mSpells.mList.end(); ++it) - mContext->mPlayer.mObject.mCreatureStats.mSpells.mSpells[*it] = empty; + for (const auto & spell : npc.mSpells.mList) + mContext->mPlayer.mObject.mCreatureStats.mSpells.mSpells[spell] = empty; // Clear the list now that we've written it, this prevents issues cropping up with // ensureCustomData() in OpenMW tripping over no longer existing spells, where an error would be fatal. @@ -434,9 +434,9 @@ public: for (std::map >::const_iterator it = mStolenItems.begin(); it != mStolenItems.end(); ++it) { std::map, int> owners; - for (std::set::const_iterator ownerIt = it->second.begin(); ownerIt != it->second.end(); ++ownerIt) + for (const auto & ownerIt : it->second) { - owners.insert(std::make_pair(std::make_pair(ownerIt->first, ownerIt->second) + owners.insert(std::make_pair(std::make_pair(ownerIt.first, ownerIt.second) // Since OpenMW doesn't suffer from the owner contamination bug, // it needs a count argument. But for legacy savegames, we don't know // this count, so must assume all items of that ID are stolen, @@ -588,10 +588,10 @@ public: } virtual void write(ESM::ESMWriter &esm) { - for (std::vector::const_iterator it = mScripts.begin(); it != mScripts.end(); ++it) + for (const auto & script : mScripts) { esm.startRecord(ESM::REC_GSCR); - it->save(esm); + script.save(esm); esm.endRecord(ESM::REC_GSCR); } } diff --git a/apps/essimporter/convertinventory.cpp b/apps/essimporter/convertinventory.cpp index 0799c8d11..79e09488c 100644 --- a/apps/essimporter/convertinventory.cpp +++ b/apps/essimporter/convertinventory.cpp @@ -9,21 +9,20 @@ namespace ESSImport void convertInventory(const Inventory &inventory, ESM::InventoryState &state) { int index = 0; - for (std::vector::const_iterator it = inventory.mItems.begin(); - it != inventory.mItems.end(); ++it) + for (const auto & item : inventory.mItems) { ESM::ObjectState objstate; objstate.blank(); - objstate.mRef = *it; - objstate.mRef.mRefID = Misc::StringUtils::lowerCase(it->mId); - objstate.mCount = std::abs(it->mCount); // restocking items have negative count in the savefile + objstate.mRef = item; + objstate.mRef.mRefID = Misc::StringUtils::lowerCase(item.mId); + objstate.mCount = std::abs(item.mCount); // restocking items have negative count in the savefile // openmw handles them differently, so no need to set any flags state.mItems.push_back(objstate); - if (it->mRelativeEquipmentSlot != -1) + if (item.mRelativeEquipmentSlot != -1) // Note we should really write the absolute slot here, which we do not know about // Not a big deal, OpenMW will auto-correct to a valid slot, the only problem is when // an item could be equipped in two different slots (e.g. equipped two rings) - state.mEquipmentSlots[index] = it->mRelativeEquipmentSlot; + state.mEquipmentSlots[index] = item.mRelativeEquipmentSlot; ++index; } } diff --git a/apps/essimporter/convertplayer.cpp b/apps/essimporter/convertplayer.cpp index 5e2da2b03..b3ccbca35 100644 --- a/apps/essimporter/convertplayer.cpp +++ b/apps/essimporter/convertplayer.cpp @@ -10,13 +10,13 @@ namespace ESSImport { out.mBirthsign = pcdt.mBirthsign; out.mObject.mNpcStats.mBounty = pcdt.mBounty; - for (std::vector::const_iterator it = pcdt.mFactions.begin(); it != pcdt.mFactions.end(); ++it) + for (const auto & essFaction : pcdt.mFactions) { ESM::NpcStats::Faction faction; - faction.mExpelled = (it->mFlags & 0x2) != 0; - faction.mRank = it->mRank; - faction.mReputation = it->mReputation; - out.mObject.mNpcStats.mFactions[Misc::StringUtils::lowerCase(it->mFactionName.toString())] = faction; + faction.mExpelled = (essFaction.mFlags & 0x2) != 0; + faction.mRank = essFaction.mRank; + faction.mReputation = essFaction.mReputation; + out.mObject.mNpcStats.mFactions[Misc::StringUtils::lowerCase(essFaction.mFactionName.toString())] = faction; } for (int i=0; i<3; ++i) out.mObject.mNpcStats.mSpecIncreases[i] = pcdt.mPNAM.mSpecIncreases[i]; @@ -35,10 +35,9 @@ namespace ESSImport teleportingEnabled = !(pcdt.mPNAM.mPlayerFlags & PCDT::PlayerFlags_TeleportingDisabled); levitationEnabled = !(pcdt.mPNAM.mPlayerFlags & PCDT::PlayerFlags_LevitationDisabled); - for (std::vector::const_iterator it = pcdt.mKnownDialogueTopics.begin(); - it != pcdt.mKnownDialogueTopics.end(); ++it) + for (const auto & knownDialogueTopic : pcdt.mKnownDialogueTopics) { - outDialogueTopics.push_back(Misc::StringUtils::lowerCase(*it)); + outDialogueTopics.push_back(Misc::StringUtils::lowerCase(knownDialogueTopic)); } controls.mViewSwitchDisabled = pcdt.mPNAM.mPlayerFlags & PCDT::PlayerFlags_ViewSwitchDisabled; diff --git a/apps/essimporter/convertscri.cpp b/apps/essimporter/convertscri.cpp index dbe35a010..eba48df77 100644 --- a/apps/essimporter/convertscri.cpp +++ b/apps/essimporter/convertscri.cpp @@ -1,18 +1,16 @@ #include "convertscri.hpp" -#include - namespace { template void storeVariables(const std::vector& variables, ESM::Locals& locals, const std::string& scriptname) { - for (typename std::vector::const_iterator it = variables.begin(); it != variables.end(); ++it) + for (const auto& variable : variables) { - ESM::Variant val(*it); + ESM::Variant val(variable); val.setType(VariantType); - locals.mVariables.push_back(std::make_pair(std::string(), val)); + locals.mVariables.emplace_back(std::string(), val); } } diff --git a/apps/essimporter/importer.cpp b/apps/essimporter/importer.cpp index 36512579c..706512263 100644 --- a/apps/essimporter/importer.cpp +++ b/apps/essimporter/importer.cpp @@ -16,15 +16,12 @@ #include #include -#include #include #include #include #include #include -#include #include -#include #include @@ -49,7 +46,7 @@ namespace image->allocateImage(128, 128, 1, GL_RGB, GL_UNSIGNED_BYTE); // need to convert pixel format from BGRA to RGB as the jpg readerwriter doesn't support it otherwise - std::vector::const_iterator it = fileHeader.mSCRS.begin(); + auto it = fileHeader.mSCRS.begin(); for (int y=0; y<128; ++y) { for (int x=0; x<128; ++x) @@ -317,10 +314,9 @@ namespace ESSImport std::set unknownRecords; - for (std::map >::const_iterator it = converters.begin(); - it != converters.end(); ++it) + for (const auto & converter : converters) { - it->second->setContext(context); + converter.second->setContext(context); } while (esm.hasMoreRecs()) @@ -328,7 +324,7 @@ namespace ESSImport ESM::NAME n = esm.getRecName(); esm.getRecHeader(); - std::map >::iterator it = converters.find(n.intval); + auto it = converters.find(n.intval); if (it != converters.end()) { it->second->read(esm); @@ -358,17 +354,15 @@ namespace ESSImport writer.setDescription(""); writer.setRecordCount (0); - for (std::vector::const_iterator it = header.mMaster.begin(); - it != header.mMaster.end(); ++it) - writer.addMaster (it->name, 0); // not using the size information anyway -> use value of 0 + for (const auto & master : header.mMaster) + writer.addMaster(master.name, 0); // not using the size information anyway -> use value of 0 writer.save (stream); ESM::SavedGame profile; - for (std::vector::const_iterator it = header.mMaster.begin(); - it != header.mMaster.end(); ++it) + for (const auto & master : header.mMaster) { - profile.mContentFiles.push_back(it->name); + profile.mContentFiles.push_back(master.name); } profile.mDescription = esm.getDesc(); profile.mInGameTime.mDay = context.mDay; diff --git a/apps/essimporter/importinventory.cpp b/apps/essimporter/importinventory.cpp index cff114acb..dbf9ce0bd 100644 --- a/apps/essimporter/importinventory.cpp +++ b/apps/essimporter/importinventory.cpp @@ -4,8 +4,6 @@ #include -#include - namespace ESSImport {