示例#1
0
        public void Simulate(double alt, double pressure, double time)
        {
            switch (state)
            {
            case ModuleParachute.deploymentStates.STOWED:
                if (alt < 3 * p.deployAltitude)
                {
                    state = ModuleParachute.deploymentStates.ACTIVE;
                }
                break;

            case ModuleParachute.deploymentStates.ACTIVE:
                if (pressure >= p.minAirPressureToOpen)
                {
                    state        = ModuleParachute.deploymentStates.SEMIDEPLOYED;
                    openningTime = time;
                }

                break;

            case ModuleParachute.deploymentStates.SEMIDEPLOYED:
                if (alt < p.deployAltitude)
                {
                    state        = ModuleParachute.deploymentStates.DEPLOYED;
                    openningTime = time;
                }
                break;
            }
        }
        private void Init(ModuleParachute mp, double startTime, int limitChutesStage)
        {
            this.para  = mp;
            this.state = mp.deploymentState;

            willDeploy = limitChutesStage != -1 && para.part.inverseStage >= limitChutesStage;

            // Work out when the chute was put into its current state based on the current drag as compared to the stowed, semi deployed and fully deployed drag

            double timeSinceDeployment = 0;

            switch (mp.deploymentState)
            {
            case ModuleParachute.deploymentStates.SEMIDEPLOYED:
                if (mp.Anim.isPlaying)
                {
                    timeSinceDeployment = mp.Anim[mp.semiDeployedAnimation].time;
                }
                else
                {
                    timeSinceDeployment = 10000000;
                }
                break;

            case ModuleParachute.deploymentStates.DEPLOYED:
                if (mp.Anim.isPlaying)
                {
                    timeSinceDeployment = mp.Anim[mp.fullyDeployedAnimation].time;
                }
                else
                {
                    timeSinceDeployment = 10000000;
                }
                break;

            case ModuleParachute.deploymentStates.STOWED:
            case ModuleParachute.deploymentStates.ACTIVE:
                // If the parachute is stowed then for some reason para.parachuteDrag does not reflect the stowed drag. set this up by hand.
                timeSinceDeployment = 10000000;
                break;

            default:
                // otherwise set the time since deployment to be a very large number to indcate that it has been in that state for a long time (although we do not know how long!
                timeSinceDeployment = 10000000;
                break;
            }

            this.openningTime = startTime - timeSinceDeployment;

#if false
            Log.dbg("Parachute {0} parachuteDrag:{1} stowedDrag:{2} semiDeployedDrag:{3} fullyDeployedDrag:{4} part.maximum_drag:{5} part.minimum_drag:{6} semiDeploymentSpeed:{7} deploymentSpeed:{8} deploymentState:{9} timeSinceDeployment:{10}", para.name, this.parachuteDrag, para.stowedDrag, para.semiDeployedDrag, para.fullyDeployedDrag, para.part.maximum_drag, para.part.minimum_drag, para.semiDeploymentSpeed, para.deploymentSpeed, para.deploymentState, timeSinceDeployment);
            // Keep that test code until they fix the bug in the new parachute module
            if ((realDrag / parachuteDrag) > 1.01d || (realDrag / parachuteDrag) < 0.99d)
            {
                Log.dbg("Parachute {0} parachuteDrag:{1:0.000} RealDrag:{2:0.000} MinDrag:{3:0.000} MaxDrag:{4:0.000}", para.name, this.parachuteDrag, realDrag, para.part.minimum_drag, para.part.maximum_drag);
            }
#endif
        }
