View Javadoc

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. Contains information about other players in
35  		the game, like their current velocity, position, weapon and
36  		reachability. Only reports those players that are visible.
37  		(within field of view and not occluded).
38  	
39                            Corresponding GameBots message is
40                            PLR.
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                Creates new instance of command Player.
54                
55  		Synchronous message. Contains information about other players in
56  		the game, like their current velocity, position, weapon and
57  		reachability. Only reports those players that are visible.
58  		(within field of view and not occluded).
59  	Corresponding GameBots message for this command is
60                .
61                    @param Id Unique Id of the player.
62                    @param Jmx 
63  			Exported just for control server. Holds jmx address we need to connect to
64              when we want to debug our bot.
65  		
66                    @param Name 
67  			Human readable name of the player.
68  		
69                    @param Action 
70  			Atomic action this bot is doing (BDI).
71  		
72                    @param Visible 
73              If the player is in the field of view of the bot.
74          
75                    @param Rotation 
76  			Which direction the player is facing in absolute terms.
77  		
78                    @param Location 
79  			An absolute location of the player within the map.
80  		
81                    @param Velocity 
82  			Absolute velocity of the player as a vector of movement per one
83  			game second.
84  		
85                    @param Team 
86  			What team the player is on. 255 is no team. 0-3 are red,
87  			blue, green, gold in that order.
88  		
89                    @param Weapon 
90  			Class of the weapon the player is holding. Weapon strings to
91  			look for include: "LinkGun", "RocketLauncher", "RocketLauncher_Content".
92  			TODO: Look if this is all.
93  		
94                    @param Reachable 
95  			True if the bot can run to this other player directly, false
96  			otherwise. Possible reasons for false: pit or obstacle
97  			between the two characters.
98  		
99                    @param Firing 
100 			0 means is not firing, 1 - firing in primary mode, 2 -
101 			firing in secondary mode (alt firing).
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     	/** Example how the message looks like - used during parser tests. */
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             /////// Properties BEGIN
140             
141         /**
142         Unique Id of the player. */
143         protected
144          UnrealId Id =
145         	null;
146 
147         
148         /**
149         Unique Id of the player. */
150         public
151         UnrealId getId() {
152             return
153          Id;
154         }
155         
156 
157         
158         /**
159         
160 			Exported just for control server. Holds jmx address we need to connect to
161             when we want to debug our bot.
162 		 */
163         protected
164          String Jmx =
165         	null;
166 
167         
168         /**
169         
170 			Exported just for control server. Holds jmx address we need to connect to
171             when we want to debug our bot.
172 		 */
173         public
174         String getJmx() {
175             return
176          Jmx;
177         }
178         
179 
180         
181         /**
182         
183 			Human readable name of the player.
184 		 */
185         protected
186          String Name =
187         	null;
188 
189         
190         /**
191         
192 			Human readable name of the player.
193 		 */
194         public
195         String getName() {
196             return
197          Name;
198         }
199         
200 
201         
202         /**
203         
204 			Atomic action this bot is doing (BDI).
205 		 */
206         protected
207          String Action =
208         	null;
209 
210         
211         /**
212         
213 			Atomic action this bot is doing (BDI).
214 		 */
215         public
216         String getAction() {
217             return
218          Action;
219         }
220         
221 
222         
223         /**
224         
225             If the player is in the field of view of the bot.
226          */
227         protected
228          boolean Visible =
229         	true;
230 
231         
232         /**
233         
234             If the player is in the field of view of the bot.
235          */
236         public
237         boolean isVisible() {
238             return
239          Visible;
240         }
241         
242 
243         
244         /**
245         
246 			Which direction the player is facing in absolute terms.
247 		 */
248         protected
249          Rotation Rotation =
250         	null;
251 
252         
253         /**
254         
255 			Which direction the player is facing in absolute terms.
256 		 */
257         public
258         Rotation getRotation() {
259             return
260          Rotation;
261         }
262         
263 
264         
265         /**
266         
267 			An absolute location of the player within the map.
268 		 */
269         protected
270          Location Location =
271         	null;
272 
273         
274         /**
275         
276 			An absolute location of the player within the map.
277 		 */
278         public
279         Location getLocation() {
280             return
281          Location;
282         }
283         
284 
285         
286         /**
287         
288 			Absolute velocity of the player as a vector of movement per one
289 			game second.
290 		 */
291         protected
292          Velocity Velocity =
293         	null;
294 
295         
296         /**
297         
298 			Absolute velocity of the player as a vector of movement per one
299 			game second.
300 		 */
301         public
302         Velocity getVelocity() {
303             return
304          Velocity;
305         }
306         
307 
308         
309         /**
310         
311 			What team the player is on. 255 is no team. 0-3 are red,
312 			blue, green, gold in that order.
313 		 */
314         protected
315          int Team =
316         	0;
317 
318         
319         /**
320         
321 			What team the player is on. 255 is no team. 0-3 are red,
322 			blue, green, gold in that order.
323 		 */
324         public
325         int getTeam() {
326             return
327          Team;
328         }
329         
330 
331         
332         /**
333         
334 			Class of the weapon the player is holding. Weapon strings to
335 			look for include: "LinkGun", "RocketLauncher", "RocketLauncher_Content".
336 			TODO: Look if this is all.
337 		 */
338         protected
339          String Weapon =
340         	null;
341 
342         
343         /**
344         
345 			Class of the weapon the player is holding. Weapon strings to
346 			look for include: "LinkGun", "RocketLauncher", "RocketLauncher_Content".
347 			TODO: Look if this is all.
348 		 */
349         public
350         String getWeapon() {
351             return
352          Weapon;
353         }
354         
355 
356         
357         /**
358         
359 			True if the bot can run to this other player directly, false
360 			otherwise. Possible reasons for false: pit or obstacle
361 			between the two characters.
362 		 */
363         protected
364          boolean Reachable =
365         	false;
366 
367         
368         /**
369         
370 			True if the bot can run to this other player directly, false
371 			otherwise. Possible reasons for false: pit or obstacle
372 			between the two characters.
373 		 */
374         public
375         boolean isReachable() {
376             return
377          Reachable;
378         }
379         
380 
381         
382         /**
383         
384 			0 means is not firing, 1 - firing in primary mode, 2 -
385 			firing in secondary mode (alt firing).
386 		 */
387         protected
388          int Firing =
389         	0;
390 
391         
392         /**
393         
394 			0 means is not firing, 1 - firing in primary mode, 2 -
395 			firing in secondary mode (alt firing).
396 		 */
397         public
398         int getFiring() {
399             return
400          Firing;
401         }
402         
403 
404         
405             /////// Properties END
406 
407             /////// Extra Java code BEGIN
408 
409             	/////// Additional code from xslt BEGIN
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             	/////// Additional code from xslt END
459 
460 	            /////// Extra Java from XML BEGIN
461             		
462             	/////// Extra Java from XML END
463 
464             /////// Extra Java code END
465 
466             
467 
468             /**
469               * Cloning constructor.
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                   * Used by Yylex to create empty message then to fill it's protected fields (Yylex is in the same package).
502                   */
503 	             public Player() {
504 	             }
505              
506 
507 	    		     /**
508 	    		      * Used to drop Visible flag from the object.
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 	    		      * Used to create event that drops the Visible flag of the item.
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 	    		 * Here we save the original object for which this object is an update.
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 		            // typecast
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 	             * Returns original object (if method update() has already been called, for bot-programmer that is always true
645 	             * as the original object is updated and then the event is propagated).
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