Пример #1
0
        private dblPoint FindNearestSpot(UnitClass unit, UnitClass enemy)
        {
            var RealDist = Helpers.Dist(unit, enemy);
            var MoveDist = Math.Min(RealDist, unit.MaxMoveDist);

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

            for (var Dist = MoveDist; Dist > 0; Dist -= 1)
            {
                var test = new dblPoint()
                {
                    X = unit.X + xgrad * Dist, Y = unit.Y + ygrad * Dist
                };
                if (LocationValid(unit, test.X, test.Y))
                {
                    return new dblPoint()
                           {
                               isValid = true, X = test.X, Y = test.Y
                           }
                }
                ;
                // Sim.Vis.Dot(test.X, test.Y);
            }
            return(new dblPoint()
            {
                isValid = false, X = unit.X, Y = unit.Y
            });
        }
Пример #2
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
            });
        }
Пример #3
0
 public static double Dist(dblPoint unit, double X2, double Y2)
 {
     return(Dist(unit.X, unit.Y, X2, Y2));
 }
Пример #4
0
 public static double Dist(dblPoint unit, dblPoint enemy)
 {
     return(Dist(unit.X, unit.Y, enemy.X, enemy.Y));
 }
Пример #5
0
 public PointF Point(dblPoint P, bool scale = true)
 {
     return(Point(P.X, P.Y, scale));
 }