
using UnityEngine;
using System.Collections;

public class CreateCops : MonoBehaviour
{

    public static CreateCops instance;

	public int baseCopCount, copCountIncrease, baseDrugCount, drugCountIncrease;
	public GameObject copObject, drugObject;

    void Awake()
    {
        instance = this;
    }

	void Start()
	{
        spawn();
	}


    public void spawn()
    {

        int copCount = baseCopCount + (GameController.instance.day * copCountIncrease),
            drugCount = baseDrugCount + (GameController.instance.day * drugCountIncrease);

        GameObject[] cops = GameObject.FindGameObjectsWithTag("Cop"), drugs = GameObject.FindGameObjectsWithTag("Drug");

        if (copCount > cops.Length)
        {
            for (int i = 0; i < copCount - cops.Length; i++)
            {
                GameObject.Instantiate(copObject, transform.position, Quaternion.identity);
            }
        }
        else if (copCount < cops.Length)
        {
            for (int i = 0; i < cops.Length - copCount; i++)
            {
                Destroy(cops[i].gameObject);
            }
        }

        cops = GameObject.FindGameObjectsWithTag("Cop");
        for (int i = 0; i < cops.Length; i++)
        {
            //Debug.Log(cops[i].name);
            cops[i].GetComponent<CopMovement>().reset();
        }

        QualitySettings.pixelLightCount = copCount;
        
        if (drugCount > drugs.Length)
        {
            for (int i = 0; i < drugCount - drugs.Length; i++)
            {
                GameObject.Instantiate(drugObject, transform.position, Quaternion.identity);
            }
        }
        else if (drugCount < drugs.Length)
        {
            for (int i = 0; i < drugs.Length - drugCount; i++)
            {
                Destroy(drugs[i].gameObject);
            }
        }

        drugs = GameObject.FindGameObjectsWithTag("Drug");
        for (int i = 0; i < drugs.Length; i++)
        {
            drugs[i].GetComponent<Drug>().spawn();
        }

        GameController.instance.drugCount = drugCount;
        /*
        for (int i = 0; i < baseDrugCount; i++)
        {
            GameObject.Instantiate(drugObject, transform.position, Quaternion.identity);
        }
        */
    }
    

}
