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