1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-11-17 18:06:03 -05:00

add more ds1version methods

This commit is contained in:
gravestench 2021-03-30 11:04:25 -07:00
parent 1a3fc68d03
commit 91209fd540
2 changed files with 17 additions and 4 deletions

View File

@ -340,7 +340,7 @@ func (ds1 *DS1) loadSubstitutions(br *d2datautils.StreamReader) error {
func (ds1 *DS1) getLayerSchema() []layerStreamType {
var layerStream []layerStreamType
if ds1.version < v4 {
if ds1.version.hasStandardLayers() {
layerStream = []layerStreamType{
layerStreamWall1,
layerStreamFloor1,
@ -391,7 +391,7 @@ func (ds1 *DS1) getLayerSchema() []layerStreamType {
func (ds1 *DS1) loadNPCs(br *d2datautils.StreamReader) error {
var err error
if ds1.version < v14 {
if !ds1.version.specifiesNPCs() {
return nil
}
@ -432,7 +432,7 @@ func (ds1 *DS1) loadNPCs(br *d2datautils.StreamReader) error {
return fmt.Errorf("loading paths for NPC %d: %v", npcIdx, err)
}
} else {
if ds1.version >= v15 {
if ds1.version.specifiesNPCActions() {
br.SkipBytes(int(numPaths) * 3) //nolint:gomnd // Unknown data
} else {
br.SkipBytes(int(numPaths) * 2) //nolint:gomnd // Unknown data
@ -463,7 +463,7 @@ func (ds1 *DS1) loadNpcPaths(br *d2datautils.StreamReader, objIdx, numPaths int)
newPath.Position = d2vector.NewPosition(float64(px), float64(py))
if ds1.version >= v15 {
if ds1.version.specifiesNPCActions() {
action, err := br.ReadInt32()
if err != nil {
return fmt.Errorf("reading action for path %d: %v", pathIdx, err)

View File

@ -36,6 +36,11 @@ func (v ds1version) specifiesSubstitutionType() bool {
return v >= v10
}
func (v ds1version) hasStandardLayers() bool {
// 1 of each layer, very simple ds1
return v < v4
}
func (v ds1version) specifiesWalls() bool {
// just after header, specifies number of Walls
return v >= v4
@ -57,3 +62,11 @@ func (v ds1version) hasObjects() bool {
func (v ds1version) hasSubstitutions() bool {
return v >= v12
}
func (v ds1version) specifiesNPCs() bool {
return v > v14
}
func (v ds1version) specifiesNPCActions() bool {
return v > v15
}