1 package cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages;
2
3
4 import java.util.*;import javax.vecmath.*;import cz.cuni.amis.pogamut.base.communication.messages.*;import cz.cuni.amis.pogamut.base.communication.worldview.*;import cz.cuni.amis.pogamut.base.communication.worldview.event.*;import cz.cuni.amis.pogamut.base.communication.worldview.object.*;import cz.cuni.amis.pogamut.multi.communication.worldview.object.*;import cz.cuni.amis.pogamut.base.communication.translator.event.*;import cz.cuni.amis.pogamut.multi.communication.translator.event.*;import cz.cuni.amis.pogamut.base3d.worldview.object.*;import cz.cuni.amis.pogamut.base3d.worldview.object.event.*;import cz.cuni.amis.pogamut.ut2004.communication.messages.*;import cz.cuni.amis.pogamut.ut2004.communication.worldview.objects.*;import cz.cuni.amis.pogamut.ut2004multi.communication.worldview.objects.*;import cz.cuni.amis.pogamut.ut2004.communication.translator.itemdescriptor.*;import cz.cuni.amis.pogamut.ut2004.communication.messages.ItemType.Category;import cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId;import cz.cuni.amis.utils.exception.*;import cz.cuni.amis.pogamut.base.communication.translator.event.IWorldObjectUpdateResult.Result;import cz.cuni.amis.utils.SafeEquals;import cz.cuni.amis.pogamut.base.agent.*;import cz.cuni.amis.pogamut.multi.agent.*;import cz.cuni.amis.pogamut.multi.communication.worldview.property.*;import cz.cuni.amis.pogamut.ut2004multi.communication.worldview.property.*;import cz.cuni.amis.utils.token.*;import cz.cuni.amis.utils.*;
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 public class IncomingProjectileMessage
28 extends
29 IncomingProjectile
30 implements IWorldObjectUpdatedEvent, ICompositeWorldObjectUpdatedEvent
31
32 {
33
34
35
36
37
38
39 public IncomingProjectileMessage()
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 public IncomingProjectileMessage(
120 UnrealId Id, double ImpactTime, Vector3d Direction, Location Location, Velocity Velocity, double Speed, Location Origin, double DamageRadius, String Type, boolean Visible
121 ) {
122
123 this.Id = Id;
124
125 this.ImpactTime = ImpactTime;
126
127 this.Direction = Direction;
128
129 this.Location = Location;
130
131 this.Velocity = Velocity;
132
133 this.Speed = Speed;
134
135 this.Origin = Origin;
136
137 this.DamageRadius = DamageRadius;
138
139 this.Type = Type;
140
141 this.Visible = Visible;
142
143 }
144
145
146
147
148
149
150 public IncomingProjectileMessage(IncomingProjectileMessage original) {
151
152 this.Id = original.getId()
153 ;
154
155 this.ImpactTime = original.getImpactTime()
156 ;
157
158 this.Direction = original.getDirection()
159 ;
160
161 this.Location = original.getLocation()
162 ;
163
164 this.Velocity = original.getVelocity()
165 ;
166
167 this.Speed = original.getSpeed()
168 ;
169
170 this.Origin = original.getOrigin()
171 ;
172
173 this.DamageRadius = original.getDamageRadius()
174 ;
175
176 this.Type = original.getType()
177 ;
178
179 this.Visible = original.isVisible()
180 ;
181
182 this.TeamId = original.getTeamId();
183
184 this.SimTime = original.getSimTime();
185 }
186
187
188 protected ITeamId TeamId;
189
190
191
192
193 protected void setTeamId(ITeamId TeamId) {
194 this.TeamId = TeamId;
195 }
196
197 public ITeamId getTeamId() {
198 return TeamId;
199 }
200
201
202
203
204
205
206
207 protected
208 UnrealId Id =
209 null;
210
211
212
213
214
215 protected boolean Id_Set = false;
216
217 @Override
218
219
220
221
222 public UnrealId getId()
223 {
224 return Id;
225 }
226
227
228
229
230
231 protected
232 double ImpactTime =
233 0;
234
235
236
237
238
239 protected boolean ImpactTime_Set = false;
240
241 @Override
242
243
244
245
246 public double getImpactTime()
247 {
248 return ImpactTime;
249 }
250
251
252
253
254
255
256
257
258 protected
259 Vector3d Direction =
260 null;
261
262
263
264
265
266 protected boolean Direction_Set = false;
267
268 @Override
269
270
271
272
273
274
275
276 public Vector3d getDirection()
277 {
278 return Direction;
279 }
280
281
282
283
284
285
286
287 protected
288 Location Location =
289 null;
290
291
292
293
294
295 protected boolean Location_Set = false;
296
297 @Override
298
299
300
301
302
303
304 public Location getLocation()
305 {
306 return Location;
307 }
308
309
310
311
312
313
314
315 protected
316 Velocity Velocity =
317 null;
318
319
320
321
322
323 protected boolean Velocity_Set = false;
324
325 @Override
326
327
328
329
330
331
332 public Velocity getVelocity()
333 {
334 return Velocity;
335 }
336
337
338
339
340
341
342
343 protected
344 double Speed =
345 0;
346
347
348
349
350
351 protected boolean Speed_Set = false;
352
353 @Override
354
355
356
357
358
359
360 public double getSpeed()
361 {
362 return Speed;
363 }
364
365
366
367
368
369
370
371
372 protected
373 Location Origin =
374 null;
375
376
377
378
379
380 protected boolean Origin_Set = false;
381
382 @Override
383
384
385
386
387
388
389
390 public Location getOrigin()
391 {
392 return Origin;
393 }
394
395
396
397
398
399
400
401
402 protected
403 double DamageRadius =
404 0;
405
406
407
408
409
410 protected boolean DamageRadius_Set = false;
411
412 @Override
413
414
415
416
417
418
419
420 public double getDamageRadius()
421 {
422 return DamageRadius;
423 }
424
425
426
427
428
429
430
431
432 protected
433 String Type =
434 null;
435
436
437
438
439
440 protected boolean Type_Set = false;
441
442 @Override
443
444
445
446
447
448
449
450 public String getType()
451 {
452 return Type;
453 }
454
455
456
457
458
459
460
461
462 protected
463 boolean Visible =
464 true;
465
466
467
468
469
470 protected boolean Visible_Set = false;
471
472 @Override
473
474
475
476
477
478
479
480 public boolean isVisible()
481 {
482 return Visible;
483 }
484
485
486 private IncomingProjectileLocal localPart = null;
487
488 @Override
489 public IncomingProjectileLocal
490 getLocal() {
491 if (localPart != null) return localPart;
492 return localPart = new
493 IncomingProjectileLocalMessage();
494 }
495
496 private IncomingProjectileShared sharedPart = null;
497
498 @Override
499 public IncomingProjectileShared
500 getShared() {
501 if (sharedPart != null) return sharedPart;
502 return sharedPart = new
503 IncomingProjectileSharedMessage();
504 }
505
506 private IncomingProjectileStatic staticPart = null;
507
508 @Override
509 public IncomingProjectileStatic
510 getStatic() {
511 if (staticPart != null) return staticPart;
512 return staticPart = new
513 IncomingProjectileStaticMessage();
514 }
515
516
517
518
519
520
521
522
523
524
525
526
527
528 public class IncomingProjectileLocalMessage
529 extends
530 IncomingProjectileLocal
531 {
532
533 @Override
534 public
535 IncomingProjectileLocalMessage clone() {
536 return this;
537 }
538
539 public IncomingProjectileLocalMessage getLocal() {
540 return this;
541 }
542 public ISharedWorldObject getShared() {
543 throw new UnsupportedOperationException("Could not return LOCAL as SHARED");
544 }
545 public IStaticWorldObject getStatic() {
546 throw new UnsupportedOperationException("Could not return LOCAL as STATIC");
547 }
548
549
550
551
552 public UnrealId getId()
553 {
554 return Id;
555 }
556
557
558
559
560 public double getImpactTime()
561 {
562 return ImpactTime;
563 }
564
565
566
567
568
569
570
571 public boolean isVisible()
572 {
573 return Visible;
574 }
575
576
577 public String toString() {
578 return
579 super.toString() + "[" +
580
581 "Id = " + String.valueOf(getId()
582 ) + " | " +
583
584 "ImpactTime = " + String.valueOf(getImpactTime()
585 ) + " | " +
586
587 "Visible = " + String.valueOf(isVisible()
588 ) + " | " +
589
590 "]";
591 }
592
593
594 public String toHtmlString() {
595 return super.toString() + "[<br/>" +
596
597 "<b>Id</b> = " + String.valueOf(getId()
598 ) + " <br/> " +
599
600 "<b>ImpactTime</b> = " + String.valueOf(getImpactTime()
601 ) + " <br/> " +
602
603 "<b>Visible</b> = " + String.valueOf(isVisible()
604 ) + " <br/> " +
605
606 "<br/>]";
607 }
608
609
610
611
612
613
614
615
616
617
618 }
619
620
621
622
623
624
625
626
627
628
629
630
631
632 public class IncomingProjectileStaticMessage
633 extends
634 IncomingProjectileStatic
635 {
636
637 @Override
638 public
639 IncomingProjectileStaticMessage clone() {
640 return this;
641 }
642
643
644
645
646 public UnrealId getId()
647 {
648 return Id;
649 }
650
651
652 @Override
653 public boolean isDifferentFrom(IStaticWorldObject other)
654 {
655 if (other == null)
656 {
657 return true;
658 }
659 else if (other == this)
660 {
661 return false;
662 }
663 else
664 {
665 IncomingProjectileStatic obj = (IncomingProjectileStatic) other;
666
667
668 if ( !(
669 AdvancedEquals.equalsOrNull(this.getId()
670 , obj.getId()
671 )
672 ) )
673 {
674 System.out.println("!!!!!PROPERTY UPDATE ERROR!!!! on property Id on object class IncomingProjectileStatic");
675 return true;
676 }
677
678 }
679 return false;
680 }
681
682
683 public String toString() {
684 return
685 super.toString() + "[" +
686
687 "Id = " + String.valueOf(getId()
688 ) + " | " +
689
690 "]";
691 }
692
693
694 public String toHtmlString() {
695 return super.toString() + "[<br/>" +
696
697 "<b>Id</b> = " + String.valueOf(getId()
698 ) + " <br/> " +
699
700 "<br/>]";
701 }
702
703
704
705
706
707
708
709
710
711
712 }
713
714
715
716
717
718
719
720
721
722
723
724
725
726 public class IncomingProjectileSharedMessage
727 extends
728 IncomingProjectileShared
729 {
730
731
732
733 public IncomingProjectileSharedMessage()
734 {
735
736 propertyMap.put(myDirection.getPropertyId(), myDirection);
737
738 propertyMap.put(myLocation.getPropertyId(), myLocation);
739
740 propertyMap.put(myVelocity.getPropertyId(), myVelocity);
741
742 propertyMap.put(mySpeed.getPropertyId(), mySpeed);
743
744 propertyMap.put(myOrigin.getPropertyId(), myOrigin);
745
746 propertyMap.put(myDamageRadius.getPropertyId(), myDamageRadius);
747
748 propertyMap.put(myType.getPropertyId(), myType);
749
750 }
751
752 @Override
753 public
754 IncomingProjectileSharedMessage clone() {
755 return this;
756 }
757
758
759
760
761 protected HashMap<PropertyId, ISharedProperty> propertyMap = new HashMap<PropertyId, ISharedProperty>(
762 7
763 );
764
765 @Override
766 public ISharedProperty getProperty(PropertyId id) {
767 return propertyMap.get(id);
768 }
769
770 @Override
771 public Map<PropertyId, ISharedProperty> getProperties() {
772 return propertyMap;
773 }
774
775
776
777
778
779
780 public UnrealId getId()
781 {
782 return Id;
783 }
784
785
786
787
788
789
790
791
792 protected
793 Vector3dProperty
794 myDirection
795 = new
796 Vector3dProperty
797 (
798 getId(),
799 "Direction",
800 Direction,
801 IncomingProjectile.class
802 );
803
804
805
806
807
808
809
810 public Vector3d getDirection()
811 {
812 return myDirection.getValue();
813 }
814
815
816
817
818
819
820
821 protected
822 LocationProperty
823 myLocation
824 = new
825 LocationProperty
826 (
827 getId(),
828 "Location",
829 Location,
830 IncomingProjectile.class
831 );
832
833
834
835
836
837
838 public Location getLocation()
839 {
840 return myLocation.getValue();
841 }
842
843
844
845
846
847
848
849 protected
850 VelocityProperty
851 myVelocity
852 = new
853 VelocityProperty
854 (
855 getId(),
856 "Velocity",
857 Velocity,
858 IncomingProjectile.class
859 );
860
861
862
863
864
865
866 public Velocity getVelocity()
867 {
868 return myVelocity.getValue();
869 }
870
871
872
873
874
875
876
877 protected
878 DoubleProperty
879 mySpeed
880 = new
881 DoubleProperty
882 (
883 getId(),
884 "Speed",
885 Speed,
886 IncomingProjectile.class
887 );
888
889
890
891
892
893
894 public double getSpeed()
895 {
896 return mySpeed.getValue();
897 }
898
899
900
901
902
903
904
905
906 protected
907 LocationProperty
908 myOrigin
909 = new
910 LocationProperty
911 (
912 getId(),
913 "Origin",
914 Origin,
915 IncomingProjectile.class
916 );
917
918
919
920
921
922
923
924 public Location getOrigin()
925 {
926 return myOrigin.getValue();
927 }
928
929
930
931
932
933
934
935
936 protected
937 DoubleProperty
938 myDamageRadius
939 = new
940 DoubleProperty
941 (
942 getId(),
943 "DamageRadius",
944 DamageRadius,
945 IncomingProjectile.class
946 );
947
948
949
950
951
952
953
954 public double getDamageRadius()
955 {
956 return myDamageRadius.getValue();
957 }
958
959
960
961
962
963
964
965
966 protected
967 StringProperty
968 myType
969 = new
970 StringProperty
971 (
972 getId(),
973 "Type",
974 Type,
975 IncomingProjectile.class
976 );
977
978
979
980
981
982
983
984 public String getType()
985 {
986 return myType.getValue();
987 }
988
989
990 public String toString() {
991 return
992 super.toString() + "[" +
993
994 "Id = " + String.valueOf(getId()
995 ) + " | " +
996
997 "Direction = " + String.valueOf(getDirection()
998 ) + " | " +
999
1000 "Location = " + String.valueOf(getLocation()
1001 ) + " | " +
1002
1003 "Velocity = " + String.valueOf(getVelocity()
1004 ) + " | " +
1005
1006 "Speed = " + String.valueOf(getSpeed()
1007 ) + " | " +
1008
1009 "Origin = " + String.valueOf(getOrigin()
1010 ) + " | " +
1011
1012 "DamageRadius = " + String.valueOf(getDamageRadius()
1013 ) + " | " +
1014
1015 "Type = " + String.valueOf(getType()
1016 ) + " | " +
1017
1018 "]";
1019 }
1020
1021
1022 public String toHtmlString() {
1023 return super.toString() + "[<br/>" +
1024
1025 "<b>Id</b> = " + String.valueOf(getId()
1026 ) + " <br/> " +
1027
1028 "<b>Direction</b> = " + String.valueOf(getDirection()
1029 ) + " <br/> " +
1030
1031 "<b>Location</b> = " + String.valueOf(getLocation()
1032 ) + " <br/> " +
1033
1034 "<b>Velocity</b> = " + String.valueOf(getVelocity()
1035 ) + " <br/> " +
1036
1037 "<b>Speed</b> = " + String.valueOf(getSpeed()
1038 ) + " <br/> " +
1039
1040 "<b>Origin</b> = " + String.valueOf(getOrigin()
1041 ) + " <br/> " +
1042
1043 "<b>DamageRadius</b> = " + String.valueOf(getDamageRadius()
1044 ) + " <br/> " +
1045
1046 "<b>Type</b> = " + String.valueOf(getType()
1047 ) + " <br/> " +
1048
1049 "<br/>]";
1050 }
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061 }
1062
1063
1064
1065
1066 @Override
1067 public IWorldObjectUpdateResult<IWorldObject> update(IWorldObject object) {
1068 if (object == null)
1069 {
1070 return new IWorldObjectUpdateResult.WorldObjectUpdateResult(IWorldObjectUpdateResult.Result.CREATED, this);
1071 }
1072 if (!( object instanceof IncomingProjectileMessage) ) {
1073 throw new PogamutException("Can't update different class than IncomingProjectileMessage, got class " + object.getClass().getSimpleName() + "!", this);
1074 }
1075 IncomingProjectileMessage toUpdate = (IncomingProjectileMessage)object;
1076
1077 boolean updated = false;
1078
1079
1080
1081 if (toUpdate.ImpactTime != getImpactTime()
1082 ) {
1083 toUpdate.ImpactTime=getImpactTime()
1084 ;
1085 updated = true;
1086 }
1087
1088 if (toUpdate.Visible != isVisible()
1089 ) {
1090 toUpdate.Visible=isVisible()
1091 ;
1092 updated = true;
1093 }
1094
1095
1096
1097
1098 if (!SafeEquals.equals(toUpdate.Direction, getDirection()
1099 )) {
1100 toUpdate.Direction=getDirection()
1101 ;
1102 updated = true;
1103 }
1104
1105 if (!SafeEquals.equals(toUpdate.Location, getLocation()
1106 )) {
1107 toUpdate.Location=getLocation()
1108 ;
1109 updated = true;
1110 }
1111
1112 if (!SafeEquals.equals(toUpdate.Velocity, getVelocity()
1113 )) {
1114 toUpdate.Velocity=getVelocity()
1115 ;
1116 updated = true;
1117 }
1118
1119 if (toUpdate.Speed != getSpeed()
1120 ) {
1121 toUpdate.Speed=getSpeed()
1122 ;
1123 updated = true;
1124 }
1125
1126 if (getOrigin()
1127 != null) {
1128
1129 if (!SafeEquals.equals(toUpdate.Origin, getOrigin()
1130 )) {
1131 toUpdate.Origin=getOrigin()
1132 ;
1133 updated = true;
1134 }
1135
1136 }
1137
1138 if (toUpdate.DamageRadius != getDamageRadius()
1139 ) {
1140 toUpdate.DamageRadius=getDamageRadius()
1141 ;
1142 updated = true;
1143 }
1144
1145 if (!SafeEquals.equals(toUpdate.Type, getType()
1146 )) {
1147 toUpdate.Type=getType()
1148 ;
1149 updated = true;
1150 }
1151
1152
1153
1154 toUpdate.SimTime = SimTime;
1155
1156 if (updated) {
1157 return new IWorldObjectUpdateResult.WorldObjectUpdateResult<IWorldObject>(IWorldObjectUpdateResult.Result.UPDATED, toUpdate);
1158 } else {
1159 return new IWorldObjectUpdateResult.WorldObjectUpdateResult<IWorldObject>(IWorldObjectUpdateResult.Result.SAME, toUpdate);
1160 }
1161 }
1162
1163 @Override
1164 public ILocalWorldObjectUpdatedEvent getLocalEvent() {
1165 return new IncomingProjectileLocalImpl.IncomingProjectileLocalUpdate
1166 (this.getLocal(), SimTime);
1167 }
1168
1169 @Override
1170 public ISharedWorldObjectUpdatedEvent getSharedEvent() {
1171 return new IncomingProjectileSharedImpl.IncomingProjectileSharedUpdate
1172 (this.getShared(), SimTime, this.getTeamId());
1173 }
1174
1175 @Override
1176 public IStaticWorldObjectUpdatedEvent getStaticEvent() {
1177 return new IncomingProjectileStaticImpl.IncomingProjectileStaticUpdate
1178 (this.getStatic(), SimTime);
1179 }
1180
1181
1182 public String toString() {
1183 return
1184 super.toString() + "[" +
1185
1186 "Id = " + String.valueOf(getId()
1187 ) + " | " +
1188
1189 "ImpactTime = " + String.valueOf(getImpactTime()
1190 ) + " | " +
1191
1192 "Direction = " + String.valueOf(getDirection()
1193 ) + " | " +
1194
1195 "Location = " + String.valueOf(getLocation()
1196 ) + " | " +
1197
1198 "Velocity = " + String.valueOf(getVelocity()
1199 ) + " | " +
1200
1201 "Speed = " + String.valueOf(getSpeed()
1202 ) + " | " +
1203
1204 "Origin = " + String.valueOf(getOrigin()
1205 ) + " | " +
1206
1207 "DamageRadius = " + String.valueOf(getDamageRadius()
1208 ) + " | " +
1209
1210 "Type = " + String.valueOf(getType()
1211 ) + " | " +
1212
1213 "Visible = " + String.valueOf(isVisible()
1214 ) + " | " +
1215
1216 "]";
1217 }
1218
1219
1220 public String toHtmlString() {
1221 return super.toString() + "[<br/>" +
1222
1223 "<b>Id</b> = " + String.valueOf(getId()
1224 ) + " <br/> " +
1225
1226 "<b>ImpactTime</b> = " + String.valueOf(getImpactTime()
1227 ) + " <br/> " +
1228
1229 "<b>Direction</b> = " + String.valueOf(getDirection()
1230 ) + " <br/> " +
1231
1232 "<b>Location</b> = " + String.valueOf(getLocation()
1233 ) + " <br/> " +
1234
1235 "<b>Velocity</b> = " + String.valueOf(getVelocity()
1236 ) + " <br/> " +
1237
1238 "<b>Speed</b> = " + String.valueOf(getSpeed()
1239 ) + " <br/> " +
1240
1241 "<b>Origin</b> = " + String.valueOf(getOrigin()
1242 ) + " <br/> " +
1243
1244 "<b>DamageRadius</b> = " + String.valueOf(getDamageRadius()
1245 ) + " <br/> " +
1246
1247 "<b>Type</b> = " + String.valueOf(getType()
1248 ) + " <br/> " +
1249
1250 "<b>Visible</b> = " + String.valueOf(isVisible()
1251 ) + " <br/> " +
1252
1253 "<br/>]";
1254 }
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265 }
1266