示例#1
0
        private void UpdateBell()
        {
            if (selectedBell == null || selectedBellName == selectedBell.name)
            {
                return;
            }

            SRBBellConfig oldSelectedBell = selectedBell;

            if (!srbConfigs.TryGetValue(selectedBellName, out selectedBell))
            {
                Debug.LogError("*ST* Selected bell name \"" + selectedBellName + "\" does not exist. Reverting.");
                selectedBellName = oldSelectedBell.name;
                selectedBell     = oldSelectedBell;
                return;
            }

            oldSelectedBell.model.gameObject.SetActive(false);

            MoveBottomAttachmentAndNode(selectedBell.srbAttach.position - oldSelectedBell.srbAttach.position);

            InitModulesFromBell();

            UpdateMaxThrust();
        }
示例#2
0
 private void LoadBells(ConfigNode node)
 {
     srbConfigs.Clear();
     foreach (ConfigNode srbNode in node.GetNodes("SRB_BELL"))
     {
         SRBBellConfig conf = new SRBBellConfig();
         conf.Load(srbNode);
         srbConfigs.Add(conf.name, conf);
     }
 }
示例#3
0
 private void LoadSRBConfigs()
 {
     srbConfigs = new Dictionary <string, SRBBellConfig>();
     foreach (ConfigNode srbNode in srbConfigsSerialized)
     {
         SRBBellConfig conf = new SRBBellConfig();
         conf.Load(srbNode);
         srbConfigs.Add(conf.name, conf);
     }
 }
示例#4
0
 private void LoadSRBConfigs()
 {
     srbConfigs.Clear();
     foreach (ConfigNode srbNode in srbConfigsSerialized)
     {
         SRBBellConfig conf = new SRBBellConfig();
         conf.Load(srbNode);
         srbConfigs.Add(conf.name, conf);
     }
 }
示例#5
0
        private void UpdateBellType()
        {
            if (selectedBell == null || selectedBellName == selectedBell.name)
            {
                return;
            }

            SRBBellConfig oldSelectedBell = selectedBell;

            if (!srbConfigs.TryGetValue(selectedBellName, out selectedBell))
            {
                Debug.LogError($"{ModTag} {part}.{this}: Selected bell name \"{selectedBellName}\" does not exist. Reverting.");
                selectedBellName = oldSelectedBell.name;
                selectedBell     = oldSelectedBell;
                return;
            }

            oldSelectedBell.model.gameObject.SetActive(false);

            InitModulesFromBell();
            UpdateMaxThrust();
        }
示例#6
0
        private void InitializeBells()
        {
            Debug.Log($"{ModTag} {this}: InitializeBells");
            // Initialize the configs.
            if (srbConfigs.Count < 1)
            {
                srbConfigs = new Dictionary <string, SRBBellConfig>(part.partInfo.partPrefab.FindModuleImplementing <ProceduralSRB>().srbConfigs);
            }

            bellTransform = part.FindModelTransform(srbBellName);
            PrepareBellModels();

            if (srbConfigs.Count < 1)
            {
                Debug.LogError($"{ModTag} {this}: No valid SRB bells configured");
                return;
            }

            // Select the bell
            if (string.IsNullOrEmpty(selectedBellName) || !srbConfigs.ContainsKey(selectedBellName))
            {
                selectedBellName = srbConfigs.First().Key;
            }
            selectedBell = srbConfigs[selectedBellName];

            ConfigureRealFuels();

            InitModulesFromBell();
            SetBellRotation(thrustDeflection);

            if (HighLogic.LoadedSceneIsFlight)
            {
                thrustTransform          = bellTransform.Find(thrustVectorTransformName);
                thrustTransform.position = selectedBell.srbAttach.position;
                thrustTransform.SetParent(selectedBell.srbAttach);
            }
        }
