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=base]+classtype[@name=message] BEGIN
13  		
14  		// --- IMPORTS FROM extra/code/java/javapart/classcategory[@name=base]+classtype[@name=message] END
15      
16   		/**
17           *  
18               				Implementation of the GameBots2004 message TES contains also its Local/Shared/Static subpart class definitions..  
19              			
20           *
21           *  <p></p><p></p>
22           *  Complete message documentation:               
23           *  
24  		Synchronous message. Contains the info about team score.
25  	
26           */
27   	public class TeamScoreMessage   
28    				extends 
29    				TeamScore
30    						implements IWorldObjectUpdatedEvent, ICompositeWorldObjectUpdatedEvent
31    						
32  	    {
33   	
34      	
35      	
36      	/**
37      	 * Parameter-less contructor for the message.
38      	 */
39  		public TeamScoreMessage()
40  		{
41  		}
42  	
43      	
44      	
45      	
46      	/**
47  		 * Creates new instance of the message TeamScore.
48  		 * 
49  		Synchronous message. Contains the info about team score.
50  	
51  		 * Corresponding GameBots message
52  		 *   
53  		 *   is
54  		 *   TES.
55  		 * 
56   	  	 * 
57  		 *   
58  		 *     @param Id Message identifier.
59  		 *   
60  		 * 
61  		 *   
62  		 *     @param Team Team identifier.
63  		 *   
64  		 * 
65  		 *   
66  		 *     @param Score 
67  			The score of the team (can be some special measurement that
68  			differs from game type to game type - number of stolen flags
69  			in CTF game, number of team frags in TeamGame, etc.)
70  		
71  		 *   
72  		 * 
73  		 */
74  		public TeamScoreMessage(
75  			UnrealId Id,  Integer Team,  Integer Score
76  		) {
77  			
78  					this.Id = Id;
79  				
80  					this.Team = Team;
81  				
82  					this.Score = Score;
83  				
84  		}
85      
86  		/**
87  		 * Cloning constructor from the full message.
88  		 *
89  		 * @param original
90  		 */
91  		public TeamScoreMessage(TeamScoreMessage original) {		
92  			
93  					this.Id = original.getId()
94   	;
95  				
96  					this.Team = original.getTeam()
97   	;
98  				
99  					this.Score = original.getScore()
100  	;
101 				
102 				this.TeamId = original.getTeamId();
103 			
104 			this.SimTime = original.getSimTime();
105 		}
106 		
107     				
108     					protected ITeamId TeamId;
109     					
110     					/**
111     					 * Used by Yylex to slip corretn TeamId.
112     					 */
113     					protected void setTeamId(ITeamId TeamId) {
114     					    this.TeamId = TeamId;
115     					}
116     				
117     					public ITeamId getTeamId() {
118 							return TeamId;
119 						}
120     	
121     					
122     					
123     	
124 	    /**
125          * Message identifier. 
126          */
127         protected
128          UnrealId Id =
129        	null;
130 	
131     						
132     						/**
133 		 					 * Whether property 'Id' was received from GB2004.
134 		 					 */
135 							protected boolean Id_Set = false;
136 							
137     						@Override
138 		    				
139  		/**
140          * Message identifier. 
141          */
142         public  UnrealId getId()
143  	 {
144 		    					return Id;
145 		    				}
146 		    			
147     	
148 	    /**
149          * Team identifier. 
150          */
151         protected
152          Integer Team =
153        	255;
154 	
155     						
156     						/**
157 		 					 * Whether property 'Team' was received from GB2004.
158 		 					 */
159 							protected boolean Team_Set = false;
160 							
161     						@Override
162 		    				
163  		/**
164          * Team identifier. 
165          */
166         public  Integer getTeam()
167  	 {
168 		    					return Team;
169 		    				}
170 		    			
171     	
172 	    /**
173          * 
174 			The score of the team (can be some special measurement that
175 			differs from game type to game type - number of stolen flags
176 			in CTF game, number of team frags in TeamGame, etc.)
177 		 
178          */
179         protected
180          Integer Score =
181        	0;
182 	
183     						
184     						/**
185 		 					 * Whether property 'Score' was received from GB2004.
186 		 					 */
187 							protected boolean Score_Set = false;
188 							
189     						@Override
190 		    				
191  		/**
192          * 
193 			The score of the team (can be some special measurement that
194 			differs from game type to game type - number of stolen flags
195 			in CTF game, number of team frags in TeamGame, etc.)
196 		 
197          */
198         public  Integer getScore()
199  	 {
200 		    					return Score;
201 		    				}
202 		    			
203 		    			
204 		    			private TeamScoreLocal localPart = null;
205 		    			
206 		    			@Override
207 						public TeamScoreLocal 
208 						getLocal() {
209 							if (localPart != null) return localPart;
210 							return localPart = new 
211 								TeamScoreLocalMessage();
212 						}
213 					
214 						private TeamScoreShared sharedPart = null;
215 					
216 						@Override
217 						public TeamScoreShared 
218 						getShared() {
219 							if (sharedPart != null) return sharedPart;							
220 							return sharedPart = new 
221 								TeamScoreSharedMessage();
222 						}
223 					
224 						private TeamScoreStatic staticPart = null; 
225 					
226 						@Override
227 						public TeamScoreStatic 
228 						getStatic() {
229 							if (staticPart != null) return staticPart;
230 							return staticPart = new 
231 								TeamScoreStaticMessage();
232 						}
233     				
234  		/**
235          *  
236             				Implementation of the local part of the GameBots2004 message TES, used
237             				to facade TESMessage.  
238             			
239          *
240          *  <p></p><p></p>
241          *  Complete message documentation:               
242          *  
243 		Synchronous message. Contains the info about team score.
244 	
245          */
246  	public class TeamScoreLocalMessage 
247 	  					extends
248   						TeamScoreLocal
249 	    {
250  	
251 		    			@Override
252 		    			public 
253 		    			TeamScoreLocalMessage clone() {
254 		    				return this;
255 		    			}
256 		    			
257 		    				public TeamScoreLocalMessage getLocal() {
258 								return this;
259 					    	}
260 							public ISharedWorldObject getShared() {
261 							 	throw new UnsupportedOperationException("Could not return LOCAL as SHARED");
262 							}
263 							public IStaticWorldObject getStatic() {
264 							    throw new UnsupportedOperationException("Could not return LOCAL as STATIC");
265 							}
266 		    			
267  		/**
268          * Message identifier. 
269          */
270         public  UnrealId getId()
271  	 {
272 				    					return Id;
273 				    				}
274 				    			
275  		
276  	    public String toString() {
277             return
278             	super.toString() + "[" +
279             	
280 		              			"Id = " + String.valueOf(getId()
281  	) + " | " + 
282 		              		
283 				"]";           		
284         }
285  	
286  		
287  		public String toHtmlString() {
288  			return super.toString() + "[<br/>" +
289             	
290 		              			"<b>Id</b> = " + String.valueOf(getId()
291  	) + " <br/> " + 
292 		              		
293 				"<br/>]";     
294 		}
295  	
296  		
297  		// --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=all]) ---
298         	
299 		// --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=all]) ---
300 		
301 	    // --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=local+classtype[@name=message]) ---
302 	        
303 	    // --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=local+classtype[@name=message]) ---        	            	
304  	
305 		}
306  	
307  		/**
308          *  
309             				Implementation of the static part of the GameBots2004 message TES, used
310             				to facade TESMessage.  
311             			
312          *
313          *  <p></p><p></p>
314          *  Complete message documentation:               
315          *  
316 		Synchronous message. Contains the info about team score.
317 	
318          */
319  	public class TeamScoreStaticMessage 
320 	  					extends
321   						TeamScoreStatic
322 	    {
323  	
324 		    			@Override
325 		    			public 
326 		    			TeamScoreStaticMessage clone() {
327 		    				return this;
328 		    			}
329 		    			
330  		/**
331          * Message identifier. 
332          */
333         public  UnrealId getId()
334  	 {
335 				    					return Id;
336 				    				}
337 				    			
338  		
339  		@Override
340  		public boolean isDifferentFrom(IStaticWorldObject other)
341  		{
342  			if (other == null) //early fail
343  			{
344  				return true;
345  			}
346  			else if (other == this) //early out
347  			{
348  				return false;
349  			}
350  			else
351  			{
352  				TeamScoreStatic obj = (TeamScoreStatic) other;
353 
354  				
355  						if ( !(
356  	 			AdvancedEquals.equalsOrNull(this.getId()
357  	, obj.getId()
358  	)
359  	 		) )
360 						{
361 							System.out.println("!!!!!PROPERTY UPDATE ERROR!!!! on property Id on object class TeamScoreStatic");
362 							return true;
363 						}
364  					
365  			}
366  			return false;
367  		}
368  	 
369  		
370  	    public String toString() {
371             return
372             	super.toString() + "[" +
373             	
374 		              			"Id = " + String.valueOf(getId()
375  	) + " | " + 
376 		              		
377 				"]";           		
378         }
379  	
380  		
381  		public String toHtmlString() {
382  			return super.toString() + "[<br/>" +
383             	
384 		              			"<b>Id</b> = " + String.valueOf(getId()
385  	) + " <br/> " + 
386 		              		
387 				"<br/>]";     
388 		}
389  	
390  		
391  		// --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=all]) ---
392         	
393 		// --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=all]) ---
394 		
395 	    // --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=static+classtype[@name=message]) ---
396 	        
397 	    // --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=static+classtype[@name=message]) ---        	            	
398  	
399 		}
400  	
401  		/**
402          *  
403             				Implementation of the shared part of the GameBots2004 message TES, used
404             				to facade TESMessage.  
405             			
406          *
407          *  <p></p><p></p>
408          *  Complete message documentation:               
409          *  
410 		Synchronous message. Contains the info about team score.
411 	
412          */
413  	public class TeamScoreSharedMessage 
414 	  					extends
415   						TeamScoreShared
416 	    {
417  	
418     	
419     	
420 		public TeamScoreSharedMessage()
421 		{
422 			
423 				propertyMap.put(myTeam.getPropertyId(), myTeam);
424 			
425 				propertyMap.put(myScore.getPropertyId(), myScore);
426 			
427 		}		
428     
429 		    			@Override
430 		    			public 
431 		    			TeamScoreSharedMessage clone() {
432 		    				return this;
433 		    			}
434 		    			
435 		
436 		
437 		
438 		protected HashMap<PropertyId, ISharedProperty> propertyMap = new HashMap<PropertyId, ISharedProperty>(
439 			2
440 		);
441 		
442 		@Override
443 		public ISharedProperty getProperty(PropertyId id) {
444 			return propertyMap.get(id);
445 		}
446 
447 		@Override
448 		public Map<PropertyId, ISharedProperty> getProperties() {
449 			return propertyMap;
450 		}
451 	
452 		
453 		
454  		/**
455          * Message identifier. 
456          */
457         public  UnrealId getId()
458  	 {
459   			return Id;
460   		}
461   		
462     	
463 	    /**
464          * Team identifier. 
465          */
466         protected
467          IntegerProperty 
468         myTeam
469 					= new
470 					IntegerProperty
471 					(
472 						getId(), 
473 						"Team", 
474 						Team, 
475 						TeamScore.class
476 					);
477 					
478  		/**
479          * Team identifier. 
480          */
481         public  Integer getTeam()
482  	 {
483 			  			return myTeam.getValue();
484 			  		}
485 				
486     	
487 	    /**
488          * 
489 			The score of the team (can be some special measurement that
490 			differs from game type to game type - number of stolen flags
491 			in CTF game, number of team frags in TeamGame, etc.)
492 		 
493          */
494         protected
495          IntegerProperty 
496         myScore
497 					= new
498 					IntegerProperty
499 					(
500 						getId(), 
501 						"Score", 
502 						Score, 
503 						TeamScore.class
504 					);
505 					
506  		/**
507          * 
508 			The score of the team (can be some special measurement that
509 			differs from game type to game type - number of stolen flags
510 			in CTF game, number of team frags in TeamGame, etc.)
511 		 
512          */
513         public  Integer getScore()
514  	 {
515 			  			return myScore.getValue();
516 			  		}
517 				
518  		
519  	    public String toString() {
520             return
521             	super.toString() + "[" +
522             	
523 		              			"Id = " + String.valueOf(getId()
524  	) + " | " + 
525 		              		
526 		              			"Team = " + String.valueOf(getTeam()
527  	) + " | " + 
528 		              		
529 		              			"Score = " + String.valueOf(getScore()
530  	) + " | " + 
531 		              		
532 				"]";           		
533         }
534  	
535  		
536  		public String toHtmlString() {
537  			return super.toString() + "[<br/>" +
538             	
539 		              			"<b>Id</b> = " + String.valueOf(getId()
540  	) + " <br/> " + 
541 		              		
542 		              			"<b>Team</b> = " + String.valueOf(getTeam()
543  	) + " <br/> " + 
544 		              		
545 		              			"<b>Score</b> = " + String.valueOf(getScore()
546  	) + " <br/> " + 
547 		              		
548 				"<br/>]";     
549 		}
550  	
551  		
552  		// --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=all]) ---
553         	
554 		// --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=all]) ---
555 		
556 	    // --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=shared+classtype[@name=message]) ---
557 	        
558 	    // --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=shared+classtype[@name=message]) ---        	            	
559  	
560 		}
561  	
562     	
563     	
564  	
565 		@Override
566 		public IWorldObjectUpdateResult<IWorldObject> update(IWorldObject object) {
567 			if (object == null)
568 			{
569 				return new IWorldObjectUpdateResult.WorldObjectUpdateResult(IWorldObjectUpdateResult.Result.CREATED, this);
570 			}
571 			if (!( object instanceof TeamScoreMessage) ) {
572 				throw new PogamutException("Can't update different class than TeamScoreMessage, got class " + object.getClass().getSimpleName() + "!", this);		
573 			}
574 			TeamScoreMessage toUpdate = (TeamScoreMessage)object;
575 			
576 			boolean updated = false;
577 			
578 			// UPDATING LOCAL PROPERTIES
579 			
580          	
581          	// UPDATING SHARED PROPERTIES
582          	
583 				if (!SafeEquals.equals(toUpdate.Team, getTeam()
584  	)) {
585 					toUpdate.Team=getTeam()
586  	;
587 					updated = true;
588 				}
589 			
590 				if (!SafeEquals.equals(toUpdate.Score, getScore()
591  	)) {
592 					toUpdate.Score=getScore()
593  	;
594 					updated = true;
595 				}
596 			
597          	
598          	// UPDATE TIME
599          	toUpdate.SimTime = SimTime;
600 			
601 			if (updated) {
602 				return new IWorldObjectUpdateResult.WorldObjectUpdateResult<IWorldObject>(IWorldObjectUpdateResult.Result.UPDATED, toUpdate);
603 			} else {
604 				return new IWorldObjectUpdateResult.WorldObjectUpdateResult<IWorldObject>(IWorldObjectUpdateResult.Result.SAME, toUpdate);
605 			}
606 		}
607 		
608 		@Override
609 		public ILocalWorldObjectUpdatedEvent getLocalEvent() {
610 			return new TeamScoreLocalImpl.TeamScoreLocalUpdate
611     (this.getLocal(), SimTime);
612 		}
613 
614 		@Override
615 		public ISharedWorldObjectUpdatedEvent getSharedEvent() {
616 			return new TeamScoreSharedImpl.TeamScoreSharedUpdate
617     (this.getShared(), SimTime, this.getTeamId());
618 		}
619 
620 		@Override
621 		public IStaticWorldObjectUpdatedEvent getStaticEvent() {
622 			return new TeamScoreStaticImpl.TeamScoreStaticUpdate
623     (this.getStatic(), SimTime);
624 		}
625  	
626  		
627  	    public String toString() {
628             return
629             	super.toString() + "[" +
630             	
631 		              			"Id = " + String.valueOf(getId()
632  	) + " | " + 
633 		              		
634 		              			"Team = " + String.valueOf(getTeam()
635  	) + " | " + 
636 		              		
637 		              			"Score = " + String.valueOf(getScore()
638  	) + " | " + 
639 		              		
640 				"]";           		
641         }
642  	
643  		
644  		public String toHtmlString() {
645  			return super.toString() + "[<br/>" +
646             	
647 		              			"<b>Id</b> = " + String.valueOf(getId()
648  	) + " <br/> " + 
649 		              		
650 		              			"<b>Team</b> = " + String.valueOf(getTeam()
651  	) + " <br/> " + 
652 		              		
653 		              			"<b>Score</b> = " + String.valueOf(getScore()
654  	) + " <br/> " + 
655 		              		
656 				"<br/>]";     
657 		}
658  	
659  		
660  		// --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=all]) ---
661         	
662 		// --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=all]) ---
663 		
664 	    // --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=base+classtype[@name=message]) ---
665 	        
666 	    // --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=base+classtype[@name=message]) ---        	            	
667  	
668 		}
669