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 VEH.  
19              			
20           *
21           *  <p></p><p></p>
22           *  Complete message documentation:               
23           *  
24  		Synchronous message. Holds vehicles we see. Id for vehicles doesn't work, so 
25  		this message is without Id. We can join vehicles by ENTER command if we are 
26  		close enough - ussually 100 ut units or less. Note: Vehicle support is 
27  		in aplha testing right now.
28  	
29           */
30   	public class VehicleStaticImpl 
31    						extends
32    						VehicleStatic
33  	    {
34   	
35      	
36      	
37      	/**
38      	 * Parameter-less contructor for the message.
39      	 */
40  		public VehicleStaticImpl()
41  		{
42  		}
43  	
44      	
45      	
46      	
47      	/**
48  		 * Creates new instance of the message Vehicle.
49  		 * 
50  		Synchronous message. Holds vehicles we see. Id for vehicles doesn't work, so 
51  		this message is without Id. We can join vehicles by ENTER command if we are 
52  		close enough - ussually 100 ut units or less. Note: Vehicle support is 
53  		in aplha testing right now.
54  	
55  		 * Corresponding GameBots message
56  		 *   (static part)
57  		 *   is
58  		 *   VEH.
59  		 * 
60   	  	 * 
61  		 *   
62  		 *     @param Id Unique Id of the vehicle or vehicle part.
63  		 *   
64  		 * 
65  		 *   
66  		 * 
67  		 *   
68  		 * 
69  		 *   
70  		 * 
71  		 *   
72  		 * 
73  		 *   
74  		 * 
75  		 *   
76  		 * 
77  		 *   
78  		 * 
79  		 *   
80  		 * 
81  		 *   
82  		 * 
83  		 *   
84  		 *     @param Type 
85  			Class of the vehicle. If it is a car, turret etc.
86  		
87  		 *   
88  		 * 
89  		 */
90  		public VehicleStaticImpl(
91  			UnrealId Id,  String Type
92  		) {
93  			
94  					this.Id = Id;
95  				
96  					this.Type = Type;
97  				
98  		}
99      
100     	/**
101 		 * Cloning constructor from the full message.
102 		 *
103 		 * @param original
104 		 */
105 		public VehicleStaticImpl(Vehicle original) {		
106 			
107 					this.Id = original.getId()
108  	;
109 				
110 					this.Type = original.getType()
111  	;
112 				
113 			this.SimTime = original.getSimTime();			
114 		}
115 		
116 		/**
117 		 * Cloning constructor from the full message.
118 		 *
119 		 * @param original
120 		 */
121 		public VehicleStaticImpl(VehicleStaticImpl original) {		
122 			
123 					this.Id = original.getId()
124  	;
125 				
126 					this.Type = original.getType()
127  	;
128 				
129 			this.SimTime = original.getSimTime();
130 		}
131 		
132 			/**
133 			 * Cloning constructor from the message part.
134 			 *
135 			 * @param original
136 			 */
137 			public VehicleStaticImpl(VehicleStatic original) {
138 				
139 						this.Id = original.getId()
140  	;
141 					
142 						this.Type = original.getType()
143  	;
144 					
145 			}
146 		
147    				
148    				@Override
149    				public void setSimTime(long SimTime) {
150 					super.setSimTime(SimTime);
151 				}
152    			
153 	    				@Override
154 	    				public 
155 	    				VehicleStaticImpl clone() {
156 	    					return new 
157 	    					VehicleStaticImpl(this);
158 	    				}
159 	    				
160 	    				
161     	
162 	    /**
163          * Unique Id of the vehicle or vehicle part. 
164          */
165         protected
166          UnrealId Id =
167        	null;
168 	
169  		/**
170          * Unique Id of the vehicle or vehicle part. 
171          */
172         public  UnrealId getId()
173  	 {
174 				    					return Id;
175 				    				}
176 				    			
177     	
178 	    /**
179          * 
180 			Class of the vehicle. If it is a car, turret etc.
181 		 
182          */
183         protected
184          String Type =
185        	null;
186 	
187  		/**
188          * 
189 			Class of the vehicle. If it is a car, turret etc.
190 		 
191          */
192         public  String getType()
193  	 {
194 				    					return Type;
195 				    				}
196 				    			
197     	
198     	
199     	public static class VehicleStaticUpdate
200      implements IStaticWorldObjectUpdatedEvent
201 		{
202 			
203 			private VehicleStatic data;
204 			private long time;
205 			
206 			public VehicleStaticUpdate
207     (VehicleStatic source, long time)
208 			{
209 				this.data = source;
210 				this.time = time;
211 			}
212 			
213 			/**
214 			 * Simulation time in MILLI SECONDS !!!
215 			 */
216 			@Override
217 			public long getSimTime() {
218 				return time;
219 			}
220 	
221 			@Override
222 			public WorldObjectId getId() {
223 				return data.getId();
224 			}
225 			
226 			@Override
227 			public IWorldObjectUpdateResult<IStaticWorldObject> update(
228 					IStaticWorldObject object) {
229 				if ( object == null)
230 				{
231 					data = new VehicleStaticImpl(data);
232 					return new IWorldObjectUpdateResult.WorldObjectUpdateResult<IStaticWorldObject>(IWorldObjectUpdateResult.Result.CREATED, data);
233 				}
234 				//since static objects can't be updated, we'll just check that the object stays the same
235 				if ( object instanceof VehicleStaticImpl)
236 				{
237 					VehicleStaticImpl orig = (VehicleStaticImpl)object;
238 					//since these errors usually mean error in gamebots, we will just print an error message
239 					if ( data.isDifferentFrom(orig) )
240 					{
241 						//data.isDifferentFrom(orig);
242 						//throw new PogamutException("Trying to modify static object " + this.data.getId().toString() , this);
243 						System.out.println("!!!!!ERROR!!!!!! in static object modification. Object class : VehicleStaticImpl to see which property was different see !!!!PROPERTY UPDATE ERROR!!!!");
244 					}
245 					return new IWorldObjectUpdateResult.WorldObjectUpdateResult<IStaticWorldObject>(IWorldObjectUpdateResult.Result.SAME, data);
246 				}				
247 				throw new PogamutException("Unexpected object type for update, VehicleStaticImpl expected not class " + object.getClass().getSimpleName() + ".", this);
248 			}
249 		}
250 	
251     
252  		
253  		@Override
254  		public boolean isDifferentFrom(IStaticWorldObject other)
255  		{
256  			if (other == null) //early fail
257  			{
258  				return true;
259  			}
260  			else if (other == this) //early out
261  			{
262  				return false;
263  			}
264  			else
265  			{
266  				VehicleStatic obj = (VehicleStatic) other;
267 
268  				
269  						if ( !(
270  	 			AdvancedEquals.equalsOrNull(this.getId()
271  	, obj.getId()
272  	)
273  	 		) )
274 						{
275 							System.out.println("!!!!!PROPERTY UPDATE ERROR!!!! on property Id on object class VehicleStatic");
276 							return true;
277 						}
278  					
279  						if ( !(
280  	 			AdvancedEquals.equalsOrNull(this.getType()
281  	, obj.getType()
282  	)
283  	 		) )
284 						{
285 							System.out.println("!!!!!PROPERTY UPDATE ERROR!!!! on property Type on object class VehicleStatic");
286 							return true;
287 						}
288  					
289  			}
290  			return false;
291  		}
292  	 
293  		
294  	    public String toString() {
295             return
296             	super.toString() + "[" +
297             	
298 		              			"Id = " + String.valueOf(getId()
299  	) + " | " + 
300 		              		
301 		              			"Type = " + String.valueOf(getType()
302  	) + " | " + 
303 		              		
304 				"]";           		
305         }
306  	
307  		
308  		public String toHtmlString() {
309  			return super.toString() + "[<br/>" +
310             	
311 		              			"<b>Id</b> = " + String.valueOf(getId()
312  	) + " <br/> " + 
313 		              		
314 		              			"<b>Type</b> = " + String.valueOf(getType()
315  	) + " <br/> " + 
316 		              		
317 				"<br/>]";     
318 		}
319  	
320  		
321  		// --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=all]) ---
322         	
323 		// --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=all]) ---
324 		
325 	    // --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=static+classtype[@name=impl]) ---
326 	        
327 	    // --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=static+classtype[@name=impl]) ---        	            	
328  	
329 		}
330