Example #1
0
 internal static AlarmInfo Load(ConfigNode node)
 {
     Guid vesselID = Utilities.GetNodeValue(node, "vesselID");
     string Name = Utilities.GetNodeValue(node, "Name", string.Empty);
     AlarmInfo info = new AlarmInfo(Name, vesselID);
     info.AlarmType = Utilities.GetNodeValue(node, "AlarmType", KACWrapper.KACAPI.AlarmTypeEnum.Raw);
     info.Notes = Utilities.GetNodeValue(node, "Notes", string.Empty);
     info.AlarmTime = Utilities.GetNodeValue(node, "AlarmTime", 0d);
     info.AlarmMargin = Utilities.GetNodeValue(node, "AlarmMargin", 0d);
     info.AlarmExecute = Utilities.GetNodeValue(node, "AlarmExecute", false);
     string frzkbllst = Utilities.GetNodeValue(node, "FrzKerbals", string.Empty);
     string thwkbllst = Utilities.GetNodeValue(node, "ThwKerbals", string.Empty);
     string[] frzStrings = frzkbllst.Split(',');
     if (frzStrings.Length > 0)
     {
         for (int i = 0; i < frzStrings.Length; i++)
         {
             info.FrzKerbals.Add(frzStrings[i]);
         }
     }
     string[] thwStrings = thwkbllst.Split(',');
     if (thwStrings.Length > 0)
     {
         for (int i = 0; i < thwStrings.Length; i++)
         {
             if (thwStrings[i].Length > 0)
                 info.ThwKerbals.Add(thwStrings[i]);
         }
     }
     return info;
 }
