refactor: float64 types for storage and report

This commit is contained in:
Ilia Denisov
2026-02-02 13:14:57 +02:00
parent 4c14234afb
commit a567229f8a
24 changed files with 264 additions and 253 deletions
+7 -7
View File
@@ -108,7 +108,7 @@ func (c *Cache) PlanetProduction(ri int, number int, prod game.ProductionType, s
if p.Production.Type == game.ProductionShip && (prod != game.ProductionShip || *subjectID != *p.Production.SubjectID) {
mat, _ := c.MustShipType(ri, *p.Production.SubjectID).ProductionCost()
p.Material += mat * (*p.Production.Progress)
p.Mat(p.Material.F() + mat*(*p.Production.Progress))
*p.Production.Progress = 0.
} else if prod == game.ProductionShip {
// new ship class to produce; otherwise we must have been returned from the func earlier
@@ -265,15 +265,15 @@ func (c *Cache) listProducingPlanets() iter.Seq[uint] {
// Internal funcs
func (c *Cache) putPopulation(pn uint, v float64) {
c.MustPlanet(pn).Population = v
c.MustPlanet(pn).Pop(v)
}
func (c *Cache) putColonists(pn uint, v float64) {
c.MustPlanet(pn).Colonists = v
c.MustPlanet(pn).Col(v)
}
func (c *Cache) putMaterial(pn uint, v float64) {
c.MustPlanet(pn).Material = v
c.MustPlanet(pn).Mat(v)
}
func ProduceShip(p *game.Planet, shipMass float64) uint {
@@ -281,20 +281,20 @@ func ProduceShip(p *game.Planet, shipMass float64) uint {
if productionAvailable <= 0 {
return 0
}
CAP_perShip := shipMass / p.Resources
CAP_perShip := shipMass / p.Resources.F()
productionForMass := shipMass * 10.
ships := uint(0)
flZero := 0.
p.Production.Progress = &flZero
for productionAvailable > 0 {
var productionExtraCAP float64
if CAP_deficit := p.Capital - CAP_perShip; CAP_deficit < 0 {
if CAP_deficit := p.Capital.F() - CAP_perShip; CAP_deficit < 0 {
productionExtraCAP = -CAP_deficit
}
productionCost := productionExtraCAP + productionForMass
if productionAvailable >= productionCost {
productionAvailable -= productionCost
p.Capital = p.Capital - (CAP_perShip - productionExtraCAP)
p.Cap(p.Capital.F() - (CAP_perShip - productionExtraCAP))
ships++
} else {
progress := productionAvailable / productionCost