private void OnAttemptEVA(ProtoCrewMember crewMemeber, Part part, Transform transform)
        {
            // Can we be sure that all in-scene kerbal tourists were configured?

            Log.dbg("entered KourageousTourists OnAttemptEVA");

            Tourist t;

            if (!tourists.TryGetValue(crewMemeber.name, out t))
            {
                return;
            }

            if (!Tourist.isTourist(crewMemeber))              // crew always can EVA
            {
                return;
            }

            Vessel v = FlightGlobals.ActiveVessel;

            Log.dbg("Body: {0}; situation: {1}", v.mainBody.GetName(), v.situation);
            EVAAttempt attempt = t.canEVA(v);

            if (!attempt.status)
            {
                ScreenMessages.PostScreenMessage("<color=orange>" + attempt.message + "</color>");
                FlightEVA.fetch.overrideEVA = true;
            }
        }
        public void OnDestroy()
        {
            // Switch tourists back
            Log.dbg("entered OnDestroy");
            try {
                if (null == FlightGlobals.VesselsLoaded)
                {
                    return;
                }
                Log.dbg("VesselsLoaded: {0}", FlightGlobals.VesselsLoaded);
                foreach (Vessel v in FlightGlobals.VesselsLoaded)
                {
                    if (null == v)
                    {
                        continue;                                // Weird behaviour on KSP 1.10?
                    }
                    Log.dbg("restoring vessel {0}", v.name);
                    List <ProtoCrewMember> crewList = v.GetVesselCrew();
                    if (null == v.GetVesselCrew())
                    {
                        continue;                                                // Weird behaviour on KSP 1.10?
                    }
                    foreach (ProtoCrewMember crew in crewList)
                    {
                        if (null == crew)
                        {
                            continue;                                       // Weird behaviour on KSP 1.10?
                        }
                        Log.dbg("restoring crew={0}", crew.name);
                        if (Tourist.isTourist(crew))
                        {
                            crew.type = ProtoCrewMember.KerbalType.Tourist;
                        }
                    }
                }
            }
            catch (Exception e) {
                Log.error(e, "Got Exception while attempting to access loaded vessels");
            }

            GameEvents.onVesselRecovered.Remove(OnVesselRecoveredOffGame);
            GameEvents.onKerbalLevelUp.Remove(OnKerbalLevelUp);
            GameEvents.onCrewOnEva.Remove(OnEvaStart);
            GameEvents.onCrewBoardVessel.Remove(OnCrewBoardVessel);
            GameEvents.onVesselWillDestroy.Remove(OnVesselWillDestroy);
            GameEvents.onVesselLoaded.Add(OnVesselLoad);
            GameEvents.onVesselChange.Remove(OnVesselChange);
            GameEvents.onVesselCreate.Remove(OnVesselCreate);
            GameEvents.onNewVesselCreated.Remove(OnNewVesselCreated);

            GameEvents.onAttemptEva.Remove(OnAttemptEVA);
            GameEvents.onFlightReady.Remove(OnFlightReady);
            GameEvents.onVesselGoOffRails.Remove(OnVesselGoOffRails);

            tourists = null;
            factory  = null;            // do we really need this?
            smile    = false;
            taken    = false;
            fx       = null;
        }
