Exemple #1
0
 //Parachute predeployment
 public void PreDeploy()
 {
     this.Part.stackIcon.SetIconColor(XKCDColors.BrightYellow);
     this.capOff = true;
     if (RealChuteSettings.Instance.ActivateNyan)
     {
         this.Part.Effect("nyan", 1);
     }
     else
     {
         this.Part.Effect("rcpredeploy");
     }
     this.DeploymentState = DeploymentStates.PREDEPLOYED;
     this.parachute.gameObject.SetActive(true);
     this.cap.gameObject.SetActive(false);
     if (this.dragTimer.ElapsedMilliseconds != 0)
     {
         this.Part.SkipToAnimationEnd(this.preDeploymentAnimation);
     }
     else
     {
         this.Part.PlayAnimation(this.preDeploymentAnimation, 1f / this.preDeploymentSpeed);
     }
     this.dragTimer.Start();
 }
Exemple #2
0
 //Parachute cutting
 public void Cut()
 {
     if (RealChuteSettings.Instance.ActivateNyan)
     {
         this.Part.Effect("nyan", 0);
     }
     else
     {
         this.Part.Effect("rccut");
     }
     this.DeploymentState = DeploymentStates.CUT;
     this.parachute.gameObject.SetActive(false);
     this.played = false;
     if (!this.module.SecondaryChute || this.Parachutes.TrueForAll(p => p.DeploymentState == DeploymentStates.CUT))
     {
         this.module.SetRepack();
     }
     else if (this.module.SecondaryChute && this.Parachutes.Exists(p => p.DeploymentState == DeploymentStates.STOWED))
     {
         this.module.armed = true;
     }
     this.dragTimer.Reset();
     this.currentArea      = 0;
     this.chuteTemperature = RCUtils.startTemp;
 }
Exemple #3
0
        /// <summary>
        /// Creates a parachute object from the given RealChuteModule
        /// </summary>
        /// <param name="module">RealChuteModule to create the Parachute from</param>
        /// <param name="secondary">Wether this Parachute is the main or secondary parachute</param>
        public Parachute(RealChuteModule module, bool secondary)
        {
            this.module = module;
            this.secondary = secondary;
            if (this.secondary && this.material == "empty") { this.material = sec.material; }
            this.module.materials.TryGetMaterial(material, ref mat);
            this.parachute = this.part.FindModelTransform(parachuteName);
            this.cap = this.part.FindModelTransform(capName);
            this.parachute.gameObject.SetActive(false);
            this.part.InitiateAnimation(preDeploymentAnimation);
            this.part.InitiateAnimation(deploymentAnimation);

            if (!this.module.initiated)
            {
                deploymentState = DeploymentStates.STOWED;
                depState = "STOWED";
                played = false;
                this.cap.gameObject.SetActive(true);
            }

            if (HighLogic.LoadedSceneIsFlight)
            {
                deploymentState = getState;
                if (this.module.capOff)
                {
                    this.part.stackIcon.SetIconColor(XKCDColors.Red);
                    this.cap.gameObject.SetActive(false);
                }
            }
        }
Exemple #4
0
 /// <summary>
 /// Loads the Parachute from a ConfigNode.
 /// </summary>
 /// <param name="node">Node to load the Parachute from</param>
 private void Load(ConfigNode node)
 {
     node.TryGetValue("material", ref material);
     node.TryGetValue("preDeployedDiameter", ref preDeployedDiameter);
     node.TryGetValue("deployedDiameter", ref deployedDiameter);
     node.TryGetValue("minIsPressure", ref minIsPressure);
     node.TryGetValue("minDeployment", ref minDeployment);
     node.TryGetValue("minPressure", ref minPressure);
     node.TryGetValue("deploymentAlt", ref deploymentAlt);
     node.TryGetValue("cutAlt", ref cutAlt);
     node.TryGetValue("preDeploymentSpeed", ref preDeploymentSpeed);
     node.TryGetValue("deploymentSpeed", ref deploymentSpeed);
     node.TryGetValue("parachuteName", ref parachuteName);
     node.TryGetValue("baseParachuteName", ref baseParachuteName);
     node.TryGetValue("capName", ref capName);
     node.TryGetValue("preDeploymentAnimation", ref preDeploymentAnimation);
     node.TryGetValue("deploymentAnimation", ref deploymentAnimation);
     node.TryGetValue("forcedOrientation", ref forcedOrientation);
     node.TryGetValue("depState", ref depState);
     deploymentState = getState;
     if (!MaterialsLibrary.instance.TryGetMaterial(material, ref mat))
     {
         material = "Nylon";
         mat      = MaterialsLibrary.instance.GetMaterial("Nylon");
     }
     this.part.FindModelTransform(parachuteName).gameObject.SetActive(false);
 }
Exemple #5
0
        /// <summary>
        /// Creates a parachute object from the given RealChuteModule
        /// </summary>
        /// <param name="module">RealChuteModule to create the Parachute from</param>
        /// <param name="secondary">Wether this Parachute is the main or secondary parachute</param>
        public Parachute(RealChuteModule module, bool secondary)
        {
            this.module    = module;
            this.secondary = secondary;
            if (this.secondary && this.material == "empty")
            {
                this.material = sec.material;
            }
            this.module.materials.TryGetMaterial(material, ref mat);
            this.parachute = this.part.FindModelTransform(parachuteName);
            this.cap       = this.part.FindModelTransform(capName);
            this.parachute.gameObject.SetActive(false);
            this.part.InitiateAnimation(preDeploymentAnimation);
            this.part.InitiateAnimation(deploymentAnimation);

            if (!this.module.initiated)
            {
                deploymentState = DeploymentStates.STOWED;
                depState        = "STOWED";
                played          = false;
                this.cap.gameObject.SetActive(true);
            }

            if (HighLogic.LoadedSceneIsFlight)
            {
                deploymentState = getState;
                if (this.module.capOff)
                {
                    this.part.stackIcon.SetIconColor(XKCDColors.Red);
                    this.cap.gameObject.SetActive(false);
                }
            }
        }
