Exemplo n.º 1
0
        internal static VesselInfo Load(ConfigNode node)
        {
            string vesselName = "Unknown";

            node.TryGetValue("vesselName", ref vesselName);
            double lastUpdate = 0f;

            node.TryGetValue("lastUpdate", ref lastUpdate);
            //string vesselName = Utilities.GetNodeValue(node, "vesselName", "Unknown");
            //double lastUpdate = Utilities.GetNodeValue(node, "lastUpdate", 0.0);

            VesselInfo info = new VesselInfo(vesselName, lastUpdate);

            node.TryGetValue("numSeats", ref info.numSeats);
            node.TryGetValue("numCrew", ref info.numCrew);
            node.TryGetValue("numOccupiedParts", ref info.numOccupiedParts);
            node.TryGetValue("numFrznCrew", ref info.numFrznCrew);
            node.TryGetValue("hibernating", ref info.hibernating);
            node.TryGetValue("hasextDoor", ref info.hasextDoor);
            node.TryGetValue("hasextPod", ref info.hasextPod);
            node.TryGetValue("storedEC", ref info.storedEC);
            node.TryGetValue("predictedECOut", ref info.predictedECOut);

            info.vesselType = Utilities.GetNodeValue(node, "vesselType", VesselType.Unknown);

            return(info);
        }
Exemplo n.º 2
0
        internal static VesselInfo Load(ConfigNode node)
        {
            string vesselName = "Unknown";
            node.TryGetValue("vesselName", ref vesselName);
            double lastUpdate = 0f;
            node.TryGetValue("lastUpdate", ref lastUpdate);
            //string vesselName = Utilities.GetNodeValue(node, "vesselName", "Unknown");
            //double lastUpdate = Utilities.GetNodeValue(node, "lastUpdate", 0.0);

            VesselInfo info = new VesselInfo(vesselName, lastUpdate);
            node.TryGetValue("numSeats", ref info.numSeats);
            node.TryGetValue("numCrew", ref info.numCrew);
            node.TryGetValue("numOccupiedParts", ref info.numOccupiedParts);
            node.TryGetValue("numFrznCrew", ref info.numFrznCrew);
            node.TryGetValue("hibernating", ref info.hibernating);
            node.TryGetValue("hasextDoor", ref info.hasextDoor);
            node.TryGetValue("hasextPod", ref info.hasextPod);
            node.TryGetValue("storedEC", ref info.storedEC);
            node.TryGetValue("predictedECOut", ref info.predictedECOut);

            info.vesselType = Utilities.GetNodeValue(node, "vesselType", VesselType.Unknown);

            return info;
        }
