-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathauto_colony_builder.go
158 lines (145 loc) · 4.19 KB
/
auto_colony_builder.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
// Largely inspired by https://github.com/ogame-ninja/scripts/blob/master/community/cremefresh55/AutoColonyBuilder.go
coord = "P:1:2:3"
a = [
SOLARPLANT, // lvl 1
METALMINE, // lvl 1
METALMINE, // lvl 2
SOLARPLANT, // lvl 2
METALMINE, // lvl 3
METALMINE, // lvl 4
SOLARPLANT, // lvl 3
CRYSTALMINE, // lvl 1
SOLARPLANT, // ...
METALMINE,
CRYSTALMINE,
CRYSTALMINE,
SOLARPLANT,
DEUTERIUMSYNTHESIZER,
CRYSTALMINE,
SOLARPLANT,
METALMINE,
METALMINE,
SOLARPLANT,
CRYSTALMINE,
DEUTERIUMSYNTHESIZER,
SOLARPLANT,
DEUTERIUMSYNTHESIZER,
DEUTERIUMSYNTHESIZER,
SOLARPLANT,
DEUTERIUMSYNTHESIZER,
ROBOTICSFACTORY,
ROBOTICSFACTORY,
RESEARCHLAB,
SHIPYARD,
CRYSTALMINE,
SHIPYARD,
SOLARPLANT,
DEUTERIUMSYNTHESIZER,
METALMINE,
ENERGYTECHNOLOGY,
COMBUSTIONDRIVE,
SOLARPLANT,
CRYSTALMINE,
METALMINE,
COMBUSTIONDRIVE,
SMALLCARGO,
]
//-----------------------------------------------------------------------
// Return either or not a ogameID is in the current production line
func itemInProductionLine(oid) {
productionLine, _, _ = celestial.GetProduction()
for item in productionLine {
prodID = item.ID
if prodID == oid {
return true
}
}
return false
}
// If we build a colony, skip researches and lab
planets = GetCachedPlanets()
skipResearches = len(planets) > 1
// Get celestial object and buildings/researches information
celestial, _ = GetCelestial(coord)
supplies, facilities, _, _, researches, err = GetTechs(celestial)
// Map that keep track of what level to build
m = {}
for i = 0; i < len(a); i++ {
for { // Loop to retry the same step in the list if something went wrong
oid = a[i]
m[oid]++
if oid == RESEARCHLAB && skipResearches {
break
}
wantedLvl = m[oid]
lvl = 0
nbr = 0
if oid.IsResourceBuilding() {
lvl = supplies.ByID(oid)
} else if oid.IsFacility() {
lvl = facilities.ByID(oid)
} else if oid.IsTech() {
if skipResearches {
break
}
lvl = researches.ByID(oid)
} else if oid.IsShip() || oid.IsDefense() {
nbr = 1
// Check the existing ships in shipyard, if we already have it, skip
ships, err = celestial.GetShips()
if err != nil {
LogError(err)
SleepMin(1)
continue
}
nbrOnCelestial = ships.ByID(oid)
if nbrOnCelestial >= wantedLvl {
break
}
SleepMs(1000)
if itemInProductionLine(oid) {
SleepMs(1000)
break
}
}
if lvl >= wantedLvl {
break
}
// Actually build the OGameID
Print("Wants to build " + oid + " lvl " + wantedLvl)
err = celestial.Build(oid, nbr)
if err != nil {
LogError(err)
SleepMs(1000)
continue
}
SleepMs(100)
// Then verify that the item is actually being built
wait = 1
found = true
if oid.IsShip() || oid.IsDefense() {
if !itemInProductionLine(oid) {
found = false
}
} else {
buildingID, buildingCountdown, researchID, researchCountdown = celestial.ConstructionsBeingBuilt()
if (oid.IsResourceBuilding() || oid.IsFacility()) && buildingID == oid {
wait = buildingCountdown + 10
} else if oid.IsTech() && researchID == oid {
wait = researchCountdown + 10
} else {
found = false
}
}
if !found {
LogError(oid + " is not being built, wait 1min")
SleepMin(1)
continue
}
print(oid + " was built at step: " + i + ", wait " + wait)
SleepSec(wait)
supplies, facilities, _, _, researches, err = GetTechs(celestial) // Update values
break
}
}
Print("Done building list")