1 package cz.cuni.amis.pogamut.ut2004.agent.module.sensor;
2
3 import java.util.ArrayList;
4 import java.util.HashMap;
5 import java.util.List;
6 import java.util.logging.Level;
7 import java.util.logging.Logger;
8
9 import javax.vecmath.Vector3d;
10
11 import cz.cuni.amis.pogamut.base.agent.module.SensorModule;
12 import cz.cuni.amis.pogamut.base.communication.worldview.IWorldView;
13 import cz.cuni.amis.pogamut.base.communication.worldview.object.IWorldObjectEvent;
14 import cz.cuni.amis.pogamut.base.communication.worldview.object.IWorldObjectEventListener;
15 import cz.cuni.amis.pogamut.base.component.controller.ComponentDependencies;
16 import cz.cuni.amis.pogamut.base3d.worldview.object.Location;
17 import cz.cuni.amis.pogamut.base3d.worldview.object.Rotation;
18 import cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId;
19 import cz.cuni.amis.pogamut.ut2004.agent.navigation.floydwarshall.FloydWarshallMap;
20 import cz.cuni.amis.pogamut.ut2004.bot.IUT2004BotController;
21 import cz.cuni.amis.pogamut.ut2004.bot.IUT2004BotLogicController;
22 import cz.cuni.amis.pogamut.ut2004.bot.impl.UT2004Bot;
23 import cz.cuni.amis.pogamut.ut2004.bot.impl.UT2004BotModuleController;
24 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.GameInfo;
25 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.NavPoint;
26 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.NavPointMessage;
27 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.NavPointNeighbourLink;
28 import cz.cuni.amis.pogamut.ut2004.utils.LinkFlag;
29 import cz.cuni.amis.pogamut.ut2004.utils.UnrealUtils;
30 import cz.cuni.amis.utils.NullCheck;
31 import cz.cuni.amis.utils.exception.PogamutException;
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55 public class NavigationGraphBuilder extends SensorModule<UT2004Bot> {
56
57
58
59
60
61
62
63
64 public class NewNavPointBuilder {
65
66 private String id;
67 private Location location;
68 private List<NewNavPointEdgeBuilder> edges = new ArrayList<NewNavPointEdgeBuilder>();
69
70 protected NewNavPointBuilder() {
71 }
72
73
74
75
76
77
78 public NewNavPointBuilder setId(String id) {
79 NullCheck.check(id, "id");
80 this.id = autoPrefix(id);
81 return this;
82 }
83
84
85
86
87
88
89
90
91
92 public NewNavPointBuilder setLocation(double x, double y, double z) {
93 this.location = new Location(x,y,z);
94 return this;
95 }
96
97
98
99
100
101
102
103
104
105 public void createNavPoint() {
106 if (id == null) throw new PogamutException("Could not create navpoint, id is null, you must set it using setId() before calling this method.", this);
107 if (location == null) throw new PogamutException("Could not create navpoint (" + id + "), location is null, you must set it using setLocation() before calling this method.", this);
108 NavPoint newNavPoint =
109 new NavPointMessage(UnrealId.get(id), location, null, false, null, null, false, false, null, null, false, false, false, false, 255, false, 255, false, false, false, false, false, false, false, false, new Rotation(0,0,0), false, false, null, new HashMap<UnrealId, NavPointNeighbourLink>(), new HashMap<UnrealId, NavPointNeighbourLink>(), null);
110
111 for (NewNavPointEdgeBuilder edge : edges) {
112 Object np = agent.getWorldView().get(edge.toNavPointId);
113 if (np == null) {
114 throw new PogamutException("Could not create navpoint (" + id + ") as the remote end (" + edge.toNavPointId + ") of one of its edges could not be found in the bot's worldview. Warning, id is case-sensitive the upper/lower cases of the id depends on the concrete spelling of the map that was passed to the GB2004 during startup (either from the command line or by the UT2004).", this);
115 }
116 if (!(np instanceof NavPoint)) {
117 throw new PogamutException("Could not create navpoint (" + id + ") as the remote end (" + edge.toNavPointId + ") of one of its edges is not an instance of NavPoint, but " + np.getClass().getSimpleName() + ". Wrong id used?", this);
118 }
119 NavPoint toNavPoint = (NavPoint)np;
120 NavPointNeighbourLink link = new NavPointNeighbourLink(UnrealId.get(id), edge.flags, edge.collisionR, edge.collisionH, 0, null, false, edge.forceDoubleJump, edge.neededJump, false, false, 0, newNavPoint, toNavPoint);
121 newNavPoint.getOutgoingEdges().put(link.getToNavPoint().getId(), link);
122 link.getToNavPoint().getIncomingEdges().put(newNavPoint.getId(), link);
123 }
124
125 agent.getWorldView().notifyImmediately(newNavPoint);
126 }
127
128
129
130
131
132
133
134
135 public NewNavPointEdgeBuilder<NewNavPointBuilder> newEdge() {
136 return new NewNavPointEdgeBuilder<NewNavPointBuilder>(this);
137 }
138
139
140
141
142
143
144
145
146
147 public NewNavPointEdgeBuilder<NewNavPointBuilder> newEdgeTo(String navPointId) {
148 NullCheck.check(navPointId, "navPointId");
149 NewNavPointEdgeBuilder<NewNavPointBuilder> edgeBuilder = new NewNavPointEdgeBuilder<NewNavPointBuilder>(this);
150 edgeBuilder.setTo(navPointId);
151 return edgeBuilder;
152 }
153
154
155
156
157
158 public void createSimpleEdgeTo(String navPointId) {
159 NullCheck.check(navPointId, "navPointId");
160 newEdgeTo(navPointId).createEdge();
161 }
162
163
164
165
166
167
168 protected void addEdge(NewNavPointEdgeBuilder newNavPointEdgeBuilder) {
169 this.edges.add(newNavPointEdgeBuilder);
170 }
171
172 }
173
174
175
176
177
178
179
180
181 public class NewNavPointEdgeBuilder<OWNER> {
182
183 protected OWNER owner;
184 protected UnrealId toNavPointId;
185 protected int collisionR = (int)UnrealUtils.CHARACTER_COLLISION_RADIUS * 2;
186 protected int collisionH = (int)UnrealUtils.CHARACTER_HEIGHT_STANDING + 10;
187 protected boolean forceDoubleJump = false;
188 protected Vector3d neededJump;
189 protected int flags = 0;
190
191 protected NewNavPointEdgeBuilder(OWNER owner) {
192 this.owner = owner;
193 NullCheck.check(this.owner, "owner");
194 }
195
196
197
198
199
200
201
202 public NewNavPointEdgeBuilder<OWNER> setTo(String navPointId) {
203 NullCheck.check(navPointId, "navPointId");
204 this.toNavPointId = UnrealId.get(autoPrefix(navPointId));
205 return this;
206 }
207
208
209
210
211
212
213
214 public NewNavPointEdgeBuilder<OWNER> setTo(UnrealId navPointId) {
215 this.toNavPointId = navPointId;
216 return this;
217 }
218
219
220
221
222
223
224
225 public NewNavPointEdgeBuilder<OWNER> setCollisionRadius(int collisionRadius) {
226 this.collisionR = collisionRadius;
227 return this;
228 }
229
230
231
232
233
234
235
236 public NewNavPointEdgeBuilder<OWNER> setCollisionHeight(int collisionHeight) {
237 this.collisionH = collisionHeight;
238 return this;
239 }
240
241
242
243
244
245
246
247
248
249 public NewNavPointEdgeBuilder<OWNER> setNeededJump(double x, double y, double z) {
250 this.neededJump = new Vector3d(x,y,z);
251 return this;
252 }
253
254
255
256
257
258
259
260 public NewNavPointEdgeBuilder<OWNER> setDoubleJump() {
261 this.forceDoubleJump = true;
262 return this;
263 }
264
265
266
267
268
269
270
271
272 public NewNavPointEdgeBuilder<OWNER> setWalkFlag() {
273 flags |= LinkFlag.WALK.get();
274 return this;
275 }
276
277
278
279
280
281
282
283 public NewNavPointEdgeBuilder<OWNER> setFlyFlag() {
284 flags |= LinkFlag.FLY.get();
285 return this;
286 }
287
288
289
290
291
292
293
294 public NewNavPointEdgeBuilder<OWNER> setSwimFlag() {
295 flags |= LinkFlag.SWIM.get();
296 return this;
297 }
298
299
300
301
302
303
304
305 public NewNavPointEdgeBuilder<OWNER> setJumpFlag() {
306 flags |= LinkFlag.JUMP.get();
307 return this;
308 }
309
310
311
312
313
314
315
316 public NewNavPointEdgeBuilder<OWNER> setDoorFlag() {
317 flags |= LinkFlag.DOOR.get();
318 return this;
319 }
320
321
322
323
324
325
326
327 public NewNavPointEdgeBuilder<OWNER> setSpecialFlag() {
328 flags |= LinkFlag.SPECIAL.get();
329 return this;
330 }
331
332
333
334
335
336
337
338 public NewNavPointEdgeBuilder<OWNER> setLadderFlag() {
339 flags |= LinkFlag.LADDER.get();
340 return this;
341 }
342
343
344
345
346
347
348
349 public NewNavPointEdgeBuilder<OWNER> setProscribedFlag() {
350 flags |= LinkFlag.PROSCRIBED.get();
351 return this;
352 }
353
354
355
356
357
358
359
360 public NewNavPointEdgeBuilder<OWNER> setForcedFlag() {
361 flags |= LinkFlag.FORCED.get();
362 return this;
363 }
364
365
366
367
368
369
370
371 public NewNavPointEdgeBuilder<OWNER> setPlayerOnlyFlag() {
372 flags |= LinkFlag.PLAYERONLY.get();
373 return this;
374 }
375
376
377
378
379
380
381
382
383
384
385 public OWNER createEdge() {
386 if (toNavPointId == null) {
387 throw new PogamutException("Could not create edge - toNavPoint not specified, you must call setTo() with non-null argument (to specify the other end of the edge) before calling this method.", this);
388 }
389 ((NewNavPointBuilder)owner).addEdge(this);
390 return ((OWNER)owner);
391 }
392
393 }
394
395
396
397
398
399
400
401 public class ExistingNavPointModifier {
402
403 private NavPoint navPoint;
404
405 protected ExistingNavPointModifier(NavPoint navPoint) {
406 this.navPoint = navPoint;
407 NullCheck.check(this.navPoint, "navPoint");
408 }
409
410
411
412
413
414
415
416
417 public void removeEdgeTo(String navPointId) {
418 NullCheck.check(navPointId, "navPointId");
419 navPointId = autoPrefix(navPointId);
420 UnrealId navPointUnrealId = UnrealId.get(navPointId);
421 navPoint.getOutgoingEdges().remove(navPointUnrealId);
422 Object np = agent.getWorldView().get(navPointUnrealId);
423 if (np != null && (np instanceof NavPoint)) {
424 ((NavPoint)np).getIncomingEdges().remove(navPoint.getId());
425 }
426 }
427
428
429
430
431
432
433
434
435 public void removeEdgesBetween(String navPointId) {
436 NullCheck.check(navPointId, "navPointId");
437 navPointId = autoPrefix(navPointId);
438 UnrealId toNavPointUnrealId = UnrealId.get(navPointId);
439
440 Object np = agent.getWorldView().get(toNavPointUnrealId);
441 NavPoint toNavPoint = null;
442 if (np != null && (np instanceof NavPoint)) {
443 toNavPoint = (NavPoint)np;
444 }
445
446 navPoint.getOutgoingEdges().remove(toNavPointUnrealId);
447 navPoint.getIncomingEdges().remove(toNavPointUnrealId);
448
449 if (toNavPoint != null) {
450 toNavPoint.getOutgoingEdges().remove(navPoint.getId());
451 toNavPoint.getIncomingEdges().remove(navPoint.getId());
452 }
453 }
454
455
456
457
458
459
460
461
462
463
464
465 public ExistingNavPointEdgeBuilder modifyEdgeTo(String navPointId) {
466 NullCheck.check(navPointId, "navPointId");
467 navPointId = autoPrefix(navPointId);
468 UnrealId navPointUnrealId = UnrealId.get(navPointId);
469 NavPointNeighbourLink link = navPoint.getOutgoingEdges().get(navPointUnrealId);
470 if (link != null) {
471 return new ExistingNavPointEdgeBuilder(this, link);
472 } else {
473 return new ExistingNavPointEdgeBuilder(this).setTo(navPointId);
474 }
475 }
476
477
478
479
480
481
482
483
484
485
486
487
488
489 public ExistingNavPointEdgeBuilder createEdgeTo(String navPointId) {
490 NullCheck.check(navPointId, "navPointId");
491 navPointId = autoPrefix(navPointId);
492 ExistingNavPointEdgeBuilder builder = new ExistingNavPointEdgeBuilder(this, null);
493 builder.setTo(navPointId);
494 return builder;
495 }
496
497
498
499
500
501
502
503
504
505
506
507
508
509 public ExistingNavPointEdgeBuilder createEdge() {
510 return new ExistingNavPointEdgeBuilder(this, null);
511 }
512
513
514
515
516
517
518
519
520 public void createSimpleEdgeTo(String navPointId) {
521 NullCheck.check(navPointId, "navPointId");
522 createEdgeTo(navPointId).createEdge();
523 }
524
525
526
527
528
529
530
531
532 public void createSimpleEdgesBetween(String navPointId) {
533 NullCheck.check(navPointId, "navPointId");
534 createEdgeTo(navPointId).createEdge();
535 modifyNavPoint(navPointId).createSimpleEdgeTo(navPoint.getId().getStringId());
536 }
537
538 }
539
540 public class ExistingNavPointEdgeBuilder extends NewNavPointEdgeBuilder<ExistingNavPointModifier> {
541
542 private NavPointNeighbourLink parentLink;
543
544 protected ExistingNavPointEdgeBuilder(ExistingNavPointModifier navPointModifier) {
545 super(navPointModifier);
546 }
547
548 protected ExistingNavPointEdgeBuilder(ExistingNavPointModifier navPointModifier, NavPointNeighbourLink parent) {
549 super(navPointModifier);
550 this.parentLink = parent;
551 if (this.parentLink != null) {
552 this.collisionH = this.parentLink.getCollisionH();
553 this.collisionR = this.parentLink.getCollisionR();
554 this.flags = this.parentLink.getFlags();
555 this.forceDoubleJump = this.parentLink.isForceDoubleJump();
556 this.neededJump = this.parentLink.getNeededJump();
557 this.toNavPointId = this.parentLink.getToNavPoint().getId();
558 }
559 }
560
561 @Override
562 public ExistingNavPointEdgeBuilder setTo(String navPointId) {
563 super.setTo(navPointId);
564 return this;
565 }
566
567 @Override
568 public ExistingNavPointEdgeBuilder setTo(UnrealId navPointId) {
569 super.setTo(navPointId);
570 return this;
571 }
572
573 @Override
574 public ExistingNavPointEdgeBuilder setCollisionRadius(int collisionRadius) {
575 super.setCollisionRadius(collisionRadius);
576 return this;
577 }
578
579 @Override
580 public ExistingNavPointEdgeBuilder setCollisionHeight(int collisionHeight) {
581 super.setCollisionHeight(collisionHeight);
582 return this;
583 }
584
585 @Override
586 public ExistingNavPointEdgeBuilder setNeededJump(double x, double y, double z) {
587 super.setNeededJump(x, y, z);
588 return this;
589 }
590
591
592
593
594
595 public ExistingNavPointEdgeBuilder removeNeededJump() {
596 this.neededJump = null;
597 return this;
598 }
599
600 @Override
601 public ExistingNavPointEdgeBuilder setDoubleJump() {
602 super.setDoubleJump();
603 return this;
604 }
605
606
607
608
609
610 public ExistingNavPointEdgeBuilder removeDoubleJump() {
611 this.forceDoubleJump = false;
612 return this;
613 }
614
615
616 @Override
617 public ExistingNavPointEdgeBuilder setWalkFlag() {
618 super.setWalkFlag();
619 return this;
620 }
621
622
623
624
625
626
627 public ExistingNavPointEdgeBuilder removeWalkFlag() {
628 this.flags = (this.flags | LinkFlag.WALK.get()) ^ LinkFlag.WALK.get();
629 return this;
630 }
631
632 @Override
633 public ExistingNavPointEdgeBuilder setFlyFlag() {
634 super.setFlyFlag();
635 return this;
636 }
637
638
639
640
641
642
643 public ExistingNavPointEdgeBuilder removeFlyFlag() {
644 this.flags = (this.flags | LinkFlag.FLY.get()) ^ LinkFlag.FLY.get();
645 return this;
646 }
647
648 @Override
649 public ExistingNavPointEdgeBuilder setSwimFlag() {
650 super.setSwimFlag();
651 return this;
652 }
653
654
655
656
657
658
659 public ExistingNavPointEdgeBuilder removeSwimFlag() {
660 this.flags = (this.flags | LinkFlag.SWIM.get()) ^ LinkFlag.SWIM.get();
661 return this;
662 }
663
664 @Override
665 public ExistingNavPointEdgeBuilder setJumpFlag() {
666 super.setJumpFlag();
667 return this;
668 }
669
670
671
672
673
674
675 public ExistingNavPointEdgeBuilder removeJumpFlag() {
676 this.flags = (this.flags | LinkFlag.JUMP.get()) ^ LinkFlag.JUMP.get();
677 return this;
678 }
679
680 @Override
681 public ExistingNavPointEdgeBuilder setDoorFlag() {
682 super.setDoorFlag();
683 return this;
684 }
685
686
687
688
689
690
691 public ExistingNavPointEdgeBuilder removeDoorFlag() {
692 this.flags = (this.flags | LinkFlag.DOOR.get()) ^ LinkFlag.DOOR.get();
693 return this;
694 }
695
696 @Override
697 public ExistingNavPointEdgeBuilder setSpecialFlag() {
698 super.setSpecialFlag();
699 return this;
700 }
701
702
703
704
705
706
707 public ExistingNavPointEdgeBuilder removeSpecialFlag() {
708 this.flags = (this.flags | LinkFlag.SPECIAL.get()) ^ LinkFlag.SPECIAL.get();
709 return this;
710 }
711
712 @Override
713 public ExistingNavPointEdgeBuilder setLadderFlag() {
714 super.setLadderFlag();
715 return this;
716 }
717
718
719
720
721
722
723 public ExistingNavPointEdgeBuilder removeLadderFlag() {
724 this.flags = (this.flags | LinkFlag.LADDER.get()) ^ LinkFlag.LADDER.get();
725 return this;
726 }
727
728 @Override
729 public ExistingNavPointEdgeBuilder setProscribedFlag() {
730 super.setProscribedFlag();
731 return this;
732 }
733
734
735
736
737
738
739 public ExistingNavPointEdgeBuilder removeProscribedFlag() {
740 this.flags = (this.flags | LinkFlag.PROSCRIBED.get()) ^ LinkFlag.PROSCRIBED.get();
741 return this;
742 }
743
744 @Override
745 public ExistingNavPointEdgeBuilder setForcedFlag() {
746 super.setForcedFlag();
747 return this;
748 }
749
750
751
752
753
754
755 public ExistingNavPointEdgeBuilder removeForcedFlag() {
756 this.flags = (this.flags | LinkFlag.FORCED.get()) ^ LinkFlag.FORCED.get();
757 return this;
758 }
759
760 @Override
761 public ExistingNavPointEdgeBuilder setPlayerOnlyFlag() {
762 super.setPlayerOnlyFlag();
763 return this;
764 }
765
766
767
768
769
770
771 public ExistingNavPointEdgeBuilder removePlayerOnlyFlag() {
772 this.flags = (this.flags | LinkFlag.PLAYERONLY.get()) ^ LinkFlag.PLAYERONLY.get();
773 return this;
774 }
775
776
777
778
779
780
781 public ExistingNavPointEdgeBuilder clearFlags() {
782 this.flags = 0;
783 return this;
784 }
785
786
787
788
789
790
791
792
793 @Override
794 public ExistingNavPointModifier createEdge() {
795 if (toNavPointId == null) {
796 throw new PogamutException("Could not create/modify edge from navpoint '" + owner.navPoint.getId().getStringId() + "' as toNavPoint not specified, you must call setTo() with non-null argument (to specify the other end of the edge) before calling this method.", this);
797 }
798 Object np = agent.getWorldView().get(toNavPointId);
799 if (np == null) {
800 throw new PogamutException("Could not create/modify navpoint edge from '" + owner.navPoint.getId().getStringId() + "' as the remote end (" + toNavPointId.getStringId() + ") could not be found in the bot's worldview. Warning, id is case-sensitive the upper/lower cases of the id depends on the concrete spelling of the map that was passed to the GB2004 during startup (either from the command line or by the UT2004).", this);
801 }
802 if (!(np instanceof NavPoint)) {
803 throw new PogamutException("Could not create/modify navpoint edge from '" + owner.navPoint.getId().getStringId() + "' as the remote end '" + toNavPointId.getStringId() + "' is not an instance of NavPoint but " + np.getClass().getSimpleName() + ". Wrong id specified?", this);
804 }
805
806 NavPoint toNavPoint = (NavPoint)np;
807
808 NavPointNeighbourLink link = null;
809
810 if (parentLink == null) {
811 link = new NavPointNeighbourLink(owner.navPoint.getId(), flags, collisionR, collisionH, 0, null, false, forceDoubleJump, neededJump, false, false, 0, owner.navPoint, toNavPoint);
812 } else {
813 link = new NavPointNeighbourLink(owner.navPoint.getId(), flags, collisionR, collisionH, parentLink.getTranslocZOffset(), parentLink.getTranslocTargetTag(), parentLink.isOnlyTranslocator(), forceDoubleJump, neededJump, parentLink.isNeverImpactJump(), parentLink.isNoLowGrav(), parentLink.getCalculatedGravityZ(), owner.navPoint, toNavPoint);
814 }
815
816 owner.navPoint.getOutgoingEdges().put(link.getToNavPoint().getId(), link);
817 link.getToNavPoint().getIncomingEdges().put(owner.navPoint.getId(), link);
818
819 return owner;
820 }
821
822
823
824
825
826
827
828
829 public ExistingNavPointModifier modifyEdge() {
830 return createEdge();
831 }
832
833 }
834
835
836
837
838 private class GameInfoListener implements IWorldObjectEventListener<GameInfo, IWorldObjectEvent<GameInfo>>
839 {
840 @Override
841 public void notify(IWorldObjectEvent<GameInfo> event)
842 {
843 lastGameInfo = event.getObject();
844 if (lastGameInfo.getLevel() == null) {
845 throw new PogamutException("GameInfo.getLevel() is null!!!", this);
846 }
847 mapNameLowerChar = lastGameInfo.getLevel().toLowerCase();
848 }
849
850
851
852
853
854 public GameInfoListener(IWorldView worldView)
855 {
856 worldView.addObjectListener(GameInfo.class, this);
857 }
858 }
859
860
861 GameInfoListener gameInfoListener;
862
863
864 GameInfo lastGameInfo = null;
865
866 String mapNameLowerChar = null;
867
868 public NavigationGraphBuilder(UT2004Bot bot) {
869 this(bot, null);
870 }
871
872 public NavigationGraphBuilder(UT2004Bot bot, Logger log) {
873 this(bot, log, null);
874 }
875
876 public NavigationGraphBuilder(UT2004Bot bot, Logger log, ComponentDependencies dependencies) {
877 super(bot, log, dependencies);
878 gameInfoListener = new GameInfoListener(bot.getWorldView());
879 }
880
881 @Override
882 protected void cleanUp() {
883 super.cleanUp();
884 lastGameInfo = null;
885 mapNameLowerChar = null;
886 }
887
888
889
890
891
892
893
894
895
896
897
898
899 public String getMapName() {
900 if (lastGameInfo == null) return null;
901 return lastGameInfo.getLevel();
902 }
903
904
905
906
907
908
909 public boolean isMapName(String name) {
910 if (lastGameInfo == null) return false;
911 if (name == null) return false;
912 return lastGameInfo.getLevel().toLowerCase().equals(name.toLowerCase());
913 }
914
915 private boolean autoPrefix = true;
916
917
918
919
920 private boolean used;
921
922
923
924
925
926
927
928
929
930
931
932
933 public boolean isAutoPrefix() {
934 return autoPrefix;
935 }
936
937
938
939
940
941
942
943
944
945
946
947
948 public void setAutoPrefix(boolean autoPrefix) {
949 this.autoPrefix = autoPrefix;
950 }
951
952
953
954
955
956
957
958
959
960
961
962 public String getPrefixed(String navPointId) {
963
964 if (getMapName() == null) {
965 throw new PogamutException("GameInfo was not received yet, can't auto-prefix name of the navpoint '" + navPointId + "'.", this);
966 }
967 if (navPointId.toLowerCase().startsWith(mapNameLowerChar + ".")) {
968
969 if (!navPointId.startsWith(getMapName())) {
970
971 navPointId = getMapName() + navPointId.substring(mapNameLowerChar.length());
972 }
973
974 return navPointId;
975 } else {
976
977 if (navPointId.contains(".")) {
978
979 throw new PogamutException("navPointId '" + navPointId + "' is already prefixed with '" + navPointId.substring(0, navPointId.indexOf(".")) + "' which is different from current map name '" + getMapName() + "', map name validation fails!", this);
980 }
981
982 return getMapName() + "." + navPointId;
983 }
984 }
985
986
987
988
989
990
991
992
993
994
995 public String autoPrefix(String navPointId) {
996 NullCheck.check(navPointId, "navPointId");
997 if (autoPrefix) {
998 return getPrefixed(navPointId);
999 } else {
1000
1001 return navPointId;
1002 }
1003 }
1004
1005
1006
1007
1008
1009
1010
1011
1012 public NewNavPointBuilder newNavPoint() {
1013 used = true;
1014 return new NewNavPointBuilder();
1015 }
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026 public NewNavPointBuilder newNavPoint(String navPointId) {
1027 used = true;
1028 NullCheck.check(navPointId, "navPointId");
1029 return new NewNavPointBuilder().setId(navPointId);
1030 }
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040 public ExistingNavPointModifier modifyNavPoint(String navPointId) {
1041 used = true;
1042 NullCheck.check(navPointId, "navPointId");
1043 navPointId = autoPrefix(navPointId);
1044
1045 Object np = agent.getWorldView().get(UnrealId.get(navPointId));
1046 if (np == null) {
1047 throw new PogamutException("Could not modify navpoint '" + navPointId + "' as it was not found in the worldview. No object under this id exists in worldview. Warning, id is case-sensitive the upper/lower cases of the id depends on the concrete spelling of the map that was passed to the GB2004 during startup (either from the command line or by the UT2004).", this);
1048 }
1049 if (!(np instanceof NavPoint)) {
1050 throw new PogamutException("Could not modify navpoint '" + navPointId + "' it does not point to an NavPoint instance but " + np.getClass().getSimpleName() + ". Wrong id specified?", this);
1051 }
1052 return new ExistingNavPointModifier((NavPoint)np);
1053 }
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063 public void createSimpleEdge(String fromNavPointId, String toNavPointId) {
1064 used = true;
1065 NullCheck.check(fromNavPointId, "fromNavPointId");
1066 NullCheck.check(toNavPointId, "toNavPointId");
1067 fromNavPointId = autoPrefix(fromNavPointId);
1068 toNavPointId = autoPrefix(toNavPointId);
1069 modifyNavPoint(fromNavPointId).modifyEdgeTo(toNavPointId).createEdge();
1070 }
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080 public void createSimpleEdgesBetween(String firstNavPointId, String secondNavPointId) {
1081 used = true;
1082 NullCheck.check(firstNavPointId, "firstNavPointId");
1083 NullCheck.check(secondNavPointId, "secondNavPointId");
1084 firstNavPointId = autoPrefix(firstNavPointId);
1085 secondNavPointId = autoPrefix(secondNavPointId);
1086 modifyNavPoint(firstNavPointId).modifyEdgeTo(secondNavPointId).createEdge();
1087 modifyNavPoint(secondNavPointId).modifyEdgeTo(firstNavPointId).createEdge();
1088 }
1089
1090
1091
1092
1093
1094
1095 public void removeEdge(String fromNavPointId, String toNavPointId) {
1096 used = true;
1097 NullCheck.check(fromNavPointId, "fromNavPointId");
1098 NullCheck.check(toNavPointId, "toNavPointId");
1099 fromNavPointId = autoPrefix(fromNavPointId);
1100 toNavPointId = autoPrefix(toNavPointId);
1101 modifyNavPoint(fromNavPointId).removeEdgeTo(toNavPointId);
1102 }
1103
1104
1105
1106
1107
1108
1109 public void removeEdgesBetween(String firstNavPointId, String secondNavPointId) {
1110 used = true;
1111 NullCheck.check(firstNavPointId, "firstNavPointId");
1112 NullCheck.check(secondNavPointId, "secondNavPointId");
1113 firstNavPointId = autoPrefix(firstNavPointId);
1114 secondNavPointId = autoPrefix(secondNavPointId);
1115 modifyNavPoint(firstNavPointId).removeEdgeTo(secondNavPointId);
1116 modifyNavPoint(secondNavPointId).removeEdgeTo(firstNavPointId);
1117 }
1118
1119
1120
1121
1122
1123
1124 public boolean isUsed() {
1125 return used;
1126 }
1127
1128
1129
1130
1131
1132 public void setUsed(boolean used) {
1133 this.used = used;
1134 }
1135
1136
1137
1138 }
1139