View Javadoc

1   package cz.cuni.amis.pogamut.ut2004.bot.impl;
2   
3   import java.util.Random;
4   import java.util.logging.Level;
5   
6   import cz.cuni.amis.pathfinding.map.IPFMapView;
7   import cz.cuni.amis.pogamut.base.agent.navigation.IPathPlanner;
8   import cz.cuni.amis.pogamut.base.agent.navigation.PathExecutorState;
9   import cz.cuni.amis.pogamut.base.agent.state.impl.AgentState;
10  import cz.cuni.amis.pogamut.base.agent.state.level0.IAgentState;
11  import cz.cuni.amis.pogamut.base.agent.state.level1.IAgentStateDown;
12  import cz.cuni.amis.pogamut.base.communication.command.IAct;
13  import cz.cuni.amis.pogamut.base.communication.worldview.IWorldView;
14  import cz.cuni.amis.pogamut.base.communication.worldview.listener.annotation.AnnotationListenerRegistrator;
15  import cz.cuni.amis.pogamut.base.communication.worldview.listener.annotation.EventListener;
16  import cz.cuni.amis.pogamut.base.communication.worldview.listener.annotation.ObjectClassEventListener;
17  import cz.cuni.amis.pogamut.base.communication.worldview.listener.annotation.ObjectClassListener;
18  import cz.cuni.amis.pogamut.base.communication.worldview.listener.annotation.ObjectEventListener;
19  import cz.cuni.amis.pogamut.base.communication.worldview.listener.annotation.ObjectListener;
20  import cz.cuni.amis.pogamut.base.utils.math.DistanceUtils;
21  import cz.cuni.amis.pogamut.base3d.worldview.IVisionWorldView;
22  import cz.cuni.amis.pogamut.base3d.worldview.object.ILocated;
23  import cz.cuni.amis.pogamut.unreal.agent.navigation.IUnrealPathExecutor;
24  import cz.cuni.amis.pogamut.ut2004.agent.module.sensomotoric.AdrenalineCombo;
25  import cz.cuni.amis.pogamut.ut2004.agent.module.sensomotoric.AgentConfig;
26  import cz.cuni.amis.pogamut.ut2004.agent.module.sensomotoric.Raycasting;
27  import cz.cuni.amis.pogamut.ut2004.agent.module.sensomotoric.UT2004Weaponry;
28  import cz.cuni.amis.pogamut.ut2004.agent.module.sensomotoric.Weaponry;
29  import cz.cuni.amis.pogamut.ut2004.agent.module.sensor.AgentInfo;
30  import cz.cuni.amis.pogamut.ut2004.agent.module.sensor.UT2004AgentInfo;
31  import cz.cuni.amis.pogamut.ut2004.agent.module.sensor.AgentStats;
32  import cz.cuni.amis.pogamut.ut2004.agent.module.sensor.CTF;
33  import cz.cuni.amis.pogamut.ut2004.agent.module.sensor.Game;
34  import cz.cuni.amis.pogamut.ut2004.agent.module.sensor.ItemDescriptors;
35  import cz.cuni.amis.pogamut.ut2004.agent.module.sensor.Items;
36  import cz.cuni.amis.pogamut.ut2004.agent.module.sensor.NavPoints;
37  import cz.cuni.amis.pogamut.ut2004.agent.module.sensor.NavigationGraphBuilder;
38  import cz.cuni.amis.pogamut.ut2004.agent.module.sensor.Players;
39  import cz.cuni.amis.pogamut.ut2004.agent.module.sensor.Senses;
40  import cz.cuni.amis.pogamut.ut2004.agent.module.sensor.UT2004Items;
41  import cz.cuni.amis.pogamut.ut2004.agent.module.sensor.WeaponPrefs;
42  import cz.cuni.amis.pogamut.ut2004.agent.module.sensor.visibility.Visibility;
43  import cz.cuni.amis.pogamut.ut2004.agent.navigation.IUT2004GetBackToNavGraph;
44  import cz.cuni.amis.pogamut.ut2004.agent.navigation.IUT2004Navigation;
45  import cz.cuni.amis.pogamut.ut2004.agent.navigation.IUT2004PathExecutor;
46  import cz.cuni.amis.pogamut.ut2004.agent.navigation.IUT2004RunStraight;
47  import cz.cuni.amis.pogamut.ut2004.agent.navigation.UT2004AStarPathPlanner;
48  import cz.cuni.amis.pogamut.ut2004.agent.navigation.UT2004GetBackToNavGraph;
49  import cz.cuni.amis.pogamut.ut2004.agent.navigation.UT2004Navigation;
50  import cz.cuni.amis.pogamut.ut2004.agent.navigation.UT2004PathExecutor;
51  import cz.cuni.amis.pogamut.ut2004.agent.navigation.UT2004RunStraight;
52  import cz.cuni.amis.pogamut.ut2004.agent.navigation.astar.UT2004AStar;
53  import cz.cuni.amis.pogamut.ut2004.agent.navigation.floydwarshall.FloydWarshallMap;
54  import cz.cuni.amis.pogamut.ut2004.agent.navigation.loquenavigator.LoqueNavigator;
55  import cz.cuni.amis.pogamut.ut2004.agent.navigation.navmesh.LevelGeometry;
56  import cz.cuni.amis.pogamut.ut2004.agent.navigation.navmesh.LevelGeometryModule;
57  import cz.cuni.amis.pogamut.ut2004.agent.navigation.navmesh.NavMesh;
58  import cz.cuni.amis.pogamut.ut2004.agent.navigation.navmesh.NavMeshModule;
59  import cz.cuni.amis.pogamut.ut2004.agent.navigation.navmesh.drawing.IUT2004ServerProvider;
60  import cz.cuni.amis.pogamut.ut2004.agent.navigation.navmesh.drawing.UT2004Draw;
61  import cz.cuni.amis.pogamut.ut2004.agent.navigation.navmesh.drawing.UT2004ServerProvider;
62  import cz.cuni.amis.pogamut.ut2004.agent.navigation.stuckdetector.UT2004DistanceStuckDetector;
63  import cz.cuni.amis.pogamut.ut2004.agent.navigation.stuckdetector.UT2004PositionStuckDetector;
64  import cz.cuni.amis.pogamut.ut2004.agent.navigation.stuckdetector.UT2004TimeStuckDetector;
65  import cz.cuni.amis.pogamut.ut2004.bot.IUT2004BotController;
66  import cz.cuni.amis.pogamut.ut2004.bot.command.AdvancedLocomotion;
67  import cz.cuni.amis.pogamut.ut2004.bot.command.CompleteBotCommandsWrapper;
68  import cz.cuni.amis.pogamut.ut2004.bot.command.ImprovedShooting;
69  import cz.cuni.amis.pogamut.ut2004.communication.messages.ItemType;
70  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbcommands.DrawStayingDebugLines;
71  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbcommands.GetPath;
72  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.AutoTraceRay;
73  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.ConfigChange;
74  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.InitedMessage;
75  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.NavPoint;
76  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.PathList;
77  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.Self;
78  import cz.cuni.amis.pogamut.ut2004.communication.translator.itemdescriptor.ItemDescriptor;
79  import cz.cuni.amis.utils.flag.FlagListener;
80  
81  import java.io.FileNotFoundException;
82  import java.io.IOException;
83  import java.util.logging.Logger;
84  
85  /**
86   * The most advanced controller that is available. This controller contains all useful modules pre-instantiated.
87   *
88   * @author Jimmy
89   *
90   * @param <BOT>
91   */
92  public class UT2004BotModuleController<BOT extends UT2004Bot> extends UT2004BotLogicController<BOT> {
93  
94  	/**
95  	 * Random number generator that is usually useful to have during decision making.
96  	 */
97  	protected Random random = new Random(System.currentTimeMillis());
98  	
99  	/**
100 	 * Command module that is internally using {@link UT2004PathExecutor} for path-following and {@link FloydWarshallMap}
101 	 * for path planning resulting in unified class that can solely handle navigation of the bot within the environment.
102 	 * <p><p> 
103 	 * In contrast to {@link UT2004PathExecutor} methods
104 	 * of this module may be recalled every {@link UT2004BotModuleController#logic()} iteration even with 
105 	 * the same argument (which is not true for {@link UT2004PathExecutor#followPath(cz.cuni.amis.pogamut.base.agent.navigation.IPathFuture)}.
106 	 * <p><p>
107 	 * Note that this class is actually initialized with instances of {@link UT2004BotModuleController#pathExecutor} and {@link UT2004BotModuleController#fwMap}
108 	 * so you must take care if using add/remove stuck detectors or reinitilize this property to your liking (you can do that in {@link UT2004BotModuleController#botInitialized(cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.GameInfo, ConfigChange, InitedMessage)} 
109 	 * method.
110 	 * <p><p>
111 	 * May be used since first {@link UT2004BotModuleController#logic()} is called.
112      * <p><p>
113      * Initialized inside {@link UT2004BotModuleController#initializePathFinding(UT2004Bot)}.
114 	 */
115 	protected IUT2004Navigation navigation;
116 	
117 	/**
118 	 * Memory module specialized on general info about the game - game type, time limit, frag limit, etc.
119 	 * <p><p>
120 	 * May be used since {@link IUT2004BotController#botInitialized(cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.GameInfo, cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.ConfigChange, cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.InitedMessage)}
121      * is called.
122      * <p><p>
123      * Initialized inside {@link UT2004BotModuleController#initializeModules(UT2004Bot)}.
124 	 */
125 	protected Game game;
126 	
127 	/**
128 	 * Memory module specialized on general info about the agent whereabouts - location, rotation, health, current weapon, who is enemy/friend, etc.
129 	 * <p><p>
130 	 * May be used since first {@link Self} message is received, i.e, since the first {@link IUT2004BotController#botFirstSpawn(cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.GameInfo, ConfigChange, InitedMessage, Self)} 
131      * is called.
132      * <p><p>
133      * Initialized inside {@link UT2004BotModuleController#initializeModules(UT2004Bot)}.
134 	 */
135 	protected AgentInfo info;
136 	
137 	/**
138 	 * Memory module specialized on whereabouts of other players - who is visible, enemy / friend, whether bot can see anybody, etc.
139 	 * <p><p>
140 	 * May be used since {@link IUT2004BotController#botInitialized(cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.GameInfo, cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.ConfigChange, cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.InitedMessage)}
141      * is called.
142      * <p><p>
143      * Initialized inside {@link UT2004BotModuleController#initializeModules(UT2004Bot)}.
144 	 */
145 	protected Players players;
146 	
147 	/**
148 	 * Sensory module that provides mapping between {@link ItemType} and {@link ItemDescriptor} providing
149      * an easy way to obtain item descriptors for various items in UT2004.
150      * <p><p>
151      * May be used since {@link IUT2004BotController#botInitialized(cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.GameInfo, cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.ConfigChange, cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.InitedMessage)}
152      * is called.
153      * <p><p>
154      * Initialized inside {@link UT2004BotModuleController#initializeModules(UT2004Bot)}.
155 	 */
156 	protected ItemDescriptors descriptors;
157 	
158 	/**
159 	 * Memory module specialized on items on the map - which are visible and which are probably spawned.
160 	 * <p><p>
161 	 * May be used since {@link IUT2004BotController#botInitialized(cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.GameInfo, cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.ConfigChange, cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.InitedMessage)}
162      * is called.
163      * <p><p>
164      * Initialized inside {@link UT2004BotModuleController#initializeModules(UT2004Bot)}.
165 	 */
166 	protected Items items;
167 	
168 	/**
169 	 * Memory module specialized on agent's senses - whether the bot has been recently killed, collide with level's geometry, etc.
170 	 * <p><p>
171 	 * May be used since {@link IUT2004BotController#botInitialized(cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.GameInfo, cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.ConfigChange, cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.InitedMessage)}
172      * is called.
173      * <p><p>
174      * Initialized inside {@link UT2004BotModuleController#initializeModules(UT2004Bot)}.
175 	 */
176 	protected Senses senses;
177 	
178 	/**
179 	 * Memory module specialized on info about the bot's weapon and ammo inventory - it can tell you which weapons are loaded, melee/ranged, etc.
180 	 * <p><p>
181 	 * May be used since {@link IUT2004BotController#botInitialized(cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.GameInfo, cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.ConfigChange, cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.InitedMessage)}
182      * is called.
183      * <p><p>
184      * Initialized inside {@link UT2004BotModuleController#initializeModules(UT2004Bot)}.
185 	 */
186 	protected Weaponry weaponry;
187 	
188 	/**
189 	 * Memory module specialized on the agent's configuration inside UT2004 - name, vision time, manual spawn, cheats (if enabled at GB2004).
190 	 * <p><p>
191 	 * May be used since {@link IUT2004BotController#botInitialized(cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.GameInfo, ConfigChange, cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.InitedMessage)}
192      * is called.
193      * <p><p>
194      * Initialized inside {@link UT2004BotModuleController#initializeModules(UT2004Bot)}.
195 	 */
196 	protected AgentConfig config;
197 	
198 	/**
199 	 * Support for creating rays used for raycasting (see {@link AutoTraceRay} that is being utilized).
200 	 * <p><p>
201 	 * May be used since {@link IUT2004BotController#botInitialized(cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.GameInfo, cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.ConfigChange, cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.InitedMessage)}
202      * is called.
203      * <p><p>
204      * Initialized inside {@link UT2004BotModuleController#initializeModules(UT2004Bot)}.
205 	 */
206 	protected Raycasting raycasting;
207 	
208 	/**
209 	 * Wraps all available commands that can be issued to the virtual body of the bot inside UT2004.
210      * <p><p>
211      * May be used since since the first {@link IUT2004BotController#botFirstSpawn(cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.GameInfo, ConfigChange, InitedMessage, Self)} 
212      * is called.
213      * <p><p>
214      * Initialized inside {@link UT2004BotModuleController#initializeModules(UT2004Bot)}.
215 	 */
216 	protected CompleteBotCommandsWrapper body;
217 	
218 	/**
219 	 * Shortcut for <i>body.getAdvancedShooting()</i> that allows you to shoot at opponent.
220 	 * <p><p>
221 	 * Note: more weapon-handling methods are available through {@link UT2004BotModuleControllerNew#weaponry}.
222 	 * <p><p>
223 	 * May be used since since the first {@link IUT2004BotController#botFirstSpawn(cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.GameInfo, ConfigChange, InitedMessage, Self)} 
224      * is called.
225      * <p><p>
226 	 * Initialized inside {@link UT2004BotModuleController#initializeModules(UT2004Bot)}.
227 	 */
228 	protected ImprovedShooting shoot;
229 	
230 	/**
231 	 * Shortcut for <i>body.getAdvancedLocomotion()</i> that allows you to manually steer the movement through the environment.
232 	 * <p><p>
233 	 * Note: navigation is done via {@link UT2004BotModuleControllerNew#pathExecutor} that needs {@link PathHandle} from the {@link UT2004BotModuleControllerNew#pathPlanner}.
234 	 * <p><p>
235 	 * May be used since since the first {@link IUT2004BotController#botFirstSpawn(cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.GameInfo, ConfigChange, InitedMessage, Self)} 
236      * is called.
237      * <p><p>
238 	 * Initialized inside {@link UT2004BotModuleController#initializeModules(UT2004Bot)}.
239 	 */
240 	protected AdvancedLocomotion move;
241 	
242 	/**
243 	 * Module specialized on CTF games. Enabled only for CTF games, check {@link CTF#isEnabled()}.
244 	 * <p><p>
245 	 * Initialized inside {@link UT2004BotModuleController#initializeModules(UT2004Bot)}.
246 	 */
247 	protected CTF ctf;
248 	
249 	/**
250 	 * Module for adrenaline combos.
251 	 */
252 	protected AdrenalineCombo combo;
253 	
254 	/**
255      * Executor is used for following a path in the environment.
256      * <p><p>
257      * May be used since since the first {@link IUT2004BotController#botFirstSpawn(cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.GameInfo, ConfigChange, InitedMessage, Self)} 
258      * is called.
259      * <p><p>
260      * Initialized inside {@link UT2004BotModuleController#initializePathFinding(UT2004Bot)}.
261      * <p><p>
262      * {@link UT2004PathExecutor#addStuckDetector(cz.cuni.amis.pogamut.base.agent.navigation.IStuckDetector)} is initialized with default stuck detectors:
263      * {@link UT2004TimeStuckDetector}, {@link UT2004PositionStuckDetector}, {@link UT2004DistanceStuckDetector}.
264      * <p><p>
265      * If one of stuck detectors (heuristicly) finds out that the bot has stuck somewhere,
266      * it reports it back to {@link UT2004PathExecutor} and the path executor will stop following the path switching
267      * itself to {@link PathExecutorState#STUCK}, which in turn allows us to issue another follow-path command in the right time.
268      */
269 	protected IUT2004PathExecutor<ILocated> pathExecutor = null;
270 	
271     /**
272      * Planner used to compute the path (consisting of navigation points) inside the map.
273      * <p><p>
274      * May be used since since the first {@link IUT2004BotController#botFirstSpawn(cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.GameInfo, ConfigChange, InitedMessage, Self)} 
275      * is called.
276      * <p><p>
277      * Initialized inside {@link UT2004BotModuleController#initializePathFinding(UT2004Bot)}.
278      */
279     protected IPathPlanner<ILocated> pathPlanner = null;
280     
281     /**
282      * Navigation graph builder that may be used to manually extend the navigation graph of the UT2004.
283      * <p><p>
284      * May be used since {@link IUT2004BotController#botInitialized(cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.GameInfo, ConfigChange, InitedMessage)} 
285      * is called.
286      * <p><p>
287      * Initialized inside {@link UT2004BotModuleController#initializeModules(UT2004Bot)}.
288      */
289     protected NavigationGraphBuilder navBuilder = null;
290     
291     /**
292      * Listener registrator that probes declared methods for the presence of {@link EventListener}, {@link ObjectClassEventListener},
293      * {@link ObjectClassListener}, {@link ObjectEventListener} and {@link ObjectListener} annotations and automatically registers
294      * them as listeners on a specific events.
295      * <p><p>
296      * Note that this registrator is usable for 'this' object only! It will work only for 'this' object.
297      */
298     protected AnnotationListenerRegistrator listenerRegistrator;
299     
300     /**
301      * Weapon preferences for your bot. See {@link WeaponPrefs} class javadoc. It allows you to define preferences for
302      * weapons to be used at given distance (together with their firing modes).
303      */
304     protected WeaponPrefs weaponPrefs;
305     
306     /**
307      * Shortcut for the {@link UT2004Bot#getWorldView()}.
308      */
309     protected IVisionWorldView world;
310     
311     /**
312      * Shortcut for the {@link UT2004Bot#getAct()}.
313      */
314     protected IAct act;
315     
316     /**
317      * Module that is providing various statistics about the bot. You may also used it to output these stats (in CSV format)
318      * into some file using {@link AgentStats#startOutput(String)} or {@link AgentStats#startOutput(String, boolean)}.
319      */
320     protected AgentStats stats;
321 
322     /**
323      * Path-planner ({@link IPathPlanner} using {@link NavPoint}s), you may use it to find paths inside the environment wihtout
324      * waiting for round-trip of {@link GetPath} command and {@link PathList}s response from UT2004. It is much faster than 
325      * {@link UT2004BotModuleController#pathPlanner} but you need to pass {@link NavPoint} instances to planner instead of
326      * {@link ILocated} ... to find the nearest {@link NavPoint} instance, {@link DistanceUtils} is a handy, check especially
327      * {@link DistanceUtils#getNearest(java.util.Collection, ILocated)}.
328      */
329 	protected FloydWarshallMap fwMap;
330 	
331 	/**
332 	 * Navigation helper that is able to get your bot back to the nearest navigation graph so you can use {@link UT2004BotModuleController#navigation} 
333 	 * without fear of catastrophe.
334 	 * <p><p>
335 	 * May be used since {@link IUT2004BotController#botInitialized(cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.GameInfo, ConfigChange, InitedMessage)} 
336      * is called.
337      * <p><p>
338      * Initialized inside {@link UT2004BotModuleController#initializePathFinding(UT2004Bot)}.
339 	 */
340 	protected IUT2004GetBackToNavGraph getBackToNavGraph;
341 	
342 	/**
343 	 * Navigation helper that can run-straight to some point with stuck detectors.
344 	 * <p><p>
345 	 * May be used since {@link IUT2004BotController#botInitialized(cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.GameInfo, ConfigChange, InitedMessage)} 
346      * is called.
347      * <p><p>
348      * Initialized inside {@link UT2004BotModuleController#initializePathFinding(UT2004Bot)}.
349 	 */
350 	protected IUT2004RunStraight runStraight;
351 	
352 	/**
353 	 * Module that provides visibility/cover information for the map.
354 	 * <p><p>
355 	 * May be used since {@link IUT2004BotController#botInitialized(cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.GameInfo, ConfigChange, InitedMessage)} 
356      * is called.
357      * <p><p>
358      * Initialized inside {@link UT2004BotModuleController#initializeModules(UT2004Bot)}.
359 	 */
360 	protected Visibility visibility;
361 	
362 	/**
363 	 * Module that provides shortcut for getting {@link NavPoint}s out of {@link IWorldView}.
364 	 * <p><p>
365 	 * May be used since {@link IUT2004BotController#botInitialized(cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.GameInfo, ConfigChange, InitedMessage)} 
366      * is called.
367      * <p><p>
368      * Initialized inside {@link UT2004BotModuleController#initializeModules(UT2004Bot)}.
369 	 */
370 	protected NavPoints navPoints;
371 	
372 	/**
373 	 * Class providing A-Star algorithm over the navpoints as they are present within the {@link IWorldView}.
374 	 * <p><p>
375 	 * You may provide custom {@link IPFMapView} over the map in-order to greatly customize the A-Star search.
376 	 */
377 	protected UT2004AStar aStar;
378 	
379 	/**
380 	 * Class providing {@link NavMesh} instance via {@link NavMeshModule#getNavMesh()} method.
381 	 * <p><p>
382 	 * Note that ".navmesh" file for concrete UT2004 map needs to be present inside local directory of the bot in order for this module to be working.
383 	 * <p><p>
384 	 * Download preprocessed navmesh files from: svn://artemis.ms.mff.cuni.cz/pogamut/trunk/project/Addons/UT2004NavMeshTools/04-NavMeshes
385 	 * <p><p>
386 	 * May be used since {@link IUT2004BotController#botInitialized(cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.GameInfo, ConfigChange, InitedMessage)} 
387      * is called.
388      * <p><p>
389      * Initialized inside {@link UT2004BotModuleController#initializeModules(UT2004Bot)}. 
390 	 */
391 	protected NavMeshModule navMeshModule;
392 	
393 	/**
394 	 * Class providing {@link LevelGeometry} instance via {@link LevelGeometryModule#getLevelGeometry()} method.
395 	 * <p><p>
396 	 * Note that ".obj", ".centre", ".scale" files must be present inside local directory of the bot in order for this module to be working.
397 	 * <p><p>
398 	 * Download preprocessed level geometry from: svn://artemis.ms.mff.cuni.cz/pogamut/trunk/project/Addons/UT2004NavMeshTools/04-NavMeshes 
399 	 * <p><p>
400 	 * May be used since {@link IUT2004BotController#botInitialized(cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.GameInfo, ConfigChange, InitedMessage)} 
401      * is called.
402      * <p><p>
403      * Initialized inside {@link UT2004BotModuleController#initializeModules(UT2004Bot)}. 
404 	 */
405 	protected LevelGeometryModule levelGeometryModule;
406 	
407 	/**
408 	 * Utility class that provides shared instance of {@link UT2004Server}.
409 	 */
410 	private IUT2004ServerProvider serverProvider;
411 	
412 	/**
413 	 * Class providing interface for the use of {@link DrawStayingDebugLines} inside UT2004. Can be used to draw debug stuff (lines) right into UT2004.
414 	 * <p><p>
415 	 * May be used since {@link IUT2004BotController#botInitialized(cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.GameInfo, ConfigChange, InitedMessage)} 
416      * is called.
417      * <p><p>
418      * Initialized inside {@link UT2004BotModuleController#initializeModules(UT2004Bot)}. 
419 	 */
420 	protected UT2004Draw draw;
421 
422 	private FlagListener<IAgentState> botStateListener = new FlagListener<IAgentState>() {
423 
424 		@Override
425 		public void flagChanged(IAgentState changedValue) {			
426 			if (changedValue instanceof IAgentStateDown) {
427 				botAgentDown();
428 			}
429 		}
430 	};
431 	
432     @Override
433 	public void initializeController(BOT bot) {    	
434 		super.initializeController(bot);
435 		
436 		bot.getState().addListener(botStateListener);
437 		
438 		world = getWorldView();
439 		act = getAct();
440 		initializeModules(bot);
441 		initializePathFinding(bot);
442 		initializeListeners(bot);
443 	}
444 	
445     /**
446      * Initializes {@link UT2004BotModuleControllerNew#listenerRegistrator} and calls {@link AnnotationListenerRegistrator#addListeners()} method
447      * to probe all declared methods for event-annotation presence.
448      * @param bot
449      */
450 	protected void initializeListeners(BOT bot) {
451 		listenerRegistrator = new AnnotationListenerRegistrator(this, getWorldView(), bot.getLogger().getCategory("Listeners"));
452 		listenerRegistrator.addListeners();
453 	}
454 
455 	/**
456 	 * Initializes path-finding modules: {@link UT2004BotModuleControllerNew#pathPlanner}, {@link UT2004BotModuleController#fwMap} and {@link UT2004BotModuleControllerNew#pathExecutor}.
457 	 * If you need different path planner / path executor - override this method and initialize your own modules.
458 	 * @param bot
459 	 */
460 	protected void initializePathFinding(BOT bot) {
461 		pathPlanner  = new UT2004AStarPathPlanner(bot);
462 		fwMap        = new FloydWarshallMap(bot);
463 		aStar        = new UT2004AStar(bot);		
464 		pathExecutor = 
465         	new UT2004PathExecutor<ILocated>(
466         		bot, info,move,
467         		new LoqueNavigator<ILocated>(bot,info,move, bot.getLog()), 
468         		bot.getLog()
469         	);
470 		
471 		// add stuck detectors that watch over the path-following, if it (heuristicly) finds out that the bot has stuck somewhere,
472     	// it reports an appropriate path event and the path executor will stop following the path which in turn allows 
473     	// us to issue another follow-path command in the right time
474         pathExecutor.addStuckDetector(new UT2004TimeStuckDetector(bot, 3000, 100000)); // if the bot does not move for 3 seconds, considered that it is stuck
475         pathExecutor.addStuckDetector(new UT2004PositionStuckDetector(bot));           // watch over the position history of the bot, if the bot does not move sufficiently enough, consider that it is stuck
476         pathExecutor.addStuckDetector(new UT2004DistanceStuckDetector(bot));           // watch over distances to target
477         
478 		getBackToNavGraph = new UT2004GetBackToNavGraph(bot, info, move);
479 		runStraight = new UT2004RunStraight(bot, info, move);
480 		navigation = new UT2004Navigation(bot, pathExecutor, fwMap, getBackToNavGraph, runStraight);                
481 	}
482 
483 	/**
484 	 * Initializes memory/command modules of the bot.
485 	 * 
486 	 * @param bot
487 	 */
488 	protected void initializeModules(BOT bot) {
489 		game           = new Game(bot);
490 		navPoints      = new NavPoints(bot);
491 		players        = new Players(bot);
492 		descriptors    = new ItemDescriptors(bot);
493 		config         = new AgentConfig(bot);
494 		raycasting     = new Raycasting(bot);
495 		stats          = new AgentStats(bot);
496 		navBuilder     = new NavigationGraphBuilder(bot);
497 		info           = new UT2004AgentInfo(bot, game);
498 		visibility     = new Visibility(bot, info);
499 		ctf            = new CTF(bot, info);
500 		weaponry       = new UT2004Weaponry(bot, descriptors);
501 		items          = new UT2004Items(bot, info, game, weaponry, null);
502 		senses         = new Senses(bot, info, players);
503 		body           = new CompleteBotCommandsWrapper(bot, weaponry, null);		
504 		shoot          = body.getImprovedShooting();
505 		move           = body.getLocomotion();
506 		weaponPrefs    = new WeaponPrefs(weaponry, bot);
507 		combo          = new AdrenalineCombo(bot, info);
508 		serverProvider = new UT2004ServerProvider();
509 		navMeshModule  = new NavMeshModule(serverProvider, getWorldView(), bot.getLogger());
510 		levelGeometryModule = new LevelGeometryModule(getWorldView(), bot.getLogger());		 
511 		draw           = new UT2004Draw(bot.getLogger().getCategory("Draw"), serverProvider);
512 	}
513 	
514 	@Override
515 	public void finishControllerInitialization() {
516 		if (navBuilder.isUsed()) {
517 			log.info("Navigation graph has been altered by 'navBuilder', triggering recomputation of Floyd-Warshall path matrix...");
518 			Level oldLevel = fwMap.getLog().getLevel();
519 			fwMap.getLog().setLevel(Level.FINER);
520 			fwMap.refreshPathMatrix();
521 			fwMap.getLog().setLevel(oldLevel);
522 			
523 			aStar.mapChanged();
524 		}
525 	}
526 
527 	//
528 	//
529 	// MODULE GETTERS
530 	//
531 	//
532 	
533 	public Random getRandom() {
534 		return random;
535 	}
536 	
537 	public UT2004AStar getAStar() {
538 		return aStar;
539 	}
540 
541 	public Game getGame() {
542 		return game;
543 	}
544 
545 	public AgentInfo getInfo() {
546 		return info;
547 	}
548 
549 	public Players getPlayers() {
550 		return players;
551 	}
552 
553 	public ItemDescriptors getDescriptors() {
554 		return descriptors;
555 	}
556 
557 	public Items getItems() {
558 		return items;
559 	}
560 
561 	public Senses getSenses() {
562 		return senses;
563 	}
564 
565 	public Weaponry getWeaponry() {
566 		return weaponry;
567 	}
568 
569 	public AgentConfig getConfig() {
570 		return config;
571 	}
572 
573 	public Raycasting getRaycasting() {
574 		return raycasting;
575 	}
576 
577 	public CompleteBotCommandsWrapper getBody() {
578 		return body;
579 	}
580 
581 	public ImprovedShooting getShoot() {
582 		return shoot;
583 	}
584 
585 	public AdvancedLocomotion getMove() {
586 		return move;
587 	}
588 
589 	public IUnrealPathExecutor<ILocated> getPathExecutor() {
590 		return pathExecutor;
591 	}
592 
593 	public IPathPlanner<ILocated> getPathPlanner() {
594 		return pathPlanner;
595 	}
596 	
597 	public AdrenalineCombo getCombo() {
598 		return combo;
599 	}
600 
601 	public NavigationGraphBuilder getNavBuilder() {
602 		return navBuilder;
603 	}
604 
605 	public WeaponPrefs getWeaponPrefs() {
606 		return weaponPrefs;
607 	}
608 
609 	public IVisionWorldView getWorld() {
610 		return world;
611 	}
612 
613 	public AgentStats getStats() {
614 		return stats;
615 	}
616 
617 	public FloydWarshallMap getFwMap() {
618 		return fwMap;
619 	}
620 	
621 	public IUT2004Navigation getNavigation() {
622 		return navigation;
623 	}
624 
625 	public Visibility getVisibility() {
626 		return visibility;
627 	}
628 	
629 	public NavMeshModule getNavMeshModule() {
630 		return navMeshModule;
631 	}
632 	
633 	public NavMesh getNavMesh() {
634 		if (!navMeshModule.isInitialized()) log.warning("NavMeshModule has not been initialized (yet)! You are either calling this method too early or missing .navmesh file in the local directory of your bot!");
635 		return navMeshModule.getNavMesh();
636 	}
637 	
638 	public LevelGeometryModule getLevelGeometryModule() {
639 		return levelGeometryModule;
640 	}
641 	
642 	public LevelGeometry getLevelGeometry() {
643 		if (!levelGeometryModule.isInitialized()) log.warning("LevelGeometryModule has not been initialized (yet)! You are either calling this method too early or missing .obj, .scale, .center files in the local directory of your bot!");
644 		return levelGeometryModule.getLevelGeometry();
645 	}
646 	
647 	// ==========
648 	// LIFE-CYCLE	 
649 	// ==========
650 	
651 	protected void botAgentDown() {
652 		if (serverProvider != null) {
653 			serverProvider.killServer();
654 		}
655 	}
656 	
657 }