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
62// https://ogame.fandom.com/wiki/Buildings
63
64// https://ogame.fandom.com/wiki/Metal_Mine
65func MetalMineCost(ilvl int64) Resources {
66 lvl := float64(ilvl)
67 base := Resources{
68 Metal: 60,
69 Crystal: 15,
70 Deuterium: 0,
71 Energy: 0,
72 }
73 // cost = base * 1.5^(lvl-1)
74 cost := Resources{}
75 cost.Metal = int64(float64(base.Metal) * math.Pow(1.5, lvl-1))
76 cost.Crystal = int64(float64(base.Crystal) * math.Pow(1.5, lvl-1))
77 cost.Deuterium = int64(float64(base.Deuterium) * math.Pow(1.5, lvl-1))
78 cost.Energy = int64(float64(base.Energy) * math.Pow(1.5, lvl-1))
79 return cost
80}
81
82// https://ogame.fandom.com/wiki/Crystal_Mine
83func CrystalMineCost(ilvl int64) Resources {
84 lvl := float64(ilvl)
85 base := Resources{
86 Metal: 48,
87 Crystal: 24,
88 Deuterium: 0,
89 Energy: 0,
90 }
91 // cost = base * 1.6^(lvl-1)
92 cost := Resources{}
93 cost.Metal = int64(float64(base.Metal) * math.Pow(1.6, lvl-1))
94 cost.Crystal = int64(float64(base.Crystal) * math.Pow(1.6, lvl-1))
95 cost.Deuterium = int64(float64(base.Deuterium) * math.Pow(1.6, lvl-1))
96 cost.Energy = int64(float64(base.Energy) * math.Pow(1.6, lvl-1))
97 return cost
98}
99
100// https://ogame.fandom.com/wiki/Deuterium_Synthesizer
101func DeuteriumMineCost(ilvl int64) Resources {
102 lvl := float64(ilvl)
103 base := Resources{
104 Metal: 225,
105 Crystal: 75,
106 Deuterium: 0,
107 Energy: 0,
108 }
109 // cost = base * 1.5^(lvl-1)
110 cost := Resources{}
111 cost.Metal = int64(float64(base.Metal) * math.Pow(1.5, lvl-1))
112 cost.Crystal = int64(float64(base.Crystal) * math.Pow(1.5, lvl-1))
113 cost.Deuterium = int64(float64(base.Deuterium) * math.Pow(1.5, lvl-1))
114 cost.Energy = int64(float64(base.Energy) * math.Pow(1.5, lvl-1))
115 return cost
116}
117
118func EnergyMineCost(ilvl int64) Resources {
119 lvl := float64(ilvl)
120 base := Resources{
121 Metal: 75,
122 Crystal: 30,
123 Deuterium: 0,
124 Energy: 0,
125 }
126 // cost = base * 1.5^(lvl-1)
127 cost := Resources{}
128 cost.Metal = int64(float64(base.Metal) * math.Pow(1.5, lvl-1))
129 cost.Crystal = int64(float64(base.Crystal) * math.Pow(1.5, lvl-1))
130 cost.Deuterium = int64(float64(base.Deuterium) * math.Pow(1.5, lvl-1))
131 cost.Energy = int64(float64(base.Energy) * math.Pow(1.5, lvl-1))
132 return cost
133}
134
135func FussionReactorCost(ilvl int64) Resources {
136 lvl := float64(ilvl)
137 base := Resources{
138 Metal: 900,
139 Crystal: 360,
140 Deuterium: 180,
141 Energy: 0,
142 }
143 // cost = base * 1.8^(lvl-1)
144 cost := Resources{}
145 cost.Metal = int64(float64(base.Metal) * math.Pow(1.8, lvl-1))
146 cost.Crystal = int64(float64(base.Crystal) * math.Pow(1.8, lvl-1))
147 cost.Deuterium = int64(float64(base.Deuterium) * math.Pow(1.8, lvl-1))
148 cost.Energy = int64(float64(base.Energy) * math.Pow(1.8, lvl-1))
149 return cost
150}
151func RoboticsFactoryCost(ilvl int64) Resources {
152 lvl := float64(ilvl)
153 base := Resources{
154 Metal: 400,
155 Crystal: 120,
156 Deuterium: 200,
157 Energy: 0,
158 }
159 // cost = base * 2^(lvl-1)
160 cost := Resources{}
161 cost.Metal = int64(float64(base.Metal) * math.Pow(2, lvl-1))
162 cost.Crystal = int64(float64(base.Crystal) * math.Pow(2, lvl-1))
163 cost.Deuterium = int64(float64(base.Deuterium) * math.Pow(2, lvl-1))
164 cost.Energy = int64(float64(base.Energy) * math.Pow(2, lvl-1))
165 return cost
166}
167func ShipyardCost(ilvl int64) Resources {
168 lvl := float64(ilvl)
169 base := Resources{
170 Metal: 400,
171 Crystal: 200,
172 Deuterium: 100,
173 Energy: 0,
174 }
175 // cost = base * 2^(lvl-1)
176 cost := Resources{}
177 cost.Metal = int64(float64(base.Metal) * math.Pow(2, lvl-1))
178 cost.Crystal = int64(float64(base.Crystal) * math.Pow(2, lvl-1))
179 cost.Deuterium = int64(float64(base.Deuterium) * math.Pow(2, lvl-1))
180 cost.Energy = int64(float64(base.Energy) * math.Pow(2, lvl-1))
181 return cost
182}
183func MetalStorageCost(ilvl int64) Resources {
184 lvl := float64(ilvl)
185 base := Resources{
186 Metal: 1000,
187 Crystal: 0,
188 Deuterium: 0,
189 Energy: 0,
190 }
191 // cost = base * 2^(lvl-1)
192 cost := Resources{}
193 cost.Metal = int64(float64(base.Metal) * math.Pow(2, lvl-1))
194 cost.Crystal = 0
195 cost.Deuterium = 0
196 cost.Energy = 0
197 return cost
198}
199func CrystalStorageCost(ilvl int64) Resources {
200 lvl := float64(ilvl)
201 base := Resources{
202 Metal: 1000,
203 Crystal: 500,
204 Deuterium: 0,
205 Energy: 0,
206 }
207 // cost = base * 2^(lvl-1)
208 cost := Resources{}
209 cost.Metal = int64(float64(base.Metal) * math.Pow(2, lvl-1))
210 cost.Crystal = int64(float64(base.Crystal) * math.Pow(2, lvl-1))
211 cost.Deuterium = 0
212 cost.Energy = 0
213 return cost
214}
215func DeuteriumStorageCost(ilvl int64) Resources {
216 lvl := float64(ilvl)
217 base := Resources{
218 Metal: 1000,
219 Crystal: 1000,
220 Deuterium: 0,
221 Energy: 0,
222 }
223 // cost = base * 2^(lvl-1)
224 cost := Resources{}
225 cost.Metal = int64(float64(base.Metal) * math.Pow(2, lvl-1))
226 cost.Crystal = int64(float64(base.Crystal) * math.Pow(2, lvl-1))
227 cost.Deuterium = int64(float64(base.Deuterium) * math.Pow(2, lvl-1))
228 cost.Energy = int64(float64(base.Energy) * math.Pow(2, lvl-1))
229 return cost
230}
231
232func RessearchLabCost(ilvl int64) Resources {
233 lvl := float64(ilvl)
234 base := Resources{
235 Metal: 200,
236 Crystal: 400,
237 Deuterium: 200,
238 Energy: 0,
239 }
240 // cost = base * 2^(lvl-1)
241 cost := Resources{}
242 cost.Metal = int64(float64(base.Metal) * math.Pow(2, lvl-1))
243 cost.Crystal = int64(float64(base.Crystal) * math.Pow(2, lvl-1))
244 cost.Deuterium = int64(float64(base.Deuterium) * math.Pow(2, lvl-1))
245 cost.Energy = int64(float64(base.Energy) * math.Pow(2, lvl-1))
246 return cost
247}
248func AllianceDepotCost(ilvl int64) Resources {
249 lvl := float64(ilvl)
250 base := Resources{
251 Metal: 20000,
252 Crystal: 40000,
253 Deuterium: 0,
254 Energy: 0,
255 }
256 // cost = base * 2^(lvl-1)
257 cost := Resources{}
258 cost.Metal = int64(float64(base.Metal) * math.Pow(2, lvl-1))
259 cost.Crystal = int64(float64(base.Crystal) * math.Pow(2, lvl-1))
260 cost.Deuterium = int64(float64(base.Deuterium) * math.Pow(2, lvl-1))
261 cost.Energy = int64(float64(base.Energy) * math.Pow(2, lvl-1))
262 return cost
263}
264func MissileSiloCost(ilvl int64) Resources {
265 lvl := float64(ilvl)
266 base := Resources{
267 Metal: 20000,
268 Crystal: 20000,
269 Deuterium: 1000,
270 Energy: 0,
271 }
272 // cost = base * 2^(lvl-1)
273 cost := Resources{}
274 cost.Metal = int64(float64(base.Metal) * math.Pow(2, lvl-1))
275 cost.Crystal = int64(float64(base.Crystal) * math.Pow(2, lvl-1))
276 cost.Deuterium = int64(float64(base.Deuterium) * math.Pow(2, lvl-1))
277 cost.Energy = int64(float64(base.Energy) * math.Pow(2, lvl-1))
278 return cost
279}
280func SpaceDockCost(ilvl int64) Resources {
281 lvl := float64(ilvl)
282 base := Resources{
283 Metal: 20000,
284 Crystal: 20000,
285 Deuterium: 1000,
286 Energy: 0,
287 }
288 // cost = base * 2^(lvl-1)
289 cost := Resources{}
290 cost.Metal = int64(float64(base.Metal) * math.Pow(2, lvl-1))
291 cost.Crystal = int64(float64(base.Crystal) * math.Pow(2, lvl-1))
292 cost.Deuterium = int64(float64(base.Deuterium) * math.Pow(2, lvl-1))
293 cost.Energy = int64(float64(base.Energy) * math.Pow(2, lvl-1))
294 return cost
295}