energy consumption and production working
arnaucube arnaucube@gmail.com
Mon, 22 Jul 2019 19:02:38 +0200
6 files changed,
30 insertions(+),
22 deletions(-)
M
README.md
→
README.md
@@ -26,8 +26,13 @@ - [x] mining growth from mines/buildings
- [x] building costs - [x] building time - [x] research time - - [ ] energy costs + - [x] energy costs + - [x] energy production + - [ ] production factor (based on positive/negative energy) +- [ ] ships - [ ] ships costs - [ ] ships building time - [ ] ships travel time - [ ] battle engine +- [ ] lab technologies + - [ ] how tech affects to production of material & times
M
constants/constants.go
→
constants/constants.go
@@ -5,7 +5,7 @@
const GALAXYSIZE = 50 const SOLARSYSTEMSIZE = 15 -const UniverseAcceleration = 5 +const UniverseAcceleration = 1 const MineVelocity = 1 // extra
M
models/calc.go
→
models/calc.go
@@ -39,14 +39,11 @@ perHour := constants.UniverseAcceleration * 10 * lvl * math.Pow(1.1, lvl) * ((-0.002)*t + 1.28)
r := (perHour / 60) * delta * constants.MineVelocity return int64(r) } -func SolarGrowth(ilvl int64, idelta int64) int64 { +func SolarGrowth(ilvl int64) int64 { lvl := float64(ilvl) - delta := float64(idelta) - // 20 * L * 1.1^L - perHour := constants.UniverseAcceleration * 20 * lvl * math.Pow(1.1, lvl) - r := (perHour / 60) * delta * constants.MineVelocity - return int64(r) + production := 20 * lvl * math.Pow(1.1, lvl) + return int64(production) } func FusionGrowth(ilvl int64, ilvlTech int64, idelta int64) int64 { lvl := float64(ilvl)
M
models/calc_test.go
→
models/calc_test.go
@@ -24,9 +24,9 @@ assert.Equal(t, int64(17), DeuteriumGrowth(1, 120)/constants.MineVelocity)
assert.Equal(t, int64(19), DeuteriumGrowth(2, 60)/constants.MineVelocity) // solar - assert.Equal(t, int64(22), SolarGrowth(1, 60)/constants.MineVelocity) - assert.Equal(t, int64(44), SolarGrowth(1, 120)/constants.MineVelocity) - assert.Equal(t, int64(48), SolarGrowth(2, 60)/constants.MineVelocity) + assert.Equal(t, int64(22), SolarGrowth(1)) + assert.Equal(t, int64(48), SolarGrowth(2)) + assert.Equal(t, int64(79), SolarGrowth(3)) // fusion assert.Equal(t, int64(31), FusionGrowth(1, 1, 60)/constants.MineVelocity)
M
models/planet.go
→
models/planet.go
@@ -2,7 +2,6 @@ package models
import ( "errors" - "fmt" "strconv" "time"@@ -116,17 +115,24 @@ delta := time.Since(p.LastUpdated).Seconds()
// get Resource-Plant level in each planet // and calculate growth = ResourcePlant.Level for each planet - var metalGrowth, crystalGrowth, deuteriumGrowth, energyGrowth int64 + var metalGrowth, crystalGrowth, deuteriumGrowth int64 metalGrowth = metalGrowth + MetalGrowth(p.Buildings["metalmine"], int64(delta)) - crystalGrowth = crystalGrowth + MetalGrowth(p.Buildings["crystalmine"], int64(delta)) - deuteriumGrowth = deuteriumGrowth + MetalGrowth(p.Buildings["deuteriummine"], int64(delta)) - energyGrowth = energyGrowth + MetalGrowth(p.Buildings["energymine"], int64(delta)) + crystalGrowth = crystalGrowth + CrystalGrowth(p.Buildings["crystalmine"], int64(delta)) + deuteriumGrowth = deuteriumGrowth + DeuteriumGrowth(p.Buildings["deuteriummine"], int64(delta)) + + // get energy generated and used + energyGenerated := int64(500) + energyGenerated = energyGenerated + SolarGrowth(p.Buildings["energymine"]) + var energyUsed int64 + energyUsed = energyUsed + MetalMineEnergyConsumption(p.Buildings["metalmine"]) + energyUsed = energyUsed + CrystalMineEnergyConsumption(p.Buildings["crystalmine"]) + energyUsed = energyUsed + DeuteriumMineEnergyConsumption(p.Buildings["deuteriummine"]) // calculate newAmount = oldAmount + growth p.Resources.Metal = p.Resources.Metal + metalGrowth p.Resources.Crystal = p.Resources.Crystal + crystalGrowth p.Resources.Deuterium = p.Resources.Deuterium + deuteriumGrowth - p.Resources.Energy = p.Resources.Energy + energyGrowth + p.Resources.Energy = energyGenerated - energyUsed // store new amount to user db err = p.StoreInDb()@@ -152,9 +158,9 @@ }
if p.Resources.Deuterium < r.Deuterium { return errors.New("not enough deuterium resources") } - if p.Resources.Energy < r.Energy { - return errors.New("not enough energy resources") - } + // if p.Resources.Energy < r.Energy { + // return errors.New("not enough energy resources") + // } p.Resources.Metal = p.Resources.Metal - r.Metal p.Resources.Crystal = p.Resources.Crystal - r.Crystal@@ -271,6 +277,7 @@ resourcesNeeded, err := p.GetBuildingCost(building)
if err != nil { return err } + resourcesNeeded.Energy = 0 // get time cost of the build timei64 := ConstructionTime(resourcesNeeded, p.Buildings["roboticsfactory"]) endsTime := time.Now().Add(time.Second * time.Duration(timei64))@@ -298,6 +305,5 @@ p = p + r.Metal
p = p + r.Crystal p = p + r.Deuterium p = p + r.Energy - fmt.Println("p", p) return p }