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=local]+classtype[@name=impl] BEGIN
13  		
14  		// --- IMPORTS FROM extra/code/java/javapart/classcategory[@name=local]+classtype[@name=impl] END
15      
16   		/**
17           *  
18              				Implementation of the local 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 MoverLocalImpl 
32    						extends
33    						MoverLocal
34  	    {
35   	
36      	
37      	
38      	/**
39      	 * Parameter-less contructor for the message.
40      	 */
41  		public MoverLocalImpl()
42  		{
43  		}
44  	
45      	
46      	
47      	
48      	/**
49  		 * Creates new instance of the message Mover.
50  		 * 
51  		Synchronous message. Movers can be doors, elevators, or any
52  		other chunk of architecture that can move. They generally need
53  		to be either run into, or activated by shooting or pressing a
54  		button. We are working on ways to provide bots with more of the
55  		information they need to deal with movers appropriately.
56  	
57  		 * Corresponding GameBots message
58  		 *   (local part)
59  		 *   is
60  		 *   MOV.
61  		 * 
62   	  	 * 
63  		 *   
64  		 *     @param Id 
65  			A unique Id of this mover assigned by the game.
66  		
67  		 *   
68  		 * 
69  		 *   
70  		 * 
71  		 *   
72  		 *     @param Visible If the mover is in the field of view of the bot.
73  		 *   
74  		 * 
75  		 *   
76  		 * 
77  		 *   
78  		 * 
79  		 *   
80  		 * 
81  		 *   
82  		 * 
83  		 *   
84  		 * 
85  		 *   
86  		 * 
87  		 *   
88  		 * 
89  		 *   
90  		 * 
91  		 *   
92  		 * 
93  		 *   
94  		 * 
95  		 *   
96  		 * 
97  		 */
98  		public MoverLocalImpl(
99  			UnrealId Id,  boolean Visible
100 		) {
101 			
102 					this.Id = Id;
103 				
104 					this.Visible = Visible;
105 				
106 		}
107     
108     	/**
109 		 * Cloning constructor from the full message.
110 		 *
111 		 * @param original
112 		 */
113 		public MoverLocalImpl(Mover original) {		
114 			
115 					this.Id = original.getId()
116  	;
117 				
118 					this.Visible = original.isVisible()
119  	;
120 				
121 			this.SimTime = original.getSimTime();			
122 		}
123 		
124 		/**
125 		 * Cloning constructor from the full message.
126 		 *
127 		 * @param original
128 		 */
129 		public MoverLocalImpl(MoverLocalImpl original) {		
130 			
131 					this.Id = original.getId()
132  	;
133 				
134 					this.Visible = original.isVisible()
135  	;
136 				
137 			this.SimTime = original.getSimTime();
138 		}
139 		
140 			/**
141 			 * Cloning constructor from the message part.
142 			 *
143 			 * @param original
144 			 */
145 			public MoverLocalImpl(MoverLocal original) {
146 				
147 						this.Id = original.getId()
148  	;
149 					
150 						this.Visible = original.isVisible()
151  	;
152 					
153 			}
154 		
155    				
156    				@Override
157    				public void setSimTime(long SimTime) {
158 					super.setSimTime(SimTime);
159 				}
160    			
161 	    				@Override
162 	    				public 
163 	    				MoverLocalImpl clone() {
164 	    					return new 
165 	    					MoverLocalImpl(this);
166 	    				}
167 	    				
168 	    				
169     	
170 	    /**
171          * 
172 			A unique Id of this mover assigned by the game.
173 		 
174          */
175         protected
176          UnrealId Id =
177        	null;
178 	
179  		/**
180          * 
181 			A unique Id of this mover assigned by the game.
182 		 
183          */
184         public  UnrealId getId()
185  	 {
186 				    					return Id;
187 				    				}
188 				    			
189     	
190 	    /**
191          * If the mover is in the field of view of the bot. 
192          */
193         protected
194          boolean Visible =
195        	false;
196 	
197  		/**
198          * If the mover is in the field of view of the bot. 
199          */
200         public  boolean isVisible()
201  	 {
202 				    					return Visible;
203 				    				}
204 				    			
205     	
206     	
207     	
208     	
209     	public MoverLocalImpl getLocal() {
210 			return this;
211     	}
212 		public ISharedWorldObject getShared() {
213 		 	throw new UnsupportedOperationException("Could not return LOCAL as SHARED");
214 		}
215 		public IStaticWorldObject getStatic() {
216 		    throw new UnsupportedOperationException("Could not return LOCAL as STATIC");
217 		}
218  	
219 		public static class MoverLocalUpdate
220      implements ILocalWorldObjectUpdatedEvent, IGBWorldObjectEvent
221 		{
222 			protected long time;
223 			
224 			protected MoverLocal data = null; //contains object data for this update
225 			
226 			public MoverLocalUpdate
227     (MoverLocal moverLocal, long time)
228 			{
229 				this.data = moverLocal;
230 				this.time = time;
231 			}
232 			
233 			@Override
234 			public IWorldObjectUpdateResult<ILocalWorldObject> update(
235 					ILocalWorldObject object) 
236 			{
237 				if ( object == null)
238 				{
239 					data = new MoverLocalImpl(data); //we always return Impl object
240 					return new IWorldObjectUpdateResult.WorldObjectUpdateResult<ILocalWorldObject>(IWorldObjectUpdateResult.Result.CREATED, data);
241 				}
242 				if ( object instanceof MoverLocalImpl )
243 				{
244 					MoverLocalImpl toUpdate = (MoverLocalImpl)object;
245 					
246 					boolean updated = false;
247 					
248 					// UPDATING LOCAL PROPERTIES
249 					
250 				if (toUpdate.Visible != data.isVisible()
251  	) {
252 				    toUpdate.Visible=data.isVisible()
253  	;
254 					updated = true;
255 				}
256 			
257 					
258 					data = toUpdate; //the updating has finished
259 					
260 					if ( updated )
261 					{
262 						toUpdate.SimTime = this.time;
263 						return new IWorldObjectUpdateResult.WorldObjectUpdateResult<ILocalWorldObject>(IWorldObjectUpdateResult.Result.UPDATED, data);
264 					}
265 					
266 					return new IWorldObjectUpdateResult.WorldObjectUpdateResult<ILocalWorldObject>(IWorldObjectUpdateResult.Result.SAME, data);
267 				}
268 				throw new PogamutException("Unsupported object type for update. Expected MoverLocalImpl for object " + object.getId() +", not object of class " + object.getClass().getSimpleName() + ".", this);
269 			}
270 	
271 			/**
272 			 * Simulation time in MILLI SECONDS !!!
273 			 */
274 			@Override
275 			public long getSimTime() {
276 				return this.time;
277 			}
278 	
279 			@Override
280 			public IWorldObject getObject() {
281 				return data;
282 			}
283 	
284 			@Override
285 			public WorldObjectId getId() {
286 				return data.getId();
287 			}
288 			
289 		}	
290  	
291  		
292  	    public String toString() {
293             return
294             	super.toString() + "[" +
295             	
296 		              			"Id = " + String.valueOf(getId()
297  	) + " | " + 
298 		              		
299 		              			"Visible = " + String.valueOf(isVisible()
300  	) + " | " + 
301 		              		
302 				"]";           		
303         }
304  	
305  		
306  		public String toHtmlString() {
307  			return super.toString() + "[<br/>" +
308             	
309 		              			"<b>Id</b> = " + String.valueOf(getId()
310  	) + " <br/> " + 
311 		              		
312 		              			"<b>Visible</b> = " + String.valueOf(isVisible()
313  	) + " <br/> " + 
314 		              		
315 				"<br/>]";     
316 		}
317  	
318  		
319  		// --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=all]) ---
320         	
321 		// --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=all]) ---
322 		
323 	    // --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=local+classtype[@name=impl]) ---
324 	        
325 	    // --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=local+classtype[@name=impl]) ---        	            	
326  	
327 		}
328