fix: created ships exact tech level
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
module github.com/iliadenisov/galaxy
|
module github.com/iliadenisov/galaxy
|
||||||
|
|
||||||
go 1.25.0
|
go 1.26.0
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/gin-gonic/gin v1.11.0
|
github.com/gin-gonic/gin v1.11.0
|
||||||
|
|||||||
@@ -136,8 +136,8 @@ func VotingWinners(calc []*VoteGroup, gameVotes float64) []int {
|
|||||||
return votingWinners(calc, gameVotes)
|
return votingWinners(calc, gameVotes)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Cache) CreateShipsUnsafe_T(ri int, classID uuid.UUID, planet uint, quantity uint) {
|
func (c *Cache) CreateShipsUnsafe_T(ri int, classID uuid.UUID, planet uint, quantity uint) int {
|
||||||
c.unsafeCreateShips(ri, classID, planet, quantity)
|
return c.unsafeCreateShips(ri, classID, planet, quantity)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Cache) WipeRace(ri int) {
|
func (c *Cache) WipeRace(ri int) {
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
e "github.com/iliadenisov/galaxy/internal/error"
|
e "github.com/iliadenisov/galaxy/internal/error"
|
||||||
"github.com/iliadenisov/galaxy/internal/model/game"
|
"github.com/iliadenisov/galaxy/internal/model/game"
|
||||||
|
"github.com/iliadenisov/galaxy/internal/number"
|
||||||
"github.com/iliadenisov/galaxy/internal/util"
|
"github.com/iliadenisov/galaxy/internal/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -183,7 +184,7 @@ func (c *Cache) TurnPlanetProductions() {
|
|||||||
cost := sg.StateUpgrade.Cost()
|
cost := sg.StateUpgrade.Cost()
|
||||||
if productionAvailable >= cost {
|
if productionAvailable >= cost {
|
||||||
for i := range sg.StateUpgrade.UpgradeTech {
|
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
|
productionAvailable -= cost
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import (
|
|||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
e "github.com/iliadenisov/galaxy/internal/error"
|
e "github.com/iliadenisov/galaxy/internal/error"
|
||||||
"github.com/iliadenisov/galaxy/internal/model/game"
|
"github.com/iliadenisov/galaxy/internal/model/game"
|
||||||
|
"github.com/iliadenisov/galaxy/internal/number"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ShipGroup is a proxy func, nothing to cache
|
// ShipGroup is a proxy func, nothing to cache
|
||||||
@@ -525,33 +526,24 @@ func (c *Cache) validateShipGroupIndex(i int) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
func (c *Cache) unsafeCreateShips(ri int, classID uuid.UUID, planet uint, quantity uint) int {
|
||||||
TODO: Точность тех. уровней корабля
|
|
||||||
|
|
||||||
В целях избежания неточностей в расчетах, технологические уровни кораблей
|
|
||||||
округляются до третьего знака после запятой в момент постройки или
|
|
||||||
модернизации. Поэтому в отчетах у кораблей всегда указываются действительные,
|
|
||||||
а не округлённые уровни технологий.
|
|
||||||
*/
|
|
||||||
func (c *Cache) unsafeCreateShips(ri int, classID uuid.UUID, planet uint, quantity uint) {
|
|
||||||
st := c.MustShipType(ri, classID)
|
st := c.MustShipType(ri, classID)
|
||||||
// TODO: test new group levels
|
|
||||||
level := func(t game.Tech) float64 {
|
level := func(t game.Tech) float64 {
|
||||||
if t == game.TechDrive && st.DriveBlockMass() > 0 {
|
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 {
|
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 {
|
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 {
|
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
|
return 0
|
||||||
}
|
}
|
||||||
c.appendShipGroup(ri, &game.ShipGroup{
|
return c.appendShipGroup(ri, &game.ShipGroup{
|
||||||
OwnerID: c.g.Race[ri].ID,
|
OwnerID: c.g.Race[ri].ID,
|
||||||
TypeID: classID,
|
TypeID: classID,
|
||||||
Destination: planet,
|
Destination: planet,
|
||||||
|
|||||||
@@ -35,6 +35,29 @@ func TestCreateShips(t *testing.T) {
|
|||||||
assert.Len(t, slices.Collect(c.RaceShipGroups(1)), 2)
|
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) {
|
func TestShipGroupMerge(t *testing.T) {
|
||||||
c, g := newCache()
|
c, g := newCache()
|
||||||
|
|
||||||
|
|||||||
@@ -187,6 +187,9 @@ func (sg ShipGroup) CargoCapacity(st *ShipType) float64 {
|
|||||||
// Масса перевозимого груза -
|
// Масса перевозимого груза -
|
||||||
// общее количество единиц груза, деленное на технологический уровень Грузоперевозок
|
// общее количество единиц груза, деленное на технологический уровень Грузоперевозок
|
||||||
func (sg ShipGroup) CarryingMass() float64 {
|
func (sg ShipGroup) CarryingMass() float64 {
|
||||||
|
if sg.Load.F() == 0 {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
return sg.Load.F() / sg.TechLevel(TechCargo).F()
|
return sg.Load.F() / sg.TechLevel(TechCargo).F()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user