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=base]+classtype[@name=message] BEGIN
13  		
14  		// --- IMPORTS FROM extra/code/java/javapart/classcategory[@name=base]+classtype[@name=message] END
15      
16   		/**
17           *  
18               				Implementation of the GameBots2004 message UPD contains also its Local/Shared/Static subpart class definitions..  
19              			
20           *
21           *  <p></p><p></p>
22           *  Complete message documentation:               
23           *  
24  		"Synchronous" message. Arrives outside sync. batch. The frequency of this message is configured through locUpdateMultiplier variable in GameBots2004.ini file. It gets exported N times faster than regular sync. batch where N equals locUpdateMultiplier. Holds information about Location, Velocity and Rotation of the bot and should help us to create more robust navigation.
25  	
26           */
27   	public class LocationUpdateMessage   
28    				extends 
29    				LocationUpdate
30    						implements IWorldObjectUpdatedEvent, ICompositeWorldObjectUpdatedEvent
31    						
32  	    {
33   	
34      	
35      	
36      	/**
37      	 * Parameter-less contructor for the message.
38      	 */
39  		public LocationUpdateMessage()
40  		{
41  		}
42  	
43      	
44      	
45      	
46      	/**
47  		 * Creates new instance of the message LocationUpdate.
48  		 * 
49  		"Synchronous" message. Arrives outside sync. batch. The frequency of this message is configured through locUpdateMultiplier variable in GameBots2004.ini file. It gets exported N times faster than regular sync. batch where N equals locUpdateMultiplier. Holds information about Location, Velocity and Rotation of the bot and should help us to create more robust navigation.
50  	
51  		 * Corresponding GameBots message
52  		 *   
53  		 *   is
54  		 *   UPD.
55  		 * 
56   	  	 * 
57  		 *   
58  		 *     @param Id Unique Id of this update message instance.
59  		 *   
60  		 * 
61  		 *   
62  		 *     @param Loc 
63  			An absolute location of the bot.
64  		
65  		 *   
66  		 * 
67  		 *   
68  		 *     @param Vel 
69  			Absolute velocity of the bot as a vector of movement per one
70  			game second.
71  		
72  		 *   
73  		 * 
74  		 *   
75  		 *     @param Rot 
76  			Which direction the bot is facing in absolute terms.
77  		
78  		 *   
79  		 * 
80  		 */
81  		public LocationUpdateMessage(
82  			UnrealId Id,  Location Loc,  Velocity Vel,  Rotation Rot
83  		) {
84  			
85  					this.Id = Id;
86  				
87  					this.Loc = Loc;
88  				
89  					this.Vel = Vel;
90  				
91  					this.Rot = Rot;
92  				
93  		}
94      
95  		/**
96  		 * Cloning constructor from the full message.
97  		 *
98  		 * @param original
99  		 */
100 		public LocationUpdateMessage(LocationUpdateMessage original) {		
101 			
102 					this.Id = original.getId()
103  	;
104 				
105 					this.Loc = original.getLoc()
106  	;
107 				
108 					this.Vel = original.getVel()
109  	;
110 				
111 					this.Rot = original.getRot()
112  	;
113 				
114 				this.TeamId = original.getTeamId();
115 			
116 			this.SimTime = original.getSimTime();
117 		}
118 		
119     				
120     					protected ITeamId TeamId;
121     					
122     					/**
123     					 * Used by Yylex to slip corretn TeamId.
124     					 */
125     					protected void setTeamId(ITeamId TeamId) {
126     					    this.TeamId = TeamId;
127     					}
128     				
129     					public ITeamId getTeamId() {
130 							return TeamId;
131 						}
132     	
133     					
134     					
135     	
136 	    /**
137          * Unique Id of this update message instance. 
138          */
139         protected
140          UnrealId Id =
141        	null;
142 	
143     						
144     						/**
145 		 					 * Whether property 'Id' was received from GB2004.
146 		 					 */
147 							protected boolean Id_Set = false;
148 							
149     						@Override
150 		    				
151  		/**
152          * Unique Id of this update message instance. 
153          */
154         public  UnrealId getId()
155  	 {
156 		    					return Id;
157 		    				}
158 		    			
159     	
160 	    /**
161          * 
162 			An absolute location of the bot.
163 		 
164          */
165         protected
166          Location Loc =
167        	null;
168 	
169     						
170     						/**
171 		 					 * Whether property 'Loc' was received from GB2004.
172 		 					 */
173 							protected boolean Loc_Set = false;
174 							
175     						@Override
176 		    				
177  		/**
178          * 
179 			An absolute location of the bot.
180 		 
181          */
182         public  Location getLoc()
183  	 {
184 		    					return Loc;
185 		    				}
186 		    			
187     	
188 	    /**
189          * 
190 			Absolute velocity of the bot as a vector of movement per one
191 			game second.
192 		 
193          */
194         protected
195          Velocity Vel =
196        	null;
197 	
198     						
199     						/**
200 		 					 * Whether property 'Vel' was received from GB2004.
201 		 					 */
202 							protected boolean Vel_Set = false;
203 							
204     						@Override
205 		    				
206  		/**
207          * 
208 			Absolute velocity of the bot as a vector of movement per one
209 			game second.
210 		 
211          */
212         public  Velocity getVel()
213  	 {
214 		    					return Vel;
215 		    				}
216 		    			
217     	
218 	    /**
219          * 
220 			Which direction the bot is facing in absolute terms.
221 		 
222          */
223         protected
224          Rotation Rot =
225        	null;
226 	
227     						
228     						/**
229 		 					 * Whether property 'Rot' was received from GB2004.
230 		 					 */
231 							protected boolean Rot_Set = false;
232 							
233     						@Override
234 		    				
235  		/**
236          * 
237 			Which direction the bot is facing in absolute terms.
238 		 
239          */
240         public  Rotation getRot()
241  	 {
242 		    					return Rot;
243 		    				}
244 		    			
245 		    			
246 		    			private LocationUpdateLocal localPart = null;
247 		    			
248 		    			@Override
249 						public LocationUpdateLocal 
250 						getLocal() {
251 							if (localPart != null) return localPart;
252 							return localPart = new 
253 								LocationUpdateLocalMessage();
254 						}
255 					
256 						private LocationUpdateShared sharedPart = null;
257 					
258 						@Override
259 						public LocationUpdateShared 
260 						getShared() {
261 							if (sharedPart != null) return sharedPart;							
262 							return sharedPart = new 
263 								LocationUpdateSharedMessage();
264 						}
265 					
266 						private LocationUpdateStatic staticPart = null; 
267 					
268 						@Override
269 						public LocationUpdateStatic 
270 						getStatic() {
271 							if (staticPart != null) return staticPart;
272 							return staticPart = new 
273 								LocationUpdateStaticMessage();
274 						}
275     				
276  		/**
277          *  
278             				Implementation of the local part of the GameBots2004 message UPD, used
279             				to facade UPDMessage.  
280             			
281          *
282          *  <p></p><p></p>
283          *  Complete message documentation:               
284          *  
285 		"Synchronous" message. Arrives outside sync. batch. The frequency of this message is configured through locUpdateMultiplier variable in GameBots2004.ini file. It gets exported N times faster than regular sync. batch where N equals locUpdateMultiplier. Holds information about Location, Velocity and Rotation of the bot and should help us to create more robust navigation.
286 	
287          */
288  	public class LocationUpdateLocalMessage 
289 	  					extends
290   						LocationUpdateLocal
291 	    {
292  	
293 		    			@Override
294 		    			public 
295 		    			LocationUpdateLocalMessage clone() {
296 		    				return this;
297 		    			}
298 		    			
299 		    				public LocationUpdateLocalMessage getLocal() {
300 								return this;
301 					    	}
302 							public ISharedWorldObject getShared() {
303 							 	throw new UnsupportedOperationException("Could not return LOCAL as SHARED");
304 							}
305 							public IStaticWorldObject getStatic() {
306 							    throw new UnsupportedOperationException("Could not return LOCAL as STATIC");
307 							}
308 		    			
309  		/**
310          * Unique Id of this update message instance. 
311          */
312         public  UnrealId getId()
313  	 {
314 				    					return Id;
315 				    				}
316 				    			
317  		/**
318          * 
319 			An absolute location of the bot.
320 		 
321          */
322         public  Location getLoc()
323  	 {
324 				    					return Loc;
325 				    				}
326 				    			
327  		/**
328          * 
329 			Absolute velocity of the bot as a vector of movement per one
330 			game second.
331 		 
332          */
333         public  Velocity getVel()
334  	 {
335 				    					return Vel;
336 				    				}
337 				    			
338  		/**
339          * 
340 			Which direction the bot is facing in absolute terms.
341 		 
342          */
343         public  Rotation getRot()
344  	 {
345 				    					return Rot;
346 				    				}
347 				    			
348  		
349  	    public String toString() {
350             return
351             	super.toString() + "[" +
352             	
353 		              			"Id = " + String.valueOf(getId()
354  	) + " | " + 
355 		              		
356 		              			"Loc = " + String.valueOf(getLoc()
357  	) + " | " + 
358 		              		
359 		              			"Vel = " + String.valueOf(getVel()
360  	) + " | " + 
361 		              		
362 		              			"Rot = " + String.valueOf(getRot()
363  	) + " | " + 
364 		              		
365 				"]";           		
366         }
367  	
368  		
369  		public String toHtmlString() {
370  			return super.toString() + "[<br/>" +
371             	
372 		              			"<b>Id</b> = " + String.valueOf(getId()
373  	) + " <br/> " + 
374 		              		
375 		              			"<b>Loc</b> = " + String.valueOf(getLoc()
376  	) + " <br/> " + 
377 		              		
378 		              			"<b>Vel</b> = " + String.valueOf(getVel()
379  	) + " <br/> " + 
380 		              		
381 		              			"<b>Rot</b> = " + String.valueOf(getRot()
382  	) + " <br/> " + 
383 		              		
384 				"<br/>]";     
385 		}
386  	
387  		
388  		// --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=all]) ---
389         	
390 		// --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=all]) ---
391 		
392 	    // --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=local+classtype[@name=message]) ---
393 	        
394 	    // --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=local+classtype[@name=message]) ---        	            	
395  	
396 		}
397  	
398  		/**
399          *  
400             				Implementation of the static part of the GameBots2004 message UPD, used
401             				to facade UPDMessage.  
402             			
403          *
404          *  <p></p><p></p>
405          *  Complete message documentation:               
406          *  
407 		"Synchronous" message. Arrives outside sync. batch. The frequency of this message is configured through locUpdateMultiplier variable in GameBots2004.ini file. It gets exported N times faster than regular sync. batch where N equals locUpdateMultiplier. Holds information about Location, Velocity and Rotation of the bot and should help us to create more robust navigation.
408 	
409          */
410  	public class LocationUpdateStaticMessage 
411 	  					extends
412   						LocationUpdateStatic
413 	    {
414  	
415 		    			@Override
416 		    			public 
417 		    			LocationUpdateStaticMessage clone() {
418 		    				return this;
419 		    			}
420 		    			
421  		/**
422          * Unique Id of this update message instance. 
423          */
424         public  UnrealId getId()
425  	 {
426 				    					return Id;
427 				    				}
428 				    			
429  		
430  		@Override
431  		public boolean isDifferentFrom(IStaticWorldObject other)
432  		{
433  			if (other == null) //early fail
434  			{
435  				return true;
436  			}
437  			else if (other == this) //early out
438  			{
439  				return false;
440  			}
441  			else
442  			{
443  				LocationUpdateStatic obj = (LocationUpdateStatic) other;
444 
445  				
446  						if ( !(
447  	 			AdvancedEquals.equalsOrNull(this.getId()
448  	, obj.getId()
449  	)
450  	 		) )
451 						{
452 							System.out.println("!!!!!PROPERTY UPDATE ERROR!!!! on property Id on object class LocationUpdateStatic");
453 							return true;
454 						}
455  					
456  			}
457  			return false;
458  		}
459  	 
460  		
461  	    public String toString() {
462             return
463             	super.toString() + "[" +
464             	
465 		              			"Id = " + String.valueOf(getId()
466  	) + " | " + 
467 		              		
468 				"]";           		
469         }
470  	
471  		
472  		public String toHtmlString() {
473  			return super.toString() + "[<br/>" +
474             	
475 		              			"<b>Id</b> = " + String.valueOf(getId()
476  	) + " <br/> " + 
477 		              		
478 				"<br/>]";     
479 		}
480  	
481  		
482  		// --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=all]) ---
483         	
484 		// --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=all]) ---
485 		
486 	    // --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=static+classtype[@name=message]) ---
487 	        
488 	    // --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=static+classtype[@name=message]) ---        	            	
489  	
490 		}
491  	
492  		/**
493          *  
494             				Implementation of the shared part of the GameBots2004 message UPD, used
495             				to facade UPDMessage.  
496             			
497          *
498          *  <p></p><p></p>
499          *  Complete message documentation:               
500          *  
501 		"Synchronous" message. Arrives outside sync. batch. The frequency of this message is configured through locUpdateMultiplier variable in GameBots2004.ini file. It gets exported N times faster than regular sync. batch where N equals locUpdateMultiplier. Holds information about Location, Velocity and Rotation of the bot and should help us to create more robust navigation.
502 	
503          */
504  	public class LocationUpdateSharedMessage 
505 	  					extends
506   						LocationUpdateShared
507 	    {
508  	
509     	
510     	
511 		public LocationUpdateSharedMessage()
512 		{
513 			
514 		}		
515     
516 		    			@Override
517 		    			public 
518 		    			LocationUpdateSharedMessage clone() {
519 		    				return this;
520 		    			}
521 		    			
522 		
523 		
524 		
525 		protected HashMap<PropertyId, ISharedProperty> propertyMap = new HashMap<PropertyId, ISharedProperty>(
526 			0
527 		);
528 		
529 		@Override
530 		public ISharedProperty getProperty(PropertyId id) {
531 			return propertyMap.get(id);
532 		}
533 
534 		@Override
535 		public Map<PropertyId, ISharedProperty> getProperties() {
536 			return propertyMap;
537 		}
538 	
539 		
540 		
541  		/**
542          * Unique Id of this update message instance. 
543          */
544         public  UnrealId getId()
545  	 {
546   			return Id;
547   		}
548   		
549  		
550  	    public String toString() {
551             return
552             	super.toString() + "[" +
553             	
554 		              			"Id = " + String.valueOf(getId()
555  	) + " | " + 
556 		              		
557 				"]";           		
558         }
559  	
560  		
561  		public String toHtmlString() {
562  			return super.toString() + "[<br/>" +
563             	
564 		              			"<b>Id</b> = " + String.valueOf(getId()
565  	) + " <br/> " + 
566 		              		
567 				"<br/>]";     
568 		}
569  	
570  		
571  		// --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=all]) ---
572         	
573 		// --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=all]) ---
574 		
575 	    // --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=shared+classtype[@name=message]) ---
576 	        
577 	    // --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=shared+classtype[@name=message]) ---        	            	
578  	
579 		}
580  	
581     	
582     	
583  	
584 		@Override
585 		public IWorldObjectUpdateResult<IWorldObject> update(IWorldObject object) {
586 			if (object == null)
587 			{
588 				return new IWorldObjectUpdateResult.WorldObjectUpdateResult(IWorldObjectUpdateResult.Result.CREATED, this);
589 			}
590 			if (!( object instanceof LocationUpdateMessage) ) {
591 				throw new PogamutException("Can't update different class than LocationUpdateMessage, got class " + object.getClass().getSimpleName() + "!", this);		
592 			}
593 			LocationUpdateMessage toUpdate = (LocationUpdateMessage)object;
594 			
595 			boolean updated = false;
596 			
597 			// UPDATING LOCAL PROPERTIES
598 			
599 	            if (!SafeEquals.equals(toUpdate.Loc, getLoc()
600  	)) {
601 					toUpdate.Loc=getLoc()
602  	;
603 					updated = true;
604 				}
605 			
606 				if (!SafeEquals.equals(toUpdate.Vel, getVel()
607  	)) {
608 					toUpdate.Vel=getVel()
609  	;
610 					updated = true;
611 				}
612 			
613 				if (!SafeEquals.equals(toUpdate.Rot, getRot()
614  	)) {
615 					toUpdate.Rot=getRot()
616  	;
617 					updated = true;
618 				}
619 			
620          	
621          	// UPDATING SHARED PROPERTIES
622          	
623          	
624          	// UPDATE TIME
625          	toUpdate.SimTime = SimTime;
626 			
627 			if (updated) {
628 				return new IWorldObjectUpdateResult.WorldObjectUpdateResult<IWorldObject>(IWorldObjectUpdateResult.Result.UPDATED, toUpdate);
629 			} else {
630 				return new IWorldObjectUpdateResult.WorldObjectUpdateResult<IWorldObject>(IWorldObjectUpdateResult.Result.SAME, toUpdate);
631 			}
632 		}
633 		
634 		@Override
635 		public ILocalWorldObjectUpdatedEvent getLocalEvent() {
636 			return new LocationUpdateLocalImpl.LocationUpdateLocalUpdate
637     (this.getLocal(), SimTime);
638 		}
639 
640 		@Override
641 		public ISharedWorldObjectUpdatedEvent getSharedEvent() {
642 			return new LocationUpdateSharedImpl.LocationUpdateSharedUpdate
643     (this.getShared(), SimTime, this.getTeamId());
644 		}
645 
646 		@Override
647 		public IStaticWorldObjectUpdatedEvent getStaticEvent() {
648 			return new LocationUpdateStaticImpl.LocationUpdateStaticUpdate
649     (this.getStatic(), SimTime);
650 		}
651  	
652  		
653  	    public String toString() {
654             return
655             	super.toString() + "[" +
656             	
657 		              			"Id = " + String.valueOf(getId()
658  	) + " | " + 
659 		              		
660 		              			"Loc = " + String.valueOf(getLoc()
661  	) + " | " + 
662 		              		
663 		              			"Vel = " + String.valueOf(getVel()
664  	) + " | " + 
665 		              		
666 		              			"Rot = " + String.valueOf(getRot()
667  	) + " | " + 
668 		              		
669 				"]";           		
670         }
671  	
672  		
673  		public String toHtmlString() {
674  			return super.toString() + "[<br/>" +
675             	
676 		              			"<b>Id</b> = " + String.valueOf(getId()
677  	) + " <br/> " + 
678 		              		
679 		              			"<b>Loc</b> = " + String.valueOf(getLoc()
680  	) + " <br/> " + 
681 		              		
682 		              			"<b>Vel</b> = " + String.valueOf(getVel()
683  	) + " <br/> " + 
684 		              		
685 		              			"<b>Rot</b> = " + String.valueOf(getRot()
686  	) + " <br/> " + 
687 		              		
688 				"<br/>]";     
689 		}
690  	
691  		
692  		// --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=all]) ---
693         	
694 		// --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=all]) ---
695 		
696 	    // --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=base+classtype[@name=message]) ---
697 	        
698 	    // --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=base+classtype[@name=message]) ---        	            	
699  	
700 		}
701