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 FLG.  
19              			
20           *
21           *  <p></p><p></p>
22           *  Complete message documentation:               
23           *  
24  		Synchronous message. FlagInfo contains all info about the flag
25  		in the CTF game mode. Is not sent in other game types.
26  	
27           */
28   	public class FlagInfoStaticImpl 
29    						extends
30    						FlagInfoStatic
31  	    {
32   	
33      	
34      	
35      	/**
36      	 * Parameter-less contructor for the message.
37      	 */
38  		public FlagInfoStaticImpl()
39  		{
40  		}
41  	
42      	
43      	
44      	
45      	/**
46  		 * Creates new instance of the message FlagInfo.
47  		 * 
48  		Synchronous message. FlagInfo contains all info about the flag
49  		in the CTF game mode. Is not sent in other game types.
50  	
51  		 * Corresponding GameBots message
52  		 *   (static part)
53  		 *   is
54  		 *   FLG.
55  		 * 
56   	  	 * 
57  		 *   
58  		 *     @param Id 
59  			An unique Id for this flag, assigned by the game.
60  		
61  		 *   
62  		 * 
63  		 *   
64  		 * 
65  		 *   
66  		 * 
67  		 *   
68  		 * 
69  		 *   
70  		 * 
71  		 *   
72  		 * 
73  		 */
74  		public FlagInfoStaticImpl(
75  			UnrealId Id
76  		) {
77  			
78  					this.Id = Id;
79  				
80  		}
81      
82      	/**
83  		 * Cloning constructor from the full message.
84  		 *
85  		 * @param original
86  		 */
87  		public FlagInfoStaticImpl(FlagInfo original) {		
88  			
89  					this.Id = original.getId()
90   	;
91  				
92  			this.SimTime = original.getSimTime();			
93  		}
94  		
95  		/**
96  		 * Cloning constructor from the full message.
97  		 *
98  		 * @param original
99  		 */
100 		public FlagInfoStaticImpl(FlagInfoStaticImpl original) {		
101 			
102 					this.Id = original.getId()
103  	;
104 				
105 			this.SimTime = original.getSimTime();
106 		}
107 		
108 			/**
109 			 * Cloning constructor from the message part.
110 			 *
111 			 * @param original
112 			 */
113 			public FlagInfoStaticImpl(FlagInfoStatic original) {
114 				
115 						this.Id = original.getId()
116  	;
117 					
118 			}
119 		
120    				
121    				@Override
122    				public void setSimTime(long SimTime) {
123 					super.setSimTime(SimTime);
124 				}
125    			
126 	    				@Override
127 	    				public 
128 	    				FlagInfoStaticImpl clone() {
129 	    					return new 
130 	    					FlagInfoStaticImpl(this);
131 	    				}
132 	    				
133 	    				
134     	
135 	    /**
136          * 
137 			An unique Id for this flag, assigned by the game.
138 		 
139          */
140         protected
141          UnrealId Id =
142        	null;
143 	
144  		/**
145          * 
146 			An unique Id for this flag, assigned by the game.
147 		 
148          */
149         public  UnrealId getId()
150  	 {
151 				    					return Id;
152 				    				}
153 				    			
154     	
155     	
156     	public static class FlagInfoStaticUpdate
157      implements IStaticWorldObjectUpdatedEvent
158 		{
159 			
160 			private FlagInfoStatic data;
161 			private long time;
162 			
163 			public FlagInfoStaticUpdate
164     (FlagInfoStatic source, long time)
165 			{
166 				this.data = source;
167 				this.time = time;
168 			}
169 			
170 			/**
171 			 * Simulation time in MILLI SECONDS !!!
172 			 */
173 			@Override
174 			public long getSimTime() {
175 				return time;
176 			}
177 	
178 			@Override
179 			public WorldObjectId getId() {
180 				return data.getId();
181 			}
182 			
183 			@Override
184 			public IWorldObjectUpdateResult<IStaticWorldObject> update(
185 					IStaticWorldObject object) {
186 				if ( object == null)
187 				{
188 					data = new FlagInfoStaticImpl(data);
189 					return new IWorldObjectUpdateResult.WorldObjectUpdateResult<IStaticWorldObject>(IWorldObjectUpdateResult.Result.CREATED, data);
190 				}
191 				//since static objects can't be updated, we'll just check that the object stays the same
192 				if ( object instanceof FlagInfoStaticImpl)
193 				{
194 					FlagInfoStaticImpl orig = (FlagInfoStaticImpl)object;
195 					//since these errors usually mean error in gamebots, we will just print an error message
196 					if ( data.isDifferentFrom(orig) )
197 					{
198 						//data.isDifferentFrom(orig);
199 						//throw new PogamutException("Trying to modify static object " + this.data.getId().toString() , this);
200 						System.out.println("!!!!!ERROR!!!!!! in static object modification. Object class : FlagInfoStaticImpl to see which property was different see !!!!PROPERTY UPDATE ERROR!!!!");
201 					}
202 					return new IWorldObjectUpdateResult.WorldObjectUpdateResult<IStaticWorldObject>(IWorldObjectUpdateResult.Result.SAME, data);
203 				}				
204 				throw new PogamutException("Unexpected object type for update, FlagInfoStaticImpl expected not class " + object.getClass().getSimpleName() + ".", this);
205 			}
206 		}
207 	
208     
209  		
210  		@Override
211  		public boolean isDifferentFrom(IStaticWorldObject other)
212  		{
213  			if (other == null) //early fail
214  			{
215  				return true;
216  			}
217  			else if (other == this) //early out
218  			{
219  				return false;
220  			}
221  			else
222  			{
223  				FlagInfoStatic obj = (FlagInfoStatic) other;
224 
225  				
226  						if ( !(
227  	 			AdvancedEquals.equalsOrNull(this.getId()
228  	, obj.getId()
229  	)
230  	 		) )
231 						{
232 							System.out.println("!!!!!PROPERTY UPDATE ERROR!!!! on property Id on object class FlagInfoStatic");
233 							return true;
234 						}
235  					
236  			}
237  			return false;
238  		}
239  	 
240  		
241  	    public String toString() {
242             return
243             	super.toString() + "[" +
244             	
245 		              			"Id = " + String.valueOf(getId()
246  	) + " | " + 
247 		              		
248 				"]";           		
249         }
250  	
251  		
252  		public String toHtmlString() {
253  			return super.toString() + "[<br/>" +
254             	
255 		              			"<b>Id</b> = " + String.valueOf(getId()
256  	) + " <br/> " + 
257 		              		
258 				"<br/>]";     
259 		}
260  	
261  		
262  		// --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=all]) ---
263         	
264 		// --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=all]) ---
265 		
266 	    // --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=static+classtype[@name=impl]) ---
267 	        
268 	    // --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=static+classtype[@name=impl]) ---        	            	
269  	
270 		}
271