/*
 * Created on 28.12.2004
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package de.farafin.snEADy.world;

import de.farafin.snEADy.communication.D_Vec2D;
import de.farafin.snEADy.communication.I_Constants;
import de.farafin.snEADy.communication.RingVector;
import de.farafin.snEADy.GameParameter;


/**
 * @author lars, roland
 *
 * TODO what does that class do?
 * 
 */
public final class C_GSpeed extends C_Goody implements I_Constants
{
	/** how much should the player change its speed? */
	private int amount = 0;

	/**
	 * @param parameter
	 */
	protected C_GSpeed(GameParameter parameter)
	{
		super(parameter);
		// TODO Auto-generated constructor stub
	}
	/** default constructor */
	protected C_GSpeed()
	{
		super();
		this.faceDirection = FACE_NORTH;
		this.headPosition = new D_Vec2D(0, 0);
		this.nextUpdateTime = -1;
		this.amount = 0;
		this.objPositions = new RingVector();
		this.objPositions.addLast(this.headPosition.clone());
		this.ownChar = SPEED;
		this.waitCycles = -1;		
	}
	
	/** constructor */
	protected C_GSpeed(D_Vec2D pos, int amount, GameParameter parameter)
	{
		super((D_Vec2D)pos.clone(), FACE_NORTH, (amount <= 0) ? SPEED: SLOW, -1, parameter);
		this.nextUpdateTime = -1;
		this.amount = amount;
	}
	
	/* (non-Javadoc)
	 * @see de.farafin.GameParameter.world.C_GameObject#update(de.farafin.GameParameter.world.C_Arena)
	 */
	protected void update(C_Arena arena)
	{
	// TODO Auto-generated method stub

	}

	/* (non-Javadoc)
	 * @see de.farafin.GameParameter.world.C_Goody#wasEaten(de.farafin.GameParameter.world.C_Snake)
	 */
	protected void wasEatenBy(C_Snake snake)
	{
		// snake is going to be faster
		if(parameter.getMin_move_delay() < snake.waitCycles && amount <= 0)
		{
			snake.waitCycles += amount;
			snake.nextUpdateTime += amount;
			snake.getPilot().waitCycles = snake.waitCycles;
			snake.getPilot().nextUpdateTime = snake.nextUpdateTime;
		}
		
		// snake is going to be slower
		if(amount > 0 && snake.waitCycles < parameter.getMax_move_delay())
		{
			snake.waitCycles += amount;
			snake.nextUpdateTime += amount;
			snake.getPilot().waitCycles = snake.waitCycles;
			snake.getPilot().nextUpdateTime = snake.nextUpdateTime;
		}
		if(parameter.getMin_move_delay() > snake.waitCycles) snake.waitCycles =  parameter.getMin_move_delay();
		if(parameter.getMax_move_delay() < snake.waitCycles) snake.waitCycles =  parameter.getMax_move_delay();

		snake.nextAutoSlow = parameter.getGameTime() + parameter.getAuto_slowdown_delay();
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	public String toString()
	{
		// TODO Auto-generated method stub
		return null;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#clone()
	 */
	protected Object clone()
	{
		// TODO Auto-generated method stub
		return null;
	}

}
