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
@@ -136,8 +136,8 @@ func VotingWinners(calc []*VoteGroup, gameVotes float64) []int {
return votingWinners(calc, gameVotes)
}
func (c *Cache) CreateShipsUnsafe_T(ri int, classID uuid.UUID, planet uint, quantity uint) {
c.unsafeCreateShips(ri, classID, planet, quantity)
func (c *Cache) CreateShipsUnsafe_T(ri int, classID uuid.UUID, planet uint, quantity uint) int {
return c.unsafeCreateShips(ri, classID, planet, quantity)
}
func (c *Cache) WipeRace(ri int) {
+2 -1
View File
@@ -8,6 +8,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"
"github.com/iliadenisov/galaxy/internal/util"
)
@@ -183,7 +184,7 @@ func (c *Cache) TurnPlanetProductions() {
cost := sg.StateUpgrade.Cost()
if productionAvailable >= cost {
for i := range sg.StateUpgrade.UpgradeTech {
sg.Tech = sg.Tech.Set(sg.StateUpgrade.UpgradeTech[i].Tech, sg.StateUpgrade.UpgradeTech[i].Level.F())
sg.Tech = sg.Tech.Set(sg.StateUpgrade.UpgradeTech[i].Tech, number.Fixed3(sg.StateUpgrade.UpgradeTech[i].Level.F()))
}
productionAvailable -= cost
}
+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,
+23
View File
@@ -35,6 +35,29 @@ func TestCreateShips(t *testing.T) {
assert.Len(t, slices.Collect(c.RaceShipGroups(1)), 2)
}
func TestUnsafeCreateShips(t *testing.T) {
c, _ := newCache()
r := c.Race(Race_0_idx)
r.Tech = r.Tech.Set(game.TechDrive, 1.001)
r.Tech = r.Tech.Set(game.TechWeapons, 2.999)
r.Tech = r.Tech.Set(game.TechShields, 3.1003)
r.Tech = r.Tech.Set(game.TechCargo, 4.0005001)
sgi := c.CreateShipsUnsafe_T(Race_0_idx, c.MustShipClass(Race_0_idx, Race_0_Freighter).ID, R0_Planet_0_num, 1)
sg := c.ShipGroup(sgi)
assert.Equal(t, 1.001, sg.Tech.Value(game.TechDrive))
assert.Equal(t, 0., sg.Tech.Value(game.TechWeapons))
assert.Equal(t, 3.100, sg.Tech.Value(game.TechShields))
assert.Equal(t, 4.001, sg.Tech.Value(game.TechCargo))
sgi = c.CreateShipsUnsafe_T(Race_0_idx, c.MustShipClass(Race_0_idx, Race_0_Gunship).ID, R0_Planet_0_num, 1)
sg = c.ShipGroup(sgi)
assert.Equal(t, 1.001, sg.Tech.Value(game.TechDrive))
assert.Equal(t, 2.999, sg.Tech.Value(game.TechWeapons))
assert.Equal(t, 3.100, sg.Tech.Value(game.TechShields))
assert.Equal(t, 0., sg.Tech.Value(game.TechCargo))
}
func TestShipGroupMerge(t *testing.T) {
c, g := newCache()