Exemplo n.º 3
0
        internal void Load(ConfigNode node)
        {
            KnownFrozenKerbals.Clear();
            knownVessels.Clear();
            knownFreezerParts.Clear();
            knownKACAlarms.Clear();

            if (node.HasNode(configNodeName))
            {
                ConfigNode DFsettingsNode = node.GetNode(configNodeName);
                DFsettingsNode.TryGetValue("Enabled", ref Enabled);

                KnownFrozenKerbals.Clear();
                var kerbalNodes = DFsettingsNode.GetNodes(KerbalInfo.ConfigNodeName);
                foreach (ConfigNode kerbalNode in kerbalNodes)
                {
                    if (kerbalNode.HasValue("kerbalName"))
                    {
                        string id = kerbalNode.GetValue("kerbalName");
                        Utilities.Log_Debug("DFGameSettings Loading kerbal = " + id);
                        KerbalInfo kerbalInfo = KerbalInfo.Load(kerbalNode);
                        KnownFrozenKerbals.Add(id, kerbalInfo);
                    }
                }
                Utilities.Log_Debug("DFGameSettings finished loading FrozenKerbals");
                knownVessels.Clear();
                var vesselNodes = DFsettingsNode.GetNodes(VesselInfo.ConfigNodeName);
                foreach (ConfigNode vesselNode in vesselNodes)
                {
                    if (vesselNode.HasValue("Guid"))
                    {
                        Guid id = new Guid(vesselNode.GetValue("Guid"));
                        Utilities.Log_Debug("DFGameSettings Loading Guid = " + id);
                        VesselInfo vesselInfo = VesselInfo.Load(vesselNode);
                        knownVessels[id] = vesselInfo;
                    }
                }
                Utilities.Log_Debug("DFGameSettings finished loading KnownVessels");
                knownFreezerParts.Clear();
                var partNodes = DFsettingsNode.GetNodes(PartInfo.ConfigNodeName);
                foreach (ConfigNode partNode in partNodes)
                {
                    if (partNode.HasValue("flightID"))
                    {
                        uint id = uint.Parse(partNode.GetValue("flightID"));
                        Utilities.Log_Debug("DFGameSettings Loading flightID = " + id);
                        PartInfo partInfo = PartInfo.Load(partNode);
                        knownFreezerParts[id] = partInfo;
                    }
                }
                Utilities.Log_Debug("DFGameSettings finished loading KnownParts");
                knownKACAlarms.Clear();
                var KACAlarmNodes = DFsettingsNode.GetNodes(AlarmInfo.ConfigNodeName);
                foreach (ConfigNode alarmNode in KACAlarmNodes)
                {
                    if (alarmNode.HasValue("alarmID"))
                    {
                        string alarmID = alarmNode.GetValue("alarmID");
                        Utilities.Log_Debug("DFGameSettings Loading alarmID = " + alarmID);
                        AlarmInfo alarmInfo = AlarmInfo.Load(alarmNode);
                        knownKACAlarms[alarmID] = alarmInfo;
                    }
                }
                SyncDictionaries();
            }
            Utilities.Log_Debug("DFGameSettings Loading Complete");
        }
Exemplo n.º 4
0
 private void Start()
 {
     Utilities.Log_Debug("DFIntMemory startup");
     ChkUnknownFrozenKerbals();
     ChkActiveFrozenKerbals();
     DeepFreeze.Instance.DFgameSettings.DmpKnownFznKerbals();
     resetFreezerCams();
     if (Utilities.GameModeisFlight)
     {
         if (DFInstalledMods.IsTexReplacerInstalled)
         {
             TRWrapper.InitTRWrapper();
         }
         if (DFInstalledMods.IsUSILSInstalled)
         {
             USIWrapper.InitUSIWrapper();
         }
         if (DFInstalledMods.IsSMInstalled)
         {
             SMWrapper.InitSMWrapper();
         }
     }
     if (DFInstalledMods.IsRTInstalled)
     {
         RTWrapper.InitTRWrapper();
     }
     currentTime = Planetarium.GetUniversalTime();
     lastFixedUpdateTime = currentTime;
     vesselInfo = new VesselInfo("testVessel", currentTime);
     partInfo = new PartInfo(Guid.Empty, "testPart", currentTime);
 }
