public class ResponsiveBot
extends cz.cuni.amis.pogamut.ut2004.bot.impl.UT2004BotModuleController
Notice that we're using a special annotations
for various methods, i.e., for the method bumped(Bumped)
the annotation EventListener, for the method playerAppeared(WorldObjectAppearedEvent)
we're using ObjectClassEventListener, etc. You may perceive is as a bit magic as
some methods are called as a response to some event, e.g., the method bumped(Bumped)
is called whenever GameBots2004 sends a message Bumped to the bot.
How is this possible?
Well, the UT2004BotModuleController
is using AnnotationListenerRegistrator that introspects (via Java
Reflection API) the methods declared by the ResponsiveBot looking for
annotations: EventListener, ObjectClassEventListener,
ObjectClassListener, ObjectEventListener or ObjectListener
(I recommend you to read javadoc for all of them) automatically registering a
listener inside UT2004BotController.getWorldView() using one of the
"addListener" methods (e.g. EventListener annotated method is recalled
from listener added via IWorldView.addEventListener(java.lang.Class, cz.cuni.amis.pogamut.base.communication.worldview.event.IWorldEventListener).
It provides you with a simple way how to create methods that reacts on certain events inside the game.
WARNING: these annotations works only in THIS class only. If you want other of your classes to have the
same option, you will have to instantiate AnnotationListenerRegistrator for yourself
within that class.
We advise you to read through all comments carefully and try to understand
when EventListener suffices and when you need to use one
of ObjectClassEventListener /
ObjectClassListener / ObjectEventListener / ObjectListeners.
The trick is that some messages from GB2004 are IWorldEvents only and some of them are IWorldObjects as well.
For listening IWorldEvents only you must use EventListener, for listening to object updates,
you must use one of ObjectClassEventListener / ObjectClassListener / ObjectEventListener / ObjectListeners.
We recommend you to run the bot on DM-TrainingDay map.
Start the bot and run to it. Note that whenever the bot sees you (you enter bot's field of view}
playerAppeared(cz.cuni.amis.pogamut.base3d.worldview.object.event.WorldObjectAppearedEvent) will be triggered
and the bot will greet you.
Then try to approach very close to the bot and it will ask you "what do you want". See playerUpdated(cz.cuni.amis.pogamut.base.communication.worldview.object.event.WorldObjectUpdatedEvent)
event listener method.
Check out comments inside gb2004BatchEnd(cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.EndMessage) message.
| Modifier and Type | Field and Description |
|---|---|
protected boolean |
wasCloseBefore
Flag indicating whether the player was also close to the bot last time it
was updated.
|
act, body, combo, config, ctf, descriptors, fwMap, game, getBackToNavGraph, info, items, listenerRegistrator, move, navBuilder, navigation, pathExecutor, pathPlanner, players, random, raycasting, runStraight, senses, shoot, stats, visibility, weaponPrefs, weaponry, world| Constructor and Description |
|---|
ResponsiveBot() |
| Modifier and Type | Method and Description |
|---|---|
void |
beforeFirstLogic()
This method is called only once right before actual logic() method is
called for the first time.
|
void |
botFirstSpawn(cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.GameInfo gameInfo,
cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.ConfigChange config,
cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.InitedMessage init,
cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.Self self)
The bot is initialized in the environment - a physical representation of
the bot is present in the game.
|
void |
botKilled(cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.BotKilled event)
Called each time our bot die.
|
protected void |
bumped(cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.Bumped event)
Listener called when someone/something bumps into the bot.
|
void |
gameInfo1(cz.cuni.amis.pogamut.base.communication.worldview.object.IWorldObjectEvent<cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.GameInfo> gameInfoEvent)
Example usage of
ObjectListener that will listen on every change
/ event that will be raised on the concrete IWorldObject, in this
case on the GameInfo. |
void |
gameInfo2(cz.cuni.amis.pogamut.base.communication.worldview.object.event.WorldObjectUpdatedEvent<cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.GameInfo> gameInfoEvent)
Example usage of
ObjectEventListener that will listen on SPECIFIC
event that is raised on the concrete IWorldObject. |
void |
gb2004BatchEnd(cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.EndMessage event)
If you uncomment
EventListener annotation below this comment, this message
will be triggered every time the GB2004 sends EndMessage to you. |
cz.cuni.amis.pogamut.ut2004.communication.messages.gbcommands.Initialize |
getInitializeCommand()
Here we can modify initialize command for our bot if we want to.
|
void |
logic()
Main method that controls the bot - makes decisions what to do next.
|
static void |
main(String[] args)
This method is called when the bot is started either from IDE or from
command line.
|
protected void |
playerAppeared(cz.cuni.amis.pogamut.base3d.worldview.object.event.WorldObjectAppearedEvent<cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.Player> event)
Listener called when a player appears.
|
void |
playerEvent(cz.cuni.amis.pogamut.base.communication.worldview.object.IWorldObjectEvent<cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.Player> playerEvent)
Example usage of
ObjectClassListener notice the difference
between this listener and ObjectClassEventListener that is used
on playerAppeared(WorldObjectAppearedEvent). |
protected void |
playerUpdated(cz.cuni.amis.pogamut.base.communication.worldview.object.event.WorldObjectUpdatedEvent<cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.Player> event)
Listener called each time a player is updated.
|
void |
prepareBot(cz.cuni.amis.pogamut.ut2004.bot.impl.UT2004Bot bot)
Initialize all necessary variables here, before the bot actually receives
anything from the environment + hook up your custom listener.
|
finishControllerInitialization, getBody, getCombo, getConfig, getDescriptors, getFwMap, getGame, getInfo, getItems, getMove, getNavBuilder, getNavigation, getPathExecutor, getPathPlanner, getPlayers, getRandom, getRaycasting, getSenses, getShoot, getStats, getVisibility, getWeaponPrefs, getWeaponry, getWorld, initializeController, initializeListeners, initializeModules, initializePathFindinggetLogicInitializeTime, getLogicShutdownTime, initializeLogic, logicInitialize, logicShutdownbotInitialized, botShutdown, getAct, getBot, getLog, getPassword, getWorldViewprotected boolean wasCloseBefore
protected void bumped(cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.Bumped event)
We're using EventListener here that is registered by the AnnotationListenerRegistrator
to listen for Bumped events.
Notice that Bumped is IWorldEvent only, it's not IWorldObject,
thus we're using EventListener.
protected void playerAppeared(cz.cuni.amis.pogamut.base3d.worldview.object.event.WorldObjectAppearedEvent<cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.Player> event)
We're using ObjectClassEventListener here that is registered by the AnnotationListenerRegistrator to
listen on all WorldObjectAppearedEvent that happens on any object
of the class Player.
I.e., whenever the GameBots2004 sends an
update about arbitrary Player object in the game notifying us that the
player has become visible (it's Player.isVisible() is switched to
true and the WorldObjectAppearedEvent is generated), this method
is called.
Notice that Player implements IWorldObject thus you CANNOT use
EventListener to catch events that updates Player objects.
protected void playerUpdated(cz.cuni.amis.pogamut.base.communication.worldview.object.event.WorldObjectUpdatedEvent<cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.Player> event)
Again, we're using ObjectClassEventListener
that is registered by the AnnotationListenerRegistrator to listen
on all WorldObjectUpdatedEvent that happens on any object of the
class Player.
I.e., whenever the GameBots2004 sends an update
about arbitrary Player in the game notifying us that some
information about the player has changed (the WorldObjectUpdatedEvent
is generated), this method is called.
Again, Player implements IWorldObject, thus you CANNOT use
EventListener annotation to check for events regarding Player
objects.
public void gameInfo1(cz.cuni.amis.pogamut.base.communication.worldview.object.IWorldObjectEvent<cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.GameInfo> gameInfoEvent)
ObjectListener that will listen on every change
/ event that will be raised on the concrete IWorldObject, in this
case on the GameInfo.
Notice that we have to specify which ID class the world object is using and have explicit representation of it's id - note that this is totally unsuitable for any dynamic IDs, such as NavPoint ids, etc... you will probably never use this annotation.
See implementations of IWorldObjectEvent, which are
WorldObjectFirstEncounteredEvent, WorldObjectAppearedEvent,
WorldObjectUpdatedEvent, WorldObjectDisappearedEvent
and WorldObjectDestroyedEvent. All such events may be possibly
caught by this ObjectListener annotated method.
info - public void gameInfo2(cz.cuni.amis.pogamut.base.communication.worldview.object.event.WorldObjectUpdatedEvent<cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.GameInfo> gameInfoEvent)
ObjectEventListener that will listen on SPECIFIC
event that is raised on the concrete IWorldObject. As is the case
of gameInfo1(IWorldObjectEvent), you will probably
never use this.gameInfoEvent - public void playerEvent(cz.cuni.amis.pogamut.base.communication.worldview.object.IWorldObjectEvent<cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.Player> playerEvent)
ObjectClassListener notice the difference
between this listener and ObjectClassEventListener that is used
on playerAppeared(WorldObjectAppearedEvent).
This method will receive ALL events that are raised on any Player
object whereas playerAppeared(WorldObjectAppearedEvent)
will receive only WorldObjectAppearedEvent.
See implementations of IWorldObjectEvent, which are
WorldObjectFirstEncounteredEvent, WorldObjectAppearedEvent,
WorldObjectUpdatedEvent, WorldObjectDisappearedEvent
and WorldObjectDestroyedEvent. All such events may be possibly
caught by this ObjectListener annotated method.
playerEvent - public void gb2004BatchEnd(cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.EndMessage event)
EventListener annotation below this comment, this message
will be triggered every time the GB2004 sends EndMessage to you. It will (more-less)
act the same way as logic() method.event - public void prepareBot(cz.cuni.amis.pogamut.ut2004.bot.impl.UT2004Bot bot)
prepareBot in interface cz.cuni.amis.pogamut.ut2004.bot.IUT2004BotControllerprepareBot in class cz.cuni.amis.pogamut.ut2004.bot.impl.UT2004BotControllerpublic cz.cuni.amis.pogamut.ut2004.communication.messages.gbcommands.Initialize getInitializeCommand()
getInitializeCommand in interface cz.cuni.amis.pogamut.ut2004.bot.IUT2004BotControllergetInitializeCommand in class cz.cuni.amis.pogamut.ut2004.bot.impl.UT2004BotControllerpublic void botFirstSpawn(cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.GameInfo gameInfo,
cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.ConfigChange config,
cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.InitedMessage init,
cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.Self self)
botFirstSpawn in interface cz.cuni.amis.pogamut.ut2004.bot.IUT2004BotControllerbotFirstSpawn in class cz.cuni.amis.pogamut.ut2004.bot.impl.UT2004BotControllerconfig - information about configurationinit - information about configurationpublic void beforeFirstLogic()
botFirstSpawn(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, cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.Self).beforeFirstLogic in interface cz.cuni.amis.pogamut.base.agent.module.IAgentLogicbeforeFirstLogic in class cz.cuni.amis.pogamut.ut2004.bot.impl.UT2004BotLogicControllerpublic void logic()
throws cz.cuni.amis.utils.exception.PogamutException
Notice that the method is empty as this bot is completely event-driven.
logic in interface cz.cuni.amis.pogamut.base.agent.module.IAgentLogiclogic in class cz.cuni.amis.pogamut.ut2004.bot.impl.UT2004BotLogicControllercz.cuni.amis.utils.exception.PogamutExceptionpublic void botKilled(cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.BotKilled event)
botKilled in interface cz.cuni.amis.pogamut.ut2004.bot.IUT2004BotControllerbotKilled in class cz.cuni.amis.pogamut.ut2004.bot.impl.UT2004BotControllerevent - public static void main(String[] args) throws cz.cuni.amis.utils.exception.PogamutException
args - cz.cuni.amis.utils.exception.PogamutExceptionCopyright © 2012 AMIS research group, Faculty of Mathematics and Physics, Charles University in Prague, Czech Republic. All Rights Reserved.