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 public class ItemMessage
29 extends
30 Item
31 implements IWorldObjectUpdatedEvent, ICompositeWorldObjectUpdatedEvent
32
33 {
34
35
36
37
38
39
40 public ItemMessage()
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 public ItemMessage(
117 UnrealId Id, UnrealId NavPointId, NavPoint NavPoint, boolean Visible, Location Location, int Amount, ItemType Type, ItemDescriptor Descriptor, boolean Dropped
118 ) {
119
120 this.Id = Id;
121
122 this.NavPointId = NavPointId;
123
124 this.NavPoint = NavPoint;
125
126 this.Visible = Visible;
127
128 this.Location = Location;
129
130 this.Amount = Amount;
131
132 this.Type = Type;
133
134 this.Descriptor = Descriptor;
135
136 this.Dropped = Dropped;
137
138 }
139
140
141
142
143
144
145 public ItemMessage(ItemMessage original) {
146
147 this.Id = original.getId()
148 ;
149
150 this.NavPointId = original.getNavPointId()
151 ;
152
153 this.NavPoint = original.getNavPoint()
154 ;
155
156 this.Visible = original.isVisible()
157 ;
158
159 this.Location = original.getLocation()
160 ;
161
162 this.Amount = original.getAmount()
163 ;
164
165 this.Type = original.getType()
166 ;
167
168 this.Descriptor = original.getDescriptor()
169 ;
170
171 this.Dropped = original.isDropped()
172 ;
173
174 this.TeamId = original.getTeamId();
175
176 this.SimTime = original.getSimTime();
177 }
178
179
180 protected ITeamId TeamId;
181
182
183
184
185 protected void setTeamId(ITeamId TeamId) {
186 this.TeamId = TeamId;
187 }
188
189 public ITeamId getTeamId() {
190 return TeamId;
191 }
192
193
194
195
196
197
198
199
200
201
202 protected
203 UnrealId Id =
204 null;
205
206
207
208
209
210 protected boolean Id_Set = false;
211
212 @Override
213
214
215
216
217
218
219
220 public UnrealId getId()
221 {
222 return Id;
223 }
224
225
226
227
228
229
230
231 protected
232 UnrealId NavPointId =
233 null;
234
235
236
237
238
239 protected boolean NavPointId_Set = false;
240
241 @Override
242
243
244
245
246
247
248 public UnrealId getNavPointId()
249 {
250 return NavPointId;
251 }
252
253
254
255
256
257
258
259
260 protected
261 NavPoint NavPoint =
262 null;
263
264
265
266
267
268 protected boolean NavPoint_Set = false;
269
270 @Override
271
272
273
274
275
276
277
278 public NavPoint getNavPoint()
279 {
280 return NavPoint;
281 }
282
283
284
285
286
287
288
289 protected
290 boolean Visible =
291 false;
292
293
294
295
296
297 protected boolean Visible_Set = false;
298
299 @Override
300
301
302
303
304
305
306 public boolean isVisible()
307 {
308 return Visible;
309 }
310
311
312
313
314
315 protected
316 Location Location =
317 null;
318
319
320
321
322
323 protected boolean Location_Set = false;
324
325 @Override
326
327
328
329
330 public Location getLocation()
331 {
332 return Location;
333 }
334
335
336
337
338
339
340
341
342 protected
343 int Amount =
344 0;
345
346
347
348
349
350 protected boolean Amount_Set = false;
351
352 @Override
353
354
355
356
357
358
359
360 public int getAmount()
361 {
362 return Amount;
363 }
364
365
366
367
368
369
370
371 protected
372 ItemType Type =
373 null;
374
375
376
377
378
379 protected boolean Type_Set = false;
380
381 @Override
382
383
384
385
386
387
388 public ItemType getType()
389 {
390 return Type;
391 }
392
393
394
395
396
397
398
399 protected
400 ItemDescriptor Descriptor =
401 null;
402
403
404
405
406
407 protected boolean Descriptor_Set = false;
408
409 @Override
410
411
412
413
414
415
416 public ItemDescriptor getDescriptor()
417 {
418 return Descriptor;
419 }
420
421
422
423
424
425
426
427
428 protected
429 boolean Dropped =
430 false;
431
432
433
434
435
436 protected boolean Dropped_Set = false;
437
438 @Override
439
440
441
442
443
444
445
446 public boolean isDropped()
447 {
448 return Dropped;
449 }
450
451
452 private ItemLocal localPart = null;
453
454 @Override
455 public ItemLocal
456 getLocal() {
457 if (localPart != null) return localPart;
458 return localPart = new
459 ItemLocalMessage();
460 }
461
462 private ItemShared sharedPart = null;
463
464 @Override
465 public ItemShared
466 getShared() {
467 if (sharedPart != null) return sharedPart;
468 return sharedPart = new
469 ItemSharedMessage();
470 }
471
472 private ItemStatic staticPart = null;
473
474 @Override
475 public ItemStatic
476 getStatic() {
477 if (staticPart != null) return staticPart;
478 return staticPart = new
479 ItemStaticMessage();
480 }
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495 public class ItemLocalMessage
496 extends
497 ItemLocal
498 {
499
500 @Override
501 public
502 ItemLocalMessage clone() {
503 return this;
504 }
505
506 public ItemLocalMessage getLocal() {
507 return this;
508 }
509 public ISharedWorldObject getShared() {
510 throw new UnsupportedOperationException("Could not return LOCAL as SHARED");
511 }
512 public IStaticWorldObject getStatic() {
513 throw new UnsupportedOperationException("Could not return LOCAL as STATIC");
514 }
515
516
517
518
519
520
521
522 public UnrealId getId()
523 {
524 return Id;
525 }
526
527
528
529
530
531
532 public boolean isVisible()
533 {
534 return Visible;
535 }
536
537
538 public String toString() {
539 return
540 super.toString() + "[" +
541
542 "Id = " + String.valueOf(getId()
543 ) + " | " +
544
545 "Visible = " + String.valueOf(isVisible()
546 ) + " | " +
547
548 "]";
549 }
550
551
552 public String toHtmlString() {
553 return super.toString() + "[<br/>" +
554
555 "<b>Id</b> = " + String.valueOf(getId()
556 ) + " <br/> " +
557
558 "<b>Visible</b> = " + String.valueOf(isVisible()
559 ) + " <br/> " +
560
561 "<br/>]";
562 }
563
564
565
566
567
568
569
570
571
572
573 }
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588 public class ItemStaticMessage
589 extends
590 ItemStatic
591 {
592
593 @Override
594 public
595 ItemStaticMessage clone() {
596 return this;
597 }
598
599
600
601
602
603
604
605 public UnrealId getId()
606 {
607 return Id;
608 }
609
610
611
612
613
614
615 public UnrealId getNavPointId()
616 {
617 return NavPointId;
618 }
619
620
621
622
623
624
625
626 public NavPoint getNavPoint()
627 {
628 return NavPoint;
629 }
630
631
632
633
634
635
636
637 public int getAmount()
638 {
639 return Amount;
640 }
641
642
643
644
645
646
647 public ItemType getType()
648 {
649 return Type;
650 }
651
652
653
654
655
656
657 public ItemDescriptor getDescriptor()
658 {
659 return Descriptor;
660 }
661
662
663 @Override
664 public boolean isDifferentFrom(IStaticWorldObject other)
665 {
666 if (other == null)
667 {
668 return true;
669 }
670 else if (other == this)
671 {
672 return false;
673 }
674 else
675 {
676 ItemStatic obj = (ItemStatic) other;
677
678
679 if ( !(
680 AdvancedEquals.equalsOrNull(this.getId()
681 , obj.getId()
682 )
683 ) )
684 {
685 System.out.println("!!!!!PROPERTY UPDATE ERROR!!!! on property Id on object class ItemStatic");
686 return true;
687 }
688
689 if ( !(
690 AdvancedEquals.equalsOrNull(this.getNavPointId()
691 , obj.getNavPointId()
692 )
693 ) )
694 {
695 System.out.println("!!!!!PROPERTY UPDATE ERROR!!!! on property NavPointId on object class ItemStatic");
696 return true;
697 }
698
699 if ( !(
700 AdvancedEquals.equalsOrNull(this.getNavPoint()
701 , obj.getNavPoint()
702 )
703 ) )
704 {
705 System.out.println("!!!!!PROPERTY UPDATE ERROR!!!! on property NavPoint on object class ItemStatic");
706 return true;
707 }
708
709 if ( !(this.getAmount()
710
711 == obj.getAmount()
712 ) )
713 {
714 System.out.println("!!!!!PROPERTY UPDATE ERROR!!!! on property Amount on object class ItemStatic");
715 return true;
716 }
717
718 if ( !(
719 AdvancedEquals.equalsOrNull(this.getType()
720 , obj.getType()
721 )
722 ) )
723 {
724 System.out.println("!!!!!PROPERTY UPDATE ERROR!!!! on property Type on object class ItemStatic");
725 return true;
726 }
727
728 if ( !(
729 AdvancedEquals.equalsOrNull(this.getDescriptor()
730 , obj.getDescriptor()
731 )
732 ) )
733 {
734 System.out.println("!!!!!PROPERTY UPDATE ERROR!!!! on property Descriptor on object class ItemStatic");
735 return true;
736 }
737
738 }
739 return false;
740 }
741
742
743 public String toString() {
744 return
745 super.toString() + "[" +
746
747 "Id = " + String.valueOf(getId()
748 ) + " | " +
749
750 "NavPointId = " + String.valueOf(getNavPointId()
751 ) + " | " +
752
753 "Amount = " + String.valueOf(getAmount()
754 ) + " | " +
755
756 "Type = " + String.valueOf(getType()
757 ) + " | " +
758
759 "]";
760 }
761
762
763 public String toHtmlString() {
764 return super.toString() + "[<br/>" +
765
766 "<b>Id</b> = " + String.valueOf(getId()
767 ) + " <br/> " +
768
769 "<b>NavPointId</b> = " + String.valueOf(getNavPointId()
770 ) + " <br/> " +
771
772 "<b>Amount</b> = " + String.valueOf(getAmount()
773 ) + " <br/> " +
774
775 "<b>Type</b> = " + String.valueOf(getType()
776 ) + " <br/> " +
777
778 "<br/>]";
779 }
780
781
782
783
784
785
786
787
788
789
790 }
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805 public class ItemSharedMessage
806 extends
807 ItemShared
808 {
809
810
811
812 public ItemSharedMessage()
813 {
814
815 propertyMap.put(myLocation.getPropertyId(), myLocation);
816
817 propertyMap.put(myDropped.getPropertyId(), myDropped);
818
819 }
820
821 @Override
822 public
823 ItemSharedMessage clone() {
824 return this;
825 }
826
827
828
829
830 protected HashMap<PropertyId, ISharedProperty> propertyMap = new HashMap<PropertyId, ISharedProperty>(
831 2
832 );
833
834 @Override
835 public ISharedProperty getProperty(PropertyId id) {
836 return propertyMap.get(id);
837 }
838
839 @Override
840 public Map<PropertyId, ISharedProperty> getProperties() {
841 return propertyMap;
842 }
843
844
845
846
847
848
849
850
851
852 public UnrealId getId()
853 {
854 return Id;
855 }
856
857
858
859
860
861 protected
862 LocationProperty
863 myLocation
864 = new
865 LocationProperty
866 (
867 getId(),
868 "Location",
869 Location,
870 Item.class
871 );
872
873
874
875
876 public Location getLocation()
877 {
878 return myLocation.getValue();
879 }
880
881
882
883
884
885
886
887
888 protected
889 BooleanProperty
890 myDropped
891 = new
892 BooleanProperty
893 (
894 getId(),
895 "Dropped",
896 Dropped,
897 Item.class
898 );
899
900
901
902
903
904
905
906 public boolean isDropped()
907 {
908 return myDropped.getValue();
909 }
910
911
912 public String toString() {
913 return
914 super.toString() + "[" +
915
916 "Id = " + String.valueOf(getId()
917 ) + " | " +
918
919 "Location = " + String.valueOf(getLocation()
920 ) + " | " +
921
922 "Dropped = " + String.valueOf(isDropped()
923 ) + " | " +
924
925 "]";
926 }
927
928
929 public String toHtmlString() {
930 return super.toString() + "[<br/>" +
931
932 "<b>Id</b> = " + String.valueOf(getId()
933 ) + " <br/> " +
934
935 "<b>Location</b> = " + String.valueOf(getLocation()
936 ) + " <br/> " +
937
938 "<b>Dropped</b> = " + String.valueOf(isDropped()
939 ) + " <br/> " +
940
941 "<br/>]";
942 }
943
944
945
946
947
948
949
950
951
952
953 }
954
955
956
957
958 @Override
959 public IWorldObjectUpdateResult<IWorldObject> update(IWorldObject object) {
960 if (object == null)
961 {
962 return new IWorldObjectUpdateResult.WorldObjectUpdateResult(IWorldObjectUpdateResult.Result.CREATED, this);
963 }
964 if (!( object instanceof ItemMessage) ) {
965 throw new PogamutException("Can't update different class than ItemMessage, got class " + object.getClass().getSimpleName() + "!", this);
966 }
967 ItemMessage toUpdate = (ItemMessage)object;
968
969 boolean updated = false;
970
971
972
973 if (toUpdate.Visible != isVisible()
974 ) {
975 toUpdate.Visible=isVisible()
976 ;
977 updated = true;
978 }
979
980
981
982
983 if (getLocation()
984 != null) {
985
986 if (!SafeEquals.equals(toUpdate.Location, getLocation()
987 )) {
988 toUpdate.Location=getLocation()
989 ;
990 updated = true;
991 }
992
993 }
994
995 if (toUpdate.Dropped != isDropped()
996 ) {
997 toUpdate.Dropped=isDropped()
998 ;
999 updated = true;
1000 }
1001
1002
1003
1004 toUpdate.SimTime = SimTime;
1005
1006 if (updated) {
1007 return new IWorldObjectUpdateResult.WorldObjectUpdateResult<IWorldObject>(IWorldObjectUpdateResult.Result.UPDATED, toUpdate);
1008 } else {
1009 return new IWorldObjectUpdateResult.WorldObjectUpdateResult<IWorldObject>(IWorldObjectUpdateResult.Result.SAME, toUpdate);
1010 }
1011 }
1012
1013 @Override
1014 public ILocalWorldObjectUpdatedEvent getLocalEvent() {
1015 return new ItemLocalImpl.ItemLocalUpdate
1016 (this.getLocal(), SimTime);
1017 }
1018
1019 @Override
1020 public ISharedWorldObjectUpdatedEvent getSharedEvent() {
1021 return new ItemSharedImpl.ItemSharedUpdate
1022 (this.getShared(), SimTime, this.getTeamId());
1023 }
1024
1025 @Override
1026 public IStaticWorldObjectUpdatedEvent getStaticEvent() {
1027 return new ItemStaticImpl.ItemStaticUpdate
1028 (this.getStatic(), SimTime);
1029 }
1030
1031
1032 public String toString() {
1033 return
1034 super.toString() + "[" +
1035
1036 "Id = " + String.valueOf(getId()
1037 ) + " | " +
1038
1039 "NavPointId = " + String.valueOf(getNavPointId()
1040 ) + " | " +
1041
1042 "Visible = " + String.valueOf(isVisible()
1043 ) + " | " +
1044
1045 "Location = " + String.valueOf(getLocation()
1046 ) + " | " +
1047
1048 "Amount = " + String.valueOf(getAmount()
1049 ) + " | " +
1050
1051 "Type = " + String.valueOf(getType()
1052 ) + " | " +
1053
1054 "Dropped = " + String.valueOf(isDropped()
1055 ) + " | " +
1056
1057 "]";
1058 }
1059
1060
1061 public String toHtmlString() {
1062 return super.toString() + "[<br/>" +
1063
1064 "<b>Id</b> = " + String.valueOf(getId()
1065 ) + " <br/> " +
1066
1067 "<b>NavPointId</b> = " + String.valueOf(getNavPointId()
1068 ) + " <br/> " +
1069
1070 "<b>Visible</b> = " + String.valueOf(isVisible()
1071 ) + " <br/> " +
1072
1073 "<b>Location</b> = " + String.valueOf(getLocation()
1074 ) + " <br/> " +
1075
1076 "<b>Amount</b> = " + String.valueOf(getAmount()
1077 ) + " <br/> " +
1078
1079 "<b>Type</b> = " + String.valueOf(getType()
1080 ) + " <br/> " +
1081
1082 "<b>Dropped</b> = " + String.valueOf(isDropped()
1083 ) + " <br/> " +
1084
1085 "<br/>]";
1086 }
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107 public void setNavPoint(NavPoint navPoint) {
1108 NavPoint = navPoint;
1109 }
1110
1111
1112
1113 }
1114