refactor: float64 types for storage and report
This commit is contained in:
@@ -7,25 +7,25 @@ import (
|
||||
)
|
||||
|
||||
type UnidentifiedPlanet struct {
|
||||
X float64 `json:"x"`
|
||||
Y float64 `json:"y"`
|
||||
Number uint `json:"number"`
|
||||
X Float `json:"x"`
|
||||
Y Float `json:"y"`
|
||||
Number uint `json:"number"`
|
||||
}
|
||||
|
||||
type UninhabitedPlanet struct {
|
||||
UnidentifiedPlanet
|
||||
Size float64 `json:"size"`
|
||||
Name string `json:"name"`
|
||||
Resources float64 `json:"resources"` // R - Ресурсы
|
||||
Capital float64 `json:"capital"` // CAP $ - Запасы промышленности
|
||||
Material float64 `json:"material"` // MAT M - Запасы ресурсов / сырьё
|
||||
Size Float `json:"size"`
|
||||
Name string `json:"name"`
|
||||
Resources Float `json:"resources"` // R - Ресурсы
|
||||
Capital Float `json:"capital"` // CAP $ - Запасы промышленности
|
||||
Material Float `json:"material"` // MAT M - Запасы ресурсов / сырьё
|
||||
}
|
||||
|
||||
type PlanetReport struct {
|
||||
UninhabitedPlanet
|
||||
Industry float64 `json:"industry"` // I - Промышленность
|
||||
Population float64 `json:"population"` // P - Население
|
||||
Colonists float64 `json:"colonists"` // COL C - Количество колонистов
|
||||
Industry Float `json:"industry"` // I - Промышленность
|
||||
Population Float `json:"population"` // P - Население
|
||||
Colonists Float `json:"colonists"` // COL C - Количество колонистов
|
||||
Production Production `json:"production"` // TODO: internal/report format
|
||||
// Параметр "L" - Свободный производственный потенциал
|
||||
}
|
||||
@@ -41,13 +41,33 @@ type PlanetReportForeign struct {
|
||||
PlanetReport
|
||||
}
|
||||
|
||||
func (p *Planet) Mat(v float64) {
|
||||
p.Material = F(v)
|
||||
}
|
||||
|
||||
func (p *Planet) Pop(v float64) {
|
||||
p.Population = F(v)
|
||||
}
|
||||
|
||||
func (p *Planet) Col(v float64) {
|
||||
p.Colonists = F(v)
|
||||
}
|
||||
|
||||
func (p *Planet) Ind(v float64) {
|
||||
p.Industry = F(v)
|
||||
}
|
||||
|
||||
func (p *Planet) Cap(v float64) {
|
||||
p.Capital = F(v)
|
||||
}
|
||||
|
||||
func (p Planet) Votes() float64 {
|
||||
return p.Population / 1000.
|
||||
return p.Population.F() / 1000.
|
||||
}
|
||||
|
||||
// Производственный потенциал
|
||||
func (p Planet) ProductionCapacity() float64 {
|
||||
return PlanetProduction(p.Industry, p.Population)
|
||||
return PlanetProduction(p.Industry.F(), p.Population.F())
|
||||
}
|
||||
|
||||
func PlanetProduction(industry, population float64) float64 {
|
||||
@@ -64,12 +84,12 @@ func (p *Planet) ProduceIndustry() {
|
||||
production := p.ProductionCapacity()
|
||||
var ind float64
|
||||
if p.Material > 0 {
|
||||
ind = math.Min(production/5, p.Material)
|
||||
p.Material -= ind
|
||||
ind = math.Min(production/5, p.Material.F())
|
||||
p.Mat(p.Material.F() - ind)
|
||||
production -= ind * 5.
|
||||
}
|
||||
ind += (production * p.Resources) / (5.*p.Resources + 1.)
|
||||
p.Industry += ind
|
||||
ind += (production * p.Resources.F()) / (5.*p.Resources.F() + 1.)
|
||||
p.Ind(p.Industry.F() + ind)
|
||||
if p.Industry > p.Population {
|
||||
p.Capital += p.Industry - p.Population
|
||||
p.Industry = p.Population
|
||||
@@ -78,7 +98,7 @@ func (p *Planet) ProduceIndustry() {
|
||||
|
||||
// Производство материалов
|
||||
func (p *Planet) ProduceMaterial() {
|
||||
p.Material += p.ProductionCapacity() * p.Resources
|
||||
p.Material = p.Material.Add(p.ProductionCapacity() * p.Resources.F())
|
||||
}
|
||||
|
||||
// Автоматическое увеличение населения на каждом ходу
|
||||
@@ -115,10 +135,10 @@ func (p *Planet) UnpackColonists() {
|
||||
}
|
||||
|
||||
func UnloadColonists(p Planet, v float64) Planet {
|
||||
p.Population += v * 8
|
||||
p.Pop(p.Population.F() + v*8)
|
||||
if p.Population > p.Size {
|
||||
p.Colonists += (p.Population - p.Size) / 8
|
||||
p.Population = p.Size
|
||||
p.Col(p.Colonists.F() + (p.Population.F()-p.Size.F())/8.)
|
||||
p.Pop(p.Size.F())
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user