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 ALIVE contains also its Local/Shared/Static subpart class definitions..  
19              			
20           *
21           *  <p></p><p></p>
22           *  Complete message documentation:               
23           *  
24  		Synchronous message. Alive message are for confirmation, that
25  		the connection is still working. They are sent periodically with
26  		usual period of one second (this can change depending on the
27  		configuration of ControlServer)
28  	
29           */
30   	public class AliveMessageMessage   
31    				extends 
32    				AliveMessage
33    						implements IWorldObjectUpdatedEvent, ICompositeWorldObjectUpdatedEvent
34    						
35  	    {
36   	
37      	
38      	
39      	/**
40      	 * Parameter-less contructor for the message.
41      	 */
42  		public AliveMessageMessage()
43  		{
44  		}
45  	
46      	
47      	
48      	
49      	/**
50  		 * Creates new instance of the message AliveMessage.
51  		 * 
52  		Synchronous message. Alive message are for confirmation, that
53  		the connection is still working. They are sent periodically with
54  		usual period of one second (this can change depending on the
55  		configuration of ControlServer)
56  	
57  		 * Corresponding GameBots message
58  		 *   
59  		 *   is
60  		 *   ALIVE.
61  		 * 
62   	  	 * 
63  		 *   
64  		 *     @param Time 
65  			Game time when this message was send.
66  		
67  		 *   
68  		 * 
69  		 */
70  		public AliveMessageMessage(
71  			double Time
72  		) {
73  			
74  					this.Time = Time;
75  				
76  		}
77      
78  		/**
79  		 * Cloning constructor from the full message.
80  		 *
81  		 * @param original
82  		 */
83  		public AliveMessageMessage(AliveMessageMessage original) {		
84  			
85  					this.Time = original.getTime()
86   	;
87  				
88  				this.TeamId = original.getTeamId();
89  			
90  			this.SimTime = original.getSimTime();
91  		}
92  		
93  						
94  						public UnrealId getId() {						
95  							return cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.AliveMessage.AliveMessageId;
96  						}
97  					
98      				
99      					protected ITeamId TeamId;
100     					
101     					/**
102     					 * Used by Yylex to slip corretn TeamId.
103     					 */
104     					protected void setTeamId(ITeamId TeamId) {
105     					    this.TeamId = TeamId;
106     					}
107     				
108     					public ITeamId getTeamId() {
109 							return TeamId;
110 						}
111     	
112     					
113     					
114     	
115 	    /**
116          * 
117 			Game time when this message was send.
118 		 
119          */
120         protected
121          double Time =
122        	0;
123 	
124     						
125     						/**
126 		 					 * Whether property 'Time' was received from GB2004.
127 		 					 */
128 							protected boolean Time_Set = false;
129 							
130     						@Override
131 		    				
132  		/**
133          * 
134 			Game time when this message was send.
135 		 
136          */
137         public  double getTime()
138  	 {
139 		    					return Time;
140 		    				}
141 		    			
142 		    			
143 		    			private AliveMessageLocal localPart = null;
144 		    			
145 		    			@Override
146 						public AliveMessageLocal 
147 						getLocal() {
148 							if (localPart != null) return localPart;
149 							return localPart = new 
150 								AliveMessageLocalMessage();
151 						}
152 					
153 						private AliveMessageShared sharedPart = null;
154 					
155 						@Override
156 						public AliveMessageShared 
157 						getShared() {
158 							if (sharedPart != null) return sharedPart;							
159 							return sharedPart = new 
160 								AliveMessageSharedMessage();
161 						}
162 					
163 						private AliveMessageStatic staticPart = null; 
164 					
165 						@Override
166 						public AliveMessageStatic 
167 						getStatic() {
168 							if (staticPart != null) return staticPart;
169 							return staticPart = new 
170 								AliveMessageStaticMessage();
171 						}
172     				
173  		/**
174          *  
175             				Implementation of the local part of the GameBots2004 message ALIVE, used
176             				to facade ALIVEMessage.  
177             			
178          *
179          *  <p></p><p></p>
180          *  Complete message documentation:               
181          *  
182 		Synchronous message. Alive message are for confirmation, that
183 		the connection is still working. They are sent periodically with
184 		usual period of one second (this can change depending on the
185 		configuration of ControlServer)
186 	
187          */
188  	public class AliveMessageLocalMessage 
189 	  					extends
190   						AliveMessageLocal
191 	    {
192  	
193 						
194 						public UnrealId getId() {						
195 							return cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.AliveMessage.AliveMessageId;
196 						}
197 					
198 		    			@Override
199 		    			public 
200 		    			AliveMessageLocalMessage clone() {
201 		    				return this;
202 		    			}
203 		    			
204 		    				public AliveMessageLocalMessage getLocal() {
205 								return this;
206 					    	}
207 							public ISharedWorldObject getShared() {
208 							 	throw new UnsupportedOperationException("Could not return LOCAL as SHARED");
209 							}
210 							public IStaticWorldObject getStatic() {
211 							    throw new UnsupportedOperationException("Could not return LOCAL as STATIC");
212 							}
213 		    			
214  		/**
215          * 
216 			Game time when this message was send.
217 		 
218          */
219         public  double getTime()
220  	 {
221 				    					return Time;
222 				    				}
223 				    			
224  		
225  	    public String toString() {
226             return
227             	super.toString() + "[" +
228             	
229 		              			"Time = " + String.valueOf(getTime()
230  	) + " | " + 
231 		              		
232 				"]";           		
233         }
234  	
235  		
236  		public String toHtmlString() {
237  			return super.toString() + "[<br/>" +
238             	
239 		              			"<b>Time</b> = " + String.valueOf(getTime()
240  	) + " <br/> " + 
241 		              		
242 				"<br/>]";     
243 		}
244  	
245  		
246  		// --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=all]) ---
247         	
248 		// --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=all]) ---
249 		
250 	    // --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=local+classtype[@name=message]) ---
251 	        
252 	    // --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=local+classtype[@name=message]) ---        	            	
253  	
254 		}
255  	
256  		/**
257          *  
258             				Implementation of the static part of the GameBots2004 message ALIVE, used
259             				to facade ALIVEMessage.  
260             			
261          *
262          *  <p></p><p></p>
263          *  Complete message documentation:               
264          *  
265 		Synchronous message. Alive message are for confirmation, that
266 		the connection is still working. They are sent periodically with
267 		usual period of one second (this can change depending on the
268 		configuration of ControlServer)
269 	
270          */
271  	public class AliveMessageStaticMessage 
272 	  					extends
273   						AliveMessageStatic
274 	    {
275  	
276 						
277 						public UnrealId getId() {						
278 							return cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.AliveMessage.AliveMessageId;
279 						}
280 					
281 		    			@Override
282 		    			public 
283 		    			AliveMessageStaticMessage clone() {
284 		    				return this;
285 		    			}
286 		    			
287  		
288  		@Override
289  		public boolean isDifferentFrom(IStaticWorldObject other)
290  		{
291  			if (other == null) //early fail
292  			{
293  				return true;
294  			}
295  			else if (other == this) //early out
296  			{
297  				return false;
298  			}
299  			else
300  			{
301  				AliveMessageStatic obj = (AliveMessageStatic) other;
302 
303  				
304  			}
305  			return false;
306  		}
307  	 
308  		
309  	    public String toString() {
310             return
311             	super.toString() + "[" +
312             	
313 				"]";           		
314         }
315  	
316  		
317  		public String toHtmlString() {
318  			return super.toString() + "[<br/>" +
319             	
320 				"<br/>]";     
321 		}
322  	
323  		
324  		// --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=all]) ---
325         	
326 		// --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=all]) ---
327 		
328 	    // --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=static+classtype[@name=message]) ---
329 	        
330 	    // --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=static+classtype[@name=message]) ---        	            	
331  	
332 		}
333  	
334  		/**
335          *  
336             				Implementation of the shared part of the GameBots2004 message ALIVE, used
337             				to facade ALIVEMessage.  
338             			
339          *
340          *  <p></p><p></p>
341          *  Complete message documentation:               
342          *  
343 		Synchronous message. Alive message are for confirmation, that
344 		the connection is still working. They are sent periodically with
345 		usual period of one second (this can change depending on the
346 		configuration of ControlServer)
347 	
348          */
349  	public class AliveMessageSharedMessage 
350 	  					extends
351   						AliveMessageShared
352 	    {
353  	
354     	
355     	
356 		public AliveMessageSharedMessage()
357 		{
358 			
359 		}		
360     
361 						
362 						public UnrealId getId() {						
363 							return cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.AliveMessage.AliveMessageId;
364 						}
365 					
366 		    			@Override
367 		    			public 
368 		    			AliveMessageSharedMessage clone() {
369 		    				return this;
370 		    			}
371 		    			
372 		
373 		
374 		
375 		protected HashMap<PropertyId, ISharedProperty> propertyMap = new HashMap<PropertyId, ISharedProperty>(
376 			0
377 		);
378 		
379 		@Override
380 		public ISharedProperty getProperty(PropertyId id) {
381 			return propertyMap.get(id);
382 		}
383 
384 		@Override
385 		public Map<PropertyId, ISharedProperty> getProperties() {
386 			return propertyMap;
387 		}
388 	
389 		
390 		
391  		
392  	    public String toString() {
393             return
394             	super.toString() + "[" +
395             	
396 				"]";           		
397         }
398  	
399  		
400  		public String toHtmlString() {
401  			return super.toString() + "[<br/>" +
402             	
403 				"<br/>]";     
404 		}
405  	
406  		
407  		// --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=all]) ---
408         	
409 		// --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=all]) ---
410 		
411 	    // --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=shared+classtype[@name=message]) ---
412 	        
413 	    // --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=shared+classtype[@name=message]) ---        	            	
414  	
415 		}
416  	
417     	
418     	
419  	
420 		@Override
421 		public IWorldObjectUpdateResult<IWorldObject> update(IWorldObject object) {
422 			if (object == null)
423 			{
424 				return new IWorldObjectUpdateResult.WorldObjectUpdateResult(IWorldObjectUpdateResult.Result.CREATED, this);
425 			}
426 			if (!( object instanceof AliveMessageMessage) ) {
427 				throw new PogamutException("Can't update different class than AliveMessageMessage, got class " + object.getClass().getSimpleName() + "!", this);		
428 			}
429 			AliveMessageMessage toUpdate = (AliveMessageMessage)object;
430 			
431 			boolean updated = false;
432 			
433 			// UPDATING LOCAL PROPERTIES
434 			
435 				if (toUpdate.Time != getTime()
436  	) {
437 				    toUpdate.Time=getTime()
438  	;
439 					updated = true;
440 				}
441 			
442          	
443          	// UPDATING SHARED PROPERTIES
444          	
445          	
446          	// UPDATE TIME
447          	toUpdate.SimTime = SimTime;
448 			
449 			if (updated) {
450 				return new IWorldObjectUpdateResult.WorldObjectUpdateResult<IWorldObject>(IWorldObjectUpdateResult.Result.UPDATED, toUpdate);
451 			} else {
452 				return new IWorldObjectUpdateResult.WorldObjectUpdateResult<IWorldObject>(IWorldObjectUpdateResult.Result.SAME, toUpdate);
453 			}
454 		}
455 		
456 		@Override
457 		public ILocalWorldObjectUpdatedEvent getLocalEvent() {
458 			return new AliveMessageLocalImpl.AliveMessageLocalUpdate
459     (this.getLocal(), SimTime);
460 		}
461 
462 		@Override
463 		public ISharedWorldObjectUpdatedEvent getSharedEvent() {
464 			return new AliveMessageSharedImpl.AliveMessageSharedUpdate
465     (this.getShared(), SimTime, this.getTeamId());
466 		}
467 
468 		@Override
469 		public IStaticWorldObjectUpdatedEvent getStaticEvent() {
470 			return new AliveMessageStaticImpl.AliveMessageStaticUpdate
471     (this.getStatic(), SimTime);
472 		}
473  	
474  		
475  	    public String toString() {
476             return
477             	super.toString() + "[" +
478             	
479 		              			"Time = " + String.valueOf(getTime()
480  	) + " | " + 
481 		              		
482 				"]";           		
483         }
484  	
485  		
486  		public String toHtmlString() {
487  			return super.toString() + "[<br/>" +
488             	
489 		              			"<b>Time</b> = " + String.valueOf(getTime()
490  	) + " <br/> " + 
491 		              		
492 				"<br/>]";     
493 		}
494  	
495  		
496  		// --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=all]) ---
497         	
498 		// --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=all]) ---
499 		
500 	    // --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=base+classtype[@name=message]) ---
501 	        
502 	    // --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=base+classtype[@name=message]) ---        	            	
503  	
504 		}
505