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 EntityMessage
28 extends
29 Entity
30 implements IWorldObjectUpdatedEvent, ICompositeWorldObjectUpdatedEvent
31
32 {
33
34
35
36
37
38
39 public EntityMessage()
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 public EntityMessage(
91 UnrealId Id, boolean Visible, Location Location, Rotation Rotation, Velocity Velocity, String Type, String EntityClass
92 ) {
93
94 this.Id = Id;
95
96 this.Visible = Visible;
97
98 this.Location = Location;
99
100 this.Rotation = Rotation;
101
102 this.Velocity = Velocity;
103
104 this.Type = Type;
105
106 this.EntityClass = EntityClass;
107
108 }
109
110
111
112
113
114
115 public EntityMessage(EntityMessage original) {
116
117 this.Id = original.getId()
118 ;
119
120 this.Visible = original.isVisible()
121 ;
122
123 this.Location = original.getLocation()
124 ;
125
126 this.Rotation = original.getRotation()
127 ;
128
129 this.Velocity = original.getVelocity()
130 ;
131
132 this.Type = original.getType()
133 ;
134
135 this.EntityClass = original.getEntityClass()
136 ;
137
138 this.TeamId = original.getTeamId();
139
140 this.SimTime = original.getSimTime();
141 }
142
143
144 protected ITeamId TeamId;
145
146
147
148
149 protected void setTeamId(ITeamId TeamId) {
150 this.TeamId = TeamId;
151 }
152
153 public ITeamId getTeamId() {
154 return TeamId;
155 }
156
157
158
159
160
161
162
163
164
165 protected
166 UnrealId Id =
167 null;
168
169
170
171
172
173 protected boolean Id_Set = false;
174
175 @Override
176
177
178
179
180
181
182 public UnrealId getId()
183 {
184 return Id;
185 }
186
187
188
189
190
191
192
193 protected
194 boolean Visible =
195 false;
196
197
198
199
200
201 protected boolean Visible_Set = false;
202
203 @Override
204
205
206
207
208
209
210 public boolean isVisible()
211 {
212 return Visible;
213 }
214
215
216
217
218
219 protected
220 Location Location =
221 null;
222
223
224
225
226
227 protected boolean Location_Set = false;
228
229 @Override
230
231
232
233
234 public Location getLocation()
235 {
236 return Location;
237 }
238
239
240
241
242
243 protected
244 Rotation Rotation =
245 null;
246
247
248
249
250
251 protected boolean Rotation_Set = false;
252
253 @Override
254
255
256
257
258 public Rotation getRotation()
259 {
260 return Rotation;
261 }
262
263
264
265
266
267 protected
268 Velocity Velocity =
269 null;
270
271
272
273
274
275 protected boolean Velocity_Set = false;
276
277 @Override
278
279
280
281
282 public Velocity getVelocity()
283 {
284 return Velocity;
285 }
286
287
288
289
290
291 protected
292 String Type =
293 null;
294
295
296
297
298
299 protected boolean Type_Set = false;
300
301 @Override
302
303
304
305
306 public String getType()
307 {
308 return Type;
309 }
310
311
312
313
314
315 protected
316 String EntityClass =
317 null;
318
319
320
321
322
323 protected boolean EntityClass_Set = false;
324
325 @Override
326
327
328
329
330 public String getEntityClass()
331 {
332 return EntityClass;
333 }
334
335
336 private EntityLocal localPart = null;
337
338 @Override
339 public EntityLocal
340 getLocal() {
341 if (localPart != null) return localPart;
342 return localPart = new
343 EntityLocalMessage();
344 }
345
346 private EntityShared sharedPart = null;
347
348 @Override
349 public EntityShared
350 getShared() {
351 if (sharedPart != null) return sharedPart;
352 return sharedPart = new
353 EntitySharedMessage();
354 }
355
356 private EntityStatic staticPart = null;
357
358 @Override
359 public EntityStatic
360 getStatic() {
361 if (staticPart != null) return staticPart;
362 return staticPart = new
363 EntityStaticMessage();
364 }
365
366
367
368
369
370
371
372
373
374
375
376
377
378 public class EntityLocalMessage
379 extends
380 EntityLocal
381 {
382
383 @Override
384 public
385 EntityLocalMessage clone() {
386 return this;
387 }
388
389 public EntityLocalMessage getLocal() {
390 return this;
391 }
392 public ISharedWorldObject getShared() {
393 throw new UnsupportedOperationException("Could not return LOCAL as SHARED");
394 }
395 public IStaticWorldObject getStatic() {
396 throw new UnsupportedOperationException("Could not return LOCAL as STATIC");
397 }
398
399
400
401
402
403
404 public UnrealId getId()
405 {
406 return Id;
407 }
408
409
410
411
412
413
414 public boolean isVisible()
415 {
416 return Visible;
417 }
418
419
420 public String toString() {
421 return
422 super.toString() + "[" +
423
424 "Id = " + String.valueOf(getId()
425 ) + " | " +
426
427 "Visible = " + String.valueOf(isVisible()
428 ) + " | " +
429
430 "]";
431 }
432
433
434 public String toHtmlString() {
435 return super.toString() + "[<br/>" +
436
437 "<b>Id</b> = " + String.valueOf(getId()
438 ) + " <br/> " +
439
440 "<b>Visible</b> = " + String.valueOf(isVisible()
441 ) + " <br/> " +
442
443 "<br/>]";
444 }
445
446
447
448
449
450
451
452
453
454
455 }
456
457
458
459
460
461
462
463
464
465
466
467
468
469 public class EntityStaticMessage
470 extends
471 EntityStatic
472 {
473
474 @Override
475 public
476 EntityStaticMessage clone() {
477 return this;
478 }
479
480
481
482
483
484
485 public UnrealId getId()
486 {
487 return Id;
488 }
489
490
491
492
493 public String getType()
494 {
495 return Type;
496 }
497
498
499
500
501 public String getEntityClass()
502 {
503 return EntityClass;
504 }
505
506
507 @Override
508 public boolean isDifferentFrom(IStaticWorldObject other)
509 {
510 if (other == null)
511 {
512 return true;
513 }
514 else if (other == this)
515 {
516 return false;
517 }
518 else
519 {
520 EntityStatic obj = (EntityStatic) other;
521
522
523 if ( !(
524 AdvancedEquals.equalsOrNull(this.getId()
525 , obj.getId()
526 )
527 ) )
528 {
529 System.out.println("!!!!!PROPERTY UPDATE ERROR!!!! on property Id on object class EntityStatic");
530 return true;
531 }
532
533 if ( !(
534 AdvancedEquals.equalsOrNull(this.getType()
535 , obj.getType()
536 )
537 ) )
538 {
539 System.out.println("!!!!!PROPERTY UPDATE ERROR!!!! on property Type on object class EntityStatic");
540 return true;
541 }
542
543 if ( !(
544 AdvancedEquals.equalsOrNull(this.getEntityClass()
545 , obj.getEntityClass()
546 )
547 ) )
548 {
549 System.out.println("!!!!!PROPERTY UPDATE ERROR!!!! on property EntityClass on object class EntityStatic");
550 return true;
551 }
552
553 }
554 return false;
555 }
556
557
558 public String toString() {
559 return
560 super.toString() + "[" +
561
562 "Id = " + String.valueOf(getId()
563 ) + " | " +
564
565 "Type = " + String.valueOf(getType()
566 ) + " | " +
567
568 "EntityClass = " + String.valueOf(getEntityClass()
569 ) + " | " +
570
571 "]";
572 }
573
574
575 public String toHtmlString() {
576 return super.toString() + "[<br/>" +
577
578 "<b>Id</b> = " + String.valueOf(getId()
579 ) + " <br/> " +
580
581 "<b>Type</b> = " + String.valueOf(getType()
582 ) + " <br/> " +
583
584 "<b>EntityClass</b> = " + String.valueOf(getEntityClass()
585 ) + " <br/> " +
586
587 "<br/>]";
588 }
589
590
591
592
593
594
595
596
597
598
599 }
600
601
602
603
604
605
606
607
608
609
610
611
612
613 public class EntitySharedMessage
614 extends
615 EntityShared
616 {
617
618
619
620 public EntitySharedMessage()
621 {
622
623 propertyMap.put(myLocation.getPropertyId(), myLocation);
624
625 propertyMap.put(myRotation.getPropertyId(), myRotation);
626
627 propertyMap.put(myVelocity.getPropertyId(), myVelocity);
628
629 }
630
631 @Override
632 public
633 EntitySharedMessage clone() {
634 return this;
635 }
636
637
638
639
640 protected HashMap<PropertyId, ISharedProperty> propertyMap = new HashMap<PropertyId, ISharedProperty>(
641 3
642 );
643
644 @Override
645 public ISharedProperty getProperty(PropertyId id) {
646 return propertyMap.get(id);
647 }
648
649 @Override
650 public Map<PropertyId, ISharedProperty> getProperties() {
651 return propertyMap;
652 }
653
654
655
656
657
658
659
660
661 public UnrealId getId()
662 {
663 return Id;
664 }
665
666
667
668
669
670 protected
671 LocationProperty
672 myLocation
673 = new
674 LocationProperty
675 (
676 getId(),
677 "Location",
678 Location,
679 Entity.class
680 );
681
682
683
684
685 public Location getLocation()
686 {
687 return myLocation.getValue();
688 }
689
690
691
692
693
694 protected
695 RotationProperty
696 myRotation
697 = new
698 RotationProperty
699 (
700 getId(),
701 "Rotation",
702 Rotation,
703 Entity.class
704 );
705
706
707
708
709 public Rotation getRotation()
710 {
711 return myRotation.getValue();
712 }
713
714
715
716
717
718 protected
719 VelocityProperty
720 myVelocity
721 = new
722 VelocityProperty
723 (
724 getId(),
725 "Velocity",
726 Velocity,
727 Entity.class
728 );
729
730
731
732
733 public Velocity getVelocity()
734 {
735 return myVelocity.getValue();
736 }
737
738
739 public String toString() {
740 return
741 super.toString() + "[" +
742
743 "Id = " + String.valueOf(getId()
744 ) + " | " +
745
746 "Location = " + String.valueOf(getLocation()
747 ) + " | " +
748
749 "Rotation = " + String.valueOf(getRotation()
750 ) + " | " +
751
752 "Velocity = " + String.valueOf(getVelocity()
753 ) + " | " +
754
755 "]";
756 }
757
758
759 public String toHtmlString() {
760 return super.toString() + "[<br/>" +
761
762 "<b>Id</b> = " + String.valueOf(getId()
763 ) + " <br/> " +
764
765 "<b>Location</b> = " + String.valueOf(getLocation()
766 ) + " <br/> " +
767
768 "<b>Rotation</b> = " + String.valueOf(getRotation()
769 ) + " <br/> " +
770
771 "<b>Velocity</b> = " + String.valueOf(getVelocity()
772 ) + " <br/> " +
773
774 "<br/>]";
775 }
776
777
778
779
780
781
782
783
784
785
786 }
787
788
789
790
791 @Override
792 public IWorldObjectUpdateResult<IWorldObject> update(IWorldObject object) {
793 if (object == null)
794 {
795 return new IWorldObjectUpdateResult.WorldObjectUpdateResult(IWorldObjectUpdateResult.Result.CREATED, this);
796 }
797 if (!( object instanceof EntityMessage) ) {
798 throw new PogamutException("Can't update different class than EntityMessage, got class " + object.getClass().getSimpleName() + "!", this);
799 }
800 EntityMessage toUpdate = (EntityMessage)object;
801
802 boolean updated = false;
803
804
805
806 if (toUpdate.Visible != isVisible()
807 ) {
808 toUpdate.Visible=isVisible()
809 ;
810 updated = true;
811 }
812
813
814
815
816 if (getLocation()
817 != null) {
818
819 if (!SafeEquals.equals(toUpdate.Location, getLocation()
820 )) {
821 toUpdate.Location=getLocation()
822 ;
823 updated = true;
824 }
825
826 }
827
828 if (getRotation()
829 != null) {
830
831 if (!SafeEquals.equals(toUpdate.Rotation, getRotation()
832 )) {
833 toUpdate.Rotation=getRotation()
834 ;
835 updated = true;
836 }
837
838 }
839
840 if (getVelocity()
841 != null) {
842
843 if (!SafeEquals.equals(toUpdate.Velocity, getVelocity()
844 )) {
845 toUpdate.Velocity=getVelocity()
846 ;
847 updated = true;
848 }
849
850 }
851
852
853
854 toUpdate.SimTime = SimTime;
855
856 if (updated) {
857 return new IWorldObjectUpdateResult.WorldObjectUpdateResult<IWorldObject>(IWorldObjectUpdateResult.Result.UPDATED, toUpdate);
858 } else {
859 return new IWorldObjectUpdateResult.WorldObjectUpdateResult<IWorldObject>(IWorldObjectUpdateResult.Result.SAME, toUpdate);
860 }
861 }
862
863 @Override
864 public ILocalWorldObjectUpdatedEvent getLocalEvent() {
865 return new EntityLocalImpl.EntityLocalUpdate
866 (this.getLocal(), SimTime);
867 }
868
869 @Override
870 public ISharedWorldObjectUpdatedEvent getSharedEvent() {
871 return new EntitySharedImpl.EntitySharedUpdate
872 (this.getShared(), SimTime, this.getTeamId());
873 }
874
875 @Override
876 public IStaticWorldObjectUpdatedEvent getStaticEvent() {
877 return new EntityStaticImpl.EntityStaticUpdate
878 (this.getStatic(), SimTime);
879 }
880
881
882 public String toString() {
883 return
884 super.toString() + "[" +
885
886 "Id = " + String.valueOf(getId()
887 ) + " | " +
888
889 "Visible = " + String.valueOf(isVisible()
890 ) + " | " +
891
892 "Location = " + String.valueOf(getLocation()
893 ) + " | " +
894
895 "Rotation = " + String.valueOf(getRotation()
896 ) + " | " +
897
898 "Velocity = " + String.valueOf(getVelocity()
899 ) + " | " +
900
901 "Type = " + String.valueOf(getType()
902 ) + " | " +
903
904 "EntityClass = " + String.valueOf(getEntityClass()
905 ) + " | " +
906
907 "]";
908 }
909
910
911 public String toHtmlString() {
912 return super.toString() + "[<br/>" +
913
914 "<b>Id</b> = " + String.valueOf(getId()
915 ) + " <br/> " +
916
917 "<b>Visible</b> = " + String.valueOf(isVisible()
918 ) + " <br/> " +
919
920 "<b>Location</b> = " + String.valueOf(getLocation()
921 ) + " <br/> " +
922
923 "<b>Rotation</b> = " + String.valueOf(getRotation()
924 ) + " <br/> " +
925
926 "<b>Velocity</b> = " + String.valueOf(getVelocity()
927 ) + " <br/> " +
928
929 "<b>Type</b> = " + String.valueOf(getType()
930 ) + " <br/> " +
931
932 "<b>EntityClass</b> = " + String.valueOf(getEntityClass()
933 ) + " <br/> " +
934
935 "<br/>]";
936 }
937
938
939
940
941
942
943
944
945
946
947 }
948