From b591d14edc45d5eb1736af7f64507c3a57b37d7e Mon Sep 17 00:00:00 2001 From: Jamie Leighton Date: Tue, 1 Nov 2016 08:28:58 +1100 Subject: [PATCH 1/2] Fix editor custom filter Fix difficulty settings. Fix CRY-0300 door sound. Big performance pass on code. Fix blizzy toolbar vs stock icon settings. Added RSTKSPGameEvents as a better integration option. Fixed comatose kerbal death. Fix vessel switch window. --- .../REPOSoftTech/DeepFreeze/Changelog.txt | 14 +- .../DeepFreeze/DeepFreezeContinued.version | 2 +- Source/DFEditorFilter.cs | 63 ++--- Source/DFIntMemory.cs | 206 ++++++++++----- Source/DFSettings.cs | 2 +- Source/DeepFreeze.cs | 18 +- Source/DeepFreeze.csproj | 3 + Source/DeepFreezeGUI.cs | 59 +++-- Source/DeepFreezerPart.cs | 235 ++++++++++++------ Source/KerbalPortraits.cs | 51 +++- Source/Properties/AssemblyInfo.cs | 4 +- Source/SettingsParms.cs | 155 +++--------- 12 files changed, 466 insertions(+), 346 deletions(-) diff --git a/Distribution/GameData/REPOSoftTech/DeepFreeze/Changelog.txt b/Distribution/GameData/REPOSoftTech/DeepFreeze/Changelog.txt index 03702f3..1a89152 100644 --- a/Distribution/GameData/REPOSoftTech/DeepFreeze/Changelog.txt +++ b/Distribution/GameData/REPOSoftTech/DeepFreeze/Changelog.txt @@ -1,4 +1,16 @@ -V0.23.0.0 +V0.23.1.0 +Fix Editor customer Filter for DeepFreeze parts. +Fix problem with EC and Heat settings being disabled in new game difficulty settings. https://github.com/JPLRepo/DeepFreeze/issues/63 +Fix problem with CRY-0300 Doors opening/closing with JSI Advanced Transparent Pods showing an empty Internal until fully open, unfortunately +it does mean you can no longer see the doors animate open/closed correctly. This is a limitation of the JSI Advanced Transparent Pods and camera setup for KSP. +Performance improvement pass on the code. +Fixed Difficulty Settings. +Fixed incorrect use of Blizzy ToolBar on game startup even if user has set to use Stock Icon in difficulty settings. +Implemented inter-mod GameEvents - better integration possible with other mods. +Fixed bug when Comatose Kerbal dies. +Fixed Vessel Switching to unloaded vessel when Low EC or overheat warning occurs. +Removed CRY-0300 door sound when JSI Advanced Transparent Pods mod shuts the door (not the user). +V0.23.0.0 Update for KSP 1.2 Fix Coma Kerbals to register/unregister their traits at the correct time and handle Tourist kerbals. Added Setting in the menu that allows you to turn on/off the VAB/SPH Deepfreeze Parts Category Icon. diff --git a/Distribution/GameData/REPOSoftTech/DeepFreeze/DeepFreezeContinued.version b/Distribution/GameData/REPOSoftTech/DeepFreeze/DeepFreezeContinued.version index e14401c..5c4ebd8 100644 --- a/Distribution/GameData/REPOSoftTech/DeepFreeze/DeepFreezeContinued.version +++ b/Distribution/GameData/REPOSoftTech/DeepFreeze/DeepFreezeContinued.version @@ -2,7 +2,7 @@ "NAME":"DeepFreeze Continued...", "URL":"http://ksp-avc.cybutek.net/version.php?id=183", "DOWNLOAD":"http://spacedock.info/mod/142/DeepFreeze%20Continued...", -"VERSION":{"MAJOR":0,"MINOR":23,"PATCH":0,"BUILD":0}, +"VERSION":{"MAJOR":0,"MINOR":23,"PATCH":1,"BUILD":0}, "KSP_VERSION":{"MAJOR":1,"MINOR":2,"PATCH":0}, "KSP_VERSION_MIN":{"MAJOR":1,"MINOR":2,"PATCH":0}, "KSP_VERSION_MAX":{"MAJOR":1,"MINOR":2,"PATCH":0} diff --git a/Source/DFEditorFilter.cs b/Source/DFEditorFilter.cs index 8129a02..9ea2bdc 100644 --- a/Source/DFEditorFilter.cs +++ b/Source/DFEditorFilter.cs @@ -16,12 +16,9 @@ */ using System.Collections.Generic; -using System.IO; using KSP.UI.Screens; using RUI.Icons.Selectable; using UnityEngine; -using System.Reflection; -using System.Linq; namespace DF { @@ -31,7 +28,7 @@ public class DFEditorFilter : MonoBehaviour // This class ass a Filter Icon to the Editor to show DeepFreeze Parts // which currently consist of any partprefab that has component DeepFreezer (All the freezer parts) // and the GlykerolTankRadial. - private static List avPartItems; + private static List avPartItems = new List(); public static DFEditorFilter Instance; internal string category = "Filter by Function"; internal string subCategoryTitle = "DeepFreeze Items"; @@ -54,39 +51,24 @@ public void Awake() DontDestroyOnLoad(this); } - public void Setup(bool FilterOn) + public void Setup() { Debug.Log("DFEditorFilter Start"); - avPartItems = new List(); - //icon_DeepFreeze_Editor = new Texture2D(32, 32, TextureFormat.ARGB32, false); - + RemoveSubFilter(); + AddPartUtilitiesCat(); GameEvents.onGUIEditorToolbarReady.Remove(SubCategories); + - DFMMCallBack(); - - if (!FilterOn) + if (!HighLogic.CurrentGame.Parameters.CustomParams().EditorFilter) { Debug.Log("EditorFilter Option is Off"); - PartCategorizer.Category Filter = - PartCategorizer.Instance.filters.Find(f => f.button.categoryName == category); - if (Filter != null) - { - PartCategorizer.Category subFilter = - Filter.subcategories.Find(f => f.button.categoryName == subCategoryTitle); - if (subFilter != null) - { - //MethodInfo subFilterDeleteMethod = - // typeof(PartCategorizer.Category).GetMethod("DeleteSubcategory", - // BindingFlags.Instance | BindingFlags.NonPublic); - //subFilterDeleteMethod.Invoke(subFilter, null); - subFilter.DeleteSubcategory(); - } - } - GameEvents.onGUIEditorToolbarReady.Remove(SubCategories); - AddPartUtilitiesCat(); return; } + + Debug.Log("EditorFilter Option is On"); + DFMMCallBack(); + RemovePartUtilitiesCat(); GameEvents.onGUIEditorToolbarReady.Add(SubCategories); /* //Attempt to add Module Manager callback - find the base type @@ -108,9 +90,6 @@ public void Setup(bool FilterOn) }*/ //DFMMCallBack(); - //load the icons - //icon_DeepFreeze_Editor.LoadImage(File.ReadAllBytes("GameData/REPOSoftTech/DeepFreeze/Icons/DeepFreezeEditor.png")); - RemovePartUtilitiesCat(); Debug.Log("DFEditorFilter Awake Complete"); } @@ -131,11 +110,26 @@ public bool DFMMCallBack() return true; } + private void RemoveSubFilter() + { + if (PartCategorizer.Instance != null) + { + PartCategorizer.Category Filter = PartCategorizer.Instance.filters.Find(f => f.button.categoryName == category); + if (Filter != null) + { + PartCategorizer.Category subFilter = Filter.subcategories.Find(f => f.button.categoryName == subCategoryTitle); + if (subFilter != null) + { + subFilter.DeleteSubcategory(); + } + } + } + } + private void RemovePartUtilitiesCat() { foreach (AvailablePart avPart in avPartItems) { - //PartCategorizer.Instance.subcategoryFunctionUtility.RemovePart(avPart); avPart.category = PartCategories.none; } } @@ -144,7 +138,6 @@ private void AddPartUtilitiesCat() { foreach (AvailablePart avPart in avPartItems) { - //PartCategorizer.Instance.subcategoryFunctionUtility.AddPart(avPart); avPart.category = PartCategories.Utility; } } @@ -160,12 +153,10 @@ private bool EditorItemsFilter(AvailablePart avPart) private void SubCategories() { + RemoveSubFilter(); Icon filterDeepFreeze = new Icon("DeepFreezeEditor", Textures.DeepFreeze_Editor, Textures.DeepFreeze_Editor, true); PartCategorizer.Category Filter = PartCategorizer.Instance.filters.Find(f => f.button.categoryName == category); PartCategorizer.AddCustomSubcategoryFilter(Filter, subCategoryTitle, filterDeepFreeze, p => EditorItemsFilter(p)); - //RUIToggleButtonTyped button = Filter.button.activeButton; - //button.SetFalse(button, RUIToggleButtonTyped.ClickType.FORCED); - //button.SetTrue(button, RUIToggleButtonTyped.ClickType.FORCED); } } } \ No newline at end of file diff --git a/Source/DFIntMemory.cs b/Source/DFIntMemory.cs index 52a5933..a1c7a70 100644 --- a/Source/DFIntMemory.cs +++ b/Source/DFIntMemory.cs @@ -17,7 +17,6 @@ using System; using System.Collections.Generic; -using System.Linq; using KSP.UI.Screens; using PreFlightTests; using RSTUtils; @@ -70,8 +69,6 @@ public VslFrzrCams(Transform frzrcamTransform, InternalModel frzrcamModel, int f private List> comaKerbals = new List>(); private double currentTime, lastFixedUpdateTime, checkVesselUpdateTime, checkVesselComaTime; private List TmpDpFrzrActVsl = new List(); - private List unknownkerbals = new List(); - private List crewkerbals = new List(); private List allVessels = new List(); private List vesselsToDelete = new List(); private List partsToDelete = new List(); @@ -177,7 +174,7 @@ private void Update() } //Check if the FreezerCam references have disappeared and if they have reset. - if (ActFrzrCams.Any()) + if (ActFrzrCams.Count > 0) { if (ActFrzrCams[lastFrzrCam].FrzrCamTransform == null || ActFrzrCams[lastFrzrCam].FrzrCamModel == null) { @@ -367,7 +364,7 @@ private void FixedUpdate() //We check/update kerbal Dictionary for comatose kerbals in EVERY Game Scene. try { - if (DeepFreeze.Instance.DFgameSettings.KnownFrozenKerbals.Any()) + if (DeepFreeze.Instance.DFgameSettings.KnownFrozenKerbals.Count > 0) { CheckComaUpdate(); } @@ -409,22 +406,45 @@ private void CheckComaUpdate() // Check the knownfrozenkerbals for any tourists kerbals (IE: Comatose) if their time is up and reset them if it is. ComakeysToDelete.Clear(); //comaKerbals.Clear(); - comaKerbals = DeepFreeze.Instance.DFgameSettings.KnownFrozenKerbals.Where(e => e.Value.type == ProtoCrewMember.KerbalType.Tourist).ToList(); - //foreach (KeyValuePair comaKerbal in comaKerbals) + foreach (var entry in DeepFreeze.Instance.DFgameSettings.KnownFrozenKerbals) + { + if (entry.Value.type == ProtoCrewMember.KerbalType.Tourist) + { + comaKerbals.Add(entry); + } + } for (int i=0; i < comaKerbals.Count; i++) { if (Planetarium.GetUniversalTime() - comaKerbals[i].Value.lastUpdate > DeepFreeze.Instance.DFsettings.comatoseTime) // Is time up? { - ProtoCrewMember crew = HighLogic.CurrentGame.CrewRoster.Tourist.FirstOrDefault(a => a.name == comaKerbals[i].Key); + ProtoCrewMember crew = null; + IEnumerator enumerator = HighLogic.CurrentGame.CrewRoster.Tourist.GetEnumerator(); + while (enumerator.MoveNext()) + { + if (enumerator.Current.name == comaKerbals[i].Key) + crew = enumerator.Current; + } if (crew != null) { - Vessel vsl = FlightGlobals.Vessels.FirstOrDefault(a => a.id == comaKerbals[i].Value.vesselID); + Vessel vsl = null; + List.Enumerator enumerator5 = FlightGlobals.Vessels.GetEnumerator(); + while (enumerator5.MoveNext()) + { + if (enumerator5.Current.id == comaKerbals[i].Value.vesselID) + vsl = enumerator5.Current; + } if (vsl == null) { Utilities.Log("Failed to find Vessel for Comatose Kerbal - Critical error"); return; } - Part part = vsl.parts.FirstOrDefault(b => b.flightID == comaKerbals[i].Value.partID); + Part part = null; + List.Enumerator enumerator6 = vsl.parts.GetEnumerator(); + while (enumerator6.MoveNext()) + { + if (enumerator6.Current.flightID == comaKerbals[i].Value.partID) + part = enumerator6.Current; + } if (part == null) { Utilities.Log("Failed to find Part for Comatose Kerbal - Critical error"); @@ -456,67 +476,65 @@ private void CheckComaUpdate() private void ChkUnknownFrozenKerbals() { // Check the roster list for any unknown dead kerbals (IE: Frozen) that were not in the save file and add them. - //unknownkerbals.Clear(); - unknownkerbals = HighLogic.CurrentGame.CrewRoster.Unowned.ToList(); - if (unknownkerbals != null) + IEnumerator enumerator = HighLogic.CurrentGame.CrewRoster.Unowned.GetEnumerator(); + int i = 0; + while (enumerator.MoveNext()) { - Utilities.Log("There are " + unknownkerbals.Count + " unknownKerbals in the game roster."); - for (int i = 0; i < unknownkerbals.Count; i++) + if (enumerator.Current.rosterStatus == ProtoCrewMember.RosterStatus.Dead) { - if (unknownkerbals[i].rosterStatus == ProtoCrewMember.RosterStatus.Dead) + if (!DeepFreeze.Instance.DFgameSettings.KnownFrozenKerbals.ContainsKey(enumerator.Current.name)) { - if (!DeepFreeze.Instance.DFgameSettings.KnownFrozenKerbals.ContainsKey(unknownkerbals[i].name)) + // Update the saved frozen kerbals dictionary + KerbalInfo kerbalInfo = new KerbalInfo(Planetarium.GetUniversalTime()); + kerbalInfo.vesselID = Guid.Empty; + kerbalInfo.vesselName = ""; + kerbalInfo.type = enumerator.Current.type; + kerbalInfo.status = enumerator.Current.rosterStatus; + //kerbalInfo.seatName = "Unknown"; + kerbalInfo.seatIdx = 0; + kerbalInfo.partID = 0; + kerbalInfo.experienceTraitName = enumerator.Current.experienceTrait.Title; + try { - // Update the saved frozen kerbals dictionary - KerbalInfo kerbalInfo = new KerbalInfo(Planetarium.GetUniversalTime()); - kerbalInfo.vesselID = Guid.Empty; - kerbalInfo.vesselName = ""; - kerbalInfo.type = unknownkerbals[i].type; - kerbalInfo.status = unknownkerbals[i].rosterStatus; - //kerbalInfo.seatName = "Unknown"; - kerbalInfo.seatIdx = 0; - kerbalInfo.partID = 0; - kerbalInfo.experienceTraitName = unknownkerbals[i].experienceTrait.Title; - try - { - Utilities.Log("Adding dead unknown kerbal " + unknownkerbals[i].name + " AKA FROZEN kerbal to DeepFreeze List"); - DeepFreeze.Instance.DFgameSettings.KnownFrozenKerbals.Add(unknownkerbals[i].name, kerbalInfo); - } - catch (Exception ex) - { - Utilities.Log("Add of dead unknown kerbal " + unknownkerbals[i].name + " failed " + ex); - } + Utilities.Log("Adding dead unknown kerbal " + enumerator.Current.name + " AKA FROZEN kerbal to DeepFreeze List"); + DeepFreeze.Instance.DFgameSettings.KnownFrozenKerbals.Add(enumerator.Current.name, kerbalInfo); + } + catch (Exception ex) + { + Utilities.Log("Add of dead unknown kerbal " + enumerator.Current.name + " failed " + ex); } } } + i++; } + Utilities.Log("There are " + i + " unknownKerbals in the game roster."); } internal void ChkActiveFrozenKerbals() { // Check the roster list for any crew kerbals that we think are frozen but aren't any more and delete them. - //crewkerbals.Clear(); - crewkerbals = HighLogic.CurrentGame.CrewRoster.Crew.ToList(); - if (crewkerbals != null) + IEnumerator enumerator = HighLogic.CurrentGame.CrewRoster.Crew.GetEnumerator(); + int i = 0; + while (enumerator.MoveNext()) { - Utilities.Log("There are " + crewkerbals.Count() + " crew Kerbals in the game roster."); - for (int i = 0; i < crewkerbals.Count; i++) + if (DeepFreeze.Instance.DFgameSettings.KnownFrozenKerbals.ContainsKey(enumerator.Current.name)) { - if (DeepFreeze.Instance.DFgameSettings.KnownFrozenKerbals.ContainsKey(crewkerbals[i].name)) + // Remove the saved frozen kerbals dictionary + try { - // Remove the saved frozen kerbals dictionary - try - { - Utilities.Log_Debug("Removing crew kerbal " + crewkerbals[i].name + " from DeepFreeze List"); - DeepFreeze.Instance.DFgameSettings.KnownFrozenKerbals.Remove(crewkerbals[i].name); - } - catch (Exception ex) - { - Utilities.Log("Removal of crew kerbal " + crewkerbals[i].name + " from frozen list failed " + ex); - } + Utilities.Log_Debug("Removing crew kerbal " + enumerator.Current.name + " from DeepFreeze List"); + DeepFreeze.Instance.DFgameSettings.KnownFrozenKerbals.Remove(enumerator.Current.name); + } + catch (Exception ex) + { + Utilities.Log("Removal of crew kerbal " + enumerator.Current.name + " from frozen list failed " + ex); } } + + i++; } + Utilities.Log("There are " + i + " crew Kerbals in the game roster."); + } internal void onVesselRename(GameEvents.HostedFromToAction fromToAction) @@ -651,7 +669,8 @@ internal void onVesselChange(Vessel vessel) //chk if current active vessel Has one or more DeepFreezer modules attached try { - if (!FlightGlobals.ActiveVessel.FindPartModulesImplementing().Any()) + DpFrzrActVsl = FlightGlobals.ActiveVessel.FindPartModulesImplementing(); + if (DpFrzrActVsl.Count == 0) { ActVslHasDpFrezr = false; } @@ -660,7 +679,7 @@ internal void onVesselChange(Vessel vessel) ActVslHasDpFrezr = true; DpFrzrActVsl = vessel.FindPartModulesImplementing(); //Check if vessel id has changed or last freezer cam transforms is now null, reset the freezer cams. - if (ActVslID != vessel.id || ActFrzrCams.Any()) + if (ActVslID != vessel.id || ActFrzrCams.Count > 0) { foreach (DeepFreezer frzr in DpFrzrActVsl) { @@ -673,7 +692,7 @@ internal void onVesselChange(Vessel vessel) } } ActVslID = FlightGlobals.ActiveVessel.id; - Utilities.Log_Debug("OnVesselChange ActVslID " + ActVslID + " HasFreezers " + ActVslHasDpFrezr + " FreezerCams Listed " + ActFrzrCams.Count()); + Utilities.Log_Debug("OnVesselChange ActVslID " + ActVslID + " HasFreezers " + ActVslHasDpFrezr + " FreezerCams Listed " + ActFrzrCams.Count); } catch (Exception ex) { @@ -764,7 +783,14 @@ private void CheckVslUpdate() try { if (AllVslsErrorCount < 5) - vessel = allVessels.FirstOrDefault(v => v.id == vesselId); + { + List.Enumerator enumerator = allVessels.GetEnumerator(); + while (enumerator.MoveNext()) + { + if (enumerator.Current.id == vesselId) + vessel = enumerator.Current; + } + } else continue; } @@ -795,7 +821,13 @@ private void CheckVslUpdate() { Utilities.Log("Removing entry as vessel has no frozen crew"); vesselsToDelete.Add(vesselId); - partsToDelete.AddRange(DeepFreeze.Instance.DFgameSettings.knownFreezerParts.Where(e => e.Value.vesselID == vesselId).Select(e => e.Key).ToList()); + foreach (var frzrpart in DeepFreeze.Instance.DFgameSettings.knownFreezerParts) + { + if (frzrpart.Value.vesselID == vesselId) + { + partsToDelete.Add(frzrpart.Key); + } + } continue; } } @@ -803,18 +835,30 @@ private void CheckVslUpdate() { Utilities.Log_Debug("Deleting vessel " + vesselInfo.vesselName + " - vessel does not exist anymore"); vesselsToDelete.Add(vesselId); - partsToDelete.AddRange(DeepFreeze.Instance.DFgameSettings.knownFreezerParts.Where(e => e.Value.vesselID == vesselId).Select(e => e.Key).ToList()); + foreach (var frzrpart in DeepFreeze.Instance.DFgameSettings.knownFreezerParts) + { + if (frzrpart.Value.vesselID == vesselId) + { + partsToDelete.Add(frzrpart.Key); + } + } continue; } if (vessel.loaded) { UpdateVesselInfo(vesselInfo, vessel, currentTime); crewCapacity = UpdateVesselCounts(vesselInfo, vessel, currentTime); - if (!vessel.FindPartModulesImplementing().Any()) + if (vessel.FindPartModulesImplementing().Count == 0) { Utilities.Log_Debug("Deleting vessel " + vesselInfo.vesselName + " - no freezer parts anymore"); vesselsToDelete.Add(vesselId); - partsToDelete.AddRange(DeepFreeze.Instance.DFgameSettings.knownFreezerParts.Where(e => e.Value.vesselID == vesselId).Select(e => e.Key).ToList()); + foreach (var frzrpart in DeepFreeze.Instance.DFgameSettings.knownFreezerParts) + { + if (frzrpart.Value.vesselID == vesselId) + { + partsToDelete.Add(frzrpart.Key); + } + } } else { @@ -859,7 +903,7 @@ private void CheckVslUpdate() // Scan through all in-game vessels and add any new ones we don't know about that have a freezer module. foreach (Vessel vessel in FlightGlobals.VesselsLoaded) { - if (!knownVessels.ContainsKey(vessel.id) && vessel.FindPartModulesImplementing().Any()) + if (!knownVessels.ContainsKey(vessel.id) && vessel.FindPartModulesImplementing().Count > 0) { Utilities.Log("New vessel: " + vessel.vesselName + " (" + vessel.id + ")"); vesselInfo.vesselName = vessel.vesselName; @@ -875,7 +919,12 @@ private void UpdatePredictedVesselEC(VesselInfo vesselInfo, Vessel vessel, doubl { double ECreqdsincelastupdate = 0f; int frznChargeRequired = 0; - List> DpFrzrVsl = DeepFreeze.Instance.DFgameSettings.knownFreezerParts.Where(p => p.Value.vesselID == vessel.id).ToList(); + List> DpFrzrVsl = new List>(); + foreach (var frzrpart in DeepFreeze.Instance.DFgameSettings.knownFreezerParts) + { + if (frzrpart.Value.vesselID == vessel.id) + DpFrzrVsl.Add(frzrpart); + } for (int i = 0; i < DpFrzrActVsl.Count; i++) { //calculate the predicated time EC will run out @@ -992,9 +1041,9 @@ private int UpdateVesselCounts(VesselInfo vesselInfo, Vessel vessel, double curr crewCapacity += freezer.FreezerSize; vesselInfo.numSeats += freezer.FreezerSize; vesselInfo.numCrew += vessel.parts[i].protoModuleCrew.Count; - vesselInfo.numFrznCrew += freezer.DFIStoredCrewList.Count(); + vesselInfo.numFrznCrew += freezer.DFIStoredCrewList.Count; // Utilities.Log_Debug("numcrew:" + part.protoModuleCrew.Count + " numfrzncrew:" + freezer.DFIStoredCrewList.Count()); - if (vessel.parts[i].protoModuleCrew.Count > 0 || freezer.DFIStoredCrewList.Any()) + if (vessel.parts[i].protoModuleCrew.Count > 0 || freezer.DFIStoredCrewList.Count > 0) { ++vesselInfo.numOccupiedParts; } @@ -1073,7 +1122,13 @@ private void CheckKACAlarmsUpdate() foreach (var entry in DeepFreeze.Instance.DFgameSettings.knownKACAlarms) { Utilities.Log_Debug("knownKACAlarms id = " + entry.Key + " Name = " + entry.Value.Name); - KACWrapper.KACAPI.KACAlarm alarm = KACWrapper.KAC.Alarms.FirstOrDefault(a => a.ID == entry.Key); + KACWrapper.KACAPI.KACAlarm alarm = null; + List.Enumerator enumerator = KACWrapper.KAC.Alarms.GetEnumerator(); + while (enumerator.MoveNext()) + { + if (enumerator.Current.ID == entry.Key) + alarm = enumerator.Current; + } if (alarm == null && entry.Value.AlarmExecute == false) //Alarm not known to KAC any more and not still executing so delete it. { Utilities.Log_Debug("Alarm not known to KAC any more so deleting"); @@ -1129,12 +1184,19 @@ private void CheckKACAlarmsUpdate() // First we find the ThwKerbal part and if they are still on-board frozen. // Then check the part isn't busy already and start the thaw process. bool Found = false; - string thwkerbalname = entry.Value.ThwKerbals.FirstOrDefault(); + string thwkerbalname = entry.Value.ThwKerbals[0]; Utilities.Log_Debug("Executing alarm for vessel " + entry.Value.Name + " looking to thaw crewmember " + thwkerbalname + " finding the part"); foreach (DeepFreezer frzr in DpFrzrActVsl) { // Check if they are in the frozen list for this part or not? - if (frzr.DFIStoredCrewList.FirstOrDefault(a => a.CrewName == thwkerbalname) != null) + FrznCrewMbr tmpcrew = null; + List.Enumerator enumerator2 = frzr.DFIStoredCrewList.GetEnumerator(); + while (enumerator2.MoveNext()) + { + if (enumerator2.Current.CrewName == thwkerbalname) + tmpcrew = enumerator2.Current; + } + if (tmpcrew != null) { //They are in this part. Found = true; @@ -1181,8 +1243,14 @@ private void CheckKACAlarmsUpdate() // Then check the part isn't busy already and start the freeze process. bool Found = false; List vslcrew = FlightGlobals.ActiveVessel.GetVesselCrew(); - string frzkerbalname = entry.Value.FrzKerbals.FirstOrDefault(); - ProtoCrewMember crewmember = vslcrew.FirstOrDefault(c => c.name == frzkerbalname); + string frzkerbalname = entry.Value.FrzKerbals[0]; + ProtoCrewMember crewmember = null; + List.Enumerator enumerator3 = vslcrew.GetEnumerator(); + while (enumerator3.MoveNext()) + { + if (enumerator3.Current.name == frzkerbalname) + crewmember = enumerator3.Current; + } if (crewmember == null) { //They aren't in the vessel any more. So delete this thaw and move on. diff --git a/Source/DFSettings.cs b/Source/DFSettings.cs index 4723699..b4a3705 100644 --- a/Source/DFSettings.cs +++ b/Source/DFSettings.cs @@ -259,7 +259,7 @@ internal void ApplySettings() { EditorFilter = DF_SettingsParms_Sec3.EditorFilter; if (DFEditorFilter.Instance != null) - DFEditorFilter.Instance.Setup(EditorFilter); + DFEditorFilter.Instance.Setup(); } } else diff --git a/Source/DeepFreeze.cs b/Source/DeepFreeze.cs index d6af840..d9280b9 100644 --- a/Source/DeepFreeze.cs +++ b/Source/DeepFreeze.cs @@ -128,7 +128,7 @@ public override void OnLoad(ConfigNode gameNode) } if (HighLogic.LoadedScene == GameScenes.SPACECENTER) { - DFEditorFilter.Instance.Setup(DFsettings.EditorFilter); + DFEditorFilter.Instance.Setup(); } Utilities.debuggingOn = DFsettings.debugging; APIReady = true; @@ -376,6 +376,7 @@ internal void KillFrozenCrew(string FrozenCrew) Utilities.Log("DeepFreezeEvents " + kerbal.name + " killed"); kerbal.type = ProtoCrewMember.KerbalType.Crew; kerbal.rosterStatus = ProtoCrewMember.RosterStatus.Dead; + RSTKSPGameEvents.RSTEvents.onFrozenKerbalDied.Fire(kerbal); if (HighLogic.CurrentGame.Parameters.Difficulty.MissingCrewsRespawn) { kerbal.StartRespawnPeriod(); @@ -388,17 +389,18 @@ internal void KillFrozenCrew(string FrozenCrew) ProtoCrewMember crew = HighLogic.CurrentGame.CrewRoster.Tourist.FirstOrDefault(a => a.name == FrozenCrew); if (crew != null) { - Utilities.Log("DeepFreezeEvents " + kerbal.name + " killed"); - kerbal.type = ProtoCrewMember.KerbalType.Crew; - kerbal.rosterStatus = ProtoCrewMember.RosterStatus.Dead; + Utilities.Log("DeepFreezeEvents " + crew.name + " killed"); + crew.type = ProtoCrewMember.KerbalType.Crew; + crew.rosterStatus = ProtoCrewMember.RosterStatus.Dead; + RSTKSPGameEvents.RSTEvents.onFrozenKerbalDied.Fire(crew); if (HighLogic.CurrentGame.Parameters.Difficulty.MissingCrewsRespawn) { - kerbal.StartRespawnPeriod(); - Utilities.Log("DeepFreezeEvents " + kerbal.name + " respawn started."); + crew.StartRespawnPeriod(); + Utilities.Log("DeepFreezeEvents " + crew.name + " respawn started."); } } else - Utilities.Log("DeepFreezeEvents " + kerbal.name + " couldn't find them to kill them."); + Utilities.Log("DeepFreezeEvents " + crew.name + " couldn't find them to kill them."); } } @@ -409,6 +411,7 @@ internal bool setComatoseKerbal(Part part, ProtoCrewMember crew, ProtoCrewMember if (start) { crew.UnregisterExperienceTraits(part); + RSTKSPGameEvents.RSTEvents.onKerbalSetComatose.Fire(part, crew); } crew.type = type; @@ -424,6 +427,7 @@ internal bool setComatoseKerbal(Part part, ProtoCrewMember crew, ProtoCrewMember KerbalRoster.SetExperienceTrait(crew, "Tourist"); } crew.RegisterExperienceTraits(part); + RSTKSPGameEvents.RSTEvents.onKerbalUnSetComatose.Fire(part, crew); ScreenMessages.PostScreenMessage( crew.name + " has recovered from emergency thaw and resumed normal duties.", 5.0f, ScreenMessageStyle.UPPER_CENTER); diff --git a/Source/DeepFreeze.csproj b/Source/DeepFreeze.csproj index 1236eed..ec1a0cf 100644 --- a/Source/DeepFreeze.csproj +++ b/Source/DeepFreeze.csproj @@ -40,6 +40,9 @@ False ..\..\KSPDLLs - 1.2\Assembly-CSharp.dll + + ..\..\REPOSoftTechKSPUtils\RSTKSPGameEvents\bin\Debug\RSTKSPGameEvents.dll + diff --git a/Source/DeepFreezeGUI.cs b/Source/DeepFreezeGUI.cs index 003eecf..a706127 100644 --- a/Source/DeepFreezeGUI.cs +++ b/Source/DeepFreezeGUI.cs @@ -88,6 +88,7 @@ internal class DeepFreezeGUI : MonoBehaviour, Savable private double switchVesselManualTimer; internal bool chgECHeatsettings; internal double chgECHeatsettingsTimer; + private bool switchNextUpdate = false; public bool Useapplauncher; private double currentTime; @@ -129,6 +130,8 @@ internal void Start() DFvslLstUpd = Mathf.Round((DFWINDOW_WIDTH - 28f) * .18f); DFvslRT = Mathf.Round((DFWINDOW_WIDTH - 28f) * .12f); + Useapplauncher = DeepFreeze.Instance.DFsettings.UseAppLauncher; + Utilities.setScaledScreen(); DFMenuAppLToolBar = new AppLauncherToolBar("DeepFreeze", "DeepFreeze", @@ -141,7 +144,7 @@ internal void Start() GameScenes.FLIGHT, GameScenes.EDITOR, GameScenes.SPACECENTER, GameScenes.TRACKSTATION); //If Settings wants to use ToolBar mod, check it is installed and available. If not set the TST Setting to use Stock. - if (!ToolbarManager.ToolbarAvailable && Useapplauncher) + if (!ToolbarManager.ToolbarAvailable && !Useapplauncher) { Useapplauncher = true; } @@ -165,6 +168,37 @@ private void FixedUpdate() } } + private void Update() + { + if (switchNextUpdate) + { + //Jump to vessel code here. + switchNextUpdate = false; + int intVesselidx = Utilities.getVesselIdx(switchVessel); + if (intVesselidx < 0) + { + Utilities.Log("Couldn't find the index for the vessel " + switchVessel.vesselName + "(" + + switchVessel.id + ")"); + showUnabletoSwitchVessel = true; + } + else + { + + if (HighLogic.LoadedSceneIsFlight) + { + FlightGlobals.SetActiveVessel(switchVessel); + } + else + { + String strret = GamePersistence.SaveGame("DFJumpToShip", HighLogic.SaveFolder, + SaveMode.OVERWRITE); + Game tmpGame = GamePersistence.LoadGame(strret, HighLogic.SaveFolder, false, false); + FlightDriver.StartAndFocusVessel(tmpGame, intVesselidx); + } + } + } + } + #region GUI private void OnGUI() @@ -864,7 +898,7 @@ private void windowVS(int id) TimeWarp.SetRate(0, true); if (HighLogic.LoadedSceneIsFlight && FlightGlobals.ready && !FlightDriver.Pause) FlightDriver.SetPause(true); - + GUILayout.BeginVertical(); GUILayout.BeginHorizontal(); //GUILayout.Box(new GUIContent("ElectricCharge is running out on vessel, you must switch to the vessel now.", "Switch to DeepFreeze vessel required"), statusStyle, GUILayout.Width(280)); @@ -877,26 +911,7 @@ private void windowVS(int id) showSwitchVessel = false; if (HighLogic.LoadedSceneIsFlight && FlightGlobals.ready) FlightDriver.SetPause(false); - //Jump to vessel code here. - int intVesselidx = Utilities.getVesselIdx(switchVessel); - if (intVesselidx < 0) - { - Utilities.Log("Couldn't find the index for the vessel " + switchVessel.vesselName + "(" + switchVessel.id + ")"); - showUnabletoSwitchVessel = true; - } - else - { - if (HighLogic.LoadedSceneIsFlight) - { - FlightGlobals.SetActiveVessel(switchVessel); - } - else - { - String strret = GamePersistence.SaveGame("DFJumpToShip", HighLogic.SaveFolder, SaveMode.OVERWRITE); - Game tmpGame = GamePersistence.LoadGame(strret, HighLogic.SaveFolder, false, false); - FlightDriver.StartAndFocusVessel(tmpGame, intVesselidx); - } - } + switchNextUpdate = true; } if (GUILayout.Button(new GUIContent("Not Now", "Don't switch vessel now"), GUILayout.Width(160))) { diff --git a/Source/DeepFreezerPart.cs b/Source/DeepFreezerPart.cs index dc0c0e0..84aee2c 100644 --- a/Source/DeepFreezerPart.cs +++ b/Source/DeepFreezerPart.cs @@ -18,9 +18,8 @@ using System; using System.Collections; using System.Collections.Generic; -using System.Linq; using DeepFreeze; -using KSP.UI.Screens.Flight; +using RSTKSPGameEvents; using RSTUtils; using UnityEngine; using Object = System.Object; @@ -582,28 +581,7 @@ public void Update() _prevexterndoorstate = _externaldoorstate; } } - // This is now handled by a coroutine callback. - //If a kerbal entered the part from EVA into a frozen kerbals seat then we moved them - // and now we wait IvaUpdateFrameDelay frames to refresh the portraits - /* - if (IvaUpdateActive) - { - Utilities.Log_Debug("IvaUpdateActive delay counter=" + IvaPortraitDelay); - if (IvaPortraitDelay >= IvaUpdateFrameDelay) - { - IvaUpdateActive = false; - IvaPortraitDelay = 0; - vessel.SpawnCrew(); - resetFrozenKerbals(); - onvslchgInternal = true; - GameEvents.onVesselChange.Fire(vessel); - } - else - { - IvaPortraitDelay += 1; - } - } - */ + //Refresh IVA mode Messages and Bools if (IVAKerbalName != null) ScreenMessages.RemoveMessage(IVAKerbalName); if (IVAkerbalPart != null) ScreenMessages.RemoveMessage(IVAkerbalPart); @@ -618,7 +596,13 @@ public void Update() { if (Utilities.ActiveKerbalIsLocal(part)) { - ProtoCrewMember crew = part.protoModuleCrew.FirstOrDefault(a => a.name == CameraManager.Instance.IVACameraActiveKerbal.name); + ProtoCrewMember crew = null; + List.Enumerator enumerator = part.protoModuleCrew.GetEnumerator(); + while (enumerator.MoveNext()) + { + if (enumerator.Current.name == CameraManager.Instance.IVACameraActiveKerbal.name) + crew = enumerator.Current; + } int SeatIndx = -1; if (crew != null) { @@ -769,7 +753,7 @@ private void processRPMPodSettingsPartHasDoor(string transparentPodSetting) anim["DOORHandle"].normalizedTime = 1; anim.Play("DOORHandle"); } - ext_door.Play(); + //ext_door.Play(); } catch (Exception ex) { @@ -881,9 +865,9 @@ private void RPMPodOccluderProcessing() { if (transparentPodSetting == "ON") { - if (_externaldoorstate == DoorState.CLOSED || - _externaldoorstate == DoorState.CLOSING || - _externaldoorstate == DoorState.OPENING) + if (_externaldoorstate == DoorState.CLOSED)// || + //_externaldoorstate == DoorState.CLOSING || + //_externaldoorstate == DoorState.OPENING) //If the Door is Closed, closing or opening { //If Stock Overlay is on we turn the Occluder OFF so we can see inside. @@ -1431,7 +1415,11 @@ public override void OnStart(StartState state) //Set Shaders for changing the Crypod Windows HashSet shaders = new HashSet(); - Resources.FindObjectsOfTypeAll().ToList().ForEach(sh => shaders.Add(sh)); + var sh = Resources.FindObjectsOfTypeAll(); + for (int i = 0; i < sh.Length; ++i) + { + shaders.Add(sh[i]); + } List listshaders = new List(shaders); TransparentSpecularShader = listshaders.Find(a => a.name == "Legacy Shaders/Transparent/Specular"); KSPSpecularShader = listshaders.Find(b => b.name == "KSP/Specular"); @@ -1507,7 +1495,12 @@ public override void OnStart(StartState state) //If we have an external door (CRY-0300) check if RPM is installed, if not disable the door, otherwise set it's current state (open/closed). if (animationName != string.Empty && PartHasDoor) { - externalDoorAnim = part.FindModelAnimators(animationName).FirstOrDefault(); + externalDoorAnim = null; + var Dooranims = part.FindModelAnimators(animationName); + if (Dooranims.Length > 0) + { + externalDoorAnim = Dooranims[0]; + } if (externalDoorAnim == null) { Utilities.Log_Debug("Part has external animation defined but cannot find the animation on the part"); @@ -1521,7 +1514,12 @@ public override void OnStart(StartState state) { if (part.internalModel != null) { - externalDoorAnimOccluder = part.internalModel.FindModelAnimators(animationName).FirstOrDefault(); + externalDoorAnimOccluder = null; + var anims = part.internalModel.FindModelAnimators(animationName); + if (anims.Length > 0) + { + externalDoorAnimOccluder = anims[0]; + } } else { @@ -1611,7 +1609,14 @@ private void UpdateEvents() { string crewname = ""; crewname = subStrings[1] + " " + subStrings[2]; - if (part.protoModuleCrew.FirstOrDefault(a => a.name == crewname) == null) // Search the part for the crewmember. + ProtoCrewMember crew = null; + List.Enumerator enumerator = part.protoModuleCrew.GetEnumerator(); + while (enumerator.MoveNext()) + { + if (enumerator.Current.name == crewname) + crew = enumerator.Current; + } + if (crew == null) // Search the part for the crewmember. // We didn't find the crewmember so remove the Freeze Event. { eventsToDelete.Add(itemX); @@ -2158,6 +2163,7 @@ private void FreezeKerbalConfirm(ProtoCrewMember CrewMember) ScreenMessages.PostScreenMessage(CrewMember.name + " frozen", 5.0f, ScreenMessageStyle.UPPER_CENTER); onvslchgInternal = true; + RSTEvents.onKerbalFrozen.Fire(this.part, CrewMember); CrewHatchController.fetch.EnableInterface(); GameEvents.onVesselChange.Fire(vessel); GameEvents.onVesselWasModified.Fire(vessel); @@ -2196,26 +2202,7 @@ private void KBDisableKerbal(string crewmember, bool disable) Debug.Log("DeepFreeze has been unable to connect to Kerbalism mod. API is not ready. Report this error on the Forum Thread."); } } - - private void USIUntrackVessel(string vesselId) - //This will remove tracking of a frozen kerbal from USI Life Support MOD, so that they don't consume resources when they are thawed. - { - if (USIWrapper.APIReady && USIWrapper.InstanceExists) - { - USIWrapper.USIActualAPI.UntrackVessel(vesselId); - bool checkTracked = USIWrapper.USIActualAPI.IsVesselTracked(vesselId); - if (checkTracked) - { - Debug.Log("DeepFreeze has been unable to untrack vessel " + vesselId + " in USI LS mod. Report this error on the Forum Thread."); - } - - } - else - { - Debug.Log("DeepFreeze has been unable to connect to USI LS mod. API is not ready. Report this error on the Forum Thread."); - } - } - + #endregion FrzKerbals #region ThwKerbals @@ -2439,7 +2426,13 @@ public void beginThawKerbal(string frozenkerbal) private void ThawKerbalStep0(string frozenkerbal) { // First we find out Unowned Crewmember in the roster. - ProtoCrewMember kerbal = HighLogic.CurrentGame.CrewRoster.Unowned.FirstOrDefault(a => a.name == frozenkerbal); + ProtoCrewMember kerbal = null; + IEnumerator enumerator = HighLogic.CurrentGame.CrewRoster.Unowned.GetEnumerator(); + while (enumerator.MoveNext()) + { + if (enumerator.Current.name == frozenkerbal) + kerbal = enumerator.Current; + } if (kerbal != null) { // Set our newly thawed Popsicle, er Kerbal, to Crew type again (from Unowned) and Assigned status (from Dead status). @@ -2448,7 +2441,13 @@ private void ThawKerbalStep0(string frozenkerbal) kerbal.rosterStatus = ProtoCrewMember.RosterStatus.Assigned; Utilities.Log_Debug("find the stored crew member"); //Now we find our Crewmember in the stored crew list in the part. - FrznCrewMbr tmpcrew = _StoredCrewList.Find(a => a.CrewName == frozenkerbal); // Find the thawed kerbal in the frozen kerbal list. + FrznCrewMbr tmpcrew = null; // Find the thawed kerbal in the frozen kerbal list. + List.Enumerator enumerator2 = _StoredCrewList.GetEnumerator(); + while (enumerator2.MoveNext()) + { + if (enumerator2.Current.CrewName == frozenkerbal) + tmpcrew = enumerator2.Current; + } if (tmpcrew != null) { //check if seat is empty, if it is we have to seat them in next available seat @@ -2681,7 +2680,13 @@ private void ThawKerbalAbort(String ThawKerbal) OpenPodAnimPlaying = false; ThawWindowAnimPlaying = false; ThawStepInProgress = 0; - ProtoCrewMember kerbal = HighLogic.CurrentGame.CrewRoster.Crew.FirstOrDefault(a => a.name == ThawKerbal); + ProtoCrewMember kerbal = null; + IEnumerator enumerator = HighLogic.CurrentGame.CrewRoster.Crew.GetEnumerator(); + while (enumerator.MoveNext()) + { + if (enumerator.Current.name == ThawKerbal) + kerbal = enumerator.Current; + } if (!RemoveKerbal(kerbal, ToThawKerbalSeat)) // remove the CrewMember from the part, because they are frozen, and this is the only way to trick the game. { Debug.Log("ThawKerbalAbort Procedure FAILED! Critical error"); @@ -2720,9 +2725,14 @@ private void ThawKerbalStep4(String frozenkerbal) Utilities.Log_Debug("ThawKerbalConfirm start for " + frozenkerbal); machine_hum.Stop(); //stop sound effects StoredCharge = 0; // Discharge all EC stored - - ProtoCrewMember kerbal = HighLogic.CurrentGame.CrewRoster.Crew.FirstOrDefault(a => a.name == frozenkerbal); - + + ProtoCrewMember kerbal = null; + IEnumerator enumerator = HighLogic.CurrentGame.CrewRoster.Crew.GetEnumerator(); + while (enumerator.MoveNext()) + { + if (enumerator.Current.name == frozenkerbal) + kerbal = enumerator.Current; + } if (!AddKerbal(kerbal, ToThawKerbalSeat)) { ThawKerbalAbort(frozenkerbal); @@ -2805,6 +2815,7 @@ private void ThawKerbalStep4(String frozenkerbal) } } CrewHatchController.fetch.EnableInterface(); + RSTEvents.onKerbalThaw.Fire(this.part, kerbal); GameEvents.onVesselChange.Fire(vessel); GameEvents.onVesselWasModified.Fire(vessel); Utilities.Log_Debug("ThawKerbalConfirm End"); @@ -2818,7 +2829,13 @@ private bool RemoveKerbal(ProtoCrewMember kerbal, int SeatIndx) try { Utilities.Log_Debug("RemoveKerbal " + kerbal.name + " seat " + SeatIndx); - FrznCrewMbr tmpcrew = _StoredCrewList.Find(a => a.CrewName == kerbal.name); // Find the thawed kerbal in the frozen kerbal list. + FrznCrewMbr tmpcrew = null; + List.Enumerator enumerator = _StoredCrewList.GetEnumerator(); + while (enumerator.MoveNext()) + { + if (enumerator.Current.CrewName == kerbal.name) + tmpcrew = enumerator.Current; + } if (tmpcrew == null) { FrznCrewMbr frzncrew = new FrznCrewMbr(kerbal.name, SeatIndx, vessel.id, vessel.name); @@ -2906,8 +2923,14 @@ private bool AddKerbal(ProtoCrewMember kerbal, int SeatIndx) { try { - FrznCrewMbr tmpcrew = _StoredCrewList.Find(a => a.CrewName == kerbal.name); // Find the thawed kerbal in the frozen kerbal list. - if (_StoredCrewList.Contains(tmpcrew)) + FrznCrewMbr tmpcrew = null; // Find the thawed kerbal in the frozen kerbal list. + List.Enumerator enumerator = _StoredCrewList.GetEnumerator(); + while (enumerator.MoveNext()) + { + if (enumerator.Current.CrewName == kerbal.name) + tmpcrew = enumerator.Current; + } + if (tmpcrew != null) { Utilities.Log_Debug("Removing _StoredCrewList entry"); _StoredCrewList.Remove(tmpcrew); @@ -3175,14 +3198,24 @@ private void onVesselDestroy(Vessel vessel) internal void resetFrozenPortraits() { // create a list of kerbal that are in this part in this vessel & they are not comatose/tourist - List> FrznKerbalsinPart = - DeepFreeze.Instance.DFgameSettings.KnownFrozenKerbals.Where( - e => - e.Value.partID == CrntPartID && e.Value.vesselID == CrntVslID && - e.Value.type != ProtoCrewMember.KerbalType.Tourist).ToList(); + List> FrznKerbalsinPart = new List>(); + foreach (var frznKerbal in DeepFreeze.Instance.DFgameSettings.KnownFrozenKerbals) + { + if (frznKerbal.Value.partID == CrntPartID && frznKerbal.Value.vesselID == CrntVslID && + frznKerbal.Value.type != ProtoCrewMember.KerbalType.Tourist) + { + FrznKerbalsinPart.Add(frznKerbal); + } + } for (int i = 0; i < FrznKerbalsinPart.Count; i++) { - ProtoCrewMember crewmember = HighLogic.CurrentGame.CrewRoster.Unowned.FirstOrDefault(a => a.name == FrznKerbalsinPart[i].Key); + ProtoCrewMember crewmember = null; + IEnumerator enumerator = HighLogic.CurrentGame.CrewRoster.Unowned.GetEnumerator(); + while (enumerator.MoveNext()) + { + if (enumerator.Current.name == FrznKerbalsinPart[i].Key) + crewmember = enumerator.Current; + } if (crewmember != null) { DFPortraits.DestroyPortrait(crewmember.KerbalRef); @@ -3195,12 +3228,29 @@ internal void resetFrozenKerbals() try { // Create a list of kerbals that are in Invalid Seats (SeatIndx == -1 where kerbal is in this part in this vessel & they are not comatose/tourist - List> kerbalsInvSeats = DeepFreeze.Instance.DFgameSettings.KnownFrozenKerbals.Where(e => e.Value.partID == CrntPartID && e.Value.vesselID == CrntVslID && e.Value.type != ProtoCrewMember.KerbalType.Tourist && e.Value.seatIdx == -1).ToList(); + List> kerbalsInvSeats = new List>(); + foreach (var frznKerbal in DeepFreeze.Instance.DFgameSettings.KnownFrozenKerbals) + { + if (frznKerbal.Value.partID == CrntPartID && frznKerbal.Value.vesselID == CrntVslID && + frznKerbal.Value.type != ProtoCrewMember.KerbalType.Tourist && frznKerbal.Value.seatIdx == -1) + { + kerbalsInvSeats.Add(frznKerbal); + } + } + // create a list of kerbal that are in this part in this vessel & they are not comatose/tourist - List> FrznKerbalsinPart = DeepFreeze.Instance.DFgameSettings.KnownFrozenKerbals.Where(e => e.Value.partID == CrntPartID && e.Value.vesselID == CrntVslID && e.Value.type != ProtoCrewMember.KerbalType.Tourist).ToList(); + List> FrznKerbalsinPart = new List>(); + foreach (var frznKerbal in DeepFreeze.Instance.DFgameSettings.KnownFrozenKerbals) + { + if (frznKerbal.Value.partID == CrntPartID && frznKerbal.Value.vesselID == CrntVslID && + frznKerbal.Value.type != ProtoCrewMember.KerbalType.Tourist) + { + FrznKerbalsinPart.Add(frznKerbal); + } + } //If we found any Invalid Seat assignments we need to find them empty seats - if (kerbalsInvSeats.Any()) + if (kerbalsInvSeats.Count > 0) { bool[] seatIndxs = new bool[FreezerSize]; //Create a bool array to store whether seats are taken or not //go through all the frozen kerbals in the part that don't have invalid seats and set bool array seat index to true (taken) for each @@ -3236,7 +3286,14 @@ internal void resetFrozenKerbals() { //Check if they are in the _StoredCrewList and if they aren't Add them in. FrznCrewMbr fzncrew = new FrznCrewMbr(kerbal.Key, kerbal.Value.seatIdx, CrntVslID, CrntVslName); - FrznCrewMbr tmpcrew = _StoredCrewList.Find(a => a.CrewName == kerbal.Key); + FrznCrewMbr tmpcrew = null; // Find the thawed kerbal in the frozen kerbal list. + List.Enumerator enumerator2 = _StoredCrewList.GetEnumerator(); + while (enumerator2.MoveNext()) + { + if (enumerator2.Current.CrewName == kerbal.Key) + tmpcrew = enumerator2.Current; + } + if (tmpcrew == null) { //add them to our storedcrewlist for this part. @@ -3245,7 +3302,13 @@ internal void resetFrozenKerbals() } //check if they are in the part and spawned, if not do so. - ProtoCrewMember crewmember = HighLogic.CurrentGame.CrewRoster.Unowned.FirstOrDefault(a => a.name == kerbal.Key); + ProtoCrewMember crewmember = null; + IEnumerator enumerator = HighLogic.CurrentGame.CrewRoster.Unowned.GetEnumerator(); + while (enumerator.MoveNext()) + { + if (enumerator.Current.name == kerbal.Key) + crewmember = enumerator.Current; + } if (crewmember != null) { if (partHasInternals) @@ -3301,8 +3364,15 @@ internal void resetFrozenKerbals() private void onCrewTransferred(GameEvents.HostedFromToAction HostedFromTo) { - if (HostedFromTo.to == part && HostedFromTo.from.Modules.Cast().Any(x => x is KerbalEVA) && - PartFull) + bool fromEVA = false; + for (int i = 0; i < HostedFromTo.from.Modules.Count; ++i) + { + if (HostedFromTo.from.Modules[i] as KerbalEVA) + { + fromEVA = true; + } + } + if (fromEVA && PartFull) { Utilities.Log_Debug("DeepFreezer EVA kerbal tried to enter a FULL Freezer part, so we kick them out"); if (ExternalDoorActive) @@ -3358,7 +3428,13 @@ private void UpdateCounts() seatTakenbyFrznKerbal[_StoredCrewList[i].SeatIdx] = true; setCryopodWindowSpecular(_StoredCrewList[i].SeatIdx); - ProtoCrewMember kerbal = HighLogic.CurrentGame.CrewRoster.Unowned.FirstOrDefault(a => a.name == _StoredCrewList[i].CrewName); + ProtoCrewMember kerbal = null; + IEnumerator enumerator = HighLogic.CurrentGame.CrewRoster.Unowned.GetEnumerator(); + while (enumerator.MoveNext()) + { + if (enumerator.Current.name == _StoredCrewList[i].CrewName) + kerbal = enumerator.Current; + } if (kerbal == null) { Utilities.Log("DeepFreezer Frozen Kerbal " + _StoredCrewList[i].CrewName + " is not found in the currentgame.crewroster.unowned, this should never happen"); @@ -3427,7 +3503,12 @@ private void savecryopodstatepersistent() try { cryopodstateclosedstring = string.Empty; - cryopodstateclosedstring = string.Join(", ", cryopodstateclosed.Select(b => b.ToString()).ToArray()); + string[] tmpCryopodstateclosedarray = new string[cryopodstateclosed.Length]; + for (int i = 0; i < cryopodstateclosed.Length; i++) + { + tmpCryopodstateclosedarray[i] = cryopodstateclosed[i].ToString(); + } + cryopodstateclosedstring = string.Join(", ", tmpCryopodstateclosedarray); //Debug.Log("Save cryopodstatepersistent value " + cryopodstateclosedstring); } catch (Exception ex) diff --git a/Source/KerbalPortraits.cs b/Source/KerbalPortraits.cs index f936c6a..cc44597 100644 --- a/Source/KerbalPortraits.cs +++ b/Source/KerbalPortraits.cs @@ -1,7 +1,19 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; +/** + * DeepFreeze Continued... + * (C) Copyright 2015, Jamie Leighton + * + * Kerbal Space Program is Copyright (C) 2013 Squad. See http://kerbalspaceprogram.com/. This + * project is in no way associated with nor endorsed by Squad. + * + * This file is part of JPLRepo's DeepFreeze (continued...) - a Fork of DeepFreeze. Original Author of DeepFreeze is 'scottpaladin' on the KSP Forums. + * This File was not part of the original Deepfreeze but was written by Jamie Leighton. + * (C) Copyright 2015, Jamie Leighton + * + * Continues to be licensed under the Attribution-NonCommercial-ShareAlike 3.0 (CC BY-NC-SA 4.0) + * creative commons license. See + * for full details. + * + */ using KSP.UI.Screens.Flight; using UnityEngine; @@ -11,18 +23,25 @@ namespace DeepFreeze [KSPAddon(KSPAddon.Startup.Flight, false)] class DFPortraits : MonoBehaviour { - - internal static BindingFlags eFlags = BindingFlags.Instance | BindingFlags.NonPublic; - internal static bool HasPortrait(Kerbal crew, bool checkName = false) { if (!checkName) { - return KerbalPortraitGallery.Instance.Portraits.Any(p => p.crewMember == crew); + for (int i = 0; i < KerbalPortraitGallery.Instance.Portraits.Count; ++i) + { + if (KerbalPortraitGallery.Instance.Portraits[i].crewMember == crew) + return true; + } + return false; } else { - return KerbalPortraitGallery.Instance.Portraits.Any(p => p.crewMemberName == crew.crewMemberName); + for (int i = 0; i < KerbalPortraitGallery.Instance.Portraits.Count; ++i) + { + if (KerbalPortraitGallery.Instance.Portraits[i].crewMemberName == crew.crewMemberName) + return true; + } + return false; } } @@ -30,11 +49,21 @@ internal static bool InActiveCrew(Kerbal crew, bool checkName = false) { if (!checkName) { - return KerbalPortraitGallery.Instance.ActiveCrew.Any(p => p == crew); + for (int i = 0; i < KerbalPortraitGallery.Instance.ActiveCrew.Count; ++i) + { + if (KerbalPortraitGallery.Instance.ActiveCrew[i] == crew) + return true; + } + return false; } else { - return KerbalPortraitGallery.Instance.ActiveCrew.Any(p => p.crewMemberName == crew.crewMemberName); + for (int i = 0; i < KerbalPortraitGallery.Instance.ActiveCrew.Count; ++i) + { + if (KerbalPortraitGallery.Instance.ActiveCrew[i].crewMemberName == crew.crewMemberName) + return true; + } + return false; } } diff --git a/Source/Properties/AssemblyInfo.cs b/Source/Properties/AssemblyInfo.cs index 500c5b9..471d6b8 100644 --- a/Source/Properties/AssemblyInfo.cs +++ b/Source/Properties/AssemblyInfo.cs @@ -31,6 +31,6 @@ // 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("0.23.0.0")] -[assembly: AssemblyFileVersion("0.23.0.0")] +[assembly: AssemblyVersion("0.23.1.0")] +[assembly: AssemblyFileVersion("0.23.1.0")] [assembly: KSPAssembly("DeepFreeze", 0, 23)] \ No newline at end of file diff --git a/Source/SettingsParms.cs b/Source/SettingsParms.cs index b379aeb..9bb101a 100644 --- a/Source/SettingsParms.cs +++ b/Source/SettingsParms.cs @@ -5,7 +5,7 @@ using System.Text; using UnityEngine; -namespace DeepFreeze +namespace DF { public class DeepFreeze_SettingsParms : GameParameters.CustomParameterNode @@ -44,34 +44,32 @@ public override void SetDifficultyPreset(GameParameters.Preset preset) switch (preset) { case GameParameters.Preset.Easy: - ECreqdForFreezer = false; - AutoRecoverFznKerbals = true; - KSCcostToThawKerbal = 5000f; - ECReqdToFreezeThaw = 1000; - GlykerolReqdToFreeze = 5; + this.ECreqdForFreezer = false; + this.AutoRecoverFznKerbals = true; + this.KSCcostToThawKerbal = 5000f; + this.ECReqdToFreezeThaw = 1000; + this.GlykerolReqdToFreeze = 5; break; case GameParameters.Preset.Normal: - ECreqdForFreezer = false; - AutoRecoverFznKerbals = true; - KSCcostToThawKerbal = 10000f; - ECReqdToFreezeThaw = 2000; - GlykerolReqdToFreeze = 5; + this.ECreqdForFreezer = false; + this.AutoRecoverFznKerbals = true; + this.KSCcostToThawKerbal = 10000f; + this.ECReqdToFreezeThaw = 2000; + this.GlykerolReqdToFreeze = 5; break; case GameParameters.Preset.Moderate: - ECreqdForFreezer = true; - AutoRecoverFznKerbals = false; - KSCcostToThawKerbal = 20000f; - ECReqdToFreezeThaw = 3000; - GlykerolReqdToFreeze = 10; + this.ECreqdForFreezer = true; + this.AutoRecoverFznKerbals = false; + this.KSCcostToThawKerbal = 20000f; + this.ECReqdToFreezeThaw = 3000; + this.GlykerolReqdToFreeze = 10; break; case GameParameters.Preset.Hard: - ECreqdForFreezer = true; - AutoRecoverFznKerbals = false; - KSCcostToThawKerbal = 30000f; - ECReqdToFreezeThaw = 4000; - GlykerolReqdToFreeze = 15; - break; - case GameParameters.Preset.Custom: + this.ECreqdForFreezer = true; + this.AutoRecoverFznKerbals = false; + this.KSCcostToThawKerbal = 30000f; + this.ECReqdToFreezeThaw = 4000; + this.GlykerolReqdToFreeze = 15; break; } } @@ -82,9 +80,7 @@ public override bool Enabled(MemberInfo member, GameParameters parameters) { if (HighLogic.LoadedSceneIsFlight) { - if (member.Name != "TempinKelvin" && member.Name != "StripLightsActive" && member.Name != "ToolTips" && - member.Name != "UseAppLToolbar" && member.Name != "DebugLogging") - return false; + return false; } } @@ -97,31 +93,21 @@ public override bool Interactible(MemberInfo member, GameParameters parameters) { if (HighLogic.LoadedSceneIsFlight) { - if (member.Name != "TempinKelvin" && member.Name != "StripLightsActive" && member.Name != "ToolTips" && - member.Name != "UseAppLToolbar" && member.Name != "DebugLogging") - return false; + return false; } } if (member.Name == "fatalOption") { - if (ECreqdForFreezer) - return true; - else - return false; + return parameters.CustomParams().ECreqdForFreezer; } if (member.Name == "comatoseTime") { - if (ECreqdForFreezer && !fatalOption) - return true; - else - return false; + return (parameters.CustomParams().ECreqdForFreezer && + !parameters.CustomParams().fatalOption); } if (member.Name == "KSCcostToThawKerbal") { - if (AutoRecoverFznKerbals) - return true; - else - return false; + return parameters.CustomParams().AutoRecoverFznKerbals; } return true; @@ -164,55 +150,34 @@ public override void SetDifficultyPreset(GameParameters.Preset preset) switch (preset) { case GameParameters.Preset.Easy: - RegTempReqd = false; + this.RegTempReqd = false; break; case GameParameters.Preset.Normal: - RegTempReqd = false; + this.RegTempReqd = false; break; case GameParameters.Preset.Moderate: - RegTempReqd = true; + this.RegTempReqd = true; break; case GameParameters.Preset.Hard: - RegTempReqd = true; - break; - case GameParameters.Preset.Custom: + this.RegTempReqd = true; break; } } - public override bool Enabled(MemberInfo member, GameParameters parameters) - { - if (HighLogic.fetch != null) - { - if (HighLogic.LoadedSceneIsFlight) - { - if (member.Name != "TempinKelvin" && member.Name != "StripLightsActive" && member.Name != "ToolTips" && - member.Name != "UseAppLToolbar" && member.Name != "DebugLogging") - return false; - } - } - - return true; - } - public override bool Interactible(MemberInfo member, GameParameters parameters) { if (HighLogic.fetch != null) { if (HighLogic.LoadedSceneIsFlight) { - if (member.Name != "TempinKelvin" && member.Name != "StripLightsActive" && member.Name != "ToolTips" && - member.Name != "UseAppLToolbar" && member.Name != "DebugLogging") + if (member.Name != "TempinKelvin") return false; } } if (member.Name == "RegTempFreeze" || member.Name == "RegTempMonitor" || member.Name == "heatamtMonitoringFrznKerbals" || member.Name == "heatamtThawFreezeKerbal") { - if (RegTempReqd) - return true; - else - return false; + return parameters.CustomParams().RegTempReqd; } return true; @@ -224,7 +189,7 @@ public class DeepFreeze_SettingsParms_Sec3 : GameParameters.CustomParameterNode { public override string Title { get { return "DeepFreeze Misc."; } } public override GameParameters.GameMode GameMode { get { return GameParameters.GameMode.ANY; } } - public override bool HasPresets { get { return true; } } + public override bool HasPresets { get { return false; } } public override string Section { get { return "DeepFreeze"; } } public override int SectionOrder { get { return 3; } } @@ -242,62 +207,14 @@ public class DeepFreeze_SettingsParms_Sec3 : GameParameters.CustomParameterNode [GameParameters.CustomParameterUI("Extra Debug Logging", toolTip = "Turn this On to capture lots of extra information\ninto the KSP log for reporting a problem.")] public bool DebugLogging = false; - - public override void SetDifficultyPreset(GameParameters.Preset preset) - { - Debug.Log("Setting difficulty preset"); - switch (preset) - { - case GameParameters.Preset.Easy: - - break; - case GameParameters.Preset.Normal: - - break; - case GameParameters.Preset.Moderate: - - break; - case GameParameters.Preset.Hard: - - break; - case GameParameters.Preset.Custom: - break; - } - } - - public override bool Enabled(MemberInfo member, GameParameters parameters) - { - if (HighLogic.fetch != null) - { - if (HighLogic.LoadedSceneIsFlight) - { - if (member.Name != "TempinKelvin" && member.Name != "StripLightsActive" && member.Name != "ToolTips" && - member.Name != "UseAppLToolbar" && member.Name != "DebugLogging") - return false; - } - } - - return true; - } - + public override bool Interactible(MemberInfo member, GameParameters parameters) { - if (HighLogic.fetch != null) - { - if (HighLogic.LoadedSceneIsFlight) - { - if (member.Name != "TempinKelvin" && member.Name != "StripLightsActive" && member.Name != "ToolTips" && - member.Name != "UseAppLToolbar" && member.Name != "DebugLogging") - return false; - } - } - if (member.Name == "UseAppLToolbar") { if (RSTUtils.ToolbarManager.ToolbarAvailable) return true; - else - return false; + return false; } return true; From 25571899d7404253eacdf8163d253d7f655410b1 Mon Sep 17 00:00:00 2001 From: Jamie Leighton Date: Thu, 3 Nov 2016 20:09:06 +1100 Subject: [PATCH 2/2] bump build and re-compile for KSP 1.2.1 --- Distribution/GameData/REPOSoftTech/DeepFreeze/Changelog.txt | 1 + .../REPOSoftTech/DeepFreeze/DeepFreezeContinued.version | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Distribution/GameData/REPOSoftTech/DeepFreeze/Changelog.txt b/Distribution/GameData/REPOSoftTech/DeepFreeze/Changelog.txt index 1a89152..246f4df 100644 --- a/Distribution/GameData/REPOSoftTech/DeepFreeze/Changelog.txt +++ b/Distribution/GameData/REPOSoftTech/DeepFreeze/Changelog.txt @@ -1,4 +1,5 @@ V0.23.1.0 +Compile for KSP 1.2.1 Fix Editor customer Filter for DeepFreeze parts. Fix problem with EC and Heat settings being disabled in new game difficulty settings. https://github.com/JPLRepo/DeepFreeze/issues/63 Fix problem with CRY-0300 Doors opening/closing with JSI Advanced Transparent Pods showing an empty Internal until fully open, unfortunately diff --git a/Distribution/GameData/REPOSoftTech/DeepFreeze/DeepFreezeContinued.version b/Distribution/GameData/REPOSoftTech/DeepFreeze/DeepFreezeContinued.version index 5c4ebd8..097f161 100644 --- a/Distribution/GameData/REPOSoftTech/DeepFreeze/DeepFreezeContinued.version +++ b/Distribution/GameData/REPOSoftTech/DeepFreeze/DeepFreezeContinued.version @@ -3,7 +3,7 @@ "URL":"http://ksp-avc.cybutek.net/version.php?id=183", "DOWNLOAD":"http://spacedock.info/mod/142/DeepFreeze%20Continued...", "VERSION":{"MAJOR":0,"MINOR":23,"PATCH":1,"BUILD":0}, -"KSP_VERSION":{"MAJOR":1,"MINOR":2,"PATCH":0}, +"KSP_VERSION":{"MAJOR":1,"MINOR":2,"PATCH":1}, "KSP_VERSION_MIN":{"MAJOR":1,"MINOR":2,"PATCH":0}, -"KSP_VERSION_MAX":{"MAJOR":1,"MINOR":2,"PATCH":0} +"KSP_VERSION_MAX":{"MAJOR":1,"MINOR":2,"PATCH":1} } \ No newline at end of file