package edu.calpoly.csc480.Corral.Agent;

import java.awt.*;
import java.io.*;

import com.bcurry.www.lang.*;
import edu.calpoly.csc480.Corral.Agent.*;
import edu.calpoly.csc480.Corral.Agent.Util.*;
import edu.calpoly.csc480.Corral.Area.*;

public abstract class BaseMeans
{
	public BaseMeans(BaseAgent agent) {
		this.agent = agent;
		this.teleported = false;
		
		view = makeView();
		view.setDocument(this);
	}

	final public boolean hasTeleported() {
		return (!lastLocation.equals(location));
	}

	final public BaseAgent getAgent()				{return agent;}
	final public BaseArea getOwner()					{return area;}
	final public BaseMeansView getView()			{return view;}

	final public Direction getDirection()			{return direction;}
	final public long getLifespan()					{return lifespan;}
	final public Point getLocation()					{return location;}
	final public Point getLastLocation()			{return lastLocation;}
	
	public void setOwner(BaseArea area) {
		this.area = area;
		view.setOwner(area.getView());
	}
	
	public void setLifespan(long lifespan) {
		this.lifespan = lifespan;
	}
	
	public void setDirection(Direction direction) {
		this.direction = direction;
	}
	
	public void setLocation(Point location) {
	}

	public void setTeleportation(Point location) {
		this.lastLocation = (this.location == null ? location : this.location);
		this.location = location;
	}

	public void write(PrintWriter out) {
		out.println("lifespan:  " + lifespan);
		out.println("location:  " + location);
	}
	
	protected BaseAgent agent;
	protected BaseArea area;
	protected BaseMeansView view;
	
	protected boolean teleported;

	protected long lifespan;
	protected Direction direction;
	protected Point location, lastLocation;

	abstract protected BaseMeansView makeView();	
}