Example #1
0
        public ProtoAntenna(Vessel v, ProtoPartSnapshot p, ProtoPartModuleSnapshot ppms)
        {
            ConfigNode n = new ConfigNode();

            ppms.Save(n);
            Name         = p.partInfo.title;
            Consumption  = 0;
            Guid         = v.id;
            mProtoPart   = p;
            mProtoModule = ppms;
            try
            {
                mDishTarget = new Guid(n.GetValue("RTAntennaTarget"));
            }
            catch (ArgumentException)
            {
                mDishTarget = Guid.Empty;
            }
            double temp_double;
            float  temp_float;
            bool   temp_bool;

            Dish      = Single.TryParse(n.GetValue("RTDishRange"), out temp_float) ? temp_float : 0.0f;
            CosAngle  = Double.TryParse(n.GetValue("RTDishCosAngle"), out temp_double) ? temp_double : 0.0;
            Omni      = Single.TryParse(n.GetValue("RTOmniRange"), out temp_float) ? temp_float : 0.0f;
            Powered   = Boolean.TryParse(n.GetValue("IsRTPowered"), out temp_bool) ? temp_bool : false;
            Activated = Boolean.TryParse(n.GetValue("IsRTActive"), out temp_bool) ? temp_bool : false;

            RTLog.Notify(ToString());
        }
        public ProtoAntenna(Vessel v, ProtoPartSnapshot p, ProtoPartModuleSnapshot ppms)
        {
            ConfigNode n = new ConfigNode();
            ppms.Save(n);
            Name = p.partInfo.title;
            try {
                mTarget = new Guid(n.GetValue("RTAntennaTarget"));
                DishRange = Single.Parse(n.GetValue("RTDishRange"));
                DishFactor = Double.Parse(n.GetValue("RTDishFactor"));
                OmniRange = Single.Parse(n.GetValue("RTOmniRange"));
            }
            catch (ArgumentException) {
                mTarget = Guid.Empty;
                DishRange = 0.0f;
                DishFactor = 1.0f;
                OmniRange = 0.0f;
                RTUtil.Log("ProtoAntenna parsing error. Default values assumed.");
            }

            mProtoPart = p;
            mProtoModule = ppms;
            Vessel = v;
            RTUtil.Log("ProtoAntenna: DishRange: {0}, OmniRange: {1}, Name: {2}, DishTarget: {3})",
                DishRange, OmniRange, Vessel.vesselName, DishTarget);
        }
Example #3
0
        public ProtoAntenna(Vessel v, ProtoPartSnapshot p, ProtoPartModuleSnapshot ppms)
        {
            ConfigNode n = new ConfigNode();
            ppms.Save(n);
            Name = p.partInfo.title;
            Consumption = 0;
            Guid = v.id;
            mProtoPart = p;
            mProtoModule = ppms;
            try
            {
                mDishTarget = new Guid(n.GetValue("RTAntennaTarget"));
            }
            catch (ArgumentException)
            {
                mDishTarget = Guid.Empty;
            }
            double temp_double;
            float temp_float;
            bool temp_bool;
            Dish = Single.TryParse(n.GetValue("RTDishRange"), out temp_float) ? temp_float : 0.0f;
            CosAngle = Double.TryParse(n.GetValue("RTDishCosAngle"), out temp_double) ? temp_double : 0.0;
            Omni = Single.TryParse(n.GetValue("RTOmniRange"), out temp_float) ? temp_float : 0.0f;
            Powered = Boolean.TryParse(n.GetValue("IsRTPowered"), out temp_bool) ? temp_bool : false;
            Activated = Boolean.TryParse(n.GetValue("IsRTActive"), out temp_bool) ? temp_bool : false;

            RTLog.Notify(ToString());
        }
