cmd: join group to fleet

This commit is contained in:
Ilia Denisov
2025-11-26 23:03:07 +03:00
parent c86ab84ad7
commit 92ad81b2a2
6 changed files with 133 additions and 36 deletions
+16 -6
View File
@@ -121,7 +121,7 @@ func (g *Game) JoinEqualGroups(raceName string) error {
}
func (g *Game) joinEqualGroupsInternal(ri int) {
shipGroups := slices.Collect(maps.Values(maps.Collect(g.listShipGroups(ri))))
shipGroups := slices.Collect(maps.Values(maps.Collect(g.listIndexShipGroups(ri))))
origin := len(shipGroups)
if origin < 2 {
return
@@ -156,7 +156,7 @@ func (g *Game) createShips(ri int, shipTypeName string, planetNumber int, quanti
}
var maxIndex uint
for _, sg := range g.listShipGroups(ri) {
for _, sg := range g.listIndexShipGroups(ri) {
if sg.Index > maxIndex {
maxIndex = sg.Index
}
@@ -176,11 +176,21 @@ func (g *Game) createShips(ri int, shipTypeName string, planetNumber int, quanti
return nil
}
func (g Game) listShipGroups(ri int) iter.Seq2[int, ShipGroup] {
func (g Game) listShipGroups(ri int) iter.Seq[ShipGroup] {
return func(yield func(ShipGroup) bool) {
for _, sg := range g.listIndexShipGroups(ri) {
if !yield(sg) {
return
}
}
}
}
func (g Game) listIndexShipGroups(ri int) iter.Seq2[int, ShipGroup] {
return func(yield func(int, ShipGroup) bool) {
for sg := range g.ShipGroups {
if g.ShipGroups[sg].OwnerID == g.Race[ri].ID {
if !yield(sg, g.ShipGroups[sg]) {
for i := range g.ShipGroups {
if g.ShipGroups[i].OwnerID == g.Race[ri].ID {
if !yield(i, g.ShipGroups[i]) {
return
}
}