-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunloader.code
164 lines (124 loc) · 3.83 KB
/
unloader.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
// put all ressource in store to core or "loader" if specified
import onOff
import idBots
import msg
import store
set unloader container1
set loader container2
set switch switch1
set message message1
// which bot to use
ubind @flare // let player choose with bot image the bind
set botNb 12 // run on 8 bots fluid with a small processor
if @unit == null
msg.printAndWait("[yellow] no unit of choosen type", message)
end
if unloader == null
msg.printAndWait("[yellow] unloader store not selected", message)
end
sensor unloaderX unloader @x
sensor unloaderY unloader @y
coreX, coreY, core = store.getCoreOr(loader)
// to flag bots with, done only once
if procId == null
procId = idBots.genProcId()
set botOwnedNb 0
set loopSearchingBots 0
botList = [
bot1, bot2, bot3, bot4,
bot5, bot6, bot7, bot8,
bot9, bot10, bot11, bot12,
]
reverseBotList = [
bot12, bot11, bot10, bot9,
bot8, bot7, bot6, bot5,
bot4, bot3, bot2, bot1,
]
#ref freeBots
set botOwnedNb 0
// free bot list memory
// 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 // free it
set ownedBot null
sensor botType @unit @type // get botType
// set a default ressource
set toUnload @copper
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
// sensor ressource unloader @firstItem
// it prevent others to unload if low but continuously comming
// will do a random on ressource list
ressourceList = [
@copper, @lead, @silicon,
@graphite, @coal, @metaglass,
@titanium, @thorium, @surge-alloy,
@blast-compound, @pyratite,
@phase-fabric, @plastanium,
@spore-pod, @sand, @scrap,
]
sensor content unloader toUnload
if content > 40
jump noRessourceChange
// will set the best ressource
set bestContent 0
for ressource in ressourceList
sensor contentChallenger unloader ressource
if contentChallenger > bestContent
set bestContent contentChallenger
set toUnload ressource
#ref noRessourceChange
sensor content unloader toUnload
if content < 40
// need to free some bots
print "store practicaly empty, will free some bots"
printflush message
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
if content > 200
// try take another bot
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
print "ressource: "
print toUnload
printflush message
for ownedBot in botList
if ownedBot == null
jump loop
ubind ownedBot
unloadRessource(toUnload, unloader, unloaderX, unloaderY, core, coreX, coreY, message)
jump loop
unloadRessource(toUnload, unloader, unloaderX, unloaderY, core, coreX, coreY, message)
// sensor ressourceToUnload unloader @firstItem
sensor payload @unit @totalItems
if payload > 0
ucontrol approach coreX coreY 5 null null
ucontrol itemDrop core 800 null null null
else
ucontrol approach unloaderX unloaderY 5 null null
ucontrol itemTake unloader toUnload 800 null null