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