refactor: float64 types for storage and report

This commit is contained in:
Ilia Denisov
2026-02-02 13:14:57 +02:00
parent 4c14234afb
commit a567229f8a
24 changed files with 264 additions and 253 deletions
+8 -8
View File
@@ -39,7 +39,7 @@ func (c *Cache) SetRoute(ri int, rt game.RouteType, origin, destination uint) er
if !ok {
return e.NewEntityNotExistsError("destination planet #%d", destination)
}
rangeToDestination := util.ShortDistance(c.g.Map.Width, c.g.Map.Height, p1.X, p1.Y, p2.X, p2.Y)
rangeToDestination := util.ShortDistance(c.g.Map.Width, c.g.Map.Height, p1.X.F(), p1.Y.F(), p2.X.F(), p2.Y.F())
if rangeToDestination > c.g.Race[ri].FlightDistance() {
return e.NewSendUnreachableDestinationError("range=%.03f max=%.03f", rangeToDestination, c.g.Race[ri].FlightDistance())
}
@@ -127,7 +127,7 @@ func (c *Cache) SendRoutedGroups() {
if !ok {
continue
}
var res *float64
var res *game.Float
var ct game.CargoType
switch rt {
case game.RouteColonist:
@@ -152,7 +152,7 @@ func (c *Cache) SendRoutedGroups() {
st := c.ShipGroupShipClass(sgi)
ships := sg.Number
sgCapacity := sg.CargoCapacity(st)
toLoad := *res
toLoad := (*res).F()
if toLoad > sgCapacity {
toLoad = sgCapacity
} else if maxShips := uint(math.Ceil(toLoad / (sgCapacity / float64(ships)))); maxShips < ships {
@@ -160,9 +160,9 @@ func (c *Cache) SendRoutedGroups() {
sg = c.ShipGroup(newGroupIdx)
}
// decrease planet resource
*res = *res - toLoad
*res = (*res).Add(-toLoad)
// load group
sg.Load += toLoad
sg.Load = sg.Load.Add(toLoad)
sg.CargoType = &ct
c.LaunchShips(sg, dest)
groups = reorderGroups(groups)
@@ -214,7 +214,7 @@ func (c *Cache) RemoveUnreachableRoutes() {
ri := c.RaceIndex(p1.Owner)
for rt, destination := range p1.Route {
p2 := c.MustPlanet(destination)
rangeToDestination := util.ShortDistance(c.g.Map.Width, c.g.Map.Height, p1.X, p1.Y, p2.X, p2.Y)
rangeToDestination := util.ShortDistance(c.g.Map.Width, c.g.Map.Height, p1.X.F(), p1.Y.F(), p2.X.F(), p2.Y.F())
if rangeToDestination > c.g.Race[ri].FlightDistance() {
delete(p1.Route, rt)
}
@@ -224,7 +224,7 @@ func (c *Cache) RemoveUnreachableRoutes() {
func (c *Cache) doUnload(groups iter.Seq[int]) {
for sgi := range groups {
c.unsafeUnloadCargo(sgi, c.ShipGroup(sgi).Load)
c.unsafeUnloadCargo(sgi, c.ShipGroup(sgi).Load.F())
}
}
@@ -255,7 +255,7 @@ func (c *Cache) selectColUnloadGroup(groups []int) (result iter.Seq[int]) {
sg := c.ShipGroup(i)
ri := c.RaceIndex(sg.OwnerID)
groupByRace[ri] = append(groupByRace[ri], i)
loadByRace[ri] += sg.Load
loadByRace[ri] += sg.Load.F()
}
if len(loadByRace) < 2 {
// only one race has to unload cargo