Пример #1
0
        public static AssaultTemplate GetAssualtTemplate(Fortification toAssault, ArmyBlueprint subArmy)
        {
            bool   isPossibleAssault = true;
            ushort simulationDamage  = 0;

            if (!toAssault.IsPlaceHolderFort)
            {
                float damageRatio = 1;
                if (subArmy.Damage > 0)
                {
                    damageRatio = (float)toAssault.Defense / subArmy.Damage;
                }

                // The more damage an army has the faster it will take the city
                simulationDamage = (ushort)(toAssault.Offense * damageRatio);
                ushort damageReduction =
                    (ushort)(subArmy.Soldiers.Count > 1
                    ? (subArmy.Soldiers.Count - 1 * ArmyConstants.SOLDIER_STACKING_DEFENCE) * subArmy.Soldiers.Count
                    : 0);
                simulationDamage = (ushort)(damageReduction > simulationDamage ? 0 : simulationDamage - damageReduction);

                isPossibleAssault = subArmy.Health > simulationDamage && subArmy.Damage >= toAssault.Defense || toAssault.IsPlaceHolderFort;
            }
            // else fort damage is zero so just put it through

            return(isPossibleAssault ?
                   new AssaultTemplate(toAssault, subArmy, simulationDamage)
                : null);
        }
Пример #2
0
 public bool Equals(ArmyBlueprint toCompare)
 {
     if (Soldiers.Count == toCompare.Soldiers.Count &&
         Healers.Count == toCompare.Healers.Count &&
         Archers.Count == toCompare.Archers.Count)
     {
         for (int i = 0; i < Soldiers.Count; i++)
         {
             if (Mathf.Abs(Soldiers[i] - toCompare.Soldiers[i]) > ArmyConstants.EQUALITY_RANGE)
             {
                 return(false);
             }
         }
         for (int i = 0; i < Healers.Count; i++)
         {
             if (Mathf.Abs(Healers[i] - toCompare.Healers[i]) > ArmyConstants.EQUALITY_RANGE)
             {
                 return(false);
             }
         }
         for (int i = 0; i < Archers.Count; i++)
         {
             if (Mathf.Abs(Archers[i] - toCompare.Archers[i]) > ArmyConstants.EQUALITY_RANGE)
             {
                 return(false);
             }
         }
         return(true);
     }
     return(false);
 }
Пример #3
0
        public static ArmyBlueprint MergeSubArmies(List <ArmyBlueprint> subArmies)
        {
            List <ushort> soldiers = new List <ushort>();
            List <ushort> archers  = new List <ushort>();
            List <ushort> healers  = new List <ushort>();

            foreach (ArmyBlueprint subArmy in subArmies)
            {
                for (int i = 0; i < subArmy.Soldiers.Count; ++i)
                {
                    if (subArmy.Soldiers[i] > 0)
                    {
                        soldiers.Add(subArmy.Soldiers[i]);
                    }
                }
                for (int i = 0; i < subArmy.Healers.Count; ++i)
                {
                    if (subArmy.Healers[i] > 0)
                    {
                        healers.Add(subArmy.Healers[i]);
                    }
                }
                for (int i = 0; i < subArmy.Archers.Count; ++i)
                {
                    if (subArmy.Archers[i] > 0)
                    {
                        archers.Add(subArmy.Archers[i]);
                    }
                }
            }
            soldiers.Sort();
            healers.Sort();
            archers.Sort();
            ArmyBlueprint merged = new ArmyBlueprint(soldiers, healers, archers);

            return(merged);
        }
Пример #4
0
        public ArmyBlueprint AssaultFortification(bool healGroupAfter = true)
        {
            // Create new copy of army so template can be stored for inspection purposes
            List <ushort> soldiers = new List <ushort>(Attackers.Soldiers);
            List <ushort> healers  = new List <ushort>(Attackers.Healers);
            List <ushort> archers  = new List <ushort>(Attackers.Archers);

            if (!ToAssault.IsPlaceHolderFort)
            {
                ushort remainingDamage = CalculatedFortDamage;
                remainingDamage = ApplyDamageToInvaderGroup(soldiers, remainingDamage);
                remainingDamage = ApplyDamageToInvaderGroup(healers, remainingDamage);
                remainingDamage = ApplyDamageToInvaderGroup(archers, remainingDamage);

                Debug.Assert(remainingDamage == 0, "After applying damage to an invasion group there is still " + remainingDamage + " damage to apply");
            }
            ArmyBlueprint armyPostBattle = new ArmyBlueprint(soldiers, healers, archers);

            if (healGroupAfter)
            {
                armyPostBattle.Heal();
            }
            return(armyPostBattle);
        }
Пример #5
0
 public AssaultTemplate(Fortification toAssault, ArmyBlueprint invaders, ushort fortDamage)
 {
     ToAssault            = toAssault;
     Attackers            = invaders;
     CalculatedFortDamage = fortDamage;
 }