2014-01-14 11:25:35 +00:00
|
|
|
#include "player.hpp"
|
|
|
|
|
|
|
|
#include "esmreader.hpp"
|
|
|
|
#include "esmwriter.hpp"
|
|
|
|
|
2022-04-11 22:18:39 +00:00
|
|
|
namespace ESM
|
|
|
|
{
|
|
|
|
|
|
|
|
void Player::load(ESMReader& esm)
|
2014-01-14 11:25:35 +00:00
|
|
|
{
|
2015-01-19 22:29:06 +00:00
|
|
|
mObject.mRef.loadId(esm, true);
|
2014-01-14 11:25:35 +00:00
|
|
|
mObject.load(esm);
|
|
|
|
|
2023-02-21 22:26:40 +00:00
|
|
|
mCellId = esm.getCellId();
|
2014-01-14 11:25:35 +00:00
|
|
|
|
2023-12-17 12:00:14 +00:00
|
|
|
esm.getHNT("LKEP", mLastKnownExteriorPosition);
|
2014-01-14 11:25:35 +00:00
|
|
|
|
2024-02-27 19:47:46 +00:00
|
|
|
mHasMark = esm.getOptionalComposite("MARK", mMarkedPosition);
|
2023-12-20 11:28:34 +00:00
|
|
|
if (mHasMark)
|
2023-02-21 22:26:40 +00:00
|
|
|
mMarkedCell = esm.getCellId();
|
2014-01-14 11:25:35 +00:00
|
|
|
|
2020-06-06 12:45:48 +00:00
|
|
|
// Automove, no longer used.
|
|
|
|
if (esm.isNextSub("AMOV"))
|
|
|
|
esm.skipHSub();
|
2014-01-17 09:51:52 +00:00
|
|
|
|
2023-02-12 18:36:56 +00:00
|
|
|
mBirthsign = esm.getHNRefId("SIGN");
|
2014-04-06 02:45:40 +00:00
|
|
|
|
2014-04-20 17:34:58 +00:00
|
|
|
mCurrentCrimeId = -1;
|
2014-04-18 10:34:12 +00:00
|
|
|
esm.getHNOT(mCurrentCrimeId, "CURD");
|
2014-05-03 10:23:22 +00:00
|
|
|
mPaidCrimeId = -1;
|
|
|
|
esm.getHNOT(mPaidCrimeId, "PAYD");
|
2015-06-21 15:36:11 +00:00
|
|
|
|
2024-01-06 13:59:22 +00:00
|
|
|
while (esm.peekNextSub("BOUN"))
|
2018-03-09 06:20:17 +00:00
|
|
|
{
|
2024-01-06 13:59:22 +00:00
|
|
|
ESM::RefId boundItemId = esm.getHNRefId("BOUN");
|
|
|
|
ESM::RefId prevItemId = esm.getHNRefId("PREV");
|
2018-03-09 06:20:17 +00:00
|
|
|
|
2024-01-06 13:59:22 +00:00
|
|
|
mPreviousItems[boundItemId] = prevItemId;
|
2018-03-09 06:20:17 +00:00
|
|
|
}
|
|
|
|
|
2023-02-10 12:16:52 +00:00
|
|
|
if (esm.getFormatVersion() <= MaxOldSkillsAndAttributesFormatVersion)
|
2021-12-26 23:47:33 +00:00
|
|
|
{
|
2023-02-10 12:16:52 +00:00
|
|
|
const bool intFallback = esm.getFormatVersion() <= MaxIntFallbackFormatVersion;
|
|
|
|
const bool clearModified
|
|
|
|
= esm.getFormatVersion() <= MaxClearModifiersFormatVersion && !mObject.mNpcStats.mIsWerewolf;
|
2022-04-11 22:18:39 +00:00
|
|
|
if (esm.hasMoreSubs())
|
2021-12-26 23:47:33 +00:00
|
|
|
{
|
2023-07-17 17:37:28 +00:00
|
|
|
for (size_t i = 0; i < std::size(mSaveAttributes); ++i)
|
2022-09-22 18:26:05 +00:00
|
|
|
{
|
2021-12-26 23:47:33 +00:00
|
|
|
StatState<float> attribute;
|
|
|
|
attribute.load(esm, intFallback);
|
|
|
|
if (clearModified)
|
|
|
|
attribute.mMod = 0.f;
|
|
|
|
mSaveAttributes[i] = attribute.mBase + attribute.mMod - attribute.mDamage;
|
|
|
|
if (mObject.mNpcStats.mIsWerewolf)
|
|
|
|
mObject.mCreatureStats.mAttributes[i] = attribute;
|
|
|
|
}
|
2023-07-17 17:37:28 +00:00
|
|
|
for (size_t i = 0; i < std::size(mSaveSkills); ++i)
|
2021-12-26 23:47:33 +00:00
|
|
|
{
|
|
|
|
StatState<float> skill;
|
|
|
|
skill.load(esm, intFallback);
|
|
|
|
if (clearModified)
|
|
|
|
skill.mMod = 0.f;
|
|
|
|
mSaveSkills[i] = skill.mBase + skill.mMod - skill.mDamage;
|
|
|
|
if (mObject.mNpcStats.mIsWerewolf)
|
2022-09-22 18:26:05 +00:00
|
|
|
{
|
2023-06-06 15:24:22 +00:00
|
|
|
constexpr int Acrobatics = 20;
|
|
|
|
if (i == Acrobatics)
|
2021-12-26 23:47:33 +00:00
|
|
|
mSetWerewolfAcrobatics = mObject.mNpcStats.mSkills[i].mBase != skill.mBase;
|
|
|
|
mObject.mNpcStats.mSkills[i] = skill;
|
2022-09-22 18:26:05 +00:00
|
|
|
}
|
2021-12-26 23:47:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-09-22 18:26:05 +00:00
|
|
|
else
|
|
|
|
{
|
2021-12-26 23:47:33 +00:00
|
|
|
mSetWerewolfAcrobatics = false;
|
|
|
|
esm.getHNT(mSaveAttributes, "WWAT");
|
|
|
|
esm.getHNT(mSaveSkills, "WWSK");
|
2022-09-22 18:26:05 +00:00
|
|
|
}
|
2021-12-26 23:47:33 +00:00
|
|
|
}
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2021-12-26 23:47:33 +00:00
|
|
|
void Player::save(ESMWriter& esm) const
|
|
|
|
{
|
|
|
|
mObject.save(esm);
|
2014-01-14 11:25:35 +00:00
|
|
|
|
2023-02-21 22:26:40 +00:00
|
|
|
esm.writeCellId(mCellId);
|
2014-01-14 11:25:35 +00:00
|
|
|
|
|
|
|
esm.writeHNT("LKEP", mLastKnownExteriorPosition);
|
|
|
|
|
2019-10-06 11:19:55 +00:00
|
|
|
if (mHasMark)
|
2022-09-22 18:26:05 +00:00
|
|
|
{
|
2024-02-27 19:47:46 +00:00
|
|
|
esm.writeNamedComposite("MARK", mMarkedPosition);
|
2023-02-21 22:26:40 +00:00
|
|
|
esm.writeCellId(mMarkedCell);
|
2022-09-22 18:26:05 +00:00
|
|
|
}
|
2014-01-14 11:25:35 +00:00
|
|
|
|
2023-02-12 18:36:56 +00:00
|
|
|
esm.writeHNRefId("SIGN", mBirthsign);
|
2014-01-14 11:25:35 +00:00
|
|
|
|
2014-01-17 09:51:52 +00:00
|
|
|
esm.writeHNT("CURD", mCurrentCrimeId);
|
2014-05-03 10:23:22 +00:00
|
|
|
esm.writeHNT("PAYD", mPaidCrimeId);
|
2014-04-06 02:45:40 +00:00
|
|
|
|
2024-01-06 13:59:22 +00:00
|
|
|
for (const auto& [bound, prev] : mPreviousItems)
|
2022-09-22 18:26:05 +00:00
|
|
|
{
|
2024-01-06 13:59:22 +00:00
|
|
|
esm.writeHNRefId("BOUN", bound);
|
|
|
|
esm.writeHNRefId("PREV", prev);
|
2022-09-22 18:26:05 +00:00
|
|
|
}
|
2015-06-21 15:36:11 +00:00
|
|
|
|
2018-03-09 06:20:17 +00:00
|
|
|
esm.writeHNT("WWAT", mSaveAttributes);
|
|
|
|
esm.writeHNT("WWSK", mSaveSkills);
|
|
|
|
}
|
|
|
|
|
2022-04-11 22:18:39 +00:00
|
|
|
}
|