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
+50
View File
@@ -3,8 +3,11 @@ package controller_test
import (
"testing"
"github.com/google/uuid"
"github.com/iliadenisov/galaxy/internal/controller"
e "github.com/iliadenisov/galaxy/internal/error"
"github.com/iliadenisov/galaxy/internal/model/game"
"github.com/iliadenisov/galaxy/internal/number"
"github.com/stretchr/testify/assert"
)
@@ -118,3 +121,50 @@ func TestPlanetProductionCapacity(t *testing.T) {
c.UpgradeShipGroup(0, game.TechDrive, 1.6)
assert.Equal(t, 53.125, c.PlanetProductionCapacity(R0_Planet_0_num))
}
func TestProduceShip(t *testing.T) {
Drone := game.ShipType{
ShipTypeReport: game.ShipTypeReport{
Name: "Drone",
Drive: 1,
Armament: 0,
Weapons: 0,
Shields: 0,
Cargo: 0,
},
}
BattleShip := game.ShipType{
ShipTypeReport: game.ShipTypeReport{
Name: "BattleShip",
Drive: 25,
Armament: 1,
Weapons: 30,
Shields: 35,
Cargo: 0,
},
}
p := controller.NewPlanet(0, "Planet_0", uuid.New(), 1, 1, 1000, 1000, 1000, 10, game.ProductionShip.AsType(uuid.Nil))
r := controller.ProduceShip(&p, Drone.EmptyMass())
assert.Equal(t, 99, r)
assert.InDelta(t, 0.0099, *p.Production.Progress, 0.000001)
(&p).Production = game.ProductionShip.AsType(uuid.Nil)
(&p).Capital = 10.
r = controller.ProduceShip(&p, Drone.EmptyMass())
assert.Equal(t, 100, r)
assert.Equal(t, 0., *p.Production.Progress)
assert.Equal(t, 0., number.Fixed3(p.Capital)) // TODO: zero CAP is not actual zero after series of decrements
(&p).Production = game.ProductionShip.AsType(uuid.Nil)
(&p).Capital = 0.
r = controller.ProduceShip(&p, BattleShip.EmptyMass())
assert.Equal(t, 1, r)
assert.InDelta(t, 0.1, *p.Production.Progress, 0.001)
(&p).Production = game.ProductionShip.AsType(uuid.Nil)
(&p).Capital = 20.
r = controller.ProduceShip(&p, BattleShip.EmptyMass())
assert.Equal(t, 1, r)
assert.Equal(t, 1./9., *p.Production.Progress)
}