package agents;

import gameObjects.Player;
import knowledgeAndTechnics.Intelligence;
import knowledgeAndTechnics.NoFreePlayerException;


/*
 * Created on Oct 12, 2004
 *
 */

/*******************************************************************************
 * Steht nur dumm rum
 * 
 * @author wir
 *  
 ******************************************************************************/
public class U01_GoalieAgent extends Agent {
    int lastTime;
    public void playerInitialization() {
    	baseFunctions.init(infoPool.getTeamName(),true);

        //Die Startposition
        infoPool.setXPlayerStart(-52.5);
        infoPool.setYPlayerStart(0);

        // Die Ruheposition
        infoPool.setXPlayerHome(-7);
        infoPool.setYPlayerHome(25);
        // Der Handlungsbereich
        infoPool.setX1PlayerActingField(-57.5);
        infoPool.setY1PlayerActingField(-39);
        infoPool.setX2PlayerActingField(57.5);
        infoPool.setY2PlayerActingField(39);
        // weitere Variablen
        infoPool.setX1PlayerFreeKickField(-60); //außerhalb, damit er nix tut
        infoPool.setY1PlayerFreeKickField(-60);
        infoPool.setX2PlayerFreeKickField(-60);
        infoPool.setY2PlayerFreeKickField(-60);
    }

    public U01_GoalieAgent(String[] args) {
        super(args);
    }

      			
    public void handleFreeKickWe(){
    	if (infoPool.getBallPossession() == Intelligence.BALL_POSSESSION_ME){
    		infoPool.goalieFreeKickAction();	
    	} else {
    		infoPool.goalieGoToPosition();
    	}
	}

    public void handleGoalKickWe(){
		baseFunctions.turnNeckWithoutWaiting(0);
		baseFunctions.changeViewWithoutWaiting("normal","high");
		infoPool.setBallPossession(Intelligence.BALL_POSSESSION_ME);
		infoPool.runToBall(100,200);
		try{
		    infoPool.resetLastKickTime();
			Player freePlayer = infoPool.findFreePlayer();
			infoPool.resetLastKickTime();
		    infoPool.passToFreePlayer(freePlayer);
		} catch (NoFreePlayerException e){
		    infoPool.kickToGoal(); 
		}
    }
    
    public void handlePlayOn() {
    	
        while ((infoPool.getSeeTime() - infoPool.getBall().getLastSeenTime()) > 5 ){
            baseFunctions.changeViewWithoutWaiting("wide", "high");
            baseFunctions.turnNeckRelToBodyWithoutWaiting(0);
            baseFunctions.turnAbs(0);
            baseFunctions.changeViewWithoutWaiting("normal", "high");
            if ((infoPool.getSeeTime() - infoPool.getBall().getLastSeenTime()) > 5 ){
                infoPool.coordinateDefense();
            }
    	}
        if (
    		(infoPool.getBall().getDist() > 30)    		
    	){
    		infoPool.coordinateDefense();
    	} else infoPool.goalieGoToPosition();
    }
           
    public static void main(String[] args) {
        U01_GoalieAgent d = new U01_GoalieAgent(args);
        d.start();
    }
}