1 package cz.cuni.amis.pogamut.sposh.context; 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.communication.command.IAct; 9 import cz.cuni.amis.pogamut.base.communication.worldview.IWorldView; 10 import cz.cuni.amis.pogamut.base.communication.worldview.listener.annotation.AnnotationListenerRegistrator; 11 import cz.cuni.amis.pogamut.base.communication.worldview.listener.annotation.EventListener; 12 import cz.cuni.amis.pogamut.base.communication.worldview.listener.annotation.ObjectClassEventListener; 13 import cz.cuni.amis.pogamut.base.communication.worldview.listener.annotation.ObjectClassListener; 14 import cz.cuni.amis.pogamut.base.communication.worldview.listener.annotation.ObjectEventListener; 15 import cz.cuni.amis.pogamut.base.communication.worldview.listener.annotation.ObjectListener; 16 import cz.cuni.amis.pogamut.base.utils.logging.LogCategory; 17 import cz.cuni.amis.pogamut.base.utils.math.DistanceUtils; 18 import cz.cuni.amis.pogamut.base3d.worldview.IVisionWorldView; 19 import cz.cuni.amis.pogamut.base3d.worldview.object.ILocated; 20 import cz.cuni.amis.pogamut.ut2004.agent.module.sensomotoric.AdrenalineCombo; 21 import cz.cuni.amis.pogamut.ut2004.agent.module.sensomotoric.AgentConfig; 22 import cz.cuni.amis.pogamut.ut2004.agent.module.sensomotoric.Raycasting; 23 import cz.cuni.amis.pogamut.ut2004.agent.module.sensomotoric.Weaponry; 24 import cz.cuni.amis.pogamut.ut2004.agent.module.sensor.AgentInfo; 25 import cz.cuni.amis.pogamut.ut2004.agent.module.sensor.AgentStats; 26 import cz.cuni.amis.pogamut.ut2004.agent.module.sensor.CTF; 27 import cz.cuni.amis.pogamut.ut2004.agent.module.sensor.Game; 28 import cz.cuni.amis.pogamut.ut2004.agent.module.sensor.ItemDescriptors; 29 import cz.cuni.amis.pogamut.ut2004.agent.module.sensor.Items; 30 import cz.cuni.amis.pogamut.ut2004.agent.module.sensor.NavPoints; 31 import cz.cuni.amis.pogamut.ut2004.agent.module.sensor.NavigationGraphBuilder; 32 import cz.cuni.amis.pogamut.ut2004.agent.module.sensor.Players; 33 import cz.cuni.amis.pogamut.ut2004.agent.module.sensor.Senses; 34 import cz.cuni.amis.pogamut.ut2004.agent.module.sensor.WeaponPrefs; 35 import cz.cuni.amis.pogamut.ut2004.agent.module.sensor.visibility.Visibility; 36 import cz.cuni.amis.pogamut.ut2004.agent.navigation.UT2004AStarPathPlanner; 37 import cz.cuni.amis.pogamut.ut2004.agent.navigation.UT2004GetBackToNavGraph; 38 import cz.cuni.amis.pogamut.ut2004.agent.navigation.UT2004Navigation; 39 import cz.cuni.amis.pogamut.ut2004.agent.navigation.UT2004PathExecutor; 40 import cz.cuni.amis.pogamut.ut2004.agent.navigation.UT2004RunStraight; 41 import cz.cuni.amis.pogamut.ut2004.agent.navigation.astar.UT2004AStar; 42 import cz.cuni.amis.pogamut.ut2004.agent.navigation.floydwarshall.FloydWarshallMap; 43 import cz.cuni.amis.pogamut.ut2004.agent.navigation.loquenavigator.KefikRunner; 44 import cz.cuni.amis.pogamut.ut2004.agent.navigation.loquenavigator.LoqueNavigator; 45 import cz.cuni.amis.pogamut.ut2004.bot.IUT2004BotController; 46 import cz.cuni.amis.pogamut.ut2004.bot.command.AdvancedLocomotion; 47 import cz.cuni.amis.pogamut.ut2004.bot.command.CompleteBotCommandsWrapper; 48 import cz.cuni.amis.pogamut.ut2004.bot.command.ImprovedShooting; 49 import cz.cuni.amis.pogamut.ut2004.bot.impl.UT2004Bot; 50 import cz.cuni.amis.pogamut.ut2004.bot.impl.UT2004BotController; 51 import cz.cuni.amis.pogamut.ut2004.bot.impl.UT2004BotModuleController; 52 import cz.cuni.amis.pogamut.ut2004.communication.messages.ItemType; 53 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbcommands.GetPath; 54 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.AutoTraceRay; 55 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.BotKilled; 56 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.ConfigChange; 57 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.GameInfo; 58 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.InitedMessage; 59 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.NavPoint; 60 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.PathList; 61 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.Self; 62 import cz.cuni.amis.pogamut.ut2004.communication.translator.itemdescriptor.ItemDescriptor; 63 64 /** 65 * Primitive State Context for UT2004. 66 * @author Honza 67 */ 68 public class UT2004Context<BOT extends UT2004Bot> extends Context<BOT> implements IUT2004Context<BOT> { 69 70 /** 71 * Random number generator that is usually useful to have during decision making. 72 */ 73 protected Random random = new Random(System.currentTimeMillis()); 74 75 /** 76 * Alias for user's log. 77 */ 78 protected LogCategory log = null; 79 80 /** 81 * Memory module specialized on general info about the game - game type, time limit, frag limit, etc. 82 * <p><p> 83 * May be used since {@link SposhBotLogic#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)} 84 * is called. 85 * <p><p> 86 * Initialized inside {@link UT2004Behaviour#initializeModules(UT2004Bot)}. 87 */ 88 protected Game game; 89 90 /** 91 * Memory module specialized on general info about the agent whereabouts - location, rotation, health, current weapon, who is enemy/friend, etc. 92 * <p><p> 93 * May be used since first {@link Self} message is received, i.e, since the first {@link SposhBotLogic#botFirstSpawn(cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.GameInfo, ConfigChange, InitedMessage, Self)} 94 * is called. 95 * <p><p> 96 * Initialized inside {@link UT2004Behaviour#initializeModules(UT2004Bot)}. 97 */ 98 protected AgentInfo info; 99 100 /** 101 * Memory module specialized on whereabouts of other players - who is visible, enemy / friend, whether bot can see anybody, etc. 102 * <p><p> 103 * May be used since {@link SposhBotLogic#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)} 104 * is called. 105 * <p><p> 106 * Initialized inside {@link UT2004Behaviour#initializeModules(UT2004Bot)}. 107 */ 108 protected Players players; 109 110 /** 111 * Sensory module that provides mapping between {@link ItemType} and {@link ItemDescriptor} providing 112 * an easy way to obtain item descriptors for various items in UT2004. 113 * <p><p> 114 * May be used since {@link SposhBotLogic#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)} 115 * is called. 116 * <p><p> 117 * Initialized inside {@link UT2004Behaviour#initializeModules(UT2004Bot)}. 118 */ 119 protected ItemDescriptors descriptors; 120 121 /** 122 * Memory module specialized on items on the map - which are visible and which are probably spawned. 123 * <p><p> 124 * May be used since {@link SposhBotLogic#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)} 125 * is called. 126 * <p><p> 127 * Initialized inside {@link UT2004Behaviour#initializeModules(UT2004Bot)}. 128 */ 129 protected Items items; 130 131 /** 132 * Memory module specialized on agent's senses - whether the bot has been recently killed, collide with level's geometry, etc. 133 * <p><p> 134 * May be used since {@link SposhBotLogic#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)} 135 * is called. 136 * <p><p> 137 * Initialized inside {@link UT2004Behaviour#initializeModules(UT2004Bot)}. 138 */ 139 protected Senses senses; 140 141 /** 142 * Memory module specialized on info about the bot's weapon and ammo inventory - it can tell you which weapons are loaded, melee/ranged, etc. 143 * <p><p> 144 * May be used since {@link SposhBotLogic#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)} 145 * is called. 146 * <p><p> 147 * Initialized inside {@link UT2004Behaviour#initializeModules(UT2004Bot)}. 148 */ 149 protected Weaponry weaponry; 150 151 /** 152 * Memory module specialized on the agent's configuration inside UT2004 - name, vision time, manual spawn, cheats (if enabled at GB2004). 153 * <p><p> 154 * May be used since {@link SposhBotLogic#botInitialized(cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.GameInfo, ConfigChange, cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.InitedMessage)} 155 * is called. 156 * <p><p> 157 * Initialized inside {@link UT2004Behaviour#initializeModules(UT2004Bot)}. 158 */ 159 protected AgentConfig config; 160 161 /** 162 * Support for creating rays used for raycasting (see {@link AutoTraceRay} that is being utilized). 163 * <p><p> 164 * May be used since {@link SposhBotLogic#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)} 165 * is called. 166 */ 167 protected Raycasting raycasting; 168 169 /** 170 * Module for adrenaline combos. 171 */ 172 protected AdrenalineCombo combo; 173 174 /** 175 * Creates and wraps all available commands that can be issued to the virtual body of the bot inside UT2004. 176 * <p><p> 177 * May be used since since the first {@link SposhBotLogic#botFirstSpawn(cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.GameInfo, ConfigChange, InitedMessage, Self)} 178 * is called. 179 * <p><p> 180 * Initialized inside {@link UT2004Behaviour#initializeModules(UT2004Bot)}. 181 */ 182 protected CompleteBotCommandsWrapper body; 183 184 /** 185 * Shortcut for <i>body.getImprovedShooting()</i> that allows you to shoot at opponent. 186 * <p><p> 187 * Note: more weapon-handling methods are available through {@link UT2004Behaviour#weaponry}. 188 * <p><p> 189 * May be used since since the first {@link SposhBotLogic#botFirstSpawn(cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.GameInfo, ConfigChange, InitedMessage, Self)} 190 * is called. 191 * <p><p> 192 * Initialized inside {@link UT2004Behaviour#initializeModules(UT2004Bot)}. 193 */ 194 protected ImprovedShooting shoot; 195 196 /** 197 * Shortcut for <i>body.getAdvancedLocomotion()</i> that allows you to manually steer the movement through the environment. 198 * <p><p> 199 * Note: navigation is done via {@link UT2004Behaviour#pathExecutor} that needs {@link PathHandle} from the {@link UT2004Behaviour#pathPlanner}. 200 * <p><p> 201 * May be used since since the first {@link SposhBotLogic#botFirstSpawn(cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.GameInfo, ConfigChange, InitedMessage, Self)} 202 * is called. 203 * <p><p> 204 * Initialized inside {@link UT2004Behaviour#initializeModules(UT2004Bot)}. 205 */ 206 protected AdvancedLocomotion move; 207 208 /** 209 * Executor is used for following a path in the environment. 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 UT2004BotModuleControllerNew#initializePathFinding(UT2004Bot)}. 215 */ 216 protected UT2004PathExecutor<ILocated> pathExecutor = null; 217 218 /** 219 * Planner used to compute the path (consisting of navigation points) inside the map. 220 * <p><p> 221 * May be used since since the first {@link IUT2004BotController#botFirstSpawn(cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.GameInfo, ConfigChange, InitedMessage, Self)} 222 * is called. 223 * <p><p> 224 * Initialized inside {@link UT2004BotModuleControllerNew#initializePathFinding(UT2004Bot)}. 225 */ 226 protected IPathPlanner<ILocated> pathPlanner = null; 227 228 /** 229 * Weapon preferences for your bot. See {@link WeaponPrefs} class javadoc. It allows you to define preferences for 230 * weapons to be used at given distance (together with their firing mode). 231 */ 232 protected WeaponPrefs weaponPrefs; 233 234 /** 235 * Navigation graph builder that may be used to manually extend the navigation graph of the UT2004. 236 * <p><p> 237 * May be used since {@link IUT2004BotController#botInitialized(cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.GameInfo, ConfigChange, InitedMessage)} 238 * is called. 239 * <p><p> 240 * Initialized inside {@link UT2004BotModuleController#initializeModules(UT2004Bot)}. 241 */ 242 protected NavigationGraphBuilder navBuilder; 243 244 /** 245 * Module that is providing various statistics about the bot. You may also used it to output these stats (in CSV format) 246 * into some file using {@link AgentStats#startOutput(String)} or {@link AgentStats#startOutput(String, boolean)}. 247 */ 248 protected AgentStats stats; 249 250 /** 251 * Path-planner ({@link IPathPlanner} using {@link NavPoint}s), you may use it to find paths inside the environment wihtout 252 * waiting for round-trip of {@link GetPath} command and {@link PathList}s response from UT2004. It is much faster than 253 * {@link UT2004BotModuleController#pathPlanner} but you need to pass {@link NavPoint} instances to planner instead of 254 * {@link ILocated} ... to find the nearest {@link NavPoint} instance, {@link DistanceUtils} is a handy, check especially 255 * {@link DistanceUtils#getNearest(java.util.Collection, ILocated)}. 256 */ 257 protected FloydWarshallMap fwMap; 258 259 /** 260 * Command module that is internally using {@link UT2004PathExecutor} for path-following and {@link FloydWarshallMap} 261 * for path planning resulting in unified class that can solely handle navigation of the bot within the environment. 262 * <p><p> 263 * In contrast to {@link UT2004PathExecutor} methods 264 * of this module may be recalled every {@link UT2004BotModuleController#logic()} iteration even with 265 * the same argument (which is not true for {@link UT2004PathExecutor#followPath(cz.cuni.amis.pogamut.base.agent.navigation.IPathFuture)}. 266 * <p><p> 267 * Note that this class is actually initialized with instances of {@link UT2004BotModuleController#pathExecutor} and {@link UT2004BotModuleController#fwMap} 268 * 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)} 269 * method. 270 * <p><p> 271 * May be used since first {@link UT2004BotModuleController#logic()} is called. 272 * <p><p> 273 * Initialized inside {@link UT2004BotModuleController#initializePathFinding(UT2004Bot)}. 274 */ 275 protected UT2004Navigation navigation; 276 277 /** 278 * Listener registrator that probes declared methods for the presence of {@link EventListener}, {@link ObjectClassEventListener}, 279 * {@link ObjectClassListener}, {@link ObjectEventListener} and {@link ObjectListener} annotations and automatically registers 280 * them as listeners on a specific events. 281 * <p><p> 282 * Note that this registrator is usable for 'this' object only! It will work only for 'this' object. 283 */ 284 protected AnnotationListenerRegistrator listenerRegistrator; 285 286 /** 287 * Shortcut for the {@link UT2004BotModuleController#getWorldView()}. 288 */ 289 protected IVisionWorldView world; 290 291 /** 292 * Shortcut for the {@link UT2004BotModuleController#getAct()}. 293 */ 294 protected IAct act; 295 296 /** 297 * Navigation helper that is able to get your bot back to the nearest navigation graph so you can use {@link UT2004BotModuleController#navigation} 298 * without fear of catastrophe. 299 * May be used since {@link IUT2004BotController#botInitialized(cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.GameInfo, ConfigChange, InitedMessage)} 300 * is called. 301 * <p><p> 302 * Initialized inside {@link UT2004BotModuleController#initializePathFinding(UT2004Bot)}. 303 */ 304 protected UT2004GetBackToNavGraph getBackToNavGraph; 305 306 /** 307 * Navigation helper that can run-straight to some point with stuck detectors. 308 * <p><p> 309 * May be used since {@link IUT2004BotController#botInitialized(cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.GameInfo, ConfigChange, InitedMessage)} 310 * is called. 311 * <p><p> 312 * Initialized inside {@link UT2004BotModuleController#initializePathFinding(UT2004Bot)}. 313 */ 314 protected UT2004RunStraight runStraight; 315 316 /** 317 * Module that provides visibility/cover information for the map. 318 * <p><p> 319 * May be used since {@link IUT2004BotController#botInitialized(cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.GameInfo, ConfigChange, InitedMessage)} 320 * is called. 321 * <p><p> 322 * Initialized inside {@link UT2004BotModuleController#initializeModules(UT2004Bot)}. 323 */ 324 protected Visibility visibility; 325 326 /** 327 * Module specialized on CTF games. Enabled only for CTF games, check {@link CTF#isEnabled()}. 328 * <p><p> 329 * Initialized inside {@link UT2004BotModuleController#initializeModules(UT2004Bot)}. 330 */ 331 protected CTF ctf; 332 333 /** 334 * Module that provides shortcut for getting {@link NavPoint}s out of {@link IWorldView}. 335 * <p><p> 336 * May be used since {@link IUT2004BotController#botInitialized(cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.GameInfo, ConfigChange, InitedMessage)} 337 * is called. 338 * <p><p> 339 * Initialized inside {@link UT2004BotModuleController#initializeModules(UT2004Bot)}. 340 */ 341 protected NavPoints navPoints; 342 343 /** 344 * Class providing A-Star algorithm over the navpoints as they are present within the {@link IWorldView}. 345 * <p><p> 346 * You may provide custom {@link IPFMapView} over the map in-order to greatly customize the A-Star search. 347 */ 348 protected UT2004AStar aStar; 349 350 public UT2004Context(String name, BOT bot) { 351 super(name, bot); 352 log = bot.getLogger().getCategory(UT2004BotController.USER_LOG_CATEGORY_ID); 353 log.setLevel(Level.ALL); 354 } 355 356 /** 357 * Called after the construction of the {@link UT2004Behaviour} before the GameBots2004 greets the bot even before 358 * {@link UT2004Behaviour#prepareBehaviour(UT2004Bot)} method. 359 * <p><p> 360 * <b>NOTE:</b> This is Pogamut's developers reserved method - do not override it and if you do, always use 'super' 361 * to call parent's initializeBehaviour. 362 */ 363 protected void initialize() { 364 initializeModules(bot); 365 initializePathFinding(bot); 366 initializeListeners(bot); 367 } 368 369 /** 370 * Initializes {@link UT2004Behaviour#listenerRegistrator} and calls {@link AnnotationListenerRegistrator#addListeners()} method 371 * to probe all declared methods for event-annotation presence. 372 * @param bot 373 */ 374 protected void initializeListeners(BOT bot) { 375 listenerRegistrator = new AnnotationListenerRegistrator(this, getWorldView(), bot.getLogger().getCategory("Listeners")); 376 listenerRegistrator.addListeners(); 377 } 378 379 /** 380 * Initializes path-finding modules: {@link UT2004BotModuleControllerNew#pathPlanner} and {@link UT2004BotModuleControllerNew#pathExecutor}. 381 * If you need different path planner / path executor - override this method and initialize your own modules. 382 * @param bot 383 */ 384 protected void initializePathFinding(BOT bot) { 385 pathPlanner = new UT2004AStarPathPlanner(bot); 386 fwMap = new FloydWarshallMap(bot); 387 aStar = new UT2004AStar(bot); 388 pathExecutor = 389 new UT2004PathExecutor<ILocated>( 390 bot, 391 new LoqueNavigator<ILocated>(bot, 392 bot.getLog()) 393 ); 394 getBackToNavGraph = new UT2004GetBackToNavGraph(bot, info, move); 395 runStraight = new UT2004RunStraight(bot, info, move); 396 navigation = new UT2004Navigation(bot, pathExecutor, fwMap, getBackToNavGraph, runStraight); 397 } 398 399 /** 400 * Initializes memory/command modules of the bot. 401 * 402 * @param bot 403 */ 404 protected void initializeModules(BOT bot) { 405 world = getWorldView(); 406 act = getAct(); 407 408 game = new Game(bot); 409 navPoints = new NavPoints(bot); 410 players = new Players(bot); 411 descriptors = new ItemDescriptors(bot); 412 config = new AgentConfig(bot); 413 raycasting = new Raycasting(bot); 414 stats = new AgentStats(bot); 415 navBuilder = new NavigationGraphBuilder(bot); 416 info = new AgentInfo(bot, game); 417 visibility = new Visibility(bot, info); 418 ctf = new CTF(bot, info); 419 weaponry = new Weaponry(bot, descriptors); 420 items = new Items(bot, info, game, weaponry, null); 421 senses = new Senses(bot, info, players); 422 body = new CompleteBotCommandsWrapper(bot, weaponry, null); 423 shoot = body.getImprovedShooting(); 424 move = body.getLocomotion(); 425 weaponPrefs = new WeaponPrefs(weaponry, bot); 426 combo = new AdrenalineCombo(bot, info); 427 } 428 429 /** 430 * Called after the behaviour construction to initialize user's data structures. 431 * @param bot 432 */ 433 protected void prepareBehaviour(BOT bot) { 434 } 435 436 /** 437 * This method is called whenever {@link InitedMessage} is received. Various agent modules are usable since this 438 * method is called. 439 * 440 * @param gameInfo 441 * @param config 442 * @param init 443 * @param self 444 */ 445 public void botInitialized(GameInfo info, ConfigChange config, InitedMessage init) { 446 } 447 448 /** 449 * This method is called only once whenever first batch of information what the bot can see is received. 450 * <i><i> 451 * It is sort of "first-logic-method" where you may issue commands for the first time and handle everything 452 * else in bot's logic then. It eliminates the need to have 'boolean firstLogic' field inside your bot. 453 * <p><p> 454 * Note that this method has advantage over the {@link IUT2004BotController#botInitialized(GameInfo, ConfigChange, InitedMessage)} 455 * that you already have {@link Self} object. 456 * 457 * @param gameInfo 458 * @param config 459 * @param init 460 * @param self 461 */ 462 public void botSpawned(GameInfo gameInfo, ConfigChange config, InitedMessage init, Self self) { 463 } 464 465 /** 466 * Called after {@link UT2004Behaviour#botFirstSpawn(GameInfo, ConfigChange, InitedMessage, Self)} as a hook for Pogamut's core developers 467 * to finalize initialization of various modules. 468 * <p><p> 469 * <b>NOTE:</b> This is Pogamut's developers reserved method - do not override it and if you do, always use 'super' 470 * to call parent's finishControllerInitialization. 471 */ 472 public void finishInitialization() { 473 if (navBuilder.isUsed()) { 474 log.info("Navigation graph has been altered by 'navBuilder', triggering recomputation of Floyd-Warshall path matrix..."); 475 Level oldLevel = fwMap.getLog().getLevel(); 476 fwMap.getLog().setLevel(Level.FINER); 477 fwMap.refreshPathMatrix(); 478 fwMap.getLog().setLevel(oldLevel); 479 480 aStar.mapChanged(); 481 } 482 } 483 484 /** 485 * This method is called before the SPOSH iteration is invoked. You may clear previous-state variables here. 486 */ 487 public void logicIteration() { 488 } 489 490 /** 491 * Called whenever the bot gets killed inside the game. 492 * 493 * @param event 494 */ 495 public void botKilled(BotKilled event) { 496 } 497 498 public IVisionWorldView getWorldView() { 499 return bot.getWorldView(); 500 } 501 502 public IAct getAct() { 503 return bot.getAct(); 504 } 505 506 public CompleteBotCommandsWrapper getBody() { 507 return body; 508 } 509 510 public Random getRandom() { 511 return random; 512 } 513 514 public LogCategory getLog() { 515 return log; 516 } 517 518 public UT2004AStar getAStar() { 519 return aStar; 520 } 521 522 public Game getGame() { 523 return game; 524 } 525 526 public AgentInfo getInfo() { 527 return info; 528 } 529 530 public Players getPlayers() { 531 return players; 532 } 533 534 public ItemDescriptors getDescriptors() { 535 return descriptors; 536 } 537 538 public Items getItems() { 539 return items; 540 } 541 542 public Senses getSenses() { 543 return senses; 544 } 545 546 public Weaponry getWeaponry() { 547 return weaponry; 548 } 549 550 public AgentConfig getConfig() { 551 return config; 552 } 553 554 public Raycasting getRaycasting() { 555 return raycasting; 556 } 557 558 public ImprovedShooting getShoot() { 559 return shoot; 560 } 561 562 public AdvancedLocomotion getMove() { 563 return move; 564 } 565 566 public UT2004PathExecutor<ILocated> getPathExecutor() { 567 return pathExecutor; 568 } 569 570 public IPathPlanner<ILocated> getPathPlanner() { 571 return pathPlanner; 572 } 573 574 public WeaponPrefs getWeaponPrefs() { 575 return weaponPrefs; 576 } 577 578 public NavigationGraphBuilder getNavBuilder() { 579 return navBuilder; 580 } 581 582 public AgentStats getStats() { 583 return stats; 584 } 585 586 public FloydWarshallMap getFwMap() { 587 return fwMap; 588 } 589 590 public UT2004Navigation getNavigation() { 591 return navigation; 592 } 593 594 public AnnotationListenerRegistrator getListenerRegistrator() { 595 return listenerRegistrator; 596 } 597 598 public IVisionWorldView getWorld() { 599 return world; 600 } 601 602 public UT2004GetBackToNavGraph getBackToNavGraph() { 603 return getBackToNavGraph; 604 } 605 606 public CTF getCtf() { 607 return ctf; 608 } 609 610 public Visibility getVisibility() { 611 return visibility; 612 } 613 614 public AdrenalineCombo getCombo() { 615 return combo; 616 } 617 618 }