示例#3
0
        public SimulatedParachute(ModuleParachute p, double startTime)
        {
            this.p     = p;
            this.state = p.deploymentState;

            // Work out when the chute was put into its current state based on the current drag as compared to the stoed, semi deployed and fully deployed drag

            double timeSinceDeployment = 0;

            switch (p.deploymentState)
            {
            case ModuleParachute.deploymentStates.SEMIDEPLOYED:
                if (p.Anim.isPlaying)
                {
                    timeSinceDeployment = p.Anim[p.semiDeployedAnimation].time;
                }
                else
                {
                    timeSinceDeployment = 10000000;
                }
                break;

            case ModuleParachute.deploymentStates.DEPLOYED:
                if (p.Anim.isPlaying)
                {
                    timeSinceDeployment = p.Anim[p.fullyDeployedAnimation].time;
                }
                else
                {
                    timeSinceDeployment = 10000000;
                }
                break;

            case ModuleParachute.deploymentStates.STOWED:
            case ModuleParachute.deploymentStates.ACTIVE:
                // If the parachute is stowed then for some reason p.parachuteDrag does not reflect the stowed drag. set this up by hand.
                timeSinceDeployment = 10000000;
                break;

            default:
                // otherwise set the time since deployment to be a very large number to indcate that it has been in that state for a long time (although we do not know how long!
                timeSinceDeployment = 10000000;
                break;
            }

            this.openningTime = startTime - timeSinceDeployment;

            // This is the current drag for the parachute only
            this.parachuteDrag = p.part.maximum_drag - p.part.minimum_drag;

            //Debug.Log("Parachute " + p.name + " parachuteDrag:" + this.parachuteDrag + " stowedDrag:" + p.stowedDrag + " semiDeployedDrag:" + p.semiDeployedDrag + " fullyDeployedDrag:" + p.fullyDeployedDrag + " part.maximum_drag:" + p.part.maximum_drag + " part.minimum_drag:" + p.part.minimum_drag + " semiDeploymentSpeed:" + p.semiDeploymentSpeed + " deploymentSpeed:" + p.deploymentSpeed + " deploymentState:" + p.deploymentState + " timeSinceDeployment:" + timeSinceDeployment);
            // Keep that test code until they fix the bug in the new parachute module
            //if ((realDrag / parachuteDrag) > 1.01d || (realDrag / parachuteDrag) < 0.99d)
            //    Debug.Log("Parachute " + p.name + " parachuteDrag:" + this.parachuteDrag.ToString("F3") + " RealDrag:" + realDrag.ToString("F3") + " MinDrag:" + p.part.minimum_drag.ToString("F3") + " MaxDrag:" + p.part.maximum_drag.ToString("F3"));
        }
            public SimulatedParachute(ModuleParachute mp, SimCurves simCurve, double startTime, int limitChutesStage) : base(mp.part, simCurve)
            {
                this.para  = mp;
                this.state = mp.deploymentState;

                willDeploy = limitChutesStage != -1 && para.part.inverseStage >= limitChutesStage;

                // Work out when the chute was put into its current state based on the current drag as compared to the stowed, semi deployed and fully deployed drag

                double timeSinceDeployment = 0;

                switch (mp.deploymentState)
                {
                case ModuleParachute.deploymentStates.SEMIDEPLOYED:
                    if (mp.Anim.isPlaying)
                    {
                        timeSinceDeployment = mp.Anim[mp.semiDeployedAnimation].time;
                    }
                    else
                    {
                        timeSinceDeployment = 10000000;
                    }
                    break;

                case ModuleParachute.deploymentStates.DEPLOYED:
                    if (mp.Anim.isPlaying)
                    {
                        timeSinceDeployment = mp.Anim[mp.fullyDeployedAnimation].time;
                    }
                    else
                    {
                        timeSinceDeployment = 10000000;
                    }
                    break;

                case ModuleParachute.deploymentStates.STOWED:
                case ModuleParachute.deploymentStates.ACTIVE:
                    // If the parachute is stowed then for some reason para.parachuteDrag does not reflect the stowed drag. set this up by hand.
                    timeSinceDeployment = 10000000;
                    break;

                default:
                    // otherwise set the time since deployment to be a very large number to indcate that it has been in that state for a long time (although we do not know how long!
                    timeSinceDeployment = 10000000;
                    break;
                }

                this.openningTime = startTime - timeSinceDeployment;
            }
        public void Set(ModuleParachute mp, double startTime, int limitChutesStage)
        {
            this.para = mp;
            this.state = mp.deploymentState;

            willDeploy = limitChutesStage != -1 && para.part.inverseStage >= limitChutesStage;

            // Work out when the chute was put into its current state based on the current drag as compared to the stowed, semi deployed and fully deployed drag

            double timeSinceDeployment = 0;
            
            switch (mp.deploymentState)
            {
                case ModuleParachute.deploymentStates.SEMIDEPLOYED:
                    if (mp.Anim.isPlaying)
                        timeSinceDeployment = mp.Anim[mp.semiDeployedAnimation].time;
                    else
                        timeSinceDeployment = 10000000;
                    break;

                case ModuleParachute.deploymentStates.DEPLOYED:
                    if (mp.Anim.isPlaying)
                        timeSinceDeployment = mp.Anim[mp.fullyDeployedAnimation].time;
                    else
                        timeSinceDeployment = 10000000;
                    break;

                case ModuleParachute.deploymentStates.STOWED:
                case ModuleParachute.deploymentStates.ACTIVE:
                    // If the parachute is stowed then for some reason para.parachuteDrag does not reflect the stowed drag. set this up by hand. 
                    timeSinceDeployment = 10000000;
                    break;

                default:
                    // otherwise set the time since deployment to be a very large number to indcate that it has been in that state for a long time (although we do not know how long!
                    timeSinceDeployment = 10000000;
                    break;
            }

            this.openningTime = startTime - timeSinceDeployment;

            //Debug.Log("Parachute " + para.name + " parachuteDrag:" + this.parachuteDrag + " stowedDrag:" + para.stowedDrag + " semiDeployedDrag:" + para.semiDeployedDrag + " fullyDeployedDrag:" + para.fullyDeployedDrag + " part.maximum_drag:" + para.part.maximum_drag + " part.minimum_drag:" + para.part.minimum_drag + " semiDeploymentSpeed:" + para.semiDeploymentSpeed + " deploymentSpeed:" + para.deploymentSpeed + " deploymentState:" + para.deploymentState + " timeSinceDeployment:" + timeSinceDeployment);
            // Keep that test code until they fix the bug in the new parachute module
            //if ((realDrag / parachuteDrag) > 1.01d || (realDrag / parachuteDrag) < 0.99d)
            //    Debug.Log("Parachute " + para.name + " parachuteDrag:" + this.parachuteDrag.ToString("F3") + " RealDrag:" + realDrag.ToString("F3") + " MinDrag:" + para.part.minimum_drag.ToString("F3") + " MaxDrag:" + para.part.maximum_drag.ToString("F3"));
        }
