1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-11-18 02:16:23 -05:00

Re-fix map starting location bug (#388)

This commit is contained in:
Tim Sarbin 2020-06-21 23:23:00 -04:00 committed by GitHub
parent 75112ec736
commit e81450b9d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 7 deletions

View File

@ -45,8 +45,7 @@ func (m *MapEngine) GetStartingPosition() (int, int) {
return m.startSubTileX, m.startSubTileY return m.startSubTileX, m.startSubTileY
} }
func (m *MapEngine) ResetMap(seed int64, levelType d2enum.RegionIdType, width, height int) { func (m *MapEngine) ResetMap(levelType d2enum.RegionIdType, width, height int) {
m.seed = seed
m.entities = make([]d2mapentity.MapEntity, 0) m.entities = make([]d2mapentity.MapEntity, 0)
m.levelType = d2datadict.LevelTypes[levelType] m.levelType = d2datadict.LevelTypes[levelType]
m.size = d2common.Size{Width: width, Height: height} m.size = d2common.Size{Width: width, Height: height}
@ -67,6 +66,15 @@ func (m *MapEngine) ResetMap(seed int64, levelType d2enum.RegionIdType, width, h
} }
} }
func (m *MapEngine) FindTile(style, sequence, tileType int32) d2dt1.Tile {
for _, tile := range m.dt1TileData {
if tile.Style == style && tile.Sequence == sequence && tile.Type == tileType {
return tile
}
}
panic("Could not find the requested tile!")
}
// Returns the level type of this map // Returns the level type of this map
func (m *MapEngine) LevelType() d2datadict.LevelTypeRecord { func (m *MapEngine) LevelType() d2datadict.LevelTypeRecord {
return m.levelType return m.levelType
@ -193,7 +201,7 @@ func (m *MapEngine) TileExists(tileX, tileY int) bool {
func (m *MapEngine) GenerateMap(regionType d2enum.RegionIdType, levelPreset int, fileIndex int, cacheTiles bool) { func (m *MapEngine) GenerateMap(regionType d2enum.RegionIdType, levelPreset int, fileIndex int, cacheTiles bool) {
region := d2mapstamp.LoadStamp(m.seed, regionType, levelPreset, fileIndex) region := d2mapstamp.LoadStamp(m.seed, regionType, levelPreset, fileIndex)
regionSize := region.Size() regionSize := region.Size()
m.ResetMap(0, regionType, regionSize.Width, regionSize.Height) m.ResetMap(regionType, regionSize.Width, regionSize.Height)
m.PlaceStamp(region, 0, 0) m.PlaceStamp(region, 0, 0)
} }

View File

@ -1,6 +1,7 @@
package d2mapgen package d2mapgen
import ( import (
"log"
"math/rand" "math/rand"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
@ -9,10 +10,11 @@ import (
) )
func GenerateAct1Overworld(mapEngine *d2mapengine.MapEngine) { func GenerateAct1Overworld(mapEngine *d2mapengine.MapEngine) {
log.Printf("Map seed: %d", mapEngine.Seed())
rand.Seed(mapEngine.Seed()) rand.Seed(mapEngine.Seed())
townStamp := d2mapstamp.LoadStamp(mapEngine.Seed(), d2enum.RegionAct1Town, 1, -1) townStamp := d2mapstamp.LoadStamp(mapEngine.Seed(), d2enum.RegionAct1Town, 1, -1)
townSize := townStamp.Size() townSize := townStamp.Size()
mapEngine.ResetMap(0, d2enum.RegionAct1Town, townSize.Width, townSize.Height) // TODO: Mapgen - Needs levels.txt stuff mapEngine.ResetMap(d2enum.RegionAct1Town, townSize.Width, townSize.Height) // TODO: Mapgen - Needs levels.txt stuff
mapEngine.PlaceStamp(townStamp, 0, 0) mapEngine.PlaceStamp(townStamp, 0, 0)
mapEngine.RegenerateWalkPaths() mapEngine.RegenerateWalkPaths()

View File

@ -1,7 +1,6 @@
package d2gamescreen package d2gamescreen
import ( import (
"math/rand"
"os" "os"
"time" "time"
@ -130,10 +129,11 @@ func (met *MapEngineTest) LoadRegionByIndex(n int, levelPreset, fileIndex int) {
} }
if n == 0 { if n == 0 {
rand.Seed(time.Now().UnixNano()) met.mapEngine.SetSeed(time.Now().UnixNano())
d2mapgen.GenerateAct1Overworld(met.mapEngine) d2mapgen.GenerateAct1Overworld(met.mapEngine)
} else { } else {
met.mapEngine = d2mapengine.CreateMapEngine() // necessary for map name update met.mapEngine = d2mapengine.CreateMapEngine() // necessary for map name update
met.mapEngine.SetSeed(time.Now().UnixNano())
met.mapEngine.GenerateMap(d2enum.RegionIdType(n), levelPreset, fileIndex, true) met.mapEngine.GenerateMap(d2enum.RegionIdType(n), levelPreset, fileIndex, true)
met.mapEngine.RegenerateWalkPaths() met.mapEngine.RegenerateWalkPaths()
} }

View File

@ -48,7 +48,8 @@ func Create(openNetworkServer bool) {
} }
mapEngine := d2mapengine.CreateMapEngine() mapEngine := d2mapengine.CreateMapEngine()
mapEngine.ResetMap(0, d2enum.RegionAct1Town, 100, 100) // TODO: Mapgen - Needs levels.txt stuff mapEngine.SetSeed(singletonServer.seed)
mapEngine.ResetMap(d2enum.RegionAct1Town, 100, 100) // TODO: Mapgen - Needs levels.txt stuff
d2mapgen.GenerateAct1Overworld(mapEngine) d2mapgen.GenerateAct1Overworld(mapEngine)
singletonServer.mapEngines = append(singletonServer.mapEngines, mapEngine) singletonServer.mapEngines = append(singletonServer.mapEngines, mapEngine)