示例#1
0
 public override string GetInfo()
 {
     try
     {
         return(this.GetType().Name);
     }
     catch (Exception e)
     {
         GTIDebug.LogError(this.GetType().Name + " GetInfo() Error " + e.Message);
         throw;
     }
 }
示例#2
0
        protected override void initializeSettings()
        {
            if (!_settingsInitialized)
            {
                GTIDebug.Log("GTI_MultiModeRCS() --> initializeSettings()", iDebugLevel.DebugInfo);

                string[] arrGUIRCSID;

                #region Split into Arrays
                //arrRCSID = RCSID.Trim().Split(';');
                GUIRCSIDEmpty = ArraySplitEvaluate(GUIRCSID, out arrGUIRCSID, ';');
                #endregion

                #region Identify ModuleRCS in Scope
                GTIDebug.Log("Find modules RCS from part", iDebugLevel.DebugInfo);
                ModuleRCSs = part.FindModulesImplementing <ModuleRCS>();

                modes = new List <MultiMode>(ModuleRCSs.Count);
                if (ModuleRCSs.Count != arrGUIRCSID.Length || GUIRCSIDEmpty)
                {
                    GTIDebug.LogError("GTI_MultiModeRCS Error in CFG configuration detected");
                }


                GTIDebug.Log("Create list of modes", iDebugLevel.DebugInfo);
                for (int i = 0; i < ModuleRCSs.Count; i++)
                {
                    modes.Add(new MultiMode()
                    {
                        moduleIndex = i,
                        ID          = i.ToString(),
                        Name        = GUIRCSIDEmpty ? ModuleRCSs[i].resourceName : arrGUIRCSID[i]
                    });
                }

                //Remove the is interactions buttons of the engines, so that it is controlled by this mod instead
                //foreach (var moduleEngine in ModuleEngines)
                for (int i = 0; i < ModuleRCSs.Count; i++)
                {
                    //Deactivate stock RCS actions
                    ModuleRCSs[i].Actions["ToggleAction"].active = false;
                }

                useModuleAnimationGroup = false;    //ModuleAnimationGroup handling, can be added if needed later
                #endregion
            }
        }
        public override string GetInfo()
        {
            StringBuilder Info = new StringBuilder();

            GTIDebug.Log("GTI_MultiModeEngineFX GetInfo");
            try
            {
                if (!_settingsInitialized)
                {
                    initializeSettings();
                    //ModuleEngines = part.FindModulesImplementing<ModuleEnginesFX>();
                }


                //Info.AppendLine("GTI MultiMode Engine FX");
                Info.AppendLine("<color=yellow>Engine Modes Available:</color>");
                Info.AppendLine(GUIengineID);
                Info.AppendLine("\nIn Flight switching is <color=yellow>" + (availableInFlight ? "available" : "not available") + "</color>");
                //foreach (ModuleEnginesFX e in ModuleEngines)
                //foreach (MultiMode m in modes)
                //{

                //    //ModuleEngines[m.moduleIndex].GetMaxThrust();

                //    Info.AppendLine("Max Trust " + ModuleEngines[m.moduleIndex].GetMaxThrust());
                //}


                //str.AppendFormat("Maximal force: {0:0.0}iN\n", maxGeneratorForce);
                //str.AppendFormat("Maximal charge time: {0:0.0}s\n\n", maxChargeTime);
                //str.AppendFormat("Requires\n");
                //str.AppendFormat("- Electric charge: {0:0.00}/s\n\n", requiredElectricalCharge);
                //str.Append("Navigational computer\n");
                //str.Append("- Required force\n");
                //str.Append("- Success probability\n");


                //return "GTI MultiMode Engine FX";
                return(Info.ToString());
            }
            catch (Exception e)
            {
                GTIDebug.LogError("GTI_MultiModeEngineFX GetInfo Error " + e.Message);
                throw;
            }
        }