示例#6
0
        public SimulatedParachute(ModuleParachute p)
        {
            this.p     = p;
            this.state = p.deploymentState;

            // Work out when the chute was put into its current state based on the current drag as compared to the stoed, semi deployed and fully deployed drag

            double timeSinceDeployment = 0;

            this.targetDrag    = p.targetDrag;
            this.parachuteDrag = p.parachuteDrag;

            switch (p.deploymentState)
            {
            case ModuleParachute.deploymentStates.SEMIDEPLOYED:
                // If the parachute is semi deployed calculate when it was semideployed by comparing the actual drag with the stowed drag and the semideployed drag.
                timeSinceDeployment = (p.parachuteDrag - p.stowedDrag) / (p.semiDeployedDrag - p.stowedDrag) * p.semiDeploymentSpeed;     // TODO there is an error in this, because the (semi)deployment does not increase the drag in a linear way. However this will only cause a problem for simulations run during the deployment and in unlikely to cause an error in the landing location.
                break;

            case ModuleParachute.deploymentStates.DEPLOYED:
                // If the parachute is deployed calculate when it was deployed by comparing the actual drag with the semideployed drag and the deployed drag.
                timeSinceDeployment = (p.parachuteDrag - p.semiDeployedDrag) / (p.fullyDeployedDrag - p.semiDeployedDrag) * p.deploymentSpeed;     // TODO there is an error in this, because the (semi)deployment does not increase the drag in a linear way. However this will only cause a problem for simulations run during the deployment and in unlikely to cause an error in the landing location.
                break;

            case ModuleParachute.deploymentStates.STOWED:
            case ModuleParachute.deploymentStates.ACTIVE:
                // If the parachute is stowed then for some reason p.parachuteDrag does not reflect the stowed drag. set this up by hand.
                this.parachuteDrag  = this.targetDrag = p.stowedDrag;
                timeSinceDeployment = 10000000;
                break;

            default:
                // otherwise set the time since deployment to be a very large number to indcate that it has been in that state for a long time (although we do not know how long!
                timeSinceDeployment = 10000000;
                break;
            }

            this.openningTime = -timeSinceDeployment;

            // Debug.Log("Parachute " + p.name + " parachuteDrag:" + p.parachuteDrag + " targetDrag:" + p.targetDrag + " stowedDrag:" + p.stowedDrag + " semiDeployedDrag:" + p.semiDeployedDrag + " fullyDeployedDrag:" + p.fullyDeployedDrag + " part.maximum_drag:" + p.part.maximum_drag + " part.minimum_drag:" + p.part.minimum_drag + " semiDeploymentSpeed:" + p.semiDeploymentSpeed + " deploymentSpeed:" + p.deploymentSpeed + " deploymentState:" + p.deploymentState + " timeSinceDeployment:" + timeSinceDeployment);
        }