Exemple #6
0
 //Repack actions
 internal void Repack()
 {
     deploymentState = DeploymentStates.STOWED;
     this.randomTimer.Reset();
     this.dragTimer.Reset();
     this.time   = 0;
     this.capOff = false;
     cap.gameObject.SetActive(true);
 }
Exemple #7
0
    private void animate(string mode)
    {
        if (anim != null)
        {
            animTime = anim[animationName].normalizedTime;

            if (deploymentStateEnum == DeploymentStates.Retracted) //fixes stupid unity animation timing (0 to 0.99 to 0)
            {
                animTime = 1f;
            }

            if (mode == "Deploy")
            {
                if (deploymentStateEnum == DeploymentStates.Retracted)
                {
                    animTime = 1f;
                }
                animSpeed           = -1f * customAnimationSpeed;
                deploymentStateEnum = DeploymentStates.Deploying;
                if (startDeployEffect != string.Empty)
                {
                    part.Effect(startDeployEffect);
                }
            }
            else if (mode == "Retract")
            {
                if (deploymentStateEnum == DeploymentStates.Deployed)
                {
                    animTime = 0f;
                }
                animSpeed           = 1f * customAnimationSpeed;
                deploymentStateEnum = DeploymentStates.Retracting;
                if (startRetractEffect != string.Empty)
                {
                    part.Effect(startRetractEffect);
                }
            }
            else if (mode == "Stop")
            {
                animSpeed           = 0f;
                deploymentStateEnum = DeploymentStates.Stopped;
            }

            anim[animationName].normalizedTime = animTime;
            anim[animationName].speed          = animSpeed;
            if (animSpeed != 0f)
            {
                anim.Play(animationName);
                setBrakeLight(BrakeStatus.deploying);
            }
            else
            {
                anim.Stop();
            }
        }
    }
Exemple #8
0
 //Repack actions
 public void Repack()
 {
     this.DeploymentState = DeploymentStates.STOWED;
     this.randomTimer.Reset();
     this.randomTime = (float)this.random.NextDouble();
     this.dragTimer.Reset();
     this.time   = 0;
     this.capOff = false;
     this.cap.gameObject.SetActive(true);
 }
Exemple #9
0
        //Initializes the chute
        public void Initialize()
        {
            MaterialsLibrary.Instance.TryGetMaterial(this.material, ref this.mat);

            //I know this seems random, but trust me, it's needed, else some parachutes don't animate, because f**k you, that's why.
            Animation anim = this.Part.FindModelAnimators(this.capName).FirstOrDefault();

            this.cap       = this.Part.FindModelTransform(this.capName);
            this.parachute = this.Part.FindModelTransform(this.parachuteName);
            if (this.parachute == null && !string.IsNullOrEmpty(this.baseParachuteName))
            {
                this.parachute = this.Part.FindModelTransform(this.baseParachuteName);
            }
            this.parachute.gameObject.SetActive(true);
            this.Part.InitiateAnimation(this.preDeploymentAnimation);
            this.Part.InitiateAnimation(this.deploymentAnimation);
            this.parachute.gameObject.SetActive(false);

            if (string.IsNullOrEmpty(this.baseParachuteName))
            {
                this.baseParachuteName = this.parachuteName;
            }

            if (!this.module.initiated)
            {
                this.played = false;
                this.cap.gameObject.SetActive(true);
            }
            if (HighLogic.LoadedSceneIsFlight)
            {
                this.randomX    = (float)((this.random.NextDouble() - 0.5) * 200);
                this.randomY    = (float)((this.random.NextDouble() - 0.5) * 200);
                this.randomTime = (float)this.random.NextDouble();
                if (this.time != 0)
                {
                    this.dragTimer = new PhysicsWatch(this.time);
                }
                if (this.capOff)
                {
                    this.Part.stackIcon.SetIconColor(XKCDColors.Red);
                    this.cap.gameObject.SetActive(false);
                }

                if (this.module.staged && this.DeploymentState != DeploymentStates.CUT)
                {
                    this.DeploymentState = DeploymentStates.STOWED;
                }
            }
        }
Exemple #10
0
 //Parachute predeployment
 public void PreDeploy()
 {
     this.part.stackIcon.SetIconColor(XKCDColors.BrightYellow);
     this.module.capOff = true;
     this.module.Events["GUIDeploy"].active = false;
     this.module.Events["GUIArm"].active    = false;
     this.part.Effect("rcpredeploy");
     deploymentState = DeploymentStates.PREDEPLOYED;
     depState        = stateString;
     parachute.gameObject.SetActive(true);
     cap.gameObject.SetActive(false);
     this.module.Events["GUICut"].active = true;
     this.part.PlayAnimation(preDeploymentAnimation, 1 / preDeploymentSpeed);
     dragTimer.Start();
 }
Exemple #11
0
 //Parachute deployment
 public void Deploy()
 {
     this.part.stackIcon.SetIconColor(XKCDColors.RadioactiveGreen);
     this.part.Effect("rcdeploy");
     this.deploymentState = DeploymentStates.DEPLOYED;
     if (!this.part.CheckAnimationPlaying(this.preDeploymentAnimation))
     {
         this.dragTimer.Restart();
         this.part.PlayAnimation(this.deploymentAnimation, 1f / this.deploymentSpeed);
         this.played = true;
     }
     else
     {
         this.played = false;
     }
 }
