-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfillBotFactory.code
425 lines (344 loc) · 14 KB
/
fillBotFactory.code
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
// this code fill all linked bot factory (and overdrive-projector/dome), with bots
// medium processor required (480 instr/s)
// ressource will be picked from core of "appro" if specified, default to container1
// can change who take it (here @flare)
// the bot will take ressource to it's max transport capacity
// max bot controled: botNb
import onOff
import idBots
import msg
set appro container1
set switch switch1
set message message1
// which bot to use
ubind @flare // let player choose with bot image the bind
set botNb 8
set radiusApproche 6 // max working radius: 8
if @unit == null // no bot of that type
print "[yellow] no bots of the choosen type, \n"
print "you can pick another kind of bot in the instruction 'ubind' at the begining of the programme"
msg.printAndWait("", message)
end
set baseX null
set baseY null
// where to take ressource from, appro or base
if appro != null
print "[green] appro not null, will replace base to take ressource from"
msg.printAndWait(appro, message)
// appro position, default to base if null
sensor baseX appro @x
sensor baseY appro @y
set base appro
// get base position
#ref getCorePos
// require to have a @unite
if baseX == null
msg.printAndWait("looking for core, this is done once", message)
ulocate building core false @copper baseX baseY baseFound base
if baseFound == false
msg.printAndWait("[red] core not found, searching again", message)
msg.printAndWait(base, message)
msg.printAndWait(baseFound, message)
jump getCorePos
print "[green] core found at "
print baseX
print " "
print baseY
msg.printAndWait("", message)
// to flag bots with, done only once
if procId == null
procId = idBots.genProcId()
set botOwnedNb 0
set loopSearchingBots 0
sensor botType @unit @type // get botType
// bot to take, in order of priority to transport ressource
botTypeList = [@zenith, @horizon, @flare]
if botNb > 8
msg.printAndWait("[red] can't take more than 8 bots\n change parameter 'botNb' to fix it", message)
end
listBotRessourceLink = [
(bot1, link1), (bot2, link2),
(bot3, link3), (bot4, link4),
(bot5, link5), (bot6, link6),
(bot7, link7), (bot8, link8),
]
reverseBotList = [bot8, bot7, bot6, bot5, bot4, bot3, bot2, bot1]
// free bot memory
#ref freeBots
set botOwnedNb 0
// variable content is keep after end instruction, memory not free
for ownedBot, botFactoLink in listBotRessourceLink
if ownedBot != null
ubind ownedBot
ucontrol flag 0 null null null null // free it
set ownedBot null
set botFactoLink 0
set needToFreeBot false
set reset false
// --- Prog Loop ---
#ref loop
// switch to turn off
sensor isOn switch @enabled
op add count count 1
print "switch is "
print isOn
print " c: "
print count
printflush message
if isOn != true
msg.printAndWait("[yellow] process is turn off", message)
set reset true // will reset after switch On
jump freeBots
if reset == true
msg.printAndWait("reset prog", message)
end // to reset procId and botOwnedNb
// check facto need ressource
if haveFreeBots == true
set haveFreeBots false
set factoIndex 0
#ref loopFacto
getlink facto factoIndex
if facto == null // end link list, no facto need ressources
jump freeSomeBots
ressourceNeeded = getNeededRessource(facto, message)
if ressourceNeeded != false
jump continueProg
op add factoIndex factoIndex 1
jump loopFacto
#ref continueProg
if botOwnedNb < botNb // need one ?
if botType == @flare // is the default bot, will try to take better
for listedBotType in botTypeList
haveNewBot = idBots.getFreeBotAndFlagIt(listedBotType, procId, message)
if haveNewBot == true
jump saveNewBot
haveNewBot = idBots.tryTakeOneMoreBot(procId, botType, message)
if haveNewBot == true
jump saveNewBot
jump passSave
#ref saveNewBot
op add botOwnedNb botOwnedNb 1
for ownedBot, linkId in listBotRessourceLink
if ownedBot == null
set ownedBot @unit
jump endBotSave
#ref endBotSave
#ref passSave
for ownedBot, botFactoLink in listBotRessourceLink
ubind ownedBot
if @unit == null // no more owned bots
jump loop
botFactoLink, needToFreeBot = moveBotToFillFactoInNeed(botFactoLink, baseX, baseY, base, radiusApproche, message)
if needToFreeBot == true
set botFactoLink 0
jump freeSomeBots
// end here
jump loop
#ref freeSomeBots
// free some bots
for ownedBot in reverseBotList
if ownedBot != null // free it
ubind ownedBot
ucontrol flag 0 null null null null
set ownedBot null
op sub botOwnedNb botOwnedNb 1
jump haveFreeOneBot
#ref haveFreeOneBot
set haveFreeBots true
jump loop
moveBotToFillFactoInNeed(botFactoLink, baseX, baseY, base, radiusApproche, message)
getlink facto botFactoLink
sensor payload @unit @totalItems
if payload > 0
sensor transportedRessource @unit @firstItem
if facto == null // end link list
ucontrol approach baseX baseY radiusApproche null null
ucontrol itemDrop base 800 null null null
set botFactoLink 0
else
sensor factoType facto @type
isGoodR = isGoodRessource(transportedRessource, facto)
if isGoodR == true // dropRessourceToFacto
sensor factoX facto @x
sensor factoY facto @y
ucontrol approach factoX factoY radiusApproche null null
ucontrol itemDrop facto 800 null null null
else
// go see next facto
op add botFactoLink botFactoLink 1
else // empty
set nothingToDo 0
#ref searchingRessource
getlink facto botFactoLink
if facto == null // end link list, search again
set botFactoLink 0
op add nothingToDo nothingToDo 1
jump searchingRessource
ressourceNeeded = getNeededRessource(facto, message)
if ressourceNeeded != false
ucontrol approach baseX baseY radiusApproche null null
sensor coreStored base ressourceNeeded
if coreStored > 40 // take it
ucontrol itemTake base ressourceNeeded 800 null null
else
print "[yellow] not enouth of "
print ressourceNeeded
print " in base, will fill another factory"
printflush message
jump toSearchingR
else
jump toSearchingR
return botFactoLink, false
#ref toSearchingR
op add botFactoLink botFactoLink 1
if nothingToDo > 3
return botFactoLink, true
jump searchingRessource
// will return ressourceType needed by factory or false if facto does not need any
getNeededRessource(facto, message)
sensor factoType facto @type
sensor selectedBotToBuild facto @config
if factoType == @ground-factory
if selectedBotToBuild == @dagger
for ressource in [@silicon, @lead]
// sensor maxCapacity facto @itemCapacity
sensor currentCapacity facto ressource
if currentCapacity < 30 // we could say < 30 for every ressources for ground
return ressource
elif selectedBotToBuild == @crawler
for ressource in [@silicon, @coal]
sensor currentCapacity facto ressource
if currentCapacity < 30 // we could say < 30 for every ressources for ground
return ressource
elif selectedBotToBuild == @nova
for ressource in [@silicon, @lead, @titanium]
sensor currentCapacity facto ressource
if currentCapacity < 30 // we could say < 30 for every ressources for ground
return ressource
elif factoType == @air-factory
if selectedBotToBuild == @flare
for ressource in [@silicon]
sensor currentCapacity facto ressource
if currentCapacity < 30 // we could say < 30 for every ressources for ground
return ressource
elif selectedBotToBuild == @mono
for ressource in [@silicon, @lead]
sensor currentCapacity facto ressource
if currentCapacity < 30 // we could say < 30 for every ressources for ground
return ressource
elif factoType == @naval-factory
if selectedBotToBuild == @risso
for ressource in [@silicon, @metaglass]
sensor currentCapacity facto ressource
if currentCapacity < 40 // need 35 metaglass
return ressource
elif factoType == @additive-reconstructor
for ressource in [@graphite, @silicon]
sensor currentCapacity facto ressource
if currentCapacity < 80
return ressource
elif factoType == @multiplicative-reconstructor
for ressource, quatity in [(@silicon, 260), (@titanium, 160), (@metaglass, 80)]
sensor currentCapacity facto ressource
if currentCapacity < quatity
return ressource
elif factoType == @exponential-reconstructor
for ressource, quatity in [(@silicon, 1700), (@titanium, 1500), (@plastanium, 1300)]
sensor currentCapacity facto ressource
if currentCapacity < quatity
return ressource
elif factoType == @tetrative-reconstructor
for ressource, quatity in [(@silicon, 2000), (@plastanium, 1200), (@surge-alloy, 1000), (@phase-fabric, 700)]
sensor currentCapacity facto ressource
if currentCapacity < quatity
return ressource
elif factoType == @overdrive-projector
for ressource in [@phase-fabric]
sensor currentCapacity facto ressource
if currentCapacity < 3
return ressource
elif factoType == @overdrive-dome
for ressource in [@phase-fabric, @silicon]
sensor currentCapacity facto ressource
if currentCapacity < 3
return ressource
return false
isGoodRessource(transportedRessource, facto)
sensor factoType facto @type
sensor selectedBotToBuild facto @config
if factoType == @ground-factory
if selectedBotToBuild == @dagger
for ressource in [@silicon, @lead]
if transportedRessource == ressource
sensor currentCapacity facto ressource
if currentCapacity < 30 // we could say < 30 for every ressources for ground
return true
elif selectedBotToBuild == @crawler
for ressource in [@silicon, @coal]
if transportedRessource == ressource
sensor currentCapacity facto ressource
if currentCapacity < 30 // we could say < 30 for every ressources for ground
return true
elif selectedBotToBuild == @nova
for ressource in [@silicon, @lead, @titanium]
if transportedRessource == ressource
sensor currentCapacity facto ressource
if currentCapacity < 30 // we could say < 30 for every ressources for ground
return true
elif factoType == @air-factory
if selectedBotToBuild == @flare
for ressource in [@silicon]
if transportedRessource == ressource
sensor currentCapacity facto ressource
if currentCapacity < 30 // we could say < 30 for every ressources for ground
return true
elif selectedBotToBuild == @mono
for ressource in [@silicon, @lead]
if transportedRessource == ressource
sensor currentCapacity facto ressource
if currentCapacity < 30 // we could say < 30 for every ressources for ground
return true
elif factoType == @naval-factory
if selectedBotToBuild == @risso
for ressource in [@silicon, @metaglass]
if transportedRessource == ressource
sensor currentCapacity facto ressource
if currentCapacity < 40 // need 35 metaglass
return true
elif factoType == @additive-reconstructor
for ressource in [@graphite, @silicon]
if transportedRessource == ressource
sensor currentCapacity facto ressource
if currentCapacity < 80
return true
elif factoType == @multiplicative-reconstructor
for ressource, quatity in [(@silicon, 260), (@titanium, 160), (@metaglass, 80)]
if transportedRessource == ressource
sensor currentCapacity facto ressource
if currentCapacity < quatity
return true
elif factoType == @exponential-reconstructor
for ressource, quatity in [(@silicon, 1700), (@titanium, 1500), (@plastanium, 1300)]
if transportedRessource == ressource
sensor currentCapacity facto ressource
if currentCapacity < quatity
return true
elif factoType == @tetrative-reconstructor
for ressource, quatity in [(@silicon, 2000), (@plastanium, 1200), (@surge-alloy, 1000), (@phase-fabric, 700)]
if transportedRessource == ressource
sensor currentCapacity facto ressource
if currentCapacity < quatity
return true
elif factoType == @overdrive-projector
for ressource in [@phase-fabric]
if transportedRessource == ressource
sensor currentCapacity facto ressource
if currentCapacity < 3
return true
elif factoType == @overdrive-dome
for ressource in [@phase-fabric, @silicon]
if transportedRessource == ressource
sensor currentCapacity facto ressource
if currentCapacity < 3
return true
return false