using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TargetWaypoint : Waypoint {
	private Vertex oldPosition;
	private DeployedUnit unit;
	private DeployedUnit target;
	private float distance;
	private float altitude;

	public TargetWaypoint(DeployedUnit unit, DeployedUnit target, float distance, float altitude) {
		this.unit = unit;
		this.target = target;
		this.distance = distance;
		this.altitude = altitude;

		this.oldPosition = getVertex();
	}

	override public Vertex getVertex() {
		Vector direction = (unit.getPosition() - target.getPosition());
		Vector flatDirection = (new Vector(direction.x(), direction.y(), 0.0f)).normalized();

		return target.getPosition() + flatDirection * distance + new Vector(0, 0, 1.0f) * altitude;
	}

	public DeployedUnit getUnit() {
		return unit;
	}

	public DeployedUnit getTarget() {
		return target;
	}

	public float getDistance() {
		return distance;
	}

	public float getAltitude() {
		return altitude;
	}

	override public bool isTooFar() {
		return oldPosition.distance(getVertex()) > Constants.MIN_DISTANCE_WAYPOINTS_UPDATE;
	}

	override public bool isValid() {
		return GameController.fromID(unit.getID()) != null && GameController.fromID(target.getID()) != null;
	}

	override public void resetInfo() {
		oldPosition = getVertex();
	}
}
