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;
        }
        public void Awake()
        {
            ConfigNode config = GameDatabase.Instance.GetConfigNodes(
                KourageousTouristsAddOn.cfgRoot).FirstOrDefault();
            String debugState = config.GetValue("debug");

            debug = debugState != null &&
                    (debugState.ToLower().Equals("true") || debugState.Equals("1"));


            printDebug("entered");
            printDebug("scene: " + HighLogic.LoadedScene);

            GameEvents.OnVesselRecoveryRequested.Add(OnVesselRecoveryRequested);

            if (!HighLogic.LoadedSceneIsFlight)
            {
                return;
            }

            if (factory == null)
            {
                factory = new TouristFactory();
            }
            if (tourists == null)
            {
                tourists = new Dictionary <String, Tourist> ();
            }

            selfieTime = DateTime.Now;

            printDebug("Setting handlers");

            //GameEvents.onVesselChange.Add (OnVesselChange);
            GameEvents.onVesselGoOffRails.Add(OnVesselGoOffRails);
            GameEvents.onFlightReady.Add(OnFlightReady);
            GameEvents.onAttemptEva.Add(OnAttemptEVA);

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

            //reinitCrew (FlightGlobals.ActiveVessel);
        }
Esempio n. 3
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;
        }
        public void Awake()
        {
            Log.dbg("entered KourageousTourists Awake scene:{0}", HighLogic.LoadedScene);

            bool forceTouristsInSandbox = false;

            ConfigNode config = Settings.Read();

            if (config == null)
            {
                Log.warn("No config nodes!");
                return;
            }
            String debugState     = config.GetValue("debug");
            String noDiving       = config.GetValue("noSkyDiving");
            String forceInSandbox = config.GetValue("forceTouristsInSandbox");

            try
            {
                paraglidingChutePitch  = float.Parse(config.GetValue("paraglidingChutePitch"));
                paraglidingDeployDelay = float.Parse(config.GetValue("paraglidingDeployDelay"));
                paraglidingMaxAirspeed = float.Parse(config.GetValue("paraglidingMaxAirpseed"));
                paraglidingMinAltAGL   = float.Parse(config.GetValue("paraglidingMinAltAGL"));
                Log.detail("paragliding params: pitch: {0}, delay: {1}, speed: {2}, alt: {3}", paraglidingChutePitch, paraglidingDeployDelay, paraglidingMaxAirspeed, paraglidingMinAltAGL);
            }
            catch (Exception) {
                Log.detail("Failed parsing paragliding tweaks!");
            }

            Log.detail("debug: {0}; nodiving: {1}; forceInSB: {2}", debugState, noDiving, forceInSandbox);

            debug = debugState != null &&
                    (debugState.ToLower().Equals("true") || debugState.Equals("1"));
            noSkyDiving = noDiving != null &&
                          (noDiving.ToLower().Equals("true") || noDiving.Equals("1"));
            forceTouristsInSandbox = forceInSandbox != null &&
                                     (forceInSandbox.ToLower().Equals("true") || forceInSandbox.Equals("1"));

            Log.detail("debug: {0}; nodiving: {1}; forceInSB: {2}", debug, noSkyDiving, forceTouristsInSandbox);
            Log.detail("highlogic: {0}", HighLogic.fetch);
            Log.detail("game: {0}", HighLogic.CurrentGame);

            // Ignore non-career game mode
            if (HighLogic.CurrentGame == null ||
                (!forceTouristsInSandbox && HighLogic.CurrentGame.Mode != Game.Modes.CAREER))
            {
                return;
            }
            Log.detail("scene: {0}", HighLogic.LoadedScene);

            GameEvents.OnVesselRecoveryRequested.Add(OnVesselRecoveryRequested);

            if (!HighLogic.LoadedSceneIsFlight)
            {
                return;
            }

            if (factory == null)
            {
                factory = new TouristFactory();
            }
            if (tourists == null)
            {
                tourists = new Dictionary <String, Tourist> ();
            }

            selfieTime = DateTime.Now;

            Log.dbg("Setting handlers");

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

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

            //reinitCrew (FlightGlobals.ActiveVessel);
        }