Example #4
0
        public ProtoAntenna(Vessel v, ProtoPartSnapshot p, ProtoPartModuleSnapshot ppms)
        {
            ConfigNode n = new ConfigNode();

            ppms.Save(n);
            Name         = p.partInfo.title;
            mVessel      = v;
            mProtoPart   = p;
            mProtoModule = ppms;
            try {
                mTarget          = new Guid(n.GetValue("RTAntennaTarget"));
                CurrentDishRange = Single.Parse(n.GetValue("RTDishRange"));
                DishFactor       = Double.Parse(n.GetValue("RTDishFactor"));
                CurrentOmniRange = Single.Parse(n.GetValue("RTOmniRange"));
            }
            catch (ArgumentException) {
                mTarget          = Guid.Empty;
                CurrentDishRange = 0.0f;
                DishFactor       = 1.0f;
                CurrentOmniRange = 0.0f;
                RTUtil.Log("ProtoAntenna parsing error. Default values assumed.");
            }
            RTUtil.Log("ProtoAntenna: DishRange: {0}, OmniRange: {1}, Name: {2}, DishTarget: {3}",
                       CurrentDishRange, CurrentOmniRange, v.vesselName, DishTarget);
        }
        public ProtoAntenna(Vessel v, ProtoPartSnapshot p, ProtoPartModuleSnapshot ppms)
        {
            ConfigNode n = new ConfigNode();

            ppms.Save(n);
            Name = p.partInfo.title;
            try {
                mTarget    = new Guid(n.GetValue("RTAntennaTarget"));
                DishRange  = Single.Parse(n.GetValue("RTDishRange"));
                DishFactor = Double.Parse(n.GetValue("RTDishFactor"));
                OmniRange  = Single.Parse(n.GetValue("RTOmniRange"));
            }
            catch (ArgumentException) {
                mTarget    = Guid.Empty;
                DishRange  = 0.0f;
                DishFactor = 1.0f;
                OmniRange  = 0.0f;
            }

            mProtoPart   = p;
            mProtoModule = ppms;
            Vessel       = v;
            RTUtil.Log("ProtoAntenna: DishRange: {0}, OmniRange: {1}, Name: {2}, DishTarget: {3})",
                       DishRange, OmniRange, Vessel.vesselName, DishTarget);
        }
Example #6
0
        public static bool HasValue(this ProtoPartModuleSnapshot ppms, String name)
        {
            var n = new ConfigNode();

            ppms.Save(n);
            return(n.HasValue(name));
        }
Example #7
0
        public void ReloadDishRange()
        {
            if (isLoaded)
            {
                try
                {
                    if (RTUtils.containsField(partModule, "dishRange"))
                    {
                        this.dishRange = (float)partModule.Fields.GetValue("dishRange");
                    }
                    else
                    {
                        this.dishRange = 0;
                    }
                }
                catch (Exception)
                { }
            }
            else
            {
                ConfigNode n = new ConfigNode();
                protoPartModule.Save(n);

                if (n.HasValue("dishRange"))
                {
                    this.dishRange = float.Parse(n.GetValue("dishRange"));
                }
                else
                {
                    this.dishRange = 0;
                }
            }
        }
Example #8
0
        public SatSettingNode(ProtoPartModuleSnapshot s, Vessel v, ProtoPartSnapshot sn)
        {
            this.protoPartModule = s;
            this.vessel = v;
            this.snapshot = sn;
            isLoaded = false;

            ConfigNode n = new ConfigNode();
            protoPartModule.Save(n);

            if (n.HasValue("pointedAt"))
                this.pointedAt = new Target(n.GetValue("pointedAt"));
            else
                this.pointedAt = new Target();

            if (n.HasValue("dishRange"))
                this.dishRange = float.Parse(n.GetValue("dishRange"));
            else
                this.dishRange = 0;

            if (n.HasValue("antennaName"))
                this.antennaName = n.GetValue("antennaName");

            for (int i = 0; i < RTGlobals.targets.Count; i++)
            {
                if (pointedAt.Equals(RTGlobals.targets[i])) { selectedTarget = i; break; }
            }
        }
Example #9
0
        public static bool GetBool(this ProtoPartModuleSnapshot ppms, String value)
        {
            var n = new ConfigNode();

            ppms.Save(n);
            bool result;

            return(Boolean.TryParse(n.GetValue(value) ?? "False", out result) && result);
        }
