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