feat: produce on planets, unload on routes
This commit is contained in:
@@ -18,7 +18,7 @@ type UninhabitedPlanet struct {
|
||||
Name string `json:"name"`
|
||||
Resources float64 `json:"resources"` // R - Ресурсы
|
||||
Capital float64 `json:"capital"` // CAP $ - Запасы промышленности
|
||||
Material float64 `json:"material"` // MAT M - Запасы ресурсов / сырья
|
||||
Material float64 `json:"material"` // MAT M - Запасы ресурсов / сырьё
|
||||
}
|
||||
|
||||
type PlanetReport struct {
|
||||
@@ -52,13 +52,23 @@ func PlanetProduction(industry, population float64) float64 {
|
||||
|
||||
// Производство промышленности
|
||||
// TODO: test on real values
|
||||
// [x] ind * 5 + ind / res = prod
|
||||
// [x] ind = (res * prod) / (5 * res + 1)
|
||||
// ind = 10 * 1000 / (5 * 10 + 1) = 10000 / 55 = 181.(81)
|
||||
// int = 10 * 500 / 55 = 5000 / 55
|
||||
func (p *Planet) IncreaseIndustry() {
|
||||
prod := p.ProductionCapacity() / 5.
|
||||
industryIncrement := math.Min(prod, p.Material)
|
||||
p.Industry += industryIncrement
|
||||
production := p.ProductionCapacity()
|
||||
var ind float64
|
||||
if p.Material > 0 {
|
||||
ind = math.Min(production/5, p.Material)
|
||||
p.Material -= ind
|
||||
production -= ind * 5.
|
||||
}
|
||||
ind += (production * p.Resources) / (5.*p.Resources + 1.)
|
||||
p.Industry += ind
|
||||
if p.Industry > p.Population {
|
||||
p.Capital += p.Industry - p.Population
|
||||
p.Industry = p.Population
|
||||
p.Capital += p.Population - p.Industry
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,11 +87,11 @@ func (p *Planet) UnpackCAPtoIND() {
|
||||
// Производство материалов
|
||||
// TODO: test on real values
|
||||
func (p *Planet) IncreaseMaterial() {
|
||||
p.Material += p.ProductionCapacity() * p.Industry
|
||||
p.Material += p.ProductionCapacity() * p.Resources
|
||||
}
|
||||
|
||||
// Автоматическое увеличение населения на каждом ходу
|
||||
// TODO: test
|
||||
// TODO: test - whether POP is busy on production or not?
|
||||
func (p *Planet) IncreasePopulation() {
|
||||
p.Population *= 1.08
|
||||
if p.Population > p.Size {
|
||||
|
||||
@@ -13,3 +13,45 @@ func TestPlanetProduction(t *testing.T) {
|
||||
assert.Equal(t, 750., game.PlanetProduction(1000., 0.))
|
||||
assert.Equal(t, 250., game.PlanetProduction(0., 1000.))
|
||||
}
|
||||
|
||||
func TestIncreaseIndustry(t *testing.T) {
|
||||
HW := &game.Planet{
|
||||
PlanetReport: game.PlanetReport{
|
||||
UninhabitedPlanet: game.UninhabitedPlanet{
|
||||
Size: 1000,
|
||||
Resources: 10,
|
||||
},
|
||||
Population: 1000,
|
||||
Industry: 1000,
|
||||
},
|
||||
}
|
||||
DW := &game.Planet{
|
||||
PlanetReport: game.PlanetReport{
|
||||
UninhabitedPlanet: game.UninhabitedPlanet{
|
||||
Size: 500,
|
||||
Resources: 10,
|
||||
},
|
||||
Population: 500,
|
||||
Industry: 500,
|
||||
},
|
||||
}
|
||||
HW.IncreaseIndustry()
|
||||
assert.InDelta(t, 196.078, HW.Capital, 0.0005)
|
||||
|
||||
HW.Capital = 0
|
||||
HW.Material = 200
|
||||
|
||||
HW.IncreaseIndustry()
|
||||
assert.Equal(t, 200., HW.Capital)
|
||||
assert.Equal(t, 0., HW.Material)
|
||||
|
||||
DW.IncreaseIndustry()
|
||||
assert.InDelta(t, 98.039, DW.Capital, 0.0003)
|
||||
|
||||
DW.Capital = 0
|
||||
DW.Material = 100
|
||||
|
||||
DW.IncreaseIndustry()
|
||||
assert.Equal(t, 100., DW.Capital)
|
||||
assert.Equal(t, 0., DW.Material)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user