56 lines
1.6 KiB
Go
56 lines
1.6 KiB
Go
package game
|
|
|
|
import "math"
|
|
|
|
type Planet struct {
|
|
X, Y float32
|
|
Size float32
|
|
|
|
Name string
|
|
Owner string
|
|
|
|
Production ProductionType
|
|
Resources float32 // Сырьё
|
|
Industry float32 // Промышленность
|
|
Population float32 // Население
|
|
|
|
Capital float32 // CAP $ - Запасы промышленности
|
|
Material float32 // MAT M - Запасы сырья
|
|
Colonists float32 // COL C - Количество колонистов
|
|
// Параметр "L" означает количество свободных производственных единиц.
|
|
}
|
|
|
|
// Производственный потенциал (I)
|
|
// промышленность * 0.75 + население * 0.25
|
|
func (p Planet) ProductionCapacity() float32 {
|
|
return p.Industry*0.75 + p.Population*0.25
|
|
}
|
|
|
|
// Производство промышленности
|
|
// TODO: test on real values
|
|
func (p *Planet) IncreaseIndustry() {
|
|
prod := p.ProductionCapacity() / 5
|
|
industryIncrement := float32(math.Min(float64(prod), float64(p.Material)))
|
|
p.Industry += industryIncrement
|
|
if p.Industry > p.Population {
|
|
p.Industry = p.Population
|
|
p.Capital += p.Population - p.Industry
|
|
}
|
|
}
|
|
|
|
// Производство материалов
|
|
// TODO: test on real values
|
|
func (p *Planet) IncreaseMaterial() {
|
|
p.Material += p.ProductionCapacity() * p.Industry
|
|
}
|
|
|
|
// Автоматическое увеличение населения на каждом ходу
|
|
func (p *Planet) IncreasePopulation() {
|
|
p.Population *= 1.08
|
|
var extraPopulation = p.Size - p.Population
|
|
if extraPopulation > 0 {
|
|
p.Colonists += extraPopulation / 8
|
|
p.Population -= extraPopulation
|
|
}
|
|
}
|