cmd: send group

This commit is contained in:
Ilia Denisov
2026-01-04 21:43:16 +02:00
parent c6e1cb5cdf
commit a6093a1c29
12 changed files with 266 additions and 15 deletions
+25 -3
View File
@@ -47,8 +47,11 @@ const (
)
type InSpace struct {
Origin uint `json:"origin"`
Origin uint `json:"origin"`
X float64 `json:"x"`
Y float64 `json:"y"`
// zero is for Launched status
// TODO: calculate range dynamically
Range float64 `json:"range"`
}
@@ -136,6 +139,17 @@ func (sg ShipGroup) State() ShipGroupState {
}
}
func (sg ShipGroup) OnPlanet() (uint, bool) {
switch sg.State() {
case StateInOrbit:
return sg.Destination, true
case StateLaunched:
return sg.StateInSpace.Origin, true
default:
return 0, false
}
}
func (sg ShipGroup) Equal(other ShipGroup) bool {
return sg.OwnerID == other.OwnerID &&
sg.TypeID == other.TypeID &&
@@ -145,7 +159,7 @@ func (sg ShipGroup) Equal(other ShipGroup) bool {
sg.TechLevel(TechShields) == other.TechLevel(TechShields) &&
sg.TechLevel(TechCargo) == other.TechLevel(TechCargo) &&
sg.CargoType == other.CargoType &&
sg.Load == other.Load &&
sg.Load/float64(sg.Number) == other.Load/float64(other.Number) &&
sg.State() == other.State()
}
@@ -471,7 +485,6 @@ func (g *Game) loadCargoInternal(ri int, groupIndex uint, ct CargoType, ships ui
}
*availableOnPlanet = *availableOnPlanet - toBeLoaded
g.ShipGroups[sgi].Load += toBeLoaded
// fmt.Println("capacity:", capacity, "loaded:", g.ShipGroups[sgi].Load, "free:", capacity-g.ShipGroups[sgi].Load)
if g.ShipGroups[sgi].Load > 0 {
g.ShipGroups[sgi].CargoType = &ct
}
@@ -706,6 +719,15 @@ func (g Game) listIndexShipGroups(ri int) iter.Seq2[int, ShipGroup] {
}
}
func MustShipGroup(g *Game, ri int, index uint) ShipGroup {
for sg := range g.listShipGroups(ri) {
if sg.Index == index {
return sg
}
}
panic(fmt.Sprintf("race i=%d have no group i=%d", ri, index))
}
func maxUint(a, b uint) uint {
if b > a {
return b