refactor: float64 types for storage and report
This commit is contained in:
@@ -61,7 +61,7 @@ func (c *Cache) ShipGroupJoinFleet(groupIndex int, fID *uuid.UUID) {
|
||||
func (c *Cache) ShipGroupShipsNumber(groupIndex int, number uint) {
|
||||
c.validateShipGroupIndex(groupIndex)
|
||||
if c.g.ShipGroups[groupIndex].Number > 0 {
|
||||
c.g.ShipGroups[groupIndex].Load = c.g.ShipGroups[groupIndex].Load / float64(c.g.ShipGroups[groupIndex].Number) * float64(number)
|
||||
c.g.ShipGroups[groupIndex].Load = game.F(c.g.ShipGroups[groupIndex].Load.F() / float64(c.g.ShipGroups[groupIndex].Number) * float64(number))
|
||||
}
|
||||
c.g.ShipGroups[groupIndex].Number = number
|
||||
}
|
||||
@@ -228,20 +228,20 @@ func (c *Cache) DisassembleGroup(ri int, groupIndex, quantity uint) error {
|
||||
|
||||
if c.ShipGroup(sgi).CargoType != nil {
|
||||
ct := *c.ShipGroup(sgi).CargoType
|
||||
load := c.ShipGroup(sgi).Load
|
||||
load := c.ShipGroup(sgi).Load.F()
|
||||
switch ct {
|
||||
case game.CargoColonist:
|
||||
if p.Owner == c.g.Race[ri].ID {
|
||||
p = game.UnloadColonists(p, load)
|
||||
}
|
||||
case game.CargoMaterial:
|
||||
p.Material += load
|
||||
p.Material = p.Material.Add(load)
|
||||
case game.CargoCapital:
|
||||
p.Capital += load
|
||||
p.Capital = p.Capital.Add(load)
|
||||
}
|
||||
}
|
||||
|
||||
p.Material += c.ShipGroup(sgi).EmptyMass(st)
|
||||
p.Material = p.Material.Add(c.ShipGroup(sgi).EmptyMass(st))
|
||||
|
||||
c.unsafeDeleteShipGroup(sgi)
|
||||
|
||||
@@ -300,11 +300,11 @@ func (c *Cache) LoadCargo(ri int, groupIndex uint, ct game.CargoType, ships uint
|
||||
sgi = nsgi
|
||||
}
|
||||
capacity := c.ShipGroup(sgi).CargoCapacity(st)
|
||||
freeShipGroupCargoLoad := capacity - c.ShipGroup(sgi).Load
|
||||
freeShipGroupCargoLoad := capacity - c.ShipGroup(sgi).Load.F()
|
||||
if freeShipGroupCargoLoad == 0 {
|
||||
return e.NewCargoLoadNoSpaceLeftError()
|
||||
}
|
||||
var availableOnPlanet *float64
|
||||
var availableOnPlanet *game.Float
|
||||
switch ct {
|
||||
case game.CargoMaterial:
|
||||
availableOnPlanet = &p.Material
|
||||
@@ -315,18 +315,18 @@ func (c *Cache) LoadCargo(ri int, groupIndex uint, ct game.CargoType, ships uint
|
||||
default:
|
||||
return e.NewGameStateError("CargoType not accepted: %v", ct)
|
||||
}
|
||||
if quantity > *availableOnPlanet || *availableOnPlanet == 0 {
|
||||
if quantity > float64(*availableOnPlanet) || *availableOnPlanet == 0 {
|
||||
return e.NewCargoLoadNotEnoughError("planet: #%d, %s=%.03f", p.Number, ct, *availableOnPlanet)
|
||||
}
|
||||
toBeLoaded := quantity
|
||||
if quantity == 0 {
|
||||
toBeLoaded = *availableOnPlanet
|
||||
toBeLoaded = float64(*availableOnPlanet)
|
||||
}
|
||||
if toBeLoaded > freeShipGroupCargoLoad {
|
||||
toBeLoaded = freeShipGroupCargoLoad
|
||||
}
|
||||
*availableOnPlanet = *availableOnPlanet - toBeLoaded
|
||||
c.ShipGroup(sgi).Load += toBeLoaded
|
||||
*availableOnPlanet = (*availableOnPlanet).Add(-toBeLoaded)
|
||||
c.ShipGroup(sgi).Load = c.ShipGroup(sgi).Load.Add(toBeLoaded)
|
||||
if c.ShipGroup(sgi).Load > 0 {
|
||||
c.ShipGroup(sgi).CargoType = &ct
|
||||
}
|
||||
@@ -379,9 +379,9 @@ func (c *Cache) UnloadCargo(ri int, groupIndex uint, ships uint, quantity float6
|
||||
|
||||
toBeUnloaded := quantity
|
||||
if quantity == 0 {
|
||||
toBeUnloaded = c.ShipGroup(sgi).Load
|
||||
toBeUnloaded = c.ShipGroup(sgi).Load.F()
|
||||
}
|
||||
if toBeUnloaded > c.ShipGroup(sgi).Load {
|
||||
if toBeUnloaded > c.ShipGroup(sgi).Load.F() {
|
||||
return e.NewCargoUnoadNotEnoughError("load: %.03f", c.ShipGroup(sgi).Load)
|
||||
}
|
||||
|
||||
@@ -401,7 +401,7 @@ func (c *Cache) unsafeUnloadCargo(sgi int, q float64) {
|
||||
p := c.MustPlanet(c.ShipGroup(sgi).Destination)
|
||||
ct := *c.ShipGroup(sgi).CargoType
|
||||
|
||||
var availableOnPlanet *float64
|
||||
var availableOnPlanet *game.Float
|
||||
switch ct {
|
||||
case game.CargoColonist:
|
||||
availableOnPlanet = &p.Colonists
|
||||
@@ -414,9 +414,9 @@ func (c *Cache) unsafeUnloadCargo(sgi int, q float64) {
|
||||
case game.CargoCapital:
|
||||
availableOnPlanet = &p.Capital
|
||||
}
|
||||
*availableOnPlanet += q
|
||||
*availableOnPlanet = (*availableOnPlanet).Add(q)
|
||||
|
||||
c.ShipGroup(sgi).Load -= q // TODO: apply rounding for Load property?
|
||||
c.ShipGroup(sgi).Load = c.ShipGroup(sgi).Load.Add(-q) // TODO: apply rounding for Load property?
|
||||
if c.ShipGroup(sgi).Load == 0 {
|
||||
c.ShipGroup(sgi).CargoType = nil
|
||||
}
|
||||
@@ -532,7 +532,7 @@ func (c *Cache) breakGroupSafe(ri int, groupIndex uint, newGroupShips uint) (int
|
||||
func (c *Cache) breakGroupUnsafe(ri, sgi int, newGroupShips uint) int {
|
||||
newGroup := *c.ShipGroup(sgi)
|
||||
if c.ShipGroup(sgi).CargoType != nil {
|
||||
newGroup.Load = c.ShipGroup(sgi).Load / float64(c.ShipGroup(sgi).Number) * float64(newGroupShips)
|
||||
newGroup.Load = game.F(c.ShipGroup(sgi).Load.F() / float64(c.ShipGroup(sgi).Number) * float64(newGroupShips))
|
||||
}
|
||||
newGroup.Number = newGroupShips
|
||||
c.ShipGroupShipsNumber(sgi, c.ShipGroup(sgi).Number-newGroup.Number)
|
||||
|
||||
Reference in New Issue
Block a user