Example #2
0
        internal static AlarmInfo Load(ConfigNode node)
        {
            Guid   vesselID = Utilities.GetNodeValue(node, "vesselID");
            string Name     = "";

            node.TryGetValue("Name", ref Name);

            AlarmInfo info = new AlarmInfo(Name, vesselID);

            info.AlarmType = Utilities.GetNodeValue(node, "AlarmType", KACWrapper.KACAPI.AlarmTypeEnum.Raw);
            node.TryGetValue("Notes", ref info.Notes);
            node.TryGetValue("AlarmTime", ref info.AlarmTime);
            node.TryGetValue("AlarmMargin", ref info.AlarmMargin);
            node.TryGetValue("AlarmExecute", ref info.AlarmExecute);


            string frzkbllst = "";

            node.TryGetValue("FrzKerbals", ref frzkbllst);
            string thwkbllst = "";

            node.TryGetValue("ThwKerbals", ref thwkbllst);

            string[] frzStrings = frzkbllst.Split(',');
            if (frzStrings.Length > 0)
            {
                for (int i = 0; i < frzStrings.Length; i++)
                {
                    info.FrzKerbals.Add(frzStrings[i]);
                }
            }
            string[] thwStrings = thwkbllst.Split(',');
            if (thwStrings.Length > 0)
            {
                for (int i = 0; i < thwStrings.Length; i++)
                {
                    if (thwStrings[i].Length > 0)
                    {
                        info.ThwKerbals.Add(thwStrings[i]);
                    }
                }
            }
            return(info);
        }
        private void CheckKACAlarmsUpdate()
        {
            var alarmstoDelete = new List<string>();
            //iterate all the alarms looking for vessel.ID matches
            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);
                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");
                    alarmstoDelete.Add(entry.Key);
                    continue;
                }
                // Check if Alarm has been modified and no longer has any DeepFreeze association, in which case we delete it.
                if ((entry.Value.FrzKerbals.Count == 0 && entry.Value.ThwKerbals.Count == 0) || !DeepFreeze.Instance.DFgameSettings.knownVessels.ContainsKey(entry.Value.VesselID))
                // No FREEZE or THAW events in the Notes and unknown vessel, so delete it.
                {
                     Utilities.Log_Debug("Alarm has no THAW FREEZE any more so deleting");
                    alarmstoDelete.Add(entry.Key);
                    continue;
                }
                // Check if alarm has occurred and still executing and try to execute it.
                if (entry.Value.AlarmExecute)
                {
                    if (entry.Value.ThwKerbals.Count == 0 && entry.Value.FrzKerbals.Count == 0)
                    {
                        // we are all done. Delete the alarm. Do a message.
                         Utilities.Log_Debug("Execution of alarm for vessel " + entry.Value.Name + " is complete");
                        ScreenMessages.PostScreenMessage("DeepFreeze Alarm processing completed.", 5.0f, ScreenMessageStyle.UPPER_CENTER);
                        alarmstoDelete.Add(entry.Key);
                        continue;
                    }
                    if (!DeepFreeze.Instance.DFgameSettings.knownVessels.ContainsKey(entry.Value.VesselID)) // vessel doesn't exist any more, so just delete the executing alarm.
                    {
                         Utilities.Log_Debug("Executing alarm for vessel " + entry.Value.Name + " deleted as vessel no longer exists");
                        alarmstoDelete.Add(entry.Key);
                        continue;
                    }
                    if (!HighLogic.LoadedSceneIsFlight) //If we aren't in flightmode we can't, so just do message and skip this logic section
                    {
                         Utilities.Log_Debug("Executing alarm for vessel " + entry.Value.Name + " scene is not flight");
                        SwitchVslAlarmMsg(DeepFreeze.Instance.DFgameSettings.knownKACAlarms[entry.Key].Name);
                        continue;
                    }
                    if (FlightGlobals.ActiveVessel.id != DeepFreeze.Instance.DFgameSettings.knownKACAlarms[entry.Key].VesselID) // We are in flight, but active vessel is not the one we want
                    {
                        Utilities.Log_Debug("Executing alarm for vessel " + entry.Value.Name + " not the active vessel");
                        SwitchVslAlarmMsg(DeepFreeze.Instance.DFgameSettings.knownKACAlarms[entry.Key].Name);
                        continue;
                    }
                    // Ok , all that is out of the way, so no we really try to execute it.
                    //THAW first
                     Utilities.Log_Debug("Alarm is executing");
                    if (entry.Value.ThwKerbals.Count > 0)
                    {
                        foreach (string kerbnme in entry.Value.ThwKerbals)
                        {
                             Utilities.Log_Debug("Dump ThwKerbals list entry=" + kerbnme);
                        }
                        // 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();
                         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)
                            {
                                //They are in this part.
                                Found = true;
                                if (frzr.DFIcrewXferFROMActive || frzr.DFIcrewXferTOActive || frzr.DFIIsFreezeActive || frzr.DFIIsThawActive)
                                {
                                    //part is busy, so we wait.
                                     Utilities.Log_Debug("We found the crewmember and the part, but it is busy, so we wait");
                                    break;
                                }
                                //If we just switched to the vessel we have to wait for the vessel to load.
                                if (Time.timeSinceLevelLoad < 6f)
                                {
                                    Utilities.Log_Debug("We found the crewmember and the part, but < 4 secs since level loaded, so we wait");
                                    break;
                                }
                                //If we get here, we have found the kerbal, and the part, and it isn't busy. So we THAW!!!!!!
                                Utilities.Log_Debug("We found the crewmember and the part and it isn't busy, so we THAW!!!");
                                frzr.beginThawKerbal(thwkerbalname);
                                entry.Value.ThwKerbals.Remove(thwkerbalname);
                                foreach (string kerbnme in entry.Value.ThwKerbals)
                                {
                                    Utilities.Log_Debug("Dump ThwKerbals list entry=" + kerbnme);
                                }
                                ModifyKACAlarm(alarm, entry.Value.FrzKerbals, entry.Value.ThwKerbals);
                                break;
                            }
                        }
                        if (!Found)
                        {
                            //We didn't find them anywhere. Remove the thaw request.
                            entry.Value.ThwKerbals.Remove(thwkerbalname);
                             Utilities.Log_Debug("We didn't find the thaw kerbal " + thwkerbalname + " anywhere on the vessel so we deleted the request");
                        }
                    }
                    else
                    {
                        if (entry.Value.FrzKerbals.Count > 0)
                        {
                            foreach (string kerbnme in entry.Value.FrzKerbals)
                            {
                                 Utilities.Log_Debug("Dump FrzKerbals list entry=" + kerbnme);
                            }
                            // First we find the FrzKerbal part and if they are still on-board
                            // Then check the part isn't busy already and start the freeze process.
                            bool Found = false;
                            List<ProtoCrewMember> vslcrew = FlightGlobals.ActiveVessel.GetVesselCrew();
                            string frzkerbalname = entry.Value.FrzKerbals.FirstOrDefault();
                            ProtoCrewMember crewmember = vslcrew.FirstOrDefault(c => c.name == frzkerbalname);
                            if (crewmember == null)
                            {
                                //They aren't in the vessel any more. So delete this thaw and move on.
                                 Utilities.Log_Debug("Executing alarm for vessel " + entry.Value.Name + " looking to freeze crewmember " + frzkerbalname + " but the aren't on-board so move on");
                                entry.Value.FrzKerbals.Remove(frzkerbalname);
                                continue;
                            }
                            //ProtoCrewMember crewmember = FlightGlobals.ActiveVessel.GetVesselCrew().Find(a => a.name == entry.Value.ThwKerbals[0]);
                             Utilities.Log_Debug("Executing alarm for vessel " + entry.Value.Name + " looking to freeze crewmember " + frzkerbalname + " finding the part");
                            foreach (DeepFreezer frzr in DpFrzrActVsl)
                            {
                                if (frzr.part.protoModuleCrew.Contains(crewmember))
                                {
                                    //They are in this part.
                                    Found = true;
                                    if (frzr.DFIcrewXferFROMActive || frzr.DFIcrewXferTOActive || frzr.DFIIsFreezeActive || frzr.DFIIsThawActive)
                                    {
                                        //part is busy, so we wait.
                                         Utilities.Log_Debug("We found the crewmember and the part, but it is busy, so we wait");
                                        break;
                                    }
                                    //If we just switched to the vessel we have to wait for the vessel to load.
                                    if (Time.timeSinceLevelLoad < 6f)
                                    {
                                        Utilities.Log_Debug("We found the crewmember and the part, but < 4 secs since level loaded, so we wait");
                                        break;
                                    }
                                    //If we get here, we have found the kerbal, and the part, and it isn't busy. So we FREEZE!!!!!!
                                    Utilities.Log_Debug("We found the crewmember and the part and it isn't busy, so we FREEZE!!!");
                                    frzr.beginFreezeKerbal(crewmember);
                                    entry.Value.FrzKerbals.Remove(frzkerbalname);
                                    foreach (string kerbnme in entry.Value.FrzKerbals)
                                    {
                                        Utilities.Log_Debug("Dump FrzKerbals list entry=" + kerbnme);
                                    }
                                    ModifyKACAlarm(alarm, entry.Value.FrzKerbals, entry.Value.ThwKerbals);
                                    break;
                                }
                            }
                            if (!Found)
                            {
                                //We didn't find them anywhere. Remove the freeze request.
                                entry.Value.FrzKerbals.Remove(frzkerbalname);
                                 Utilities.Log_Debug("We didn't find the freeze kerbal " + frzkerbalname + " anywhere on the vessel so we deleted the request");
                            }
                        }
                    }
                }
            }

            alarmstoDelete.ForEach(id => DeepFreeze.Instance.DFgameSettings.knownKACAlarms.Remove(id));

            //loop through all the KAC alarms. If the alarm is NOT already in the KnownList and the Vessel has a Freezer association that we know of, we add it to the KnownList
            foreach (var entry in KACWrapper.KAC.Alarms)
            {
                if (!DeepFreeze.Instance.DFgameSettings.knownKACAlarms.ContainsKey(entry.ID)) // So we don't already know about it
                {
                    if (entry.VesselID != string.Empty && entry.AlarmType != KACWrapper.KACAPI.AlarmTypeEnum.Crew)
                    {
                        Guid tmpid = Guid.Empty;
                        try
                        {
                            tmpid = new Guid(entry.VesselID);
                        }
                        catch (FormatException)
                        {
                            if (invalidKACGUIDItems < 10)
                            {
                                Debug.Log("DeepFreeze invalid KAC alarm GUID caught (" + entry.VesselID + ")");
                                invalidKACGUIDItems++;
                            }
                        }
                        if (tmpid != Guid.Empty)
                        {
                            if (DeepFreeze.Instance.DFgameSettings.knownVessels.ContainsKey(tmpid)) // So we do know that vessel does have a Freezer Assocation so we add it to the KnownList
                            {
                                AlarmInfo tempAlarmInfo = new AlarmInfo(entry.Name, tmpid);
                                UpdateKACAlarmInfo(tempAlarmInfo, entry);
                                DeepFreeze.Instance.DFgameSettings.knownKACAlarms.Add(entry.ID, tempAlarmInfo);
                            }
                        }
                    }
                }
                else  //We do know about it, we update it's details
                {
                    Guid tmpid = Guid.Empty;
                    try
                    {
                        tmpid = new Guid(entry.VesselID);
                    }
                    catch (FormatException)
                    {
                        if (invalidKACGUIDItems < 10)
                        {
                            Debug.Log("DeepFreeze invalid KAC alarm GUID caught (" + entry.VesselID + ")");
                            invalidKACGUIDItems++;
                        }
                    }
                    if (tmpid != Guid.Empty)
                    {
                        AlarmInfo tempAlarmInfo = new AlarmInfo(entry.Name, tmpid);
                        UpdateKACAlarmInfo(tempAlarmInfo, entry);
                        tempAlarmInfo.AlarmExecute = DeepFreeze.Instance.DFgameSettings.knownKACAlarms[entry.ID].AlarmExecute;
                        DeepFreeze.Instance.DFgameSettings.knownKACAlarms[entry.ID] = tempAlarmInfo;
                    }
                }
            }
        }
Example #4
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");
        }
 private void UpdateKACAlarmInfo(AlarmInfo alarmInfo, KACWrapper.KACAPI.KACAlarm alarm)
 {
     alarmInfo.AlarmType = alarm.AlarmType;
     alarmInfo.AlarmTime = alarm.AlarmTime;
     alarmInfo.AlarmMargin = alarm.AlarmMargin;
     alarmInfo.Notes = alarm.Notes;
     string tmpnotes = ParseKACNotes(alarm.Notes, out alarmInfo.FrzKerbals, out alarmInfo.ThwKerbals);
 }