示例#4
0
        public override void updateMultiMode(bool silentUpdate = false)
        {
            GTIDebug.Log(this.GetType().Name + " --> GTI_MultiModeIntake: updateMultiMode() --> Begin", iDebugLevel.High);
            Part currentPart = this.part;

            if (silentUpdate == false)
            {
                writeScreenMessage();
            }

            for (int i = 0; i < ModuleIntakes.Count; i++)
            {
                if (i == modes[selectedMode].moduleIndex)
                {
                    GTIDebug.Log("GTI_MultiMode (" + (silentUpdate ? "silent" : "non-silent") + "): Activate Module [" + modes[i].moduleIndex + "] --> " + ModuleIntakes[modes[i].moduleIndex].resourceName, iDebugLevel.High);
                    GTIDebug.Log("selectedMode Intake: " + selectedMode + "\tselectedModeStatus: " + selectedModeStatus);
                    if (selectedModeStatus)
                    {
                        GTIDebug.Log("Activating Intake Mode: " + modes[selectedMode].resourceName);
                        ModuleIntakes[i].intakeEnabled = true;
                    }
                    else
                    {
                        ModuleIntakes[i].intakeEnabled = false;
                    }
                    ModuleIntakes[i].enabled   = true;
                    ModuleIntakes[i].isEnabled = true;
                }
                else
                {
                    GTIDebug.Log("GTI_MultiMode (" + (silentUpdate ? "silent" : "non-silent") + "): Deactivate Module [" + modes[i].moduleIndex + "] --> " + ModuleIntakes[modes[i].moduleIndex].resourceName, iDebugLevel.High);
                    ModuleIntakes[i].enabled       = false;
                    ModuleIntakes[i].isEnabled     = false;     //=> FixedUpdate() will update status = "Closed" and exit
                    ModuleIntakes[i].intakeEnabled = false;
                }
            }
            this.Events["IntakeActivate"].active   = !selectedModeStatus;
            this.Events["IntakeDeactivate"].active = selectedModeStatus;

            #region Create new Resource node
            //Only handle resources if preservation is not activated
            if (!preserveResourceNodes)
            {
                //List<ConfigNode> IntakeResources = new List<ConfigNode>();
                ConfigNode IntakeResource = new ConfigNode("RESOURCE");
                float      resMaxAmount   = (float)ModuleIntakes[modes[selectedMode].moduleIndex].res.maxAmount;
                if (resMaxAmount <= 0)
                {
                    resMaxAmount = 1f;
                }
                float resIniAmount = HighLogic.LoadedSceneIsFlight ? 0f : resMaxAmount;

                //Create Resource node
                IntakeResource.AddValue("name", modes[selectedMode].resourceName);
                IntakeResource.AddValue("amount", resIniAmount);
                IntakeResource.AddValue("maxAmount", resMaxAmount);

                //All resource properties
                //partResource.amount = amount;
                //partResource.maxAmount = maxAmount;
                //partResource.flowState = flowState;
                //partResource.isTweakable = isTweakable;
                //partResource.hideFlow = hideFlow;
                //partResource.isVisible = isVisible;
                //partResource.flowMode = flow;


                //Clear all resources since I get null ref error when I do not do this
                //currentPart.Resources.Clear();
                bool preserveResource;
                // remove all target resources
                List <PartResource> resourcesDeleteList = new List <PartResource>();
                foreach (PartResource resource in currentPart.Resources)
                {
                    preserveResource = true;
                    GTIDebug.Log("Check for resource removal: " + resource.resourceName, iDebugLevel.DebugInfo);
                    for (int j = 0; j < modes.Count; j++)
                    {
                        if (modes[j].resourceName == resource.resourceName)
                        {
                            //Remove resources managed by this mod
                            preserveResource = false;
                            break;
                        }
                    }
                    if (!preserveResource)
                    {
                        GTIDebug.Log("Removing Resource: " + resource.resourceName, iDebugLevel.DebugInfo);
                        //if (currentPart.Resources.Remove(resource)) GTIDebug.Log("Resource removed: " + GetResourceID(resource.resourceName), iDebugLevel.DebugInfo);
                        resourcesDeleteList.Add(resource);
                    }
                }
                foreach (var resource in resourcesDeleteList)
                {
                    if (currentPart.Resources.Remove(resource))
                    {
                        GTIDebug.Log("Resource removed: " + GetResourceID(resource.resourceName), iDebugLevel.DebugInfo);
                    }
                }
                resourcesDeleteList = null;

                //Add the resources
                GTIDebug.Log("MultiModeIntake: Add Resource\n" + IntakeResource.ToString(), iDebugLevel.DebugInfo);
                currentPart.AddResource(IntakeResource);
                //IntakeResource.ClearNodes();
                //IntakeResource.ClearValues();

                GTIDebug.Log("Listing resources defined in part", iDebugLevel.DebugInfo);
                if (DebugLevel == iDebugLevel.DebugInfo)
                {
                    for (int i = 0; i < currentPart.Resources.Count; i++)
                    {
                        GTIDebug.Log("currentPart.Resources[" + i + "].resourceName: " + currentPart.Resources[i].resourceName + " \t" + currentPart.Resources[i].maxAmount, iDebugLevel.DebugInfo);
                    }
                }
            }
            #endregion

            try
            { if (HighLogic.LoadedSceneIsFlight && !silentUpdate)
              {
                  KSP.UI.Screens.ResourceDisplay.Instance.Refresh();
              }
            }
            catch { GTIDebug.LogError("Update resource panel failed."); }
        }