-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNChargeBot.txt
More file actions
243 lines (217 loc) · 5.51 KB
/
NChargeBot.txt
File metadata and controls
243 lines (217 loc) · 5.51 KB
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
extern void object::NkchargeBots()
{
object item;
int List[], i;
point startpoint;
int retval;
int Angle;
i=0;
Angle=0;
List[i++]=WingedShooter;
List[i++]=PracticeBot;
List[i++]=TargetBot;
List[i++]=WheeledGrabber;
List[i++]=TrackedGrabber;
List[i++]=WingedGrabber;
List[i++]=LeggedGrabber;
List[i++]=WheeledShooter;
List[i++]=TrackedShooter;
List[i++]=WingedShooter;
List[i++]=LeggedShooter;
List[i++]=WheeledSniffer;
List[i++]=TrackedSniffer;
List[i++]=WingedSniffer;
List[i++]=LeggedSniffer;
List[i++]=WheeledOrgaShooter;
List[i++]=TrackedOrgaShooter;
List[i++]=WingedOrgaShooter;
i=0;
item = radar(List[i]);
while (true)
{
if (load!=null && load.category != NuclearCell)
{
message("Brazo de carga ocupado. Soltando objeto.",DisplayInfo);
drop(InFront); // No es una bateria, lo suelto
}
else
{
if (item!=null)
{
for (Angle=0;Angle<360;Angle++)
{
if (item!=null && item.energyCell!=null)
{
//message("Localizado un " + item.category + ". Investigando estado de baterias...",DisplayInfo);
if (item.energyCell.energyLevel <= 0.2)
{
message("El " + item.category + " tiene bateria agotada. Acudiendo en su auxilio.",DisplayInfo);
retval=0;
retval=goto(item.position);
if (retval==0)
{
message("Procediendo a recuperacion de bateria agotada...",DisplayInfo);
retval=grab(InFront); // Coge la bateria del otro robot
if (retval==0)
{
startpoint=item.position; // Memoriza la posicion actual
message("Regresando a base para recarga de bateria...",DisplayInfo);
RechargeBattery(); // A cargar las baterias
goto(startpoint); // Vuelvo donde estaba el robot
retval=drop(InFront); //Coloco la bateria
if (retval!=0)
{
message("Imposible cargar bateria.",DisplayInfo);
}
else
{
message("Recarga de bateria del " + item.category +" completada.",DisplayInfo);
}
}
else
{
message("Imposible recuperar la bateria. Operacion abortada.",DisplayInfo);
}
}
}
}
if (item!=null)
{
if (item.energyCell==null) // Si el robot no tiene bateria, le busco una
{
if(load!=null && load.category==NuclearCell)
{
message("El " + item.category + " no tiene bateria. Transportando bateria cargada...",DisplayInfo);
if (load.energyLevel<0.5) // Miro si tiene energia
{
RechargeBattery();
}
message("Bateria cargada en " + item.category + ".",DisplayInfo);
}
else
{
message("El " + item.category + " no tiene bateria. Localizando una disponible...",DisplayInfo);
startpoint=position; // Memoriza la posicion actual
item=radar(NuclearCell,0,360,10,1000); //Localizo la celula de carga
message("Bateria localizada. Dirigiendose a su ubicacion...",DisplayInfo);
retval=goto(item.position);
if (retval==0)
{
retval=grab(InFront); //La cojo
if (retval==0)
{
if (load.energyLevel<0.5) // Miro si tiene enrgia
{
RechargeBattery();
}
}
else
{
message("Imposible recuperar bateria. Operacion abortada.",DisplayInfo);
}
}
}
}
}
item = radar(List[i],Angle,10);
}
}
}
++i;
if (i>17)
{
i=0;
}
item = radar(List[i]);
CheckOwnState();
}
}
void object::RechargeBattery()
{
point start; // variable for initial pos.
object item; // info. about power station
//start = position; // stores initial position
NukeRecharge();
//goto(start); // comes back to initial pos.
message("Auto-recarga completada");
}
void object::RepairBot()
{
point start; // variable for initial pos.
object item; // info. about power station
//start = position; // stores initial position
item = radar(RepairCenter); // looks for station
goto(item.position); // goes to the power station
while ( shieldLevel < 1 )
{
wait(1); // waits until recharged
}
move(-1);
//goto(start); // comes back to initial pos.
message("Auto-reparacion completada.",DisplayInfo);
}
void object::CheckOwnState()
{
// Comprobar estado propio
if (energyCell.energyLevel<0.6)
{
message("Nivel de bateria bajo. Regresando a base...",DisplayInfo);
NRechargeMe();
}
if (shieldLevel<1)
{
message("Nivel de escudos bajo. Regresando a base...",DisplayInfo);
RepairBot();
}
}
bool object::NukeRecharge()
{
object cell;
float min = 0;
while( (cell = radar(NuclearCell,0,360,0,1000)) != null )
{
if(cell.energyLevel >= 0.5)
{
goto(cell.position);
if(load!=null)
{
message("Putting down object...",DisplayInfo);
turn(90);
drop();
turn(-90);
}
message("Swapping with better PowerCell...",DisplayInfo);
grab();
return true;
}
}
return false;
}
bool object::NRechargeMe()
{
object cell;
float min = 0;
while( (cell = radar(NuclearCell,0,360,0,1000)) != null )
{
if(cell.energyLevel >= 0.5)
{
goto(cell.position);
if(load!=null)
{
message("Putting down object...",DisplayInfo);
turn(90);
drop();
turn(-90);
}
message("Swapping with better PowerCell...",DisplayInfo);
grab();
drop(Behind);
grab(EnergyCell);
drop();
grab(Behind);
drop(EnergyCell);
return true;
}
}
return false;
}