lpackage edu.calpoly.csc480.Corral.Seer;

import java.awt.*;

import edu.calpoly.csc480.Corral.Agent.*;
import edu.calpoly.csc480.Corral.Agent.Util.*;
import edu.calpoly.csc480.Corral.Area.*;
import edu.calpoly.csc480.Corral.Tile.*;

public class Seer extends BaseSeer
{
	public Seer() {
		super();
	}
	
	protected BaseMeans means;
	protected BaseTile tiles[][];

	protected LifeReceiver lifeRC;
	protected TileReceiver tileRC;

	protected NodeCallback nodeCB;
	protected HintCallback hintCB;

	protected BaseArea makeArea()				{return new Area();}
	protected BaseRules makeRules()			{return new BaseRules();}
	protected BaseSeerView makeView()		{return new SeerView();}

	public void initBeans() {
		BaseAgent agent;

		area.initMeans();
		means = area.getMeans();
		tiles = area.getTiles().getTiles();

		agent = means.getAgent();

		nodeCB = new NodeCallback(this);
		hintCB = new HintCallback(this);

		if (agent instanceof LifeReceiver) {lifeRC = (LifeReceiver)agent;}
		if (agent instanceof TileReceiver) {tileRC = (TileReceiver)agent;}

		if (agent instanceof NodeProducer) {
			((NodeProducer)agent).setCallback(nodeCB);
		}

		if (agent instanceof HintProducer) {
			((HintProducer)agent).setCallback(hintCB);
		}

		lifeRC.receive(
		 ((Area)area).getDawnTile(),
		 new State(means.getLocation(), means.getDirection()));
	}

	protected void cycle() {
		Point agent, drift;

		agent = means.getLocation();
		drift = means.getDirection().getPoint();

		tileRC.receive(tiles[agent.y + drift.y][agent.x + drift.x]);
	}
}