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. Movers can be doors, elevators, or any
35  		other chunk of architecture that can move. They generally need
36  		to be either run into, or activated by shooting or pressing a
37  		button. We are working on ways to provide bots with more of the
38  		information they need to deal with movers appropriately.
39  	
40                            Corresponding GameBots message is
41                            MOV.
42                        
43               */
44              
45              public class
46              Mover
47                      extends GBObjectUpdate
48                  
49  	            	implements IGBWorldObjectEvent, IWorldObject, ILocated, ILocomotive, IGBViewable
50  
51              {
52              
53              /**
54                Creates new instance of command Mover.
55                
56  		Synchronous message. Movers can be doors, elevators, or any
57  		other chunk of architecture that can move. They generally need
58  		to be either run into, or activated by shooting or pressing a
59  		button. We are working on ways to provide bots with more of the
60  		information they need to deal with movers appropriately.
61  	Corresponding GameBots message for this command is
62                .
63                    @param Id 
64  			A unique Id of this mover assigned by the game.
65  		
66                    @param Location Location of the mover.
67                    @param Visible If the mover is in the field of view of the bot.
68                    @param Reachable 
69  			True if the bot can run here, false otherwise.
70  		
71                    @param DamageTrig 
72  			True if the mover needs to be shot to be activated.
73  		
74                    @param Type String class of the mover.
75                    @param IsMoving Does the mover move right now?
76                    @param Velocity Velocity vector.
77                    @param MoveTime How long the mover moves, when it becomes triggered, before it stops.
78                    @param OpenTime How long the mover stands still when it reaches its destination position. After
79        this time, the mover returns back to its initial position.
80                    @param BasePos Base position of the mover.
81                    @param BaseRot Base rotation of the mover.
82                    @param DelayTime Delay before starting to open (or before lift starts to move).
83                    @param State Name of the state Mover is currently in. Can be used to determine the type of the mover. 
84                    @param NavPointMarker Navigation point marking this mover. We can parse this Id to get information about type of the mover. Marker Id contains "lift" string if it is a lift, "door" string if it is a door, etc. 
85                */
86               public Mover(
87                  UnrealId Id,  Location Location,  boolean Visible,  boolean Reachable,  boolean DamageTrig,  String Type,  boolean IsMoving,  Velocity Velocity,  double MoveTime,  double OpenTime,  Location BasePos,  Location BaseRot,  double DelayTime,  String State,  UnrealId NavPointMarker) {
88                      
89                      this.Id = Id;
90                  
91                      this.Location = Location;
92                  
93                      this.Visible = Visible;
94                  
95                      this.Reachable = Reachable;
96                  
97                      this.DamageTrig = DamageTrig;
98                  
99                      this.Type = Type;
100                 
101                     this.IsMoving = IsMoving;
102                 
103                     this.Velocity = Velocity;
104                 
105                     this.MoveTime = MoveTime;
106                 
107                     this.OpenTime = OpenTime;
108                 
109                     this.BasePos = BasePos;
110                 
111                     this.BaseRot = BaseRot;
112                 
113                     this.DelayTime = DelayTime;
114                 
115                     this.State = State;
116                 
117                     this.NavPointMarker = NavPointMarker;
118                 
119                 }
120 
121             
122     	/** Example how the message looks like - used during parser tests. */
123     	public static final String PROTOTYPE =
124     		"MOV {Id unreal_id} {Location 0,0,0} {Visible False} {Reachable False} {DamageTrig False} {Type text} {IsMoving False} {Velocity 0,0,0} {MoveTime 0} {OpenTime 0} {BasePos 0,0,0} {BaseRot 0,0,0} {DelayTime 0} {State text} {NavPointMarker unreal_id}";
125     
126 
127             /////// Properties BEGIN
128             
129         /**
130         
131 			A unique Id of this mover assigned by the game.
132 		 */
133         protected
134          UnrealId Id =
135         	null;
136 
137         
138         /**
139         
140 			A unique Id of this mover assigned by the game.
141 		 */
142         public
143         UnrealId getId() {
144             return
145          Id;
146         }
147         
148 
149         
150         /**
151         Location of the mover. */
152         protected
153          Location Location =
154         	null;
155 
156         
157         /**
158         Location of the mover. */
159         public
160         Location getLocation() {
161             return
162          Location;
163         }
164         
165 
166         
167         /**
168         If the mover is in the field of view of the bot. */
169         protected
170          boolean Visible =
171         	false;
172 
173         
174         /**
175         If the mover is in the field of view of the bot. */
176         public
177         boolean isVisible() {
178             return
179          Visible;
180         }
181         
182 
183         
184         /**
185         
186 			True if the bot can run here, false otherwise.
187 		 */
188         protected
189          boolean Reachable =
190         	false;
191 
192         
193         /**
194         
195 			True if the bot can run here, false otherwise.
196 		 */
197         public
198         boolean isReachable() {
199             return
200          Reachable;
201         }
202         
203 
204         
205         /**
206         
207 			True if the mover needs to be shot to be activated.
208 		 */
209         protected
210          boolean DamageTrig =
211         	false;
212 
213         
214         /**
215         
216 			True if the mover needs to be shot to be activated.
217 		 */
218         public
219         boolean isDamageTrig() {
220             return
221          DamageTrig;
222         }
223         
224 
225         
226         /**
227         String class of the mover. */
228         protected
229          String Type =
230         	null;
231 
232         
233         /**
234         String class of the mover. */
235         public
236         String getType() {
237             return
238          Type;
239         }
240         
241 
242         
243         /**
244         Does the mover move right now? */
245         protected
246          boolean IsMoving =
247         	false;
248 
249         
250         /**
251         Does the mover move right now? */
252         public
253         boolean isIsMoving() {
254             return
255          IsMoving;
256         }
257         
258 
259         
260         /**
261         Velocity vector. */
262         protected
263          Velocity Velocity =
264         	null;
265 
266         
267         /**
268         Velocity vector. */
269         public
270         Velocity getVelocity() {
271             return
272          Velocity;
273         }
274         
275 
276         
277         /**
278         How long the mover moves, when it becomes triggered, before it stops. */
279         protected
280          double MoveTime =
281         	0;
282 
283         
284         /**
285         How long the mover moves, when it becomes triggered, before it stops. */
286         public
287         double getMoveTime() {
288             return
289          MoveTime;
290         }
291         
292 
293         
294         /**
295         How long the mover stands still when it reaches its destination position. After
296       this time, the mover returns back to its initial position. */
297         protected
298          double OpenTime =
299         	0;
300 
301         
302         /**
303         How long the mover stands still when it reaches its destination position. After
304       this time, the mover returns back to its initial position. */
305         public
306         double getOpenTime() {
307             return
308          OpenTime;
309         }
310         
311 
312         
313         /**
314         Base position of the mover. */
315         protected
316          Location BasePos =
317         	null;
318 
319         
320         /**
321         Base position of the mover. */
322         public
323         Location getBasePos() {
324             return
325          BasePos;
326         }
327         
328 
329         
330         /**
331         Base rotation of the mover. */
332         protected
333          Location BaseRot =
334         	null;
335 
336         
337         /**
338         Base rotation of the mover. */
339         public
340         Location getBaseRot() {
341             return
342          BaseRot;
343         }
344         
345 
346         
347         /**
348         Delay before starting to open (or before lift starts to move). */
349         protected
350          double DelayTime =
351         	0;
352 
353         
354         /**
355         Delay before starting to open (or before lift starts to move). */
356         public
357         double getDelayTime() {
358             return
359          DelayTime;
360         }
361         
362 
363         
364         /**
365         Name of the state Mover is currently in. Can be used to determine the type of the mover.  */
366         protected
367          String State =
368         	null;
369 
370         
371         /**
372         Name of the state Mover is currently in. Can be used to determine the type of the mover.  */
373         public
374         String getState() {
375             return
376          State;
377         }
378         
379 
380         
381         /**
382         Navigation point marking this mover. We can parse this Id to get information about type of the mover. Marker Id contains "lift" string if it is a lift, "door" string if it is a door, etc.  */
383         protected
384          UnrealId NavPointMarker =
385         	null;
386 
387         
388         /**
389         Navigation point marking this mover. We can parse this Id to get information about type of the mover. Marker Id contains "lift" string if it is a lift, "door" string if it is a door, etc.  */
390         public
391         UnrealId getNavPointMarker() {
392             return
393          NavPointMarker;
394         }
395         
396 
397         
398             /////// Properties END
399 
400             /////// Extra Java code BEGIN
401 
402             	/////// Additional code from xslt BEGIN
403             		
404        							protected double Time = 0;
405 
406        							protected double getTime() {
407        								return Time;
408        							}
409 
410        							protected void setTime(double time) {
411        								this.Time = time;
412        							}
413 
414        							public double getLastSeenTime() {
415        								return Time;
416        							}
417        						
418        					
419        					public ILocalWorldObject getLocal() {
420        						return null;
421        					}
422        					
423        					public ISharedWorldObject getShared() {
424        						return null;
425        					}
426        					
427        					public IStaticWorldObject getStatic() {
428        						return null;
429        					}
430        					
431        					@Override
432        					public long getSimTime() {
433        						return (long)getLastSeenTime();
434        					}
435 
436        					public boolean equals(Object obj) {
437 	                      if (!(obj instanceof Mover)) return false;
438 	                      Mover cast = (Mover)obj;
439 	                      if (this.getId() != null) return this.getId().equals(cast.getId());
440 	                      else return cast.getId() == null;
441 	                    }
442 
443 	                    public int hashCode() {
444 	                      if (getId() != null) return getId().hashCode();
445 	                      return 0;
446 	                    }
447 
448             		
449 
450 
451             	/////// Additional code from xslt END
452 
453 	            /////// Extra Java from XML BEGIN
454             		
455             	/////// Extra Java from XML END
456 
457             /////// Extra Java code END
458 
459             
460 
461             /**
462               * Cloning constructor.
463               */
464              public Mover(Mover original) {
465                 
466                      this.Id=original.Id;
467                 
468                      this.Location=original.Location;
469                 
470                      this.Visible=original.Visible;
471                 
472                      this.Reachable=original.Reachable;
473                 
474                      this.DamageTrig=original.DamageTrig;
475                 
476                      this.Type=original.Type;
477                 
478                      this.IsMoving=original.IsMoving;
479                 
480                      this.Velocity=original.Velocity;
481                 
482                      this.MoveTime=original.MoveTime;
483                 
484                      this.OpenTime=original.OpenTime;
485                 
486                      this.BasePos=original.BasePos;
487                 
488                      this.BaseRot=original.BaseRot;
489                 
490                      this.DelayTime=original.DelayTime;
491                 
492                      this.State=original.State;
493                 
494                      this.NavPointMarker=original.NavPointMarker;
495                 
496              }
497 
498              
499                  /**
500                   * Used by Yylex to create empty message then to fill it's protected fields (Yylex is in the same package).
501                   */
502 	             public Mover() {
503 	             }
504              
505 
506 	    		     /**
507 	    		      * Used to drop Visible flag from the object.
508 	    		      */
509 	    		     public static class ObjectDisappeared implements IGBWorldObjectDisappeared {
510 
511 	    		         private IWorldObject orig;
512 
513 	    		         public ObjectDisappeared(IWorldObject orig) {
514 	    		             this.orig = orig;
515 	    		         }
516 
517 	    		         public WorldObjectId getId() {
518 	    		             return orig.getId();
519 	    		         }
520 	    		         
521 	    		         public long getSimTime() {
522 	    		         	return 0;
523 	    		         }
524 
525                          public IWorldObjectUpdateResult update(IWorldObject obj) {
526                             if (obj == null) {
527                                 throw new PogamutException("not meant to create new object, probably wanted to update non-existing object of id: " + getId(), this);
528                             }
529                             if (!(obj instanceof Mover)) {
530                                 throw new PogamutException("can't update object of class " + obj.getClass() + ", meant to update Mover", this);
531                             }
532                             orig = obj;
533                             Mover toUpdate = (Mover)obj;
534                             if (toUpdate.Visible) {
535 								toUpdate.Visible = false;
536 								return new IWorldObjectUpdateResult.WorldObjectUpdateResult(cz.cuni.amis.pogamut.base.communication.translator.event.IWorldObjectUpdateResult.Result.UPDATED, toUpdate);
537 							} else {
538 								return new IWorldObjectUpdateResult.WorldObjectUpdateResult(cz.cuni.amis.pogamut.base.communication.translator.event.IWorldObjectUpdateResult.Result.SAME, toUpdate);
539 							}
540                          }
541 
542                          public IWorldObject getObject() {
543                             return orig;
544                          }
545 
546                          public String toString() {
547                             return "ObjectDisappeared[" + orig.getClass().getSimpleName() + " " + orig.getId().getStringId() + "]";
548                          }
549 
550 	    		     }
551 
552 	    		     /**
553 	    		      * Used to create event that drops the Visible flag of the item.
554 	    		      */
555 	    		     public Mover(Mover Original, boolean Visible) {
556 	    		         this(Original);
557 	    		         this.Visible = Visible;
558 	    		     }
559 
560 	    		     public IGBWorldObjectDisappeared createDisappearEvent() {
561 	    		         return new ObjectDisappeared(this);
562 	    		     }
563 	    		
564 
565 	    		/**
566 	    		 * Here we save the original object for which this object is an update.
567 	    		 */
568 	    		private IWorldObject orig = null;
569 
570 	            public IWorldObjectUpdateResult update(IWorldObject obj) {
571 		            if(obj == null) {
572 		               orig = this;
573 		               return new IWorldObjectUpdateResult.WorldObjectUpdateResult(cz.cuni.amis.pogamut.base.communication.translator.event.IWorldObjectUpdateResult.Result.CREATED, this);
574 		            }
575 		            orig = obj;
576 		            // typecast
577 		            Mover  o = (Mover)obj;
578 
579 		            boolean updated = false;
580 
581 		            
582                                 if (!SafeEquals.equals(o.Location, Location)) {
583 		    						o.Location=Location;
584 		    						updated = true;
585 		    					}
586                             
587 		    					if (o.Visible != Visible) {
588 		    					    o.Visible=Visible;
589 		    						updated = true;
590 		    					}
591 		    				
592 		    					if (o.Reachable != Reachable) {
593 		    					    o.Reachable=Reachable;
594 		    						updated = true;
595 		    					}
596 		    				
597 		    					if (o.IsMoving != IsMoving) {
598 		    					    o.IsMoving=IsMoving;
599 		    						updated = true;
600 		    					}
601 		    				
602                                 if (!SafeEquals.equals(o.Velocity, Velocity)) {
603 		    						o.Velocity=Velocity;
604 		    						updated = true;
605 		    					}
606                             
607 		    					if (!SafeEquals.equals(o.State, State)) {
608 		    						o.State=State;
609 		    						updated = true;
610 		    					}
611 		    				
612 								o.Time = Time;
613 							
614 
615 		            if (updated) {
616 		                return new IWorldObjectUpdateResult.WorldObjectUpdateResult(cz.cuni.amis.pogamut.base.communication.translator.event.IWorldObjectUpdateResult.Result.UPDATED, o);
617 		            } else {
618 		            	return new IWorldObjectUpdateResult.WorldObjectUpdateResult(cz.cuni.amis.pogamut.base.communication.translator.event.IWorldObjectUpdateResult.Result.SAME, o);
619 		            }
620 		        }
621 
622 	            /**
623 	             * Returns original object (if method update() has already been called, for bot-programmer that is always true
624 	             * as the original object is updated and then the event is propagated).
625 	             */
626 		        public IWorldObject getObject() {
627 		            if (orig == null) return this;
628 		            return orig;
629 		        }
630 	        
631 
632                  
633             public String toString() {
634                 return
635                 
636                 		super.toString() + " | " +
637                 		
638 				               "Id = " +
639 				               String.valueOf(Id) + " | " +
640 				            
641 				               "Location = " +
642 				               String.valueOf(Location) + " | " +
643 				            
644 				               "Visible = " +
645 				               String.valueOf(Visible) + " | " +
646 				            
647 				               "Reachable = " +
648 				               String.valueOf(Reachable) + " | " +
649 				            
650 				               "DamageTrig = " +
651 				               String.valueOf(DamageTrig) + " | " +
652 				            
653 				               "Type = " +
654 				               String.valueOf(Type) + " | " +
655 				            
656 				               "IsMoving = " +
657 				               String.valueOf(IsMoving) + " | " +
658 				            
659 				               "Velocity = " +
660 				               String.valueOf(Velocity) + " | " +
661 				            
662 				               "MoveTime = " +
663 				               String.valueOf(MoveTime) + " | " +
664 				            
665 				               "OpenTime = " +
666 				               String.valueOf(OpenTime) + " | " +
667 				            
668 				               "BasePos = " +
669 				               String.valueOf(BasePos) + " | " +
670 				            
671 				               "BaseRot = " +
672 				               String.valueOf(BaseRot) + " | " +
673 				            
674 				               "DelayTime = " +
675 				               String.valueOf(DelayTime) + " | " +
676 				            
677 				               "State = " +
678 				               String.valueOf(State) + " | " +
679 				            
680 				               "NavPointMarker = " +
681 				               String.valueOf(NavPointMarker) + " | " +
682 				             "";
683                 	
684              }
685 
686              public String toHtmlString() {
687                 return super.toString() +
688             
689             "<b>Id</b> : " +
690             String.valueOf(Id) +
691             " <br/> " +
692             
693             "<b>Location</b> : " +
694             String.valueOf(Location) +
695             " <br/> " +
696             
697             "<b>Visible</b> : " +
698             String.valueOf(Visible) +
699             " <br/> " +
700             
701             "<b>Reachable</b> : " +
702             String.valueOf(Reachable) +
703             " <br/> " +
704             
705             "<b>DamageTrig</b> : " +
706             String.valueOf(DamageTrig) +
707             " <br/> " +
708             
709             "<b>Type</b> : " +
710             String.valueOf(Type) +
711             " <br/> " +
712             
713             "<b>IsMoving</b> : " +
714             String.valueOf(IsMoving) +
715             " <br/> " +
716             
717             "<b>Velocity</b> : " +
718             String.valueOf(Velocity) +
719             " <br/> " +
720             
721             "<b>MoveTime</b> : " +
722             String.valueOf(MoveTime) +
723             " <br/> " +
724             
725             "<b>OpenTime</b> : " +
726             String.valueOf(OpenTime) +
727             " <br/> " +
728             
729             "<b>BasePos</b> : " +
730             String.valueOf(BasePos) +
731             " <br/> " +
732             
733             "<b>BaseRot</b> : " +
734             String.valueOf(BaseRot) +
735             " <br/> " +
736             
737             "<b>DelayTime</b> : " +
738             String.valueOf(DelayTime) +
739             " <br/> " +
740             
741             "<b>State</b> : " +
742             String.valueOf(State) +
743             " <br/> " +
744             
745             "<b>NavPointMarker</b> : " +
746             String.valueOf(NavPointMarker) +
747             " <br/> " +
748              "";
749              }
750 
751              
752              
753              }
754 
755