Exemple #12
0
 //Parachute cutting
 public void Cut()
 {
     this.part.Effect("rccut");
     deploymentState = DeploymentStates.CUT;
     parachute.gameObject.SetActive(false);
     this.played = false;
     if (!this.module.secondaryChute || this.parachutes.All(p => p.deploymentState == DeploymentStates.CUT))
     {
         this.module.SetRepack();
     }
     else if (this.module.secondaryChute && this.parachutes.Any(p => p.deploymentState == DeploymentStates.STOWED))
     {
         this.module.armed = true;
     }
     dragTimer.Reset();
 }
Exemple #13
0
        //Initializes the chute
        public void Initialize()
        {
            this.module.materials.TryGetMaterial(material, ref mat);

            anim     = this.part.FindModelAnimators(capName).FirstOrDefault();
            this.cap = this.part.FindModelTransform(capName);

            this.parachute = this.part.FindModelTransform(parachuteName);
            if (this.parachute == null && !string.IsNullOrEmpty(baseParachuteName))
            {
                this.parachute = this.part.FindModelTransform(baseParachuteName);
            }
            this.parachute.gameObject.SetActive(true);
            this.part.InitiateAnimation(preDeploymentAnimation);
            this.part.InitiateAnimation(deploymentAnimation);
            this.parachute.gameObject.SetActive(false);

            if (string.IsNullOrEmpty(baseParachuteName))
            {
                baseParachuteName = parachuteName;
            }

            if (!this.module.initiated)
            {
                played = false;
                this.cap.gameObject.SetActive(true);
            }
            if (HighLogic.LoadedSceneIsFlight)
            {
                if (this.time != 0)
                {
                    this.dragTimer = new PhysicsWatch(this.time);
                }
                if (this.capOff)
                {
                    this.part.stackIcon.SetIconColor(XKCDColors.Red);
                    this.cap.gameObject.SetActive(false);
                }

                if (this.module.staged && this.deploymentState != DeploymentStates.CUT)
                {
                    this.deploymentState = DeploymentStates.STOWED;
                }
            }
        }
Exemple #14
0
 //Parachute predeployment
 public void PreDeploy()
 {
     this.part.stackIcon.SetIconColor(XKCDColors.BrightYellow);
     this.capOff = true;
     this.part.Effect("rcpredeploy");
     deploymentState = DeploymentStates.PREDEPLOYED;
     parachute.gameObject.SetActive(true);
     cap.gameObject.SetActive(false);
     if (this.dragTimer.elapsedMilliseconds != 0)
     {
         this.part.SkipToAnimationEnd(preDeploymentAnimation);
     }
     else
     {
         this.part.PlayAnimation(preDeploymentAnimation, 1f / preDeploymentSpeed);
     }
     dragTimer.Start();
 }
Exemple #15
0
 //Parachute cutting
 public void Cut()
 {
     this.part.Effect("rccut");
     deploymentState = DeploymentStates.CUT;
     depState        = stateString;
     parachute.gameObject.SetActive(false);
     this.module.Events["GUICut"].active = false;
     this.played = false;
     if (!this.module.secondaryChute || sec.deploymentState == DeploymentStates.CUT)
     {
         this.module.SetRepack();
     }
     else if (this.module.secondaryChute && sec.deploymentState == DeploymentStates.STOWED)
     {
         this.module.armed = true;
     }
     dragTimer.Reset();
 }
Exemple #16
0
 //Parachute low deployment
 public void LowDeploy()
 {
     this.part.stackIcon.SetIconColor(XKCDColors.RadioactiveGreen);
     this.capOff = true;
     this.part.Effect("rcdeploy");
     deploymentState = DeploymentStates.LOWDEPLOYED;
     parachute.gameObject.SetActive(true);
     cap.gameObject.SetActive(false);
     if (this.dragTimer.elapsedMilliseconds != 0)
     {
         this.part.SkipToAnimationEnd(deploymentAnimation); this.played = true;
     }
     else
     {
         this.part.PlayAnimation(preDeploymentAnimation, 1f / preDeploymentSpeed);
     }
     dragTimer.Start();
 }
Exemple #17
0
 private void updateDeploymentState()
 {
     if (anim != null)
     {
         if (!anim.isPlaying)
         {
             if (deploymentStateEnum == DeploymentStates.Deploying)
             {
                 deploymentStateEnum = DeploymentStates.Deployed;
                 setBrakeLight(brakesEngaged);
             }
             else if (deploymentStateEnum == DeploymentStates.Retracting)
             {
                 deploymentStateEnum = DeploymentStates.Retracted;
                 setBrakeLight(brakesEngaged);
             }
         }
     }
 }
Exemple #18
0
 //Parachute cutting
 public void Cut()
 {
     this.part.Effect("rccut");
     deploymentState = DeploymentStates.CUT;
     depState = stateString;
     parachute.gameObject.SetActive(false);
     this.module.Events["GUICut"].active = false;
     this.played = false;
     if (!this.module.secondaryChute || sec.deploymentState == DeploymentStates.CUT) { this.module.SetRepack(); }
     else if (this.module.secondaryChute && sec.deploymentState == DeploymentStates.STOWED) { this.module.armed = true; }
     dragTimer.Reset();
 }
