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