-
Notifications
You must be signed in to change notification settings - Fork 3
/
cleanup.go
146 lines (121 loc) · 3.82 KB
/
cleanup.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package cs
import "github.com/rs/zerolog/log"
/*
Because the game is actively running, bugs are introduced and we need to fix them as
we go. For example, a bug was introduced to "discover" player starbase designs leading
to duplciate designs on the UI.
This file will hold cleanup functions for cleaning up this sort of data on the game
*/
type Cleaner interface {
RemovePlayerDesignIntels(game *FullGame)
AddScannerToInnateScannerPlanets(game *FullGame)
AddRandomArtifactsToPlanets(game *FullGame)
ResetHomeworldBaseHab(game *FullGame)
FixMineralConc(game *FullGame)
}
type cleanup struct {
}
func NewCleaner() Cleaner {
return &cleanup{}
}
// cleanup design intels owned by the player
func (c *cleanup) RemovePlayerDesignIntels(game *FullGame) {
for _, player := range game.Players {
designIntels := make([]ShipDesignIntel, 0, len(player.ShipDesignIntels))
for _, design := range player.ShipDesignIntels {
if design.PlayerNum != player.Num {
designIntels = append(designIntels, design)
} else {
log.Info().
Int64("GameID", game.ID).
Str("Name", game.Name).
Msgf("cleanup: removing design intel for player %d's %s design", player.Num, design.Name)
}
}
player.ShipDesignIntels = designIntels
}
}
// ensure AR planets have scanners
func (c *cleanup) AddScannerToInnateScannerPlanets(game *FullGame) {
for _, planet := range game.Planets {
if !planet.Owned() {
continue
}
player := game.getPlayer(planet.PlayerNum)
if !player.Race.Spec.InnateScanner {
continue
}
planet.Scanner = true
planet.MarkDirty()
log.Info().
Int64("GameID", game.ID).
Str("Name", game.Name).
Msgf("cleanup: setting scanner to true for player %d's %s planet", player.Num, planet.Name)
}
}
// we support random artifacts now, yay! upgrade our existing games
func (c *cleanup) AddRandomArtifactsToPlanets(game *FullGame) {
if !game.RandomEvents {
return
}
for _, planet := range game.Planets {
if planet.Owned() {
continue
}
// check if this planet should have a random artifact
if game.Rules.RandomEventChances[RandomEventAncientArtifact] > game.Rules.random.Float64() {
planet.RandomArtifact = true
planet.MarkDirty()
log.Info().
Int64("GameID", game.ID).
Str("Name", game.Name).
Msgf("cleanup: added random artifact to planet %s", planet.Name)
}
}
}
func (c *cleanup) ResetHomeworldBaseHab(game *FullGame) {
for _, planet := range game.Planets {
if !planet.Homeworld {
continue
}
// these are homeworlds. hopefully they haven't been hit by a comet
// and re-terraformed...
prevHab := planet.BaseHab
planet.BaseHab = planet.Hab
planet.MarkDirty()
log.Info().
Int64("GameID", game.ID).
Str("Name", game.Name).
Msgf("cleanup: reset BaseHab on homeworld %s from %s to %s", planet.Name, prevHab, planet.BaseHab)
}
}
func (c *cleanup) FixMineralConc(game *FullGame) {
rules := NewRules()
minMinConc := rules.MinStartingMineralConcentration
for _, planet := range game.Planets {
// homeworlds are fine...
if planet.Homeworld {
continue
}
// this planet
if planet.MineralConcentration.Ironium < minMinConc ||
planet.MineralConcentration.Boranium < minMinConc ||
planet.MineralConcentration.Germanium < minMinConc {
prevMinConc := planet.MineralConcentration
if planet.MineralConcentration.Ironium < minMinConc {
planet.MineralConcentration.Ironium += minMinConc
}
if planet.MineralConcentration.Boranium < minMinConc {
planet.MineralConcentration.Boranium += minMinConc
}
if planet.MineralConcentration.Germanium < minMinConc {
planet.MineralConcentration.Germanium += minMinConc
}
planet.MarkDirty()
log.Info().
Int64("GameID", game.ID).
Str("Name", game.Name).
Msgf("cleanup: reset MineralConcentration on planet %s from %s to %s", planet.Name, prevMinConc, planet.MineralConcentration)
}
}
}