fix: production with free P.I.
This commit is contained in:
@@ -76,7 +76,7 @@ func (p Planet) Votes() float64 {
|
||||
return p.Population.F() / 1000.
|
||||
}
|
||||
|
||||
// Производственный потенциал
|
||||
// Производственный потенциал без учёта модернизации кораблей
|
||||
func (p Planet) ProductionCapacity() float64 {
|
||||
return PlanetProduction(p.Industry.F(), p.Population.F())
|
||||
}
|
||||
@@ -104,15 +104,14 @@ func ProducedMaterial(shipMass, progress float64) float64 {
|
||||
// [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) ProduceIndustry() {
|
||||
production := p.ProductionCapacity()
|
||||
func (p *Planet) ProduceIndustry(freeProduction float64) {
|
||||
var ind float64
|
||||
if p.Material > 0 {
|
||||
ind = math.Min(production/5, p.Material.F())
|
||||
ind = math.Min(freeProduction/5, p.Material.F())
|
||||
p.Mat(p.Material.F() - ind)
|
||||
production -= ind * 5.
|
||||
freeProduction -= ind * 5.
|
||||
}
|
||||
ind += (production * p.Resources.F()) / (5.*p.Resources.F() + 1.)
|
||||
ind += (freeProduction * p.Resources.F()) / (5.*p.Resources.F() + 1.)
|
||||
p.Ind(p.Industry.F() + ind)
|
||||
if p.Industry > p.Population {
|
||||
p.Capital += p.Industry - p.Population
|
||||
@@ -121,8 +120,8 @@ func (p *Planet) ProduceIndustry() {
|
||||
}
|
||||
|
||||
// Производство материалов
|
||||
func (p *Planet) ProduceMaterial() {
|
||||
p.Material = p.Material.Add(p.ProductionCapacity() * p.Resources.F())
|
||||
func (p *Planet) ProduceMaterial(freeProduction float64) {
|
||||
p.Material = p.Material.Add(freeProduction * p.Resources.F())
|
||||
}
|
||||
|
||||
// Автоматическое увеличение населения на каждом ходу
|
||||
|
||||
@@ -27,23 +27,23 @@ func TestProduceIndustry(t *testing.T) {
|
||||
Population: 500,
|
||||
Industry: 500,
|
||||
}
|
||||
HW.ProduceIndustry()
|
||||
HW.ProduceIndustry(HW.ProductionCapacity())
|
||||
assert.InDelta(t, 196.078, HW.Capital.F(), 0.0005)
|
||||
|
||||
HW.Capital = 0
|
||||
HW.Material = 200
|
||||
|
||||
HW.ProduceIndustry()
|
||||
HW.ProduceIndustry(HW.ProductionCapacity())
|
||||
assert.Equal(t, 200., HW.Capital.F())
|
||||
assert.Equal(t, 0., HW.Material.F())
|
||||
|
||||
DW.ProduceIndustry()
|
||||
DW.ProduceIndustry(DW.ProductionCapacity())
|
||||
assert.InDelta(t, 98.039, DW.Capital.F(), 0.0003)
|
||||
|
||||
DW.Capital = 0
|
||||
DW.Material = 100
|
||||
|
||||
DW.ProduceIndustry()
|
||||
DW.ProduceIndustry(DW.ProductionCapacity())
|
||||
assert.Equal(t, 100., DW.Capital.F())
|
||||
assert.Equal(t, 0., DW.Material.F())
|
||||
}
|
||||
@@ -57,16 +57,16 @@ func TestProduceMaterial(t *testing.T) {
|
||||
}
|
||||
assert.Equal(t, 0., HW.Material.F())
|
||||
|
||||
HW.ProduceMaterial()
|
||||
HW.ProduceMaterial(HW.ProductionCapacity())
|
||||
assert.Equal(t, 10000., HW.Material.F())
|
||||
|
||||
HW.Industry = 500
|
||||
HW.Population = 500
|
||||
HW.ProduceMaterial()
|
||||
HW.ProduceMaterial(HW.ProductionCapacity())
|
||||
assert.Equal(t, 15000., HW.Material.F())
|
||||
|
||||
HW.Population = 1000
|
||||
HW.ProduceMaterial()
|
||||
HW.ProduceMaterial(HW.ProductionCapacity())
|
||||
assert.Equal(t, 21250., HW.Material.F())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user