2014-01-14 12:25:35 +01:00
|
|
|
#include "cellid.hpp"
|
|
|
|
|
|
|
|
#include "esmreader.hpp"
|
|
|
|
#include "esmwriter.hpp"
|
|
|
|
|
2022-04-12 00:18:39 +02:00
|
|
|
namespace ESM
|
|
|
|
{
|
|
|
|
|
|
|
|
const std::string CellId::sDefaultWorldspace = "sys::default";
|
2016-07-02 19:48:11 +02:00
|
|
|
|
2022-04-12 00:18:39 +02:00
|
|
|
void CellId::load(ESMReader& esm)
|
2014-01-14 12:25:35 +01:00
|
|
|
{
|
2022-04-10 13:35:00 +02:00
|
|
|
mWorldspace = esm.getHNString("SPAC");
|
2014-01-14 12:25:35 +01:00
|
|
|
|
2022-04-12 00:18:39 +02:00
|
|
|
if (esm.isNextSub("CIDX"))
|
2014-01-14 12:25:35 +01:00
|
|
|
{
|
|
|
|
esm.getHTSized<8>(mIndex);
|
|
|
|
mPaged = true;
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
|
|
|
else
|
2014-01-14 12:25:35 +01:00
|
|
|
mPaged = false;
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
2014-01-14 12:25:35 +01:00
|
|
|
|
|
|
|
void CellId::save(ESMWriter& esm) const
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2014-01-14 12:25:35 +01:00
|
|
|
esm.writeHNString("SPAC", mWorldspace);
|
2014-02-23 21:39:18 +01:00
|
|
|
|
|
|
|
if (mPaged)
|
|
|
|
esm.writeHNT("CIDX", mIndex, 8);
|
|
|
|
}
|
|
|
|
|
2022-04-12 00:18:39 +02:00
|
|
|
bool operator==(const CellId& left, const CellId& right)
|
2014-02-23 21:39:18 +01:00
|
|
|
{
|
|
|
|
return left.mWorldspace == right.mWorldspace && left.mPaged == right.mPaged
|
|
|
|
&& (!left.mPaged || (left.mIndex.mX == right.mIndex.mX && left.mIndex.mY == right.mIndex.mY));
|
|
|
|
}
|
2015-07-17 20:49:10 +02:00
|
|
|
|
2022-04-12 00:18:39 +02:00
|
|
|
bool operator!=(const CellId& left, const CellId& right)
|
2015-07-17 20:49:10 +02:00
|
|
|
{
|
|
|
|
return !(left == right);
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
2015-07-17 20:49:10 +02:00
|
|
|
|
|
|
|
bool operator<(const CellId& left, const CellId& right)
|
|
|
|
{
|
|
|
|
if (left.mPaged < right.mPaged)
|
|
|
|
return true;
|
|
|
|
if (left.mPaged > right.mPaged)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (left.mPaged)
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2015-07-17 20:49:10 +02:00
|
|
|
if (left.mIndex.mX < right.mIndex.mX)
|
|
|
|
return true;
|
|
|
|
if (left.mIndex.mX > right.mIndex.mX)
|
|
|
|
return false;
|
|
|
|
|
2014-02-23 21:39:18 +01:00
|
|
|
if (left.mIndex.mY < right.mIndex.mY)
|
2015-07-17 20:49:10 +02:00
|
|
|
return true;
|
2014-02-23 21:39:18 +01:00
|
|
|
if (left.mIndex.mY > right.mIndex.mY)
|
2015-07-17 20:49:10 +02:00
|
|
|
return false;
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
|
|
|
|
2015-07-17 20:49:10 +02:00
|
|
|
return left.mWorldspace < right.mWorldspace;
|
|
|
|
}
|
2022-04-12 00:18:39 +02:00
|
|
|
|
|
|
|
}
|