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=abstract] BEGIN
13  		
14  		// --- IMPORTS FROM extra/code/java/javapart/classcategory[@name=base]+classtype[@name=abstract] END
15      
16   		/**
17           *  
18              				Abstract definition 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 abstract class IncomingProjectile   
28    				extends 
29    				InfoMessage
30    						implements IWorldEvent, IWorldChangeEvent, ICompositeWorldObject
31    						
32  	    		,IGBViewable
33  	    		,ILocated
34  	    {
35   	
36      	/** Example how the message looks like - used during parser tests. */
37      	public static final String PROTOTYPE =
38      		"PRJ {Id unreal_id}  {ImpactTime 0}  {Direction 0,0,0}  {Location 0,0,0}  {Velocity 0,0,0}  {Speed 0}  {Origin 0,0,0}  {DamageRadius 0}  {Type text}  {Visible False} ";
39      
40      	
41      	
42      	/**
43      	 * Parameter-less contructor for the message.
44      	 */
45  		public IncomingProjectile()
46  		{
47  		}
48  	
49  				// abstract message, it does not have any more constructors				
50  			
51  	   		
52  			protected long SimTime;
53  				
54  			/**
55  			 * Simulation time in MILLI SECONDS !!!
56  			 */	
57  			@Override
58  			public long getSimTime() {
59  				return SimTime;
60  			}
61  						
62  			/**
63  			 * Used by Yylex to slip correct time of the object or programmatically.
64  			 */
65  			protected void setSimTime(long SimTime) {
66  				this.SimTime = SimTime;
67  			}
68  	   	
69   		/**
70           * Unique Id of the projectile. 
71           */
72          public abstract UnrealId getId()
73   	;
74  		    			
75   		/**
76           * Estimated time till impact. 
77           */
78          public abstract double getImpactTime()
79   	;
80  		    			
81   		/**
82           * 
83  			Which direction projectile is heading to -> orientation
84  			vector.
85  		 
86           */
87          public abstract Vector3d getDirection()
88   	;
89  		    			
90   		/**
91           * 
92  			Current location of the projectile.
93  		 
94           */
95          public abstract Location getLocation()
96   	;
97  		    			
98   		/**
99           * 
100 			Current velocity vector of the projectile.
101 		 
102          */
103         public abstract Velocity getVelocity()
104  	;
105 		    			
106  		/**
107          * 
108 			Current speed of the projectile.
109 		 
110          */
111         public abstract double getSpeed()
112  	;
113 		    			
114  		/**
115          * 
116 			Possition of the origin, when combined with direction can
117 			define the line of fire.
118 		 
119          */
120         public abstract Location getOrigin()
121  	;
122 		    			
123  		/**
124          * 
125 			If the projectile has splash damage, how big it is – in ut
126 			units.
127 		 
128          */
129         public abstract double getDamageRadius()
130  	;
131 		    			
132  		/**
133          * 
134 			The class of the projectile (so you know what is flying
135 			against you).
136 		 
137          */
138         public abstract String getType()
139  	;
140 		    			
141  		/**
142          * 
143 			The class of the projectile (so you know what is flying
144 			against you).
145 		 
146          */
147         public abstract boolean isVisible()
148  	;
149 		    			
150 		 	@Override
151 			public IWorldObjectUpdatedEvent createDisappearEvent() {
152 				return new ObjectDisappeared(this, getSimTime());
153 			}
154 			
155 			public static class ObjectDisappeared implements IWorldObjectUpdatedEvent
156 			{
157 				
158 				public ObjectDisappeared(IncomingProjectile obj, long time) {
159 					this.obj = obj;
160 					this.time = time;
161 				}
162 				
163 				private IncomingProjectile obj;
164 				private long time;
165 		
166 				@Override
167 				public WorldObjectId getId() {
168 					return obj.getId();
169 				}
170 		
171 		        /**
172 		         * Simulation time in MILLI SECONDS !!!
173 		         */
174 				@Override
175 				public long getSimTime() {
176 					return time;
177 				}
178 		
179 				@Override
180 				public IWorldObjectUpdateResult<IWorldObject> update(IWorldObject obj) {
181 					if (obj == null) {
182 						throw new PogamutException("Can't 'disappear' null!", this);
183 					}
184 					if (!(obj instanceof IncomingProjectileMessage)) {
185 						throw new PogamutException("Can't update different class than IncomingProjectileMessage, got class " + obj.getClass().getSimpleName() + "!", this);
186 					}
187 					IncomingProjectileMessage toUpdate = (IncomingProjectileMessage)obj;
188 					if (toUpdate.Visible) {
189 						toUpdate.Visible = false;
190 						return new IWorldObjectUpdateResult.WorldObjectUpdateResult(IWorldObjectUpdateResult.Result.UPDATED, obj);
191 					} else {
192 						return new IWorldObjectUpdateResult.WorldObjectUpdateResult(IWorldObjectUpdateResult.Result.SAME, obj);
193 					}
194 				}
195 		
196 			}
197 	
198 		
199     	
200     	public static class IncomingProjectileUpdate
201      extends GBObjectUpdate implements ICompositeWorldObjectUpdatedEvent, IGBWorldObjectEvent {	
202 			private IncomingProjectile object;
203 			private long time;
204 			private ITeamId teamId;
205 			
206 			public IncomingProjectileUpdate
207     (IncomingProjectile source, long eventTime, ITeamId teamId) {
208 				this.object = source;
209 				this.time = eventTime;
210 				this.teamId = teamId;
211 			}
212 			
213 			/**
214 			 * Simulation time in MILLI SECONDS !!!
215 			 */ 
216 			@Override
217 			public long getSimTime() {
218 				return time;
219 			}
220 	
221 			@Override
222 			public IWorldObject getObject() {
223 				return object;
224 			}
225 	
226 			@Override
227 			public WorldObjectId getId() {
228 				return object.getId();
229 			}
230 	
231 			@Override
232 			public ILocalWorldObjectUpdatedEvent getLocalEvent() {
233 				return new IncomingProjectileLocalImpl.IncomingProjectileLocalUpdate
234     ((IncomingProjectileLocal)object.getLocal(), time);
235 			}
236 	
237 			@Override
238 			public ISharedWorldObjectUpdatedEvent getSharedEvent() {
239 				return new IncomingProjectileSharedImpl.IncomingProjectileSharedUpdate
240     ((IncomingProjectileShared)object.getShared(), time, teamId);
241 			}
242 	
243 			@Override
244 			public IStaticWorldObjectUpdatedEvent getStaticEvent() {
245 				return new IncomingProjectileStaticImpl.IncomingProjectileStaticUpdate
246     ((IncomingProjectileStatic)object.getStatic(), time);
247 			}
248 			
249 		}
250     
251  		
252  	    public String toString() {
253             return
254             	super.toString() + "[" +
255             	
256 		              			"Id = " + String.valueOf(getId()
257  	) + " | " + 
258 		              		
259 		              			"ImpactTime = " + String.valueOf(getImpactTime()
260  	) + " | " + 
261 		              		
262 		              			"Direction = " + String.valueOf(getDirection()
263  	) + " | " + 
264 		              		
265 		              			"Location = " + String.valueOf(getLocation()
266  	) + " | " + 
267 		              		
268 		              			"Velocity = " + String.valueOf(getVelocity()
269  	) + " | " + 
270 		              		
271 		              			"Speed = " + String.valueOf(getSpeed()
272  	) + " | " + 
273 		              		
274 		              			"Origin = " + String.valueOf(getOrigin()
275  	) + " | " + 
276 		              		
277 		              			"DamageRadius = " + String.valueOf(getDamageRadius()
278  	) + " | " + 
279 		              		
280 		              			"Type = " + String.valueOf(getType()
281  	) + " | " + 
282 		              		
283 		              			"Visible = " + String.valueOf(isVisible()
284  	) + " | " + 
285 		              		
286 				"]";           		
287         }
288  	
289  		
290  		public String toHtmlString() {
291  			return super.toString() + "[<br/>" +
292             	
293 		              			"<b>Id</b> = " + String.valueOf(getId()
294  	) + " <br/> " + 
295 		              		
296 		              			"<b>ImpactTime</b> = " + String.valueOf(getImpactTime()
297  	) + " <br/> " + 
298 		              		
299 		              			"<b>Direction</b> = " + String.valueOf(getDirection()
300  	) + " <br/> " + 
301 		              		
302 		              			"<b>Location</b> = " + String.valueOf(getLocation()
303  	) + " <br/> " + 
304 		              		
305 		              			"<b>Velocity</b> = " + String.valueOf(getVelocity()
306  	) + " <br/> " + 
307 		              		
308 		              			"<b>Speed</b> = " + String.valueOf(getSpeed()
309  	) + " <br/> " + 
310 		              		
311 		              			"<b>Origin</b> = " + String.valueOf(getOrigin()
312  	) + " <br/> " + 
313 		              		
314 		              			"<b>DamageRadius</b> = " + String.valueOf(getDamageRadius()
315  	) + " <br/> " + 
316 		              		
317 		              			"<b>Type</b> = " + String.valueOf(getType()
318  	) + " <br/> " + 
319 		              		
320 		              			"<b>Visible</b> = " + String.valueOf(isVisible()
321  	) + " <br/> " + 
322 		              		
323 				"<br/>]";     
324 		}
325  	
326  	    public String toJsonLiteral() {
327             return "incomingprojectile( "
328             		+
329 									(getId()
330  	 == null ? "null" :
331 										"\"" + getId()
332  	.getStringId() + "\"" 
333 									)
334 								+ ", " + 
335 								    String.valueOf(getImpactTime()
336  	)									
337 								+ ", " + 
338 									(getDirection()
339  	 == null ? "null" :
340 										"[" + getDirection()
341  	.getX() + ", " + getDirection()
342  	.getY() + ", " + getDirection()
343  	.getZ() + "]" 
344 									)
345 								+ ", " + 
346 								    (getLocation()
347  	 == null ? "null" :
348 										"[" + getLocation()
349  	.getX() + ", " + getLocation()
350  	.getY() + ", " + getLocation()
351  	.getZ() + "]" 
352 									)
353 								+ ", " + 
354 								    (getVelocity()
355  	 == null ? "null" :
356 										"[" + getVelocity()
357  	.getX() + ", " + getVelocity()
358  	.getY() + ", " + getVelocity()
359  	.getZ() + "]" 
360 									)
361 								+ ", " + 
362 								    String.valueOf(getSpeed()
363  	)									
364 								+ ", " + 
365 								    (getOrigin()
366  	 == null ? "null" :
367 										"[" + getOrigin()
368  	.getX() + ", " + getOrigin()
369  	.getY() + ", " + getOrigin()
370  	.getZ() + "]" 
371 									)
372 								+ ", " + 
373 								    String.valueOf(getDamageRadius()
374  	)									
375 								+ ", " + 
376 									(getType()
377  	 == null ? "null" :
378 										"\"" + getType()
379  	 + "\"" 
380 									)
381 								+ ", " + 
382 								    String.valueOf(isVisible()
383  	)									
384 								
385                    + ")";
386         }
387  	
388  		
389  		// --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=all]) ---
390         	
391 		// --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=all]) ---
392 		
393 	    // --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=base+classtype[@name=abstract]) ---
394 	        
395 	    // --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=base+classtype[@name=abstract]) ---        	            	
396  	
397 		}
398