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