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