Beispiel #1
0
        void vesselRecovered(ProtoVessel vessel, bool b)
        {
            // note: this is called multiple times when a vessel is recovered

            // for each crew member
            foreach (ProtoCrewMember c in vessel.GetVesselCrew())
            {
                // avoid creating kerbal data in db again,
                // as this function may be called multiple times
                if (!DB.Kerbals().ContainsKey(c.name))
                {
                    continue;
                }

                // set roster status of eva dead kerbals
                if (DB.KerbalData(c.name).eva_dead)
                {
                    c.rosterStatus = ProtoCrewMember.RosterStatus.Dead;
                }

                // forget kerbal data of recovered kerbals
                DB.ForgetKerbal(c.name);
            }

            // TODO: [SCIENCE] add science data from recovered vessel
            // beware of double calls to this function

            // forget vessel data
            DB.ForgetVessel(vessel.vesselID);

            // purge vessel from resource cache
            ResourceCache.Purge(vessel.vesselID);
        }
Beispiel #2
0
        void vesselDestroyed(Vessel vessel)
        {
            // forget vessel data
            DB.ForgetVessel(vessel.id);

            // purge vessel from resource cache
            ResourceCache.Purge(vessel.id);

            // rescan the damn kerbals
            // note: vessel crew is empty at destruction time
            // note: we can't even use the flightglobal roster, because sometimes it isn't updated yet at this point
            HashSet <string> kerbals_alive = new HashSet <string>();
            HashSet <string> kerbals_dead  = new HashSet <string>();

            foreach (Vessel v in FlightGlobals.Vessels)
            {
                List <ProtoCrewMember> crew = v.loaded ? v.GetVesselCrew() : v.protoVessel.GetVesselCrew();
                foreach (ProtoCrewMember c in crew)
                {
                    kerbals_alive.Add(c.name);
                }
            }
            foreach (var p in DB.Kerbals())
            {
                if (!kerbals_alive.Contains(p.Key))
                {
                    kerbals_dead.Add(p.Key);
                }
            }
            foreach (string n in kerbals_dead)
            {
                DB.ForgetKerbal(n);
            }
        }
Beispiel #3
0
        void VesselDestroyed(Vessel v)
        {
            // rescan the damn kerbals
            // - vessel crew is empty at destruction time
            // - we can't even use the flightglobal roster, because sometimes it isn't updated yet at this point
            HashSet <string> kerbals_alive = new HashSet <string>();
            HashSet <string> kerbals_dead  = new HashSet <string>();

            foreach (Vessel ov in FlightGlobals.Vessels)
            {
                foreach (ProtoCrewMember c in Lib.CrewList(ov))
                {
                    kerbals_alive.Add(c.name);
                }
            }
            foreach (string key in DB.Kerbals().Keys)
            {
                if (!kerbals_alive.Contains(key))
                {
                    kerbals_dead.Add(key);
                }
            }
            foreach (string n in kerbals_dead)
            {
                // we don't know if the kerbal really is dead, or if it is just not currently assigned to a mission
                DB.KillKerbal(n, false);
            }

            // purge the caches
            ResourceCache.Purge(v);                 // works with loaded and unloaded vessels
            //Drive.Purge(v);				// works with loaded and unloaded vessels
            Cache.PurgeVesselCaches(v);             // works with loaded and unloaded vessels
        }
Beispiel #4
0
 // hook: Shielding()
 public static double hook_Shielding(string k_name)
 {
     if (!DB.Ready())
     {
         return(0.0);
     }
     if (!DB.Kerbals().ContainsKey(k_name))
     {
         return(0.0);
     }
     return(DB.KerbalData(k_name).shielding);
 }
Beispiel #5
0
 // hook: Entertainment()
 public static double hook_Entertainment(string k_name)
 {
     if (!DB.Ready())
     {
         return(1.0);
     }
     if (!DB.Kerbals().ContainsKey(k_name))
     {
         return(1.0);
     }
     return(DB.KerbalData(k_name).entertainment);
 }
Beispiel #6
0
 // hook: LivingSpace()
 public static double hook_LivingSpace(string k_name)
 {
     if (!DB.Ready())
     {
         return(1.0);
     }
     if (!DB.Kerbals().ContainsKey(k_name))
     {
         return(1.0);
     }
     return(DB.KerbalData(k_name).living_space);
 }
Beispiel #7
0
 // hook: DisableKerbal()
 public static void hook_DisableKerbal(string k_name, bool disabled)
 {
     if (!DB.Ready())
     {
         return;
     }
     if (!DB.Kerbals().ContainsKey(k_name))
     {
         return;
     }
     DB.KerbalData(k_name).disabled = disabled ? 1u : 0;
 }
Beispiel #8
0
        // hook: InjectRadiation()
        public static void hook_InjectRadiation(string k_name, double amount)
        {
            if (!DB.Ready())
            {
                return;
            }
            if (!DB.Kerbals().ContainsKey(k_name))
            {
                return;
            }
            kerbal_data kd = DB.KerbalData(k_name);

            kd.radiation = Math.Max(kd.radiation + amount, 0.0);
        }
Beispiel #9
0
        // hook: InjectRadiation()
        public static void hook_InjectRadiation(string k_name, double amount)
        {
            if (!DB.Ready())
            {
                return;
            }
            if (!DB.Kerbals().ContainsKey(k_name))
            {
                return;
            }
            kerbal_data kd = DB.KerbalData(k_name);

            foreach (Rule r in Kerbalism.rules)
            {
                if (r.modifier.Contains("radiation"))
                {
                    var kmon = DB.KmonData(k_name, r.name);
                    kmon.problem = Math.Max(kmon.problem + amount, 0.0);
                }
            }
        }
Beispiel #10
0
        // hook: Breakdown
        public static void hook_Breakdown(Vessel v, ProtoCrewMember c)
        {
            if (!Cache.VesselInfo(v).is_valid)
            {
                return;
            }
            if (!DB.Ready())
            {
                return;
            }
            if (!DB.Vessels().ContainsKey(v.id))
            {
                return;
            }
            if (!DB.Kerbals().ContainsKey(c.name))
            {
                return;
            }

            Breakdown(v, c);
        }
Beispiel #11
0
        void VesselDestroyed(Vessel v)
        {
            // for each part
            foreach (Part p in v.parts)
            {
                // forget all potential vessel data
                DB.vessels.Remove(p.flightID);
            }

            // rescan the damn kerbals
            // - vessel crew is empty at destruction time
            // - we can't even use the flightglobal roster, because sometimes it isn't updated yet at this point
            HashSet <string> kerbals_alive = new HashSet <string>();
            HashSet <string> kerbals_dead  = new HashSet <string>();

            foreach (Vessel ov in FlightGlobals.Vessels)
            {
                foreach (ProtoCrewMember c in Lib.CrewList(ov))
                {
                    kerbals_alive.Add(c.name);
                }
            }
            foreach (KeyValuePair <string, KerbalData> p in DB.Kerbals())
            {
                if (!kerbals_alive.Contains(p.Key))
                {
                    kerbals_dead.Add(p.Key);
                }
            }
            foreach (string n in kerbals_dead)
            {
                // we don't know if the kerbal really is dead, or if it is just not currently assigned to a mission
                DB.KillKerbal(n, false);
            }

            // purge the caches
            Cache.Purge(v);
            ResourceCache.Purge(v);
        }