Exemple #19
0
    public override void OnStart(PartModule.StartState state)
    {
        try
        {
            deploymentStateEnum = (DeploymentStates)Enum.Parse(typeof(DeploymentStates), deploymentState);
        }
        catch
        {
            Debug.Log("FSwheel: Could not set deployment state " + deploymentState);
        }

        #region animation

        anim = part.FindModelAnimators(animationName).FirstOrDefault();
        if (anim != null)
        {
            hasAnimation = true;
            anim[animationName].layer = animationLayer;
            float startAnimTime = 0f;
            if (deploymentStateEnum == DeploymentStates.Retracted)
            {
                startAnimTime = 1f;
                animSpeed     = 1f * customAnimationSpeed;
            }
            else
            {
                animSpeed = -1f * customAnimationSpeed;
            }
            anim[animationName].normalizedTime = startAnimTime;
            anim[animationName].speed          = animSpeed;
            anim.Play(animationName);
        }
        #endregion

        #region In flight
        if (HighLogic.LoadedSceneIsFlight)
        {
            #region create wheel setup
            List <WheelCollider> colliderList   = new List <WheelCollider>();
            List <Transform>     wheelMeshList  = new List <Transform>();
            List <Transform>     suspensionList = new List <Transform>();

            for (int i = 0; i < numberOfWheels; i++)
            {
                string suffix = (i + 1).ToString(); // the names used are e.g. "Wheel", "Wheel2", "Wheel3", to remain compatible with stock wheels
                if (i == 0)
                {
                    suffix = "";
                }
                Transform colliderTransform = part.FindModelTransform(wheelColliderName + suffix);
                if (colliderTransform != null)
                {
                    WheelCollider collider = colliderTransform.GetComponent <WheelCollider>();
                    if (collider != null)
                    {
                        colliderList.Add(collider);
                    }
                }
                else
                {
                    Debug.Log("FSwheel: missing wheel collider " + wheelColliderName + suffix);
                }

                Transform wheelMeshTransform = part.FindModelTransform(wheelMeshName + suffix);
                if (wheelMeshTransform != null)
                {
                    wheelMeshList.Add(wheelMeshTransform);
                }
                else
                {
                    Debug.Log("FSwheel: missing wheel mesh " + wheelMeshName + suffix);
                }

                Transform suspensionTransform = part.FindModelTransform(suspensionParentName + suffix);
                if (suspensionTransform != null)
                {
                    suspensionList.Add(suspensionTransform);
                }
                else
                {
                    Debug.Log("FSwheel: missing suspensionParent " + suspensionParentName + suffix);
                }
            }

            wheelList.Create(colliderList, wheelMeshList, suspensionList);
            if (wheelList != null)
            {
                if (!wheelList.enabled)
                {
                    wheelList.enabled = true;
                }
            }

            // set the motor direction based on the first found wheelColliders orientation
            //Debug.Log("FSwheel: wheelist count is " + wheelList.wheels.Count);
            if (wheelList.wheels.Count > 0)
            {
                Debug.Log("FSwheel: reversemotorset: " + reverseMotorSet);
                if (!reverseMotorSet)                                                                                           //run only the first time the craft is loaded
                {
                    float dot = Vector3.Dot(wheelList.wheels[0].wheelCollider.transform.forward, vessel.ReferenceTransform.up); // up is forward
                    if (dot < 0)                                                                                                // below 0 means the engine is on the left side of the craft
                    {
                        reverseMotor = true;
                        //Debug.Log("FSwheel: Reversing motor, dot: " + dot);
                    }
                    else
                    {
                        reverseMotor = false;
                        //Debug.Log("FSwheel: Motor reversing skipped, dot: " + dot);
                    }
                    if (motorStartsReversed)
                    {
                        reverseMotor = !reverseMotor;
                    }
                    reverseMotorSet = true;
                }
            }

            if (disableColliderWhenRetracted)
            {
                if (deploymentStateEnum == DeploymentStates.Retracted)
                {
                    wheelList.enabled = false;
                }
            }

            //friction override
            if (overrideModelFrictionValues)
            {
                wheelList.forwardStiffness       = forwardsStiffness;
                wheelList.forwardsAsymptoteSlip  = forwardsAsymptoteSlip;
                wheelList.forwardsAsymptoteValue = forwardsAsymptoteValue;
                wheelList.forwardsExtremumSlip   = forwardsExtremumSlip;
                wheelList.forwardsExtremumValue  = forwardsExtremumValue;
                wheelList.sidewaysStiffness      = sidewaysStiffness;
                wheelList.sidewaysAsymptoteSlip  = sidewaysAsymptoteSlip;
                wheelList.sidewaysAsymptoteValue = sidewaysAsymptoteValue;
                wheelList.sidewaysExtremumSlip   = sidewaysExtremumSlip;
                wheelList.sidewaysExtremumValue  = sidewaysExtremumValue;
                wheelList.updateWheelFriction();
            }

            //optionally set collider and spring values
            if ((suspensionSpring >= 0f && suspensionDamper >= 0f && suspensionTargetPosition >= 0f) || overrideModelSpringValues)
            {
                wheelList.updateSpring(suspensionSpring, suspensionDamper, suspensionTargetPosition);
            }
            if (wheelColliderRadius >= 0f)
            {
                wheelList.radius = wheelColliderRadius;
            }
            else
            {
                wheelColliderRadius = wheelList.radius;
            }
            if (wheelColliderMass >= 0f)
            {
                wheelList.mass = wheelColliderMass;
            }
            if (wheelColliderSuspensionDistance >= 0f || overrideSuspensionDistance)
            {
                wheelList.suspensionDistance = wheelColliderSuspensionDistance;
            }
            else
            {
                wheelColliderSuspensionDistance = wheelList.suspensionDistance;
            }

            #endregion

            #region GUI popup

            /*
             * popup = new FSGUIPopup(part, "FSwheel", moduleID, FSGUIwindowID.wheel, new Rect(500f, 300f, 250f, 100f), "Wheel settings", new PopupElement("Suspension Settings:"));
             * popup.useInFlight = true;
             * wheelRadiusElement = new PopupElement("Radius", wheelColliderRadius.ToString());
             * suspensionDistanceElement = new PopupElement("Distance", wheelColliderSuspensionDistance.ToString());
             * suspensionSpringElement = new PopupElement("Spring", suspensionSpring.ToString());
             * suspensionDamperElement = new PopupElement("Damper", suspensionDamper.ToString());
             * suspensionTargetPositionElement = new PopupElement("Target pos", suspensionTargetPosition.ToString());
             * popup.sections[0].elements.Add(wheelRadiusElement);
             * popup.sections[0].elements.Add(suspensionDistanceElement);
             * popup.sections[0].elements.Add(suspensionSpringElement);
             * popup.sections[0].elements.Add(suspensionDamperElement);
             * popup.sections[0].elements.Add(suspensionTargetPositionElement);
             *
             * suspensionUpdateElement = new PopupElement(new PopupButton("Update", 0f, popupUpdateSuspension));
             * popup.sections[0].elements.Add(suspensionUpdateElement);
             */
            #endregion

            if (brakeEmissiveObjectName != string.Empty)
            {
                brakeEmissiveObject = part.FindModelTransform(brakeEmissiveObjectName);
            }
            setBrakeLight(brakesEngaged);

            #region set up fx
            if (useCustomParticleFX)
            {
                smokeFXtexture = GameDatabase.Instance.GetTexture(smokeFXtextureName, false);
                if (smokeFXtexture == null)
                {
                    useCustomParticleFX = false;
                }
                else
                {
                    for (int i = 0; i < wheelList.wheels.Count; i++)
                    {
                        wheelList.wheels[i].smokeFX = new FSBDparticleFX(wheelList.wheels[i].fxLocation, smokeFXtexture);
                        wheelList.wheels[i].smokeFX.AnimatorColor0 = new Color(1.0f, 1.0f, 1.0f, 0.8f);
                        wheelList.wheels[i].smokeFX.AnimatorColor1 = new Color(1.0f, 1.0f, 1.0f, 0.5f);
                        wheelList.wheels[i].smokeFX.AnimatorColor2 = new Color(1.0f, 1.0f, 1.0f, 0.2f);
                        wheelList.wheels[i].smokeFX.AnimatorColor3 = new Color(1.0f, 1.0f, 1.0f, 0.1f);
                        wheelList.wheels[i].smokeFX.AnimatorColor4 = new Color(1.0f, 1.0f, 1.0f, 0.0f);

                        wheelList.wheels[i].smokeFX.EmitterMinSize     = 0.3f;
                        wheelList.wheels[i].smokeFX.EmitterMaxSize     = 0.5f;
                        wheelList.wheels[i].smokeFX.EmitterMinEnergy   = 0.1f;
                        wheelList.wheels[i].smokeFX.EmitterMaxEnergy   = 0.3f;
                        wheelList.wheels[i].smokeFX.EmitterMinEmission = 0f;
                        wheelList.wheels[i].smokeFX.EmitterMaxEmission = 0f;
                        wheelList.wheels[i].smokeFX.AnimatorSizeGrow   = 0.1f;

                        wheelList.wheels[i].smokeFX.setupFXValues();
                    }
                }
            }

            #endregion


            //alg
            alg = GetComponent <BDAnimationModules.BDAdjustableLandingGear>();
        }

        #endregion

        #region GUI element changes
        Events["RaiseGear"].guiActiveUnfocused = guiActiveUnfocused;
        Events["RaiseGear"].unfocusedRange     = unfocusedRange;

        Events["LowerGear"].guiActiveUnfocused = guiActiveUnfocused;
        Events["LowerGear"].unfocusedRange     = unfocusedRange;

        Events["EnableMotorEvent"].guiActive        = !motorEnabled;
        Events["DisableMotorEvent"].guiActive       = motorEnabled;
        Events["EnableMotorEvent"].guiActiveEditor  = !motorEnabled;
        Events["DisableMotorEvent"].guiActiveEditor = motorEnabled;

        Events["brakesOnEvent"].guiActive        = !brakesEngaged;
        Events["brakesOffEvent"].guiActive       = brakesEngaged;
        Events["brakesOnEvent"].guiActiveEditor  = !brakesEngaged;
        Events["brakesOffEvent"].guiActiveEditor = brakesEngaged;

        Events["EnableReverseMotorEvent"].guiActive        = !reverseMotor;
        Events["DisableReverseMotorEvent"].guiActive       = reverseMotor;
        Events["EnableReverseMotorEvent"].guiActiveEditor  = !reverseMotor;
        Events["DisableReverseMotorEvent"].guiActiveEditor = reverseMotor;

        Events["brakesOnEvent"].guiActiveUnfocused  = guiActiveUnfocused;
        Events["brakesOffEvent"].guiActiveUnfocused = guiActiveUnfocused;

        if (!hasMotor)
        {
            //Events["EnableMotorEvent"].guiActive = false;
            //Events["DisableMotorEvent"].guiActive = false;
            Events["EnableMotorEvent"].active         = false;
            Events["DisableMotorEvent"].active        = false;
            Events["EnableReverseMotorEvent"].active  = false;
            Events["DisableReverseMotorEvent"].active = false;
        }
        if (!hasAnimation)
        {
            Events["RaiseGear"].active = false;
            Events["LowerGear"].active = false;
        }
        if (debugMode)
        {
            Events["increaseFrictionEvent"].guiActive = true;
            Events["decreaseFrictionEvent"].guiActive = true;
            Events["suspensionGUIEvent"].guiActive    = true;
        }

        if (brakesLockedOn)
        {
            Events["brakesOnEvent"].guiActive           = false;
            Events["brakesOffEvent"].guiActive          = false;
            Events["brakesOnEvent"].guiActiveUnfocused  = false;
            Events["brakesOffEvent"].guiActiveUnfocused = false;
        }

        #endregion
    }
