Ejemplo n.º 1
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);
            }
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        void vesselRecovered(ProtoVessel vessel, bool b)
        {
            // note: this is called multiple times when a vessel is recovered, but its safe

            // find out if this was an EVA kerbal and if it was dead
            bool is_eva_dead = false;

            foreach (ProtoPartSnapshot p in vessel.protoPartSnapshots)
            {
                foreach (ProtoPartModuleSnapshot m in p.modules)
                {
                    is_eva_dead |= (m.moduleName == "EVA" && Lib.GetProtoValue <bool>(m, "is_dead"));
                }
            }

            // set roster status of eva dead kerbals
            if (is_eva_dead)
            {
                vessel.GetVesselCrew()[0].rosterStatus = ProtoCrewMember.RosterStatus.Dead;
            }
            // forget kerbal data of recovered kerbals
            else
            {
                foreach (ProtoCrewMember c in vessel.GetVesselCrew())
                {
                    DB.ForgetKerbal(c.name);
                }
            }

            // forget vessel data
            DB.ForgetVessel(vessel.vesselID);
        }
Ejemplo n.º 4
0
        void vesselTerminated(ProtoVessel vessel)
        {
            // forget all kerbals data
            foreach (ProtoCrewMember c in vessel.GetVesselCrew())
            {
                DB.ForgetKerbal(c.name);
            }

            // forget vessel data
            DB.ForgetVessel(vessel.vesselID);
        }
Ejemplo n.º 5
0
        void vesselTerminated(ProtoVessel vessel)
        {
            // forget all kerbals data
            foreach (ProtoCrewMember c in vessel.GetVesselCrew())
            {
                DB.ForgetKerbal(c.name);
            }

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

            // purge vessel from resource cache
            ResourceCache.Purge(vessel.vesselID);
        }
Ejemplo n.º 6
0
        // kill a kerbal
        public static void Kill(Vessel v, ProtoCrewMember c)
        {
            // if on pod
            if (!v.isEVA)
            {
                // forget kerbal data
                DB.ForgetKerbal(c.name);

                // if vessel is loaded
                if (v.loaded)
                {
                    // find part
                    Part part = null;
                    foreach (Part p in v.parts)
                    {
                        if (p.protoModuleCrew.Find(k => k.name == c.name) != null)
                        {
                            part = p; break;
                        }
                    }

                    // remove kerbal and kill it
                    part.RemoveCrewmember(c);
                    c.Die();
                }
                // if vessel is not loaded
                else
                {
                    // find proto part
                    ProtoPartSnapshot part = null;
                    foreach (ProtoPartSnapshot p in v.protoVessel.protoPartSnapshots)
                    {
                        if (p.HasCrew(c.name))
                        {
                            part = p; break;
                        }
                    }

                    // remove from vessel
                    part.RemoveCrew(c.name);

                    // flag as dead
                    c.rosterStatus = ProtoCrewMember.RosterStatus.Dead;
                }
            }
            // else it must be an eva death
            else
            {
                // flag as eva death
                DB.KerbalData(c.name).eva_dead = true;

                // rename vessel
                v.vesselName = c.name + "'s body";
            }

            // remove reputation
            if (HighLogic.CurrentGame.Mode == Game.Modes.CAREER)
            {
                Reputation.Instance.AddReputation(-Settings.DeathReputationPenalty, TransactionReasons.Any);
            }
        }