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=local]+classtype[@name=impl] BEGIN
13  		
14  		// --- IMPORTS FROM extra/code/java/javapart/classcategory[@name=local]+classtype[@name=impl] END
15      
16   		/**
17           *  
18              				Implementation of the local part 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 class AutoTraceRayLocalImpl 
31    						extends
32    						AutoTraceRayLocal
33  	    {
34   	
35      	
36      	
37      	/**
38      	 * Parameter-less contructor for the message.
39      	 */
40  		public AutoTraceRayLocalImpl()
41  		{
42  		}
43  	
44      	
45      	
46      	
47      	/**
48  		 * Creates new instance of the message AutoTraceRay.
49  		 * 
50  		Synchronous message. Contains the results of automatically
51  		casted rays. One ATR message is for one casted ray. New
52  		automatically casted rays can be defined by ADDRAY command and
53  		removed by REMOVERAY command.
54  	
55  		 * Corresponding GameBots message
56  		 *   (local part)
57  		 *   is
58  		 *   ATR.
59  		 * 
60   	  	 * 
61  		 *   
62  		 *     @param Id 
63  			An Id for this ray (should be unique), assigned by the user
64  			when adding ray.
65  		
66  		 *   
67  		 * 
68  		 *   
69  		 *     @param From 
70  			Location from which the ray is emitted.
71  		
72  		 *   
73  		 * 
74  		 *   
75  		 *     @param To 
76  			Location to which the ray is sent.
77  		
78  		 *   
79  		 * 
80  		 *   
81  		 *     @param FastTrace 
82  			True if it is a fast trace, false if not (fast trace is a
83  			bit faster version of UT2004 ray trace - but provides us
84  			with less information - just true/false if we hit something
85  			on the way or not).
86  		
87  		 *   
88  		 * 
89  		 *   
90  		 *     @param FloorCorrection 
91        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.
92  		
93  		 *   
94  		 * 
95  		 *   
96  		 *     @param Result 
97  			True if it hit something, false if not.
98  		
99  		 *   
100 		 * 
101 		 *   
102 		 *     @param HitNormal 
103 			Vector with normal of the plane we have hit (not sent if
104 			FastTrace is True).
105 		
106 		 *   
107 		 * 
108 		 *   
109 		 *     @param HitLocation 
110 			Vector with location of the collision (not sent if FastTrace
111 			is True).
112 		
113 		 *   
114 		 * 
115 		 *   
116 		 *     @param TraceActors 
117 			If we traced also actors with this ray (actors – moving
118 			things in a game – bots, players, monsters, pickup …) (only
119 			if NOT using FastTrace)
120 		
121 		 *   
122 		 * 
123 		 *   
124 		 *     @param HitId 
125 			Id of the actor we have hit. (Sent if FastTrace is False and
126 			TraceActors is True).
127 		
128 		 *   
129 		 * 
130 		 */
131 		public AutoTraceRayLocalImpl(
132 			UnrealId Id,  Location From,  Location To,  boolean FastTrace,  boolean FloorCorrection,  boolean Result,  Vector3d HitNormal,  Location HitLocation,  boolean TraceActors,  UnrealId HitId
133 		) {
134 			
135 					this.Id = Id;
136 				
137 					this.From = From;
138 				
139 					this.To = To;
140 				
141 					this.FastTrace = FastTrace;
142 				
143 					this.FloorCorrection = FloorCorrection;
144 				
145 					this.Result = Result;
146 				
147 					this.HitNormal = HitNormal;
148 				
149 					this.HitLocation = HitLocation;
150 				
151 					this.TraceActors = TraceActors;
152 				
153 					this.HitId = HitId;
154 				
155 		}
156     
157     	/**
158 		 * Cloning constructor from the full message.
159 		 *
160 		 * @param original
161 		 */
162 		public AutoTraceRayLocalImpl(AutoTraceRay original) {		
163 			
164 					this.Id = original.getId()
165  	;
166 				
167 					this.From = original.getFrom()
168  	;
169 				
170 					this.To = original.getTo()
171  	;
172 				
173 					this.FastTrace = original.isFastTrace()
174  	;
175 				
176 					this.FloorCorrection = original.isFloorCorrection()
177  	;
178 				
179 					this.Result = original.isResult()
180  	;
181 				
182 					this.HitNormal = original.getHitNormal()
183  	;
184 				
185 					this.HitLocation = original.getHitLocation()
186  	;
187 				
188 					this.TraceActors = original.isTraceActors()
189  	;
190 				
191 					this.HitId = original.getHitId()
192  	;
193 				
194 			this.SimTime = original.getSimTime();			
195 		}
196 		
197 		/**
198 		 * Cloning constructor from the full message.
199 		 *
200 		 * @param original
201 		 */
202 		public AutoTraceRayLocalImpl(AutoTraceRayLocalImpl original) {		
203 			
204 					this.Id = original.getId()
205  	;
206 				
207 					this.From = original.getFrom()
208  	;
209 				
210 					this.To = original.getTo()
211  	;
212 				
213 					this.FastTrace = original.isFastTrace()
214  	;
215 				
216 					this.FloorCorrection = original.isFloorCorrection()
217  	;
218 				
219 					this.Result = original.isResult()
220  	;
221 				
222 					this.HitNormal = original.getHitNormal()
223  	;
224 				
225 					this.HitLocation = original.getHitLocation()
226  	;
227 				
228 					this.TraceActors = original.isTraceActors()
229  	;
230 				
231 					this.HitId = original.getHitId()
232  	;
233 				
234 			this.SimTime = original.getSimTime();
235 		}
236 		
237 			/**
238 			 * Cloning constructor from the message part.
239 			 *
240 			 * @param original
241 			 */
242 			public AutoTraceRayLocalImpl(AutoTraceRayLocal original) {
243 				
244 						this.Id = original.getId()
245  	;
246 					
247 						this.From = original.getFrom()
248  	;
249 					
250 						this.To = original.getTo()
251  	;
252 					
253 						this.FastTrace = original.isFastTrace()
254  	;
255 					
256 						this.FloorCorrection = original.isFloorCorrection()
257  	;
258 					
259 						this.Result = original.isResult()
260  	;
261 					
262 						this.HitNormal = original.getHitNormal()
263  	;
264 					
265 						this.HitLocation = original.getHitLocation()
266  	;
267 					
268 						this.TraceActors = original.isTraceActors()
269  	;
270 					
271 						this.HitId = original.getHitId()
272  	;
273 					
274 			}
275 		
276    				
277    				@Override
278    				public void setSimTime(long SimTime) {
279 					super.setSimTime(SimTime);
280 				}
281    			
282 	    				@Override
283 	    				public 
284 	    				AutoTraceRayLocalImpl clone() {
285 	    					return new 
286 	    					AutoTraceRayLocalImpl(this);
287 	    				}
288 	    				
289 	    				
290     	
291 	    /**
292          * 
293 			An Id for this ray (should be unique), assigned by the user
294 			when adding ray.
295 		 
296          */
297         protected
298          UnrealId Id =
299        	null;
300 	
301  		/**
302          * 
303 			An Id for this ray (should be unique), assigned by the user
304 			when adding ray.
305 		 
306          */
307         public  UnrealId getId()
308  	 {
309 				    					return Id;
310 				    				}
311 				    			
312     	
313 	    /**
314          * 
315 			Location from which the ray is emitted.
316 		 
317          */
318         protected
319          Location From =
320        	null;
321 	
322  		/**
323          * 
324 			Location from which the ray is emitted.
325 		 
326          */
327         public  Location getFrom()
328  	 {
329 				    					return From;
330 				    				}
331 				    			
332     	
333 	    /**
334          * 
335 			Location to which the ray is sent.
336 		 
337          */
338         protected
339          Location To =
340        	null;
341 	
342  		/**
343          * 
344 			Location to which the ray is sent.
345 		 
346          */
347         public  Location getTo()
348  	 {
349 				    					return To;
350 				    				}
351 				    			
352     	
353 	    /**
354          * 
355 			True if it is a fast trace, false if not (fast trace is a
356 			bit faster version of UT2004 ray trace - but provides us
357 			with less information - just true/false if we hit something
358 			on the way or not).
359 		 
360          */
361         protected
362          boolean FastTrace =
363        	false;
364 	
365  		/**
366          * 
367 			True if it is a fast trace, false if not (fast trace is a
368 			bit faster version of UT2004 ray trace - but provides us
369 			with less information - just true/false if we hit something
370 			on the way or not).
371 		 
372          */
373         public  boolean isFastTrace()
374  	 {
375 				    					return FastTrace;
376 				    				}
377 				    			
378     	
379 	    /**
380          * 
381       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.
382 		 
383          */
384         protected
385          boolean FloorCorrection =
386        	false;
387 	
388  		/**
389          * 
390       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.
391 		 
392          */
393         public  boolean isFloorCorrection()
394  	 {
395 				    					return FloorCorrection;
396 				    				}
397 				    			
398     	
399 	    /**
400          * 
401 			True if it hit something, false if not.
402 		 
403          */
404         protected
405          boolean Result =
406        	false;
407 	
408  		/**
409          * 
410 			True if it hit something, false if not.
411 		 
412          */
413         public  boolean isResult()
414  	 {
415 				    					return Result;
416 				    				}
417 				    			
418     	
419 	    /**
420          * 
421 			Vector with normal of the plane we have hit (not sent if
422 			FastTrace is True).
423 		 
424          */
425         protected
426          Vector3d HitNormal =
427        	null;
428 	
429  		/**
430          * 
431 			Vector with normal of the plane we have hit (not sent if
432 			FastTrace is True).
433 		 
434          */
435         public  Vector3d getHitNormal()
436  	 {
437 				    					return HitNormal;
438 				    				}
439 				    			
440     	
441 	    /**
442          * 
443 			Vector with location of the collision (not sent if FastTrace
444 			is True).
445 		 
446          */
447         protected
448          Location HitLocation =
449        	null;
450 	
451  		/**
452          * 
453 			Vector with location of the collision (not sent if FastTrace
454 			is True).
455 		 
456          */
457         public  Location getHitLocation()
458  	 {
459 				    					return HitLocation;
460 				    				}
461 				    			
462     	
463 	    /**
464          * 
465 			If we traced also actors with this ray (actors – moving
466 			things in a game – bots, players, monsters, pickup …) (only
467 			if NOT using FastTrace)
468 		 
469          */
470         protected
471          boolean TraceActors =
472        	false;
473 	
474  		/**
475          * 
476 			If we traced also actors with this ray (actors – moving
477 			things in a game – bots, players, monsters, pickup …) (only
478 			if NOT using FastTrace)
479 		 
480          */
481         public  boolean isTraceActors()
482  	 {
483 				    					return TraceActors;
484 				    				}
485 				    			
486     	
487 	    /**
488          * 
489 			Id of the actor we have hit. (Sent if FastTrace is False and
490 			TraceActors is True).
491 		 
492          */
493         protected
494          UnrealId HitId =
495        	null;
496 	
497  		/**
498          * 
499 			Id of the actor we have hit. (Sent if FastTrace is False and
500 			TraceActors is True).
501 		 
502          */
503         public  UnrealId getHitId()
504  	 {
505 				    					return HitId;
506 				    				}
507 				    			
508     	
509     	
510     	
511     	
512     	public AutoTraceRayLocalImpl getLocal() {
513 			return this;
514     	}
515 		public ISharedWorldObject getShared() {
516 		 	throw new UnsupportedOperationException("Could not return LOCAL as SHARED");
517 		}
518 		public IStaticWorldObject getStatic() {
519 		    throw new UnsupportedOperationException("Could not return LOCAL as STATIC");
520 		}
521  	
522 		public static class AutoTraceRayLocalUpdate
523      implements ILocalWorldObjectUpdatedEvent, IGBWorldObjectEvent
524 		{
525 			protected long time;
526 			
527 			protected AutoTraceRayLocal data = null; //contains object data for this update
528 			
529 			public AutoTraceRayLocalUpdate
530     (AutoTraceRayLocal moverLocal, long time)
531 			{
532 				this.data = moverLocal;
533 				this.time = time;
534 			}
535 			
536 			@Override
537 			public IWorldObjectUpdateResult<ILocalWorldObject> update(
538 					ILocalWorldObject object) 
539 			{
540 				if ( object == null)
541 				{
542 					data = new AutoTraceRayLocalImpl(data); //we always return Impl object
543 					return new IWorldObjectUpdateResult.WorldObjectUpdateResult<ILocalWorldObject>(IWorldObjectUpdateResult.Result.CREATED, data);
544 				}
545 				if ( object instanceof AutoTraceRayLocalImpl )
546 				{
547 					AutoTraceRayLocalImpl toUpdate = (AutoTraceRayLocalImpl)object;
548 					
549 					boolean updated = false;
550 					
551 					// UPDATING LOCAL PROPERTIES
552 					
553 	            if (!SafeEquals.equals(toUpdate.From, data.getFrom()
554  	)) {
555 					toUpdate.From=data.getFrom()
556  	;
557 					updated = true;
558 				}
559 			
560 	            if (!SafeEquals.equals(toUpdate.To, data.getTo()
561  	)) {
562 					toUpdate.To=data.getTo()
563  	;
564 					updated = true;
565 				}
566 			
567 				if (toUpdate.FastTrace != data.isFastTrace()
568  	) {
569 				    toUpdate.FastTrace=data.isFastTrace()
570  	;
571 					updated = true;
572 				}
573 			
574 				if (toUpdate.FloorCorrection != data.isFloorCorrection()
575  	) {
576 				    toUpdate.FloorCorrection=data.isFloorCorrection()
577  	;
578 					updated = true;
579 				}
580 			
581 				if (toUpdate.Result != data.isResult()
582  	) {
583 				    toUpdate.Result=data.isResult()
584  	;
585 					updated = true;
586 				}
587 			
588 				if (!SafeEquals.equals(toUpdate.HitNormal, data.getHitNormal()
589  	)) {
590 					toUpdate.HitNormal=data.getHitNormal()
591  	;
592 					updated = true;
593 				}
594 			
595 	            if (!SafeEquals.equals(toUpdate.HitLocation, data.getHitLocation()
596  	)) {
597 					toUpdate.HitLocation=data.getHitLocation()
598  	;
599 					updated = true;
600 				}
601 			
602 				if (toUpdate.TraceActors != data.isTraceActors()
603  	) {
604 				    toUpdate.TraceActors=data.isTraceActors()
605  	;
606 					updated = true;
607 				}
608 			
609 				if (!SafeEquals.equals(toUpdate.HitId, data.getHitId()
610  	)) {
611 					toUpdate.HitId=data.getHitId()
612  	;
613 					updated = true;
614 				}
615 			
616 					
617 					data = toUpdate; //the updating has finished
618 					
619 					if ( updated )
620 					{
621 						toUpdate.SimTime = this.time;
622 						return new IWorldObjectUpdateResult.WorldObjectUpdateResult<ILocalWorldObject>(IWorldObjectUpdateResult.Result.UPDATED, data);
623 					}
624 					
625 					return new IWorldObjectUpdateResult.WorldObjectUpdateResult<ILocalWorldObject>(IWorldObjectUpdateResult.Result.SAME, data);
626 				}
627 				throw new PogamutException("Unsupported object type for update. Expected AutoTraceRayLocalImpl for object " + object.getId() +", not object of class " + object.getClass().getSimpleName() + ".", this);
628 			}
629 	
630 			/**
631 			 * Simulation time in MILLI SECONDS !!!
632 			 */
633 			@Override
634 			public long getSimTime() {
635 				return this.time;
636 			}
637 	
638 			@Override
639 			public IWorldObject getObject() {
640 				return data;
641 			}
642 	
643 			@Override
644 			public WorldObjectId getId() {
645 				return data.getId();
646 			}
647 			
648 		}	
649  	
650  		
651  	    public String toString() {
652             return
653             	super.toString() + "[" +
654             	
655 		              			"Id = " + String.valueOf(getId()
656  	) + " | " + 
657 		              		
658 		              			"From = " + String.valueOf(getFrom()
659  	) + " | " + 
660 		              		
661 		              			"To = " + String.valueOf(getTo()
662  	) + " | " + 
663 		              		
664 		              			"FastTrace = " + String.valueOf(isFastTrace()
665  	) + " | " + 
666 		              		
667 		              			"FloorCorrection = " + String.valueOf(isFloorCorrection()
668  	) + " | " + 
669 		              		
670 		              			"Result = " + String.valueOf(isResult()
671  	) + " | " + 
672 		              		
673 		              			"HitNormal = " + String.valueOf(getHitNormal()
674  	) + " | " + 
675 		              		
676 		              			"HitLocation = " + String.valueOf(getHitLocation()
677  	) + " | " + 
678 		              		
679 		              			"TraceActors = " + String.valueOf(isTraceActors()
680  	) + " | " + 
681 		              		
682 		              			"HitId = " + String.valueOf(getHitId()
683  	) + " | " + 
684 		              		
685 				"]";           		
686         }
687  	
688  		
689  		public String toHtmlString() {
690  			return super.toString() + "[<br/>" +
691             	
692 		              			"<b>Id</b> = " + String.valueOf(getId()
693  	) + " <br/> " + 
694 		              		
695 		              			"<b>From</b> = " + String.valueOf(getFrom()
696  	) + " <br/> " + 
697 		              		
698 		              			"<b>To</b> = " + String.valueOf(getTo()
699  	) + " <br/> " + 
700 		              		
701 		              			"<b>FastTrace</b> = " + String.valueOf(isFastTrace()
702  	) + " <br/> " + 
703 		              		
704 		              			"<b>FloorCorrection</b> = " + String.valueOf(isFloorCorrection()
705  	) + " <br/> " + 
706 		              		
707 		              			"<b>Result</b> = " + String.valueOf(isResult()
708  	) + " <br/> " + 
709 		              		
710 		              			"<b>HitNormal</b> = " + String.valueOf(getHitNormal()
711  	) + " <br/> " + 
712 		              		
713 		              			"<b>HitLocation</b> = " + String.valueOf(getHitLocation()
714  	) + " <br/> " + 
715 		              		
716 		              			"<b>TraceActors</b> = " + String.valueOf(isTraceActors()
717  	) + " <br/> " + 
718 		              		
719 		              			"<b>HitId</b> = " + String.valueOf(getHitId()
720  	) + " <br/> " + 
721 		              		
722 				"<br/>]";     
723 		}
724  	
725  		
726  		// --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=all]) ---
727         	
728 		// --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=all]) ---
729 		
730 	    // --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=local+classtype[@name=impl]) ---
731 	        
732 	    // --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=local+classtype[@name=impl]) ---        	            	
733  	
734 		}
735