Some more map progress
This commit is contained in:
@@ -26,8 +26,8 @@ const (
|
||||
|
||||
CellSize = 16 // seems to be
|
||||
|
||||
cellDataOffset = 0x100 // tentatively
|
||||
cellDataSize = MaxHeight * MaxLength * MaxWidth * CellSize
|
||||
cellDataOffset = 0x120 // tentatively
|
||||
cellCount = MaxHeight * MaxLength * MaxWidth
|
||||
)
|
||||
|
||||
type Header struct {
|
||||
@@ -59,21 +59,79 @@ func (h Header) Height() int {
|
||||
return MaxHeight
|
||||
}
|
||||
|
||||
type Cell []byte // FIXME: need to deconstruct this into the various fields
|
||||
func (h Header) MapSetFilename() string {
|
||||
idx := bytes.IndexByte(h.SetName[:], 0)
|
||||
if idx < 0 {
|
||||
idx = 8 // all 8 bytes are used
|
||||
}
|
||||
|
||||
return string(h.SetName[0:idx:idx]) + ".set"
|
||||
}
|
||||
|
||||
type Cell struct {
|
||||
DoorAndCanisterRelated byte
|
||||
DoorLockAndReactorRelated byte
|
||||
Unknown2 byte
|
||||
Object0SurfaceArea byte
|
||||
Unknown4 byte
|
||||
Object1LeftArea byte
|
||||
Unknown6 byte
|
||||
Object2RightArea byte
|
||||
Unknown8 byte
|
||||
Object3CenterArea byte
|
||||
Unknown10 byte
|
||||
Unknown11 byte
|
||||
Unknown12 byte
|
||||
Unknown13 byte
|
||||
Unknown14 byte
|
||||
SquadRelated byte
|
||||
}
|
||||
|
||||
func (c *Cell) At(n int) byte {
|
||||
switch n {
|
||||
case 0:
|
||||
return c.DoorAndCanisterRelated
|
||||
case 1:
|
||||
return c.DoorLockAndReactorRelated
|
||||
case 2:
|
||||
return c.Unknown2
|
||||
case 3:
|
||||
return c.Object0SurfaceArea
|
||||
case 4:
|
||||
return c.Unknown4
|
||||
case 5:
|
||||
return c.Object1LeftArea
|
||||
case 6:
|
||||
return c.Unknown6
|
||||
case 7:
|
||||
return c.Object2RightArea
|
||||
case 8:
|
||||
return c.Unknown8
|
||||
case 9:
|
||||
return c.Object3CenterArea
|
||||
case 10:
|
||||
return c.Unknown10
|
||||
case 11:
|
||||
return c.Unknown11
|
||||
case 12:
|
||||
return c.Unknown12
|
||||
case 13:
|
||||
return c.Unknown13
|
||||
case 14:
|
||||
return c.Unknown14
|
||||
case 15:
|
||||
return c.SquadRelated
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
// Cells is always a fixed size; use At to get a cell according to x,y,z
|
||||
type Cells []byte
|
||||
type Cells []Cell
|
||||
|
||||
// FIXME: Ordering may be incorrect? I assume z,y,x for now...
|
||||
func (c Cells) At(x, y, z int) Cell {
|
||||
start :=
|
||||
(z * MaxLength * MaxWidth * CellSize) +
|
||||
(y * MaxWidth * CellSize) +
|
||||
(x * CellSize)
|
||||
|
||||
end := start + CellSize
|
||||
|
||||
return Cell(c[start:end:end])
|
||||
return c[(z*MaxLength*MaxWidth)+(y*MaxWidth)+x]
|
||||
}
|
||||
|
||||
func (h Header) Check() []error {
|
||||
@@ -194,9 +252,9 @@ func loadMapFile(filename string) (*GameMap, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
out.Cells = make(Cells, cellDataSize)
|
||||
out.Cells = make(Cells, cellCount)
|
||||
if err := binary.Read(zr, binary.LittleEndian, &out.Cells); err != nil {
|
||||
return nil, fmt.Errorf("Error parsing %s: %v", filename, err)
|
||||
return nil, fmt.Errorf("Error parsing cells for %s: %v", filename, err)
|
||||
}
|
||||
|
||||
return &out, nil
|
||||
|
Reference in New Issue
Block a user