Ejemplo n.º 1
0
        //Applies the parameters to the parachute
        internal void Apply(bool toSymmetryCounterparts, bool showMessage = true)
        {
            if (!showMessage && (GetErrors(true).Count > 0 || GetErrors(false).Count > 0))
            {
                this.editorGUI.failedVisible = true; return;
            }
            this.rcModule.mustGoDown     = this.mustGoDown;
            this.rcModule.deployOnGround = this.deployOnGround;
            this.rcModule.timer          = GUIUtils.ParseTime(this.timer);
            this.rcModule.cutSpeed       = float.Parse(this.cutSpeed);
            this.rcModule.spareChutes    = GUIUtils.ParseEmpty(this.spares);
            this.rcModule.chuteCount     = (int)this.rcModule.spareChutes;

            this.chutes.ForEach(c => c.ApplyChanges(toSymmetryCounterparts));

            if (toSymmetryCounterparts)
            {
                foreach (Part part in this.part.symmetryCounterparts)
                {
                    RealChuteModule module = part.Modules["RealChuteModule"] as RealChuteModule;
                    UpdateCaseTexture(part, module);
                    UpdateScale(part, module);

                    module.mustGoDown  = this.mustGoDown;
                    module.timer       = GUIUtils.ParseTime(this.timer);
                    module.cutSpeed    = float.Parse(this.cutSpeed);
                    module.spareChutes = GUIUtils.ParseEmpty(this.spares);

                    ProceduralChute pChute = part.Modules["ProceduralChute"] as ProceduralChute;
                    pChute.presetID       = this.presetID;
                    pChute.planets        = this.planets;
                    pChute.size           = this.size;
                    pChute.caseID         = this.caseID;
                    pChute.mustGoDown     = this.mustGoDown;
                    pChute.deployOnGround = this.deployOnGround;
                    pChute.timer          = this.timer;
                    pChute.cutSpeed       = this.cutSpeed;
                    pChute.spares         = this.spares;
                }
            }
            this.part.mass = this.rcModule.caseMass + this.rcModule.parachutes.Sum(p => p.chuteMass);
            if (showMessage)
            {
                this.editorGUI.successfulVisible = true;
                if (!this.editorGUI.warning)
                {
                    this.editorGUI.successfulWindow.height = 50;
                }
            }
            GameEvents.onEditorShipModified.Fire(EditorLogic.fetch.ship);
        }
