feat: store battles and bombings
This commit is contained in:
@@ -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,
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user