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 MOV.  
19              			
20           *
21           *  <p></p><p></p>
22           *  Complete message documentation:               
23           *  
24  		Synchronous message. Movers can be doors, elevators, or any
25  		other chunk of architecture that can move. They generally need
26  		to be either run into, or activated by shooting or pressing a
27  		button. We are working on ways to provide bots with more of the
28  		information they need to deal with movers appropriately.
29  	
30           */
31   	public class MoverSharedImpl 
32    						extends
33    						MoverShared
34  	    {
35   	
36      
37      	
38      	public MoverSharedImpl(MoverSharedImpl source) {
39  			
40  				this.Id = source.
41  					getId()
42   	;
43  			
44  				this.myLocation = source.myLocation;
45  			
46  				this.myVelocity = source.myVelocity;
47  			
48  				this.myState = source.myState;
49  			
50  		}
51  		
52  		public MoverSharedImpl(WorldObjectId objectId, Collection<ISharedProperty> properties) {
53  			this.Id = (UnrealId)objectId;
54  			NullCheck.check(this.Id, "objectId");
55  		
56  			if (properties.size() != 3) {
57  				throw new PogamutException("Not enough properties passed to the constructor.", MoverSharedImpl.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 MoverSharedImpl with different WorldObjectId properties : " + 
66  											    this.Id.getStringId() + " / " + property.getObjectId().getStringId() , this);
67  				}
68  				if (!MoverShared.SharedPropertyTokens.contains(pId.getPropertyToken())) {
69  				// property that does not belong here
70  				throw new PogamutException("Trying to create a MoverSharedImpl 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("State"))
87  					{
88  						this.myState = (StringProperty)property;
89  					}
90  				
91  			}
92  		}
93      
94     				
95     				@Override
96     				public void setSimTime(long SimTime) {
97  					super.setSimTime(SimTime);
98  				}
99     			
100 	    				@Override
101 	    				public 
102 	    				MoverSharedImpl clone() {
103 	    					return new 
104 	    					MoverSharedImpl(this);
105 	    				}
106 	    				
107 	    				
108 		
109 		
110 		
111 		protected HashMap<PropertyId, ISharedProperty> propertyMap = new HashMap<PropertyId, ISharedProperty>(
112 			3
113 		);
114 		
115 		@Override
116 		public ISharedProperty getProperty(PropertyId id) {
117 			return propertyMap.get(id);
118 		}
119 
120 		@Override
121 		public Map<PropertyId, ISharedProperty> getProperties() {
122 			return propertyMap;
123 		}
124 	
125 		
126 		
127     	
128 	    /**
129          * 
130 			A unique Id of this mover assigned by the game.
131 		 
132          */
133         protected
134          UnrealId Id =
135        	null;
136 	
137  		/**
138          * 
139 			A unique Id of this mover assigned by the game.
140 		 
141          */
142         public  UnrealId getId()
143  	 {
144   			return Id;
145   		}
146   		
147     	
148 	    /**
149          * Location of the mover. 
150          */
151         protected
152          LocationProperty 
153         myLocation
154 					= null;
155 					
156 					
157  		/**
158          * Location of the mover. 
159          */
160         public  Location getLocation()
161  	 {
162 			  			return myLocation.getValue();
163 			  		}
164 				
165     	
166 	    /**
167          * Velocity vector. 
168          */
169         protected
170          VelocityProperty 
171         myVelocity
172 					= null;
173 					
174 					
175  		/**
176          * Velocity vector. 
177          */
178         public  Velocity getVelocity()
179  	 {
180 			  			return myVelocity.getValue();
181 			  		}
182 				
183     	
184 	    /**
185          * Name of the state Mover is currently in. Can be used to determine the type of the mover.  
186          */
187         protected
188          StringProperty 
189         myState
190 					= null;
191 					
192 					
193  		/**
194          * Name of the state Mover is currently in. Can be used to determine the type of the mover.  
195          */
196         public  String getState()
197  	 {
198 			  			return myState.getValue();
199 			  		}
200 				
201     	
202     	
203     	public static class MoverSharedUpdate
204      implements ISharedWorldObjectUpdatedEvent
205 		{
206 	
207 			private MoverShared object;
208 			private long time;
209 			private ITeamId teamId;
210 			
211 			public MoverSharedUpdate
212     (MoverShared data, long time, ITeamId teamId)
213 			{
214 				this.object = data;
215 				this.time = time;
216 				this.teamId = teamId;
217 			}
218 			
219 			/**
220 			 * Simulation time in MILLI SECONDS !!!
221 			 */
222 			@Override
223 			public long getSimTime() {
224 				return this.time;
225 			}
226 	
227 			@Override
228 			public WorldObjectId getId() {
229 				return object.getId();
230 			}
231 	
232 			@Override
233 			public ITeamId getTeamId() {
234 				return teamId;
235 			}
236 			
237 			@Override
238 			public Class getCompositeObjectClass()
239 			{
240 				return object.getCompositeClass();
241 			}
242 	
243 			@Override
244 			public Collection<ISharedPropertyUpdatedEvent> getPropertyEvents() {
245 				LinkedList<ISharedPropertyUpdatedEvent> events = new LinkedList<ISharedPropertyUpdatedEvent>();
246 				
247 				for ( ISharedProperty property : object.getProperties().values() )
248 				{
249 					if ( property != null)
250 					{
251 						events.push( property.createUpdateEvent(time, teamId) );
252 					}
253 				}
254 				return events;
255 			}
256 			
257 		}
258 	
259     
260  		
261  	    public String toString() {
262             return
263             	super.toString() + "[" +
264             	
265 		              			"Id = " + String.valueOf(getId()
266  	) + " | " + 
267 		              		
268 		              			"Location = " + String.valueOf(getLocation()
269  	) + " | " + 
270 		              		
271 		              			"Velocity = " + String.valueOf(getVelocity()
272  	) + " | " + 
273 		              		
274 		              			"State = " + String.valueOf(getState()
275  	) + " | " + 
276 		              		
277 				"]";           		
278         }
279  	
280  		
281  		public String toHtmlString() {
282  			return super.toString() + "[<br/>" +
283             	
284 		              			"<b>Id</b> = " + String.valueOf(getId()
285  	) + " <br/> " + 
286 		              		
287 		              			"<b>Location</b> = " + String.valueOf(getLocation()
288  	) + " <br/> " + 
289 		              		
290 		              			"<b>Velocity</b> = " + String.valueOf(getVelocity()
291  	) + " <br/> " + 
292 		              		
293 		              			"<b>State</b> = " + String.valueOf(getState()
294  	) + " <br/> " + 
295 		              		
296 				"<br/>]";     
297 		}
298  	
299  		
300  		// --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=all]) ---
301         	
302 		// --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=all]) ---
303 		
304 	    // --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=shared+classtype[@name=impl]) ---
305 	        
306 	    // --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=shared+classtype[@name=impl]) ---        	            	
307  	
308 		}
309