示例#7
0
        public static ParachuteState ToParachuteState(this ModuleParachute.deploymentStates state)
        {
            switch (state)
            {
            case ModuleParachute.deploymentStates.ACTIVE:
                return(ParachuteState.Active);

            case ModuleParachute.deploymentStates.CUT:
                return(ParachuteState.Cut);

            case ModuleParachute.deploymentStates.DEPLOYED:
                return(ParachuteState.Deployed);

            case ModuleParachute.deploymentStates.SEMIDEPLOYED:
                return(ParachuteState.SemiDeployed);

            case ModuleParachute.deploymentStates.STOWED:
                return(ParachuteState.Stowed);

            default:
                throw new ArgumentOutOfRangeException(nameof(state));
            }
        }
示例#8
0
        public void Simulate(double alt, double pressure, double time)
        {
            switch (state)
            {
                case ModuleParachute.deploymentStates.STOWED:
                    if (alt < 3 * p.deployAltitude)
                        state = ModuleParachute.deploymentStates.ACTIVE;
                    break;
                case ModuleParachute.deploymentStates.ACTIVE:
                    if (pressure >= p.minAirPressureToOpen)
                    {
                        state = ModuleParachute.deploymentStates.SEMIDEPLOYED;
                        openningTime = time;
                    }

                    break;
                case ModuleParachute.deploymentStates.SEMIDEPLOYED:
                    if (alt < p.deployAltitude)
                    {
                        state = ModuleParachute.deploymentStates.DEPLOYED;
                        openningTime = time;
                    }
                    break;
            }
        }
示例#9
0
 public SimulatedParachute(ModuleParachute p)
 {
     this.p = p;
     state = p.deploymentState;
 }
