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=base]+classtype[@name=abstract] BEGIN
13  		
14  		// --- IMPORTS FROM extra/code/java/javapart/classcategory[@name=base]+classtype[@name=abstract] END
15      
16   		/**
17           *  
18              				Abstract definition 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 abstract class Player   
31    				extends 
32    				InfoMessage
33    						implements IWorldEvent, IWorldChangeEvent, ICompositeWorldObject
34    						
35  	    		,IPerson
36  	    		,cz.cuni.amis.pogamut.unreal.communication.messages.gbinfomessages.IPlayer
37  	    		,IGBViewable
38  	    {
39   	
40      	/** Example how the message looks like - used during parser tests. */
41      	public static final String PROTOTYPE =
42      		"PLR {Id unreal_id}  {Jmx text}  {Name text}  {Action text}  {Visible False}  {Rotation 0,0,0}  {Location 0,0,0}  {Velocity 0,0,0}  {Team 0}  {Weapon text}  {Crouched False}  {Firing 0}  {EmotLeft text}  {EmotCenter text}  {EmotRight text}  {Bubble text}  {Anim text} ";
43      
44      	
45      	
46      	/**
47      	 * Parameter-less contructor for the message.
48      	 */
49  		public Player()
50  		{
51  		}
52  	
53  				// abstract message, it does not have any more constructors				
54  			
55  	   		
56  			protected long SimTime;
57  				
58  			/**
59  			 * Simulation time in MILLI SECONDS !!!
60  			 */	
61  			@Override
62  			public long getSimTime() {
63  				return SimTime;
64  			}
65  						
66  			/**
67  			 * Used by Yylex to slip correct time of the object or programmatically.
68  			 */
69  			protected void setSimTime(long SimTime) {
70  				this.SimTime = SimTime;
71  			}
72  	   	
73   		/**
74           * Unique Id of the player. 
75           */
76          public abstract UnrealId getId()
77   	;
78  		    			
79   		/**
80           * 
81  			Exported just for control server. Holds jmx address we need to connect to
82              when we want to debug our bot.
83  		 
84           */
85          public abstract String getJmx()
86   	;
87  		    			
88   		/**
89           * 
90  			Human readable name of the player.
91  		 
92           */
93          public abstract String getName()
94   	;
95  		    			
96   		/**
97           * 
98  			Atomic action this bot is doing (BDI).
99  		 
100          */
101         public abstract String getAction()
102  	;
103 		    			
104  		/**
105          * 
106             If the player is in the field of view of the bot.
107          
108          */
109         public abstract boolean isVisible()
110  	;
111 		    			
112  		/**
113          * 
114 			Which direction the player is facing in absolute terms.
115 		 
116          */
117         public abstract Rotation getRotation()
118  	;
119 		    			
120  		/**
121          * 
122 			An absolute location of the player within the map.
123 		 
124          */
125         public abstract Location getLocation()
126  	;
127 		    			
128  		/**
129          * 
130 			Absolute velocity of the player as a vector of movement per one
131 			game second.
132 		 
133          */
134         public abstract Velocity getVelocity()
135  	;
136 		    			
137  		/**
138          * 
139 			What team the player is on. 255 is no team. 0-3 are red,
140 			blue, green, gold in that order.
141 		 
142          */
143         public abstract int getTeam()
144  	;
145 		    			
146  		/**
147          * 
148 			Class of the weapon the player is holding. Weapon strings to
149 			look for include: "AssaultRifle", "ShieldGun", "FlakCannon",
150 			"BioRifle", "ShockRifle", "LinkGun", "SniperRifle",
151 			"RocketLauncher", "Minigun", "LightingGun", "Translocator".
152 			TODO: Look if this is all.
153 		 
154          */
155         public abstract String getWeapon()
156  	;
157 		    			
158  		/**
159          * 
160 			True if the bot is crouched.
161 		 
162          */
163         public abstract boolean isCrouched()
164  	;
165 		    			
166  		/**
167          * 
168 			0 means is not firing, 1 - firing in primary mode, 2 -
169 			firing in secondary mode (alt firing).
170 		 
171          */
172         public abstract int getFiring()
173  	;
174 		    			
175  		/**
176          * 
177 			For UE2. Holds left emoticon of the bot, "None" means none set.
178 		 
179          */
180         public abstract String getEmotLeft()
181  	;
182 		    			
183  		/**
184          * 
185 			For UE2. Holds center emoticon of the bot, "None" means none set.
186 		 
187          */
188         public abstract String getEmotCenter()
189  	;
190 		    			
191  		/**
192          * 
193 			For UE2. Holds right emoticon of the bot, "None" means none set.
194 		 
195          */
196         public abstract String getEmotRight()
197  	;
198 		    			
199  		/**
200          * 
201 			For UE2. Holds the bubble of the emoticon of the bot, "None" means none set.
202 		 
203          */
204         public abstract String getBubble()
205  	;
206 		    			
207  		/**
208          * 
209 			For UE2. Current played animation of the bot.
210 		 
211          */
212         public abstract String getAnim()
213  	;
214 		    			
215 		 	@Override
216 			public IWorldObjectUpdatedEvent createDisappearEvent() {
217 				return new ObjectDisappeared(this, getSimTime());
218 			}
219 			
220 			public static class ObjectDisappeared implements IWorldObjectUpdatedEvent
221 			{
222 				
223 				public ObjectDisappeared(Player obj, long time) {
224 					this.obj = obj;
225 					this.time = time;
226 				}
227 				
228 				private Player obj;
229 				private long time;
230 		
231 				@Override
232 				public WorldObjectId getId() {
233 					return obj.getId();
234 				}
235 		
236 		        /**
237 		         * Simulation time in MILLI SECONDS !!!
238 		         */
239 				@Override
240 				public long getSimTime() {
241 					return time;
242 				}
243 		
244 				@Override
245 				public IWorldObjectUpdateResult<IWorldObject> update(IWorldObject obj) {
246 					if (obj == null) {
247 						throw new PogamutException("Can't 'disappear' null!", this);
248 					}
249 					if (!(obj instanceof PlayerMessage)) {
250 						throw new PogamutException("Can't update different class than PlayerMessage, got class " + obj.getClass().getSimpleName() + "!", this);
251 					}
252 					PlayerMessage toUpdate = (PlayerMessage)obj;
253 					if (toUpdate.Visible) {
254 						toUpdate.Visible = false;
255 						return new IWorldObjectUpdateResult.WorldObjectUpdateResult(IWorldObjectUpdateResult.Result.UPDATED, obj);
256 					} else {
257 						return new IWorldObjectUpdateResult.WorldObjectUpdateResult(IWorldObjectUpdateResult.Result.SAME, obj);
258 					}
259 				}
260 		
261 			}
262 	
263 		
264     	
265     	public static class PlayerUpdate
266      extends GBObjectUpdate implements ICompositeWorldObjectUpdatedEvent, IGBWorldObjectEvent {	
267 			private Player object;
268 			private long time;
269 			private ITeamId teamId;
270 			
271 			public PlayerUpdate
272     (Player source, long eventTime, ITeamId teamId) {
273 				this.object = source;
274 				this.time = eventTime;
275 				this.teamId = teamId;
276 			}
277 			
278 			/**
279 			 * Simulation time in MILLI SECONDS !!!
280 			 */ 
281 			@Override
282 			public long getSimTime() {
283 				return time;
284 			}
285 	
286 			@Override
287 			public IWorldObject getObject() {
288 				return object;
289 			}
290 	
291 			@Override
292 			public WorldObjectId getId() {
293 				return object.getId();
294 			}
295 	
296 			@Override
297 			public ILocalWorldObjectUpdatedEvent getLocalEvent() {
298 				return new PlayerLocalImpl.PlayerLocalUpdate
299     ((PlayerLocal)object.getLocal(), time);
300 			}
301 	
302 			@Override
303 			public ISharedWorldObjectUpdatedEvent getSharedEvent() {
304 				return new PlayerSharedImpl.PlayerSharedUpdate
305     ((PlayerShared)object.getShared(), time, teamId);
306 			}
307 	
308 			@Override
309 			public IStaticWorldObjectUpdatedEvent getStaticEvent() {
310 				return new PlayerStaticImpl.PlayerStaticUpdate
311     ((PlayerStatic)object.getStatic(), time);
312 			}
313 			
314 		}
315     
316  		
317  	    public String toString() {
318             return
319             	super.toString() + "[" +
320             	
321 		              			"Id = " + String.valueOf(getId()
322  	) + " | " + 
323 		              		
324 		              			"Jmx = " + String.valueOf(getJmx()
325  	) + " | " + 
326 		              		
327 		              			"Name = " + String.valueOf(getName()
328  	) + " | " + 
329 		              		
330 		              			"Action = " + String.valueOf(getAction()
331  	) + " | " + 
332 		              		
333 		              			"Visible = " + String.valueOf(isVisible()
334  	) + " | " + 
335 		              		
336 		              			"Rotation = " + String.valueOf(getRotation()
337  	) + " | " + 
338 		              		
339 		              			"Location = " + String.valueOf(getLocation()
340  	) + " | " + 
341 		              		
342 		              			"Velocity = " + String.valueOf(getVelocity()
343  	) + " | " + 
344 		              		
345 		              			"Team = " + String.valueOf(getTeam()
346  	) + " | " + 
347 		              		
348 		              			"Weapon = " + String.valueOf(getWeapon()
349  	) + " | " + 
350 		              		
351 		              			"Crouched = " + String.valueOf(isCrouched()
352  	) + " | " + 
353 		              		
354 		              			"Firing = " + String.valueOf(getFiring()
355  	) + " | " + 
356 		              		
357 		              			"EmotLeft = " + String.valueOf(getEmotLeft()
358  	) + " | " + 
359 		              		
360 		              			"EmotCenter = " + String.valueOf(getEmotCenter()
361  	) + " | " + 
362 		              		
363 		              			"EmotRight = " + String.valueOf(getEmotRight()
364  	) + " | " + 
365 		              		
366 		              			"Bubble = " + String.valueOf(getBubble()
367  	) + " | " + 
368 		              		
369 		              			"Anim = " + String.valueOf(getAnim()
370  	) + " | " + 
371 		              		
372 				"]";           		
373         }
374  	
375  		
376  		public String toHtmlString() {
377  			return super.toString() + "[<br/>" +
378             	
379 		              			"<b>Id</b> = " + String.valueOf(getId()
380  	) + " <br/> " + 
381 		              		
382 		              			"<b>Jmx</b> = " + String.valueOf(getJmx()
383  	) + " <br/> " + 
384 		              		
385 		              			"<b>Name</b> = " + String.valueOf(getName()
386  	) + " <br/> " + 
387 		              		
388 		              			"<b>Action</b> = " + String.valueOf(getAction()
389  	) + " <br/> " + 
390 		              		
391 		              			"<b>Visible</b> = " + String.valueOf(isVisible()
392  	) + " <br/> " + 
393 		              		
394 		              			"<b>Rotation</b> = " + String.valueOf(getRotation()
395  	) + " <br/> " + 
396 		              		
397 		              			"<b>Location</b> = " + String.valueOf(getLocation()
398  	) + " <br/> " + 
399 		              		
400 		              			"<b>Velocity</b> = " + String.valueOf(getVelocity()
401  	) + " <br/> " + 
402 		              		
403 		              			"<b>Team</b> = " + String.valueOf(getTeam()
404  	) + " <br/> " + 
405 		              		
406 		              			"<b>Weapon</b> = " + String.valueOf(getWeapon()
407  	) + " <br/> " + 
408 		              		
409 		              			"<b>Crouched</b> = " + String.valueOf(isCrouched()
410  	) + " <br/> " + 
411 		              		
412 		              			"<b>Firing</b> = " + String.valueOf(getFiring()
413  	) + " <br/> " + 
414 		              		
415 		              			"<b>EmotLeft</b> = " + String.valueOf(getEmotLeft()
416  	) + " <br/> " + 
417 		              		
418 		              			"<b>EmotCenter</b> = " + String.valueOf(getEmotCenter()
419  	) + " <br/> " + 
420 		              		
421 		              			"<b>EmotRight</b> = " + String.valueOf(getEmotRight()
422  	) + " <br/> " + 
423 		              		
424 		              			"<b>Bubble</b> = " + String.valueOf(getBubble()
425  	) + " <br/> " + 
426 		              		
427 		              			"<b>Anim</b> = " + String.valueOf(getAnim()
428  	) + " <br/> " + 
429 		              		
430 				"<br/>]";     
431 		}
432  	 
433  	    public String toJsonLiteral() {
434             return "Player(null, "
435             		
436 		              		+ ", " +
437 		              		
438 									(getId()
439  	 == null ? "null" :
440 										"\"" + getId()
441  	.getStringId() + "\"" 
442 									)
443 								
444 		              		+ ", " +
445 		              		
446 									(getName()
447  	 == null ? "null" :
448 										"\"" + getName()
449  	 + "\"" 
450 									)
451 								
452 		              		+ ", " +
453 		              		
454 								    String.valueOf(isVisible()
455  	)									
456 								
457 		              		+ ", " +
458 		              		
459 								    (getLocation()
460  	 == null ? "null" :
461 										"[" + getLocation()
462  	.getX() + ", " + getLocation()
463  	.getY() + ", " + getLocation()
464  	.getZ() + "]" 
465 									)
466 								
467 		              		+ ", " +
468 		              		
469 								    String.valueOf(getTeam()
470  	)									
471 								
472                    + ")";
473         }
474  	
475  		
476  		// --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=all]) ---
477         	
478 		// --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=all]) ---
479 		
480 	    // --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=base+classtype[@name=abstract]) ---
481 	        
482 	    // --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=base+classtype[@name=abstract]) ---        	            	
483  	
484 		}
485