feat: bomb planets

This commit is contained in:
Ilia Denisov
2026-01-19 23:08:57 +02:00
parent bd9db26ef4
commit 40b2cb27f6
13 changed files with 440 additions and 22 deletions
+1 -5
View File
@@ -5,7 +5,6 @@ import (
"math"
"github.com/google/uuid"
"github.com/iliadenisov/galaxy/internal/number"
)
type CargoType string
@@ -227,13 +226,10 @@ func (sg ShipGroup) UpgradeCargoCost(st *ShipType, cargo float64) float64 {
}
// Мощность бомбардировки
// TODO: maybe rounding must be done only for display?
func (sg ShipGroup) BombingPower(st *ShipType) float64 {
// return math.Sqrt(sg.Type.Weapons * sg.Weapons)
result := (math.Sqrt(st.Weapons*sg.TechLevel(TechWeapons))/10. + 1.) *
return (math.Sqrt(st.Weapons*sg.TechLevel(TechWeapons))/10. + 1.) *
st.Weapons *
sg.TechLevel(TechWeapons) *
float64(st.Armament) *
float64(sg.Number)
return number.Fixed3(result)
}
+6 -4
View File
@@ -6,6 +6,7 @@ import (
"github.com/google/uuid"
"github.com/iliadenisov/galaxy/internal/model/game"
"github.com/iliadenisov/galaxy/internal/number"
"github.com/stretchr/testify/assert"
)
@@ -104,8 +105,9 @@ func TestSpeed(t *testing.T) {
}
func TestBombingPower(t *testing.T) {
Gunship := game.ShipType{
BattleStation := game.ShipType{
ShipTypeReport: game.ShipTypeReport{
Name: "Battle_Station",
Drive: 60.0,
Armament: 3,
Weapons: 30.0,
@@ -122,9 +124,9 @@ func TestBombingPower(t *testing.T) {
game.TechCargo: 1.0,
},
}
expectedBombingPower := 139.295
result := sg.BombingPower(&Gunship)
assert.Equal(t, expectedBombingPower, result)
assert.Equal(t, 139.295, number.Fixed3(sg.BombingPower(&BattleStation)))
sg.Number = 2
assert.Equal(t, 278.590, number.Fixed3(sg.BombingPower(&BattleStation)))
}
func TestDriveEffective(t *testing.T) {
+30 -4
View File
@@ -41,9 +41,9 @@ type PlanetReportForeign struct {
PlanetReport
}
// TODO: delete func
// Производственный потенциал
func (p Planet) ProductionCapacity() float64 {
return p.Industry*0.75 + p.Population*0.25
return PlanetProduction(p.Industry, p.Population)
}
func PlanetProduction(industry, population float64) float64 {
@@ -53,7 +53,7 @@ func PlanetProduction(industry, population float64) float64 {
// Производство промышленности
// TODO: test on real values
func (p *Planet) IncreaseIndustry() {
prod := p.ProductionCapacity() / 5
prod := p.ProductionCapacity() / 5.
industryIncrement := math.Min(prod, p.Material)
p.Industry += industryIncrement
if p.Industry > p.Population {
@@ -62,6 +62,18 @@ func (p *Planet) IncreaseIndustry() {
}
}
func (p *Planet) UnpackCAPtoIND() {
if p.Capital == 0 {
return
}
cap := p.Population - p.Industry
if cap > p.Capital {
cap = p.Capital
}
p.Capital -= cap
p.Industry += cap
}
// Производство материалов
// TODO: test on real values
func (p *Planet) IncreaseMaterial() {
@@ -69,14 +81,28 @@ func (p *Planet) IncreaseMaterial() {
}
// Автоматическое увеличение населения на каждом ходу
// TODO: test
func (p *Planet) IncreasePopulation() {
p.Population *= 1.08
if p.Population > p.Size {
p.Colonists += (p.Population - p.Size) / 8
p.Colonists += (p.Population - p.Size) / 8.
p.Population = p.Size
}
}
func (p *Planet) UnpackCOLtoPOP() {
if p.Colonists < 1 {
return
}
maxCOL := uint((p.Size - p.Population) / 8.)
if float64(maxCOL) > p.Colonists {
maxCOL = uint(p.Colonists)
}
maxCOL = uint(float64(maxCOL) - math.Mod(float64(maxCOL), 8.))
p.Colonists -= float64(maxCOL)
p.Population += float64(maxCOL) * 8
}
func UnloadColonists(p Planet, v float64) Planet {
p.Population += v * 8
if p.Population > p.Size {
+1
View File
@@ -9,6 +9,7 @@ import (
func TestPlanetProduction(t *testing.T) {
assert.Equal(t, 1000., game.PlanetProduction(1000., 1000.))
assert.Equal(t, 625., game.PlanetProduction(500., 1000.))
assert.Equal(t, 750., game.PlanetProduction(1000., 0.))
assert.Equal(t, 250., game.PlanetProduction(0., 1000.))
}