arnaucube
arnaucube/gogame-oldPublic Self-hosted repository
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) int64 {
 43	lvl := float64(ilvl)
 44	// 20 * L * 1.1^L
 45	production := 20 * lvl * math.Pow(1.1, lvl)
 46	return int64(production)
 47}
 48func FusionGrowth(ilvl int64, ilvlTech int64, idelta int64) int64 {
 49	lvl := float64(ilvl)
 50	lvlTech := float64(ilvlTech)
 51	delta := float64(idelta)
 52
 53	// 30 * L * (1.05 + lvlTech * 0.01)^lvl
 54	perHour := constants.UniverseAcceleration * 30 * math.Pow((1.05+lvlTech*0.01), lvl)
 55	r := (perHour / 60) * delta * constants.MineVelocity
 56	return int64(r)
 57}
 58
 59func MetalMineEnergyConsumption(ilvl int64) int64 {
 60	lvl := float64(ilvl)
 61	// 10 * lvl * 1.1^lvl
 62	c := 10 * lvl * math.Pow(1.1, lvl)
 63	return int64(c)
 64}
 65func CrystalMineEnergyConsumption(ilvl int64) int64 {
 66	lvl := float64(ilvl)
 67	// 10 * lvl * 1.1^lvl
 68	c := 10 * lvl * math.Pow(1.1, lvl)
 69	return int64(c)
 70}
 71func DeuteriumMineEnergyConsumption(ilvl int64) int64 {
 72	lvl := float64(ilvl)
 73	// 20 * lvl * 1.1^lvl
 74	c := 10 * lvl * math.Pow(1.1, lvl)
 75	return int64(c)
 76}
 77
 78// https://ogame.fandom.com/wiki/Buildings
 79
 80// https://ogame.fandom.com/wiki/Metal_Mine
 81func MetalMineCost(ilvl int64) Resources {
 82	lvl := float64(ilvl)
 83	base := Resources{
 84		Metal:     60,
 85		Crystal:   15,
 86		Deuterium: 0,
 87		Energy:    0,
 88	}
 89	// cost = base * 1.5^(lvl-1)
 90	cost := Resources{}
 91	cost.Metal = int64(float64(base.Metal) * math.Pow(1.5, lvl-1))
 92	cost.Crystal = int64(float64(base.Crystal) * math.Pow(1.5, lvl-1))
 93	cost.Deuterium = int64(float64(base.Deuterium) * math.Pow(1.5, lvl-1))
 94	cost.Energy = int64(float64(base.Energy) * math.Pow(1.5, lvl-1))
 95	return cost
 96}
 97
 98// https://ogame.fandom.com/wiki/Crystal_Mine
 99func CrystalMineCost(ilvl int64) Resources {
100	lvl := float64(ilvl)
101	base := Resources{
102		Metal:     48,
103		Crystal:   24,
104		Deuterium: 0,
105		Energy:    0,
106	}
107	// cost = base * 1.6^(lvl-1)
108	cost := Resources{}
109	cost.Metal = int64(float64(base.Metal) * math.Pow(1.6, lvl-1))
110	cost.Crystal = int64(float64(base.Crystal) * math.Pow(1.6, lvl-1))
111	cost.Deuterium = int64(float64(base.Deuterium) * math.Pow(1.6, lvl-1))
112	cost.Energy = int64(float64(base.Energy) * math.Pow(1.6, lvl-1))
113	return cost
114}
115
116// https://ogame.fandom.com/wiki/Deuterium_Synthesizer
117func DeuteriumMineCost(ilvl int64) Resources {
118	lvl := float64(ilvl)
119	base := Resources{
120		Metal:     225,
121		Crystal:   75,
122		Deuterium: 0,
123		Energy:    0,
124	}
125	// cost = base * 1.5^(lvl-1)
126	cost := Resources{}
127	cost.Metal = int64(float64(base.Metal) * math.Pow(1.5, lvl-1))
128	cost.Crystal = int64(float64(base.Crystal) * math.Pow(1.5, lvl-1))
129	cost.Deuterium = int64(float64(base.Deuterium) * math.Pow(1.5, lvl-1))
130	cost.Energy = int64(float64(base.Energy) * math.Pow(1.5, lvl-1))
131	return cost
132}
133
134func EnergyMineCost(ilvl int64) Resources {
135	lvl := float64(ilvl)
136	base := Resources{
137		Metal:     75,
138		Crystal:   30,
139		Deuterium: 0,
140		Energy:    0,
141	}
142	// cost = base * 1.5^(lvl-1)
143	cost := Resources{}
144	cost.Metal = int64(float64(base.Metal) * math.Pow(1.5, lvl-1))
145	cost.Crystal = int64(float64(base.Crystal) * math.Pow(1.5, lvl-1))
146	cost.Deuterium = int64(float64(base.Deuterium) * math.Pow(1.5, lvl-1))
147	cost.Energy = int64(float64(base.Energy) * math.Pow(1.5, lvl-1))
148	return cost
149}
150
151func FussionReactorCost(ilvl int64) Resources {
152	lvl := float64(ilvl)
153	base := Resources{
154		Metal:     900,
155		Crystal:   360,
156		Deuterium: 180,
157		Energy:    0,
158	}
159	// cost = base * 1.8^(lvl-1)
160	cost := Resources{}
161	cost.Metal = int64(float64(base.Metal) * math.Pow(1.8, lvl-1))
162	cost.Crystal = int64(float64(base.Crystal) * math.Pow(1.8, lvl-1))
163	cost.Deuterium = int64(float64(base.Deuterium) * math.Pow(1.8, lvl-1))
164	cost.Energy = int64(float64(base.Energy) * math.Pow(1.8, lvl-1))
165	return cost
166}
167func RoboticsFactoryCost(ilvl int64) Resources {
168	lvl := float64(ilvl)
169	base := Resources{
170		Metal:     400,
171		Crystal:   120,
172		Deuterium: 200,
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 ShipyardCost(ilvl int64) Resources {
184	lvl := float64(ilvl)
185	base := Resources{
186		Metal:     400,
187		Crystal:   200,
188		Deuterium: 100,
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 = int64(float64(base.Crystal) * math.Pow(2, lvl-1))
195	cost.Deuterium = int64(float64(base.Deuterium) * math.Pow(2, lvl-1))
196	cost.Energy = int64(float64(base.Energy) * math.Pow(2, lvl-1))
197	return cost
198}
199func MetalStorageCost(ilvl int64) Resources {
200	lvl := float64(ilvl)
201	base := Resources{
202		Metal:     1000,
203		Crystal:   0,
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 = 0
211	cost.Deuterium = 0
212	cost.Energy = 0
213	return cost
214}
215func CrystalStorageCost(ilvl int64) Resources {
216	lvl := float64(ilvl)
217	base := Resources{
218		Metal:     1000,
219		Crystal:   500,
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 = 0
228	cost.Energy = 0
229	return cost
230}
231func DeuteriumStorageCost(ilvl int64) Resources {
232	lvl := float64(ilvl)
233	base := Resources{
234		Metal:     1000,
235		Crystal:   1000,
236		Deuterium: 0,
237		Energy:    0,
238	}
239	// cost = base * 2^(lvl-1)
240	cost := Resources{}
241	cost.Metal = int64(float64(base.Metal) * math.Pow(2, lvl-1))
242	cost.Crystal = int64(float64(base.Crystal) * math.Pow(2, lvl-1))
243	cost.Deuterium = int64(float64(base.Deuterium) * math.Pow(2, lvl-1))
244	cost.Energy = int64(float64(base.Energy) * math.Pow(2, lvl-1))
245	return cost
246}
247
248func RessearchLabCost(ilvl int64) Resources {
249	lvl := float64(ilvl)
250	base := Resources{
251		Metal:     200,
252		Crystal:   400,
253		Deuterium: 200,
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 AllianceDepotCost(ilvl int64) Resources {
265	lvl := float64(ilvl)
266	base := Resources{
267		Metal:     20000,
268		Crystal:   40000,
269		Deuterium: 0,
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 MissileSiloCost(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}
296func SpaceDockCost(ilvl int64) Resources {
297	lvl := float64(ilvl)
298	base := Resources{
299		Metal:     20000,
300		Crystal:   20000,
301		Deuterium: 1000,
302		Energy:    0,
303	}
304	// cost = base * 2^(lvl-1)
305	cost := Resources{}
306	cost.Metal = int64(float64(base.Metal) * math.Pow(2, lvl-1))
307	cost.Crystal = int64(float64(base.Crystal) * math.Pow(2, lvl-1))
308	cost.Deuterium = int64(float64(base.Deuterium) * math.Pow(2, lvl-1))
309	cost.Energy = int64(float64(base.Energy) * math.Pow(2, lvl-1))
310	return cost
311}
312
313// TODO ConstructionTime and ResearchTime are following the formulas from https://ogame.fandom.com/wiki/Formulas
314// but are not giving exact same numbers than in online calculators
315func ConstructionTime(r Resources, roboticsLvl int64) int64 {
316	naniteLvl := float64(1)
317	// T(h) = (metal + crystal) / (2500 * (1+roboticsLvl) * 2^naniteLvl * universespeed)
318	tHours := float64(r.Metal+r.Crystal) / (float64(2500) * float64(1+roboticsLvl) * math.Pow(2, naniteLvl) * constants.UniverseAcceleration)
319	return int64(tHours * 3600)
320}
321func RessearchTime(r Resources, researchLvl int64) int64 {
322	// T(h) = (metal + crystal) / (1000 * (1+researchLvl * universespeed)
323	tHours := float64(r.Metal+r.Crystal) / (float64(1000) * float64(1+researchLvl*constants.UniverseAcceleration))
324	return int64(tHours * 3600)
325}