mirror of
https://github.com/arnaucube/gogame.git
synced 2026-02-06 19:16:40 +01:00
add construction & research time calculations
This commit is contained in:
25
README.md
25
README.md
@@ -5,3 +5,28 @@ Nostalgic OGame clone in Go
|
||||
WIP
|
||||
|
||||
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
|
||||
|
||||
@@ -293,3 +293,17 @@ func SpaceDockCost(ilvl int64) Resources {
|
||||
cost.Energy = int64(float64(base.Energy) * math.Pow(2, lvl-1))
|
||||
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)
|
||||
}
|
||||
|
||||
@@ -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: 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))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user