generate dw planets

This commit is contained in:
Ilia Denisov
2025-09-23 22:21:33 +03:00
parent c777ba91dd
commit 1a1bd0af17
+11 -1
View File
@@ -2,6 +2,8 @@ package generator
import ( import (
"fmt" "fmt"
"math"
"math/rand"
) )
func Generate(cfg ...func(*MapSetting)) (Map, error) { func Generate(cfg ...func(*MapSetting)) (Map, error) {
@@ -40,7 +42,15 @@ func Generate(cfg ...func(*MapSetting)) (Map, error) {
return Map{}, fmt.Errorf("%s: hw new_coordinate: %s", ms, err) return Map{}, fmt.Errorf("%s: hw new_coordinate: %s", ms, err)
} }
planet := NewPlanet(coord, float32(ms.HWSize), float32(ms.HWResources)) planet := NewPlanet(coord, float32(ms.HWSize), float32(ms.HWResources))
m.HomePlanets[player] = PlanetarySystem{HW: planet} m.HomePlanets[player] = PlanetarySystem{HW: planet, DW: make([]Planet, ms.DWCount)}
for dw := 0; dw < int(ms.DWCount); dw++ {
p := rand.Float64()*(float64(ms.DWMaxDistance)-float64(ms.DWMinDistance)) + float64(ms.DWMinDistance)
phi := rand.Float64() * 360
x := float32(p * math.Cos(phi))
y := float32(p * math.Sin(phi))
dwPlanet := NewPlanet(Coordinate{x, y}, float32(ms.DWSize), float32(ms.DWResources))
m.HomePlanets[player].DW[dw] = dwPlanet
}
} }
// 4. Clear plotter and set dead zones around existing planets // 4. Clear plotter and set dead zones around existing planets