forked from alaingilbert/ogame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
baseTechnology.go
33 lines (29 loc) · 1002 Bytes
/
baseTechnology.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package ogame
import (
"math"
"time"
)
// BaseTechnology base struct for technologies
type BaseTechnology struct {
BaseLevelable
}
// ConstructionTime returns the duration it takes to build given technology
func (b BaseTechnology) ConstructionTime(level, universeSpeed int64, facilities Facilities, hasTechnocrat, isDiscoverer bool) time.Duration {
price := b.GetPrice(int64(level))
metalCost := float64(price.Metal)
crystalCost := float64(price.Crystal)
researchLabLvl := float64(facilities.ResearchLab)
hours := (metalCost + crystalCost) / (1000 * (1 + researchLabLvl) * float64(universeSpeed))
if hasTechnocrat {
hours -= 0.25 * hours
}
if isDiscoverer {
hours -= 0.25 * hours
}
secs := math.Max(1, hours*3600)
return time.Duration(int64(math.Floor(secs))) * time.Second
}
// GetLevel returns current level of a technology
func (b BaseTechnology) GetLevel(_ LazyResourcesBuildings, _ LazyFacilities, lazyResearches LazyResearches) int64 {
return lazyResearches().ByID(b.ID)
}