Пример #3
0
        private void reinitVessel(Vessel vessel)
        {
            printDebug(String.Format("entered for {0}", vessel.name));
            foreach (ProtoCrewMember crew in vessel.GetVesselCrew())
            {
                printDebug("crew = " + crew.name);
                if (Tourist.isTourist(crew))
                {
                    crew.type = ProtoCrewMember.KerbalType.Crew;
                    printDebug("Tourist promotion: " + crew.name);
                }

                if (tourists == null)
                {
                    // TODO: Find out while half of the time we are getting this message
                    printDebug("for some reason tourists are null");
                    continue;
                }
                if (tourists.ContainsKey(crew.name))
                {
                    continue;
                }

                printDebug(String.Format("Creating tourist from cfg; lvl: {0}, crew: {1}", crew.experienceLevel, crew));
                Tourist t = factory.createForLevel(crew.experienceLevel, crew);
                this.tourists.Add(crew.name, t);
                printDebug("Added: " + crew.name + " (" + this.tourists + ")");
            }
            printDebug(String.Format("crew count: {0}", vessel.GetVesselCrew().Count));
            if (vessel.isEVA)
            {
                // ???
            }
        }
        private void reinitEvents(Vessel v)
        {
            Log.dbg("entered reinitEvents for vessel {0}", v);
            foreach (Part p in v.Parts)
            {
                if (!"kerbalEVA".Equals(p.name))
                {
                    continue;
                }
                this.reinitEvents(p);
            }

            KerbalEVA evaCtl = v.evaController;

            if (null == evaCtl)
            {
                return;
            }

            List <ProtoCrewMember> roster = v.GetVesselCrew();

            if (0 == roster.Count)
            {
                Log.dbg("Vessel has no crew.");
                return;
            }

            ProtoCrewMember crew       = roster[0];
            String          kerbalName = crew.name;

            Log.dbg("evCtl found; checking name: {0}", kerbalName);

            if (!tourists.TryGetValue(kerbalName, out Tourist t))
            {
                return;
            }

            Log.dbg("among tourists: {0}", kerbalName);
            t.smile = false;
            t.taken = false;

            if (!Tourist.isTourist(crew))
            {
                Log.dbg("...but is a crew, not a tourist!");
                return;                 // not a real tourist
            }

            // Change crew type right away to avoid them being crew after recovery
            crew.type = ProtoCrewMember.KerbalType.Tourist;

            EVASupport.INSTANCE.disableEvaEvents(v, t.hasAbility("EVA"));
            this.addSelfie(evaCtl);

            Log.dbg("Initializing sound");
            // Should we always invalidate cache???
            fx = null;
            getOrCreateAudio(evaCtl.part.gameObject);
        }
