From f3c79c0aa0c831d85c28630d2eadcde3d35987fe Mon Sep 17 00:00:00 2001 From: scrawl Date: Fri, 30 Jan 2015 22:56:03 +0100 Subject: [PATCH] ESSImport: convert player DrawState, cleanup --- apps/essimporter/CMakeLists.txt | 1 + apps/essimporter/converter.hpp | 22 ++----------------- apps/essimporter/convertplayer.cpp | 34 ++++++++++++++++++++++++++++++ apps/essimporter/convertplayer.hpp | 15 +++++++++++++ apps/essimporter/importplayer.hpp | 9 +++++++- 5 files changed, 60 insertions(+), 21 deletions(-) create mode 100644 apps/essimporter/convertplayer.cpp create mode 100644 apps/essimporter/convertplayer.hpp diff --git a/apps/essimporter/CMakeLists.txt b/apps/essimporter/CMakeLists.txt index 76fc9aa94a..72ef364ee6 100644 --- a/apps/essimporter/CMakeLists.txt +++ b/apps/essimporter/CMakeLists.txt @@ -25,6 +25,7 @@ set(ESSIMPORTER_FILES convertcntc.cpp convertscri.cpp convertscpt.cpp + convertplayer.cpp ) add_executable(openmw-essimporter diff --git a/apps/essimporter/converter.hpp b/apps/essimporter/converter.hpp index 886983aab3..bbafd5ba95 100644 --- a/apps/essimporter/converter.hpp +++ b/apps/essimporter/converter.hpp @@ -35,6 +35,7 @@ #include "convertacdt.hpp" #include "convertnpcc.hpp" #include "convertscpt.hpp" +#include "convertplayer.hpp" namespace ESSImport { @@ -265,26 +266,7 @@ public: PCDT pcdt; pcdt.load(esm); - mContext->mPlayer.mBirthsign = pcdt.mBirthsign; - mContext->mPlayer.mObject.mNpcStats.mBounty = pcdt.mBounty; - for (std::vector::const_iterator it = pcdt.mFactions.begin(); it != pcdt.mFactions.end(); ++it) - { - ESM::NpcStats::Faction faction; - faction.mExpelled = (it->mFlags & 0x2) != 0; - faction.mRank = it->mRank; - faction.mReputation = it->mReputation; - mContext->mPlayer.mObject.mNpcStats.mFactions[Misc::StringUtils::lowerCase(it->mFactionName.toString())] = faction; - } - for (int i=0; i<8; ++i) - mContext->mPlayer.mObject.mNpcStats.mSkillIncrease[i] = pcdt.mPNAM.mSkillIncreases[i]; - mContext->mPlayer.mObject.mNpcStats.mLevelProgress = pcdt.mPNAM.mLevelProgress; - - for (std::vector::const_iterator it = pcdt.mKnownDialogueTopics.begin(); - it != pcdt.mKnownDialogueTopics.end(); ++it) - { - mContext->mDialogueState.mKnownTopics.push_back(Misc::StringUtils::lowerCase(*it)); - } - + convertPCDT(pcdt, mContext->mPlayer, mContext->mDialogueState.mKnownTopics); } }; diff --git a/apps/essimporter/convertplayer.cpp b/apps/essimporter/convertplayer.cpp new file mode 100644 index 0000000000..fb225284ee --- /dev/null +++ b/apps/essimporter/convertplayer.cpp @@ -0,0 +1,34 @@ +#include "convertplayer.hpp" + +namespace ESSImport +{ + + void convertPCDT(const PCDT& pcdt, ESM::Player& out, std::vector& outDialogueTopics) + { + out.mBirthsign = pcdt.mBirthsign; + out.mObject.mNpcStats.mBounty = pcdt.mBounty; + for (std::vector::const_iterator it = pcdt.mFactions.begin(); it != pcdt.mFactions.end(); ++it) + { + ESM::NpcStats::Faction faction; + faction.mExpelled = (it->mFlags & 0x2) != 0; + faction.mRank = it->mRank; + faction.mReputation = it->mReputation; + out.mObject.mNpcStats.mFactions[Misc::StringUtils::lowerCase(it->mFactionName.toString())] = faction; + } + for (int i=0; i<8; ++i) + out.mObject.mNpcStats.mSkillIncrease[i] = pcdt.mPNAM.mSkillIncreases[i]; + out.mObject.mNpcStats.mLevelProgress = pcdt.mPNAM.mLevelProgress; + + if (pcdt.mPNAM.mDrawState & PCDT::DrawState_Weapon) + out.mObject.mCreatureStats.mDrawState = 1; + if (pcdt.mPNAM.mDrawState & PCDT::DrawState_Spell) + out.mObject.mCreatureStats.mDrawState = 2; + + for (std::vector::const_iterator it = pcdt.mKnownDialogueTopics.begin(); + it != pcdt.mKnownDialogueTopics.end(); ++it) + { + outDialogueTopics.push_back(Misc::StringUtils::lowerCase(*it)); + } + } + +} diff --git a/apps/essimporter/convertplayer.hpp b/apps/essimporter/convertplayer.hpp new file mode 100644 index 0000000000..a4541c7aa8 --- /dev/null +++ b/apps/essimporter/convertplayer.hpp @@ -0,0 +1,15 @@ +#ifndef OPENMW_ESSIMPORT_CONVERTPLAYER_H +#define OPENMW_ESSIMPORT_CONVERTPLAYER_H + +#include "importplayer.hpp" + +#include + +namespace ESSImport +{ + + void convertPCDT(const PCDT& pcdt, ESM::Player& out, std::vector& outDialogueTopics); + +} + +#endif diff --git a/apps/essimporter/importplayer.hpp b/apps/essimporter/importplayer.hpp index 64ceddfd79..fb2cb95fd0 100644 --- a/apps/essimporter/importplayer.hpp +++ b/apps/essimporter/importplayer.hpp @@ -38,6 +38,12 @@ struct PCDT std::vector mKnownDialogueTopics; + enum DrawState_ + { + DrawState_Weapon = 0x80, + DrawState_Spell = 0x100 + }; + #pragma pack(push) #pragma pack(1) struct FNAM @@ -49,9 +55,10 @@ struct PCDT unsigned char mUnknown2[3]; ESM::NAME32 mFactionName; }; + struct PNAM { - unsigned char mUnknown1[4]; + int mDrawState; // DrawState unsigned char mLevelProgress; unsigned char mUnknown2[111]; unsigned char mSkillIncreases[8]; // number of skill increases for each attribute