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 FLG.  
19              			
20           *
21           *  <p></p><p></p>
22           *  Complete message documentation:               
23           *  
24  		Synchronous message. FlagInfo contains all info about the flag
25  		in the CTF game mode. Is not sent in other game types.
26  	
27           */
28   	public class FlagInfoLocalImpl 
29    						extends
30    						FlagInfoLocal
31  	    {
32   	
33      	
34      	
35      	/**
36      	 * Parameter-less contructor for the message.
37      	 */
38  		public FlagInfoLocalImpl()
39  		{
40  		}
41  	
42      	
43      	
44      	
45      	/**
46  		 * Creates new instance of the message FlagInfo.
47  		 * 
48  		Synchronous message. FlagInfo contains all info about the flag
49  		in the CTF game mode. Is not sent in other game types.
50  	
51  		 * Corresponding GameBots message
52  		 *   (local part)
53  		 *   is
54  		 *   FLG.
55  		 * 
56   	  	 * 
57  		 *   
58  		 *     @param Id 
59  			An unique Id for this flag, assigned by the game.
60  		
61  		 *   
62  		 * 
63  		 *   
64  		 * 
65  		 *   
66  		 * 
67  		 *   
68  		 * 
69  		 *   
70  		 *     @param Visible True if the bot can see the flag.
71  		 *   
72  		 * 
73  		 *   
74  		 * 
75  		 */
76  		public FlagInfoLocalImpl(
77  			UnrealId Id,  boolean Visible
78  		) {
79  			
80  					this.Id = Id;
81  				
82  					this.Visible = Visible;
83  				
84  		}
85      
86      	/**
87  		 * Cloning constructor from the full message.
88  		 *
89  		 * @param original
90  		 */
91  		public FlagInfoLocalImpl(FlagInfo original) {		
92  			
93  					this.Id = original.getId()
94   	;
95  				
96  					this.Visible = original.isVisible()
97   	;
98  				
99  			this.SimTime = original.getSimTime();			
100 		}
101 		
102 		/**
103 		 * Cloning constructor from the full message.
104 		 *
105 		 * @param original
106 		 */
107 		public FlagInfoLocalImpl(FlagInfoLocalImpl original) {		
108 			
109 					this.Id = original.getId()
110  	;
111 				
112 					this.Visible = original.isVisible()
113  	;
114 				
115 			this.SimTime = original.getSimTime();
116 		}
117 		
118 			/**
119 			 * Cloning constructor from the message part.
120 			 *
121 			 * @param original
122 			 */
123 			public FlagInfoLocalImpl(FlagInfoLocal original) {
124 				
125 						this.Id = original.getId()
126  	;
127 					
128 						this.Visible = original.isVisible()
129  	;
130 					
131 			}
132 		
133    				
134    				@Override
135    				public void setSimTime(long SimTime) {
136 					super.setSimTime(SimTime);
137 				}
138    			
139 	    				@Override
140 	    				public 
141 	    				FlagInfoLocalImpl clone() {
142 	    					return new 
143 	    					FlagInfoLocalImpl(this);
144 	    				}
145 	    				
146 	    				
147     	
148 	    /**
149          * 
150 			An unique Id for this flag, assigned by the game.
151 		 
152          */
153         protected
154          UnrealId Id =
155        	null;
156 	
157  		/**
158          * 
159 			An unique Id for this flag, assigned by the game.
160 		 
161          */
162         public  UnrealId getId()
163  	 {
164 				    					return Id;
165 				    				}
166 				    			
167     	
168 	    /**
169          * True if the bot can see the flag. 
170          */
171         protected
172          boolean Visible =
173        	false;
174 	
175  		/**
176          * True if the bot can see the flag. 
177          */
178         public  boolean isVisible()
179  	 {
180 				    					return Visible;
181 				    				}
182 				    			
183     	
184     	
185     	
186     	
187     	public FlagInfoLocalImpl getLocal() {
188 			return this;
189     	}
190 		public ISharedWorldObject getShared() {
191 		 	throw new UnsupportedOperationException("Could not return LOCAL as SHARED");
192 		}
193 		public IStaticWorldObject getStatic() {
194 		    throw new UnsupportedOperationException("Could not return LOCAL as STATIC");
195 		}
196  	
197 		public static class FlagInfoLocalUpdate
198      implements ILocalWorldObjectUpdatedEvent, IGBWorldObjectEvent
199 		{
200 			protected long time;
201 			
202 			protected FlagInfoLocal data = null; //contains object data for this update
203 			
204 			public FlagInfoLocalUpdate
205     (FlagInfoLocal moverLocal, long time)
206 			{
207 				this.data = moverLocal;
208 				this.time = time;
209 			}
210 			
211 			@Override
212 			public IWorldObjectUpdateResult<ILocalWorldObject> update(
213 					ILocalWorldObject object) 
214 			{
215 				if ( object == null)
216 				{
217 					data = new FlagInfoLocalImpl(data); //we always return Impl object
218 					return new IWorldObjectUpdateResult.WorldObjectUpdateResult<ILocalWorldObject>(IWorldObjectUpdateResult.Result.CREATED, data);
219 				}
220 				if ( object instanceof FlagInfoLocalImpl )
221 				{
222 					FlagInfoLocalImpl toUpdate = (FlagInfoLocalImpl)object;
223 					
224 					boolean updated = false;
225 					
226 					// UPDATING LOCAL PROPERTIES
227 					
228 				if (toUpdate.Visible != data.isVisible()
229  	) {
230 				    toUpdate.Visible=data.isVisible()
231  	;
232 					updated = true;
233 				}
234 			
235 					
236 					data = toUpdate; //the updating has finished
237 					
238 					if ( updated )
239 					{
240 						toUpdate.SimTime = this.time;
241 						return new IWorldObjectUpdateResult.WorldObjectUpdateResult<ILocalWorldObject>(IWorldObjectUpdateResult.Result.UPDATED, data);
242 					}
243 					
244 					return new IWorldObjectUpdateResult.WorldObjectUpdateResult<ILocalWorldObject>(IWorldObjectUpdateResult.Result.SAME, data);
245 				}
246 				throw new PogamutException("Unsupported object type for update. Expected FlagInfoLocalImpl for object " + object.getId() +", not object of class " + object.getClass().getSimpleName() + ".", this);
247 			}
248 	
249 			/**
250 			 * Simulation time in MILLI SECONDS !!!
251 			 */
252 			@Override
253 			public long getSimTime() {
254 				return this.time;
255 			}
256 	
257 			@Override
258 			public IWorldObject getObject() {
259 				return data;
260 			}
261 	
262 			@Override
263 			public WorldObjectId getId() {
264 				return data.getId();
265 			}
266 			
267 		}	
268  	
269  		
270  	    public String toString() {
271             return
272             	super.toString() + "[" +
273             	
274 		              			"Id = " + String.valueOf(getId()
275  	) + " | " + 
276 		              		
277 		              			"Visible = " + String.valueOf(isVisible()
278  	) + " | " + 
279 		              		
280 				"]";           		
281         }
282  	
283  		
284  		public String toHtmlString() {
285  			return super.toString() + "[<br/>" +
286             	
287 		              			"<b>Id</b> = " + String.valueOf(getId()
288  	) + " <br/> " + 
289 		              		
290 		              			"<b>Visible</b> = " + String.valueOf(isVisible()
291  	) + " <br/> " + 
292 		              		
293 				"<br/>]";     
294 		}
295  	
296  		
297  		// --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=all]) ---
298         	
299 		// --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=all]) ---
300 		
301 	    // --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=local+classtype[@name=impl]) ---
302 	        
303 	    // --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=local+classtype[@name=impl]) ---        	            	
304  	
305 		}
306