Exemplo n.º 1
0
        //when started
        /// <summary>Configures the part for editor and flight.</summary>
        /// <remarks>
        /// Most importantly, it grabs a list of wheel colliders to be
        /// used later. Also configures visibility of tweakables, figures
        /// out the parts orientation and position in the vessel to calculate
        /// steering angles and sets some defaults.
        /// </remarks>
        /// <param name="state">Start state. Set by KSP to declare the scene it initializes this class in.</param>
        public override void OnStart(PartModule.StartState state)
        {
            base.OnStart(state);

            susInc = KFPersistenceManager.suspensionIncrement;

            CustomResourceTextSetup(); // Calls a method to set up the statusLowResource text for resource alternatives.

            _colliderMass = 10; //just a beginning value to stop stuff going crazy before it's all calculated properly.

            var partOrientationForward = new Vector3(0,0,0);
            var partOrientationRight = new Vector3(0, 0, 0);
            var partOrientationUp = new Vector3(0, 0, 0);

            if (!string.Equals(orientationObjectName, "Default"))
            {
                KFLog.Warning("Transformed part orientation.");
                partOrientationUp = transform.Search(orientationObjectName).up;
                partOrientationForward = transform.Search(orientationObjectName).forward;
                partOrientationRight = transform.Search(orientationObjectName).right;
            }
            else
            {
                KFLog.Warning("Default part orientation.");
                partOrientationUp = this.part.transform.up;
                partOrientationForward = this.part.transform.forward;
                partOrientationRight = this.part.transform.right;
            }

            if (hasRetractAnimation)
            {
                foreach (ModuleAnimateGeneric ma in this.part.FindModulesImplementing<ModuleAnimateGeneric>())
                {
                    ma.Actions["ToggleAction"].active = false;
                    ma.Events["Toggle"].guiActive = false;
                    ma.Events["Toggle"].guiActiveEditor = false;
                }
                SetupAnimation();
            }

            KFLog.Log(string.Format("Version: {0}", System.Reflection.Assembly.GetExecutingAssembly().GetName().Version));

            //disables tweakables if being used on a passive part (mecannum wheel or skid, for example)
            if (disableTweakables)
            {
                KFLog.Warning("Disabling tweakables.");
                foreach (BaseField k in this.Fields)
                {
                    KFLog.Log(string.Format("Found {0}", k.guiName));
                    k.guiActive = false;
                    k.guiActiveEditor = false;
                }
                foreach (BaseAction a in this.Actions)
                {
                    KFLog.Log(string.Format("Found {0}", a.guiName));
                    a.active = false;
                }
                foreach (BaseEvent e in this.Events)
                {
                    KFLog.Log(string.Format("Found {0}", e.guiName));
                    e.active = false;
                }
            }

            if (startRetracted)
                isRetracted = true;

            if (!isRetracted)
                currentTravel = rideHeight; //set up correct values from persistence
            else
                currentTravel = 0;
            //KFLog.Log(string.Format("\"appliedRideHeight\" = {0}", appliedRideHeight));

            // Disable retract tweakables if retract option not specified.
            if (HighLogic.LoadedSceneIsEditor && !hasRetract)
            {
                Extensions.DisableAnimateButton(this.part);
                Actions["AGToggleDeployed"].active = false;
                Actions["Deploy"].active = false;
                Actions["Retract"].active = false;
                Fields["startRetracted"].guiActiveEditor = false;
            }

            if (HighLogic.LoadedSceneIsFlight && !Equals(vessel.vesselType, VesselType.Debris)) // && vessel.parts.Count > 1) // Vessels don't have to be made up of only one part to still be considered debris.
            {
                _dustFX = this.part.gameObject.GetComponent<KFDustFX>();
                if (Equals(_dustFX, null)) //add if not... sets some defaults.
                {
                    _dustFX = this.part.gameObject.AddComponent<KFDustFX>();
                    _dustFX.OnStart(state);
                }
                _dustFX.tweakScaleFactor = tweakScaleCorrector;

                appliedTravel = rideHeight / 100; // need to be here if no KFWheel or everything gets set to zero as below.
                StartCoroutine(StartupStuff());
                maxRPM /= tweakScaleCorrector;
                startRetracted = false;
                if (!hasRetract)
                    Extensions.DisableAnimateButton(this.part);

                // Wheel steering ratio setup
                rootIndexLong = WheelUtils.GetRefAxis(this.part.transform.forward, this.vessel.rootPart.transform); //Find the root part axis which matches each wheel axis.
                rootIndexLat = WheelUtils.GetRefAxis(this.part.transform.right, this.vessel.rootPart.transform);
                rootIndexUp = WheelUtils.GetRefAxis(this.part.transform.up, this.vessel.rootPart.transform);

                steeringRatio = WheelUtils.SetupRatios(rootIndexLong, this.part, this.vessel, groupNumber); //use the axis which corresponds to the forward axis of the wheel.
                GetControlAxis();

                if (torque > 2) // Check if the torque value is using the old numbering system
                    torque /= 100;

                wheelCount = 0;

                foreach (WheelCollider wc in this.part.GetComponentsInChildren<WheelCollider>()) // Set colliders to values chosen in editor and activate
                {
                    wheelCount++;
                    JointSpring userSpring = wc.suspensionSpring;
                    userSpring.spring = springRate * tweakScaleCorrector;
                    userSpring.damper = damperRate * tweakScaleCorrector;
                    wc.suspensionSpring = userSpring;
                    wc.suspensionDistance = wc.suspensionDistance * appliedTravel;
                    wcList.Add(wc);
                    suspensionDistance.Add(wc.suspensionDistance);
                    wc.enabled = true;
                    wc.gameObject.layer = 27;
                }

                if (brakesApplied)
                    brakeTorque = brakingTorque; // Were the brakes left applied?

                if (isRetracted)
                    RetractDeploy("retract");
                isReady = true;
            } // End scene is flight
            DestroyBounds();
        }
Exemplo n.º 2
0
 // End start
 void SetupDust(PartModule.StartState state)
 {
     _dustFX = part.GetComponent<KFDustFX>(); //see if it's been added by MM. MM deprecated in favor of adding the module manually. - Gaalidas
     if (!Equals(_dustFX, null)) //add if not... sets some defaults.
     {
         _dustFX = part.gameObject.AddComponent<KFDustFX>();
         _dustFX.isRepulsor = true;
         _dustFX.OnStart(state);
     }
 }