From ae6136816d44eddf58b151f7419281b0062eece3 Mon Sep 17 00:00:00 2001 From: Nicolay Korslund Date: Sat, 20 Feb 2010 21:55:51 +0100 Subject: [PATCH] Finished SPEL, added defs.hpp --- esm/defs.hpp | 60 ++++++++++++++++++++++++++++++++++++ esm/esm_reader.hpp | 9 ++++++ esm/loadbsgn.hpp | 2 +- esm/loadspel.hpp | 44 +++++--------------------- esm/tests/esmtool.cpp | 16 ++++++++++ old_d_version/esm/loadacti.d | 53 ------------------------------- old_d_version/esm/loadbsgn.d | 55 --------------------------------- old_d_version/esm/loadsoun.d | 54 -------------------------------- 8 files changed, 93 insertions(+), 200 deletions(-) create mode 100644 esm/defs.hpp delete mode 100644 old_d_version/esm/loadacti.d delete mode 100644 old_d_version/esm/loadbsgn.d delete mode 100644 old_d_version/esm/loadsoun.d diff --git a/esm/defs.hpp b/esm/defs.hpp new file mode 100644 index 0000000000..9f89add7b7 --- /dev/null +++ b/esm/defs.hpp @@ -0,0 +1,60 @@ +#ifndef _ESM_DEFS_H +#define _ESM_DEFS_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. +*/ +struct SpellList +{ + std::vector list; + + void load(ESMReader &esm) + { + while(esm.isNextSub("NPCS")) + list.push_back(esm.getHString()); + } +}; + +/** Defines a spell effect. Shared between SPEL (Spells), ALCH + (Potions) and ENCH (Item enchantments) records +*/ +#pragma pack(push) +#pragma pack(1) +struct ENAMstruct +{ + // Magical effect, hard-coded ID + short effectID; + + // Which skills/attributes are affected (for restore/drain spells + // etc.) + char skill, attribute; // -1 if N/A + + // Other spell parameters + int range; // 0 - self, 1 - touch, 2 - target + int area, duration, magnMin, magnMax; + + // Struct size should be 24 bytes +}; +#pragma pack(pop) + +struct EffectList +{ + std::vector list; + + void load(ESMReader &esm) + { + ENAMstruct s; + while(esm.isNextSub("ENAM")) + { + esm.getHT(s, 24); + list.push_back(s); + } + } +}; + +} +#endif diff --git a/esm/esm_reader.hpp b/esm/esm_reader.hpp index 52486d6853..7ab313e6d7 100644 --- a/esm/esm_reader.hpp +++ b/esm/esm_reader.hpp @@ -279,6 +279,15 @@ public: getT(x); } + // Version with extra size checking, to make sure the compiler + // doesn't mess up our struct padding. + template + void getHT(X &x, int size) + { + assert(sizeof(X) == size); + getHT(x); + } + // Read a string by the given name if it is the next record. std::string getHNOString(const char* name) { diff --git a/esm/loadbsgn.hpp b/esm/loadbsgn.hpp index bab39ff84e..8c713e5ef8 100644 --- a/esm/loadbsgn.hpp +++ b/esm/loadbsgn.hpp @@ -1,8 +1,8 @@ #ifndef _ESM_BSGN_H #define _ESM_BSGN_H +#include "defs.hpp" #include "esm_reader.hpp" -#include "loadspel.hpp" namespace ESM { diff --git a/esm/loadspel.hpp b/esm/loadspel.hpp index 4e30b851c2..be1ebc2a4a 100644 --- a/esm/loadspel.hpp +++ b/esm/loadspel.hpp @@ -5,25 +5,6 @@ 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 @@ -51,26 +32,15 @@ struct Spell }; 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); - } - }} - -} - */ + void load(ESMReader &esm) + { + name = esm.getHNOString("FNAM"); + esm.getHNT(data, "SPDT", 12); + effects.load(esm); + } +}; } #endif diff --git a/esm/tests/esmtool.cpp b/esm/tests/esmtool.cpp index f5f77a0ea3..860c5381a6 100644 --- a/esm/tests/esmtool.cpp +++ b/esm/tests/esmtool.cpp @@ -64,6 +64,15 @@ int main(int argc, char**argv) switch(n.val) { + case REC_ACTI: + { + Activator ac; + ac.load(esm); + cout << " Name: " << ac.name << endl; + cout << " Mesh: " << ac.model << endl; + cout << " Script: " << ac.script << endl; + break; + } case REC_ARMO: { Armor am; @@ -113,6 +122,13 @@ int main(int argc, char**argv) cout << " Volume: " << (int)d.data.volume << endl; break; } + case REC_SPEL: + { + Spell s; + s.load(esm); + cout << " Name: " << s.name << endl; + break; + } default: cout << " Skipping\n"; esm.skipRecord(); diff --git a/old_d_version/esm/loadacti.d b/old_d_version/esm/loadacti.d deleted file mode 100644 index 1bed2a7390..0000000000 --- a/old_d_version/esm/loadacti.d +++ /dev/null @@ -1,53 +0,0 @@ -/* - OpenMW - The completely unofficial reimplementation of Morrowind - Copyright (C) 2008 Nicolay Korslund - Email: < korslund@gmail.com > - WWW: http://openmw.snaptoad.com/ - - This file (loadacti.d) is part of the OpenMW package. - - OpenMW is distributed as free software: you can redistribute it - and/or modify it under the terms of the GNU General Public License - version 3, as published by the Free Software Foundation. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - version 3 along with this program. If not, see - http://www.gnu.org/licenses/ . - - */ - -module esm.loadacti; - -import esm.imports; - -/* - * Activator - * - * Activators are static in-world objects that pop up a caption when - * you stand close and look at them, for example signs. Some - * activators have scrips, such as beds that let you sleep when you - * activate them. - */ - -struct Activator -{ - mixin LoadT; - - Script *script; - MeshIndex model; - - void load() - {with(esFile){ - model = getMesh(); - name = getHNString("FNAM"); - script = getHNOPtr!(Script)("SCRI", scripts); - - makeProto(); - }} -} -ListID!(Activator) activators; diff --git a/old_d_version/esm/loadbsgn.d b/old_d_version/esm/loadbsgn.d deleted file mode 100644 index f026378827..0000000000 --- a/old_d_version/esm/loadbsgn.d +++ /dev/null @@ -1,55 +0,0 @@ -/* - OpenMW - The completely unofficial reimplementation of Morrowind - Copyright (C) 2008 Nicolay Korslund - Email: < korslund@gmail.com > - WWW: http://openmw.snaptoad.com/ - - This file (loadbsgn.d) is part of the OpenMW package. - - OpenMW is distributed as free software: you can redistribute it - and/or modify it under the terms of the GNU General Public License - version 3, as published by the Free Software Foundation. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - version 3 along with this program. If not, see - http://www.gnu.org/licenses/ . - - */ - -module esm.loadbsgn; -import esm.imports; - -/* - * Birth signs - */ - -struct BirthSign -{ - char[] description; - - mixin LoadT; - - TextureIndex texture; - - // List of powers and abilities that come with this birth sign. - SpellList powers; - - void load() - {with(esFile){ - name = getHNString("FNAM"); - - texture = getOTexture(); - - description = getHNOString("DESC"); - - powers.load(); - - // No monster class equivalent yet - }} -} -ListID!(BirthSign) birthSigns; diff --git a/old_d_version/esm/loadsoun.d b/old_d_version/esm/loadsoun.d deleted file mode 100644 index e06f917cf3..0000000000 --- a/old_d_version/esm/loadsoun.d +++ /dev/null @@ -1,54 +0,0 @@ -/* - OpenMW - The completely unofficial reimplementation of Morrowind - Copyright (C) 2008 Nicolay Korslund - Email: < korslund@gmail.com > - WWW: http://openmw.snaptoad.com/ - - This file (loadsoun.d) is part of the OpenMW package. - - OpenMW is distributed as free software: you can redistribute it - and/or modify it under the terms of the GNU General Public License - version 3, as published by the Free Software Foundation. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - version 3 along with this program. If not, see - http://www.gnu.org/licenses/ . - - */ - -module esm.loadsoun; - -import esm.imports; - -/* - * Sounds - */ - -align(1) struct SOUNstruct -{ - ubyte volume, minRange, maxRange; -} -static assert(SOUNstruct.sizeof == 3); - -struct Sound -{ - LoadState state; - char[] id; - - SOUNstruct data; - - SoundIndex sound; - - void load() - { - sound = esFile.getSound(); - esFile.readHNExact(&data, data.sizeof, "DATA"); - } -} - -ListID!(Sound) sounds;