diff --git a/Source/Engines/ModuleEngineConfigs.cs b/Source/Engines/ModuleEngineConfigs.cs
index 28263106..e1c4a8d2 100644
--- a/Source/Engines/ModuleEngineConfigs.cs
+++ b/Source/Engines/ModuleEngineConfigs.cs
@@ -219,6 +219,8 @@ public class ModuleEngineConfigsBase : PartModule, IPartCostModifier, IPartMassM
public float origMass = -1;
protected float massDelta = 0;
+ public int? Ignitions { get; protected set; }
+
[KSPField]
public string gimbalTransform = string.Empty;
[KSPField]
@@ -824,15 +826,18 @@ protected void SetConfiguration(ConfigNode newConfig, bool resetTechLevels)
DoConfig(config);
HandleEngineIgnitor(config);
+
+ Ignitions = null;
if (config.HasValue("ignitions"))
{
- if (HighLogic.LoadedSceneIsFlight && vessel?.situation != Vessel.Situations.PRELAUNCH)
- config.RemoveValue("ignitions");
- else if (int.TryParse(config.GetValue("ignitions"), out int ignitions))
+ if (int.TryParse(config.GetValue("ignitions"), out int tmpIgnitions))
{
- ignitions = ConfigIgnitions(ignitions);
- config.SetValue("ignitions", ignitions);
+ Ignitions = ConfigIgnitions(tmpIgnitions);
+ config.SetValue("ignitions", Ignitions.Value);
}
+
+ if (HighLogic.LoadedSceneIsFlight && vessel?.situation != Vessel.Situations.PRELAUNCH)
+ config.RemoveValue("ignitions");
}
// Trigger re-computation of the response rate if one is not set explicitly.
diff --git a/Source/Engines/ModuleEnginesRF.cs b/Source/Engines/ModuleEnginesRF.cs
index dec462bb..52db2344 100644
--- a/Source/Engines/ModuleEnginesRF.cs
+++ b/Source/Engines/ModuleEnginesRF.cs
@@ -756,6 +756,25 @@ public void SetScale(double newScale)
scale = newScale;
rfSolver?.SetScale(scale);
}
+
+ ///
+ /// Used by the engine repair feature in RP-1.
+ ///
+ public void ResetIgnitions()
+ {
+ List mecs = part.FindModulesImplementing();
+ ModuleEngineConfigs matchingMEC = mecs.Find(m => m.pModule == this);
+ if (matchingMEC != null && matchingMEC.Ignitions.HasValue)
+ {
+ ignitions = matchingMEC.Ignitions.Value;
+ }
+ else
+ {
+ ModuleEnginesRF merf = part.FetchModuleFromPrefab(this);
+ if (merf != null)
+ ignitions = merf.ignitions;
+ }
+ }
#endregion
#region Info
diff --git a/Source/Tanks/ModuleFuelTanks.cs b/Source/Tanks/ModuleFuelTanks.cs
index 208b980a..c95cf1f3 100644
--- a/Source/Tanks/ModuleFuelTanks.cs
+++ b/Source/Tanks/ModuleFuelTanks.cs
@@ -130,15 +130,7 @@ public override void OnAwake()
unmanagedResources = new Dictionary();
else if (HighLogic.LoadedSceneIsFlight || HighLogic.LoadedSceneIsEditor)
{
- int index = part.Modules.IndexOf(this);
- if (index < 0)
- index = part.Modules.Count;
- Part prefab = part.partInfo.partPrefab;
- ModuleFuelTanks mft;
- if (prefab.Modules.Count > index && prefab.Modules[index] is ModuleFuelTanks m)
- mft = m;
- else
- mft = prefab.FindModuleImplementing();
+ ModuleFuelTanks mft = part.FetchModuleFromPrefab(this);
unmanagedResources = mft.unmanagedResources;
typesAvailable = new List(mft.typesAvailable); // Copy so any changes don't impact the prefab
allPossibleTypes = mft.allPossibleTypes;
diff --git a/Source/Utilities/Utilities.cs b/Source/Utilities/Utilities.cs
index 181366a9..781fd605 100644
--- a/Source/Utilities/Utilities.cs
+++ b/Source/Utilities/Utilities.cs
@@ -275,5 +275,18 @@ public static void ResolveAndAddUnique(this IList defs, IEnumera
ResolveAndAddUnique(defs, name);
}
}
+
+ public static T FetchModuleFromPrefab(this Part part, T pm)
+ where T : PartModule
+ {
+ int index = part.Modules.IndexOf(pm);
+ if (index < 0)
+ index = part.Modules.Count; // during instantiation (OnAwake), when we are addcomponenting this module, we may not have added it to the Modules list
+ Part prefab = part.partInfo.partPrefab;
+ if (prefab.Modules.Count > index && prefab.Modules[index] is T m)
+ return m;
+ else
+ return prefab.FindModuleImplementing();
+ }
}
}