CPD Results

The following document contains the results of PMD's CPD 4.2.5.

Duplications

FileLine
cz/cuni/amis/pogamut/sposh/context/UT2004Context.java318
cz/cuni/amis/pogamut/ut2004/bot/sposh/UT2004Behaviour.java326
	protected void initializeBehaviour(BOT bot) {
		initializeModules(bot);
		initializePathFinding(bot);
		initializeListeners(bot);
	}
	
	/**
     * Initializes {@link UT2004Behaviour#listenerRegistrator} and calls {@link AnnotationListenerRegistrator#addListeners()} method
     * to probe all declared methods for event-annotation presence.
     * @param bot
     */
	protected void initializeListeners(BOT bot) {
		listenerRegistrator = new AnnotationListenerRegistrator(this, getWorldView(), bot.getLogger().getCategory("Listeners"));
		listenerRegistrator.addListeners();
	}

	/**
	 * Initializes path-finding modules: {@link UT2004BotModuleControllerNew#pathPlanner} and {@link UT2004BotModuleControllerNew#pathExecutor}.
	 * If you need different path planner / path executor - override this method and initialize your own modules.
	 * @param bot
	 */
	protected void initializePathFinding(BOT bot) {
		pathPlanner  = new UT2004AStarPathPlanner(bot);
		fwMap        = new FloydWarshallMap(bot);
		pathExecutor = 
        	new UT2004PathExecutor<ILocated>(
        		bot, 
        		new LoqueNavigator<ILocated>(bot, 
        			new KefikRunner(bot, info, move, bot.getLog()), 
        		bot.getLog())
        	);   
		getBackToNavGraph = new UT2004GetBackToNavGraph(bot, info, move);
		navigation = new UT2004Navigation(bot, pathExecutor, fwMap, getBackToNavGraph, runStraight);
	}

	/**
	 * Initializes memory/command modules of the bot.
	 * 
	 * @param bot
	 */
	protected void initializeModules(BOT bot) {
		world       = getWorldView();
		act         = getAct();
		game        = new Game(bot);
		info        = new AgentInfo(bot, game);
		players     = new Players(bot);
		descriptors = new ItemDescriptors(bot);
		senses      = new Senses(bot, info, players);
		weaponry    = new Weaponry(bot, descriptors);
		items       = new Items(bot, info, game, weaponry, null);
		config      = new AgentConfig(bot);
		raycasting  = new Raycasting(bot);
		body        = new CompleteBotCommandsWrapper(bot, weaponry, null);		
		shoot       = body.getImprovedShooting();
		move        = body.getLocomotion();
		weaponPrefs = new WeaponPrefs(weaponry, bot);
		stats       = new AgentStats(bot);
		navBuilder  = new NavigationGraphBuilder(bot);
	}
	
	/**
	 * Called after the behaviour construction to initialize user's data structures.
	 * @param bot
	 */
	protected void prepareBehaviour(BOT bot) {		
	}	
	
	/**
     * This method is called whenever {@link InitedMessage} is received. Various agent modules are usable since this
     * method is called.
     * 
     * @param gameInfo
     * @param config
     * @param init
     * @param self
     */
    public void botInitialized(GameInfo info, ConfigChange config, InitedMessage init) {
    }

    /**
     * This method is called only once whenever first batch of information what the bot can see is received.
     * <i><i>
     * It is sort of "first-logic-method" where you may issue commands for the first time and handle everything
     * else in bot's logic then. It eliminates the need to have 'boolean firstLogic' field inside your bot.
     * <p><p>
     * Note that this method has advantage over the {@link IUT2004BotController#botInitialized(GameInfo, ConfigChange, InitedMessage)}
     * that you already have {@link Self} object.
     * 
     * @param gameInfo
     * @param config
     * @param init
     * @param self
     */
    public void botSpawned(GameInfo gameInfo, ConfigChange config, InitedMessage init, Self self) {
    }
    
    /**
	 * Called after {@link UT2004Behaviour#botSpawned(GameInfo, ConfigChange, InitedMessage, Self)} as a hook for Pogamut's core developers
	 * to finalize initialization of various modules.
	 * <p><p>
	 * <b>NOTE:</b> This is Pogamut's developers reserved method - do not override it and if you do, always use 'super' 
	 * to call parent's finishControllerInitialization.
     */
    public void finishBehaviourInitialization() {
FileLine
cz/cuni/amis/pogamut/sposh/context/UT2004Context.java421
cz/cuni/amis/pogamut/ut2004/bot/sposh/UT2004Behaviour.java429
    public void finishBehaviourInitialization() {
    	if (navBuilder.isUsed()) {
			log.info("Navigation graph has been altered by 'navBuilder', triggering recomputation of Floyd-Warshall path matrix...");
			Level oldLevel = fwMap.getLog().getLevel();
			fwMap.getLog().setLevel(Level.FINER);
			fwMap.refreshPathMatrix();
			fwMap.getLog().setLevel(oldLevel);
		}
    }
    
    /**
     * This method is called before the SPOSH iteration is invoked. You may clear previous-state variables here.
     */
    public void logicIteration() {    	
    }
    
    /**
     * Called whenever the bot gets killed inside the game.
     * 
     * @param event
     */
	public void botKilled(BotKilled event) {		
	}
	
	public IVisionWorldView getWorldView() {
		return bot.getWorldView();
	}
	
	public IAct getAct() {
		return bot.getAct();
	}

	public UT2004GetBackToNavGraph getGetBackToNavGraph() {