From e510674b428d8686ad2fd888bab49b29ee1969ce Mon Sep 17 00:00:00 2001 From: Tim Sarbin Date: Sat, 20 Jun 2020 14:04:51 -0400 Subject: [PATCH] Added more temporary mapgen. (#359) --- d2core/d2map/act1_overworld.go | 28 +++++++++-- .../d2wilderness/wilderness_tile_types.go | 34 ++++++------- d2core/d2map/engine.go | 48 +++++++++++++++++-- d2core/d2map/region.go | 7 ++- 4 files changed, 90 insertions(+), 27 deletions(-) diff --git a/d2core/d2map/act1_overworld.go b/d2core/d2map/act1_overworld.go index 29a0abcf..6e4ee8a4 100644 --- a/d2core/d2map/act1_overworld.go +++ b/d2core/d2map/act1_overworld.go @@ -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 } } diff --git a/d2core/d2map/d2wilderness/wilderness_tile_types.go b/d2core/d2map/d2wilderness/wilderness_tile_types.go index 14adcb4c..405fe8ed 100644 --- a/d2core/d2map/d2wilderness/wilderness_tile_types.go +++ b/d2core/d2map/d2wilderness/wilderness_tile_types.go @@ -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 ) diff --git a/d2core/d2map/engine.go b/d2core/d2map/engine.go index 91a80ec4..6599ed35 100644 --- a/d2core/d2map/engine.go +++ b/d2core/d2map/engine.go @@ -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 := ®ion.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 := ®ion.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 } diff --git a/d2core/d2map/region.go b/d2core/d2map/region.go index a2629e39..e9a7114a 100644 --- a/d2core/d2map/region.go +++ b/d2core/d2map/region.go @@ -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() } } - } } }