示例#7
0
        private void InitializeBells()
        {
            print("*PP* InitializeBells");
            // Initialize the configs.
            if (srbConfigs == null)
            {
                LoadSRBConfigs();
            }

            BaseField field = Fields["selectedBellName"];

            // ReSharper disable once PossibleNullReferenceException
            switch (srbConfigs.Count)
            {
            case 0:
                Debug.LogError("*PT*  No SRB bells configured");
                return;

            case 1:
                field.guiActiveEditor = false;
                break;

            default:
                field.guiActiveEditor = true;
                UI_ChooseOption range = (UI_ChooseOption)field.uiControlEditor;
                range.options = srbConfigs.Keys.ToArray();
                break;
            }

            Transform srbBell = part.FindModelTransform(srbBellName);

            thrustTransform = srbBell.Find(thrustVectorTransformName);

            foreach (SRBBellConfig conf in srbConfigs.Values)
            {
                conf.model = part.FindModelTransform(conf.modelName);
                if (conf.model == null)
                {
                    Debug.LogError("*PT* Unable to find model transform for SRB bell name: " + conf.modelName);
                    srbConfigs.Remove(conf.modelName);
                    continue;
                }
                conf.model.transform.parent = srbBell;

                conf.srbAttach = conf.model.Find(conf.srbAttachName);
                if (conf.srbAttach == null)
                {
                    Debug.LogError("*PT* Unable to find srbAttach for SRB bell name: " + conf.modelName);
                    srbConfigs.Remove(conf.modelName);
                    continue;
                }

                // Only enable the colider for flight mode. This prevents any surface attachments.
                if (HighLogic.LoadedSceneIsEditor && conf.model.collider != null)
                {
                    Destroy(conf.model.collider);
                }

                conf.model.gameObject.SetActive(false);
            }

            // Select the bell
            if (string.IsNullOrEmpty(selectedBellName) || !srbConfigs.ContainsKey(selectedBellName))
            {
                selectedBellName = srbConfigsSerialized[0].GetValue("name");
            }
            selectedBell = srbConfigs[selectedBellName];

            // Config for Real Fuels.
            if (part.Modules.Contains("ModuleEngineConfigs"))
            {
                // ReSharper disable once InconsistentNaming
                var mEC = part.Modules["ModuleEngineConfigs"];
                ModularEnginesChangeThrust = (Action <float>)Delegate.CreateDelegate(typeof(Action <float>), mEC, "ChangeThrust");
                try
                {
                    ModularEnginesChangeEngineType = (Action <string>)Delegate.CreateDelegate(typeof(Action <string>), mEC, "ChangeEngineType");
                }
                catch
                {
                    ModularEnginesChangeEngineType = null;
                }

                //Fields["burnTime"].guiActiveEditor = false;
                //Fields["srbISP"].guiActiveEditor = false;
                //Fields["heatProduction"].guiActiveEditor = false;
            }
            Fields["thrust"].guiActiveEditor     = !UsingME;
            Fields["burnTime"].guiActiveEditor   = !UsingME;
            Fields["burnTimeME"].guiActiveEditor = UsingME;
            Fields["thrustME"].guiActiveEditor   = UsingME;

            // Initialize the modules.
            InitModulesFromBell();

            // Break out at this stage during loading scene
            if (GameSceneFilter.AnyInitializing.IsLoaded())
            {
                UpdateThrustDependentCalcs();
                return;
            }

            // Update the thrust according to the equation when in editor mode, don't mess with ships in flight
            if (GameSceneFilter.AnyEditor.IsLoaded())
            {
                UpdateThrustDependentCalcs();
            }
            else
            {
                if (bellScale <= 0 || heatProduction <= 0)
                {
                    // We've reloaded from a legacy save
                    // Use the new heat production equation, but use the legacy bell scaling one.
                    UpdateThrustDependentCalcs();

                    // Legacy bell scaling equation
                    bellScale = Mathf.Sqrt(thrust / deprecatedThrustScaleFactor);
                }

                UpdateEngineAndBellScale();
            }

            // It makes no sense to have a thrust limiter for SRBs
            // Even though this is present in stock, I'm disabling it.
            BaseField thrustLimiter = ((PartModule)Engine).Fields["thrustPercentage"];

            thrustLimiter.guiActive       = false;
            thrustLimiter.guiActiveEditor = false;

            ProceduralPart pPart = GetComponent <ProceduralPart>();

            if (pPart != null)
            {
                // Attach the bell. In the config file this isn't in normalized position, move it into normalized position first.
                print("*PP* Setting bell position: " + pPart.transform.TransformPoint(0, -0.5f, 0));
                srbBell.position = pPart.transform.TransformPoint(0, -0.5f, 0);
                pPart.AddAttachment(srbBell, true);

                // Move the bottom attach node into position.
                // This needs to be done in flight mode too for the joints to work correctly
                bottomAttachNode = part.findAttachNode(bottomAttachNodeName);
                Vector3 delta = selectedBell.srbAttach.position - selectedBell.model.position;
                bottomAttachNode.originalPosition = bottomAttachNode.position += part.transform.InverseTransformDirection(delta);

                pPart.AddNodeOffset(bottomAttachNodeName, GetOffset);
            }

            // Move thrust transform to the end of the bell
            thrustTransform.position = selectedBell.srbAttach.position;
        }
