1
2
3
4
5
6
7
8
9
10 package
11 cz.cuni.amis.pogamut.udk.communication.messages.gbinfomessages;
12 import java.util.*;
13 import javax.vecmath.*;
14 import cz.cuni.amis.pogamut.base.communication.messages.*;
15 import cz.cuni.amis.pogamut.base.communication.worldview.*;
16 import cz.cuni.amis.pogamut.base.communication.worldview.event.*;
17 import cz.cuni.amis.pogamut.base.communication.worldview.object.*;
18 import cz.cuni.amis.pogamut.base.communication.translator.event.*;
19 import cz.cuni.amis.pogamut.base3d.worldview.object.*;
20 import cz.cuni.amis.pogamut.base3d.worldview.object.event.*;
21 import cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId;
22 import cz.cuni.amis.pogamut.udk.communication.messages.*;
23 import cz.cuni.amis.pogamut.udk.communication.worldview.objects.*;
24 import cz.cuni.amis.pogamut.udk.communication.translator.itemdescriptor.*;
25 import cz.cuni.amis.pogamut.udk.communication.messages.ItemType.Category;
26 import cz.cuni.amis.utils.exception.*;
27 import cz.cuni.amis.pogamut.base.communication.translator.event.IWorldObjectUpdateResult.Result;
28 import cz.cuni.amis.utils.SafeEquals;
29 import cz.cuni.amis.pogamut.multi.communication.worldview.object.*;
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44 public class
45 Player
46 extends GBObjectUpdate
47
48 implements IGBWorldObjectEvent, IWorldObject, IPerson, IGBViewable, cz.cuni.amis.pogamut.unreal.communication.messages.gbinfomessages.IPlayer
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 public Player(
105 UnrealId Id, String Jmx, String Name, String Action, boolean Visible, Rotation Rotation, Location Location, Velocity Velocity, int Team, String Weapon, boolean Reachable, int Firing) {
106
107 this.Id = Id;
108
109 this.Jmx = Jmx;
110
111 this.Name = Name;
112
113 this.Action = Action;
114
115 this.Visible = Visible;
116
117 this.Rotation = Rotation;
118
119 this.Location = Location;
120
121 this.Velocity = Velocity;
122
123 this.Team = Team;
124
125 this.Weapon = Weapon;
126
127 this.Reachable = Reachable;
128
129 this.Firing = Firing;
130
131 }
132
133
134
135 public static final String PROTOTYPE =
136 "PLR {Id unreal_id} {Jmx text} {Name text} {Action text} {Visible False} {Rotation 0,0,0} {Location 0,0,0} {Velocity 0,0,0} {Team 0} {Weapon text} {Reachable False} {Firing 0}";
137
138
139
140
141
142
143 protected
144 UnrealId Id =
145 null;
146
147
148
149
150 public
151 UnrealId getId() {
152 return
153 Id;
154 }
155
156
157
158
159
160
161
162
163 protected
164 String Jmx =
165 null;
166
167
168
169
170
171
172
173 public
174 String getJmx() {
175 return
176 Jmx;
177 }
178
179
180
181
182
183
184
185 protected
186 String Name =
187 null;
188
189
190
191
192
193
194 public
195 String getName() {
196 return
197 Name;
198 }
199
200
201
202
203
204
205
206 protected
207 String Action =
208 null;
209
210
211
212
213
214
215 public
216 String getAction() {
217 return
218 Action;
219 }
220
221
222
223
224
225
226
227 protected
228 boolean Visible =
229 true;
230
231
232
233
234
235
236 public
237 boolean isVisible() {
238 return
239 Visible;
240 }
241
242
243
244
245
246
247
248 protected
249 Rotation Rotation =
250 null;
251
252
253
254
255
256
257 public
258 Rotation getRotation() {
259 return
260 Rotation;
261 }
262
263
264
265
266
267
268
269 protected
270 Location Location =
271 null;
272
273
274
275
276
277
278 public
279 Location getLocation() {
280 return
281 Location;
282 }
283
284
285
286
287
288
289
290
291 protected
292 Velocity Velocity =
293 null;
294
295
296
297
298
299
300
301 public
302 Velocity getVelocity() {
303 return
304 Velocity;
305 }
306
307
308
309
310
311
312
313
314 protected
315 int Team =
316 0;
317
318
319
320
321
322
323
324 public
325 int getTeam() {
326 return
327 Team;
328 }
329
330
331
332
333
334
335
336
337
338 protected
339 String Weapon =
340 null;
341
342
343
344
345
346
347
348
349 public
350 String getWeapon() {
351 return
352 Weapon;
353 }
354
355
356
357
358
359
360
361
362
363 protected
364 boolean Reachable =
365 false;
366
367
368
369
370
371
372
373
374 public
375 boolean isReachable() {
376 return
377 Reachable;
378 }
379
380
381
382
383
384
385
386
387 protected
388 int Firing =
389 0;
390
391
392
393
394
395
396
397 public
398 int getFiring() {
399 return
400 Firing;
401 }
402
403
404
405
406
407
408
409
410
411 protected double Time = 0;
412
413 protected double getTime() {
414 return Time;
415 }
416
417 protected void setTime(double time) {
418 this.Time = time;
419 }
420
421 public double getLastSeenTime() {
422 return Time;
423 }
424
425
426 public ILocalWorldObject getLocal() {
427 return null;
428 }
429
430 public ISharedWorldObject getShared() {
431 return null;
432 }
433
434 public IStaticWorldObject getStatic() {
435 return null;
436 }
437
438 @Override
439 public long getSimTime() {
440 return (long)getLastSeenTime();
441 }
442
443 public boolean equals(Object obj) {
444 if (!(obj instanceof Player)) return false;
445 Player cast = (Player)obj;
446 if (this.getId() != null) return this.getId().equals(cast.getId());
447 else return cast.getId() == null;
448 }
449
450 public int hashCode() {
451 if (getId() != null) return getId().hashCode();
452 return 0;
453 }
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471 public Player(Player original) {
472
473 this.Id=original.Id;
474
475 this.Jmx=original.Jmx;
476
477 this.Name=original.Name;
478
479 this.Action=original.Action;
480
481 this.Visible=original.Visible;
482
483 this.Rotation=original.Rotation;
484
485 this.Location=original.Location;
486
487 this.Velocity=original.Velocity;
488
489 this.Team=original.Team;
490
491 this.Weapon=original.Weapon;
492
493 this.Reachable=original.Reachable;
494
495 this.Firing=original.Firing;
496
497 }
498
499
500
501
502
503 public Player() {
504 }
505
506
507
508
509
510 public static class ObjectDisappeared implements IGBWorldObjectDisappeared {
511
512 private IWorldObject orig;
513
514 public ObjectDisappeared(IWorldObject orig) {
515 this.orig = orig;
516 }
517
518 public WorldObjectId getId() {
519 return orig.getId();
520 }
521
522 public long getSimTime() {
523 return 0;
524 }
525
526 public IWorldObjectUpdateResult update(IWorldObject obj) {
527 if (obj == null) {
528 throw new PogamutException("not meant to create new object, probably wanted to update non-existing object of id: " + getId(), this);
529 }
530 if (!(obj instanceof Player)) {
531 throw new PogamutException("can't update object of class " + obj.getClass() + ", meant to update Player", this);
532 }
533 orig = obj;
534 Player toUpdate = (Player)obj;
535 if (toUpdate.Visible) {
536 toUpdate.Visible = false;
537 return new IWorldObjectUpdateResult.WorldObjectUpdateResult(cz.cuni.amis.pogamut.base.communication.translator.event.IWorldObjectUpdateResult.Result.UPDATED, toUpdate);
538 } else {
539 return new IWorldObjectUpdateResult.WorldObjectUpdateResult(cz.cuni.amis.pogamut.base.communication.translator.event.IWorldObjectUpdateResult.Result.SAME, toUpdate);
540 }
541 }
542
543 public IWorldObject getObject() {
544 return orig;
545 }
546
547 public String toString() {
548 return "ObjectDisappeared[" + orig.getClass().getSimpleName() + " " + orig.getId().getStringId() + "]";
549 }
550
551 }
552
553
554
555
556 public Player(Player Original, boolean Visible) {
557 this(Original);
558 this.Visible = Visible;
559 }
560
561 public IGBWorldObjectDisappeared createDisappearEvent() {
562 return new ObjectDisappeared(this);
563 }
564
565
566
567
568
569 private IWorldObject orig = null;
570
571 public IWorldObjectUpdateResult update(IWorldObject obj) {
572 if(obj == null) {
573 orig = this;
574 return new IWorldObjectUpdateResult.WorldObjectUpdateResult(cz.cuni.amis.pogamut.base.communication.translator.event.IWorldObjectUpdateResult.Result.CREATED, this);
575 }
576 orig = obj;
577
578 Player o = (Player)obj;
579
580 boolean updated = false;
581
582
583 if (!SafeEquals.equals(o.Name, Name)) {
584 o.Name=Name;
585 updated = true;
586 }
587
588 if (!SafeEquals.equals(o.Action, Action)) {
589 o.Action=Action;
590 updated = true;
591 }
592
593 if (o.Visible != Visible) {
594 o.Visible=Visible;
595 updated = true;
596 }
597
598 if (!SafeEquals.equals(o.Rotation, Rotation)) {
599 o.Rotation=Rotation;
600 updated = true;
601 }
602
603 if (!SafeEquals.equals(o.Location, Location)) {
604 o.Location=Location;
605 updated = true;
606 }
607
608 if (!SafeEquals.equals(o.Velocity, Velocity)) {
609 o.Velocity=Velocity;
610 updated = true;
611 }
612
613 if (o.Team != Team) {
614 o.Team=Team;
615 updated = true;
616 }
617
618 if (!SafeEquals.equals(o.Weapon, Weapon)) {
619 o.Weapon=Weapon;
620 updated = true;
621 }
622
623 if (o.Reachable != Reachable) {
624 o.Reachable=Reachable;
625 updated = true;
626 }
627
628 if (o.Firing != Firing) {
629 o.Firing=Firing;
630 updated = true;
631 }
632
633 o.Time = Time;
634
635
636 if (updated) {
637 return new IWorldObjectUpdateResult.WorldObjectUpdateResult(cz.cuni.amis.pogamut.base.communication.translator.event.IWorldObjectUpdateResult.Result.UPDATED, o);
638 } else {
639 return new IWorldObjectUpdateResult.WorldObjectUpdateResult(cz.cuni.amis.pogamut.base.communication.translator.event.IWorldObjectUpdateResult.Result.SAME, o);
640 }
641 }
642
643
644
645
646
647 public IWorldObject getObject() {
648 if (orig == null) return this;
649 return orig;
650 }
651
652
653
654 public String toString() {
655 return
656
657 super.toString() + " | " +
658
659 "Id = " +
660 String.valueOf(Id) + " | " +
661
662 "Jmx = " +
663 String.valueOf(Jmx) + " | " +
664
665 "Name = " +
666 String.valueOf(Name) + " | " +
667
668 "Action = " +
669 String.valueOf(Action) + " | " +
670
671 "Visible = " +
672 String.valueOf(Visible) + " | " +
673
674 "Rotation = " +
675 String.valueOf(Rotation) + " | " +
676
677 "Location = " +
678 String.valueOf(Location) + " | " +
679
680 "Velocity = " +
681 String.valueOf(Velocity) + " | " +
682
683 "Team = " +
684 String.valueOf(Team) + " | " +
685
686 "Weapon = " +
687 String.valueOf(Weapon) + " | " +
688
689 "Reachable = " +
690 String.valueOf(Reachable) + " | " +
691
692 "Firing = " +
693 String.valueOf(Firing) + " | " +
694 "";
695
696 }
697
698 public String toHtmlString() {
699 return super.toString() +
700
701 "<b>Id</b> : " +
702 String.valueOf(Id) +
703 " <br/> " +
704
705 "<b>Jmx</b> : " +
706 String.valueOf(Jmx) +
707 " <br/> " +
708
709 "<b>Name</b> : " +
710 String.valueOf(Name) +
711 " <br/> " +
712
713 "<b>Action</b> : " +
714 String.valueOf(Action) +
715 " <br/> " +
716
717 "<b>Visible</b> : " +
718 String.valueOf(Visible) +
719 " <br/> " +
720
721 "<b>Rotation</b> : " +
722 String.valueOf(Rotation) +
723 " <br/> " +
724
725 "<b>Location</b> : " +
726 String.valueOf(Location) +
727 " <br/> " +
728
729 "<b>Velocity</b> : " +
730 String.valueOf(Velocity) +
731 " <br/> " +
732
733 "<b>Team</b> : " +
734 String.valueOf(Team) +
735 " <br/> " +
736
737 "<b>Weapon</b> : " +
738 String.valueOf(Weapon) +
739 " <br/> " +
740
741 "<b>Reachable</b> : " +
742 String.valueOf(Reachable) +
743 " <br/> " +
744
745 "<b>Firing</b> : " +
746 String.valueOf(Firing) +
747 " <br/> " +
748 "";
749 }
750
751
752
753 }
754
755