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}  {Spectator False}  {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  			Whether this player is in SPECTATE mode. Humans can change the mode during runtime!
99  		 
100          */
101         public abstract Boolean isSpectator()
102  	;
103 		    			
104  		/**
105          * 
106 			Atomic action this bot is doing (BDI).
107 		 
108          */
109         public abstract String getAction()
110  	;
111 		    			
112  		/**
113          * 
114             If the player is in the field of view of the bot.
115          
116          */
117         public abstract boolean isVisible()
118  	;
119 		    			
120  		/**
121          * 
122 			Which direction the player is facing in absolute terms.
123 		 
124          */
125         public abstract Rotation getRotation()
126  	;
127 		    			
128  		/**
129          * 
130 			An absolute location of the player within the map.
131 		 
132          */
133         public abstract Location getLocation()
134  	;
135 		    			
136  		/**
137          * 
138 			Absolute velocity of the player as a vector of movement per one
139 			game second.
140 		 
141          */
142         public abstract Velocity getVelocity()
143  	;
144 		    			
145  		/**
146          * 
147 			What team the player is on. 255 is no team. 0-3 are red,
148 			blue, green, gold in that order.
149 		 
150          */
151         public abstract int getTeam()
152  	;
153 		    			
154  		/**
155          * 
156 			Class of the weapon the player is holding. Weapon strings to
157 			look for include: "AssaultRifle", "ShieldGun", "FlakCannon",
158 			"BioRifle", "ShockRifle", "LinkGun", "SniperRifle",
159 			"RocketLauncher", "Minigun", "LightingGun", "Translocator".
160 			TODO: Look if this is all.
161 		 
162          */
163         public abstract String getWeapon()
164  	;
165 		    			
166  		/**
167          * 
168 			True if the bot is crouched.
169 		 
170          */
171         public abstract boolean isCrouched()
172  	;
173 		    			
174  		/**
175          * 
176 			0 means is not firing, 1 - firing in primary mode, 2 -
177 			firing in secondary mode (alt firing).
178 		 
179          */
180         public abstract int getFiring()
181  	;
182 		    			
183  		/**
184          * 
185 			For UE2. Holds left emoticon of the bot, "None" means none set.
186 		 
187          */
188         public abstract String getEmotLeft()
189  	;
190 		    			
191  		/**
192          * 
193 			For UE2. Holds center emoticon of the bot, "None" means none set.
194 		 
195          */
196         public abstract String getEmotCenter()
197  	;
198 		    			
199  		/**
200          * 
201 			For UE2. Holds right emoticon of the bot, "None" means none set.
202 		 
203          */
204         public abstract String getEmotRight()
205  	;
206 		    			
207  		/**
208          * 
209 			For UE2. Holds the bubble of the emoticon of the bot, "None" means none set.
210 		 
211          */
212         public abstract String getBubble()
213  	;
214 		    			
215  		/**
216          * 
217 			For UE2. Current played animation of the bot.
218 		 
219          */
220         public abstract String getAnim()
221  	;
222 		    			
223 		 	@Override
224 			public IWorldObjectUpdatedEvent createDisappearEvent() {
225 				return new ObjectDisappeared(this, getSimTime());
226 			}
227 			
228 			public static class ObjectDisappeared implements IWorldObjectUpdatedEvent
229 			{
230 				
231 				public ObjectDisappeared(Player obj, long time) {
232 					this.obj = obj;
233 					this.time = time;
234 				}
235 				
236 				private Player obj;
237 				private long time;
238 		
239 				@Override
240 				public WorldObjectId getId() {
241 					return obj.getId();
242 				}
243 		
244 		        /**
245 		         * Simulation time in MILLI SECONDS !!!
246 		         */
247 				@Override
248 				public long getSimTime() {
249 					return time;
250 				}
251 		
252 				@Override
253 				public IWorldObjectUpdateResult<IWorldObject> update(IWorldObject obj) {
254 					if (obj == null) {
255 						throw new PogamutException("Can't 'disappear' null!", this);
256 					}
257 					if (!(obj instanceof PlayerMessage)) {
258 						throw new PogamutException("Can't update different class than PlayerMessage, got class " + obj.getClass().getSimpleName() + "!", this);
259 					}
260 					PlayerMessage toUpdate = (PlayerMessage)obj;
261 					if (toUpdate.Visible) {
262 						toUpdate.Visible = false;
263 						return new IWorldObjectUpdateResult.WorldObjectUpdateResult(IWorldObjectUpdateResult.Result.UPDATED, obj);
264 					} else {
265 						return new IWorldObjectUpdateResult.WorldObjectUpdateResult(IWorldObjectUpdateResult.Result.SAME, obj);
266 					}
267 				}
268 		
269 			}
270 	
271 		
272     	
273     	public static class PlayerUpdate
274      extends GBObjectUpdate implements ICompositeWorldObjectUpdatedEvent, IGBWorldObjectEvent {	
275 			private Player object;
276 			private long time;
277 			private ITeamId teamId;
278 			
279 			public PlayerUpdate
280     (Player source, long eventTime, ITeamId teamId) {
281 				this.object = source;
282 				this.time = eventTime;
283 				this.teamId = teamId;
284 			}
285 			
286 			/**
287 			 * Simulation time in MILLI SECONDS !!!
288 			 */ 
289 			@Override
290 			public long getSimTime() {
291 				return time;
292 			}
293 	
294 			@Override
295 			public IWorldObject getObject() {
296 				return object;
297 			}
298 	
299 			@Override
300 			public WorldObjectId getId() {
301 				return object.getId();
302 			}
303 	
304 			@Override
305 			public ILocalWorldObjectUpdatedEvent getLocalEvent() {
306 				return new PlayerLocalImpl.PlayerLocalUpdate
307     ((PlayerLocal)object.getLocal(), time);
308 			}
309 	
310 			@Override
311 			public ISharedWorldObjectUpdatedEvent getSharedEvent() {
312 				return new PlayerSharedImpl.PlayerSharedUpdate
313     ((PlayerShared)object.getShared(), time, teamId);
314 			}
315 	
316 			@Override
317 			public IStaticWorldObjectUpdatedEvent getStaticEvent() {
318 				return new PlayerStaticImpl.PlayerStaticUpdate
319     ((PlayerStatic)object.getStatic(), time);
320 			}
321 			
322 		}
323     
324  		
325  	    public String toString() {
326             return
327             	super.toString() + "[" +
328             	
329 		              			"Id = " + String.valueOf(getId()
330  	) + " | " + 
331 		              		
332 		              			"Jmx = " + String.valueOf(getJmx()
333  	) + " | " + 
334 		              		
335 		              			"Name = " + String.valueOf(getName()
336  	) + " | " + 
337 		              		
338 		              			"Spectator = " + String.valueOf(isSpectator()
339  	) + " | " + 
340 		              		
341 		              			"Action = " + String.valueOf(getAction()
342  	) + " | " + 
343 		              		
344 		              			"Visible = " + String.valueOf(isVisible()
345  	) + " | " + 
346 		              		
347 		              			"Rotation = " + String.valueOf(getRotation()
348  	) + " | " + 
349 		              		
350 		              			"Location = " + String.valueOf(getLocation()
351  	) + " | " + 
352 		              		
353 		              			"Velocity = " + String.valueOf(getVelocity()
354  	) + " | " + 
355 		              		
356 		              			"Team = " + String.valueOf(getTeam()
357  	) + " | " + 
358 		              		
359 		              			"Weapon = " + String.valueOf(getWeapon()
360  	) + " | " + 
361 		              		
362 		              			"Crouched = " + String.valueOf(isCrouched()
363  	) + " | " + 
364 		              		
365 		              			"Firing = " + String.valueOf(getFiring()
366  	) + " | " + 
367 		              		
368 		              			"EmotLeft = " + String.valueOf(getEmotLeft()
369  	) + " | " + 
370 		              		
371 		              			"EmotCenter = " + String.valueOf(getEmotCenter()
372  	) + " | " + 
373 		              		
374 		              			"EmotRight = " + String.valueOf(getEmotRight()
375  	) + " | " + 
376 		              		
377 		              			"Bubble = " + String.valueOf(getBubble()
378  	) + " | " + 
379 		              		
380 		              			"Anim = " + String.valueOf(getAnim()
381  	) + " | " + 
382 		              		
383 				"]";           		
384         }
385  	
386  		
387  		public String toHtmlString() {
388  			return super.toString() + "[<br/>" +
389             	
390 		              			"<b>Id</b> = " + String.valueOf(getId()
391  	) + " <br/> " + 
392 		              		
393 		              			"<b>Jmx</b> = " + String.valueOf(getJmx()
394  	) + " <br/> " + 
395 		              		
396 		              			"<b>Name</b> = " + String.valueOf(getName()
397  	) + " <br/> " + 
398 		              		
399 		              			"<b>Spectator</b> = " + String.valueOf(isSpectator()
400  	) + " <br/> " + 
401 		              		
402 		              			"<b>Action</b> = " + String.valueOf(getAction()
403  	) + " <br/> " + 
404 		              		
405 		              			"<b>Visible</b> = " + String.valueOf(isVisible()
406  	) + " <br/> " + 
407 		              		
408 		              			"<b>Rotation</b> = " + String.valueOf(getRotation()
409  	) + " <br/> " + 
410 		              		
411 		              			"<b>Location</b> = " + String.valueOf(getLocation()
412  	) + " <br/> " + 
413 		              		
414 		              			"<b>Velocity</b> = " + String.valueOf(getVelocity()
415  	) + " <br/> " + 
416 		              		
417 		              			"<b>Team</b> = " + String.valueOf(getTeam()
418  	) + " <br/> " + 
419 		              		
420 		              			"<b>Weapon</b> = " + String.valueOf(getWeapon()
421  	) + " <br/> " + 
422 		              		
423 		              			"<b>Crouched</b> = " + String.valueOf(isCrouched()
424  	) + " <br/> " + 
425 		              		
426 		              			"<b>Firing</b> = " + String.valueOf(getFiring()
427  	) + " <br/> " + 
428 		              		
429 		              			"<b>EmotLeft</b> = " + String.valueOf(getEmotLeft()
430  	) + " <br/> " + 
431 		              		
432 		              			"<b>EmotCenter</b> = " + String.valueOf(getEmotCenter()
433  	) + " <br/> " + 
434 		              		
435 		              			"<b>EmotRight</b> = " + String.valueOf(getEmotRight()
436  	) + " <br/> " + 
437 		              		
438 		              			"<b>Bubble</b> = " + String.valueOf(getBubble()
439  	) + " <br/> " + 
440 		              		
441 		              			"<b>Anim</b> = " + String.valueOf(getAnim()
442  	) + " <br/> " + 
443 		              		
444 				"<br/>]";     
445 		}
446  	
447  	    public String toJsonLiteral() {
448             return "player( "
449             		+
450 									(getId()
451  	 == null ? "null" :
452 										"\"" + getId()
453  	.getStringId() + "\"" 
454 									)
455 								+ ", " + 
456 									(getJmx()
457  	 == null ? "null" :
458 										"\"" + getJmx()
459  	 + "\"" 
460 									)
461 								+ ", " + 
462 									(getName()
463  	 == null ? "null" :
464 										"\"" + getName()
465  	 + "\"" 
466 									)
467 								+ ", " + 
468 								    String.valueOf(isSpectator()
469  	)									
470 								+ ", " + 
471 									(getAction()
472  	 == null ? "null" :
473 										"\"" + getAction()
474  	 + "\"" 
475 									)
476 								+ ", " + 
477 								    String.valueOf(isVisible()
478  	)									
479 								+ ", " + 
480 									(getRotation()
481  	 == null ? "null" :
482 										"[" + getRotation()
483  	.getPitch() + ", " + getRotation()
484  	.getYaw() + ", " + getRotation()
485  	.getRoll() + "]" 
486 									)								    
487 								+ ", " + 
488 								    (getLocation()
489  	 == null ? "null" :
490 										"[" + getLocation()
491  	.getX() + ", " + getLocation()
492  	.getY() + ", " + getLocation()
493  	.getZ() + "]" 
494 									)
495 								+ ", " + 
496 								    (getVelocity()
497  	 == null ? "null" :
498 										"[" + getVelocity()
499  	.getX() + ", " + getVelocity()
500  	.getY() + ", " + getVelocity()
501  	.getZ() + "]" 
502 									)
503 								+ ", " + 
504 								    String.valueOf(getTeam()
505  	)									
506 								+ ", " + 
507 									(getWeapon()
508  	 == null ? "null" :
509 										"\"" + getWeapon()
510  	 + "\"" 
511 									)
512 								+ ", " + 
513 								    String.valueOf(isCrouched()
514  	)									
515 								+ ", " + 
516 								    String.valueOf(getFiring()
517  	)									
518 								+ ", " + 
519 									(getEmotLeft()
520  	 == null ? "null" :
521 										"\"" + getEmotLeft()
522  	 + "\"" 
523 									)
524 								+ ", " + 
525 									(getEmotCenter()
526  	 == null ? "null" :
527 										"\"" + getEmotCenter()
528  	 + "\"" 
529 									)
530 								+ ", " + 
531 									(getEmotRight()
532  	 == null ? "null" :
533 										"\"" + getEmotRight()
534  	 + "\"" 
535 									)
536 								+ ", " + 
537 									(getBubble()
538  	 == null ? "null" :
539 										"\"" + getBubble()
540  	 + "\"" 
541 									)
542 								+ ", " + 
543 									(getAnim()
544  	 == null ? "null" :
545 										"\"" + getAnim()
546  	 + "\"" 
547 									)
548 								
549                    + ")";
550         }
551  	
552  		
553  		// --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=all]) ---
554         	
555 		// --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=all]) ---
556 		
557 	    // --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=base+classtype[@name=abstract]) ---
558 	        
559 	    // --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=base+classtype[@name=abstract]) ---        	            	
560  	
561 		}
562