Browse Source

add construction & research time calculations

master
arnaucube 5 years ago
parent
commit
bf1c564a45
4 changed files with 61 additions and 13 deletions
  1. +25
    -0
      README.md
  2. +14
    -0
      models/calc.go
  3. +22
    -0
      models/calc_test.go
  4. +0
    -13
      parts.md

+ 25
- 0
README.md

@ -5,3 +5,28 @@ Nostalgic OGame clone in Go
WIP WIP
The frontend is in https://github.com/arnaucube/gogame-frontend The frontend is in https://github.com/arnaucube/gogame-frontend
- [x] queue system
- [x] server api
- [ ] log system (console print and file save)
- [x] register/login
- [ ] data models
- [x] user
- [x] planet
- [x] galaxy
- [ ] ships
- [x] mongodb connectors
- [x] buildings engine
- [x] resources engine
- [ ] costs calculators
- [x] mining growth from mines/buildings
- [x] building costs
- [x] building time
- [x] research time
- [ ] energy costs
- [ ] ships costs
- [ ] ships building time
- [ ] ships travel time
- [ ] battle engine

+ 14
- 0
models/calc.go

@ -293,3 +293,17 @@ func SpaceDockCost(ilvl int64) Resources {
cost.Energy = int64(float64(base.Energy) * math.Pow(2, lvl-1)) cost.Energy = int64(float64(base.Energy) * math.Pow(2, lvl-1))
return cost return cost
} }
// TODO ConstructionTime and ResearchTime are following the formulas from https://ogame.fandom.com/wiki/Formulas
// but are not giving exact same numbers than in online calculators
func ConstructionTime(r Resources, roboticsLvl int64) int64 {
naniteLvl := float64(1)
// T(h) = (metal + crystal) / (2500 * (1+roboticsLvl) * 2^naniteLvl * universespeed)
tHours := float64(r.Metal+r.Crystal) / (float64(2500) * float64(1+roboticsLvl) * math.Pow(2, naniteLvl) * constants.UniverseAcceleration)
return int64(tHours * 3600)
}
func RessearchTime(r Resources, researchLvl int64) int64 {
// T(h) = (metal + crystal) / (1000 * (1+researchLvl * universespeed)
tHours := float64(r.Metal+r.Crystal) / (float64(1000) * float64(1+researchLvl*constants.UniverseAcceleration))
return int64(tHours * 3600)
}

+ 22
- 0
models/calc_test.go

@ -105,3 +105,25 @@ func TestMineCost(t *testing.T) {
assert.Equal(t, Resources{Metal: 40000, Crystal: 40000, Deuterium: 2000}, SpaceDockCost(2)) assert.Equal(t, Resources{Metal: 40000, Crystal: 40000, Deuterium: 2000}, SpaceDockCost(2))
assert.Equal(t, Resources{Metal: 327680000, Crystal: 327680000, Deuterium: 16384000}, SpaceDockCost(15)) assert.Equal(t, Resources{Metal: 327680000, Crystal: 327680000, Deuterium: 16384000}, SpaceDockCost(15))
} }
func TestConstructionTime(t *testing.T) {
// Numbers of the online calculators
// assert.Equal(t, int64(30), ConstructionTime(Resources{Metal: 60, Crystal: 15}, 1))
// assert.Equal(t, int64(53), ConstructionTime(Resources{Metal: 90, Crystal: 22}, 1))
// assert.Equal(t, int64(96), ConstructionTime(Resources{Metal: 135, Crystal: 33}, 1))
// assert.Equal(t, int64(383340), ConstructionTime(Resources{Metal: 204800, Crystal: 61440}, 10))
// Numbers following the formulas
assert.Equal(t, int64(27), ConstructionTime(Resources{Metal: 60, Crystal: 15}, 1))
assert.Equal(t, int64(40), ConstructionTime(Resources{Metal: 90, Crystal: 22}, 1))
assert.Equal(t, int64(60), ConstructionTime(Resources{Metal: 135, Crystal: 33}, 1))
assert.Equal(t, int64(17426), ConstructionTime(Resources{Metal: 204800, Crystal: 61440}, 10))
}
func TestRessearchTime(t *testing.T) {
assert.Equal(t, int64(1440), RessearchTime(Resources{Metal: 0, Crystal: 800}, 1))
assert.Equal(t, int64(5236), RessearchTime(Resources{Metal: 12800, Crystal: 3200}, 10))
// Numbers of the online calculators
// assert.Equal(t, int64(2880), RessearchTime(Resources{Metal: 12800, Crystal: 6400}, 15))
// assert.Equal(t, int64(360), RessearchTime(Resources{Metal: 1600, Crystal: 800}, 15))
}

+ 0
- 13
parts.md

@ -1,13 +0,0 @@
- queue system
- server api
- register/login
- data models
- user
- planet
- ships
- galaxy
- mongodb connectors
- planet engine
- building engine
- battle engine
- log system (console print and file save)

Loading…
Cancel
Save