diff --git a/components/esm/loadskil.hpp b/components/esm/loadskil.hpp index 0e5585ac6c..9ccde237d4 100644 --- a/components/esm/loadskil.hpp +++ b/components/esm/loadskil.hpp @@ -32,6 +32,7 @@ struct Skill void load(ESMReader &esm) { + esm.getHNT(index, "INDX"); esm.getHNT(data, "SKDT", 24); description = esm.getHNOString("DESC"); } diff --git a/components/esm_store/reclists.hpp b/components/esm_store/reclists.hpp index 81b0d60540..8b19b0cf12 100644 --- a/components/esm_store/reclists.hpp +++ b/components/esm_store/reclists.hpp @@ -308,12 +308,53 @@ namespace ESMS int getSize() { return list.size(); } }; + template + struct IndexListT + { + typedef std::map MapType; + + MapType list; + + void load(ESMReader &esm) + { + X ref; + ref.load (esm); + int index = ref.index; + list[index] = ref; + } + + int getSize() + { + return list.size(); + } + + // Find the given object ID, or return NULL if not found. + const X* search (int id) const + { + if (list.find (id) == list.end()) + return NULL; + + return &list.find(id)->second; + } + + // Find the given object ID (throws an exception if not found) + const X* find (int id) const + { + const X *object = search (id); + + if (!object) + { + std::ostringstream error; + error << "object " << id << " not found"; + throw std::runtime_error (error.str()); + } + + return object; + } + }; + /* We need special lists for: - Magic effects - Skills - Dialog / Info combo - Scripts Land Path grids Land textures diff --git a/components/esm_store/store.cpp b/components/esm_store/store.cpp index c43855873a..8204c63045 100644 --- a/components/esm_store/store.cpp +++ b/components/esm_store/store.cpp @@ -46,15 +46,21 @@ void ESMStore::load(ESMReader &esm) { std::cerr << "error: info record without dialog" << std::endl; esm.skipRecord(); - continue; } } + else if (n.val==ESM::REC_MGEF) + { + magicEffects.load (esm); + } + else if (n.val==ESM::REC_SKIL) + { + skills.load (esm); + } else { // Not found (this would be an error later) esm.skipRecord(); missing.insert(n.toString()); - continue; } } else diff --git a/components/esm_store/store.hpp b/components/esm_store/store.hpp index 1b9184aa61..b0f75785df 100644 --- a/components/esm_store/store.hpp +++ b/components/esm_store/store.hpp @@ -71,9 +71,9 @@ namespace ESMS RecIDListT gameSettings; //RecListT lands; //RecListT landTexts; - //RecListT magicEffects; + IndexListT magicEffects; ScriptListT