示例#1
0
            private IEnumerator <bool> TargetingRoutine()
            {
                if (control.GetNaturalGravity() == Vector3D.Zero && control.GetShipSpeed() < 2)         // Easy
                {
                    quartic = new QuarticTargeting(control.GetVelocityVector(), control.GetPosition(), maxProjectileVel);

                    Vector3D?result = quartic.CalculateTrajectory(target);
                    if (result.HasValue)
                    {
                        onRoutineFinish?.Invoke(result.Value);
                    }
                    else
                    {
                        onRoutineFail?.Invoke();
                    }

                    yield return(false);
                }
                else                                                                                  // This may take a while...
                {
                    double timescale      = 0.1;
                    var    projectileInfo = new AdvancedSimTargeting.ProjectileInfo(200, maxProjectileVel, timescale, control.GetPosition(), control.GetVelocityVector());
                    simTargeting = new AdvancedSimTargeting(projectileInfo, target, control, ingameTime, 25, true, maxProjectileVel, timescale);
                    simTargeting.onSimComplete += OnSimValid;
                    simTargeting.onSimFail     += OnSimFail;

                    yield return(true);

                    while (keepRunning)
                    {
                        simTargeting.Tick();
                        yield return(true);
                    }
                }
            }
        public void OnEntityDetected(HaE_Entity entity)
        {
            if (Vector3D.DistanceSquared(entity.entityInfo.Position, control.GetPosition()) > 1000 * 1000)
            {
                return;
            }

            if (IgnoreEventAfterOnce)
            {
                return;
            }

            if (control.GetShipSpeed() < maxActiveRotorGunVel)
            {
                gridCannonTargeting.NewTarget(entity.entityInfo);
            }
            else
            {
                foreach (var cannon in rotorTurretGroups)
                {
                    cannon.TargetDirection(ref Vector3D.Zero);
                }
            }

            statusWriter.UpdateStatus(StatusWriter.TargetingStatus.Targeting);

            missileCannonTargeting.NewTarget(entity.entityInfo);
            basicTargeting.UpdateValues(control.GetVelocityVector(), control.GetPosition(), maxGatlingBulletVel);
            var result = basicTargeting.CalculateTrajectory(entity.entityInfo);

            if (result.HasValue)
            {
                TargetSolvedGatling(result.Value);
            }

            IgnoreEventAfterOnce = true;
        }