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