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