diff --git a/GameData/DMagicOrbitalScience/Change Log.txt b/GameData/DMagicOrbitalScience/Change Log.txt index f56c350..b307117 100644 --- a/GameData/DMagicOrbitalScience/Change Log.txt +++ b/GameData/DMagicOrbitalScience/Change Log.txt @@ -1,4 +1,26 @@ -v1.3.2 +v1.3.3 +- Update for KSP 1.2 + +- Add data transfer function to all parts +- Support CommNet + - Experiments respect CommNet antenna selection + - SIGINT dish works as a long range Direct transmitter +- Detect new anomaly types +- Add KerbNet Modules + - Terrain for Basic Orbital Telescope + - Terrain, Biomes and Anomalies for the Imaging Platform + - Terrain and Anomalies for the Recon Telescopes + +- Fixed error with out-of-power data return to recon telescopes +- Add toggle for asteroid scanner targetting line +- Add support for Science Relay data transmission +- Fix some error with asteroid science values not taking the Science multiplier into account +- Fix some errors with recon contract orbits +- Remove EC usage from Universal Storage environmental sensors +- Support new SCANsat EC usage +- Various KSP 1.2-related updates and bug fixes + +v1.3.2 - Fixes a bug related to recon contracts v1.3.1 diff --git a/GameData/DMagicOrbitalScience/DMagicOrbitalScience.version b/GameData/DMagicOrbitalScience/DMagicOrbitalScience.version index 0671d77..86d5371 100644 --- a/GameData/DMagicOrbitalScience/DMagicOrbitalScience.version +++ b/GameData/DMagicOrbitalScience/DMagicOrbitalScience.version @@ -1,7 +1,7 @@ { "NAME":"DMagic Orbital Science", "URL":"https://raw.githubusercontent.com/DMagic1/Orbital-Science/master/GameData/DMagicOrbitalScience/DMagicOrbitalScience.version", - "DOWNLOAD":"https://spacedock.info/mod/128/DMagic%20Orbital%20Science/download/1.3.2", + "DOWNLOAD":"https://spacedock.info/mod/128/DMagic%20Orbital%20Science/download/1.3.3", "GITHUB":{ "USERNAME":"DMagic1", "REPOSITORY":"Orbital-Science", @@ -11,21 +11,21 @@ "MAJOR":1, "MINOR":3, "PATCH":0, - "BUILD":2 + "BUILD":3 }, "KSP_VERSION":{ "MAJOR":1, - "MINOR":1, - "PATCH":3 + "MINOR":2, + "PATCH":0 }, "KSP_VERSION_MIN":{ "MAJOR":1, - "MINOR":1, - "PATCH":3 + "MINOR":2, + "PATCH":0 }, "KSP_VERSION_MAX":{ "MAJOR":1, - "MINOR":1, - "PATCH":3 + "MINOR":2, + "PATCH":0 } } diff --git a/GameData/DMagicOrbitalScience/OversizeScience/LargeRecon.cfg b/GameData/DMagicOrbitalScience/OversizeScience/LargeRecon.cfg index e3191a8..52ba709 100644 --- a/GameData/DMagicOrbitalScience/OversizeScience/LargeRecon.cfg +++ b/GameData/DMagicOrbitalScience/OversizeScience/LargeRecon.cfg @@ -53,6 +53,18 @@ dragModelType = default maximum_drag = 0.2 minimum_drag = 0.2 +MODULE +{ + name = ModuleKerbNetAccess + MinimumFoV = 5 + MaximumFoV = 80 + AnomalyDetection = 0.8 + DISPLAY_MODES + { + Mode = Terrain + } +} + MODULE { name = DMReconScope diff --git a/GameData/DMagicOrbitalScience/OversizeScience/SIGINT.cfg b/GameData/DMagicOrbitalScience/OversizeScience/SIGINT.cfg index faf0b16..820a1ff 100644 --- a/GameData/DMagicOrbitalScience/OversizeScience/SIGINT.cfg +++ b/GameData/DMagicOrbitalScience/OversizeScience/SIGINT.cfg @@ -108,10 +108,13 @@ DRAG_CUBE MODULE { name = ModuleDataTransmitter + antennaType = DIRECT packetInterval = 0.08 packetSize = 4 packetResourceCost = 55.0 requiredResource = ElectricCharge DeployFxModules = 0 + antennaPower = 1000000000000 + antennaCombinable = False } } diff --git a/GameData/DMagicOrbitalScience/OversizeScience/SIGINT_End.cfg b/GameData/DMagicOrbitalScience/OversizeScience/SIGINT_End.cfg index 082f7ce..442000c 100644 --- a/GameData/DMagicOrbitalScience/OversizeScience/SIGINT_End.cfg +++ b/GameData/DMagicOrbitalScience/OversizeScience/SIGINT_End.cfg @@ -107,11 +107,14 @@ DRAG_CUBE MODULE { name = ModuleDataTransmitter + antennaType = DIRECT packetInterval = 0.08 packetSize = 4 packetResourceCost = 55.0 requiredResource = ElectricCharge DeployFxModules = 0 + antennaPower = 1000000000000 + antennaCombinable = False } MODULE diff --git a/GameData/DMagicOrbitalScience/OversizeScience/SIGINT_Small.cfg b/GameData/DMagicOrbitalScience/OversizeScience/SIGINT_Small.cfg index 7adaab0..b103504 100644 --- a/GameData/DMagicOrbitalScience/OversizeScience/SIGINT_Small.cfg +++ b/GameData/DMagicOrbitalScience/OversizeScience/SIGINT_Small.cfg @@ -110,10 +110,13 @@ DRAG_CUBE MODULE { name = ModuleDataTransmitter + antennaType = DIRECT packetInterval = 0.1 packetSize = 2 packetResourceCost = 20.0 requiredResource = ElectricCharge DeployFxModules = 0 + antennaPower = 10000000000 + antennaCombinable = False } } diff --git a/GameData/DMagicOrbitalScience/OversizeScience/SmallRecon.cfg b/GameData/DMagicOrbitalScience/OversizeScience/SmallRecon.cfg index 347464c..4c11aa8 100644 --- a/GameData/DMagicOrbitalScience/OversizeScience/SmallRecon.cfg +++ b/GameData/DMagicOrbitalScience/OversizeScience/SmallRecon.cfg @@ -53,6 +53,18 @@ dragModelType = default maximum_drag = 0.2 minimum_drag = 0.2 +MODULE +{ + name = ModuleKerbNetAccess + MinimumFoV = 8 + MaximumFoV = 60 + AnomalyDetection = 0.4 + DISPLAY_MODES + { + Mode = Terrain + } +} + MODULE { name = DMReconScope diff --git a/GameData/DMagicOrbitalScience/ProbeScience/ImagingPlatform/ImagingPlatform.cfg b/GameData/DMagicOrbitalScience/ProbeScience/ImagingPlatform/ImagingPlatform.cfg index 749edf3..c46a573 100644 --- a/GameData/DMagicOrbitalScience/ProbeScience/ImagingPlatform/ImagingPlatform.cfg +++ b/GameData/DMagicOrbitalScience/ProbeScience/ImagingPlatform/ImagingPlatform.cfg @@ -46,7 +46,15 @@ MODULE MODULE { - name = ModuleHighDefCamera + name = ModuleKerbNetAccess + MinimumFoV = 30 + MaximumFoV = 65 + AnomalyDetection = 0.35 + DISPLAY_MODES + { + Mode = Biome + Mode = Terrain + } } MODULE diff --git a/GameData/DMagicOrbitalScience/ProbeScience/Scope/Scope.cfg b/GameData/DMagicOrbitalScience/ProbeScience/Scope/Scope.cfg index 4e2aeec..6607a0c 100644 --- a/GameData/DMagicOrbitalScience/ProbeScience/Scope/Scope.cfg +++ b/GameData/DMagicOrbitalScience/ProbeScience/Scope/Scope.cfg @@ -41,6 +41,17 @@ dragModelType = default maximum_drag = 0.2 minimum_drag = 0.2 +MODULE + { + name = ModuleKerbNetAccess + MinimumFoV = 15 + MaximumFoV = 35 + AnomalyDetection = 0 + DISPLAY_MODES + { + Mode = Terrain + } + } MODULE { diff --git a/GameData/DMagicOrbitalScience/Resources/DMagicSCANsatScanner.cfg b/GameData/DMagicOrbitalScience/Resources/DMagicSCANsatScanner.cfg index 24196ab..bce5ab5 100644 --- a/GameData/DMagicOrbitalScience/Resources/DMagicSCANsatScanner.cfg +++ b/GameData/DMagicOrbitalScience/Resources/DMagicSCANsatScanner.cfg @@ -13,8 +13,12 @@ Magnetometer Ore Scanner min_alt = 30000 max_alt = 60000 best_alt = 50000 - power = 0.75 scanName = Ore scan + RESOURCE + { + name = ElectricCharge + rate = 0.5 + } } MODULE @@ -38,8 +42,12 @@ Universal Storage Magnetometer Ore Scanner min_alt = 30000 max_alt = 60000 best_alt = 50000 - power = 0.75 scanName = Ore scan + RESOURCE + { + name = ElectricCharge + rate = 0.5 + } } MODULE @@ -63,8 +71,12 @@ Universal Storage Magnetometer Ore Scanner min_alt = 5000 max_alt = 500000 best_alt = 250000 - power = 1.5 scanName = Multi-Spectral scan + RESOURCE + { + name = ElectricCharge + rate = 1.5 + } } } @@ -91,8 +103,12 @@ Universal Storage Magnetometer Ore Scanner min_alt = 50000 max_alt = 300000 best_alt = 200000 - power = 1.0 scanName = Minerals scan + RESOURCE + { + name = ElectricCharge + rate = 0.5 + } } MODULE @@ -116,8 +132,12 @@ Universal Storage Magnetometer Ore Scanner min_alt = 5000 max_alt = 500000 best_alt = 250000 - power = 1.5 scanName = Multi-Spectral scan + RESOURCE + { + name = ElectricCharge + rate = 1.5 + } } } @@ -144,8 +164,12 @@ Universal Storage Magnetometer Ore Scanner min_alt = 50000 max_alt = 300000 best_alt = 200000 - power = 1.0 scanName = Minerals scan + RESOURCE + { + name = ElectricCharge + rate = 0.5 + } } MODULE @@ -196,8 +220,12 @@ Soil Moisture Resource and SCANsat Water Scanner min_alt = 50000 max_alt = 500000 best_alt = 250000 - power = 1.5 scanName = Water scan + RESOURCE + { + name = ElectricCharge + rate = 1.0 + } } MODULE @@ -248,8 +276,12 @@ Universal Storage Soil Moisture Resource and SCANsat Water Scanner min_alt = 50000 max_alt = 500000 best_alt = 250000 - power = 1.5 scanName = Water scan + RESOURCE + { + name = ElectricCharge + rate = 1.0 + } } MODULE @@ -273,7 +305,11 @@ Universal Storage Soil Moisture Resource and SCANsat Water Scanner min_alt = 0 max_alt = 2000 best_alt = 0 - power = 0.1 scanName = BTDT scan + RESOURCE + { + name = ElectricCharge + rate = 0.1 + } } } \ No newline at end of file diff --git a/GameData/DMagicOrbitalScience/Resources/dmorbitalsci.ksp b/GameData/DMagicOrbitalScience/Resources/dmorbitalsci.ksp new file mode 100644 index 0000000..d36225a Binary files /dev/null and b/GameData/DMagicOrbitalScience/Resources/dmorbitalsci.ksp differ diff --git a/GameData/DMagicOrbitalScience/UniversalStorage/USImagingPlatform/USImagingPlatform.cfg b/GameData/DMagicOrbitalScience/UniversalStorage/USImagingPlatform/USImagingPlatform.cfg index 5a8c2cd..483d68b 100644 --- a/GameData/DMagicOrbitalScience/UniversalStorage/USImagingPlatform/USImagingPlatform.cfg +++ b/GameData/DMagicOrbitalScience/UniversalStorage/USImagingPlatform/USImagingPlatform.cfg @@ -59,7 +59,15 @@ MODULE MODULE { - name = ModuleHighDefCamera + name = ModuleKerbNetAccess + MinimumFoV = 30 + MaximumFoV = 65 + AnomalyDetection = 0.35 + DISPLAY_MODES + { + Mode = Biome + Mode = Terrain + } } MODULE diff --git a/GameData/DMagicOrbitalScience/UniversalStorage/USScope/USScope.cfg b/GameData/DMagicOrbitalScience/UniversalStorage/USScope/USScope.cfg index 69913fe..b8eae3f 100644 --- a/GameData/DMagicOrbitalScience/UniversalStorage/USScope/USScope.cfg +++ b/GameData/DMagicOrbitalScience/UniversalStorage/USScope/USScope.cfg @@ -50,6 +50,17 @@ tags = experiment research rerun re-run reus re-us redo re-do reset re-set scien angularDrag = 1 dragModelType = default +MODULE + { + name = ModuleKerbNetAccess + MinimumFoV = 15 + MaximumFoV = 35 + AnomalyDetection = 0 + DISPLAY_MODES + { + Mode = Terrain + } + } MODULE { diff --git a/GameData/DMagicOrbitalScience/UniversalStorage/USStock/ACCGRAV.cfg b/GameData/DMagicOrbitalScience/UniversalStorage/USStock/ACCGRAV.cfg index be9e863..3036a3a 100644 --- a/GameData/DMagicOrbitalScience/UniversalStorage/USStock/ACCGRAV.cfg +++ b/GameData/DMagicOrbitalScience/UniversalStorage/USStock/ACCGRAV.cfg @@ -55,7 +55,6 @@ MODULE min = 25 max = 335 primary = True - powerConsumption = 0.2 } MODULE @@ -65,7 +64,6 @@ MODULE min = 0 max = 5 primary = False - powerConsumption = 0 } MODULE diff --git a/GameData/DMagicOrbitalScience/UniversalStorage/USStock/PRESTEMP.cfg b/GameData/DMagicOrbitalScience/UniversalStorage/USStock/PRESTEMP.cfg index ed894b6..31c95ab 100644 --- a/GameData/DMagicOrbitalScience/UniversalStorage/USStock/PRESTEMP.cfg +++ b/GameData/DMagicOrbitalScience/UniversalStorage/USStock/PRESTEMP.cfg @@ -54,7 +54,6 @@ MODULE min = 0 max = 1 primary = True - powerConsumption = 0.2 } MODULE @@ -64,7 +63,6 @@ MODULE min = 25 max = 335 primary = False - powerConsumption = 0 } MODULE diff --git a/Source/Contracts/DMMagneticSurveyContract.cs b/Source/Contracts/DMMagneticSurveyContract.cs index d7b4f01..59a5e31 100644 --- a/Source/Contracts/DMMagneticSurveyContract.cs +++ b/Source/Contracts/DMMagneticSurveyContract.cs @@ -191,7 +191,7 @@ protected override bool Generate() double inclination = incMod * ((double)rand.Next(7, 14) / 10d); if (inclination > 75) inclination = 75; - Dictionary> parts = new Dictionary>(); + DictionaryValueList> parts = new DictionaryValueList>(); parts.Add(0, DMContractDefs.DMMagnetic.magParts); parts.Add(1, DMContractDefs.DMMagnetic.rpwsParts); @@ -245,7 +245,7 @@ protected override bool Generate() this.agent = AgentList.Instance.GetAgentRandom(); base.SetExpiry(DMContractDefs.DMMagnetic.Expire.MinimumExpireDays, DMContractDefs.DMMagnetic.Expire.MaximumExpireDays); - base.SetDeadlineDays((float)(time / ((KSPUtil.DefaultDateTimeFormatter)KSPUtil.dateTimeFormatter).KerbinDay) * DMContractDefs.DMMagnetic.Expire.DeadlineModifier * (this.GetDestinationWeight(body) / 1.8f) * primaryModifier, null); + base.SetDeadlineDays((float)(time / 3600) * DMContractDefs.DMMagnetic.Expire.DeadlineModifier * (this.GetDestinationWeight(body) / 1.8f) * primaryModifier, null); base.SetReputation(DMContractDefs.DMMagnetic.Reputation.BaseReward * Mod, DMContractDefs.DMMagnetic.Reputation.BaseFailure * Mod, null); base.SetFunds(DMContractDefs.DMMagnetic.Funds.BaseAdvance * Mod, DMContractDefs.DMMagnetic.Funds.BaseReward * Mod, DMContractDefs.DMMagnetic.Funds.BaseFailure * Mod, body); base.SetScience(DMContractDefs.DMMagnetic.Science.BaseReward * Mod, body); diff --git a/Source/Contracts/DMReconContract.cs b/Source/Contracts/DMReconContract.cs index 82b356f..f6c5a62 100644 --- a/Source/Contracts/DMReconContract.cs +++ b/Source/Contracts/DMReconContract.cs @@ -121,7 +121,7 @@ protected override bool Generate() OrbitType orbitType = OrbitType.POLAR; - Dictionary> parts = new Dictionary>(); + DictionaryValueList> parts = new DictionaryValueList>(); Orbit o = new Orbit(); double incMod = (rand.NextDouble() * 10) - 5; @@ -270,7 +270,7 @@ protected override bool Generate() this.agent = AgentList.Instance.GetAgentRandom(); base.SetExpiry(DMContractDefs.DMRecon.Expire.MinimumExpireDays, DMContractDefs.DMRecon.Expire.MaximumExpireDays); - base.SetDeadlineDays((float)(time / ((KSPUtil.DefaultDateTimeFormatter)KSPUtil.dateTimeFormatter).KerbinDay) * DMContractDefs.DMRecon.Expire.DeadlineModifier * (this.GetDestinationWeight(body) / 1.4f) * primaryModifier, null); + base.SetDeadlineDays((float)(time / 3600) * DMContractDefs.DMRecon.Expire.DeadlineModifier * (this.GetDestinationWeight(body) / 1.4f) * primaryModifier, null); base.SetReputation(DMContractDefs.DMRecon.Reputation.BaseReward * Mod, DMContractDefs.DMRecon.Reputation.BaseFailure * Mod, null); base.SetFunds(DMContractDefs.DMRecon.Funds.BaseAdvance * Mod, DMContractDefs.DMRecon.Funds.BaseReward * Mod, DMContractDefs.DMRecon.Funds.BaseFailure * Mod, body); base.SetScience(DMContractDefs.DMRecon.Science.BaseReward * Mod, body); diff --git a/Source/DMAnomalyList.cs b/Source/DMAnomalyList.cs index a023ece..01f91e4 100644 --- a/Source/DMAnomalyList.cs +++ b/Source/DMAnomalyList.cs @@ -40,17 +40,17 @@ namespace DMagic public static class DMAnomalyList { private static bool scannerUpdating; - private static Dictionary anomalies = new Dictionary(); + private static DictionaryValueList anomalies = new DictionaryValueList(); public static void addAnomalyStorage(string body, DMAnomalyStorage anom) { - if (!anomalies.ContainsKey(body)) + if (!anomalies.Contains(body)) anomalies.Add(body, anom); } public static DMAnomalyObject getAnomalyObject(string body, string city) { - if (!anomalies.ContainsKey(body)) + if (!anomalies.Contains(body)) { DMUtils.Logging("No anomaly of name [{0}] found for body [{1}]", city, body); return null; @@ -62,14 +62,14 @@ public static DMAnomalyObject getAnomalyObject(string body, string city) public static DMAnomalyStorage getAnomalyStorage(int index) { if (anomalies.Count > index) - return anomalies.ElementAt(index).Value; + return anomalies.At(index); return null; } public static DMAnomalyStorage getAnomalyStorage(string body) { - if (anomalies.ContainsKey(body)) + if (anomalies.Contains(body)) return anomalies[body]; return null; @@ -99,7 +99,7 @@ public static List getScannedBodies for (int i = 0; i < anomalies.Count; i++) { - CelestialBody c = FlightGlobals.Bodies.FirstOrDefault(a => a.name == anomalies.ElementAt(i).Key); + CelestialBody c = FlightGlobals.Bodies.FirstOrDefault(a => a.name == anomalies.At(i).Body.bodyName); if (c == null) continue; @@ -113,7 +113,7 @@ public static List getScannedBodies public static void updateCoordinates(CelestialBody b) { - if (anomalies.ContainsKey(b.name)) + if (anomalies.Contains(b.name)) { for (int i = 0; i < anomalies[b.name].AnomalyCount; i++) { diff --git a/Source/DMAnomalyObject.cs b/Source/DMAnomalyObject.cs index 5d2f942..7a401d3 100644 --- a/Source/DMAnomalyObject.cs +++ b/Source/DMAnomalyObject.cs @@ -44,9 +44,9 @@ public class DMAnomalyObject private double bearing; private string name; - public DMAnomalyObject(PQSCity City) + public DMAnomalyObject(PQSSurfaceObject City) { - name = City.name; + name = City.SurfaceObjectName; try { body = FlightGlobals.Bodies.FirstOrDefault(b => b.name == City.transform.parent.name); diff --git a/Source/DMAnomalyStorage.cs b/Source/DMAnomalyStorage.cs index 67b29ae..231789f 100644 --- a/Source/DMAnomalyStorage.cs +++ b/Source/DMAnomalyStorage.cs @@ -42,7 +42,7 @@ public class DMAnomalyStorage private CelestialBody body; private bool scanned; private float level; - private Dictionary anomalies = new Dictionary(); + private DictionaryValueList anomalies = new DictionaryValueList(); public DMAnomalyStorage(CelestialBody b, bool s = true) { @@ -53,7 +53,7 @@ public DMAnomalyStorage(CelestialBody b, bool s = true) public void addAnomaly(DMAnomalyObject anom) { - if (!anomalies.ContainsKey(anom.Name)) + if (!anomalies.Contains(anom.Name)) anomalies.Add(anom.Name, anom); } @@ -64,11 +64,11 @@ public bool scanBody() if (body.pqsController == null) return false; - PQSCity[] Cities = body.pqsController.GetComponentsInChildren(); + PQSSurfaceObject[] Cities = body.pqsSurfaceObjects; for (int i = 0; i < Cities.Length; i++) { - PQSCity city = Cities[i]; + PQSSurfaceObject city = Cities[i]; if (city == null) continue; @@ -86,7 +86,7 @@ public bool scanBody() public DMAnomalyObject getAnomaly(string name) { - if (anomalies.ContainsKey(name)) + if (anomalies.Contains(name)) return anomalies[name]; return null; @@ -95,7 +95,7 @@ public DMAnomalyObject getAnomaly(string name) public DMAnomalyObject getAnomaly(int index) { if (anomalies.Count > index) - return anomalies.ElementAt(index).Value; + return anomalies.At(index); return null; } diff --git a/Source/DMAsteroidScience.cs b/Source/DMAsteroidScience.cs index ab28254..ba2ef4b 100644 --- a/Source/DMAsteroidScience.cs +++ b/Source/DMAsteroidScience.cs @@ -192,16 +192,13 @@ public static bool AsteroidNear { get { - for (int i = 0; i < FlightGlobals.Vessels.Count; i++) + for (int i = FlightGlobals.VesselsLoaded.Count - 1; i >= 0; i--) { - Vessel v = FlightGlobals.Vessels[i]; + Vessel v = FlightGlobals.VesselsLoaded[i]; if (v == null) continue; - if (!v.loaded) - continue; - if (v == FlightGlobals.ActiveVessel) continue; diff --git a/Source/DMExtensions.cs b/Source/DMExtensions.cs index b46a24a..c3b34d3 100644 --- a/Source/DMExtensions.cs +++ b/Source/DMExtensions.cs @@ -233,6 +233,38 @@ public static List parse(this ConfigNode node, string name, List ori } } + public static List parse(this string name, List original) + { + if (string.IsNullOrEmpty(name)) + return original; + else + { + List ids = new List(); + + string[] sA = name.Split('|'); + for (int i = 0; i < sA.Length; i++) + { + try + { + Guid g = new Guid(sA[i]); + + if (g == null) + continue; + + if (!ids.Contains(g)) + ids.Add(g); + } + catch (Exception e) + { + DMUtils.Logging("Guid invalid:\n{0}", e); + continue; + } + } + + return ids; + } + } + public static Vessel parse(this ConfigNode node, string name, Vessel original) { if (!node.HasValue(name)) diff --git a/Source/DMSeismicHandler.cs b/Source/DMSeismicHandler.cs index 7fc8be6..8b129d3 100644 --- a/Source/DMSeismicHandler.cs +++ b/Source/DMSeismicHandler.cs @@ -93,7 +93,7 @@ private IEnumerator loadSensors() while (!FlightGlobals.ready) yield return null; - for (int i = 0; i < FlightGlobals.Vessels.Count; i++) + for (int i = FlightGlobals.Vessels.Count - 1; i >= 0; i--) { Vessel v = FlightGlobals.Vessels[i]; @@ -411,7 +411,7 @@ public static ScienceData makeData(DMSeismometerValues sensor, float score, Scie sub.title = exp.experimentTitle + string.Format(" from {0}'s {1}", body.theName, biome); } - return new ScienceData(science, 1f, v.VesselValues.ScienceReturn.value, sub.id, sub.title, false, sensor.ID); + return new ScienceData(science, 1f, 0, sub.id, sub.title, false, sensor.ID); } private static void registerDMScience(DMAsteroidScience newAst, ScienceExperiment exp, ScienceSubject sub) diff --git a/Source/DMUtils.cs b/Source/DMUtils.cs index 385d116..73e12ba 100644 --- a/Source/DMUtils.cs +++ b/Source/DMUtils.cs @@ -99,7 +99,7 @@ internal static string stringConcat(List source) return string.Concat(s).TrimEnd('|'); } - internal static string stringConcat(Dictionary> source) + internal static string stringConcat(DictionaryValueList> source) { if (source.Count == 0) return ""; @@ -107,7 +107,7 @@ internal static string stringConcat(Dictionary> source) string[] result = new string[source.Count]; for (int i = 0; i < source.Count; i++) { - List group = source.ElementAt(i).Value; + List group = source.At(i); if (group.Count == 0) { @@ -146,9 +146,9 @@ internal static List formatFixStringList(List source) return fixedList; } - internal static Dictionary> stringSplit(string source) + internal static DictionaryValueList> stringSplit(string source) { - Dictionary> result = new Dictionary>(); + DictionaryValueList> result = new DictionaryValueList>(); string[] groups = source.Split('|'); @@ -285,10 +285,8 @@ internal static double bearing(double lat1, double lon1, double lat2, double lon internal static double timeInDays(double D) { - if (GameSettings.KERBIN_TIME) - D /= ((KSPUtil.DefaultDateTimeFormatter)KSPUtil.dateTimeFormatter).KerbinDay; - else - D /= ((KSPUtil.DefaultDateTimeFormatter)KSPUtil.dateTimeFormatter).EarthDay; + D /= KSPUtil.dateTimeFormatter.Day; + return D; } diff --git a/Source/DMagicOrbital.csproj b/Source/DMagicOrbital.csproj index e91cfcd..cff9b7b 100644 --- a/Source/DMagicOrbital.csproj +++ b/Source/DMagicOrbital.csproj @@ -39,24 +39,16 @@ - ..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Kerbal Space Program\KSP_x64_Data\Managed\Assembly-CSharp.dll - False - - - ..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Kerbal Space Program\KSP_x64_Data\Managed\Assembly-CSharp-firstpass.dll - False - - - ..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Kerbal Space Program\KSP_x64_Data\Managed\KSPUtil.dll + ..\..\KSP Dev\Kerbal Space Program\KSP_x64_Data\Managed\Assembly-CSharp.dll False - ..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Kerbal Space Program\KSP_x64_Data\Managed\UnityEngine.dll + ..\..\KSP Dev\Kerbal Space Program\KSP_x64_Data\Managed\UnityEngine.dll False - ..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Kerbal Space Program\KSP_x64_Data\Managed\UnityEngine.UI.dll + ..\..\KSP Dev\Kerbal Space Program\KSP_x64_Data\Managed\UnityEngine.UI.dll False diff --git a/Source/Parameters/DMPartRequestParameter.cs b/Source/Parameters/DMPartRequestParameter.cs index 593984c..7675678 100644 --- a/Source/Parameters/DMPartRequestParameter.cs +++ b/Source/Parameters/DMPartRequestParameter.cs @@ -44,9 +44,9 @@ namespace DMagic.Parameters { public class DMPartRequestParameter : WaypointParameter { - private Dictionary suitableVessels = new Dictionary(); - private Dictionary wps = new Dictionary(); - private Dictionary> requiredParts = new Dictionary>(); + private DictionaryValueList suitableVessels = new DictionaryValueList(); + private DictionaryValueList wps = new DictionaryValueList(); + private DictionaryValueList> requiredParts = new DictionaryValueList>(); private List partTitles = new List(); private string vesselNames; private bool updatingVesselState; @@ -56,7 +56,7 @@ public class DMPartRequestParameter : WaypointParameter public DMPartRequestParameter() { } - public DMPartRequestParameter(Dictionary> parts, bool b, CelestialBody body) + public DMPartRequestParameter(DictionaryValueList> parts, bool b, CelestialBody body) { requiredParts = parts; TargetBody = body; @@ -69,7 +69,7 @@ private void getPartTitles() { for (int i = 0; i < requiredParts.Count; i++) { - string s = requiredParts.ElementAt(i).Value.FirstOrDefault(); + string s = requiredParts.At(i).FirstOrDefault(); AvailablePart aPart = PartLoader.getPartInfoByName(s); if (aPart == null) continue; @@ -85,7 +85,7 @@ public int VesselCount public Vessel getVessel(int index) { if (suitableVessels.Count > index) - return suitableVessels.ElementAt(index).Value; + return suitableVessels.At(index); return null; } @@ -203,10 +203,48 @@ protected override void OnLoad(ConfigNode node) getPartTitles(); vesselNames = node.parse("Vessels", ""); - if (!string.IsNullOrEmpty(vesselNames) && !HighLogic.LoadedSceneIsEditor && this.Root.ContractState == Contract.State.Active) - { - List ids = node.parse("Vessels", new List()); + ContractSystem.Instance.StartCoroutine(loadVessels(vesselNames)); + + //if (!string.IsNullOrEmpty(vesselNames) && !HighLogic.LoadedSceneIsEditor && this.Root.ContractState == Contract.State.Active) + //{ + + // List ids = node.parse("Vessels", new List()); + // if (ids.Count > 0) + // { + // foreach (Guid id in ids) + // { + // try + // { + // Vessel V = FlightGlobals.Vessels.FirstOrDefault(v => v.id == id); + // addVessel(V); + // DMUtils.DebugLog("Vessel {0} Loaded", V.vesselName); + // } + // catch + // { + // DMUtils.Logging("Failed To Load Vessel; DM Part Request Parameter Reset"); + // if (HighLogic.LoadedSceneIsFlight) + // { + // DMUtils.Logging("Checking If Currently Loaded Vessel Is Appropriate"); + // if (vesselEquipped(FlightGlobals.ActiveVessel, FlightGlobals.currentMainBody)) + // addVessel(FlightGlobals.ActiveVessel); + // } + // } + // } + // } + //} + + this.disableOnStateChange = false; + } + + private IEnumerator loadVessels(string vessels) + { + while (!FlightGlobals.ready && FlightGlobals.Vessels.Count <= 0) + yield return null; + + if (!HighLogic.LoadedSceneIsEditor && this.Root.ContractState == Contract.State.Active) + { + List ids = vessels.parse(new List()); if (ids.Count > 0) { foreach (Guid id in ids) @@ -230,8 +268,6 @@ protected override void OnLoad(ConfigNode node) } } } - - this.disableOnStateChange = false; } public override void UpdateWaypoints(bool focused) @@ -239,27 +275,31 @@ public override void UpdateWaypoints(bool focused) if (!useWaypoints) return; - for (int i = 0; i < wps.Count; i++) + var enumerator = wps.GetDictEnumerator(); + + while (enumerator.MoveNext()) { - var pair = wps.ElementAt(i); + var pair = enumerator.Current; + + Vessel v = pair.Key; - if (pair.Key == null) + if (v == null) continue; Waypoint wp = pair.Value; if (wp == null) { - wp = setupNewWaypoint(pair.Key); - wps[pair.Key] = wp; + wp = setupNewWaypoint(v); + wps[v] = wp; } Orbit o; - if (pair.Key.loaded) - o = pair.Key.orbit; + if (v.loaded) + o = v.orbit; else - o = pair.Key.protoVessel.orbitSnapShot.Load(); + o = v.protoVessel.orbitSnapShot.Load(); wp.celestialName = TargetBody.GetName(); wp.isOnSurface = false; @@ -317,7 +357,7 @@ private Waypoint setupNewWaypoint(Vessel v) private void removeWaypoint(Vessel v) { - if (wps.ContainsKey(v)) + if (wps.Contains(v)) { Waypoint wp = wps[v]; @@ -332,7 +372,7 @@ private void removeWaypoint(Vessel v) private void addVessel(Vessel v) { - if (!suitableVessels.ContainsKey(v.id)) + if (!suitableVessels.Contains(v.id)) suitableVessels.Add(v.id, v); else DMUtils.Logging("Vessel: [{0}] Already Included In DM Part Request List", v.name); @@ -342,14 +382,14 @@ private void addVessel(Vessel v) if (HighLogic.LoadedSceneIsFlight || HighLogic.LoadedScene == GameScenes.TRACKSTATION) { - if (!wps.ContainsKey(v)) + if (!wps.Contains(v)) wps.Add(v, setupNewWaypoint(v)); } } private void removeVessel(Vessel v) { - if (suitableVessels.ContainsKey(v.id)) + if (suitableVessels.Contains(v.id)) suitableVessels.Remove(v.id); if (!useWaypoints) @@ -365,7 +405,7 @@ private bool vesselEquipped(Vessel v, CelestialBody b) { for (int i = 0; i < requiredParts.Count; i++) { - List parts = requiredParts.ElementAt(i).Value; + List parts = requiredParts.At(i); if (parts.Count <= 0) return false; diff --git a/Source/Parameters/DMSpecificOrbitParameter.cs b/Source/Parameters/DMSpecificOrbitParameter.cs index 261cbbd..7fadb34 100644 --- a/Source/Parameters/DMSpecificOrbitParameter.cs +++ b/Source/Parameters/DMSpecificOrbitParameter.cs @@ -50,6 +50,7 @@ public class DMSpecificOrbitParameter : SpecificOrbitParameter private bool orbitTested; private DMLongOrbitParameter root; private Orbit KSCOrbit = null; + private bool loaded; public DMSpecificOrbitParameter() { } @@ -74,7 +75,8 @@ private void setupOrbit(bool ksc) if (ksc) KSCOrbit = new Orbit(inc, ecc, sma, lan, aop, mae, epo, body); else - orbitRenderer = ContractOrbitRenderer.Setup(Root, new Orbit(inc, ecc, sma, lan, aop, mae, epo, body)); + SetupRenderer(); + //orbitRenderer = ContractOrbitRenderer.Setup(Root, new Orbit(inc, ecc, sma, lan, aop, mae, epo, body)); orbitLoaded = true; } @@ -87,7 +89,7 @@ protected override void OnUpdate() if (HighLogic.LoadedSceneIsEditor) return; - if (!orbitTested) + if (!orbitTested && loaded) { setupOrbit(HighLogic.LoadedScene == GameScenes.SPACECENTER); orbitLoaded = testOrbit(HighLogic.LoadedScene == GameScenes.SPACECENTER); @@ -181,6 +183,8 @@ protected override void OnLoad(ConfigNode node) if (this.Root.ContractState == Contract.State.Active) orbitLoaded = testOrbit(HighLogic.LoadedScene == GameScenes.SPACECENTER); + + loaded = true; } private bool testOrbit(bool ksc) @@ -199,7 +203,7 @@ private bool testOrbit(bool ksc) catch (Exception e) { if (!HighLogic.LoadedSceneIsEditor) - Debug.LogError("[DM] Error detected in setting up long term recon orbit parameter; deactivating\n" + e.StackTrace); + Debug.LogError("[DM] Error detected in setting up long term recon orbit parameter; deactivating\n" + e.ToString()); return false; } } diff --git a/Source/Part Modules/DMAnomalyScanner.cs b/Source/Part Modules/DMAnomalyScanner.cs index f4d2278..ea43990 100644 --- a/Source/Part Modules/DMAnomalyScanner.cs +++ b/Source/Part Modules/DMAnomalyScanner.cs @@ -100,9 +100,11 @@ protected override void Update() spinDishDown(); } } - - new private void OnDestroy() + + protected override void OnDestroy() { + base.OnDestroy(); + DMAnomalyList.ScannerUpdating = false; if (!HighLogic.LoadedSceneIsEditor) { @@ -242,11 +244,11 @@ private void PQSloaded(CelestialBody body, string name) if (body.pqsController == null) return; - PQSCity[] Cities = body.pqsController.GetComponentsInChildren(); + PQSSurfaceObject[] Cities = body.pqsSurfaceObjects; for (int i = 0; i < Cities.Length; i++) { - PQSCity city = Cities[i]; + PQSSurfaceObject city = Cities[i]; if (city == null) continue; @@ -254,7 +256,7 @@ private void PQSloaded(CelestialBody body, string name) if (city.transform.parent.name != body.name) continue; - if (city.name != name) + if (city.SurfaceObjectName != name) continue; currentAnomaly = new DMAnomalyObject(city); @@ -499,6 +501,8 @@ internal static string anomalyCleanup(string anomName) case "Icehenge": case "Pyramid": return anomName; + case "Randolith": + return "Random Monolith"; case "IslandAirfield": return "Island Airfield"; case "KSC2": diff --git a/Source/Part Modules/DMAsteroidScanner.cs b/Source/Part Modules/DMAsteroidScanner.cs index 576d067..0f76a3d 100644 --- a/Source/Part Modules/DMAsteroidScanner.cs +++ b/Source/Part Modules/DMAsteroidScanner.cs @@ -77,6 +77,8 @@ class DMAsteroidScanner : PartModule, IScienceDataContainer public int usageReqMaskExternal = -1; [KSPField] public string usageReqMessage = ""; + [KSPField(isPersistant = true)] + public bool showLines = true; private string failMessage = ""; private string asteroidBodyNameFixed = "Eeloo"; @@ -100,11 +102,20 @@ class DMAsteroidScanner : PartModule, IScienceDataContainer private Transform dishArm; private float targetDistance = 0f; private float[] astWidth = new float[6] { 4, 8, 14, 20, 26, 40 }; + private ExperimentsResultDialog resultsDialog; + private bool hasContainer; #endregion #region PartModule + public override void OnAwake() + { + GameEvents.onGamePause.Add(onPause); + GameEvents.onGameUnpause.Add(onUnPause); + GameEvents.onVesselStandardModification.Add(onVesselModified); + } + public override void OnStart(PartModule.StartState state) { if (!string.IsNullOrEmpty(animationName)) @@ -131,6 +142,7 @@ public override void OnStart(PartModule.StartState state) if (FlightGlobals.Bodies.Count >= 17) asteroidBodyNameFixed = FlightGlobals.Bodies[16].bodyName; + findContainers(); } public override void OnSave(ConfigNode node) @@ -155,6 +167,53 @@ public override void OnLoad(ConfigNode node) } } + private void OnDestroy() + { + GameEvents.onGamePause.Remove(onPause); + GameEvents.onGameUnpause.Remove(onUnPause); + GameEvents.onVesselStandardModification.Remove(onVesselModified); + } + + private void onPause() + { + if (resultsDialog != null) + resultsDialog.gameObject.SetActive(false); + } + + private void onUnPause() + { + if (resultsDialog != null) + resultsDialog.gameObject.SetActive(true); + } + + private void onVesselModified(Vessel v) + { + if (v == vessel && HighLogic.LoadedSceneIsFlight) + findContainers(); + } + + private void findContainers() + { + for (int i = vessel.Parts.Count - 1; i >= 0; i--) + { + Part p = vessel.Parts[i]; + + if (p == null) + continue; + + if (p.State == PartStates.DEAD) + continue; + + ModuleScienceContainer container = p.FindModuleImplementing(); + + if (container == null) + continue; + + hasContainer = container.canBeTransferredToInVessel; + break; + } + } + private void Update() { if (HighLogic.LoadedSceneIsFlight) @@ -315,6 +374,8 @@ private void EventsCheck() Events["CollectDataExternalEvent"].active = scienceReports.Count > 0 && dataIsCollectable; Events["DeployExperiment"].active = scienceReports.Count == 0 && !Deployed && !Inoperable && asteroidInSight; Events["ReviewDataEvent"].active = scienceReports.Count > 0; + Events["toggleLine"].active = fullyDeployed; + Events["TransferDataEvent"].active = hasContainer && dataIsCollectable && scienceReports.Count > 0; } //Point the dish at the target @@ -340,7 +401,8 @@ private void lookAtTarget() dishArm.localRotation = Quaternion.RotateTowards(dishArm.localRotation, Quaternion.AngleAxis(angleZ, Vector3.forward), Time.deltaTime * 30f); dish.localRotation = Quaternion.RotateTowards(dish.localRotation, Quaternion.AngleAxis(angleY, Vector3.up), Time.deltaTime * 30f); - drawLine(dishBase.position, targetModule.part.transform.position, Color.red); + if (showLines) + drawLine(dishBase.position, targetModule.part.transform.position, Color.red); } private void drawLine(Vector3 start, Vector3 end, Color c) @@ -570,6 +632,12 @@ public void toggleAction(KSPActionParam param) toggleEvent(); } + [KSPEvent(guiActive = true, guiName = "Toggle Asteroid Targeting line", active = false)] + public void toggleLine() + { + showLines = !showLines; + } + [KSPEvent(guiActiveEditor = true, guiName = "Deploy Asteroid Scanner", active = true)] public void editorDeployEvent() { @@ -587,6 +655,78 @@ public void editorRetractEvent() Events["editorRetractEvent"].active = false; } + [KSPEvent(guiActive = true, guiName = "Transfer Data", active = false)] + public void TransferDataEvent() + { + if (PartItemTransfer.Instance != null) + { + ScreenMessages.PostScreenMessage("A transfer is already in progress.", 3f, ScreenMessageStyle.UPPER_CENTER); + return; + } + + ExperimentTransfer.Create(part, this, new Callback(transferData)); + } + + private void transferData(PartItemTransfer.DismissAction dismiss, Part p) + { + if (dismiss != PartItemTransfer.DismissAction.ItemMoved) + return; + + if (p == null) + return; + + if (scienceReports.Count <= 0) + { + ScreenMessages.PostScreenMessage(string.Format("[{0}]: has no data to transfer.", part.partInfo.title), 6, ScreenMessageStyle.UPPER_CENTER); + return; + } + + ModuleScienceContainer container = p.FindModuleImplementing(); + + if (container == null) + { + ScreenMessages.PostScreenMessage(string.Format("[{0}]: {1} has no data container, canceling transfer.", part.partInfo.title, p.partInfo.title), 6, ScreenMessageStyle.UPPER_CENTER); + return; + } + + if (!rerunnable) + { + List dialog = new List(); + dialog.Add(new DialogGUIButton("Remove Data", new Callback(onTransferData), container)); + dialog.Add(new DialogGUIButton("Cancel", null, true)); + + PopupDialog.SpawnPopupDialog( + new Vector2(0.5f, 0.5f), + new Vector2(0.5f, 0.5f), + new MultiOptionDialog( + "Removing the experiment data will render this module inoperable.\n\nRestoring functionality will require a Scientist.", + part.partInfo.title + "Warning!", + UISkinManager.defaultSkin, + dialog.ToArray() + ), + false, + UISkinManager.defaultSkin, + true, + "" + ); + } + else + onTransferData(container); + } + + private void onTransferData(ModuleScienceContainer target) + { + if (target == null) + return; + + int i = scienceReports.Count; + + if (target.StoreData(new List { this }, false)) + ScreenMessages.PostScreenMessage(string.Format("[{0}]: {1} Data stored.", target.part.partInfo.title, i), 6, ScreenMessageStyle.UPPER_LEFT); + else + ScreenMessages.PostScreenMessage(string.Format("[{0}]: Not all data was stored.", target.part.partInfo.title), 6, ScreenMessageStyle.UPPER_LEFT); + } + [KSPEvent(guiActive = true, guiActiveUnfocused = true, externalToEVAOnly = true, guiName = "Reset Asteroid Scanner", active = false)] public void ResetExperiment() { @@ -823,7 +963,7 @@ private ScienceData makeScience(float dist, ModuleAsteroid m) registerDMScience(ast, sub); body.bodyName = asteroidBodyNameFixed; - data = new ScienceData(multiplier * exp.baseValue * sub.dataScale, transmitValue, vessel.VesselValues.ScienceReturn.value, sub.id, dataTitle, false, part.flightID); + data = new ScienceData(multiplier * exp.baseValue * sub.dataScale, transmitValue, 0, sub.id, dataTitle, false, part.flightID); return data; } @@ -860,13 +1000,14 @@ private void experimentResultsPage(ScienceData data) { if (scienceReports.Count > 0) { - ExperimentResultDialogPage page = new ExperimentResultDialogPage(part, data, transmitValue, ModuleScienceLab.GetBoostForVesselData(vessel, data), false, "", true, new ScienceLabSearch(vessel, data), new Callback(onDiscardData), new Callback(onKeepData), new Callback(onTransmitData), new Callback(onSendToLab)); - ExperimentsResultDialog.DisplayResult(page); + ExperimentResultDialogPage page = new ExperimentResultDialogPage(part, data, data.baseTransmitValue, data.transmitBonus, false, "", true, new ScienceLabSearch(vessel, data), new Callback(onDiscardData), new Callback(onKeepData), new Callback(onTransmitData), new Callback(onSendToLab)); + resultsDialog = ExperimentsResultDialog.DisplayResult(page); } } private void onDiscardData(ScienceData data) { + resultsDialog = null; if (scienceReports.Count > 0) { scienceReports.Clear(); @@ -876,23 +1017,29 @@ private void onDiscardData(ScienceData data) private void onKeepData(ScienceData data) { + resultsDialog = null; } private void onTransmitData(ScienceData data) { - List tranList = vessel.FindPartModulesImplementing(); - if (tranList.Count > 0 && scienceReports.Count > 0) + resultsDialog = null; + + IScienceDataTransmitter bestTransmitter = ScienceUtil.GetBestTransmitter(vessel); + if (bestTransmitter != null) { - DMUtils.Logging("Sending data to vessel comms. {0} devices to choose from. Will try to pick the best one", tranList.Count); - tranList.OrderBy(ScienceUtil.GetTransmitterScore).First().TransmitData(new List { data }); + bestTransmitter.TransmitData(new List { data }); DumpData(data); } + else if (CommNet.CommNetScenario.CommNetEnabled) + ScreenMessages.PostScreenMessage("No usable, in-range Comms Devices on this vessel. Cannot Transmit Data.", 3f, ScreenMessageStyle.UPPER_CENTER); else ScreenMessages.PostScreenMessage("No Comms Devices on this vessel. Cannot Transmit Data.", 3f, ScreenMessageStyle.UPPER_CENTER); } private void onSendToLab(ScienceData data) { + resultsDialog = null; + ScienceLabSearch labSearch = new ScienceLabSearch(vessel, data); if (labSearch.NextLabForDataFound) diff --git a/Source/Part Modules/DMBasicScienceModule.cs b/Source/Part Modules/DMBasicScienceModule.cs index 9aaffa1..bd78a75 100644 --- a/Source/Part Modules/DMBasicScienceModule.cs +++ b/Source/Part Modules/DMBasicScienceModule.cs @@ -102,6 +102,8 @@ public class DMBasicScienceModule : PartModule, IScienceDataContainer protected ScienceExperiment exp = null; protected List scienceReports = new List(); + private ExperimentsResultDialog resultsDialog; + private bool hasContainer; private Animation anim; @@ -127,6 +129,13 @@ public static bool conduct(PartModule MSE) } } + public override void OnAwake() + { + GameEvents.onGamePause.Add(onPause); + GameEvents.onGameUnpause.Add(onUnPause); + GameEvents.onVesselStandardModification.Add(onVesselModified); + } + public override void OnStart(PartModule.StartState state) { if (!string.IsNullOrEmpty(animationName)) @@ -140,6 +149,8 @@ public override void OnStart(PartModule.StartState state) if (IsDeployed) primaryAnimator(1f, 1f, WrapMode.Default, animationName, anim); } + + findContainers(); } public override void OnSave(ConfigNode node) @@ -164,6 +175,13 @@ public override void OnLoad(ConfigNode node) } } + protected virtual void OnDestroy() + { + GameEvents.onGamePause.Remove(onPause); + GameEvents.onGameUnpause.Remove(onUnPause); + GameEvents.onVesselStandardModification.Remove(onVesselModified); + } + public override string GetInfo() { string info = base.GetInfo(); @@ -173,12 +191,53 @@ public override string GetInfo() return info; } + private void onPause() + { + if (resultsDialog != null) + resultsDialog.gameObject.SetActive(false); + } + + private void onUnPause() + { + if (resultsDialog != null) + resultsDialog.gameObject.SetActive(true); + } + + private void onVesselModified(Vessel v) + { + if (v == vessel && HighLogic.LoadedSceneIsFlight) + findContainers(); + } + + private void findContainers() + { + for (int i = vessel.Parts.Count - 1; i >= 0; i--) + { + Part p = vessel.Parts[i]; + + if (p == null) + continue; + + if (p.State == PartStates.DEAD) + continue; + + ModuleScienceContainer container = p.FindModuleImplementing(); + + if (container == null) + continue; + + hasContainer = container.canBeTransferredToInVessel; + break; + } + } + protected virtual void EventsCheck() { Events["ResetExperiment"].active = scienceReports.Count > 0; Events["CollectDataExternalEvent"].active = scienceReports.Count > 0 && dataIsCollectable; Events["DeployExperiment"].active = scienceReports.Count == 0 && !Deployed && !Inoperable; Events["ReviewDataEvent"].active = scienceReports.Count > 0; + Events["TransferDataEvent"].active = hasContainer && dataIsCollectable && scienceReports.Count > 0; } protected virtual void setup() @@ -314,6 +373,78 @@ public void CollectDataExternalEvent() } } + [KSPEvent(guiActive = true, guiName = "Transfer Data", active = false)] + public void TransferDataEvent() + { + if (PartItemTransfer.Instance != null) + { + ScreenMessages.PostScreenMessage("A transfer is already in progress.", 3f, ScreenMessageStyle.UPPER_CENTER); + return; + } + + ExperimentTransfer.Create(part, this, new Callback(transferData)); + } + + private void transferData(PartItemTransfer.DismissAction dismiss, Part p) + { + if (dismiss != PartItemTransfer.DismissAction.ItemMoved) + return; + + if (p == null) + return; + + if (scienceReports.Count <= 0) + { + ScreenMessages.PostScreenMessage(string.Format("[{0}]: has no data to transfer.", part.partInfo.title), 6, ScreenMessageStyle.UPPER_CENTER); + return; + } + + ModuleScienceContainer container = p.FindModuleImplementing(); + + if (container == null) + { + ScreenMessages.PostScreenMessage(string.Format("[{0}]: {1} has no data container, canceling transfer.", part.partInfo.title, p.partInfo.title), 6, ScreenMessageStyle.UPPER_CENTER); + return; + } + + if (!rerunnable) + { + List dialog = new List(); + dialog.Add(new DialogGUIButton("Remove Data", new Callback(onTransferData), container)); + dialog.Add(new DialogGUIButton("Cancel", null, true)); + + PopupDialog.SpawnPopupDialog( + new Vector2(0.5f, 0.5f), + new Vector2(0.5f, 0.5f), + new MultiOptionDialog( + "Removing the experiment data will render this module inoperable.\n\nRestoring functionality will require a Scientist.", + part.partInfo.title + "Warning!", + UISkinManager.defaultSkin, + dialog.ToArray() + ), + false, + UISkinManager.defaultSkin, + true, + "" + ); + } + else + onTransferData(container); + } + + private void onTransferData(ModuleScienceContainer target) + { + if (target == null) + return; + + int i = scienceReports.Count; + + if (target.StoreData(new List { this }, false)) + ScreenMessages.PostScreenMessage(string.Format("[{0}]: {1} Data stored.", target.part.partInfo.title, i), 6, ScreenMessageStyle.UPPER_LEFT); + else + ScreenMessages.PostScreenMessage(string.Format("[{0}]: Not all data was stored.", target.part.partInfo.title), 6, ScreenMessageStyle.UPPER_LEFT); + } + [KSPEvent(guiActive = true, guiName = "Review Data", active = false)] public void ReviewDataEvent() { @@ -356,13 +487,14 @@ private void experimentResultsPage(ScienceData data) { if (scienceReports.Count > 0) { - ExperimentResultDialogPage page = new ExperimentResultDialogPage(part, data, transmitValue, ModuleScienceLab.GetBoostForVesselData(vessel, data), false, "", true, new ScienceLabSearch(vessel, data), new Callback(onDiscardData), new Callback(onKeepData), new Callback(onTransmitData), new Callback(onSendToLab)); - ExperimentsResultDialog.DisplayResult(page); + ExperimentResultDialogPage page = new ExperimentResultDialogPage(part, data, data.baseTransmitValue, data.transmitBonus, false, "", true, new ScienceLabSearch(vessel, data), new Callback(onDiscardData), new Callback(onKeepData), new Callback(onTransmitData), new Callback(onSendToLab)); + resultsDialog = ExperimentsResultDialog.DisplayResult(page); } } private void onDiscardData(ScienceData data) { + resultsDialog = null; if (scienceReports.Count > 0) { scienceReports.Clear(); @@ -372,23 +504,29 @@ private void onDiscardData(ScienceData data) private void onKeepData(ScienceData data) { + resultsDialog = null; } private void onTransmitData(ScienceData data) { - List tranList = vessel.FindPartModulesImplementing(); - if (tranList.Count > 0 && scienceReports.Count > 0) + resultsDialog = null; + + IScienceDataTransmitter bestTransmitter = ScienceUtil.GetBestTransmitter(vessel); + + if (bestTransmitter != null) { - DMUtils.Logging("Sending data to vessel comms. {0} devices to choose from. Will try to pick the best one", tranList.Count); - tranList.OrderBy(ScienceUtil.GetTransmitterScore).First().TransmitData(new List { data }); + bestTransmitter.TransmitData(new List { data }); DumpData(data); } + else if (CommNet.CommNetScenario.CommNetEnabled) + ScreenMessages.PostScreenMessage("No usable, in-range Comms Devices on this vessel. Cannot Transmit Data.", 3f, ScreenMessageStyle.UPPER_CENTER); else ScreenMessages.PostScreenMessage("No Comms Devices on this vessel. Cannot Transmit Data.", 3f, ScreenMessageStyle.UPPER_CENTER); } private void onSendToLab(ScienceData data) { + resultsDialog = null; ScienceLabSearch labSearch = new ScienceLabSearch(vessel, data); if (labSearch.NextLabForDataFound) diff --git a/Source/Part Modules/DMBreakablePart.cs b/Source/Part Modules/DMBreakablePart.cs index b747d3b..b4efdd3 100644 --- a/Source/Part Modules/DMBreakablePart.cs +++ b/Source/Part Modules/DMBreakablePart.cs @@ -270,31 +270,30 @@ private void breakObjects() if (o == null) continue; - Rigidbody r = o.AddComponent(); + physicalObject pO = physicalObject.ConvertToPhysicalObject(part, o); - if (r == null) + if (pO == null || pO.rb == null) continue; - DMUtils.DebugLog("Breaking Object [{0}]...", o.name); + //DMUtils.DebugLog("Breaking Object [{0}]...", o.name); - Rigidbody partRigid = part.GetComponent(); + pO.rb.maxAngularVelocity = PhysicsGlobals.MaxAngularVelocity; - Vector3 randomAngular = new Vector3((float)DMUtils.rand.NextDouble() * 3, (float)DMUtils.rand.NextDouble() * 3, (float)DMUtils.rand.NextDouble() * 3); - DMUtils.DebugLog("Random Angular: [{0:F4}]", randomAngular); - DMUtils.DebugLog("Old Angular: [{0:F4}]", r.angularVelocity); - r.angularVelocity = partRigid.angularVelocity + randomAngular; - DMUtils.DebugLog("New Angular: [{0:F4}]", r.angularVelocity); + Vector3 randomAngular = new Vector3(((float)DMUtils.rand.NextDouble() * 6) - 3, ((float)DMUtils.rand.NextDouble() * 6) - 3, ((float)DMUtils.rand.NextDouble() * 6) - 3); + //DMUtils.DebugLog("Random Angular: [{0:F4}]", randomAngular); + //DMUtils.DebugLog("Old Angular: [{0:F4}]", pO.rb.angularVelocity); + pO.rb.angularVelocity = part.Rigidbody.angularVelocity + randomAngular; + //DMUtils.DebugLog("New Angular: [{0:F4}]", pO.rb.angularVelocity); Vector3 randomVel = new Vector3(((float)DMUtils.rand.NextDouble() * 8) - 4, ((float)DMUtils.rand.NextDouble() * 8) - 4, ((float)DMUtils.rand.NextDouble() * 8) - 4); - DMUtils.DebugLog("Random Velocity: [{0:F4}]", randomVel); - Vector3 localCOM = vessel.findWorldCenterOfMass() - partRigid.worldCenterOfMass; - DMUtils.DebugLog("Old Velocity: [{0:F4}]", r.velocity); - r.velocity = partRigid.velocity + randomVel + Vector3.Cross(localCOM, r.angularVelocity); - DMUtils.DebugLog("New Velocity: [{0:F4}]", r.velocity); - r.mass = componentMass; - r.useGravity = false; + //DMUtils.DebugLog("Random Velocity: [{0:F4}]", randomVel); + Vector3 localCOM = vessel.CurrentCoM - part.Rigidbody.worldCenterOfMass; + //DMUtils.DebugLog("Old Velocity: [{0:F4}]", pO.rb.velocity); + pO.rb.velocity = part.Rigidbody.velocity + randomVel + Vector3.Cross(localCOM, pO.rb.angularVelocity); + //DMUtils.DebugLog("New Velocity: [{0:F4}]", pO.rb.velocity); + pO.rb.mass = componentMass; + pO.rb.useGravity = false; o.transform.parent = null; - physicalObject p = o.AddComponent(); - r.drag = componentDrag; + pO.origDrag = componentDrag; var colliders = o.GetComponentsInChildren(); diff --git a/Source/Part Modules/DMEnviroSensor.cs b/Source/Part Modules/DMEnviroSensor.cs index 07a697e..56a2986 100644 --- a/Source/Part Modules/DMEnviroSensor.cs +++ b/Source/Part Modules/DMEnviroSensor.cs @@ -50,7 +50,6 @@ internal class DMEnviroSensor : ModuleEnviroSensor private Transform rotor3 = null; private Transform tilt1 = null; private Vector3 indicatorPosition = new Vector3(0, 0, 0); - private int sensorInt = 0; private List modList = new List(); private float timeDelay = 0f; private float lastValue = 0f; @@ -58,24 +57,27 @@ internal class DMEnviroSensor : ModuleEnviroSensor public override void OnStart(PartModule.StartState state) { base.OnStart(state); - if (HighLogic.LoadedSceneIsFlight) { - sensorInt = sensorTypeInt(sensorType); - Fields["readoutInfo"].guiName = guiReadout(sensorInt); + if (HighLogic.LoadedSceneIsFlight) + { + Fields["readoutInfo"].guiName = sensorType.ToString(); //Assign transforms for all of the indicator needles, etc.. for each part type - if (sensorInt == 1 || sensorInt == 2 || sensorInt == 3) - indicator = part.FindModelTransform(sensorType); - if (sensorInt == 3) + if (sensorType != SensorType.ACC) + indicator = part.FindModelTransform(sensorType.ToString()); + if (sensorType == SensorType.TEMP) indicatorPosition = indicator.localPosition; - if (sensorInt == 4) { + if (sensorType == SensorType.ACC) + { rotor1 = part.FindModelTransform(sensorType + "_000"); rotor2 = part.FindModelTransform(sensorType + "_001"); rotor3 = part.FindModelTransform(sensorType + "_002"); tilt1 = part.FindModelTransform(sensorType + "_003"); } //Prevent multiple modules from interfering with each other - if (primary) { + if (primary) + { modList = this.part.FindModulesImplementing(); - if (modList.Count > 1) { + if (modList.Count > 1) + { modList[0].Events["toggleSensor"].active = true; modList[1].Events["toggleSensor"].active = false; } @@ -83,20 +85,14 @@ public override void OnStart(PartModule.StartState state) } } - public override string GetInfo() - { - string info = base.GetInfo(); - if (primary) - info += "Requires:\n- " + resourceName + ": " + powerConsumption.ToString() + "/s\n"; - return info; - } - [KSPEvent(guiActiveUnfocused = true, externalToEVAOnly = true, guiActive = false, guiName = "Activate", active = false)] public void toggleSensor() { - foreach (DMEnviroSensor DMES in modList) { - DMES.sensorActive= !DMES.sensorActive; - if (DMES.primary) { + foreach (DMEnviroSensor DMES in modList) + { + DMES.sensorActive = !DMES.sensorActive; + if (DMES.primary) + { if (DMES.sensorActive) Events["toggleSensor"].guiName = "Deactivate"; else @@ -105,22 +101,6 @@ public void toggleSensor() } } - private int sensorTypeInt(string type) - { - switch (type) { - case "PRES": - return 1; - case "GRAV": - return 2; - case "TEMP": - return 3; - case "ACC": - return 4; - default: - return 0; - } - } - public void Update() { animateIndicator(); @@ -128,32 +108,36 @@ public void Update() private void animateIndicator() { - if (indicator != null || rotor1 != null) { + if (indicator != null || rotor1 != null) + { float maxSensorValue = 0f; float currentSensorValue = 0f; float normSensorValue = 0f; - if (sensorActive) { + if (sensorActive) + { if (timeDelay <= 1f) timeDelay += TimeWarp.deltaTime; - maxSensorValue = sensorValue(sensorInt); + maxSensorValue = sensorValue(sensorType); currentSensorValue = parseSensor(); - if (sensorInt == 3) + if (sensorType == SensorType.TEMP) currentSensorValue += 429; //For negative temp values if (maxSensorValue != 0) normSensorValue = Mathf.Clamp(currentSensorValue / maxSensorValue, 0f, 1f); normSensorValue *= timeDelay; lastValue = normSensorValue; } - else { + else + { if (timeDelay >= 0f) timeDelay -= TimeWarp.deltaTime; normSensorValue = lastValue * timeDelay; } - if (sensorInt == 1 || sensorInt == 2) + if (sensorType == SensorType.PRES || sensorType == SensorType.GRAV) indicator.localRotation = Quaternion.Euler(Mathf.Lerp(min, max, normSensorValue), 0f, 0f); - if (sensorInt == 3) + if (sensorType == SensorType.TEMP) indicator.localPosition = Vector3.MoveTowards(indicator.localPosition, indicatorPosition + new Vector3(0f, 0f, 0.12f * normSensorValue), Time.deltaTime); - if (sensorInt == 4) { + if (sensorType == SensorType.ACC) + { rotor1.Rotate(1000 * TimeWarp.deltaTime, 0f, 0f); rotor2.Rotate(0f, 0f, 3000 * normSensorValue * TimeWarp.deltaTime); rotor3.Rotate(0f, 3000 * normSensorValue * TimeWarp.deltaTime, 0f); @@ -168,9 +152,11 @@ private float parseSensor() float parseValue = 0f; if (float.TryParse(readoutInfo, out parseValue)) return parseValue; - else { + else + { string a = ""; - for (int i = 0; i < readoutInfo.Length; i++) { + for (int i = 0; i < readoutInfo.Length; i++) + { if (Char.IsDigit(readoutInfo[i]) || readoutInfo[i] == '.' || readoutInfo[i] == '-') a += readoutInfo[i]; } @@ -180,36 +166,21 @@ private float parseSensor() return parseValue; } - //Some imperically determined max values for each sensor - private float sensorValue(int type) + //Some emperically determined max values for each sensor + private float sensorValue(ModuleEnviroSensor.SensorType type) { - switch (type) { - case 1: + switch (type) + { + case SensorType.PRES: return 3; - case 2: + case SensorType.GRAV: return 30; - case 3: + case SensorType.TEMP: return 1500; - case 4: + case SensorType.ACC: return 10; default: - return 1; - } - } - - private string guiReadout(int type) - { - switch (type) { - case 1: - return "PRES"; - case 2: - return "GRAV"; - case 3: - return "TEMP"; - case 4: - return "ACC"; - default: - return "Display"; + return 0; } } diff --git a/Source/Part Modules/DMModuleScienceAnimate.cs b/Source/Part Modules/DMModuleScienceAnimate.cs index 10674ec..3ce95b0 100644 --- a/Source/Part Modules/DMModuleScienceAnimate.cs +++ b/Source/Part Modules/DMModuleScienceAnimate.cs @@ -140,6 +140,7 @@ public class DMModuleScienceAnimate : ModuleScienceExperiment, IScienceDataConta private bool lastInOperableState; protected float scienceBoost = 1f; protected string failMessage = ""; + private ExperimentsResultDialog resultsDialog; /// /// For external use to determine if a module can conduct science @@ -167,6 +168,13 @@ public static bool conduct(ModuleScienceExperiment MSE) #region PartModule + public override void OnAwake() + { + GameEvents.onGamePause.Add(onPause); + GameEvents.onGameUnpause.Add(onUnPause); + GameEvents.onVesselStandardModification.Add(OnVesselModified); + } + public override void OnStart(StartState state) { if (!string.IsNullOrEmpty(animationName)) @@ -217,6 +225,13 @@ public override void OnStart(StartState state) } } + new protected virtual void OnDestroy() + { + GameEvents.onGamePause.Remove(onPause); + GameEvents.onGameUnpause.Remove(onUnPause); + GameEvents.onVesselStandardModification.Remove(OnVesselModified); + } + public override void OnSave(ConfigNode node) { node.RemoveNodes("ScienceData"); @@ -335,6 +350,7 @@ private void setup() Events["DeployExperiment"].guiActiveUnfocused = externalDeploy; Events["DeployExperiment"].externalToEVAOnly = externalDeploy; Events["DeployExperiment"].unfocusedRange = interactionRange; + Actions["DeployAction"].active = useActionGroups; Actions["deployAction"].guiName = startEventGUIName; Actions["retractAction"].guiName = endEventGUIName; Actions["toggleAction"].guiName = toggleEventGUIName; @@ -392,6 +408,20 @@ private void eventsCheck() Events["ReviewInitialData"].active = scienceReports.Count > 0; Events["DeployExperimentExternal"].guiActiveUnfocused = false; Events["CleanUpExperimentExternal"].active = Inoperable; + Events["TransferDataEvent"].active = hasContainer && dataIsCollectable && storedScienceReports.Count > 0; + Actions["ResetAction"].active = useActionGroups && storedScienceReports.Count > 0 && resettable; + } + + private void onPause() + { + if (resultsDialog != null) + resultsDialog.gameObject.SetActive(false); + } + + private void onUnPause() + { + if (resultsDialog != null) + resultsDialog.gameObject.SetActive(true); } #endregion @@ -652,6 +682,77 @@ public virtual void editorRetractEvent() ScreenMessages.PostScreenMessage(string.Format("[{0}]: Media Restored. Module is operational again.", part.partInfo.title), 6f, ScreenMessageStyle.UPPER_LEFT); } + new public void TransferDataEvent() + { + if (PartItemTransfer.Instance != null) + { + ScreenMessages.PostScreenMessage("A transfer is already in progress.", 3f, ScreenMessageStyle.UPPER_CENTER); + return; + } + + ExperimentTransfer.Create(part, this, new Callback(transferData)); + } + + private void transferData(PartItemTransfer.DismissAction dismiss, Part p) + { + if (dismiss != PartItemTransfer.DismissAction.ItemMoved) + return; + + if (p == null) + return; + + if (storedScienceReports.Count <= 0) + { + ScreenMessages.PostScreenMessage(string.Format("[{0}]: has no data to transfer.", part.partInfo.title), 6, ScreenMessageStyle.UPPER_CENTER); + return; + } + + ModuleScienceContainer container = p.FindModuleImplementing(); + + if (container == null) + { + ScreenMessages.PostScreenMessage(string.Format("[{0}]: {1} has no data container, canceling transfer.", part.partInfo.title, p.partInfo.title), 6, ScreenMessageStyle.UPPER_CENTER); + return; + } + + if ((experimentsReturned >= (experimentLimit - 1)) && !rerunnable) + { + List dialog = new List(); + dialog.Add(new DialogGUIButton("Remove Data", new Callback(onTransferData), container)); + dialog.Add(new DialogGUIButton("Cancel", null, true)); + + PopupDialog.SpawnPopupDialog( + new Vector2(0.5f, 0.5f), + new Vector2(0.5f, 0.5f), + new MultiOptionDialog( + collectWarningText, + part.partInfo.title + "Warning!", + UISkinManager.defaultSkin, + dialog.ToArray() + ), + false, + UISkinManager.defaultSkin, + true, + "" + ); + } + else + onTransferData(container); + } + + private void onTransferData(ModuleScienceContainer target) + { + if (target == null) + return; + + int i = storedScienceReports.Count; + + if (target.StoreData(new List { this }, false)) + ScreenMessages.PostScreenMessage(string.Format("[{0}]: {1} Data stored.", target.part.partInfo.title, i), 6, ScreenMessageStyle.UPPER_LEFT); + else + ScreenMessages.PostScreenMessage(string.Format("[{0}]: Not all data was stored.", target.part.partInfo.title), 6, ScreenMessageStyle.UPPER_LEFT); + } + #endregion #region Science Experiment Setup @@ -997,7 +1098,7 @@ private ScienceData makeScience(ExperimentSituations vesselSituation) } } - data = new ScienceData(dat, xmitDataScalar, vessel.VesselValues.ScienceReturn.value, sub.id, sub.title, false, part.flightID); + data = new ScienceData(dat, xmitDataScalar, 0, sub.id, sub.title, false, part.flightID); return data; } @@ -1038,8 +1139,8 @@ private void newResultPage(ScienceData data = null) { if (data == null) data = storedScienceReports[dataIndex]; - ExperimentResultDialogPage page = new ExperimentResultDialogPage(part, data, data.transmitValue, ModuleScienceLab.GetBoostForVesselData(vessel, data), (experimentsReturned >= (experimentLimit - 1)) && !rerunnable, transmitWarningText, true, new ScienceLabSearch(vessel, data), new Callback(onDiscardData), new Callback(onKeepData), new Callback(onTransmitData), new Callback(onSendToLab)); - ExperimentsResultDialog.DisplayResult(page); + ExperimentResultDialogPage page = new ExperimentResultDialogPage(part, data, data.baseTransmitValue, data.transmitBonus, (experimentsReturned >= (experimentLimit - 1)) && !rerunnable, transmitWarningText, true, new ScienceLabSearch(vessel, data), new Callback(onDiscardData), new Callback(onKeepData), new Callback(onTransmitData), new Callback(onSendToLab)); + resultsDialog = ExperimentsResultDialog.DisplayResult(page); } } @@ -1076,13 +1177,15 @@ private void initialResultsPage() if (scienceReports.Count > 0) { ScienceData data = scienceReports[0]; - ExperimentResultDialogPage page = new ExperimentResultDialogPage(part, data, data.transmitValue, ModuleScienceLab.GetBoostForVesselData(vessel, data), (experimentsReturned >= (experimentLimit - 1)) && !rerunnable, transmitWarningText, true, new ScienceLabSearch(vessel, data), new Callback(onDiscardInitialData), new Callback(onKeepInitialData), new Callback(onTransmitInitialData), new Callback(onSendInitialToLab)); - ExperimentsResultDialog.DisplayResult(page); + ExperimentResultDialogPage page = new ExperimentResultDialogPage(part, data, data.baseTransmitValue, data.transmitBonus, (experimentsReturned >= (experimentLimit - 1)) && !rerunnable, transmitWarningText, true, new ScienceLabSearch(vessel, data), new Callback(onDiscardInitialData), new Callback(onKeepInitialData), new Callback(onTransmitInitialData), new Callback(onSendInitialToLab)); + resultsDialog = ExperimentsResultDialog.DisplayResult(page); } } private void onDiscardData(ScienceData data) { + resultsDialog = null; + if (storedScienceReports.Count > 0) { if (experimentLimit != 0) @@ -1105,23 +1208,27 @@ private void onDiscardData(ScienceData data) private void onKeepData(ScienceData data) { + resultsDialog = null; } private void onTransmitData(ScienceData data) { - List tranList = vessel.FindPartModulesImplementing(); - if (tranList.Count > 0 && storedScienceReports.Count > 0) + resultsDialog = null; + IScienceDataTransmitter bestTransmitter = ScienceUtil.GetBestTransmitter(vessel); + if (bestTransmitter != null) { - DMUtils.Logging("Sending data to vessel comms. {0} devices to choose from. Will try to pick the best one", tranList.Count); - tranList.OrderBy(ScienceUtil.GetTransmitterScore).First().TransmitData(new List { data }); + bestTransmitter.TransmitData(new List { data }); DumpData(data); } + else if (CommNet.CommNetScenario.CommNetEnabled) + ScreenMessages.PostScreenMessage("No usable, in-range Comms Devices on this vessel. Cannot Transmit Data.", 3f, ScreenMessageStyle.UPPER_CENTER); else ScreenMessages.PostScreenMessage("No Comms Devices on this vessel. Cannot Transmit Data.", 3f, ScreenMessageStyle.UPPER_CENTER); } private void onSendToLab(ScienceData data) { + resultsDialog = null; ScienceLabSearch labSearch = new ScienceLabSearch(vessel, data); if (labSearch.NextLabForDataFound) @@ -1135,6 +1242,7 @@ private void onSendToLab(ScienceData data) private void onDiscardInitialData(ScienceData data) { + resultsDialog = null; if (scienceReports.Count > 0) { scienceReports.Remove(data); @@ -1145,6 +1253,7 @@ private void onDiscardInitialData(ScienceData data) private void onKeepInitialData(ScienceData data) { + resultsDialog = null; if (experimentNumber >= experimentLimit) { ScreenMessages.PostScreenMessage(storageFullMessage, 5f, ScreenMessageStyle.UPPER_CENTER); @@ -1167,33 +1276,48 @@ private void onKeepInitialData(ScienceData data) private void onTransmitInitialData(ScienceData data) { - List tranList = vessel.FindPartModulesImplementing(); - if (tranList.Count > 0 && scienceReports.Count > 0) + resultsDialog = null; + + if (experimentLimit != 0) { - DMUtils.Logging("Sending data to vessel comms. {0} devices to choose from. Will try to pick the best one", tranList.Count); - if (experimentLimit != 0) - { - if (!string.IsNullOrEmpty(sampleAnim)) - secondaryAnimator(sampleAnim, animSpeed, experimentNumber * (1f / experimentLimit), anim2[sampleAnim].length / experimentLimit); - if (!string.IsNullOrEmpty(indicatorAnim)) - secondaryAnimator(indicatorAnim, animSpeed, experimentNumber * (1f / experimentLimit), anim2[indicatorAnim].length / experimentLimit); - } - tranList.OrderBy(ScienceUtil.GetTransmitterScore).First().TransmitData(new List { data }); + if (!string.IsNullOrEmpty(sampleAnim)) + secondaryAnimator(sampleAnim, animSpeed, experimentNumber * (1f / experimentLimit), anim2[sampleAnim].length / experimentLimit); + if (!string.IsNullOrEmpty(indicatorAnim)) + secondaryAnimator(indicatorAnim, animSpeed, experimentNumber * (1f / experimentLimit), anim2[indicatorAnim].length / experimentLimit); + } + + IScienceDataTransmitter bestTransmitter = ScienceUtil.GetBestTransmitter(vessel); + if (bestTransmitter != null) + { + bestTransmitter.TransmitData(new List { data }); DumpInitialData(data); experimentNumber++; } + else if (CommNet.CommNetScenario.CommNetEnabled) + ScreenMessages.PostScreenMessage("No usable, in-range Comms Devices on this vessel. Cannot Transmit Data.", 3f, ScreenMessageStyle.UPPER_CENTER); else ScreenMessages.PostScreenMessage("No Comms Devices on this vessel. Cannot Transmit Data.", 3f, ScreenMessageStyle.UPPER_CENTER); + } private void onSendInitialToLab(ScienceData data) { + resultsDialog = null; ScienceLabSearch labSearch = new ScienceLabSearch(vessel, data); if (labSearch.NextLabForDataFound) { + if (experimentLimit != 0) + { + if (!string.IsNullOrEmpty(sampleAnim)) + secondaryAnimator(sampleAnim, animSpeed, experimentNumber * (1f / experimentLimit), anim2[sampleAnim].length / experimentLimit); + if (!string.IsNullOrEmpty(indicatorAnim)) + secondaryAnimator(indicatorAnim, animSpeed, experimentNumber * (1f / experimentLimit), anim2[indicatorAnim].length / experimentLimit); + } + StartCoroutine(labSearch.NextLabForData.ProcessData(data, null)); - DumpData(data); + DumpInitialData(data); + experimentNumber++; } else labSearch.PostErrorToScreen(); @@ -1240,7 +1364,12 @@ void IScienceDataContainer.DumpData(ScienceData data) new public ScienceData[] GetData() { - return storedScienceReports.ToArray(); + List DataList = new List(); + + DataList.AddRange(storedScienceReports); + DataList.AddRange(scienceReports); + + return DataList.ToArray(); } new public int GetScienceCount() @@ -1301,6 +1430,19 @@ protected virtual void DumpDataOverride(ScienceData data) Deployed = Inoperable; storedScienceReports.Remove(data); } + else if (scienceReports.Contains(data)) + { + if (experimentLimit != 0) + { + if (!string.IsNullOrEmpty(sampleAnim)) + secondaryAnimator(sampleAnim, animSpeed, experimentNumber * (1f / experimentLimit), anim2[sampleAnim].length / experimentLimit); + if (!string.IsNullOrEmpty(indicatorAnim)) + secondaryAnimator(indicatorAnim, animSpeed, experimentNumber * (1f / experimentLimit), anim2[indicatorAnim].length / experimentLimit); + } + + DumpInitialData(data); + experimentNumber++; + } } protected virtual void DumpInitialData(ScienceData data) diff --git a/Source/Part Modules/DMReconScope.cs b/Source/Part Modules/DMReconScope.cs index 324c345..c902f3c 100644 --- a/Source/Part Modules/DMReconScope.cs +++ b/Source/Part Modules/DMReconScope.cs @@ -170,7 +170,7 @@ protected override void DumpDataOverride(ScienceData data) override protected void ReturnDataOverRide(ScienceData data) { - base.ReturnData(data); + base.ReturnDataOverRide(data); int i = experimentsReturned; diff --git a/Source/Part Modules/DMSIGINT.cs b/Source/Part Modules/DMSIGINT.cs index 3ca06e1..3e54154 100644 --- a/Source/Part Modules/DMSIGINT.cs +++ b/Source/Part Modules/DMSIGINT.cs @@ -433,6 +433,11 @@ public void SetUIWrite(bool state) } + public string ScalarModuleID + { + get { return "dmsigint"; } + } + public override void OnUpdate() { base.OnUpdate(); diff --git a/Source/Part Modules/DMSeismicHammer.cs b/Source/Part Modules/DMSeismicHammer.cs index a6fdbd1..0240de3 100644 --- a/Source/Part Modules/DMSeismicHammer.cs +++ b/Source/Part Modules/DMSeismicHammer.cs @@ -149,8 +149,10 @@ public override void OnSave(ConfigNode node) base.OnSave(node); } - private void OnDestroy() + protected override void OnDestroy() { + base.OnDestroy(); + GameEvents.onVesselWasModified.Remove(onVesselModified); GameEvents.onPartCouple.Remove(onCouple); } diff --git a/Source/Properties/AssemblyInfo.cs b/Source/Properties/AssemblyInfo.cs index 4d7f830..1853c35 100644 --- a/Source/Properties/AssemblyInfo.cs +++ b/Source/Properties/AssemblyInfo.cs @@ -19,7 +19,7 @@ // The following GUID is for the ID of the typelib if this project is exposed to COM [assembly: Guid("5428988e-53a6-4d8e-8af4-014572513e22")] -[assembly: AssemblyVersion("1.3.0.2")] -[assembly: AssemblyFileVersion("1.3.0.2")] -[assembly: AssemblyInformationalVersion("v1.3.2")] +[assembly: AssemblyVersion("1.3.0.3")] +[assembly: AssemblyFileVersion("1.3.0.3")] +[assembly: AssemblyInformationalVersion("v1.3.3")] [assembly: KSPAssembly("DMagic", 1, 4)] diff --git a/Source/Scenario/DMRecoveryWatcher.cs b/Source/Scenario/DMRecoveryWatcher.cs index eee73e2..0c17de8 100644 --- a/Source/Scenario/DMRecoveryWatcher.cs +++ b/Source/Scenario/DMRecoveryWatcher.cs @@ -59,6 +59,8 @@ private void RecoveryWatcher(float sci, ScienceSubject sub, ProtoVessel pv, bool if (DMScienceScenario.SciScenario == null) return; + sci /= HighLogic.CurrentGame.Parameters.Career.ScienceGainMultiplier; + if (HighLogic.LoadedScene == GameScenes.SPACECENTER || HighLogic.LoadedScene == GameScenes.TRACKSTATION) { float DMScience = sci; diff --git a/Source/Scenario/DMScienceScenario.cs b/Source/Scenario/DMScienceScenario.cs index 32bb847..660fefd 100644 --- a/Source/Scenario/DMScienceScenario.cs +++ b/Source/Scenario/DMScienceScenario.cs @@ -30,6 +30,7 @@ #endregion using System; +using System.Collections; using System.Collections.Generic; using System.Linq; using UnityEngine; @@ -179,11 +180,30 @@ public override void OnLoad(ConfigNode node) } } } - + private void Start() { if (HighLogic.LoadedSceneIsFlight) - updateRemainingData(); + StartCoroutine(updateWhenReady()); + } + + private IEnumerator updateWhenReady() + { + while (!FlightGlobals.ready) + yield return null; + + while (FlightGlobals.ActiveVessel == null) + yield return null; + + int timer = 0; + + while (timer < 30) + { + timer++; + yield return null; + } + + updateRemainingData(); } private void addDMScience(DMScienceData data) @@ -242,7 +262,8 @@ private void updateRemainingData() { foreach (IScienceDataContainer container in FlightGlobals.ActiveVessel.FindPartModulesImplementing()) { - dataList.AddRange(container.GetData()); + if (container.GetData() != null && container.GetData().Length > 0) + dataList.AddRange(container.GetData()); } if (dataList.Count > 0) { diff --git a/Source/Scenario/DMTransmissionWatcher.cs b/Source/Scenario/DMTransmissionWatcher.cs index f3e9bfa..4aeea7c 100644 --- a/Source/Scenario/DMTransmissionWatcher.cs +++ b/Source/Scenario/DMTransmissionWatcher.cs @@ -59,6 +59,8 @@ private void scienceReceived(float sci, ScienceSubject sub, ProtoVessel pv, bool if (DMScienceScenario.SciScenario == null) return; + sci /= HighLogic.CurrentGame.Parameters.Career.ScienceGainMultiplier; + if (HighLogic.LoadedSceneIsFlight) { DMScienceData DMData = DMScienceScenario.SciScenario.getDMScience(sub.title);