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 PlayerSharedImpl
31 extends
32 PlayerShared
33 {
34
35
36
37 public PlayerSharedImpl(PlayerSharedImpl source) {
38
39 this.Id = source.
40 getId()
41 ;
42
43 this.myName = source.myName;
44
45 this.myAction = source.myAction;
46
47 this.myRotation = source.myRotation;
48
49 this.myLocation = source.myLocation;
50
51 this.myVelocity = source.myVelocity;
52
53 this.myTeam = source.myTeam;
54
55 this.myWeapon = source.myWeapon;
56
57 this.myCrouched = source.myCrouched;
58
59 this.myFiring = source.myFiring;
60
61 this.myEmotLeft = source.myEmotLeft;
62
63 this.myEmotCenter = source.myEmotCenter;
64
65 this.myEmotRight = source.myEmotRight;
66
67 this.myBubble = source.myBubble;
68
69 this.myAnim = source.myAnim;
70
71 }
72
73 public PlayerSharedImpl(WorldObjectId objectId, Collection<ISharedProperty> properties) {
74 this.Id = (UnrealId)objectId;
75 NullCheck.check(this.Id, "objectId");
76
77 if (properties.size() != 14) {
78 throw new PogamutException("Not enough properties passed to the constructor.", PlayerSharedImpl.class);
79 }
80
81
82 for ( ISharedProperty property : properties ) {
83 PropertyId pId = property.getPropertyId();
84 if ( !objectId.equals( property.getObjectId() )) {
85
86 throw new PogamutException("Trying to create a PlayerSharedImpl with different WorldObjectId properties : " +
87 this.Id.getStringId() + " / " + property.getObjectId().getStringId() , this);
88 }
89 if (!PlayerShared.SharedPropertyTokens.contains(pId.getPropertyToken())) {
90
91 throw new PogamutException("Trying to create a PlayerSharedImpl with invalid property (invalid property token): " +
92 this.Id.getStringId() + " / " + property.getPropertyId().getPropertyToken().getToken() , this);
93 }
94 propertyMap.put(property.getPropertyId(), property);
95
96
97 if (pId.getPropertyToken().getToken().equals("Name"))
98 {
99 this.myName = (StringProperty)property;
100 }
101
102 if (pId.getPropertyToken().getToken().equals("Action"))
103 {
104 this.myAction = (StringProperty)property;
105 }
106
107 if (pId.getPropertyToken().getToken().equals("Rotation"))
108 {
109 this.myRotation = (RotationProperty)property;
110 }
111
112 if (pId.getPropertyToken().getToken().equals("Location"))
113 {
114 this.myLocation = (LocationProperty)property;
115 }
116
117 if (pId.getPropertyToken().getToken().equals("Velocity"))
118 {
119 this.myVelocity = (VelocityProperty)property;
120 }
121
122 if (pId.getPropertyToken().getToken().equals("Team"))
123 {
124 this.myTeam = (IntProperty)property;
125 }
126
127 if (pId.getPropertyToken().getToken().equals("Weapon"))
128 {
129 this.myWeapon = (StringProperty)property;
130 }
131
132 if (pId.getPropertyToken().getToken().equals("Crouched"))
133 {
134 this.myCrouched = (BooleanProperty)property;
135 }
136
137 if (pId.getPropertyToken().getToken().equals("Firing"))
138 {
139 this.myFiring = (IntProperty)property;
140 }
141
142 if (pId.getPropertyToken().getToken().equals("EmotLeft"))
143 {
144 this.myEmotLeft = (StringProperty)property;
145 }
146
147 if (pId.getPropertyToken().getToken().equals("EmotCenter"))
148 {
149 this.myEmotCenter = (StringProperty)property;
150 }
151
152 if (pId.getPropertyToken().getToken().equals("EmotRight"))
153 {
154 this.myEmotRight = (StringProperty)property;
155 }
156
157 if (pId.getPropertyToken().getToken().equals("Bubble"))
158 {
159 this.myBubble = (StringProperty)property;
160 }
161
162 if (pId.getPropertyToken().getToken().equals("Anim"))
163 {
164 this.myAnim = (StringProperty)property;
165 }
166
167 }
168 }
169
170
171 @Override
172 public void setSimTime(long SimTime) {
173 super.setSimTime(SimTime);
174 }
175
176 @Override
177 public
178 PlayerSharedImpl clone() {
179 return new
180 PlayerSharedImpl(this);
181 }
182
183
184
185
186
187 protected HashMap<PropertyId, ISharedProperty> propertyMap = new HashMap<PropertyId, ISharedProperty>(
188 14
189 );
190
191 @Override
192 public ISharedProperty getProperty(PropertyId id) {
193 return propertyMap.get(id);
194 }
195
196 @Override
197 public Map<PropertyId, ISharedProperty> getProperties() {
198 return propertyMap;
199 }
200
201
202
203
204
205
206
207 protected
208 UnrealId Id =
209 null;
210
211
212
213
214 public UnrealId getId()
215 {
216 return Id;
217 }
218
219
220
221
222
223
224
225 protected
226 StringProperty
227 myName
228 = null;
229
230
231
232
233
234
235
236 public String getName()
237 {
238 return myName.getValue();
239 }
240
241
242
243
244
245
246
247 protected
248 StringProperty
249 myAction
250 = null;
251
252
253
254
255
256
257
258 public String getAction()
259 {
260 return myAction.getValue();
261 }
262
263
264
265
266
267
268
269 protected
270 RotationProperty
271 myRotation
272 = null;
273
274
275
276
277
278
279
280 public Rotation getRotation()
281 {
282 return myRotation.getValue();
283 }
284
285
286
287
288
289
290
291 protected
292 LocationProperty
293 myLocation
294 = null;
295
296
297
298
299
300
301
302 public Location getLocation()
303 {
304 return myLocation.getValue();
305 }
306
307
308
309
310
311
312
313
314 protected
315 VelocityProperty
316 myVelocity
317 = null;
318
319
320
321
322
323
324
325
326 public Velocity getVelocity()
327 {
328 return myVelocity.getValue();
329 }
330
331
332
333
334
335
336
337
338 protected
339 IntProperty
340 myTeam
341 = null;
342
343
344
345
346
347
348
349
350 public int getTeam()
351 {
352 return myTeam.getValue();
353 }
354
355
356
357
358
359
360
361
362
363
364
365 protected
366 StringProperty
367 myWeapon
368 = null;
369
370
371
372
373
374
375
376
377
378
379
380 public String getWeapon()
381 {
382 return myWeapon.getValue();
383 }
384
385
386
387
388
389
390
391 protected
392 BooleanProperty
393 myCrouched
394 = null;
395
396
397
398
399
400
401
402 public boolean isCrouched()
403 {
404 return myCrouched.getValue();
405 }
406
407
408
409
410
411
412
413
414 protected
415 IntProperty
416 myFiring
417 = null;
418
419
420
421
422
423
424
425
426 public int getFiring()
427 {
428 return myFiring.getValue();
429 }
430
431
432
433
434
435
436
437 protected
438 StringProperty
439 myEmotLeft
440 = null;
441
442
443
444
445
446
447
448 public String getEmotLeft()
449 {
450 return myEmotLeft.getValue();
451 }
452
453
454
455
456
457
458
459 protected
460 StringProperty
461 myEmotCenter
462 = null;
463
464
465
466
467
468
469
470 public String getEmotCenter()
471 {
472 return myEmotCenter.getValue();
473 }
474
475
476
477
478
479
480
481 protected
482 StringProperty
483 myEmotRight
484 = null;
485
486
487
488
489
490
491
492 public String getEmotRight()
493 {
494 return myEmotRight.getValue();
495 }
496
497
498
499
500
501
502
503 protected
504 StringProperty
505 myBubble
506 = null;
507
508
509
510
511
512
513
514 public String getBubble()
515 {
516 return myBubble.getValue();
517 }
518
519
520
521
522
523
524
525 protected
526 StringProperty
527 myAnim
528 = null;
529
530
531
532
533
534
535
536 public String getAnim()
537 {
538 return myAnim.getValue();
539 }
540
541
542
543 public static class PlayerSharedUpdate
544 implements ISharedWorldObjectUpdatedEvent
545 {
546
547 private PlayerShared object;
548 private long time;
549 private ITeamId teamId;
550
551 public PlayerSharedUpdate
552 (PlayerShared data, long time, ITeamId teamId)
553 {
554 this.object = data;
555 this.time = time;
556 this.teamId = teamId;
557 }
558
559
560
561
562 @Override
563 public long getSimTime() {
564 return this.time;
565 }
566
567 @Override
568 public WorldObjectId getId() {
569 return object.getId();
570 }
571
572 @Override
573 public ITeamId getTeamId() {
574 return teamId;
575 }
576
577 @Override
578 public Class getCompositeObjectClass()
579 {
580 return object.getCompositeClass();
581 }
582
583 @Override
584 public Collection<ISharedPropertyUpdatedEvent> getPropertyEvents() {
585 LinkedList<ISharedPropertyUpdatedEvent> events = new LinkedList<ISharedPropertyUpdatedEvent>();
586
587 for ( ISharedProperty property : object.getProperties().values() )
588 {
589 if ( property != null)
590 {
591 events.push( property.createUpdateEvent(time, teamId) );
592 }
593 }
594 return events;
595 }
596
597 }
598
599
600
601 public String toString() {
602 return
603 super.toString() + "[" +
604
605 "Id = " + String.valueOf(getId()
606 ) + " | " +
607
608 "Name = " + String.valueOf(getName()
609 ) + " | " +
610
611 "Action = " + String.valueOf(getAction()
612 ) + " | " +
613
614 "Rotation = " + String.valueOf(getRotation()
615 ) + " | " +
616
617 "Location = " + String.valueOf(getLocation()
618 ) + " | " +
619
620 "Velocity = " + String.valueOf(getVelocity()
621 ) + " | " +
622
623 "Team = " + String.valueOf(getTeam()
624 ) + " | " +
625
626 "Weapon = " + String.valueOf(getWeapon()
627 ) + " | " +
628
629 "Crouched = " + String.valueOf(isCrouched()
630 ) + " | " +
631
632 "Firing = " + String.valueOf(getFiring()
633 ) + " | " +
634
635 "EmotLeft = " + String.valueOf(getEmotLeft()
636 ) + " | " +
637
638 "EmotCenter = " + String.valueOf(getEmotCenter()
639 ) + " | " +
640
641 "EmotRight = " + String.valueOf(getEmotRight()
642 ) + " | " +
643
644 "Bubble = " + String.valueOf(getBubble()
645 ) + " | " +
646
647 "Anim = " + String.valueOf(getAnim()
648 ) + " | " +
649
650 "]";
651 }
652
653
654 public String toHtmlString() {
655 return super.toString() + "[<br/>" +
656
657 "<b>Id</b> = " + String.valueOf(getId()
658 ) + " <br/> " +
659
660 "<b>Name</b> = " + String.valueOf(getName()
661 ) + " <br/> " +
662
663 "<b>Action</b> = " + String.valueOf(getAction()
664 ) + " <br/> " +
665
666 "<b>Rotation</b> = " + String.valueOf(getRotation()
667 ) + " <br/> " +
668
669 "<b>Location</b> = " + String.valueOf(getLocation()
670 ) + " <br/> " +
671
672 "<b>Velocity</b> = " + String.valueOf(getVelocity()
673 ) + " <br/> " +
674
675 "<b>Team</b> = " + String.valueOf(getTeam()
676 ) + " <br/> " +
677
678 "<b>Weapon</b> = " + String.valueOf(getWeapon()
679 ) + " <br/> " +
680
681 "<b>Crouched</b> = " + String.valueOf(isCrouched()
682 ) + " <br/> " +
683
684 "<b>Firing</b> = " + String.valueOf(getFiring()
685 ) + " <br/> " +
686
687 "<b>EmotLeft</b> = " + String.valueOf(getEmotLeft()
688 ) + " <br/> " +
689
690 "<b>EmotCenter</b> = " + String.valueOf(getEmotCenter()
691 ) + " <br/> " +
692
693 "<b>EmotRight</b> = " + String.valueOf(getEmotRight()
694 ) + " <br/> " +
695
696 "<b>Bubble</b> = " + String.valueOf(getBubble()
697 ) + " <br/> " +
698
699 "<b>Anim</b> = " + String.valueOf(getAnim()
700 ) + " <br/> " +
701
702 "<br/>]";
703 }
704
705
706
707
708
709
710
711
712
713
714 }
715