Skip to content

Commit

Permalink
fix: star generation not being varied enough
Browse files Browse the repository at this point in the history
  • Loading branch information
MrEliasen committed Sep 21, 2024
1 parent a066025 commit 7f785af
Show file tree
Hide file tree
Showing 8 changed files with 422 additions and 331 deletions.
2 changes: 1 addition & 1 deletion src/pkg/galaxy/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

func New(rng *rand.Rand, seed int64) interfaces.GalaxyInterface {
radiiMin := 35_000.0
radiiMax := 150_000.0
radiiMax := 125_000.0

thicknessMin := 800.0
thicknessMax := 2200.0
Expand Down
11 changes: 5 additions & 6 deletions src/pkg/galaxy/internal/StellarNeighbourhood.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
type StellarNeighbourhood struct {
Rng *rand.Rand `json:"-"`
Seed int64 `json:"seed"`
Dist float64 `json:"distance"`
Density float64 `json:"stellar_density"`
Radius float64 `json:"neighbourhood_radius"`
Coords ic.CoordinateInterface `json:"galactic_coordinate"`
Expand Down Expand Up @@ -74,17 +73,17 @@ func (sn *StellarNeighbourhood) randomStarClassification() star.StarClassType {
num := sn.Rng.Float64() * 100

switch true {
case num <= 3.0e-005:
case num <= 0.00003:
return star.OClass
case num <= 0.13:
return star.BClass
case num <= 0.6:
case num <= 0.6+0.13:
return star.AClass
case num <= 3.0:
case num <= 3.0+0.6+0.13:
return star.FClass
case num <= 7.6:
case num <= 7.6+3.0+0.6+0.13:
return star.GClass
case num <= 12.1:
case num <= 12.1+7.6+3.0+0.6+0.13:
return star.KClass
default:
return star.MClass
Expand Down
6 changes: 1 addition & 5 deletions src/pkg/galaxy/internal/galaxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,13 @@ func (g *Galaxy) GenerateStellarNeighbourhood(seed int64) interfaces.StellarNeig

nhRng := utils.NewSeededRNG(g.Seed ^ seed)

dist := utils.RoundFloat(nhRng.Float64()*((hzOuter-hzInner)/100)+hzInner, 5)
rad := utils.RoundFloat(float64(nhRng.Intn(30-15)+15), 0) // 15 LY min, up to 30 LY
sDensity := utils.RoundFloat(nhRng.Float64()*((0.006-0.003)/10)+0.003, 5) // 0.003 min density, up to 0.006

location := utils.RandomCartesianCoord(nhRng, dist, g.BulgeRadius+60, hzOuter)
location.SetZ(nhRng.Float64()*(g.Thickness-rad) + rad)
location := utils.RandomPointInCylindricalAnnulus(nhRng, hzInner, hzOuter, ((g.Thickness/2)+rad)*-1, ((g.Thickness / 2) + rad))

neighbourhood := &StellarNeighbourhood{
Rng: nhRng,
Seed: seed,
Dist: dist,
Radius: rad,
Density: sDensity,
Coords: location,
Expand Down
184 changes: 88 additions & 96 deletions src/pkg/galaxy/internal/star/classification.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ import (

type StarClassType struct {
Name string
SizeMin float64
SizeMax float64
MassMin float64
MassMax float64
TempRangeMin float64
TempRangeMax float64
maxPlanets int
Expand All @@ -36,22 +32,22 @@ func (sc *StarClassType) RanIceGiantCount(rng *rand.Rand) int {
}

func (sc *StarClassType) GenerateStar(rng *rand.Rand) (*Star, error) {
cl := calculateSpectralClass(rng, sc.Name)
radius := cl.RadiusMin + rng.Float64()*(cl.RadiusMax-cl.RadiusMin)
temp := sc.TempRangeMin + rng.Float64()*(sc.TempRangeMax-sc.TempRangeMin)

if temp < 2400 {
temp = 2400
if temp == 0 {
temp = cl.TempRangeMin + rng.Float64()*(cl.TempRangeMax-cl.TempRangeMin)
}

radSteps := (cl.RadiusMax - cl.RadiusMin) / 100
mass := (rng.Float64() * radSteps) * 100

star := &Star{
Class: sc.Name,
SolarRadii: utils.RoundFloat(rng.Float64()*(sc.SizeMax-sc.SizeMin)+sc.SizeMin, 4),
SolarMasses: utils.RoundFloat(rng.Float64()*(sc.MassMax-sc.MassMin)+sc.MassMin, 4),
TemperatureK: utils.RoundFloat(temp, 0),
}

cl, err := calculateSpectralClass(star)
if err != nil {
return nil, err
SolarRadii: utils.RoundFloat(radius, 5),
SolarMasses: utils.RoundFloat(mass, 2),
}

star.LuminosityClass = cl.Name
Expand All @@ -62,62 +58,46 @@ func (sc *StarClassType) GenerateStar(rng *rand.Rand) (*Star, error) {
}

var (
MClass = StarClassType{
Name: "M",
SizeMin: 0.1,
SizeMax: 0.7,
MassMin: 0.1,
MassMax: 0.6,
TempRangeMin: 2400,
TempRangeMax: 3699,
maxPlanets: 8,
gasGiantMin: 0.0,
gasGiantMax: 1.0,
OClass = StarClassType{
Name: "O",
TempRangeMin: 30000,
TempRangeMax: 52000,
maxPlanets: 6,
gasGiantMin: 1.0,
gasGiantMax: 3.0,
iceGiantMin: 1.0,
iceGiantMax: 2.0,
rockyMin: 3.0,
rockyMax: 6.0,
iceGiantMax: 3.0,
rockyMin: 0.0,
rockyMax: 2.0,
}
KClass = StarClassType{
Name: "K",
SizeMin: 0.8,
SizeMax: 0.9,
MassMin: 0.6,
MassMax: 0.8,
TempRangeMin: 3700,
TempRangeMax: 5199,
maxPlanets: 9,
BClass = StarClassType{
Name: "B",
TempRangeMin: 10000,
TempRangeMax: 30000,
maxPlanets: 7,
gasGiantMin: 1.0,
gasGiantMax: 2.0,
gasGiantMax: 3.0,
iceGiantMin: 1.0,
iceGiantMax: 3.0,
rockyMin: 3.0,
rockyMax: 5.0,
rockyMin: 0.0,
rockyMax: 2.0,
}
GClass = StarClassType{
Name: "G",
SizeMin: 0.9,
SizeMax: 1.1,
MassMin: 0.8,
MassMax: 1.2,
TempRangeMin: 5200,
TempRangeMax: 5999,
maxPlanets: 10,
gasGiantMin: 2.0,
gasGiantMax: 3.0,
iceGiantMin: 2.0,
AClass = StarClassType{
Name: "A",
TempRangeMin: 7500,
TempRangeMax: 10000,
maxPlanets: 9,
gasGiantMin: 3.0,
gasGiantMax: 6.0,
iceGiantMin: 1.0,
iceGiantMax: 3.0,
rockyMin: 2.0,
rockyMax: 5.0,
rockyMin: 1.0,
rockyMax: 3.0,
}
FClass = StarClassType{
Name: "F",
SizeMin: 1.1,
SizeMax: 1.4,
MassMin: 1.2,
MassMax: 1.4,
TempRangeMin: 6000,
TempRangeMax: 7499,
TempRangeMax: 7500,
maxPlanets: 12,
gasGiantMin: 2.0,
gasGiantMax: 5.0,
Expand All @@ -126,51 +106,63 @@ var (
rockyMin: 2.0,
rockyMax: 4.0,
}
AClass = StarClassType{
Name: "A",
SizeMin: 1.4,
SizeMax: 1.8,
MassMin: 1.4,
MassMax: 2.0,
TempRangeMin: 7500,
TempRangeMax: 9999,
maxPlanets: 9,
gasGiantMin: 3.0,
gasGiantMax: 6.0,
iceGiantMin: 1.0,
GClass = StarClassType{
Name: "G",
TempRangeMin: 5200,
TempRangeMax: 6000,
maxPlanets: 10,
gasGiantMin: 2.0,
gasGiantMax: 3.0,
iceGiantMin: 2.0,
iceGiantMax: 3.0,
rockyMin: 1.0,
rockyMax: 3.0,
rockyMin: 2.0,
rockyMax: 5.0,
}
BClass = StarClassType{
Name: "B",
SizeMin: 1.8,
SizeMax: 6.6,
MassMin: 2.0,
MassMax: 15.0,
TempRangeMin: 10000,
TempRangeMax: 29999,
maxPlanets: 7,
KClass = StarClassType{
Name: "K",
TempRangeMin: 3700,
TempRangeMax: 5200,
maxPlanets: 9,
gasGiantMin: 1.0,
gasGiantMax: 3.0,
gasGiantMax: 2.0,
iceGiantMin: 1.0,
iceGiantMax: 3.0,
rockyMin: 0.0,
rockyMax: 2.0,
rockyMin: 3.0,
rockyMax: 5.0,
}
OClass = StarClassType{
Name: "O",
SizeMin: 6.6,
SizeMax: 1700.0,
MassMin: 15.0,
MassMax: 30.0,
TempRangeMin: 30000,
TempRangeMax: 60000,
maxPlanets: 6,
gasGiantMin: 1.0,
gasGiantMax: 3.0,
MClass = StarClassType{
Name: "M",
TempRangeMin: 2400,
TempRangeMax: 3700,
maxPlanets: 8,
gasGiantMin: 0.0,
gasGiantMax: 1.0,
iceGiantMin: 1.0,
iceGiantMax: 3.0,
iceGiantMax: 2.0,
rockyMin: 3.0,
rockyMax: 6.0,
}
BDClass = StarClassType{
Name: "Brown Dwarf",
TempRangeMin: 0, // we get this from the sub type
TempRangeMax: 0, // we get this from the sub type
maxPlanets: 2,
gasGiantMin: 0.0,
gasGiantMax: 1.0,
iceGiantMin: 0.0,
iceGiantMax: 1.0,
rockyMin: 0.0,
rockyMax: 1.0,
}
WDClass = StarClassType{
Name: "White Dwarf",
TempRangeMin: 10_000,
TempRangeMax: 100_000,
maxPlanets: 3,
gasGiantMin: 0.0,
gasGiantMax: 1.0,
iceGiantMin: 0.0,
iceGiantMax: 1.0,
rockyMin: 0.0,
rockyMax: 2.0,
}
Expand Down
Loading

0 comments on commit 7f785af

Please sign in to comment.