1 package cz.cuni.amis.pogamut.ut2004.agent.navigation.loquenavigator;
2
3 import java.util.logging.Level;
4 import java.util.logging.Logger;
5
6 import cz.cuni.amis.pogamut.base.communication.worldview.event.IWorldEventListener;
7 import cz.cuni.amis.pogamut.base.communication.worldview.object.IWorldObject;
8 import cz.cuni.amis.pogamut.base3d.worldview.object.ILocated;
9 import cz.cuni.amis.pogamut.base3d.worldview.object.Location;
10 import cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId;
11 import cz.cuni.amis.pogamut.ut2004.agent.module.sensor.AgentInfo;
12 import cz.cuni.amis.pogamut.ut2004.agent.module.sensor.Senses;
13 import cz.cuni.amis.pogamut.ut2004.agent.navigation.IUT2004PathRunner;
14 import cz.cuni.amis.pogamut.ut2004.bot.command.AdvancedLocomotion;
15 import cz.cuni.amis.pogamut.ut2004.bot.impl.UT2004Bot;
16 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbcommands.Move;
17 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.NavPointNeighbourLink;
18 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.Player;
19 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.WallCollision;
20 import cz.cuni.amis.pogamut.ut2004.utils.LinkFlag;
21 import cz.cuni.amis.pogamut.ut2004.utils.UnrealUtils;
22 import cz.cuni.amis.utils.NullCheck;
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 public class KefikRunner implements IUT2004PathRunner {
77
78
79
80
81
82
83 private int runnerStep = 0;
84
85
86
87
88 private int jumpStep = 0;
89
90
91
92
93 private int collisionNum = 0;
94
95
96
97
98 private Location collisionSpot = null;
99
100
101
102
103
104
105 private double distance;
106
107
108
109
110 private double distance2D;
111
112
113
114
115 private double distanceZ;
116
117
118
119
120 private double velocity;
121
122
123
124
125 private double velocityZ;
126
127
128
129
130 private boolean jumpRequired;
131
132
133
134
135 private double fallDistance;
136
137
138
139
140
141
142 private Location runningFrom;
143
144
145
146
147 private Location firstLocation;
148
149
150
151
152 private Location secondLocation;
153
154
155
156
157 private ILocated focus;
158
159
160
161
162 private NavPointNeighbourLink link;
163
164
165
166
167 private boolean reachable;
168
169
170 protected WallCollision lastCollidingEvent = null;
171
172 private static final double WALL_COLLISION_THRESHOLD = 1;
173
174
175
176
177
178
179 public NavPointNeighbourLink getLink() {
180 return link;
181 }
182
183
184
185
186
187
188 public void reset()
189 {
190
191 runnerStep = 0;
192 jumpStep = 0;
193 collisionNum = 0;
194 collisionSpot = null;
195 lastCollidingEvent = null;
196 distance = 0;
197 distance2D = 0;
198 distanceZ = 0;
199 velocity = 0;
200 velocityZ = 0;
201 jumpRequired = false;
202 }
203
204
205
206 private void debug(String message) {
207 if (log.isLoggable(Level.FINER)) log.finer("Runner: " + message);
208 }
209
210
211
212
213
214
215 private double getFallDistance(double distanceZ) {
216 distanceZ = Math.abs(distanceZ);
217 if (distanceZ == 60) return 160;
218 if (distanceZ < 60) return 2.66667*distanceZ;
219 return 1.3714 * distanceZ + 35.527;
220 }
221
222
223
224
225
226
227
228
229
230
231 private double getMaxJumpDistance(boolean doubleJump, double jumpDelay, double jumpForce, double distanceZ, double velocity) {
232 if (doubleJump) {
233 jumpForce = Math.min(UnrealUtils.FULL_DOUBLEJUMP_FORCE, jumpForce);
234 } else {
235 jumpForce = Math.min(UnrealUtils.FULL_JUMP_FORCE, jumpForce);
236 }
237 jumpDelay = Math.min(0.75, jumpDelay);
238
239 if (distanceZ >= -5) {
240
241 if (doubleJump) {
242 return velocity * jumpDelay + (jumpForce / UnrealUtils.FULL_DOUBLEJUMP_FORCE) * 400 * (1 + jumpDelay);
243 } else {
244 return velocity * jumpForce;
245 }
246 } else {
247
248 return getFallDistance(distanceZ) + getMaxJumpDistance(doubleJump, jumpDelay, jumpForce, 0, velocity);
249 }
250 }
251
252
253
254
255
256
257
258
259
260
261
262
263 private double getJumpUpDistance(boolean doubleJump, double jumpDelay, double jumpForce, double distanceZ, double velocity) {
264 double jumpForceHeight;
265
266 double result;
267
268 if (doubleJump) {
269
270
271 jumpDelay = Math.min(0.75, jumpDelay);
272 jumpForce = Math.min(UnrealUtils.FULL_DOUBLEJUMP_FORCE, jumpForce);
273
274
275 jumpForceHeight = (jumpForce / UnrealUtils.FULL_DOUBLEJUMP_FORCE) * 125;
276
277
278 double totalTimeOfTheJump = (jumpForce / UnrealUtils.FULL_DOUBLEJUMP_FORCE) + jumpDelay;
279
280 if (jumpForceHeight > distanceZ) {
281
282 result =
283
284 velocity * jumpDelay
285
286 + UnrealUtils.MAX_VELOCITY * ((totalTimeOfTheJump-jumpDelay)/2)
287
288 + UnrealUtils.MAX_VELOCITY * (((totalTimeOfTheJump-jumpDelay)/2) * (1-distanceZ/jumpForceHeight));
289 } else {
290
291 result =
292
293 velocity * jumpDelay
294
295 + ((totalTimeOfTheJump-jumpDelay)/2) * UnrealUtils.MAX_VELOCITY;
296 }
297
298 } else {
299
300
301 jumpForce = Math.min(UnrealUtils.FULL_JUMP_FORCE, jumpForce);
302
303
304 jumpForceHeight = (jumpForce / UnrealUtils.FULL_JUMP_FORCE) * 55;
305
306
307 double totalTimeOfTheJump = jumpForce / UnrealUtils.FULL_JUMP_FORCE;
308
309 if (jumpForceHeight > distanceZ) {
310
311 result =
312
313 velocity * (totalTimeOfTheJump/2)
314
315 + velocity * ((totalTimeOfTheJump/2) * (1 - (distanceZ / jumpForceHeight)));
316 } else {
317
318 result = velocity * (totalTimeOfTheJump/2);
319 }
320 }
321
322 return result;
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 @Override
350 public boolean runToLocation(Location runningFrom, Location firstLocation, Location secondLocation, ILocated focus, NavPointNeighbourLink navPointsLink, boolean reachable)
351 {
352
353 runnerStep++;
354
355
356 this.runningFrom = runningFrom;
357 this.firstLocation = firstLocation;
358 this.secondLocation = secondLocation;
359 this.focus = focus;
360 this.link = navPointsLink;
361 this.reachable = reachable;
362
363
364
365 distance = memory.getLocation().getDistance(firstLocation);
366 distance2D = memory.getLocation().getDistance2D(firstLocation);
367 distanceZ = firstLocation.getDistanceZ(memory.getLocation());
368 if (distanceZ >= 0) fallDistance = 0;
369 else fallDistance = getFallDistance(distanceZ);
370 velocity = memory.getVelocity().size();
371 velocityZ = memory.getVelocity().z;
372 jumpRequired =
373 !reachable ||
374 (link != null
375 && (((link.getFlags() & LinkFlag.JUMP.get()) != 0)
376 || (link.isForceDoubleJump())
377 || (link.getNeededJump() != null)
378 )
379 )
380 ;
381
382
383
384 if (log != null && log.isLoggable(Level.FINER)) {
385 debug("KefikRunner!");
386 debug("running to = " + firstLocation + " and than to " + secondLocation + " and focusing to " + focus);
387 debug("bot position = " + memory.getLocation());
388 debug("distance = " + distance);
389 debug("distance2D = " + distance2D);
390 debug("distanceZ = " + distanceZ);
391 debug("fallDistance = " + fallDistance);
392 debug("velocity = " + velocity);
393 debug("velocityZ = " + velocityZ);
394 debug("jumpRequired = " + jumpRequired
395 + (!reachable ? " NOT_REACHABLE" : "")
396 + (link == null ?
397 ""
398 : (
399 (link.getFlags() & LinkFlag.JUMP.get()) != 0 ? " JUMP_FLAG" : "") + (link.isForceDoubleJump() ? " DOUBLE_JUMP_FORCED" : "") + (link.getNeededJump() != null ? " AT[" + link.getNeededJump() + "]" : ""
400 )
401 )
402 );
403 debug("reachable = " + reachable);
404 if (link != null) {
405 debug("link = " + link);
406 } else {
407 debug("LINK NOT PRESENT");
408 }
409 debug("collisionNum = " + collisionNum);
410 debug("collisionSpot = " + collisionSpot);
411 debug("jumpStep = " + jumpStep);
412 debug("runnerStep = " + runnerStep);
413 }
414
415
416
417 if (runnerStep <= 1) {
418 debug("FIRST STEP - start running towards new location");
419 move(firstLocation, secondLocation, focus);
420 }
421
422
423 if (jumpStep > 0)
424 {
425 debug("we're already jumping");
426 return iterateJumpSequence();
427 }
428
429
430 if (isColliding())
431 {
432 debug("sensing collision");
433
434 return resolveCollision();
435 } else {
436 if (collisionSpot != null || collisionNum != 0) {
437 debug("no collision, clearing collision data");
438 collisionNum = 0;
439 collisionSpot = null;
440 }
441 }
442
443 if (velocity < 5 && runnerStep > 1) {
444 debug("velocity is zero and we're in the middle of running");
445 if (link != null && (link.getFromNavPoint().isLiftCenter() || link.getFromNavPoint().isLiftExit())) {
446 if (link.getFromNavPoint().isLiftCenter()) {
447 debug("we're standing on the lift center, ok");
448 } else {
449 debug("we're standing on the lift exit, ok");
450 }
451 } else {
452 debug("and we're not standing on the lift center");
453 return initJump(true);
454 }
455 }
456
457
458 if (jumpRequired) {
459 debug("jump is required");
460 return resolveJump();
461 }
462
463
464 debug("keeping running to the target");
465 move(firstLocation, secondLocation, focus);
466
467 return true;
468 }
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484 private boolean resolveJump()
485 {
486 debug("resolveJump(): called");
487
488
489
490
491 int jumpDistance2D = ((int)distance2D) % 1000;
492
493 debug("resolveJump(): jumpDistance2D = " + jumpDistance2D);
494
495
496 boolean jumpIndicated = false;
497 boolean mustJumpIfIndicated = false;
498
499 boolean goingToJump = false;
500
501
502
503 if (link != null &&
504 ( ((link.getFlags() & LinkFlag.JUMP.get()) != 0)
505 || (link.isForceDoubleJump())
506 || (link.getNeededJump() != null)
507 )) {
508 debug("resolveJump(): deliberation - jumping condition present");
509 jumpIndicated = true;
510 }
511
512 if (jumpDistance2D < 250) {
513 debug("resolveJump(): we've missed all jumping opportunities (jumpDistance2D < 250)");
514 if (runnerStep > 1) {
515 debug("resolveJump(): and runnerStep > 1, if indicated we will be forced to jump right now");
516 mustJumpIfIndicated = true;
517 } else {
518 debug("resolveJump(): but runnerStep <= 1, can't force jump yet");
519 }
520 }
521
522 debug("resolveJump(): jumpIndicated = " + jumpIndicated);
523 debug("resolveJump(): mustJumpIfIndicated = " + mustJumpIfIndicated);
524
525 if (jumpIndicated && mustJumpIfIndicated) {
526 if (distanceZ > 0) {
527 debug("resolveJump(): we MUST jump!");
528 return prepareJump(true);
529 } else {
530 debug("resolveJump(): we MUST fall down with a jump!");
531 return prepareJump(true);
532 }
533 } else
534 if (jumpIndicated) {
535 debug("resolveJump(): we should jump");
536 return prepareJump(false);
537 } else {
538 debug("resolveJump(): we do not need to jump, waiting to reach the right spot to jump from");
539
540
541 move(firstLocation, secondLocation, focus);
542 return true;
543 }
544 }
545
546
547
548
549
550
551
552
553
554
555
556
557
558 private boolean prepareJump(boolean jumpForced) {
559 debug("prepareJump(): called");
560
561 Location direction = Location.sub(firstLocation, memory.getLocation()).setZ(0);
562 direction = direction.getNormalized();
563 Location velocityDir = new Location(memory.getVelocity().asVector3d()).setZ(0);
564 velocityDir = velocityDir.getNormalized();
565 Double jumpAngleDeviation = Math.acos(direction.dot(velocityDir));
566
567 boolean angleSuitable = !jumpAngleDeviation.isNaN() && jumpAngleDeviation < (Math.PI / 9);
568
569 debug("prepareJump(): jumpAngleDeviation = " + jumpAngleDeviation);
570 debug("prepareJump(): angleSuitable = " + angleSuitable);
571
572 if (jumpForced) {
573 debug("prepareJump(): jump is forced, bypassing jump checks!");
574 } else {
575 debug("prepareJump(): jump is not forced, checking jump conditions");
576
577
578 if (velocity < 200 && distance2D > getMaxJumpDistance(true, UnrealUtils.FULL_DOUBLEJUMP_DELAY, UnrealUtils.FULL_DOUBLEJUMP_FORCE, distanceZ, velocity)) {
579 debug("prepareJump(): velocity is too low for jump (velocity < 200) and target is too far away to jump there with double jump");
580 debug("prepareJump(): proceeding with the straight movement to gain speed");
581 move(firstLocation, secondLocation, focus);
582 return true;
583 }
584
585 if (!angleSuitable) {
586 debug("prepareJump(): angle is not suitable for jumping (angle > 20 degrees)");
587 debug("prepareJump(): proceeding with the straight movement to gain speed");
588 move(firstLocation, secondLocation, focus);
589 return true;
590 }
591
592 debug("prepareJump(): velocity & angle is OK!");
593 }
594
595 if (distanceZ >= 0) {
596 debug("prepareJump(): JUMP (distanceZ >= 0)");
597 return initJump(jumpForced);
598 } else {
599 debug("prepareFall(): FALL (distanceZ < 0)");
600 return initFall(jumpForced);
601 }
602 }
603
604
605
606 private double adjustJumpForce(double distanceSafeZone, boolean doubleJump, double jumpForce, double jumpDelay) {
607 double distanceJumped = getJumpUpDistance(doubleJump, jumpDelay, jumpForce, distanceZ, velocity);
608 debug("initJump(): adjusting jumpForce...");
609 while (distanceJumped-distanceSafeZone < distance2D &&
610 ( (doubleJump && jumpForce < UnrealUtils.FULL_DOUBLEJUMP_FORCE)
611 || (!doubleJump && jumpForce < UnrealUtils.FULL_JUMP_FORCE))
612 ) {
613 jumpForce += 10;
614 distanceJumped = getJumpUpDistance(doubleJump, jumpDelay, jumpForce, distanceZ, velocity);
615 }
616
617 if (doubleJump) {
618 jumpForce = Math.min(jumpForce, UnrealUtils.FULL_DOUBLEJUMP_FORCE);
619 } else {
620 jumpForce = Math.min(jumpForce, UnrealUtils.FULL_JUMP_FORCE);
621 }
622 debug("initJump(): jumpForce = " + jumpForce);
623 return jumpForce;
624 }
625
626
627
628
629
630
631
632
633
634
635 private boolean initJump(boolean jumpForced) {
636 debug("initJump(): called");
637
638 boolean shouldJump = true;
639
640 boolean doubleJump = true;
641 double jumpForce = UnrealUtils.FULL_DOUBLEJUMP_FORCE;
642 double jumpDelay = UnrealUtils.FULL_DOUBLEJUMP_DELAY;
643
644 if (distanceZ > 130) {
645 debug("initJump(): jump could not be made (distanceZ = " + distanceZ + " > 130)");
646 if (jumpForced) {
647 debug("initJump(): but jump is being forced!");
648 } else {
649 debug("initJump(): jump is not forced ... we will wait till the bot reach the right jumping spot");
650 move(firstLocation, secondLocation, focus);
651 jumpStep = 0;
652 return true;
653 }
654 }
655
656
657
658 if (collisionNum == 0 && distanceZ < 55 && distance2D < velocity * 0.85
659 && (link == null || link.getNeededJump() == null || link.getNeededJump().getZ() <= UnrealUtils.FULL_JUMP_FORCE) ) {
660 debug("initJump(): single jump suffices (distanceZ < 55 && distance2D = " + distance2D + " < " + (velocity*0.85) +" = velocity * 0.85) && (link.getNeededJump == null || link.getNeededJump().getZ() <= UnrealUtils.FULL_JUMP_FORCE ))");
661 doubleJump = false;
662 jumpForce = UnrealUtils.FULL_JUMP_FORCE;
663 }
664
665 double jumpUp_force = 0;
666 if (doubleJump) {
667 if (collisionNum != 0)
668 jumpUp_force = UnrealUtils.FULL_DOUBLEJUMP_FORCE;
669 else
670 jumpUp_force = UnrealUtils.FULL_DOUBLEJUMP_FORCE * ((distanceZ+5) / 110);
671 jumpUp_force = Math.min(jumpUp_force, UnrealUtils.FULL_DOUBLEJUMP_FORCE);
672 } else {
673 jumpUp_force = UnrealUtils.FULL_JUMP_FORCE * ((distanceZ+5) / 55);
674
675 jumpUp_force = Math.min(jumpUp_force, UnrealUtils.FULL_JUMP_FORCE);
676 }
677
678
679
680
681
682
683
684
685
686 debug("initJump(): minimum force to jump to height " + distanceZ + " with " + (doubleJump ? "double" : "single") + " is " + jumpUp_force);
687 double distanceSafeZone = 0;
688 debug("initJump(): adjusting force to match jumping distance = " + distance2D + " = distance2D (safe zone = " + distanceSafeZone + ")");
689 jumpForce = adjustJumpForce(distanceSafeZone, doubleJump, jumpUp_force, jumpDelay);
690 double distanceJumped = getJumpUpDistance(doubleJump, jumpDelay, jumpForce, distanceZ, velocity);
691 if (distanceJumped-distanceSafeZone < distance2D) {
692 debug("initJump(): too short! (distanceJumped-" + distanceSafeZone + " = " + (distanceJumped-distanceSafeZone) + " < " + distance2D + " = distance2D)");
693 if (!doubleJump) {
694 debug("initJump(): trying double jump");
695 doubleJump = true;
696 jumpUp_force = UnrealUtils.FULL_DOUBLEJUMP_FORCE * ((distanceZ+5) / 125);
697 jumpUp_force = Math.min(jumpUp_force, UnrealUtils.FULL_DOUBLEJUMP_FORCE);
698 debug("initJump(): minimum force to jump to height " + distanceZ + " with double jump is " + jumpUp_force);
699 debug("initJump(): adjusting force to match jumping distance = " + distance2D + " = distance2D (safe zone = " + distanceSafeZone + ")");
700 jumpForce = adjustJumpForce(distanceSafeZone, doubleJump, jumpUp_force, jumpDelay);
701 distanceJumped = getMaxJumpDistance(doubleJump, jumpDelay, jumpForce, distanceZ, velocity);
702 if (distanceJumped-distanceSafeZone < distance2D) {
703 debug("initJump(): still too short! (distanceJumped-" + distanceSafeZone + " = " + (distanceJumped-distanceSafeZone) + " < " + distance2D + " = distance2D)");
704 shouldJump = false;
705 } else {
706 debug("initJump(): distance ok (distanceJumped-" + distanceSafeZone + " = " + (distanceJumped-distanceSafeZone) + " >= " + distance2D + " = distance2D)");
707 shouldJump = true;
708 }
709 } else {
710 shouldJump = false;
711 }
712 } else {
713 debug("initJump(): distance ok (distanceJumped-" + distanceSafeZone + " = " + (distanceJumped-distanceSafeZone) + " >= " + distance2D + " = distance2D)");
714 shouldJump = true;
715 }
716
717 if (shouldJump || jumpForced) {
718 if (jumpForced && !shouldJump) {
719 debug("initJump(): we should not be jumping, but jump is FORCED!");
720 }
721 jumpStep = 1;
722 return jump(true, jumpDelay, jumpForce);
723 } else {
724 debug("initJump(): jump is not forced ... we will wait till the bot reach the right jumping spot");
725 move(firstLocation, secondLocation, focus);
726 jumpStep = 0;
727 return true;
728 }
729 }
730
731
732
733
734
735 private boolean initFall(boolean jumpForced) {
736 debug("initFall(): called");
737
738 jumpStep = 1;
739
740 log.finer("Runner.initDoubleJumpSequence(): FALLING DOWN! Adjusting parameters of the jump for falling...");
741
742
743
744 double remainingDistance2D = distance2D - fallDistance;
745
746 debug("initFall(): distance2D = " + distance2D);
747 debug("initFall(): falling will get us = " + fallDistance + " further");
748 debug("initFall(): remainingDistance2D = " + remainingDistance2D);
749
750
751 boolean doubleJump = true;
752 double jumpZ = 705;
753
754
755
756
757
758 if (remainingDistance2D < velocity) {
759 debug("initFall(): single jump suffices (remainingDistance2D < velocity)");
760 doubleJump = false;
761 jumpZ = 340 * remainingDistance2D / 300;
762 } else
763 if (remainingDistance2D < 450) {
764 log.finer("initFall(): smaller double jump is needed (remainingDistance2D < 450)");
765 doubleJump = true;
766 jumpZ = 340 + 365 * (remainingDistance2D - 220) * 150;
767 } else {
768 log.finer("Runner.initDoubleJumpSequence(): full double jump is needed (remainingDistance2D > 450)");
769 doubleJump = true;
770 jumpZ = 705;
771 }
772
773 return jump(doubleJump, 0.39, jumpZ);
774 }
775
776
777
778
779
780
781 private boolean jump(boolean doubleJump, double delay, double force) {
782 if (doubleJump) {
783 debug("DOUBLE JUMPING (delay = " + delay + ", force = " + force + ")");
784 } else {
785 debug("JUMPING (delay = " + delay + ", force = " + force + ")");
786 }
787 body.jump(doubleJump, delay, force);
788
789 return true;
790 }
791
792 private void move(ILocated firstLocation, ILocated secondLocation, ILocated focus) {
793 Move move = new Move();
794 if (firstLocation != null) {
795 move.setFirstLocation(firstLocation.getLocation());
796 }
797 if (secondLocation != null) {
798 move.setSecondLocation(secondLocation.getLocation());
799 }
800
801 if (focus != null) {
802 if (focus instanceof Player) {
803 move.setFocusTarget((UnrealId)((IWorldObject)focus).getId());
804 } else {
805 move.setFocusLocation(focus.getLocation());
806 }
807 }
808
809 log.finer("MOVING: " + move);
810 bot.getAct().act(move);
811 }
812
813
814
815
816
817
818
819
820
821
822
823 private boolean resolveCollision()
824 {
825
826 if (
827
828 (collisionSpot == null)
829
830 || (memory.getLocation().getDistance2D(collisionSpot) > 120)
831 ) {
832
833 if (log != null && log.isLoggable(Level.FINER)) log.finer("Runner.resolveCollision(): collision");
834 collisionSpot = memory.getLocation();
835 collisionNum = 1;
836
837 move(firstLocation, secondLocation, focus);
838 return true;
839 }
840
841
842 else {
843 return initJump(true);
844 }
845 }
846
847
848
849
850
851
852
853 private boolean iterateJumpSequence()
854 {
855 debug("iterateJumpSequence(): called");
856
857 switch (jumpStep) {
858
859 case 1:
860
861 if (velocityZ > 100)
862 {
863 debug("iterateJumpSequence(): jumping in progress (velocityZ > 100), increasing jumpStep");
864 jumpStep++;
865 }
866
867 debug("iterateJumpSequence(): issuing move command to the target (just to be sure)");
868 move(firstLocation, secondLocation, focus);
869 return true;
870
871
872 default:
873
874 if (velocityZ <= 0.01)
875 {
876 debug("iterateJumpSequence(): jump ascension has ended (velocityZ < 0.01)");
877 jumpStep = 0;
878 }
879 debug("iterateJumpSequence(): continuing movement to the target");
880 move(firstLocation, secondLocation, focus);
881 return true;
882 }
883
884
885 }
886
887
888
889 protected boolean isColliding() {
890 if (lastCollidingEvent == null) return false;
891 debug("isColliding():"+"(memory.getTime():" + memory.getTime() + " - (lastCollidingEvent.getSimTime() / 1000):" + (lastCollidingEvent.getSimTime() / 1000) +" <= WALL_COLLISION_THRESHOLD:" + WALL_COLLISION_THRESHOLD + " )");
892 if (memory.getTime() - (lastCollidingEvent.getSimTime() / 1000) <= WALL_COLLISION_THRESHOLD ) {
893 debug("isColliding():return true;");
894 return true;
895 }
896
897 return false;
898 }
899
900
901
902
903
904 IWorldEventListener<WallCollision> myCollisionsListener = new IWorldEventListener<WallCollision>() {
905 @Override
906 public void notify(WallCollision event) {
907 lastCollidingEvent = event;
908 }
909
910 };
911
912
913
914
915
916 protected UT2004Bot bot;
917
918 protected AgentInfo memory;
919
920 protected AdvancedLocomotion body;
921
922 protected Logger log;
923
924
925
926
927
928
929
930
931
932
933 public KefikRunner(UT2004Bot bot, AgentInfo agentInfo, AdvancedLocomotion locomotion, Logger log) {
934
935 NullCheck.check(bot, "bot");
936 this.bot = bot;
937 NullCheck.check(agentInfo, "agentInfo");
938 this.memory = agentInfo;
939 NullCheck.check(locomotion, "locomotion");
940 this.body = locomotion;
941
942
943 bot.getWorldView().addEventListener(WallCollision.class, myCollisionsListener);
944
945 this.log = log;
946 if (this.log == null) {
947 log = bot.getLogger().getCategory(this.getClass().getSimpleName());
948 }
949 }
950
951 }