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 VEH.  
19              			
20           *
21           *  <p></p><p></p>
22           *  Complete message documentation:               
23           *  
24  		Synchronous message. Holds vehicles we see. Id for vehicles doesn't work, so 
25  		this message is without Id. We can join vehicles by ENTER command if we are 
26  		close enough - ussually 100 ut units or less. Note: Vehicle support is 
27  		in aplha testing right now.
28  	
29           */
30   	public abstract class Vehicle   
31    				extends 
32    				InfoMessage
33    						implements IWorldEvent, IWorldChangeEvent, ICompositeWorldObject
34    						
35  	    		,ILocated
36  	    		,ILocomotive
37  	    		,IRotable
38  	    		,IGBViewable
39  	    {
40   	
41      	/** Example how the message looks like - used during parser tests. */
42      	public static final String PROTOTYPE =
43      		"VEH {Id unreal_id}  {Rotation 0,0,0}  {Location 0,0,0}  {Velocity 0,0,0}  {Visible False}  {Team 0}  {Health 0}  {Armor 0}  {Driver unreal_id}  {TeamLocked False}  {Type text} ";
44      
45      	
46      	
47      	/**
48      	 * Parameter-less contructor for the message.
49      	 */
50  		public Vehicle()
51  		{
52  		}
53  	
54  				// abstract message, it does not have any more constructors				
55  			
56  	   		
57  			protected long SimTime;
58  				
59  			/**
60  			 * Simulation time in MILLI SECONDS !!!
61  			 */	
62  			@Override
63  			public long getSimTime() {
64  				return SimTime;
65  			}
66  						
67  			/**
68  			 * Used by Yylex to slip correct time of the object or programmatically.
69  			 */
70  			protected void setSimTime(long SimTime) {
71  				this.SimTime = SimTime;
72  			}
73  	   	
74   		/**
75           * Unique Id of the vehicle or vehicle part. 
76           */
77          public abstract UnrealId getId()
78   	;
79  		    			
80   		/**
81           * 
82  			Which direction the vehicle is facing in absolute terms.
83  		 
84           */
85          public abstract Rotation getRotation()
86   	;
87  		    			
88   		/**
89           * 
90  			An absolute location of the vehicle within the map.
91  		 
92           */
93          public abstract Location getLocation()
94   	;
95  		    			
96   		/**
97           * 
98  			Absolute velocity of the vehicle as a vector of movement per one
99  			game second.
100 		 
101          */
102         public abstract Velocity getVelocity()
103  	;
104 		    			
105  		/**
106          * 
107             If the vehicle is in the field of view of the bot.
108          
109          */
110         public abstract boolean isVisible()
111  	;
112 		    			
113  		/**
114          * 
115 			What team the vehicle is on. 255 is no team. 0-3 are red,
116 			blue, green, gold in that order.
117 		 
118          */
119         public abstract Integer getTeam()
120  	;
121 		    			
122  		/**
123          * 
124 			How much health the vehicle has left. Ranges from 0 to x, depending on the vehicle type.
125 		 
126          */
127         public abstract Integer getHealth()
128  	;
129 		    			
130  		/**
131          * 
132 			How much the vehicle has left. Note: This may be 0 all the time. Maybe the vehicles are not supporting armor.
133 		 
134          */
135         public abstract Integer getArmor()
136  	;
137 		    			
138  		/**
139          * Unique Id of the driver - if any. 
140          */
141         public abstract UnrealId getDriver()
142  	;
143 		    			
144  		/**
145          * 
146             If the vehicle is locked just for its current team.
147          
148          */
149         public abstract boolean isTeamLocked()
150  	;
151 		    			
152  		/**
153          * 
154 			Class of the vehicle. If it is a car, turret etc.
155 		 
156          */
157         public abstract String getType()
158  	;
159 		    			
160 		 	@Override
161 			public IWorldObjectUpdatedEvent createDisappearEvent() {
162 				return new ObjectDisappeared(this, getSimTime());
163 			}
164 			
165 			public static class ObjectDisappeared implements IWorldObjectUpdatedEvent
166 			{
167 				
168 				public ObjectDisappeared(Vehicle obj, long time) {
169 					this.obj = obj;
170 					this.time = time;
171 				}
172 				
173 				private Vehicle obj;
174 				private long time;
175 		
176 				@Override
177 				public WorldObjectId getId() {
178 					return obj.getId();
179 				}
180 		
181 		        /**
182 		         * Simulation time in MILLI SECONDS !!!
183 		         */
184 				@Override
185 				public long getSimTime() {
186 					return time;
187 				}
188 		
189 				@Override
190 				public IWorldObjectUpdateResult<IWorldObject> update(IWorldObject obj) {
191 					if (obj == null) {
192 						throw new PogamutException("Can't 'disappear' null!", this);
193 					}
194 					if (!(obj instanceof VehicleMessage)) {
195 						throw new PogamutException("Can't update different class than VehicleMessage, got class " + obj.getClass().getSimpleName() + "!", this);
196 					}
197 					VehicleMessage toUpdate = (VehicleMessage)obj;
198 					if (toUpdate.Visible) {
199 						toUpdate.Visible = false;
200 						return new IWorldObjectUpdateResult.WorldObjectUpdateResult(IWorldObjectUpdateResult.Result.UPDATED, obj);
201 					} else {
202 						return new IWorldObjectUpdateResult.WorldObjectUpdateResult(IWorldObjectUpdateResult.Result.SAME, obj);
203 					}
204 				}
205 		
206 			}
207 	
208 		
209     	
210     	public static class VehicleUpdate
211      extends GBObjectUpdate implements ICompositeWorldObjectUpdatedEvent, IGBWorldObjectEvent {	
212 			private Vehicle object;
213 			private long time;
214 			private ITeamId teamId;
215 			
216 			public VehicleUpdate
217     (Vehicle source, long eventTime, ITeamId teamId) {
218 				this.object = source;
219 				this.time = eventTime;
220 				this.teamId = teamId;
221 			}
222 			
223 			/**
224 			 * Simulation time in MILLI SECONDS !!!
225 			 */ 
226 			@Override
227 			public long getSimTime() {
228 				return time;
229 			}
230 	
231 			@Override
232 			public IWorldObject getObject() {
233 				return object;
234 			}
235 	
236 			@Override
237 			public WorldObjectId getId() {
238 				return object.getId();
239 			}
240 	
241 			@Override
242 			public ILocalWorldObjectUpdatedEvent getLocalEvent() {
243 				return new VehicleLocalImpl.VehicleLocalUpdate
244     ((VehicleLocal)object.getLocal(), time);
245 			}
246 	
247 			@Override
248 			public ISharedWorldObjectUpdatedEvent getSharedEvent() {
249 				return new VehicleSharedImpl.VehicleSharedUpdate
250     ((VehicleShared)object.getShared(), time, teamId);
251 			}
252 	
253 			@Override
254 			public IStaticWorldObjectUpdatedEvent getStaticEvent() {
255 				return new VehicleStaticImpl.VehicleStaticUpdate
256     ((VehicleStatic)object.getStatic(), time);
257 			}
258 			
259 		}
260     
261  		
262  	    public String toString() {
263             return
264             	super.toString() + "[" +
265             	
266 		              			"Id = " + String.valueOf(getId()
267  	) + " | " + 
268 		              		
269 		              			"Rotation = " + String.valueOf(getRotation()
270  	) + " | " + 
271 		              		
272 		              			"Location = " + String.valueOf(getLocation()
273  	) + " | " + 
274 		              		
275 		              			"Velocity = " + String.valueOf(getVelocity()
276  	) + " | " + 
277 		              		
278 		              			"Visible = " + String.valueOf(isVisible()
279  	) + " | " + 
280 		              		
281 		              			"Team = " + String.valueOf(getTeam()
282  	) + " | " + 
283 		              		
284 		              			"Health = " + String.valueOf(getHealth()
285  	) + " | " + 
286 		              		
287 		              			"Armor = " + String.valueOf(getArmor()
288  	) + " | " + 
289 		              		
290 		              			"Driver = " + String.valueOf(getDriver()
291  	) + " | " + 
292 		              		
293 		              			"TeamLocked = " + String.valueOf(isTeamLocked()
294  	) + " | " + 
295 		              		
296 		              			"Type = " + String.valueOf(getType()
297  	) + " | " + 
298 		              		
299 				"]";           		
300         }
301  	
302  		
303  		public String toHtmlString() {
304  			return super.toString() + "[<br/>" +
305             	
306 		              			"<b>Id</b> = " + String.valueOf(getId()
307  	) + " <br/> " + 
308 		              		
309 		              			"<b>Rotation</b> = " + String.valueOf(getRotation()
310  	) + " <br/> " + 
311 		              		
312 		              			"<b>Location</b> = " + String.valueOf(getLocation()
313  	) + " <br/> " + 
314 		              		
315 		              			"<b>Velocity</b> = " + String.valueOf(getVelocity()
316  	) + " <br/> " + 
317 		              		
318 		              			"<b>Visible</b> = " + String.valueOf(isVisible()
319  	) + " <br/> " + 
320 		              		
321 		              			"<b>Team</b> = " + String.valueOf(getTeam()
322  	) + " <br/> " + 
323 		              		
324 		              			"<b>Health</b> = " + String.valueOf(getHealth()
325  	) + " <br/> " + 
326 		              		
327 		              			"<b>Armor</b> = " + String.valueOf(getArmor()
328  	) + " <br/> " + 
329 		              		
330 		              			"<b>Driver</b> = " + String.valueOf(getDriver()
331  	) + " <br/> " + 
332 		              		
333 		              			"<b>TeamLocked</b> = " + String.valueOf(isTeamLocked()
334  	) + " <br/> " + 
335 		              		
336 		              			"<b>Type</b> = " + String.valueOf(getType()
337  	) + " <br/> " + 
338 		              		
339 				"<br/>]";     
340 		}
341  	 
342  	    public String toJsonLiteral() {
343             return "Vehicle(null, "
344             		
345                    + ")";
346         }
347  	
348  		
349  		// --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=all]) ---
350         	
351 		// --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=all]) ---
352 		
353 	    // --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=base+classtype[@name=abstract]) ---
354 	        
355 	    // --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=base+classtype[@name=abstract]) ---        	            	
356  	
357 		}
358