Esempio n. 1
0
        public Wave(IContext context, IEnemy enemy, double waveEnergy)
        {
            // Use previous Because the bullet was fired on the previous go
            _initialEnemyLocation = enemy.PenultimateBlipLocation;
            _initialMyLocation    = context.MyLocation;
            _initialEnemyDirect   = _initialMyLocation - _initialEnemyLocation;
            _initialTime          = context.Time;

            _bulletSpeed    = Rules.GetBulletSpeed(waveEnergy);
            _maxEscapeAngle = VirtualBullet.GetMaximumEscapeAngle(_bulletSpeed);
        }
        public override void Execute()
        {
            Contract.Requires(Context != null);
            Contract.Requires(Context != null);

            if (Context.Target != null &&
                Context.Target.Location != null &&
                Context.Target.EnemyDirect != null)
            {
                _location = Context.Target.Location;
                _direct   = Context.Target.EnemyDirect;

                // TODO POWER
                _power          = Rules.MIN_BULLET_POWER + 0.2 * (Rules.MAX_BULLET_POWER - Rules.MIN_BULLET_POWER);
                _speed          = Rules.GetBulletSpeed(_power);
                _maxEscapeAngle = VirtualBullet.GetMaximumEscapeAngle(_speed);

                EnemyGuessFactorData gfData = Context.Target.EnemyGuessFactorData;

                double gf = gfData.GuessFactor;
                _stats = gfData.Statistics;

                _minEscapeAngleRelativeVector = new Vector(
                    _direct.Magnitude,
                    new Angle(
                        _direct.Heading.Degrees
                        - _maxEscapeAngle));

                _maxEscapeAngleRelativeVector = new Vector(
                    _direct.Magnitude,
                    new Angle(
                        _direct.Heading.Degrees
                        + _maxEscapeAngle));

                _guessFactorRelativeVector = new Vector(
                    _direct.Magnitude,
                    new Angle(
                        _direct.Heading.Degrees
                        + gf * _maxEscapeAngle));
            }

            if (_guessFactorRelativeVector != null)
            {
                Context.MoveToAbsolute += new Vector(
                    _guessFactorRelativeVector.Magnitude *
                    Math.Sin((_guessFactorRelativeVector.Heading - _direct.Heading).Radians),
                    _guessFactorRelativeVector.Heading.Perpendicular);
            }
        }
        public override Vector GetFuturePosition(IEnemy target, long delta)
        {
            if (
                Context != null &&
                Context.MyLocation != null &&
                target != null &&
                target.LastBlipDirect != null &&
                target.BulletPower.HasValue
                )
            {
                GuessFactorData gfData = target.GetGuessFactorData();
                if (gfData != null)
                {
                    _stats       = gfData.Data;
                    _guessFactor = target.Energy > 0d ? gfData.GuessFactor : 0d;

                    _location = Context.MyLocation;
                    _direct   = target.LastBlipDirect;

                    _power          = target.BulletPower.Value;
                    _speed          = Rules.GetBulletSpeed(_power);
                    _maxEscapeAngle = VirtualBullet.GetMaximumEscapeAngle(_speed);

                    _minEscapeAngleRelativeVector = new Vector(
                        _direct.Magnitude,
                        new Angle(
                            _direct.Heading.Degrees
                            - _maxEscapeAngle));

                    _maxEscapeAngleRelativeVector = new Vector(
                        _direct.Magnitude,
                        new Angle(
                            _direct.Heading.Degrees
                            + _maxEscapeAngle));

                    _guessFactorRelativeVector = new Vector(
                        _direct.Magnitude,
                        new Angle(
                            _direct.Heading.Degrees
                            + _guessFactor * _maxEscapeAngle));

                    return(_location + _guessFactorRelativeVector);
                }
            }

            return(null);
        }