package simogl.resource;

/**
 * This class represents an abstract resource. Concrete resources like 
 * gold or food can be generated by extending this class.
 * @author Frank Bruns
 *
 */
public abstract class AbstractResource
{
	private int resourceAmount = 0;
	
	/**
	 * This is the intervall of time in miliseconds in which
	 * calculations on resources will be performed, effecting the
	 * amount of the player's resources
	 */
	private long intervall;
	protected long cumulatedTime = 0L;
	
	/**
	 * Creates a new resource with the specified initial amount.
	 * @param amount initial amount of the resource
	 * @param intervall intervall of time in miliseconds in which
	 * calculations on resources will be performed, effecting the
	 * amount of the player's resources
	 */
	public AbstractResource(int amount, long intervall)
	{
		this.resourceAmount = amount;
		this.intervall = intervall;
	}
	
	/**
	 * Returns the intervall on which the resource gets recalculated
	 * @return intervall of recalculation of the resource's amount
	 */
	public long getUpdateIntervall()
	{
		return this.intervall;
	}
	
	/**
	 * Sets the new intervall on which the resource gets recalculated
	 * @param intervall new intervall for recalculating the resource's 
	 * amount
	 */
	public void setUpdateIntervall(long intervall)
	{
		this.intervall = intervall;
	}
	
	/**
	 * Returns the current amount of the resource
	 * @return current amount of the resource
	 */
	public int getCurrentAmount()
	{
		return this.resourceAmount;
	}
	
	/**
	 * Sets the current amount of the resource to the specified value
	 * @param amount new current amount of the resource
	 */
	public void setCurrentAmount(int amount)
	{
		this.resourceAmount = amount;
	}
	
	/**
	 * Increase the resource about the specified amount
	 * @param amount amount to increase the resource
	 */
	public void increase(int amount)
	{
		this.resourceAmount += amount;
	}
	
	/**
	 * Decrease the resource about the specified amount
	 * @param amount amount to decrease the resource
	 */
	public void decrease(int amount)
	{
		this.resourceAmount -= amount;
	}
	
	/**
	 * Recalculates the available amount of the resource
	 * @param elapsedTime time between two calls of the updater thread
	 */
	public abstract void update(long elapsedTime);
}