Exemple #20
0
            public static bool IsDeployed(PartModule p)
            {
                DeploymentStates state = GetDeploymentState(p);

                return(state == DeploymentStates.DEPLOYED || state == DeploymentStates.PREDEPLOYED);
            }
Exemple #21
0
 //Repack actions
 internal void Repack()
 {
     deploymentState = DeploymentStates.STOWED;
     depState        = stateString;
     cap.gameObject.SetActive(true);
 }
    public override void OnStart(PartModule.StartState state)
    {
        try
        {
            deploymentStateEnum = (DeploymentStates)Enum.Parse(typeof(DeploymentStates), deploymentState);
        }
        catch
        {
            Debug.Log("FSwheel: Could not set deployment state " + deploymentState);
        }

        #region animation

        anim = part.FindModelAnimators(animationName).FirstOrDefault();
        if (anim != null)
        {
            hasAnimation = true;
            anim[animationName].layer = animationLayer;
            float startAnimTime = 0f;
            if (deploymentStateEnum == DeploymentStates.Retracted)
            {
                startAnimTime = 1f;
                animSpeed = 1f * customAnimationSpeed;
            }
            else
            {
                animSpeed = -1f * customAnimationSpeed;
            }
            anim[animationName].normalizedTime = startAnimTime;
            anim[animationName].speed = animSpeed;
            anim.Play(animationName);
        }
        #endregion

        #region In flight
        if (HighLogic.LoadedSceneIsFlight)
        {

            #region create wheel setup
            List<WheelCollider> colliderList = new List<WheelCollider>();
            List<Transform> wheelMeshList = new List<Transform>();
            List<Transform> suspensionList = new List<Transform>();

            for (int i = 0; i < numberOfWheels; i++)
            {
                string suffix = (i + 1).ToString(); // the names used are e.g. "Wheel", "Wheel2", "Wheel3", to remain compatible with stock wheels
                if (i == 0)
                    suffix = "";
                Transform colliderTransform = part.FindModelTransform(wheelColliderName + suffix);
                if (colliderTransform != null)
                {
                    WheelCollider collider = colliderTransform.GetComponent<WheelCollider>();
                    if (collider != null)
                    {
                        colliderList.Add(collider);
                    }
                }
                else
                {
                    Debug.Log("FSwheel: missing wheel collider " + wheelColliderName + suffix);
                }

                Transform wheelMeshTransform = part.FindModelTransform(wheelMeshName + suffix);
                if (wheelMeshTransform != null)
                {
                    wheelMeshList.Add(wheelMeshTransform);
                }
                else
                {
                    Debug.Log("FSwheel: missing wheel mesh " + wheelMeshName + suffix);
                }

                Transform suspensionTransform = part.FindModelTransform(suspensionParentName + suffix);
                if (suspensionTransform != null)
                {
                    suspensionList.Add(suspensionTransform);
                }
                else
                {
                    Debug.Log("FSwheel: missing suspensionParent " + suspensionParentName + suffix);
                }

            }

            wheelList.Create(colliderList, wheelMeshList, suspensionList);
            if (wheelList != null)
            {
                if (!wheelList.enabled)
                {
                    wheelList.enabled = true;
                }
            }

            // set the motor direction based on the first found wheelColliders orientation
            //Debug.Log("FSwheel: wheelist count is " + wheelList.wheels.Count);
            if (wheelList.wheels.Count > 0)
            {
                Debug.Log("FSwheel: reversemotorset: " + reverseMotorSet);
                if (!reverseMotorSet) //run only the first time the craft is loaded
                {
                    float dot = Vector3.Dot(wheelList.wheels[0].wheelCollider.transform.forward, vessel.ReferenceTransform.up); // up is forward
                    if (dot < 0) // below 0 means the engine is on the left side of the craft
                    {
                        reverseMotor = true;
                        //Debug.Log("FSwheel: Reversing motor, dot: " + dot);
                    }
                    else
                    {
                        reverseMotor = false;
                        //Debug.Log("FSwheel: Motor reversing skipped, dot: " + dot);
                    }
                    if (motorStartsReversed)
                        reverseMotor = !reverseMotor;
                    reverseMotorSet = true;
                }
            }

            if (disableColliderWhenRetracted)
            {
                if (deploymentStateEnum == DeploymentStates.Retracted)
                {
                    wheelList.enabled = false;
                }
            }

            //friction override
            if (overrideModelFrictionValues)
            {
                wheelList.forwardStiffness = forwardsStiffness;
                wheelList.forwardsAsymptoteSlip = forwardsAsymptoteSlip;
                wheelList.forwardsAsymptoteValue = forwardsAsymptoteValue;
                wheelList.forwardsExtremumSlip = forwardsExtremumSlip;
                wheelList.forwardsExtremumValue = forwardsExtremumValue;
                wheelList.sidewaysStiffness = sidewaysStiffness;
                wheelList.sidewaysAsymptoteSlip = sidewaysAsymptoteSlip;
                wheelList.sidewaysAsymptoteValue = sidewaysAsymptoteValue;
                wheelList.sidewaysExtremumSlip = sidewaysExtremumSlip;
                wheelList.sidewaysExtremumValue = sidewaysExtremumValue;
                wheelList.updateWheelFriction();
            }

            //optionally set collider and spring values
            if ((suspensionSpring >= 0f && suspensionDamper >= 0f && suspensionTargetPosition >= 0f) || overrideModelSpringValues)
            {
                wheelList.updateSpring(suspensionSpring, suspensionDamper, suspensionTargetPosition);
            }
            if (wheelColliderRadius >= 0f) wheelList.radius = wheelColliderRadius;
            else
                wheelColliderRadius = wheelList.radius;
            if (wheelColliderMass >= 0f) wheelList.mass = wheelColliderMass;
            if (wheelColliderSuspensionDistance >= 0f || overrideSuspensionDistance) wheelList.suspensionDistance = wheelColliderSuspensionDistance;
            else
                wheelColliderSuspensionDistance = wheelList.suspensionDistance;

            #endregion

            #region GUI popup
            /*
            popup = new FSGUIPopup(part, "FSwheel", moduleID, FSGUIwindowID.wheel, new Rect(500f, 300f, 250f, 100f), "Wheel settings", new PopupElement("Suspension Settings:"));
            popup.useInFlight = true;
            wheelRadiusElement = new PopupElement("Radius", wheelColliderRadius.ToString());
            suspensionDistanceElement = new PopupElement("Distance", wheelColliderSuspensionDistance.ToString());
            suspensionSpringElement = new PopupElement("Spring", suspensionSpring.ToString());
            suspensionDamperElement = new PopupElement("Damper", suspensionDamper.ToString());
            suspensionTargetPositionElement = new PopupElement("Target pos", suspensionTargetPosition.ToString());
            popup.sections[0].elements.Add(wheelRadiusElement);
            popup.sections[0].elements.Add(suspensionDistanceElement);
            popup.sections[0].elements.Add(suspensionSpringElement);
            popup.sections[0].elements.Add(suspensionDamperElement);
            popup.sections[0].elements.Add(suspensionTargetPositionElement);

            suspensionUpdateElement = new PopupElement(new PopupButton("Update", 0f, popupUpdateSuspension));
            popup.sections[0].elements.Add(suspensionUpdateElement);
             */
            #endregion

            if (brakeEmissiveObjectName != string.Empty)
            {
                brakeEmissiveObject = part.FindModelTransform(brakeEmissiveObjectName);
            }
            setBrakeLight(brakesEngaged);

            #region set up fx
            if (useCustomParticleFX)
            {
                smokeFXtexture = GameDatabase.Instance.GetTexture(smokeFXtextureName, false);
                if (smokeFXtexture == null)
                {
                    useCustomParticleFX = false;
                }
                else
                {
                    for (int i = 0; i < wheelList.wheels.Count; i++)
                    {
                        wheelList.wheels[i].smokeFX = new FSBDparticleFX(wheelList.wheels[i].fxLocation, smokeFXtexture);
                        wheelList.wheels[i].smokeFX.AnimatorColor0 = new Color(1.0f, 1.0f, 1.0f, 0.8f);
                        wheelList.wheels[i].smokeFX.AnimatorColor1 = new Color(1.0f, 1.0f, 1.0f, 0.5f);
                        wheelList.wheels[i].smokeFX.AnimatorColor2 = new Color(1.0f, 1.0f, 1.0f, 0.2f);
                        wheelList.wheels[i].smokeFX.AnimatorColor3 = new Color(1.0f, 1.0f, 1.0f, 0.1f);
                        wheelList.wheels[i].smokeFX.AnimatorColor4 = new Color(1.0f, 1.0f, 1.0f, 0.0f);

                        wheelList.wheels[i].smokeFX.EmitterMinSize = 0.3f;
                        wheelList.wheels[i].smokeFX.EmitterMaxSize = 0.5f;
                        wheelList.wheels[i].smokeFX.EmitterMinEnergy = 0.1f;
                        wheelList.wheels[i].smokeFX.EmitterMaxEnergy = 0.3f;
                        wheelList.wheels[i].smokeFX.EmitterMinEmission = 0f;
                        wheelList.wheels[i].smokeFX.EmitterMaxEmission = 0f;
                        wheelList.wheels[i].smokeFX.AnimatorSizeGrow = 0.1f;

                        wheelList.wheels[i].smokeFX.setupFXValues();
                    }
                }
            }

            #endregion

            //alg
            alg = GetComponent<BDAnimationModules.BDAdjustableLandingGear>();

        }

        #endregion

        #region GUI element changes
        Events["RaiseGear"].guiActiveUnfocused = guiActiveUnfocused;
        Events["RaiseGear"].unfocusedRange = unfocusedRange;

        Events["LowerGear"].guiActiveUnfocused = guiActiveUnfocused;
        Events["LowerGear"].unfocusedRange = unfocusedRange;

        Events["EnableMotorEvent"].guiActive = !motorEnabled;
        Events["DisableMotorEvent"].guiActive = motorEnabled;
        Events["EnableMotorEvent"].guiActiveEditor = !motorEnabled;
        Events["DisableMotorEvent"].guiActiveEditor = motorEnabled;

        Events["brakesOnEvent"].guiActive = !brakesEngaged;
        Events["brakesOffEvent"].guiActive = brakesEngaged;
        Events["brakesOnEvent"].guiActiveEditor = !brakesEngaged;
        Events["brakesOffEvent"].guiActiveEditor = brakesEngaged;

        Events["EnableReverseMotorEvent"].guiActive = !reverseMotor;
        Events["DisableReverseMotorEvent"].guiActive = reverseMotor;
        Events["EnableReverseMotorEvent"].guiActiveEditor = !reverseMotor;
        Events["DisableReverseMotorEvent"].guiActiveEditor = reverseMotor;

        Events["brakesOnEvent"].guiActiveUnfocused = guiActiveUnfocused;
        Events["brakesOffEvent"].guiActiveUnfocused = guiActiveUnfocused;

        if (!hasMotor)
        {
            //Events["EnableMotorEvent"].guiActive = false;
            //Events["DisableMotorEvent"].guiActive = false;
            Events["EnableMotorEvent"].active = false;
            Events["DisableMotorEvent"].active = false;
            Events["EnableReverseMotorEvent"].active = false;
            Events["DisableReverseMotorEvent"].active = false;
        }
        if (!hasAnimation)
        {
            Events["RaiseGear"].active = false;
            Events["LowerGear"].active = false;
        }
        if (debugMode)
        {
            Events["increaseFrictionEvent"].guiActive = true;
            Events["decreaseFrictionEvent"].guiActive = true;
            Events["suspensionGUIEvent"].guiActive = true;
        }

        if (brakesLockedOn)
        {
            Events["brakesOnEvent"].guiActive = false;
            Events["brakesOffEvent"].guiActive = false;
            Events["brakesOnEvent"].guiActiveUnfocused = false;
            Events["brakesOffEvent"].guiActiveUnfocused = false;
        }

        #endregion
    }
    private void animate(string mode)
    {
        if (anim != null)
        {
            animTime = anim[animationName].normalizedTime;

            if (deploymentStateEnum == DeploymentStates.Retracted) //fixes stupid unity animation timing (0 to 0.99 to 0)
                animTime = 1f;

            if (mode == "Deploy")
            {
                if (deploymentStateEnum == DeploymentStates.Retracted)
                    animTime = 1f;
                animSpeed = -1f * customAnimationSpeed;
                deploymentStateEnum = DeploymentStates.Deploying;
                if (startDeployEffect != string.Empty)
                {
                    part.Effect(startDeployEffect);
                }
            }
            else if (mode == "Retract")
            {
                if (deploymentStateEnum == DeploymentStates.Deployed)
                    animTime = 0f;
                animSpeed = 1f * customAnimationSpeed;
                deploymentStateEnum = DeploymentStates.Retracting;
                if (startRetractEffect != string.Empty)
                {
                    part.Effect(startRetractEffect);
                }
            }
            else if (mode == "Stop")
            {
                animSpeed = 0f;
                deploymentStateEnum = DeploymentStates.Stopped;
            }

            anim[animationName].normalizedTime = animTime;
            anim[animationName].speed = animSpeed;
            if (animSpeed != 0f)
            {
                anim.Play(animationName);
                setBrakeLight(BrakeStatus.deploying);
            }
            else
            {
                anim.Stop();
            }
        }
    }
