Exemple #1
0
        static void HitAndRun(BattleData battleData, Squad current)
        {
            if (battleData.EnemyArmy.Length < 1)
                return;

            int TargetIndex = Strategy.NearestToPoint(current.Position, battleData.EnemyArmy);
            if (TargetIndex < 0)
                return;
            Step[] Path = DistanceAndPath.PathTo(
                battleData,
                current.Position,
                battleData.EnemyArmy[TargetIndex].Position,
                current.Unit.Range);
            if (Path != null)
                if (Path.Length == 0)
                {
                    Point SafePoint = GetSafeFrom(current.Position, battleData.EnemyArmy[TargetIndex].Position);

                    Path = DistanceAndPath.PathTo(
                    battleData,
                    current.Position,
                    SafePoint,
                    0);

                    Strategy.AttackAndMove(current, battleData.EnemyArmy[TargetIndex], Path, battleData);
                }
                else
                    Strategy.MoveAndAttack(current, battleData.EnemyArmy[TargetIndex], Path, battleData);
        }
Exemple #2
0
        protected static bool Move(Squad mover, Step[] path, BattleData bd)
        {
            if (path == null)
                return false;
            int length = path.Length;
            if (length < 1)
                return true;
            double movement = mover.Unit.MovementSpeed;
            Point temp = path[0].Key;

            for (int k = length - 1; k > 0; k--)
            {
                if (path[k].Value > movement)
                {
                    temp = path[k + 1].Key;

                    mover.CurrentAction.Type = Squad.ActionType.Move;
                    mover.CurrentAction.Path = path.Select(x => x.Key).SkipWhile(x => x != temp).TakeWhile(x => x != mover.Position).Concat(new Point[] { mover
                    .Position}).ToArray();

                    bd.Relocate(mover.Position, temp);
                    mover.Position = temp;
                    return false;
                }
            }

            mover.CurrentAction.Type = Squad.ActionType.Move;
            mover.CurrentAction.Path = path.Select(x => x.Key).SkipWhile(x => x != temp).TakeWhile(x => x != mover.Position).Concat(new Point[] { mover
                    .Position}).ToArray();

            bd.Relocate(mover.Position, temp);
            mover.Position = temp;
            return true;
        }
Exemple #3
0
 public BattleData(Squad[] enemyArmy, Squad[] allyArmy, byte[] map, int mapWidth)
 {
     this.EnemyArmy = enemyArmy;
     this.AllyArmy = allyArmy;
     this.Map = map;
     this.MapWidth = mapWidth;
     this.MapHeight = map.Length / mapWidth;
     this.MapHeightLog2 = (int)(Math.Log(MapWidth, 2));
     this.PathFinder = new PathFinderFast(Map, MapWidth);
     PathFinder.PathFinderDebug += PathFinder_PathFinderDebug;
 }
Exemple #4
0
        protected static void AttackAndMove(Squad attacker, Squad target, Step[] path, BattleData bd)
        {
            attacker.CurrentAction.Type = Squad.ActionType.Attack;
            attacker.CurrentAction.Target = target;

            int dmg = target.Amount;
            attacker.Attack(target);

            attacker.CurrentAction.Damage = dmg - target.Amount;

            Move(attacker, path, bd);

            if (attacker.CurrentAction.Type == Squad.ActionType.Move)
                attacker.CurrentAction.Type = Squad.ActionType.AttackAndMove;
        }
Exemple #5
0
        static void Ambysh(BattleData battleData, Squad current)
        {
            if (battleData.EnemyArmy.Length < 1)
                return;

                int TargetIndex = Strategy.NearestToPoint(current.Position, battleData.EnemyArmy);
                if (TargetIndex < 0)
                    return;
                Step[] Path = DistanceAndPath.PathTo(
                    battleData,
                    current.Position,
                    battleData.EnemyArmy[TargetIndex].Position,
                    current.Unit.Range);
                if (Path != null)
                    Strategy.MoveAndAttack(current, battleData.EnemyArmy[TargetIndex], Path, battleData);
        }
Exemple #6
0
        protected static int NearestToPoint(Point p1, Squad[] army)
        {
            int Temp = -1;
            double minDistance = Double.MaxValue;
            for (int i = 0; i < army.Length; i++)
            {

                double distance = DistanceAndPath.DistanceTo(p1, army[i].Position);
                if ((distance < minDistance) && army[i].Alive)
                {

                    minDistance = distance;
                    Temp = i;
                }
            }
            return Temp;
        }
Exemple #7
0
        /// <summary>
        /// Chose Nearest target to all army squads
        /// </summary>
        /// <param name="army"></param>
        /// <param name="targets"></param>
        /// <returns></returns>
        protected static int NearestToAll(Squad[] army, Squad[] targets)
        {
            int Temp = -1;
            double[] distances = new double[targets.Length];

            for (int i = 0; i < targets.Length; i++)
            {
                for (int j = 0; j < army.Length; j++)
                {
                    distances[i] += DistanceAndPath.DistanceTo(army[j].Position, targets[i].Position);
                }
            }

            double min = double.MaxValue;
            for (int i = 0; i < distances.Length; i++)
            {
                if ((distances[i] < min) && targets[i].Alive)
                {
                    min = distances[i];
                    Temp = i;
                }
            }

            return Temp;
        }
Exemple #8
0
        private void EraseDeadSquads(ref Squad[] Army)
        {
            int aliveSq = 0;
            bool change = false;
            foreach (var item in Army)
            {
                if (item.Alive)
                    aliveSq++;
                else
                {
                    EraseFromMap(item.Position);
                    change = true;
                }
            }
            if (!change)
                return;
            Squad[] temp = new Squad[aliveSq];
            int index = 0;
            foreach (var item in Army)
            {
                if (item.Alive)
                {
                    temp[index] = item;
                    index++;
                }
            }

            Army = temp;
        }
Exemple #9
0
        public void Attack(Squad target)
        {
            attaking = true;
            int Damage = 0;
            for (int i = 0; i < Amount; i++)
            {
                if ((1 + Random.Next(20) + Unit.Attack) >= target.Unit.Defense)
                    Damage += Unit.Damage;
            }

            target.TakeDamage(Damage);
        }