wip: refactor controller
This commit is contained in:
@@ -27,3 +27,42 @@ func (c *Cache) MustPlanet(planetNumber uint) *game.Planet {
|
||||
panic(fmt.Sprintf("Planet: not found by number=%d", planetNumber))
|
||||
}
|
||||
}
|
||||
|
||||
// Свободный производственный потенциал (L)
|
||||
// промышленность * 0.75 + население * 0.25
|
||||
// за вычетом затрат, расходуемых в течение хода на модернизацию кораблей
|
||||
func (c *Cache) PlanetProductionCapacity(planetNumber uint) float64 {
|
||||
p := c.MustPlanet(planetNumber)
|
||||
// p, err := g.PlanetByNumber(planetNumber)
|
||||
// if err != nil {
|
||||
// panic(err)
|
||||
// }
|
||||
var busyResources float64
|
||||
for sg := range c.g.ShipsInUpgrade(p.Number) {
|
||||
busyResources += sg.StateUpgrade.Cost()
|
||||
}
|
||||
return game.PlanetProduction(p.Industry, p.Population) - busyResources
|
||||
}
|
||||
|
||||
// Internal fincs
|
||||
|
||||
func (c *Cache) putPopulation(pn uint, v float64) {
|
||||
c.MustPlanet(pn).Population = v
|
||||
}
|
||||
|
||||
func (c *Cache) putColonists(pn uint, v float64) {
|
||||
c.MustPlanet(pn).Colonists = v
|
||||
}
|
||||
|
||||
func (c *Cache) putMaterial(pn uint, v float64) {
|
||||
c.MustPlanet(pn).Material = v
|
||||
}
|
||||
|
||||
func UnloadColonists(p game.Planet, v float64) game.Planet {
|
||||
p.Population += v * 8
|
||||
if p.Population > p.Size {
|
||||
p.Colonists += (p.Population - p.Size) / 8
|
||||
p.Population = p.Size
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user