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