From c766665010505b44ad8a8e2c861df1b01ed87902 Mon Sep 17 00:00:00 2001 From: Xarun Date: Sun, 4 Jun 2017 14:13:01 +0200 Subject: [PATCH] 1.3.3 Fix for KSP 1.3 Search for IScienceDataContainer instead of ModuleScienceContainer for higher mod compatibility --- .../AutomatedScienceSampler.cs | 24 +++++++++++++------ .../DefaultActivator.cs | 18 +++++++++----- .../IScienceActivator.cs | 4 ++-- .../Properties/AssemblyInfo.cs | 2 +- .../Activator.cs | 10 ++++---- .../Properties/AssemblyInfo.cs | 2 +- .../DMagic Orbital Science/Activator.cs | 8 +++---- .../Properties/AssemblyInfo.cs | 2 +- source/Plugins/Station Science/Activator.cs | 9 +++---- .../Properties/AssemblyInfo.cs | 2 +- 10 files changed, 49 insertions(+), 32 deletions(-) diff --git a/source/AutomatedScienceSampler/AutomatedScienceSampler.cs b/source/AutomatedScienceSampler/AutomatedScienceSampler.cs index f7f4a2a..0aed75d 100644 --- a/source/AutomatedScienceSampler/AutomatedScienceSampler.cs +++ b/source/AutomatedScienceSampler/AutomatedScienceSampler.cs @@ -22,7 +22,7 @@ public class AutomatedScienceSampler : KerboKatzBase, IToolbar private static List _activeScences = new List() { GameScenes.FLIGHT }; private Sprite _icon = AssetLoader.GetAsset("icon56", "Icons/AutomatedScienceSampler", "AutomatedScienceSampler/AutomatedScienceSampler"); private List experiments; - private List scienceContainers; + private List scienceContainers; private Dropdown transferScienceUIElement; private bool uiElementsReady; private string settingsUIName; @@ -185,7 +185,7 @@ private void OnTransferScienceChange(int arg0) Log("OnTransferScienceChange "); if (craftSettings.currentContainer != 0 && scienceContainers.Count >= craftSettings.currentContainer) { - StartCoroutine(DisableHighlight(0.25f, scienceContainers[craftSettings.currentContainer - 1].part)); + StartCoroutine(DisableHighlight(0.25f, ((PartModule)scienceContainers[craftSettings.currentContainer - 1]).part)); } SaveSettings(); } @@ -407,7 +407,7 @@ private void CheckExperimentOptions(ModuleScienceExperiment experiment, IScience } else if (CanTransferExperiment(experiment, activator)) { - + activator.Transfer(experiment, scienceContainers[craftSettings.currentContainer - 1]); } else if (CanResetExperiment(experiment, activator)) @@ -477,7 +477,7 @@ private bool BasicTransferCheck() return false; if (craftSettings.currentContainer > scienceContainers.Count) return false; - if (scienceContainers[craftSettings.currentContainer - 1].vessel != FlightGlobals.ActiveVessel) + if (((PartModule)scienceContainers[craftSettings.currentContainer - 1]).vessel != FlightGlobals.ActiveVessel) return false; return true; } @@ -509,11 +509,20 @@ private void UpdateShipInformation() transferScienceUIElement.options.RemoveAt(transferScienceUIElement.options.Count - 1); } experiments = FlightGlobals.ActiveVessel.FindPartModulesImplementing(); - scienceContainers = FlightGlobals.ActiveVessel.FindPartModulesImplementing(); + //scienceContainers = FlightGlobals.ActiveVessel.FindPartModulesImplementing(); + scienceContainers = FlightGlobals.ActiveVessel.FindPartModulesImplementing(); + for(var i = scienceContainers.Count-1; i >= 0; i--) + { + if (scienceContainers[i].GetType().IsTypeOf(typeof(ModuleScienceExperiment)))//dont want stock ModuleScienceExperiment as a transfer target as these can only contain the experiments results + { + Log("Removing ", (scienceContainers[i] as PartModule).moduleName, " as transfer target"); + scienceContainers.RemoveAt(i); + } + } shipCotainsExperiments.Clear(); - foreach (ModuleScienceContainer currentContainer in scienceContainers) + foreach (var currentContainer in scienceContainers) { - AddOptionToDropdown(transferScienceUIElement, currentContainer.part.partInfo.title); + AddOptionToDropdown(transferScienceUIElement, (currentContainer as PartModule).part.partInfo.title); foreach (var data in currentContainer.GetData()) { AddToContainer(data.subjectID); @@ -537,6 +546,7 @@ private void AddToContainer(string subjectID, int add = 0) } } + #region IToolbar public List activeScences diff --git a/source/AutomatedScienceSampler/DefaultActivator.cs b/source/AutomatedScienceSampler/DefaultActivator.cs index f919265..1443c24 100644 --- a/source/AutomatedScienceSampler/DefaultActivator.cs +++ b/source/AutomatedScienceSampler/DefaultActivator.cs @@ -43,7 +43,7 @@ public bool CanRunExperiment(ModuleScienceExperiment baseExperiment, float curre _AutomatedScienceSamplerInstance.Log(baseExperiment.experimentID, ": Science value is less than cutoff threshold: ", currentScienceValue, "<", _AutomatedScienceSamplerInstance.craftSettings.threshold); return false; } - if(baseExperiment.GetData().Length > 0) + if (baseExperiment.GetData().Length > 0) { _AutomatedScienceSamplerInstance.Log(baseExperiment.experimentID, ": Experiment already contains results!"); return false; @@ -74,8 +74,8 @@ public void DeployExperiment(ModuleScienceExperiment baseExperiment) public ScienceSubject GetScienceSubject(ModuleScienceExperiment baseExperiment) { - //experiment.BiomeIsRelevantWhile - return ResearchAndDevelopment.GetExperimentSubject(baseExperiment.experiment, ScienceUtil.GetExperimentSituation(FlightGlobals.ActiveVessel), FlightGlobals.currentMainBody, CurrentBiome(baseExperiment.experiment)); + string currentBiome = CurrentBiome(baseExperiment.experiment); + return ResearchAndDevelopment.GetExperimentSubject(baseExperiment.experiment, ScienceUtil.GetExperimentSituation(FlightGlobals.ActiveVessel), FlightGlobals.currentMainBody, currentBiome, ScienceUtil.GetBiomedisplayName(FlightGlobals.currentMainBody, currentBiome)); } public float GetScienceValue(ModuleScienceExperiment baseExperiment, Dictionary shipCotainsExperiments, ScienceSubject currentScienceSubject) @@ -131,9 +131,15 @@ public void Reset(ModuleScienceExperiment baseExperiment) baseExperiment.ResetExperiment(); } - public bool CanTransfer(ModuleScienceExperiment baseExperiment, ModuleScienceContainer moduleScienceContainer) + public bool CanTransfer(ModuleScienceExperiment baseExperiment, IScienceDataContainer moduleScienceContainer) { _AutomatedScienceSamplerInstance.Log(baseExperiment.experimentID, ": CanTransfer"); + + if (moduleScienceContainer == baseExperiment as IScienceDataContainer) + {//no point in transfering to the same container + _AutomatedScienceSamplerInstance.Log(baseExperiment.experimentID, ": Experiment is same as Container ", baseExperiment.GetScienceCount()); + return false; + } if (baseExperiment.GetScienceCount() == 0) { _AutomatedScienceSamplerInstance.Log(baseExperiment.experimentID, ": Experiment has no data skiping transfer ", baseExperiment.GetScienceCount()); @@ -162,10 +168,10 @@ public bool CanTransfer(ModuleScienceExperiment baseExperiment, ModuleScienceCon return true; } - public void Transfer(ModuleScienceExperiment baseExperiment, ModuleScienceContainer moduleScienceContainer) + public void Transfer(ModuleScienceExperiment baseExperiment, IScienceDataContainer moduleScienceContainer) { _AutomatedScienceSamplerInstance.Log(baseExperiment.experimentID, ": transfering"); - moduleScienceContainer.StoreData(new List() { baseExperiment }, _AutomatedScienceSamplerInstance.craftSettings.dumpDuplicates); + moduleScienceContainer.StoreData(baseExperiment, _AutomatedScienceSamplerInstance.craftSettings.dumpDuplicates); } private string CurrentBiome(ScienceExperiment baseExperiment) diff --git a/source/AutomatedScienceSampler/IScienceActivator.cs b/source/AutomatedScienceSampler/IScienceActivator.cs index 1510afa..80b3a65 100644 --- a/source/AutomatedScienceSampler/IScienceActivator.cs +++ b/source/AutomatedScienceSampler/IScienceActivator.cs @@ -22,8 +22,8 @@ public interface IScienceActivator void Reset(ModuleScienceExperiment baseExperimentModule); - bool CanTransfer(ModuleScienceExperiment baseExperimentModule, ModuleScienceContainer moduleScienceContainer); + bool CanTransfer(ModuleScienceExperiment baseExperimentModule, IScienceDataContainer moduleScienceContainer); - void Transfer(ModuleScienceExperiment baseExperimentModule, ModuleScienceContainer moduleScienceContainer); + void Transfer(ModuleScienceExperiment baseExperimentModule, IScienceDataContainer moduleScienceContainer); } } \ No newline at end of file diff --git a/source/AutomatedScienceSampler/Properties/AssemblyInfo.cs b/source/AutomatedScienceSampler/Properties/AssemblyInfo.cs index 8b56c81..418376e 100644 --- a/source/AutomatedScienceSampler/Properties/AssemblyInfo.cs +++ b/source/AutomatedScienceSampler/Properties/AssemblyInfo.cs @@ -31,5 +31,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.3.2")] +[assembly: AssemblyVersion("1.3.3")] //[assembly: AssemblyFileVersion("0.26.1.0")] \ No newline at end of file diff --git a/source/Plugins/DMModuleScienceAnimateGeneric/Activator.cs b/source/Plugins/DMModuleScienceAnimateGeneric/Activator.cs index b2a4d50..b60eacb 100644 --- a/source/Plugins/DMModuleScienceAnimateGeneric/Activator.cs +++ b/source/Plugins/DMModuleScienceAnimateGeneric/Activator.cs @@ -62,8 +62,8 @@ public ScienceSubject GetScienceSubject(ModuleScienceExperiment baseExperiment) { ExperimentSituations situation = ScienceUtil.GetExperimentSituation(FlightGlobals.ActiveVessel); var biome = currentExperiment.getBiome(situation); - _AutomatedScienceSamplerInstance.Log(biome, "_", situation, "_", ResearchAndDevelopment.GetExperimentSubject(ResearchAndDevelopment.GetExperiment(currentExperiment.experimentID), situation, FlightGlobals.currentMainBody, biome) == null); - return ResearchAndDevelopment.GetExperimentSubject(ResearchAndDevelopment.GetExperiment(currentExperiment.experimentID), situation, FlightGlobals.currentMainBody, biome); + _AutomatedScienceSamplerInstance.Log(biome, "_", situation, "_", ResearchAndDevelopment.GetExperimentSubject(ResearchAndDevelopment.GetExperiment(currentExperiment.experimentID), situation, FlightGlobals.currentMainBody, biome, ScienceUtil.GetBiomedisplayName(FlightGlobals.currentMainBody, biome)) == null); + return ResearchAndDevelopment.GetExperimentSubject(ResearchAndDevelopment.GetExperiment(currentExperiment.experimentID), situation, FlightGlobals.currentMainBody, biome, ScienceUtil.GetBiomedisplayName(FlightGlobals.currentMainBody, biome)); } } @@ -121,7 +121,7 @@ public void Reset(ModuleScienceExperiment baseExperiment) currentExperiment.ResetExperiment(); } - public bool CanTransfer(ModuleScienceExperiment baseExperiment, ModuleScienceContainer moduleScienceContainer) + public bool CanTransfer(ModuleScienceExperiment baseExperiment, IScienceDataContainer moduleScienceContainer) { var currentExperiment = baseExperiment as DMModuleScienceAnimateGeneric.DMModuleScienceAnimateGeneric; if ((currentExperiment as IScienceDataContainer).GetScienceCount() == 0) @@ -152,11 +152,11 @@ public bool CanTransfer(ModuleScienceExperiment baseExperiment, ModuleScienceCon return true; } - public void Transfer(ModuleScienceExperiment baseExperiment, ModuleScienceContainer moduleScienceContainer) + public void Transfer(ModuleScienceExperiment baseExperiment, IScienceDataContainer moduleScienceContainer) { var currentExperiment = baseExperiment as DMModuleScienceAnimateGeneric.DMModuleScienceAnimateGeneric; _AutomatedScienceSamplerInstance.Log(currentExperiment.experimentID, ": transfering"); - moduleScienceContainer.StoreData(new List() { currentExperiment as DMModuleScienceAnimateGeneric.DMModuleScienceAnimateGeneric }, _AutomatedScienceSamplerInstance.craftSettings.dumpDuplicates); + moduleScienceContainer.StoreData(currentExperiment as DMModuleScienceAnimateGeneric.DMModuleScienceAnimateGeneric, _AutomatedScienceSamplerInstance.craftSettings.dumpDuplicates); } public List GetValidTypes() diff --git a/source/Plugins/DMModuleScienceAnimateGeneric/Properties/AssemblyInfo.cs b/source/Plugins/DMModuleScienceAnimateGeneric/Properties/AssemblyInfo.cs index 7633120..ab6741a 100644 --- a/source/Plugins/DMModuleScienceAnimateGeneric/Properties/AssemblyInfo.cs +++ b/source/Plugins/DMModuleScienceAnimateGeneric/Properties/AssemblyInfo.cs @@ -31,5 +31,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.3.1")] +[assembly: AssemblyVersion("1.3.3")] //[assembly: AssemblyFileVersion("0.26.1.0")] \ No newline at end of file diff --git a/source/Plugins/DMagic Orbital Science/Activator.cs b/source/Plugins/DMagic Orbital Science/Activator.cs index 53837ae..b079b28 100644 --- a/source/Plugins/DMagic Orbital Science/Activator.cs +++ b/source/Plugins/DMagic Orbital Science/Activator.cs @@ -78,7 +78,7 @@ public ScienceSubject GetScienceSubject(ModuleScienceExperiment baseExperiment) return null; } //_AutomatedScienceSamplerInstance.Log(ResearchAndDevelopment.GetExperiment(currentExperiment.experimentID) == null, FlightGlobals.currentMainBody == null, biome == null); - var scienceSubject = ResearchAndDevelopment.GetExperimentSubject(ResearchAndDevelopment.GetExperiment(currentExperiment.experimentID), situation, FlightGlobals.currentMainBody, biome); + var scienceSubject = ResearchAndDevelopment.GetExperimentSubject(ResearchAndDevelopment.GetExperiment(currentExperiment.experimentID), situation, FlightGlobals.currentMainBody, biome, ScienceUtil.GetBiomedisplayName(FlightGlobals.currentMainBody, biome)); _AutomatedScienceSamplerInstance.Log(biome, "_", situation, "_", scienceSubject == null); return scienceSubject; } @@ -146,7 +146,7 @@ public void Reset(ModuleScienceExperiment baseExperiment) currentExperiment.ResetExperiment(); } - public bool CanTransfer(ModuleScienceExperiment baseExperiment, ModuleScienceContainer moduleScienceContainer) + public bool CanTransfer(ModuleScienceExperiment baseExperiment, IScienceDataContainer moduleScienceContainer) { var currentExperiment = baseExperiment as DMModuleScienceAnimate; if ((currentExperiment as IScienceDataContainer).GetScienceCount() == 0) @@ -177,11 +177,11 @@ public bool CanTransfer(ModuleScienceExperiment baseExperiment, ModuleScienceCon return true; } - public void Transfer(ModuleScienceExperiment baseExperiment, ModuleScienceContainer moduleScienceContainer) + public void Transfer(ModuleScienceExperiment baseExperiment, IScienceDataContainer moduleScienceContainer) { var currentExperiment = baseExperiment as DMModuleScienceAnimate; _AutomatedScienceSamplerInstance.Log(currentExperiment.experimentID, ": transfering"); - moduleScienceContainer.StoreData(new List() { currentExperiment as DMModuleScienceAnimate }, _AutomatedScienceSamplerInstance.craftSettings.dumpDuplicates); + moduleScienceContainer.StoreData(currentExperiment as DMModuleScienceAnimate , _AutomatedScienceSamplerInstance.craftSettings.dumpDuplicates); } public List GetValidTypes() diff --git a/source/Plugins/DMagic Orbital Science/Properties/AssemblyInfo.cs b/source/Plugins/DMagic Orbital Science/Properties/AssemblyInfo.cs index b0a8776..0615477 100644 --- a/source/Plugins/DMagic Orbital Science/Properties/AssemblyInfo.cs +++ b/source/Plugins/DMagic Orbital Science/Properties/AssemblyInfo.cs @@ -31,5 +31,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.3.2")] +[assembly: AssemblyVersion("1.3.3")] //[assembly: AssemblyFileVersion("0.26.1.0")] \ No newline at end of file diff --git a/source/Plugins/Station Science/Activator.cs b/source/Plugins/Station Science/Activator.cs index a1fe22d..46b8012 100644 --- a/source/Plugins/Station Science/Activator.cs +++ b/source/Plugins/Station Science/Activator.cs @@ -86,7 +86,8 @@ public void DeployExperiment(ModuleScienceExperiment baseExperiment) public ScienceSubject GetScienceSubject(ModuleScienceExperiment baseExperiment) { //experiment.BiomeIsRelevantWhile - return ResearchAndDevelopment.GetExperimentSubject(baseExperiment.experiment, ScienceUtil.GetExperimentSituation(FlightGlobals.ActiveVessel), FlightGlobals.currentMainBody, CurrentBiome(baseExperiment.experiment)); + string biome = CurrentBiome(baseExperiment.experiment); + return ResearchAndDevelopment.GetExperimentSubject(baseExperiment.experiment, ScienceUtil.GetExperimentSituation(FlightGlobals.ActiveVessel), FlightGlobals.currentMainBody, biome, ScienceUtil.GetBiomedisplayName(FlightGlobals.currentMainBody, biome)); } public float GetScienceValue(ModuleScienceExperiment baseExperiment, Dictionary shipCotainsExperiments, ScienceSubject currentScienceSubject) @@ -141,7 +142,7 @@ public void Reset(ModuleScienceExperiment baseExperiment) baseExperiment.ResetExperiment(); } - public bool CanTransfer(ModuleScienceExperiment baseExperiment, ModuleScienceContainer moduleScienceContainer) + public bool CanTransfer(ModuleScienceExperiment baseExperiment, IScienceDataContainer moduleScienceContainer) { if (baseExperiment.GetScienceCount() == 0) { @@ -171,10 +172,10 @@ public bool CanTransfer(ModuleScienceExperiment baseExperiment, ModuleScienceCon return true; } - public void Transfer(ModuleScienceExperiment baseExperiment, ModuleScienceContainer moduleScienceContainer) + public void Transfer(ModuleScienceExperiment baseExperiment, IScienceDataContainer moduleScienceContainer) { _AutomatedScienceSamplerInstance.Log(baseExperiment.experimentID, ": transfering"); - moduleScienceContainer.StoreData(new List() { baseExperiment }, _AutomatedScienceSamplerInstance.craftSettings.dumpDuplicates); + moduleScienceContainer.StoreData(baseExperiment , _AutomatedScienceSamplerInstance.craftSettings.dumpDuplicates); } private string CurrentBiome(ScienceExperiment baseExperiment) diff --git a/source/Plugins/Station Science/Properties/AssemblyInfo.cs b/source/Plugins/Station Science/Properties/AssemblyInfo.cs index 35aa677..1dcb357 100644 --- a/source/Plugins/Station Science/Properties/AssemblyInfo.cs +++ b/source/Plugins/Station Science/Properties/AssemblyInfo.cs @@ -31,5 +31,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.3.1")] +[assembly: AssemblyVersion("1.3.3")] //[assembly: AssemblyFileVersion("0.26.1.0")] \ No newline at end of file