1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-09-28 06:06:29 -04: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.AppendRegion(region)
m.entities.Add(entities...) m.entities.Add(entities...)
} else if strings.Contains(region.regionPath, "S1") { } 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 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) region, entities := loadRegion(m.seed, 0, yOffset, d2enum.RegionAct1Town, 3, -1, cacheTiles)
m.AppendRegion(region) m.AppendRegion(region)
m.entities.Add(entities...) m.entities.Add(entities...)
yOffset += region.tileRect.Height 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 // West Border
region, entities = loadRegion(m.seed, 0, yOffset, d2enum.RegionAct1Wilderness, d2wilderness.TreeBorderWest, 0, cacheTiles) region, entities = loadRegion(m.seed, 0, yOffset, d2enum.RegionAct1Wilderness, d2wilderness.TreeBorderWest, 0, cacheTiles)
m.AppendRegion(region) m.AppendRegion(region)
@ -37,7 +52,14 @@ func (m *MapEngine) GenerateAct1Overworld(cacheTiles bool) {
m.AppendRegion(region) m.AppendRegion(region)
m.entities.Add(entities...) 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 WaterBorderEast
WaterBorderWest WaterBorderWest
WaterBridgeEast WaterBridgeEast
DirtSquareWithRocks StoneFill1
FourDirtSquaresWithRocks StoneFill2
FenceMaze CorralFill
RandomTreesAndWallBoxLarge RandomTreesAndWallBoxLarge
TreeBoxNorthSouth TreeBoxNorthSouth
ShrineWithFenceAndTrees ShrineWithFenceAndTrees
RandomTreesAndWallBoxSmall RandomTreesAndWallBoxSmall
TreeBoxWestEastWithNorthSouthPath TreeBoxWestEastWithNorthSouthPath
TreeBoxNorthSouthWithEastWestPath TreeBoxNorthSouthWithEastWestPath
GrassPatch1 SwampFill1
GrassPatch2 SwampFill2
EnemyFeature1 TreeFill
EnemyFeature2 Ruin
EnemyFeature3 FallenCamp1
EnemyFeature4 FallenCamp2
EnemyFeature5 FallenCampBishbosh
EnemyFeature6 Camp
Pond Pond
House1 Cottages1
House2 Cottages2
BurnedHouse Cottages3
NotTheCowLevel Bivouac
UndergroundCavern CaveEntrance
DenOfEvil DenOfEvilEntrance
) )

View File

@ -74,12 +74,14 @@ func (m *MapEngine) GenerateMap(regionType d2enum.RegionIdType, levelPreset int,
func (m *MapEngine) AppendRegion(region *MapRegion) { func (m *MapEngine) AppendRegion(region *MapRegion) {
m.regions = append(m.regions, region) m.regions = append(m.regions, region)
// Stitch together the walk map // Stitch together the walk map
// Top/Bottom
for x := 0; x < region.tileRect.Width*5; x++ { for x := 0; x < region.tileRect.Width*5; x++ {
otherRegion := m.GetRegionAtTile(region.tileRect.Left+(x/5), region.tileRect.Top-1) otherRegion := m.GetRegionAtTile(region.tileRect.Left+(x/5), region.tileRect.Top-1)
if otherRegion == nil { if otherRegion == nil {
continue continue
} }
xDiff := region.tileRect.Left - otherRegion.tileRect.Left xDiff := (region.tileRect.Left - otherRegion.tileRect.Left) * 5
sourceSubtile := &region.walkableArea[0][x] sourceSubtile := &region.walkableArea[0][x]
if !sourceSubtile.Walkable { if !sourceSubtile.Walkable {
@ -112,16 +114,56 @@ func (m *MapEngine) AppendRegion(region *MapRegion) {
sourceSubtile.UpRight = &otherRegion.walkableArea[otherY][x+xDiff] 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 // Returns the region located at the specified tile location
func (m *MapEngine) GetRegionAtTile(x, y int) *MapRegion { 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) { if region.tileRect.IsInRect(x, y) {
return region return region
} }
} }
return nil return nil
} }

View File

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