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 RessearchLabCost(ilvl int64) Resources {
136 lvl := float64(ilvl)
137 base := Resources{
138 Metal: 200,
139 Crystal: 400,
140 Deuterium: 200,
141 Energy: 0,
142 }
143 // cost = base * 1.5^(lvl-1)
144 cost := Resources{}
145 cost.Metal = int64(float64(base.Metal) * math.Pow(2, lvl-1))
146 cost.Crystal = int64(float64(base.Crystal) * math.Pow(2, lvl-1))
147 cost.Deuterium = int64(float64(base.Deuterium) * math.Pow(2, lvl-1))
148 cost.Energy = int64(float64(base.Energy) * math.Pow(2, lvl-1))
149 return cost
150}