예제 #1
0
        public GameObject SpawnHuman()
        {
            GameObject theObj = Instantiate(TheHuman, transform.position, Quaternion.identity);
            Human      human  = theObj.GetComponent <Human>();

            human.Tribe = base.Tribe;
            WorldObjectsReferenceHelper.Current().Humans.Add(theObj);
            return(theObj);
        }
    private void AddExistingMinerals()
    {
        var objects = GameObject.FindObjectsOfType <Mineral>();

        foreach (var element in objects)
        {
            if (element != null)
            {
                WorldObjectsReferenceHelper.Current().Minerals.Add(element.gameObject);
            }
        }
    }
    private void GenerateTribes()
    {
        var Tribes = WorldObjectsReferenceHelper.Current().Tribes;

        Tribes.Add(new Tribe(1, Tribe1Color, new Vector3(PositionXStart, PositionYStart, 0), MaxAmountOfWorkers));
        Tribes.Add(new Tribe(2, Tribe2Color, new Vector3(PositionXStart, PositionYEnd, 0), MaxAmountOfWorkers));
        Tribes.Add(new Tribe(3, Tribe3Color, new Vector3(PositionXEnd, PositionYStart, 0), MaxAmountOfWorkers));
        Tribes.Add(new Tribe(4, Tribe4Color, new Vector3(PositionXEnd, PositionYEnd, 0), MaxAmountOfWorkers));
        Tribes.Add(new Tribe(5, Tribe5Color, new Vector3(PositionXStart, PositionYStart, 0), MaxAmountOfWorkers));
        Tribes.Add(new Tribe(6, Tribe6Color, new Vector3(PositionXStart, PositionYEnd, 0), MaxAmountOfWorkers));
        Tribes.Add(new Tribe(7, Tribe7Color, new Vector3(PositionXStart, PositionYStart, 0), MaxAmountOfWorkers));
        Tribes.Add(new Tribe(8, Tribe8Color, new Vector3(PositionXStart, PositionYStart, 0), MaxAmountOfWorkers));
        Tribes.Add(new Tribe(9, Tribe9Color, new Vector3(PositionXStart, PositionYStart, 0), MaxAmountOfWorkers));
        Tribes.Add(new Tribe(10, Tribe10Color, new Vector3(PositionXStart, PositionYEnd, 0), MaxAmountOfWorkers));
    }
    private void GenerateBuildingInCorners()
    {
        WorldObjectsReferenceHelper worldObjectsReferenceHelper = WorldObjectsReferenceHelper.Current();
        Tribe tribe = null;

        for (int i = 0; i < numofTribes; i++)
        {
            tribe = worldObjectsReferenceHelper.Tribes.Find(ji => ji.Id == (i % numofTribes) + 1);
            GameObject  theObj      = Instantiate(BaseBuliding, tribe.TeamPosition, Quaternion.identity);
            BaseBulding humanScript = theObj.GetComponent <BaseBulding>();
            if (humanScript != null)
            {
                humanScript.Tribe = tribe;
                worldObjectsReferenceHelper.Humans.Add(theObj);
            }
        }
    }
    private void GenerateHumansCloseInTribe()
    {
        WorldObjectsReferenceHelper worldObjectsReferenceHelper = WorldObjectsReferenceHelper.Current();

        for (int i = 0; i < numberOfHumans; i++)
        {
            Tribe tribe = null;
            tribe = worldObjectsReferenceHelper.Tribes.Find(ji => ji.Id == (i % numofTribes) + 1);

            GameObject theObj      = Instantiate(WhatToPlace, tribe.TeamPosition, Quaternion.identity);
            Human      humanScript = theObj.GetComponent <Human>();
            if (humanScript != null)
            {
                humanScript.Tribe = tribe;
                worldObjectsReferenceHelper.Humans.Add(theObj);
            }
        }
    }
예제 #6
0
        private void FindMineralTarget()
        {
            mineralTarget = null;
            float minDistanceSoFar = float.MaxValue;

            foreach (var obj in WorldObjectsReferenceHelper.Current().Minerals)
            {
                if (obj != null)
                {
                    Mineral currentlyChecked = obj.GetComponent <Mineral>();
                    if (currentlyChecked != null && currentlyChecked != this)
                    {
                        float distance = Vector2.Distance(transform.position, currentlyChecked.transform.position);
                        if (distance < minDistanceSoFar)
                        {
                            minDistanceSoFar = distance;
                            mineralTarget    = new MineralTarget(currentlyChecked, distance);
                        }
                    }
                }
            }
        }
예제 #7
0
        private void GetHumanTarget()
        {
            float minDistanceSoFar = float.MaxValue;

            humanTarget = null;

            foreach (GameObject xxx in WorldObjectsReferenceHelper.Current().Humans)
            {
                if (xxx != null)
                {
                    Human currentlyChecked = xxx.GetComponent <Human>();
                    if (currentlyChecked != null && currentlyChecked != this && currentlyChecked.Tribe != this.Tribe && currentlyChecked.IsAlive)
                    {
                        float distance = Vector2.Distance(transform.position, currentlyChecked.transform.position);
                        if (distance < minDistanceSoFar && distance < AgressionRange)
                        {
                            minDistanceSoFar = distance;
                            humanTarget      = new HumanTarget(currentlyChecked, minDistanceSoFar);
                        }
                    }
                }
            }
        }
    private void GenerateHumansRandomly()
    {
        WorldObjectsReferenceHelper worldObjectsReferenceHelper = WorldObjectsReferenceHelper.Current();

        for (int i = 0; i < numberOfHumans; i++)
        {
            GameObject theObj      = Instantiate(WhatToPlace, GenerateRandomPosition(), Quaternion.identity);
            Human      humanScript = theObj.GetComponent <Human>();
            if (humanScript != null)
            {
                worldObjectsReferenceHelper.Humans.Add(theObj);

                if (HowManyTribes == 0)
                {
                    humanScript.Tribe = null;
                }
                else
                {
                    humanScript.Tribe = worldObjectsReferenceHelper.Tribes.Find(ji => ji.Id == (i % numofTribes) + 1);
                }
            }
        }
    }