示例#10
0
        // Consider activating, semi deploying or deploying a parachute. returns true if the state has changed
        public bool Simulate(double altATGL, double altASL, double endASL, double pressure, double time, double semiDeployMultiplier)
        {
            bool stateChanged = false;

            switch (state)
            {
            case ModuleParachute.deploymentStates.STOWED:
                if (altATGL < semiDeployMultiplier * p.deployAltitude)
                {
                    state        = ModuleParachute.deploymentStates.ACTIVE;
                    stateChanged = true;
                    activatedAGL = altATGL;
                    activatedASL = altASL;
                    // Immediately check to see if the parachute should be semi deployed, rather than waiting for another iteration.
                    if (pressure >= p.minAirPressureToOpen)
                    {
                        state                 = ModuleParachute.deploymentStates.SEMIDEPLOYED;
                        openningTime          = time;
                        semiDeployAGL         = altATGL;
                        semiDeployASL         = altASL;
                        targetASLAtSemiDeploy = endASL;
                    }
                }
                break;

            case ModuleParachute.deploymentStates.ACTIVE:
                if (pressure >= p.minAirPressureToOpen)
                {
                    state                 = ModuleParachute.deploymentStates.SEMIDEPLOYED;
                    stateChanged          = true;
                    openningTime          = time;
                    semiDeployAGL         = altATGL;
                    semiDeployASL         = altASL;
                    targetASLAtSemiDeploy = endASL;
                }

                break;

            case ModuleParachute.deploymentStates.SEMIDEPLOYED:
                if (altATGL < p.deployAltitude)
                {
                    state                 = ModuleParachute.deploymentStates.DEPLOYED;
                    stateChanged          = true;
                    openningTime          = time;
                    fullDeployAGL         = altATGL;
                    fullDeployASL         = altASL;
                    targetASLAtFullDeploy = endASL;
                }
                break;
            }

            // Now that we have potentially changed states calculate the current drag or the parachute in whatever state (or transition to a state) that it is in.
            float normalizedTime;

            // Depending on the state that we are in consider if we are part way through a deployment.
            if (state == ModuleParachute.deploymentStates.SEMIDEPLOYED)
            {
                normalizedTime = (float)Math.Min((time - openningTime) / p.semiDeploymentSpeed, 1);
            }
            else if (state == ModuleParachute.deploymentStates.DEPLOYED)
            {
                normalizedTime = (float)Math.Min((time - openningTime) / p.deploymentSpeed, 1);
            }
            else
            {
                normalizedTime = 1;
            }

            // Are we deploying in any way? We know if we are deploying or not if normalized time is less than 1
            if (normalizedTime < 1)
            {
                this.deploying = true;
            }
            else
            {
                this.deploying = false;
            }

            // If we are deploying or semi deploying then use Lerp to replicate the way the game increases the drag as we deploy.
            if (state == ModuleParachute.deploymentStates.SEMIDEPLOYED)
            {
                this.parachuteDrag = Mathf.Lerp(p.stowedDrag, p.semiDeployedDrag, Mathf.Pow(normalizedTime, p.deploymentCurve));
            }
            else if (state == ModuleParachute.deploymentStates.DEPLOYED)
            {
                this.parachuteDrag = Mathf.Lerp(p.semiDeployedDrag, p.fullyDeployedDrag, normalizedTime);
            }

            return(stateChanged);
        }
示例#11
0
        // Consider activating, semi deploying or deploying a parachute. returns true if the state has changed
        public override bool Simulate(double altATGL, double altASL, double endASL, double pressure, double shockTemp, double time, double semiDeployMultiplier)
        {
            if (!willDeploy)
            {
                return(false);
            }
            switch (state)
            {
            case ModuleParachute.deploymentStates.STOWED:
                if (altATGL < semiDeployMultiplier * para.deployAltitude && shockTemp * para.machHeatMult < para.chuteMaxTemp * para.safeMult)
                {
                    state = ModuleParachute.deploymentStates.ACTIVE;
                    //activatedAGL = altATGL;
                    //activatedASL = altASL;
                    // Immediately check to see if the parachute should be semi deployed, rather than waiting for another iteration.
                    if (pressure >= para.minAirPressureToOpen)
                    {
                        state        = ModuleParachute.deploymentStates.SEMIDEPLOYED;
                        openningTime = time;
                        //semiDeployAGL = altATGL;
                        //semiDeployASL = altASL;
                        //targetASLAtSemiDeploy = endASL;
                    }
                }
                break;

            case ModuleParachute.deploymentStates.ACTIVE:
                if (pressure >= para.minAirPressureToOpen)
                {
                    state        = ModuleParachute.deploymentStates.SEMIDEPLOYED;
                    openningTime = time;
                    //semiDeployAGL = altATGL;
                    //semiDeployASL = altASL;
                    //targetASLAtSemiDeploy = endASL;
                }

                break;

            case ModuleParachute.deploymentStates.SEMIDEPLOYED:
                if (altATGL < para.deployAltitude)
                {
                    state        = ModuleParachute.deploymentStates.DEPLOYED;
                    openningTime = time;
                    //fullDeployAGL = altATGL;
                    //fullDeployASL = altASL;
                    //targetASLAtFullDeploy = endASL;
                }
                break;
            }

            // Now that we have potentially changed states calculate the current drag or the parachute in whatever state (or transition to a state) that it is in.
            float normalizedTime;

            // Depending on the state that we are in consider if we are part way through a deployment.
            if (state == ModuleParachute.deploymentStates.SEMIDEPLOYED)
            {
                normalizedTime = (float)Math.Min((time - openningTime) / para.semiDeploymentSpeed, 1);
            }
            else if (state == ModuleParachute.deploymentStates.DEPLOYED)
            {
                normalizedTime = (float)Math.Min((time - openningTime) / para.deploymentSpeed, 1);
            }
            else
            {
                normalizedTime = 1;
            }

            // Are we deploying in any way? We know if we are deploying or not if normalized time is less than 1
            if (normalizedTime < 1)
            {
                this.deploying = true;
            }
            else
            {
                this.deploying = false;
            }
            // If we are deploying or semi deploying then use Lerp to replicate the way the game increases the drag as we deploy.
            if (deploying && (state == ModuleParachute.deploymentStates.SEMIDEPLOYED || state == ModuleParachute.deploymentStates.DEPLOYED))
            {
                this.deployLevel = Mathf.Pow(normalizedTime, para.deploymentCurve);
            }
            else
            {
                this.deployLevel = 1;
            }
            switch (state)
            {
            case ModuleParachute.deploymentStates.STOWED:
            case ModuleParachute.deploymentStates.ACTIVE:
            case ModuleParachute.deploymentStates.CUT:
                SetCubeWeight("PACKED", 1f);
                SetCubeWeight("SEMIDEPLOYED", 0f);
                SetCubeWeight("DEPLOYED", 0f);
                break;

            case ModuleParachute.deploymentStates.SEMIDEPLOYED:
                SetCubeWeight("PACKED", 1f - deployLevel);
                SetCubeWeight("SEMIDEPLOYED", deployLevel);
                SetCubeWeight("DEPLOYED", 0f);
                break;

            case ModuleParachute.deploymentStates.DEPLOYED:
                SetCubeWeight("PACKED", 0f);
                SetCubeWeight("SEMIDEPLOYED", 1f - deployLevel);
                SetCubeWeight("DEPLOYED", deployLevel);
                break;
            }
            return(deploying);
        }
