// Runs on PartModule startup.
        public override void OnStart(StartState state)
        {
            // Startup the PartModule stuff first.
            base.OnStart(state);

            // Set our state trackers to the opposite of our states, to force first-run updates.
//			this.startLockedState = !this.startLocked;

            // Fetch the gimbal module from the part.
            this.gimbalModule = base.part.getFirstModuleOfType <ModuleGimbal>();

            if (this.gimbalModule == null)
            {
                return;
            }

            //PartLoader.getPartInfoByName(base.part.partInfo.name).partPrefab.Modules

            /*.OfType<ModuleGimbal>()
             * .FirstOrDefault()
             * .gimbalRange*/

            ModuleGimbal gimbalPrefab;

            if (PartLoader.getPartInfoByName(base.part.partInfo.name).partPrefab.tryGetFirstModuleOfType(out gimbalPrefab))
            {
                // Initialize the gimbal range tweakable and value.
                TweakableTools.InitializeTweakable <ModuleTweakableGimbal>(
                    this.Fields["gimbalRange"].uiControlCurrent(),
                    ref this.gimbalRange,
                    ref this.gimbalModule.gimbalRange,
                    gimbalPrefab.gimbalRange,
                    this.lowerMult,
                    this.upperMult
                    );
            }

            // If we're in flight mode...
            if (HighLogic.LoadedSceneIsFlight)
            {
                // ...and if our control state and gimbal range don't match...
                if (
                    (this.reverseGimbalControl && this.gimbalRange >= 0) ||
                    (!this.reverseGimbalControl && this.gimbalRange < 0)
                    )
                {
                    // ...toggle the reverse state.
                    this.ToggleGimbalFlip();

                    // ...and seed our last state.
                    this.reverseControlState = this.reverseGimbalControl;
                }
            }

            if (this.disableStockLimiter)
            {
                this.gimbalModule.Fields["gimbalLimiter"].guiActive       = false;
                this.gimbalModule.Fields["gimbalLimiter"].guiActiveEditor = false;
            }
        }
        /*
         * Methods
         * */
        // Runs when each new part is started.
        public override void OnStart(StartState st)
        {
            if (!this.part.tryGetFirstModuleOfType <ModuleDockingNode>(out this.dockingNodeModule))
            {
                return;
            }

            this.deployAnimation = this.part.getFirstModuleOfType <ModuleAnimateGeneric>();
            // If we've loaded a deployAnimationControllerName from the cfg...

            // Start the underlying ModuleDockingNode.
            base.OnStart(st);

            ModuleDockingNode prefabModule = PartLoader.getPartInfoByName(this.part.partInfo.name)
                                             .partPrefab.getFirstModuleOfType <ModuleDockingNode>();

            TweakableTools.InitializeTweakable <ModuleTweakableDockingNode>(
                this.Fields["acquireRange"].uiControlCurrent(),
                ref this.acquireRange,
                ref this.dockingNodeModule.acquireRange,
                prefabModule.acquireRange
                );

            TweakableTools.InitializeTweakable <ModuleTweakableDockingNode>(
                this.Fields["acquireForce"].uiControlCurrent(),
                ref this.acquireForce,
                ref this.dockingNodeModule.acquireForce,
                prefabModule.acquireForce
                );

            TweakableTools.InitializeTweakable <ModuleTweakableDockingNode>(
                this.Fields["acquireTorque"].uiControlCurrent(),
                ref this.acquireTorque,
                ref this.dockingNodeModule.acquireTorque,
                prefabModule.acquireForce
                );

            TweakableTools.InitializeTweakable <ModuleTweakableDockingNode>(
                this.Fields["undockEjectionForce"].uiControlCurrent(),
                ref this.undockEjectionForce,
                ref this.dockingNodeModule.undockEjectionForce,
                prefabModule.undockEjectionForce
                );

            TweakableTools.InitializeTweakable <ModuleTweakableDockingNode>(
                this.Fields["minDistanceToReEngage"].uiControlCurrent(),
                ref this.minDistanceToReEngage,
                ref this.dockingNodeModule.minDistanceToReEngage,
                prefabModule.minDistanceToReEngage
                );

            this.Fields["maxCaptureRollAngle"].uiControlFlight.controlEnabled = false;
            this.Fields["maxAcquireRollAngle"].uiControlFlight.controlEnabled = false;

            this.maxCaptureRollAngle = Mathf.Acos(this.minCaptureRollDotProduct) * 180f / Mathf.PI;
            this.dockingNodeModule.captureMinRollDot = Mathf.Min(this.minCaptureRollDotProduct, 0.99995f);

            this.maxAcquireRollAngle = Mathf.Acos(this.minAcquireRollDotProduct) * 180f / Mathf.PI;
            this.dockingNodeModule.acquireMinRollDot = Mathf.Min(this.minAcquireRollDotProduct, 0.99995f);

                        #if DEBUG
            this.dockingNodeModule.Fields["captureMinRollDot"].guiActive       = true;
            this.dockingNodeModule.Fields["captureMinRollDot"].guiActiveEditor = true;
                        #endif

            this.lastMaxCaptureRollAngle = this.maxCaptureRollAngle;
            this.lastMaxAcquireRollAngle = this.maxAcquireRollAngle;

            // If we have a tweakable AttachNode, use it.
            if (this.TDNnodeName != string.Empty)
            {
                this.attachNode = base.part.findAttachNode(this.TDNnodeName);
            }

            base.part.attachRules.allowStack = this.IsOpen | this.AlwaysAllowStack;

            /* @subclass
             * ModuleStagingToggle stagingToggleModule;
             *
             * if (this.part.tryGetFirstModuleOfType<ModuleStagingToggle>(out stagingToggleModule))
             * {
             *      stagingToggleModule.OnToggle += new ModuleStagingToggle.ToggleEventHandler(this.OnStagingToggle);
             * }
             */

            // Yay debugging!
            this.LogDebug(
                "{0}: Started with assembly version {4}." +
                "\n\tdeployAnimationModule={1}, attachNode={2}, TDNnodeName={3}, attachedPart={5}, fuelCrossFeed={6}",
                this.GetType().Name,
                this.deployAnimation,
                this.attachNode,
                this.TDNnodeName,
                this.GetType().Assembly.GetName().Version,
                this.attachedPart
                );
        }
