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=base]+classtype[@name=abstract] BEGIN
13  		
14  		// --- IMPORTS FROM extra/code/java/javapart/classcategory[@name=base]+classtype[@name=abstract] END
15      
16   		/**
17           *  
18              				Abstract definition of the GameBots2004 message INV.  
19              			
20           *
21           *  <p></p><p></p>
22           *  Complete message documentation:               
23           *  
24  		Synchronous/asynchronous message. An object on the ground that
25  		can be picked up.
26  	
27           */
28   	public abstract class Item   
29    				extends 
30    				InfoMessage
31    						implements IWorldEvent, IWorldChangeEvent, ICompositeWorldObject
32    						
33  	    		,ILocated
34  	    		,IGBViewable
35  	    		,ItemTyped
36  	    {
37   	
38      	/** Example how the message looks like - used during parser tests. */
39      	public static final String PROTOTYPE =
40      		"INV {Id unreal_id}  {NavPointId unreal_id}  {Visible False}  {Location 0,0,0}  {Amount 0}  {Type xWeapons.FlakCannonPickup}  {Dropped False} ";
41      
42      	
43      	
44      	/**
45      	 * Parameter-less contructor for the message.
46      	 */
47  		public Item()
48  		{
49  		}
50  	
51  				// abstract message, it does not have any more constructors				
52  			
53  	   		
54  			protected long SimTime;
55  				
56  			/**
57  			 * Simulation time in MILLI SECONDS !!!
58  			 */	
59  			@Override
60  			public long getSimTime() {
61  				return SimTime;
62  			}
63  						
64  			/**
65  			 * Used by Yylex to slip correct time of the object or programmatically.
66  			 */
67  			protected void setSimTime(long SimTime) {
68  				this.SimTime = SimTime;
69  			}
70  	   	
71   		/**
72           * 
73  			Unique Id of the item. This Id represents just item on the
74  			map, not in our inventory.
75  		 
76           */
77          public abstract UnrealId getId()
78   	;
79  		    			
80   		/**
81           * 
82              Id of the navpoint where the item is laying. If null - the item was dropped by the bot or another player.
83           
84           */
85          public abstract UnrealId getNavPointId()
86   	;
87  		    			
88   		/**
89           * 
90              If the Item is not dropped then it's item that is laying at some navpoint and
91              this is that NavPoint instance.
92           
93           */
94          public abstract NavPoint getNavPoint()
95   	;
96  		    			
97   		/**
98           * 
99  			If the item is in the field of view of the bot.
100 		 
101          */
102         public abstract boolean isVisible()
103  	;
104 		    			
105  		/**
106          * Location of the item. 
107          */
108         public abstract Location getLocation()
109  	;
110 		    			
111  		/**
112          * 
113 			If this item is some ammo or health pack, here we can find
114 			out how much of the attribute this item will add.
115 		 
116          */
117         public abstract int getAmount()
118  	;
119 		    			
120  		/**
121          * 
122 			Class of the item (e.g. xWeapons.FlakCannonPickup).
123 		 
124          */
125         public abstract ItemType getType()
126  	;
127 		    			
128  		/**
129          * 
130 			Descriptor of the item - according the ItemType you may cast this to various XYZDescriptor. 
131 		 
132          */
133         public abstract ItemDescriptor getDescriptor()
134  	;
135 		    			
136  		/**
137          * 
138             Whether it is regular item or one dropped by some bot (usually during dying). Items that are not dropped
139             usually respawns itself (depends on the game settings) while those that are dropped may be taken only once.
140          
141          */
142         public abstract boolean isDropped()
143  	;
144 		    			
145 		 	@Override
146 			public IWorldObjectUpdatedEvent createDisappearEvent() {
147 				return new ObjectDisappeared(this, getSimTime());
148 			}
149 			
150 			public static class ObjectDisappeared implements IWorldObjectUpdatedEvent
151 			{
152 				
153 				public ObjectDisappeared(Item obj, long time) {
154 					this.obj = obj;
155 					this.time = time;
156 				}
157 				
158 				private Item obj;
159 				private long time;
160 		
161 				@Override
162 				public WorldObjectId getId() {
163 					return obj.getId();
164 				}
165 		
166 		        /**
167 		         * Simulation time in MILLI SECONDS !!!
168 		         */
169 				@Override
170 				public long getSimTime() {
171 					return time;
172 				}
173 		
174 				@Override
175 				public IWorldObjectUpdateResult<IWorldObject> update(IWorldObject obj) {
176 					if (obj == null) {
177 						throw new PogamutException("Can't 'disappear' null!", this);
178 					}
179 					if (!(obj instanceof ItemMessage)) {
180 						throw new PogamutException("Can't update different class than ItemMessage, got class " + obj.getClass().getSimpleName() + "!", this);
181 					}
182 					ItemMessage toUpdate = (ItemMessage)obj;
183 					if (toUpdate.Visible) {
184 						toUpdate.Visible = false;
185 						return new IWorldObjectUpdateResult.WorldObjectUpdateResult(IWorldObjectUpdateResult.Result.UPDATED, obj);
186 					} else {
187 						return new IWorldObjectUpdateResult.WorldObjectUpdateResult(IWorldObjectUpdateResult.Result.SAME, obj);
188 					}
189 				}
190 		
191 			}
192 	
193 		
194     	
195     	public static class ItemUpdate
196      extends GBObjectUpdate implements ICompositeWorldObjectUpdatedEvent, IGBWorldObjectEvent {	
197 			private Item object;
198 			private long time;
199 			private ITeamId teamId;
200 			
201 			public ItemUpdate
202     (Item source, long eventTime, ITeamId teamId) {
203 				this.object = source;
204 				this.time = eventTime;
205 				this.teamId = teamId;
206 			}
207 			
208 			/**
209 			 * Simulation time in MILLI SECONDS !!!
210 			 */ 
211 			@Override
212 			public long getSimTime() {
213 				return time;
214 			}
215 	
216 			@Override
217 			public IWorldObject getObject() {
218 				return object;
219 			}
220 	
221 			@Override
222 			public WorldObjectId getId() {
223 				return object.getId();
224 			}
225 	
226 			@Override
227 			public ILocalWorldObjectUpdatedEvent getLocalEvent() {
228 				return new ItemLocalImpl.ItemLocalUpdate
229     ((ItemLocal)object.getLocal(), time);
230 			}
231 	
232 			@Override
233 			public ISharedWorldObjectUpdatedEvent getSharedEvent() {
234 				return new ItemSharedImpl.ItemSharedUpdate
235     ((ItemShared)object.getShared(), time, teamId);
236 			}
237 	
238 			@Override
239 			public IStaticWorldObjectUpdatedEvent getStaticEvent() {
240 				return new ItemStaticImpl.ItemStaticUpdate
241     ((ItemStatic)object.getStatic(), time);
242 			}
243 			
244 		}
245     
246  		
247  	    public String toString() {
248             return
249             	super.toString() + "[" +
250             	
251 		              			"Id = " + String.valueOf(getId()
252  	) + " | " + 
253 		              		
254 		              			"NavPointId = " + String.valueOf(getNavPointId()
255  	) + " | " + 
256 		              		
257 		              			"Visible = " + String.valueOf(isVisible()
258  	) + " | " + 
259 		              		
260 		              			"Location = " + String.valueOf(getLocation()
261  	) + " | " + 
262 		              		
263 		              			"Amount = " + String.valueOf(getAmount()
264  	) + " | " + 
265 		              		
266 		              			"Type = " + String.valueOf(getType()
267  	) + " | " + 
268 		              		
269 		              			"Dropped = " + String.valueOf(isDropped()
270  	) + " | " + 
271 		              		
272 				"]";           		
273         }
274  	
275  		
276  		public String toHtmlString() {
277  			return super.toString() + "[<br/>" +
278             	
279 		              			"<b>Id</b> = " + String.valueOf(getId()
280  	) + " <br/> " + 
281 		              		
282 		              			"<b>NavPointId</b> = " + String.valueOf(getNavPointId()
283  	) + " <br/> " + 
284 		              		
285 		              			"<b>Visible</b> = " + String.valueOf(isVisible()
286  	) + " <br/> " + 
287 		              		
288 		              			"<b>Location</b> = " + String.valueOf(getLocation()
289  	) + " <br/> " + 
290 		              		
291 		              			"<b>Amount</b> = " + String.valueOf(getAmount()
292  	) + " <br/> " + 
293 		              		
294 		              			"<b>Type</b> = " + String.valueOf(getType()
295  	) + " <br/> " + 
296 		              		
297 		              			"<b>Dropped</b> = " + String.valueOf(isDropped()
298  	) + " <br/> " + 
299 		              		
300 				"<br/>]";     
301 		}
302  	
303  	    public String toJsonLiteral() {
304             return "item( "
305             		+
306 									(getId()
307  	 == null ? "null" :
308 										"\"" + getId()
309  	.getStringId() + "\"" 
310 									)
311 								+ ", " + 
312 									(getNavPointId()
313  	 == null ? "null" :
314 										"\"" + getNavPointId()
315  	.getStringId() + "\"" 
316 									)
317 								+ ", " + 
318 								    String.valueOf(isVisible()
319  	)									
320 								+ ", " + 
321 								    (getLocation()
322  	 == null ? "null" :
323 										"[" + getLocation()
324  	.getX() + ", " + getLocation()
325  	.getY() + ", " + getLocation()
326  	.getZ() + "]" 
327 									)
328 								+ ", " + 
329 								    String.valueOf(getAmount()
330  	)									
331 								+ ", " + 
332 									(getType()
333  	 == null ? "null" :
334 										"\"" + getType()
335  	.getName() + "\"" 
336 									)
337 								+ ", " + 
338 								    String.valueOf(isDropped()
339  	)									
340 								
341                    + ")";
342         }
343  	
344  		
345  		// --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=all]) ---
346         	
347 		// --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=all]) ---
348 		
349 	    // --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=base+classtype[@name=abstract]) ---
350 	        
351 	    // --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=base+classtype[@name=abstract]) ---        	            	
352  	
353 		}
354