public override void OnLoad(ConfigNode node)
 {
     base.OnLoad(node);
     //get settings node and kerbal node
     try
     {
         ConfigNode DataNode = node.GetNode("TerminusData");
         if (DataNode != null)
         {
             ConfigNode TLS_Kerbals = DataNode.GetNode("TLS_Kerbals");
             if (TLS_Kerbals != null)
             {
                 Terminus_Life_Support.TrackedKerbals.Clear();
                 foreach (ConfigNode kiNode in TLS_Kerbals.GetNodes("KerbalInfo"))
                 {
                     KerbalInfo ki = new KerbalInfo();
                     ki.FromConfigNode(kiNode);
                     if (ki.Name != "")
                         Terminus_Life_Support.TrackedKerbals.Add(ki);
                 }
                 Terminus_Life_Support.UpdateKerbalList(true);
             }
         }
     }
     catch (Exception e)
     {
         UnityEngine.Debug.LogException(e);
     }
 }
        public void FixedUpdate()
        {
            if (Time.timeSinceLevelLoad < 1)
                return;

            double currentTime = Planetarium.GetUniversalTime();
            //loop through all the loaded kerbals and take resources as needed
            /*for (int i = 0; i < LoadedKerbals.Count; i++)
            {
                KerbalInfo ki = LoadedKerbals[i];
                //(KerbalInfo ki in LoadedKerbals)
                if (ki.CrewedVessel != null && ki.CrewedVessel.loaded)
                {
                    //vessel is loaded (and crewmember is valid)
                    //consume resources
                    double delta = currentTime - ki.LastUpdated;
                    double requiredLS = delta * consumptionRate;
                    //if we do it per kerbal then all later kerbals wont have LS if we're low (remember the issues with intake air?)
                        //we should do it per vessel instead, which requires a bit more work
                    
                }
                else
                {
                    LoadedKerbals.RemoveAt(i);
                    i--;
                }
            }*/
            PartResourceDefinition LSRscDef = PartResourceLibrary.Instance.GetDefinition("LifeSupport");

            for (int i = 0; i < LoadedVessels.Count; i++)
            {
                Vessel v = LoadedVessels[i];
                if (v == null || !v.loaded)
                {
                    Debug.Log("Terminus LS: Vessel not loaded: " + v.vesselName);
                    UpdateKerbalList();
                    break;
                }

                int crewCount = v.GetCrewCount();
                //double totalReqLS = 0;

                Vessel.ActiveResource LSRSC = v.GetActiveResources().FirstOrDefault(rs => rs.info.name == "LifeSupport");
                double LSRemaining = (LSRSC != null) ? LSRSC.amount : 0;
                //Debug.Log("Terminus LS: " + LSRemaining + " remaining LS");
                foreach (ProtoCrewMember pcm in new List<ProtoCrewMember>(v.GetVesselCrew()))
                {
                    KerbalInfo ki = GetInfoForPCM(pcm, true);
                    if (ki == null) //not loaded but should be
                    {
                        ki = GetInfoForPCM(pcm, false);
                        if (ki == null) //not tracked but should be
                        {
                            ki = new KerbalInfo(pcm);
                            ki.LastUpdated = currentTime;
                            ki.LastSated = currentTime;
                            TrackedKerbals.Add(ki);
                        }
                        LoadedKerbals.Add(ki);
                    }

                    if (v.situation == Vessel.Situations.PRELAUNCH) //don't run for prelaunched craft
                    {
                        ki.LastUpdated = currentTime;
                        ki.LastSated = currentTime;
                        continue;
                    }

                    if (ki.LastUpdated > currentTime)
                    {
                        ki.LastUpdated = currentTime;
                        ki.LastSated = currentTime;
                    }

                    if (ki.LastUpdated > 0)
                    {
                        double deltaTime = currentTime - ki.LastSated;
                        double desiredLS = consumptionRate * deltaTime;
                        List<PartResource> resourceList = new List<PartResource>();
                        double LSGotten = 0;
                        if (pcm.KerbalRef != null)
                        {
                            //pcm.KerbalRef.InPart.GetConnectedResources(LSRsc.id, LSRsc.resourceFlowMode, resourceList);
                            LSGotten = pcm.KerbalRef.InPart.RequestResource(LSRscDef.id, Math.Min(desiredLS, LSRemaining / crewCount), LSRscDef.resourceFlowMode);
                        }
                        // = pcm.KerbalRef != null ?  //.RequestResource("LifeSupport", Math.Min(desiredLS, LSRemaining / crewCount)) : 0;
                        LSRemaining -= LSGotten;
                        ki.LastSated += deltaTime * (LSGotten / desiredLS); //tries to take all the resources it has missed out on

                        ki.LastUpdated = currentTime;

                        if (currentTime - ki.LastSated > 3600 * 6)
                        {
                            //greater than 6 hours since last fed, kill crewmember
                            KillCrewmember(pcm, v);
                        }
                    }
                    else
                    {
                        ki.LastUpdated = currentTime;
                    }
                }
            }
        }