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