Ejemplo n.º 2
0
        //Applies changes to the parachute
        internal void ApplyChanges(bool toSymmetryCounterparts)
        {
            this.parachute.material = this.material.name;
            this.parachute.mat      = this.material;

            if (this.templateGUI.calcSelect)
            {
                double m = this.templateGUI.getMass ? this.pChute.GetCraftMass(this.templateGUI.useDry) : double.Parse(this.templateGUI.mass);
                double alt = 0, acc = 0;
                switch (this.templateGUI.type)
                {
                case ParachuteType.Main:
                {
                    alt = double.Parse(this.pChute.landingAlt);
                    acc = (this.body.GeeASL * RCUtils.geeToAcc);
                    break;
                }

                case ParachuteType.Drogue:
                {
                    alt = double.Parse(this.templateGUI.refDepAlt);
                    acc = (this.body.GeeASL * RCUtils.geeToAcc);
                    break;
                }

                case ParachuteType.Drag:
                {
                    alt = double.Parse(this.pChute.landingAlt);
                    acc = double.Parse(this.templateGUI.deceleration);
                    break;
                }

                default:
                    break;
                }
                double density = this.body.GetDensityAtAlt(alt, this.body.GetMaxTemperatureAtAlt(alt));
                double speed   = double.Parse(this.templateGUI.landingSpeed);
                speed *= speed;

                Debug.Log(String.Format("[RealChute]: {0} {1} - m: {2}t, alt: {3}m, ρ: {4}kg/m³, v²: {5}m²/s², a: {6}m/s²", this.part.partInfo.title, RCUtils.ParachuteNumber(this.id), m, alt, density, speed, acc));

                this.parachute.deployedDiameter = RCUtils.Round(Math.Sqrt((8000 * m * acc) / (Math.PI * speed * material.dragCoefficient * density * double.Parse(this.templateGUI.chuteCount))));
                float maxDiam = (this.textures != null || this.textures.models.Count > 0) ? this.model.maxDiam : 70;
                if (this.parachute.deployedDiameter > this.model.maxDiam)
                {
                    this.parachute.deployedDiameter = maxDiam;
                    this.editorGUI.warning          = true;
                }
                else
                {
                    this.editorGUI.warning = false;
                }
                this.parachute.preDeployedDiameter = RCUtils.Round(this.templateGUI.type == ParachuteType.Main ? (this.parachute.deployedDiameter / 20) : (this.parachute.deployedDiameter / 2));
                Debug.Log(String.Format("[RealChute]: {0} {1} - depDiam: {2}m, preDepDiam: {3}m", this.part.partInfo.title, RCUtils.ParachuteNumber(this.id), this.parachute.deployedDiameter, this.parachute.preDeployedDiameter));
            }

            else
            {
                this.parachute.preDeployedDiameter = RCUtils.Round(float.Parse(this.templateGUI.preDepDiam));
                this.parachute.deployedDiameter    = RCUtils.Round(float.Parse(this.templateGUI.depDiam));
                Debug.Log(String.Format("[RealChute]: {0} {1} - depDiam: {2}m, preDepDiam: {3}m", this.part.partInfo.title, RCUtils.ParachuteNumber(this.id), this.parachute.deployedDiameter, this.parachute.preDeployedDiameter));
            }

            this.parachute.minIsPressure = this.templateGUI.isPressure;
            if (this.templateGUI.isPressure)
            {
                this.parachute.minPressure = float.Parse(this.templateGUI.predepClause);
            }
            else
            {
                this.parachute.minDeployment = float.Parse(this.templateGUI.predepClause);
            }
            this.parachute.deploymentAlt      = float.Parse(this.templateGUI.deploymentAlt);
            this.parachute.cutAlt             = GUIUtils.ParseEmpty(this.templateGUI.cutAlt);
            this.parachute.preDeploymentSpeed = float.Parse(this.templateGUI.preDepSpeed);
            this.parachute.deploymentSpeed    = float.Parse(this.templateGUI.depSpeed);

            if (toSymmetryCounterparts)
            {
                foreach (Part part in this.part.symmetryCounterparts)
                {
                    Parachute sym = ((RealChuteModule)part.Modules["RealChuteModule"]).parachutes[id];
                    sym.material            = this.material.name;
                    sym.mat                 = this.material;
                    sym.deployedDiameter    = this.parachute.deployedDiameter;
                    sym.preDeployedDiameter = this.parachute.preDeployedDiameter;
                    sym.minIsPressure       = this.templateGUI.isPressure;
                    sym.minPressure         = this.parachute.minPressure;
                    sym.minDeployment       = this.parachute.minDeployment;
                    sym.deploymentAlt       = this.parachute.deploymentAlt;
                    sym.cutAlt              = this.parachute.cutAlt;
                    sym.preDeploymentSpeed  = this.parachute.preDeploymentSpeed;
                    sym.deploymentSpeed     = this.parachute.deploymentSpeed;

                    TemplateGUI template = ((ProceduralChute)part.Modules["ProceduralChute"]).chutes[id].templateGUI;
                    template.chuteID       = this.templateGUI.chuteID;
                    template.typeID        = this.templateGUI.typeID;
                    template.modelID       = this.templateGUI.modelID;
                    template.materialsID   = this.templateGUI.materialsID;
                    template.isPressure    = this.templateGUI.isPressure;
                    template.calcSelect    = this.templateGUI.calcSelect;
                    template.getMass       = this.templateGUI.getMass;
                    template.useDry        = this.templateGUI.useDry;
                    template.preDepDiam    = this.templateGUI.preDepDiam;
                    template.depDiam       = this.templateGUI.depDiam;
                    template.predepClause  = this.templateGUI.predepClause;
                    template.mass          = this.templateGUI.mass;
                    template.landingSpeed  = this.templateGUI.landingSpeed;
                    template.deceleration  = this.templateGUI.deceleration;
                    template.refDepAlt     = this.templateGUI.refDepAlt;
                    template.chuteCount    = this.templateGUI.chuteCount;
                    template.deploymentAlt = this.templateGUI.deploymentAlt;
                    template.cutAlt        = this.templateGUI.cutAlt;
                    template.preDepSpeed   = this.templateGUI.preDepSpeed;
                    template.depSpeed      = this.templateGUI.depSpeed;
                }
            }
        }