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 ATR.  
19              			
20           *
21           *  <p></p><p></p>
22           *  Complete message documentation:               
23           *  
24  		Synchronous message. Contains the results of automatically
25  		casted rays. One ATR message is for one casted ray. New
26  		automatically casted rays can be defined by ADDRAY command and
27  		removed by REMOVERAY command.
28  	
29           */
30   	public abstract class AutoTraceRay   
31    				extends 
32    				InfoMessage
33    						implements IWorldEvent, IWorldChangeEvent, ICompositeWorldObject
34    						
35  	    {
36   	
37      	/** Example how the message looks like - used during parser tests. */
38      	public static final String PROTOTYPE =
39      		"ATR {Id unreal_id}  {From 0,0,0}  {To 0,0,0}  {FastTrace False}  {FloorCorrection False}  {Result False}  {HitNormal 0,0,0}  {HitLocation 0,0,0}  {TraceActors False}  {HitId unreal_id} ";
40      
41      	
42      	
43      	/**
44      	 * Parameter-less contructor for the message.
45      	 */
46  		public AutoTraceRay()
47  		{
48  		}
49  	
50  				// abstract message, it does not have any more constructors				
51  			
52  	   		
53  			protected long SimTime;
54  				
55  			/**
56  			 * Simulation time in MILLI SECONDS !!!
57  			 */	
58  			@Override
59  			public long getSimTime() {
60  				return SimTime;
61  			}
62  						
63  			/**
64  			 * Used by Yylex to slip correct time of the object or programmatically.
65  			 */
66  			protected void setSimTime(long SimTime) {
67  				this.SimTime = SimTime;
68  			}
69  	   	
70   		/**
71           * 
72  			An Id for this ray (should be unique), assigned by the user
73  			when adding ray.
74  		 
75           */
76          public abstract UnrealId getId()
77   	;
78  		    			
79   		/**
80           * 
81  			Location from which the ray is emitted.
82  		 
83           */
84          public abstract Location getFrom()
85   	;
86  		    			
87   		/**
88           * 
89  			Location to which the ray is sent.
90  		 
91           */
92          public abstract Location getTo()
93   	;
94  		    			
95   		/**
96           * 
97  			True if it is a fast trace, false if not (fast trace is a
98  			bit faster version of UT2004 ray trace - but provides us
99  			with less information - just true/false if we hit something
100 			on the way or not).
101 		 
102          */
103         public abstract boolean isFastTrace()
104  	;
105 		    			
106  		/**
107          * 
108       If we should correct ray directions accoring floor normal. Note: Has issue - we can't set set rays up or down when correction is active.
109 		 
110          */
111         public abstract boolean isFloorCorrection()
112  	;
113 		    			
114  		/**
115          * 
116 			True if it hit something, false if not.
117 		 
118          */
119         public abstract boolean isResult()
120  	;
121 		    			
122  		/**
123          * 
124 			Vector with normal of the plane we have hit (not sent if
125 			FastTrace is True).
126 		 
127          */
128         public abstract Vector3d getHitNormal()
129  	;
130 		    			
131  		/**
132          * 
133 			Vector with location of the collision (not sent if FastTrace
134 			is True).
135 		 
136          */
137         public abstract Location getHitLocation()
138  	;
139 		    			
140  		/**
141          * 
142 			If we traced also actors with this ray (actors – moving
143 			things in a game – bots, players, monsters, pickup …) (only
144 			if NOT using FastTrace)
145 		 
146          */
147         public abstract boolean isTraceActors()
148  	;
149 		    			
150  		/**
151          * 
152 			Id of the actor we have hit. (Sent if FastTrace is False and
153 			TraceActors is True).
154 		 
155          */
156         public abstract UnrealId getHitId()
157  	;
158 		    			
159     	
160     	public static class AutoTraceRayUpdate
161      extends GBObjectUpdate implements ICompositeWorldObjectUpdatedEvent, IGBWorldObjectEvent {	
162 			private AutoTraceRay object;
163 			private long time;
164 			private ITeamId teamId;
165 			
166 			public AutoTraceRayUpdate
167     (AutoTraceRay source, long eventTime, ITeamId teamId) {
168 				this.object = source;
169 				this.time = eventTime;
170 				this.teamId = teamId;
171 			}
172 			
173 			/**
174 			 * Simulation time in MILLI SECONDS !!!
175 			 */ 
176 			@Override
177 			public long getSimTime() {
178 				return time;
179 			}
180 	
181 			@Override
182 			public IWorldObject getObject() {
183 				return object;
184 			}
185 	
186 			@Override
187 			public WorldObjectId getId() {
188 				return object.getId();
189 			}
190 	
191 			@Override
192 			public ILocalWorldObjectUpdatedEvent getLocalEvent() {
193 				return new AutoTraceRayLocalImpl.AutoTraceRayLocalUpdate
194     ((AutoTraceRayLocal)object.getLocal(), time);
195 			}
196 	
197 			@Override
198 			public ISharedWorldObjectUpdatedEvent getSharedEvent() {
199 				return new AutoTraceRaySharedImpl.AutoTraceRaySharedUpdate
200     ((AutoTraceRayShared)object.getShared(), time, teamId);
201 			}
202 	
203 			@Override
204 			public IStaticWorldObjectUpdatedEvent getStaticEvent() {
205 				return new AutoTraceRayStaticImpl.AutoTraceRayStaticUpdate
206     ((AutoTraceRayStatic)object.getStatic(), time);
207 			}
208 			
209 		}
210     
211  		
212  	    public String toString() {
213             return
214             	super.toString() + "[" +
215             	
216 		              			"Id = " + String.valueOf(getId()
217  	) + " | " + 
218 		              		
219 		              			"From = " + String.valueOf(getFrom()
220  	) + " | " + 
221 		              		
222 		              			"To = " + String.valueOf(getTo()
223  	) + " | " + 
224 		              		
225 		              			"FastTrace = " + String.valueOf(isFastTrace()
226  	) + " | " + 
227 		              		
228 		              			"FloorCorrection = " + String.valueOf(isFloorCorrection()
229  	) + " | " + 
230 		              		
231 		              			"Result = " + String.valueOf(isResult()
232  	) + " | " + 
233 		              		
234 		              			"HitNormal = " + String.valueOf(getHitNormal()
235  	) + " | " + 
236 		              		
237 		              			"HitLocation = " + String.valueOf(getHitLocation()
238  	) + " | " + 
239 		              		
240 		              			"TraceActors = " + String.valueOf(isTraceActors()
241  	) + " | " + 
242 		              		
243 		              			"HitId = " + String.valueOf(getHitId()
244  	) + " | " + 
245 		              		
246 				"]";           		
247         }
248  	
249  		
250  		public String toHtmlString() {
251  			return super.toString() + "[<br/>" +
252             	
253 		              			"<b>Id</b> = " + String.valueOf(getId()
254  	) + " <br/> " + 
255 		              		
256 		              			"<b>From</b> = " + String.valueOf(getFrom()
257  	) + " <br/> " + 
258 		              		
259 		              			"<b>To</b> = " + String.valueOf(getTo()
260  	) + " <br/> " + 
261 		              		
262 		              			"<b>FastTrace</b> = " + String.valueOf(isFastTrace()
263  	) + " <br/> " + 
264 		              		
265 		              			"<b>FloorCorrection</b> = " + String.valueOf(isFloorCorrection()
266  	) + " <br/> " + 
267 		              		
268 		              			"<b>Result</b> = " + String.valueOf(isResult()
269  	) + " <br/> " + 
270 		              		
271 		              			"<b>HitNormal</b> = " + String.valueOf(getHitNormal()
272  	) + " <br/> " + 
273 		              		
274 		              			"<b>HitLocation</b> = " + String.valueOf(getHitLocation()
275  	) + " <br/> " + 
276 		              		
277 		              			"<b>TraceActors</b> = " + String.valueOf(isTraceActors()
278  	) + " <br/> " + 
279 		              		
280 		              			"<b>HitId</b> = " + String.valueOf(getHitId()
281  	) + " <br/> " + 
282 		              		
283 				"<br/>]";     
284 		}
285  	
286  	    public String toJsonLiteral() {
287             return "autotraceray( "
288             		+
289 									(getId()
290  	 == null ? "null" :
291 										"\"" + getId()
292  	.getStringId() + "\"" 
293 									)
294 								+ ", " + 
295 								    (getFrom()
296  	 == null ? "null" :
297 										"[" + getFrom()
298  	.getX() + ", " + getFrom()
299  	.getY() + ", " + getFrom()
300  	.getZ() + "]" 
301 									)
302 								+ ", " + 
303 								    (getTo()
304  	 == null ? "null" :
305 										"[" + getTo()
306  	.getX() + ", " + getTo()
307  	.getY() + ", " + getTo()
308  	.getZ() + "]" 
309 									)
310 								+ ", " + 
311 								    String.valueOf(isFastTrace()
312  	)									
313 								+ ", " + 
314 								    String.valueOf(isFloorCorrection()
315  	)									
316 								+ ", " + 
317 								    String.valueOf(isResult()
318  	)									
319 								+ ", " + 
320 									(getHitNormal()
321  	 == null ? "null" :
322 										"[" + getHitNormal()
323  	.getX() + ", " + getHitNormal()
324  	.getY() + ", " + getHitNormal()
325  	.getZ() + "]" 
326 									)
327 								+ ", " + 
328 								    (getHitLocation()
329  	 == null ? "null" :
330 										"[" + getHitLocation()
331  	.getX() + ", " + getHitLocation()
332  	.getY() + ", " + getHitLocation()
333  	.getZ() + "]" 
334 									)
335 								+ ", " + 
336 								    String.valueOf(isTraceActors()
337  	)									
338 								+ ", " + 
339 									(getHitId()
340  	 == null ? "null" :
341 										"\"" + getHitId()
342  	.getStringId() + "\"" 
343 									)
344 								
345                    + ")";
346         }
347  	
348  		
349  		// --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=all]) ---
350         	
351 		// --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=all]) ---
352 		
353 	    // --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=base+classtype[@name=abstract]) ---
354 	        
355 	    // --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=base+classtype[@name=abstract]) ---        	            	
356  	
357 		}
358