From 6b2ef96b8869dc9bbb2a823c16264e55c7313237 Mon Sep 17 00:00:00 2001 From: MOARdV Date: Wed, 25 Oct 2017 07:48:39 -0500 Subject: [PATCH 1/3] Fix formatting --- RasterPropMonitor/Core/RPMGlobals.cs | 8 +- RasterPropMonitor/Core/RPMVCPerModule.cs | 198 ++++++++++++-------- RasterPropMonitor/Core/RPMVesselComputer.cs | 2 +- RasterPropMonitor/Core/UtilityFunctions.cs | 56 +++--- 4 files changed, 159 insertions(+), 105 deletions(-) diff --git a/RasterPropMonitor/Core/RPMGlobals.cs b/RasterPropMonitor/Core/RPMGlobals.cs index 3fd97116..748a3c23 100644 --- a/RasterPropMonitor/Core/RPMGlobals.cs +++ b/RasterPropMonitor/Core/RPMGlobals.cs @@ -68,9 +68,9 @@ internal static class RPMGlobals internal static SortedDictionary systemNamedResources = new SortedDictionary(); internal static List triggeredEvents = new List(); - /// List of parts where all PartModule should be ignored. - internal static List ignoreAllPartModules = new List(); - /// List of parts where some PartModules should be ignored. Part names are the Key, list of module names is the Value. - internal static Dictionary> ignorePartModules = new Dictionary>(); + /// List of parts where all PartModule should be ignored. + internal static List ignoreAllPartModules = new List(); + /// List of parts where some PartModules should be ignored. Part names are the Key, list of module names is the Value. + internal static Dictionary> ignorePartModules = new Dictionary>(); } } diff --git a/RasterPropMonitor/Core/RPMVCPerModule.cs b/RasterPropMonitor/Core/RPMVCPerModule.cs index e11eb5b4..061e8613 100644 --- a/RasterPropMonitor/Core/RPMVCPerModule.cs +++ b/RasterPropMonitor/Core/RPMVCPerModule.cs @@ -38,7 +38,7 @@ public partial class RPMVesselComputer : VesselModule /// JSIInternalButtons methods is outright eliminated. private bool listsInvalid = true; - private readonly static List emptyIgnoreList = new List(); + private readonly static List emptyIgnoreList = new List(); //--- Docking Nodes internal ModuleDockingNode mainDockingNode; @@ -169,79 +169,124 @@ internal void UpdateModuleLists() var partsList = vessel.parts; for (int partsIdx = 0; partsIdx < partsList.Count; ++partsIdx) { - string partName = partsList[partsIdx].partInfo.name; - if (!RPMGlobals.ignoreAllPartModules.Contains(partName)) { - List modulesToIgnore; - if (!RPMGlobals.ignorePartModules.TryGetValue(partName, out modulesToIgnore)) { - modulesToIgnore = emptyIgnoreList; - } - foreach (PartModule module in partsList[partsIdx].Modules) { - if (module.isEnabled && !modulesToIgnore.Contains(module.moduleName)) { - if (module is ModuleEngines) { - availableEngines.Add(module as ModuleEngines); - } else if (module is MultiModeEngine) { - availableMultiModeEngines.Add(module as MultiModeEngine); - } else if (module is JSIThrustReverser) { - availableThrustReverser.Add(module as JSIThrustReverser); - } else if (module is ModuleAblator) { - availableAblators.Add(module as ModuleAblator); - } else if (module is ModuleResourceIntake) { - if ((module as ModuleResourceIntake).resourceName == "IntakeAir") { - availableAirIntakes.Add(module as ModuleResourceIntake); - } else { - JUtil.LogMessage(this, "intake resource is {0}?", (module as ModuleResourceIntake).resourceName); - } - } else if (module is ModuleAlternator) { - ModuleAlternator alt = module as ModuleAlternator; - for (int i = 0; i < alt.resHandler.outputResources.Count; ++i) { - if (alt.resHandler.outputResources[i].name == "ElectricCharge") { - availableAlternators.Add(alt); - break; - } - } - } else if (module is ModuleGenerator) { - ModuleGenerator gen = module as ModuleGenerator; - for (int i = 0; i < gen.resHandler.outputResources.Count; ++i) { - if (gen.resHandler.outputResources[i].name == "ElectricCharge") { - availableGenerators.Add(gen); - availableGeneratorOutput.Add((float)gen.resHandler.outputResources[i].rate); - break; - } - } - } else if (module is ModuleResourceConverter) { - ModuleResourceConverter gen = module as ModuleResourceConverter; - ConversionRecipe recipe = gen.Recipe; - for (int i = 0; i < recipe.Outputs.Count; ++i) { - if (recipe.Outputs[i].ResourceName == "ElectricCharge") { - availableFuelCells.Add(gen); - availableFuelCellOutput.Add((float)recipe.Outputs[i].Ratio); - break; - } - } - } else if (module is ModuleDeployableSolarPanel) { - ModuleDeployableSolarPanel sp = module as ModuleDeployableSolarPanel; - - if (sp.resourceName == "ElectricCharge") { - availableSolarPanels.Add(sp); - } - } else if (module is ModuleGimbal) { - availableGimbals.Add(module as ModuleGimbal); - } else if (module is JSIRadar) { - availableRadars.Add(module as JSIRadar); - } else if (module is ModuleParachute) { - availableParachutes.Add(module as ModuleParachute); - } else if (module is ModuleWheels.ModuleWheelDeployment) { - availableDeployableWheels.Add(module as ModuleWheels.ModuleWheelDeployment); - } else if (module is ModuleWheels.ModuleWheelDamage) { - availableWheelDamage.Add(module as ModuleWheels.ModuleWheelDamage); - } else if (module is ModuleWheels.ModuleWheelBrakes) { - availableWheelBrakes.Add(module as ModuleWheels.ModuleWheelBrakes); - } else if (JSIParachute.rcFound && module.GetType() == JSIParachute.rcModuleRealChute) { - availableRealChutes.Add(module); - } - } - } - } + string partName = partsList[partsIdx].partInfo.name; + if (!RPMGlobals.ignoreAllPartModules.Contains(partName)) + { + List modulesToIgnore; + if (!RPMGlobals.ignorePartModules.TryGetValue(partName, out modulesToIgnore)) + { + modulesToIgnore = emptyIgnoreList; + } + foreach (PartModule module in partsList[partsIdx].Modules) + { + if (module.isEnabled && !modulesToIgnore.Contains(module.moduleName)) + { + if (module is ModuleEngines) + { + availableEngines.Add(module as ModuleEngines); + } + else if (module is MultiModeEngine) + { + availableMultiModeEngines.Add(module as MultiModeEngine); + } + else if (module is JSIThrustReverser) + { + availableThrustReverser.Add(module as JSIThrustReverser); + } + else if (module is ModuleAblator) + { + availableAblators.Add(module as ModuleAblator); + } + else if (module is ModuleResourceIntake) + { + if ((module as ModuleResourceIntake).resourceName == "IntakeAir") + { + availableAirIntakes.Add(module as ModuleResourceIntake); + } + else + { + JUtil.LogMessage(this, "intake resource is {0}?", (module as ModuleResourceIntake).resourceName); + } + } + else if (module is ModuleAlternator) + { + ModuleAlternator alt = module as ModuleAlternator; + for (int i = 0; i < alt.resHandler.outputResources.Count; ++i) + { + if (alt.resHandler.outputResources[i].name == "ElectricCharge") + { + availableAlternators.Add(alt); + break; + } + } + } + else if (module is ModuleGenerator) + { + ModuleGenerator gen = module as ModuleGenerator; + for (int i = 0; i < gen.resHandler.outputResources.Count; ++i) + { + if (gen.resHandler.outputResources[i].name == "ElectricCharge") + { + availableGenerators.Add(gen); + availableGeneratorOutput.Add((float)gen.resHandler.outputResources[i].rate); + break; + } + } + } + else if (module is ModuleResourceConverter) + { + ModuleResourceConverter gen = module as ModuleResourceConverter; + ConversionRecipe recipe = gen.Recipe; + for (int i = 0; i < recipe.Outputs.Count; ++i) + { + if (recipe.Outputs[i].ResourceName == "ElectricCharge") + { + availableFuelCells.Add(gen); + availableFuelCellOutput.Add((float)recipe.Outputs[i].Ratio); + break; + } + } + } + else if (module is ModuleDeployableSolarPanel) + { + ModuleDeployableSolarPanel sp = module as ModuleDeployableSolarPanel; + + if (sp.resourceName == "ElectricCharge") + { + availableSolarPanels.Add(sp); + } + } + else if (module is ModuleGimbal) + { + availableGimbals.Add(module as ModuleGimbal); + } + else if (module is JSIRadar) + { + availableRadars.Add(module as JSIRadar); + } + else if (module is ModuleParachute) + { + availableParachutes.Add(module as ModuleParachute); + } + else if (module is ModuleWheels.ModuleWheelDeployment) + { + availableDeployableWheels.Add(module as ModuleWheels.ModuleWheelDeployment); + } + else if (module is ModuleWheels.ModuleWheelDamage) + { + availableWheelDamage.Add(module as ModuleWheels.ModuleWheelDamage); + } + else if (module is ModuleWheels.ModuleWheelBrakes) + { + availableWheelBrakes.Add(module as ModuleWheels.ModuleWheelBrakes); + } + else if (JSIParachute.rcFound && module.GetType() == JSIParachute.rcModuleRealChute) + { + availableRealChutes.Add(module); + } + } + } + } if (vessel.currentStage <= partsList[partsIdx].inverseStage) { @@ -767,8 +812,9 @@ internal void SetEnableEngines(bool state) { Part thatPart = availableEngines[i].part; - if (StageManager.CurrentStage == StageManager.StageCount && thatPart.inverseStage == StageManager.StageCount - 1 || //This line allows to start engines of the first stage before the initial launch - thatPart.inverseStage == StageManager.CurrentStage || !state) + // The first line allows to start engines of the first stage before the initial launch + if ((StageManager.CurrentStage == StageManager.StageCount && thatPart.inverseStage == StageManager.StageCount - 1) || + thatPart.inverseStage == StageManager.CurrentStage || !state) { if (availableEngines[i].EngineIgnited != state) { diff --git a/RasterPropMonitor/Core/RPMVesselComputer.cs b/RasterPropMonitor/Core/RPMVesselComputer.cs index 28ad76e5..59ddbe56 100644 --- a/RasterPropMonitor/Core/RPMVesselComputer.cs +++ b/RasterPropMonitor/Core/RPMVesselComputer.cs @@ -1437,7 +1437,7 @@ internal double SuicideBurnCountdown() return impactTime - decelTime / 2.0 - Planetarium.GetUniversalTime(); } - /// + /// /// Determines if enough screen updates have passed to trigger another data update. /// /// true if it's time to update things diff --git a/RasterPropMonitor/Core/UtilityFunctions.cs b/RasterPropMonitor/Core/UtilityFunctions.cs index a18e686b..6135419b 100644 --- a/RasterPropMonitor/Core/UtilityFunctions.cs +++ b/RasterPropMonitor/Core/UtilityFunctions.cs @@ -2034,30 +2034,38 @@ private IEnumerator LoadRasterPropMonitorValues() } } - RPMGlobals.ignoreAllPartModules.Clear(); - RPMGlobals.ignorePartModules.Clear(); - nodes = GameDatabase.Instance.GetConfigNodes("RPM_IGNORE_MODULES"); - for (int idx = 0; idx < nodes.Length; ++idx) { - foreach (string nameExpression in nodes[idx].GetValuesList("moduleName")) { - string[] splitted = nameExpression.Split(':'); //splitted[0] - part name, splitted[1] - module name - if (splitted.Length != 2 || splitted[0].Length == 0 || splitted[1].Length == 0) { - continue; //just skipping in case of bad syntax - } - string partName = splitted[0].Replace('_','.'); //KSP does it, so we do - if (splitted[1] == "*") { - RPMGlobals.ignoreAllPartModules.Add(partName); - } else { - List moduleNameList; - if (!RPMGlobals.ignorePartModules.TryGetValue(partName, out moduleNameList)) { - moduleNameList = new List(); - RPMGlobals.ignorePartModules.Add(partName, moduleNameList); - } - if (!moduleNameList.Contains(splitted[1])) { - moduleNameList.Add(splitted[1]); - } - } - } - } + RPMGlobals.ignoreAllPartModules.Clear(); + RPMGlobals.ignorePartModules.Clear(); + nodes = GameDatabase.Instance.GetConfigNodes("RPM_IGNORE_MODULES"); + for (int idx = 0; idx < nodes.Length; ++idx) + { + foreach (string nameExpression in nodes[idx].GetValuesList("moduleName")) + { + string[] splitted = nameExpression.Split(':'); //splitted[0] - part name, splitted[1] - module name + if (splitted.Length != 2 || splitted[0].Length == 0 || splitted[1].Length == 0) + { + continue; //just skipping in case of bad syntax + } + string partName = splitted[0].Replace('_', '.'); //KSP does it, so we do + if (splitted[1] == "*") + { + RPMGlobals.ignoreAllPartModules.Add(partName); + } + else + { + List moduleNameList; + if (!RPMGlobals.ignorePartModules.TryGetValue(partName, out moduleNameList)) + { + moduleNameList = new List(); + RPMGlobals.ignorePartModules.Add(partName, moduleNameList); + } + if (!moduleNameList.Contains(splitted[1])) + { + moduleNameList.Add(splitted[1]); + } + } + } + } RPMGlobals.knownLoadedAssemblies.Clear(); for (int i = 0; i < AssemblyLoader.loadedAssemblies.Count; ++i) From f82786ee542276fc4adb98bf571faffd7692af0a Mon Sep 17 00:00:00 2001 From: MOARdV Date: Mon, 1 Jan 2018 08:30:02 -0600 Subject: [PATCH 2/3] Allow MJ interface to work without spaceplane autopilot. AP was substantially changed in MJ dev build 742. --- RasterPropMonitor.sln | 2 +- RasterPropMonitor/Handlers/JSIMechJeb.cs | 61 +++++++++++++----------- SharedAssemblyInfo.cs | 4 +- 3 files changed, 35 insertions(+), 32 deletions(-) diff --git a/RasterPropMonitor.sln b/RasterPropMonitor.sln index a6157efc..908c2556 100644 --- a/RasterPropMonitor.sln +++ b/RasterPropMonitor.sln @@ -195,6 +195,6 @@ Global $36.inheritsSet = Mono $36.inheritsScope = text/plain $36.scope = text/plain - version = 0.29.2 + version = 0.29.3 EndGlobalSection EndGlobal diff --git a/RasterPropMonitor/Handlers/JSIMechJeb.cs b/RasterPropMonitor/Handlers/JSIMechJeb.cs index 36d819d4..f89e7252 100644 --- a/RasterPropMonitor/Handlers/JSIMechJeb.cs +++ b/RasterPropMonitor/Handlers/JSIMechJeb.cs @@ -657,11 +657,14 @@ static JSIMechJeb() } spaceplaneAutoland = DynamicMethodDelegateFactory.Create(mjSPAutoland); MethodInfo mjSPHoldHeadingAndAltitude = mjSpaceplaneAutopilot_t.GetMethod("HoldHeadingAndAltitude", BindingFlags.Instance | BindingFlags.Public); - if (mjSPHoldHeadingAndAltitude == null) + //if (mjSPHoldHeadingAndAltitude == null) + //{ + // throw new NotImplementedException("mjSPHoldHeadingAndAltitude"); + //} + if (mjSPHoldHeadingAndAltitude != null) { - throw new NotImplementedException("mjSPHoldHeadingAndAltitude"); + spaceplaneHoldHeading = DynamicMethodDelegateFactory.Create(mjSPHoldHeadingAndAltitude); } - spaceplaneHoldHeading = DynamicMethodDelegateFactory.Create(mjSPHoldHeadingAndAltitude); MethodInfo mjSPAutopilotOff = mjSpaceplaneAutopilot_t.GetMethod("AutopilotOff", BindingFlags.Instance | BindingFlags.Public); if (mjSPAutopilotOff == null) { @@ -669,25 +672,25 @@ static JSIMechJeb() } spaceplaneAPOff = DynamicMethodDelegateFactory.CreateAction(mjSPAutopilotOff); spaceplaneAPMode = mjSpaceplaneAutopilot_t.GetField("mode", BindingFlags.Instance | BindingFlags.Public); - if (spaceplaneAPMode == null) - { - throw new NotImplementedException("spaceplaneAPMode"); - } + //if (spaceplaneAPMode == null) + //{ + // throw new NotImplementedException("spaceplaneAPMode"); + //} spaceplaneAltitude = mjSpaceplaneAutopilot_t.GetField("targetAltitude", BindingFlags.Instance | BindingFlags.Public); - if (spaceplaneAltitude == null) - { - throw new NotImplementedException("spaceplaneAltitude"); - } + //if (spaceplaneAltitude == null) + //{ + // throw new NotImplementedException("spaceplaneAltitude"); + //} spaceplaneHeading = mjSpaceplaneAutopilot_t.GetField("targetHeading", BindingFlags.Instance | BindingFlags.Public); - if (spaceplaneHeading == null) - { - throw new NotImplementedException("spaceplaneHeading"); - } + //if (spaceplaneHeading == null) + //{ + // throw new NotImplementedException("spaceplaneHeading"); + //} spaceplaneGlideslope = mjSpaceplaneAutopilot_t.GetField("glideslope", BindingFlags.Instance | BindingFlags.Public); - if (spaceplaneGlideslope == null) - { - throw new NotImplementedException("spaceplaneGlideslope"); - } + //if (spaceplaneGlideslope == null) + //{ + // throw new NotImplementedException("spaceplaneGlideslope"); + //} // EditableDouble Type mjEditableDouble_t = loadedMechJebAssy.assembly.GetExportedTypes() @@ -1500,7 +1503,7 @@ public double SpaceplaneHoldAltitude() { object activeJeb = GetMasterMechJeb(vessel); object ap = GetComputerModule(activeJeb, "MechJebModuleSpaceplaneAutopilot"); - if (ap != null) + if (ap != null && spaceplaneAltitude != null) { object altitude = spaceplaneAltitude.GetValue(ap); return getEditableDouble(altitude); @@ -1515,7 +1518,7 @@ public void SetSpaceplaneHoldAltitude(double altitude) { object activeJeb = GetMasterMechJeb(vessel); object ap = GetComputerModule(activeJeb, "MechJebModuleSpaceplaneAutopilot"); - if (ap != null) + if (ap != null && spaceplaneAltitude != null) { object holdAltitude = spaceplaneAltitude.GetValue(ap); setEditableDouble(holdAltitude, new object[] { altitude }); @@ -1526,7 +1529,7 @@ public bool SpaceplaneAltitudeProximity() { object activeJeb = GetMasterMechJeb(vessel); object ap = GetComputerModule(activeJeb, "MechJebModuleSpaceplaneAutopilot"); - if (ap != null) + if (ap != null && spaceplaneAltitude != null) { object holdaltitude = spaceplaneAltitude.GetValue(ap); double goalAltitude = getEditableDouble(holdaltitude); @@ -1544,7 +1547,7 @@ public double SpaceplaneHoldHeading() { object activeJeb = GetMasterMechJeb(vessel); object ap = GetComputerModule(activeJeb, "MechJebModuleSpaceplaneAutopilot"); - if (ap != null) + if (ap != null && spaceplaneHeading != null) { object heading = spaceplaneHeading.GetValue(ap); return getEditableDouble(heading); @@ -1560,7 +1563,7 @@ public void SetSpaceplaneHoldHeading(double heading) { object activeJeb = GetMasterMechJeb(vessel); object ap = GetComputerModule(activeJeb, "MechJebModuleSpaceplaneAutopilot"); - if (ap != null) + if (ap != null && spaceplaneHeading != null) { object holdHeading = spaceplaneHeading.GetValue(ap); setEditableDouble(holdHeading, new object[] { heading }); @@ -1571,7 +1574,7 @@ public double SpaceplaneGlideslope() { object activeJeb = GetMasterMechJeb(vessel); object ap = GetComputerModule(activeJeb, "MechJebModuleSpaceplaneAutopilot"); - if (ap != null) + if (ap != null && spaceplaneGlideslope != null) { object slope = spaceplaneGlideslope.GetValue(ap); return getEditableDouble(slope); @@ -1587,7 +1590,7 @@ public void SetSpaceplaneGlideslope(double angle) { object activeJeb = GetMasterMechJeb(vessel); object ap = GetComputerModule(activeJeb, "MechJebModuleSpaceplaneAutopilot"); - if (ap != null) + if (ap != null && spaceplaneGlideslope != null) { object slope = spaceplaneGlideslope.GetValue(ap); setEditableDouble(slope, new object[] { angle }); @@ -2114,7 +2117,7 @@ public void ButtonSpaceplaneHoldHeading(bool state) object activeJeb = GetMasterMechJeb(vessel); object ap = GetComputerModule(activeJeb, "MechJebModuleSpaceplaneAutopilot"); object controller = GetComputerModule(activeJeb, "MechJebModuleSpaceplaneGuidance"); - if (ap != null && controller != null) + if (ap != null && controller != null && spaceplaneHoldHeading != null) { if (state) { @@ -2135,7 +2138,7 @@ public bool ButtonSpaceplaneHoldHeadingState() { object activeJeb = GetMasterMechJeb(vessel); object ap = GetComputerModule(activeJeb, "MechJebModuleSpaceplaneAutopilot"); - if (ap != null) + if (ap != null && spaceplaneAPMode != null) { object mode = spaceplaneAPMode.GetValue(ap); return ((int)mode == (int)SpaceplaneMode.HOLD); @@ -2176,7 +2179,7 @@ public bool ButtonSpaceplaneAutolandState() { object activeJeb = GetMasterMechJeb(vessel); object ap = GetComputerModule(activeJeb, "MechJebModuleSpaceplaneAutopilot"); - if (ap != null) + if (ap != null && spaceplaneAPMode != null) { object mode = spaceplaneAPMode.GetValue(ap); return ((int)mode == (int)SpaceplaneMode.AUTOLAND); diff --git a/SharedAssemblyInfo.cs b/SharedAssemblyInfo.cs index d504ba8a..079258f5 100644 --- a/SharedAssemblyInfo.cs +++ b/SharedAssemblyInfo.cs @@ -4,7 +4,7 @@ [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct ("RasterPropMonitor")] -[assembly: AssemblyCopyright ("Copyright ©2013-2017 by Mihara, MOARdV, and other contributors, released under the terms of GNU GPLv3")] +[assembly: AssemblyCopyright ("Copyright ©2013-2018 by Mihara, MOARdV, and other contributors, released under the terms of GNU GPLv3")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] @@ -12,7 +12,7 @@ // The form "{Major}.{Minor}.*" will automatically update the build and revision, // and "{Major}.{Minor}.{Build}.*" will update just the revision. // Revision number is altered automatically. -[assembly: AssemblyVersion("0.29.2.*")] +[assembly: AssemblyVersion("0.29.3.*")] // The following attributes are used to specify the signing key for the assembly, // if desired. See the Mono documentation for more information about signing. From dbdf26ae070b2b28ad595ddbfa6840b0d98e92cf Mon Sep 17 00:00:00 2001 From: MOARdV Date: Mon, 1 Jan 2018 08:38:44 -0600 Subject: [PATCH 3/3] Bumpo version to 0.29.3 here, too --- GameData/JSI/RasterPropMonitor/RasterPropMonitor.version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GameData/JSI/RasterPropMonitor/RasterPropMonitor.version b/GameData/JSI/RasterPropMonitor/RasterPropMonitor.version index f5af2852..05e7ac86 100644 --- a/GameData/JSI/RasterPropMonitor/RasterPropMonitor.version +++ b/GameData/JSI/RasterPropMonitor/RasterPropMonitor.version @@ -5,7 +5,7 @@ "VERSION": { "MAJOR": 0, "MINOR": 29, - "PATCH": 2 + "PATCH": 3 }, "KSP_VERSION": { "MAJOR": 1,