Пример #5
0
        private void OnEvaStart(GameEvents.FromToAction <Part, Part> evaData)
        {
            printDebug("entered; Parts: " + evaData.from + "; " + evaData.to);
            printDebug("active vessel: " + FlightGlobals.ActiveVessel);
            Vessel v = evaData.to.vessel;

            if (!v || !v.evaController)
            {
                return;
            }
            printDebug("vessel: " + v + "; evaCtl: " + v.evaController);
            ProtoCrewMember crew = v.GetVesselCrew() [0];

            printDebug("crew: " + crew);
            if (this.tourists == null)
            {
                // Why we get here twice with the same data?
                printDebug("for some reasons tourists is null");
                return;
            }
            foreach (KeyValuePair <String, Tourist> pair in this.tourists)
            {
                printDebug(pair.Key + "=" + pair.Value);
            }
            printDebug("roster: " + this.tourists);
            Tourist t;

            if (!tourists.TryGetValue(crew.name, out t))
            {
                return;
            }
            printDebug("tourist: " + t);
            if (!Tourist.isTourist(crew) || t.hasAbility("Jetpack"))
            {
                return;
            }

            evaData.to.RequestResource(v.evaController.propellantResourceName,
                                       v.evaController.propellantResourceDefaultAmount);
            // Set propellantResourceDefaultAmount to 0 for EVAFuel to recognize it.
            v.evaController.propellantResourceDefaultAmount = 0.0;

            ScreenMessages.PostScreenMessage(String.Format(
                                                 "<color=orange>Jetpack propellant drained as tourists of level {0} are not allowed to use it</color>",
                                                 t.level));

            // SkyDiving...
            print(String.Format("skydiving: {0}, situation: {1}", t.looksLikeSkydiving(v), v.situation));
            if (t.looksLikeSkydiving(v))
            {
                v.evaController.ladderPushoffForce    = 50;
                v.evaController.autoGrabLadderOnStart = false;
                StartCoroutine(this.deployChute(v));
            }
        }
        private void reinitVessel(Vessel vessel)
        {
            Log.dbg("entered reinitVessel for {0}", vessel.name);
            foreach (ProtoCrewMember crew in vessel.GetVesselCrew())
            {
                Log.dbg("crew = {0}", crew.name);
                if (Tourist.isTourist(crew))
                {
                    crew.type = ProtoCrewMember.KerbalType.Crew;
                    Log.dbg("Tourist promotion: {0}", crew.name);
                }

                if (tourists == null)
                {
                    // TODO: Find out while half of the time we are getting this message
                    Log.dbg("for some reason tourists are null");
                    continue;
                }
                if (tourists.ContainsKey(crew.name))
                {
                    continue;
                }

                Log.dbg("Creating tourist from cfg; lvl: {0}, crew: {1}", crew.experienceLevel, crew);
                Tourist t = factory.createForLevel(crew.experienceLevel, crew);
                this.tourists.Add(crew.name, t);
                Log.dbg("Added: {0} ({1})", crew.name, this.tourists);
            }
            Log.dbg("crew count: {0}", vessel.GetVesselCrew().Count);
            if (vessel.isEVA)
            {
                List <ProtoCrewMember> roster = vessel.GetVesselCrew();
                if (0 == roster.Count)
                {
                    return;
                }
                if (!tourists.TryGetValue(roster[0].name, out Tourist t))
                {
                    return;
                }
                if (!Tourist.isTourist(roster[0]))
                {
                    return;
                }
                if (!t.hasAbility("EVA"))
                {
                    EVASupport.INSTANCE.equipHelmet(vessel);
                }
            }
        }
        private void OnVesselRecoveredOffGame(ProtoVessel vessel, bool wtf)
        {
            Log.dbg("entered; vessel: {0}; wtf: {1}", vessel.vesselName, wtf);
            // Switch tourists back to tourists
            List <ProtoCrewMember> crewList = vessel.GetVesselCrew();

            foreach (ProtoCrewMember crew in crewList)
            {
                Log.dbg("crew={0}", crew.name);
                if (Tourist.isTourist(crew))
                {
                    crew.type = ProtoCrewMember.KerbalType.Tourist;
                }
            }
        }
        private void OnVesselRecoveryRequested(Vessel vessel)
        {
            Log.dbg("entered; vessel: {0}", vessel.name);
            // Switch tourists back to tourists
            List <ProtoCrewMember> crewList = vessel.GetVesselCrew();

            foreach (ProtoCrewMember crew in crewList)
            {
                Log.dbg("crew={0}", crew.name);
                if (Tourist.isTourist(crew))
                {
                    crew.type = ProtoCrewMember.KerbalType.Tourist;
                }
            }
        }
Пример #9
0
        private void OnVesselRecoveredOffGame(ProtoVessel vessel, bool wtf)
        {
            printDebug("entered; vessel: " + vessel.vesselName + "; wtf: " + wtf);
            // Switch tourists back to tourists
            List <ProtoCrewMember> crewList = vessel.GetVesselCrew();

            foreach (ProtoCrewMember crew in crewList)
            {
                printDebug("crew=" + crew.name);
                if (Tourist.isTourist(crew))
                {
                    crew.type = ProtoCrewMember.KerbalType.Tourist;
                }
            }
        }
Пример #10
0
        private void OnVesselCreate(Vessel vessel)
        {
            if (vessel == null)
            {
                return;
            }

            printDebug("name=" + vessel.GetName());

            reinitVessel(vessel);
            reinitEvents(vessel);

            if (vessel.evaController == null)
            {
                return;
            }
            if (!Tourist.isTourist(vessel.GetVesselCrew() [0]))
            {
                return;
            }
        }
