Ejemplo n.º 1
0
        public override void OnUpdate()
        {
            Events["EnableDetection"].active  = !IsDetecting;
            Events["DisableDetection"].active = IsDetecting;
            Events["EnableSounds"].active     = !ScanningSound;
            Events["DisableSounds"].active    = ScanningSound;

            if (Misc.GetTrueAltitude(vessel) <= this.DetectingHeight)
            {
                if (IsDetecting)
                {
                    Status = powerRatio > 0 ? "Active" : "Insufficient Power";
                }
                else
                {
                    Status = "Idle";
                }
            }
            else
            {
                Status = "Out Of Range";
            }

            foreach (var animator in part.Modules.OfType <IDetectorAnimator>())
            {
                animator.IsDetecting = IsDetecting;
                animator.PowerRatio  = powerRatio;
            }
        }
Ejemplo n.º 2
0
        public override void OnFixedUpdate()
        {
            var    controller = KethaneController.GetInstance(this.vessel);
            double Altitude   = Misc.GetTrueAltitude(vessel);

            if (IsDetecting && this.vessel != null && this.vessel.gameObject.activeSelf && Altitude <= this.DetectingHeight)
            {
                var energyRequest = PowerConsumption * TimeWarp.fixedDeltaTime;
                var energyDrawn   = this.part.RequestResource("ElectricCharge", energyRequest);
                this.powerRatio = energyDrawn / energyRequest;
                TimerEcho      += Time.deltaTime * (1 + Math.Log(TimeWarp.CurrentRate)) * this.powerRatio;

                var TimerThreshold = this.DetectingPeriod + Altitude * 0.000005d; // 0,5s delay at 100km
                var DepositUnder   = controller.GetDepositUnder();

                if (TimerEcho >= TimerThreshold)
                {
                    if (DepositUnder != null && DepositUnder.Kethane >= 1.0f)
                    {
                        controller.DrawMap(true);
                        controller.LastLat      = vessel.latitude;
                        controller.LastLon      = Misc.clampDegrees(vessel.longitude);
                        controller.LastQuantity = DepositUnder.Kethane;
                        if (vessel == FlightGlobals.ActiveVessel && controller.ScanningSound)
                        {
                            PingDeposit.Play();
                        }
                    }
                    else
                    {
                        controller.DrawMap(false);
                        if (vessel == FlightGlobals.ActiveVessel && controller.ScanningSound)
                        {
                            PingEmpty.Play();
                        }
                    }
                    TimerEcho = 0;
                }
            }
            else
            {
                this.powerRatio = 0;
            }
        }
Ejemplo n.º 3
0
        public override void OnFixedUpdate()
        {
            double Altitude = Misc.GetTrueAltitude(vessel);

            if (IsDetecting && this.vessel != null && this.vessel.gameObject.activeSelf && Altitude <= this.DetectingHeight)
            {
                var energyRequest = PowerConsumption * TimeWarp.fixedDeltaTime;
                var energyDrawn   = this.part.RequestResource("ElectricCharge", energyRequest);
                this.powerRatio = energyDrawn / energyRequest;
                TimerEcho      += Time.deltaTime * (1 + Math.Log(TimeWarp.CurrentRate)) * this.powerRatio;

                var TimerThreshold = this.DetectingPeriod * (1 + Altitude * 0.000002d);

                if (TimerEcho >= TimerThreshold)
                {
                    var detected = false;
                    var cell     = MapOverlay.GetCellUnder(vessel.mainBody, vessel.transform.position);
                    if (resources.All(r => KethaneData.Current.Scans[r][vessel.mainBody.name][cell]))
                    {
                        return;
                    }
                    foreach (var resource in resources)
                    {
                        KethaneData.Current.Scans[resource][vessel.mainBody.name][cell] = true;
                        if (KethaneData.Current.GetCellDeposit(resource, vessel.mainBody, cell) != null)
                        {
                            detected = true;
                        }
                    }
                    MapOverlay.Instance.RefreshCellColor(cell, vessel.mainBody);
                    TimerEcho = 0;
                    if (vessel == FlightGlobals.ActiveVessel && ScanningSound)
                    {
                        (detected ? PingDeposit : PingEmpty).Play();
                    }
                }
            }
            else
            {
                this.powerRatio = 0;
            }
        }
Ejemplo n.º 4
0
        public override void OnUpdate()
        {
            Events["EnableDetection"].active  = !IsDetecting;
            Events["DisableDetection"].active = IsDetecting;
            var controller = KethaneController.GetInstance(this.vessel);

            Events["ShowMap"].active = !controller.ShowDetectorWindow;
            Events["HideMap"].active = controller.ShowDetectorWindow;

            if (Misc.GetTrueAltitude(vessel) <= this.DetectingHeight)
            {
                if (IsDetecting)
                {
                    Status = powerRatio > 0 ? "Active" : "Insufficient Power";
                }
                else
                {
                    Status = "Idle";
                }
            }
            else
            {
                Status = "Out Of Range";
            }

            CelestialBody body = this.vessel.mainBody;

            if (body == null)
            {
                return;
            }

            var BaseT = this.part.transform.FindChild("model");

            if (!String.IsNullOrEmpty(PartTransform))
            {
                BaseT = BaseT.FindChild(PartTransform);
            }

            BaseT = BaseT.FindChild(BaseTransform);

            Vector3 bodyCoords = BaseT.InverseTransformPoint(body.transform.position);
            Vector2 pos        = Misc.CartesianToPolar(bodyCoords);

            var alpha = (float)Misc.NormalizeAngle(pos.x + 90);
            var beta  = (float)Misc.NormalizeAngle(pos.y);

            Transform RotH = BaseT.FindChild(HeadingTransform);
            Transform RotV = RotH.FindChild(ElevationTransform);

            if (Math.Abs(RotH.localEulerAngles.y - beta) > 90)
            {
                beta += 180;
                alpha = 360 - alpha;
            }

            var speed = Time.deltaTime * this.powerRatio * 60;

            RotH.localRotation = Quaternion.RotateTowards(RotH.localRotation, Quaternion.AngleAxis(beta, new Vector3(0, 1, 0)), speed);
            RotV.localRotation = Quaternion.RotateTowards(RotV.localRotation, Quaternion.AngleAxis(alpha, new Vector3(1, 0, 0)), speed);

            if (float.IsNaN(RotH.localRotation.w))
            {
                RotH.localRotation = Quaternion.identity;
            }
            if (float.IsNaN(RotV.localRotation.w))
            {
                RotV.localRotation = Quaternion.identity;
            }
        }