Merge pull request #2903 from akortunov/refactoring

Use more C++11 in tools code
This commit is contained in:
Bret Curtis 2020-06-10 16:28:33 +02:00 committed by GitHub
commit bfe3f13c90
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 120 additions and 137 deletions

View File

@ -183,19 +183,19 @@ int list(Bsa::BSAFile& bsa, Arguments& info)
{ {
// List all files // List all files
const Bsa::BSAFile::FileList &files = bsa.getList(); const Bsa::BSAFile::FileList &files = bsa.getList();
for(unsigned int i=0; i<files.size(); i++) for (const auto& file : files)
{ {
if(info.longformat) if(info.longformat)
{ {
// Long format // Long format
std::ios::fmtflags f(std::cout.flags()); std::ios::fmtflags f(std::cout.flags());
std::cout << std::setw(50) << std::left << files[i].name; std::cout << std::setw(50) << std::left << file.name;
std::cout << std::setw(8) << std::left << std::dec << files[i].fileSize; std::cout << std::setw(8) << std::left << std::dec << file.fileSize;
std::cout << "@ 0x" << std::hex << files[i].offset << std::endl; std::cout << "@ 0x" << std::hex << file.offset << std::endl;
std::cout.flags(f); std::cout.flags(f);
} }
else else
std::cout << files[i].name << std::endl; std::cout << file.name << std::endl;
} }
return 0; return 0;
@ -252,14 +252,9 @@ int extract(Bsa::BSAFile& bsa, Arguments& info)
int extractAll(Bsa::BSAFile& bsa, Arguments& info) int extractAll(Bsa::BSAFile& bsa, Arguments& info)
{ {
// Get the list of files present in the archive for (const auto &file : bsa.getList())
Bsa::BSAFile::FileList list = bsa.getList(); {
std::string extractPath(file.name);
// Iter on the list
for(Bsa::BSAFile::FileList::iterator it = list.begin(); it != list.end(); ++it) {
const char* archivePath = it->name;
std::string extractPath (archivePath);
replaceAll(extractPath, "\\", "/"); replaceAll(extractPath, "\\", "/");
// Get the target path (the path the file will be extracted to) // 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 // Get a stream for the file to extract
// (inefficient because getFile iter on the list again) // (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); bfs::ofstream out(target, std::ios::binary);
// Write the file to disk // Write the file to disk

View File

@ -352,12 +352,12 @@ int load(Arguments& info)
std::cout << "Author: " << esm.getAuthor() << std::endl std::cout << "Author: " << esm.getAuthor() << std::endl
<< "Description: " << esm.getDesc() << std::endl << "Description: " << esm.getDesc() << std::endl
<< "File format version: " << esm.getFVer() << std::endl; << "File format version: " << esm.getFVer() << std::endl;
std::vector<ESM::Header::MasterData> m = esm.getGameFiles(); std::vector<ESM::Header::MasterData> masterData = esm.getGameFiles();
if (!m.empty()) if (!masterData.empty())
{ {
std::cout << "Masters:" << std::endl; std::cout << "Masters:" << std::endl;
for(unsigned int i=0;i<m.size();i++) for(const auto& master : masterData)
std::cout << " " << m[i].name << ", " << m[i].size << " bytes" << std::endl; std::cout << " " << master.name << ", " << master.size << " bytes" << std::endl;
} }
} }
@ -369,7 +369,7 @@ int load(Arguments& info)
esm.getRecHeader(flags); esm.getRecHeader(flags);
EsmTool::RecordBase *record = EsmTool::RecordBase::create(n); EsmTool::RecordBase *record = EsmTool::RecordBase::create(n);
if (record == 0) if (record == nullptr)
{ {
if (std::find(skipped.begin(), skipped.end(), n.intval) == skipped.end()) if (std::find(skipped.begin(), skipped.end(), n.intval) == skipped.end())
{ {
@ -538,8 +538,8 @@ int comp(Arguments& info)
Arguments fileOne; Arguments fileOne;
Arguments fileTwo; Arguments fileTwo;
fileOne.raw_given = 0; fileOne.raw_given = false;
fileTwo.raw_given = 0; fileTwo.raw_given = false;
fileOne.mode = "clone"; fileOne.mode = "clone";
fileTwo.mode = "clone"; fileTwo.mode = "clone";

View File

@ -779,7 +779,7 @@ std::string creatureListFlags(int flags)
std::string lightFlags(int flags) std::string lightFlags(int flags)
{ {
std::string properties = ""; std::string properties;
if (flags == 0) properties += "[None] "; if (flags == 0) properties += "[None] ";
if (flags & ESM::Light::Dynamic) properties += "Dynamic "; if (flags & ESM::Light::Dynamic) properties += "Dynamic ";
if (flags & ESM::Light::Fire) properties += "Fire "; if (flags & ESM::Light::Fire) properties += "Fire ";

View File

@ -9,7 +9,7 @@
namespace namespace
{ {
void printAIPackage(ESM::AIPackage p) void printAIPackage(const ESM::AIPackage& p)
{ {
std::cout << " AI Type: " << aiTypeLabel(p.mType) std::cout << " AI Type: " << aiTypeLabel(p.mType)
<< " (" << Misc::StringUtils::format("0x%08X", p.mType) << ")" << std::endl; << " (" << Misc::StringUtils::format("0x%08X", p.mType) << ")" << std::endl;
@ -53,7 +53,7 @@ void printAIPackage(ESM::AIPackage p)
std::cout << " Cell Name: " << p.mCellName << std::endl; std::cout << " Cell Name: " << p.mCellName << std::endl;
} }
std::string ruleString(ESM::DialInfo::SelectStruct ss) std::string ruleString(const ESM::DialInfo::SelectStruct& ss)
{ {
std::string rule = ss.mSelectRule; std::string rule = ss.mSelectRule;
@ -126,7 +126,7 @@ std::string ruleString(ESM::DialInfo::SelectStruct ss)
return result; return result;
} }
void printEffectList(ESM::EffectList effects) void printEffectList(const ESM::EffectList& effects)
{ {
int i = 0; int i = 0;
for (const ESM::ENAMstruct& effect : effects.mList) for (const ESM::ENAMstruct& effect : effects.mList)
@ -174,7 +174,7 @@ namespace EsmTool {
RecordBase * RecordBase *
RecordBase::create(ESM::NAME type) RecordBase::create(ESM::NAME type)
{ {
RecordBase *record = 0; RecordBase *record = nullptr;
switch (type.intval) { switch (type.intval) {
case ESM::REC_ACTI: case ESM::REC_ACTI:
@ -388,7 +388,7 @@ RecordBase::create(ESM::NAME type)
break; break;
} }
default: default:
record = 0; record = nullptr;
} }
if (record) { if (record) {
record->mType = type; record->mType = type;
@ -728,10 +728,9 @@ void Record<ESM::Faction>::print()
<< " (" << mData.mData.mAttribute[0] << ")" << std::endl; << " (" << mData.mData.mAttribute[0] << ")" << std::endl;
std::cout << " Attribute2: " << attributeLabel(mData.mData.mAttribute[1]) std::cout << " Attribute2: " << attributeLabel(mData.mData.mAttribute[1])
<< " (" << mData.mData.mAttribute[1] << ")" << std::endl; << " (" << mData.mData.mAttribute[1] << ")" << std::endl;
for (int i = 0; i < 7; i++) for (int skill : mData.mData.mSkills)
if (mData.mData.mSkills[i] != -1) if (skill != -1)
std::cout << " Skill: " << skillLabel(mData.mData.mSkills[i]) std::cout << " Skill: " << skillLabel(skill) << " (" << skill << ")" << std::endl;
<< " (" << mData.mData.mSkills[i] << ")" << std::endl;
for (int i = 0; i != 10; i++) for (int i = 0; i != 10; i++)
if (!mData.mRanks[i].empty()) if (!mData.mRanks[i].empty())
{ {

View File

@ -74,7 +74,7 @@ namespace EsmTool
: mIsDeleted(false) : mIsDeleted(false)
{} {}
std::string getId() const { std::string getId() const override {
return mData.mId; return mData.mId;
} }
@ -82,15 +82,15 @@ namespace EsmTool
return mData; return mData;
} }
void save(ESM::ESMWriter &esm) { void save(ESM::ESMWriter &esm) override {
mData.save(esm, mIsDeleted); mData.save(esm, mIsDeleted);
} }
void load(ESM::ESMReader &esm) { void load(ESM::ESMReader &esm) override {
mData.load(esm, mIsDeleted); mData.load(esm, mIsDeleted);
} }
void print(); void print() override;
}; };
template<> std::string Record<ESM::Cell>::getId() const; template<> std::string Record<ESM::Cell>::getId() const;

View File

@ -52,9 +52,7 @@ namespace
// a dynamically created record e.g. player-enchanted weapon // a dynamically created record e.g. player-enchanted weapon
std::string index = indexedRefId.substr(indexedRefId.size()-8); std::string index = indexedRefId.substr(indexedRefId.size()-8);
if(index.find_first_not_of("0123456789ABCDEF") == std::string::npos ) return index.find_first_not_of("0123456789ABCDEF") == std::string::npos;
return true;
return false;
} }
void splitIndexedRefId(const std::string& indexedRefId, int& refIndex, std::string& refId) 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); image2->allocateImage(width, height, 1, GL_RGBA, GL_UNSIGNED_BYTE);
memcpy(image2->data(), &data[0], data.size()); memcpy(image2->data(), &data[0], data.size());
for (std::set<std::pair<int, int> >::const_iterator it = mContext->mExploredCells.begin(); it != mContext->mExploredCells.end(); ++it) for (const auto & exploredCell : mContext->mExploredCells)
{ {
if (it->first > mContext->mGlobalMapState.mBounds.mMaxX if (exploredCell.first > mContext->mGlobalMapState.mBounds.mMaxX
|| it->first < mContext->mGlobalMapState.mBounds.mMinX || exploredCell.first < mContext->mGlobalMapState.mBounds.mMinX
|| it->second > mContext->mGlobalMapState.mBounds.mMaxY || exploredCell.second > mContext->mGlobalMapState.mBounds.mMaxY
|| it->second < mContext->mGlobalMapState.mBounds.mMinY) || exploredCell.second < mContext->mGlobalMapState.mBounds.mMinY)
{ {
// out of bounds, I think this could happen, since the original engine had a fixed-size map // out of bounds, I think this could happen, since the original engine had a fixed-size map
continue; continue;
@ -152,12 +150,12 @@ namespace ESSImport
int imageLeftSrc = mGlobalMapImage->s()/2; int imageLeftSrc = mGlobalMapImage->s()/2;
int imageTopSrc = mGlobalMapImage->t()/2; int imageTopSrc = mGlobalMapImage->t()/2;
imageLeftSrc += it->first * cellSize; imageLeftSrc += exploredCell.first * cellSize;
imageTopSrc -= it->second * cellSize; imageTopSrc -= exploredCell.second * cellSize;
int imageLeftDst = width/2; int imageLeftDst = width/2;
int imageTopDst = height/2; int imageTopDst = height/2;
imageLeftDst += it->first * cellSize; imageLeftDst += exploredCell.first * cellSize;
imageTopDst -= it->second * cellSize; imageTopDst -= exploredCell.second * cellSize;
for (int x=0; x<cellSize; ++x) for (int x=0; x<cellSize; ++x)
for (int y=0; y<cellSize; ++y) for (int y=0; y<cellSize; ++y)
{ {
@ -329,9 +327,8 @@ namespace ESSImport
csta.mWaterLevel = esmcell.mWater; csta.mWaterLevel = esmcell.mWater;
csta.save(esm); csta.save(esm);
for (std::vector<CellRef>::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); ESM::CellRef out (cellref);
// TODO: use mContext->mCreatures/mNpcs // TODO: use mContext->mCreatures/mNpcs
@ -437,16 +434,16 @@ namespace ESSImport
void ConvertCell::write(ESM::ESMWriter &esm) void ConvertCell::write(ESM::ESMWriter &esm)
{ {
for (std::map<std::string, Cell>::const_iterator it = mIntCells.begin(); it != mIntCells.end(); ++it) for (const auto & cell : mIntCells)
writeCell(it->second, esm); writeCell(cell.second, esm);
for (std::map<std::pair<int, int>, Cell>::const_iterator it = mExtCells.begin(); it != mExtCells.end(); ++it) for (const auto & cell : mExtCells)
writeCell(it->second, esm); writeCell(cell.second, esm);
for (std::vector<ESM::CustomMarker>::const_iterator it = mMarkers.begin(); it != mMarkers.end(); ++it) for (const auto & marker : mMarkers)
{ {
esm.startRecord(ESM::REC_MARK); esm.startRecord(ESM::REC_MARK);
it->save(esm); marker.save(esm);
esm.endRecord(ESM::REC_MARK); esm.endRecord(ESM::REC_MARK);
} }
} }

View File

@ -79,9 +79,9 @@ template <typename T>
class DefaultConverter : public Converter class DefaultConverter : public Converter
{ {
public: public:
virtual int getStage() { return 0; } int getStage() override { return 0; }
virtual void read(ESM::ESMReader& esm) void read(ESM::ESMReader& esm) override
{ {
T record; T record;
bool isDeleted = false; bool isDeleted = false;
@ -90,7 +90,7 @@ public:
mRecords[record.mId] = record; mRecords[record.mId] = record;
} }
virtual void write(ESM::ESMWriter& esm) void write(ESM::ESMWriter& esm) override
{ {
for (typename std::map<std::string, T>::const_iterator it = mRecords.begin(); it != mRecords.end(); ++it) for (typename std::map<std::string, T>::const_iterator it = mRecords.begin(); it != mRecords.end(); ++it)
{ {
@ -107,7 +107,7 @@ protected:
class ConvertNPC : public Converter class ConvertNPC : public Converter
{ {
public: public:
virtual void read(ESM::ESMReader &esm) void read(ESM::ESMReader &esm) override
{ {
ESM::NPC npc; ESM::NPC npc;
bool isDeleted = false; bool isDeleted = false;
@ -127,8 +127,8 @@ public:
ESM::SpellState::SpellParams empty; ESM::SpellState::SpellParams empty;
// FIXME: player start spells and birthsign spells aren't listed here, // FIXME: player start spells and birthsign spells aren't listed here,
// need to fix openmw to account for this // need to fix openmw to account for this
for (std::vector<std::string>::const_iterator it = npc.mSpells.mList.begin(); it != npc.mSpells.mList.end(); ++it) for (const auto & spell : npc.mSpells.mList)
mContext->mPlayer.mObject.mCreatureStats.mSpells.mSpells[*it] = empty; mContext->mPlayer.mObject.mCreatureStats.mSpells.mSpells[spell] = empty;
// Clear the list now that we've written it, this prevents issues cropping up with // 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. // ensureCustomData() in OpenMW tripping over no longer existing spells, where an error would be fatal.
@ -144,7 +144,7 @@ public:
class ConvertCREA : public Converter class ConvertCREA : public Converter
{ {
public: public:
virtual void read(ESM::ESMReader &esm) void read(ESM::ESMReader &esm) override
{ {
// See comment in ConvertNPC // See comment in ConvertNPC
ESM::Creature creature; ESM::Creature creature;
@ -162,7 +162,7 @@ public:
class ConvertGlobal : public DefaultConverter<ESM::Global> class ConvertGlobal : public DefaultConverter<ESM::Global>
{ {
public: public:
virtual void read(ESM::ESMReader &esm) void read(ESM::ESMReader &esm) override
{ {
ESM::Global global; ESM::Global global;
bool isDeleted = false; bool isDeleted = false;
@ -183,7 +183,7 @@ public:
class ConvertClass : public DefaultConverter<ESM::Class> class ConvertClass : public DefaultConverter<ESM::Class>
{ {
public: public:
virtual void read(ESM::ESMReader &esm) void read(ESM::ESMReader &esm) override
{ {
ESM::Class class_; ESM::Class class_;
bool isDeleted = false; bool isDeleted = false;
@ -199,7 +199,7 @@ public:
class ConvertBook : public DefaultConverter<ESM::Book> class ConvertBook : public DefaultConverter<ESM::Book>
{ {
public: public:
virtual void read(ESM::ESMReader &esm) void read(ESM::ESMReader &esm) override
{ {
ESM::Book book; ESM::Book book;
bool isDeleted = false; bool isDeleted = false;
@ -215,7 +215,7 @@ public:
class ConvertNPCC : public Converter class ConvertNPCC : public Converter
{ {
public: public:
virtual void read(ESM::ESMReader &esm) void read(ESM::ESMReader &esm) override
{ {
std::string id = esm.getHNString("NAME"); std::string id = esm.getHNString("NAME");
NPCC npcc; NPCC npcc;
@ -235,7 +235,7 @@ public:
class ConvertREFR : public Converter class ConvertREFR : public Converter
{ {
public: public:
virtual void read(ESM::ESMReader &esm) void read(ESM::ESMReader &esm) override
{ {
REFR refr; REFR refr;
refr.load(esm); refr.load(esm);
@ -261,7 +261,7 @@ public:
} }
} }
} }
virtual void write(ESM::ESMWriter& esm) void write(ESM::ESMWriter& esm) override
{ {
esm.startRecord(ESM::REC_ASPL); esm.startRecord(ESM::REC_ASPL);
esm.writeHNString("ID__", mSelectedSpell); esm.writeHNString("ID__", mSelectedSpell);
@ -280,14 +280,14 @@ public:
mLevitationEnabled(true) mLevitationEnabled(true)
{} {}
virtual void read(ESM::ESMReader &esm) void read(ESM::ESMReader &esm) override
{ {
PCDT pcdt; PCDT pcdt;
pcdt.load(esm); pcdt.load(esm);
convertPCDT(pcdt, mContext->mPlayer, mContext->mDialogueState.mKnownTopics, mFirstPersonCam, mTeleportingEnabled, mLevitationEnabled, mContext->mControlsState); convertPCDT(pcdt, mContext->mPlayer, mContext->mDialogueState.mKnownTopics, mFirstPersonCam, mTeleportingEnabled, mLevitationEnabled, mContext->mControlsState);
} }
virtual void write(ESM::ESMWriter &esm) void write(ESM::ESMWriter &esm) override
{ {
esm.startRecord(ESM::REC_ENAB); esm.startRecord(ESM::REC_ENAB);
esm.writeHNT("TELE", mTeleportingEnabled); esm.writeHNT("TELE", mTeleportingEnabled);
@ -306,7 +306,7 @@ private:
class ConvertCNTC : public Converter class ConvertCNTC : public Converter
{ {
virtual void read(ESM::ESMReader &esm) void read(ESM::ESMReader &esm) override
{ {
std::string id = esm.getHNString("NAME"); std::string id = esm.getHNString("NAME");
CNTC cntc; CNTC cntc;
@ -318,7 +318,7 @@ class ConvertCNTC : public Converter
class ConvertCREC : public Converter class ConvertCREC : public Converter
{ {
public: public:
virtual void read(ESM::ESMReader &esm) void read(ESM::ESMReader &esm) override
{ {
std::string id = esm.getHNString("NAME"); std::string id = esm.getHNString("NAME");
CREC crec; CREC crec;
@ -330,8 +330,8 @@ public:
class ConvertFMAP : public Converter class ConvertFMAP : public Converter
{ {
public: public:
virtual void read(ESM::ESMReader &esm); void read(ESM::ESMReader &esm) override;
virtual void write(ESM::ESMWriter &esm); void write(ESM::ESMWriter &esm) override;
private: private:
osg::ref_ptr<osg::Image> mGlobalMapImage; osg::ref_ptr<osg::Image> mGlobalMapImage;
@ -340,8 +340,8 @@ private:
class ConvertCell : public Converter class ConvertCell : public Converter
{ {
public: public:
virtual void read(ESM::ESMReader& esm); void read(ESM::ESMReader& esm) override;
virtual void write(ESM::ESMWriter& esm); void write(ESM::ESMWriter& esm) override;
private: private:
struct Cell struct Cell
@ -362,7 +362,7 @@ private:
class ConvertKLST : public Converter class ConvertKLST : public Converter
{ {
public: public:
virtual void read(ESM::ESMReader& esm) void read(ESM::ESMReader& esm) override
{ {
KLST klst; KLST klst;
klst.load(esm); klst.load(esm);
@ -371,7 +371,7 @@ public:
mContext->mPlayer.mObject.mNpcStats.mWerewolfKills = klst.mWerewolfKills; mContext->mPlayer.mObject.mNpcStats.mWerewolfKills = klst.mWerewolfKills;
} }
virtual void write(ESM::ESMWriter &esm) void write(ESM::ESMWriter &esm) override
{ {
esm.startRecord(ESM::REC_DCOU); esm.startRecord(ESM::REC_DCOU);
for (std::map<std::string, int>::const_iterator it = mKillCounter.begin(); it != mKillCounter.end(); ++it) for (std::map<std::string, int>::const_iterator it = mKillCounter.begin(); it != mKillCounter.end(); ++it)
@ -389,7 +389,7 @@ private:
class ConvertFACT : public Converter class ConvertFACT : public Converter
{ {
public: public:
virtual void read(ESM::ESMReader& esm) void read(ESM::ESMReader& esm) override
{ {
ESM::Faction faction; ESM::Faction faction;
bool isDeleted = false; bool isDeleted = false;
@ -409,7 +409,7 @@ public:
class ConvertSTLN : public Converter class ConvertSTLN : public Converter
{ {
public: public:
virtual void read(ESM::ESMReader &esm) void read(ESM::ESMReader &esm) override
{ {
std::string itemid = esm.getHNString("NAME"); std::string itemid = esm.getHNString("NAME");
Misc::StringUtils::lowerCaseInPlace(itemid); Misc::StringUtils::lowerCaseInPlace(itemid);
@ -428,15 +428,15 @@ public:
} }
} }
} }
virtual void write(ESM::ESMWriter &esm) void write(ESM::ESMWriter &esm) override
{ {
ESM::StolenItems items; ESM::StolenItems items;
for (std::map<std::string, std::set<Owner> >::const_iterator it = mStolenItems.begin(); it != mStolenItems.end(); ++it) for (std::map<std::string, std::set<Owner> >::const_iterator it = mStolenItems.begin(); it != mStolenItems.end(); ++it)
{ {
std::map<std::pair<std::string, bool>, int> owners; std::map<std::pair<std::string, bool>, int> owners;
for (std::set<Owner>::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, // Since OpenMW doesn't suffer from the owner contamination bug,
// it needs a count argument. But for legacy savegames, we don't know // 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, // this count, so must assume all items of that ID are stolen,
@ -467,7 +467,7 @@ private:
class ConvertINFO : public Converter class ConvertINFO : public Converter
{ {
public: public:
virtual void read(ESM::ESMReader& esm) void read(ESM::ESMReader& esm) override
{ {
INFO info; INFO info;
info.load(esm); info.load(esm);
@ -477,7 +477,7 @@ public:
class ConvertDIAL : public Converter class ConvertDIAL : public Converter
{ {
public: public:
virtual void read(ESM::ESMReader& esm) void read(ESM::ESMReader& esm) override
{ {
std::string id = esm.getHNString("NAME"); std::string id = esm.getHNString("NAME");
DIAL dial; DIAL dial;
@ -485,7 +485,7 @@ public:
if (dial.mIndex > 0) if (dial.mIndex > 0)
mDials[id] = dial; mDials[id] = dial;
} }
virtual void write(ESM::ESMWriter &esm) void write(ESM::ESMWriter &esm) override
{ {
for (std::map<std::string, DIAL>::const_iterator it = mDials.begin(); it != mDials.end(); ++it) for (std::map<std::string, DIAL>::const_iterator it = mDials.begin(); it != mDials.end(); ++it)
{ {
@ -505,7 +505,7 @@ private:
class ConvertQUES : public Converter class ConvertQUES : public Converter
{ {
public: public:
virtual void read(ESM::ESMReader& esm) void read(ESM::ESMReader& esm) override
{ {
std::string id = esm.getHNString("NAME"); std::string id = esm.getHNString("NAME");
QUES quest; QUES quest;
@ -516,7 +516,7 @@ public:
class ConvertJOUR : public Converter class ConvertJOUR : public Converter
{ {
public: public:
virtual void read(ESM::ESMReader& esm) void read(ESM::ESMReader& esm) override
{ {
JOUR journal; JOUR journal;
journal.load(esm); journal.load(esm);
@ -531,7 +531,7 @@ public:
{ {
} }
virtual void read(ESM::ESMReader &esm) void read(ESM::ESMReader &esm) override
{ {
mGame.load(esm); mGame.load(esm);
mHasGame = true; mHasGame = true;
@ -551,7 +551,7 @@ public:
} }
} }
virtual void write(ESM::ESMWriter &esm) void write(ESM::ESMWriter &esm) override
{ {
if (!mHasGame) if (!mHasGame)
return; return;
@ -578,7 +578,7 @@ private:
class ConvertSCPT : public Converter class ConvertSCPT : public Converter
{ {
public: public:
virtual void read(ESM::ESMReader &esm) void read(ESM::ESMReader &esm) override
{ {
SCPT script; SCPT script;
script.load(esm); script.load(esm);
@ -586,12 +586,12 @@ public:
convertSCPT(script, out); convertSCPT(script, out);
mScripts.push_back(out); mScripts.push_back(out);
} }
virtual void write(ESM::ESMWriter &esm) void write(ESM::ESMWriter &esm) override
{ {
for (std::vector<ESM::GlobalScript>::const_iterator it = mScripts.begin(); it != mScripts.end(); ++it) for (const auto & script : mScripts)
{ {
esm.startRecord(ESM::REC_GSCR); esm.startRecord(ESM::REC_GSCR);
it->save(esm); script.save(esm);
esm.endRecord(ESM::REC_GSCR); esm.endRecord(ESM::REC_GSCR);
} }
} }
@ -603,9 +603,9 @@ private:
class ConvertPROJ : public Converter class ConvertPROJ : public Converter
{ {
public: public:
virtual int getStage() override { return 2; } int getStage() override { return 2; }
virtual void read(ESM::ESMReader& esm) override; void read(ESM::ESMReader& esm) override;
virtual void write(ESM::ESMWriter& esm) override; void write(ESM::ESMWriter& esm) override;
private: private:
void convertBaseState(ESM::BaseProjectileState& base, const PROJ::PNAM& pnam); void convertBaseState(ESM::BaseProjectileState& base, const PROJ::PNAM& pnam);
PROJ mProj; PROJ mProj;
@ -614,8 +614,8 @@ private:
class ConvertSPLM : public Converter class ConvertSPLM : public Converter
{ {
public: public:
virtual void read(ESM::ESMReader& esm) override; void read(ESM::ESMReader& esm) override;
virtual void write(ESM::ESMWriter& esm) override; void write(ESM::ESMWriter& esm) override;
private: private:
SPLM mSPLM; SPLM mSPLM;
}; };

View File

@ -9,21 +9,20 @@ namespace ESSImport
void convertInventory(const Inventory &inventory, ESM::InventoryState &state) void convertInventory(const Inventory &inventory, ESM::InventoryState &state)
{ {
int index = 0; int index = 0;
for (std::vector<Inventory::InventoryItem>::const_iterator it = inventory.mItems.begin(); for (const auto & item : inventory.mItems)
it != inventory.mItems.end(); ++it)
{ {
ESM::ObjectState objstate; ESM::ObjectState objstate;
objstate.blank(); objstate.blank();
objstate.mRef = *it; objstate.mRef = item;
objstate.mRef.mRefID = Misc::StringUtils::lowerCase(it->mId); objstate.mRef.mRefID = Misc::StringUtils::lowerCase(item.mId);
objstate.mCount = std::abs(it->mCount); // restocking items have negative count in the savefile 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 // openmw handles them differently, so no need to set any flags
state.mItems.push_back(objstate); 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 // 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 // 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) // 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; ++index;
} }
} }

View File

@ -10,13 +10,13 @@ namespace ESSImport
{ {
out.mBirthsign = pcdt.mBirthsign; out.mBirthsign = pcdt.mBirthsign;
out.mObject.mNpcStats.mBounty = pcdt.mBounty; out.mObject.mNpcStats.mBounty = pcdt.mBounty;
for (std::vector<PCDT::FNAM>::const_iterator it = pcdt.mFactions.begin(); it != pcdt.mFactions.end(); ++it) for (const auto & essFaction : pcdt.mFactions)
{ {
ESM::NpcStats::Faction faction; ESM::NpcStats::Faction faction;
faction.mExpelled = (it->mFlags & 0x2) != 0; faction.mExpelled = (essFaction.mFlags & 0x2) != 0;
faction.mRank = it->mRank; faction.mRank = essFaction.mRank;
faction.mReputation = it->mReputation; faction.mReputation = essFaction.mReputation;
out.mObject.mNpcStats.mFactions[Misc::StringUtils::lowerCase(it->mFactionName.toString())] = faction; out.mObject.mNpcStats.mFactions[Misc::StringUtils::lowerCase(essFaction.mFactionName.toString())] = faction;
} }
for (int i=0; i<3; ++i) for (int i=0; i<3; ++i)
out.mObject.mNpcStats.mSpecIncreases[i] = pcdt.mPNAM.mSpecIncreases[i]; out.mObject.mNpcStats.mSpecIncreases[i] = pcdt.mPNAM.mSpecIncreases[i];
@ -35,10 +35,9 @@ namespace ESSImport
teleportingEnabled = !(pcdt.mPNAM.mPlayerFlags & PCDT::PlayerFlags_TeleportingDisabled); teleportingEnabled = !(pcdt.mPNAM.mPlayerFlags & PCDT::PlayerFlags_TeleportingDisabled);
levitationEnabled = !(pcdt.mPNAM.mPlayerFlags & PCDT::PlayerFlags_LevitationDisabled); levitationEnabled = !(pcdt.mPNAM.mPlayerFlags & PCDT::PlayerFlags_LevitationDisabled);
for (std::vector<std::string>::const_iterator it = pcdt.mKnownDialogueTopics.begin(); for (const auto & knownDialogueTopic : pcdt.mKnownDialogueTopics)
it != pcdt.mKnownDialogueTopics.end(); ++it)
{ {
outDialogueTopics.push_back(Misc::StringUtils::lowerCase(*it)); outDialogueTopics.push_back(Misc::StringUtils::lowerCase(knownDialogueTopic));
} }
controls.mViewSwitchDisabled = pcdt.mPNAM.mPlayerFlags & PCDT::PlayerFlags_ViewSwitchDisabled; controls.mViewSwitchDisabled = pcdt.mPNAM.mPlayerFlags & PCDT::PlayerFlags_ViewSwitchDisabled;

View File

@ -1,18 +1,16 @@
#include "convertscri.hpp" #include "convertscri.hpp"
#include <iostream>
namespace namespace
{ {
template <typename T, ESM::VarType VariantType> template <typename T, ESM::VarType VariantType>
void storeVariables(const std::vector<T>& variables, ESM::Locals& locals, const std::string& scriptname) void storeVariables(const std::vector<T>& variables, ESM::Locals& locals, const std::string& scriptname)
{ {
for (typename std::vector<T>::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); val.setType(VariantType);
locals.mVariables.push_back(std::make_pair(std::string(), val)); locals.mVariables.emplace_back(std::string(), val);
} }
} }

View File

@ -86,7 +86,9 @@ namespace ESSImport
bool mHasANIS; bool mHasANIS;
ANIS mANIS; // scripted animation state ANIS mANIS; // scripted animation state
void load(ESM::ESMReader& esm); virtual void load(ESM::ESMReader& esm);
virtual ~ActorData() = default;
}; };
} }

View File

@ -25,7 +25,9 @@ namespace ESSImport
bool mDeleted; bool mDeleted;
void load(ESM::ESMReader& esm); void load(ESM::ESMReader& esm) override;
virtual ~CellRef() = default;
}; };
} }

View File

@ -16,15 +16,12 @@
#include <components/esm/player.hpp> #include <components/esm/player.hpp>
#include <components/esm/loadalch.hpp> #include <components/esm/loadalch.hpp>
#include <components/esm/loadclas.hpp>
#include <components/esm/loadspel.hpp> #include <components/esm/loadspel.hpp>
#include <components/esm/loadarmo.hpp> #include <components/esm/loadarmo.hpp>
#include <components/esm/loadweap.hpp> #include <components/esm/loadweap.hpp>
#include <components/esm/loadclot.hpp> #include <components/esm/loadclot.hpp>
#include <components/esm/loadench.hpp> #include <components/esm/loadench.hpp>
#include <components/esm/loadweap.hpp>
#include <components/esm/loadlevlist.hpp> #include <components/esm/loadlevlist.hpp>
#include <components/esm/loadglob.hpp>
#include <components/misc/constants.hpp> #include <components/misc/constants.hpp>
@ -49,7 +46,7 @@ namespace
image->allocateImage(128, 128, 1, GL_RGB, GL_UNSIGNED_BYTE); 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 // need to convert pixel format from BGRA to RGB as the jpg readerwriter doesn't support it otherwise
std::vector<unsigned char>::const_iterator it = fileHeader.mSCRS.begin(); auto it = fileHeader.mSCRS.begin();
for (int y=0; y<128; ++y) for (int y=0; y<128; ++y)
{ {
for (int x=0; x<128; ++x) for (int x=0; x<128; ++x)
@ -317,10 +314,9 @@ namespace ESSImport
std::set<unsigned int> unknownRecords; std::set<unsigned int> unknownRecords;
for (std::map<unsigned int, std::shared_ptr<Converter> >::const_iterator it = converters.begin(); for (const auto & converter : converters)
it != converters.end(); ++it)
{ {
it->second->setContext(context); converter.second->setContext(context);
} }
while (esm.hasMoreRecs()) while (esm.hasMoreRecs())
@ -328,7 +324,7 @@ namespace ESSImport
ESM::NAME n = esm.getRecName(); ESM::NAME n = esm.getRecName();
esm.getRecHeader(); esm.getRecHeader();
std::map<unsigned int, std::shared_ptr<Converter> >::iterator it = converters.find(n.intval); auto it = converters.find(n.intval);
if (it != converters.end()) if (it != converters.end())
{ {
it->second->read(esm); it->second->read(esm);
@ -358,17 +354,15 @@ namespace ESSImport
writer.setDescription(""); writer.setDescription("");
writer.setRecordCount (0); writer.setRecordCount (0);
for (std::vector<ESM::Header::MasterData>::const_iterator it = header.mMaster.begin(); for (const auto & master : header.mMaster)
it != header.mMaster.end(); ++it) writer.addMaster(master.name, 0); // not using the size information anyway -> use value of 0
writer.addMaster (it->name, 0); // not using the size information anyway -> use value of 0
writer.save (stream); writer.save (stream);
ESM::SavedGame profile; ESM::SavedGame profile;
for (std::vector<ESM::Header::MasterData>::const_iterator it = header.mMaster.begin(); for (const auto & master : header.mMaster)
it != header.mMaster.end(); ++it)
{ {
profile.mContentFiles.push_back(it->name); profile.mContentFiles.push_back(master.name);
} }
profile.mDescription = esm.getDesc(); profile.mDescription = esm.getDesc();
profile.mInGameTime.mDay = context.mDay; profile.mInGameTime.mDay = context.mDay;

View File

@ -4,8 +4,6 @@
#include <components/esm/esmreader.hpp> #include <components/esm/esmreader.hpp>
#include <components/esm/loadcont.hpp>
namespace ESSImport namespace ESSImport
{ {