Example #10
0
        public static bool HasValue(this ProtoPartModuleSnapshot ppms, String value)
        {
            var n = new ConfigNode();

            ppms.Save(n);
            bool result;

            return(Boolean.TryParse(value, out result) ? result : false);
        }
Example #11
0
        public static bool GetBool(this ProtoPartModuleSnapshot ppms, String value)
        {
            var n = new ConfigNode();

            ppms.Save(n);
            try {
                return(Boolean.Parse(n.GetValue(value) ?? "False"));
            } catch (ArgumentException) {
                return(false);
            }
        }
Example #12
0
        /// <summary>
        /// Searches a ProtoPartModuleSnapshot for an integer field
        /// </summary>
        ///
        /// <returns>The value of the field named by <paramref name="value"/> in the PartModule represented
        ///     by <paramref name="ppms"/></returns>
        /// <param name="ppms">The ProtoPartModule to query</param>
        /// <param name="value">The name of a member PartModule </param>
        ///
        /// <exception cref="System.ArgumentException">Thrown if <paramref name="value"/> does not exist
        ///     or cannot be parsed as an integer.</exception>
        /// <exceptionsafe>The program state is unchanged in the event of an exception.</exceptionsafe>
        public static int GetInt(this ProtoPartModuleSnapshot ppms, String value)
        {
            var n = new ConfigNode();

            ppms.Save(n);
            int result;

            if (Int32.TryParse(n.GetValue(value) ?? "", out result))
            {
                return(result);
            }
            throw new ArgumentException(String.Format("No integer '{0}' in ProtoPartModule", value), "value");
        }
Example #13
0
        public static bool HasValue(this ProtoPartModuleSnapshot ppms, String value)
        {
            var n = new ConfigNode();

            ppms.Save(n);
            try {
                if (Boolean.Parse(n.GetValue(value)))
                {
                    return(true);
                }
            } catch (ArgumentException) {
                /* nothing */
            }
            return(false);
        }
Example #14
0
        public SatSettingNode(ProtoPartModuleSnapshot s, Vessel v, ProtoPartSnapshot sn)
        {
            this.protoPartModule = s;
            this.vessel          = v;
            this.snapshot        = sn;
            isLoaded             = false;

            ConfigNode n = new ConfigNode();

            protoPartModule.Save(n);

            if (n.HasValue("pointedAt"))
            {
                this.pointedAt = new Target(n.GetValue("pointedAt"));
            }
            else
            {
                this.pointedAt = new Target();
            }

            if (n.HasValue("dishRange"))
            {
                this.dishRange = float.Parse(n.GetValue("dishRange"));
            }
            else
            {
                this.dishRange = 0;
            }

            if (n.HasValue("antennaName"))
            {
                this.antennaName = n.GetValue("antennaName");
            }


            for (int i = 0; i < RTGlobals.targets.Count; i++)
            {
                if (pointedAt.Equals(RTGlobals.targets[i]))
                {
                    selectedTarget = i; break;
                }
            }
        }
