Rework EsmTool code. Remove explicit NAME handling

openmw-38
Stanislav Bas 10 years ago
parent 8e6a7be6f5
commit ede4bfcf52

@ -251,8 +251,7 @@ void loadCell(ESM::Cell &cell, ESM::ESMReader &esm, Arguments& info)
ESM::CellRef ref;
if(!quiet) std::cout << " References:\n";
bool deleted = false;
while(cell.getNextRef(esm, ref, deleted))
while(cell.getNextRef(esm, ref))
{
if (save) {
info.data.mCellRefs[&cell].push_back(ref);
@ -270,7 +269,7 @@ void loadCell(ESM::Cell &cell, ESM::ESMReader &esm, Arguments& info)
std::cout << " Uses/health: '" << ref.mChargeInt << "'\n";
std::cout << " Gold value: '" << ref.mGoldValue << "'\n";
std::cout << " Blocked: '" << static_cast<int>(ref.mReferenceBlocked) << "'" << std::endl;
std::cout << " Deleted: " << deleted << std::endl;
std::cout << " Deleted: " << ref.mIsDeleted << std::endl;
if (!ref.mKey.empty())
std::cout << " Key: '" << ref.mKey << "'" << std::endl;
}
@ -352,61 +351,58 @@ int load(Arguments& info)
uint32_t flags;
esm.getRecHeader(flags);
EsmTool::RecordBase *record = EsmTool::RecordBase::create(n);
if (record == 0)
{
if (std::find(skipped.begin(), skipped.end(), n.val) == skipped.end())
{
std::cout << "Skipping " << n.toString() << " records." << std::endl;
skipped.push_back(n.val);
}
esm.skipRecord();
if (quiet) break;
std::cout << " Skipping\n";
continue;
}
record->setFlags(static_cast<int>(flags));
record->setPrintPlain(info.plain_given);
record->load(esm);
// Is the user interested in this record type?
bool interested = true;
if (!info.types.empty())
{
std::vector<std::string>::iterator match;
match = std::find(info.types.begin(), info.types.end(),
n.toString());
match = std::find(info.types.begin(), info.types.end(), n.toString());
if (match == info.types.end()) interested = false;
}
std::string id = esm.getHNOString("NAME");
if (id.empty())
id = esm.getHNOString("INAM");
if (!info.name.empty() && !Misc::StringUtils::ciEqual(info.name, id))
if (!info.name.empty() && !Misc::StringUtils::ciEqual(info.name, record->getId()))
interested = false;
if(!quiet && interested)
std::cout << "\nRecord: " << n.toString()
<< " '" << id << "'\n";
EsmTool::RecordBase *record = EsmTool::RecordBase::create(n);
if (record == 0) {
if (std::find(skipped.begin(), skipped.end(), n.val) == skipped.end())
{
std::cout << "Skipping " << n.toString() << " records." << std::endl;
skipped.push_back(n.val);
}
{
std::cout << "\nRecord: " << n.toString() << " '" << record->getId() << "'\n";
record->print();
}
esm.skipRecord();
if (quiet) break;
std::cout << " Skipping\n";
} else {
if (record->getType().val == ESM::REC_GMST) {
// preset id for GameSetting record
record->cast<ESM::GameSetting>()->get().mId = id;
}
record->setId(id);
record->setFlags((int) flags);
record->setPrintPlain(info.plain_given);
record->load(esm);
if (!quiet && interested) record->print();
if (record->getType().val == ESM::REC_CELL && loadCells && interested) {
loadCell(record->cast<ESM::Cell>()->get(), esm, info);
}
if (record->getType().val == ESM::REC_CELL && loadCells && interested)
{
loadCell(record->cast<ESM::Cell>()->get(), esm, info);
}
if (save) {
info.data.mRecords.push_back(record);
} else {
delete record;
}
++info.data.mRecordStats[n.val];
if (save)
{
info.data.mRecords.push_back(record);
}
else
{
delete record;
}
++info.data.mRecordStats[n.val];
}
} catch(std::exception &e) {
@ -493,20 +489,11 @@ int clone(Arguments& info)
for (Records::iterator it = records.begin(); it != records.end() && i > 0; ++it)
{
EsmTool::RecordBase *record = *it;
name.val = record->getType().val;
esm.startRecord(name.toString(), record->getFlags());
// TODO wrap this with std::set
if (ESMData::sLabeledRec.count(name.val) > 0) {
esm.writeHNCString("NAME", record->getId());
} else {
esm.writeHNOString("NAME", record->getId());
}
record->save(esm);
if (name.val == ESM::REC_CELL) {
ESM::Cell *ptr = &record->cast<ESM::Cell>()->get();
if (!info.data.mCellRefs[ptr].empty()) {

@ -405,6 +405,7 @@ void Record<ESM::Activator>::print()
std::cout << " Name: " << mData.mName << std::endl;
std::cout << " Model: " << mData.mModel << std::endl;
std::cout << " Script: " << mData.mScript << std::endl;
std::cout << " Deleted: " << mData.mIsDeleted << std::endl;
}
template<>
@ -419,6 +420,7 @@ void Record<ESM::Potion>::print()
std::cout << " Value: " << mData.mData.mValue << std::endl;
std::cout << " AutoCalc: " << mData.mData.mAutoCalc << std::endl;
printEffectList(mData.mEffects);
std::cout << " Deleted: " << mData.mIsDeleted << std::endl;
}
template<>
@ -447,6 +449,7 @@ void Record<ESM::Armor>::print()
if (pit->mFemale != "")
std::cout << " Female Name: " << pit->mFemale << std::endl;
}
std::cout << " Deleted: " << mData.mIsDeleted << std::endl;
}
template<>
@ -461,6 +464,7 @@ void Record<ESM::Apparatus>::print()
std::cout << " Weight: " << mData.mData.mWeight << std::endl;
std::cout << " Value: " << mData.mData.mValue << std::endl;
std::cout << " Quality: " << mData.mData.mQuality << std::endl;
std::cout << " Deleted: " << mData.mIsDeleted << std::endl;
}
template<>
@ -474,6 +478,7 @@ void Record<ESM::BodyPart>::print()
std::cout << " Part: " << meshPartLabel(mData.mData.mPart)
<< " (" << (int)mData.mData.mPart << ")" << std::endl;
std::cout << " Vampire: " << (int)mData.mData.mVampire << std::endl;
std::cout << " Deleted: " << mData.mIsDeleted << std::endl;
}
template<>
@ -502,6 +507,7 @@ void Record<ESM::Book>::print()
{
std::cout << " Text: [skipped]" << std::endl;
}
std::cout << " Deleted: " << mData.mIsDeleted << std::endl;
}
template<>
@ -513,6 +519,7 @@ void Record<ESM::BirthSign>::print()
std::vector<std::string>::iterator pit;
for (pit = mData.mPowers.mList.begin(); pit != mData.mPowers.mList.end(); ++pit)
std::cout << " Power: " << *pit << std::endl;
std::cout << " Deleted: " << mData.mIsDeleted << std::endl;
}
template<>
@ -541,6 +548,7 @@ void Record<ESM::Cell>::print()
std::cout << " Map Color: " << boost::format("0x%08X") % mData.mMapColor << std::endl;
std::cout << " Water Level Int: " << mData.mWaterInt << std::endl;
std::cout << " RefId counter: " << mData.mRefNumCounter << std::endl;
std::cout << " Deleted: " << mData.mIsDeleted << std::endl;
}
@ -563,6 +571,7 @@ void Record<ESM::Class>::print()
for (int i = 0; i != 5; i++)
std::cout << " Major Skill: " << skillLabel(mData.mData.mSkills[i][1])
<< " (" << mData.mData.mSkills[i][1] << ")" << std::endl;
std::cout << " Deleted: " << mData.mIsDeleted << std::endl;
}
template<>
@ -589,6 +598,7 @@ void Record<ESM::Clothing>::print()
if (pit->mFemale != "")
std::cout << " Female Name: " << pit->mFemale << std::endl;
}
std::cout << " Deleted: " << mData.mIsDeleted << std::endl;
}
template<>
@ -604,6 +614,7 @@ void Record<ESM::Container>::print()
for (cit = mData.mInventory.mList.begin(); cit != mData.mInventory.mList.end(); ++cit)
std::cout << " Inventory: Count: " << boost::format("%4d") % cit->mCount
<< " Item: " << cit->mItem.toString() << std::endl;
std::cout << " Deleted: " << mData.mIsDeleted << std::endl;
}
template<>
@ -670,6 +681,7 @@ void Record<ESM::Creature>::print()
std::vector<ESM::AIPackage>::iterator pit;
for (pit = mData.mAiPackage.mList.begin(); pit != mData.mAiPackage.mList.end(); ++pit)
printAIPackage(*pit);
std::cout << " Deleted: " << mData.mIsDeleted << std::endl;
}
template<>
@ -677,6 +689,7 @@ void Record<ESM::Dialogue>::print()
{
std::cout << " Type: " << dialogTypeLabel(mData.mType)
<< " (" << (int)mData.mType << ")" << std::endl;
std::cout << " Deleted: " << mData.mIsDeleted << std::endl;
// Sadly, there are no DialInfos, because the loader dumps as it
// loads, rather than loading and then dumping. :-( Anyone mind if
// I change this?
@ -693,6 +706,7 @@ void Record<ESM::Door>::print()
std::cout << " Script: " << mData.mScript << std::endl;
std::cout << " OpenSound: " << mData.mOpenSound << std::endl;
std::cout << " CloseSound: " << mData.mCloseSound << std::endl;
std::cout << " Deleted: " << mData.mIsDeleted << std::endl;
}
template<>
@ -704,6 +718,7 @@ void Record<ESM::Enchantment>::print()
std::cout << " Charge: " << mData.mData.mCharge << std::endl;
std::cout << " AutoCalc: " << mData.mData.mAutocalc << std::endl;
printEffectList(mData.mEffects);
std::cout << " Deleted: " << mData.mIsDeleted << std::endl;
}
template<>
@ -737,12 +752,14 @@ void Record<ESM::Faction>::print()
std::map<std::string, int>::iterator rit;
for (rit = mData.mReactions.begin(); rit != mData.mReactions.end(); ++rit)
std::cout << " Reaction: " << rit->second << " = " << rit->first << std::endl;
std::cout << " Deleted: " << mData.mIsDeleted << std::endl;
}
template<>
void Record<ESM::Global>::print()
{
std::cout << " " << mData.mValue << std::endl;
std::cout << " Deleted: " << mData.mIsDeleted << std::endl;
}
template<>
@ -809,6 +826,7 @@ void Record<ESM::DialInfo>::print()
std::cout << " Result Script: [skipped]" << std::endl;
}
}
std::cout << " Deleted: " << mData.mIsDeleted << std::endl;
}
template<>
@ -832,6 +850,7 @@ void Record<ESM::Ingredient>::print()
std::cout << " Attribute: " << attributeLabel(mData.mData.mAttributes[i])
<< " (" << mData.mData.mAttributes[i] << ")" << std::endl;
}
std::cout << " Deleted: " << mData.mIsDeleted << std::endl;
}
template<>
@ -854,6 +873,7 @@ void Record<ESM::Land>::print()
std::cout << " Unknown2: " << mData.mLandData->mUnk2 << std::endl;
}
if (!wasLoaded) mData.unloadData();
std::cout << " Deleted: " << mData.mIsDeleted << std::endl;
}
template<>
@ -866,6 +886,7 @@ void Record<ESM::CreatureLevList>::print()
for (iit = mData.mList.begin(); iit != mData.mList.end(); ++iit)
std::cout << " Creature: Level: " << iit->mLevel
<< " Creature: " << iit->mId << std::endl;
std::cout << " Deleted: " << mData.mIsDeleted << std::endl;
}
template<>
@ -878,6 +899,7 @@ void Record<ESM::ItemLevList>::print()
for (iit = mData.mList.begin(); iit != mData.mList.end(); ++iit)
std::cout << " Inventory: Level: " << iit->mLevel
<< " Item: " << iit->mId << std::endl;
std::cout << " Deleted: " << mData.mIsDeleted << std::endl;
}
template<>
@ -898,6 +920,7 @@ void Record<ESM::Light>::print()
std::cout << " Duration: " << mData.mData.mTime << std::endl;
std::cout << " Radius: " << mData.mData.mRadius << std::endl;
std::cout << " Color: " << mData.mData.mColor << std::endl;
std::cout << " Deleted: " << mData.mIsDeleted << std::endl;
}
template<>
@ -912,6 +935,7 @@ void Record<ESM::Lockpick>::print()
std::cout << " Value: " << mData.mData.mValue << std::endl;
std::cout << " Quality: " << mData.mData.mQuality << std::endl;
std::cout << " Uses: " << mData.mData.mUses << std::endl;
std::cout << " Deleted: " << mData.mIsDeleted << std::endl;
}
template<>
@ -926,6 +950,7 @@ void Record<ESM::Probe>::print()
std::cout << " Value: " << mData.mData.mValue << std::endl;
std::cout << " Quality: " << mData.mData.mQuality << std::endl;
std::cout << " Uses: " << mData.mData.mUses << std::endl;
std::cout << " Deleted: " << mData.mIsDeleted << std::endl;
}
template<>
@ -940,6 +965,7 @@ void Record<ESM::Repair>::print()
std::cout << " Value: " << mData.mData.mValue << std::endl;
std::cout << " Quality: " << mData.mData.mQuality << std::endl;
std::cout << " Uses: " << mData.mData.mUses << std::endl;
std::cout << " Deleted: " << mData.mIsDeleted << std::endl;
}
template<>
@ -948,6 +974,7 @@ void Record<ESM::LandTexture>::print()
std::cout << " Id: " << mData.mId << std::endl;
std::cout << " Index: " << mData.mIndex << std::endl;
std::cout << " Texture: " << mData.mTexture << std::endl;
std::cout << " Deleted: " << mData.mIsDeleted << std::endl;
}
template<>
@ -998,6 +1025,7 @@ void Record<ESM::Miscellaneous>::print()
std::cout << " Weight: " << mData.mData.mWeight << std::endl;
std::cout << " Value: " << mData.mData.mValue << std::endl;
std::cout << " Is Key: " << mData.mData.mIsKey << std::endl;
std::cout << " Deleted: " << mData.mIsDeleted << std::endl;
}
template<>
@ -1083,6 +1111,8 @@ void Record<ESM::NPC>::print()
std::vector<ESM::AIPackage>::iterator pit;
for (pit = mData.mAiPackage.mList.begin(); pit != mData.mAiPackage.mList.end(); ++pit)
printAIPackage(*pit);
std::cout << " Deleted: " << mData.mIsDeleted << std::endl;
}
template<>
@ -1117,6 +1147,8 @@ void Record<ESM::Pathgrid>::print()
std::cout << " BAD POINT IN EDGE!" << std::endl;
i++;
}
std::cout << " Deleted: " << mData.mIsDeleted << std::endl;
}
template<>
@ -1157,6 +1189,8 @@ void Record<ESM::Race>::print()
std::vector<std::string>::iterator sit;
for (sit = mData.mPowers.mList.begin(); sit != mData.mPowers.mList.end(); ++sit)
std::cout << " Power: " << *sit << std::endl;
std::cout << " Deleted: " << mData.mIsDeleted << std::endl;
}
template<>
@ -1216,6 +1250,8 @@ void Record<ESM::Script>::print()
{
std::cout << " Script: [skipped]" << std::endl;
}
std::cout << " Deleted: " << mData.mIsDeleted << std::endl;
}
template<>
@ -1239,6 +1275,7 @@ void Record<ESM::SoundGenerator>::print()
std::cout << " Sound: " << mData.mSound << std::endl;
std::cout << " Type: " << soundTypeLabel(mData.mType)
<< " (" << mData.mType << ")" << std::endl;
std::cout << " Deleted: " << mData.mIsDeleted << std::endl;
}
template<>
@ -1249,6 +1286,7 @@ void Record<ESM::Sound>::print()
if (mData.mData.mMinRange != 0 && mData.mData.mMaxRange != 0)
std::cout << " Range: " << (int)mData.mData.mMinRange << " - "
<< (int)mData.mData.mMaxRange << std::endl;
std::cout << " Deleted: " << mData.mIsDeleted << std::endl;
}
template<>
@ -1260,13 +1298,15 @@ void Record<ESM::Spell>::print()
std::cout << " Flags: " << spellFlags(mData.mData.mFlags) << std::endl;
std::cout << " Cost: " << mData.mData.mCost << std::endl;
printEffectList(mData.mEffects);
std::cout << " Deleted: " << mData.mIsDeleted << std::endl;
}
template<>
void Record<ESM::StartScript>::print()
{
std::cout << "Start Script: " << mData.mId << std::endl;
std::cout << "Start Data: " << mData.mData << std::endl;
std::cout << " Start Script: " << mData.mId << std::endl;
std::cout << " Start Data: " << mData.mData << std::endl;
std::cout << " Deleted: " << mData.mIsDeleted << std::endl;
}
template<>
@ -1307,6 +1347,37 @@ void Record<ESM::Weapon>::print()
if (mData.mData.mThrust[0] != 0 && mData.mData.mThrust[1] != 0)
std::cout << " Thrust: " << (int)mData.mData.mThrust[0] << "-"
<< (int)mData.mData.mThrust[1] << std::endl;
std::cout << " Deleted: " << mData.mIsDeleted << std::endl;
}
template<>
std::string Record<ESM::Cell>::getId() const
{
return mData.mName;
}
template<>
std::string Record<ESM::Land>::getId() const
{
return ""; // No ID for Land record
}
template<>
std::string Record<ESM::MagicEffect>::getId() const
{
return ""; // No ID for MagicEffect record
}
template<>
std::string Record<ESM::Pathgrid>::getId() const
{
return ""; // No ID for Pathgrid record
}
template<>
std::string Record<ESM::Skill>::getId() const
{
return ""; // No ID for Skill record
}
} // end namespace

@ -32,13 +32,7 @@ namespace EsmTool
virtual ~RecordBase() {}
const std::string &getId() const {
return mId;
}
void setId(const std::string &id) {
mId = id;
}
virtual std::string getId() const = 0;
uint32_t getFlags() const {
return mFlags;
@ -75,6 +69,10 @@ namespace EsmTool
T mData;
public:
std::string getId() const {
return mData.mId;
}
T &get() {
return mData;
}
@ -89,6 +87,12 @@ namespace EsmTool
void print();
};
template<> std::string Record<ESM::Cell>::getId() const;
template<> std::string Record<ESM::Land>::getId() const;
template<> std::string Record<ESM::MagicEffect>::getId() const;
template<> std::string Record<ESM::Pathgrid>::getId() const;
template<> std::string Record<ESM::Skill>::getId() const;
template<> void Record<ESM::Activator>::print();
template<> void Record<ESM::Potion>::print();

Loading…
Cancel
Save