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  		public IncomingProjectileLocalImpl(
79  			UnrealId Id,  double ImpactTime
80  		) {
81  			
82  					this.Id = Id;
83  				
84  					this.ImpactTime = ImpactTime;
85  				
86  		}
87      
88      	/**
89  		 * Cloning constructor from the full message.
90  		 *
91  		 * @param original
92  		 */
93  		public IncomingProjectileLocalImpl(IncomingProjectile original) {		
94  			
95  					this.Id = original.getId()
96   	;
97  				
98  					this.ImpactTime = original.getImpactTime()
99   	;
100 				
101 			this.SimTime = original.getSimTime();			
102 		}
103 		
104 		/**
105 		 * Cloning constructor from the full message.
106 		 *
107 		 * @param original
108 		 */
109 		public IncomingProjectileLocalImpl(IncomingProjectileLocalImpl original) {		
110 			
111 					this.Id = original.getId()
112  	;
113 				
114 					this.ImpactTime = original.getImpactTime()
115  	;
116 				
117 			this.SimTime = original.getSimTime();
118 		}
119 		
120 			/**
121 			 * Cloning constructor from the message part.
122 			 *
123 			 * @param original
124 			 */
125 			public IncomingProjectileLocalImpl(IncomingProjectileLocal original) {
126 				
127 						this.Id = original.getId()
128  	;
129 					
130 						this.ImpactTime = original.getImpactTime()
131  	;
132 					
133 			}
134 		
135    				
136    				@Override
137    				public void setSimTime(long SimTime) {
138 					super.setSimTime(SimTime);
139 				}
140    			
141 	    				@Override
142 	    				public 
143 	    				IncomingProjectileLocalImpl clone() {
144 	    					return new 
145 	    					IncomingProjectileLocalImpl(this);
146 	    				}
147 	    				
148 	    				
149     	
150 	    /**
151          * Unique Id of the projectile. 
152          */
153         protected
154          UnrealId Id =
155        	null;
156 	
157  		/**
158          * Unique Id of the projectile. 
159          */
160         public  UnrealId getId()
161  	 {
162 				    					return Id;
163 				    				}
164 				    			
165     	
166 	    /**
167          * Estimated time till impact. 
168          */
169         protected
170          double ImpactTime =
171        	0;
172 	
173  		/**
174          * Estimated time till impact. 
175          */
176         public  double getImpactTime()
177  	 {
178 				    					return ImpactTime;
179 				    				}
180 				    			
181     	
182     	
183     	
184     	
185     	public IncomingProjectileLocalImpl getLocal() {
186 			return this;
187     	}
188 		public ISharedWorldObject getShared() {
189 		 	throw new UnsupportedOperationException("Could not return LOCAL as SHARED");
190 		}
191 		public IStaticWorldObject getStatic() {
192 		    throw new UnsupportedOperationException("Could not return LOCAL as STATIC");
193 		}
194  	
195 		public static class IncomingProjectileLocalUpdate
196      implements ILocalWorldObjectUpdatedEvent, IGBWorldObjectEvent
197 		{
198 			protected long time;
199 			
200 			protected IncomingProjectileLocal data = null; //contains object data for this update
201 			
202 			public IncomingProjectileLocalUpdate
203     (IncomingProjectileLocal moverLocal, long time)
204 			{
205 				this.data = moverLocal;
206 				this.time = time;
207 			}
208 			
209 			@Override
210 			public IWorldObjectUpdateResult<ILocalWorldObject> update(
211 					ILocalWorldObject object) 
212 			{
213 				if ( object == null)
214 				{
215 					data = new IncomingProjectileLocalImpl(data); //we always return Impl object
216 					return new IWorldObjectUpdateResult.WorldObjectUpdateResult<ILocalWorldObject>(IWorldObjectUpdateResult.Result.CREATED, data);
217 				}
218 				if ( object instanceof IncomingProjectileLocalImpl )
219 				{
220 					IncomingProjectileLocalImpl toUpdate = (IncomingProjectileLocalImpl)object;
221 					
222 					boolean updated = false;
223 					
224 					// UPDATING LOCAL PROPERTIES
225 					
226 				if (toUpdate.ImpactTime != data.getImpactTime()
227  	) {
228 				    toUpdate.ImpactTime=data.getImpactTime()
229  	;
230 					updated = true;
231 				}
232 			
233 					
234 					data = toUpdate; //the updating has finished
235 					
236 					if ( updated )
237 					{
238 						toUpdate.SimTime = this.time;
239 						return new IWorldObjectUpdateResult.WorldObjectUpdateResult<ILocalWorldObject>(IWorldObjectUpdateResult.Result.UPDATED, data);
240 					}
241 					
242 					return new IWorldObjectUpdateResult.WorldObjectUpdateResult<ILocalWorldObject>(IWorldObjectUpdateResult.Result.SAME, data);
243 				}
244 				throw new PogamutException("Unsupported object type for update. Expected IncomingProjectileLocalImpl for object " + object.getId() +", not object of class " + object.getClass().getSimpleName() + ".", this);
245 			}
246 	
247 			/**
248 			 * Simulation time in MILLI SECONDS !!!
249 			 */
250 			@Override
251 			public long getSimTime() {
252 				return this.time;
253 			}
254 	
255 			@Override
256 			public IWorldObject getObject() {
257 				return data;
258 			}
259 	
260 			@Override
261 			public WorldObjectId getId() {
262 				return data.getId();
263 			}
264 			
265 		}	
266  	
267  		
268  	    public String toString() {
269             return
270             	super.toString() + "[" +
271             	
272 		              			"Id = " + String.valueOf(getId()
273  	) + " | " + 
274 		              		
275 		              			"ImpactTime = " + String.valueOf(getImpactTime()
276  	) + " | " + 
277 		              		
278 				"]";           		
279         }
280  	
281  		
282  		public String toHtmlString() {
283  			return super.toString() + "[<br/>" +
284             	
285 		              			"<b>Id</b> = " + String.valueOf(getId()
286  	) + " <br/> " + 
287 		              		
288 		              			"<b>ImpactTime</b> = " + String.valueOf(getImpactTime()
289  	) + " <br/> " + 
290 		              		
291 				"<br/>]";     
292 		}
293  	
294  		
295  		// --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=all]) ---
296         	
297 		// --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=all]) ---
298 		
299 	    // --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=local+classtype[@name=impl]) ---
300 	        
301 	    // --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=local+classtype[@name=impl]) ---        	            	
302  	
303 		}
304