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

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

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

		this.oldPosition = getVertex();
	}

	override public Vertex getVertex() {
		Vector direction = new Vector(Mathf.Cos(target.getAngle()), Mathf.Sin(target.getAngle()), 0);

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

	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(target.getID()) != null;
	}

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