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 message. FlagInfo contains all info about the flag
35  		in the CTF game mode. Is not sent in other game types.
36  	
37                            Corresponding GameBots message is
38                            FLG.
39                        
40               */
41              
42              public class
43              FlagInfo
44                      extends GBObjectUpdate
45                  
46  	            	implements IGBWorldObjectEvent, IWorldObject, ILocated, IGBViewable
47  
48              {
49              
50              /**
51                Creates new instance of command FlagInfo.
52                
53  		Synchronous message. FlagInfo contains all info about the flag
54  		in the CTF game mode. Is not sent in other game types.
55  	Corresponding GameBots message for this command is
56                .
57                    @param Id 
58  			An unique Id for this flag, assigned by the game.
59  		
60                    @param Location 
61  			An absolute location of the flag (Sent if we can actually
62  			see the flag).
63  		
64                    @param Holder 
65  			Id of player/bot holding the flag. (Sent if we can actually
66  			see the flag and the flag is being carried, or if the flag
67  			is being carried by us).
68  		
69                    @param Team The owner team of this flag.
70                    @param Reachable 
71  			True if the bot can run here directly, false otherwise.
72  		
73                    @param Visible True if the bot can see the flag.
74                    @param State 
75  			Represents the state the flag is in. Can be "Held",
76  			"Dropped" or "Home" (note that the first letter does not have to be in upper case!).
77  		
78                */
79               public FlagInfo(
80                  UnrealId Id,  Location Location,  UnrealId Holder,  int Team,  boolean Reachable,  boolean Visible,  String State) {
81                      
82                      this.Id = Id;
83                  
84                      this.Location = Location;
85                  
86                      this.Holder = Holder;
87                  
88                      this.Team = Team;
89                  
90                      this.Reachable = Reachable;
91                  
92                      this.Visible = Visible;
93                  
94                      this.State = State;
95                  
96                  }
97  
98              
99      	/** Example how the message looks like - used during parser tests. */
100     	public static final String PROTOTYPE =
101     		"FLG {Id unreal_id} {Location 0,0,0} {Holder unreal_id} {Team 0} {Reachable False} {Visible False} {State text}";
102     
103 
104             /////// Properties BEGIN
105             
106         /**
107         
108 			An unique Id for this flag, assigned by the game.
109 		 */
110         protected
111          UnrealId Id =
112         	null;
113 
114         
115         /**
116         
117 			An unique Id for this flag, assigned by the game.
118 		 */
119         public
120         UnrealId getId() {
121             return
122          Id;
123         }
124         
125 
126         
127         /**
128         
129 			An absolute location of the flag (Sent if we can actually
130 			see the flag).
131 		 */
132         protected
133          Location Location =
134         	null;
135 
136         
137         /**
138         
139 			An absolute location of the flag (Sent if we can actually
140 			see the flag).
141 		 */
142         public
143         Location getLocation() {
144             return
145          Location;
146         }
147         
148 
149         
150         /**
151         
152 			Id of player/bot holding the flag. (Sent if we can actually
153 			see the flag and the flag is being carried, or if the flag
154 			is being carried by us).
155 		 */
156         protected
157          UnrealId Holder =
158         	null;
159 
160         
161         /**
162         
163 			Id of player/bot holding the flag. (Sent if we can actually
164 			see the flag and the flag is being carried, or if the flag
165 			is being carried by us).
166 		 */
167         public
168         UnrealId getHolder() {
169             return
170          Holder;
171         }
172         
173 
174         
175         /**
176         The owner team of this flag. */
177         protected
178          int Team =
179         	0;
180 
181         
182         /**
183         The owner team of this flag. */
184         public
185         int getTeam() {
186             return
187          Team;
188         }
189         
190 
191         
192         /**
193         
194 			True if the bot can run here directly, false otherwise.
195 		 */
196         protected
197          boolean Reachable =
198         	false;
199 
200         
201         /**
202         
203 			True if the bot can run here directly, false otherwise.
204 		 */
205         public
206         boolean isReachable() {
207             return
208          Reachable;
209         }
210         
211 
212         
213         /**
214         True if the bot can see the flag. */
215         protected
216          boolean Visible =
217         	false;
218 
219         
220         /**
221         True if the bot can see the flag. */
222         public
223         boolean isVisible() {
224             return
225          Visible;
226         }
227         
228 
229         
230         /**
231         
232 			Represents the state the flag is in. Can be "Held",
233 			"Dropped" or "Home" (note that the first letter does not have to be in upper case!).
234 		 */
235         protected
236          String State =
237         	null;
238 
239         
240         /**
241         
242 			Represents the state the flag is in. Can be "Held",
243 			"Dropped" or "Home" (note that the first letter does not have to be in upper case!).
244 		 */
245         public
246         String getState() {
247             return
248          State;
249         }
250         
251 
252         
253             /////// Properties END
254 
255             /////// Extra Java code BEGIN
256 
257             	/////// Additional code from xslt BEGIN
258             		
259        							protected double Time = 0;
260 
261        							protected double getTime() {
262        								return Time;
263        							}
264 
265        							protected void setTime(double time) {
266        								this.Time = time;
267        							}
268 
269        							public double getLastSeenTime() {
270        								return Time;
271        							}
272        						
273        					
274        					public ILocalWorldObject getLocal() {
275        						return null;
276        					}
277        					
278        					public ISharedWorldObject getShared() {
279        						return null;
280        					}
281        					
282        					public IStaticWorldObject getStatic() {
283        						return null;
284        					}
285        					
286        					@Override
287        					public long getSimTime() {
288        						return (long)getLastSeenTime();
289        					}
290 
291        					public boolean equals(Object obj) {
292 	                      if (!(obj instanceof FlagInfo)) return false;
293 	                      FlagInfo cast = (FlagInfo)obj;
294 	                      if (this.getId() != null) return this.getId().equals(cast.getId());
295 	                      else return cast.getId() == null;
296 	                    }
297 
298 	                    public int hashCode() {
299 	                      if (getId() != null) return getId().hashCode();
300 	                      return 0;
301 	                    }
302 
303             		
304 
305 
306             	/////// Additional code from xslt END
307 
308 	            /////// Extra Java from XML BEGIN
309             		
310             	/////// Extra Java from XML END
311 
312             /////// Extra Java code END
313 
314             
315 
316             /**
317               * Cloning constructor.
318               */
319              public FlagInfo(FlagInfo original) {
320                 
321                      this.Id=original.Id;
322                 
323                      this.Location=original.Location;
324                 
325                      this.Holder=original.Holder;
326                 
327                      this.Team=original.Team;
328                 
329                      this.Reachable=original.Reachable;
330                 
331                      this.Visible=original.Visible;
332                 
333                      this.State=original.State;
334                 
335              }
336 
337              
338                  /**
339                   * Used by Yylex to create empty message then to fill it's protected fields (Yylex is in the same package).
340                   */
341 	             public FlagInfo() {
342 	             }
343              
344 
345 	    		     /**
346 	    		      * Used to drop Visible flag from the object.
347 	    		      */
348 	    		     public static class ObjectDisappeared implements IGBWorldObjectDisappeared {
349 
350 	    		         private IWorldObject orig;
351 
352 	    		         public ObjectDisappeared(IWorldObject orig) {
353 	    		             this.orig = orig;
354 	    		         }
355 
356 	    		         public WorldObjectId getId() {
357 	    		             return orig.getId();
358 	    		         }
359 	    		         
360 	    		         public long getSimTime() {
361 	    		         	return 0;
362 	    		         }
363 
364                          public IWorldObjectUpdateResult update(IWorldObject obj) {
365                             if (obj == null) {
366                                 throw new PogamutException("not meant to create new object, probably wanted to update non-existing object of id: " + getId(), this);
367                             }
368                             if (!(obj instanceof FlagInfo)) {
369                                 throw new PogamutException("can't update object of class " + obj.getClass() + ", meant to update FlagInfo", this);
370                             }
371                             orig = obj;
372                             FlagInfo toUpdate = (FlagInfo)obj;
373                             if (toUpdate.Visible) {
374 								toUpdate.Visible = false;
375 								return new IWorldObjectUpdateResult.WorldObjectUpdateResult(cz.cuni.amis.pogamut.base.communication.translator.event.IWorldObjectUpdateResult.Result.UPDATED, toUpdate);
376 							} else {
377 								return new IWorldObjectUpdateResult.WorldObjectUpdateResult(cz.cuni.amis.pogamut.base.communication.translator.event.IWorldObjectUpdateResult.Result.SAME, toUpdate);
378 							}
379                          }
380 
381                          public IWorldObject getObject() {
382                             return orig;
383                          }
384 
385                          public String toString() {
386                             return "ObjectDisappeared[" + orig.getClass().getSimpleName() + " " + orig.getId().getStringId() + "]";
387                          }
388 
389 	    		     }
390 
391 	    		     /**
392 	    		      * Used to create event that drops the Visible flag of the item.
393 	    		      */
394 	    		     public FlagInfo(FlagInfo Original, boolean Visible) {
395 	    		         this(Original);
396 	    		         this.Visible = Visible;
397 	    		     }
398 
399 	    		     public IGBWorldObjectDisappeared createDisappearEvent() {
400 	    		         return new ObjectDisappeared(this);
401 	    		     }
402 	    		
403 
404 	    		/**
405 	    		 * Here we save the original object for which this object is an update.
406 	    		 */
407 	    		private IWorldObject orig = null;
408 
409 	            public IWorldObjectUpdateResult update(IWorldObject obj) {
410 		            if(obj == null) {
411 		               orig = this;
412 		               return new IWorldObjectUpdateResult.WorldObjectUpdateResult(cz.cuni.amis.pogamut.base.communication.translator.event.IWorldObjectUpdateResult.Result.CREATED, this);
413 		            }
414 		            orig = obj;
415 		            // typecast
416 		            FlagInfo  o = (FlagInfo)obj;
417 
418 		            boolean updated = false;
419 
420 		            
421                                 if (!SafeEquals.equals(o.Location, Location)) {
422 		    						o.Location=Location;
423 		    						updated = true;
424 		    					}
425                             
426 		    					if (!SafeEquals.equals(o.Holder, Holder)) {
427 		    						o.Holder=Holder;
428 		    						updated = true;
429 		    					}
430 		    				
431 		    					if (o.Team != Team) {
432 		    					    o.Team=Team;
433 		    						updated = true;
434 		    					}
435 		    				
436 		    					if (o.Reachable != Reachable) {
437 		    					    o.Reachable=Reachable;
438 		    						updated = true;
439 		    					}
440 		    				
441 		    					if (o.Visible != Visible) {
442 		    					    o.Visible=Visible;
443 		    						updated = true;
444 		    					}
445 		    				
446 		    					if (!SafeEquals.equals(o.State, State)) {
447 		    						o.State=State;
448 		    						updated = true;
449 		    					}
450 		    				
451 								o.Time = Time;
452 							
453 
454 		            if (updated) {
455 		                return new IWorldObjectUpdateResult.WorldObjectUpdateResult(cz.cuni.amis.pogamut.base.communication.translator.event.IWorldObjectUpdateResult.Result.UPDATED, o);
456 		            } else {
457 		            	return new IWorldObjectUpdateResult.WorldObjectUpdateResult(cz.cuni.amis.pogamut.base.communication.translator.event.IWorldObjectUpdateResult.Result.SAME, o);
458 		            }
459 		        }
460 
461 	            /**
462 	             * Returns original object (if method update() has already been called, for bot-programmer that is always true
463 	             * as the original object is updated and then the event is propagated).
464 	             */
465 		        public IWorldObject getObject() {
466 		            if (orig == null) return this;
467 		            return orig;
468 		        }
469 	        
470 
471                  
472             public String toString() {
473                 return
474                 
475                 		super.toString() + " | " +
476                 		
477 				               "Id = " +
478 				               String.valueOf(Id) + " | " +
479 				            
480 				               "Location = " +
481 				               String.valueOf(Location) + " | " +
482 				            
483 				               "Holder = " +
484 				               String.valueOf(Holder) + " | " +
485 				            
486 				               "Team = " +
487 				               String.valueOf(Team) + " | " +
488 				            
489 				               "Reachable = " +
490 				               String.valueOf(Reachable) + " | " +
491 				            
492 				               "Visible = " +
493 				               String.valueOf(Visible) + " | " +
494 				            
495 				               "State = " +
496 				               String.valueOf(State) + " | " +
497 				             "";
498                 	
499              }
500 
501              public String toHtmlString() {
502                 return super.toString() +
503             
504             "<b>Id</b> : " +
505             String.valueOf(Id) +
506             " <br/> " +
507             
508             "<b>Location</b> : " +
509             String.valueOf(Location) +
510             " <br/> " +
511             
512             "<b>Holder</b> : " +
513             String.valueOf(Holder) +
514             " <br/> " +
515             
516             "<b>Team</b> : " +
517             String.valueOf(Team) +
518             " <br/> " +
519             
520             "<b>Reachable</b> : " +
521             String.valueOf(Reachable) +
522             " <br/> " +
523             
524             "<b>Visible</b> : " +
525             String.valueOf(Visible) +
526             " <br/> " +
527             
528             "<b>State</b> : " +
529             String.valueOf(State) +
530             " <br/> " +
531              "";
532              }
533 
534              
535              
536              }
537 
538