View Javadoc

1   
2               /**
3               IMPORTANT !!!
4   
5               DO NOT EDIT THIS FILE. IT IS GENERATED FROM approriate xml file in xmlresources/gbinfomessages BY
6               THE JavaClassesGenerator.xslt. MODIFY THESE FILES INSTEAD OF THIS ONE.
7   
8               IMPORTANT END !!!
9               */
10              package
11              cz.cuni.amis.pogamut.udk.communication.messages.gbinfomessages;
12  	    		import java.util.*;
13      import javax.vecmath.*;
14      import cz.cuni.amis.pogamut.base.communication.messages.*;
15      import cz.cuni.amis.pogamut.base.communication.worldview.*;
16      import cz.cuni.amis.pogamut.base.communication.worldview.event.*;
17      import cz.cuni.amis.pogamut.base.communication.worldview.object.*;
18      import cz.cuni.amis.pogamut.base.communication.translator.event.*;
19      import cz.cuni.amis.pogamut.base3d.worldview.object.*;
20      import cz.cuni.amis.pogamut.base3d.worldview.object.event.*;
21      import cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId;
22      import cz.cuni.amis.pogamut.udk.communication.messages.*;
23      import cz.cuni.amis.pogamut.udk.communication.worldview.objects.*;
24      import cz.cuni.amis.pogamut.udk.communication.translator.itemdescriptor.*;
25      import cz.cuni.amis.pogamut.udk.communication.messages.ItemType.Category;
26      import cz.cuni.amis.utils.exception.*;
27      import cz.cuni.amis.pogamut.base.communication.translator.event.IWorldObjectUpdateResult.Result;
28      import cz.cuni.amis.utils.SafeEquals;
29      import cz.cuni.amis.pogamut.multi.communication.worldview.object.*;
30      
31              
32              /**
33                
34  		Synchronous/asynchronous message. An object on the ground that
35  		can be picked up.
36  	
37                            Corresponding GameBots message is
38                            INV.
39                        
40               */
41              
42              public class
43              Item
44                      extends GBObjectUpdate
45                  
46  	            	implements IGBWorldObjectEvent, IWorldObject, ILocated, IGBViewable, ItemTyped
47  
48              {
49              
50              /**
51                Creates new instance of command Item.
52                
53  		Synchronous/asynchronous message. An object on the ground that
54  		can be picked up.
55  	Corresponding GameBots message for this command is
56                .
57                    @param Id 
58  			Unique Id of the item. This Id represents just item on the
59  			map, not in our inventory.
60  		
61                    @param NavPointId 
62              Id of the navpoint where the item is laying. If null - the item was dropped by the bot or another player.
63          
64                    @param NavPoint 
65              If the Item is not dropped then it's item that is laying at some navpoint and
66              this is that NavPoint instance.
67          
68                    @param Visible 
69  			If the item is in the field of view of the bot.
70  		
71                    @param Location Location of the item.
72                    @param Reachable True if agent can reach the item.
73                    @param Amount 
74  			If this item is some ammo or health pack, here we can find
75  			out how much of the attribute this item will add.
76  		
77                    @param Type 
78  			Class of the item (e.g. xWeapons.FlakCannonPickup).
79  		
80                    @param Descriptor 
81  			Descriptor of the item - according the ItemType you may cast this to various XYZDescriptor. 
82  		
83                    @param Dropped 
84              Whether it is regular item or one dropped by some bot (usually during dying). Items that are not dropped
85              usually respawns itself (depends on the game settings) while those that are dropped may be taken only once.
86          
87                */
88               public Item(
89                  UnrealId Id,  UnrealId NavPointId,  NavPoint NavPoint,  boolean Visible,  Location Location,  boolean Reachable,  int Amount,  ItemType Type,  ItemDescriptor Descriptor,  boolean Dropped) {
90                      
91                      this.Id = Id;
92                  
93                      this.NavPointId = NavPointId;
94                  
95                      this.NavPoint = NavPoint;
96                  
97                      this.Visible = Visible;
98                  
99                      this.Location = Location;
100                 
101                     this.Reachable = Reachable;
102                 
103                     this.Amount = Amount;
104                 
105                     this.Type = Type;
106                 
107                     this.Descriptor = Descriptor;
108                 
109                     this.Dropped = Dropped;
110                 
111                 }
112 
113             
114     	/** Example how the message looks like - used during parser tests. */
115     	public static final String PROTOTYPE =
116     		"INV {Id unreal_id} {NavPointId unreal_id} {Visible False} {Location 0,0,0} {Reachable False} {Amount 0} {Type xWeapons.FlakCannonPickup} {Dropped False}";
117     
118 
119             /////// Properties BEGIN
120             
121         /**
122         
123 			Unique Id of the item. This Id represents just item on the
124 			map, not in our inventory.
125 		 */
126         protected
127          UnrealId Id =
128         	null;
129 
130         
131         /**
132         
133 			Unique Id of the item. This Id represents just item on the
134 			map, not in our inventory.
135 		 */
136         public
137         UnrealId getId() {
138             return
139          Id;
140         }
141         
142 
143         
144         /**
145         
146             Id of the navpoint where the item is laying. If null - the item was dropped by the bot or another player.
147          */
148         protected
149          UnrealId NavPointId =
150         	null;
151 
152         
153         /**
154         
155             Id of the navpoint where the item is laying. If null - the item was dropped by the bot or another player.
156          */
157         public
158         UnrealId getNavPointId() {
159             return
160          NavPointId;
161         }
162         
163 
164         
165         /**
166         
167             If the Item is not dropped then it's item that is laying at some navpoint and
168             this is that NavPoint instance.
169          */
170         protected
171          NavPoint NavPoint =
172         	null;
173 
174         
175         /**
176         
177             If the Item is not dropped then it's item that is laying at some navpoint and
178             this is that NavPoint instance.
179          */
180         public
181         NavPoint getNavPoint() {
182             return
183          NavPoint;
184         }
185         
186 
187         
188         /**
189         
190 			If the item is in the field of view of the bot.
191 		 */
192         protected
193          boolean Visible =
194         	false;
195 
196         
197         /**
198         
199 			If the item is in the field of view of the bot.
200 		 */
201         public
202         boolean isVisible() {
203             return
204          Visible;
205         }
206         
207 
208         
209         /**
210         Location of the item. */
211         protected
212          Location Location =
213         	null;
214 
215         
216         /**
217         Location of the item. */
218         public
219         Location getLocation() {
220             return
221          Location;
222         }
223         
224 
225         
226         /**
227         True if agent can reach the item. */
228         protected
229          boolean Reachable =
230         	false;
231 
232         
233         /**
234         True if agent can reach the item. */
235         public
236         boolean isReachable() {
237             return
238          Reachable;
239         }
240         
241 
242         
243         /**
244         
245 			If this item is some ammo or health pack, here we can find
246 			out how much of the attribute this item will add.
247 		 */
248         protected
249          int Amount =
250         	0;
251 
252         
253         /**
254         
255 			If this item is some ammo or health pack, here we can find
256 			out how much of the attribute this item will add.
257 		 */
258         public
259         int getAmount() {
260             return
261          Amount;
262         }
263         
264 
265         
266         /**
267         
268 			Class of the item (e.g. xWeapons.FlakCannonPickup).
269 		 */
270         protected
271          ItemType Type =
272         	null;
273 
274         
275         /**
276         
277 			Class of the item (e.g. xWeapons.FlakCannonPickup).
278 		 */
279         public
280         ItemType getType() {
281             return
282          Type;
283         }
284         
285 
286         
287         /**
288         
289 			Descriptor of the item - according the ItemType you may cast this to various XYZDescriptor. 
290 		 */
291         protected
292          ItemDescriptor Descriptor =
293         	null;
294 
295         
296         /**
297         
298 			Descriptor of the item - according the ItemType you may cast this to various XYZDescriptor. 
299 		 */
300         public
301         ItemDescriptor getDescriptor() {
302             return
303          Descriptor;
304         }
305         
306 
307         
308         /**
309         
310             Whether it is regular item or one dropped by some bot (usually during dying). Items that are not dropped
311             usually respawns itself (depends on the game settings) while those that are dropped may be taken only once.
312          */
313         protected
314          boolean Dropped =
315         	false;
316 
317         
318         /**
319         
320             Whether it is regular item or one dropped by some bot (usually during dying). Items that are not dropped
321             usually respawns itself (depends on the game settings) while those that are dropped may be taken only once.
322          */
323         public
324         boolean isDropped() {
325             return
326          Dropped;
327         }
328         
329 
330         
331             /////// Properties END
332 
333             /////// Extra Java code BEGIN
334 
335             	/////// Additional code from xslt BEGIN
336             		
337        							protected double Time = 0;
338 
339        							protected double getTime() {
340        								return Time;
341        							}
342 
343        							protected void setTime(double time) {
344        								this.Time = time;
345        							}
346 
347        							public double getLastSeenTime() {
348        								return Time;
349        							}
350        						
351        					
352        					public ILocalWorldObject getLocal() {
353        						return null;
354        					}
355        					
356        					public ISharedWorldObject getShared() {
357        						return null;
358        					}
359        					
360        					public IStaticWorldObject getStatic() {
361        						return null;
362        					}
363        					
364        					@Override
365        					public long getSimTime() {
366        						return (long)getLastSeenTime();
367        					}
368 
369        					public boolean equals(Object obj) {
370 	                      if (!(obj instanceof Item)) return false;
371 	                      Item cast = (Item)obj;
372 	                      if (this.getId() != null) return this.getId().equals(cast.getId());
373 	                      else return cast.getId() == null;
374 	                    }
375 
376 	                    public int hashCode() {
377 	                      if (getId() != null) return getId().hashCode();
378 	                      return 0;
379 	                    }
380 
381             		
382 
383 
384             	/////// Additional code from xslt END
385 
386 	            /////// Extra Java from XML BEGIN
387             					
388 			    /**
389 			     * DO NOT USE THIS METHOD! Reserved for GaviaLib (Pogamut core)! It's used
390 			     * to set correct navpoint instance into the item.
391 			     */  	
392 			    public void setNavPoint(NavPoint navPoint) {
393 			        this.NavPoint = navPoint;
394 			    } 
395 			
396             	/////// Extra Java from XML END
397 
398             /////// Extra Java code END
399 
400             
401 
402             /**
403               * Cloning constructor.
404               */
405              public Item(Item original) {
406                 
407                      this.Id=original.Id;
408                 
409                      this.NavPointId=original.NavPointId;
410                 
411                      this.NavPoint=original.NavPoint;
412                 
413                      this.Visible=original.Visible;
414                 
415                      this.Location=original.Location;
416                 
417                      this.Reachable=original.Reachable;
418                 
419                      this.Amount=original.Amount;
420                 
421                      this.Type=original.Type;
422                 
423                      this.Descriptor=original.Descriptor;
424                 
425                      this.Dropped=original.Dropped;
426                 
427              }
428 
429              
430                  /**
431                   * Used by Yylex to create empty message then to fill it's protected fields (Yylex is in the same package).
432                   */
433 	             public Item() {
434 	             }
435              
436 
437 	    		     /**
438 	    		      * Used to drop Visible flag from the object.
439 	    		      */
440 	    		     public static class ObjectDisappeared implements IGBWorldObjectDisappeared {
441 
442 	    		         private IWorldObject orig;
443 
444 	    		         public ObjectDisappeared(IWorldObject orig) {
445 	    		             this.orig = orig;
446 	    		         }
447 
448 	    		         public WorldObjectId getId() {
449 	    		             return orig.getId();
450 	    		         }
451 	    		         
452 	    		         public long getSimTime() {
453 	    		         	return 0;
454 	    		         }
455 
456                          public IWorldObjectUpdateResult update(IWorldObject obj) {
457                             if (obj == null) {
458                                 throw new PogamutException("not meant to create new object, probably wanted to update non-existing object of id: " + getId(), this);
459                             }
460                             if (!(obj instanceof Item)) {
461                                 throw new PogamutException("can't update object of class " + obj.getClass() + ", meant to update Item", this);
462                             }
463                             orig = obj;
464                             Item toUpdate = (Item)obj;
465                             if (toUpdate.Visible) {
466 								toUpdate.Visible = false;
467 								return new IWorldObjectUpdateResult.WorldObjectUpdateResult(cz.cuni.amis.pogamut.base.communication.translator.event.IWorldObjectUpdateResult.Result.UPDATED, toUpdate);
468 							} else {
469 								return new IWorldObjectUpdateResult.WorldObjectUpdateResult(cz.cuni.amis.pogamut.base.communication.translator.event.IWorldObjectUpdateResult.Result.SAME, toUpdate);
470 							}
471                          }
472 
473                          public IWorldObject getObject() {
474                             return orig;
475                          }
476 
477                          public String toString() {
478                             return "ObjectDisappeared[" + orig.getClass().getSimpleName() + " " + orig.getId().getStringId() + "]";
479                          }
480 
481 	    		     }
482 
483 	    		     /**
484 	    		      * Used to create event that drops the Visible flag of the item.
485 	    		      */
486 	    		     public Item(Item Original, boolean Visible) {
487 	    		         this(Original);
488 	    		         this.Visible = Visible;
489 	    		     }
490 
491 	    		     public IGBWorldObjectDisappeared createDisappearEvent() {
492 	    		         return new ObjectDisappeared(this);
493 	    		     }
494 	    		
495 
496 	    		/**
497 	    		 * Here we save the original object for which this object is an update.
498 	    		 */
499 	    		private IWorldObject orig = null;
500 
501 	            public IWorldObjectUpdateResult update(IWorldObject obj) {
502 		            if(obj == null) {
503 		               orig = this;
504 		               return new IWorldObjectUpdateResult.WorldObjectUpdateResult(cz.cuni.amis.pogamut.base.communication.translator.event.IWorldObjectUpdateResult.Result.CREATED, this);
505 		            }
506 		            orig = obj;
507 		            // typecast
508 		            Item  o = (Item)obj;
509 
510 		            boolean updated = false;
511 
512 		            
513 		    					if (o.Visible != Visible) {
514 		    					    o.Visible=Visible;
515 		    						updated = true;
516 		    					}
517 		    				
518 		    					if (o.Reachable != Reachable) {
519 		    					    o.Reachable=Reachable;
520 		    						updated = true;
521 		    					}
522 		    				
523 								o.Time = Time;
524 							
525 
526 		            if (updated) {
527 		                return new IWorldObjectUpdateResult.WorldObjectUpdateResult(cz.cuni.amis.pogamut.base.communication.translator.event.IWorldObjectUpdateResult.Result.UPDATED, o);
528 		            } else {
529 		            	return new IWorldObjectUpdateResult.WorldObjectUpdateResult(cz.cuni.amis.pogamut.base.communication.translator.event.IWorldObjectUpdateResult.Result.SAME, o);
530 		            }
531 		        }
532 
533 	            /**
534 	             * Returns original object (if method update() has already been called, for bot-programmer that is always true
535 	             * as the original object is updated and then the event is propagated).
536 	             */
537 		        public IWorldObject getObject() {
538 		            if (orig == null) return this;
539 		            return orig;
540 		        }
541 	        
542 
543                  
544             public String toString() {
545                 return
546                 
547                 		super.toString() + " | " +
548                 		
549 				               "Id = " +
550 				               String.valueOf(Id) + " | " +
551 				            
552 				               "NavPointId = " +
553 				               String.valueOf(NavPointId) + " | " +
554 				            
555 				               "Visible = " +
556 				               String.valueOf(Visible) + " | " +
557 				            
558 				               "Location = " +
559 				               String.valueOf(Location) + " | " +
560 				            
561 				               "Reachable = " +
562 				               String.valueOf(Reachable) + " | " +
563 				            
564 				               "Amount = " +
565 				               String.valueOf(Amount) + " | " +
566 				            
567 				               "Type = " +
568 				               String.valueOf(Type) + " | " +
569 				            
570 				               "Dropped = " +
571 				               String.valueOf(Dropped) + " | " +
572 				             "";
573                 	
574              }
575 
576              public String toHtmlString() {
577                 return super.toString() +
578             
579             "<b>Id</b> : " +
580             String.valueOf(Id) +
581             " <br/> " +
582             
583             "<b>NavPointId</b> : " +
584             String.valueOf(NavPointId) +
585             " <br/> " +
586             
587             "<b>NavPoint</b> : " +
588             String.valueOf(NavPoint) +
589             " <br/> " +
590             
591             "<b>Visible</b> : " +
592             String.valueOf(Visible) +
593             " <br/> " +
594             
595             "<b>Location</b> : " +
596             String.valueOf(Location) +
597             " <br/> " +
598             
599             "<b>Reachable</b> : " +
600             String.valueOf(Reachable) +
601             " <br/> " +
602             
603             "<b>Amount</b> : " +
604             String.valueOf(Amount) +
605             " <br/> " +
606             
607             "<b>Type</b> : " +
608             String.valueOf(Type) +
609             " <br/> " +
610             
611             "<b>Descriptor</b> : " +
612             String.valueOf(Descriptor) +
613             " <br/> " +
614             
615             "<b>Dropped</b> : " +
616             String.valueOf(Dropped) +
617             " <br/> " +
618              "";
619              }
620 
621              
622              
623              }
624 
625