-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfillSpeedShield.code
393 lines (322 loc) · 11.1 KB
/
fillSpeedShield.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
// will fill with one bot all linked overdrive and shield
// if turret given, will desactivate shield when no ennemies around
import msg
import store
import idBots
import onOff
set store container1
set message message1
set switch switch1
set turret hail1
coreX, coreY, core = store.getCoreOr(store, message)
// to flag bots with, done only once
if procId == null
procId = idBots.genProcId()
set reset false
set haveTryGetBetterBot false
// --- Prog Loop ---
#ref loop
// switch to turn off
isOn = onOff.isOn(switch)
if isOn != true
msg.printAndWait("[yellow] process is turn off", message)
set reset true // will reset after switch On
if @unit != null
ucontrol flag 0 null null null null
ubind null
jump loop
if reset == true
msg.printAndWait("reset prog", message)
end // to reset procId and botOwnedNb
// check turret to turn shield on if no radars
sensor isDead turret @dead
if isDead == true
set turret null
if turret == null
if hail1 != null
set turret hail1
// if turret, list all force-projector to turn it on/off if needed
if turret != null
set aTurretWasHere true
radar enemy any any distance turret 1 spotted
set linkId 0
#ref loopProjector
getlink projector linkId
if projector == null
jump endLoopProjector
sensor projectorType projector @type
if projectorType == @force-projector
control enabled projector spotted null null null
elif projectorType == @overdrive-dome
control enabled projector spotted null null null
elif projectorType == @overdrive-projector
control enabled projector spotted null null null
elif projectorType == @mend-projector
control enabled projector spotted null null null
elif projectorType == @mender
control enabled projector spotted null null null
op add linkId linkId 1
jump loopProjector
#ref endLoopProjector
// if the radar turret is disconnected, enable all shield
if turret == null
if aTurretWasHere == true
set aTurretWasHere false
set linkId 0
#ref loopProjectorActivate
getlink projector linkId
if projector == null
jump endLoopProjectorActivate
sensor projectorType projector @type
if projectorType == @force-projector
control enabled projector true null null null
elif projectorType == @overdrive-dome
control enabled projector true null null null
elif projectorType == @overdrive-projector
control enabled projector true null null null
elif projectorType == @mend-projector
control enabled projector true null null null
elif projectorType == @mender
control enabled projector true null null null
op add linkId linkId 1
jump loopProjectorActivate
#ref endLoopProjectorActivate
// if we have a unit
if @unit != null // @unit is myBot
sensor payload @unit @totalItems
if payload > 0 // with ressource, check first if we could need the ressource
sensor transportedRessource @unit @firstItem
facto = getFactoThatNeedThisRessource(transportedRessource)
if facto != null // a facto need this ressource
fillFacto(facto, transportedRessource, core, procId, message)
we have the best bot here
set haveTryGetBetterBot false
jump loop
if haveTryGetBetterBot == false
set haveTryGetBetterBot true
jump freebotAndLoop
// check facto that need another ressource:
facto, ressource = getFactoNeededRessource()
if facto != null
fillFacto(facto, ressource, core, procId, message)
jump loop
else
jump freebotAndLoop
// we don't have a bot, do we need one ?
facto, ressource = getFactoNeededRessource()
print "no bots, need something ? "
print facto
print " need: "
print ressource
printflush message
if facto != null
fillFacto(facto, ressource, core, procId, message)
jump loop
#ref freebotAndLoop
// free bot
// ask him to go to the base
ucontrol approach coreX coreY 5 null null
ucontrol flag 0 null null null null
ubind null
jump loop
// given a facto and the needed ressource, will use a bot to fill it
fillFacto(facto, ressource, core, procId, message)
print "facto: "
print facto
print " need to be filled with ressource: "
print ressource
printflush message
sensor coreStored core ressource
if coreStored < 10
print "[yellow] not enougth of "
print ressource
msg.printAndWait(" in core/store", message)
return false
if @unit == null // will need a unit
succeed = bindBotWithPreferenceRessource(ressource, procId)
if succeed == true
print "we have a good bot"
printflush message
else
return false
sensor payload @unit @totalItems
if payload > 0
sensor transportedRessource @unit @firstItem
if transportedRessource == ressource
giveRessourceToFacto(facto)
else
throwRessource(core)
else
getRessourceInCore(ressource, core)
// will ubind a bot that have the needed ressource or is empty or at last have an incorrect ressource
bindBotWithPreferenceRessource(ressource, procId)
if @unit != null
sensor payload @unit @totalItems
if payload > 0
sensor transportedRessource @unit @firstItem
if transportedRessource == ressource
return true // we already have the bot
ucontrol flag 0 null null null null // free it
// here, we don't have a good bot, will search for one
found = searchBotTransportingRessource(ressource)
if found == true
ucontrol flag procId null null null null // tag it
return true
found = searchEmptyBot()
if found == true
ucontrol flag procId null null null null // tag it
return true
found = getFreeBot()
if found == true
return true
ubind null // clear unsucess last bind
return false
searchBotTransportingRessource(ressource)
ubind @flare
set firstBot @unit
#ref loopSearchingBetterBot
ubind @flare
if @unit == null // no bot of that botType
return false
sensor flag @unit @flag
if flag == 0 // bot is free
sensor payload @unit @totalItems
if payload > 0
sensor transportedRessource @unit @firstItem
if transportedRessource == ressource
return true // best bot found, he already have the ressource
if @unit == firstBot
return false
jump loopSearchingBetterBot
searchEmptyBot()
ubind @flare
set firstBot @unit
#ref loopSearchingBetterBot
ubind @flare
if @unit == null // no bot of that botType
return false
sensor flag @unit @flag
if flag == 0 // bot is free
sensor payload @unit @totalItems
if payload == 0
return true // best bot found, he already have the ressource
if @unit == firstBot
return false
jump loopSearchingBetterBot
getFreeBot()
ubind @flare
set firstBot @unit
#ref loopSearchingBetterBot
ubind @flare
if @unit == null // no bot of that botType
return false
sensor flag @unit @flag
if flag == 0 // bot is free
return true
if @unit == firstBot
return false
jump loopSearchingBetterBot
giveRessourceToFacto(facto)
sensor factoX facto @x
sensor factoY facto @y
ucontrol approach factoX factoY 5 null null
ucontrol itemDrop facto 800 null null null
getRessourceInCore(ressource, core)
sensor coreX core @x
sensor coreY core @y
ucontrol approach coreX coreY 5 null null
ucontrol itemTake core ressource 800 null null
throwRessource(core)
sensor coreX core @x
sensor coreY core @y
ucontrol approach coreX coreY 5 null null
ucontrol itemDrop core 800 null null null
// return facto and the ressource needed if need it, else null/false
getFactoNeededRessource()
set factoId -1
#ref searching
op add factoId factoId 1
getlink facto factoId
if facto == null
return null, false
needed = getNeededRessource(facto)
if needed != false
return facto, needed
jump searching
// return facto if exist that need the ressource, else false
getFactoThatNeedThisRessource(transportedRessource)
set factoId -1
#ref searching
op add factoId factoId 1
getlink facto factoId
if facto == null
return false
isGood = isGoodRessource(transportedRessource, facto)
if isGood == true
return facto
else
jump searching
// will return ressourceType needed by factory or false if facto does not need any
getNeededRessource(facto)
sensor factoType facto @type
sensor selectedBotToBuild facto @config
if factoType == @overdrive-projector
for ressource in [@phase-fabric]
sensor currentCapacity facto ressource
if currentCapacity < 4
return ressource
elif factoType == @overdrive-dome
for ressource in [@phase-fabric, @silicon]
sensor currentCapacity facto ressource
if currentCapacity < 4
return ressource
elif factoType == @force-projector
for ressource in [@phase-fabric]
sensor currentCapacity facto ressource
if currentCapacity < 4
return ressource
elif factoType == @mend-projector
for ressource in [@phase-fabric]
sensor currentCapacity facto ressource
if currentCapacity < 4
return ressource
elif factoType == @mender
for ressource in [@silicon]
sensor currentCapacity facto ressource
if currentCapacity < 4
return ressource
return false
isGoodRessource(transportedRessource, facto)
sensor factoType facto @type
sensor selectedBotToBuild facto @config
if factoType == @overdrive-projector
for ressource in [@phase-fabric]
if transportedRessource == ressource
sensor currentCapacity facto ressource
if currentCapacity < 4
return true
elif factoType == @overdrive-dome
for ressource in [@phase-fabric, @silicon]
if transportedRessource == ressource
sensor currentCapacity facto ressource
if currentCapacity < 4
return true
elif factoType == @force-projector
for ressource in [@phase-fabric]
if transportedRessource == ressource
sensor currentCapacity facto ressource
if currentCapacity < 4
return true
elif factoType == @mend-projector
for ressource in [@phase-fabric]
if transportedRessource == ressource
sensor currentCapacity facto ressource
if currentCapacity < 4
return true
elif factoType == @mender
for ressource in [@silicon]
if transportedRessource == ressource
sensor currentCapacity facto ressource
if currentCapacity < 4
return true
return false