Exemple #3
0
        // Runs on start.
        public override void OnStart(StartState state)
        {
            using (PooledDebugLogger log = PooledDebugLogger.New(this))
            {
                                #if DEBUG
                try {
                                #endif

                log.AppendFormat("{0}: starting up", this.ToString());

                // Start up the underlying PartModule stuff.
                base.OnStart(state);

                log.Append("\n\tbase started up");

                ModuleReactionWheel prefabModule;

                // Fetch the reaction wheel module.
                if (this.part.tryGetFirstModuleOfType <ModuleReactionWheel>(out this.reactionWheelModule))
                {
                    log.AppendFormat("\n\tFound ModuleReactionWheel {0}", this.reactionWheelModule);

                    if (PartLoader.getPartInfoByName(this.part.partInfo.name).partPrefab
                        .tryGetFirstModuleOfType <ModuleReactionWheel>(out prefabModule))
                    {
                        log.AppendFormat("\n\tFound prefab module {0}", prefabModule);

                        TweakableTools.InitializeTweakable <ModuleTweakableReactionWheel>(
                            this.Fields["RollTorque"].uiControlCurrent(),
                            ref this.RollTorque,
                            ref this.reactionWheelModule.RollTorque,
                            prefabModule.RollTorque
                            );

                        log.Append("\n\tRollTorque setup");

                        TweakableTools.InitializeTweakable <ModuleTweakableReactionWheel>(
                            this.Fields["PitchTorque"].uiControlCurrent(),
                            ref this.PitchTorque,
                            ref this.reactionWheelModule.PitchTorque,
                            prefabModule.PitchTorque
                            );

                        log.Append("\n\tPitchTorque setup");

                        TweakableTools.InitializeTweakable <ModuleTweakableReactionWheel>(
                            this.Fields["YawTorque"].uiControlCurrent(),
                            ref this.YawTorque,
                            ref this.reactionWheelModule.YawTorque,
                            prefabModule.YawTorque
                            );

                        log.Append("\n\tYawTorque setup");
                    }
                }

                var torqueGainCtl = this.Fields["TorqueGain"].uiControlCurrent();

                if (torqueGainCtl is UI_FloatRange)
                {
                    var torqueGainSlider = torqueGainCtl as UI_FloatRange;

                    torqueGainSlider.maxValue      = 1f;
                    torqueGainSlider.stepIncrement = 0.025f;
                }

                log.Append("\n\tStarted!");
                                #if DEBUG
            } finally {
                log.Print();
            }
                                #endif
            }
        }
