fixed bridges and building placment

This commit is contained in:
Grimsace
2026-02-26 11:16:39 -06:00
parent 2c7af98fb4
commit d2d249ac0c
2 changed files with 36 additions and 1 deletions
+21
View File
@@ -28,14 +28,27 @@ func GenerateBuildings(img *image.RGBA, width, height int, settings *Settings, r
for _, p := range roadPixels {
isRoad[p] = true
}
isExitRoad := make(map[image.Point]bool)
for _, p := range getExitRoadPixels() {
isExitRoad[p] = true
}
isBuilding := make(map[image.Point]bool)
var buildings [][]image.Point
var allBuildingPixels []image.Point
var anchorPoints []image.Point
var normalRoadAnchors []image.Point
var exitRoadAnchors []image.Point
if len(roadPixels) > 0 {
anchorPoints = roadPixels
for _, p := range anchorPoints {
if isExitRoad[p] {
exitRoadAnchors = append(exitRoadAnchors, p)
} else {
normalRoadAnchors = append(normalRoadAnchors, p)
}
}
} else {
// If no roads, use all land pixels as anchors
for y := 0; y < height; y++ {
@@ -81,7 +94,15 @@ func GenerateBuildings(img *image.RGBA, width, height int, settings *Settings, r
// Select an anchor point for the new building
var anchor image.Point
if randSrc.Float64() > settings.BuildingDistribution/100.0 {
// Buildings should only rarely use exit-road anchors.
useExitAnchor := len(exitRoadAnchors) > 0 && randSrc.Float64() < 0.02
if useExitAnchor {
anchor = exitRoadAnchors[randSrc.Intn(len(exitRoadAnchors))]
} else if len(normalRoadAnchors) > 0 {
anchor = normalRoadAnchors[randSrc.Intn(len(normalRoadAnchors))]
} else {
anchor = anchorPoints[randSrc.Intn(len(anchorPoints))]
}
} else {
if len(landPoints) == 0 {
continue // No land to place buildings on
+14
View File
@@ -31,6 +31,14 @@ type Road struct {
Importance int
}
var lastExitRoadPixels []image.Point
func getExitRoadPixels() []image.Point {
out := make([]image.Point, len(lastExitRoadPixels))
copy(out, lastExitRoadPixels)
return out
}
// GenerateRoads creates roads on the map.
func GenerateRoads(width, height int, settings *Settings, _ image.Image, allWaterPixels []image.Point, seed int64) ([]image.Point, []image.Point, *image.RGBA) {
img := image.NewRGBA(image.Rect(0, 0, width, height))
@@ -57,11 +65,17 @@ func GenerateRoads(width, height int, settings *Settings, _ image.Image, allWate
allRoadPixels := make([]image.Point, 0, len(roads)*64)
allBridgePixels := make([]image.Point, 0, len(roads)*16)
exitRoadPixels := make([]image.Point, 0, len(roads)*16)
for _, road := range roads {
roadPixels, bridgePixels := drawRoad(img, road.Points, roadColor, bridgeColor, road.Width)
allRoadPixels = append(allRoadPixels, roadPixels...)
allBridgePixels = append(allBridgePixels, bridgePixels...)
if road.Start.IsExit || road.End.IsExit {
exitRoadPixels = append(exitRoadPixels, roadPixels...)
exitRoadPixels = append(exitRoadPixels, bridgePixels...)
}
}
lastExitRoadPixels = exitRoadPixels
return allRoadPixels, allBridgePixels, img
}