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 ENT.  
19              			
20           *
21           *  <p></p><p></p>
22           *  Complete message documentation:               
23           *  
24  		Generic physical entity that may be present in the world. Works as a hook for custom objects, such as new items from EmohawkRPG extension.
25  	
26           */
27   	public abstract class Entity   
28    				extends 
29    				InfoMessage
30    						implements IWorldEvent, IWorldChangeEvent, ICompositeWorldObject
31    						
32  	    		,ILocated
33  	    		,IGBViewable
34  	    {
35   	
36      	/** Example how the message looks like - used during parser tests. */
37      	public static final String PROTOTYPE =
38      		"ENT {Id unreal_id}  {Visible False}  {Location 0,0,0}  {Rotation 0,0,0}  {Velocity 0,0,0}  {Type text}  {EntityClass text} ";
39      
40      	
41      	
42      	/**
43      	 * Parameter-less contructor for the message.
44      	 */
45  		public Entity()
46  		{
47  		}
48  	
49  				// abstract message, it does not have any more constructors				
50  			
51  	   		
52  			protected long SimTime;
53  				
54  			/**
55  			 * Simulation time in MILLI SECONDS !!!
56  			 */	
57  			@Override
58  			public long getSimTime() {
59  				return SimTime;
60  			}
61  						
62  			/**
63  			 * Used by Yylex to slip correct time of the object or programmatically.
64  			 */
65  			protected void setSimTime(long SimTime) {
66  				this.SimTime = SimTime;
67  			}
68  	   	
69   		/**
70           * 
71  			Unique Id of the item. This Id represents some entity in the world.
72  		 
73           */
74          public abstract UnrealId getId()
75   	;
76  		    			
77   		/**
78           * 
79  			If the item is in the field of view of the bot.
80  		 
81           */
82          public abstract boolean isVisible()
83   	;
84  		    			
85   		/**
86           * Location of the item. 
87           */
88          public abstract Location getLocation()
89   	;
90  		    			
91   		/**
92           * Rotation of the item. 
93           */
94          public abstract Rotation getRotation()
95   	;
96  		    			
97   		/**
98           * Velocity of the item. 
99           */
100         public abstract Velocity getVelocity()
101  	;
102 		    			
103  		/**
104          * Type (category) of the entity. 
105          */
106         public abstract String getType()
107  	;
108 		    			
109  		/**
110          * Type (category) of the entity. 
111          */
112         public abstract String getEntityClass()
113  	;
114 		    			
115 		 	@Override
116 			public IWorldObjectUpdatedEvent createDisappearEvent() {
117 				return new ObjectDisappeared(this, getSimTime());
118 			}
119 			
120 			public static class ObjectDisappeared implements IWorldObjectUpdatedEvent
121 			{
122 				
123 				public ObjectDisappeared(Entity obj, long time) {
124 					this.obj = obj;
125 					this.time = time;
126 				}
127 				
128 				private Entity 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<IWorldObject> update(IWorldObject obj) {
146 					if (obj == null) {
147 						throw new PogamutException("Can't 'disappear' null!", this);
148 					}
149 					if (!(obj instanceof EntityMessage)) {
150 						throw new PogamutException("Can't update different class than EntityMessage, got class " + obj.getClass().getSimpleName() + "!", this);
151 					}
152 					EntityMessage toUpdate = (EntityMessage)obj;
153 					if (toUpdate.Visible) {
154 						toUpdate.Visible = false;
155 						return new IWorldObjectUpdateResult.WorldObjectUpdateResult(IWorldObjectUpdateResult.Result.UPDATED, obj);
156 					} else {
157 						return new IWorldObjectUpdateResult.WorldObjectUpdateResult(IWorldObjectUpdateResult.Result.SAME, obj);
158 					}
159 				}
160 		
161 			}
162 	
163 		
164     	
165     	public static class EntityUpdate
166      extends GBObjectUpdate implements ICompositeWorldObjectUpdatedEvent, IGBWorldObjectEvent {	
167 			private Entity object;
168 			private long time;
169 			private ITeamId teamId;
170 			
171 			public EntityUpdate
172     (Entity source, long eventTime, ITeamId teamId) {
173 				this.object = source;
174 				this.time = eventTime;
175 				this.teamId = teamId;
176 			}
177 			
178 			/**
179 			 * Simulation time in MILLI SECONDS !!!
180 			 */ 
181 			@Override
182 			public long getSimTime() {
183 				return time;
184 			}
185 	
186 			@Override
187 			public IWorldObject getObject() {
188 				return object;
189 			}
190 	
191 			@Override
192 			public WorldObjectId getId() {
193 				return object.getId();
194 			}
195 	
196 			@Override
197 			public ILocalWorldObjectUpdatedEvent getLocalEvent() {
198 				return new EntityLocalImpl.EntityLocalUpdate
199     ((EntityLocal)object.getLocal(), time);
200 			}
201 	
202 			@Override
203 			public ISharedWorldObjectUpdatedEvent getSharedEvent() {
204 				return new EntitySharedImpl.EntitySharedUpdate
205     ((EntityShared)object.getShared(), time, teamId);
206 			}
207 	
208 			@Override
209 			public IStaticWorldObjectUpdatedEvent getStaticEvent() {
210 				return new EntityStaticImpl.EntityStaticUpdate
211     ((EntityStatic)object.getStatic(), time);
212 			}
213 			
214 		}
215     
216  		
217  	    public String toString() {
218             return
219             	super.toString() + "[" +
220             	
221 		              			"Id = " + String.valueOf(getId()
222  	) + " | " + 
223 		              		
224 		              			"Visible = " + String.valueOf(isVisible()
225  	) + " | " + 
226 		              		
227 		              			"Location = " + String.valueOf(getLocation()
228  	) + " | " + 
229 		              		
230 		              			"Rotation = " + String.valueOf(getRotation()
231  	) + " | " + 
232 		              		
233 		              			"Velocity = " + String.valueOf(getVelocity()
234  	) + " | " + 
235 		              		
236 		              			"Type = " + String.valueOf(getType()
237  	) + " | " + 
238 		              		
239 		              			"EntityClass = " + String.valueOf(getEntityClass()
240  	) + " | " + 
241 		              		
242 				"]";           		
243         }
244  	
245  		
246  		public String toHtmlString() {
247  			return super.toString() + "[<br/>" +
248             	
249 		              			"<b>Id</b> = " + String.valueOf(getId()
250  	) + " <br/> " + 
251 		              		
252 		              			"<b>Visible</b> = " + String.valueOf(isVisible()
253  	) + " <br/> " + 
254 		              		
255 		              			"<b>Location</b> = " + String.valueOf(getLocation()
256  	) + " <br/> " + 
257 		              		
258 		              			"<b>Rotation</b> = " + String.valueOf(getRotation()
259  	) + " <br/> " + 
260 		              		
261 		              			"<b>Velocity</b> = " + String.valueOf(getVelocity()
262  	) + " <br/> " + 
263 		              		
264 		              			"<b>Type</b> = " + String.valueOf(getType()
265  	) + " <br/> " + 
266 		              		
267 		              			"<b>EntityClass</b> = " + String.valueOf(getEntityClass()
268  	) + " <br/> " + 
269 		              		
270 				"<br/>]";     
271 		}
272  	
273  	    public String toJsonLiteral() {
274             return "entity( "
275             		+
276 									(getId()
277  	 == null ? "null" :
278 										"\"" + getId()
279  	.getStringId() + "\"" 
280 									)
281 								+ ", " + 
282 								    String.valueOf(isVisible()
283  	)									
284 								+ ", " + 
285 								    (getLocation()
286  	 == null ? "null" :
287 										"[" + getLocation()
288  	.getX() + ", " + getLocation()
289  	.getY() + ", " + getLocation()
290  	.getZ() + "]" 
291 									)
292 								+ ", " + 
293 									(getRotation()
294  	 == null ? "null" :
295 										"[" + getRotation()
296  	.getPitch() + ", " + getRotation()
297  	.getYaw() + ", " + getRotation()
298  	.getRoll() + "]" 
299 									)								    
300 								+ ", " + 
301 								    (getVelocity()
302  	 == null ? "null" :
303 										"[" + getVelocity()
304  	.getX() + ", " + getVelocity()
305  	.getY() + ", " + getVelocity()
306  	.getZ() + "]" 
307 									)
308 								+ ", " + 
309 									(getType()
310  	 == null ? "null" :
311 										"\"" + getType()
312  	 + "\"" 
313 									)
314 								+ ", " + 
315 									(getEntityClass()
316  	 == null ? "null" :
317 										"\"" + getEntityClass()
318  	 + "\"" 
319 									)
320 								
321                    + ")";
322         }
323  	
324  		
325  		// --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=all]) ---
326         	
327 		// --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=all]) ---
328 		
329 	    // --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=base+classtype[@name=abstract]) ---
330 	        
331 	    // --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=base+classtype[@name=abstract]) ---        	            	
332  	
333 		}
334