refactor: planet industry production
This commit is contained in:
@@ -113,7 +113,7 @@ type ShipGroup struct {
|
||||
CargoType *CargoType `json:"loadType,omitempty"` //
|
||||
Load Float `json:"load"` // Cargo loaded - "Масса груза"
|
||||
Tech TechSet `json:"tech"` //
|
||||
Destination uint `json:"destination"` // TODO: TEST: Destination, Origin, Range
|
||||
Destination uint `json:"destination"` //
|
||||
StateInSpace *InSpace `json:"inSpace,omitempty"` //
|
||||
StateUpgrade *InUpgrade `json:"upgrade,omitempty"` //
|
||||
StateTransfer bool `json:"transfer,omitempty"` //
|
||||
@@ -123,7 +123,6 @@ func (sg ShipGroup) TechLevel(t Tech) Float {
|
||||
return F(sg.Tech.Value(t))
|
||||
}
|
||||
|
||||
// TODO: refactor to separate method with *ShipGroup as parameter
|
||||
func (sg *ShipGroup) SetTechLevel(t Tech, v float64) {
|
||||
sg.Tech = sg.Tech.Set(t, v)
|
||||
}
|
||||
@@ -213,23 +212,6 @@ func (sg ShipGroup) Speed(st *ShipType) float64 {
|
||||
return sg.DriveEffective(st) * 20 / sg.FullMass(st)
|
||||
}
|
||||
|
||||
func (sg ShipGroup) UpgradeDriveCost(st *ShipType, drive float64) float64 {
|
||||
return (1 - sg.TechLevel(TechDrive).F()/drive) * 10 * st.Drive.F()
|
||||
}
|
||||
|
||||
// TODO: test on other values
|
||||
func (sg ShipGroup) UpgradeWeaponsCost(st *ShipType, weapons float64) float64 {
|
||||
return (1 - sg.TechLevel(TechWeapons).F()/weapons) * 10 * st.WeaponsBlockMass()
|
||||
}
|
||||
|
||||
func (sg ShipGroup) UpgradeShieldsCost(st *ShipType, shields float64) float64 {
|
||||
return (1 - sg.TechLevel(TechShields).F()/shields) * 10 * st.Shields.F()
|
||||
}
|
||||
|
||||
func (sg ShipGroup) UpgradeCargoCost(st *ShipType, cargo float64) float64 {
|
||||
return (1 - sg.TechLevel(TechCargo).F()/cargo) * 10 * st.Cargo.F()
|
||||
}
|
||||
|
||||
// Мощность бомбардировки
|
||||
func (sg ShipGroup) BombingPower(st *ShipType) float64 {
|
||||
return (math.Sqrt(st.Weapons.F()*sg.TechLevel(TechWeapons).F())/10. + 1.) *
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package game
|
||||
|
||||
import (
|
||||
"math"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
@@ -106,20 +104,15 @@ func ProducedMaterial(shipMass, progress 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) ProduceIndustry(freeProduction float64) {
|
||||
var ind float64
|
||||
if p.Material > 0 {
|
||||
ind = math.Min(freeProduction/5, p.Material.F())
|
||||
p.Mat(p.Material.F() - ind)
|
||||
freeProduction -= ind * 5.
|
||||
prod := freeProduction / 5
|
||||
if float64(p.Material) < prod {
|
||||
prod = (freeProduction + float64(p.Material/p.Resources)) / (5. + 1./float64(p.Resources))
|
||||
p.Material = 0.
|
||||
} else {
|
||||
p.Material = p.Material.Add(-prod)
|
||||
}
|
||||
ind += (freeProduction * p.Resources.F()) / (5.*p.Resources.F() + 1.)
|
||||
p.Ind(p.Industry.F() + ind)
|
||||
p.Industry = p.Industry.Add(prod)
|
||||
if p.Industry > p.Population {
|
||||
p.Capital += p.Industry - p.Population
|
||||
p.Industry = p.Population
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package game
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
@@ -42,8 +44,8 @@ func (st ShipType) DriveBlockMass() float64 {
|
||||
}
|
||||
|
||||
func (st ShipType) WeaponsBlockMass() float64 {
|
||||
if st.Armament == 0 || st.Weapons == 0 {
|
||||
return 0
|
||||
if (st.Armament == 0 && st.Weapons != 0) || (st.Armament != 0 && st.Weapons == 0) {
|
||||
panic(fmt.Sprintf("ship class invalid design: A=%d W=%.03f", st.Armament, st.Weapons))
|
||||
}
|
||||
return float64(st.Armament+1) * (st.Weapons.F() / 2)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user