Пример #11
0
        public void OnDestroy()
        {
            // Switch tourists back
            printDebug("entered");
            try {
                if (FlightGlobals.VesselsLoaded == null)
                {
                    return;
                }
                printDebug(String.Format("VesselsLoaded: {0}", FlightGlobals.VesselsLoaded));
                foreach (Vessel v in FlightGlobals.VesselsLoaded)
                {
                    printDebug("restoring vessel " + v.name);
                    List <ProtoCrewMember> crewList = v.GetVesselCrew();
                    foreach (ProtoCrewMember crew in crewList)
                    {
                        printDebug("restoring crew=" + crew.name);
                        if (Tourist.isTourist(crew))
                        {
                            crew.type = ProtoCrewMember.KerbalType.Tourist;
                        }
                    }
                }
            }
            catch (NullReferenceException e) {
                printDebug(String.Format("Got NullRef while attempting to access loaded vessels: {0}", e));
            }

            GameEvents.onVesselGoOffRails.Remove(OnVesselGoOffRails);
            GameEvents.onFlightReady.Remove(OnFlightReady);
            GameEvents.onAttemptEva.Remove(OnAttemptEVA);
            GameEvents.onVesselChange.Remove(OnVesselChange);
            GameEvents.onVesselWillDestroy.Remove(OnVesselWillDestroy);

            tourists = null;
            factory  = null;            // do we really need this?
            smile    = false;
            taken    = false;
            fx       = null;
        }
Пример #12
0
        private void checkApproachingGeeLimit()
        {
            if (FlightGlobals.ActiveVessel != null &&
                FlightGlobals.ActiveVessel.geeForce < 4.0)                          // Can there be any tourist with Gee force tolerance below that?

            {
                if (highGee)
                {
                    reinitVessel(FlightGlobals.ActiveVessel);
                    highGee = false;
                    ScreenMessages.PostScreenMessage("EVA prohibition cleared");
                }
                return;
            }
            if (tourists == null)
            {
                return;
            }
            foreach (ProtoCrewMember crew in FlightGlobals.ActiveVessel.GetVesselCrew())
            {
                if (!tourists.ContainsKey(crew.name) ||         // not among tourists
                    !Tourist.isTourist(crew) ||                 // not really a tourist
                    crew.type != ProtoCrewMember.KerbalType.Crew)
                {
                    // was probably unpromoted
                    continue;
                }

                if (crew.gExperienced / ProtoCrewMember.GToleranceMult(crew) > 50000)                   // Magic number. At 60000 kerbal passes out

                {
                    printDebug(String.Format("Unpromoting {0} due to high gee", crew.name));
                    crew.type = ProtoCrewMember.KerbalType.Tourist;
                    ScreenMessages.PostScreenMessage(String.Format(
                                                         "{0} temporary prohibited from EVA due to experienced high Gee forces", crew.name));
                    highGee = true;
                }
            }
        }
        private void OnEvaStart(GameEvents.FromToAction <Part, Part> evaData)
        {
            Log.dbg("entered; KourageousTourists OnEvaStart Parts: {0}; {1}; active vessel: {2}", evaData.from, evaData.to, FlightGlobals.ActiveVessel);
            Vessel v = evaData.to.vessel;

            if (!v || !v.evaController)
            {
                return;
            }
            Log.dbg("vessel: {0}; evaCtl: {1}", v, v.evaController);
            ProtoCrewMember crew = v.GetVesselCrew() [0];

            Log.dbg("crew: {0}", crew);
            if (this.tourists == null)
            {
                // Why we get here twice with the same data?
                Log.dbg("for some reasons tourists is null");
                return;
            }
#if DEBUG
            foreach (KeyValuePair <String, Tourist> pair in this.tourists)
            {
                Log.dbg("{0}={1}", pair.Key, pair.Value);
            }
#endif
            Log.dbg("roster: {0}", this.tourists.Keys);
            Tourist t;
            if (!tourists.TryGetValue(crew.name, out t))
            {
                return;
            }

            if (Tourist.isTourist(crew))
            {
                Log.dbg("tourist: {0}", t);
            }
            else
            {
                Log.error("{0} is not a Tourist. Aborting!", crew);
                return;
            }

            if (!t.hasAbility("Jetpack"))
            {
                evaData.to.RequestResource(v.evaController.propellantResourceName, v.evaController.propellantResourceDefaultAmount);
                // Set propellantResourceDefaultAmount to 0 for EVAFuel to recognize it.
                v.evaController.propellantResourceDefaultAmount = 0.0;
            }

            // SkyDiving...
            if (t.looksLikeSkydiving(v))
            {
                Log.info("skydiving: {0}, situation: {1}", t.looksLikeSkydiving(v), v.situation);
                v.evaController.ladderPushoffForce    = 50;
                v.evaController.autoGrabLadderOnStart = false;
                StartCoroutine(this.deployChute(v));
                return;
            }

            if (0f == v.evaController.propellantResourceDefaultAmount)
            {
                ScreenMessages.PostScreenMessage(String.Format(
                                                     "<color=orange>Jetpack propellant drained as tourists of level {0} are not allowed to use it</color>",
                                                     t.level));
            }
        }
