1 package cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages;
2
3
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
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 public class EntitySharedImpl
28 extends
29 EntityShared
30 {
31
32
33
34 public EntitySharedImpl(EntitySharedImpl source) {
35
36 this.Id = source.
37 getId()
38 ;
39
40 this.myLocation = source.myLocation;
41
42 this.myRotation = source.myRotation;
43
44 this.myVelocity = source.myVelocity;
45
46 }
47
48 public EntitySharedImpl(WorldObjectId objectId, Collection<ISharedProperty> properties) {
49 this.Id = (UnrealId)objectId;
50 NullCheck.check(this.Id, "objectId");
51
52 if (properties.size() != 3) {
53 throw new PogamutException("Not enough properties passed to the constructor.", EntitySharedImpl.class);
54 }
55
56
57 for ( ISharedProperty property : properties ) {
58 PropertyId pId = property.getPropertyId();
59 if ( !objectId.equals( property.getObjectId() )) {
60
61 throw new PogamutException("Trying to create a EntitySharedImpl with different WorldObjectId properties : " +
62 this.Id.getStringId() + " / " + property.getObjectId().getStringId() , this);
63 }
64 if (!EntityShared.SharedPropertyTokens.contains(pId.getPropertyToken())) {
65
66 throw new PogamutException("Trying to create a EntitySharedImpl with invalid property (invalid property token): " +
67 this.Id.getStringId() + " / " + property.getPropertyId().getPropertyToken().getToken() , this);
68 }
69 propertyMap.put(property.getPropertyId(), property);
70
71
72 if (pId.getPropertyToken().getToken().equals("Location"))
73 {
74 this.myLocation = (LocationProperty)property;
75 }
76
77 if (pId.getPropertyToken().getToken().equals("Rotation"))
78 {
79 this.myRotation = (RotationProperty)property;
80 }
81
82 if (pId.getPropertyToken().getToken().equals("Velocity"))
83 {
84 this.myVelocity = (VelocityProperty)property;
85 }
86
87 }
88 }
89
90
91 @Override
92 public void setSimTime(long SimTime) {
93 super.setSimTime(SimTime);
94 }
95
96 @Override
97 public
98 EntitySharedImpl clone() {
99 return new
100 EntitySharedImpl(this);
101 }
102
103
104
105
106
107 protected HashMap<PropertyId, ISharedProperty> propertyMap = new HashMap<PropertyId, ISharedProperty>(
108 3
109 );
110
111 @Override
112 public ISharedProperty getProperty(PropertyId id) {
113 return propertyMap.get(id);
114 }
115
116 @Override
117 public Map<PropertyId, ISharedProperty> getProperties() {
118 return propertyMap;
119 }
120
121
122
123
124
125
126
127
128
129 protected
130 UnrealId Id =
131 null;
132
133
134
135
136
137
138 public UnrealId getId()
139 {
140 return Id;
141 }
142
143
144
145
146
147 protected
148 LocationProperty
149 myLocation
150 = null;
151
152
153
154
155
156 public Location getLocation()
157 {
158 return myLocation.getValue();
159 }
160
161
162
163
164
165 protected
166 RotationProperty
167 myRotation
168 = null;
169
170
171
172
173
174 public Rotation getRotation()
175 {
176 return myRotation.getValue();
177 }
178
179
180
181
182
183 protected
184 VelocityProperty
185 myVelocity
186 = null;
187
188
189
190
191
192 public Velocity getVelocity()
193 {
194 return myVelocity.getValue();
195 }
196
197
198
199 public static class EntitySharedUpdate
200 implements ISharedWorldObjectUpdatedEvent
201 {
202
203 private EntityShared object;
204 private long time;
205 private ITeamId teamId;
206
207 public EntitySharedUpdate
208 (EntityShared data, long time, ITeamId teamId)
209 {
210 this.object = data;
211 this.time = time;
212 this.teamId = teamId;
213 }
214
215
216
217
218 @Override
219 public long getSimTime() {
220 return this.time;
221 }
222
223 @Override
224 public WorldObjectId getId() {
225 return object.getId();
226 }
227
228 @Override
229 public ITeamId getTeamId() {
230 return teamId;
231 }
232
233 @Override
234 public Class getCompositeObjectClass()
235 {
236 return object.getCompositeClass();
237 }
238
239 @Override
240 public Collection<ISharedPropertyUpdatedEvent> getPropertyEvents() {
241 LinkedList<ISharedPropertyUpdatedEvent> events = new LinkedList<ISharedPropertyUpdatedEvent>();
242
243 for ( ISharedProperty property : object.getProperties().values() )
244 {
245 if ( property != null)
246 {
247 events.push( property.createUpdateEvent(time, teamId) );
248 }
249 }
250 return events;
251 }
252
253 }
254
255
256
257 public String toString() {
258 return
259 super.toString() + "[" +
260
261 "Id = " + String.valueOf(getId()
262 ) + " | " +
263
264 "Location = " + String.valueOf(getLocation()
265 ) + " | " +
266
267 "Rotation = " + String.valueOf(getRotation()
268 ) + " | " +
269
270 "Velocity = " + String.valueOf(getVelocity()
271 ) + " | " +
272
273 "]";
274 }
275
276
277 public String toHtmlString() {
278 return super.toString() + "[<br/>" +
279
280 "<b>Id</b> = " + String.valueOf(getId()
281 ) + " <br/> " +
282
283 "<b>Location</b> = " + String.valueOf(getLocation()
284 ) + " <br/> " +
285
286 "<b>Rotation</b> = " + String.valueOf(getRotation()
287 ) + " <br/> " +
288
289 "<b>Velocity</b> = " + String.valueOf(getVelocity()
290 ) + " <br/> " +
291
292 "<br/>]";
293 }
294
295
296
297
298
299
300
301
302
303
304 }
305