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
28
29
30 public class VehicleSharedImpl
31 extends
32 VehicleShared
33 {
34
35
36
37 public VehicleSharedImpl(VehicleSharedImpl source) {
38
39 this.Id = source.
40 getId()
41 ;
42
43 this.myRotation = source.myRotation;
44
45 this.myLocation = source.myLocation;
46
47 this.myVelocity = source.myVelocity;
48
49 this.myTeam = source.myTeam;
50
51 this.myHealth = source.myHealth;
52
53 this.myArmor = source.myArmor;
54
55 this.myDriver = source.myDriver;
56
57 this.myTeamLocked = source.myTeamLocked;
58
59 }
60
61 public VehicleSharedImpl(WorldObjectId objectId, Collection<ISharedProperty> properties) {
62 this.Id = (UnrealId)objectId;
63 NullCheck.check(this.Id, "objectId");
64
65 if (properties.size() != 8) {
66 throw new PogamutException("Not enough properties passed to the constructor.", VehicleSharedImpl.class);
67 }
68
69
70 for ( ISharedProperty property : properties ) {
71 PropertyId pId = property.getPropertyId();
72 if ( !objectId.equals( property.getObjectId() )) {
73
74 throw new PogamutException("Trying to create a VehicleSharedImpl with different WorldObjectId properties : " +
75 this.Id.getStringId() + " / " + property.getObjectId().getStringId() , this);
76 }
77 if (!VehicleShared.SharedPropertyTokens.contains(pId.getPropertyToken())) {
78
79 throw new PogamutException("Trying to create a VehicleSharedImpl with invalid property (invalid property token): " +
80 this.Id.getStringId() + " / " + property.getPropertyId().getPropertyToken().getToken() , this);
81 }
82 propertyMap.put(property.getPropertyId(), property);
83
84
85 if (pId.getPropertyToken().getToken().equals("Rotation"))
86 {
87 this.myRotation = (RotationProperty)property;
88 }
89
90 if (pId.getPropertyToken().getToken().equals("Location"))
91 {
92 this.myLocation = (LocationProperty)property;
93 }
94
95 if (pId.getPropertyToken().getToken().equals("Velocity"))
96 {
97 this.myVelocity = (VelocityProperty)property;
98 }
99
100 if (pId.getPropertyToken().getToken().equals("Team"))
101 {
102 this.myTeam = (IntegerProperty)property;
103 }
104
105 if (pId.getPropertyToken().getToken().equals("Health"))
106 {
107 this.myHealth = (IntegerProperty)property;
108 }
109
110 if (pId.getPropertyToken().getToken().equals("Armor"))
111 {
112 this.myArmor = (IntegerProperty)property;
113 }
114
115 if (pId.getPropertyToken().getToken().equals("Driver"))
116 {
117 this.myDriver = (UnrealIdProperty)property;
118 }
119
120 if (pId.getPropertyToken().getToken().equals("TeamLocked"))
121 {
122 this.myTeamLocked = (BooleanProperty)property;
123 }
124
125 }
126 }
127
128
129 @Override
130 public void setSimTime(long SimTime) {
131 super.setSimTime(SimTime);
132 }
133
134 @Override
135 public
136 VehicleSharedImpl clone() {
137 return new
138 VehicleSharedImpl(this);
139 }
140
141
142
143
144
145 protected HashMap<PropertyId, ISharedProperty> propertyMap = new HashMap<PropertyId, ISharedProperty>(
146 8
147 );
148
149 @Override
150 public ISharedProperty getProperty(PropertyId id) {
151 return propertyMap.get(id);
152 }
153
154 @Override
155 public Map<PropertyId, ISharedProperty> getProperties() {
156 return propertyMap;
157 }
158
159
160
161
162
163
164
165 protected
166 UnrealId Id =
167 null;
168
169
170
171
172 public UnrealId getId()
173 {
174 return Id;
175 }
176
177
178
179
180
181
182
183 protected
184 RotationProperty
185 myRotation
186 = null;
187
188
189
190
191
192
193
194 public Rotation getRotation()
195 {
196 return myRotation.getValue();
197 }
198
199
200
201
202
203
204
205 protected
206 LocationProperty
207 myLocation
208 = null;
209
210
211
212
213
214
215
216 public Location getLocation()
217 {
218 return myLocation.getValue();
219 }
220
221
222
223
224
225
226
227
228 protected
229 VelocityProperty
230 myVelocity
231 = null;
232
233
234
235
236
237
238
239
240 public Velocity getVelocity()
241 {
242 return myVelocity.getValue();
243 }
244
245
246
247
248
249
250
251
252 protected
253 IntegerProperty
254 myTeam
255 = null;
256
257
258
259
260
261
262
263
264 public Integer getTeam()
265 {
266 return myTeam.getValue();
267 }
268
269
270
271
272
273
274
275 protected
276 IntegerProperty
277 myHealth
278 = null;
279
280
281
282
283
284
285
286 public Integer getHealth()
287 {
288 return myHealth.getValue();
289 }
290
291
292
293
294
295
296
297 protected
298 IntegerProperty
299 myArmor
300 = null;
301
302
303
304
305
306
307
308 public Integer getArmor()
309 {
310 return myArmor.getValue();
311 }
312
313
314
315
316
317 protected
318 UnrealIdProperty
319 myDriver
320 = null;
321
322
323
324
325
326 public UnrealId getDriver()
327 {
328 return myDriver.getValue();
329 }
330
331
332
333
334
335
336
337 protected
338 BooleanProperty
339 myTeamLocked
340 = null;
341
342
343
344
345
346
347
348 public boolean isTeamLocked()
349 {
350 return myTeamLocked.getValue();
351 }
352
353
354
355 public static class VehicleSharedUpdate
356 implements ISharedWorldObjectUpdatedEvent
357 {
358
359 private VehicleShared object;
360 private long time;
361 private ITeamId teamId;
362
363 public VehicleSharedUpdate
364 (VehicleShared data, long time, ITeamId teamId)
365 {
366 this.object = data;
367 this.time = time;
368 this.teamId = teamId;
369 }
370
371
372
373
374 @Override
375 public long getSimTime() {
376 return this.time;
377 }
378
379 @Override
380 public WorldObjectId getId() {
381 return object.getId();
382 }
383
384 @Override
385 public ITeamId getTeamId() {
386 return teamId;
387 }
388
389 @Override
390 public Class getCompositeObjectClass()
391 {
392 return object.getCompositeClass();
393 }
394
395 @Override
396 public Collection<ISharedPropertyUpdatedEvent> getPropertyEvents() {
397 LinkedList<ISharedPropertyUpdatedEvent> events = new LinkedList<ISharedPropertyUpdatedEvent>();
398
399 for ( ISharedProperty property : object.getProperties().values() )
400 {
401 if ( property != null)
402 {
403 events.push( property.createUpdateEvent(time, teamId) );
404 }
405 }
406 return events;
407 }
408
409 }
410
411
412
413 public String toString() {
414 return
415 super.toString() + "[" +
416
417 "Id = " + String.valueOf(getId()
418 ) + " | " +
419
420 "Rotation = " + String.valueOf(getRotation()
421 ) + " | " +
422
423 "Location = " + String.valueOf(getLocation()
424 ) + " | " +
425
426 "Velocity = " + String.valueOf(getVelocity()
427 ) + " | " +
428
429 "Team = " + String.valueOf(getTeam()
430 ) + " | " +
431
432 "Health = " + String.valueOf(getHealth()
433 ) + " | " +
434
435 "Armor = " + String.valueOf(getArmor()
436 ) + " | " +
437
438 "Driver = " + String.valueOf(getDriver()
439 ) + " | " +
440
441 "TeamLocked = " + String.valueOf(isTeamLocked()
442 ) + " | " +
443
444 "]";
445 }
446
447
448 public String toHtmlString() {
449 return super.toString() + "[<br/>" +
450
451 "<b>Id</b> = " + String.valueOf(getId()
452 ) + " <br/> " +
453
454 "<b>Rotation</b> = " + String.valueOf(getRotation()
455 ) + " <br/> " +
456
457 "<b>Location</b> = " + String.valueOf(getLocation()
458 ) + " <br/> " +
459
460 "<b>Velocity</b> = " + String.valueOf(getVelocity()
461 ) + " <br/> " +
462
463 "<b>Team</b> = " + String.valueOf(getTeam()
464 ) + " <br/> " +
465
466 "<b>Health</b> = " + String.valueOf(getHealth()
467 ) + " <br/> " +
468
469 "<b>Armor</b> = " + String.valueOf(getArmor()
470 ) + " <br/> " +
471
472 "<b>Driver</b> = " + String.valueOf(getDriver()
473 ) + " <br/> " +
474
475 "<b>TeamLocked</b> = " + String.valueOf(isTeamLocked()
476 ) + " <br/> " +
477
478 "<br/>]";
479 }
480
481
482
483
484
485
486
487
488
489
490 }
491