Exemple #24
0
 //Parachute predeployment
 public void PreDeploy()
 {
     this.part.stackIcon.SetIconColor(XKCDColors.BrightYellow);
     this.module.capOff = true;
     this.module.Events["GUIDeploy"].active = false;
     this.module.Events["GUIArm"].active = false;
     this.part.Effect("rcpredeploy");
     deploymentState = DeploymentStates.PREDEPLOYED;
     depState = stateString;
     parachute.gameObject.SetActive(true);
     cap.gameObject.SetActive(false);
     this.module.Events["GUICut"].active = true;
     this.part.PlayAnimation(preDeploymentAnimation, 1 / preDeploymentSpeed);
     dragTimer.Start();
 }
Exemple #25
0
 //Repack actions
 internal void Repack()
 {
     deploymentState = DeploymentStates.STOWED;
     depState = stateString;
     cap.gameObject.SetActive(true);
 }
    private void updateDeploymentState()
    {
        if (anim != null)
        {

            if (!anim.isPlaying)
            {
                if (deploymentStateEnum == DeploymentStates.Deploying)
                {
                    deploymentStateEnum = DeploymentStates.Deployed;
                    setBrakeLight(brakesEngaged);
                }
                else if (deploymentStateEnum == DeploymentStates.Retracting)
                {
                    deploymentStateEnum = DeploymentStates.Retracted;
                    setBrakeLight(brakesEngaged);
                }
            }
        }
    }
