1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-02-22 12:39:59 +00:00

ESSImport: convert stolen item tracker

This commit is contained in:
scrawl 2015-02-04 22:10:58 +01:00
parent bea88c3643
commit 356d1c7657
2 changed files with 32 additions and 5 deletions

View File

@ -18,6 +18,7 @@
#include <components/esm/weatherstate.hpp> #include <components/esm/weatherstate.hpp>
#include <components/esm/globalscript.hpp> #include <components/esm/globalscript.hpp>
#include <components/esm/queststate.hpp> #include <components/esm/queststate.hpp>
#include <components/esm/stolenitems.hpp>
#include "importcrec.hpp" #include "importcrec.hpp"
#include "importcntc.hpp" #include "importcntc.hpp"
@ -387,24 +388,50 @@ public:
virtual void read(ESM::ESMReader &esm) virtual void read(ESM::ESMReader &esm)
{ {
std::string itemid = esm.getHNString("NAME"); std::string itemid = esm.getHNString("NAME");
Misc::StringUtils::toLower(itemid);
while (esm.isNextSub("FNAM") || esm.isNextSub("ONAM")) while (esm.isNextSub("FNAM") || esm.isNextSub("ONAM"))
{ {
if (esm.retSubName().toString() == "FNAM") if (esm.retSubName().toString() == "FNAM")
{ {
std::string factionid = esm.getHString(); std::string factionid = esm.getHString();
mFactionStolenItems.insert(std::make_pair(itemid, factionid)); mStolenItems[itemid].insert(std::make_pair(Misc::StringUtils::lowerCase(factionid), true));
} }
else else
{ {
std::string ownerid = esm.getHString(); std::string ownerid = esm.getHString();
mStolenItems.insert(std::make_pair(itemid, ownerid)); mStolenItems[itemid].insert(std::make_pair(Misc::StringUtils::lowerCase(ownerid), false));
} }
} }
} }
virtual void write(ESM::ESMWriter &esm)
{
ESM::StolenItems items;
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;
for (std::set<Owner>::const_iterator ownerIt = it->second.begin(); ownerIt != it->second.end(); ++ownerIt)
{
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,
// like vanilla MW did.
,std::numeric_limits<int>::max()));
}
items.mStolenItems.insert(std::make_pair(it->first, owners));
}
esm.startRecord(ESM::REC_STLN);
items.write(esm);
esm.endRecord(ESM::REC_STLN);
}
private: private:
std::multimap<std::string, std::string> mStolenItems; typedef std::pair<std::string, bool> Owner; // <owner id, bool isFaction>
std::multimap<std::string, std::string> mFactionStolenItems;
std::map<std::string, std::set<Owner> > mStolenItems;
}; };
/// Seen responses for a dialogue topic? /// Seen responses for a dialogue topic?

View File

@ -593,7 +593,7 @@ namespace MWGui
for (std::vector<std::pair<std::string, int> >::const_iterator it = itemOwners.begin(); it != itemOwners.end(); ++it) for (std::vector<std::pair<std::string, int> >::const_iterator it = itemOwners.begin(); it != itemOwners.end(); ++it)
{ {
ret += std::string("\nStolen ") + MyGUI::utility::toString(it->second) + " from " + it->first; ret += std::string("\nStolen from ") + it->first;
} }
ret += getMiscString(cellref.getGlobalVariable(), "Global"); ret += getMiscString(cellref.getGlobalVariable(), "Global");