energy consumption and production working

This commit is contained in:
arnaucube
2019-07-22 19:02:38 +02:00
parent 7fddfa16c4
commit fc44d3cbec
6 changed files with 30 additions and 22 deletions

View File

@@ -26,8 +26,13 @@ The frontend is in https://github.com/arnaucube/gogame-frontend
- [x] building costs - [x] building costs
- [x] building time - [x] building time
- [x] research time - [x] research time
- [ ] energy costs - [x] energy costs
- [x] energy production
- [ ] production factor (based on positive/negative energy)
- [ ] ships
- [ ] ships costs - [ ] ships costs
- [ ] ships building time - [ ] ships building time
- [ ] ships travel time - [ ] ships travel time
- [ ] battle engine - [ ] battle engine
- [ ] lab technologies
- [ ] how tech affects to production of material & times

View File

@@ -5,7 +5,7 @@ package constants
const GALAXYSIZE = 50 const GALAXYSIZE = 50
const SOLARSYSTEMSIZE = 15 const SOLARSYSTEMSIZE = 15
const UniverseAcceleration = 5 const UniverseAcceleration = 1
const MineVelocity = 1 const MineVelocity = 1
// extra // extra

2
go.mod
View File

@@ -17,4 +17,4 @@ require (
gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce
) )
replace githoub.com/arnaucube/gogame => ./ replace github.com/arnaucube/gogame => ./

View File

@@ -39,14 +39,11 @@ func DeuteriumGrowth(ilvl int64, idelta int64) int64 {
r := (perHour / 60) * delta * constants.MineVelocity r := (perHour / 60) * delta * constants.MineVelocity
return int64(r) return int64(r)
} }
func SolarGrowth(ilvl int64, idelta int64) int64 { func SolarGrowth(ilvl int64) int64 {
lvl := float64(ilvl) lvl := float64(ilvl)
delta := float64(idelta)
// 20 * L * 1.1^L // 20 * L * 1.1^L
perHour := constants.UniverseAcceleration * 20 * lvl * math.Pow(1.1, lvl) production := 20 * lvl * math.Pow(1.1, lvl)
r := (perHour / 60) * delta * constants.MineVelocity return int64(production)
return int64(r)
} }
func FusionGrowth(ilvl int64, ilvlTech int64, idelta int64) int64 { func FusionGrowth(ilvl int64, ilvlTech int64, idelta int64) int64 {
lvl := float64(ilvl) lvl := float64(ilvl)

View File

@@ -24,9 +24,9 @@ func TestGrowth(t *testing.T) {
assert.Equal(t, int64(19), DeuteriumGrowth(2, 60)/constants.MineVelocity) assert.Equal(t, int64(19), DeuteriumGrowth(2, 60)/constants.MineVelocity)
// solar // solar
assert.Equal(t, int64(22), SolarGrowth(1, 60)/constants.MineVelocity) assert.Equal(t, int64(22), SolarGrowth(1))
assert.Equal(t, int64(44), SolarGrowth(1, 120)/constants.MineVelocity) assert.Equal(t, int64(48), SolarGrowth(2))
assert.Equal(t, int64(48), SolarGrowth(2, 60)/constants.MineVelocity) assert.Equal(t, int64(79), SolarGrowth(3))
// fusion // fusion
assert.Equal(t, int64(31), FusionGrowth(1, 1, 60)/constants.MineVelocity) assert.Equal(t, int64(31), FusionGrowth(1, 1, 60)/constants.MineVelocity)

View File

@@ -2,7 +2,6 @@ package models
import ( import (
"errors" "errors"
"fmt"
"strconv" "strconv"
"time" "time"
@@ -116,17 +115,24 @@ func (p *Planet) GetResources() (*Resources, error) {
// get Resource-Plant level in each planet // get Resource-Plant level in each planet
// and calculate growth = ResourcePlant.Level for 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)) metalGrowth = metalGrowth + MetalGrowth(p.Buildings["metalmine"], int64(delta))
crystalGrowth = crystalGrowth + MetalGrowth(p.Buildings["crystalmine"], int64(delta)) crystalGrowth = crystalGrowth + CrystalGrowth(p.Buildings["crystalmine"], int64(delta))
deuteriumGrowth = deuteriumGrowth + MetalGrowth(p.Buildings["deuteriummine"], int64(delta)) deuteriumGrowth = deuteriumGrowth + DeuteriumGrowth(p.Buildings["deuteriummine"], int64(delta))
energyGrowth = energyGrowth + MetalGrowth(p.Buildings["energymine"], 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 // calculate newAmount = oldAmount + growth
p.Resources.Metal = p.Resources.Metal + metalGrowth p.Resources.Metal = p.Resources.Metal + metalGrowth
p.Resources.Crystal = p.Resources.Crystal + crystalGrowth p.Resources.Crystal = p.Resources.Crystal + crystalGrowth
p.Resources.Deuterium = p.Resources.Deuterium + deuteriumGrowth 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 // store new amount to user db
err = p.StoreInDb() err = p.StoreInDb()
@@ -152,9 +158,9 @@ func (p *Planet) SpendResources(r Resources) error {
if p.Resources.Deuterium < r.Deuterium { if p.Resources.Deuterium < r.Deuterium {
return errors.New("not enough deuterium resources") return errors.New("not enough deuterium resources")
} }
if p.Resources.Energy < r.Energy { // if p.Resources.Energy < r.Energy {
return errors.New("not enough energy resources") // return errors.New("not enough energy resources")
} // }
p.Resources.Metal = p.Resources.Metal - r.Metal p.Resources.Metal = p.Resources.Metal - r.Metal
p.Resources.Crystal = p.Resources.Crystal - r.Crystal p.Resources.Crystal = p.Resources.Crystal - r.Crystal
@@ -271,6 +277,7 @@ func (p *Planet) UpgradeBuilding(building string) error {
if err != nil { if err != nil {
return err return err
} }
resourcesNeeded.Energy = 0
// get time cost of the build // get time cost of the build
timei64 := ConstructionTime(resourcesNeeded, p.Buildings["roboticsfactory"]) timei64 := ConstructionTime(resourcesNeeded, p.Buildings["roboticsfactory"])
endsTime := time.Now().Add(time.Second * time.Duration(timei64)) endsTime := time.Now().Add(time.Second * time.Duration(timei64))
@@ -298,6 +305,5 @@ func ResourcesToPoints(r Resources) int64 {
p = p + r.Crystal p = p + r.Crystal
p = p + r.Deuterium p = p + r.Deuterium
p = p + r.Energy p = p + r.Energy
fmt.Println("p", p)
return p return p
} }