Exemplo n.º 5
0
        private void UpdateVesselInfo(VesselInfo vesselInfo, Vessel vessel, double currentTime)
        {
            // Utilities.Log_Debug("UpdateVesselInfo " + vesselInfo.vesselName);
            vesselInfo.vesselType = vessel.vesselType;
            vesselInfo.lastUpdate = Planetarium.GetUniversalTime();
            vesselInfo.hibernating = false;
            vesselInfo.hasextDoor = false;
            vesselInfo.hasextPod = false;
            DpFrzrLoadedVsl.Clear();
            DpFrzrLoadedVsl = vessel.FindPartModulesImplementing<DeepFreezer>();
            foreach (DeepFreezer frzr in DpFrzrLoadedVsl)
            {
                // do we have a known part? If not add it
                if (!DeepFreeze.Instance.DFgameSettings.knownFreezerParts.TryGetValue(frzr.part.flightID, out partInfo))
                {
                    Utilities.Log("New Freezer Part: " + frzr.name + "(" + frzr.part.flightID + ")" + " (" + vessel.id + ")");
                    partInfo = new PartInfo(vessel.id, frzr.name, currentTime);
                    //partInfo.vesselID = vessel.id;
                    //partInfo.PartName = frzr.name;
                    partInfo.hibernating = false;
                    partInfo.ECWarning = false;
                    partInfo.TempWarning = false;
                    partInfo.lastUpdate = currentTime;
                    partInfo.crewMembers.Clear();
                    partInfo.crewMemberTraits.Clear();

                    partInfo.hasextDoor = frzr.ExternalDoorActive;
                    partInfo.hasextPod = frzr.isPodExternal;
                    partInfo.numSeats = frzr.FreezerSize;
                    partInfo.timeLastElectricity = frzr.timeSinceLastECtaken;
                    partInfo.frznChargeRequired = frzr.FrznChargeRequired;
                    partInfo.timeLastTempCheck = frzr.timeSinceLastTmpChk;
                    partInfo.deathCounter = frzr.deathCounter;
                    partInfo.tmpdeathCounter = frzr.tmpdeathCounter;
                    partInfo.outofEC = frzr.DFFreezerOutofEC;
                    partInfo.TmpStatus = frzr.DFFrzrTmp;
                    partInfo.cabinTemp = frzr.CabinTemp;
                    foreach (ProtoCrewMember crew in frzr.part.protoModuleCrew)
                    {
                        partInfo.crewMembers.Add(crew.name);
                        partInfo.crewMemberTraits.Add(crew.experienceTrait.Title);
                    }

                    DeepFreeze.Instance.DFgameSettings.knownFreezerParts[frzr.part.flightID] = partInfo;
                }
                else   // Update existing entry
                {
                    partInfo.hasextDoor = frzr.ExternalDoorActive;
                    partInfo.hasextPod = frzr.isPodExternal;
                    partInfo.numSeats = frzr.FreezerSize;
                    partInfo.timeLastElectricity = frzr.timeSinceLastECtaken;
                    partInfo.frznChargeRequired = frzr.FrznChargeRequired;
                    partInfo.timeLastTempCheck = frzr.timeSinceLastTmpChk;
                    partInfo.deathCounter = frzr.deathCounter;
                    partInfo.tmpdeathCounter = frzr.tmpdeathCounter;
                    partInfo.outofEC = frzr.DFFreezerOutofEC;
                    partInfo.TmpStatus = frzr.DFFrzrTmp;
                    partInfo.cabinTemp = frzr.CabinTemp;
                    partInfo.crewMembers.Clear();
                    partInfo.crewMemberTraits.Clear();
                    foreach (ProtoCrewMember crew in frzr.part.protoModuleCrew)
                    {
                        partInfo.crewMembers.Add(crew.name);
                        partInfo.crewMemberTraits.Add(crew.experienceTrait.Title);
                    }
                }
                //now update the knownfreezerpart and any related vesselinfo field
                if (frzr.ExternalDoorActive)
                    vesselInfo.hasextDoor = true;
                if (frzr.isPodExternal)
                    vesselInfo.hasextPod = true;
            }
        }
