1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-06-20 14:15:23 +00:00

Added more temporary mapgen. (#359)

This commit is contained in:
Tim Sarbin 2020-06-20 14:04:51 -04:00 committed by GitHub
parent 5edf314b48
commit e510674b42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 90 additions and 27 deletions

View File

@ -19,14 +19,29 @@ func (m *MapEngine) GenerateAct1Overworld(cacheTiles bool) {
m.AppendRegion(region)
m.entities.Add(entities...)
} else if strings.Contains(region.regionPath, "S1") {
region.tileRect.Height -= 1 // For some reason, this has a duplciate wall tile strip...
mapWidthTiles := ((region.tileRect.Width - 18) / 9)
yOffset := region.tileRect.Height
waterXOffset := region.tileRect.Width - 16
waterXOffset := region.tileRect.Width - 17
region, entities := loadRegion(m.seed, 0, yOffset, d2enum.RegionAct1Town, 3, -1, cacheTiles)
m.AppendRegion(region)
m.entities.Add(entities...)
yOffset += region.tileRect.Height
for i := 0; i < 8; i++ {
var choices = [...]int{
d2wilderness.StoneFill1,
d2wilderness.StoneFill2,
d2wilderness.SwampFill1,
d2wilderness.Cottages1,
d2wilderness.Cottages2,
d2wilderness.Cottages3,
d2wilderness.CorralFill,
d2wilderness.FallenCamp1,
d2wilderness.FallenCamp2,
d2wilderness.Pond,
}
for i := 0; i < 6; i++ {
// West Border
region, entities = loadRegion(m.seed, 0, yOffset, d2enum.RegionAct1Wilderness, d2wilderness.TreeBorderWest, 0, cacheTiles)
m.AppendRegion(region)
@ -37,7 +52,14 @@ func (m *MapEngine) GenerateAct1Overworld(cacheTiles bool) {
m.AppendRegion(region)
m.entities.Add(entities...)
yOffset += region.tileRect.Height
// Grass
for ix := 0; ix < mapWidthTiles; ix++ {
region, entities = loadRegion(m.seed, ((ix)*9)+7, yOffset, d2enum.RegionAct1Wilderness, choices[rand.Intn(len(choices))], 0, cacheTiles)
m.AppendRegion(region)
m.entities.Add(entities...)
}
yOffset += 9
}
}

View File

@ -26,28 +26,28 @@ const (
WaterBorderEast
WaterBorderWest
WaterBridgeEast
DirtSquareWithRocks
FourDirtSquaresWithRocks
FenceMaze
StoneFill1
StoneFill2
CorralFill
RandomTreesAndWallBoxLarge
TreeBoxNorthSouth
ShrineWithFenceAndTrees
RandomTreesAndWallBoxSmall
TreeBoxWestEastWithNorthSouthPath
TreeBoxNorthSouthWithEastWestPath
GrassPatch1
GrassPatch2
EnemyFeature1
EnemyFeature2
EnemyFeature3
EnemyFeature4
EnemyFeature5
EnemyFeature6
SwampFill1
SwampFill2
TreeFill
Ruin
FallenCamp1
FallenCamp2
FallenCampBishbosh
Camp
Pond
House1
House2
BurnedHouse
NotTheCowLevel
UndergroundCavern
DenOfEvil
Cottages1
Cottages2
Cottages3
Bivouac
CaveEntrance
DenOfEvilEntrance
)

View File

@ -74,12 +74,14 @@ func (m *MapEngine) GenerateMap(regionType d2enum.RegionIdType, levelPreset int,
func (m *MapEngine) AppendRegion(region *MapRegion) {
m.regions = append(m.regions, region)
// Stitch together the walk map
// Top/Bottom
for x := 0; x < region.tileRect.Width*5; x++ {
otherRegion := m.GetRegionAtTile(region.tileRect.Left+(x/5), region.tileRect.Top-1)
if otherRegion == nil {
continue
}
xDiff := region.tileRect.Left - otherRegion.tileRect.Left
xDiff := (region.tileRect.Left - otherRegion.tileRect.Left) * 5
sourceSubtile := &region.walkableArea[0][x]
if !sourceSubtile.Walkable {
@ -112,16 +114,56 @@ func (m *MapEngine) AppendRegion(region *MapRegion) {
sourceSubtile.UpRight = &otherRegion.walkableArea[otherY][x+xDiff]
}
// West/East
for y := 0; y < region.tileRect.Height*5; y++ {
otherRegion := m.GetRegionAtTile(region.tileRect.Left-1, region.tileRect.Top+(y/5))
if otherRegion == nil {
continue
}
yDiff := (region.tileRect.Top - otherRegion.tileRect.Top) * 5
sourceSubtile := &region.walkableArea[y][0]
if !sourceSubtile.Walkable {
continue
}
// North West
otherX := (otherRegion.tileRect.Width * 5) - 1
otherY := y + yDiff - 1
if otherY < 0 || otherY >= len(otherRegion.walkableArea) {
continue
}
otherRegion.walkableArea[y+yDiff][otherX].DownRight = sourceSubtile
sourceSubtile.UpLeft = &otherRegion.walkableArea[y+yDiff][otherX]
// West
otherY++
if otherY < 0 || otherY >= len(otherRegion.walkableArea) {
continue
}
otherRegion.walkableArea[y+yDiff][otherX].Right = sourceSubtile
sourceSubtile.Left = &otherRegion.walkableArea[y+yDiff][otherX]
// South East
otherY++
if otherY < 0 || otherY >= len(otherRegion.walkableArea) {
continue
}
otherRegion.walkableArea[y+yDiff][otherX].UpRight = sourceSubtile
sourceSubtile.DownLeft = &otherRegion.walkableArea[y+yDiff][otherX]
}
}
// Returns the region located at the specified tile location
func (m *MapEngine) GetRegionAtTile(x, y int) *MapRegion {
for _, region := range m.regions {
// Read in reverse order as tiles can be placed over other tiles, and we prioritize the top level tiles
for i := len(m.regions) - 1; i >= 0; i-- {
region := m.regions[i]
if region.tileRect.IsInRect(x, y) {
return region
}
}
return nil
}

View File

@ -139,8 +139,8 @@ func loadRegion(seed int64, tileOffsetX, tileOffsetY int, levelType d2enum.Regio
region.tileRect = d2common.Rectangle{
Left: tileOffsetX,
Top: tileOffsetY,
Width: int(region.ds1.Width - 1),
Height: int(region.ds1.Height - 1),
Width: int(region.ds1.Width),
Height: int(region.ds1.Height),
}
entities := region.loadEntities()
@ -525,7 +525,7 @@ func (mr *MapRegion) renderTileDebug(x, y int, debugVisLevel int, viewport *View
ay := y - mr.tileRect.Top
if debugVisLevel > 0 {
if ay < 0 || ax < 0 || ay >= len(mr.ds1.Tiles) || x >= len(mr.ds1.Tiles[ay]) {
if ay < 0 || ax < 0 || ay >= len(mr.ds1.Tiles) || ax >= len(mr.ds1.Tiles[ay]) {
return
}
subTileColor := color.RGBA{R: 80, G: 80, B: 255, A: 50}
@ -579,7 +579,6 @@ func (mr *MapRegion) renderTileDebug(x, y int, debugVisLevel int, viewport *View
target.Pop()
}
}
}
}
}