1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package nl.tudelft.goal.ut2004.agent;
22
23 import java.lang.reflect.Method;
24 import java.util.ArrayList;
25 import java.util.Collection;
26 import java.util.LinkedList;
27 import java.util.List;
28 import java.util.Map;
29
30 import nl.tudelft.goal.unreal.messages.BotParameters;
31 import nl.tudelft.goal.unreal.messages.Parameters;
32 import nl.tudelft.goal.unreal.util.Selector;
33 import nl.tudelft.goal.ut2004.actions.Action;
34 import nl.tudelft.goal.ut2004.actions.ActionQueue;
35 import nl.tudelft.goal.ut2004.actions.Continue;
36 import nl.tudelft.goal.ut2004.actions.DropWeapon;
37 import nl.tudelft.goal.ut2004.actions.Look;
38 import nl.tudelft.goal.ut2004.actions.Navigate;
39 import nl.tudelft.goal.ut2004.actions.Prefer;
40 import nl.tudelft.goal.ut2004.actions.Respawn;
41 import nl.tudelft.goal.ut2004.actions.Shoot;
42 import nl.tudelft.goal.ut2004.actions.Stop;
43 import nl.tudelft.goal.ut2004.floydwarshall.SharedFloydWarshallMap;
44 import nl.tudelft.goal.ut2004.messages.Combo;
45 import nl.tudelft.goal.ut2004.messages.FireMode;
46 import nl.tudelft.goal.ut2004.messages.FlagState;
47 import nl.tudelft.goal.ut2004.messages.None;
48 import nl.tudelft.goal.ut2004.messages.Percept;
49 import nl.tudelft.goal.ut2004.messages.SelectorList;
50 import nl.tudelft.goal.ut2004.messages.UnrealIdOrLocation;
51 import nl.tudelft.goal.ut2004.messages.WeaponPrefList;
52 import nl.tudelft.goal.ut2004.selector.ContextSelector;
53 import nl.tudelft.goal.ut2004.selector.NearestEnemy;
54 import nl.tudelft.goal.ut2004.util.Team;
55 import nl.tudelft.pogamut.ut2004.agent.module.sensor.Projectiles;
56 import nl.tudelft.pogamut.ut2004.agent.module.shooting.WeaponryShooting;
57 import nl.tudelft.pogamut.ut2004.agent.module.shooting.util.FocusProvider;
58 import nl.tudelft.pogamut.ut2004.agent.module.shooting.util.OrderedFocusProvider;
59 import nl.tudelft.pogamut.ut2004.agent.module.shooting.weapon.AssaultRifleShooting;
60 import nl.tudelft.pogamut.ut2004.agent.module.shooting.weapon.BioRifleShooting;
61 import nl.tudelft.pogamut.ut2004.agent.module.shooting.weapon.FlakCannonShooting;
62 import nl.tudelft.pogamut.ut2004.agent.module.shooting.weapon.LigthningGunShooting;
63 import nl.tudelft.pogamut.ut2004.agent.module.shooting.weapon.LinkGunShooting;
64 import nl.tudelft.pogamut.ut2004.agent.module.shooting.weapon.MinigunShooting;
65 import nl.tudelft.pogamut.ut2004.agent.module.shooting.weapon.RocketLauncherShooting;
66 import nl.tudelft.pogamut.ut2004.agent.module.shooting.weapon.ShieldGunShooting;
67 import nl.tudelft.pogamut.ut2004.agent.module.shooting.weapon.ShockRifleShooting;
68 import nl.tudelft.pogamut.ut2004.agent.module.shooting.weapon.SniperRifleShooting;
69 import cz.cuni.amis.pogamut.base.agent.navigation.IPathPlanner;
70 import cz.cuni.amis.pogamut.base.communication.worldview.listener.annotation.EventListener;
71 import cz.cuni.amis.pogamut.base.communication.worldview.object.IWorldObject;
72 import cz.cuni.amis.pogamut.base.utils.logging.IAgentLogger;
73 import cz.cuni.amis.pogamut.base.utils.math.DistanceUtils;
74 import cz.cuni.amis.pogamut.base3d.worldview.object.ILocated;
75 import cz.cuni.amis.pogamut.base3d.worldview.object.Location;
76 import cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId;
77 import cz.cuni.amis.pogamut.ut2004.agent.module.sensomotoric.Weapon;
78 import cz.cuni.amis.pogamut.ut2004.agent.module.sensor.WeaponPref;
79 import cz.cuni.amis.pogamut.ut2004.agent.navigation.UT2004AStarPathPlanner;
80 import cz.cuni.amis.pogamut.ut2004.agent.navigation.UT2004GetBackToNavGraph;
81 import cz.cuni.amis.pogamut.ut2004.agent.navigation.UT2004Navigation;
82 import cz.cuni.amis.pogamut.ut2004.agent.navigation.UT2004PathExecutor;
83 import cz.cuni.amis.pogamut.ut2004.agent.navigation.UT2004RunStraight;
84 import cz.cuni.amis.pogamut.ut2004.agent.navigation.loquenavigator.LoqueNavigator;
85 import cz.cuni.amis.pogamut.ut2004.agent.navigation.stuckdetector.UT2004DistanceStuckDetector;
86 import cz.cuni.amis.pogamut.ut2004.agent.navigation.stuckdetector.UT2004PositionStuckDetector;
87 import cz.cuni.amis.pogamut.ut2004.agent.navigation.stuckdetector.UT2004TimeStuckDetector;
88 import cz.cuni.amis.pogamut.ut2004.agent.params.UT2004AgentParameters;
89 import cz.cuni.amis.pogamut.ut2004.bot.impl.UT2004Bot;
90 import cz.cuni.amis.pogamut.ut2004.bot.impl.UT2004BotModuleController;
91 import cz.cuni.amis.pogamut.ut2004.communication.messages.ItemType;
92 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbcommands.AddInventory;
93 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbcommands.GetPath;
94 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbcommands.Initialize;
95 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.BotKilled;
96 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.FlagInfo;
97 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.Item;
98 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.NavPoint;
99 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.PathList;
100 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.Player;
101 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.PlayerKilled;
102 import cz.cuni.amis.pogamut.ut2004.utils.UT2004BotRunner;
103 import cz.cuni.amis.utils.exception.PogamutException;
104 import eis.eis2java.annotation.AsAction;
105 import eis.eis2java.annotation.AsPercept;
106 import eis.eis2java.translation.Filter.Type;
107 import eis.eis2java.util.AllPerceptsModule;
108 import eis.eis2java.util.AllPerceptsProvider;
109 import eis.exceptions.EntityException;
110 import eis.exceptions.PerceiveException;
111
112 @SuppressWarnings("rawtypes")
113 public class UT2004BotBehavior extends UT2004BotModuleController<UT2004Bot> implements AllPerceptsProvider {
114
115 protected List<ContextSelector> targetSelector = new ArrayList<ContextSelector>();
116 protected List<ContextSelector> lookSelector = new ArrayList<ContextSelector>();
117 protected Projectiles projectiles;
118 protected WeaponryShooting weaponShooting;
119 protected FocusProvider lookFocus = new FocusProvider();
120 protected OrderedFocusProvider focus = new OrderedFocusProvider();
121 protected long logicIteration;
122 protected long actionCount;
123
124 protected AllPerceptsModule percepts;
125
126
127
128 protected BotParameters parameters;
129
130
131
132
133
134
135
136
137 private static final int ACTION_QUEUE_SIZE = 8;
138
139
140
141
142
143 private ActionQueue actions = new ActionQueue(ACTION_QUEUE_SIZE);
144
145 @Override
146 public void initializeController(UT2004Bot bot) {
147 super.initializeController(bot);
148
149
150 IAgentLogger logger = bot.getLogger();
151 UT2004AgentParameters parameters = bot.getParams();
152 if ((parameters instanceof BotParameters)) {
153 this.parameters = (BotParameters) parameters;
154 } else {
155 log.warning("Provided parameters were not a subclass of UnrealGoalParameters, using defaults.");
156 this.parameters = new BotParameters(logger);
157 }
158 Parameters defaults = BotParameters.getDefaults(logger);
159 this.parameters.assignDefaults(defaults);
160
161 }
162
163
164
165
166 protected void initializeModules(UT2004Bot bot) {
167 super.initializeModules(bot);
168
169 projectiles = new Projectiles(bot, info);
170 weaponShooting = new WeaponryShooting(bot, info, weaponry, weaponPrefs, shoot);
171
172
173 try {
174 percepts = new AllPerceptsModule(this);
175 } catch (EntityException e) {
176 throw new PogamutException("Could not create percept module", e);
177 }
178
179 initializeWeaponShootings();
180 }
181
182
183
184
185 protected void initializeWeaponShootings() {
186 weaponShooting.addWeaponShooting(new LinkGunShooting(bot, info, shoot, weaponry));
187 weaponShooting.addWeaponShooting(new ShockRifleShooting(bot, info, shoot, weaponry, projectiles));
188 weaponShooting.addWeaponShooting(new MinigunShooting(bot, info, shoot, weaponry));
189 weaponShooting.addWeaponShooting(new FlakCannonShooting(bot, info, shoot, weaponry));
190 weaponShooting.addWeaponShooting(new ShieldGunShooting(bot, info, shoot, weaponry, projectiles, senses));
191 weaponShooting.addWeaponShooting(new BioRifleShooting(bot, info, shoot, weaponry));
192 weaponShooting.addWeaponShooting(new AssaultRifleShooting(bot, info, shoot, weaponry));
193 weaponShooting.addWeaponShooting(new RocketLauncherShooting(bot, info, shoot, weaponry));
194 weaponShooting.addWeaponShooting(new LigthningGunShooting(bot, info, shoot, weaponry));
195 weaponShooting.addWeaponShooting(new SniperRifleShooting(bot, info, shoot, weaponry));
196 }
197
198
199
200
201
202
203
204
205 protected SharedFloydWarshallMap sfwMap;
206
207
208
209
210
211
212 @Override
213 protected void initializePathFinding(UT2004Bot bot) {
214 pathPlanner = new UT2004AStarPathPlanner(bot);
215 sfwMap = new SharedFloydWarshallMap(bot);
216 pathExecutor =
217 new UT2004PathExecutor<ILocated>(
218 bot,
219 new LoqueNavigator<ILocated>(bot, bot.getLog()),
220 bot.getLog()
221 );
222
223
224
225
226 pathExecutor.addStuckDetector(new UT2004TimeStuckDetector(bot, 3000, 100000));
227 pathExecutor.addStuckDetector(new UT2004PositionStuckDetector(bot));
228 pathExecutor.addStuckDetector(new UT2004DistanceStuckDetector(bot));
229
230 getBackToNavGraph = new UT2004GetBackToNavGraph(bot, info, move);
231 runStraight = new UT2004RunStraight(bot, info, move);
232 navigation = new UT2004Navigation(bot, pathExecutor, sfwMap, getBackToNavGraph, runStraight);
233 }
234
235
236
237
238
239 @Override
240 public void finishControllerInitialization() {
241 super.finishControllerInitialization();
242
243
244
245
246 focus.add(weaponShooting.getFocus());
247 focus.add(lookFocus);
248 navigation.setFocus(focus);
249 }
250
251
252
253
254
255
256 @Override
257 public Initialize getInitializeCommand() {
258 assert parameters != null;
259
260
261 Initialize init = super.getInitializeCommand();
262 init.setDesiredSkill(parameters.getSkill());
263 init.setSkin(parameters.getSkin().getUnrealName());
264 init.setTeam(parameters.getTeam());
265 init.setShouldLeadTarget(parameters.shouldLeadTarget());
266
267 init.setLocation(parameters.getInitialLocation());
268 init.setRotation(parameters.getInitialRotation());
269
270 log.setLevel(this.parameters.getLogLevel());
271
272 return init;
273
274 }
275
276
277
278
279
280
281 @Override
282 public void beforeFirstLogic() {
283 targetSelector.add(new NearestEnemy().setContext(this));
284 lookSelector.add(new NearestEnemy().setContext(this));
285
286 weaponPrefs.addGeneralPref(ItemType.SHOCK_RIFLE, false);
287 weaponPrefs.addGeneralPref(ItemType.ROCKET_LAUNCHER, true);
288 weaponPrefs.addGeneralPref(ItemType.FLAK_CANNON, true);
289 weaponPrefs.addGeneralPref(ItemType.SNIPER_RIFLE, true);
290 weaponPrefs.addGeneralPref(ItemType.LIGHTNING_GUN, true);
291 weaponPrefs.addGeneralPref(ItemType.MINIGUN, true);
292 weaponPrefs.addGeneralPref(ItemType.LINK_GUN, true);
293 weaponPrefs.addGeneralPref(ItemType.BIO_RIFLE, false);
294 weaponPrefs.addGeneralPref(ItemType.ASSAULT_RIFLE, true);
295 weaponPrefs.addGeneralPref(ItemType.ASSAULT_RIFLE, false);
296 weaponPrefs.addGeneralPref(ItemType.SHIELD_GUN, false);
297 weaponPrefs.addGeneralPref(ItemType.SHIELD_GUN, true);
298
299 }
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328 @Override
329 public void logic() {
330 super.logic();
331
332
333 for (Action action : actions.drain()) {
334 action.execute();
335 actionCount++;
336 }
337
338
339
340 ILocated shootSelected = null;
341 for (Selector<ILocated> selector : targetSelector) {
342 shootSelected = selector.select(players.getVisiblePlayers().values());
343 if (shootSelected != null) {
344 break;
345 }
346 }
347 weaponShooting.shoot(shootSelected);
348
349
350
351 ILocated lookSelected = null;
352 for (Selector<ILocated> selector : lookSelector) {
353 lookSelected = selector.select(players.getVisiblePlayers().values());
354 if (lookSelected != null) {
355 break;
356 }
357 }
358 lookFocus.setFocus(lookSelected);
359
360
361 if (!navigation.isNavigating()) {
362
363 if (focus.getLocation() != null) {
364 move.turnTo(focus.getLocation());
365 }
366
367 else {
368 move.turnHorizontal(30);
369 }
370 }
371
372 logicIteration++;
373
374
375 try {
376 percepts.updatePercepts();
377 } catch (PerceiveException e) {
378 throw new PogamutException("Could not update percepts", e);
379 }
380
381 }
382
383
384
385
386
387
388
389
390
391 public void addAction(Action action) throws InterruptedException {
392 actions.put(action);
393 }
394
395
396
397
398
399
400 public Map<Method, Object> getAllPercepts() {
401 return percepts.getAllPercepts();
402 }
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427 @AsAction(name = "navigate")
428 public void navigate(final UnrealIdOrLocation destination) throws InterruptedException {
429 log.fine(String.format("called navigate to %s", destination));
430 if (destination.isLocation()) {
431 navigate(destination.getLocation());
432 } else {
433 navigate(destination.getId());
434 }
435 }
436
437 private void navigate(final ILocated destination) throws InterruptedException {
438
439 addAction(new Navigate() {
440
441 @Override
442 public void execute() {
443 log.info(String.format("executed navigate to %s", destination));
444 navigation.navigate(destination);
445 return;
446 }
447 });
448 }
449
450 private void navigate(final UnrealId destination) throws InterruptedException {
451
452 addAction(new Navigate() {
453
454 @Override
455 public void execute() {
456
457 IWorldObject object = world.get(destination);
458 if (!(object instanceof ILocated)) {
459 log.warning(String.format(
460 "failed to navigate to %s. The object associated with this Id was not located in the world. Halting.", object));
461 navigation.stopNavigation();
462 return;
463 }
464
465 log.fine(String.format("executed navigate to %s", object));
466 navigation.navigate((ILocated) object);
467 }
468 });
469
470 }
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489 @AsAction(name = "continue")
490 public void continueAction(UnrealIdOrLocation destination) throws InterruptedException {
491 log.fine(String.format("called continue to %s", destination));
492
493 if (destination.isLocation()) {
494 continueAction(destination.getLocation());
495
496 } else {
497 continueAction(destination.getId());
498 }
499 }
500
501 public void continueAction(final ILocated destination) throws InterruptedException {
502 addAction(new Continue() {
503
504 @Override
505 public void execute() {
506 log.info(String.format("executed continue to %s", destination.getLocation()));
507
508 if (!navigation.isNavigating()) {
509 navigation.navigate(destination);
510 } else {
511 navigation.setContinueTo(destination);
512 }
513 }
514 });
515 }
516
517 public void continueAction(final UnrealId destination) throws InterruptedException {
518 addAction(new Continue() {
519
520 @Override
521 public void execute() {
522
523 IWorldObject object = world.get(destination);
524 if (!(object instanceof ILocated)) {
525 log.warning(String.format(
526 "failed to navigate to %s. The object associated with this Id was not located in the world. Halting.", object));
527 navigation.stopNavigation();
528 return;
529 }
530
531 log.info(String.format("executed continue to %s", object));
532
533 if (!navigation.isNavigating()) {
534 navigation.navigate((ILocated) object);
535 } else {
536 navigation.setContinueTo((ILocated) object);
537 }
538
539 }
540 });
541 }
542
543
544
545
546
547
548 @AsAction(name = "stop")
549 public void stop() throws InterruptedException {
550 log.fine("called stop");
551
552 addAction(new Stop() {
553 @Override
554 public void execute() {
555 log.info("executed stop");
556 navigation.stopNavigation();
557 }
558 });
559 }
560
561
562
563
564
565
566
567
568
569 @AsAction(name = "respawn")
570 public void respawn() throws InterruptedException {
571 log.fine("called respawn");
572 addAction(new Respawn() {
573 @Override
574 public void execute() {
575 log.info("executed respawn");
576 bot.respawn();
577 }
578 });
579 }
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609 @AsAction(name = "combo")
610 public void combo(final Combo combo) throws InterruptedException {
611 log.fine("called combo %s", combo);
612
613 addAction(new nl.tudelft.goal.ut2004.actions.Combo() {
614 @Override
615 public void execute() {
616
617 if (info.isAdrenalineSufficient()) {
618 log.info("executed combo %s", combo);
619 body.getAction().startCombo(combo.toString());
620 } else {
621 log.warning("combo %s failed, insufficient adrenaline", combo);
622 }
623 }
624 });
625 }
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644 @AsAction(name = "dropWeapon")
645 public void dropWeapon() throws InterruptedException {
646 log.fine("called drop");
647
648 addAction(new DropWeapon() {
649 @Override
650 public void execute() {
651 Weapon weapon = weaponry.getCurrentWeapon();
652
653 body.getAction().throwWeapon();
654
655 if (weapon == null) {
656 log.warning(String.format("Could not drop weapon. Not holding a weapon."));
657 } else if (weapon.getType() == ItemType.SHIELD_GUN || weapon.getType() == ItemType.TRANSLOCATOR) {
658 log.warning(String.format("Could not drop weapon %s", weapon));
659 } else {
660 log.info("executed drop %s", weapon);
661 }
662 }
663 });
664 }
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697 @AsAction(name = "path")
698 public Percept path(UnrealIdOrLocation from, UnrealIdOrLocation to) {
699 if (from.isLocation()) {
700 return path(from.getLocation(), to);
701 } else {
702 return path(from.getId(), to);
703 }
704 }
705
706 private Percept path(UnrealId from, UnrealIdOrLocation to) {
707 if (to.isLocation()) {
708 return path(from, to.getLocation());
709 } else {
710 return path(from, to.getId());
711 }
712 }
713
714 private Percept path(ILocated from, UnrealIdOrLocation to) {
715 if (to.isLocation()) {
716 return path(from, to.getLocation());
717 } else {
718 return path(from, to.getId());
719 }
720 }
721
722 private Percept path(ILocated from, UnrealId to) {
723 IWorldObject toObject = world.get(to);
724
725 if (!(toObject instanceof ILocated)) {
726 throw new PogamutException(String.format("failed to compute path from %s to %s. One or both were no locations", from, to), this);
727 }
728
729 return path(from, (ILocated) toObject);
730 }
731
732 private Percept path(UnrealId from, UnrealId to) {
733 IWorldObject toObject = world.get(to);
734 IWorldObject fromObject = world.get(from);
735
736 if (!(fromObject instanceof ILocated) || !(toObject instanceof ILocated)) {
737 throw new PogamutException(String.format("failed to compute path from %s to %s. One or both were no locations", from, to), this);
738 }
739
740 return path((ILocated) fromObject, (ILocated) toObject);
741 }
742
743 private Percept path(UnrealId from, ILocated to) {
744 IWorldObject fromObject = world.get(from);
745
746 if (!(fromObject instanceof ILocated)) {
747 throw new PogamutException(String.format("failed to compute path from %s to %s. One or both were no locations", from, to), this);
748 }
749
750 return path(((ILocated) fromObject), to);
751 }
752
753 private Percept path(ILocated from, ILocated to) {
754
755
756
757 log.info(String.format("executed path from %s to %s", from, to));
758
759 NavPoint fromNav = DistanceUtils.getNearest(world.getAll(NavPoint.class).values(), from);
760
761 NavPoint toNav = DistanceUtils.getNearest(world.getAll(NavPoint.class).values(), to);
762
763 double distance = sfwMap.getDistance(fromNav, toNav);
764 List<NavPoint> navPoints = sfwMap.getPath(fromNav, toNav);
765 List<UnrealId> unrealIds = new ArrayList<UnrealId>(navPoints.size());
766 for (NavPoint n : navPoints) {
767 unrealIds.add(n.getId());
768 }
769 return new Percept(distance, unrealIds);
770 }
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802 @AsAction(name = "shoot")
803 public void shoot(final SelectorList targets) throws InterruptedException {
804 log.fine(String.format("called shoot %s", targets));
805
806 addAction(new Shoot() {
807
808 @Override
809 public void execute() {
810 log.info(String.format("executed shoot %s ", targetSelector));
811
812 targetSelector = targets.setContext(UT2004BotBehavior.this);
813 }
814 });
815
816 }
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831 @AsAction(name = "stopShooting")
832 public void stopShooting() throws InterruptedException {
833 shoot(new SelectorList());
834 }
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872 @AsAction(name = "prefer")
873 public void prefer(final WeaponPrefList weaponList) throws InterruptedException {
874 log.fine(String.format("called prefer %s", weaponList));
875
876 addAction(new Prefer() {
877
878 @Override
879 public void execute() {
880 weaponPrefs.clearAllPrefs();
881
882 for (WeaponPref pref : weaponList) {
883 weaponPrefs.addGeneralPref(pref.getWeapon(), pref.isPrimary());
884 }
885
886 log.info(String.format("executed prefer %s", weaponList));
887 }
888 });
889 }
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921 @AsAction(name = "look")
922 public void look(final SelectorList targets) throws InterruptedException {
923 log.fine(String.format("called look %s", targets));
924
925 addAction(new Look() {
926
927 @Override
928 public void execute() {
929 log.info(String.format("executed look %s", targets));
930
931 lookSelector = targets.setContext(UT2004BotBehavior.this);
932 }
933 });
934 }
935
936
937
938
939
940
941
942
943
944
945
946
947 @AsAction(name = "skip")
948 public void skip() {
949
950 }
951
952
953
954
955
956
957
958
959
960
961 @AsAction(name = "cheatAdrenaline")
962 public void cheatAdrenaline() {
963 getAct().act(new AddInventory().setType(ItemType.ADRENALINE_PACK.getName()));
964 }
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984 @AsPercept(name = "self", filter = Type.ON_CHANGE)
985 public Percept self() {
986 return new Percept(info.getId(), info.getName(), Team.valueOf(info.getTeam()));
987 }
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012 @AsPercept(name = "logic", filter = Type.ON_CHANGE)
1013 public Percept logicIteration() {
1014 return new Percept(logicIteration);
1015 }
1016
1017 @AsPercept(name = "actionCount", filter = Type.ON_CHANGE)
1018 public Percept actionCount() {
1019 return new Percept(actionCount);
1020 }
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040 @AsPercept(name = "orientation", filter = Type.ON_CHANGE)
1041 public Percept orientation() {
1042 return new Percept(info.getLocation(), info.getRotation(), info.getVelocity());
1043 }
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065 @AsPercept(name = "status", filter = Type.ON_CHANGE)
1066 public Percept status() {
1067 return new Percept(info.getHealth(), info.getArmor(), info.getAdrenaline(), Combo.parseCombo(info.getSelf().getCombo()));
1068 }
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095 @AsPercept(name = "score", filter = Type.ON_CHANGE)
1096 public Percept score() {
1097 return new Percept(info.getKills(), info.getDeaths(), info.getSuicides());
1098 }
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121 @AsPercept(name = "currentWeapon", filter = Type.ON_CHANGE)
1122 public Percept currentWeapon() {
1123 final Weapon weapon = weaponry.getCurrentWeapon();
1124
1125 if (weapon == null) {
1126 return new Percept(new None(), FireMode.NONE);
1127 }
1128
1129 return new Percept(weapon.getType(), FireMode.valueOf(info.isPrimaryShooting(), info.isSecondaryShooting()));
1130 }
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159 @AsPercept(name = "weapon", multiplePercepts = true, filter = Type.ON_CHANGE_NEG)
1160 public Collection<Percept> weapon() {
1161 Collection<Weapon> weapons = weaponry.getWeapons().values();
1162 Collection<Percept> percepts = new ArrayList<Percept>(weapons.size());
1163
1164 for (Weapon w : weapons) {
1165 if (w.getType() == ItemType.SHIELD_GUN) {
1166
1167
1168
1169 percepts.add(new Percept(w.getType(), 1, w.getSecondaryAmmo()));
1170 } else {
1171 percepts.add(new Percept(w.getType(), w.getPrimaryAmmo(), w.getSecondaryAmmo()));
1172 }
1173 }
1174
1175 return percepts;
1176 }
1177
1178
1179
1180
1181 private List<Percept> fragged = new LinkedList<Percept>();
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191 private void fraggedEvent(final long time, final UnrealId killer, final UnrealId victem, final String weaponName) {
1192 fragged.add(new Percept(time, killer, victem, ItemType.getItemType(weaponName)));
1193 }
1194
1195
1196
1197
1198
1199
1200 @EventListener(eventClass = BotKilled.class)
1201 public void msgBotKilled(BotKilled msg) {
1202 fraggedEvent(msg.getSimTime(), msg.getKiller(), info.getId(), msg.getWeaponName());
1203 }
1204
1205
1206
1207
1208
1209
1210
1211 @EventListener(eventClass = PlayerKilled.class)
1212 public void msgPlayerKilled(PlayerKilled msg) {
1213 fraggedEvent(msg.getSimTime(), msg.getKiller(), msg.getId(), msg.getWeaponName());
1214 }
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237 @AsPercept(name = "fragged", multiplePercepts = true, filter = Type.ALWAYS, event = true)
1238 public List<Percept> fragged() {
1239 ArrayList<Percept> percepts = new ArrayList<Percept>(fragged);
1240 fragged.clear();
1241 return percepts;
1242 }
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269 @AsPercept(name = "navigation", filter = Type.ON_CHANGE)
1270 public Percept navigation() {
1271 ILocated currentTarget = navigation.getCurrentTarget();
1272
1273
1274 if (currentTarget == null) {
1275 return new Percept(navigation.getState().getFlag(), new None());
1276 }
1277
1278
1279 if (currentTarget instanceof IWorldObject) {
1280 IWorldObject targetObject = (IWorldObject) navigation.getCurrentTarget();
1281 return new Percept(navigation.getState().getFlag(), targetObject.getId());
1282 }
1283
1284
1285 return new Percept(navigation.getState().getFlag(), currentTarget.getLocation());
1286 }
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309 @AsPercept(name = "navPoint", multiplePercepts = true, filter = Type.ONCE)
1310 public Collection<Percept> navPoint() {
1311 Collection<NavPoint> navPoints = world.getAll(NavPoint.class).values();
1312 List<Percept> percepts = new ArrayList<Percept>(navPoints.size());
1313
1314 for (NavPoint p : navPoints) {
1315 percepts.add(new Percept(p.getId(), p.getLocation(), p.getOutgoingEdges().keySet()));
1316 }
1317
1318 return percepts;
1319 }
1320
1321
1322
1323
1324
1325
1326 @AsPercept(name = "navPoint", multiplePercepts = true, filter = Type.ON_CHANGE_NEG)
1327 public Collection<Percept> visibleNavPoint() {
1328 Collection<NavPoint> navPoints = world.getAll(NavPoint.class).values();
1329 List<Percept> percepts = new ArrayList<Percept>(navPoints.size());
1330
1331 for (NavPoint p : navPoints) {
1332 if (p.isVisible()) {
1333 percepts.add(new Percept(p.getId(), p.getLocation(), p.getOutgoingEdges().keySet()));
1334 }
1335 }
1336
1337 return percepts;
1338 }
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373 @AsPercept(name = "pickup", multiplePercepts = true, filter = Type.ONCE)
1374 public Collection<Percept> pickup() {
1375 Collection<Item> pickups = items.getKnownPickups().values();
1376 Collection<Percept> percepts = new ArrayList<Percept>(pickups.size());
1377
1378 for (Item item : pickups) {
1379 if (!item.isDropped()) {
1380 percepts.add(new Percept(item.getNavPoint().getId(), item.getType().getCategory(), item.getType()));
1381 }
1382 }
1383 return percepts;
1384 }
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405 @AsPercept(name = "base", multiplePercepts = true, filter = Type.ONCE)
1406 public List<Percept> base() {
1407 List<Percept> base = new ArrayList<Percept>(2);
1408
1409 Collection<NavPoint> navPoints = world.getAll(NavPoint.class).values();
1410
1411 NavPoint nav = DistanceUtils.getNearest(navPoints, game.getFlagBase(0));
1412 assert nav != null;
1413 base.add(new Percept(Team.RED, nav.getId()));
1414
1415 nav = DistanceUtils.getNearest(navPoints, game.getFlagBase(1));
1416 assert nav != null;
1417 base.add(new Percept(Team.BLUE, nav.getId()));
1418
1419 return base;
1420 }
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445 @AsPercept(name = "game", filter = Type.ON_CHANGE)
1446 public Percept game() {
1447 return new Percept(game.getGameType(), game.getMapName(), game.getTeamScoreLimit(), game.getRemainingTime());
1448 }
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477 @AsPercept(name = "teamScore", filter = Type.ON_CHANGE)
1478 public Percept teamScore() {
1479 return new Percept(game.getTeamScore(info.getTeam()), game.getTeamScore(1 - info.getTeam()));
1480 }
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509 @AsPercept(name = "flagState", multiplePercepts = true, filter = Type.ON_CHANGE_NEG)
1510 public List<Percept> flagState() {
1511 List<Percept> percepts = new ArrayList<Percept>(2);
1512
1513 percepts.add(new Percept(Team.RED, FlagState.valueOfIgnoreCase(game.getFlag(Team.RED.id()).getState())));
1514 percepts.add(new Percept(Team.BLUE, FlagState.valueOfIgnoreCase(game.getFlag(Team.BLUE.id()).getState())));
1515
1516 return percepts;
1517 }
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555 @AsPercept(name = "item", multiplePercepts = true, filter = Type.ON_CHANGE_NEG)
1556 public Collection<Percept> item() {
1557 Collection<Item> visibleItems = items.getVisibleItems().values();
1558 Collection<Percept> percepts = new ArrayList<Percept>(visibleItems.size());
1559
1560 for (Item item : visibleItems) {
1561 if (item.isDropped()) {
1562 percepts.add(new Percept(item.getId(), item.getType().getCategory(), item.getType(), item.getLocation()));
1563 } else {
1564 percepts.add(new Percept(item.getId(), item.getType().getCategory(), item.getType(), item.getNavPointId()));
1565 }
1566 }
1567
1568 return percepts;
1569 }
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601 @AsPercept(name = "flag", multiplePercepts = true, filter = Type.ON_CHANGE_NEG)
1602 public Collection<Percept> flag() {
1603 Collection<FlagInfo> flags = game.getAllCTFFlagsCollection();
1604 Collection<Percept> percepts = new ArrayList<Percept>(flags.size());
1605
1606 for (FlagInfo flag : flags) {
1607 if (flag.isVisible())
1608 percepts.add(new Percept(Team.valueOf(flag.getTeam()), flag.getHolder(), flag.getLocation()));
1609 }
1610
1611 return percepts;
1612 }
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638 @AsPercept(name = "bot", multiplePercepts = true, filter = Type.ON_CHANGE_NEG)
1639 public Collection<Percept> bot() {
1640 Collection<Player> visible = players.getVisiblePlayers().values();
1641 Collection<Percept> wrapped = new ArrayList<Percept>(visible.size());
1642
1643 for (Player p : visible) {
1644 wrapped.add(new Percept(p.getId(), p.getName(), Team.valueOf(p.getTeam()), p.getLocation(),
1645 ItemType.getItemType(p.getWeapon()), FireMode.valueOf(p.getFiring())));
1646 }
1647
1648 return wrapped;
1649 }
1650 }