Ejemplo n.º 1
0
 public bool LocationValid(UnitClass unit, double X, double Y)
 {
     foreach (var otherunit in Sim.Units.Where(o => o.Alive && (o.ID != unit.ID)))
     {
         if (Helpers.Dist(X, Y, otherunit.X, otherunit.Y) < Sim.SimRules.MinUnitDistance)
         {
             return(false);
         }
     }
     return(true);
 }
Ejemplo n.º 2
0
 public void TakeTurn(UnitClass unit)
 {
     if (Strategy == "hunt")
     {
         Turn_KillHeros(unit);
     }
     else if (Strategy == "weakest")
     {
         Turn_KillWeakest(unit);
     }
     else
     {
         Turn_KillNearest(unit);
     }
 }
Ejemplo n.º 3
0
        private dblPoint FindAttackSpot(UnitClass unit, UnitClass enemy)
        {
            double thstart = Math.Atan2(unit.Y - enemy.Y, unit.X - enemy.X);

            for (double thoff = 0; thoff <= Math.PI; thoff += 0.2)
            {
                for (int direction = -1; direction <= 1; direction += 2)
                {
                    double th   = thstart + thoff * direction;
                    var    test = new dblPoint()
                    {
                        X = enemy.X + Math.Cos(th) * unit.Weapon.Range * Sim.SimRules.EngageRange,
                        Y = enemy.Y + Math.Sin(th) * unit.Weapon.Range * Sim.SimRules.EngageRange
                    };

                    //Sim.Vis.Dot(test.X, test.Y);
                    if (Helpers.Dist(unit, test) < unit.MaxMoveDist)
                    {
                        if (LocationValid(unit, test.X, test.Y))
                        {
                            return new dblPoint()
                                   {
                                       isValid = true, X = test.X, Y = test.Y
                                   }
                        }
                        ;
                    }
                    else
                    {
                        return(new dblPoint()
                        {
                            isValid = false, X = 0, Y = 0
                        });
                    }

                    if (thoff == 0)
                    {
                        break;
                    }
                }
            }

            return(new dblPoint()
            {
                isValid = false, X = 0, Y = 0
            });
        }
Ejemplo n.º 4
0
        public void RenderAttack(UnitClass unit, UnitClass def, double Damage)
        {
            if (!Enabled)
            {
                return;
            }

            string msg = "Miss!";

            if (Damage > 0)
            {
                msg = "Ouch! " + ((int)Damage).ToString() + " damage";
            }

            g.DrawString("Attack!", new Font("Arial", 16), Brushes.Black, Point(unit.X, unit.Y - DrawRadius * 2), stringFormat);
            g.DrawString(msg, new Font("Arial", 16), Brushes.Black, Point(def.X, def.Y - DrawRadius * 2), stringFormat);

            Refresh();
        }
Ejemplo n.º 5
0
        public bool MoveToAttack(UnitClass unit, UnitClass enemy)
        {
            bool Madeit = true;

            var MoveTo = FindAttackSpot(unit, enemy);

            if (MoveTo.isValid)
            {
                Log.debug($"Moving to engage {enemy.ToString()}");
            }
            else
            {
                Log.debug($"Too far: Approaching {enemy.ToString()}");
                MoveTo = FindNearestSpot(unit, enemy);
                Madeit = false;
            }

            MoveToSpot(unit, MoveTo.X, MoveTo.Y);

            return(Madeit);
        }
Ejemplo n.º 6
0
        public void MoveToSpot(UnitClass unit, double X, double Y)
        {
            var DistToMove = Helpers.Dist(unit, X, Y);

            unit.SP -= (int)Math.Ceiling(Math.Round(DistToMove, 2) / unit.BaseStats.MovementPerSP);
            var steps = Math.Round(DistToMove) + 1;

            if (!Sim.Vis.Enabled)
            {
                steps = 1;
            }

            var xgrad = (X - unit.X) / steps;
            var ygrad = (Y - unit.Y) / steps;

            for (var i = 0; i < steps; i++)
            {
                unit.X += xgrad;
                unit.Y += ygrad;
                Sim.Vis.RenderUnit(unit);
            }
            Sim.Vis.RenderAll();
        }
Ejemplo n.º 7
0
 public static double Dist(UnitClass unit, double X2, double Y2)
 {
     return(Dist(unit.X, unit.Y, X2, Y2));
 }
Ejemplo n.º 8
0
 public static double Dist(UnitClass unit, dblPoint enemy)
 {
     return(Dist(unit.X, unit.Y, enemy.X, enemy.Y));
 }
