using UnityEngine;
using System.Collections;

public class States : MonoBehaviour {

	public bool cursorFlag = true;
	public bool controllerFlag = true;
	public bool mouselookFlag = true;
	public bool pauseFlag = false;
	public bool selling = false;
	public int tableMoney = 0;
	public int playerMoney = 0;
	public bool medicated = false;
	public int pills;
	public int missedPills;
	public int water = 1;
	public int dailyWater;
	public int tankWater;
	
	public int sleepCount;
	public int plantWaterCount;

	private Component[] mouseLook;
	//private ZoomFOV zoomFOV;
	private CharacterController controller1;
	private FPSInputController controller2;
	private CharacterMotor controller3;

	// Use this for initialization
	void Start () {
		//Store controller components
		mouseLook = gameObject.GetComponentsInChildren<MouseLook>();
		//zoomFOV = gameObject.GetComponent<ZoomFOV>();
		controller1 = gameObject.GetComponent<CharacterController>();
		controller2 = gameObject.GetComponent<FPSInputController>();
		controller3 = gameObject.GetComponent<CharacterMotor>();
	}
	
	// Update is called once per frame
	void Update () {
		CursorLock ();
		ControllerLock ();
		MouselookLock ();
	}

	//Locks the cursor to the game
	void CursorLock ()
	{
		if (cursorFlag && !pauseFlag)
		{
			Screen.lockCursor = true;
		} else {
			Screen.lockCursor = false;
		}
	}

	//Locks the movement controls on or off
	void ControllerLock ()
	{
		if (controllerFlag && !pauseFlag)
		{
			controller1.enabled = true;
			controller2.enabled = true;
			controller3.enabled = true;
		} else {
			controller1.enabled = false;
			controller2.enabled = false;
			controller3.enabled = false;
		}
	}

	//Locks the first person mouselook on or off
	void MouselookLock ()
	{
		if (mouselookFlag && !pauseFlag)
		{
			foreach (MouseLook mL in mouseLook) {
				mL.enabled = true;
			}
			//zoomFOV.enabled = true;
		} else {
			foreach (MouseLook mL in mouseLook) {
				mL.enabled = false;
			}
			//zoomFOV.enabled = false;
		}
	}
}
