fix: ship production math

This commit is contained in:
IliaDenisov
2026-02-05 21:35:13 +03:00
committed by Ilia Denisov
parent 9088cc77c9
commit 327f2865d4
10 changed files with 158 additions and 205 deletions
+1 -1
View File
@@ -16,7 +16,7 @@ func F(v float64) Float {
}
func (f Float) Add(v float64) Float {
return F(f.F() + v)
return f + F(v)
}
func (f Float) F() float64 {
+13
View File
@@ -83,6 +83,19 @@ func PlanetProduction(industry, population float64) float64 {
return industry*0.75 + population*0.25
}
func (p *Planet) ReleaseMaterial(shipMass float64) {
if p.Production.Type != ProductionShip || p.Production.Progress == nil {
panic("planet is not producing any ships")
}
p.Material = p.Material.Add(ProducedMaterial(shipMass, float64(*p.Production.Progress)))
p.Production.Progress = new(Float)
p.Production.ProdUsed = new(Float)
}
func ProducedMaterial(shipMass, progress float64) float64 {
return shipMass * progress
}
// Производство промышленности
// TODO: test on real values
// [x] ind * 5 + ind / res = prod
+3 -3
View File
@@ -22,9 +22,9 @@ const (
type Production struct {
Type ProductionType `json:"type"`
SubjectID *uuid.UUID `json:"subjectId"` // TODO: get rid of Nils?
Progress *Float `json:"progress"`
FreeProd *Float // TODO: rename, store
SubjectID *uuid.UUID `json:"subjectId,omitempty"` // TODO: get rid of Nils?
Progress *Float `json:"progress,omitempty"`
ProdUsed *Float `json:"prodUsed,omitempty"`
}
func (p ProductionType) AsType(subject uuid.UUID) Production {
-8
View File
@@ -60,11 +60,3 @@ func (st ShipType) EmptyMass() float64 {
shipMass := st.DriveBlockMass() + st.ShieldsBlockMass() + st.CargoBlockMass() + st.WeaponsBlockMass()
return shipMass
}
// ProductionCost returns Material (MAT) and Population (POP) to produce this [ShipType]
// TODO: do we need this?
func (st ShipType) ProductionCost() (mat float64, pop float64) {
mat = st.EmptyMass()
pop = mat * 10
return
}
+6 -5
View File
@@ -16,11 +16,12 @@ type OthersShipClass struct {
}
type ShipProduction struct {
Planet uint `json:"planet"` // Галактический номер планеты
Class string `json:"class"` // Наименование типа строящегося корабля
Cost Float `json:"cost"` // Стоимость постройки одного такого корабля (в производственных ед.) без учета расходов на добычу сырья
Wasted Float `json:"wasted"` // Сколько производственных единиц уже было затрачено на постройку этого корабля (уже учитывая производство сырья)
Free Float `json:"free"` // Свободный производственный потенциал
Planet uint `json:"planet"` // Галактический номер планеты
Class string `json:"class"` // Наименование типа строящегося корабля
Cost Float `json:"cost"` // Стоимость постройки одного такого корабля (в производственных ед.) без учета расходов на добычу сырья
ProdUsed Float `json:"prodUsed"` // Сколько производственных единиц уже было затрачено на постройку этого корабля (уже учитывая производство сырья)
Percent Float `json:"percent"` // Процент завершения активного производства
Free Float `json:"free"` // Свободный производственный потенциал
}
type IncomingGroup struct {