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 ATR.  
19              			
20           *
21           *  <p></p><p></p>
22           *  Complete message documentation:               
23           *  
24  		Synchronous message. Contains the results of automatically
25  		casted rays. One ATR message is for one casted ray. New
26  		automatically casted rays can be defined by ADDRAY command and
27  		removed by REMOVERAY command.
28  	
29           */
30   	public class AutoTraceRaySharedImpl 
31    						extends
32    						AutoTraceRayShared
33  	    {
34   	
35      
36      	
37      	public AutoTraceRaySharedImpl(AutoTraceRaySharedImpl source) {
38  			
39  				this.Id = source.
40  					getId()
41   	;
42  			
43  		}
44  		
45  		public AutoTraceRaySharedImpl(WorldObjectId objectId, Collection<ISharedProperty> properties) {
46  			this.Id = (UnrealId)objectId;
47  			NullCheck.check(this.Id, "objectId");
48  		
49  			if (properties.size() != 0) {
50  				throw new PogamutException("Not enough properties passed to the constructor.", AutoTraceRaySharedImpl.class);
51  			}
52  		
53  			//we have to do some checking in this one to know that we get all properties required
54  			for ( ISharedProperty property : properties ) {
55  				PropertyId pId = property.getPropertyId();
56  				if ( !objectId.equals( property.getObjectId() )) {
57  					//properties for different objects
58  					throw new PogamutException("Trying to create a AutoTraceRaySharedImpl with different WorldObjectId properties : " + 
59  											    this.Id.getStringId() + " / " + property.getObjectId().getStringId() , this);
60  				}
61  				if (!AutoTraceRayShared.SharedPropertyTokens.contains(pId.getPropertyToken())) {
62  				// property that does not belong here
63  				throw new PogamutException("Trying to create a AutoTraceRaySharedImpl with invalid property (invalid property token): " + 
64  					this.Id.getStringId() + " / " + property.getPropertyId().getPropertyToken().getToken() , this);
65  				}
66  				propertyMap.put(property.getPropertyId(), property);
67  				
68  				
69  			}
70  		}
71      
72     				
73     				@Override
74     				public void setSimTime(long SimTime) {
75  					super.setSimTime(SimTime);
76  				}
77     			
78  	    				@Override
79  	    				public 
80  	    				AutoTraceRaySharedImpl clone() {
81  	    					return new 
82  	    					AutoTraceRaySharedImpl(this);
83  	    				}
84  	    				
85  	    				
86  		
87  		
88  		
89  		protected HashMap<PropertyId, ISharedProperty> propertyMap = new HashMap<PropertyId, ISharedProperty>(
90  			0
91  		);
92  		
93  		@Override
94  		public ISharedProperty getProperty(PropertyId id) {
95  			return propertyMap.get(id);
96  		}
97  
98  		@Override
99  		public Map<PropertyId, ISharedProperty> getProperties() {
100 			return propertyMap;
101 		}
102 	
103 		
104 		
105     	
106 	    /**
107          * 
108 			An Id for this ray (should be unique), assigned by the user
109 			when adding ray.
110 		 
111          */
112         protected
113          UnrealId Id =
114        	null;
115 	
116  		/**
117          * 
118 			An Id for this ray (should be unique), assigned by the user
119 			when adding ray.
120 		 
121          */
122         public  UnrealId getId()
123  	 {
124   			return Id;
125   		}
126   		
127     	
128     	
129     	public static class AutoTraceRaySharedUpdate
130      implements ISharedWorldObjectUpdatedEvent
131 		{
132 	
133 			private AutoTraceRayShared object;
134 			private long time;
135 			private ITeamId teamId;
136 			
137 			public AutoTraceRaySharedUpdate
138     (AutoTraceRayShared data, long time, ITeamId teamId)
139 			{
140 				this.object = data;
141 				this.time = time;
142 				this.teamId = teamId;
143 			}
144 			
145 			/**
146 			 * Simulation time in MILLI SECONDS !!!
147 			 */
148 			@Override
149 			public long getSimTime() {
150 				return this.time;
151 			}
152 	
153 			@Override
154 			public WorldObjectId getId() {
155 				return object.getId();
156 			}
157 	
158 			@Override
159 			public ITeamId getTeamId() {
160 				return teamId;
161 			}
162 			
163 			@Override
164 			public Class getCompositeObjectClass()
165 			{
166 				return object.getCompositeClass();
167 			}
168 	
169 			@Override
170 			public Collection<ISharedPropertyUpdatedEvent> getPropertyEvents() {
171 				LinkedList<ISharedPropertyUpdatedEvent> events = new LinkedList<ISharedPropertyUpdatedEvent>();
172 				
173 				for ( ISharedProperty property : object.getProperties().values() )
174 				{
175 					if ( property != null)
176 					{
177 						events.push( property.createUpdateEvent(time, teamId) );
178 					}
179 				}
180 				return events;
181 			}
182 			
183 		}
184 	
185     
186  		
187  	    public String toString() {
188             return
189             	super.toString() + "[" +
190             	
191 		              			"Id = " + String.valueOf(getId()
192  	) + " | " + 
193 		              		
194 				"]";           		
195         }
196  	
197  		
198  		public String toHtmlString() {
199  			return super.toString() + "[<br/>" +
200             	
201 		              			"<b>Id</b> = " + String.valueOf(getId()
202  	) + " <br/> " + 
203 		              		
204 				"<br/>]";     
205 		}
206  	
207  		
208  		// --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=all]) ---
209         	
210 		// --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=all]) ---
211 		
212 	    // --- Extra Java from XML BEGIN (extra/code/java/javapart/classcategory[@name=shared+classtype[@name=impl]) ---
213 	        
214 	    // --- Extra Java from XML END (extra/code/java/javapart/classcategory[@name=shared+classtype[@name=impl]) ---        	            	
215  	
216 		}
217