Exemplo n.º 6
0
        private int UpdateVesselCounts(VesselInfo vesselInfo, Vessel vessel, double currentTime)
        {
            // save current toggles to current vesselinfo
            // Utilities.Log_Debug("UpdateVesselCounts " + vessel.id);
            crewCapacity = 0;
            vesselInfo.ClearAmounts(); // numCrew = 0; numOccupiedParts = 0; numseats = 0;
            foreach (Part part in vessel.parts)
            {
                DeepFreezer freezer = part.FindModuleImplementing<DeepFreezer>();
                if (freezer != null) // this vessel part does contain a freezer
                {
                     Utilities.Log_Debug("part:" + part.name + " Has Freezer");
                    //first Update the PartInfo counts

                    if (DeepFreeze.Instance.DFgameSettings.knownFreezerParts.TryGetValue(freezer.part.flightID, out partInfo))
                    {
                        partInfo.numCrew = freezer.part.protoModuleCrew.Count;
                        partInfo.numFrznCrew = freezer.DFIStoredCrewList.Count;
                    }
                    //Now update the VesselInfo counts
                    crewCapacity += freezer.FreezerSize;
                    vesselInfo.numSeats += freezer.FreezerSize;
                    vesselInfo.numCrew += part.protoModuleCrew.Count;
                    vesselInfo.numFrznCrew += freezer.DFIStoredCrewList.Count();
                    // Utilities.Log_Debug("numcrew:" + part.protoModuleCrew.Count + " numfrzncrew:" + freezer.DFIStoredCrewList.Count());
                    if (part.protoModuleCrew.Count > 0 || freezer.DFIStoredCrewList.Any())
                    {
                        ++vesselInfo.numOccupiedParts;
                    }
                }
                else //this vessel part does not contain a freezer
                {
                    crewCapacity += part.CrewCapacity;
                    vesselInfo.numSeats += part.CrewCapacity;
                    if (part.protoModuleCrew.Count > 0)
                    {
                        vesselInfo.numCrew += part.protoModuleCrew.Count;
                        ++vesselInfo.numOccupiedParts;
                    }
                    foreach (PartResource res in part.Resources)
                    {
                        if (res.resourceName == "ElectricCharge")
                        {
                            vesselInfo.storedEC += res.amount;
                        }
                    }
                }
            }
            // Utilities.Log_Debug("UpdateVesselCounts " + vessel.id + " complete. numCrew=" + vesselInfo.numCrew + " numfrzncrew=" + vesselInfo.numFrznCrew + " crewcapacity=" + crewCapacity + " numoccupparts=" + vesselInfo.numOccupiedParts);
            return crewCapacity;
        }
Exemplo n.º 7
0
 private void UpdatePredictedVesselEC(VesselInfo vesselInfo, Vessel vessel, double currentTime)
 {
     double ECreqdsincelastupdate = 0f;
     int frznChargeRequired = 0;
     List<KeyValuePair<uint, PartInfo>> DpFrzrVsl = DeepFreeze.Instance.DFgameSettings.knownFreezerParts.Where(p => p.Value.vesselID == vessel.id).ToList();
     foreach (KeyValuePair<uint, PartInfo> frzr in DpFrzrVsl)
     {
         //calculate the predicated time EC will run out
         double timeperiod = Planetarium.GetUniversalTime() - frzr.Value.timeLastElectricity;
         frznChargeRequired = (int)frzr.Value.frznChargeRequired;
         ECreqdsincelastupdate += frznChargeRequired / 60.0f * timeperiod * frzr.Value.numFrznCrew;
         frzr.Value.deathCounter = currentTime;
         // Utilities.Log_Debug("predicted EC part " + frzr.Value.vesselID + " " + frzr.Value.PartName + " FrznChargeRequired " + frznChargeRequired + " timeperiod " + timeperiod + " #frzncrew " + frzr.Value.numFrznCrew);
     }
     double ECafterlastupdate = vesselInfo.storedEC - ECreqdsincelastupdate;
     double predictedMinutes = ECafterlastupdate / frznChargeRequired;  // This probably should be per PART, but for simplicity we will do for the whole vessel
     vesselInfo.predictedECOut = predictedMinutes * 60;
     // Utilities.Log_Debug("UpdatePredictedVesselEC vessel " + vessel.id + " " + vessel.name + " StoredEC=" + vesselInfo.storedEC + " ECreqd=" + ECreqdsincelastupdate + " Prediction Secs=" + vesselInfo.predictedECOut);
     // Utilities.Log_Debug("ECafterlastupdate " + ECafterlastupdate + " FrznChargeRequired " + frznChargeRequired + " predictedMinutes " + predictedMinutes);
 }
