Esempio n. 1
0
        public static Vector2 ProjectClosest(HookComputer hook, Vector2 fromPosition, Vector2 targetPosition, float maxTime, int fleetSize)
        {
            var boostSpeed  = hook.Hook.BoostThrust;
            var bulletSpeed = hook.ShotThrust(fleetSize) * 10;
            var path        = targetPosition - fromPosition;
            var pLen        = path.Length();
            var maxD        = bulletSpeed * maxTime + boostSpeed * hook.Hook.BoostDuration;

            // if(maxD>pLen){
            //     Console.Write("Switch");
            // }
            return(fromPosition + path * (1.0f / pLen) * MathF.Min(pLen - 10.0f, maxD));
        }
Esempio n. 2
0
        public static Vector2[] ProjectClosest(HookComputer hook, float maxTime, Vector2[] fromPosition, Vector2[] targetPosition, int[] fleetSize)
        {
            var boostSpeed = hook.Hook.BoostThrust;
            int N          = fromPosition.Length;

            Vector2[] vout = new Vector2[N];
            for (int i = 0; i < N; i++)
            {
                var bulletSpeed = hook.ShotThrust(fleetSize[i]) * 10;
                var path        = targetPosition[i] - fromPosition[i];
                var pLen        = path.Length();
                var maxD        = bulletSpeed * maxTime + boostSpeed * hook.Hook.BoostDuration;
                vout[i] = fromPosition[i] + path * (1.0f / pLen) * MathF.Min(pLen - 10.0f, maxD);
            }
            return(vout);
        }
Esempio n. 3
0
        public static Vector2 FiringIntercept(
            HookComputer hook,
            Vector2 fromPosition,
            Vector2 targetPosition,
            Vector2 targetMomentum,
            int fleetSize,
            out int timeToImpact
            )
        {
            var toTarget = targetPosition - fromPosition;

            var bulletSpeed = hook.ShotThrust(fleetSize) * 10;

            var a = Vector2.Dot(targetMomentum, targetMomentum) - (bulletSpeed * bulletSpeed);
            var b = 2 * Vector2.Dot(targetMomentum, toTarget);
            var c = Vector2.Dot(toTarget, toTarget);

            var p = -b / (2 * a);
            var q = MathF.Sqrt((b * b) - 4 * a * c) / (2 * a);

            var t1 = p - q;
            var t2 = p + q;
            var t  = 0f;

            if (t1 > t2 && t2 > 0)
            {
                t = t2;
            }
            else
            {
                t = t1;
            }

            var aimSpot = targetPosition + targetMomentum * t;

            var bulletPath = aimSpot - fromPosition;

            timeToImpact = (int)(bulletPath.Length() / bulletSpeed);//speed must be in units per second

            if (timeToImpact > hook.Hook.BulletLife)
            {
                timeToImpact = int.MaxValue;
            }

            return(aimSpot);
        }
Esempio n. 4
0
        public static bool MightHit(
            HookComputer hook,
            Fleet shooter,
            Fleet monstrosity,
            float angle
            )
        {
            Vector2 dirN = new Vector2(MathF.Cos(angle), MathF.Sin(angle));
            bool    hit  = false;

            foreach (var firer in shooter.Ships)
            {
                foreach (var other in monstrosity.Ships)
                {
                    var toTarget = other.Position - firer.Position;

                    var bulletSpeed = hook.ShotThrust(shooter.Ships.Count) * 10;
                    var b           = toTarget.Length();

                    var c = Vector2.Dot(dirN, toTarget);

                    var q = MathF.Sqrt((b * b) - c * c);


                    var bulletPath   = toTarget;
                    var timeToImpact = (int)(bulletPath.Length() / bulletSpeed);//speed must be in units per second

                    if (timeToImpact < hook.Hook.BulletLife && q < 1000 && c > 0)
                    {
                        hit = true;
                        break;
                    }
                }
            }
            return(hit);
        }