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
+3 -19
View File
@@ -27,12 +27,10 @@ func (c *Cache) SendFleet(ri, fi int, planetNumber uint) error {
}
p1, ok := c.Planet(*sourcePlanet)
// p1, ok := PlanetByNum(g, *sourcePlanet)
if !ok {
return e.NewGameStateError("source planet #%d does not exists", sourcePlanet)
}
p2, ok := c.Planet(planetNumber)
// p2, ok := PlanetByNum(g, planetNumber)
if !ok {
return e.NewEntityNotExistsError("destination planet #%d", planetNumber)
}
@@ -42,11 +40,7 @@ func (c *Cache) SendFleet(ri, fi int, planetNumber uint) error {
}
for sg := range c.FleetGroups(ri, fi) {
st := c.ShipType(ri, sg.TypeID)
// st, ok := ShipClass(g, ri, sg.TypeID)
// if !ok {
// return e.NewGameStateError("not found: ShipType ID=%v", sg.TypeID)
// }
st := c.MustShipType(ri, sg.TypeID)
if st.DriveBlockMass() == 0 {
return e.NewSendShipHasNoDrivesError("Class=%s", st.Name)
}
@@ -66,12 +60,7 @@ func (c *Cache) LaunchFleet(ri, fi int, destination uint) {
c.validateRaceIndex(ri)
c.validateFleetIndex(fi)
for sg := range c.FleetGroups(ri, fi) {
c.LaunchShips(*sg, destination)
// sgi := slices.IndexFunc(g.ShipGroups, func(s ShipGroup) bool { return sg.Index == s.Index })
// if sgi < 0 {
// panic(fmt.Sprintf("LauncgFleet: cannot find ship group index=%d", sg.Index))
// }
// g.ShipGroups[sgi] = c.LaunchShips(sg, destination)
c.LaunchShips(sg, destination)
}
}
@@ -79,11 +68,6 @@ func (c *Cache) UnsendFleet(ri, fi int) {
c.validateRaceIndex(ri)
c.validateFleetIndex(fi)
for sg := range c.FleetGroups(ri, fi) {
c.UnsendShips(*sg)
// sgi := slices.IndexFunc(g.ShipGroups, func(s ShipGroup) bool { return sg.Index == s.Index })
// if sgi < 0 {
// panic(fmt.Sprintf("UnsendFleet: cannot find ship group index=%d", sg.Index))
// }
// g.ShipGroups[sgi] = c.UnsendShips(sg)
c.UnsendShips(sg)
}
}