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 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 IncomingProjectileLocalImpl 
28    						extends
29    						IncomingProjectileLocal
30  	    {
31   	
32      	
33      	
34      	/**
35      	 * Parameter-less contructor for the message.
36      	 */
37  		public IncomingProjectileLocalImpl()
38  		{
39  		}
40  	
41      	
42      	
43      	
44      	/**
45  		 * Creates new instance of the message IncomingProjectile.
46  		 * 
47  		Both asynchronous and synchronous message. Incoming projectile that we can see.
48  	
49  		 * Corresponding GameBots message
50  		 *   (local part)
51  		 *   is
52  		 *   PRJ.
53  		 * 
54   	  	 * 
55  		 *   
56  		 *     @param Id Unique Id of the projectile.
57  		 *   
58  		 * 
59  		 *   
60  		 *     @param ImpactTime Estimated time till impact.
61  		 *   
62  		 * 
63  		 *   
64  		 * 
65  		 *   
66  		 * 
67  		 *   
68  		 * 
69  		 *   
70  		 * 
71  		 *   
72  		 * 
73  		 *   
74  		 * 
75  		 *   
76  		 * 
77  		 *   
78  		 *     @param Visible 
79  			The class of the projectile (so you know what is flying
80  			against you).
81  		
82  		 *   
83  		 * 
84  		 */
85  		public IncomingProjectileLocalImpl(
86  			UnrealId Id,  double ImpactTime,  boolean Visible
87  		) {
88  			
89  					this.Id = Id;
90  				
91  					this.ImpactTime = ImpactTime;
92  				
93  					this.Visible = Visible;
94  				
95  		}
96      
97      	/**
98  		 * Cloning constructor from the full message.
99  		 *
100 		 * @param original
101 		 */
102 		public IncomingProjectileLocalImpl(IncomingProjectile original) {		
103 			
104 					this.Id = original.getId()
105  	;
106 				
107 					this.ImpactTime = original.getImpactTime()
108  	;
109 				
110 					this.Visible = original.isVisible()
111  	;
112 				
113 			this.SimTime = original.getSimTime();			
114 		}
115 		
116 		/**
117 		 * Cloning constructor from the full message.
118 		 *
119 		 * @param original
120 		 */
121 		public IncomingProjectileLocalImpl(IncomingProjectileLocalImpl original) {		
122 			
123 					this.Id = original.getId()
124  	;
125 				
126 					this.ImpactTime = original.getImpactTime()
127  	;
128 				
129 					this.Visible = original.isVisible()
130  	;
131 				
132 			this.SimTime = original.getSimTime();
133 		}
134 		
135 			/**
136 			 * Cloning constructor from the message part.
137 			 *
138 			 * @param original
139 			 */
140 			public IncomingProjectileLocalImpl(IncomingProjectileLocal original) {
141 				
142 						this.Id = original.getId()
143  	;
144 					
145 						this.ImpactTime = original.getImpactTime()
146  	;
147 					
148 						this.Visible = original.isVisible()
149  	;
150 					
151 			}
152 		
153    				
154    				@Override
155    				public void setSimTime(long SimTime) {
156 					super.setSimTime(SimTime);
157 				}
158    			
159 	    				@Override
160 	    				public 
161 	    				IncomingProjectileLocalImpl clone() {
162 	    					return new 
163 	    					IncomingProjectileLocalImpl(this);
164 	    				}
165 	    				
166 	    				
167     	
168 	    /**
169          * Unique Id of the projectile. 
170          */
171         protected
172          UnrealId Id =
173        	null;
174 	
175  		/**
176          * Unique Id of the projectile. 
177          */
178         public  UnrealId getId()
179  	 {
180 				    					return Id;
181 				    				}
182 				    			
183     	
184 	    /**
185          * Estimated time till impact. 
186          */
187         protected
188          double ImpactTime =
189        	0;
190 	
191  		/**
192          * Estimated time till impact. 
193          */
194         public  double getImpactTime()
195  	 {
196 				    					return ImpactTime;
197 				    				}
198 				    			
199     	
200 	    /**
201          * 
202 			The class of the projectile (so you know what is flying
203 			against you).
204 		 
205          */
206         protected
207          boolean Visible =
208        	true;
209 	
210  		/**
211          * 
212 			The class of the projectile (so you know what is flying
213 			against you).
214 		 
215          */
216         public  boolean isVisible()
217  	 {
218 				    					return Visible;
219 				    				}
220 				    			
221     	
222     	
223     	
224     	
225     	public IncomingProjectileLocalImpl getLocal() {
226 			return this;
227     	}
228 		public ISharedWorldObject getShared() {
229 		 	throw new UnsupportedOperationException("Could not return LOCAL as SHARED");
230 		}
231 		public IStaticWorldObject getStatic() {
232 		    throw new UnsupportedOperationException("Could not return LOCAL as STATIC");
233 		}
234  	
235 		public static class IncomingProjectileLocalUpdate
236      implements ILocalWorldObjectUpdatedEvent, IGBWorldObjectEvent
237 		{
238 			protected long time;
239 			
240 			protected IncomingProjectileLocal data = null; //contains object data for this update
241 			
242 			public IncomingProjectileLocalUpdate
243     (IncomingProjectileLocal moverLocal, long time)
244 			{
245 				this.data = moverLocal;
246 				this.time = time;
247 			}
248 			
249 			@Override
250 			public IWorldObjectUpdateResult<ILocalWorldObject> update(
251 					ILocalWorldObject object) 
252 			{
253 				if ( object == null)
254 				{
255 					data = new IncomingProjectileLocalImpl(data); //we always return Impl object
256 					return new IWorldObjectUpdateResult.WorldObjectUpdateResult<ILocalWorldObject>(IWorldObjectUpdateResult.Result.CREATED, data);
257 				}
258 				if ( object instanceof IncomingProjectileLocalImpl )
259 				{
260 					IncomingProjectileLocalImpl toUpdate = (IncomingProjectileLocalImpl)object;
261 					
262 					boolean updated = false;
263 					
264 					// UPDATING LOCAL PROPERTIES
265 					
266 				if (toUpdate.ImpactTime != data.getImpactTime()
267  	) {
268 				    toUpdate.ImpactTime=data.getImpactTime()
269  	;
270 					updated = true;
271 				}
272 			
273 				if (toUpdate.Visible != data.isVisible()
274  	) {
275 				    toUpdate.Visible=data.isVisible()
276  	;
277 					updated = true;
278 				}
279 			
280 					
281 					data = toUpdate; //the updating has finished
282 					
283 					if ( updated )
284 					{
285 						toUpdate.SimTime = this.time;
286 						return new IWorldObjectUpdateResult.WorldObjectUpdateResult<ILocalWorldObject>(IWorldObjectUpdateResult.Result.UPDATED, data);
287 					}
288 					
289 					return new IWorldObjectUpdateResult.WorldObjectUpdateResult<ILocalWorldObject>(IWorldObjectUpdateResult.Result.SAME, data);
290 				}
291 				throw new PogamutException("Unsupported object type for update. Expected IncomingProjectileLocalImpl for object " + object.getId() +", not object of class " + object.getClass().getSimpleName() + ".", this);
292 			}
293 	
294 			/**
295 			 * Simulation time in MILLI SECONDS !!!
296 			 */
297 			@Override
298 			public long getSimTime() {
299 				return this.time;
300 			}
301 	
302 			@Override
303 			public IWorldObject getObject() {
304 				return data;
305 			}
306 	
307 			@Override
308 			public WorldObjectId getId() {
309 				return data.getId();
310 			}
311 			
312 		}	
313  	
314  		
315  	    public String toString() {
316             return
317             	super.toString() + "[" +
318             	
319 		              			"Id = " + String.valueOf(getId()
320  	) + " | " + 
321 		              		
322 		              			"ImpactTime = " + String.valueOf(getImpactTime()
323  	) + " | " + 
324 		              		
325 		              			"Visible = " + String.valueOf(isVisible()
326  	) + " | " + 
327 		              		
328 				"]";           		
329         }
330  	
331  		
332  		public String toHtmlString() {
333  			return super.toString() + "[<br/>" +
334             	
335 		              			"<b>Id</b> = " + String.valueOf(getId()
336  	) + " <br/> " + 
337 		              		
338 		              			"<b>ImpactTime</b> = " + String.valueOf(getImpactTime()
339  	) + " <br/> " + 
340 		              		
341 		              			"<b>Visible</b> = " + String.valueOf(isVisible()
342  	) + " <br/> " + 
343 		              		
344 				"<br/>]";     
345 		}
346  	
347  		
348  		// --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=all]) ---
349         	
350 		// --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=all]) ---
351 		
352 	    // --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=local+classtype[@name=impl]) ---
353 	        
354 	    // --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=local+classtype[@name=impl]) ---        	            	
355  	
356 		}
357