1 package cz.cuni.amis.pogamut.udk.bot.command;
2
3 import java.util.logging.Logger;
4
5 import javax.vecmath.Vector3d;
6
7 import cz.cuni.amis.pogamut.base3d.worldview.object.ILocated;
8 import cz.cuni.amis.pogamut.base3d.worldview.object.Location;
9 import cz.cuni.amis.pogamut.base3d.worldview.object.Rotation;
10 import cz.cuni.amis.pogamut.udk.bot.impl.UDKBot;
11 import cz.cuni.amis.pogamut.udk.communication.messages.gbcommands.Configuration;
12 import cz.cuni.amis.pogamut.udk.communication.messages.gbcommands.ContinuousMove;
13 import cz.cuni.amis.pogamut.udk.communication.messages.gbcommands.Dodge;
14 import cz.cuni.amis.pogamut.udk.communication.messages.gbcommands.Jump;
15 import cz.cuni.amis.pogamut.udk.communication.messages.gbcommands.Move;
16 import cz.cuni.amis.pogamut.udk.communication.messages.gbinfomessages.Item;
17 import cz.cuni.amis.pogamut.udk.communication.messages.gbinfomessages.Player;
18 import cz.cuni.amis.pogamut.udk.communication.messages.gbinfomessages.Self;
19 import cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId;
20
21
22
23
24
25
26
27 public class AdvancedLocomotion extends SimpleLocomotion {
28
29
30
31
32 Self self = null;
33
34
35
36
37
38 private static final double FOCUS_DISTANCE = 3000;
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59 public void moveAlong(ILocated firstLocation, ILocated secondLocation) {
60 Move moveAlong = new Move();
61
62 moveAlong.setFirstLocation(firstLocation.getLocation());
63 moveAlong.setSecondLocation(secondLocation.getLocation());
64
65 agent.getAct().act(moveAlong);
66 }
67
68
69
70
71
72
73
74
75
76
77
78 public void moveContinuos() {
79 agent.getAct().act(new ContinuousMove());
80 }
81
82
83
84
85
86
87
88
89
90
91
92
93
94 public void strafeRight(double distance, UnrealId focusId) {
95 if (self == null) {
96 self = agent.getWorldView().getSingle(Self.class);
97 }
98 if (self != null) {
99 Location startLoc = self.getLocation();
100 Location directionVector = self.getRotation().toLocation();
101 Location targetVec = directionVector.cross(new Location(0, 0, 1))
102 .getNormalized().scale(-distance);
103
104 agent.getAct().act(
105 new Move().setFirstLocation(startLoc.add(targetVec))
106 .setFocusTarget(focusId));
107 }
108 }
109
110
111
112
113
114
115
116
117
118
119
120
121
122 public void strafeRight(double distance, ILocated focusLocation) {
123 if (self == null) {
124 self = agent.getWorldView().getSingle(Self.class);
125 }
126 if (self != null) {
127 Location startLoc = self.getLocation();
128 Location directionVector = self.getRotation().toLocation();
129 Location targetVec = directionVector.cross(new Location(0, 0, 1))
130 .getNormalized().scale(-distance);
131
132 agent.getAct().act(
133 new Move().setFirstLocation(startLoc.add(targetVec))
134 .setFocusLocation(focusLocation.getLocation()));
135 }
136 }
137
138
139
140
141
142
143
144
145
146
147
148
149
150 public void strafeRight(double distance) {
151 if (self == null) {
152 self = agent.getWorldView().getSingle(Self.class);
153 }
154 if (self != null) {
155 Location startLoc = self.getLocation();
156 Location directionVector = self.getRotation().toLocation();
157 Location targetVec = directionVector.cross(new Location(0, 0, 1))
158 .getNormalized().scale(-distance);
159
160 agent.getAct().act(
161 new Move().setFirstLocation(startLoc.add(targetVec))
162 .setFocusLocation(
163 startLoc.add(directionVector
164 .getNormalized().scale(
165 FOCUS_DISTANCE))));
166 }
167 }
168
169
170
171
172
173
174
175
176
177
178
179
180
181 public void strafeLeft(double distance, UnrealId focusId) {
182 if (self == null) {
183 self = agent.getWorldView().getSingle(Self.class);
184 }
185 if (self != null) {
186 Location startLoc = self.getLocation();
187 Location directionVector = self.getRotation().toLocation();
188 Location targetVec = directionVector.cross(new Location(0, 0, 1))
189 .getNormalized().scale(distance);
190
191 agent.getAct().act(
192 new Move().setFirstLocation(startLoc.add(targetVec))
193 .setFocusTarget(focusId));
194 }
195 }
196
197
198
199
200
201
202
203
204
205
206
207
208
209 public void strafeLeft(double distance, ILocated focusLocation) {
210 if (self == null) {
211 self = agent.getWorldView().getSingle(Self.class);
212 }
213 if (self != null) {
214 Location startLoc = self.getLocation();
215 Location directionVector = self.getRotation().toLocation();
216 Location targetVec = directionVector.cross(new Location(0, 0, 1))
217 .getNormalized().scale(distance);
218
219 agent.getAct().act(
220 new Move().setFirstLocation(startLoc.add(targetVec))
221 .setFocusLocation(focusLocation.getLocation()));
222 }
223 }
224
225
226
227
228
229
230
231
232
233
234
235
236
237 public void strafeLeft(double distance) {
238 if (self == null) {
239 self = agent.getWorldView().getSingle(Self.class);
240 }
241 if (self != null) {
242 Location startLoc = self.getLocation();
243 Location directionVector = self.getRotation().toLocation();
244 Location targetVec = directionVector.cross(new Location(0, 0, 1))
245 .getNormalized().scale(distance);
246
247 agent.getAct().act(
248 new Move().setFirstLocation(startLoc.add(targetVec))
249 .setFocusLocation(
250 startLoc.add(directionVector
251 .getNormalized().scale(
252 FOCUS_DISTANCE))));
253 }
254 }
255
256
257
258
259
260
261
262
263
264
265
266
267 public void strafeTo(ILocated location, ILocated focusLocation) {
268 Move move = new Move().setFirstLocation(location.getLocation())
269 .setFocusLocation(focusLocation.getLocation());
270 agent.getAct().act(move);
271 }
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291 public void strafeTo(ILocated location, UnrealId focus) {
292 Move move = new Move().setFirstLocation(location.getLocation())
293 .setFocusTarget(focus);
294
295
296
297
298
299
300
301
302
303 agent.getAct().act(move);
304 }
305
306
307
308
309
310
311
312
313 public void doubleJump() {
314 Jump jump = new Jump();
315 jump.setDoubleJump(true);
316 agent.getAct().act(jump);
317 }
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332 public void doubleJump(double secondJumpDelay, double jumpZ) {
333 Jump jump = new Jump();
334 jump.setDoubleJump(true);
335
336
337
338
339 agent.getAct().act(jump);
340 }
341
342
343
344
345
346
347
348
349
350
351
352
353 public void dodge(Vector3d direction) {
354 agent.getAct().act(new Dodge(direction));
355 }
356
357
358
359
360
361
362
363
364
365
366
367 public void setSpeed(double speedMultiplier) {
368 Configuration configure = new Configuration();
369 configure.setSpeedMultiplier(speedMultiplier);
370 agent.getAct().act(configure);
371 }
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388 public void setRotationSpeed(Rotation newRotationRate) {
389 Configuration configure = new Configuration();
390 configure.setRotationRate(newRotationRate);
391 agent.getAct().act(configure);
392 }
393
394
395
396
397
398
399
400
401
402 public AdvancedLocomotion(UDKBot agent, Logger log) {
403 super(agent, log);
404 }
405
406 @Override
407 public void jump() {
408 super.jump();
409 }
410
411 @Override
412 public void moveTo(ILocated location) {
413 super.moveTo(location);
414 }
415
416 @Override
417 public void setRun() {
418 super.setRun();
419 }
420
421 @Override
422 public void setWalk() {
423 super.setWalk();
424 }
425
426 @Override
427 public void stopMovement() {
428 super.stopMovement();
429 }
430
431 @Override
432 public void turnHorizontal(int amount) {
433 super.turnHorizontal(amount);
434 }
435
436 @Override
437 public void turnTo(ILocated location) {
438 super.turnTo(location);
439 }
440
441 @Override
442 public void turnTo(Player player) {
443 super.turnTo(player);
444 }
445
446 @Override
447 public void turnTo(Item item) {
448 super.turnTo(item);
449 }
450
451 @Override
452 public void turnVertical(int amount) {
453 super.turnVertical(amount);
454 }
455
456 }