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 NavPointSharedImpl
28 extends
29 NavPointShared
30 {
31
32
33
34 public NavPointSharedImpl(NavPointSharedImpl source) {
35
36 this.Id = source.
37 getId()
38 ;
39
40 this.myLocation = source.myLocation;
41
42 this.myVelocity = source.myVelocity;
43
44 this.myItemSpawned = source.myItemSpawned;
45
46 this.myDoorOpened = source.myDoorOpened;
47
48 this.myDomPointController = source.myDomPointController;
49
50 }
51
52 public NavPointSharedImpl(WorldObjectId objectId, Collection<ISharedProperty> properties) {
53 this.Id = (UnrealId)objectId;
54 NullCheck.check(this.Id, "objectId");
55
56 if (properties.size() != 5) {
57 throw new PogamutException("Not enough properties passed to the constructor.", NavPointSharedImpl.class);
58 }
59
60
61 for ( ISharedProperty property : properties ) {
62 PropertyId pId = property.getPropertyId();
63 if ( !objectId.equals( property.getObjectId() )) {
64
65 throw new PogamutException("Trying to create a NavPointSharedImpl with different WorldObjectId properties : " +
66 this.Id.getStringId() + " / " + property.getObjectId().getStringId() , this);
67 }
68 if (!NavPointShared.SharedPropertyTokens.contains(pId.getPropertyToken())) {
69
70 throw new PogamutException("Trying to create a NavPointSharedImpl with invalid property (invalid property token): " +
71 this.Id.getStringId() + " / " + property.getPropertyId().getPropertyToken().getToken() , this);
72 }
73 propertyMap.put(property.getPropertyId(), property);
74
75
76 if (pId.getPropertyToken().getToken().equals("Location"))
77 {
78 this.myLocation = (LocationProperty)property;
79 }
80
81 if (pId.getPropertyToken().getToken().equals("Velocity"))
82 {
83 this.myVelocity = (VelocityProperty)property;
84 }
85
86 if (pId.getPropertyToken().getToken().equals("ItemSpawned"))
87 {
88 this.myItemSpawned = (BooleanProperty)property;
89 }
90
91 if (pId.getPropertyToken().getToken().equals("DoorOpened"))
92 {
93 this.myDoorOpened = (BooleanProperty)property;
94 }
95
96 if (pId.getPropertyToken().getToken().equals("DomPointController"))
97 {
98 this.myDomPointController = (IntProperty)property;
99 }
100
101 }
102 }
103
104
105 @Override
106 public void setSimTime(long SimTime) {
107 super.setSimTime(SimTime);
108 }
109
110 @Override
111 public
112 NavPointSharedImpl clone() {
113 return new
114 NavPointSharedImpl(this);
115 }
116
117
118
119
120
121 protected HashMap<PropertyId, ISharedProperty> propertyMap = new HashMap<PropertyId, ISharedProperty>(
122 5
123 );
124
125 @Override
126 public ISharedProperty getProperty(PropertyId id) {
127 return propertyMap.get(id);
128 }
129
130 @Override
131 public Map<PropertyId, ISharedProperty> getProperties() {
132 return propertyMap;
133 }
134
135
136
137
138
139
140
141
142
143 protected
144 UnrealId Id =
145 null;
146
147
148
149
150
151
152 public UnrealId getId()
153 {
154 return Id;
155 }
156
157
158
159
160
161 protected
162 LocationProperty
163 myLocation
164 = null;
165
166
167
168
169
170 public Location getLocation()
171 {
172 return myLocation.getValue();
173 }
174
175
176
177
178
179
180
181
182 protected
183 VelocityProperty
184 myVelocity
185 = null;
186
187
188
189
190
191
192
193
194 public Velocity getVelocity()
195 {
196 return myVelocity.getValue();
197 }
198
199
200
201
202
203
204
205 protected
206 BooleanProperty
207 myItemSpawned
208 = null;
209
210
211
212
213
214
215
216 public boolean isItemSpawned()
217 {
218 return myItemSpawned.getValue();
219 }
220
221
222
223
224
225
226
227 protected
228 BooleanProperty
229 myDoorOpened
230 = null;
231
232
233
234
235
236
237
238 public boolean isDoorOpened()
239 {
240 return myDoorOpened.getValue();
241 }
242
243
244
245
246
247 protected
248 IntProperty
249 myDomPointController
250 = null;
251
252
253
254
255
256 public int getDomPointController()
257 {
258 return myDomPointController.getValue();
259 }
260
261
262
263 public static class NavPointSharedUpdate
264 implements ISharedWorldObjectUpdatedEvent
265 {
266
267 private NavPointShared object;
268 private long time;
269 private ITeamId teamId;
270
271 public NavPointSharedUpdate
272 (NavPointShared data, long time, ITeamId teamId)
273 {
274 this.object = data;
275 this.time = time;
276 this.teamId = teamId;
277 }
278
279
280
281
282 @Override
283 public long getSimTime() {
284 return this.time;
285 }
286
287 @Override
288 public WorldObjectId getId() {
289 return object.getId();
290 }
291
292 @Override
293 public ITeamId getTeamId() {
294 return teamId;
295 }
296
297 @Override
298 public Class getCompositeObjectClass()
299 {
300 return object.getCompositeClass();
301 }
302
303 @Override
304 public Collection<ISharedPropertyUpdatedEvent> getPropertyEvents() {
305 LinkedList<ISharedPropertyUpdatedEvent> events = new LinkedList<ISharedPropertyUpdatedEvent>();
306
307 for ( ISharedProperty property : object.getProperties().values() )
308 {
309 if ( property != null)
310 {
311 events.push( property.createUpdateEvent(time, teamId) );
312 }
313 }
314 return events;
315 }
316
317 }
318
319
320
321 public String toString() {
322 return
323 super.toString() + "[" +
324
325 "Id = " + String.valueOf(getId()
326 ) + " | " +
327
328 "Location = " + String.valueOf(getLocation()
329 ) + " | " +
330
331 "Velocity = " + String.valueOf(getVelocity()
332 ) + " | " +
333
334 "ItemSpawned = " + String.valueOf(isItemSpawned()
335 ) + " | " +
336
337 "DoorOpened = " + String.valueOf(isDoorOpened()
338 ) + " | " +
339
340 "DomPointController = " + String.valueOf(getDomPointController()
341 ) + " | " +
342
343 "]";
344 }
345
346
347 public String toHtmlString() {
348 return super.toString() + "[<br/>" +
349
350 "<b>Id</b> = " + String.valueOf(getId()
351 ) + " <br/> " +
352
353 "<b>Location</b> = " + String.valueOf(getLocation()
354 ) + " <br/> " +
355
356 "<b>Velocity</b> = " + String.valueOf(getVelocity()
357 ) + " <br/> " +
358
359 "<b>ItemSpawned</b> = " + String.valueOf(isItemSpawned()
360 ) + " <br/> " +
361
362 "<b>DoorOpened</b> = " + String.valueOf(isDoorOpened()
363 ) + " <br/> " +
364
365 "<b>DomPointController</b> = " + String.valueOf(getDomPointController()
366 ) + " <br/> " +
367
368 "<br/>]";
369 }
370
371
372
373
374
375
376
377
378
379
380 }
381