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 public class
43 Item
44 extends GBObjectUpdate
45
46 implements IGBWorldObjectEvent, IWorldObject, ILocated, IGBViewable, ItemTyped
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 public Item(
89 UnrealId Id, UnrealId NavPointId, NavPoint NavPoint, boolean Visible, Location Location, boolean Reachable, int Amount, ItemType Type, ItemDescriptor Descriptor, boolean Dropped) {
90
91 this.Id = Id;
92
93 this.NavPointId = NavPointId;
94
95 this.NavPoint = NavPoint;
96
97 this.Visible = Visible;
98
99 this.Location = Location;
100
101 this.Reachable = Reachable;
102
103 this.Amount = Amount;
104
105 this.Type = Type;
106
107 this.Descriptor = Descriptor;
108
109 this.Dropped = Dropped;
110
111 }
112
113
114
115 public static final String PROTOTYPE =
116 "INV {Id unreal_id} {NavPointId unreal_id} {Visible False} {Location 0,0,0} {Reachable False} {Amount 0} {Type xWeapons.FlakCannonPickup} {Dropped False}";
117
118
119
120
121
122
123
124
125
126 protected
127 UnrealId Id =
128 null;
129
130
131
132
133
134
135
136 public
137 UnrealId getId() {
138 return
139 Id;
140 }
141
142
143
144
145
146
147
148 protected
149 UnrealId NavPointId =
150 null;
151
152
153
154
155
156
157 public
158 UnrealId getNavPointId() {
159 return
160 NavPointId;
161 }
162
163
164
165
166
167
168
169
170 protected
171 NavPoint NavPoint =
172 null;
173
174
175
176
177
178
179
180 public
181 NavPoint getNavPoint() {
182 return
183 NavPoint;
184 }
185
186
187
188
189
190
191
192 protected
193 boolean Visible =
194 false;
195
196
197
198
199
200
201 public
202 boolean isVisible() {
203 return
204 Visible;
205 }
206
207
208
209
210
211 protected
212 Location Location =
213 null;
214
215
216
217
218 public
219 Location getLocation() {
220 return
221 Location;
222 }
223
224
225
226
227
228 protected
229 boolean Reachable =
230 false;
231
232
233
234
235 public
236 boolean isReachable() {
237 return
238 Reachable;
239 }
240
241
242
243
244
245
246
247
248 protected
249 int Amount =
250 0;
251
252
253
254
255
256
257
258 public
259 int getAmount() {
260 return
261 Amount;
262 }
263
264
265
266
267
268
269
270 protected
271 ItemType Type =
272 null;
273
274
275
276
277
278
279 public
280 ItemType getType() {
281 return
282 Type;
283 }
284
285
286
287
288
289
290
291 protected
292 ItemDescriptor Descriptor =
293 null;
294
295
296
297
298
299
300 public
301 ItemDescriptor getDescriptor() {
302 return
303 Descriptor;
304 }
305
306
307
308
309
310
311
312
313 protected
314 boolean Dropped =
315 false;
316
317
318
319
320
321
322
323 public
324 boolean isDropped() {
325 return
326 Dropped;
327 }
328
329
330
331
332
333
334
335
336
337 protected double Time = 0;
338
339 protected double getTime() {
340 return Time;
341 }
342
343 protected void setTime(double time) {
344 this.Time = time;
345 }
346
347 public double getLastSeenTime() {
348 return Time;
349 }
350
351
352 public ILocalWorldObject getLocal() {
353 return null;
354 }
355
356 public ISharedWorldObject getShared() {
357 return null;
358 }
359
360 public IStaticWorldObject getStatic() {
361 return null;
362 }
363
364 @Override
365 public long getSimTime() {
366 return (long)getLastSeenTime();
367 }
368
369 public boolean equals(Object obj) {
370 if (!(obj instanceof Item)) return false;
371 Item cast = (Item)obj;
372 if (this.getId() != null) return this.getId().equals(cast.getId());
373 else return cast.getId() == null;
374 }
375
376 public int hashCode() {
377 if (getId() != null) return getId().hashCode();
378 return 0;
379 }
380
381
382
383
384
385
386
387
388
389
390
391
392 public void setNavPoint(NavPoint navPoint) {
393 this.NavPoint = navPoint;
394 }
395
396
397
398
399
400
401
402
403
404
405 public Item(Item original) {
406
407 this.Id=original.Id;
408
409 this.NavPointId=original.NavPointId;
410
411 this.NavPoint=original.NavPoint;
412
413 this.Visible=original.Visible;
414
415 this.Location=original.Location;
416
417 this.Reachable=original.Reachable;
418
419 this.Amount=original.Amount;
420
421 this.Type=original.Type;
422
423 this.Descriptor=original.Descriptor;
424
425 this.Dropped=original.Dropped;
426
427 }
428
429
430
431
432
433 public Item() {
434 }
435
436
437
438
439
440 public static class ObjectDisappeared implements IGBWorldObjectDisappeared {
441
442 private IWorldObject orig;
443
444 public ObjectDisappeared(IWorldObject orig) {
445 this.orig = orig;
446 }
447
448 public WorldObjectId getId() {
449 return orig.getId();
450 }
451
452 public long getSimTime() {
453 return 0;
454 }
455
456 public IWorldObjectUpdateResult update(IWorldObject obj) {
457 if (obj == null) {
458 throw new PogamutException("not meant to create new object, probably wanted to update non-existing object of id: " + getId(), this);
459 }
460 if (!(obj instanceof Item)) {
461 throw new PogamutException("can't update object of class " + obj.getClass() + ", meant to update Item", this);
462 }
463 orig = obj;
464 Item toUpdate = (Item)obj;
465 if (toUpdate.Visible) {
466 toUpdate.Visible = false;
467 return new IWorldObjectUpdateResult.WorldObjectUpdateResult(cz.cuni.amis.pogamut.base.communication.translator.event.IWorldObjectUpdateResult.Result.UPDATED, toUpdate);
468 } else {
469 return new IWorldObjectUpdateResult.WorldObjectUpdateResult(cz.cuni.amis.pogamut.base.communication.translator.event.IWorldObjectUpdateResult.Result.SAME, toUpdate);
470 }
471 }
472
473 public IWorldObject getObject() {
474 return orig;
475 }
476
477 public String toString() {
478 return "ObjectDisappeared[" + orig.getClass().getSimpleName() + " " + orig.getId().getStringId() + "]";
479 }
480
481 }
482
483
484
485
486 public Item(Item Original, boolean Visible) {
487 this(Original);
488 this.Visible = Visible;
489 }
490
491 public IGBWorldObjectDisappeared createDisappearEvent() {
492 return new ObjectDisappeared(this);
493 }
494
495
496
497
498
499 private IWorldObject orig = null;
500
501 public IWorldObjectUpdateResult update(IWorldObject obj) {
502 if(obj == null) {
503 orig = this;
504 return new IWorldObjectUpdateResult.WorldObjectUpdateResult(cz.cuni.amis.pogamut.base.communication.translator.event.IWorldObjectUpdateResult.Result.CREATED, this);
505 }
506 orig = obj;
507
508 Item o = (Item)obj;
509
510 boolean updated = false;
511
512
513 if (o.Visible != Visible) {
514 o.Visible=Visible;
515 updated = true;
516 }
517
518 if (o.Reachable != Reachable) {
519 o.Reachable=Reachable;
520 updated = true;
521 }
522
523 o.Time = Time;
524
525
526 if (updated) {
527 return new IWorldObjectUpdateResult.WorldObjectUpdateResult(cz.cuni.amis.pogamut.base.communication.translator.event.IWorldObjectUpdateResult.Result.UPDATED, o);
528 } else {
529 return new IWorldObjectUpdateResult.WorldObjectUpdateResult(cz.cuni.amis.pogamut.base.communication.translator.event.IWorldObjectUpdateResult.Result.SAME, o);
530 }
531 }
532
533
534
535
536
537 public IWorldObject getObject() {
538 if (orig == null) return this;
539 return orig;
540 }
541
542
543
544 public String toString() {
545 return
546
547 super.toString() + " | " +
548
549 "Id = " +
550 String.valueOf(Id) + " | " +
551
552 "NavPointId = " +
553 String.valueOf(NavPointId) + " | " +
554
555 "Visible = " +
556 String.valueOf(Visible) + " | " +
557
558 "Location = " +
559 String.valueOf(Location) + " | " +
560
561 "Reachable = " +
562 String.valueOf(Reachable) + " | " +
563
564 "Amount = " +
565 String.valueOf(Amount) + " | " +
566
567 "Type = " +
568 String.valueOf(Type) + " | " +
569
570 "Dropped = " +
571 String.valueOf(Dropped) + " | " +
572 "";
573
574 }
575
576 public String toHtmlString() {
577 return super.toString() +
578
579 "<b>Id</b> : " +
580 String.valueOf(Id) +
581 " <br/> " +
582
583 "<b>NavPointId</b> : " +
584 String.valueOf(NavPointId) +
585 " <br/> " +
586
587 "<b>NavPoint</b> : " +
588 String.valueOf(NavPoint) +
589 " <br/> " +
590
591 "<b>Visible</b> : " +
592 String.valueOf(Visible) +
593 " <br/> " +
594
595 "<b>Location</b> : " +
596 String.valueOf(Location) +
597 " <br/> " +
598
599 "<b>Reachable</b> : " +
600 String.valueOf(Reachable) +
601 " <br/> " +
602
603 "<b>Amount</b> : " +
604 String.valueOf(Amount) +
605 " <br/> " +
606
607 "<b>Type</b> : " +
608 String.valueOf(Type) +
609 " <br/> " +
610
611 "<b>Descriptor</b> : " +
612 String.valueOf(Descriptor) +
613 " <br/> " +
614
615 "<b>Dropped</b> : " +
616 String.valueOf(Dropped) +
617 " <br/> " +
618 "";
619 }
620
621
622
623 }
624
625