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

public class WindManager : MonoBehaviour {

	public static WindManager instance;
	public Vector3 Direction;

	public float ChangeIntervall = 20F;
	private float lastChanged = 0;

	// Use this for initialization
	void Awake () {
		if(WindManager.instance == null) {
			WindManager.instance = this;
		}
	}

	void Start() {
		SetDir(new Vector3(0,0,1));
	}
	
	void SetDir(Vector3 dir) {
		lastChanged = Time.time;
		ChangeIntervall -= Mathf.Pow(ChangeIntervall*0.05F,2);

		Direction = dir;
		PlayerShipController.instance.SetWindDir(PlayerShipController.instance.NavigatorID,new Vector2(Direction.x,Direction.z));
	}
	void ChangeDir() {
		lastChanged = Time.time;
		ChangeIntervall -= Mathf.Pow(ChangeIntervall*0.05F,2);

		Direction = getRandomWind();
		PlayerShipController.instance.SetWindDir(PlayerShipController.instance.NavigatorID,new Vector2(Direction.x,Direction.z));
	}

	Vector3 getRandomWind() {
		Vector3 res = Direction;
		res.x += Random.Range(-1F,1F);
		res.y = Random.Range(0.5F,1.0F);
		return res;
	}

	// Update is called once per frame
	void Update () {
		if(Time.time >= lastChanged + ChangeIntervall) {
			ChangeDir();
		}
	}
}
