feat: store battles and bombings

This commit is contained in:
Ilia Denisov
2026-01-30 18:57:43 +03:00
parent 824f6609ab
commit 4c14234afb
16 changed files with 274 additions and 103 deletions
+11 -2
View File
@@ -14,6 +14,7 @@ type Battle struct {
ID uuid.UUID
Planet uint
observerGroups map[int]bool // True = In_Battle, False = Out_Battle
initialNumbers map[int]uint // Initial number of ships in the group
Protocol []BattleAction
shipAmmo map[int]uint
@@ -22,7 +23,7 @@ type Battle struct {
type BattleAction struct {
Attacker int
Defenter int
Defender int
Destroyed bool
}
@@ -94,6 +95,11 @@ func ProduceBattles(c *Cache) []*Battle {
result := make([]*Battle, 0)
// TODO: check this behavior:
// Multiple battles on single planet shoul be produced as single battle too:
// A <--> B
// C <--> D
// where: A in peace with [C, D], B in peace with [C, D], and so on.
for pl, observerGroups := range planetGroups {
battleGroups := FilterBattleGroups(c, observerGroups)
b := &Battle{
@@ -102,6 +108,9 @@ func ProduceBattles(c *Cache) []*Battle {
attacker: make(map[int]map[int]float64),
shipAmmo: make(map[int]uint),
}
for sgi := range observerGroups {
b.initialNumbers[sgi] = c.ShipGroup(sgi).Number
}
for i := range battleGroups {
attIdx := battleGroups[i]
@@ -159,7 +168,7 @@ func SingleBattle(c *Cache, b *Battle) {
b.Protocol = append(b.Protocol, BattleAction{
Attacker: attIdx,
Defenter: defIdx,
Defender: defIdx,
Destroyed: destroyed,
})