View Javadoc

1   package cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages;
2    		
3    		// --- IMPORTS FROM /messages/settings/javasettings/javaimport BEGIN
4   			import java.util.*;import javax.vecmath.*;import cz.cuni.amis.pogamut.base.communication.messages.*;import cz.cuni.amis.pogamut.base.communication.worldview.*;import cz.cuni.amis.pogamut.base.communication.worldview.event.*;import cz.cuni.amis.pogamut.base.communication.worldview.object.*;import cz.cuni.amis.pogamut.multi.communication.worldview.object.*;import cz.cuni.amis.pogamut.base.communication.translator.event.*;import cz.cuni.amis.pogamut.multi.communication.translator.event.*;import cz.cuni.amis.pogamut.base3d.worldview.object.*;import cz.cuni.amis.pogamut.base3d.worldview.object.event.*;import cz.cuni.amis.pogamut.ut2004.communication.messages.*;import cz.cuni.amis.pogamut.ut2004.communication.worldview.objects.*;import cz.cuni.amis.pogamut.ut2004multi.communication.worldview.objects.*;import cz.cuni.amis.pogamut.ut2004.communication.translator.itemdescriptor.*;import cz.cuni.amis.pogamut.ut2004.communication.messages.ItemType.Category;import cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId;import cz.cuni.amis.utils.exception.*;import cz.cuni.amis.pogamut.base.communication.translator.event.IWorldObjectUpdateResult.Result;import cz.cuni.amis.utils.SafeEquals;import cz.cuni.amis.pogamut.base.agent.*;import cz.cuni.amis.pogamut.multi.agent.*;import cz.cuni.amis.pogamut.multi.communication.worldview.property.*;import cz.cuni.amis.pogamut.ut2004multi.communication.worldview.property.*;import cz.cuni.amis.utils.token.*;import cz.cuni.amis.utils.*;
5   		// --- IMPORTS FROM /messages/settings/javasettings/javaimport END
6   		
7   		
8   		// --- IMPORTS FROM extra/code/java/javapart/classcategory[@name='all'] BEGIN
9   				
10  		// --- IMPORTS FROM extra/code/java/javapart/classcategory[@name='all'] END
11  		
12  		// --- IMPORTS FROM extra/code/java/javapart/classcategory[@name=static]+classtype[@name=impl] BEGIN
13  		
14  		// --- IMPORTS FROM extra/code/java/javapart/classcategory[@name=static]+classtype[@name=impl] END
15      
16   		/**
17           *  
18              				Implementation of the static part of the GameBots2004 message MOV.  
19              			
20           *
21           *  <p></p><p></p>
22           *  Complete message documentation:               
23           *  
24  		Synchronous message. Movers can be doors, elevators, or any
25  		other chunk of architecture that can move. They generally need
26  		to be either run into, or activated by shooting or pressing a
27  		button. We are working on ways to provide bots with more of the
28  		information they need to deal with movers appropriately.
29  	
30           */
31   	public class MoverStaticImpl 
32    						extends
33    						MoverStatic
34  	    {
35   	
36      	
37      	
38      	/**
39      	 * Parameter-less contructor for the message.
40      	 */
41  		public MoverStaticImpl()
42  		{
43  		}
44  	
45      	
46      	
47      	
48      	/**
49  		 * Creates new instance of the message Mover.
50  		 * 
51  		Synchronous message. Movers can be doors, elevators, or any
52  		other chunk of architecture that can move. They generally need
53  		to be either run into, or activated by shooting or pressing a
54  		button. We are working on ways to provide bots with more of the
55  		information they need to deal with movers appropriately.
56  	
57  		 * Corresponding GameBots message
58  		 *   (static part)
59  		 *   is
60  		 *   MOV.
61  		 * 
62   	  	 * 
63  		 *   
64  		 *     @param Id 
65  			A unique Id of this mover assigned by the game.
66  		
67  		 *   
68  		 * 
69  		 *   
70  		 * 
71  		 *   
72  		 * 
73  		 *   
74  		 *     @param DamageTrig 
75  			True if the mover needs to be shot to be activated.
76  		
77  		 *   
78  		 * 
79  		 *   
80  		 *     @param Type String class of the mover.
81  		 *   
82  		 * 
83  		 *   
84  		 *     @param IsMoving Does the mover move right now?
85  		 *   
86  		 * 
87  		 *   
88  		 * 
89  		 *   
90  		 *     @param MoveTime How long the mover moves, when it becomes triggered, before it stops.
91  		 *   
92  		 * 
93  		 *   
94  		 *     @param OpenTime How long the mover stands still when it reaches its destination position. After
95        this time, the mover returns back to its initial position.
96  		 *   
97  		 * 
98  		 *   
99  		 *     @param BasePos Base position of the mover.
100 		 *   
101 		 * 
102 		 *   
103 		 *     @param BaseRot Base rotation of the mover.
104 		 *   
105 		 * 
106 		 *   
107 		 *     @param DelayTime Delay before starting to open (or before lift starts to move).
108 		 *   
109 		 * 
110 		 *   
111 		 * 
112 		 *   
113 		 *     @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. 
114 		 *   
115 		 * 
116 		 */
117 		public MoverStaticImpl(
118 			UnrealId Id,  boolean DamageTrig,  String Type,  boolean IsMoving,  double MoveTime,  double OpenTime,  Location BasePos,  Location BaseRot,  double DelayTime,  UnrealId NavPointMarker
119 		) {
120 			
121 					this.Id = Id;
122 				
123 					this.DamageTrig = DamageTrig;
124 				
125 					this.Type = Type;
126 				
127 					this.IsMoving = IsMoving;
128 				
129 					this.MoveTime = MoveTime;
130 				
131 					this.OpenTime = OpenTime;
132 				
133 					this.BasePos = BasePos;
134 				
135 					this.BaseRot = BaseRot;
136 				
137 					this.DelayTime = DelayTime;
138 				
139 					this.NavPointMarker = NavPointMarker;
140 				
141 		}
142     
143     	/**
144 		 * Cloning constructor from the full message.
145 		 *
146 		 * @param original
147 		 */
148 		public MoverStaticImpl(Mover original) {		
149 			
150 					this.Id = original.getId()
151  	;
152 				
153 					this.DamageTrig = original.isDamageTrig()
154  	;
155 				
156 					this.Type = original.getType()
157  	;
158 				
159 					this.IsMoving = original.isIsMoving()
160  	;
161 				
162 					this.MoveTime = original.getMoveTime()
163  	;
164 				
165 					this.OpenTime = original.getOpenTime()
166  	;
167 				
168 					this.BasePos = original.getBasePos()
169  	;
170 				
171 					this.BaseRot = original.getBaseRot()
172  	;
173 				
174 					this.DelayTime = original.getDelayTime()
175  	;
176 				
177 					this.NavPointMarker = original.getNavPointMarker()
178  	;
179 				
180 			this.SimTime = original.getSimTime();			
181 		}
182 		
183 		/**
184 		 * Cloning constructor from the full message.
185 		 *
186 		 * @param original
187 		 */
188 		public MoverStaticImpl(MoverStaticImpl original) {		
189 			
190 					this.Id = original.getId()
191  	;
192 				
193 					this.DamageTrig = original.isDamageTrig()
194  	;
195 				
196 					this.Type = original.getType()
197  	;
198 				
199 					this.IsMoving = original.isIsMoving()
200  	;
201 				
202 					this.MoveTime = original.getMoveTime()
203  	;
204 				
205 					this.OpenTime = original.getOpenTime()
206  	;
207 				
208 					this.BasePos = original.getBasePos()
209  	;
210 				
211 					this.BaseRot = original.getBaseRot()
212  	;
213 				
214 					this.DelayTime = original.getDelayTime()
215  	;
216 				
217 					this.NavPointMarker = original.getNavPointMarker()
218  	;
219 				
220 			this.SimTime = original.getSimTime();
221 		}
222 		
223 			/**
224 			 * Cloning constructor from the message part.
225 			 *
226 			 * @param original
227 			 */
228 			public MoverStaticImpl(MoverStatic original) {
229 				
230 						this.Id = original.getId()
231  	;
232 					
233 						this.DamageTrig = original.isDamageTrig()
234  	;
235 					
236 						this.Type = original.getType()
237  	;
238 					
239 						this.IsMoving = original.isIsMoving()
240  	;
241 					
242 						this.MoveTime = original.getMoveTime()
243  	;
244 					
245 						this.OpenTime = original.getOpenTime()
246  	;
247 					
248 						this.BasePos = original.getBasePos()
249  	;
250 					
251 						this.BaseRot = original.getBaseRot()
252  	;
253 					
254 						this.DelayTime = original.getDelayTime()
255  	;
256 					
257 						this.NavPointMarker = original.getNavPointMarker()
258  	;
259 					
260 			}
261 		
262    				
263    				@Override
264    				public void setSimTime(long SimTime) {
265 					super.setSimTime(SimTime);
266 				}
267    			
268 	    				@Override
269 	    				public 
270 	    				MoverStaticImpl clone() {
271 	    					return new 
272 	    					MoverStaticImpl(this);
273 	    				}
274 	    				
275 	    				
276     	
277 	    /**
278          * 
279 			A unique Id of this mover assigned by the game.
280 		 
281          */
282         protected
283          UnrealId Id =
284        	null;
285 	
286  		/**
287          * 
288 			A unique Id of this mover assigned by the game.
289 		 
290          */
291         public  UnrealId getId()
292  	 {
293 				    					return Id;
294 				    				}
295 				    			
296     	
297 	    /**
298          * 
299 			True if the mover needs to be shot to be activated.
300 		 
301          */
302         protected
303          boolean DamageTrig =
304        	false;
305 	
306  		/**
307          * 
308 			True if the mover needs to be shot to be activated.
309 		 
310          */
311         public  boolean isDamageTrig()
312  	 {
313 				    					return DamageTrig;
314 				    				}
315 				    			
316     	
317 	    /**
318          * String class of the mover. 
319          */
320         protected
321          String Type =
322        	null;
323 	
324  		/**
325          * String class of the mover. 
326          */
327         public  String getType()
328  	 {
329 				    					return Type;
330 				    				}
331 				    			
332     	
333 	    /**
334          * Does the mover move right now? 
335          */
336         protected
337          boolean IsMoving =
338        	false;
339 	
340  		/**
341          * Does the mover move right now? 
342          */
343         public  boolean isIsMoving()
344  	 {
345 				    					return IsMoving;
346 				    				}
347 				    			
348     	
349 	    /**
350          * How long the mover moves, when it becomes triggered, before it stops. 
351          */
352         protected
353          double MoveTime =
354        	0;
355 	
356  		/**
357          * How long the mover moves, when it becomes triggered, before it stops. 
358          */
359         public  double getMoveTime()
360  	 {
361 				    					return MoveTime;
362 				    				}
363 				    			
364     	
365 	    /**
366          * How long the mover stands still when it reaches its destination position. After
367       this time, the mover returns back to its initial position. 
368          */
369         protected
370          double OpenTime =
371        	0;
372 	
373  		/**
374          * How long the mover stands still when it reaches its destination position. After
375       this time, the mover returns back to its initial position. 
376          */
377         public  double getOpenTime()
378  	 {
379 				    					return OpenTime;
380 				    				}
381 				    			
382     	
383 	    /**
384          * Base position of the mover. 
385          */
386         protected
387          Location BasePos =
388        	null;
389 	
390  		/**
391          * Base position of the mover. 
392          */
393         public  Location getBasePos()
394  	 {
395 				    					return BasePos;
396 				    				}
397 				    			
398     	
399 	    /**
400          * Base rotation of the mover. 
401          */
402         protected
403          Location BaseRot =
404        	null;
405 	
406  		/**
407          * Base rotation of the mover. 
408          */
409         public  Location getBaseRot()
410  	 {
411 				    					return BaseRot;
412 				    				}
413 				    			
414     	
415 	    /**
416          * Delay before starting to open (or before lift starts to move). 
417          */
418         protected
419          double DelayTime =
420        	0;
421 	
422  		/**
423          * Delay before starting to open (or before lift starts to move). 
424          */
425         public  double getDelayTime()
426  	 {
427 				    					return DelayTime;
428 				    				}
429 				    			
430     	
431 	    /**
432          * 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.  
433          */
434         protected
435          UnrealId NavPointMarker =
436        	null;
437 	
438  		/**
439          * 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.  
440          */
441         public  UnrealId getNavPointMarker()
442  	 {
443 				    					return NavPointMarker;
444 				    				}
445 				    			
446     	
447     	
448     	public static class MoverStaticUpdate
449      implements IStaticWorldObjectUpdatedEvent
450 		{
451 			
452 			private MoverStatic data;
453 			private long time;
454 			
455 			public MoverStaticUpdate
456     (MoverStatic source, long time)
457 			{
458 				this.data = source;
459 				this.time = time;
460 			}
461 			
462 			/**
463 			 * Simulation time in MILLI SECONDS !!!
464 			 */
465 			@Override
466 			public long getSimTime() {
467 				return time;
468 			}
469 	
470 			@Override
471 			public WorldObjectId getId() {
472 				return data.getId();
473 			}
474 			
475 			@Override
476 			public IWorldObjectUpdateResult<IStaticWorldObject> update(
477 					IStaticWorldObject object) {
478 				if ( object == null)
479 				{
480 					data = new MoverStaticImpl(data);
481 					return new IWorldObjectUpdateResult.WorldObjectUpdateResult<IStaticWorldObject>(IWorldObjectUpdateResult.Result.CREATED, data);
482 				}
483 				//since static objects can't be updated, we'll just check that the object stays the same
484 				if ( object instanceof MoverStaticImpl)
485 				{
486 					MoverStaticImpl orig = (MoverStaticImpl)object;
487 					//since these errors usually mean error in gamebots, we will just print an error message
488 					if ( data.isDifferentFrom(orig) )
489 					{
490 						//data.isDifferentFrom(orig);
491 						//throw new PogamutException("Trying to modify static object " + this.data.getId().toString() , this);
492 						System.out.println("!!!!!ERROR!!!!!! in static object modification. Object class : MoverStaticImpl to see which property was different see !!!!PROPERTY UPDATE ERROR!!!!");
493 					}
494 					return new IWorldObjectUpdateResult.WorldObjectUpdateResult<IStaticWorldObject>(IWorldObjectUpdateResult.Result.SAME, data);
495 				}				
496 				throw new PogamutException("Unexpected object type for update, MoverStaticImpl expected not class " + object.getClass().getSimpleName() + ".", this);
497 			}
498 		}
499 	
500     
501  		
502  		@Override
503  		public boolean isDifferentFrom(IStaticWorldObject other)
504  		{
505  			if (other == null) //early fail
506  			{
507  				return true;
508  			}
509  			else if (other == this) //early out
510  			{
511  				return false;
512  			}
513  			else
514  			{
515  				MoverStatic obj = (MoverStatic) other;
516 
517  				
518  						if ( !(
519  	 			AdvancedEquals.equalsOrNull(this.getId()
520  	, obj.getId()
521  	)
522  	 		) )
523 						{
524 							System.out.println("!!!!!PROPERTY UPDATE ERROR!!!! on property Id on object class MoverStatic");
525 							return true;
526 						}
527  					
528  						if ( !(this.isDamageTrig()
529  	
530  	 			== obj.isDamageTrig()
531  	) )
532 						{
533 							System.out.println("!!!!!PROPERTY UPDATE ERROR!!!! on property DamageTrig on object class MoverStatic");
534 							return true;
535 						}
536  					
537  						if ( !(
538  	 			AdvancedEquals.equalsOrNull(this.getType()
539  	, obj.getType()
540  	)
541  	 		) )
542 						{
543 							System.out.println("!!!!!PROPERTY UPDATE ERROR!!!! on property Type on object class MoverStatic");
544 							return true;
545 						}
546  					
547  						if ( !(this.isIsMoving()
548  	
549  	 			== obj.isIsMoving()
550  	) )
551 						{
552 							System.out.println("!!!!!PROPERTY UPDATE ERROR!!!! on property IsMoving on object class MoverStatic");
553 							return true;
554 						}
555  					
556  						if ( !(this.getMoveTime()
557  	
558  	 			== obj.getMoveTime()
559  	) )
560 						{
561 							System.out.println("!!!!!PROPERTY UPDATE ERROR!!!! on property MoveTime on object class MoverStatic");
562 							return true;
563 						}
564  					
565  						if ( !(this.getOpenTime()
566  	
567  	 			== obj.getOpenTime()
568  	) )
569 						{
570 							System.out.println("!!!!!PROPERTY UPDATE ERROR!!!! on property OpenTime on object class MoverStatic");
571 							return true;
572 						}
573  					
574  						if ( !(
575  	 			AdvancedEquals.equalsOrNull(this.getBasePos()
576  	, obj.getBasePos()
577  	)
578  	 		) )
579 						{
580 							System.out.println("!!!!!PROPERTY UPDATE ERROR!!!! on property BasePos on object class MoverStatic");
581 							return true;
582 						}
583  					
584  						if ( !(
585  	 			AdvancedEquals.equalsOrNull(this.getBaseRot()
586  	, obj.getBaseRot()
587  	)
588  	 		) )
589 						{
590 							System.out.println("!!!!!PROPERTY UPDATE ERROR!!!! on property BaseRot on object class MoverStatic");
591 							return true;
592 						}
593  					
594  						if ( !(this.getDelayTime()
595  	
596  	 			== obj.getDelayTime()
597  	) )
598 						{
599 							System.out.println("!!!!!PROPERTY UPDATE ERROR!!!! on property DelayTime on object class MoverStatic");
600 							return true;
601 						}
602  					
603  						if ( !(
604  	 			AdvancedEquals.equalsOrNull(this.getNavPointMarker()
605  	, obj.getNavPointMarker()
606  	)
607  	 		) )
608 						{
609 							System.out.println("!!!!!PROPERTY UPDATE ERROR!!!! on property NavPointMarker on object class MoverStatic");
610 							return true;
611 						}
612  					
613  			}
614  			return false;
615  		}
616  	 
617  		
618  	    public String toString() {
619             return
620             	super.toString() + "[" +
621             	
622 		              			"Id = " + String.valueOf(getId()
623  	) + " | " + 
624 		              		
625 		              			"DamageTrig = " + String.valueOf(isDamageTrig()
626  	) + " | " + 
627 		              		
628 		              			"Type = " + String.valueOf(getType()
629  	) + " | " + 
630 		              		
631 		              			"IsMoving = " + String.valueOf(isIsMoving()
632  	) + " | " + 
633 		              		
634 		              			"MoveTime = " + String.valueOf(getMoveTime()
635  	) + " | " + 
636 		              		
637 		              			"OpenTime = " + String.valueOf(getOpenTime()
638  	) + " | " + 
639 		              		
640 		              			"BasePos = " + String.valueOf(getBasePos()
641  	) + " | " + 
642 		              		
643 		              			"BaseRot = " + String.valueOf(getBaseRot()
644  	) + " | " + 
645 		              		
646 		              			"DelayTime = " + String.valueOf(getDelayTime()
647  	) + " | " + 
648 		              		
649 		              			"NavPointMarker = " + String.valueOf(getNavPointMarker()
650  	) + " | " + 
651 		              		
652 				"]";           		
653         }
654  	
655  		
656  		public String toHtmlString() {
657  			return super.toString() + "[<br/>" +
658             	
659 		              			"<b>Id</b> = " + String.valueOf(getId()
660  	) + " <br/> " + 
661 		              		
662 		              			"<b>DamageTrig</b> = " + String.valueOf(isDamageTrig()
663  	) + " <br/> " + 
664 		              		
665 		              			"<b>Type</b> = " + String.valueOf(getType()
666  	) + " <br/> " + 
667 		              		
668 		              			"<b>IsMoving</b> = " + String.valueOf(isIsMoving()
669  	) + " <br/> " + 
670 		              		
671 		              			"<b>MoveTime</b> = " + String.valueOf(getMoveTime()
672  	) + " <br/> " + 
673 		              		
674 		              			"<b>OpenTime</b> = " + String.valueOf(getOpenTime()
675  	) + " <br/> " + 
676 		              		
677 		              			"<b>BasePos</b> = " + String.valueOf(getBasePos()
678  	) + " <br/> " + 
679 		              		
680 		              			"<b>BaseRot</b> = " + String.valueOf(getBaseRot()
681  	) + " <br/> " + 
682 		              		
683 		              			"<b>DelayTime</b> = " + String.valueOf(getDelayTime()
684  	) + " <br/> " + 
685 		              		
686 		              			"<b>NavPointMarker</b> = " + String.valueOf(getNavPointMarker()
687  	) + " <br/> " + 
688 		              		
689 				"<br/>]";     
690 		}
691  	
692  		
693  		// --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=all]) ---
694         	
695 		// --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=all]) ---
696 		
697 	    // --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=static+classtype[@name=impl]) ---
698 	        
699 	    // --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=static+classtype[@name=impl]) ---        	            	
700  	
701 		}
702