1
2
3
4
5
6
7
8
9
10
11
12
13 package cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages;
14
15 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.*;
16
17 public class UT2004CompositeObjectCreator {
18
19 public static interface ICompositeWorldObjectCreator<T extends ICompositeWorldObject> {
20
21 public T create(ILocalWorldObject localPart, ISharedWorldObject sharedPart, IStaticWorldObject staticPart);
22
23 }
24
25
26 public static class AliveMessageCreator implements ICompositeWorldObjectCreator<AliveMessage> {
27
28 @Override
29 public AliveMessage
30 create(ILocalWorldObject localPart, ISharedWorldObject sharedPart, IStaticWorldObject staticPart)
31 {
32 return
33 new
34 AliveMessageCompositeImpl
35 (
36 new
37 AliveMessageLocalImpl
38 ((AliveMessageLocal
39 )localPart
40 ),
41 new
42 AliveMessageSharedImpl
43 (
44 sharedPart.getId(), sharedPart.getProperties().values()
45 ),
46 new
47 AliveMessageStaticImpl
48 ((AliveMessageStatic
49 )staticPart
50 )
51 )
52 ;
53 }
54 }
55
56
57 public static class AutoTraceRayCreator implements ICompositeWorldObjectCreator<AutoTraceRay> {
58
59 @Override
60 public AutoTraceRay
61 create(ILocalWorldObject localPart, ISharedWorldObject sharedPart, IStaticWorldObject staticPart)
62 {
63 return
64 new
65 AutoTraceRayCompositeImpl
66 (
67 new
68 AutoTraceRayLocalImpl
69 ((AutoTraceRayLocal
70 )localPart
71 ),
72 new
73 AutoTraceRaySharedImpl
74 (
75 sharedPart.getId(), sharedPart.getProperties().values()
76 ),
77 new
78 AutoTraceRayStaticImpl
79 ((AutoTraceRayStatic
80 )staticPart
81 )
82 )
83 ;
84 }
85 }
86
87
88 public static class BombInfoCreator implements ICompositeWorldObjectCreator<BombInfo> {
89
90 @Override
91 public BombInfo
92 create(ILocalWorldObject localPart, ISharedWorldObject sharedPart, IStaticWorldObject staticPart)
93 {
94 return
95 new
96 BombInfoCompositeImpl
97 (
98 new
99 BombInfoLocalImpl
100 ((BombInfoLocal
101 )localPart
102 ),
103 new
104 BombInfoSharedImpl
105 (
106 sharedPart.getId(), sharedPart.getProperties().values()
107 ),
108 new
109 BombInfoStaticImpl
110 ((BombInfoStatic
111 )staticPart
112 )
113 )
114 ;
115 }
116 }
117
118
119 public static class ConfigChangeCreator implements ICompositeWorldObjectCreator<ConfigChange> {
120
121 @Override
122 public ConfigChange
123 create(ILocalWorldObject localPart, ISharedWorldObject sharedPart, IStaticWorldObject staticPart)
124 {
125 return
126 new
127 ConfigChangeCompositeImpl
128 (
129 new
130 ConfigChangeLocalImpl
131 ((ConfigChangeLocal
132 )localPart
133 ),
134 new
135 ConfigChangeSharedImpl
136 (
137 sharedPart.getId(), sharedPart.getProperties().values()
138 ),
139 new
140 ConfigChangeStaticImpl
141 ((ConfigChangeStatic
142 )staticPart
143 )
144 )
145 ;
146 }
147 }
148
149
150 public static class EntityCreator implements ICompositeWorldObjectCreator<Entity> {
151
152 @Override
153 public Entity
154 create(ILocalWorldObject localPart, ISharedWorldObject sharedPart, IStaticWorldObject staticPart)
155 {
156 return
157 new
158 EntityCompositeImpl
159 (
160 new
161 EntityLocalImpl
162 ((EntityLocal
163 )localPart
164 ),
165 new
166 EntitySharedImpl
167 (
168 sharedPart.getId(), sharedPart.getProperties().values()
169 ),
170 new
171 EntityStaticImpl
172 ((EntityStatic
173 )staticPart
174 )
175 )
176 ;
177 }
178 }
179
180
181 public static class FlagInfoCreator implements ICompositeWorldObjectCreator<FlagInfo> {
182
183 @Override
184 public FlagInfo
185 create(ILocalWorldObject localPart, ISharedWorldObject sharedPart, IStaticWorldObject staticPart)
186 {
187 return
188 new
189 FlagInfoCompositeImpl
190 (
191 new
192 FlagInfoLocalImpl
193 ((FlagInfoLocal
194 )localPart
195 ),
196 new
197 FlagInfoSharedImpl
198 (
199 sharedPart.getId(), sharedPart.getProperties().values()
200 ),
201 new
202 FlagInfoStaticImpl
203 ((FlagInfoStatic
204 )staticPart
205 )
206 )
207 ;
208 }
209 }
210
211
212 public static class GameInfoCreator implements ICompositeWorldObjectCreator<GameInfo> {
213
214 @Override
215 public GameInfo
216 create(ILocalWorldObject localPart, ISharedWorldObject sharedPart, IStaticWorldObject staticPart)
217 {
218 return
219 new
220 GameInfoCompositeImpl
221 (
222 new
223 GameInfoLocalImpl
224 ((GameInfoLocal
225 )localPart
226 ),
227 new
228 GameInfoSharedImpl
229 (
230 sharedPart.getId(), sharedPart.getProperties().values()
231 ),
232 new
233 GameInfoStaticImpl
234 ((GameInfoStatic
235 )staticPart
236 )
237 )
238 ;
239 }
240 }
241
242
243 public static class IncomingProjectileCreator implements ICompositeWorldObjectCreator<IncomingProjectile> {
244
245 @Override
246 public IncomingProjectile
247 create(ILocalWorldObject localPart, ISharedWorldObject sharedPart, IStaticWorldObject staticPart)
248 {
249 return
250 new
251 IncomingProjectileCompositeImpl
252 (
253 new
254 IncomingProjectileLocalImpl
255 ((IncomingProjectileLocal
256 )localPart
257 ),
258 new
259 IncomingProjectileSharedImpl
260 (
261 sharedPart.getId(), sharedPart.getProperties().values()
262 ),
263 new
264 IncomingProjectileStaticImpl
265 ((IncomingProjectileStatic
266 )staticPart
267 )
268 )
269 ;
270 }
271 }
272
273
274 public static class InitedMessageCreator implements ICompositeWorldObjectCreator<InitedMessage> {
275
276 @Override
277 public InitedMessage
278 create(ILocalWorldObject localPart, ISharedWorldObject sharedPart, IStaticWorldObject staticPart)
279 {
280 return
281 new
282 InitedMessageCompositeImpl
283 (
284 new
285 InitedMessageLocalImpl
286 ((InitedMessageLocal
287 )localPart
288 ),
289 new
290 InitedMessageSharedImpl
291 (
292 sharedPart.getId(), sharedPart.getProperties().values()
293 ),
294 new
295 InitedMessageStaticImpl
296 ((InitedMessageStatic
297 )staticPart
298 )
299 )
300 ;
301 }
302 }
303
304
305 public static class ItemCreator implements ICompositeWorldObjectCreator<Item> {
306
307 @Override
308 public Item
309 create(ILocalWorldObject localPart, ISharedWorldObject sharedPart, IStaticWorldObject staticPart)
310 {
311 return
312 new
313 ItemCompositeImpl
314 (
315 new
316 ItemLocalImpl
317 ((ItemLocal
318 )localPart
319 ),
320 new
321 ItemSharedImpl
322 (
323 sharedPart.getId(), sharedPart.getProperties().values()
324 ),
325 new
326 ItemStaticImpl
327 ((ItemStatic
328 )staticPart
329 )
330 )
331 ;
332 }
333 }
334
335
336 public static class MoverCreator implements ICompositeWorldObjectCreator<Mover> {
337
338 @Override
339 public Mover
340 create(ILocalWorldObject localPart, ISharedWorldObject sharedPart, IStaticWorldObject staticPart)
341 {
342 return
343 new
344 MoverCompositeImpl
345 (
346 new
347 MoverLocalImpl
348 ((MoverLocal
349 )localPart
350 ),
351 new
352 MoverSharedImpl
353 (
354 sharedPart.getId(), sharedPart.getProperties().values()
355 ),
356 new
357 MoverStaticImpl
358 ((MoverStatic
359 )staticPart
360 )
361 )
362 ;
363 }
364 }
365
366
367 public static class MyInventoryCreator implements ICompositeWorldObjectCreator<MyInventory> {
368
369 @Override
370 public MyInventory
371 create(ILocalWorldObject localPart, ISharedWorldObject sharedPart, IStaticWorldObject staticPart)
372 {
373 return
374 new
375 MyInventoryCompositeImpl
376 (
377 new
378 MyInventoryLocalImpl
379 ((MyInventoryLocal
380 )localPart
381 ),
382 new
383 MyInventorySharedImpl
384 (
385 sharedPart.getId(), sharedPart.getProperties().values()
386 ),
387 new
388 MyInventoryStaticImpl
389 ((MyInventoryStatic
390 )staticPart
391 )
392 )
393 ;
394 }
395 }
396
397
398 public static class NavPointCreator implements ICompositeWorldObjectCreator<NavPoint> {
399
400 @Override
401 public NavPoint
402 create(ILocalWorldObject localPart, ISharedWorldObject sharedPart, IStaticWorldObject staticPart)
403 {
404 return
405 new
406 NavPointCompositeImpl
407 (
408 new
409 NavPointLocalImpl
410 ((NavPointLocal
411 )localPart
412 ),
413 new
414 NavPointSharedImpl
415 (
416 sharedPart.getId(), sharedPart.getProperties().values()
417 ),
418 new
419 NavPointStaticImpl
420 ((NavPointStatic
421 )staticPart
422 )
423 )
424 ;
425 }
426 }
427
428
429 public static class PlayerCreator implements ICompositeWorldObjectCreator<Player> {
430
431 @Override
432 public Player
433 create(ILocalWorldObject localPart, ISharedWorldObject sharedPart, IStaticWorldObject staticPart)
434 {
435 return
436 new
437 PlayerCompositeImpl
438 (
439 new
440 PlayerLocalImpl
441 ((PlayerLocal
442 )localPart
443 ),
444 new
445 PlayerSharedImpl
446 (
447 sharedPart.getId(), sharedPart.getProperties().values()
448 ),
449 new
450 PlayerStaticImpl
451 ((PlayerStatic
452 )staticPart
453 )
454 )
455 ;
456 }
457 }
458
459
460 public static class SelfCreator implements ICompositeWorldObjectCreator<Self> {
461
462 @Override
463 public Self
464 create(ILocalWorldObject localPart, ISharedWorldObject sharedPart, IStaticWorldObject staticPart)
465 {
466 return
467 new
468 SelfCompositeImpl
469 (
470 new
471 SelfLocalImpl
472 ((SelfLocal
473 )localPart
474 ),
475 new
476 SelfSharedImpl
477 (
478 sharedPart.getId(), sharedPart.getProperties().values()
479 ),
480 new
481 SelfStaticImpl
482 ((SelfStatic
483 )staticPart
484 )
485 )
486 ;
487 }
488 }
489
490
491 public static class TeamScoreCreator implements ICompositeWorldObjectCreator<TeamScore> {
492
493 @Override
494 public TeamScore
495 create(ILocalWorldObject localPart, ISharedWorldObject sharedPart, IStaticWorldObject staticPart)
496 {
497 return
498 new
499 TeamScoreCompositeImpl
500 (
501 new
502 TeamScoreLocalImpl
503 ((TeamScoreLocal
504 )localPart
505 ),
506 new
507 TeamScoreSharedImpl
508 (
509 sharedPart.getId(), sharedPart.getProperties().values()
510 ),
511 new
512 TeamScoreStaticImpl
513 ((TeamScoreStatic
514 )staticPart
515 )
516 )
517 ;
518 }
519 }
520
521
522 public static class VehicleCreator implements ICompositeWorldObjectCreator<Vehicle> {
523
524 @Override
525 public Vehicle
526 create(ILocalWorldObject localPart, ISharedWorldObject sharedPart, IStaticWorldObject staticPart)
527 {
528 return
529 new
530 VehicleCompositeImpl
531 (
532 new
533 VehicleLocalImpl
534 ((VehicleLocal
535 )localPart
536 ),
537 new
538 VehicleSharedImpl
539 (
540 sharedPart.getId(), sharedPart.getProperties().values()
541 ),
542 new
543 VehicleStaticImpl
544 ((VehicleStatic
545 )staticPart
546 )
547 )
548 ;
549 }
550 }
551
552
553 private static Map<Class, ICompositeWorldObjectCreator> creators = new HashMap<Class, ICompositeWorldObjectCreator>();
554
555 static {
556
557 creators.put(
558 AliveMessage
559 .class,
560 new AliveMessageCreator());
561
562 creators.put(
563 AutoTraceRay
564 .class,
565 new AutoTraceRayCreator());
566
567 creators.put(
568 BombInfo
569 .class,
570 new BombInfoCreator());
571
572 creators.put(
573 ConfigChange
574 .class,
575 new ConfigChangeCreator());
576
577 creators.put(
578 Entity
579 .class,
580 new EntityCreator());
581
582 creators.put(
583 FlagInfo
584 .class,
585 new FlagInfoCreator());
586
587 creators.put(
588 GameInfo
589 .class,
590 new GameInfoCreator());
591
592 creators.put(
593 IncomingProjectile
594 .class,
595 new IncomingProjectileCreator());
596
597 creators.put(
598 InitedMessage
599 .class,
600 new InitedMessageCreator());
601
602 creators.put(
603 Item
604 .class,
605 new ItemCreator());
606
607 creators.put(
608 Mover
609 .class,
610 new MoverCreator());
611
612 creators.put(
613 MyInventory
614 .class,
615 new MyInventoryCreator());
616
617 creators.put(
618 NavPoint
619 .class,
620 new NavPointCreator());
621
622 creators.put(
623 Player
624 .class,
625 new PlayerCreator());
626
627 creators.put(
628 Self
629 .class,
630 new SelfCreator());
631
632 creators.put(
633 TeamScore
634 .class,
635 new TeamScoreCreator());
636
637 creators.put(
638 Vehicle
639 .class,
640 new VehicleCreator());
641
642 }
643
644
645 public static ICompositeWorldObject createObject(ILocalWorldObject localPart, ISharedWorldObject sharedPart, IStaticWorldObject staticPart)
646 {
647 NullCheck.check(localPart, "localPart");
648 NullCheck.check(sharedPart, "sharedPart");
649 NullCheck.check(staticPart, "staticPart");
650
651 NullCheck.check(localPart.getCompositeClass(), "localPart.getCompositeClass()");
652 NullCheck.check(sharedPart.getCompositeClass(), "sharedPart.getCompositeClass()");
653 NullCheck.check(staticPart.getCompositeClass(), "staticPart.getCompositeClass()");
654
655 if ( localPart.getCompositeClass() != sharedPart.getCompositeClass() || sharedPart.getCompositeClass() != staticPart.getCompositeClass()) {
656 throw new PogamutException("CompositeObject cannot be created, because the objectParts belong to different compositeObject classes : "
657 + localPart.getCompositeClass() + "," + sharedPart.getCompositeClass() + "," + staticPart.getCompositeClass() , localPart);
658 }
659
660 ICompositeWorldObjectCreator creator = creators.get(localPart.getCompositeClass());
661 if (creator == null) {
662 throw new PogamutException("There is no ICompositeWorldObjectCreator registered for class " + localPart.getCompositeClass(), UT2004CompositeObjectCreator.class);
663 }
664
665 return creator.create(localPart, sharedPart, staticPart);
666 }
667 }
668