2020-01-26 00:39:13 -05:00
|
|
|
package d2datadict
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"strings"
|
|
|
|
|
2020-06-22 11:53:44 -04:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common"
|
2020-01-26 00:39:13 -05:00
|
|
|
)
|
|
|
|
|
2020-06-30 09:17:07 -04:00
|
|
|
// LevelPresetRecord is a representation of a row from lvlprest.txt
|
|
|
|
// these records define parameters for the preset level map generator
|
2020-01-26 00:39:13 -05:00
|
|
|
type LevelPresetRecord struct {
|
2020-06-30 09:17:07 -04:00
|
|
|
Files [6]string
|
2020-01-26 00:39:13 -05:00
|
|
|
Name string
|
2020-06-29 12:37:11 -04:00
|
|
|
DefinitionID int
|
|
|
|
LevelID int
|
2020-06-30 09:17:07 -04:00
|
|
|
SizeX int
|
|
|
|
SizeY int
|
|
|
|
Pops int
|
|
|
|
PopPad int
|
|
|
|
FileCount int
|
|
|
|
Dt1Mask uint
|
2020-01-26 00:39:13 -05:00
|
|
|
Populate bool
|
|
|
|
Logicals bool
|
|
|
|
Outdoors bool
|
|
|
|
Animate bool
|
|
|
|
KillEdge bool
|
|
|
|
FillBlanks bool
|
|
|
|
AutoMap bool
|
|
|
|
Scan bool
|
|
|
|
Beta bool
|
|
|
|
Expansion bool
|
|
|
|
}
|
|
|
|
|
|
|
|
// CreateLevelPresetRecord parses a row from lvlprest.txt into a LevelPresetRecord
|
2020-06-26 17:12:19 -04:00
|
|
|
func createLevelPresetRecord(props []string) LevelPresetRecord {
|
2020-01-26 00:39:13 -05:00
|
|
|
i := -1
|
|
|
|
inc := func() int {
|
|
|
|
i++
|
|
|
|
return i
|
|
|
|
}
|
2020-06-26 17:12:19 -04:00
|
|
|
result := LevelPresetRecord{
|
2020-01-26 00:39:13 -05:00
|
|
|
Name: props[inc()],
|
2020-06-29 12:37:11 -04:00
|
|
|
DefinitionID: d2common.StringToInt(props[inc()]),
|
|
|
|
LevelID: d2common.StringToInt(props[inc()]),
|
2020-06-22 11:53:44 -04:00
|
|
|
Populate: d2common.StringToUint8(props[inc()]) == 1,
|
|
|
|
Logicals: d2common.StringToUint8(props[inc()]) == 1,
|
|
|
|
Outdoors: d2common.StringToUint8(props[inc()]) == 1,
|
|
|
|
Animate: d2common.StringToUint8(props[inc()]) == 1,
|
|
|
|
KillEdge: d2common.StringToUint8(props[inc()]) == 1,
|
|
|
|
FillBlanks: d2common.StringToUint8(props[inc()]) == 1,
|
|
|
|
SizeX: d2common.StringToInt(props[inc()]),
|
|
|
|
SizeY: d2common.StringToInt(props[inc()]),
|
|
|
|
AutoMap: d2common.StringToUint8(props[inc()]) == 1,
|
|
|
|
Scan: d2common.StringToUint8(props[inc()]) == 1,
|
|
|
|
Pops: d2common.StringToInt(props[inc()]),
|
|
|
|
PopPad: d2common.StringToInt(props[inc()]),
|
|
|
|
FileCount: d2common.StringToInt(props[inc()]),
|
2020-01-26 00:39:13 -05:00
|
|
|
Files: [6]string{
|
|
|
|
props[inc()],
|
|
|
|
props[inc()],
|
|
|
|
props[inc()],
|
|
|
|
props[inc()],
|
|
|
|
props[inc()],
|
|
|
|
props[inc()],
|
|
|
|
},
|
2020-06-22 11:53:44 -04:00
|
|
|
Dt1Mask: d2common.StringToUint(props[inc()]),
|
|
|
|
Beta: d2common.StringToUint8(props[inc()]) == 1,
|
|
|
|
Expansion: d2common.StringToUint8(props[inc()]) == 1,
|
2020-01-26 00:39:13 -05:00
|
|
|
}
|
2020-06-29 12:37:11 -04:00
|
|
|
|
2020-01-26 00:39:13 -05:00
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
2020-06-30 09:17:07 -04:00
|
|
|
// LevelPresets stores all of the LevelPresetRecords
|
|
|
|
var LevelPresets map[int]LevelPresetRecord //nolint:gochecknoglobals // Currently global by design
|
2020-01-26 00:39:13 -05:00
|
|
|
|
2020-06-29 12:37:11 -04:00
|
|
|
// LoadLevelPresets loads level presets from text file
|
2020-01-31 23:18:11 -05:00
|
|
|
func LoadLevelPresets(file []byte) {
|
2020-06-26 17:12:19 -04:00
|
|
|
LevelPresets = make(map[int]LevelPresetRecord)
|
2020-01-31 23:18:11 -05:00
|
|
|
data := strings.Split(string(file), "\r\n")[1:]
|
2020-06-29 12:37:11 -04:00
|
|
|
|
2020-01-26 00:39:13 -05:00
|
|
|
for _, line := range data {
|
2020-06-29 12:37:11 -04:00
|
|
|
if line == "" {
|
2020-01-26 00:39:13 -05:00
|
|
|
continue
|
|
|
|
}
|
2020-06-29 12:37:11 -04:00
|
|
|
|
2020-01-26 00:39:13 -05:00
|
|
|
props := strings.Split(line, "\t")
|
2020-06-29 12:37:11 -04:00
|
|
|
|
2020-01-26 00:39:13 -05:00
|
|
|
if props[1] == "" {
|
|
|
|
continue // any line without a definition id is skipped (e.g. the "Expansion" line)
|
|
|
|
}
|
2020-06-29 12:37:11 -04:00
|
|
|
|
2020-01-26 00:39:13 -05:00
|
|
|
rec := createLevelPresetRecord(props)
|
2020-06-29 12:37:11 -04:00
|
|
|
LevelPresets[rec.DefinitionID] = rec
|
2020-01-26 00:39:13 -05:00
|
|
|
}
|
2020-06-29 12:37:11 -04:00
|
|
|
|
2020-01-26 00:39:13 -05:00
|
|
|
log.Printf("Loaded %d level presets", len(LevelPresets))
|
|
|
|
}
|
2020-06-24 00:04:27 -04:00
|
|
|
|
2020-06-29 12:37:11 -04:00
|
|
|
// LevelPreset looks up a LevelPresetRecord by ID
|
2020-06-26 17:12:19 -04:00
|
|
|
func LevelPreset(id int) LevelPresetRecord {
|
2020-06-24 00:04:27 -04:00
|
|
|
for i := 0; i < len(LevelPresets); i++ {
|
2020-06-29 12:37:11 -04:00
|
|
|
if LevelPresets[i].DefinitionID == id {
|
2020-06-24 00:04:27 -04:00
|
|
|
return LevelPresets[i]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
panic("Unknown level preset")
|
|
|
|
}
|