refactor: game funcs moved to controller

This commit is contained in:
Ilia Denisov
2026-01-15 14:42:04 +02:00
parent fe8a8d4150
commit 16aba8435d
47 changed files with 1023 additions and 3093 deletions
+2 -65
View File
@@ -22,33 +22,11 @@ func (c *Cache) UpgradeGroup(ri int, groupIndex uint, techInput string, limitShi
}
st := c.ShipGroupShipClass(sgi)
// sgi := -1
// for i, sg := range g.listIndexShipGroups(ri) {
// if sgi < 0 && sg.Index == groupIndex {
// sgi = i
// }
// }
// if sgi < 0 {
// return e.NewEntityNotExistsError("group #%d", groupIndex)
// }
// var sti int
// if sti = slices.IndexFunc(g.Race[ri].ShipTypes, func(st ShipType) bool { return st.ID == c.ShipGroup(sgi).TypeID }); sti < 0 {
// // hard to test, need manual game data invalidation
// return e.NewGameStateError("not found: ShipType ID=%v", c.ShipGroup(sgi).TypeID)
// }
// st := g.Race[ri].ShipTypes[sti]
if s := c.ShipGroup(sgi).State(); s != game.StateInOrbit && s != game.StateUpgrade {
return e.NewShipsBusyError()
}
pl := c.MustPlanet(c.ShipGroup(sgi).Destination)
// pl := slices.IndexFunc(g.Map.Planet, func(p Planet) bool { return p.Number == c.ShipGroup(sgi).Destination })
// if pl < 0 {
// return e.NewGameStateError("planet #%d", c.ShipGroup(sgi).Destination)
// }
if pl.Owner != uuid.Nil && pl.Owner != c.g.Race[ri].ID {
return e.NewEntityNotOwnedError("planet #%d for upgrade group #%d", pl.Number, groupIndex)
}
@@ -160,56 +138,15 @@ func (c *Cache) UpgradeGroup(ri int, groupIndex uint, techInput string, limitShi
// finally, fill group upgrade prefs
for tech := range targetLevel {
if targetLevel[tech] > 0 {
c.upgradeShipGroup(sgi, tech, targetLevel[tech])
c.UpgradeShipGroup(sgi, tech, targetLevel[tech])
}
}
return nil
}
// func CurrentUpgradingLevel(sg game.ShipGroup, tech game.Tech) float64 {
// if sg.StateUpgrade == nil {
// return 0
// }
// ti := slices.IndexFunc(sg.StateUpgrade.UpgradeTech, func(pref game.UpgradePreference) bool { return pref.Tech == tech })
// if ti >= 0 {
// return sg.StateUpgrade.UpgradeTech[ti].Level
// }
// return 0
// }
// func FutureUpgradeLevel(raceLevel, groupLevel, limit float64) float64 {
// target := limit
// if target == 0 || target > raceLevel {
// target = raceLevel
// }
// if groupLevel == target {
// return 0
// }
// return target
// }
func (c *Cache) upgradeShipGroup(sgi int, tech game.Tech, v float64) {
func (c *Cache) UpgradeShipGroup(sgi int, tech game.Tech, v float64) {
sg := *(c.ShipGroup(sgi))
st := c.ShipGroupShipClass(sgi)
// if v <= 0 || st.BlockMass(tech) == 0 || sg.TechLevel(tech) >= v {
// return
// }
// var su game.InUpgrade
// if sg.StateUpgrade != nil {
// su = *sg.StateUpgrade
// } else {
// su = game.InUpgrade{UpgradeTech: []game.UpgradePreference{}}
// }
// ti := slices.IndexFunc(su.UpgradeTech, func(pref game.UpgradePreference) bool { return pref.Tech == tech })
// if ti < 0 {
// su.UpgradeTech = append(su.UpgradeTech, game.UpgradePreference{Tech: tech})
// ti = len(su.UpgradeTech) - 1
// }
// su.UpgradeTech[ti].Level = v
// su.UpgradeTech[ti].Cost = game.BlockUpgradeCost(st.BlockMass(tech), sg.TechLevel(tech), v) * float64(sg.Number)
// sg.StateUpgrade = &su
c.g.ShipGroups[sgi] = game.UpgradeGroupPreference(sg, *st, tech, v)
}