1
2 /**
3 IMPORTANT !!!
4
5 DO NOT EDIT THIS FILE. IT IS GENERATED FROM approriate xml file in xmlresources/gbinfomessages BY
6 THE JavaClassesGenerator.xslt. MODIFY THESE FILES INSTEAD OF THIS ONE.
7
8 IMPORTANT END !!!
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 Synchronous message. Holds vehicles we see. Id for vehicles doesn't work, so
35 this message is without Id. We can join vehicles by ENTER command if we are
36 close enough - ussually 100 ut units or less. Note: Vehicle support is
37 in alpha testing right now.
38
39 Corresponding GameBots message is
40 VEH.
41
42 */
43
44 public class
45 Vehicle
46 extends GBObjectUpdate
47
48 implements IGBWorldObjectEvent, IWorldObject, ILocated, ILocomotive, IRotable, IGBViewable
49
50 {
51
52 /**
53 Creates new instance of command Vehicle.
54
55 Synchronous message. Holds vehicles we see. Id for vehicles doesn't work, so
56 this message is without Id. We can join vehicles by ENTER command if we are
57 close enough - ussually 100 ut units or less. Note: Vehicle support is
58 in alpha testing right now.
59 Corresponding GameBots message for this command is
60 .
61 @param Id Unique Id of the vehicle or vehicle part.
62 @param Rotation
63 Which direction the vehicle is facing in absolute terms.
64
65 @param Location
66 An absolute location of the vehicle within the map.
67
68 @param Velocity
69 Absolute velocity of the vehicle as a vector of movement per one
70 game second.
71
72 @param Visible
73 If the vehicle is in the field of view of the bot.
74
75 @param Team
76 What team the vehicle is on. 255 is no team. 0-3 are red,
77 blue, green, gold in that order.
78
79 @param Health
80 How much health the vehicle has left. Ranges from 0 to x, depending on the vehicle type.
81
82 @param Armor
83 How much the vehicle has left. Note: This may be 0 all the time. Maybe the vehicles are not supporting armor.
84
85 @param Driver Unique Id of the driver - if any.
86 @param TeamLocked
87 If the vehicle is locked just for its current team.
88
89 @param Type
90 Class of the vehicle. If it is a car, turret etc.
91
92 */
93 public Vehicle(
94 UnrealId Id, Rotation Rotation, Location Location, Velocity Velocity, boolean Visible, int Team, int Health, int Armor, UnrealId Driver, boolean TeamLocked, String Type) {
95
96 this.Id = Id;
97
98 this.Rotation = Rotation;
99
100 this.Location = Location;
101
102 this.Velocity = Velocity;
103
104 this.Visible = Visible;
105
106 this.Team = Team;
107
108 this.Health = Health;
109
110 this.Armor = Armor;
111
112 this.Driver = Driver;
113
114 this.TeamLocked = TeamLocked;
115
116 this.Type = Type;
117
118 }
119
120
121 /** Example how the message looks like - used during parser tests. */
122 public static final String PROTOTYPE =
123 "VEH {Id unreal_id} {Rotation 0,0,0} {Location 0,0,0} {Velocity 0,0,0} {Visible False} {Team 0} {Health 0} {Armor 0} {Driver unreal_id} {TeamLocked False} {Type text}";
124
125
126 /////// Properties BEGIN
127
128 /**
129 Unique Id of the vehicle or vehicle part. */
130 protected
131 UnrealId Id =
132 null;
133
134
135 /**
136 Unique Id of the vehicle or vehicle part. */
137 public
138 UnrealId getId() {
139 return
140 Id;
141 }
142
143
144
145 /**
146
147 Which direction the vehicle is facing in absolute terms.
148 */
149 protected
150 Rotation Rotation =
151 null;
152
153
154 /**
155
156 Which direction the vehicle is facing in absolute terms.
157 */
158 public
159 Rotation getRotation() {
160 return
161 Rotation;
162 }
163
164
165
166 /**
167
168 An absolute location of the vehicle within the map.
169 */
170 protected
171 Location Location =
172 null;
173
174
175 /**
176
177 An absolute location of the vehicle within the map.
178 */
179 public
180 Location getLocation() {
181 return
182 Location;
183 }
184
185
186
187 /**
188
189 Absolute velocity of the vehicle as a vector of movement per one
190 game second.
191 */
192 protected
193 Velocity Velocity =
194 null;
195
196
197 /**
198
199 Absolute velocity of the vehicle as a vector of movement per one
200 game second.
201 */
202 public
203 Velocity getVelocity() {
204 return
205 Velocity;
206 }
207
208
209
210 /**
211
212 If the vehicle is in the field of view of the bot.
213 */
214 protected
215 boolean Visible =
216 false;
217
218
219 /**
220
221 If the vehicle is in the field of view of the bot.
222 */
223 public
224 boolean isVisible() {
225 return
226 Visible;
227 }
228
229
230
231 /**
232
233 What team the vehicle is on. 255 is no team. 0-3 are red,
234 blue, green, gold in that order.
235 */
236 protected
237 int Team =
238 0;
239
240
241 /**
242
243 What team the vehicle is on. 255 is no team. 0-3 are red,
244 blue, green, gold in that order.
245 */
246 public
247 int getTeam() {
248 return
249 Team;
250 }
251
252
253
254 /**
255
256 How much health the vehicle has left. Ranges from 0 to x, depending on the vehicle type.
257 */
258 protected
259 int Health =
260 0;
261
262
263 /**
264
265 How much health the vehicle has left. Ranges from 0 to x, depending on the vehicle type.
266 */
267 public
268 int getHealth() {
269 return
270 Health;
271 }
272
273
274
275 /**
276
277 How much the vehicle has left. Note: This may be 0 all the time. Maybe the vehicles are not supporting armor.
278 */
279 protected
280 int Armor =
281 0;
282
283
284 /**
285
286 How much the vehicle has left. Note: This may be 0 all the time. Maybe the vehicles are not supporting armor.
287 */
288 public
289 int getArmor() {
290 return
291 Armor;
292 }
293
294
295
296 /**
297 Unique Id of the driver - if any. */
298 protected
299 UnrealId Driver =
300 null;
301
302
303 /**
304 Unique Id of the driver - if any. */
305 public
306 UnrealId getDriver() {
307 return
308 Driver;
309 }
310
311
312
313 /**
314
315 If the vehicle is locked just for its current team.
316 */
317 protected
318 boolean TeamLocked =
319 false;
320
321
322 /**
323
324 If the vehicle is locked just for its current team.
325 */
326 public
327 boolean isTeamLocked() {
328 return
329 TeamLocked;
330 }
331
332
333
334 /**
335
336 Class of the vehicle. If it is a car, turret etc.
337 */
338 protected
339 String Type =
340 null;
341
342
343 /**
344
345 Class of the vehicle. If it is a car, turret etc.
346 */
347 public
348 String getType() {
349 return
350 Type;
351 }
352
353
354
355 /////// Properties END
356
357 /////// Extra Java code BEGIN
358
359 /////// Additional code from xslt BEGIN
360
361 protected double Time = 0;
362
363 protected double getTime() {
364 return Time;
365 }
366
367 protected void setTime(double time) {
368 this.Time = time;
369 }
370
371 public double getLastSeenTime() {
372 return Time;
373 }
374
375
376 public ILocalWorldObject getLocal() {
377 return null;
378 }
379
380 public ISharedWorldObject getShared() {
381 return null;
382 }
383
384 public IStaticWorldObject getStatic() {
385 return null;
386 }
387
388 @Override
389 public long getSimTime() {
390 return (long)getLastSeenTime();
391 }
392
393 public boolean equals(Object obj) {
394 if (!(obj instanceof Vehicle)) return false;
395 Vehicle cast = (Vehicle)obj;
396 if (this.getId() != null) return this.getId().equals(cast.getId());
397 else return cast.getId() == null;
398 }
399
400 public int hashCode() {
401 if (getId() != null) return getId().hashCode();
402 return 0;
403 }
404
405
406
407
408 /////// Additional code from xslt END
409
410 /////// Extra Java from XML BEGIN
411
412 /////// Extra Java from XML END
413
414 /////// Extra Java code END
415
416
417
418 /**
419 * Cloning constructor.
420 */
421 public Vehicle(Vehicle original) {
422
423 this.Id=original.Id;
424
425 this.Rotation=original.Rotation;
426
427 this.Location=original.Location;
428
429 this.Velocity=original.Velocity;
430
431 this.Visible=original.Visible;
432
433 this.Team=original.Team;
434
435 this.Health=original.Health;
436
437 this.Armor=original.Armor;
438
439 this.Driver=original.Driver;
440
441 this.TeamLocked=original.TeamLocked;
442
443 this.Type=original.Type;
444
445 }
446
447
448 /**
449 * Used by Yylex to create empty message then to fill it's protected fields (Yylex is in the same package).
450 */
451 public Vehicle() {
452 }
453
454
455 /**
456 * Used to drop Visible flag from the object.
457 */
458 public static class ObjectDisappeared implements IGBWorldObjectDisappeared {
459
460 private IWorldObject orig;
461
462 public ObjectDisappeared(IWorldObject orig) {
463 this.orig = orig;
464 }
465
466 public WorldObjectId getId() {
467 return orig.getId();
468 }
469
470 public long getSimTime() {
471 return 0;
472 }
473
474 public IWorldObjectUpdateResult update(IWorldObject obj) {
475 if (obj == null) {
476 throw new PogamutException("not meant to create new object, probably wanted to update non-existing object of id: " + getId(), this);
477 }
478 if (!(obj instanceof Vehicle)) {
479 throw new PogamutException("can't update object of class " + obj.getClass() + ", meant to update Vehicle", this);
480 }
481 orig = obj;
482 Vehicle toUpdate = (Vehicle)obj;
483 if (toUpdate.Visible) {
484 toUpdate.Visible = false;
485 return new IWorldObjectUpdateResult.WorldObjectUpdateResult(cz.cuni.amis.pogamut.base.communication.translator.event.IWorldObjectUpdateResult.Result.UPDATED, toUpdate);
486 } else {
487 return new IWorldObjectUpdateResult.WorldObjectUpdateResult(cz.cuni.amis.pogamut.base.communication.translator.event.IWorldObjectUpdateResult.Result.SAME, toUpdate);
488 }
489 }
490
491 public IWorldObject getObject() {
492 return orig;
493 }
494
495 public String toString() {
496 return "ObjectDisappeared[" + orig.getClass().getSimpleName() + " " + orig.getId().getStringId() + "]";
497 }
498
499 }
500
501 /**
502 * Used to create event that drops the Visible flag of the item.
503 */
504 public Vehicle(Vehicle Original, boolean Visible) {
505 this(Original);
506 this.Visible = Visible;
507 }
508
509 public IGBWorldObjectDisappeared createDisappearEvent() {
510 return new ObjectDisappeared(this);
511 }
512
513
514 /**
515 * Here we save the original object for which this object is an update.
516 */
517 private IWorldObject orig = null;
518
519 public IWorldObjectUpdateResult update(IWorldObject obj) {
520 if(obj == null) {
521 orig = this;
522 return new IWorldObjectUpdateResult.WorldObjectUpdateResult(cz.cuni.amis.pogamut.base.communication.translator.event.IWorldObjectUpdateResult.Result.CREATED, this);
523 }
524 orig = obj;
525 // typecast
526 Vehicle o = (Vehicle)obj;
527
528 boolean updated = false;
529
530
531 if (!SafeEquals.equals(o.Rotation, Rotation)) {
532 o.Rotation=Rotation;
533 updated = true;
534 }
535
536 if (!SafeEquals.equals(o.Location, Location)) {
537 o.Location=Location;
538 updated = true;
539 }
540
541 if (!SafeEquals.equals(o.Velocity, Velocity)) {
542 o.Velocity=Velocity;
543 updated = true;
544 }
545
546 if (o.Visible != Visible) {
547 o.Visible=Visible;
548 updated = true;
549 }
550
551 if (o.Team != Team) {
552 o.Team=Team;
553 updated = true;
554 }
555
556 if (o.Health != Health) {
557 o.Health=Health;
558 updated = true;
559 }
560
561 if (o.Armor != Armor) {
562 o.Armor=Armor;
563 updated = true;
564 }
565
566 if (!SafeEquals.equals(o.Driver, Driver)) {
567 o.Driver=Driver;
568 updated = true;
569 }
570
571 o.Time = Time;
572
573
574 if (updated) {
575 return new IWorldObjectUpdateResult.WorldObjectUpdateResult(cz.cuni.amis.pogamut.base.communication.translator.event.IWorldObjectUpdateResult.Result.UPDATED, o);
576 } else {
577 return new IWorldObjectUpdateResult.WorldObjectUpdateResult(cz.cuni.amis.pogamut.base.communication.translator.event.IWorldObjectUpdateResult.Result.SAME, o);
578 }
579 }
580
581 /**
582 * Returns original object (if method update() has already been called, for bot-programmer that is always true
583 * as the original object is updated and then the event is propagated).
584 */
585 public IWorldObject getObject() {
586 if (orig == null) return this;
587 return orig;
588 }
589
590
591
592 public String toString() {
593 return
594
595 super.toString() + " | " +
596
597 "Id = " +
598 String.valueOf(Id) + " | " +
599
600 "Rotation = " +
601 String.valueOf(Rotation) + " | " +
602
603 "Location = " +
604 String.valueOf(Location) + " | " +
605
606 "Velocity = " +
607 String.valueOf(Velocity) + " | " +
608
609 "Visible = " +
610 String.valueOf(Visible) + " | " +
611
612 "Team = " +
613 String.valueOf(Team) + " | " +
614
615 "Health = " +
616 String.valueOf(Health) + " | " +
617
618 "Armor = " +
619 String.valueOf(Armor) + " | " +
620
621 "Driver = " +
622 String.valueOf(Driver) + " | " +
623
624 "TeamLocked = " +
625 String.valueOf(TeamLocked) + " | " +
626
627 "Type = " +
628 String.valueOf(Type) + " | " +
629 "";
630
631 }
632
633 public String toHtmlString() {
634 return super.toString() +
635
636 "<b>Id</b> : " +
637 String.valueOf(Id) +
638 " <br/> " +
639
640 "<b>Rotation</b> : " +
641 String.valueOf(Rotation) +
642 " <br/> " +
643
644 "<b>Location</b> : " +
645 String.valueOf(Location) +
646 " <br/> " +
647
648 "<b>Velocity</b> : " +
649 String.valueOf(Velocity) +
650 " <br/> " +
651
652 "<b>Visible</b> : " +
653 String.valueOf(Visible) +
654 " <br/> " +
655
656 "<b>Team</b> : " +
657 String.valueOf(Team) +
658 " <br/> " +
659
660 "<b>Health</b> : " +
661 String.valueOf(Health) +
662 " <br/> " +
663
664 "<b>Armor</b> : " +
665 String.valueOf(Armor) +
666 " <br/> " +
667
668 "<b>Driver</b> : " +
669 String.valueOf(Driver) +
670 " <br/> " +
671
672 "<b>TeamLocked</b> : " +
673 String.valueOf(TeamLocked) +
674 " <br/> " +
675
676 "<b>Type</b> : " +
677 String.valueOf(Type) +
678 " <br/> " +
679 "";
680 }
681
682
683
684 }
685
686