1 #include "convertplayer.hpp"
2 
3 #include <components/misc/constants.hpp>
4 #include <components/misc/stringops.hpp>
5 
6 namespace ESSImport
7 {
8 
convertPCDT(const PCDT & pcdt,ESM::Player & out,std::vector<std::string> & outDialogueTopics,bool & firstPersonCam,bool & teleportingEnabled,bool & levitationEnabled,ESM::ControlsState & controls)9     void convertPCDT(const PCDT& pcdt, ESM::Player& out, std::vector<std::string>& outDialogueTopics, bool& firstPersonCam, bool& teleportingEnabled, bool& levitationEnabled, ESM::ControlsState& controls)
10     {
11         out.mBirthsign = pcdt.mBirthsign;
12         out.mObject.mNpcStats.mBounty = pcdt.mBounty;
13         for (const auto & essFaction : pcdt.mFactions)
14         {
15             ESM::NpcStats::Faction faction;
16             faction.mExpelled = (essFaction.mFlags & 0x2) != 0;
17             faction.mRank = essFaction.mRank;
18             faction.mReputation = essFaction.mReputation;
19             out.mObject.mNpcStats.mFactions[Misc::StringUtils::lowerCase(essFaction.mFactionName.toString())] = faction;
20         }
21         for (int i=0; i<3; ++i)
22             out.mObject.mNpcStats.mSpecIncreases[i] = pcdt.mPNAM.mSpecIncreases[i];
23         for (int i=0; i<8; ++i)
24             out.mObject.mNpcStats.mSkillIncrease[i] = pcdt.mPNAM.mSkillIncreases[i];
25         for (int i=0; i<27; ++i)
26             out.mObject.mNpcStats.mSkills[i].mProgress = pcdt.mPNAM.mSkillProgress[i];
27         out.mObject.mNpcStats.mLevelProgress = pcdt.mPNAM.mLevelProgress;
28 
29         if (pcdt.mPNAM.mPlayerFlags & PCDT::PlayerFlags_WeaponDrawn)
30             out.mObject.mCreatureStats.mDrawState = 1;
31         if (pcdt.mPNAM.mPlayerFlags & PCDT::PlayerFlags_SpellDrawn)
32             out.mObject.mCreatureStats.mDrawState = 2;
33 
34         firstPersonCam = !(pcdt.mPNAM.mPlayerFlags & PCDT::PlayerFlags_ThirdPerson);
35         teleportingEnabled = !(pcdt.mPNAM.mPlayerFlags & PCDT::PlayerFlags_TeleportingDisabled);
36         levitationEnabled = !(pcdt.mPNAM.mPlayerFlags & PCDT::PlayerFlags_LevitationDisabled);
37 
38         for (const auto & knownDialogueTopic : pcdt.mKnownDialogueTopics)
39         {
40             outDialogueTopics.push_back(Misc::StringUtils::lowerCase(knownDialogueTopic));
41         }
42 
43         controls.mViewSwitchDisabled = pcdt.mPNAM.mPlayerFlags & PCDT::PlayerFlags_ViewSwitchDisabled;
44         controls.mControlsDisabled = pcdt.mPNAM.mPlayerFlags & PCDT::PlayerFlags_ControlsDisabled;
45         controls.mJumpingDisabled = pcdt.mPNAM.mPlayerFlags & PCDT::PlayerFlags_JumpingDisabled;
46         controls.mLookingDisabled = pcdt.mPNAM.mPlayerFlags & PCDT::PlayerFlags_LookingDisabled;
47         controls.mVanityModeDisabled = pcdt.mPNAM.mPlayerFlags & PCDT::PlayerFlags_VanityModeDisabled;
48         controls.mWeaponDrawingDisabled = pcdt.mPNAM.mPlayerFlags & PCDT::PlayerFlags_WeaponDrawingDisabled;
49         controls.mSpellDrawingDisabled = pcdt.mPNAM.mPlayerFlags & PCDT::PlayerFlags_SpellDrawingDisabled;
50 
51         if (pcdt.mHasMark)
52         {
53             out.mHasMark = 1;
54 
55             const PCDT::PNAM::MarkLocation& mark = pcdt.mPNAM.mMarkLocation;
56 
57             ESM::CellId cell;
58             cell.mWorldspace = ESM::CellId::sDefaultWorldspace;
59             cell.mPaged = true;
60 
61             cell.mIndex.mX = mark.mCellX;
62             cell.mIndex.mY = mark.mCellY;
63 
64             // TODO: Figure out a better way to detect interiors. (0, 0) is a valid exterior cell.
65             if (mark.mCellX == 0 && mark.mCellY == 0)
66             {
67                 cell.mWorldspace = pcdt.mMNAM;
68                 cell.mPaged = false;
69             }
70 
71             out.mMarkedCell = cell;
72             out.mMarkedPosition.pos[0] = mark.mX;
73             out.mMarkedPosition.pos[1] = mark.mY;
74             out.mMarkedPosition.pos[2] = mark.mZ;
75             out.mMarkedPosition.rot[0] = out.mMarkedPosition.rot[1] = 0.0f;
76             out.mMarkedPosition.rot[2] = mark.mRotZ;
77         }
78 
79         if (pcdt.mHasENAM)
80         {
81             out.mLastKnownExteriorPosition[0] = (pcdt.mENAM.mCellX + 0.5f) * Constants::CellSizeInUnits;
82             out.mLastKnownExteriorPosition[1] = (pcdt.mENAM.mCellY + 0.5f) * Constants::CellSizeInUnits;
83             out.mLastKnownExteriorPosition[2] = 0.0f;
84         }
85     }
86 
87 }
88