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=local]+classtype[@name=impl] BEGIN
13  		
14  		// --- IMPORTS FROM extra/code/java/javapart/classcategory[@name=local]+classtype[@name=impl] END
15      
16   		/**
17           *  
18              				Implementation of the local 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 EntityLocalImpl 
28    						extends
29    						EntityLocal
30  	    {
31   	
32      	
33      	
34      	/**
35      	 * Parameter-less contructor for the message.
36      	 */
37  		public EntityLocalImpl()
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  		 *   (local 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  		 *     @param Visible 
63  			If the item is in the field of view of the bot.
64  		
65  		 *   
66  		 * 
67  		 *   
68  		 * 
69  		 *   
70  		 * 
71  		 *   
72  		 * 
73  		 *   
74  		 * 
75  		 *   
76  		 * 
77  		 */
78  		public EntityLocalImpl(
79  			UnrealId Id,  boolean Visible
80  		) {
81  			
82  					this.Id = Id;
83  				
84  					this.Visible = Visible;
85  				
86  		}
87      
88      	/**
89  		 * Cloning constructor from the full message.
90  		 *
91  		 * @param original
92  		 */
93  		public EntityLocalImpl(Entity original) {		
94  			
95  					this.Id = original.getId()
96   	;
97  				
98  					this.Visible = original.isVisible()
99   	;
100 				
101 			this.SimTime = original.getSimTime();			
102 		}
103 		
104 		/**
105 		 * Cloning constructor from the full message.
106 		 *
107 		 * @param original
108 		 */
109 		public EntityLocalImpl(EntityLocalImpl original) {		
110 			
111 					this.Id = original.getId()
112  	;
113 				
114 					this.Visible = original.isVisible()
115  	;
116 				
117 			this.SimTime = original.getSimTime();
118 		}
119 		
120 			/**
121 			 * Cloning constructor from the message part.
122 			 *
123 			 * @param original
124 			 */
125 			public EntityLocalImpl(EntityLocal original) {
126 				
127 						this.Id = original.getId()
128  	;
129 					
130 						this.Visible = original.isVisible()
131  	;
132 					
133 			}
134 		
135    				
136    				@Override
137    				public void setSimTime(long SimTime) {
138 					super.setSimTime(SimTime);
139 				}
140    			
141 	    				@Override
142 	    				public 
143 	    				EntityLocalImpl clone() {
144 	    					return new 
145 	    					EntityLocalImpl(this);
146 	    				}
147 	    				
148 	    				
149     	
150 	    /**
151          * 
152 			Unique Id of the item. This Id represents some entity in the world.
153 		 
154          */
155         protected
156          UnrealId Id =
157        	null;
158 	
159  		/**
160          * 
161 			Unique Id of the item. This Id represents some entity in the world.
162 		 
163          */
164         public  UnrealId getId()
165  	 {
166 				    					return Id;
167 				    				}
168 				    			
169     	
170 	    /**
171          * 
172 			If the item is in the field of view of the bot.
173 		 
174          */
175         protected
176          boolean Visible =
177        	false;
178 	
179  		/**
180          * 
181 			If the item is in the field of view of the bot.
182 		 
183          */
184         public  boolean isVisible()
185  	 {
186 				    					return Visible;
187 				    				}
188 				    			
189     	
190     	
191     	
192     	
193     	public EntityLocalImpl getLocal() {
194 			return this;
195     	}
196 		public ISharedWorldObject getShared() {
197 		 	throw new UnsupportedOperationException("Could not return LOCAL as SHARED");
198 		}
199 		public IStaticWorldObject getStatic() {
200 		    throw new UnsupportedOperationException("Could not return LOCAL as STATIC");
201 		}
202  	
203 		public static class EntityLocalUpdate
204      implements ILocalWorldObjectUpdatedEvent, IGBWorldObjectEvent
205 		{
206 			protected long time;
207 			
208 			protected EntityLocal data = null; //contains object data for this update
209 			
210 			public EntityLocalUpdate
211     (EntityLocal moverLocal, long time)
212 			{
213 				this.data = moverLocal;
214 				this.time = time;
215 			}
216 			
217 			@Override
218 			public IWorldObjectUpdateResult<ILocalWorldObject> update(
219 					ILocalWorldObject object) 
220 			{
221 				if ( object == null)
222 				{
223 					data = new EntityLocalImpl(data); //we always return Impl object
224 					return new IWorldObjectUpdateResult.WorldObjectUpdateResult<ILocalWorldObject>(IWorldObjectUpdateResult.Result.CREATED, data);
225 				}
226 				if ( object instanceof EntityLocalImpl )
227 				{
228 					EntityLocalImpl toUpdate = (EntityLocalImpl)object;
229 					
230 					boolean updated = false;
231 					
232 					// UPDATING LOCAL PROPERTIES
233 					
234 				if (toUpdate.Visible != data.isVisible()
235  	) {
236 				    toUpdate.Visible=data.isVisible()
237  	;
238 					updated = true;
239 				}
240 			
241 					
242 					data = toUpdate; //the updating has finished
243 					
244 					if ( updated )
245 					{
246 						toUpdate.SimTime = this.time;
247 						return new IWorldObjectUpdateResult.WorldObjectUpdateResult<ILocalWorldObject>(IWorldObjectUpdateResult.Result.UPDATED, data);
248 					}
249 					
250 					return new IWorldObjectUpdateResult.WorldObjectUpdateResult<ILocalWorldObject>(IWorldObjectUpdateResult.Result.SAME, data);
251 				}
252 				throw new PogamutException("Unsupported object type for update. Expected EntityLocalImpl for object " + object.getId() +", not object of class " + object.getClass().getSimpleName() + ".", this);
253 			}
254 	
255 			/**
256 			 * Simulation time in MILLI SECONDS !!!
257 			 */
258 			@Override
259 			public long getSimTime() {
260 				return this.time;
261 			}
262 	
263 			@Override
264 			public IWorldObject getObject() {
265 				return data;
266 			}
267 	
268 			@Override
269 			public WorldObjectId getId() {
270 				return data.getId();
271 			}
272 			
273 		}	
274  	
275  		
276  	    public String toString() {
277             return
278             	super.toString() + "[" +
279             	
280 		              			"Id = " + String.valueOf(getId()
281  	) + " | " + 
282 		              		
283 		              			"Visible = " + String.valueOf(isVisible()
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 		              			"<b>Visible</b> = " + String.valueOf(isVisible()
297  	) + " <br/> " + 
298 		              		
299 				"<br/>]";     
300 		}
301  	
302  		
303  		// --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=all]) ---
304         	
305 		// --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=all]) ---
306 		
307 	    // --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=local+classtype[@name=impl]) ---
308 	        
309 	    // --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=local+classtype[@name=impl]) ---        	            	
310  	
311 		}
312