-
Notifications
You must be signed in to change notification settings - Fork 1
/
map.go
86 lines (74 loc) · 1.46 KB
/
map.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
package main
type City struct {
Major bool `json:"major"`
X uint `json:"x"`
Y uint `json:"y"`
}
type Tile struct {
Index uint16 `json:"index"`
Owner uint8 `json:"owner"`
Troops uint32 `json:"troops"`
X uint `json:"x"`
Y uint `json:"y"`
Width uint `json:"w"`
Height uint `json:"h"`
City *City `json:"city,omitempty"`
Region string `json:"region,omitempty"`
}
type Region struct {
Color string `json:"color"`
Tiles []Tile `json:"tiles"`
}
type Map struct {
Regions map[string]Region `json:"regions"`
Scale float32 `json:"scale"`
}
func (m *Map) Initialize() {
id := uint16(0)
for key := range m.Regions {
for i := range m.Regions[key].Tiles {
t := &m.Regions[key].Tiles[i]
t.Index = id
id++
t.Troops = 1
}
}
}
func (m *Map) Update() {
for key := range m.Regions {
for i := range m.Regions[key].Tiles {
t := &m.Regions[key].Tiles[i]
if t.City != nil {
if t.City.Major {
t.Troops += 5
} else {
t.Troops += 2
}
}
if t.Owner == 0 {
t.Troops += 2
} else {
t.Troops += 3
}
}
}
}
func (m *Map) Reset() {
for key := range m.Regions {
for i := range m.Regions[key].Tiles {
t := &m.Regions[key].Tiles[i]
t.Owner = 0
t.Troops = 1
}
}
}
func (m *Map) Read(tile Tile) {
reg := m.Regions[tile.Region]
for i := range reg.Tiles {
if tile.Index == reg.Tiles[i].Index {
reg.Tiles[i].Owner = tile.Owner
reg.Tiles[i].Troops = tile.Troops
return
}
}
}