forked from alaingilbert/ogame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
baseDefender.go
56 lines (47 loc) · 1.95 KB
/
baseDefender.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package ogame
import (
"math"
"time"
)
// BaseDefender base for defender units (ships, defenses)
type BaseDefender struct {
Base
StructuralIntegrity int64
ShieldPower int64
WeaponPower int64
RapidfireFrom map[ID]int64
RapidfireAgainst map[ID]int64
Price Resources
}
// GetStructuralIntegrity returns structural integrity of a defender unit
func (b BaseDefender) GetStructuralIntegrity(researches Researches) int64 {
return int64(float64(b.StructuralIntegrity) * (1 + float64(researches.ArmourTechnology)*0.1))
}
// GetShieldPower returns shield power of a defender unit
func (b BaseDefender) GetShieldPower(researches Researches) int64 {
return int64(float64(b.ShieldPower) * (1 + float64(researches.ShieldingTechnology)*0.1))
}
// GetWeaponPower returns weapon power of a defender unit
func (b BaseDefender) GetWeaponPower(researches Researches) int64 {
return int64(float64(b.WeaponPower) * (1 + float64(researches.WeaponsTechnology)*0.1))
}
// GetRapidfireFrom returns which ships have rapid fire against the defender unit
func (b BaseDefender) GetRapidfireFrom() map[ID]int64 {
return b.RapidfireFrom
}
// GetRapidfireAgainst returns which ships/defenses we have rapid fire against
func (b BaseDefender) GetRapidfireAgainst() map[ID]int64 {
return b.RapidfireAgainst
}
// ConstructionTime returns the duration it takes to build nbr defender units
func (b BaseDefender) ConstructionTime(nbr, universeSpeed int64, facilities Facilities, hasTechnocrat, isDiscoverer bool) time.Duration {
shipyardLvl := float64(facilities.Shipyard)
naniteLvl := float64(facilities.NaniteFactory)
hours := float64(b.StructuralIntegrity) / (2500 * (1 + shipyardLvl) * float64(universeSpeed) * math.Pow(2, naniteLvl))
secs := math.Max(1, hours*3600)
return time.Duration(int64(math.Floor(secs))*nbr) * time.Second
}
// GetPrice returns the price of nbr defender units
func (b BaseDefender) GetPrice(nbr int64) Resources {
return b.Price.Mul(nbr)
}