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=abstract] BEGIN
13  		
14  		// --- IMPORTS FROM extra/code/java/javapart/classcategory[@name=local]+classtype[@name=abstract] END
15      
16   		/**
17           *  
18              				Abstract definition 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 abstract class PlayerLocal 
31    						extends InfoMessage
32    						implements ILocalWorldObject
33    						
34  	    		,ILocalGBViewable
35  	    {
36   	
37      	
38      	
39      	/**
40      	 * Parameter-less contructor for the message.
41      	 */
42  		public PlayerLocal()
43  		{
44  		}
45  		
46  				// abstract definition of the local-part of the message, no more constructors is needed
47  			
48  	   		
49  			protected long SimTime;
50  				
51  			/**
52  			 * Simulation time in MILLI SECONDS !!!
53  			 */	
54  			@Override
55  			public long getSimTime() {
56  				return SimTime;
57  			}
58  						
59  			/**
60  			 * Used by Yylex to slip correct time of the object or programmatically.
61  			 */
62  			protected void setSimTime(long SimTime) {
63  				this.SimTime = SimTime;
64  			}
65  	   	
66  	    			
67  	    				@Override
68  		    			public abstract 
69  		    			PlayerLocal clone();
70  		    			
71  						@Override
72  						public Class getCompositeClass() {
73  							return Player.class;
74  						}
75  	
76  						
77  		    			
78   		/**
79           * Unique Id of the player. 
80           */
81          public abstract UnrealId getId()
82   	;
83  		    			
84   		/**
85           * 
86  			Exported just for control server. Holds jmx address we need to connect to
87              when we want to debug our bot.
88  		 
89           */
90          public abstract String getJmx()
91   	;
92  		    			
93   		/**
94           * 
95              If the player is in the field of view of the bot.
96           
97           */
98          public abstract boolean isVisible()
99   	;
100 		    			
101     	
102     	
103     	
104     	public PlayerLocal getLocal() {
105 			return this;
106     	}
107 		public ISharedWorldObject getShared() {
108 		 	throw new UnsupportedOperationException("Could not return LOCAL");
109 		}
110 		public IStaticWorldObject getStatic() {
111 		    throw new UnsupportedOperationException("Could not return LOCAL");
112 		}
113  	
114  		
115 		 	@Override
116 			public ILocalWorldObjectUpdatedEvent createDisappearEvent() {
117 				return new ObjectDisappeared(this, getSimTime());
118 			}
119 			
120 			public static class ObjectDisappeared implements ILocalWorldObjectUpdatedEvent
121 			{
122 				
123 				public ObjectDisappeared(PlayerLocal obj, long time) {
124 					this.obj = obj;
125 					this.time = time;
126 				}
127 				
128 				private PlayerLocal obj;
129 				private long time;
130 		
131 				@Override
132 				public WorldObjectId getId() {
133 					return obj.getId();
134 				}
135 		
136 		        /**
137 		         * Simulation time in MILLI SECONDS !!!
138 		         */
139 				@Override
140 				public long getSimTime() {
141 					return time;
142 				}
143 		
144 				@Override
145 				public IWorldObjectUpdateResult<ILocalWorldObject> update(ILocalWorldObject obj) 
146 				{
147 					if (obj == null) {
148 						throw new PogamutException("Can't 'disappear' null!", this);
149 					}
150 					if (!(obj instanceof PlayerLocalImpl)) {
151 						throw new PogamutException("Can't update different class than PlayerLocalImpl, got class " + obj.getClass().getSimpleName() + "!", this);
152 					}
153 					PlayerLocalImpl toUpdate = (PlayerLocalImpl)obj;
154 					if (toUpdate.Visible) {
155 						toUpdate.Visible = false;
156 						return new IWorldObjectUpdateResult.WorldObjectUpdateResult(IWorldObjectUpdateResult.Result.UPDATED, obj);
157 					} else {
158 						return new IWorldObjectUpdateResult.WorldObjectUpdateResult(IWorldObjectUpdateResult.Result.SAME, obj);
159 					}	
160 				}
161 				
162 			}
163 	
164 		
165  		
166  	    public String toString() {
167             return
168             	super.toString() + "[" +
169             	
170 		              			"Id = " + String.valueOf(getId()
171  	) + " | " + 
172 		              		
173 		              			"Jmx = " + String.valueOf(getJmx()
174  	) + " | " + 
175 		              		
176 		              			"Visible = " + String.valueOf(isVisible()
177  	) + " | " + 
178 		              		
179 				"]";           		
180         }
181  	
182  		
183  		public String toHtmlString() {
184  			return super.toString() + "[<br/>" +
185             	
186 		              			"<b>Id</b> = " + String.valueOf(getId()
187  	) + " <br/> " + 
188 		              		
189 		              			"<b>Jmx</b> = " + String.valueOf(getJmx()
190  	) + " <br/> " + 
191 		              		
192 		              			"<b>Visible</b> = " + String.valueOf(isVisible()
193  	) + " <br/> " + 
194 		              		
195 				"<br/>]";     
196 		}
197  	
198  		
199  		// --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=all]) ---
200         	
201 		// --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=all]) ---
202 		
203 	    // --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=local+classtype[@name=abstract]) ---
204 	        
205 	    // --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=local+classtype[@name=abstract]) ---        	            	
206  	
207 		}
208