Ejemplo n.º 9
0
        public void RenderUnit(UnitClass unit, bool BlankOld = true)
        {
            if (!Enabled)
            {
                return;
            }
            if (!unit.Alive)
            {
                return;
            }

            if (BlankOld)
            {
                g.FillRectangle(Brushes.White, Rect(unit.OldX - Sim.SimRules.MinUnitDistance - .1, unit.OldY - Sim.SimRules.MinUnitDistance - .4,
                                                    Sim.SimRules.MinUnitDistance * 2 + .2, Sim.SimRules.MinUnitDistance * 2 + .8));
            }

            unit.OldX = unit.X;
            unit.OldY = unit.Y;

            var BodyRect = Rect(unit.X - DrawRadius, unit.Y - DrawRadius, DrawRadius * 2, DrawRadius * 2);

            if (UsePics)
            {
                g.FillRectangle(unit.Team.Colour, BodyRect);
                g.DrawImage(Pics[unit.BaseStats.Class.ToLower()], BodyRect);
            }
            else
            {
                if (unit.BaseStats.Class == "Leader")
                {
                    g.FillRectangle(unit.Team.Colour, BodyRect);
                }
                else if (unit.BaseStats.Class == "Hero")
                {
                    g.FillPie(unit.Team.Colour, BodyRect, 210, 120);
                    g.FillPie(unit.Team.Colour, BodyRect, 30, 120);
                }
                else
                {
                    g.FillEllipse(unit.Team.Colour, BodyRect);
                }
            }

            var ExcRec = Rect(unit.X - Sim.SimRules.MinUnitDistance, unit.Y - Sim.SimRules.MinUnitDistance, Sim.SimRules.MinUnitDistance * 2, Sim.SimRules.MinUnitDistance * 2);

            // g.DrawEllipse(Pens.Black, ExcRec);


            if (!unit.HadTurn)
            {
                Dot(unit.X, unit.Y - DrawRadius * 2, 0.3, Brushes.LightGreen, false);
            }

            g.DrawString(unit.ID.ToString(), new Font("Arial", 12), Brushes.Black, Point(unit.X, unit.Y - DrawRadius * 2), stringFormat);

            var HPbar = Rect(unit.X - DrawRadius * 1.5, unit.Y + DrawRadius * 1.5, DrawRadius * 3 * unit.HP / unit.MaxHP, DrawRadius / 2);
            var HPred = Rect(HPbar.X, HPbar.Y, DrawRadius * 3 * PxPerMeter, HPbar.Height, false);


            g.FillRectangle(Brushes.Red, HPred);
            g.FillRectangle(Brushes.Green, HPbar);


            if (BlankOld)
            {
                Refresh();
            }
        }
Ejemplo n.º 10
0
        public void Turn_KillNearest(UnitClass unit)
        {
            while (true)
            {
                //Log.debug($"SP: {Units[Uidx].SP}, OP: {Units[Uidx].OP}");

                var CanAttack = unit.OP >= unit.Weapon.OP_cost;
                var CanMove   = unit.SP > 0;

                if (!CanMove && !CanAttack)
                {
                    Log.debug("No OP or SP, end turn");
                    break;
                }

                //where are enemies?
                var Enemies = Sim.Units.Where(o => o.TeamID != unit.TeamID && o.Alive);

                if (!Enemies.Any())
                {
                    Log.debug("No enemies, end turn");
                    break;
                }

                var EnemyDistList   = Enemies.Select(o => Helpers.Dist(o.X, o.Y, unit.X, unit.Y)).ToArray();
                int NearestEnemyInd = Array.IndexOf(EnemyDistList, EnemyDistList.Min());
                var NearestEnemy    = Enemies.ElementAt(NearestEnemyInd);
                var EnemyDist       = EnemyDistList[NearestEnemyInd];

                // Log.debug($"There are {Enemies.Count} closest is {EnemyDist}m");

                //can we attack?
                if (EnemyDist <= unit.Weapon.Range)
                {
                    if (CanAttack)
                    {
                        DoAttack(unit, NearestEnemy);
                        continue;
                    }
                    else
                    {
                        Log.debug("Out of attacks");
                        break;
                    }
                }

                if (!CanMove)
                {
                    Log.debug("Can attack but out of SP, end turn");
                    break;
                }

                //there is an enemy, we can move
                var MoveAllowed = MoveToAttack(unit, NearestEnemy);
                if (!MoveAllowed)
                {
                    Log.debug("Not enough room to attack, waiting");
                    break;
                }
            }
        }