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