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 fromEVA(GameEvents.FromToAction <Part, Part> data)
        {
            // get any leftover monoprop (eva fuel in reality) from EVA vessel
            double monoprop = data.from.Resources.list[0].amount;

            // get any leftover ec
            double ec = data.from.Resources.list[1].amount;


            // add the leftover monoprop back to the pod
            data.to.RequestResource("MonoPropellant", -monoprop);

            // add the leftover ec back to the pod
            data.to.RequestResource("ElectricCharge", -ec);


            // if oxygen was transfered
            if (data.from.FindModuleImplementing <EVA>().has_helmet)
            {
                // get any leftover oxygen
                double oxygen = data.from.RequestResource("Oxygen", Settings.OxygenOnEVA);

                // add the leftover oxygen back to the pod
                data.to.RequestResource("Oxygen", -oxygen);
            }

            // forget vessel data
            DB.ForgetVessel(data.from.vessel.id);
        }
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);
        }
Ejemplo n.º 6
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.º 7
0
        void fromEVA(GameEvents.FromToAction <Part, Part> data)
        {
            // use Hydrazine instead of MonoPropellant if RealFuel is installed
            string monoprop_name = detected_mods.RealFuels ? "Hydrazine" : "MonoPropellant";

            // get any leftover EVA Fuel from EVA vessel
            double monoprop = data.from.Resources.list[0].amount;

            // add the leftover monoprop back to the pod
            data.to.RequestResource(monoprop_name, -monoprop);

            // manage resources in rules
            foreach (Rule r in rules)
            {
                if (r.resource_name.Length == 0 || r.on_eva <= double.Epsilon)
                {
                    continue;
                }
                double leftover = ResourceCache.Info(data.from.vessel, r.resource_name).amount;
                data.to.RequestResource(r.resource_name, -leftover);
            }

            // merge EVA computer files into vessel
            Computer a = DB.VesselData(data.from.vessel.id).computer;
            Computer b = DB.VesselData(data.to.vessel.id).computer;

            b.merge(a);

            // forget vessel data
            DB.ForgetVessel(data.from.vessel.id);

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

            // execute script on vessel computer
            if (DB.Ready())
            {
                DB.VesselData(data.to.vessel.id).computer.execute("run", "auto/eva_in", string.Empty, data.to.vessel);
            }

            // mute messages for a couple seconds to avoid warning messages from the vessel resource amounts
            Message.MuteInternal();
            base.StartCoroutine(CallbackUtil.DelayedCallback(2.0f, Message.UnmuteInternal));

            // if vessel info is open, switch to the vessel
            if (Info.IsOpen())
            {
                Info.Open(data.to.vessel);
            }
        }
Ejemplo n.º 8
0
        void vesselDock(GameEvents.FromToAction <Part, Part> e)
        {
            // this need to happen when db is in a valid state
            if (DB.Ready())
            {
                // merge computer data from vessel A to vessel B on docking
                Computer a = DB.VesselData(e.from.vessel.id).computer;
                Computer b = DB.VesselData(e.to.vessel.id).computer;
                b.merge(a);

                // forget vessel being docked
                DB.ForgetVessel(e.from.vessel.id);
            }

            // purge vessel from resource cache
            ResourceCache.Purge(e.from.vessel.id);
        }
Ejemplo n.º 9
0
 void vesselDock(GameEvents.FromToAction <Part, Part> e)
 {
     // forget vessel being docked
     DB.ForgetVessel(e.from.vessel.id);
 }