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 FlagInfoCreator implements ICompositeWorldObjectCreator<FlagInfo> {
151
152 @Override
153 public FlagInfo
154 create(ILocalWorldObject localPart, ISharedWorldObject sharedPart, IStaticWorldObject staticPart)
155 {
156 return
157 new
158 FlagInfoCompositeImpl
159 (
160 new
161 FlagInfoLocalImpl
162 ((FlagInfoLocal
163 )localPart
164 ),
165 new
166 FlagInfoSharedImpl
167 (
168 sharedPart.getId(), sharedPart.getProperties().values()
169 ),
170 new
171 FlagInfoStaticImpl
172 ((FlagInfoStatic
173 )staticPart
174 )
175 )
176 ;
177 }
178 }
179
180
181 public static class GameInfoCreator implements ICompositeWorldObjectCreator<GameInfo> {
182
183 @Override
184 public GameInfo
185 create(ILocalWorldObject localPart, ISharedWorldObject sharedPart, IStaticWorldObject staticPart)
186 {
187 return
188 new
189 GameInfoCompositeImpl
190 (
191 new
192 GameInfoLocalImpl
193 ((GameInfoLocal
194 )localPart
195 ),
196 new
197 GameInfoSharedImpl
198 (
199 sharedPart.getId(), sharedPart.getProperties().values()
200 ),
201 new
202 GameInfoStaticImpl
203 ((GameInfoStatic
204 )staticPart
205 )
206 )
207 ;
208 }
209 }
210
211
212 public static class IncomingProjectileCreator implements ICompositeWorldObjectCreator<IncomingProjectile> {
213
214 @Override
215 public IncomingProjectile
216 create(ILocalWorldObject localPart, ISharedWorldObject sharedPart, IStaticWorldObject staticPart)
217 {
218 return
219 new
220 IncomingProjectileCompositeImpl
221 (
222 new
223 IncomingProjectileLocalImpl
224 ((IncomingProjectileLocal
225 )localPart
226 ),
227 new
228 IncomingProjectileSharedImpl
229 (
230 sharedPart.getId(), sharedPart.getProperties().values()
231 ),
232 new
233 IncomingProjectileStaticImpl
234 ((IncomingProjectileStatic
235 )staticPart
236 )
237 )
238 ;
239 }
240 }
241
242
243 public static class InitedMessageCreator implements ICompositeWorldObjectCreator<InitedMessage> {
244
245 @Override
246 public InitedMessage
247 create(ILocalWorldObject localPart, ISharedWorldObject sharedPart, IStaticWorldObject staticPart)
248 {
249 return
250 new
251 InitedMessageCompositeImpl
252 (
253 new
254 InitedMessageLocalImpl
255 ((InitedMessageLocal
256 )localPart
257 ),
258 new
259 InitedMessageSharedImpl
260 (
261 sharedPart.getId(), sharedPart.getProperties().values()
262 ),
263 new
264 InitedMessageStaticImpl
265 ((InitedMessageStatic
266 )staticPart
267 )
268 )
269 ;
270 }
271 }
272
273
274 public static class ItemCreator implements ICompositeWorldObjectCreator<Item> {
275
276 @Override
277 public Item
278 create(ILocalWorldObject localPart, ISharedWorldObject sharedPart, IStaticWorldObject staticPart)
279 {
280 return
281 new
282 ItemCompositeImpl
283 (
284 new
285 ItemLocalImpl
286 ((ItemLocal
287 )localPart
288 ),
289 new
290 ItemSharedImpl
291 (
292 sharedPart.getId(), sharedPart.getProperties().values()
293 ),
294 new
295 ItemStaticImpl
296 ((ItemStatic
297 )staticPart
298 )
299 )
300 ;
301 }
302 }
303
304
305 public static class MoverCreator implements ICompositeWorldObjectCreator<Mover> {
306
307 @Override
308 public Mover
309 create(ILocalWorldObject localPart, ISharedWorldObject sharedPart, IStaticWorldObject staticPart)
310 {
311 return
312 new
313 MoverCompositeImpl
314 (
315 new
316 MoverLocalImpl
317 ((MoverLocal
318 )localPart
319 ),
320 new
321 MoverSharedImpl
322 (
323 sharedPart.getId(), sharedPart.getProperties().values()
324 ),
325 new
326 MoverStaticImpl
327 ((MoverStatic
328 )staticPart
329 )
330 )
331 ;
332 }
333 }
334
335
336 public static class MyInventoryCreator implements ICompositeWorldObjectCreator<MyInventory> {
337
338 @Override
339 public MyInventory
340 create(ILocalWorldObject localPart, ISharedWorldObject sharedPart, IStaticWorldObject staticPart)
341 {
342 return
343 new
344 MyInventoryCompositeImpl
345 (
346 new
347 MyInventoryLocalImpl
348 ((MyInventoryLocal
349 )localPart
350 ),
351 new
352 MyInventorySharedImpl
353 (
354 sharedPart.getId(), sharedPart.getProperties().values()
355 ),
356 new
357 MyInventoryStaticImpl
358 ((MyInventoryStatic
359 )staticPart
360 )
361 )
362 ;
363 }
364 }
365
366
367 public static class NavPointCreator implements ICompositeWorldObjectCreator<NavPoint> {
368
369 @Override
370 public NavPoint
371 create(ILocalWorldObject localPart, ISharedWorldObject sharedPart, IStaticWorldObject staticPart)
372 {
373 return
374 new
375 NavPointCompositeImpl
376 (
377 new
378 NavPointLocalImpl
379 ((NavPointLocal
380 )localPart
381 ),
382 new
383 NavPointSharedImpl
384 (
385 sharedPart.getId(), sharedPart.getProperties().values()
386 ),
387 new
388 NavPointStaticImpl
389 ((NavPointStatic
390 )staticPart
391 )
392 )
393 ;
394 }
395 }
396
397
398 public static class PlayerCreator implements ICompositeWorldObjectCreator<Player> {
399
400 @Override
401 public Player
402 create(ILocalWorldObject localPart, ISharedWorldObject sharedPart, IStaticWorldObject staticPart)
403 {
404 return
405 new
406 PlayerCompositeImpl
407 (
408 new
409 PlayerLocalImpl
410 ((PlayerLocal
411 )localPart
412 ),
413 new
414 PlayerSharedImpl
415 (
416 sharedPart.getId(), sharedPart.getProperties().values()
417 ),
418 new
419 PlayerStaticImpl
420 ((PlayerStatic
421 )staticPart
422 )
423 )
424 ;
425 }
426 }
427
428
429 public static class SelfCreator implements ICompositeWorldObjectCreator<Self> {
430
431 @Override
432 public Self
433 create(ILocalWorldObject localPart, ISharedWorldObject sharedPart, IStaticWorldObject staticPart)
434 {
435 return
436 new
437 SelfCompositeImpl
438 (
439 new
440 SelfLocalImpl
441 ((SelfLocal
442 )localPart
443 ),
444 new
445 SelfSharedImpl
446 (
447 sharedPart.getId(), sharedPart.getProperties().values()
448 ),
449 new
450 SelfStaticImpl
451 ((SelfStatic
452 )staticPart
453 )
454 )
455 ;
456 }
457 }
458
459
460 public static class TeamScoreCreator implements ICompositeWorldObjectCreator<TeamScore> {
461
462 @Override
463 public TeamScore
464 create(ILocalWorldObject localPart, ISharedWorldObject sharedPart, IStaticWorldObject staticPart)
465 {
466 return
467 new
468 TeamScoreCompositeImpl
469 (
470 new
471 TeamScoreLocalImpl
472 ((TeamScoreLocal
473 )localPart
474 ),
475 new
476 TeamScoreSharedImpl
477 (
478 sharedPart.getId(), sharedPart.getProperties().values()
479 ),
480 new
481 TeamScoreStaticImpl
482 ((TeamScoreStatic
483 )staticPart
484 )
485 )
486 ;
487 }
488 }
489
490
491 public static class VehicleCreator implements ICompositeWorldObjectCreator<Vehicle> {
492
493 @Override
494 public Vehicle
495 create(ILocalWorldObject localPart, ISharedWorldObject sharedPart, IStaticWorldObject staticPart)
496 {
497 return
498 new
499 VehicleCompositeImpl
500 (
501 new
502 VehicleLocalImpl
503 ((VehicleLocal
504 )localPart
505 ),
506 new
507 VehicleSharedImpl
508 (
509 sharedPart.getId(), sharedPart.getProperties().values()
510 ),
511 new
512 VehicleStaticImpl
513 ((VehicleStatic
514 )staticPart
515 )
516 )
517 ;
518 }
519 }
520
521
522 private static Map<Class, ICompositeWorldObjectCreator> creators = new HashMap<Class, ICompositeWorldObjectCreator>();
523
524 static {
525
526 creators.put(
527 AliveMessage
528 .class,
529 new AliveMessageCreator());
530
531 creators.put(
532 AutoTraceRay
533 .class,
534 new AutoTraceRayCreator());
535
536 creators.put(
537 BombInfo
538 .class,
539 new BombInfoCreator());
540
541 creators.put(
542 ConfigChange
543 .class,
544 new ConfigChangeCreator());
545
546 creators.put(
547 FlagInfo
548 .class,
549 new FlagInfoCreator());
550
551 creators.put(
552 GameInfo
553 .class,
554 new GameInfoCreator());
555
556 creators.put(
557 IncomingProjectile
558 .class,
559 new IncomingProjectileCreator());
560
561 creators.put(
562 InitedMessage
563 .class,
564 new InitedMessageCreator());
565
566 creators.put(
567 Item
568 .class,
569 new ItemCreator());
570
571 creators.put(
572 Mover
573 .class,
574 new MoverCreator());
575
576 creators.put(
577 MyInventory
578 .class,
579 new MyInventoryCreator());
580
581 creators.put(
582 NavPoint
583 .class,
584 new NavPointCreator());
585
586 creators.put(
587 Player
588 .class,
589 new PlayerCreator());
590
591 creators.put(
592 Self
593 .class,
594 new SelfCreator());
595
596 creators.put(
597 TeamScore
598 .class,
599 new TeamScoreCreator());
600
601 creators.put(
602 Vehicle
603 .class,
604 new VehicleCreator());
605
606 }
607
608
609 public static ICompositeWorldObject createObject(ILocalWorldObject localPart, ISharedWorldObject sharedPart, IStaticWorldObject staticPart)
610 {
611 NullCheck.check(localPart, "localPart");
612 NullCheck.check(sharedPart, "sharedPart");
613 NullCheck.check(staticPart, "staticPart");
614
615 NullCheck.check(localPart.getCompositeClass(), "localPart.getCompositeClass()");
616 NullCheck.check(sharedPart.getCompositeClass(), "sharedPart.getCompositeClass()");
617 NullCheck.check(staticPart.getCompositeClass(), "staticPart.getCompositeClass()");
618
619 if ( localPart.getCompositeClass() != sharedPart.getCompositeClass() || sharedPart.getCompositeClass() != staticPart.getCompositeClass()) {
620 throw new PogamutException("CompositeObject cannot be created, because the objectParts belong to different compositeObject classes : "
621 + localPart.getCompositeClass() + "," + sharedPart.getCompositeClass() + "," + staticPart.getCompositeClass() , localPart);
622 }
623
624 ICompositeWorldObjectCreator creator = creators.get(localPart.getCompositeClass());
625 if (creator == null) {
626 throw new PogamutException("There is no ICompositeWorldObjectCreator registered for class " + localPart.getCompositeClass(), UT2004CompositeObjectCreator.class);
627 }
628
629 return creator.create(localPart, sharedPart, staticPart);
630 }
631 }
632