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=shared]+classtype[@name=impl] BEGIN
13  		
14  		// --- IMPORTS FROM extra/code/java/javapart/classcategory[@name=shared]+classtype[@name=impl] END
15      
16   		/**
17           *  
18              				Implementation of the shared part of the GameBots2004 message PRJ.  
19              			
20           *
21           *  <p></p><p></p>
22           *  Complete message documentation:               
23           *  
24  		Both asynchronous and synchronous message. Incoming projectile that we can see.
25  	
26           */
27   	public class IncomingProjectileSharedImpl 
28    						extends
29    						IncomingProjectileShared
30  	    {
31   	
32      
33      	
34      	public IncomingProjectileSharedImpl(IncomingProjectileSharedImpl source) {
35  			
36  				this.Id = source.
37  					getId()
38   	;
39  			
40  				this.myDirection = source.myDirection;
41  			
42  				this.myLocation = source.myLocation;
43  			
44  				this.myVelocity = source.myVelocity;
45  			
46  				this.mySpeed = source.mySpeed;
47  			
48  				this.myOrigin = source.myOrigin;
49  			
50  				this.myDamageRadius = source.myDamageRadius;
51  			
52  				this.myType = source.myType;
53  			
54  		}
55  		
56  		public IncomingProjectileSharedImpl(WorldObjectId objectId, Collection<ISharedProperty> properties) {
57  			this.Id = (UnrealId)objectId;
58  			NullCheck.check(this.Id, "objectId");
59  		
60  			if (properties.size() != 7) {
61  				throw new PogamutException("Not enough properties passed to the constructor.", IncomingProjectileSharedImpl.class);
62  			}
63  		
64  			//we have to do some checking in this one to know that we get all properties required
65  			for ( ISharedProperty property : properties ) {
66  				PropertyId pId = property.getPropertyId();
67  				if ( !objectId.equals( property.getObjectId() )) {
68  					//properties for different objects
69  					throw new PogamutException("Trying to create a IncomingProjectileSharedImpl with different WorldObjectId properties : " + 
70  											    this.Id.getStringId() + " / " + property.getObjectId().getStringId() , this);
71  				}
72  				if (!IncomingProjectileShared.SharedPropertyTokens.contains(pId.getPropertyToken())) {
73  				// property that does not belong here
74  				throw new PogamutException("Trying to create a IncomingProjectileSharedImpl with invalid property (invalid property token): " + 
75  					this.Id.getStringId() + " / " + property.getPropertyId().getPropertyToken().getToken() , this);
76  				}
77  				propertyMap.put(property.getPropertyId(), property);
78  				
79  				
80  					if (pId.getPropertyToken().getToken().equals("Direction"))
81  					{
82  						this.myDirection = (Vector3dProperty)property;
83  					}
84  				
85  					if (pId.getPropertyToken().getToken().equals("Location"))
86  					{
87  						this.myLocation = (LocationProperty)property;
88  					}
89  				
90  					if (pId.getPropertyToken().getToken().equals("Velocity"))
91  					{
92  						this.myVelocity = (VelocityProperty)property;
93  					}
94  				
95  					if (pId.getPropertyToken().getToken().equals("Speed"))
96  					{
97  						this.mySpeed = (DoubleProperty)property;
98  					}
99  				
100 					if (pId.getPropertyToken().getToken().equals("Origin"))
101 					{
102 						this.myOrigin = (LocationProperty)property;
103 					}
104 				
105 					if (pId.getPropertyToken().getToken().equals("DamageRadius"))
106 					{
107 						this.myDamageRadius = (DoubleProperty)property;
108 					}
109 				
110 					if (pId.getPropertyToken().getToken().equals("Type"))
111 					{
112 						this.myType = (StringProperty)property;
113 					}
114 				
115 			}
116 		}
117     
118    				
119    				@Override
120    				public void setSimTime(long SimTime) {
121 					super.setSimTime(SimTime);
122 				}
123    			
124 	    				@Override
125 	    				public 
126 	    				IncomingProjectileSharedImpl clone() {
127 	    					return new 
128 	    					IncomingProjectileSharedImpl(this);
129 	    				}
130 	    				
131 	    				
132 		
133 		
134 		
135 		protected HashMap<PropertyId, ISharedProperty> propertyMap = new HashMap<PropertyId, ISharedProperty>(
136 			7
137 		);
138 		
139 		@Override
140 		public ISharedProperty getProperty(PropertyId id) {
141 			return propertyMap.get(id);
142 		}
143 
144 		@Override
145 		public Map<PropertyId, ISharedProperty> getProperties() {
146 			return propertyMap;
147 		}
148 	
149 		
150 		
151     	
152 	    /**
153          * Unique Id of the projectile. 
154          */
155         protected
156          UnrealId Id =
157        	null;
158 	
159  		/**
160          * Unique Id of the projectile. 
161          */
162         public  UnrealId getId()
163  	 {
164   			return Id;
165   		}
166   		
167     	
168 	    /**
169          * 
170 			Which direction projectile is heading to -> orientation
171 			vector.
172 		 
173          */
174         protected
175          Vector3dProperty 
176         myDirection
177 					= null;
178 					
179 					
180  		/**
181          * 
182 			Which direction projectile is heading to -> orientation
183 			vector.
184 		 
185          */
186         public  Vector3d getDirection()
187  	 {
188 			  			return myDirection.getValue();
189 			  		}
190 				
191     	
192 	    /**
193          * 
194 			Current location of the projectile.
195 		 
196          */
197         protected
198          LocationProperty 
199         myLocation
200 					= null;
201 					
202 					
203  		/**
204          * 
205 			Current location of the projectile.
206 		 
207          */
208         public  Location getLocation()
209  	 {
210 			  			return myLocation.getValue();
211 			  		}
212 				
213     	
214 	    /**
215          * 
216 			Current velocity vector of the projectile.
217 		 
218          */
219         protected
220          VelocityProperty 
221         myVelocity
222 					= null;
223 					
224 					
225  		/**
226          * 
227 			Current velocity vector of the projectile.
228 		 
229          */
230         public  Velocity getVelocity()
231  	 {
232 			  			return myVelocity.getValue();
233 			  		}
234 				
235     	
236 	    /**
237          * 
238 			Current speed of the projectile.
239 		 
240          */
241         protected
242          DoubleProperty 
243         mySpeed
244 					= null;
245 					
246 					
247  		/**
248          * 
249 			Current speed of the projectile.
250 		 
251          */
252         public  double getSpeed()
253  	 {
254 			  			return mySpeed.getValue();
255 			  		}
256 				
257     	
258 	    /**
259          * 
260 			Possition of the origin, when combined with direction can
261 			define the line of fire.
262 		 
263          */
264         protected
265          LocationProperty 
266         myOrigin
267 					= null;
268 					
269 					
270  		/**
271          * 
272 			Possition of the origin, when combined with direction can
273 			define the line of fire.
274 		 
275          */
276         public  Location getOrigin()
277  	 {
278 			  			return myOrigin.getValue();
279 			  		}
280 				
281     	
282 	    /**
283          * 
284 			If the projectile has splash damage, how big it is – in ut
285 			units.
286 		 
287          */
288         protected
289          DoubleProperty 
290         myDamageRadius
291 					= null;
292 					
293 					
294  		/**
295          * 
296 			If the projectile has splash damage, how big it is – in ut
297 			units.
298 		 
299          */
300         public  double getDamageRadius()
301  	 {
302 			  			return myDamageRadius.getValue();
303 			  		}
304 				
305     	
306 	    /**
307          * 
308 			The class of the projectile (so you know what is flying
309 			against you).
310 		 
311          */
312         protected
313          StringProperty 
314         myType
315 					= null;
316 					
317 					
318  		/**
319          * 
320 			The class of the projectile (so you know what is flying
321 			against you).
322 		 
323          */
324         public  String getType()
325  	 {
326 			  			return myType.getValue();
327 			  		}
328 				
329     	
330     	
331     	public static class IncomingProjectileSharedUpdate
332      implements ISharedWorldObjectUpdatedEvent
333 		{
334 	
335 			private IncomingProjectileShared object;
336 			private long time;
337 			private ITeamId teamId;
338 			
339 			public IncomingProjectileSharedUpdate
340     (IncomingProjectileShared data, long time, ITeamId teamId)
341 			{
342 				this.object = data;
343 				this.time = time;
344 				this.teamId = teamId;
345 			}
346 			
347 			/**
348 			 * Simulation time in MILLI SECONDS !!!
349 			 */
350 			@Override
351 			public long getSimTime() {
352 				return this.time;
353 			}
354 	
355 			@Override
356 			public WorldObjectId getId() {
357 				return object.getId();
358 			}
359 	
360 			@Override
361 			public ITeamId getTeamId() {
362 				return teamId;
363 			}
364 			
365 			@Override
366 			public Class getCompositeObjectClass()
367 			{
368 				return object.getCompositeClass();
369 			}
370 	
371 			@Override
372 			public Collection<ISharedPropertyUpdatedEvent> getPropertyEvents() {
373 				LinkedList<ISharedPropertyUpdatedEvent> events = new LinkedList<ISharedPropertyUpdatedEvent>();
374 				
375 				for ( ISharedProperty property : object.getProperties().values() )
376 				{
377 					if ( property != null)
378 					{
379 						events.push( property.createUpdateEvent(time, teamId) );
380 					}
381 				}
382 				return events;
383 			}
384 			
385 		}
386 	
387     
388  		
389  	    public String toString() {
390             return
391             	super.toString() + "[" +
392             	
393 		              			"Id = " + String.valueOf(getId()
394  	) + " | " + 
395 		              		
396 		              			"Direction = " + String.valueOf(getDirection()
397  	) + " | " + 
398 		              		
399 		              			"Location = " + String.valueOf(getLocation()
400  	) + " | " + 
401 		              		
402 		              			"Velocity = " + String.valueOf(getVelocity()
403  	) + " | " + 
404 		              		
405 		              			"Speed = " + String.valueOf(getSpeed()
406  	) + " | " + 
407 		              		
408 		              			"Origin = " + String.valueOf(getOrigin()
409  	) + " | " + 
410 		              		
411 		              			"DamageRadius = " + String.valueOf(getDamageRadius()
412  	) + " | " + 
413 		              		
414 		              			"Type = " + String.valueOf(getType()
415  	) + " | " + 
416 		              		
417 				"]";           		
418         }
419  	
420  		
421  		public String toHtmlString() {
422  			return super.toString() + "[<br/>" +
423             	
424 		              			"<b>Id</b> = " + String.valueOf(getId()
425  	) + " <br/> " + 
426 		              		
427 		              			"<b>Direction</b> = " + String.valueOf(getDirection()
428  	) + " <br/> " + 
429 		              		
430 		              			"<b>Location</b> = " + String.valueOf(getLocation()
431  	) + " <br/> " + 
432 		              		
433 		              			"<b>Velocity</b> = " + String.valueOf(getVelocity()
434  	) + " <br/> " + 
435 		              		
436 		              			"<b>Speed</b> = " + String.valueOf(getSpeed()
437  	) + " <br/> " + 
438 		              		
439 		              			"<b>Origin</b> = " + String.valueOf(getOrigin()
440  	) + " <br/> " + 
441 		              		
442 		              			"<b>DamageRadius</b> = " + String.valueOf(getDamageRadius()
443  	) + " <br/> " + 
444 		              		
445 		              			"<b>Type</b> = " + String.valueOf(getType()
446  	) + " <br/> " + 
447 		              		
448 				"<br/>]";     
449 		}
450  	
451  		
452  		// --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=all]) ---
453         	
454 		// --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=all]) ---
455 		
456 	    // --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=shared+classtype[@name=impl]) ---
457 	        
458 	    // --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=shared+classtype[@name=impl]) ---        	            	
459  	
460 		}
461