示例#1
0
        private void UpdateArmySprite()
        {
            // Set the drawing texture to the Unit that is most prevalent in this stack
            int maxUnits = 0;
            Dictionary <string, int> newUAC      = new Dictionary <string, int>();
            Dictionary <string, int> newSelected = new Dictionary <string, int>();

            foreach (string soldierType in unitsAndCounts.Keys)
            {
                if (unitsAndCounts[soldierType] > maxUnits)
                {
                    Soldier soldier = SoldierRegistry.GetSoldier(soldierType, owner);
                    DrawingTexture = soldier.DrawingTexture;
                    maxUnits       = unitsAndCounts[soldierType];
                }

                if (unitsAndCounts[soldierType] != 0)
                {
                    newUAC[soldierType]      = unitsAndCounts[soldierType];
                    newSelected[soldierType] = newUAC[soldierType];
                }
            }

            unitsAndCounts = newUAC;
            selectedUnits  = newSelected;

            refreshInfo = true;
        }
示例#2
0
        /// <summary>
        /// Gets the Soldier in this Army with the lowest movement speed. Used to update moves left at the start of a turn.
        /// </summary>
        /// <returns>A copy of the Soldier with the lowest movement speed.</returns>
        private Soldier GetSlowestUnit()
        {
            // If this army is invalid, don't do shit.
            if (unitsAndCounts == null || unitsAndCounts.Keys.Count == 0)
            {
                return(null); // Invalid army
            }
            // Get all units
            ICollection <string> unitsInStack = unitsAndCounts.Keys;

            // Get the movespeed of the slowest one.
            int     moveSpeed = 99999;
            Soldier slowest   = null;

            foreach (string soldierType in unitsInStack)
            {
                Soldier soldier = SoldierRegistry.GetSoldier(soldierType, owner);
                moveSpeed = Math.Min(moveSpeed, soldier.MoveSpeed);
                if (moveSpeed == soldier.MoveSpeed)
                {
                    slowest = soldier.Copy(owner);
                }
            }

            // Return the unit that was found slowest
            return(slowest);
        }