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 MOV.  
19              			
20           *
21           *  <p></p><p></p>
22           *  Complete message documentation:               
23           *  
24  		Synchronous message. Movers can be doors, elevators, or any
25  		other chunk of architecture that can move. They generally need
26  		to be either run into, or activated by shooting or pressing a
27  		button. We are working on ways to provide bots with more of the
28  		information they need to deal with movers appropriately.
29  	
30           */
31   	public abstract class Mover   
32    				extends 
33    				InfoMessage
34    						implements IWorldEvent, IWorldChangeEvent, ICompositeWorldObject
35    						
36  	    		,ILocated
37  	    		,ILocomotive
38  	    		,IGBViewable
39  	    {
40   	
41      	/** Example how the message looks like - used during parser tests. */
42      	public static final String PROTOTYPE =
43      		"MOV {Id unreal_id}  {Location 0,0,0}  {Visible False}  {DamageTrig False}  {Type text}  {IsMoving False}  {Velocity 0,0,0}  {MoveTime 0}  {OpenTime 0}  {BasePos 0,0,0}  {BaseRot 0,0,0}  {DelayTime 0}  {State text}  {NavPointMarker unreal_id} ";
44      
45      	
46      	
47      	/**
48      	 * Parameter-less contructor for the message.
49      	 */
50  		public Mover()
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           * 
76  			A unique Id of this mover assigned by the game.
77  		 
78           */
79          public abstract UnrealId getId()
80   	;
81  		    			
82   		/**
83           * Location of the mover. 
84           */
85          public abstract Location getLocation()
86   	;
87  		    			
88   		/**
89           * If the mover is in the field of view of the bot. 
90           */
91          public abstract boolean isVisible()
92   	;
93  		    			
94   		/**
95           * 
96  			True if the mover needs to be shot to be activated.
97  		 
98           */
99          public abstract boolean isDamageTrig()
100  	;
101 		    			
102  		/**
103          * String class of the mover. 
104          */
105         public abstract String getType()
106  	;
107 		    			
108  		/**
109          * Does the mover move right now? 
110          */
111         public abstract boolean isIsMoving()
112  	;
113 		    			
114  		/**
115          * Velocity vector. 
116          */
117         public abstract Velocity getVelocity()
118  	;
119 		    			
120  		/**
121          * How long the mover moves, when it becomes triggered, before it stops. 
122          */
123         public abstract double getMoveTime()
124  	;
125 		    			
126  		/**
127          * How long the mover stands still when it reaches its destination position. After
128       this time, the mover returns back to its initial position. 
129          */
130         public abstract double getOpenTime()
131  	;
132 		    			
133  		/**
134          * Base position of the mover. 
135          */
136         public abstract Location getBasePos()
137  	;
138 		    			
139  		/**
140          * Base rotation of the mover. 
141          */
142         public abstract Location getBaseRot()
143  	;
144 		    			
145  		/**
146          * Delay before starting to open (or before lift starts to move). 
147          */
148         public abstract double getDelayTime()
149  	;
150 		    			
151  		/**
152          * Name of the state Mover is currently in. Can be used to determine the type of the mover.  
153          */
154         public abstract String getState()
155  	;
156 		    			
157  		/**
158          * Navigation point marking this mover. We can parse this Id to get information about type of the mover. Marker Id contains "lift" string if it is a lift, "door" string if it is a door, etc.  
159          */
160         public abstract UnrealId getNavPointMarker()
161  	;
162 		    			
163 		 	@Override
164 			public IWorldObjectUpdatedEvent createDisappearEvent() {
165 				return new ObjectDisappeared(this, getSimTime());
166 			}
167 			
168 			public static class ObjectDisappeared implements IWorldObjectUpdatedEvent
169 			{
170 				
171 				public ObjectDisappeared(Mover obj, long time) {
172 					this.obj = obj;
173 					this.time = time;
174 				}
175 				
176 				private Mover obj;
177 				private long time;
178 		
179 				@Override
180 				public WorldObjectId getId() {
181 					return obj.getId();
182 				}
183 		
184 		        /**
185 		         * Simulation time in MILLI SECONDS !!!
186 		         */
187 				@Override
188 				public long getSimTime() {
189 					return time;
190 				}
191 		
192 				@Override
193 				public IWorldObjectUpdateResult<IWorldObject> update(IWorldObject obj) {
194 					if (obj == null) {
195 						throw new PogamutException("Can't 'disappear' null!", this);
196 					}
197 					if (!(obj instanceof MoverMessage)) {
198 						throw new PogamutException("Can't update different class than MoverMessage, got class " + obj.getClass().getSimpleName() + "!", this);
199 					}
200 					MoverMessage toUpdate = (MoverMessage)obj;
201 					if (toUpdate.Visible) {
202 						toUpdate.Visible = false;
203 						return new IWorldObjectUpdateResult.WorldObjectUpdateResult(IWorldObjectUpdateResult.Result.UPDATED, obj);
204 					} else {
205 						return new IWorldObjectUpdateResult.WorldObjectUpdateResult(IWorldObjectUpdateResult.Result.SAME, obj);
206 					}
207 				}
208 		
209 			}
210 	
211 		
212     	
213     	public static class MoverUpdate
214      extends GBObjectUpdate implements ICompositeWorldObjectUpdatedEvent, IGBWorldObjectEvent {	
215 			private Mover object;
216 			private long time;
217 			private ITeamId teamId;
218 			
219 			public MoverUpdate
220     (Mover source, long eventTime, ITeamId teamId) {
221 				this.object = source;
222 				this.time = eventTime;
223 				this.teamId = teamId;
224 			}
225 			
226 			/**
227 			 * Simulation time in MILLI SECONDS !!!
228 			 */ 
229 			@Override
230 			public long getSimTime() {
231 				return time;
232 			}
233 	
234 			@Override
235 			public IWorldObject getObject() {
236 				return object;
237 			}
238 	
239 			@Override
240 			public WorldObjectId getId() {
241 				return object.getId();
242 			}
243 	
244 			@Override
245 			public ILocalWorldObjectUpdatedEvent getLocalEvent() {
246 				return new MoverLocalImpl.MoverLocalUpdate
247     ((MoverLocal)object.getLocal(), time);
248 			}
249 	
250 			@Override
251 			public ISharedWorldObjectUpdatedEvent getSharedEvent() {
252 				return new MoverSharedImpl.MoverSharedUpdate
253     ((MoverShared)object.getShared(), time, teamId);
254 			}
255 	
256 			@Override
257 			public IStaticWorldObjectUpdatedEvent getStaticEvent() {
258 				return new MoverStaticImpl.MoverStaticUpdate
259     ((MoverStatic)object.getStatic(), time);
260 			}
261 			
262 		}
263     
264  		
265  	    public String toString() {
266             return
267             	super.toString() + "[" +
268             	
269 		              			"Id = " + String.valueOf(getId()
270  	) + " | " + 
271 		              		
272 		              			"Location = " + String.valueOf(getLocation()
273  	) + " | " + 
274 		              		
275 		              			"Visible = " + String.valueOf(isVisible()
276  	) + " | " + 
277 		              		
278 		              			"DamageTrig = " + String.valueOf(isDamageTrig()
279  	) + " | " + 
280 		              		
281 		              			"Type = " + String.valueOf(getType()
282  	) + " | " + 
283 		              		
284 		              			"IsMoving = " + String.valueOf(isIsMoving()
285  	) + " | " + 
286 		              		
287 		              			"Velocity = " + String.valueOf(getVelocity()
288  	) + " | " + 
289 		              		
290 		              			"MoveTime = " + String.valueOf(getMoveTime()
291  	) + " | " + 
292 		              		
293 		              			"OpenTime = " + String.valueOf(getOpenTime()
294  	) + " | " + 
295 		              		
296 		              			"BasePos = " + String.valueOf(getBasePos()
297  	) + " | " + 
298 		              		
299 		              			"BaseRot = " + String.valueOf(getBaseRot()
300  	) + " | " + 
301 		              		
302 		              			"DelayTime = " + String.valueOf(getDelayTime()
303  	) + " | " + 
304 		              		
305 		              			"State = " + String.valueOf(getState()
306  	) + " | " + 
307 		              		
308 		              			"NavPointMarker = " + String.valueOf(getNavPointMarker()
309  	) + " | " + 
310 		              		
311 				"]";           		
312         }
313  	
314  		
315  		public String toHtmlString() {
316  			return super.toString() + "[<br/>" +
317             	
318 		              			"<b>Id</b> = " + String.valueOf(getId()
319  	) + " <br/> " + 
320 		              		
321 		              			"<b>Location</b> = " + String.valueOf(getLocation()
322  	) + " <br/> " + 
323 		              		
324 		              			"<b>Visible</b> = " + String.valueOf(isVisible()
325  	) + " <br/> " + 
326 		              		
327 		              			"<b>DamageTrig</b> = " + String.valueOf(isDamageTrig()
328  	) + " <br/> " + 
329 		              		
330 		              			"<b>Type</b> = " + String.valueOf(getType()
331  	) + " <br/> " + 
332 		              		
333 		              			"<b>IsMoving</b> = " + String.valueOf(isIsMoving()
334  	) + " <br/> " + 
335 		              		
336 		              			"<b>Velocity</b> = " + String.valueOf(getVelocity()
337  	) + " <br/> " + 
338 		              		
339 		              			"<b>MoveTime</b> = " + String.valueOf(getMoveTime()
340  	) + " <br/> " + 
341 		              		
342 		              			"<b>OpenTime</b> = " + String.valueOf(getOpenTime()
343  	) + " <br/> " + 
344 		              		
345 		              			"<b>BasePos</b> = " + String.valueOf(getBasePos()
346  	) + " <br/> " + 
347 		              		
348 		              			"<b>BaseRot</b> = " + String.valueOf(getBaseRot()
349  	) + " <br/> " + 
350 		              		
351 		              			"<b>DelayTime</b> = " + String.valueOf(getDelayTime()
352  	) + " <br/> " + 
353 		              		
354 		              			"<b>State</b> = " + String.valueOf(getState()
355  	) + " <br/> " + 
356 		              		
357 		              			"<b>NavPointMarker</b> = " + String.valueOf(getNavPointMarker()
358  	) + " <br/> " + 
359 		              		
360 				"<br/>]";     
361 		}
362  	 
363  	    public String toJsonLiteral() {
364             return "Mover(null, "
365             		
366                    + ")";
367         }
368  	
369  		
370  		// --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=all]) ---
371         	
372 		// --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=all]) ---
373 		
374 	    // --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=base+classtype[@name=abstract]) ---
375 	        
376 	    // --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=base+classtype[@name=abstract]) ---        	            	
377  	
378 		}
379