circle radius
This commit is contained in:
@@ -2,10 +2,16 @@ package generator
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"galaxy/util"
|
||||
"math"
|
||||
"math/rand"
|
||||
)
|
||||
|
||||
const (
|
||||
fullSectorWithFactor = int(360. / defaultFactor)
|
||||
deadZoneDWGrad = 15.
|
||||
)
|
||||
|
||||
func Generate(cfg ...func(*MapSetting)) (Map, error) {
|
||||
ms := DefaultMapSetting()
|
||||
for i := range cfg {
|
||||
@@ -43,12 +49,35 @@ func Generate(cfg ...func(*MapSetting)) (Map, error) {
|
||||
}
|
||||
hwPlanet := NewPlanet(PlanetClassHW, hwCoord, ms.HWSize, ms.HWResources)
|
||||
m.HomePlanets[player] = PlanetarySystem{HW: hwPlanet, DW: make([]Planet, ms.DWCount)}
|
||||
grads := make(map[uint16]bool, fullSectorWithFactor)
|
||||
for i := range fullSectorWithFactor {
|
||||
grads[uint16(i)] = true
|
||||
}
|
||||
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 := p * math.Cos(phi)
|
||||
y := p * math.Sin(phi)
|
||||
dwPlanet := NewPlanet(PlanetClassDW, Coordinate{hwCoord.X + x, hwCoord.Y + y}, ms.DWSize, ms.DWResources)
|
||||
free := make([]uint16, 0)
|
||||
for g := range grads {
|
||||
if v, ok := grads[g]; ok && v {
|
||||
free = append(free, g)
|
||||
}
|
||||
}
|
||||
randGrad := free[rand.Intn(len(free))]
|
||||
phi := float64(randGrad) * defaultFactor
|
||||
for i := range int(deadZoneDWGrad / defaultFactor) {
|
||||
lx := randGrad - uint16(i)
|
||||
if uint16(i) > randGrad {
|
||||
lx = uint16(fullSectorWithFactor) - (uint16(i) - randGrad)
|
||||
}
|
||||
grads[lx] = false
|
||||
rx := randGrad + uint16(i)
|
||||
if rx > uint16(fullSectorWithFactor) {
|
||||
rx = rx - uint16(fullSectorWithFactor)
|
||||
}
|
||||
grads[rx] = false
|
||||
}
|
||||
x := util.WrapF(hwCoord.X+p*math.Cos(phi), int(size))
|
||||
y := util.WrapF(hwCoord.Y+p*math.Sin(phi), int(size))
|
||||
dwPlanet := NewPlanet(PlanetClassDW, Coordinate{x, y}, ms.DWSize, ms.DWResources)
|
||||
m.HomePlanets[player].DW[dw] = dwPlanet
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user