コード例 #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
ファイル: Helpers.cs プロジェクト: tjosgood/TurnSim
 public static double Dist(dblPoint unit, double X2, double Y2)
 {
     return(Dist(unit.X, unit.Y, X2, Y2));
 }
コード例 #4
0
ファイル: Helpers.cs プロジェクト: tjosgood/TurnSim
 public static double Dist(dblPoint unit, dblPoint enemy)
 {
     return(Dist(unit.X, unit.Y, enemy.X, enemy.Y));
 }
コード例 #5
0
ファイル: Helpers.cs プロジェクト: tjosgood/TurnSim
 public PointF Point(dblPoint P, bool scale = true)
 {
     return(Point(P.X, P.Y, scale));
 }