Exemplo n.º 1
0
 void reboundConscience(KerbalGData kerbalGData, bool isCommander)
 {
     if (isCommander)
     {
         kerbalGData.gLocFadeAmount -= conf.gLocFadeSpeed;
     }
     if (kerbalGData.gLocFadeAmount <= 0)
     {
         InputLockManager.RemoveControlLock(CONTROL_LOCK_ID);
         kerbalGData.gLocFadeAmount = 0;
     }
 }
Exemplo n.º 2
0
 void loseConscience(KerbalGData kerbalGData, bool isCommander)
 {
     kerbalGData.gLocFadeAmount += conf.gLocFadeSpeed;
     if (kerbalGData.gLocFadeAmount > MAX_GLOC_FADE)
     {
         kerbalGData.gLocFadeAmount = MAX_GLOC_FADE;
         if (isCommander)
         {
             InputLockManager.SetControlLock(ControlTypes.ALL_SHIP_CONTROLS, CONTROL_LOCK_ID);
         }
         if ((conf.gLocScreenWarning != null) && (conf.gLocScreenWarning.Length > 0))
         {
             ScreenMessages.PostScreenMessage(conf.gLocScreenWarning);
         }
     }
 }
Exemplo n.º 3
0
        public void Update()
        {
            if (paused) {
                return;
            }

            Vessel vessel = FlightGlobals.ActiveVessel;
            Part referencePart = vessel.GetReferenceTransformPart();

            commander = null; //the commander is recalculated every update
            playEffects = false; //this changes to true later if all neccessary conditions are met

            //Return without any effect if the vessel hasn't any crew
            if ((vessel.GetCrewCount() == 0)) {
                return;
            }

            if (!gAudio.IsBoundToTransform()) {
                gAudio.bindToTransform(FlightCamera.fetch.mainCamera.transform);
            }

            if (referencePart.CrewCapacity > 0) { //otherwise the vessel is controlled via probe core
                //Find a crew member that most likely is controlling the vessel. So he is the one who sees the effects.
                foreach (ProtoCrewMember crewMember in vessel.GetVesselCrew()) {
                    if (crewMember.seat.part.isControlSource) {
                        commander = bestCommander(commander, crewMember);
                    }
                }
            }
            if (commander == null) { //if there's still no commander in the vessel then control lock must be removed because it is probably a probe core that has control at the moment
                InputLockManager.RemoveControlLock(CONTROL_LOCK_ID);
            }

            //Calcualte g-effects for each crew member
            foreach (ProtoCrewMember crewMember in vessel.GetVesselCrew()) {

                if ( (crewMember.rosterStatus.Equals(ProtoCrewMember.RosterStatus.Dead)) || (crewMember.rosterStatus.Equals(ProtoCrewMember.RosterStatus.Missing)) ) {
                    continue;
                }

                playEffects =
                    crewMember.Equals(commander) &&
                    (!conf.IVAOnly || (CameraManager.Instance.currentCameraMode == CameraManager.CameraMode.IVA)) &&
                    !MapView.MapIsEnabled;

                gAudio.SetAudioEnabled(playEffects);

                KerbalGData gData;
                if (!kerbalGDict.TryGetValue(crewMember.name, out gData)) {
                    gData = new KerbalGData();
                    kerbalGDict.Add(crewMember.name, gData);
                }

                //Calculate modifer by Kerbal individual charateristics
                float kerbalModifier = 1;
                conf.traitModifiers.TryGetValue(crewMember.experienceTrait.Title, out kerbalModifier);
                if (crewMember.gender == ProtoCrewMember.Gender.Female) {
                    kerbalModifier *= conf.femaleModifier;
                }

                //Calculate G forces
                Vector3d gAcceleration = FlightGlobals.getGeeForceAtPosition(vessel.GetWorldPos3D()) - vessel.acceleration;
                Vector3d cabinAcceleration = vessel.transform.InverseTransformDirection(gAcceleration); //vessel.transform is an active part's transform
                downwardG = cabinAcceleration.z / G_CONST * (downwardG-1 > 0 ? conf.downwardGMultiplier : conf.upwardGMultiplier);
                forwardG = cabinAcceleration.y / G_CONST * (forwardG > 0 ? conf.forwardGMultiplier : conf.backwardGMultiplier);

                gData.cumulativeG -= Math.Sign(gData.cumulativeG) * conf.gResistance * kerbalModifier;

                if ((downwardG > conf.positiveThreshold) || (downwardG < conf.negativeThreshold) || (forwardG > conf.positiveThreshold) || (forwardG < conf.negativeThreshold)) {

                    double rebCompensation = conf.gResistance * kerbalModifier - conf.deltaGTolerance * conf.deltaGTolerance / kerbalModifier; //this is calculated so the rebound is in equilibrium with cumulativeG at the very point of G threshold
                    gData.cumulativeG += Math.Sign(downwardG-1+forwardG) * rebCompensation + (Math.Abs(downwardG-1)*(downwardG-1) + Math.Abs(forwardG) * forwardG) / kerbalModifier;

                    gAudio.stopBreath();
                    gData.needBreath = 0;

                    if (Math.Abs(gData.cumulativeG) > conf.GLOC_CUMULATIVE_G) {
                        loseConscience(gData, crewMember.Equals(commander));
                        gData.needBreath = 0;
                        gAudio.stopHeartBeats();
                    } else {
                        //Positive and frontal G sound effects
                        if( ((downwardG > conf.positiveThreshold) || (forwardG > conf.positiveThreshold)) && (gData.cumulativeG > 0.1 * conf.MAX_CUMULATIVE_G)) {
                            gData.needBreath = (gData.needBreath > 0) || (gData.cumulativeG > 0.3 * conf.MAX_CUMULATIVE_G) ? (int)(1 + MAX_BREATHS * gData.cumulativeG / conf.MAX_CUMULATIVE_G) : 0;
                            gAudio.playGrunt(commander.gender.Equals(ProtoCrewMember.Gender.Female), -1f /*(float)((Math.Max(Math.Max(downwardG, forwardG), 10.0 + conf.positiveThreshold) - conf.positiveThreshold) / 10.0)*/);
                            //Negative G sound effects
                        } else if (gData.cumulativeG < -0.1 * conf.MAX_CUMULATIVE_G) {
                            if (gAudio.isHeartBeatsPlaying()) {
                                gAudio.setHeartBeatsVolume(Math.Min((float)(2 * Math.Abs(gData.cumulativeG + 0.1 * conf.MAX_CUMULATIVE_G) /(1 - 0.1) / conf.MAX_CUMULATIVE_G * conf.heartBeatVolume * GameSettings.VOICE_VOLUME), GameSettings.VOICE_VOLUME * conf.heartBeatVolume));
                            } else {
                                gAudio.playHeartBeats();
                            }
                        }
                    }

                } else {
                    //Breath back sound effect
                    if ((gData.needBreath > 0) && (gData.gLocFadeAmount == 0)) {
                        if (gAudio.tryPlayBreath(commander.gender.Equals(ProtoCrewMember.Gender.Female), (float)gData.needBreath / (float)MAX_BREATHS * conf.breathVolume * GameSettings.VOICE_VOLUME)) {
                            gData.needBreath -= 1;
                        }
                    }
                    if (Math.Abs(gData.cumulativeG) < 0.1 * conf.MAX_CUMULATIVE_G) {
                        reboundConscience(gData, crewMember.Equals(commander));
                    }
                }

                //If out of danger then stop negative G sound effects
                if (gData.cumulativeG > -0.3 * conf.MAX_CUMULATIVE_G) {
                    gAudio.stopHeartBeats();
                }
            }
        }
