public override void OnStart(StartState state)
 {
     laser  = GetLaser();
     wm     = GetWM();
     camera = GetCamera();
     Setup();
     base.OnStart(state);
 }
        private ModuleTargetingCamera GetCamera()
        {
            ModuleTargetingCamera c = null;

            c = part.FindModuleImplementing <ModuleTargetingCamera>();

            return(c);
        }
Exemple #3
0
 public static void RegisterLaserPoint(ModuleTargetingCamera cam)
 {
     if (ActiveLasers.Contains(cam))
     {
         return;
     }
     else
     {
         ActiveLasers.Add(cam);
     }
 }
Exemple #4
0
 protected void SetLaserTargeting()
 {
     if (TargetingMode == TargetingModes.Laser)
     {
         laserStartPosition = MissileReferenceTransform.position;
         if (lockedCamera)
         {
             TargetAcquired = true;
             TargetPosition = lastLaserPoint = lockedCamera.groundTargetPosition;
             targetingPod   = lockedCamera;
         }
     }
 }
Exemple #5
0
        protected void UpdateLaserTarget()
        {
            if (TargetAcquired)
            {
                if (lockedCamera && lockedCamera.groundStabilized && !lockedCamera.gimbalLimitReached && lockedCamera.surfaceDetected) //active laser target
                {
                    TargetPosition     = lockedCamera.groundTargetPosition;
                    TargetVelocity     = (TargetPosition - lastLaserPoint) / Time.fixedDeltaTime;
                    TargetAcceleration = Vector3.zero;
                    lastLaserPoint     = TargetPosition;

                    if (GuidanceMode == GuidanceModes.BeamRiding && TimeIndex > 0.25f && Vector3.Dot(GetForwardTransform(), part.transform.position - lockedCamera.transform.position) < 0)
                    {
                        TargetAcquired = false;
                        lockedCamera   = null;
                    }
                }
                else //lost active laser target, home on last known position
                {
                    if (CMSmoke.RaycastSmoke(new Ray(transform.position, lastLaserPoint - transform.position)))
                    {
                        //Debug.Log("Laser missileBase affected by smoke countermeasure");
                        float angle = VectorUtils.FullRangePerlinNoise(0.75f * Time.time, 10) * BDArmorySettings.SMOKE_DEFLECTION_FACTOR;
                        TargetPosition     = VectorUtils.RotatePointAround(lastLaserPoint, transform.position, VectorUtils.GetUpDirection(transform.position), angle);
                        TargetVelocity     = Vector3.zero;
                        TargetAcceleration = Vector3.zero;
                        lastLaserPoint     = TargetPosition;
                    }
                    else
                    {
                        TargetPosition = lastLaserPoint;
                    }
                }
            }
            else
            {
                ModuleTargetingCamera foundCam = null;
                bool parentOnly = (GuidanceMode == GuidanceModes.BeamRiding);
                foundCam = BDATargetManager.GetLaserTarget(this, parentOnly);
                if (foundCam != null && foundCam.cameraEnabled && foundCam.groundStabilized && BDATargetManager.CanSeePosition(foundCam.groundTargetPosition, vessel.transform.position, MissileReferenceTransform.position))
                {
                    Debug.Log("[BDArmory]: Laser guided missileBase actively found laser point. Enabling guidance.");
                    lockedCamera   = foundCam;
                    TargetAcquired = true;
                }
            }
        }
Exemple #6
0
        private static ModuleTargetingCamera GetModuleTargeting(bool parentOnly, Vector3 missilePosition, Vector3 position, float maxOffBoresight, Vessel vessel, Vessel sourceVessel)
        {
            ModuleTargetingCamera finalCam = null;
            float smallestAngle            = 360;

            List <ModuleTargetingCamera> .Enumerator cam = ActiveLasers.GetEnumerator();
            while (cam.MoveNext())
            {
                if (cam.Current == null)
                {
                    continue;
                }
                if (parentOnly && !(cam.Current.vessel == vessel || cam.Current.vessel == sourceVessel))
                {
                    continue;
                }
                if (!cam.Current.cameraEnabled || !cam.Current.groundStabilized || !cam.Current.surfaceDetected ||
                    cam.Current.gimbalLimitReached)
                {
                    continue;
                }

                float angle = Vector3.Angle(missilePosition, cam.Current.groundTargetPosition - position);
                if (!(angle < maxOffBoresight) || !(angle < smallestAngle) ||
                    !CanSeePosition(cam.Current.groundTargetPosition, vessel.transform.position,
                                    (vessel.transform.position + missilePosition)))
                {
                    continue;
                }

                smallestAngle = angle;
                finalCam      = cam.Current;
            }
            cam.Dispose();
            return(finalCam);
        }