You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

325 lines
9.4 KiB

  1. package models
  2. import (
  3. "math"
  4. "github.com/arnaucube/gogame/constants"
  5. )
  6. // formulas
  7. // https://ogame.fandom.com/wiki/Formulas
  8. // https://ogame.fandom.com/wiki/Research
  9. // idelta is time in seconds units
  10. func MetalGrowth(ilvl int64, idelta int64) int64 {
  11. lvl := float64(ilvl)
  12. delta := float64(idelta)
  13. // 30 * L * 1.1^L
  14. perHour := constants.UniverseAcceleration * 30 * lvl * math.Pow(1.1, lvl)
  15. r := (perHour / 60) * delta * constants.MineVelocity
  16. return int64(r)
  17. }
  18. func CrystalGrowth(ilvl int64, idelta int64) int64 {
  19. lvl := float64(ilvl)
  20. delta := float64(idelta)
  21. // 20 * L * 1.1^L
  22. perHour := constants.UniverseAcceleration * 20 * lvl * math.Pow(1.1, lvl)
  23. r := (perHour / 60) * delta * constants.MineVelocity
  24. return int64(r)
  25. }
  26. func DeuteriumGrowth(ilvl int64, idelta int64) int64 {
  27. lvl := float64(ilvl)
  28. delta := float64(idelta)
  29. t := float64(240) // t: max temperature
  30. // 10 * L * 1.1^L * (−0.002 * T + 1.28))
  31. perHour := constants.UniverseAcceleration * 10 * lvl * math.Pow(1.1, lvl) * ((-0.002)*t + 1.28)
  32. r := (perHour / 60) * delta * constants.MineVelocity
  33. return int64(r)
  34. }
  35. func SolarGrowth(ilvl int64) int64 {
  36. lvl := float64(ilvl)
  37. // 20 * L * 1.1^L
  38. production := 20 * lvl * math.Pow(1.1, lvl)
  39. return int64(production)
  40. }
  41. func FusionGrowth(ilvl int64, ilvlTech int64, idelta int64) int64 {
  42. lvl := float64(ilvl)
  43. lvlTech := float64(ilvlTech)
  44. delta := float64(idelta)
  45. // 30 * L * (1.05 + lvlTech * 0.01)^lvl
  46. perHour := constants.UniverseAcceleration * 30 * math.Pow((1.05+lvlTech*0.01), lvl)
  47. r := (perHour / 60) * delta * constants.MineVelocity
  48. return int64(r)
  49. }
  50. func MetalMineEnergyConsumption(ilvl int64) int64 {
  51. lvl := float64(ilvl)
  52. // 10 * lvl * 1.1^lvl
  53. c := 10 * lvl * math.Pow(1.1, lvl)
  54. return int64(c)
  55. }
  56. func CrystalMineEnergyConsumption(ilvl int64) int64 {
  57. lvl := float64(ilvl)
  58. // 10 * lvl * 1.1^lvl
  59. c := 10 * lvl * math.Pow(1.1, lvl)
  60. return int64(c)
  61. }
  62. func DeuteriumMineEnergyConsumption(ilvl int64) int64 {
  63. lvl := float64(ilvl)
  64. // 20 * lvl * 1.1^lvl
  65. c := 10 * lvl * math.Pow(1.1, lvl)
  66. return int64(c)
  67. }
  68. // https://ogame.fandom.com/wiki/Buildings
  69. // https://ogame.fandom.com/wiki/Metal_Mine
  70. func MetalMineCost(ilvl int64) Resources {
  71. lvl := float64(ilvl)
  72. base := Resources{
  73. Metal: 60,
  74. Crystal: 15,
  75. Deuterium: 0,
  76. Energy: 0,
  77. }
  78. // cost = base * 1.5^(lvl-1)
  79. cost := Resources{}
  80. cost.Metal = int64(float64(base.Metal) * math.Pow(1.5, lvl-1))
  81. cost.Crystal = int64(float64(base.Crystal) * math.Pow(1.5, lvl-1))
  82. cost.Deuterium = int64(float64(base.Deuterium) * math.Pow(1.5, lvl-1))
  83. cost.Energy = int64(float64(base.Energy) * math.Pow(1.5, lvl-1))
  84. return cost
  85. }
  86. // https://ogame.fandom.com/wiki/Crystal_Mine
  87. func CrystalMineCost(ilvl int64) Resources {
  88. lvl := float64(ilvl)
  89. base := Resources{
  90. Metal: 48,
  91. Crystal: 24,
  92. Deuterium: 0,
  93. Energy: 0,
  94. }
  95. // cost = base * 1.6^(lvl-1)
  96. cost := Resources{}
  97. cost.Metal = int64(float64(base.Metal) * math.Pow(1.6, lvl-1))
  98. cost.Crystal = int64(float64(base.Crystal) * math.Pow(1.6, lvl-1))
  99. cost.Deuterium = int64(float64(base.Deuterium) * math.Pow(1.6, lvl-1))
  100. cost.Energy = int64(float64(base.Energy) * math.Pow(1.6, lvl-1))
  101. return cost
  102. }
  103. // https://ogame.fandom.com/wiki/Deuterium_Synthesizer
  104. func DeuteriumMineCost(ilvl int64) Resources {
  105. lvl := float64(ilvl)
  106. base := Resources{
  107. Metal: 225,
  108. Crystal: 75,
  109. Deuterium: 0,
  110. Energy: 0,
  111. }
  112. // cost = base * 1.5^(lvl-1)
  113. cost := Resources{}
  114. cost.Metal = int64(float64(base.Metal) * math.Pow(1.5, lvl-1))
  115. cost.Crystal = int64(float64(base.Crystal) * math.Pow(1.5, lvl-1))
  116. cost.Deuterium = int64(float64(base.Deuterium) * math.Pow(1.5, lvl-1))
  117. cost.Energy = int64(float64(base.Energy) * math.Pow(1.5, lvl-1))
  118. return cost
  119. }
  120. func EnergyMineCost(ilvl int64) Resources {
  121. lvl := float64(ilvl)
  122. base := Resources{
  123. Metal: 75,
  124. Crystal: 30,
  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. func FussionReactorCost(ilvl int64) Resources {
  137. lvl := float64(ilvl)
  138. base := Resources{
  139. Metal: 900,
  140. Crystal: 360,
  141. Deuterium: 180,
  142. Energy: 0,
  143. }
  144. // cost = base * 1.8^(lvl-1)
  145. cost := Resources{}
  146. cost.Metal = int64(float64(base.Metal) * math.Pow(1.8, lvl-1))
  147. cost.Crystal = int64(float64(base.Crystal) * math.Pow(1.8, lvl-1))
  148. cost.Deuterium = int64(float64(base.Deuterium) * math.Pow(1.8, lvl-1))
  149. cost.Energy = int64(float64(base.Energy) * math.Pow(1.8, lvl-1))
  150. return cost
  151. }
  152. func RoboticsFactoryCost(ilvl int64) Resources {
  153. lvl := float64(ilvl)
  154. base := Resources{
  155. Metal: 400,
  156. Crystal: 120,
  157. Deuterium: 200,
  158. Energy: 0,
  159. }
  160. // cost = base * 2^(lvl-1)
  161. cost := Resources{}
  162. cost.Metal = int64(float64(base.Metal) * math.Pow(2, lvl-1))
  163. cost.Crystal = int64(float64(base.Crystal) * math.Pow(2, lvl-1))
  164. cost.Deuterium = int64(float64(base.Deuterium) * math.Pow(2, lvl-1))
  165. cost.Energy = int64(float64(base.Energy) * math.Pow(2, lvl-1))
  166. return cost
  167. }
  168. func ShipyardCost(ilvl int64) Resources {
  169. lvl := float64(ilvl)
  170. base := Resources{
  171. Metal: 400,
  172. Crystal: 200,
  173. Deuterium: 100,
  174. Energy: 0,
  175. }
  176. // cost = base * 2^(lvl-1)
  177. cost := Resources{}
  178. cost.Metal = int64(float64(base.Metal) * math.Pow(2, lvl-1))
  179. cost.Crystal = int64(float64(base.Crystal) * math.Pow(2, lvl-1))
  180. cost.Deuterium = int64(float64(base.Deuterium) * math.Pow(2, lvl-1))
  181. cost.Energy = int64(float64(base.Energy) * math.Pow(2, lvl-1))
  182. return cost
  183. }
  184. func MetalStorageCost(ilvl int64) Resources {
  185. lvl := float64(ilvl)
  186. base := Resources{
  187. Metal: 1000,
  188. Crystal: 0,
  189. Deuterium: 0,
  190. Energy: 0,
  191. }
  192. // cost = base * 2^(lvl-1)
  193. cost := Resources{}
  194. cost.Metal = int64(float64(base.Metal) * math.Pow(2, lvl-1))
  195. cost.Crystal = 0
  196. cost.Deuterium = 0
  197. cost.Energy = 0
  198. return cost
  199. }
  200. func CrystalStorageCost(ilvl int64) Resources {
  201. lvl := float64(ilvl)
  202. base := Resources{
  203. Metal: 1000,
  204. Crystal: 500,
  205. Deuterium: 0,
  206. Energy: 0,
  207. }
  208. // cost = base * 2^(lvl-1)
  209. cost := Resources{}
  210. cost.Metal = int64(float64(base.Metal) * math.Pow(2, lvl-1))
  211. cost.Crystal = int64(float64(base.Crystal) * math.Pow(2, lvl-1))
  212. cost.Deuterium = 0
  213. cost.Energy = 0
  214. return cost
  215. }
  216. func DeuteriumStorageCost(ilvl int64) Resources {
  217. lvl := float64(ilvl)
  218. base := Resources{
  219. Metal: 1000,
  220. Crystal: 1000,
  221. Deuterium: 0,
  222. Energy: 0,
  223. }
  224. // cost = base * 2^(lvl-1)
  225. cost := Resources{}
  226. cost.Metal = int64(float64(base.Metal) * math.Pow(2, lvl-1))
  227. cost.Crystal = int64(float64(base.Crystal) * math.Pow(2, lvl-1))
  228. cost.Deuterium = int64(float64(base.Deuterium) * math.Pow(2, lvl-1))
  229. cost.Energy = int64(float64(base.Energy) * math.Pow(2, lvl-1))
  230. return cost
  231. }
  232. func 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. }
  248. func 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. }
  264. func 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. }
  280. func 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. }
  296. // TODO ConstructionTime and ResearchTime are following the formulas from https://ogame.fandom.com/wiki/Formulas
  297. // but are not giving exact same numbers than in online calculators
  298. func ConstructionTime(r Resources, roboticsLvl int64) int64 {
  299. naniteLvl := float64(1)
  300. // T(h) = (metal + crystal) / (2500 * (1+roboticsLvl) * 2^naniteLvl * universespeed)
  301. tHours := float64(r.Metal+r.Crystal) / (float64(2500) * float64(1+roboticsLvl) * math.Pow(2, naniteLvl) * constants.UniverseAcceleration)
  302. return int64(tHours * 3600)
  303. }
  304. func RessearchTime(r Resources, researchLvl int64) int64 {
  305. // T(h) = (metal + crystal) / (1000 * (1+researchLvl * universespeed)
  306. tHours := float64(r.Metal+r.Crystal) / (float64(1000) * float64(1+researchLvl*constants.UniverseAcceleration))
  307. return int64(tHours * 3600)
  308. }