Exemplo n.º 4
0
 void reboundConscience(KerbalGData kerbalGData, bool isCommander)
 {
     if (isCommander) {
         kerbalGData.gLocFadeAmount -= conf.gLocFadeSpeed;
     }
     if (kerbalGData.gLocFadeAmount <= 0) {
         InputLockManager.RemoveControlLock(CONTROL_LOCK_ID);
         kerbalGData.gLocFadeAmount = 0;
     }
 }
Exemplo n.º 5
0
 void loseConscience(KerbalGData kerbalGData, bool isCommander)
 {
     kerbalGData.gLocFadeAmount += conf.gLocFadeSpeed;
     if (kerbalGData.gLocFadeAmount > MAX_GLOC_FADE) {
         kerbalGData.gLocFadeAmount = MAX_GLOC_FADE;
         if (isCommander) {
             InputLockManager.SetControlLock(ControlTypes.ALL_SHIP_CONTROLS, CONTROL_LOCK_ID);
         }
         if ( (conf.gLocScreenWarning != null) && (conf.gLocScreenWarning.Length > 0) ) {
             ScreenMessages.PostScreenMessage(conf.gLocScreenWarning);
         }
     }
 }
Exemplo n.º 6
0
        public void Update()
        {
            if (paused)
            {
                return;
            }

            Vessel vessel        = FlightGlobals.ActiveVessel;
            Part   referencePart = vessel.GetReferenceTransformPart();

            commander   = null;           //the commander is recalculated every update
            playEffects = false;          //this changes to true later if all neccessary conditions are met

            //Return without any effect if the vessel hasn't any crew
            if ((vessel.GetCrewCount() == 0))
            {
                return;
            }

            if (!gAudio.IsBoundToTransform())
            {
                gAudio.bindToTransform(FlightCamera.fetch.mainCamera.transform);
            }

            if (referencePart.CrewCapacity > 0)               //otherwise the vessel is controlled via probe core
            //Find a crew member that most likely is controlling the vessel. So he is the one who sees the effects.
            {
                foreach (ProtoCrewMember crewMember in vessel.GetVesselCrew())
                {
                    if (crewMember.seat.part.isControlSource)
                    {
                        commander = bestCommander(commander, crewMember);
                    }
                }
            }
            if (commander == null)               //if there's still no commander in the vessel then control lock must be removed because it is probably a probe core that has control at the moment
            {
                InputLockManager.RemoveControlLock(CONTROL_LOCK_ID);
            }

            //Calcualte g-effects for each crew member
            foreach (ProtoCrewMember crewMember in vessel.GetVesselCrew())
            {
                if ((crewMember.rosterStatus.Equals(ProtoCrewMember.RosterStatus.Dead)) || (crewMember.rosterStatus.Equals(ProtoCrewMember.RosterStatus.Missing)))
                {
                    continue;
                }

                playEffects =
                    crewMember.Equals(commander) &&
                    (!conf.IVAOnly || (CameraManager.Instance.currentCameraMode == CameraManager.CameraMode.IVA)) &&
                    !MapView.MapIsEnabled;

                gAudio.SetAudioEnabled(playEffects);

                KerbalGData gData;
                if (!kerbalGDict.TryGetValue(crewMember.name, out gData))
                {
                    gData = new KerbalGData();
                    kerbalGDict.Add(crewMember.name, gData);
                }

                //Calculate modifer by Kerbal individual charateristics
                float kerbalModifier = 1;
                conf.traitModifiers.TryGetValue(crewMember.experienceTrait.Title, out kerbalModifier);
                if (crewMember.gender == ProtoCrewMember.Gender.Female)
                {
                    kerbalModifier *= conf.femaleModifier;
                }

                //Calculate G forces
                Vector3d gAcceleration     = FlightGlobals.getGeeForceAtPosition(vessel.GetWorldPos3D()) - vessel.acceleration;
                Vector3d cabinAcceleration = vessel.transform.InverseTransformDirection(gAcceleration);                 //vessel.transform is an active part's transform
                downwardG = cabinAcceleration.z / G_CONST * (downwardG - 1 > 0 ? conf.downwardGMultiplier : conf.upwardGMultiplier);
                forwardG  = cabinAcceleration.y / G_CONST * (forwardG > 0 ? conf.forwardGMultiplier : conf.backwardGMultiplier);

                gData.cumulativeG -= Math.Sign(gData.cumulativeG) * conf.gResistance * kerbalModifier;

                if ((downwardG > conf.positiveThreshold) || (downwardG < conf.negativeThreshold) || (forwardG > conf.positiveThreshold) || (forwardG < conf.negativeThreshold))
                {
                    double rebCompensation = conf.gResistance * kerbalModifier - conf.deltaGTolerance * conf.deltaGTolerance / kerbalModifier;                     //this is calculated so the rebound is in equilibrium with cumulativeG at the very point of G threshold
                    gData.cumulativeG += Math.Sign(downwardG - 1 + forwardG) * rebCompensation + (Math.Abs(downwardG - 1) * (downwardG - 1) + Math.Abs(forwardG) * forwardG) / kerbalModifier;

                    gAudio.stopBreath();
                    gData.needBreath = 0;

                    if (Math.Abs(gData.cumulativeG) > conf.GLOC_CUMULATIVE_G)
                    {
                        loseConscience(gData, crewMember.Equals(commander));
                        gData.needBreath = 0;
                        gAudio.stopHeartBeats();
                    }
                    else
                    {
                        //Positive and frontal G sound effects
                        if (((downwardG > conf.positiveThreshold) || (forwardG > conf.positiveThreshold)) && (gData.cumulativeG > 0.1 * conf.MAX_CUMULATIVE_G))
                        {
                            gData.needBreath = (gData.needBreath > 0) || (gData.cumulativeG > 0.3 * conf.MAX_CUMULATIVE_G) ? (int)(1 + MAX_BREATHS * gData.cumulativeG / conf.MAX_CUMULATIVE_G) : 0;
                            gAudio.playGrunt(commander.gender.Equals(ProtoCrewMember.Gender.Female), -1f /*(float)((Math.Max(Math.Max(downwardG, forwardG), 10.0 + conf.positiveThreshold) - conf.positiveThreshold) / 10.0)*/);
                            //Negative G sound effects
                        }
                        else if (gData.cumulativeG < -0.1 * conf.MAX_CUMULATIVE_G)
                        {
                            if (gAudio.isHeartBeatsPlaying())
                            {
                                gAudio.setHeartBeatsVolume(Math.Min((float)(2 * Math.Abs(gData.cumulativeG + 0.1 * conf.MAX_CUMULATIVE_G) / (1 - 0.1) / conf.MAX_CUMULATIVE_G * conf.heartBeatVolume * GameSettings.VOICE_VOLUME), GameSettings.VOICE_VOLUME * conf.heartBeatVolume));
                            }
                            else
                            {
                                gAudio.playHeartBeats();
                            }
                        }
                    }
                }
                else
                {
                    //Breath back sound effect
                    if ((gData.needBreath > 0) && (gData.gLocFadeAmount == 0))
                    {
                        if (gAudio.tryPlayBreath(commander.gender.Equals(ProtoCrewMember.Gender.Female), (float)gData.needBreath / (float)MAX_BREATHS * conf.breathVolume * GameSettings.VOICE_VOLUME))
                        {
                            gData.needBreath -= 1;
                        }
                    }
                    if (Math.Abs(gData.cumulativeG) < 0.1 * conf.MAX_CUMULATIVE_G)
                    {
                        reboundConscience(gData, crewMember.Equals(commander));
                    }
                }

                //If out of danger then stop negative G sound effects
                if (gData.cumulativeG > -0.3 * conf.MAX_CUMULATIVE_G)
                {
                    gAudio.stopHeartBeats();
                }
            }
        }