Exemplo n.º 1
0
 private void resetRadarStatus(RadarServiceNetCmds.RadarStatus value)
 {
     if (value == null || (RadarStatus != null && CompareTypeValue.AreEqual(RadarStatus, value)))
     {
         return;
     }
     _radarStatus = value.Clone();
     FirePropertyChanged("RadarConfigChanged");
 }
Exemplo n.º 2
0
        private void updateRadarConfigData(RadarStatus baseStatus)
        {
            int index = 0;

            _radarConfig[index++].BaseValue = baseStatus.Name;
            _radarConfig[index++].BaseValue = baseStatus.Longitude.ToString();
            _radarConfig[index++].BaseValue = baseStatus.Latitude.ToString();
            _radarConfig[index++].BaseValue = baseStatus.Altitude.ToString();
            _radarConfig[index++].BaseValue = baseStatus.Range.ToString();
            _radarConfig[index++].BaseValue = baseStatus.StartRange.ToString();
            _radarConfig[index++].BaseValue = baseStatus.StartScanAngle.ToString();
            _radarConfig[index++].BaseValue = baseStatus.OffsetAngle.ToString();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Scan for a target.
        /// </summary>
        private void ScanForTarget(FlightGlobals fg)
        {
            try
            {
                List <Vessel> vessels = fg.vessels;

                double currentScanDistance        = maxRangeMeters;
                double currentScanDistanceSquared = maxRangeMetersSquared;

                Vessel candidateTarget = null;
                for (int currentScanTarget = vessels.Count - 1; currentScanTarget >= 0; --currentScanTarget)
                {
                    // See if this one is a candidate.
                    Vessel candidate = vessels[currentScanTarget];

                    VesselType vesselType = candidate.vesselType;
                    if (candidate.id != vessel.id && candidate.mainBody == vessel.mainBody && !(vesselType == VesselType.EVA || vesselType == VesselType.Flag || vesselType == VesselType.Unknown) && (vesselType != VesselType.Debris || targetDebris))
                    {
                        Vector3d displacement     = (candidate.GetTransform().position - scanTransform.position);
                        double   cardinalDistance = Math.Max(Math.Abs(displacement.x), Math.Max(Math.Abs(displacement.y), Math.Abs(displacement.z)));
                        if (cardinalDistance < currentScanDistance)
                        {
                            // Within the current scanning distance on one axis.  Check for real distance (squared, so we're not wasting cycles on a square root operation).
                            double distSq = displacement.sqrMagnitude;
                            if (distSq < currentScanDistanceSquared)
                            {
                                // See if it's within our scanning angle.
                                float angle = Vector3.Angle(displacement.normalized, (scanTransformIsDockingNode) ? scanTransform.forward : scanTransform.up);
                                if (angle < scanAngle)
                                {
                                    currentScanDistanceSquared = distSq;
                                    currentScanDistance        = Math.Sqrt(distSq);
                                    candidateTarget            = candidate;
                                }
                            }
                        }
                    }
                }

                if (candidateTarget != null)
                {
                    status = RadarStatus.TRACKING;
                    fg.SetVesselTarget(candidateTarget);
                }
            }
            catch
            {
            }
        }
Exemplo n.º 4
0
        private void updateRadarStatusData(RadarStatus baseStatus)
        {
            int index = 0;

            _radarStatus[index++].BaseValue = baseStatus.BearingPulseStatus.ToString();
            _radarStatus[index++].BaseValue = baseStatus.ShipHeadingMarkerStatus.ToString();
            _radarStatus[index++].BaseValue = baseStatus.TriggerStatus.ToString();
            _radarStatus[index++].BaseValue = baseStatus.InterruptStatus.ToString();
            _radarStatus[index++].BaseValue = baseStatus.RoundPerMinute.ToString();
            _radarStatus[index++].BaseValue = baseStatus.PulseRepetitionRate.ToString();
            _radarStatus[index++].BaseValue = baseStatus.BPPerSweep.ToString();
            _radarStatus[index++].BaseValue = baseStatus.ADBits.ToString();
            _radarStatus[index++].BaseValue = baseStatus.SampleCount.ToString();
            _radarStatus[index++].BaseValue = baseStatus.ScanLineCount.ToString();
        }
Exemplo n.º 5
0
        private void resetRadarStatusFromRadarConfigChanged(RadarConfig radarConfig)
        {
            if (radarConfig == null)
            {
                return;
            }
            var radarStatusInfo = RadarStatus;

            radarStatusInfo.Name           = radarConfig.Name;
            radarStatusInfo.Longitude      = radarConfig.Longitude;
            radarStatusInfo.Latitude       = radarConfig.Latitude;
            radarStatusInfo.Altitude       = radarConfig.Altitude;
            radarStatusInfo.StartScanAngle = radarConfig.StartScanAngle;
            radarStatusInfo.StartRange     = radarConfig.StartRange;
            radarStatusInfo.Range          = radarConfig.Range;
            radarStatusInfo.OffsetAngle    = radarConfig.OffsetAngle;
            _radarStatus = radarStatusInfo;
        }
Exemplo n.º 6
0
        /// <summary>
        /// Do stuff, or not, depending on whether we're supposed to.
        /// </summary>
        public void FixedUpdate()
        {
            if (HighLogic.LoadedSceneIsEditor || !vessel.isActiveVessel)
            {
                return;
            }

            if (radarEnabled)
            {
                bool radarDeployed = true;
                bool radarBroken   = false;
                if (deployPart != null)
                {
                    radarDeployed = deployPart.useAnimation && deployPart.deployState == ModuleDeployablePart.DeployState.EXTENDED;
                    radarBroken   = deployPart.deployState == ModuleDeployablePart.DeployState.BROKEN;
                }
                else if (deployAnimator != null)
                {
                    radarDeployed = deployAnimator.IsMoving() == false && deployAnimator.animTime == 1.0f;
                }

                if (!radarDeployed)
                {
                    // If the radar's not deployed, we're done.
                    status = (radarBroken) ? RadarStatus.BROKEN : RadarStatus.NOT_DEPLOYED;
                    UpdateRadarStatus();
                    return;
                }
                status = RadarStatus.SCANNING;

                // Resources check
                if (resourceAmount > 0.0f)
                {
                    double requested = resourceAmount * TimeWarp.fixedDeltaTime;
                    double supplied  = part.RequestResource(resourceId, requested);
                    if (supplied < requested * 0.5f)
                    {
                        status = RadarStatus.NO_POWER;
                        UpdateRadarStatus();
                        return;
                    }
                }

                FlightGlobals fg     = FlightGlobals.fetch;
                ITargetable   target = fg.VesselTarget;
                if (target == null)
                {
                    // Scan
                    ScanForTarget(fg);
                }
                else if (targetDockingPorts && dock != null && (target is Vessel))
                {
                    Vessel targetVessel = target as Vessel;

                    if (!targetVessel.packed && targetVessel.loaded)
                    {
                        // Attempt to refine our target.
                        ModuleDockingNode        closestNode     = null;
                        float                    closestDistance = float.MaxValue;
                        List <ModuleDockingNode> docks           = targetVessel.FindPartModulesImplementing <ModuleDockingNode>();
                        if (docks != null)
                        {
                            for (int i = docks.Count - 1; i >= 0; --i)
                            {
                                ModuleDockingNode otherDock = docks[i];
                                // Only lock on to an available dock of the same type that is either ungendered or the opposite gender.
                                if (otherDock.state == "Ready" && (string.IsNullOrEmpty(nodeType) || nodeType == otherDock.nodeType) && (dock.gendered == false || dock.genderFemale != otherDock.genderFemale))
                                {
                                    Vector3 vectorToTarget = (otherDock.part.transform.position - scanTransform.position);
                                    if (vectorToTarget.sqrMagnitude < closestDistance)
                                    {
                                        closestDistance = vectorToTarget.sqrMagnitude;
                                        closestNode     = otherDock;
                                    }
                                }
                            }
                        }

                        if (closestNode != null)
                        {
                            fg.SetVesselTarget(closestNode);
                            status = RadarStatus.TRACKING;
                        }
                    }
                }
                else
                {
                    status = RadarStatus.TRACKING;
                }
            }
            else
            {
                status = RadarStatus.STANDBY;
            }

            UpdateRadarStatus();
        }