refactor: floats, tests
This commit is contained in:
@@ -108,11 +108,11 @@ 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.Mat(p.Material.F() + mat*(*p.Production.Progress))
|
||||
p.Mat(p.Material.F() + mat*(*p.Production.Progress).F())
|
||||
*p.Production.Progress = 0.
|
||||
} else if prod == game.ProductionShip {
|
||||
// new ship class to produce; otherwise we must have been returned from the func earlier
|
||||
var progress float64 = 0.
|
||||
progress := game.F(0.)
|
||||
p.Production.Progress = &progress
|
||||
}
|
||||
|
||||
@@ -218,7 +218,7 @@ func (c *Cache) TurnPlanetProductions() {
|
||||
cost := sg.StateUpgrade.Cost()
|
||||
if productionAvailable >= cost {
|
||||
for i := range sg.StateUpgrade.UpgradeTech {
|
||||
sg.Tech = sg.Tech.Set(sg.StateUpgrade.UpgradeTech[i].Tech, sg.StateUpgrade.UpgradeTech[i].Level)
|
||||
sg.Tech = sg.Tech.Set(sg.StateUpgrade.UpgradeTech[i].Tech, sg.StateUpgrade.UpgradeTech[i].Level.F())
|
||||
}
|
||||
productionAvailable -= cost
|
||||
}
|
||||
@@ -233,7 +233,7 @@ func (c *Cache) TurnPlanetProductions() {
|
||||
}
|
||||
case game.ResearchScience:
|
||||
sc := c.mustScience(ri, *p.Production.SubjectID)
|
||||
ResearchTech(r, p.ProductionCapacity(), sc.Drive, sc.Weapons, sc.Shields, sc.Cargo)
|
||||
ResearchTech(r, p.ProductionCapacity(), sc.Drive.F(), sc.Weapons.F(), sc.Shields.F(), sc.Cargo.F())
|
||||
case game.ResearchDrive:
|
||||
ResearchTech(r, p.ProductionCapacity(), 1., 0, 0, 0)
|
||||
case game.ResearchWeapons:
|
||||
@@ -247,7 +247,7 @@ func (c *Cache) TurnPlanetProductions() {
|
||||
case game.ProductionCapital:
|
||||
p.ProduceIndustry()
|
||||
default:
|
||||
panic(fmt.Sprintf("unprocessed production type: %v", pt))
|
||||
panic(fmt.Sprintf("unprocessed production type: '%v' for planet: #%d owner=%v", pt, pn, p.Owner))
|
||||
}
|
||||
|
||||
// last step: increase population / colonists
|
||||
@@ -261,7 +261,7 @@ func (c *Cache) TurnPlanetProductions() {
|
||||
func (c *Cache) listProducingPlanets() iter.Seq[uint] {
|
||||
ordered := make([]int, 0)
|
||||
for i := range c.g.Map.Planet {
|
||||
if c.g.Map.Planet[i].Owner == uuid.Nil {
|
||||
if c.g.Map.Planet[i].Owner == uuid.Nil || c.g.Map.Planet[i].Production.Type == game.ProductionNone {
|
||||
continue
|
||||
}
|
||||
ordered = append(ordered, i)
|
||||
@@ -305,7 +305,7 @@ func ProduceShip(p *game.Planet, productionAvailable, shipMass float64) uint {
|
||||
CAP_perShip := shipMass / p.Resources.F()
|
||||
productionForMass := shipMass * 10.
|
||||
ships := uint(0)
|
||||
flZero := 0.
|
||||
flZero := game.F(0.)
|
||||
p.Production.Progress = &flZero
|
||||
for productionAvailable > 0 {
|
||||
var productionExtraCAP float64
|
||||
@@ -318,8 +318,8 @@ func ProduceShip(p *game.Planet, productionAvailable, shipMass float64) uint {
|
||||
p.Cap(p.Capital.F() - (CAP_perShip - productionExtraCAP))
|
||||
ships++
|
||||
} else {
|
||||
progress := productionAvailable / productionCost
|
||||
productionAvailable -= productionCost * progress
|
||||
progress := game.F(productionAvailable / productionCost)
|
||||
productionAvailable -= productionCost * progress.F()
|
||||
p.Production.Progress = &progress
|
||||
break
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user