示例#12
0
 public SimulatedParachute(ModuleParachute p)
 {
     this.p = p;
     state  = p.deploymentState;
 }
示例#13
0
        // Consider activating, semi deploying or deploying a parachute. returns true if the state has changed
        public bool Simulate(double altATGL, double altASL, double endASL ,double pressure, double time, double semiDeployMultiplier)
        {
            bool stateChanged = false;
            switch (state)
            {
                case ModuleParachute.deploymentStates.STOWED:
                    if (altATGL < semiDeployMultiplier * p.deployAltitude)
                    {
                        state = ModuleParachute.deploymentStates.ACTIVE;
                        stateChanged = true;
                        activatedAGL = altATGL;
                        activatedASL = altASL;
                        // Immediately check to see if the parachute should be semi deployed, rather than waiting for another iteration.
                        if (pressure >= p.minAirPressureToOpen)
                        {
                            state = ModuleParachute.deploymentStates.SEMIDEPLOYED;
                            openningTime = time;
                            semiDeployAGL = altATGL;
                            semiDeployASL = altASL;
                            targetASLAtSemiDeploy = endASL;
                            this.targetDrag = p.semiDeployedDrag;
                        }
                    }
                    break;
                case ModuleParachute.deploymentStates.ACTIVE:
                    if (pressure >= p.minAirPressureToOpen)
                    {
                        state = ModuleParachute.deploymentStates.SEMIDEPLOYED;
                        stateChanged = true;
                        openningTime = time;
                        semiDeployAGL = altATGL;
                        semiDeployASL = altASL;
                        targetASLAtSemiDeploy = endASL;
                        this.targetDrag = p.semiDeployedDrag;
                    }

                    break;
                case ModuleParachute.deploymentStates.SEMIDEPLOYED:
                    if (altATGL < p.deployAltitude)
                    {
                        state = ModuleParachute.deploymentStates.DEPLOYED;
                        stateChanged = true;
                        openningTime = time;
                        fullDeployAGL = altATGL;
                        fullDeployASL = altASL;
                        targetASLAtFullDeploy = endASL;
                        this.targetDrag = p.fullyDeployedDrag;
                    }
                    break;
            }

            // Now that we have potentially changed states calculate the current drag or the parachute in whatever state (or transition to a state) that it is in.
            float normalizedTime;

            // Depending on the state that we are in consider if we are part way through a deployment.
            if (state == ModuleParachute.deploymentStates.SEMIDEPLOYED)
            {
                normalizedTime = (float)Math.Min((time - openningTime) / p.semiDeploymentSpeed, 1);
            }
            else if (state == ModuleParachute.deploymentStates.DEPLOYED)
            {
                normalizedTime = (float)Math.Min((time - openningTime) / p.deploymentSpeed, 1);
            }
            else
            {
                normalizedTime = 1;
            }

            // Are we deploying in any way? We know if we are deploying or not if normalized time is less than 1
            if (normalizedTime < 1)
            {
                this.deploying = true;
            }
            else
            {
                this.deploying = false;
            }

            // If we are deploying or semi deploying then use Lerp to replicate the way the game increases the drag as we deploy.
            if (state == ModuleParachute.deploymentStates.DEPLOYED || state == ModuleParachute.deploymentStates.SEMIDEPLOYED)
            {
                this.parachuteDrag = Mathf.Lerp((float)this.parachuteDrag, (float)this.targetDrag, normalizedTime);
            }

            return (stateChanged);
        }
