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