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=static]+classtype[@name=impl] BEGIN
13  		
14  		// --- IMPORTS FROM extra/code/java/javapart/classcategory[@name=static]+classtype[@name=impl] END
15      
16   		/**
17           *  
18              				Implementation of the static 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 ItemStaticImpl 
29    						extends
30    						ItemStatic
31  	    {
32   	
33      	
34      	
35      	/**
36      	 * Parameter-less contructor for the message.
37      	 */
38  		public ItemStaticImpl()
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  		 *   (static 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  		 *     @param NavPointId 
66              Id of the navpoint where the item is laying. If null - the item was dropped by the bot or another player.
67          
68  		 *   
69  		 * 
70  		 *   
71  		 *     @param NavPoint 
72              If the Item is not dropped then it's item that is laying at some navpoint and
73              this is that NavPoint instance.
74          
75  		 *   
76  		 * 
77  		 *   
78  		 * 
79  		 *   
80  		 * 
81  		 *   
82  		 *     @param Amount 
83  			If this item is some ammo or health pack, here we can find
84  			out how much of the attribute this item will add.
85  		
86  		 *   
87  		 * 
88  		 *   
89  		 *     @param Type 
90  			Class of the item (e.g. xWeapons.FlakCannonPickup).
91  		
92  		 *   
93  		 * 
94  		 *   
95  		 *     @param Descriptor 
96  			Descriptor of the item - according the ItemType you may cast this to various XYZDescriptor. 
97  		
98  		 *   
99  		 * 
100 		 *   
101 		 * 
102 		 */
103 		public ItemStaticImpl(
104 			UnrealId Id,  UnrealId NavPointId,  NavPoint NavPoint,  int Amount,  ItemType Type,  ItemDescriptor Descriptor
105 		) {
106 			
107 					this.Id = Id;
108 				
109 					this.NavPointId = NavPointId;
110 				
111 					this.NavPoint = NavPoint;
112 				
113 					this.Amount = Amount;
114 				
115 					this.Type = Type;
116 				
117 					this.Descriptor = Descriptor;
118 				
119 		}
120     
121     	/**
122 		 * Cloning constructor from the full message.
123 		 *
124 		 * @param original
125 		 */
126 		public ItemStaticImpl(Item original) {		
127 			
128 					this.Id = original.getId()
129  	;
130 				
131 					this.NavPointId = original.getNavPointId()
132  	;
133 				
134 					this.NavPoint = original.getNavPoint()
135  	;
136 				
137 					this.Amount = original.getAmount()
138  	;
139 				
140 					this.Type = original.getType()
141  	;
142 				
143 					this.Descriptor = original.getDescriptor()
144  	;
145 				
146 			this.SimTime = original.getSimTime();			
147 		}
148 		
149 		/**
150 		 * Cloning constructor from the full message.
151 		 *
152 		 * @param original
153 		 */
154 		public ItemStaticImpl(ItemStaticImpl original) {		
155 			
156 					this.Id = original.getId()
157  	;
158 				
159 					this.NavPointId = original.getNavPointId()
160  	;
161 				
162 					this.NavPoint = original.getNavPoint()
163  	;
164 				
165 					this.Amount = original.getAmount()
166  	;
167 				
168 					this.Type = original.getType()
169  	;
170 				
171 					this.Descriptor = original.getDescriptor()
172  	;
173 				
174 			this.SimTime = original.getSimTime();
175 		}
176 		
177 			/**
178 			 * Cloning constructor from the message part.
179 			 *
180 			 * @param original
181 			 */
182 			public ItemStaticImpl(ItemStatic original) {
183 				
184 						this.Id = original.getId()
185  	;
186 					
187 						this.NavPointId = original.getNavPointId()
188  	;
189 					
190 						this.NavPoint = original.getNavPoint()
191  	;
192 					
193 						this.Amount = original.getAmount()
194  	;
195 					
196 						this.Type = original.getType()
197  	;
198 					
199 						this.Descriptor = original.getDescriptor()
200  	;
201 					
202 			}
203 		
204    				
205    				@Override
206    				public void setSimTime(long SimTime) {
207 					super.setSimTime(SimTime);
208 				}
209    			
210 	    				@Override
211 	    				public 
212 	    				ItemStaticImpl clone() {
213 	    					return new 
214 	    					ItemStaticImpl(this);
215 	    				}
216 	    				
217 	    				
218     	
219 	    /**
220          * 
221 			Unique Id of the item. This Id represents just item on the
222 			map, not in our inventory.
223 		 
224          */
225         protected
226          UnrealId Id =
227        	null;
228 	
229  		/**
230          * 
231 			Unique Id of the item. This Id represents just item on the
232 			map, not in our inventory.
233 		 
234          */
235         public  UnrealId getId()
236  	 {
237 				    					return Id;
238 				    				}
239 				    			
240     	
241 	    /**
242          * 
243             Id of the navpoint where the item is laying. If null - the item was dropped by the bot or another player.
244          
245          */
246         protected
247          UnrealId NavPointId =
248        	null;
249 	
250  		/**
251          * 
252             Id of the navpoint where the item is laying. If null - the item was dropped by the bot or another player.
253          
254          */
255         public  UnrealId getNavPointId()
256  	 {
257 				    					return NavPointId;
258 				    				}
259 				    			
260     	
261 	    /**
262          * 
263             If the Item is not dropped then it's item that is laying at some navpoint and
264             this is that NavPoint instance.
265          
266          */
267         protected
268          NavPoint NavPoint =
269        	null;
270 	
271  		/**
272          * 
273             If the Item is not dropped then it's item that is laying at some navpoint and
274             this is that NavPoint instance.
275          
276          */
277         public  NavPoint getNavPoint()
278  	 {
279 				    					return NavPoint;
280 				    				}
281 				    			
282     	
283 	    /**
284          * 
285 			If this item is some ammo or health pack, here we can find
286 			out how much of the attribute this item will add.
287 		 
288          */
289         protected
290          int Amount =
291        	0;
292 	
293  		/**
294          * 
295 			If this item is some ammo or health pack, here we can find
296 			out how much of the attribute this item will add.
297 		 
298          */
299         public  int getAmount()
300  	 {
301 				    					return Amount;
302 				    				}
303 				    			
304     	
305 	    /**
306          * 
307 			Class of the item (e.g. xWeapons.FlakCannonPickup).
308 		 
309          */
310         protected
311          ItemType Type =
312        	null;
313 	
314  		/**
315          * 
316 			Class of the item (e.g. xWeapons.FlakCannonPickup).
317 		 
318          */
319         public  ItemType getType()
320  	 {
321 				    					return Type;
322 				    				}
323 				    			
324     	
325 	    /**
326          * 
327 			Descriptor of the item - according the ItemType you may cast this to various XYZDescriptor. 
328 		 
329          */
330         protected
331          ItemDescriptor Descriptor =
332        	null;
333 	
334  		/**
335          * 
336 			Descriptor of the item - according the ItemType you may cast this to various XYZDescriptor. 
337 		 
338          */
339         public  ItemDescriptor getDescriptor()
340  	 {
341 				    					return Descriptor;
342 				    				}
343 				    			
344     	
345     	
346     	public static class ItemStaticUpdate
347      implements IStaticWorldObjectUpdatedEvent
348 		{
349 			
350 			private ItemStatic data;
351 			private long time;
352 			
353 			public ItemStaticUpdate
354     (ItemStatic source, long time)
355 			{
356 				this.data = source;
357 				this.time = time;
358 			}
359 			
360 			/**
361 			 * Simulation time in MILLI SECONDS !!!
362 			 */
363 			@Override
364 			public long getSimTime() {
365 				return time;
366 			}
367 	
368 			@Override
369 			public WorldObjectId getId() {
370 				return data.getId();
371 			}
372 			
373 			@Override
374 			public IWorldObjectUpdateResult<IStaticWorldObject> update(
375 					IStaticWorldObject object) {
376 				if ( object == null)
377 				{
378 					data = new ItemStaticImpl(data);
379 					return new IWorldObjectUpdateResult.WorldObjectUpdateResult<IStaticWorldObject>(IWorldObjectUpdateResult.Result.CREATED, data);
380 				}
381 				//since static objects can't be updated, we'll just check that the object stays the same
382 				if ( object instanceof ItemStaticImpl)
383 				{
384 					ItemStaticImpl orig = (ItemStaticImpl)object;
385 					//since these errors usually mean error in gamebots, we will just print an error message
386 					if ( data.isDifferentFrom(orig) )
387 					{
388 						//data.isDifferentFrom(orig);
389 						//throw new PogamutException("Trying to modify static object " + this.data.getId().toString() , this);
390 						System.out.println("!!!!!ERROR!!!!!! in static object modification. Object class : ItemStaticImpl to see which property was different see !!!!PROPERTY UPDATE ERROR!!!!");
391 					}
392 					return new IWorldObjectUpdateResult.WorldObjectUpdateResult<IStaticWorldObject>(IWorldObjectUpdateResult.Result.SAME, data);
393 				}				
394 				throw new PogamutException("Unexpected object type for update, ItemStaticImpl expected not class " + object.getClass().getSimpleName() + ".", this);
395 			}
396 		}
397 	
398     
399  		
400  		@Override
401  		public boolean isDifferentFrom(IStaticWorldObject other)
402  		{
403  			if (other == null) //early fail
404  			{
405  				return true;
406  			}
407  			else if (other == this) //early out
408  			{
409  				return false;
410  			}
411  			else
412  			{
413  				ItemStatic obj = (ItemStatic) other;
414 
415  				
416  						if ( !(
417  	 			AdvancedEquals.equalsOrNull(this.getId()
418  	, obj.getId()
419  	)
420  	 		) )
421 						{
422 							System.out.println("!!!!!PROPERTY UPDATE ERROR!!!! on property Id on object class ItemStatic");
423 							return true;
424 						}
425  					
426  						if ( !(
427  	 			AdvancedEquals.equalsOrNull(this.getNavPointId()
428  	, obj.getNavPointId()
429  	)
430  	 		) )
431 						{
432 							System.out.println("!!!!!PROPERTY UPDATE ERROR!!!! on property NavPointId on object class ItemStatic");
433 							return true;
434 						}
435  					
436  						if ( !(
437  	 			AdvancedEquals.equalsOrNull(this.getNavPoint()
438  	, obj.getNavPoint()
439  	)
440  	 		) )
441 						{
442 							System.out.println("!!!!!PROPERTY UPDATE ERROR!!!! on property NavPoint on object class ItemStatic");
443 							return true;
444 						}
445  					
446  						if ( !(this.getAmount()
447  	
448  	 			== obj.getAmount()
449  	) )
450 						{
451 							System.out.println("!!!!!PROPERTY UPDATE ERROR!!!! on property Amount on object class ItemStatic");
452 							return true;
453 						}
454  					
455  						if ( !(
456  	 			AdvancedEquals.equalsOrNull(this.getType()
457  	, obj.getType()
458  	)
459  	 		) )
460 						{
461 							System.out.println("!!!!!PROPERTY UPDATE ERROR!!!! on property Type on object class ItemStatic");
462 							return true;
463 						}
464  					
465  						if ( !(
466  	 			AdvancedEquals.equalsOrNull(this.getDescriptor()
467  	, obj.getDescriptor()
468  	)
469  	 		) )
470 						{
471 							System.out.println("!!!!!PROPERTY UPDATE ERROR!!!! on property Descriptor on object class ItemStatic");
472 							return true;
473 						}
474  					
475  			}
476  			return false;
477  		}
478  	 
479  		
480  	    public String toString() {
481             return
482             	super.toString() + "[" +
483             	
484 		              			"Id = " + String.valueOf(getId()
485  	) + " | " + 
486 		              		
487 		              			"NavPointId = " + String.valueOf(getNavPointId()
488  	) + " | " + 
489 		              		
490 		              			"Amount = " + String.valueOf(getAmount()
491  	) + " | " + 
492 		              		
493 		              			"Type = " + String.valueOf(getType()
494  	) + " | " + 
495 		              		
496 				"]";           		
497         }
498  	
499  		
500  		public String toHtmlString() {
501  			return super.toString() + "[<br/>" +
502             	
503 		              			"<b>Id</b> = " + String.valueOf(getId()
504  	) + " <br/> " + 
505 		              		
506 		              			"<b>NavPointId</b> = " + String.valueOf(getNavPointId()
507  	) + " <br/> " + 
508 		              		
509 		              			"<b>Amount</b> = " + String.valueOf(getAmount()
510  	) + " <br/> " + 
511 		              		
512 		              			"<b>Type</b> = " + String.valueOf(getType()
513  	) + " <br/> " + 
514 		              		
515 				"<br/>]";     
516 		}
517  	
518  		
519  		// --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=all]) ---
520         	
521 		// --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=all]) ---
522 		
523 	    // --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=static+classtype[@name=impl]) ---
524 	        
525          	  	
526          		    
527          		    
528 			         
529 			         	
530          		    
531          		    
532          	  
533 			/**
534 			 * DO NOT USE THIS METHOD! Reserved for GaviaLib (Pogamut core)! It's used
535 			 * to set correct navpoint instance into the item.
536 			 */  	
537 			public void setNavPoint(NavPoint navPoint) {
538 			    NavPoint = navPoint;
539 			} 		
540 		
541 	    // --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=static+classtype[@name=impl]) ---        	            	
542  	
543 		}
544