Example #15
0
        public static double GetChuteArea(List <ProtoPartSnapshot> protoParts)
        {
            double RCParameter    = 0;
            bool   realChuteInUse = false;

            try
            {
                foreach (ProtoPartSnapshot p in protoParts)
                {
                    if (p.modules.Exists(ppms => ppms.moduleName == "RealChuteModule"))
                    {
                        if (!realChuteInUse)
                        {
                            RCParameter = 0;
                        }
                        //First off, get the PPMS since we'll need that
                        ProtoPartModuleSnapshot realChute = p.modules.First(mod => mod.moduleName == "RealChuteModule");
                        //Assuming that's not somehow null, then we continue
                        if (realChute != null) //Some of this was adopted from DebRefund, as Vendan's method of handling multiple parachutes is better than what I had.
                        {
                            //We make a list of ConfigNodes containing the parachutes (usually 1, but now there can be any number of them)
                            //We get that from the PPMS
                            ConfigNode rcNode = new ConfigNode();
                            realChute.Save(rcNode);

                            //It's existence means that RealChute is installed and in use on the craft (you could have it installed and use stock chutes, so we only check if it's on the craft)
                            realChuteInUse = true;

                            RCParameter += ProcessRealchute(rcNode);
                        }
                    }
                    else if (p.modules.Exists(ppms => ppms.moduleName == "RealChuteFAR")) //RealChute Lite for FAR
                    {
                        if (!realChuteInUse)
                        {
                            RCParameter = 0;
                        }

                        ProtoPartModuleSnapshot realChute = p.modules.First(mod => mod.moduleName == "RealChuteFAR");
                        float diameter = 0.0F; //realChute.moduleValues.GetValue("deployedDiameter")

                        if (realChute.moduleRef != null)
                        {
                            try
                            {
                                diameter = realChute.moduleRef.Fields.GetValue <float>("deployedDiameter");
                                Log.Info($"[SR] Diameter is {diameter}.");
                            }
                            catch (Exception e)
                            {
                                Debug.LogError("[SR] Exception while finding deployedDiameter for RealChuteFAR module on moduleRef.");
                                Debug.LogException(e);
                            }
                        }
                        else
                        {
                            Log.Info("[SR] moduleRef is null, attempting workaround to find diameter.");
                            object dDefault = p.partInfo.partPrefab.Modules["RealChuteFAR"]?.Fields?.GetValue("deployedDiameter"); //requires C# 6
                            if (dDefault != null)
                            {
                                diameter = Convert.ToSingle(dDefault);
                                Log.Info($"[SR] Workaround gave a diameter of {diameter}.");
                            }
                            else
                            {
                                Log.Info("[SR] Couldn't get default value, setting to 0 and calling it a day.");
                                diameter = 0.0F;
                            }
                        }
                        float dragC = 1.0f; //float.Parse(realChute.moduleValues.GetValue("staticCd"));
                        RCParameter += (dragC * Mathf.Pow(diameter, 2) * Math.PI / 4.0);

                        realChuteInUse = true;
                    }
                    else if (!realChuteInUse && p.modules.Exists(ppms => ppms.moduleName == "ModuleParachute"))
                    {
                        //Credit to m4v and RCSBuildAid: https://github.com/m4v/RCSBuildAid/blob/master/Plugin/CoDMarker.cs
                        Part         part      = p.partRef ?? p.partPrefab; //the part reference, or the part prefab
                        DragCubeList dragCubes = part.DragCubes;
                        dragCubes.SetCubeWeight("DEPLOYED", 1);
                        dragCubes.SetCubeWeight("SEMIDEPLOYED", 0);
                        dragCubes.SetCubeWeight("PACKED", 0);
                        dragCubes.SetOcclusionMultiplier(0);
                        Quaternion rotation = Quaternion.LookRotation(Vector3d.up);
                        try
                        {
                            rotation = Quaternion.LookRotation(part.partTransform?.InverseTransformDirection(Vector3d.up) ?? Vector3d.up);
                        }
                        catch (Exception)
                        {
                            //Debug.LogException(e);
                        }
                        dragCubes.SetDragVectorRotation(rotation);
                    }
                    if (!realChuteInUse)
                    {
                        Part         part      = p.partRef ?? p.partPrefab; //the part reference, or the part prefab
                        DragCubeList dragCubes = part.DragCubes;
                        dragCubes.ForceUpdate(false, true);
                        dragCubes.SetDragWeights();
                        dragCubes.SetPartOcclusion();

                        Vector3 dir = Vector3d.up;
                        dragCubes.SetDrag(dir, 0.03f); //mach 0.03, or about 10m/s

                        double dragCoeff = dragCubes.AreaDrag * PhysicsGlobals.DragCubeMultiplier;

                        RCParameter += (dragCoeff * PhysicsGlobals.DragMultiplier);
                    }
                }
            }
            catch (Exception e)
            {
                Debug.LogError("[SR] Error occured while trying to determine total chute area.");
                Debug.LogException(e);
            }
            return(RCParameter);
        }