cmd: upgrade group

This commit is contained in:
Ilia Denisov
2026-01-04 19:22:06 +02:00
parent 6157c07a35
commit c6e1cb5cdf
17 changed files with 918 additions and 245 deletions
+33 -6
View File
@@ -35,18 +35,45 @@ func (st ShipType) Equal(o ShipType) bool {
st.Cargo == o.Cargo
}
func (st ShipType) EmptyMass() float64 {
shipMass := st.Drive + st.Shields + st.Cargo + st.WeaponsMass()
return shipMass
func (st ShipType) BlockMass(t Tech) float64 {
switch t {
case TechDrive:
return st.DriveBlockMass()
case TechWeapons:
return st.WeaponsBlockMass()
case TechShields:
return st.ShieldsBlockMass()
case TechCargo:
return st.CargoBlockMass()
default:
panic("BlockMass: unexpectec tech: " + t.String())
}
}
func (st ShipType) WeaponsMass() float64 {
func (st ShipType) DriveBlockMass() float64 {
return st.Drive
}
func (st ShipType) WeaponsBlockMass() float64 {
if st.Armament == 0 || st.Weapons == 0 {
return 0
}
return float64(st.Armament+1) * (st.Weapons / 2)
}
func (st ShipType) ShieldsBlockMass() float64 {
return st.Shields
}
func (st ShipType) CargoBlockMass() float64 {
return st.Cargo
}
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]
func (st ShipType) ProductionCost() (mat float64, pop float64) {
mat = st.EmptyMass()
@@ -89,7 +116,7 @@ func (g Game) deleteShipTypeInternal(ri int, name string) error {
return e.NewEntityNotExistsError("ship type %w", name)
}
if pl := slices.IndexFunc(g.Map.Planet, func(p Planet) bool {
return p.Production.Production == ProductionShip &&
return p.Production.Type == ProductionShip &&
p.Production.SubjectID != nil &&
g.Race[ri].ShipTypes[st].ID == *p.Production.SubjectID
}); pl >= 0 {
@@ -160,7 +187,7 @@ func (g Game) mergeShipTypeInternal(ri int, name, targetName string) error {
// switch planet productions to the new type
for pl := range g.Map.Planet {
if g.Map.Planet[pl].Owner == g.Race[ri].ID &&
g.Map.Planet[pl].Production.Production == ProductionShip &&
g.Map.Planet[pl].Production.Type == ProductionShip &&
g.Map.Planet[pl].Production.SubjectID != nil &&
*g.Map.Planet[pl].Production.SubjectID == g.Race[ri].ShipTypes[st].ID {
g.Map.Planet[pl].Production.SubjectID = &g.Race[ri].ShipTypes[tt].ID