diff --git a/esm/esm_reader.hpp b/esm/esm_reader.hpp index 40e65527c..52486d685 100644 --- a/esm/esm_reader.hpp +++ b/esm/esm_reader.hpp @@ -14,6 +14,8 @@ #include "../mangle/tools/str_exception.h" #include "../tools/stringops.h" +namespace ESM { + /* A structure used for holding fixed-length strings. In the case of LEN=4, it can be more efficient to match the string as a 32 bit number, therefore the struct is implemented as a union with an int. @@ -532,5 +534,5 @@ private: MasterList masters; int spf; // Special file signifier (see SpecialFile below) }; - +} #endif diff --git a/esm/loadacti.hpp b/esm/loadacti.hpp new file mode 100644 index 000000000..a50a58f6d --- /dev/null +++ b/esm/loadacti.hpp @@ -0,0 +1,20 @@ +#ifndef _ESM_ACTI_H +#define _ESM_ACTI_H + +#include "esm_reader.hpp" + +namespace ESM { + +struct Activator +{ + std::string name, script, model; + + void load(ESMReader &esm) + { + model = esm.getHNString("MODL"); + name = esm.getHNString("FNAM"); + script = esm.getHNOString("SCRI"); + } +}; +} +#endif diff --git a/esm/loadarmo.hpp b/esm/loadarmo.hpp index 1e065f3e8..087d4ea52 100644 --- a/esm/loadarmo.hpp +++ b/esm/loadarmo.hpp @@ -3,6 +3,8 @@ #include "esm_reader.hpp" +namespace ESM { + enum PartReferenceType { PRT_Head = 0, @@ -98,5 +100,5 @@ struct Armor enchant = esm.getHNOString("ENAM"); } }; - +} #endif diff --git a/esm/loadbody.hpp b/esm/loadbody.hpp index 8b6a1e6ab..5da0e6acb 100644 --- a/esm/loadbody.hpp +++ b/esm/loadbody.hpp @@ -3,6 +3,8 @@ #include "esm_reader.hpp" +namespace ESM { + struct BodyPart { enum MeshPart @@ -55,5 +57,5 @@ struct BodyPart esm.getHNT(data, "BYDT", 4); } }; - +} #endif diff --git a/esm/loadbsgn.hpp b/esm/loadbsgn.hpp index e1b5f5ff7..bab39ff84 100644 --- a/esm/loadbsgn.hpp +++ b/esm/loadbsgn.hpp @@ -2,14 +2,16 @@ #define _ESM_BSGN_H #include "esm_reader.hpp" -//#include "loadspel.hpp" +#include "loadspel.hpp" + +namespace ESM { struct BirthSign { std::string name, description, texture; // List of powers and abilities that come with this birth sign. - //SpellList powers; + SpellList powers; void load(ESMReader &esm) { @@ -17,8 +19,8 @@ struct BirthSign texture = esm.getHNOString("TNAM"); description = esm.getHNOString("DESC"); - //powers.load(esm); + powers.load(esm); }; }; - +} #endif diff --git a/esm/loaddoor.hpp b/esm/loaddoor.hpp index 657163ae1..7d76f20c8 100644 --- a/esm/loaddoor.hpp +++ b/esm/loaddoor.hpp @@ -3,6 +3,8 @@ #include "esm_reader.hpp" +namespace ESM { + struct Door { std::string name, model, script, openSound, closeSound; @@ -16,4 +18,5 @@ struct Door closeSound = esm.getHNOString("ANAM"); } }; +} #endif diff --git a/esm/loadsoun.hpp b/esm/loadsoun.hpp index 355a8685e..12495a015 100644 --- a/esm/loadsoun.hpp +++ b/esm/loadsoun.hpp @@ -3,6 +3,8 @@ #include "esm_reader.hpp" +namespace ESM { + struct SOUNstruct { unsigned char volume, minRange, maxRange; @@ -19,4 +21,5 @@ struct Sound esm.getHNT(data, "DATA", 3); } }; +} #endif diff --git a/esm/loadspel.hpp b/esm/loadspel.hpp new file mode 100644 index 000000000..4e30b851c --- /dev/null +++ b/esm/loadspel.hpp @@ -0,0 +1,76 @@ +#ifndef _ESM_SPEL_H +#define _ESM_SPEL_H + +#include "esm_reader.hpp" + +namespace ESM { + +/** A list of references to spells and spell effects. This is shared + between the records BSGN, NPC and RACE. + + TODO: This should also be part of a shared definition file + */ +struct SpellList +{ + std::vector list; + + void load(ESMReader &esm) + { + while(esm.isNextSub("NPCS")) + list.push_back(esm.getHString()); + } +}; + + /* TODO: Not completely ported yet - depends on EffectList, which + should be defined in a shared definition file. + +struct Spell +{ + enum SpellType + { + ST_Spell = 0, // Normal spell, must be cast and costs mana + ST_Ability = 1, // Inert ability, always in effect + ST_Blight = 2, // Blight disease + ST_Disease = 3, // Common disease + ST_Curse = 4, // Curse (?) + ST_Power = 5 // Power, can use once a day + }; + + enum Flags + { + F_Autocalc = 1, + F_PCStart = 2, + F_Always = 4 // Casting always succeeds + }; + + struct SPDTstruct + { + int type; // SpellType + int cost; // Mana cost + int flags; // Flags + }; + + SPDTstruct data; + + std::string name; + + EffectList effects; + + void load() + {with(esFile){ + name = getHNOString("FNAM"); + getHNT(data, "SPDT", 12); + + effects = getRegion().getBuffer!(ENAMstruct)(0,1); + + while(isNextSub("ENAM")) + { + effects.length = effects.length + 1; + readHExact(&effects.array[$-1], effects.array[$-1].sizeof); + } + }} + +} + */ +} +#endif diff --git a/esm/records.hpp b/esm/records.hpp index a2c4e3463..499f1d90f 100644 --- a/esm/records.hpp +++ b/esm/records.hpp @@ -1,11 +1,15 @@ #ifndef _ESM_RECORDS_H #define _ESM_RECORDS_H +#include "loadacti.hpp" #include "loadarmo.hpp" #include "loadbody.hpp" #include "loadbsgn.hpp" #include "loaddoor.hpp" #include "loadsoun.hpp" +#include "loadspel.hpp" + +namespace ESM { // Integer versions of all the record names, used for faster lookup enum RecNameInts @@ -53,5 +57,5 @@ enum RecNameInts REC_STAT = 0x54415453, REC_WEAP = 0x50414557 }; - +} #endif diff --git a/esm/tests/esmtool.cpp b/esm/tests/esmtool.cpp index 30198cf1b..f5f77a0ea 100644 --- a/esm/tests/esmtool.cpp +++ b/esm/tests/esmtool.cpp @@ -4,7 +4,9 @@ #include "esmtool_cmd.h" #include + using namespace std; +using namespace ESM; void printRaw(ESMReader &esm); @@ -83,8 +85,36 @@ int main(int argc, char**argv) cout << " Mesh: " << bp.model << endl; break; } + case REC_BSGN: + { + BirthSign bs; + bs.load(esm); + cout << " Name: " << bs.name << endl; + cout << " Texture: " << bs.texture << endl; + cout << " Description: " << bs.description << endl; + break; + } + case REC_DOOR: + { + Door d; + d.load(esm); + cout << " Name: " << d.name << endl; + cout << " Mesh: " << d.model << endl; + cout << " Script: " << d.script << endl; + cout << " OpenSound: " << d.openSound << endl; + cout << " CloseSound: " << d.closeSound << endl; + break; + } + case REC_SOUN: + { + Sound d; + d.load(esm); + cout << " Sound: " << d.sound << endl; + cout << " Volume: " << (int)d.data.volume << endl; + break; + } default: - //cout << " Skipping\n"; + cout << " Skipping\n"; esm.skipRecord(); } }