From 5d4dba981fa56f1cf43c0a68f537401e9d9618e3 Mon Sep 17 00:00:00 2001 From: Nicolay Korslund Date: Fri, 13 Aug 2010 15:51:42 +0200 Subject: [PATCH] Fixed mistake in NPC record struct --- CMakeLists.txt | 7 ++++-- components/esm/load_impl.cpp | 48 ++++++++++++++++++++++++++++++++++++ components/esm/loadnpc.hpp | 45 ++++----------------------------- 3 files changed, 58 insertions(+), 42 deletions(-) create mode 100644 components/esm/load_impl.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 97f8ba6b3..f362f450c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,7 +48,10 @@ set(ESM_STORE_HEADER source_group(components\\esm_store FILES ${ESM_STORE} ${ESM_STORE_HEADER}) file(GLOB ESM_HEADER ${COMP_DIR}/esm/*.hpp) -source_group(components\\esm FILES ${ESM_HEADER}) +set(ESM + ${COMP_DIR}/esm/load_impl.cpp +) +source_group(components\\esm FILES ${ESM_HEADER} ${ESM}) set(MISC ${COMP_DIR}/misc/stringops.cpp @@ -68,7 +71,7 @@ file(GLOB INTERPRETER_HEADER ${COMP_DIR}/interpreter/*.hpp) source_group(components\\interpreter FILES ${INTERPRETER} ${INTERPRETER_HEADER}) set(COMPONENTS ${BSA} ${NIF} ${NIFOGRE} ${ESM_STORE} ${MISC} - ${COMPILER} ${INTERPRETER}) + ${COMPILER} ${INTERPRETER} ${ESM}) set(COMPONENTS_HEADER ${BSA_HEADER} ${NIF_HEADER} ${NIFOGRE_HEADER} ${ESM_STORE_HEADER} ${ESM_HEADER} ${MISC_HEADER} ${COMPILER_HEADER} ${INTERPRETER_HEADER}) diff --git a/components/esm/load_impl.cpp b/components/esm/load_impl.cpp new file mode 100644 index 000000000..28ae402de --- /dev/null +++ b/components/esm/load_impl.cpp @@ -0,0 +1,48 @@ +#include "records.hpp" + +/** Implementation for some of the load() functions. Most are found in + the header files themselves, but this is a bit irritating to + compile if you're changing the functions often, as virtually the + entire engine depends on these headers. + */ + +namespace ESM +{ + void NPC::load(ESMReader &esm, const std::string& id) + { + mId = id; + + npdt52.gold = -10; + + model = esm.getHNOString("MODL"); + name = esm.getHNOString("FNAM"); + + race = esm.getHNString("RNAM"); + cls = esm.getHNString("CNAM"); + faction = esm.getHNString("ANAM"); + head = esm.getHNString("BNAM"); + hair = esm.getHNString("KNAM"); + + script = esm.getHNOString("SCRI"); + + esm.getSubNameIs("NPDT"); + esm.getSubHeader(); + if(esm.getSubSize() == 52) esm.getExact(&npdt52, 52); + else if(esm.getSubSize() == 12) esm.getExact(&npdt12, 12); + else esm.fail("NPC_NPDT must be 12 or 52 bytes long"); + + esm.getHNT(flags, "FLAG"); + + inventory.load(esm); + spells.load(esm); + + if(esm.isNextSub("AIDT")) + { + esm.getHExact(&AI, sizeof(AI)); + hasAI = true; + } + else hasAI = false; + + esm.skipRecord(); + } +} diff --git a/components/esm/loadnpc.hpp b/components/esm/loadnpc.hpp index 61618c731..a699c1cdb 100644 --- a/components/esm/loadnpc.hpp +++ b/components/esm/loadnpc.hpp @@ -57,10 +57,10 @@ struct NPC char strength, intelligence, willpower, agility, speed, endurance, personality, luck; char skills[27]; + char reputation; short health, mana, fatigue; - char disposition; - char reputation; // Was "factionID", but that makes no sense. - char rank, unknown, u2; + char disposition, factionID, rank; + char unknown; int gold; }; // 52 bytes @@ -99,43 +99,8 @@ struct NPC std::string mId; - void load(ESMReader &esm, const std::string& id) - { - mId = id; - - npdt52.gold = -10; - - model = esm.getHNOString("MODL"); - name = esm.getHNOString("FNAM"); - - race = esm.getHNString("RNAM"); - cls = esm.getHNString("CNAM"); - faction = esm.getHNString("ANAM"); - head = esm.getHNString("BNAM"); - hair = esm.getHNString("KNAM"); - - script = esm.getHNOString("SCRI"); - - esm.getSubNameIs("NPDT"); - esm.getSubHeader(); - if(esm.getSubSize() == 52) esm.getExact(&npdt52, 52); - else if(esm.getSubSize() == 12) esm.getExact(&npdt12, 12); - else esm.fail("NPC_NPDT must be 12 or 52 bytes long"); - - esm.getHNT(flags, "FLAG"); - - inventory.load(esm); - spells.load(esm); - - if(esm.isNextSub("AIDT")) - { - esm.getHExact(&AI, sizeof(AI)); - hasAI = true; - } - else hasAI = false; - - esm.skipRecord(); - } + // Implementation moved to load_impl.cpp + void load(ESMReader &esm, const std::string& id); }; } #endif