forked from alaingilbert/ogame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
coordinate.go
56 lines (46 loc) · 1.44 KB
/
coordinate.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 (
"fmt"
"strings"
)
// Coordinate represent an ogame coordinate
type Coordinate struct {
Galaxy int64
System int64
Position int64
Type CelestialType
}
func (c Coordinate) String() string {
return fmt.Sprintf("[%c:%d:%d:%d]", strings.ToUpper(c.Type.String())[0], c.Galaxy, c.System, c.Position)
}
// Equal returns either two coordinates are equal or not
func (c Coordinate) Equal(v Coordinate) bool {
return c.Galaxy == v.Galaxy &&
c.System == v.System &&
c.Position == v.Position &&
c.Type == v.Type
}
// IsPlanet return true if coordinate is a planet
func (c Coordinate) IsPlanet() bool {
return c.Type == PlanetType
}
// IsMoon return true if coordinate is a moon
func (c Coordinate) IsMoon() bool {
return c.Type == MoonType
}
// IsDebris return true if coordinate is a debris field
func (c Coordinate) IsDebris() bool {
return c.Type == DebrisType
}
// Planet return a new coordinate with planet type
func (c Coordinate) Planet() Coordinate {
return Coordinate{Galaxy: c.Galaxy, System: c.System, Position: c.Position, Type: PlanetType}
}
// Moon return a new coordinate with moon type
func (c Coordinate) Moon() Coordinate {
return Coordinate{Galaxy: c.Galaxy, System: c.System, Position: c.Position, Type: MoonType}
}
// Debris return a new coordinate with debris type
func (c Coordinate) Debris() Coordinate {
return Coordinate{Galaxy: c.Galaxy, System: c.System, Position: c.Position, Type: DebrisType}
}