using UnityEngine;
using System.Collections;

public class TileScript : MonoBehaviour {
	
	public int type = 0;
	
	// TYPES:
	// 0 - Empty
	// 1 - EW
	// 2 - NS
	// 3 - NE
	// 4 - SE
	// 5 - SW
	// 6 - NW
	// 7 - SEW
	// 8 - NSW
	// 9 - NEW
	// 10 - NSE
	// 11 - NESW
	// 12 - Wire EW
	// 13 - Wire NS
	// 14 - Resist EW
	// 15 - Resist NS
	// 16 - Battery
	// 17 - Timer
	// 18 - Death
	// 19 - Safe
	
	public ControlScript CS;
	public bool iswire = false;
	public Material cuttex = null;
	public bool powered = false;
	public bool cut = false;
	public ParticleSystem warning = null;

	// Use this for initialization
	void Start () {
		CS = GameObject.FindGameObjectWithTag ("Control").GetComponent<ControlScript>();

		if ((type == 12) || (type == 13)) {
			iswire = true;
		} else if ((type == 17) || (type == 18)) {
			GameObject[] wlook;
			wlook = GameObject.FindGameObjectsWithTag ("Warning");
			foreach (GameObject wfind in wlook) {
				if ((wfind.transform.position.x == transform.position.x) && (wfind.transform.position.z == transform.position.z)) {
					warning = wfind.GetComponent<ParticleSystem>();
				}
			}
		}
	}
	
	void OnMouseDown () {
		// Cut the wire if it's type 12 or 13
		if ((CS.ingame) && (iswire) && (!cut)) {
			cut = true;
			renderer.material = cuttex;
			AudioSource.PlayClipAtPoint (CS.snip,CS.transform.position);
			CS.ResetPower ();
		}
	}
	
	// Update is called once per frame
	void Update () {
	
	}
}
