2015-01-30 21:56:03 +00:00
|
|
|
#include "convertplayer.hpp"
|
|
|
|
|
2022-07-30 12:14:46 +00:00
|
|
|
#include <cmath>
|
|
|
|
|
2023-02-22 14:57:59 +00:00
|
|
|
#include <components/esm3/loadcell.hpp>
|
2018-09-17 10:52:43 +00:00
|
|
|
#include <components/misc/constants.hpp>
|
2022-08-02 22:00:54 +00:00
|
|
|
#include <components/misc/strings/lower.hpp>
|
2015-07-07 17:16:32 +00:00
|
|
|
|
2015-01-30 21:56:03 +00:00
|
|
|
namespace ESSImport
|
|
|
|
{
|
|
|
|
|
2022-10-06 17:39:46 +00:00
|
|
|
void convertPCDT(const PCDT& pcdt, ESM::Player& out, std::vector<ESM::RefId>& outDialogueTopics,
|
2016-10-20 12:38:18 +00:00
|
|
|
bool& firstPersonCam, bool& teleportingEnabled, bool& levitationEnabled, ESM::ControlsState& controls)
|
2015-01-30 21:56:03 +00:00
|
|
|
{
|
2022-07-30 12:14:46 +00:00
|
|
|
out.mObject.mPosition.rot[0]
|
|
|
|
= -atan2(pcdt.mPNAM.mVerticalRotation.mData[2][1], pcdt.mPNAM.mVerticalRotation.mData[2][2]);
|
|
|
|
|
2022-10-06 17:39:46 +00:00
|
|
|
out.mBirthsign = ESM::RefId::stringRefId(pcdt.mBirthsign);
|
2015-01-30 21:56:03 +00:00
|
|
|
out.mObject.mNpcStats.mBounty = pcdt.mBounty;
|
2020-06-10 06:30:37 +00:00
|
|
|
for (const auto& essFaction : pcdt.mFactions)
|
2015-01-30 21:56:03 +00:00
|
|
|
{
|
|
|
|
ESM::NpcStats::Faction faction;
|
2020-06-10 06:30:37 +00:00
|
|
|
faction.mExpelled = (essFaction.mFlags & 0x2) != 0;
|
|
|
|
faction.mRank = essFaction.mRank;
|
|
|
|
faction.mReputation = essFaction.mReputation;
|
2022-10-06 17:39:46 +00:00
|
|
|
out.mObject.mNpcStats.mFactions[ESM::RefId::stringRefId(essFaction.mFactionName.toString())] = faction;
|
2015-01-30 21:56:03 +00:00
|
|
|
}
|
2023-06-03 12:26:37 +00:00
|
|
|
for (size_t i = 0; i < out.mObject.mNpcStats.mSpecIncreases.size(); ++i)
|
2016-06-26 01:28:13 +00:00
|
|
|
out.mObject.mNpcStats.mSpecIncreases[i] = pcdt.mPNAM.mSpecIncreases[i];
|
2023-06-03 12:26:37 +00:00
|
|
|
for (size_t i = 0; i < out.mObject.mNpcStats.mSkillIncrease.size(); ++i)
|
2015-01-30 21:56:03 +00:00
|
|
|
out.mObject.mNpcStats.mSkillIncrease[i] = pcdt.mPNAM.mSkillIncreases[i];
|
2023-06-03 12:26:37 +00:00
|
|
|
for (size_t i = 0; i < out.mObject.mNpcStats.mSkills.size(); ++i)
|
2015-06-21 20:15:35 +00:00
|
|
|
out.mObject.mNpcStats.mSkills[i].mProgress = pcdt.mPNAM.mSkillProgress[i];
|
2015-01-30 21:56:03 +00:00
|
|
|
out.mObject.mNpcStats.mLevelProgress = pcdt.mPNAM.mLevelProgress;
|
|
|
|
|
2016-10-20 00:14:36 +00:00
|
|
|
if (pcdt.mPNAM.mPlayerFlags & PCDT::PlayerFlags_WeaponDrawn)
|
2015-01-30 21:56:03 +00:00
|
|
|
out.mObject.mCreatureStats.mDrawState = 1;
|
2016-10-20 00:14:36 +00:00
|
|
|
if (pcdt.mPNAM.mPlayerFlags & PCDT::PlayerFlags_SpellDrawn)
|
2015-01-30 21:56:03 +00:00
|
|
|
out.mObject.mCreatureStats.mDrawState = 2;
|
|
|
|
|
2016-10-20 00:14:36 +00:00
|
|
|
firstPersonCam = !(pcdt.mPNAM.mPlayerFlags & PCDT::PlayerFlags_ThirdPerson);
|
2016-10-20 12:38:18 +00:00
|
|
|
teleportingEnabled = !(pcdt.mPNAM.mPlayerFlags & PCDT::PlayerFlags_TeleportingDisabled);
|
|
|
|
levitationEnabled = !(pcdt.mPNAM.mPlayerFlags & PCDT::PlayerFlags_LevitationDisabled);
|
2015-01-30 22:10:39 +00:00
|
|
|
|
2020-06-10 06:30:37 +00:00
|
|
|
for (const auto& knownDialogueTopic : pcdt.mKnownDialogueTopics)
|
2015-01-30 21:56:03 +00:00
|
|
|
{
|
2022-10-06 17:39:46 +00:00
|
|
|
outDialogueTopics.push_back(ESM::RefId::stringRefId(knownDialogueTopic));
|
2015-01-30 21:56:03 +00:00
|
|
|
}
|
2016-10-20 00:14:36 +00:00
|
|
|
|
|
|
|
controls.mViewSwitchDisabled = pcdt.mPNAM.mPlayerFlags & PCDT::PlayerFlags_ViewSwitchDisabled;
|
|
|
|
controls.mControlsDisabled = pcdt.mPNAM.mPlayerFlags & PCDT::PlayerFlags_ControlsDisabled;
|
|
|
|
controls.mJumpingDisabled = pcdt.mPNAM.mPlayerFlags & PCDT::PlayerFlags_JumpingDisabled;
|
|
|
|
controls.mLookingDisabled = pcdt.mPNAM.mPlayerFlags & PCDT::PlayerFlags_LookingDisabled;
|
|
|
|
controls.mVanityModeDisabled = pcdt.mPNAM.mPlayerFlags & PCDT::PlayerFlags_VanityModeDisabled;
|
|
|
|
controls.mWeaponDrawingDisabled = pcdt.mPNAM.mPlayerFlags & PCDT::PlayerFlags_WeaponDrawingDisabled;
|
|
|
|
controls.mSpellDrawingDisabled = pcdt.mPNAM.mPlayerFlags & PCDT::PlayerFlags_SpellDrawingDisabled;
|
2016-12-18 03:37:59 +00:00
|
|
|
|
|
|
|
if (pcdt.mHasMark)
|
|
|
|
{
|
|
|
|
out.mHasMark = 1;
|
|
|
|
|
|
|
|
const PCDT::PNAM::MarkLocation& mark = pcdt.mPNAM.mMarkLocation;
|
|
|
|
|
|
|
|
// TODO: Figure out a better way to detect interiors. (0, 0) is a valid exterior cell.
|
2023-02-22 22:20:15 +00:00
|
|
|
bool interior = mark.mCellX == 0 && mark.mCellY == 0;
|
|
|
|
ESM::RefId cell = ESM::Cell::generateIdForCell(!interior, pcdt.mMNAM, mark.mCellX, mark.mCellY);
|
2016-12-18 03:37:59 +00:00
|
|
|
|
2023-02-22 14:57:59 +00:00
|
|
|
out.mMarkedCell = cell;
|
2016-12-18 03:37:59 +00:00
|
|
|
out.mMarkedPosition.pos[0] = mark.mX;
|
|
|
|
out.mMarkedPosition.pos[1] = mark.mY;
|
|
|
|
out.mMarkedPosition.pos[2] = mark.mZ;
|
|
|
|
out.mMarkedPosition.rot[0] = out.mMarkedPosition.rot[1] = 0.0f;
|
|
|
|
out.mMarkedPosition.rot[2] = mark.mRotZ;
|
|
|
|
}
|
2016-12-24 17:30:39 +00:00
|
|
|
|
|
|
|
if (pcdt.mHasENAM)
|
|
|
|
{
|
2018-09-17 10:52:43 +00:00
|
|
|
out.mLastKnownExteriorPosition[0] = (pcdt.mENAM.mCellX + 0.5f) * Constants::CellSizeInUnits;
|
|
|
|
out.mLastKnownExteriorPosition[1] = (pcdt.mENAM.mCellY + 0.5f) * Constants::CellSizeInUnits;
|
2016-12-24 17:30:39 +00:00
|
|
|
out.mLastKnownExteriorPosition[2] = 0.0f;
|
|
|
|
}
|
2015-01-30 21:56:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|