示例#8
0
        private void InitializeBells()
        {
            Debug.Log($"{ModTag} {part}.{this}: InitializeBells");
            // Initialize the configs.
            if (srbConfigs == null)
            {
                LoadSRBConfigs();
            }

            BaseField field = Fields["selectedBellName"];

            // ReSharper disable once PossibleNullReferenceException
            switch (srbConfigs.Count)
            {
            case 0:
                Debug.LogError($"{ModTag} {part}.{this}: No SRB bells configured");
                return;

            case 1:
                field.guiActiveEditor = false;
                break;

            default:
                field.guiActiveEditor = true;
                UI_ChooseOption range = (UI_ChooseOption)field.uiControlEditor;
                range.options = srbConfigs.Keys.ToArray();
                break;
            }

            bellTransform     = part.FindModelTransform(srbBellName);
            bellRootTransform = part.FindModelTransform(srbBellName + "root");
            if (bellRootTransform == null)
            {
                bellRootTransform = bellTransform;
            }
            thrustTransform = bellTransform.Find(thrustVectorTransformName);

            PrepareBellModels();

            // Select the bell
            if (string.IsNullOrEmpty(selectedBellName) || !srbConfigs.ContainsKey(selectedBellName))
            {
                selectedBellName = srbConfigsSerialized[0].GetValue("name");
            }
            selectedBell = srbConfigs[selectedBellName];

            ConfigureRealFuels();

            // Initialize the modules.
            InitModulesFromBell();

            // Break out at this stage during loading scene
            if (HighLogic.LoadedScene == GameScenes.LOADING)
            {
                UpdateThrustDependentCalcs();
                return;
            }

            // Update the thrust according to the equation when in editor mode, don't mess with ships in flight
            if (HighLogic.LoadedSceneIsEditor)
            {
                UpdateThrustDependentCalcs();
            }
            else
            {
                if (bellScale <= 0 || heatProduction <= 0)
                {
                    // We've reloaded from a legacy save
                    // Use the new heat production equation, but use the legacy bell scaling one.
                    UpdateThrustDependentCalcs();

                    // Legacy bell scaling equation
                    bellScale = Mathf.Sqrt(thrust / deprecatedThrustScaleFactor);
                    Debug.Log($"{ModTag} {part}.{this}: legacy bell scale: {bellScale}");
                }

                UpdateEngineAndBellScale();
            }

            // It makes no sense to have a thrust limiter for SRBs
            // Even though this is present in stock, I'm disabling it.
            BaseField thrustLimiter = ((PartModule)Engine).Fields["thrustPercentage"];

            thrustLimiter.guiActive       = false;
            thrustLimiter.guiActiveEditor = false;

            //ProceduralPart pPart = GetComponent<ProceduralPart>();
            if (PPart != null)
            {
                SetBellRotation(thrustDeflection);
            }
            else
            {
                Debug.Log($"{ModTag} {part}.{this}: ProceduralSRB.InitializeBells() Unable to find ProceduralPart component! (null) for {part.name}");
            }

            // Move thrust transform to the end of the bell
            thrustTransform.position = selectedBell.srbAttach.position;
        }
        private void UpdateBell()
        {
            if (selectedBell == null || selectedBellName == selectedBell.name)
                return;

            SRBBellConfig oldSelectedBell = selectedBell;

            if (!srbConfigs.TryGetValue(selectedBellName, out selectedBell))
            {
                Debug.LogError("*ST* Selected bell name \"" + selectedBellName + "\" does not exist. Reverting.");
                selectedBellName = oldSelectedBell.name;
                selectedBell = oldSelectedBell;
                return;
            }

            oldSelectedBell.model.gameObject.SetActive(false);

            MoveBottomAttachmentAndNode(selectedBell.srbAttach.position - oldSelectedBell.srbAttach.position);

            InitModulesFromBell();

            UpdateMaxThrust();
        }
 private void LoadSRBConfigs()
 {
     srbConfigs = new Dictionary<string, SRBBellConfig>();
     foreach (ConfigNode srbNode in srbConfigsSerialized)
     {
         SRBBellConfig conf = new SRBBellConfig();
         conf.Load(srbNode);
         srbConfigs.Add(conf.name, conf);
     }
 }
        private void InitializeBells()
        {
            print("*PP* InitializeBells");
            // Initialize the configs.
            if (srbConfigs == null)
                LoadSRBConfigs();

            BaseField field = Fields["selectedBellName"];
            // ReSharper disable once PossibleNullReferenceException
            switch (srbConfigs.Count)
            {
                case 0:
                    Debug.LogError("*PT*  No SRB bells configured");
                    return;
                case 1:
                    field.guiActiveEditor = false;
                    break;
                default:
                    field.guiActiveEditor = true;
                    UI_ChooseOption range = (UI_ChooseOption)field.uiControlEditor;
                    range.options = srbConfigs.Keys.ToArray();
                    break;
            }

            Transform srbBell = part.FindModelTransform(srbBellName);
            thrustTransform = srbBell.Find(thrustVectorTransformName);

            foreach (SRBBellConfig conf in srbConfigs.Values)
            {
                conf.model = part.FindModelTransform(conf.modelName);
                if (conf.model == null)
                {
                    Debug.LogError("*PT* Unable to find model transform for SRB bell name: " + conf.modelName);
                    srbConfigs.Remove(conf.modelName);
                    continue;
                }
                conf.model.transform.parent = srbBell;

                conf.srbAttach = conf.model.Find(conf.srbAttachName);
                if (conf.srbAttach == null)
                {
                    Debug.LogError("*PT* Unable to find srbAttach for SRB bell name: " + conf.modelName);
                    srbConfigs.Remove(conf.modelName);
                    continue;
                }

                // Only enable the colider for flight mode. This prevents any surface attachments.
                if (HighLogic.LoadedSceneIsEditor && conf.model.collider != null)
                    Destroy(conf.model.collider);

                conf.model.gameObject.SetActive(false);
            }

            // Select the bell
            if (string.IsNullOrEmpty(selectedBellName) || !srbConfigs.ContainsKey(selectedBellName))
                selectedBellName = srbConfigsSerialized[0].GetValue("name");
            selectedBell = srbConfigs[selectedBellName];

            // Config for Real Fuels.
            if (part.Modules.Contains("ModuleEngineConfigs"))
            {
                // ReSharper disable once InconsistentNaming
                var mEC = part.Modules["ModuleEngineConfigs"];
                ModularEnginesChangeThrust = (Action<float>)Delegate.CreateDelegate(typeof(Action<float>), mEC, "ChangeThrust");
                try
                {
                    ModularEnginesChangeEngineType = (Action<string>) Delegate.CreateDelegate(typeof (Action<string>), mEC, "ChangeEngineType");
                }
                catch
                {
                    ModularEnginesChangeEngineType = null;
                }

                //Fields["burnTime"].guiActiveEditor = false;
                //Fields["srbISP"].guiActiveEditor = false;
                //Fields["heatProduction"].guiActiveEditor = false;
            }
            Fields["thrust"].guiActiveEditor = !UsingME;
            Fields["burnTime"].guiActiveEditor = !UsingME;
            Fields["burnTimeME"].guiActiveEditor = UsingME;
            Fields["thrustME"].guiActiveEditor = UsingME;

            // Initialize the modules.
            InitModulesFromBell();

            // Break out at this stage during loading scene
            if (GameSceneFilter.AnyInitializing.IsLoaded())
            {
                UpdateThrustDependentCalcs();
                return;
            }

            // Update the thrust according to the equation when in editor mode, don't mess with ships in flight
            if (GameSceneFilter.AnyEditor.IsLoaded())
                UpdateThrustDependentCalcs();
            else
            {
                if (bellScale <= 0 || heatProduction <= 0)
                {
                    // We've reloaded from a legacy save
                    // Use the new heat production equation, but use the legacy bell scaling one.
                    UpdateThrustDependentCalcs();

                    // Legacy bell scaling equation
                    bellScale = Mathf.Sqrt(thrust / deprecatedThrustScaleFactor);
                }

                UpdateEngineAndBellScale();
            }

            // It makes no sense to have a thrust limiter for SRBs
            // Even though this is present in stock, I'm disabling it.
            BaseField thrustLimiter = ((PartModule)Engine).Fields["thrustPercentage"];
            thrustLimiter.guiActive = false;
            thrustLimiter.guiActiveEditor = false;

            ProceduralPart pPart = GetComponent<ProceduralPart>();
            if (pPart != null)
            {
                // Attach the bell. In the config file this isn't in normalized position, move it into normalized position first.
                print("*PP* Setting bell position: " + pPart.transform.TransformPoint(0, -0.5f, 0));
                srbBell.position = pPart.transform.TransformPoint(0, -0.5f, 0);
                pPart.AddAttachment(srbBell, true);

                // Move the bottom attach node into position.
                // This needs to be done in flight mode too for the joints to work correctly
                bottomAttachNode = part.findAttachNode(bottomAttachNodeName);
                Vector3 delta = selectedBell.srbAttach.position - selectedBell.model.position;
                bottomAttachNode.originalPosition = bottomAttachNode.position += part.transform.InverseTransformDirection(delta);

                pPart.AddNodeOffset(bottomAttachNodeName, GetOffset);
            }

            // Move thrust transform to the end of the bell
            thrustTransform.position = selectedBell.srbAttach.position;
        }
