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