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