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