Exemple #27
0
 //Parachute deployment
 public void Deploy()
 {
     this.part.stackIcon.SetIconColor(XKCDColors.RadioactiveGreen);
     this.part.Effect("rcdeploy");
     deploymentState = DeploymentStates.DEPLOYED;
     depState = stateString;
     if (!this.part.CheckAnimationPlaying(preDeploymentAnimation))
     {
         dragTimer.Reset();
         dragTimer.Start();
         this.part.PlayAnimation(deploymentAnimation, 1 / deploymentSpeed);
         this.played = true;
     }
     else { this.played = false; }
 }
Exemple #28
0
        //Initializes the chute
        public void Initialize()
        {
            this.module.materials.TryGetMaterial(material, ref mat);

            anim = this.part.FindModelAnimators(capName).FirstOrDefault();
            this.cap = this.part.FindModelTransform(capName);

            this.parachute = this.part.FindModelTransform(parachuteName);
            if (this.parachute == null && !string.IsNullOrEmpty(baseParachuteName))
            {
                this.parachute = this.part.FindModelTransform(baseParachuteName);
            }
            this.parachute.gameObject.SetActive(false);
            this.part.InitiateAnimation(preDeploymentAnimation);
            this.part.InitiateAnimation(deploymentAnimation);

            if (string.IsNullOrEmpty(baseParachuteName)) { baseParachuteName = parachuteName; }

            if (!this.module.initiated)
            {
                deploymentState = DeploymentStates.STOWED;
                depState = "STOWED";
                played = false;
                this.cap.gameObject.SetActive(true);
            }
            if (HighLogic.LoadedSceneIsFlight)
            {
                deploymentState = getState;
                if (this.module.capOff)
                {
                    this.part.stackIcon.SetIconColor(XKCDColors.Red);
                    this.cap.gameObject.SetActive(false);
                }
            }
        }