gogame-old/models/calc.go
models/calc.goRaw
1package models
2
3import (
4 "math"
5
6 "github.com/arnaucube/gogame/constants"
7)
8
9// formulas
10// https://ogame.fandom.com/wiki/Formulas
11// https://ogame.fandom.com/wiki/Research
12
13// idelta is time in seconds units
14func MetalGrowth(ilvl int64, idelta int64) int64 {
15 lvl := float64(ilvl)
16 delta := float64(idelta)
17
18 // 30 * L * 1.1^L
19 perHour := constants.UniverseAcceleration * 30 * lvl * math.Pow(1.1, lvl)
20 r := (perHour / 60) * delta * constants.MineVelocity
21 return int64(r)
22}
23func CrystalGrowth(ilvl int64, idelta int64) int64 {
24 lvl := float64(ilvl)
25 delta := float64(idelta)
26
27 // 20 * L * 1.1^L
28 perHour := constants.UniverseAcceleration * 20 * lvl * math.Pow(1.1, lvl)
29 r := (perHour / 60) * delta * constants.MineVelocity
30 return int64(r)
31}
32func DeuteriumGrowth(ilvl int64, idelta int64) int64 {
33 lvl := float64(ilvl)
34 delta := float64(idelta)
35
36 t := float64(240) // t: max temperature
37 // 10 * L * 1.1^L * (−0.002 * T + 1.28))
38 perHour := constants.UniverseAcceleration * 10 * lvl * math.Pow(1.1, lvl) * ((-0.002)*t + 1.28)
39 r := (perHour / 60) * delta * constants.MineVelocity
40 return int64(r)
41}
42func SolarGrowth(ilvl int64, idelta int64) int64 {
43 lvl := float64(ilvl)
44 delta := float64(idelta)
45
46 // 20 * L * 1.1^L
47 perHour := constants.UniverseAcceleration * 20 * lvl * math.Pow(1.1, lvl)
48 r := (perHour / 60) * delta * constants.MineVelocity
49 return int64(r)
50}
51func FusionGrowth(ilvl int64, ilvlTech int64, idelta int64) int64 {
52 lvl := float64(ilvl)
53 lvlTech := float64(ilvlTech)
54 delta := float64(idelta)
55
56 // 30 * L * (1.05 + lvlTech * 0.01)^lvl
57 perHour := constants.UniverseAcceleration * 30 * math.Pow((1.05+lvlTech*0.01), lvl)
58 r := (perHour / 60) * delta * constants.MineVelocity
59 return int64(r)
60}
61
62func MetalMineEnergyConsumption(ilvl int64) int64 {
63 lvl := float64(ilvl)
64 // 10 * lvl * 1.1^lvl
65 c := 10 * lvl * math.Pow(1.1, lvl)
66 return int64(c)
67}
68func CrystalMineEnergyConsumption(ilvl int64) int64 {
69 lvl := float64(ilvl)
70 // 10 * lvl * 1.1^lvl
71 c := 10 * lvl * math.Pow(1.1, lvl)
72 return int64(c)
73}
74func DeuteriumMineEnergyConsumption(ilvl int64) int64 {
75 lvl := float64(ilvl)
76 // 20 * lvl * 1.1^lvl
77 c := 10 * lvl * math.Pow(1.1, lvl)
78 return int64(c)
79}
80
81// https://ogame.fandom.com/wiki/Buildings
82
83// https://ogame.fandom.com/wiki/Metal_Mine
84func MetalMineCost(ilvl int64) Resources {
85 lvl := float64(ilvl)
86 base := Resources{
87 Metal: 60,
88 Crystal: 15,
89 Deuterium: 0,
90 Energy: 0,
91 }
92 // cost = base * 1.5^(lvl-1)
93 cost := Resources{}
94 cost.Metal = int64(float64(base.Metal) * math.Pow(1.5, lvl-1))
95 cost.Crystal = int64(float64(base.Crystal) * math.Pow(1.5, lvl-1))
96 cost.Deuterium = int64(float64(base.Deuterium) * math.Pow(1.5, lvl-1))
97 cost.Energy = int64(float64(base.Energy) * math.Pow(1.5, lvl-1))
98 return cost
99}
100
101// https://ogame.fandom.com/wiki/Crystal_Mine
102func CrystalMineCost(ilvl int64) Resources {
103 lvl := float64(ilvl)
104 base := Resources{
105 Metal: 48,
106 Crystal: 24,
107 Deuterium: 0,
108 Energy: 0,
109 }
110 // cost = base * 1.6^(lvl-1)
111 cost := Resources{}
112 cost.Metal = int64(float64(base.Metal) * math.Pow(1.6, lvl-1))
113 cost.Crystal = int64(float64(base.Crystal) * math.Pow(1.6, lvl-1))
114 cost.Deuterium = int64(float64(base.Deuterium) * math.Pow(1.6, lvl-1))
115 cost.Energy = int64(float64(base.Energy) * math.Pow(1.6, lvl-1))
116 return cost
117}
118
119// https://ogame.fandom.com/wiki/Deuterium_Synthesizer
120func DeuteriumMineCost(ilvl int64) Resources {
121 lvl := float64(ilvl)
122 base := Resources{
123 Metal: 225,
124 Crystal: 75,
125 Deuterium: 0,
126 Energy: 0,
127 }
128 // cost = base * 1.5^(lvl-1)
129 cost := Resources{}
130 cost.Metal = int64(float64(base.Metal) * math.Pow(1.5, lvl-1))
131 cost.Crystal = int64(float64(base.Crystal) * math.Pow(1.5, lvl-1))
132 cost.Deuterium = int64(float64(base.Deuterium) * math.Pow(1.5, lvl-1))
133 cost.Energy = int64(float64(base.Energy) * math.Pow(1.5, lvl-1))
134 return cost
135}
136
137func EnergyMineCost(ilvl int64) Resources {
138 lvl := float64(ilvl)
139 base := Resources{
140 Metal: 75,
141 Crystal: 30,
142 Deuterium: 0,
143 Energy: 0,
144 }
145 // cost = base * 1.5^(lvl-1)
146 cost := Resources{}
147 cost.Metal = int64(float64(base.Metal) * math.Pow(1.5, lvl-1))
148 cost.Crystal = int64(float64(base.Crystal) * math.Pow(1.5, lvl-1))
149 cost.Deuterium = int64(float64(base.Deuterium) * math.Pow(1.5, lvl-1))
150 cost.Energy = int64(float64(base.Energy) * math.Pow(1.5, lvl-1))
151 return cost
152}
153
154func FussionReactorCost(ilvl int64) Resources {
155 lvl := float64(ilvl)
156 base := Resources{
157 Metal: 900,
158 Crystal: 360,
159 Deuterium: 180,
160 Energy: 0,
161 }
162 // cost = base * 1.8^(lvl-1)
163 cost := Resources{}
164 cost.Metal = int64(float64(base.Metal) * math.Pow(1.8, lvl-1))
165 cost.Crystal = int64(float64(base.Crystal) * math.Pow(1.8, lvl-1))
166 cost.Deuterium = int64(float64(base.Deuterium) * math.Pow(1.8, lvl-1))
167 cost.Energy = int64(float64(base.Energy) * math.Pow(1.8, lvl-1))
168 return cost
169}
170func RoboticsFactoryCost(ilvl int64) Resources {
171 lvl := float64(ilvl)
172 base := Resources{
173 Metal: 400,
174 Crystal: 120,
175 Deuterium: 200,
176 Energy: 0,
177 }
178 // cost = base * 2^(lvl-1)
179 cost := Resources{}
180 cost.Metal = int64(float64(base.Metal) * math.Pow(2, lvl-1))
181 cost.Crystal = int64(float64(base.Crystal) * math.Pow(2, lvl-1))
182 cost.Deuterium = int64(float64(base.Deuterium) * math.Pow(2, lvl-1))
183 cost.Energy = int64(float64(base.Energy) * math.Pow(2, lvl-1))
184 return cost
185}
186func ShipyardCost(ilvl int64) Resources {
187 lvl := float64(ilvl)
188 base := Resources{
189 Metal: 400,
190 Crystal: 200,
191 Deuterium: 100,
192 Energy: 0,
193 }
194 // cost = base * 2^(lvl-1)
195 cost := Resources{}
196 cost.Metal = int64(float64(base.Metal) * math.Pow(2, lvl-1))
197 cost.Crystal = int64(float64(base.Crystal) * math.Pow(2, lvl-1))
198 cost.Deuterium = int64(float64(base.Deuterium) * math.Pow(2, lvl-1))
199 cost.Energy = int64(float64(base.Energy) * math.Pow(2, lvl-1))
200 return cost
201}
202func MetalStorageCost(ilvl int64) Resources {
203 lvl := float64(ilvl)
204 base := Resources{
205 Metal: 1000,
206 Crystal: 0,
207 Deuterium: 0,
208 Energy: 0,
209 }
210 // cost = base * 2^(lvl-1)
211 cost := Resources{}
212 cost.Metal = int64(float64(base.Metal) * math.Pow(2, lvl-1))
213 cost.Crystal = 0
214 cost.Deuterium = 0
215 cost.Energy = 0
216 return cost
217}
218func CrystalStorageCost(ilvl int64) Resources {
219 lvl := float64(ilvl)
220 base := Resources{
221 Metal: 1000,
222 Crystal: 500,
223 Deuterium: 0,
224 Energy: 0,
225 }
226 // cost = base * 2^(lvl-1)
227 cost := Resources{}
228 cost.Metal = int64(float64(base.Metal) * math.Pow(2, lvl-1))
229 cost.Crystal = int64(float64(base.Crystal) * math.Pow(2, lvl-1))
230 cost.Deuterium = 0
231 cost.Energy = 0
232 return cost
233}
234func DeuteriumStorageCost(ilvl int64) Resources {
235 lvl := float64(ilvl)
236 base := Resources{
237 Metal: 1000,
238 Crystal: 1000,
239 Deuterium: 0,
240 Energy: 0,
241 }
242 // cost = base * 2^(lvl-1)
243 cost := Resources{}
244 cost.Metal = int64(float64(base.Metal) * math.Pow(2, lvl-1))
245 cost.Crystal = int64(float64(base.Crystal) * math.Pow(2, lvl-1))
246 cost.Deuterium = int64(float64(base.Deuterium) * math.Pow(2, lvl-1))
247 cost.Energy = int64(float64(base.Energy) * math.Pow(2, lvl-1))
248 return cost
249}
250
251func RessearchLabCost(ilvl int64) Resources {
252 lvl := float64(ilvl)
253 base := Resources{
254 Metal: 200,
255 Crystal: 400,
256 Deuterium: 200,
257 Energy: 0,
258 }
259 // cost = base * 2^(lvl-1)
260 cost := Resources{}
261 cost.Metal = int64(float64(base.Metal) * math.Pow(2, lvl-1))
262 cost.Crystal = int64(float64(base.Crystal) * math.Pow(2, lvl-1))
263 cost.Deuterium = int64(float64(base.Deuterium) * math.Pow(2, lvl-1))
264 cost.Energy = int64(float64(base.Energy) * math.Pow(2, lvl-1))
265 return cost
266}
267func AllianceDepotCost(ilvl int64) Resources {
268 lvl := float64(ilvl)
269 base := Resources{
270 Metal: 20000,
271 Crystal: 40000,
272 Deuterium: 0,
273 Energy: 0,
274 }
275 // cost = base * 2^(lvl-1)
276 cost := Resources{}
277 cost.Metal = int64(float64(base.Metal) * math.Pow(2, lvl-1))
278 cost.Crystal = int64(float64(base.Crystal) * math.Pow(2, lvl-1))
279 cost.Deuterium = int64(float64(base.Deuterium) * math.Pow(2, lvl-1))
280 cost.Energy = int64(float64(base.Energy) * math.Pow(2, lvl-1))
281 return cost
282}
283func MissileSiloCost(ilvl int64) Resources {
284 lvl := float64(ilvl)
285 base := Resources{
286 Metal: 20000,
287 Crystal: 20000,
288 Deuterium: 1000,
289 Energy: 0,
290 }
291 // cost = base * 2^(lvl-1)
292 cost := Resources{}
293 cost.Metal = int64(float64(base.Metal) * math.Pow(2, lvl-1))
294 cost.Crystal = int64(float64(base.Crystal) * math.Pow(2, lvl-1))
295 cost.Deuterium = int64(float64(base.Deuterium) * math.Pow(2, lvl-1))
296 cost.Energy = int64(float64(base.Energy) * math.Pow(2, lvl-1))
297 return cost
298}
299func SpaceDockCost(ilvl int64) Resources {
300 lvl := float64(ilvl)
301 base := Resources{
302 Metal: 20000,
303 Crystal: 20000,
304 Deuterium: 1000,
305 Energy: 0,
306 }
307 // cost = base * 2^(lvl-1)
308 cost := Resources{}
309 cost.Metal = int64(float64(base.Metal) * math.Pow(2, lvl-1))
310 cost.Crystal = int64(float64(base.Crystal) * math.Pow(2, lvl-1))
311 cost.Deuterium = int64(float64(base.Deuterium) * math.Pow(2, lvl-1))
312 cost.Energy = int64(float64(base.Energy) * math.Pow(2, lvl-1))
313 return cost
314}
315
316// TODO ConstructionTime and ResearchTime are following the formulas from https://ogame.fandom.com/wiki/Formulas
317// but are not giving exact same numbers than in online calculators
318func ConstructionTime(r Resources, roboticsLvl int64) int64 {
319 naniteLvl := float64(1)
320 // T(h) = (metal + crystal) / (2500 * (1+roboticsLvl) * 2^naniteLvl * universespeed)
321 tHours := float64(r.Metal+r.Crystal) / (float64(2500) * float64(1+roboticsLvl) * math.Pow(2, naniteLvl) * constants.UniverseAcceleration)
322 return int64(tHours * 3600)
323}
324func RessearchTime(r Resources, researchLvl int64) int64 {
325 // T(h) = (metal + crystal) / (1000 * (1+researchLvl * universespeed)
326 tHours := float64(r.Metal+r.Crystal) / (float64(1000) * float64(1+researchLvl*constants.UniverseAcceleration))
327 return int64(tHours * 3600)
328}