1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-16 17:59:56 +00:00
openmw/components/esm3/player.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

113 lines
3.4 KiB
C++
Raw Normal View History

#include "player.hpp"
#include "esmreader.hpp"
#include "esmwriter.hpp"
namespace ESM
{
void Player::load(ESMReader& esm)
{
mObject.mRef.loadId(esm, true);
mObject.load(esm);
2023-02-21 22:26:40 +00:00
mCellId = esm.getCellId();
2023-12-17 12:00:14 +00:00
esm.getHNT("LKEP", mLastKnownExteriorPosition);
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();
// Automove, no longer used.
if (esm.isNextSub("AMOV"))
esm.skipHSub();
mBirthsign = esm.getHNRefId("SIGN");
mCurrentCrimeId = -1;
esm.getHNOT(mCurrentCrimeId, "CURD");
2014-05-03 10:23:22 +00:00
mPaidCrimeId = -1;
esm.getHNOT(mPaidCrimeId, "PAYD");
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
}
if (esm.getFormatVersion() <= MaxOldSkillsAndAttributesFormatVersion)
{
const bool intFallback = esm.getFormatVersion() <= MaxIntFallbackFormatVersion;
const bool clearModified
= esm.getFormatVersion() <= MaxClearModifiersFormatVersion && !mObject.mNpcStats.mIsWerewolf;
if (esm.hasMoreSubs())
{
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
{
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)
{
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)
mSetWerewolfAcrobatics = mObject.mNpcStats.mSkills[i].mBase != skill.mBase;
mObject.mNpcStats.mSkills[i] = skill;
2022-09-22 18:26:05 +00:00
}
}
}
}
2022-09-22 18:26:05 +00:00
else
{
mSetWerewolfAcrobatics = false;
esm.getHNT(mSaveAttributes, "WWAT");
esm.getHNT(mSaveSkills, "WWSK");
2022-09-22 18:26:05 +00:00
}
}
2022-09-22 18:26:05 +00:00
void Player::save(ESMWriter& esm) const
{
mObject.save(esm);
2023-02-21 22:26:40 +00:00
esm.writeCellId(mCellId);
esm.writeHNT("LKEP", mLastKnownExteriorPosition);
if (mHasMark)
2022-09-22 18:26:05 +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
}
esm.writeHNRefId("SIGN", mBirthsign);
esm.writeHNT("CURD", mCurrentCrimeId);
2014-05-03 10:23:22 +00:00
esm.writeHNT("PAYD", mPaidCrimeId);
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
}
2018-03-09 06:20:17 +00:00
esm.writeHNT("WWAT", mSaveAttributes);
esm.writeHNT("WWSK", mSaveSkills);
}
}