forked from alaingilbert/ogame
/
planet.go
196 lines (159 loc) · 5.62 KB
/
planet.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
package ogame
import "math"
// Fields planet fields stats
type Fields struct {
Built int64
Total int64
}
// HasFieldAvailable returns either or not we can still build on this planet
func (f Fields) HasFieldAvailable() bool {
return f.Built < f.Total
}
// Temperature planet temperature values
type Temperature struct {
Min int64
Max int64
}
// Mean returns the planet mean temperature
func (t Temperature) Mean() int64 {
return int64(math.Round(float64(t.Min+t.Max) / 2))
}
// Planet ogame planet object
type Planet struct {
ogame *OGame
Img string
ID PlanetID
Name string
Diameter int64
Coordinate Coordinate
Fields Fields
Temperature Temperature
Moon *Moon
}
// GetName ...
func (p Planet) GetName() string {
return p.Name
}
// GetDiameter ...
func (p Planet) GetDiameter() int64 {
return p.Diameter
}
// GetID ...
func (p Planet) GetID() CelestialID {
return p.ID.Celestial()
}
// GetType ...
func (p Planet) GetType() CelestialType {
return PlanetType
}
// GetCoordinate ...
func (p Planet) GetCoordinate() Coordinate {
return p.Coordinate
}
// GetFields ...
func (p Planet) GetFields() Fields {
return p.Fields
}
// GetProduction get what is in the production queue.
// (ships & defense being built)
func (p Planet) GetProduction() ([]Quantifiable, int64, error) {
return p.ogame.GetProduction(p.ID.Celestial())
}
// GetResourceSettings gets the resources settings for specified planetID
func (p *Planet) GetResourceSettings() (ResourceSettings, error) {
return p.ogame.GetResourceSettings(p.ID)
}
// GetResourcesBuildings gets the resources buildings levels
func (p Planet) GetResourcesBuildings() (ResourcesBuildings, error) {
return p.ogame.GetResourcesBuildings(p.ID.Celestial())
}
// GetDefense gets all the defenses units information
func (p Planet) GetDefense() (DefensesInfos, error) {
return p.ogame.GetDefense(p.ID.Celestial())
}
// GetShips gets all ships units information
func (p Planet) GetShips() (ShipsInfos, error) {
return p.ogame.GetShips(p.ID.Celestial())
}
// GetFacilities gets all facilities information
func (p Planet) GetFacilities() (Facilities, error) {
return p.ogame.GetFacilities(p.ID.Celestial())
}
// Build builds any ogame objects (building, technology, ship, defence)
func (p Planet) Build(id ID, nbr int64) error {
return p.ogame.Build(CelestialID(p.ID), id, nbr)
}
// TearDown tears down any ogame building
func (p Planet) TearDown(buildingID ID) error {
return p.ogame.TearDown(CelestialID(p.ID), buildingID)
}
// BuildCancelable builds any cancelable ogame objects (building, technology)
func (p *Planet) BuildCancelable(id ID) error {
return p.ogame.BuildCancelable(CelestialID(p.ID), id)
}
// BuildBuilding ensure what is being built is a building
func (p Planet) BuildBuilding(buildingID ID) error {
return p.ogame.BuildBuilding(CelestialID(p.ID), buildingID)
}
// BuildDefense builds a defense unit
func (p Planet) BuildDefense(defenseID ID, nbr int64) error {
return p.ogame.BuildDefense(CelestialID(p.ID), defenseID, nbr)
}
// BuildShips builds a ship unit
func (p *Planet) BuildShips(shipID ID, nbr int64) error {
return p.ogame.BuildShips(CelestialID(p.ID), shipID, nbr)
}
// BuildTechnology ensure that we're trying to build a technology
func (p Planet) BuildTechnology(technologyID ID) error {
return p.ogame.BuildTechnology(p.ID.Celestial(), technologyID)
}
// GetResources gets user resources
func (p Planet) GetResources() (Resources, error) {
return p.ogame.GetResources(CelestialID(p.ID))
}
// GetResourcesDetails gets resources details
func (p Planet) GetResourcesDetails() (ResourcesDetails, error) {
return p.ogame.GetResourcesDetails(CelestialID(p.ID))
}
// SendFleet sends a fleet
func (p Planet) SendFleet(ships []Quantifiable, speed Speed, where Coordinate,
mission MissionID, resources Resources, expeditiontime, unionID int64) (Fleet, error) {
return p.ogame.SendFleet(CelestialID(p.ID), ships, speed, where, mission, resources, expeditiontime, unionID)
}
// EnsureFleet either sends all the requested ships or fail
func (p Planet) EnsureFleet(ships []Quantifiable, speed Speed, where Coordinate,
mission MissionID, resources Resources, expeditiontime, unionID int64) (Fleet, error) {
return p.ogame.EnsureFleet(CelestialID(p.ID), ships, speed, where, mission, resources, expeditiontime, unionID)
}
// ConstructionsBeingBuilt returns the building & research being built, and the time remaining (secs)
func (p Planet) ConstructionsBeingBuilt() (ID, int64, ID, int64) {
return p.ogame.ConstructionsBeingBuilt(CelestialID(p.ID))
}
// CancelBuilding cancel the construction of a building
func (p Planet) CancelBuilding() error {
return p.ogame.CancelBuilding(CelestialID(p.ID))
}
// CancelResearch cancel the research
func (p Planet) CancelResearch() error {
return p.ogame.CancelResearch(p.ID.Celestial())
}
// GetItems get all items information
func (p Planet) GetItems() ([]Item, error) {
return p.ogame.GetItems(p.ID.Celestial())
}
// ActivateItem activate an item
func (p Planet) ActivateItem(ref string) error {
return p.ogame.ActivateItem(ref, p.ID.Celestial())
}
// GetResourcesProductions gets the resources production
func (p *Planet) GetResourcesProductions() (Resources, error) {
return p.ogame.GetResourcesProductions(p.ID)
}
// FlightTime calculate flight time and fuel needed
func (p *Planet) FlightTime(destination Coordinate, speed Speed, ships ShipsInfos) (secs, fuel int64) {
return p.ogame.FlightTime(p.Coordinate, destination, speed, ships)
}
// SendIPM send interplanetary missiles
func (p *Planet) SendIPM(planetID PlanetID, coord Coordinate, nbr int64, priority ID) (int64, error) {
return p.ogame.SendIPM(planetID, coord, nbr, priority)
}