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