View Javadoc

1   package cz.cuni.amis.pogamut.ut2004.bot.impl;
2   
3   import java.util.logging.Level;
4   
5   import com.google.inject.Inject;
6   
7   import cz.cuni.amis.pogamut.base.communication.command.IAct;
8   import cz.cuni.amis.pogamut.base.communication.worldview.react.EventReactOnce;
9   import cz.cuni.amis.pogamut.base.utils.guice.AgentScoped;
10  import cz.cuni.amis.pogamut.base.utils.logging.LogCategory;
11  import cz.cuni.amis.pogamut.base3d.worldview.IVisionWorldView;
12  import cz.cuni.amis.pogamut.ut2004.bot.IUT2004BotController;
13  import cz.cuni.amis.pogamut.ut2004.communication.messages.ItemTypeTranslator;
14  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbcommands.Initialize;
15  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbcommands.PasswordReply;
16  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.BotKilled;
17  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.ConfigChange;
18  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.GameInfo;
19  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.InitedMessage;
20  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.Item;
21  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.MapListEnd;
22  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.NavPoint;
23  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.Self;
24  import cz.cuni.amis.pogamut.ut2004.communication.translator.shared.events.MapPointListObtained;
25  
26  @AgentScoped
27  public class UT2004BotController<BOT extends UT2004Bot> implements IUT2004BotController<BOT> { 
28  
29  	/**
30  	 * Name of the log category of the user log.
31  	 */
32      public static final String USER_LOG_CATEGORY_ID = "User";
33  
34      /**
35       * Instance of the bot we're controlling.
36       */
37  	protected BOT bot;
38  
39      /**
40       * Alias for user's log.
41       */
42      protected LogCategory log = null;
43      
44      private EventReactOnce<MapPointListObtained> onceMapPointListObtained;
45  
46      @Override
47      public void initializeController(BOT bot) {
48      	this.bot = bot;
49          log = bot.getLogger().getCategory(USER_LOG_CATEGORY_ID);
50          // set user-log to accept every message
51          log.setLevel(Level.ALL);
52          
53          onceMapPointListObtained = new EventReactOnce<MapPointListObtained>(MapPointListObtained.class, bot.getWorldView()) {
54      		@Override
55      		protected void react(MapPointListObtained event) {
56      			mapInfoObtainedInternal();
57      		}
58      	};
59      }
60      
61      @Override
62  	public void prepareBot(BOT bot) {		
63  	}
64  
65      @Override
66  	public PasswordReply getPassword() {
67  		return new PasswordReply().setPassword("unspecified");
68  	}
69      
70      void mapInfoObtainedInternal() {
71      	mapInfoObtained();
72      }
73      
74      @Override
75      public void mapInfoObtained() {    	
76      }
77      
78      @Override
79  	public Initialize getInitializeCommand() {
80  		return new Initialize();
81  	}
82      
83      @Override
84  	public void botInitialized(GameInfo gameInfo, ConfigChange currentConfig, InitedMessage init) {
85  	}
86      
87      @Override
88  	public void botFirstSpawn(GameInfo gameInfo, ConfigChange currentConfig, InitedMessage init, Self self) {
89  	}
90      
91      @Override
92  	public void finishControllerInitialization() {
93  	}
94      
95  	@Override
96  	public void botKilled(BotKilled event) {		
97  	}
98  
99  	@Override
100 	public void botShutdown() {
101 	}
102 	
103 	@Override
104 	public IVisionWorldView getWorldView() {
105 		return bot.getWorldView();
106 	}
107 	
108 	@Override
109 	public IAct getAct() {
110 		return bot.getAct();
111 	}
112 	
113 	@Override
114 	public BOT getBot() {
115 		return bot;
116 	}
117 	
118 	public UT2004BotName getName() {
119 		return bot.getBotName();
120 	}
121 
122     @Override
123     public LogCategory getLog() {
124         return log;
125     }
126 
127 }