refactor: fleet/group AtPlanet

This commit is contained in:
Ilia Denisov
2026-02-05 15:49:51 +02:00
parent e90218368c
commit fef1be577d
7 changed files with 24 additions and 21 deletions
+2 -1
View File
@@ -6,6 +6,7 @@ import (
"maps"
"github.com/google/uuid"
"github.com/iliadenisov/galaxy/internal/number"
)
type Float float64
@@ -19,7 +20,7 @@ func (f Float) Add(v float64) Float {
}
func (f Float) F() float64 {
return float64(f)
return number.Fixed12(float64(f))
}
type TechSet map[Tech]Float
+2 -3
View File
@@ -142,8 +142,7 @@ func (sg ShipGroup) State() ShipGroupState {
}
}
// FIXME: ambigous func, refactor
func (sg ShipGroup) OnPlanet() (uint, bool) {
func (sg ShipGroup) AtPlanet() (uint, bool) {
switch sg.State() {
case StateInOrbit:
return sg.Destination, true
@@ -171,7 +170,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.F()/float64(sg.Number) == other.Load.F()/float64(other.Number) &&
(sg.Load/F(float64(sg.Number))).F() == (other.Load/F(float64(other.Number))).F() &&
sg.State() == other.State()
}
+1 -1
View File
@@ -244,6 +244,6 @@ func TestShipGroupEqual(t *testing.T) {
// dirty hack to equalize loads
left.Number = 5
left.Load = game.F(right.Load.F() / float64(right.Number) * float64(left.Number))
left.Load = game.F(float64(right.Load) / float64(right.Number) * float64(left.Number))
assert.True(t, left.Equal(right))
}