View Javadoc

1   package cz.cuni.amis.pogamut.udk.bot.impl;
2   
3   import java.util.logging.Level;
4   
5   import cz.cuni.amis.pogamut.base.communication.command.IAct;
6   import cz.cuni.amis.pogamut.base.utils.guice.AgentScoped;
7   import cz.cuni.amis.pogamut.base.utils.logging.LogCategory;
8   import cz.cuni.amis.pogamut.base3d.worldview.IVisionWorldView;
9   import cz.cuni.amis.pogamut.udk.bot.IUDKBotController;
10  import cz.cuni.amis.pogamut.udk.communication.messages.gbcommands.Initialize;
11  import cz.cuni.amis.pogamut.udk.communication.messages.gbcommands.PasswordReply;
12  import cz.cuni.amis.pogamut.udk.communication.messages.gbinfomessages.BotKilled;
13  import cz.cuni.amis.pogamut.udk.communication.messages.gbinfomessages.ConfigChange;
14  import cz.cuni.amis.pogamut.udk.communication.messages.gbinfomessages.GameInfo;
15  import cz.cuni.amis.pogamut.udk.communication.messages.gbinfomessages.InitedMessage;
16  import cz.cuni.amis.pogamut.udk.communication.messages.gbinfomessages.Self;
17  
18  @AgentScoped
19  public class UDKBotController<BOT extends UDKBot> implements IUDKBotController<BOT> { 
20  
21  	/**
22  	 * Name of the log category of the user log.
23  	 */
24      public static final String USER_LOG_CATEGORY_ID = "User";
25  
26      /**
27       * Instance of the bot we're controlling.
28       */
29  	protected BOT bot;
30  
31      /**
32       * User log - it's log-level is initially set to {@link Level#ALL}.
33       */
34      protected LogCategory user = null;
35  
36      @Override
37      public void initializeController(BOT bot) {
38      	this.bot = bot;
39          user = bot.getLogger().getCategory(USER_LOG_CATEGORY_ID);
40          // sets the logger level, if we would let the logger level to be Level.All the bot would
41          // be slowed significantly due to high number of messages
42          bot.getLogger().setLevel(Level.WARNING);
43          // set user-log to accept every message
44          user.setLevel(Level.ALL);
45      }
46      
47      @Override
48  	public void prepareBot(BOT bot) {		
49  	}
50  
51      @Override
52  	public PasswordReply getPassword() {
53  		return new PasswordReply().setPassword("unspecified");
54  	}
55      
56      @Override
57  	public Initialize getInitializeCommand() {
58  		return new Initialize();
59  	}
60      
61      @Override
62  	public void botInitialized(GameInfo gameInfo, ConfigChange currentConfig, InitedMessage init) {
63  	}
64      
65      @Override
66  	public void botSpawned(GameInfo gameInfo, ConfigChange currentConfig, InitedMessage init, Self self) {
67  	}
68      
69  	@Override
70  	public void botKilled(BotKilled event) {		
71  	}
72  
73  	@Override
74  	public void botShutdown() {
75  	}
76  	
77  	public IVisionWorldView getWorldView() {
78  		return (IVisionWorldView) bot.getWorldView();
79  	}
80  	
81  	public IAct getAct() {
82  		return bot.getAct();
83  	}
84  
85      /**
86       * Returns user logger. This call is equivalent to <code>bot.getLogger().getCategory(USER_LOG_ID)</code>.
87       * @return
88       */
89      public LogCategory getLog() {
90          return user;
91      }
92  
93  }