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=shared]+classtype[@name=impl] BEGIN
13  		
14  		// --- IMPORTS FROM extra/code/java/javapart/classcategory[@name=shared]+classtype[@name=impl] END
15      
16   		/**
17           *  
18              				Implementation of the shared 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 PlayerSharedImpl 
31    						extends
32    						PlayerShared
33  	    {
34   	
35      
36      	
37      	public PlayerSharedImpl(PlayerSharedImpl source) {
38  			
39  				this.Id = source.
40  					getId()
41   	;
42  			
43  				this.myName = source.myName;
44  			
45  				this.myAction = source.myAction;
46  			
47  				this.myRotation = source.myRotation;
48  			
49  				this.myLocation = source.myLocation;
50  			
51  				this.myVelocity = source.myVelocity;
52  			
53  				this.myTeam = source.myTeam;
54  			
55  				this.myWeapon = source.myWeapon;
56  			
57  				this.myCrouched = source.myCrouched;
58  			
59  				this.myFiring = source.myFiring;
60  			
61  				this.myEmotLeft = source.myEmotLeft;
62  			
63  				this.myEmotCenter = source.myEmotCenter;
64  			
65  				this.myEmotRight = source.myEmotRight;
66  			
67  				this.myBubble = source.myBubble;
68  			
69  				this.myAnim = source.myAnim;
70  			
71  		}
72  		
73  		public PlayerSharedImpl(WorldObjectId objectId, Collection<ISharedProperty> properties) {
74  			this.Id = (UnrealId)objectId;
75  			NullCheck.check(this.Id, "objectId");
76  		
77  			if (properties.size() != 14) {
78  				throw new PogamutException("Not enough properties passed to the constructor.", PlayerSharedImpl.class);
79  			}
80  		
81  			//we have to do some checking in this one to know that we get all properties required
82  			for ( ISharedProperty property : properties ) {
83  				PropertyId pId = property.getPropertyId();
84  				if ( !objectId.equals( property.getObjectId() )) {
85  					//properties for different objects
86  					throw new PogamutException("Trying to create a PlayerSharedImpl with different WorldObjectId properties : " + 
87  											    this.Id.getStringId() + " / " + property.getObjectId().getStringId() , this);
88  				}
89  				if (!PlayerShared.SharedPropertyTokens.contains(pId.getPropertyToken())) {
90  				// property that does not belong here
91  				throw new PogamutException("Trying to create a PlayerSharedImpl with invalid property (invalid property token): " + 
92  					this.Id.getStringId() + " / " + property.getPropertyId().getPropertyToken().getToken() , this);
93  				}
94  				propertyMap.put(property.getPropertyId(), property);
95  				
96  				
97  					if (pId.getPropertyToken().getToken().equals("Name"))
98  					{
99  						this.myName = (StringProperty)property;
100 					}
101 				
102 					if (pId.getPropertyToken().getToken().equals("Action"))
103 					{
104 						this.myAction = (StringProperty)property;
105 					}
106 				
107 					if (pId.getPropertyToken().getToken().equals("Rotation"))
108 					{
109 						this.myRotation = (RotationProperty)property;
110 					}
111 				
112 					if (pId.getPropertyToken().getToken().equals("Location"))
113 					{
114 						this.myLocation = (LocationProperty)property;
115 					}
116 				
117 					if (pId.getPropertyToken().getToken().equals("Velocity"))
118 					{
119 						this.myVelocity = (VelocityProperty)property;
120 					}
121 				
122 					if (pId.getPropertyToken().getToken().equals("Team"))
123 					{
124 						this.myTeam = (IntProperty)property;
125 					}
126 				
127 					if (pId.getPropertyToken().getToken().equals("Weapon"))
128 					{
129 						this.myWeapon = (StringProperty)property;
130 					}
131 				
132 					if (pId.getPropertyToken().getToken().equals("Crouched"))
133 					{
134 						this.myCrouched = (BooleanProperty)property;
135 					}
136 				
137 					if (pId.getPropertyToken().getToken().equals("Firing"))
138 					{
139 						this.myFiring = (IntProperty)property;
140 					}
141 				
142 					if (pId.getPropertyToken().getToken().equals("EmotLeft"))
143 					{
144 						this.myEmotLeft = (StringProperty)property;
145 					}
146 				
147 					if (pId.getPropertyToken().getToken().equals("EmotCenter"))
148 					{
149 						this.myEmotCenter = (StringProperty)property;
150 					}
151 				
152 					if (pId.getPropertyToken().getToken().equals("EmotRight"))
153 					{
154 						this.myEmotRight = (StringProperty)property;
155 					}
156 				
157 					if (pId.getPropertyToken().getToken().equals("Bubble"))
158 					{
159 						this.myBubble = (StringProperty)property;
160 					}
161 				
162 					if (pId.getPropertyToken().getToken().equals("Anim"))
163 					{
164 						this.myAnim = (StringProperty)property;
165 					}
166 				
167 			}
168 		}
169     
170    				
171    				@Override
172    				public void setSimTime(long SimTime) {
173 					super.setSimTime(SimTime);
174 				}
175    			
176 	    				@Override
177 	    				public 
178 	    				PlayerSharedImpl clone() {
179 	    					return new 
180 	    					PlayerSharedImpl(this);
181 	    				}
182 	    				
183 	    				
184 		
185 		
186 		
187 		protected HashMap<PropertyId, ISharedProperty> propertyMap = new HashMap<PropertyId, ISharedProperty>(
188 			14
189 		);
190 		
191 		@Override
192 		public ISharedProperty getProperty(PropertyId id) {
193 			return propertyMap.get(id);
194 		}
195 
196 		@Override
197 		public Map<PropertyId, ISharedProperty> getProperties() {
198 			return propertyMap;
199 		}
200 	
201 		
202 		
203     	
204 	    /**
205          * Unique Id of the player. 
206          */
207         protected
208          UnrealId Id =
209        	null;
210 	
211  		/**
212          * Unique Id of the player. 
213          */
214         public  UnrealId getId()
215  	 {
216   			return Id;
217   		}
218   		
219     	
220 	    /**
221          * 
222 			Human readable name of the player.
223 		 
224          */
225         protected
226          StringProperty 
227         myName
228 					= null;
229 					
230 					
231  		/**
232          * 
233 			Human readable name of the player.
234 		 
235          */
236         public  String getName()
237  	 {
238 			  			return myName.getValue();
239 			  		}
240 				
241     	
242 	    /**
243          * 
244 			Atomic action this bot is doing (BDI).
245 		 
246          */
247         protected
248          StringProperty 
249         myAction
250 					= null;
251 					
252 					
253  		/**
254          * 
255 			Atomic action this bot is doing (BDI).
256 		 
257          */
258         public  String getAction()
259  	 {
260 			  			return myAction.getValue();
261 			  		}
262 				
263     	
264 	    /**
265          * 
266 			Which direction the player is facing in absolute terms.
267 		 
268          */
269         protected
270          RotationProperty 
271         myRotation
272 					= null;
273 					
274 					
275  		/**
276          * 
277 			Which direction the player is facing in absolute terms.
278 		 
279          */
280         public  Rotation getRotation()
281  	 {
282 			  			return myRotation.getValue();
283 			  		}
284 				
285     	
286 	    /**
287          * 
288 			An absolute location of the player within the map.
289 		 
290          */
291         protected
292          LocationProperty 
293         myLocation
294 					= null;
295 					
296 					
297  		/**
298          * 
299 			An absolute location of the player within the map.
300 		 
301          */
302         public  Location getLocation()
303  	 {
304 			  			return myLocation.getValue();
305 			  		}
306 				
307     	
308 	    /**
309          * 
310 			Absolute velocity of the player as a vector of movement per one
311 			game second.
312 		 
313          */
314         protected
315          VelocityProperty 
316         myVelocity
317 					= null;
318 					
319 					
320  		/**
321          * 
322 			Absolute velocity of the player as a vector of movement per one
323 			game second.
324 		 
325          */
326         public  Velocity getVelocity()
327  	 {
328 			  			return myVelocity.getValue();
329 			  		}
330 				
331     	
332 	    /**
333          * 
334 			What team the player is on. 255 is no team. 0-3 are red,
335 			blue, green, gold in that order.
336 		 
337          */
338         protected
339          IntProperty 
340         myTeam
341 					= null;
342 					
343 					
344  		/**
345          * 
346 			What team the player is on. 255 is no team. 0-3 are red,
347 			blue, green, gold in that order.
348 		 
349          */
350         public  int getTeam()
351  	 {
352 			  			return myTeam.getValue();
353 			  		}
354 				
355     	
356 	    /**
357          * 
358 			Class of the weapon the player is holding. Weapon strings to
359 			look for include: "AssaultRifle", "ShieldGun", "FlakCannon",
360 			"BioRifle", "ShockRifle", "LinkGun", "SniperRifle",
361 			"RocketLauncher", "Minigun", "LightingGun", "Translocator".
362 			TODO: Look if this is all.
363 		 
364          */
365         protected
366          StringProperty 
367         myWeapon
368 					= null;
369 					
370 					
371  		/**
372          * 
373 			Class of the weapon the player is holding. Weapon strings to
374 			look for include: "AssaultRifle", "ShieldGun", "FlakCannon",
375 			"BioRifle", "ShockRifle", "LinkGun", "SniperRifle",
376 			"RocketLauncher", "Minigun", "LightingGun", "Translocator".
377 			TODO: Look if this is all.
378 		 
379          */
380         public  String getWeapon()
381  	 {
382 			  			return myWeapon.getValue();
383 			  		}
384 				
385     	
386 	    /**
387          * 
388 			True if the bot is crouched.
389 		 
390          */
391         protected
392          BooleanProperty 
393         myCrouched
394 					= null;
395 					
396 					
397  		/**
398          * 
399 			True if the bot is crouched.
400 		 
401          */
402         public  boolean isCrouched()
403  	 {
404 			  			return myCrouched.getValue();
405 			  		}
406 				
407     	
408 	    /**
409          * 
410 			0 means is not firing, 1 - firing in primary mode, 2 -
411 			firing in secondary mode (alt firing).
412 		 
413          */
414         protected
415          IntProperty 
416         myFiring
417 					= null;
418 					
419 					
420  		/**
421          * 
422 			0 means is not firing, 1 - firing in primary mode, 2 -
423 			firing in secondary mode (alt firing).
424 		 
425          */
426         public  int getFiring()
427  	 {
428 			  			return myFiring.getValue();
429 			  		}
430 				
431     	
432 	    /**
433          * 
434 			For UE2. Holds left emoticon of the bot, "None" means none set.
435 		 
436          */
437         protected
438          StringProperty 
439         myEmotLeft
440 					= null;
441 					
442 					
443  		/**
444          * 
445 			For UE2. Holds left emoticon of the bot, "None" means none set.
446 		 
447          */
448         public  String getEmotLeft()
449  	 {
450 			  			return myEmotLeft.getValue();
451 			  		}
452 				
453     	
454 	    /**
455          * 
456 			For UE2. Holds center emoticon of the bot, "None" means none set.
457 		 
458          */
459         protected
460          StringProperty 
461         myEmotCenter
462 					= null;
463 					
464 					
465  		/**
466          * 
467 			For UE2. Holds center emoticon of the bot, "None" means none set.
468 		 
469          */
470         public  String getEmotCenter()
471  	 {
472 			  			return myEmotCenter.getValue();
473 			  		}
474 				
475     	
476 	    /**
477          * 
478 			For UE2. Holds right emoticon of the bot, "None" means none set.
479 		 
480          */
481         protected
482          StringProperty 
483         myEmotRight
484 					= null;
485 					
486 					
487  		/**
488          * 
489 			For UE2. Holds right emoticon of the bot, "None" means none set.
490 		 
491          */
492         public  String getEmotRight()
493  	 {
494 			  			return myEmotRight.getValue();
495 			  		}
496 				
497     	
498 	    /**
499          * 
500 			For UE2. Holds the bubble of the emoticon of the bot, "None" means none set.
501 		 
502          */
503         protected
504          StringProperty 
505         myBubble
506 					= null;
507 					
508 					
509  		/**
510          * 
511 			For UE2. Holds the bubble of the emoticon of the bot, "None" means none set.
512 		 
513          */
514         public  String getBubble()
515  	 {
516 			  			return myBubble.getValue();
517 			  		}
518 				
519     	
520 	    /**
521          * 
522 			For UE2. Current played animation of the bot.
523 		 
524          */
525         protected
526          StringProperty 
527         myAnim
528 					= null;
529 					
530 					
531  		/**
532          * 
533 			For UE2. Current played animation of the bot.
534 		 
535          */
536         public  String getAnim()
537  	 {
538 			  			return myAnim.getValue();
539 			  		}
540 				
541     	
542     	
543     	public static class PlayerSharedUpdate
544      implements ISharedWorldObjectUpdatedEvent
545 		{
546 	
547 			private PlayerShared object;
548 			private long time;
549 			private ITeamId teamId;
550 			
551 			public PlayerSharedUpdate
552     (PlayerShared data, long time, ITeamId teamId)
553 			{
554 				this.object = data;
555 				this.time = time;
556 				this.teamId = teamId;
557 			}
558 			
559 			/**
560 			 * Simulation time in MILLI SECONDS !!!
561 			 */
562 			@Override
563 			public long getSimTime() {
564 				return this.time;
565 			}
566 	
567 			@Override
568 			public WorldObjectId getId() {
569 				return object.getId();
570 			}
571 	
572 			@Override
573 			public ITeamId getTeamId() {
574 				return teamId;
575 			}
576 			
577 			@Override
578 			public Class getCompositeObjectClass()
579 			{
580 				return object.getCompositeClass();
581 			}
582 	
583 			@Override
584 			public Collection<ISharedPropertyUpdatedEvent> getPropertyEvents() {
585 				LinkedList<ISharedPropertyUpdatedEvent> events = new LinkedList<ISharedPropertyUpdatedEvent>();
586 				
587 				for ( ISharedProperty property : object.getProperties().values() )
588 				{
589 					if ( property != null)
590 					{
591 						events.push( property.createUpdateEvent(time, teamId) );
592 					}
593 				}
594 				return events;
595 			}
596 			
597 		}
598 	
599     
600  		
601  	    public String toString() {
602             return
603             	super.toString() + "[" +
604             	
605 		              			"Id = " + String.valueOf(getId()
606  	) + " | " + 
607 		              		
608 		              			"Name = " + String.valueOf(getName()
609  	) + " | " + 
610 		              		
611 		              			"Action = " + String.valueOf(getAction()
612  	) + " | " + 
613 		              		
614 		              			"Rotation = " + String.valueOf(getRotation()
615  	) + " | " + 
616 		              		
617 		              			"Location = " + String.valueOf(getLocation()
618  	) + " | " + 
619 		              		
620 		              			"Velocity = " + String.valueOf(getVelocity()
621  	) + " | " + 
622 		              		
623 		              			"Team = " + String.valueOf(getTeam()
624  	) + " | " + 
625 		              		
626 		              			"Weapon = " + String.valueOf(getWeapon()
627  	) + " | " + 
628 		              		
629 		              			"Crouched = " + String.valueOf(isCrouched()
630  	) + " | " + 
631 		              		
632 		              			"Firing = " + String.valueOf(getFiring()
633  	) + " | " + 
634 		              		
635 		              			"EmotLeft = " + String.valueOf(getEmotLeft()
636  	) + " | " + 
637 		              		
638 		              			"EmotCenter = " + String.valueOf(getEmotCenter()
639  	) + " | " + 
640 		              		
641 		              			"EmotRight = " + String.valueOf(getEmotRight()
642  	) + " | " + 
643 		              		
644 		              			"Bubble = " + String.valueOf(getBubble()
645  	) + " | " + 
646 		              		
647 		              			"Anim = " + String.valueOf(getAnim()
648  	) + " | " + 
649 		              		
650 				"]";           		
651         }
652  	
653  		
654  		public String toHtmlString() {
655  			return super.toString() + "[<br/>" +
656             	
657 		              			"<b>Id</b> = " + String.valueOf(getId()
658  	) + " <br/> " + 
659 		              		
660 		              			"<b>Name</b> = " + String.valueOf(getName()
661  	) + " <br/> " + 
662 		              		
663 		              			"<b>Action</b> = " + String.valueOf(getAction()
664  	) + " <br/> " + 
665 		              		
666 		              			"<b>Rotation</b> = " + String.valueOf(getRotation()
667  	) + " <br/> " + 
668 		              		
669 		              			"<b>Location</b> = " + String.valueOf(getLocation()
670  	) + " <br/> " + 
671 		              		
672 		              			"<b>Velocity</b> = " + String.valueOf(getVelocity()
673  	) + " <br/> " + 
674 		              		
675 		              			"<b>Team</b> = " + String.valueOf(getTeam()
676  	) + " <br/> " + 
677 		              		
678 		              			"<b>Weapon</b> = " + String.valueOf(getWeapon()
679  	) + " <br/> " + 
680 		              		
681 		              			"<b>Crouched</b> = " + String.valueOf(isCrouched()
682  	) + " <br/> " + 
683 		              		
684 		              			"<b>Firing</b> = " + String.valueOf(getFiring()
685  	) + " <br/> " + 
686 		              		
687 		              			"<b>EmotLeft</b> = " + String.valueOf(getEmotLeft()
688  	) + " <br/> " + 
689 		              		
690 		              			"<b>EmotCenter</b> = " + String.valueOf(getEmotCenter()
691  	) + " <br/> " + 
692 		              		
693 		              			"<b>EmotRight</b> = " + String.valueOf(getEmotRight()
694  	) + " <br/> " + 
695 		              		
696 		              			"<b>Bubble</b> = " + String.valueOf(getBubble()
697  	) + " <br/> " + 
698 		              		
699 		              			"<b>Anim</b> = " + String.valueOf(getAnim()
700  	) + " <br/> " + 
701 		              		
702 				"<br/>]";     
703 		}
704  	
705  		
706  		// --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=all]) ---
707         	
708 		// --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=all]) ---
709 		
710 	    // --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=shared+classtype[@name=impl]) ---
711 	        
712 	    // --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=shared+classtype[@name=impl]) ---        	            	
713  	
714 		}
715