Exemple #1
0
        public Selection(List<RtsObject> list)
        {
            objects = new List<RtsObject>(list.ToArray<RtsObject>());
            sortSelection();

            // add object/count pairs to the objectCount dictionary
            foreach (RtsObject o in objects)
            {
                RtsObjectType type = o.Type;
                if (!typeCounts.ContainsKey(type))
                {
                    typeCounts.Add(type, 1);
                }
                else
                {
                    //int count;
                    //typeCounts.TryGetValue(o.GetType(), out count);
                    //count++;
                    typeCounts[type]++;
                }
            }

            // mostPopulousType = largest count
            foreach (System.Collections.Generic.KeyValuePair<RtsObjectType, int> pair in typeCounts)
            {
                if (pair.Value > largestCount)
                {
                    mostPopulousType = pair.Key;
                    largestCount = pair.Value;
                }
            }

            SetActiveTypeToMostPopulousType();
        }
Exemple #2
0
        /*public Selection(Selection s)
         *  : this(s.objects)
         * {
         * }*/

        public void Add(RtsObject o)
        {
            //if (!objects.Contains(o))
            objects.Add(o);
            sortSelection();

            RtsObjectType type = o.Type;

            if (objects.Count == 1)
            {
                ActiveType = type;
            }

            int count;

            if (!typeCounts.ContainsKey(type))
            {
                typeCounts.Add(type, 1);
                count = 1;
            }
            else
            {
                typeCounts[type]++;
                typeCounts.TryGetValue(type, out count);
            }

            if (count > largestCount)
            {
                mostPopulousType = type;
                largestCount     = count;
            }
        }
Exemple #3
0
 public Selection()
 {
     objects = new List<RtsObject>();
     mostPopulousType = null;
     activeType = null;
     ActiveCommandCard = null;
 }
Exemple #4
0
        public Selection(List <RtsObject> list)
        {
            objects = new List <RtsObject>(list.ToArray <RtsObject>());
            sortSelection();

            // add object/count pairs to the objectCount dictionary
            foreach (RtsObject o in objects)
            {
                RtsObjectType type = o.Type;
                if (!typeCounts.ContainsKey(type))
                {
                    typeCounts.Add(type, 1);
                }
                else
                {
                    //int count;
                    //typeCounts.TryGetValue(o.GetType(), out count);
                    //count++;
                    typeCounts[type]++;
                }
            }

            // mostPopulousType = largest count
            foreach (System.Collections.Generic.KeyValuePair <RtsObjectType, int> pair in typeCounts)
            {
                if (pair.Value > largestCount)
                {
                    mostPopulousType = pair.Key;
                    largestCount     = pair.Value;
                }
            }

            SetActiveTypeToMostPopulousType();
        }
Exemple #5
0
 public Selection()
 {
     objects           = new List <RtsObject>();
     mostPopulousType  = null;
     activeType        = null;
     ActiveCommandCard = null;
 }
Exemple #6
0
 public void Clear()
 {
     objects.Clear();
     typeCounts.Clear();
     mostPopulousType = null;
     activeType       = null;
     largestCount     = 0;
 }
Exemple #7
0
 void sortTypes()
 {
     //typeCounts.ElementAt<RtsObject>();
     for (int i = 2; i < typeCounts.Count; i++)
     {
         for (int j = i; j >= 1 && typeCounts.ElementAt(j).Key.SelectionSortValue < typeCounts.ElementAt(j - 1).Key.SelectionSortValue; j--)
         {
             RtsObjectType tempKey   = typeCounts.ElementAt(j).Key;
             int           tempCount = typeCounts.ElementAt(j).Value;
             typeCounts.Remove(typeCounts.ElementAt(j).Key);
             //typeCounts.Insert(j - 1, tempItem);
         }
     }
 }
Exemple #8
0
        RtsObjectType lowestPriorityType(List <RtsObjectType> keys)
        {
            RtsObjectType lowestType = keys[0];

            foreach (RtsObjectType key in keys)
            {
                if (key.SelectionSortValue < lowestType.SelectionSortValue)
                {
                    lowestType = key;
                }
            }

            return(lowestType);
        }
