-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmineNearStore.code
132 lines (91 loc) · 2.93 KB
/
mineNearStore.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
// ask bots to mine close to the core or specified "store" the specified ressource "oreType"
import msg
import store
import idBots
import onOff
set store container1
set switch switch1
set message message1
ubind @mono
set oreType @scrap
set botNb 12
if @unit == null
msg.printAndWait("[yellow] no unit of choosen type", message)
end
storeX, storeY, store = store.getCoreOr(store)
msg.printAndWait("go to store", message)
#ref loopGoStore
ucontrol move storeX storeY 0 0 0
ucontrol within storeX storeY 5 isWithin null
if isWithin != true
jump loopGoStore
msg.printAndWait("we are to store, locate ore", message)
ulocate ore core true oreType oreX oreY found building
if found == false
msg.printAndWait("ore not found", message)
end
print "or found at: "
print oreX
print " "
print oreY
msg.printAndWait("", message)
// to flag bots with, done only once
if procId == null
procId = idBots.genProcId()
sensor botType @unit @type // get botType
if botNb > 12
msg.printAndWait("[red] can't take more than 12 bots\n change parameter 'botNb' to fix it", message)
end
botList = [bot1, bot2, bot3, bot4, bot5, bot6, bot7, bot8, bot9, bot10, bot11, bot12]
#ref freeBots
set botOwnedNb 0
// variable content is keep after end instruction, memory not free
for ownedBot in botList
if ownedBot != null
ubind ownedBot
ucontrol flag 0 null null null null // tag it
set ownedBot null
set reset 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
jump freeBots
if reset == true
msg.printAndWait("reset prog", message)
end // to reset procId and botOwnedNb
if botOwnedNb < botNb // need one ?
haveNewBot = idBots.tryTakeOneMoreBot(procId, botType, message)
if haveNewBot == true
op add botOwnedNb botOwnedNb 1
for ownedBot in botList
if ownedBot == null
set ownedBot @unit
jump endBotSave
#ref endBotSave
for ownedBot in botList
if ownedBot == null
jump loop
ubind ownedBot
mineWith(oreType, oreX, oreY, storeX, storeY, store)
jump loop
mineWith(oreType, oreX, oreY, storeX, storeY, store)
sensor payload @unit @totalItems
sensor maxCapacity @unit @itemCapacity
if payload == 0
ucontrol approach oreX oreY 6 null null
ucontrol mine oreX oreY 0 0 0
else
sensor transportedRessource @unit @firstItem
if transportedRessource != oreType
ucontrol approach storeX storeY 6 null null
ucontrol itemDrop store 800 null null null
elif payload < maxCapacity
ucontrol approach oreX oreY 6 null null
ucontrol mine oreX oreY 0 0 0
else
ucontrol approach storeX storeY 6 null null
ucontrol itemDrop store 800 null null null