diff --git a/components/esm/loadland.hpp b/components/esm/loadland.hpp index 96c9901ad..d1a9e4068 100644 --- a/components/esm/loadland.hpp +++ b/components/esm/loadland.hpp @@ -25,8 +25,9 @@ struct Land { // Get the grid location esm.getSubNameIs("INTV"); - esm.getT(X); - esm.getT(Y); + esm.getSubHeaderIs(8); + esm.getT(X); + esm.getT(Y); esm.getHNT(flags, "DATA"); diff --git a/components/esm/loadltex.hpp b/components/esm/loadltex.hpp index b8c4f4d8e..c5b17d7a0 100644 --- a/components/esm/loadltex.hpp +++ b/components/esm/loadltex.hpp @@ -23,12 +23,11 @@ namespace ESM { struct LandTexture { - std::string name, texture; + std::string id, texture; int index; void load(ESMReader &esm) { - name = esm.getHNString("NAME"); esm.getHNT(index, "INTV"); texture = esm.getHNString("DATA"); } diff --git a/components/esm_store/reclists.hpp b/components/esm_store/reclists.hpp index 81b0d6054..6aae4dfda 100644 --- a/components/esm_store/reclists.hpp +++ b/components/esm_store/reclists.hpp @@ -149,6 +149,79 @@ namespace ESMS int getSize() { return list.size(); } }; + /* Land textures are indexed by an integer number + */ + struct LTexList : RecList + { + // TODO: For multiple ESM/ESP files we need one list per file. + std::vector ltex; + int count; + + LTexList() : count(0) + { + // More than enough to hold Morrowind.esm. + ltex.reserve(128); + } + + int getSize() { return count; } + + void load(ESMReader &esm, const std::string &id) + { + LandTexture lt; + lt.load(esm); + lt.id = id; + + // Make sure we have room for the structure + if(lt.index + 1 > (int)ltex.size()) + ltex.resize(lt.index+1); + + // Store it + ltex[lt.index] = lt; + } + }; + + /* Landscapes are indexed by the X,Y coordinates of the exterior + cell they belong to. + */ + struct LandList : RecList + { + // Map containing all landscapes + typedef std::map LandsCol; + typedef std::map Lands; + Lands lands; + + int count; + LandList() : count(0) {} + int getSize() { return count; } + + // Find land for the given coordinates. Return null if no data. + const Land *search(int x, int y) const + { + Lands::const_iterator it = lands.find(x); + if(it==lands.end()) + return NULL; + + LandsCol::const_iterator it2 = it->second.find(y); + if(it2 == it->second.end()) + return NULL; + + return it2->second; + } + + void load(ESMReader &esm, const std::string &id) + { + count++; + + // Create the structure and load it. This actually skips the + // landscape data and remembers the file position for later. + Land *land = new Land; + land->load(esm); + + // Store the structure + lands[land->X][land->Y] = land; + } + }; + // Cells aren't simply indexed by name. Exterior cells are treated // separately. // TODO: case handling (cell names are case-insensitive, but they are also showen to the @@ -243,8 +316,6 @@ namespace ESMS void load(ESMReader &esm, const std::string &id) { - using namespace std; - count++; // All cells have a name record, even nameless exterior cells. diff --git a/components/esm_store/store.hpp b/components/esm_store/store.hpp index 1b9184aa6..2580c3b9c 100644 --- a/components/esm_store/store.hpp +++ b/components/esm_store/store.hpp @@ -69,10 +69,10 @@ namespace ESMS // Lists that need special rules CellList cells; RecIDListT gameSettings; - //RecListT lands; - //RecListT landTexts; + LandList lands; + LTexList landTexts; + ScriptListT