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 NAV.  
19              			
20           *
21           *  <p></p><p></p>
22           *  Complete message documentation:               
23           *  
24  		Synchronous message. NavPoint carries information about UT
25  		navigation point - location, reachability... Also some item can
26  		be respawned at this point. Or some additional information can
27  		be stored here (if it is an ambush point, or sniper point..).
28  	
29           */
30   	public class NavPointSharedImpl 
31    						extends
32    						NavPointShared
33  	    {
34   	
35      
36      	
37      	public NavPointSharedImpl(NavPointSharedImpl source) {
38  			
39  				this.Id = source.
40  					getId()
41   	;
42  			
43  				this.myLocation = source.myLocation;
44  			
45  				this.myVelocity = source.myVelocity;
46  			
47  				this.myItemSpawned = source.myItemSpawned;
48  			
49  				this.myDoorOpened = source.myDoorOpened;
50  			
51  				this.myInvSpot = source.myInvSpot;
52  			
53  				this.myPlayerStart = source.myPlayerStart;
54  			
55  		}
56  		
57  		public NavPointSharedImpl(WorldObjectId objectId, Collection<ISharedProperty> properties) {
58  			this.Id = (UnrealId)objectId;
59  			NullCheck.check(this.Id, "objectId");
60  		
61  			if (properties.size() != 6) {
62  				throw new PogamutException("Not enough properties passed to the constructor.", NavPointSharedImpl.class);
63  			}
64  		
65  			//we have to do some checking in this one to know that we get all properties required
66  			for ( ISharedProperty property : properties ) {
67  				PropertyId pId = property.getPropertyId();
68  				if ( !objectId.equals( property.getObjectId() )) {
69  					//properties for different objects
70  					throw new PogamutException("Trying to create a NavPointSharedImpl with different WorldObjectId properties : " + 
71  											    this.Id.getStringId() + " / " + property.getObjectId().getStringId() , this);
72  				}
73  				if (!NavPointShared.SharedPropertyTokens.contains(pId.getPropertyToken())) {
74  				// property that does not belong here
75  				throw new PogamutException("Trying to create a NavPointSharedImpl with invalid property (invalid property token): " + 
76  					this.Id.getStringId() + " / " + property.getPropertyId().getPropertyToken().getToken() , this);
77  				}
78  				propertyMap.put(property.getPropertyId(), property);
79  				
80  				
81  					if (pId.getPropertyToken().getToken().equals("Location"))
82  					{
83  						this.myLocation = (LocationProperty)property;
84  					}
85  				
86  					if (pId.getPropertyToken().getToken().equals("Velocity"))
87  					{
88  						this.myVelocity = (VelocityProperty)property;
89  					}
90  				
91  					if (pId.getPropertyToken().getToken().equals("ItemSpawned"))
92  					{
93  						this.myItemSpawned = (BooleanProperty)property;
94  					}
95  				
96  					if (pId.getPropertyToken().getToken().equals("DoorOpened"))
97  					{
98  						this.myDoorOpened = (BooleanProperty)property;
99  					}
100 				
101 					if (pId.getPropertyToken().getToken().equals("InvSpot"))
102 					{
103 						this.myInvSpot = (BooleanProperty)property;
104 					}
105 				
106 					if (pId.getPropertyToken().getToken().equals("PlayerStart"))
107 					{
108 						this.myPlayerStart = (BooleanProperty)property;
109 					}
110 				
111 			}
112 		}
113     
114    				
115    				@Override
116    				public void setSimTime(long SimTime) {
117 					super.setSimTime(SimTime);
118 				}
119    			
120 	    				@Override
121 	    				public 
122 	    				NavPointSharedImpl clone() {
123 	    					return new 
124 	    					NavPointSharedImpl(this);
125 	    				}
126 	    				
127 	    				
128 		
129 		
130 		
131 		protected HashMap<PropertyId, ISharedProperty> propertyMap = new HashMap<PropertyId, ISharedProperty>(
132 			6
133 		);
134 		
135 		@Override
136 		public ISharedProperty getProperty(PropertyId id) {
137 			return propertyMap.get(id);
138 		}
139 
140 		@Override
141 		public Map<PropertyId, ISharedProperty> getProperties() {
142 			return propertyMap;
143 		}
144 	
145 		
146 		
147     	
148 	    /**
149          * 
150 			A unique Id of this navigation point assigned by the game.
151 		 
152          */
153         protected
154          UnrealId Id =
155        	null;
156 	
157  		/**
158          * 
159 			A unique Id of this navigation point assigned by the game.
160 		 
161          */
162         public  UnrealId getId()
163  	 {
164   			return Id;
165   		}
166   		
167     	
168 	    /**
169          * Location of navigation point. 
170          */
171         protected
172          LocationProperty 
173         myLocation
174 					= null;
175 					
176 					
177  		/**
178          * Location of navigation point. 
179          */
180         public  Location getLocation()
181  	 {
182 			  			return myLocation.getValue();
183 			  		}
184 				
185     	
186 	    /**
187          * 
188 			Velocity of the navigation point (if the navigation point is
189 			currently moving). Not sent at the moment.
190 		 
191          */
192         protected
193          VelocityProperty 
194         myVelocity
195 					= null;
196 					
197 					
198  		/**
199          * 
200 			Velocity of the navigation point (if the navigation point is
201 			currently moving). Not sent at the moment.
202 		 
203          */
204         public  Velocity getVelocity()
205  	 {
206 			  			return myVelocity.getValue();
207 			  		}
208 				
209     	
210 	    /**
211          * 
212             True if the item is spawned at the point. Not sent if point is not an inventory spot. 
213          
214          */
215         protected
216          BooleanProperty 
217         myItemSpawned
218 					= null;
219 					
220 					
221  		/**
222          * 
223             True if the item is spawned at the point. Not sent if point is not an inventory spot. 
224          
225          */
226         public  boolean isItemSpawned()
227  	 {
228 			  			return myItemSpawned.getValue();
229 			  		}
230 				
231     	
232 	    /**
233          * 
234             True if this NavPoint is a Door and door is opened. Not sent if point is not a door.
235          
236          */
237         protected
238          BooleanProperty 
239         myDoorOpened
240 					= null;
241 					
242 					
243  		/**
244          * 
245             True if this NavPoint is a Door and door is opened. Not sent if point is not a door.
246          
247          */
248         public  boolean isDoorOpened()
249  	 {
250 			  			return myDoorOpened.getValue();
251 			  		}
252 				
253     	
254 	    /**
255          * 
256 			If this is an inventory spot (item is respawned at this point).
257 		 
258          */
259         protected
260          BooleanProperty 
261         myInvSpot
262 					= null;
263 					
264 					
265  		/**
266          * 
267 			If this is an inventory spot (item is respawned at this point).
268 		 
269          */
270         public  boolean isInvSpot()
271  	 {
272 			  			return myInvSpot.getValue();
273 			  		}
274 				
275     	
276 	    /**
277          * 
278 			If this is a player start (players and/or bots are respawned at this point).
279 		 
280          */
281         protected
282          BooleanProperty 
283         myPlayerStart
284 					= null;
285 					
286 					
287  		/**
288          * 
289 			If this is a player start (players and/or bots are respawned at this point).
290 		 
291          */
292         public  boolean isPlayerStart()
293  	 {
294 			  			return myPlayerStart.getValue();
295 			  		}
296 				
297     	
298     	
299     	public static class NavPointSharedUpdate
300      implements ISharedWorldObjectUpdatedEvent
301 		{
302 	
303 			private NavPointShared object;
304 			private long time;
305 			private ITeamId teamId;
306 			
307 			public NavPointSharedUpdate
308     (NavPointShared data, long time, ITeamId teamId)
309 			{
310 				this.object = data;
311 				this.time = time;
312 				this.teamId = teamId;
313 			}
314 			
315 			/**
316 			 * Simulation time in MILLI SECONDS !!!
317 			 */
318 			@Override
319 			public long getSimTime() {
320 				return this.time;
321 			}
322 	
323 			@Override
324 			public WorldObjectId getId() {
325 				return object.getId();
326 			}
327 	
328 			@Override
329 			public ITeamId getTeamId() {
330 				return teamId;
331 			}
332 			
333 			@Override
334 			public Class getCompositeObjectClass()
335 			{
336 				return object.getCompositeClass();
337 			}
338 	
339 			@Override
340 			public Collection<ISharedPropertyUpdatedEvent> getPropertyEvents() {
341 				LinkedList<ISharedPropertyUpdatedEvent> events = new LinkedList<ISharedPropertyUpdatedEvent>();
342 				
343 				for ( ISharedProperty property : object.getProperties().values() )
344 				{
345 					if ( property != null)
346 					{
347 						events.push( property.createUpdateEvent(time, teamId) );
348 					}
349 				}
350 				return events;
351 			}
352 			
353 		}
354 	
355     
356  		
357  	    public String toString() {
358             return
359             	super.toString() + "[" +
360             	
361 		              			"Id = " + String.valueOf(getId()
362  	) + " | " + 
363 		              		
364 		              			"Location = " + String.valueOf(getLocation()
365  	) + " | " + 
366 		              		
367 		              			"Velocity = " + String.valueOf(getVelocity()
368  	) + " | " + 
369 		              		
370 		              			"ItemSpawned = " + String.valueOf(isItemSpawned()
371  	) + " | " + 
372 		              		
373 		              			"DoorOpened = " + String.valueOf(isDoorOpened()
374  	) + " | " + 
375 		              		
376 		              			"InvSpot = " + String.valueOf(isInvSpot()
377  	) + " | " + 
378 		              		
379 		              			"PlayerStart = " + String.valueOf(isPlayerStart()
380  	) + " | " + 
381 		              		
382 				"]";           		
383         }
384  	
385  		
386  		public String toHtmlString() {
387  			return super.toString() + "[<br/>" +
388             	
389 		              			"<b>Id</b> = " + String.valueOf(getId()
390  	) + " <br/> " + 
391 		              		
392 		              			"<b>Location</b> = " + String.valueOf(getLocation()
393  	) + " <br/> " + 
394 		              		
395 		              			"<b>Velocity</b> = " + String.valueOf(getVelocity()
396  	) + " <br/> " + 
397 		              		
398 		              			"<b>ItemSpawned</b> = " + String.valueOf(isItemSpawned()
399  	) + " <br/> " + 
400 		              		
401 		              			"<b>DoorOpened</b> = " + String.valueOf(isDoorOpened()
402  	) + " <br/> " + 
403 		              		
404 		              			"<b>InvSpot</b> = " + String.valueOf(isInvSpot()
405  	) + " <br/> " + 
406 		              		
407 		              			"<b>PlayerStart</b> = " + String.valueOf(isPlayerStart()
408  	) + " <br/> " + 
409 		              		
410 				"<br/>]";     
411 		}
412  	
413  		
414  		// --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=all]) ---
415         	
416 		// --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=all]) ---
417 		
418 	    // --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=shared+classtype[@name=impl]) ---
419 	        
420 	    // --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=shared+classtype[@name=impl]) ---        	            	
421  	
422 		}
423