forked from teamnwah/openmw-tes3coop
Added LAND, PGRD and CELL
parent
5cfe2e2de0
commit
514fe3795a
@ -0,0 +1,64 @@
|
||||
#ifndef _ESM_CELL_H
|
||||
#define _ESM_CELL_H
|
||||
|
||||
#include "esm_reader.hpp"
|
||||
|
||||
namespace ESM {
|
||||
|
||||
/* Cells hold data about objects, creatures, statics (rocks, walls,
|
||||
* buildings) and landscape (for exterior cells). Cells frequently
|
||||
* also has other associated LAND and PGRD records. Combined, all this
|
||||
* data can be huge, and we cannot load it all at startup. Instead,
|
||||
* the strategy we use is to remember the file position of each cell
|
||||
* (using ESMReader::getContext()) and jumping back into place
|
||||
* whenever we need to load a given cell.
|
||||
*/
|
||||
|
||||
struct Cell
|
||||
{
|
||||
enum Flags
|
||||
{
|
||||
Interior = 0x01, // Interior cell
|
||||
HasWater = 0x02, // Does this cell have a water surface
|
||||
NoSleep = 0x04, // Is it allowed to sleep here (without a bed)
|
||||
QuasiEx = 0x80 // Behave like exterior (Tribunal+), with
|
||||
// skybox and weather
|
||||
};
|
||||
|
||||
struct DATAstruct
|
||||
{
|
||||
int flags;
|
||||
int gridX, gridY;
|
||||
};
|
||||
|
||||
// Interior cells are indexed by this (it's the 'id'), for exterior
|
||||
// cells it is optional.
|
||||
std::string name,
|
||||
|
||||
// Optional region name for exterior cells.
|
||||
region;
|
||||
|
||||
// File position
|
||||
ESM_Context context;
|
||||
|
||||
DATAstruct data;
|
||||
|
||||
void load(ESMReader &esm)
|
||||
{
|
||||
// This is implicit?
|
||||
//name = esm.getHNString("NAME");
|
||||
|
||||
// Ignore this for now, I assume it might mean we delete the entire cell?
|
||||
if(esm.isNextSub("DELE")) esm.skipHSub();
|
||||
|
||||
esm.getHNT(data, "DATA", 12);
|
||||
|
||||
// Save position and move on
|
||||
context = esm.getContext();
|
||||
esm.skipRecord();
|
||||
|
||||
region = esm.getHNOString("RGNN");
|
||||
}
|
||||
};
|
||||
}
|
||||
#endif
|
@ -0,0 +1,52 @@
|
||||
#ifndef _ESM_LAND_H
|
||||
#define _ESM_LAND_H
|
||||
|
||||
#include "esm_reader.hpp"
|
||||
|
||||
namespace ESM {
|
||||
|
||||
/*
|
||||
* Landscape data.
|
||||
*/
|
||||
|
||||
struct Land
|
||||
{
|
||||
int flags; // Only first four bits seem to be used, don't know what
|
||||
// they mean.
|
||||
int X, Y; // Map coordinates.
|
||||
|
||||
// File context. This allows the ESM reader to be 'reset' to this
|
||||
// location later when we are ready to load the full data set.
|
||||
ESM_Context context;
|
||||
|
||||
bool hasData;
|
||||
|
||||
void load(ESMReader &esm)
|
||||
{
|
||||
// Get the grid location
|
||||
esm.getSubNameIs("INTV");
|
||||
esm.getT(X);
|
||||
esm.getT(Y);
|
||||
|
||||
esm.getHNT(flags, "DATA");
|
||||
|
||||
// Store the file position
|
||||
context = esm.getContext();
|
||||
|
||||
hasData = false;
|
||||
int cnt;
|
||||
|
||||
// Skip these here. Load the actual data when the cell is loaded.
|
||||
if(esm.isNextSub("VNML")) {esm.skipHSubSize(12675);cnt++;}
|
||||
if(esm.isNextSub("VHGT")) {esm.skipHSubSize(4232);cnt++;}
|
||||
if(esm.isNextSub("WNAM")) esm.skipHSubSize(81);
|
||||
if(esm.isNextSub("VCLR")) esm.skipHSubSize(12675);
|
||||
if(esm.isNextSub("VTEX")) {esm.skipHSubSize(512);cnt++;}
|
||||
|
||||
// We need all three of VNML, VHGT and VTEX in order to use the
|
||||
// landscape.
|
||||
hasData = (cnt == 3);
|
||||
}
|
||||
};
|
||||
}
|
||||
#endif
|
@ -0,0 +1,56 @@
|
||||
#ifndef _ESM_PGRD_H
|
||||
#define _ESM_PGRD_H
|
||||
|
||||
#include "esm_reader.hpp"
|
||||
|
||||
namespace ESM {
|
||||
|
||||
/*
|
||||
* Path grid.
|
||||
*/
|
||||
struct PathGrid
|
||||
{
|
||||
struct DATAstruct
|
||||
{
|
||||
int x, y; // Grid location, matches cell for exterior cells
|
||||
short s1; // ?? Usually but not always a power of 2. Doesn't seem
|
||||
// to have any relation to the size of PGRC.
|
||||
short s2; // Number of path points? Size of PGRP block is always 16 * s2;
|
||||
}; // 12 bytes
|
||||
|
||||
std::string cell; // Cell name
|
||||
DATAstruct data;
|
||||
ESM_Context context; // Context so we can return here later and
|
||||
// finish the job
|
||||
|
||||
void load(ESMReader &esm)
|
||||
{
|
||||
esm.getHNT(data, "DATA", 12);
|
||||
cell = esm.getHNString("NAME");
|
||||
|
||||
// Remember this file position
|
||||
context = esm.getContext();
|
||||
|
||||
// Check that the sizes match up. Size = 16 * s2 (path points?)
|
||||
if(esm.isNextSub("PGRP"))
|
||||
{
|
||||
esm.skipHSub();
|
||||
int size = esm.getSubSize();
|
||||
if(size != 16*data.s2)
|
||||
esm.fail("Path grid table size mismatch");
|
||||
}
|
||||
|
||||
// Size varies. Path grid chances? Connections? Multiples of 4
|
||||
// suggest either int or two shorts, or perhaps a float. Study
|
||||
// it later.
|
||||
if(esm.isNextSub("PGRC"))
|
||||
{
|
||||
esm.skipHSub();
|
||||
int size = esm.getSubSize();
|
||||
if(size % 4 != 0)
|
||||
esm.fail("PGRC size not a multiple of 4");
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
#endif
|
Loading…
Reference in New Issue