Exemple #4
0
        /*
         * Methods
         * */
        // Runs when each new part is started.
        public override void OnStart(StartState st)
        {
            // Startup the PartModule stuff first.
            base.OnStart(st);

            if (!this.part.tryGetFirstModuleOfType <ModuleDockingNode>(out this.dockingNodeModule))
            {
                return;
            }
            if (this.dockingNodeModule.deployAnimationController != -1)
            {
                this.deployAnimation = (base.part.Modules.GetModule(this.dockingNodeModule.deployAnimationController) as ModuleAnimateGeneric);
            }
            else
            {
                this.deployAnimation = null;
                //  return;
            }

            //  this.deployAnimation = this.part.getFirstModuleOfType<ModuleAnimateGeneric>();


            ModuleDockingNode prefabModule;


            var p = PartLoader.getPartInfoByName(base.part.partInfo.name).partPrefab;

            p.tryGetFirstModuleOfType(out prefabModule);

            if (prefabModule == null)
            {
                Debug.Log("prefabModule is null");
                return;
            }
            if (this.Fields["acquireRange"].uiControlCurrent() == null)
            {
                Debug.Log("uiControlcurrent is null");
                return;
            }

#if true
            TweakableTools.InitializeTweakable <ModuleTweakableDockingNode>(
                this.Fields["acquireRange"].uiControlCurrent(),
                ref this.acquireRange,
                ref this.dockingNodeModule.acquireRange,
                prefabModule.acquireRange
                );

            UI_FloatRange floatRange = this.Fields["acquireRange"].uiControlCurrent() as UI_FloatRange;
            floatRange.minValue = 0.2f;

            TweakableTools.InitializeTweakable <ModuleTweakableDockingNode>(
                this.Fields["acquireForce"].uiControlCurrent(),
                ref this.acquireForce,
                ref this.dockingNodeModule.acquireForce,
                prefabModule.acquireForce
                );

            TweakableTools.InitializeTweakable <ModuleTweakableDockingNode>(
                this.Fields["acquireTorque"].uiControlCurrent(),
                ref this.acquireTorque,
                ref this.dockingNodeModule.acquireTorque,
                prefabModule.acquireForce
                );

            TweakableTools.InitializeTweakable <ModuleTweakableDockingNode>(
                this.Fields["undockEjectionForce"].uiControlCurrent(),
                ref this.undockEjectionForce,
                ref this.dockingNodeModule.undockEjectionForce,
                prefabModule.undockEjectionForce
                );

            TweakableTools.InitializeTweakable <ModuleTweakableDockingNode>(
                this.Fields["minDistanceToReEngage"].uiControlCurrent(),
                ref this.minDistanceToReEngage,
                ref this.dockingNodeModule.minDistanceToReEngage,
                prefabModule.minDistanceToReEngage
                );
#endif
#if true
            this.Fields["maxCaptureRollAngle"].uiControlFlight.controlEnabled = false;
            this.Fields["maxAcquireRollAngle"].uiControlFlight.controlEnabled = false;

            this.maxCaptureRollAngle = Mathf.Acos(this.minCaptureRollDotProduct) * 180f / Mathf.PI;
//			this.dockingNodeModule.captureMinRollDot = Mathf.Min(this.minCaptureRollDotProduct, 0.99995f);

            this.maxAcquireRollAngle = Mathf.Acos(this.minAcquireRollDotProduct) * 180f / Mathf.PI;
            //			this.dockingNodeModule.acquireMinRollDot = Mathf.Min(this.minAcquireRollDotProduct, 0.99995f);

#if DEBUG
            this.dockingNodeModule.Fields["acquireMinRollDot"].guiActive       = true;
            this.dockingNodeModule.Fields["acquireMinRollDot"].guiActiveEditor = true;

            this.dockingNodeModule.Fields["captureMinRollDot"].guiActive       = true;
            this.dockingNodeModule.Fields["captureMinRollDot"].guiActiveEditor = true;

            this.Fields["maxCaptureRollAngle"].guiActive       = true;
            this.Fields["maxCaptureRollAngle"].guiActiveEditor = true;

            this.Fields["maxAcquireRollAngle"].guiActive       = true;
            this.Fields["maxAcquireRollAngle"].guiActiveEditor = true;

            this.Fields["minCaptureRollDotProduct"].guiActive       = true;
            this.Fields["minCaptureRollDotProduct"].guiActiveEditor = true;

            this.Fields["minAcquireRollDotProduct"].guiActive       = true;
            this.Fields["minAcquireRollDotProduct"].guiActiveEditor = true;
#endif

            this.lastMaxCaptureRollAngle = this.maxCaptureRollAngle;
            this.lastMaxAcquireRollAngle = this.maxAcquireRollAngle;
#if true
            // If we have a tweakable AttachNode, use it.
            if (this.TDNnodeName != string.Empty)
            {
                this.attachNode = base.part.FindAttachNode(this.TDNnodeName);
            }

            base.part.attachRules.allowStack = this.IsOpen | this.AlwaysAllowStack;
#endif

            /* @subclass
             * ModuleStagingToggle stagingToggleModule;
             *
             * if (this.part.tryGetFirstModuleOfType<ModuleStagingToggle>(out stagingToggleModule))
             * {
             *      stagingToggleModule.OnToggle += new ModuleStagingToggle.ToggleEventHandler(this.OnStagingToggle);
             * }
             */
#endif
            // Yay debugging!
            this.LogDebug(
                "{0}: Started with assembly version {4}." +
                "\n\tdeployAnimationModule={1}, attachNode={2}, TDNnodeName={3}, attachedPart={5}, fuelCrossFeed={6}, AlwaysAllowStack={7} ",
                this.GetType().Name,
                this.deployAnimation,
                this.attachNode,
                this.TDNnodeName,
                this.GetType().Assembly.GetName().Version,
                this.attachedPart,
                base.part.fuelCrossFeed,
                this.AlwaysAllowStack
                );
        }