Exemple #1
0
    private List <List <TowerBehavior> > UpdateDistancePrioritys()
    {
        //list of towers we can attack
        List <TowerBehavior> towersToAttack = TowerController.GetTowersNotOfFaction(myTower.Faction);

        //dictonary to associate a list of towers with a distance
        Dictionary <int, List <TowerBehavior> > dictionary = new Dictionary <int, List <TowerBehavior> >();


        foreach (TowerBehavior tower in towersToAttack)
        {
            //get the distance between the AI tower and a tower we can attack
            float fDistance = Vector3.Distance(tower.gameObject.transform.position, myTower.gameObject.transform.position);
            //we want distance as an integer, distance as an int allows for the randomness in AI Attack Controller
            //see if we need to round up or down
            int distance = 0;
            if (fDistance - Mathf.Floor(fDistance) >= 0.5f)
            {
                distance = Mathf.CeilToInt(fDistance);
            }
            else
            {
                distance = Mathf.FloorToInt(fDistance);
            }


            //if distance isn't a key in the dictionary already, make a new list, add the tower to the list and add them to the
            //dictionary
            if (!dictionary.ContainsKey(distance))
            {
                List <TowerBehavior> newList = new List <TowerBehavior>();
                newList.Add(tower);
                dictionary.Add(distance, newList);
            }
            //if it is then add the tower to the distance's list
            else
            {
                dictionary[distance].Add(tower);
            }
        }


        return(AISortingMethods.InsertionSortDistance(this, dictionary));
    }
Exemple #2
0
    //pretty much the same as the function above
    private List <List <TowerBehavior> > UpdateUnitPrioritys()
    {
        List <TowerBehavior> towersToAttack = TowerController.GetTowersNotOfFaction(myTower.Faction);
        Dictionary <int, List <TowerBehavior> > dictionary = new Dictionary <int, List <TowerBehavior> >();

        foreach (TowerBehavior tower in towersToAttack)
        {
            if (!dictionary.ContainsKey(tower.StationedUnits))
            {
                List <TowerBehavior> newList = new List <TowerBehavior>();
                newList.Add(tower);
                dictionary.Add(tower.StationedUnits, newList);
            }
            else
            {
                dictionary[tower.StationedUnits].Add(tower);
            }
        }

        return(AISortingMethods.InsertionSortUnits(this, dictionary));
    }