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