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 VEH.  
19              			
20           *
21           *  <p></p><p></p>
22           *  Complete message documentation:               
23           *  
24  		Synchronous message. Holds vehicles we see. Id for vehicles doesn't work, so 
25  		this message is without Id. We can join vehicles by ENTER command if we are 
26  		close enough - ussually 100 ut units or less. Note: Vehicle support is 
27  		in aplha testing right now.
28  	
29           */
30   	public class VehicleLocalImpl 
31    						extends
32    						VehicleLocal
33  	    {
34   	
35      	
36      	
37      	/**
38      	 * Parameter-less contructor for the message.
39      	 */
40  		public VehicleLocalImpl()
41  		{
42  		}
43  	
44      	
45      	
46      	
47      	/**
48  		 * Creates new instance of the message Vehicle.
49  		 * 
50  		Synchronous message. Holds vehicles we see. Id for vehicles doesn't work, so 
51  		this message is without Id. We can join vehicles by ENTER command if we are 
52  		close enough - ussually 100 ut units or less. Note: Vehicle support is 
53  		in aplha testing right now.
54  	
55  		 * Corresponding GameBots message
56  		 *   (local part)
57  		 *   is
58  		 *   VEH.
59  		 * 
60   	  	 * 
61  		 *   
62  		 *     @param Id Unique Id of the vehicle or vehicle part.
63  		 *   
64  		 * 
65  		 *   
66  		 * 
67  		 *   
68  		 * 
69  		 *   
70  		 * 
71  		 *   
72  		 *     @param Visible 
73              If the vehicle is in the field of view of the bot.
74          
75  		 *   
76  		 * 
77  		 *   
78  		 * 
79  		 *   
80  		 * 
81  		 *   
82  		 * 
83  		 *   
84  		 * 
85  		 *   
86  		 * 
87  		 *   
88  		 * 
89  		 */
90  		public VehicleLocalImpl(
91  			UnrealId Id,  boolean Visible
92  		) {
93  			
94  					this.Id = Id;
95  				
96  					this.Visible = Visible;
97  				
98  		}
99      
100     	/**
101 		 * Cloning constructor from the full message.
102 		 *
103 		 * @param original
104 		 */
105 		public VehicleLocalImpl(Vehicle original) {		
106 			
107 					this.Id = original.getId()
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 VehicleLocalImpl(VehicleLocalImpl original) {		
122 			
123 					this.Id = original.getId()
124  	;
125 				
126 					this.Visible = original.isVisible()
127  	;
128 				
129 			this.SimTime = original.getSimTime();
130 		}
131 		
132 			/**
133 			 * Cloning constructor from the message part.
134 			 *
135 			 * @param original
136 			 */
137 			public VehicleLocalImpl(VehicleLocal original) {
138 				
139 						this.Id = original.getId()
140  	;
141 					
142 						this.Visible = original.isVisible()
143  	;
144 					
145 			}
146 		
147    				
148    				@Override
149    				public void setSimTime(long SimTime) {
150 					super.setSimTime(SimTime);
151 				}
152    			
153 	    				@Override
154 	    				public 
155 	    				VehicleLocalImpl clone() {
156 	    					return new 
157 	    					VehicleLocalImpl(this);
158 	    				}
159 	    				
160 	    				
161     	
162 	    /**
163          * Unique Id of the vehicle or vehicle part. 
164          */
165         protected
166          UnrealId Id =
167        	null;
168 	
169  		/**
170          * Unique Id of the vehicle or vehicle part. 
171          */
172         public  UnrealId getId()
173  	 {
174 				    					return Id;
175 				    				}
176 				    			
177     	
178 	    /**
179          * 
180             If the vehicle is in the field of view of the bot.
181          
182          */
183         protected
184          boolean Visible =
185        	false;
186 	
187  		/**
188          * 
189             If the vehicle is in the field of view of the bot.
190          
191          */
192         public  boolean isVisible()
193  	 {
194 				    					return Visible;
195 				    				}
196 				    			
197     	
198     	
199     	
200     	
201     	public VehicleLocalImpl getLocal() {
202 			return this;
203     	}
204 		public ISharedWorldObject getShared() {
205 		 	throw new UnsupportedOperationException("Could not return LOCAL as SHARED");
206 		}
207 		public IStaticWorldObject getStatic() {
208 		    throw new UnsupportedOperationException("Could not return LOCAL as STATIC");
209 		}
210  	
211 		public static class VehicleLocalUpdate
212      implements ILocalWorldObjectUpdatedEvent, IGBWorldObjectEvent
213 		{
214 			protected long time;
215 			
216 			protected VehicleLocal data = null; //contains object data for this update
217 			
218 			public VehicleLocalUpdate
219     (VehicleLocal moverLocal, long time)
220 			{
221 				this.data = moverLocal;
222 				this.time = time;
223 			}
224 			
225 			@Override
226 			public IWorldObjectUpdateResult<ILocalWorldObject> update(
227 					ILocalWorldObject object) 
228 			{
229 				if ( object == null)
230 				{
231 					data = new VehicleLocalImpl(data); //we always return Impl object
232 					return new IWorldObjectUpdateResult.WorldObjectUpdateResult<ILocalWorldObject>(IWorldObjectUpdateResult.Result.CREATED, data);
233 				}
234 				if ( object instanceof VehicleLocalImpl )
235 				{
236 					VehicleLocalImpl toUpdate = (VehicleLocalImpl)object;
237 					
238 					boolean updated = false;
239 					
240 					// UPDATING LOCAL PROPERTIES
241 					
242 				if (toUpdate.Visible != data.isVisible()
243  	) {
244 				    toUpdate.Visible=data.isVisible()
245  	;
246 					updated = true;
247 				}
248 			
249 					
250 					data = toUpdate; //the updating has finished
251 					
252 					if ( updated )
253 					{
254 						toUpdate.SimTime = this.time;
255 						return new IWorldObjectUpdateResult.WorldObjectUpdateResult<ILocalWorldObject>(IWorldObjectUpdateResult.Result.UPDATED, data);
256 					}
257 					
258 					return new IWorldObjectUpdateResult.WorldObjectUpdateResult<ILocalWorldObject>(IWorldObjectUpdateResult.Result.SAME, data);
259 				}
260 				throw new PogamutException("Unsupported object type for update. Expected VehicleLocalImpl for object " + object.getId() +", not object of class " + object.getClass().getSimpleName() + ".", this);
261 			}
262 	
263 			/**
264 			 * Simulation time in MILLI SECONDS !!!
265 			 */
266 			@Override
267 			public long getSimTime() {
268 				return this.time;
269 			}
270 	
271 			@Override
272 			public IWorldObject getObject() {
273 				return data;
274 			}
275 	
276 			@Override
277 			public WorldObjectId getId() {
278 				return data.getId();
279 			}
280 			
281 		}	
282  	
283  		
284  	    public String toString() {
285             return
286             	super.toString() + "[" +
287             	
288 		              			"Id = " + String.valueOf(getId()
289  	) + " | " + 
290 		              		
291 		              			"Visible = " + String.valueOf(isVisible()
292  	) + " | " + 
293 		              		
294 				"]";           		
295         }
296  	
297  		
298  		public String toHtmlString() {
299  			return super.toString() + "[<br/>" +
300             	
301 		              			"<b>Id</b> = " + String.valueOf(getId()
302  	) + " <br/> " + 
303 		              		
304 		              			"<b>Visible</b> = " + String.valueOf(isVisible()
305  	) + " <br/> " + 
306 		              		
307 				"<br/>]";     
308 		}
309  	
310  		
311  		// --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=all]) ---
312         	
313 		// --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=all]) ---
314 		
315 	    // --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=local+classtype[@name=impl]) ---
316 	        
317 	    // --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=local+classtype[@name=impl]) ---        	            	
318  	
319 		}
320