示例#14
0
        public SimulatedParachute(ModuleParachute p)
        {
            this.p = p;
            this.state = p.deploymentState;

            // Work out when the chute was put into its current state based on the current drag as compared to the stoed, semi deployed and fully deployed drag

            double timeSinceDeployment = 0;
            this.targetDrag = p.targetDrag;
            this.parachuteDrag = p.parachuteDrag;

            switch (p.deploymentState)
            {
                case ModuleParachute.deploymentStates.SEMIDEPLOYED:
                    // If the parachute is semi deployed calculate when it was semideployed by comparing the actual drag with the stowed drag and the semideployed drag.
                    timeSinceDeployment = (p.parachuteDrag - p.stowedDrag) / (p.semiDeployedDrag - p.stowedDrag) * p.semiDeploymentSpeed; // TODO there is an error in this, because the (semi)deployment does not increase the drag in a linear way. However this will only cause a problem for simulations run during the deployment and in unlikely to cause an error in the landing location.
                    break;

                case ModuleParachute.deploymentStates.DEPLOYED:
                    // If the parachute is deployed calculate when it was deployed by comparing the actual drag with the semideployed drag and the deployed drag.
                    timeSinceDeployment = (p.parachuteDrag - p.semiDeployedDrag) / (p.fullyDeployedDrag - p.semiDeployedDrag) * p.deploymentSpeed; // TODO there is an error in this, because the (semi)deployment does not increase the drag in a linear way. However this will only cause a problem for simulations run during the deployment and in unlikely to cause an error in the landing location.
                    break;

                case ModuleParachute.deploymentStates.STOWED:
                case ModuleParachute.deploymentStates.ACTIVE:
                    // If the parachute is stowed then for some reason p.parachuteDrag does not reflect the stowed drag. set this up by hand.
                    this.parachuteDrag = this.targetDrag = p.stowedDrag;
                    timeSinceDeployment = 10000000;
                    break;

                default:
                    // otherwise set the time since deployment to be a very large number to indcate that it has been in that state for a long time (although we do not know how long!
                    timeSinceDeployment = 10000000;
                    break;
            }

            this.openningTime = -timeSinceDeployment;

            // Debug.Log("Parachute " + p.name + " parachuteDrag:" + p.parachuteDrag + " targetDrag:" + p.targetDrag + " stowedDrag:" + p.stowedDrag + " semiDeployedDrag:" + p.semiDeployedDrag + " fullyDeployedDrag:" + p.fullyDeployedDrag + " part.maximum_drag:" + p.part.maximum_drag + " part.minimum_drag:" + p.part.minimum_drag + " semiDeploymentSpeed:" + p.semiDeploymentSpeed + " deploymentSpeed:" + p.deploymentSpeed + " deploymentState:" + p.deploymentState + " timeSinceDeployment:" + timeSinceDeployment);
        }
        // Consider activating, semi deploying or deploying a parachute. returns true if the state has changed
        public override bool Simulate(double altATGL, double altASL, double endASL, double pressure, double time, double semiDeployMultiplier)
        {
            if (!willDeploy)
                return false;

            switch (state)
            {
                case ModuleParachute.deploymentStates.STOWED:
                    if (altATGL < semiDeployMultiplier * para.deployAltitude)
                    {
                        state = ModuleParachute.deploymentStates.ACTIVE;
                        activatedAGL = altATGL;
                        activatedASL = altASL;
                        // Immediately check to see if the parachute should be semi deployed, rather than waiting for another iteration.
                        if (pressure >= para.minAirPressureToOpen)
                        {
                            state = ModuleParachute.deploymentStates.SEMIDEPLOYED;
                            openningTime = time;
                            semiDeployAGL = altATGL;
                            semiDeployASL = altASL;
                            targetASLAtSemiDeploy = endASL;
                        }
                    }
                    break;
                case ModuleParachute.deploymentStates.ACTIVE:
                    if (pressure >= para.minAirPressureToOpen)
                    {
                        state = ModuleParachute.deploymentStates.SEMIDEPLOYED;
                        openningTime = time;
                        semiDeployAGL = altATGL;
                        semiDeployASL = altASL;
                        targetASLAtSemiDeploy = endASL;
                    }

                    break;
                case ModuleParachute.deploymentStates.SEMIDEPLOYED:
                    if (altATGL < para.deployAltitude)
                    {
                        state = ModuleParachute.deploymentStates.DEPLOYED;
                        openningTime = time;
                        fullDeployAGL = altATGL;
                        fullDeployASL = altASL;
                        targetASLAtFullDeploy = endASL;
                    }
                    break;
            }

            // Now that we have potentially changed states calculate the current drag or the parachute in whatever state (or transition to a state) that it is in.
            float normalizedTime;

            // Depending on the state that we are in consider if we are part way through a deployment.
            if (state == ModuleParachute.deploymentStates.SEMIDEPLOYED)
            {
                normalizedTime = (float)Math.Min((time - openningTime) / para.semiDeploymentSpeed, 1);
            }
            else if (state == ModuleParachute.deploymentStates.DEPLOYED)
            {
                normalizedTime = (float)Math.Min((time - openningTime) / para.deploymentSpeed, 1);
            }
            else
            {
                normalizedTime = 1;
            }

            // Are we deploying in any way? We know if we are deploying or not if normalized time is less than 1
            if (normalizedTime < 1)
            {
                this.deploying = true;
            }
            else
            {
                this.deploying = false;
            }

            // If we are deploying or semi deploying then use Lerp to replicate the way the game increases the drag as we deploy.
            if (deploying && (state == ModuleParachute.deploymentStates.SEMIDEPLOYED || state == ModuleParachute.deploymentStates.DEPLOYED))
            {
                this.deployLevel = Mathf.Pow(normalizedTime, para.deploymentCurve);
            }
            else
            {
                this.deployLevel = 1;
            }

            switch (state)
            {
                case ModuleParachute.deploymentStates.STOWED:
                case ModuleParachute.deploymentStates.ACTIVE:
                case ModuleParachute.deploymentStates.CUT:
                    SetCubeWeight("PACKED", 1f);
                    SetCubeWeight("SEMIDEPLOYED", 0f);
                    SetCubeWeight("DEPLOYED", 0f);
                    break;

                case ModuleParachute.deploymentStates.SEMIDEPLOYED:
                    SetCubeWeight("PACKED", 1f - deployLevel);
                    SetCubeWeight("SEMIDEPLOYED", deployLevel);
                    SetCubeWeight("DEPLOYED", 0f);
                    break;

                case ModuleParachute.deploymentStates.DEPLOYED:
                    SetCubeWeight("PACKED", 0f);
                    SetCubeWeight("SEMIDEPLOYED", 1f - deployLevel);
                    SetCubeWeight("DEPLOYED", deployLevel);
                    break;
            }

            return deploying;

        }