1 package cz.cuni.amis.pogamut.ut2004.factory.guice.remoteagent;
2
3 import com.google.inject.AbstractModule;
4 import com.google.inject.Provider;
5 import com.google.inject.name.Names;
6
7 import cz.cuni.amis.pogamut.base.agent.IAgent;
8 import cz.cuni.amis.pogamut.base.communication.messages.InfoMessage;
9 import cz.cuni.amis.pogamut.base.communication.translator.IWorldMessageTranslator;
10 import cz.cuni.amis.pogamut.base.communication.worldview.ILockableWorldView;
11 import cz.cuni.amis.pogamut.base.communication.worldview.IWorldView;
12 import cz.cuni.amis.pogamut.base.component.controller.ComponentDependencies;
13 import cz.cuni.amis.pogamut.base.component.controller.ComponentDependencyType;
14 import cz.cuni.amis.pogamut.base.factory.guice.GuiceAgentModule;
15 import cz.cuni.amis.pogamut.base.factory.guice.GuiceRemoteAgentModule;
16 import cz.cuni.amis.pogamut.base.utils.guice.AdaptableProvider;
17 import cz.cuni.amis.pogamut.base3d.ILockableVisionWorldView;
18 import cz.cuni.amis.pogamut.base3d.agent.IAgent3D;
19 import cz.cuni.amis.pogamut.base3d.worldview.IVisionWorldView;
20 import cz.cuni.amis.pogamut.ut2004.bot.IUT2004Bot;
21 import cz.cuni.amis.pogamut.ut2004.bot.IUT2004BotController;
22 import cz.cuni.amis.pogamut.ut2004.bot.impl.UT2004Bot;
23 import cz.cuni.amis.pogamut.ut2004.bot.params.UT2004BotParameters;
24 import cz.cuni.amis.pogamut.ut2004.communication.messages.ItemType;
25 import cz.cuni.amis.pogamut.ut2004.communication.messages.UT2004ItemType;
26 import cz.cuni.amis.pogamut.ut2004.communication.translator.bot.BotFSM;
27 import cz.cuni.amis.pogamut.ut2004.communication.worldview.UT2004SyncLockableWorldView;
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64 public class UT2004BotModule<PARAMS extends UT2004BotParameters> extends UT2004CommunicationModule<PARAMS> {
65
66
67
68
69 protected AdaptableProvider<ComponentDependencies> worldViewDependenciesProvider = new AdaptableProvider<ComponentDependencies>(null);
70
71 private Class<? extends IUT2004BotController> botControllerClass;
72
73 protected UT2004BotModule() {
74 }
75
76 public UT2004BotModule(Class<? extends IUT2004BotController> botControllerClass) {
77 this.botControllerClass = botControllerClass;
78 }
79
80 @Override
81 public void prepareNewAgent(PARAMS agentParameters) {
82 super.prepareNewAgent(agentParameters);
83
84 worldViewDependenciesProvider.set(new ComponentDependencies(ComponentDependencyType.STARTS_WITH).add(agentParameters.getAgentId()));
85 }
86
87 @Override
88 protected void configureModules() {
89 super.configureModules();
90 addModule(new AbstractModule() {
91
92 @Override
93 public void configure() {
94 bind(IWorldMessageTranslator.class).to(BotFSM.class);
95 bind(IWorldView.class).to(IVisionWorldView.class);
96 bind(IVisionWorldView.class).to(ILockableVisionWorldView.class);
97 bind(ILockableWorldView.class).to(ILockableVisionWorldView.class);
98 bind(ILockableVisionWorldView.class).to(UT2004SyncLockableWorldView.class);
99 bind(ComponentDependencies.class).annotatedWith(Names.named(UT2004SyncLockableWorldView.WORLDVIEW_DEPENDENCY)).toProvider(worldViewDependenciesProvider);
100 bind(IAgent.class).to(IAgent3D.class);
101 bind(IAgent3D.class).to(IUT2004Bot.class);
102 bind(IUT2004Bot.class).to(UT2004Bot.class);
103 if (botControllerClass != null) {
104 bind(IUT2004BotController.class).to(botControllerClass);
105 }
106 bind(UT2004BotParameters.class).toProvider((Provider<? extends UT2004BotParameters>) getAgentParamsProvider());
107 }
108
109 });
110 }
111
112 }