wip: generate report
This commit is contained in:
@@ -197,16 +197,38 @@ func (c *Cache) PlanetProductionCapacity(planetNumber uint) float64 {
|
||||
return p.ProductionCapacity() - busyResources
|
||||
}
|
||||
|
||||
// TODO: test upgrade & upgrade cancel
|
||||
func (c *Cache) TurnPlanetProductions() {
|
||||
// cancel upgrade for groups on wiped planets
|
||||
for sgi := range c.ShipGroupsIndex() {
|
||||
sg := c.ShipGroup(sgi)
|
||||
if sg.State() == game.StateUpgrade && c.MustPlanet(sg.Destination).Owner == uuid.Nil {
|
||||
sg.StateUpgrade = nil
|
||||
}
|
||||
}
|
||||
|
||||
for pn := range c.listProducingPlanets() {
|
||||
p := c.MustPlanet(pn)
|
||||
ri := c.RaceIndex(p.Owner)
|
||||
r := &c.g.Race[ri]
|
||||
|
||||
// upgrade groups and return to in_orbit state
|
||||
productionAvailable := p.ProductionCapacity()
|
||||
for sg := range c.shipGroupsInUpgrade(p.Number) {
|
||||
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)
|
||||
}
|
||||
productionAvailable -= cost
|
||||
}
|
||||
sg.StateUpgrade = nil
|
||||
}
|
||||
|
||||
switch pt := p.Production.Type; pt {
|
||||
case game.ProductionShip:
|
||||
st := c.MustShipType(ri, *p.Production.SubjectID)
|
||||
if ships := ProduceShip(p, st.EmptyMass()); ships > 0 {
|
||||
if ships := ProduceShip(p, productionAvailable, st.EmptyMass()); ships > 0 {
|
||||
c.createShipsUnsafe(ri, st.ID, p.Number, ships)
|
||||
}
|
||||
case game.ResearchScience:
|
||||
@@ -239,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 || c.g.Map.Planet[i].Production.Type == game.ProductionNone {
|
||||
if c.g.Map.Planet[i].Owner == uuid.Nil {
|
||||
continue
|
||||
}
|
||||
ordered = append(ordered, i)
|
||||
@@ -276,8 +298,7 @@ func (c *Cache) putMaterial(pn uint, v float64) {
|
||||
c.MustPlanet(pn).Mat(v)
|
||||
}
|
||||
|
||||
func ProduceShip(p *game.Planet, shipMass float64) uint {
|
||||
productionAvailable := p.ProductionCapacity()
|
||||
func ProduceShip(p *game.Planet, productionAvailable, shipMass float64) uint {
|
||||
if productionAvailable <= 0 {
|
||||
return 0
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user