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=shared]+classtype[@name=impl] BEGIN
13  		
14  		// --- IMPORTS FROM extra/code/java/javapart/classcategory[@name=shared]+classtype[@name=impl] END
15      
16   		/**
17           *  
18              				Implementation of the shared part 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 class ItemSharedImpl 
29    						extends
30    						ItemShared
31  	    {
32   	
33      
34      	
35      	public ItemSharedImpl(ItemSharedImpl source) {
36  			
37  				this.Id = source.
38  					getId()
39   	;
40  			
41  				this.myLocation = source.myLocation;
42  			
43  				this.myDropped = source.myDropped;
44  			
45  		}
46  		
47  		public ItemSharedImpl(WorldObjectId objectId, Collection<ISharedProperty> properties) {
48  			this.Id = (UnrealId)objectId;
49  			NullCheck.check(this.Id, "objectId");
50  		
51  			if (properties.size() != 2) {
52  				throw new PogamutException("Not enough properties passed to the constructor.", ItemSharedImpl.class);
53  			}
54  		
55  			//we have to do some checking in this one to know that we get all properties required
56  			for ( ISharedProperty property : properties ) {
57  				PropertyId pId = property.getPropertyId();
58  				if ( !objectId.equals( property.getObjectId() )) {
59  					//properties for different objects
60  					throw new PogamutException("Trying to create a ItemSharedImpl with different WorldObjectId properties : " + 
61  											    this.Id.getStringId() + " / " + property.getObjectId().getStringId() , this);
62  				}
63  				if (!ItemShared.SharedPropertyTokens.contains(pId.getPropertyToken())) {
64  				// property that does not belong here
65  				throw new PogamutException("Trying to create a ItemSharedImpl with invalid property (invalid property token): " + 
66  					this.Id.getStringId() + " / " + property.getPropertyId().getPropertyToken().getToken() , this);
67  				}
68  				propertyMap.put(property.getPropertyId(), property);
69  				
70  				
71  					if (pId.getPropertyToken().getToken().equals("Location"))
72  					{
73  						this.myLocation = (LocationProperty)property;
74  					}
75  				
76  					if (pId.getPropertyToken().getToken().equals("Dropped"))
77  					{
78  						this.myDropped = (BooleanProperty)property;
79  					}
80  				
81  			}
82  		}
83      
84     				
85     				@Override
86     				public void setSimTime(long SimTime) {
87  					super.setSimTime(SimTime);
88  				}
89     			
90  	    				@Override
91  	    				public 
92  	    				ItemSharedImpl clone() {
93  	    					return new 
94  	    					ItemSharedImpl(this);
95  	    				}
96  	    				
97  	    				
98  		
99  		
100 		
101 		protected HashMap<PropertyId, ISharedProperty> propertyMap = new HashMap<PropertyId, ISharedProperty>(
102 			2
103 		);
104 		
105 		@Override
106 		public ISharedProperty getProperty(PropertyId id) {
107 			return propertyMap.get(id);
108 		}
109 
110 		@Override
111 		public Map<PropertyId, ISharedProperty> getProperties() {
112 			return propertyMap;
113 		}
114 	
115 		
116 		
117     	
118 	    /**
119          * 
120 			Unique Id of the item. This Id represents just item on the
121 			map, not in our inventory.
122 		 
123          */
124         protected
125          UnrealId Id =
126        	null;
127 	
128  		/**
129          * 
130 			Unique Id of the item. This Id represents just item on the
131 			map, not in our inventory.
132 		 
133          */
134         public  UnrealId getId()
135  	 {
136   			return Id;
137   		}
138   		
139     	
140 	    /**
141          * Location of the item. 
142          */
143         protected
144          LocationProperty 
145         myLocation
146 					= null;
147 					
148 					
149  		/**
150          * Location of the item. 
151          */
152         public  Location getLocation()
153  	 {
154 			  			return myLocation.getValue();
155 			  		}
156 				
157     	
158 	    /**
159          * 
160             Whether it is regular item or one dropped by some bot (usually during dying). Items that are not dropped
161             usually respawns itself (depends on the game settings) while those that are dropped may be taken only once.
162          
163          */
164         protected
165          BooleanProperty 
166         myDropped
167 					= null;
168 					
169 					
170  		/**
171          * 
172             Whether it is regular item or one dropped by some bot (usually during dying). Items that are not dropped
173             usually respawns itself (depends on the game settings) while those that are dropped may be taken only once.
174          
175          */
176         public  boolean isDropped()
177  	 {
178 			  			return myDropped.getValue();
179 			  		}
180 				
181     	
182     	
183     	public static class ItemSharedUpdate
184      implements ISharedWorldObjectUpdatedEvent
185 		{
186 	
187 			private ItemShared object;
188 			private long time;
189 			private ITeamId teamId;
190 			
191 			public ItemSharedUpdate
192     (ItemShared data, long time, ITeamId teamId)
193 			{
194 				this.object = data;
195 				this.time = time;
196 				this.teamId = teamId;
197 			}
198 			
199 			/**
200 			 * Simulation time in MILLI SECONDS !!!
201 			 */
202 			@Override
203 			public long getSimTime() {
204 				return this.time;
205 			}
206 	
207 			@Override
208 			public WorldObjectId getId() {
209 				return object.getId();
210 			}
211 	
212 			@Override
213 			public ITeamId getTeamId() {
214 				return teamId;
215 			}
216 			
217 			@Override
218 			public Class getCompositeObjectClass()
219 			{
220 				return object.getCompositeClass();
221 			}
222 	
223 			@Override
224 			public Collection<ISharedPropertyUpdatedEvent> getPropertyEvents() {
225 				LinkedList<ISharedPropertyUpdatedEvent> events = new LinkedList<ISharedPropertyUpdatedEvent>();
226 				
227 				for ( ISharedProperty property : object.getProperties().values() )
228 				{
229 					if ( property != null)
230 					{
231 						events.push( property.createUpdateEvent(time, teamId) );
232 					}
233 				}
234 				return events;
235 			}
236 			
237 		}
238 	
239     
240  		
241  	    public String toString() {
242             return
243             	super.toString() + "[" +
244             	
245 		              			"Id = " + String.valueOf(getId()
246  	) + " | " + 
247 		              		
248 		              			"Location = " + String.valueOf(getLocation()
249  	) + " | " + 
250 		              		
251 		              			"Dropped = " + String.valueOf(isDropped()
252  	) + " | " + 
253 		              		
254 				"]";           		
255         }
256  	
257  		
258  		public String toHtmlString() {
259  			return super.toString() + "[<br/>" +
260             	
261 		              			"<b>Id</b> = " + String.valueOf(getId()
262  	) + " <br/> " + 
263 		              		
264 		              			"<b>Location</b> = " + String.valueOf(getLocation()
265  	) + " <br/> " + 
266 		              		
267 		              			"<b>Dropped</b> = " + String.valueOf(isDropped()
268  	) + " <br/> " + 
269 		              		
270 				"<br/>]";     
271 		}
272  	
273  		
274  		// --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=all]) ---
275         	
276 		// --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=all]) ---
277 		
278 	    // --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=shared+classtype[@name=impl]) ---
279 	        
280 	    // --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=shared+classtype[@name=impl]) ---        	            	
281  	
282 		}
283