Exemple #9
0
        public void TabActiveType()
        {
            List <RtsObjectType> keys = typeCounts.Keys.ToList <RtsObjectType>();

            if (typeCounts.Count > 1)
            {
                RtsObjectType nextPriorityKey = null;
                int           lowest          = int.MaxValue;

                foreach (RtsObjectType key in keys)
                {
                    if (key.SelectionSortValue > activeType.SelectionSortValue)
                    {
                        if (key.SelectionSortValue < lowest)
                        {
                            nextPriorityKey = key;
                            lowest          = key.SelectionSortValue;
                        }
                    }
                }

                if (nextPriorityKey == null)
                {
                    nextPriorityKey = lowestPriorityType(keys);
                }

                ActiveType = nextPriorityKey;
            }

            /*if (typeCounts.Count > 1)
             * {
             *  for (int i = 0; i < keys.Count; i++)
             *  {
             *      if (keys[i] == activeType)
             *      {
             *          //ActiveType = keys[(i + (keys.Count - 1)) % keys.Count];
             *          ActiveType = keys[(i + 1) % keys.Count - 1];
             *          break;
             *      }
             *  }
             * }*/
            else if (typeCounts.Count == 1)
            {
                ActiveType = keys[0];
            }
            else
            {
                ActiveType = null;
            }
        }
Exemple #10
0
        public void Remove(RtsObject o)
        {
            if (!objects.Contains(o))
            {
                return;
            }

            objects.Remove(o);

            Rts.selectedUnitsChanged = true;

            RtsObjectType type = o.Type;

            if (typeCounts.ContainsKey(type))
            {
                typeCounts[type]--;
                if (typeCounts[type] == 0)
                {
                    typeCounts.Remove(type);
                    if (activeType == type)
                    {
                        TabActiveType();
                    }
                }
            }

            if (mostPopulousType == type)
            {
                largestCount = 0;
                foreach (KeyValuePair <RtsObjectType, int> pair in typeCounts)
                {
                    if (pair.Value > largestCount)
                    {
                        mostPopulousType = pair.Key;
                        largestCount     = pair.Value;
                    }
                }
            }

            if (objects.Count == 0)
            {
                mostPopulousType = null;
                activeType       = null;
                largestCount     = 0;
            }

            //if (!ContainsType(o))
            //    TabActiveType();
        }
Exemple #11
0
        public void Remove(RtsObject o)
        {
            if (!objects.Contains(o))
                return;

            objects.Remove(o);

            Rts.selectedUnitsChanged = true;

            RtsObjectType type = o.Type;

            if (typeCounts.ContainsKey(type))
            {
                typeCounts[type]--;
                if (typeCounts[type] == 0)
                {
                    typeCounts.Remove(type);
                    if (activeType == type)
                        TabActiveType();
                }
            }

            if (mostPopulousType == type)
            {
                largestCount = 0;
                foreach (KeyValuePair<RtsObjectType, int> pair in typeCounts)
                {
                    if (pair.Value > largestCount)
                    {
                        mostPopulousType = pair.Key;
                        largestCount = pair.Value;
                    }
                }
            }

            if (objects.Count == 0)
            {
                mostPopulousType = null;
                activeType = null;
                largestCount = 0;
            }

            //if (!ContainsType(o))
            //    TabActiveType();
        }
Exemple #12
0
 public void Clear()
 {
     objects.Clear();
     typeCounts.Clear();
     mostPopulousType = null;
     activeType = null;
     largestCount = 0;
 }
Exemple #13
0
        /*public Selection(Selection s)
            : this(s.objects)
        {
        }*/
        public void Add(RtsObject o)
        {
            //if (!objects.Contains(o))
                objects.Add(o);
            sortSelection();

            RtsObjectType type = o.Type;

            if (objects.Count == 1)
                ActiveType = type;

            int count;

            if (!typeCounts.ContainsKey(type))
            {
                typeCounts.Add(type, 1);
                count = 1;
            }
            else
            {
                typeCounts[type]++;
                typeCounts.TryGetValue(type, out count);
            }

            if (count > largestCount)
            {
                mostPopulousType = type;
                largestCount = count;
            }
        }
Exemple #14
0
        public bool ContainsType(RtsObject o)
        {
            RtsObjectType type = o.Type;

            return(typeCounts.ContainsKey(type));
        }