Пример #14
0
        private void reinitEvents(Vessel v)
        {
            printDebug("entered");
            if (v.evaController == null)
            {
                return;
            }
            KerbalEVA evaCtl = v.evaController;

            ProtoCrewMember crew       = v.GetVesselCrew() [0];
            String          kerbalName = crew.name;

            printDebug("evCtl found; checking name: " + kerbalName);
            Tourist t;

            if (!tourists.TryGetValue(kerbalName, out t))
            {
                return;
            }

            printDebug("among tourists: " + kerbalName);
            t.smile = false;
            t.taken = false;

            if (!Tourist.isTourist(v.GetVesselCrew()[0]))
            {
                printDebug("...but is a crew");
                return;                 // not a real tourist
            }

            // Change crew type right away to avoid them being crew after recovery
            crew.type = ProtoCrewMember.KerbalType.Tourist;

            BaseEventList pEvents = evaCtl.Events;

            foreach (BaseEvent e in pEvents)
            {
                printDebug("disabling event " + e.guiName);
                e.guiActive          = false;
                e.guiActiveUnfocused = false;
                e.guiActiveUncommand = false;
            }
            // Adding Selfie button
            BaseEventDelegate slf = new BaseEventDelegate(TakeSelfie);
            KSPEvent          evt = new KSPEvent();

            evt.active             = true;
            evt.externalToEVAOnly  = true;
            evt.guiActive          = true;
            evt.guiActiveEditor    = false;
            evt.guiActiveUnfocused = false;
            evt.guiActiveUncommand = false;
            evt.guiName            = "Take Selfie";
            evt.name = "TakeSelfie";
            BaseEvent selfie = new BaseEvent(pEvents, "Take Selfie", slf, evt);

            pEvents.Add(selfie);
            selfie.guiActive = true;
            selfie.active    = true;

            foreach (PartModule m in evaCtl.part.Modules)
            {
                if (!m.ClassName.Equals("ModuleScienceExperiment"))
                {
                    continue;
                }
                printDebug("science module id: " + ((ModuleScienceExperiment)m).experimentID);
                // Disable all science
                foreach (BaseEvent e in m.Events)
                {
                    e.guiActive          = false;
                    e.guiActiveUnfocused = false;
                    e.guiActiveUncommand = false;
                }

                foreach (BaseAction a in m.Actions)
                {
                    a.active = false;
                }
            }

            printDebug("Initializing sound");
            // Should we always invalidate cache???
            fx = null;
            getOrCreateAudio(evaCtl.part.gameObject);
        }