Exemplo n.º 8
0
        private void CheckVslUpdate()
        {
            // Called every fixed update from fixedupdate - Check for vessels that have been deleted and remove from Dictionary
            // also updates current active vessel details/settings
            // adds new vessel if current active vessel is not known and updates it's details/settings
            double currentTime = Planetarium.GetUniversalTime();
            List<Vessel> allVessels = FlightGlobals.Vessels;
            var vesselsToDelete = new List<Guid>();
            var partsToDelete = new List<uint>();
            var knownVessels = DeepFreeze.Instance.DFgameSettings.knownVessels;
            this.Log_Debug("CheckVslUpdate start");
            //* Update known vessels.
            foreach (var entry in knownVessels)
            {
                this.Log_Debug("knownvessels id = " + entry.Key + " Name = " + entry.Value.vesselName);
                Guid vesselId = entry.Key;
                VesselInfo vesselInfo = entry.Value;
                Vessel vessel = allVessels.Find(v => v.id == vesselId);
                if (vessel == null)
                {
                    this.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());
                    continue;
                }
                if (vessel.loaded)
                {
                    UpdateVesselInfo(vesselInfo, vessel, currentTime);
                    int crewCapacity = UpdateVesselCounts(vesselInfo, vessel, currentTime);
                    if (vessel.FindPartModulesImplementing<DeepFreezer>().Count() == 0)
                    {
                        this.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());
                        continue;
                    }
                    else
                    {
                        if (DeepFreeze.Instance.DFsettings.ECreqdForFreezer && vesselInfo.numFrznCrew > 0)
                        {
                            UpdatePredictedVesselEC(vesselInfo, vessel, currentTime);
                        }
                        if (vesselInfo.hasextDoor)
                        {
                            // If vessel is Not ActiveVessel and has a Transparent Pod reset the Cryopods.
                            if (FlightGlobals.ActiveVessel != vessel)
                            {
                                List<DeepFreezer> DpFrzrLoadedVsl = new List<DeepFreezer>();
                                DpFrzrLoadedVsl = vessel.FindPartModulesImplementing<DeepFreezer>();
                                foreach (DeepFreezer frzr in DpFrzrLoadedVsl)
                                {
                                    if (frzr.hasExternalDoor)
                                    {
                                        this.Log_Debug("chkvslupdate loaded freezer with door, reset the cryopods");
                                        frzr.resetCryopods(false);
                                    }
                                }
                            }
                        }
                    }
                }
                else //vessel not loaded
                {
                    //if (!DFInstalledMods.IsBGPInstalled || !Utilities.timewarpIsValid(5))
                    //{
                    UpdatePredictedVesselEC(vesselInfo, vessel, currentTime);
                    //}
                    vesselInfo.hibernating = true;
                }
            }

            // Delete vessels we don't care about any more.
            vesselsToDelete.ForEach(id => DeepFreeze.Instance.DFgameSettings.knownVessels.Remove(id));
            // Delete parts that were part of those vessels.
            partsToDelete.ForEach(id => DeepFreeze.Instance.DFgameSettings.knownFreezerParts.Remove(id));

            // 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 allVessels.Where(v => v.loaded))
            {
                if (!knownVessels.ContainsKey(vessel.id) && vessel.FindPartModulesImplementing<DeepFreezer>().Count() > 0)
                {
                    this.Log("New vessel: " + vessel.vesselName + " (" + vessel.id + ")");
                    VesselInfo vesselInfo = new VesselInfo(vessel.vesselName, currentTime);
                    UpdateVesselInfo(vesselInfo, vessel, currentTime);
                    int crewCapacity = UpdateVesselCounts(vesselInfo, vessel, currentTime);
                    knownVessels[vessel.id] = vesselInfo;
                }
            }
            this.Log_Debug("CheckVslUpdate complete");
        }