View Javadoc

1   package cz.cuni.amis.pogamut.defcon.agent.impl;
2   
3   import com.google.inject.Inject;
4   
5   import cz.cuni.amis.pogamut.base.utils.guice.AgentScoped;
6   import cz.cuni.amis.pogamut.base.utils.logging.LogCategory;
7   import cz.cuni.amis.pogamut.defcon.agent.DefConAgent;
8   import cz.cuni.amis.pogamut.defcon.agent.IDefConAgentController;
9   import cz.cuni.amis.pogamut.defcon.agent.module.sensor.GameInfo;
10  import cz.cuni.amis.pogamut.defcon.communication.command.impl.DefConAct;
11  import cz.cuni.amis.pogamut.defcon.communication.messages.commands.DefConCommand;
12  import cz.cuni.amis.pogamut.defcon.communication.worldview.DefConWorldView;
13  
14  /**
15   * Basic implementation of controller, does some basic stuff like assigning of logger
16   * @author Radek 'Black_Hand' Pibil
17   *
18   * @param <AGENT> Controlled agent
19   */
20  @AgentScoped
21  public class DefConAgentController<AGENT extends DefConAgent>
22  	implements IDefConAgentController<AGENT> {
23  
24      private static final String USER_LOG_ID = "User";
25  
26  	protected AGENT agent;
27  	
28      /**
29       * User log.
30       */
31      private LogCategory user = null;
32      
33      @Inject
34      public DefConAgentController() {
35      
36      }
37  
38      @Override
39  	public void initializeController(AGENT agent) {
40  		this.agent = agent;
41          user = agent.getLogger().getCategory(USER_LOG_ID);
42  	}
43  
44  	@Override
45  	public void botStopped() {
46  	}
47  	
48  	/**
49  	 * Casts worldview into a friendlier type.
50  	 * @return WorldView
51  	 */
52  	public DefConWorldView getWorldView() {
53  		return (DefConWorldView) agent.getWorldView();
54  	}
55  	
56  	/**
57  	 * Returns the game info object used to query the game.
58  	 * 
59  	 * @return
60  	 */
61  	public GameInfo getGameInfo() {
62  		return (GameInfo) getWorldView().getGameInfo();
63  	}
64  	
65  	public DefConAct getAct() {
66  		return (DefConAct) agent.getAct();
67  	}
68  	
69  	/**
70  	 * Simplifies access to IAct. No need to use getAct().act().
71  	 */
72  	public void act(DefConCommand command) {
73  		agent.act(command);
74  	}	
75  
76      /**
77       * Returns user logger. This call is equivalent to <code>bot.getLogger().getCategory(USER_LOG_ID)</code>.
78       * @return
79       */
80      public LogCategory getLog() {
81          return user;
82      }
83  	
84  }