Exemple #1
0
 int IComparable.CompareTo(object obj)
 {
     try
     {
         AnimosityPair pair = (AnimosityPair)obj;
         if (animosity > pair.animosity)
         {
             return(1);
         }
         else if (animosity == pair.animosity)
         {
             return(0);
         }
         else
         {
             return(-1);
         }
     }
     catch (InvalidCastException e)
     {
         Debug.Log(e.StackTrace);
     }
     return(-10);
 }
    void CalculateAnimosity(AnimosityMode mode = AnimosityMode.fifo)
    {
        switch (mode)
        {
        case AnimosityMode.fifo: return;

        case AnimosityMode.complex:
            List <AnimosityPair> pairs = new List <AnimosityPair>(enemies.Count);
            for (int i = 0; i < enemies.Count; i++)
            {
                pairs[i] = new AnimosityPair(this, enemies[i].GetComponent <Enemy>());
            }
            pairs.Sort();

            for (int i = 0; i < enemies.Count; i++)
            {
                enemies[i] = pairs[i].enemy.gameObject;
            }
            return;

        case AnimosityMode.intelligent:
            for (int i = 0; i < enemies.Count; i++)
            {
                for (int j = i + 1; j < enemies.Count; j++)
                {
                    if (this * enemies[i].GetComponent <Enemy>() < this * enemies[j].GetComponent <Enemy>())
                    {
                        GameObject t = enemies[j];
                        enemies[j] = enemies[i];
                        enemies[i] = t;
                    }
                }
            }
            return;
        }
    }