示例#12
0
        private void InitializeBells()
        {
            Debug.Log($"{ModTag} {this}: InitializeBells");
            // Initialize the configs.
            if (srbConfigs.Count < 1)
            {
                LoadSRBConfigs();
            }
            if (srbConfigs.Count < 1)
            {
                Debug.LogError($"{ModTag} {this}: No SRB bells configured");
                return;
            }

            Fields[nameof(selectedBellName)].guiActiveEditor = srbConfigs.Count > 1;
            (Fields[nameof(selectedBellName)].uiControlEditor as UI_ChooseOption).options = srbConfigs.Keys.ToArray();

            bellTransform     = part.FindModelTransform(srbBellName);
            bellRootTransform = part.FindModelTransform(srbBellName + "root");
            bellRootTransform ??= bellTransform;
            thrustTransform = bellTransform.Find(thrustVectorTransformName);

            PrepareBellModels();

            // Select the bell
            if (string.IsNullOrEmpty(selectedBellName) || !srbConfigs.ContainsKey(selectedBellName))
            {
                selectedBellName = srbConfigs.First().Key;
            }
            selectedBell = srbConfigs[selectedBellName];

            ConfigureRealFuels();

            // Initialize the modules.
            InitModulesFromBell();

            if (HighLogic.LoadedScene == GameScenes.LOADING ||
                HighLogic.LoadedSceneIsEditor ||
                (HighLogic.LoadedSceneIsFlight && (bellScale <= 0 || heatProduction <= 0)))
            {
                UpdateThrustDependentCalcs();
            }

            // Break out at this stage during loading scene
            if (HighLogic.LoadedScene == GameScenes.LOADING)
            {
                return;
            }

            // Update the thrust according to the equation when in editor mode, don't mess with ships in flight
            if (HighLogic.LoadedSceneIsFlight)
            {
                if (bellScale <= 0 || heatProduction <= 0)
                {
                    // Legacy bell scaling equation
                    bellScale = Mathf.Sqrt(thrust / deprecatedThrustScaleFactor);
                    Debug.Log($"{ModTag} {this}: legacy bell scale: {bellScale}");
                }

                UpdateEngineAndBellScale();
            }

            // Disable SRB thrust limiter
            BaseField thrustLimiter = ((PartModule)Engine).Fields["thrustPercentage"];

            thrustLimiter.guiActive = thrustLimiter.guiActiveEditor = false;

            if (PPart != null)
            {
                SetBellRotation(thrustDeflection);
            }
            else
            {
                Debug.Log($"{ModTag} {part}.{this}: ProceduralSRB.InitializeBells() Unable to find ProceduralPart component! (null) for {part.name}");
            }

            // Move thrust transform to the end of the bell
            thrustTransform.position = selectedBell.srbAttach.position;
        }