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