feat: bomb planets
This commit is contained in:
@@ -129,6 +129,36 @@ func (c *Cache) PlanetProduction(ri int, number int, prod game.ProductionType, s
|
||||
return nil
|
||||
}
|
||||
|
||||
// TODO: test
|
||||
func (c *Cache) PlanetProductionDisplayName(pn uint) string {
|
||||
p := c.MustPlanet(pn)
|
||||
ri := c.RaceIndex(p.Owner)
|
||||
switch pt := p.Production.Type; pt {
|
||||
case game.ResearchDrive:
|
||||
return "Drive"
|
||||
case game.ResearchWeapons:
|
||||
return "Weapons"
|
||||
case game.ResearchShields:
|
||||
return "Shields"
|
||||
case game.ResearchCargo:
|
||||
return "Cargo"
|
||||
case game.ProductionMaterial:
|
||||
return "Material"
|
||||
case game.ProductionCapital:
|
||||
return "Capital"
|
||||
case game.ProductionShip:
|
||||
return c.MustShipType(ri, *p.Production.SubjectID).Name
|
||||
case game.ResearchScience:
|
||||
i := slices.IndexFunc(c.g.Race[ri].Sciences, func(sc game.Science) bool { return sc.ID == *p.Production.SubjectID })
|
||||
if i < 0 {
|
||||
panic("researching science not found")
|
||||
}
|
||||
return c.g.Race[ri].Sciences[i].Name
|
||||
default:
|
||||
return string(pt)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Cache) Planet(planetNumber uint) (*game.Planet, bool) {
|
||||
if c.cachePlanetByPlanetNumber == nil {
|
||||
c.cachePlanetByPlanetNumber = make(map[uint]*game.Planet)
|
||||
@@ -159,7 +189,7 @@ func (c *Cache) MustPlanetIndex(pn uint) int {
|
||||
}
|
||||
}
|
||||
|
||||
// Свободный производственный потенциал (L)
|
||||
// Свободный "Производственный Потенциал" (L)
|
||||
// промышленность * 0.75 + население * 0.25
|
||||
// за вычетом затрат, расходуемых в течение хода на модернизацию кораблей
|
||||
func (c *Cache) PlanetProductionCapacity(planetNumber uint) float64 {
|
||||
@@ -168,7 +198,7 @@ func (c *Cache) PlanetProductionCapacity(planetNumber uint) float64 {
|
||||
for sg := range c.shipGroupsInUpgrade(p.Number) {
|
||||
busyResources += sg.StateUpgrade.Cost()
|
||||
}
|
||||
return game.PlanetProduction(p.Industry, p.Population) - busyResources
|
||||
return p.ProductionCapacity() - busyResources
|
||||
}
|
||||
|
||||
// Internal funcs
|
||||
@@ -184,3 +214,35 @@ func (c *Cache) putColonists(pn uint, v float64) {
|
||||
func (c *Cache) putMaterial(pn uint, v float64) {
|
||||
c.MustPlanet(pn).Material = v
|
||||
}
|
||||
|
||||
func ProduceShip(p *game.Planet, shipMass float64) int {
|
||||
productionAvailable := p.ProductionCapacity()
|
||||
if productionAvailable <= 0 {
|
||||
return 0
|
||||
}
|
||||
CAP_perShip := shipMass / p.Resources
|
||||
productionForMass := shipMass * 10.
|
||||
ships := 0
|
||||
flZero := 0.
|
||||
p.Production.Progress = &flZero
|
||||
for productionAvailable > 0 {
|
||||
var productionExtraCAP float64
|
||||
if CAP_deficit := p.Capital - CAP_perShip; CAP_deficit < 0 {
|
||||
productionExtraCAP = -CAP_deficit
|
||||
}
|
||||
|
||||
ship_prod := productionExtraCAP + productionForMass
|
||||
|
||||
if productionAvailable >= ship_prod {
|
||||
productionAvailable -= ship_prod
|
||||
p.Capital = p.Capital - (CAP_perShip - productionExtraCAP)
|
||||
ships++
|
||||
} else {
|
||||
progress := productionAvailable / ship_prod
|
||||
productionAvailable -= ship_prod * progress
|
||||
p.Production.Progress = &progress
|
||||
break
|
||||
}
|
||||
}
|
||||
return ships
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user