You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
openmw/components/esm3/stolenitems.cpp

47 lines
1.5 KiB
C++

#include "stolenitems.hpp"
#include <components/esm3/esmreader.hpp>
#include <components/esm3/esmwriter.hpp>
namespace ESM
{
void StolenItems::write(ESMWriter& esm) const
{
for (StolenItemsMap::const_iterator it = mStolenItems.begin(); it != mStolenItems.end(); ++it)
{
esm.writeHNString("NAME", it->first);
for (std::map<std::pair<std::string, bool>, int>::const_iterator ownerIt = it->second.begin();
ownerIt != it->second.end(); ++ownerIt)
{
if (ownerIt->first.second)
esm.writeHNString("FNAM", ownerIt->first.first);
else
esm.writeHNString("ONAM", ownerIt->first.first);
esm.writeHNT("COUN", ownerIt->second);
}
}
}
void StolenItems::load(ESMReader& esm)
{
while (esm.isNextSub("NAME"))
{
std::string itemid = esm.getHString();
std::map<std::pair<std::string, bool>, int> ownerMap;
while (esm.isNextSub("FNAM") || esm.isNextSub("ONAM"))
{
const bool isFaction = (esm.retSubName() == "FNAM");
std::string owner = esm.getHString();
int count;
esm.getHNT(count, "COUN");
ownerMap.emplace(std::make_pair(std::move(owner), isFaction), count);
}
mStolenItems.insert_or_assign(std::move(itemid), std::move(ownerMap));
}
}
}