cmd: send group
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user