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