From f8412be248f5c2185684c7fc475fb114065c7424 Mon Sep 17 00:00:00 2001 From: Ilia Denisov Date: Sun, 8 Feb 2026 20:12:27 +0200 Subject: [PATCH] refactor: planet industry production --- internal/controller/science.go | 4 ++-- internal/model/game/group.go | 20 +------------------- internal/model/game/planet.go | 21 +++++++-------------- internal/model/game/ship.go | 6 ++++-- 4 files changed, 14 insertions(+), 37 deletions(-) diff --git a/internal/controller/science.go b/internal/controller/science.go index 21dce81..1b975b9 100644 --- a/internal/controller/science.go +++ b/internal/controller/science.go @@ -64,8 +64,8 @@ func (c *Cache) DeleteScience(ri int, name string) error { return nil } -func ResearchTech(r *game.Race, indCapacity float64, drive, weapons, shields, cargo float64) { - increment := indCapacity / 5000. +func ResearchTech(r *game.Race, freeProduction float64, drive, weapons, shields, cargo float64) { + increment := freeProduction / 5000. if drive > 0 { r.Tech = r.Tech.Set(game.TechDrive, r.Tech.Value(game.TechDrive)+increment*drive) } diff --git a/internal/model/game/group.go b/internal/model/game/group.go index b398edb..1ef68c5 100644 --- a/internal/model/game/group.go +++ b/internal/model/game/group.go @@ -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.) * diff --git a/internal/model/game/planet.go b/internal/model/game/planet.go index ba04b78..664945a 100644 --- a/internal/model/game/planet.go +++ b/internal/model/game/planet.go @@ -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 diff --git a/internal/model/game/ship.go b/internal/model/game/ship.go index 9a61f5c..4de93c6 100644 --- a/internal/model/game/ship.go +++ b/internal/model/game/ship.go @@ -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) }