fix: created ships exact tech level

This commit is contained in:
Ilia Denisov
2026-02-17 19:06:26 +02:00
parent 16e281cfd6
commit 1379241967
6 changed files with 38 additions and 19 deletions
+7 -15
View File
@@ -10,6 +10,7 @@ import (
"github.com/google/uuid"
e "github.com/iliadenisov/galaxy/internal/error"
"github.com/iliadenisov/galaxy/internal/model/game"
"github.com/iliadenisov/galaxy/internal/number"
)
// ShipGroup is a proxy func, nothing to cache
@@ -525,33 +526,24 @@ func (c *Cache) validateShipGroupIndex(i int) {
}
}
/*
TODO: Точность тех. уровней корабля
В целях избежания неточностей в расчетах, технологические уровни кораблей
округляются до третьего знака после запятой в момент постройки или
модернизации. Поэтому в отчетах у кораблей всегда указываются действительные,
а не округлённые уровни технологий.
*/
func (c *Cache) unsafeCreateShips(ri int, classID uuid.UUID, planet uint, quantity uint) {
func (c *Cache) unsafeCreateShips(ri int, classID uuid.UUID, planet uint, quantity uint) int {
st := c.MustShipType(ri, classID)
// TODO: test new group levels
level := func(t game.Tech) float64 {
if t == game.TechDrive && st.DriveBlockMass() > 0 {
return c.g.Race[ri].TechLevel(game.TechDrive)
return number.Fixed3(c.g.Race[ri].TechLevel(game.TechDrive))
}
if t == game.TechWeapons && st.WeaponsBlockMass() > 0 {
return c.g.Race[ri].TechLevel(game.TechDrive)
return number.Fixed3(c.g.Race[ri].TechLevel(game.TechWeapons))
}
if t == game.TechShields && st.ShieldsBlockMass() > 0 {
return c.g.Race[ri].TechLevel(game.TechDrive)
return number.Fixed3(c.g.Race[ri].TechLevel(game.TechShields))
}
if t == game.TechCargo && st.CargoBlockMass() > 0 {
return c.g.Race[ri].TechLevel(game.TechDrive)
return number.Fixed3(c.g.Race[ri].TechLevel(game.TechCargo))
}
return 0
}
c.appendShipGroup(ri, &game.ShipGroup{
return c.appendShipGroup(ri, &game.ShipGroup{
OwnerID: c.g.Race[ri].ID,
TypeID: classID,
Destination: planet,