fixed bridges and building placment
This commit is contained in:
+22
-1
@@ -28,14 +28,27 @@ func GenerateBuildings(img *image.RGBA, width, height int, settings *Settings, r
|
|||||||
for _, p := range roadPixels {
|
for _, p := range roadPixels {
|
||||||
isRoad[p] = true
|
isRoad[p] = true
|
||||||
}
|
}
|
||||||
|
isExitRoad := make(map[image.Point]bool)
|
||||||
|
for _, p := range getExitRoadPixels() {
|
||||||
|
isExitRoad[p] = true
|
||||||
|
}
|
||||||
|
|
||||||
isBuilding := make(map[image.Point]bool)
|
isBuilding := make(map[image.Point]bool)
|
||||||
var buildings [][]image.Point
|
var buildings [][]image.Point
|
||||||
var allBuildingPixels []image.Point
|
var allBuildingPixels []image.Point
|
||||||
var anchorPoints []image.Point
|
var anchorPoints []image.Point
|
||||||
|
var normalRoadAnchors []image.Point
|
||||||
|
var exitRoadAnchors []image.Point
|
||||||
|
|
||||||
if len(roadPixels) > 0 {
|
if len(roadPixels) > 0 {
|
||||||
anchorPoints = roadPixels
|
anchorPoints = roadPixels
|
||||||
|
for _, p := range anchorPoints {
|
||||||
|
if isExitRoad[p] {
|
||||||
|
exitRoadAnchors = append(exitRoadAnchors, p)
|
||||||
|
} else {
|
||||||
|
normalRoadAnchors = append(normalRoadAnchors, p)
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// If no roads, use all land pixels as anchors
|
// If no roads, use all land pixels as anchors
|
||||||
for y := 0; y < height; y++ {
|
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
|
// Select an anchor point for the new building
|
||||||
var anchor image.Point
|
var anchor image.Point
|
||||||
if randSrc.Float64() > settings.BuildingDistribution/100.0 {
|
if randSrc.Float64() > settings.BuildingDistribution/100.0 {
|
||||||
anchor = anchorPoints[randSrc.Intn(len(anchorPoints))]
|
// 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 {
|
} else {
|
||||||
if len(landPoints) == 0 {
|
if len(landPoints) == 0 {
|
||||||
continue // No land to place buildings on
|
continue // No land to place buildings on
|
||||||
|
|||||||
@@ -31,6 +31,14 @@ type Road struct {
|
|||||||
Importance int
|
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.
|
// 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) {
|
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))
|
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)
|
allRoadPixels := make([]image.Point, 0, len(roads)*64)
|
||||||
allBridgePixels := make([]image.Point, 0, len(roads)*16)
|
allBridgePixels := make([]image.Point, 0, len(roads)*16)
|
||||||
|
exitRoadPixels := make([]image.Point, 0, len(roads)*16)
|
||||||
for _, road := range roads {
|
for _, road := range roads {
|
||||||
roadPixels, bridgePixels := drawRoad(img, road.Points, roadColor, bridgeColor, road.Width)
|
roadPixels, bridgePixels := drawRoad(img, road.Points, roadColor, bridgeColor, road.Width)
|
||||||
allRoadPixels = append(allRoadPixels, roadPixels...)
|
allRoadPixels = append(allRoadPixels, roadPixels...)
|
||||||
allBridgePixels = append(allBridgePixels, bridgePixels...)
|
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
|
return allRoadPixels, allBridgePixels, img
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user