private void OnKerbalTypeChange(ProtoCrewMember pcm, ProtoCrewMember.KerbalType oldType, ProtoCrewMember.KerbalType newType)
        {
            if (oldType == ProtoCrewMember.KerbalType.Applicant && newType == ProtoCrewMember.KerbalType.Crew)
            {
                // Check for correct trait
                if (!string.IsNullOrEmpty(trait) && pcm.experienceTrait.Config.Name != trait)
                {
                    return;
                }

                // Check for correct gender
                if (gender != null && pcm.gender != gender.Value)
                {
                    return;
                }

                CelestialBody homeworld = FlightGlobals.Bodies.Where(cb => cb.isHomeWorld).FirstOrDefault();

                Debug.Log("Strategia: Awarding experience to " + pcm.name);

                // Find existing entries
                int currentValue = 2;
                foreach (FlightLog.Entry entry in pcm.careerLog.Entries.Concat(pcm.flightLog.Entries).Where(e => e.type.Contains(SPECIAL_XP)))
                {
                    // Get the entry with the largest value
                    int entryValue = Convert.ToInt32(entry.type.Substring(SPECIAL_XP.Length, entry.type.Length - SPECIAL_XP.Length));
                    currentValue = Math.Max(currentValue, entryValue);
                }

                // Get the experience level
                int    value = level;
                string type  = SPECIAL_XP + value.ToString();

                // Do the awarding
                pcm.flightLog.AddEntry(type, homeworld.name);
                pcm.ArchiveFlightLog();

                // Force the astronaut complex GUI to refresh so we actually see the experience
                AstronautComplex ac = UnityEngine.Object.FindObjectOfType <AstronautComplex>();
                if (ac != null)
                {
                    Debug.Log("NewKerbalExperience: CreateAvailableList");
                    MethodInfo updateListMethod = typeof(AstronautComplex).GetMethods(BindingFlags.NonPublic | BindingFlags.Instance).
                                                  Where(mi => mi.Name == "CreateAvailableList").First();
                    updateListMethod.Invoke(ac, new object[] { });

                    Debug.Log("NewKerbalExperience: AddItem_Available");
                    MethodInfo addToListMethod = typeof(AstronautComplex).GetMethods(BindingFlags.NonPublic | BindingFlags.Instance).
                                                 Where(mi => mi.Name == "AddItem_Available").First();
                    addToListMethod.Invoke(ac, new object[] { pcm });
                }
            }
        }
Exemple #2
0
        internal void ThawFrozenCrew(String FrozenCrew, Guid vesselID)
        {
            Utilities.Log("DeepFreezeEvents ThawFrozenCrew = " + FrozenCrew + "," + vesselID);
            bool            fundstaken = false;
            ProtoCrewMember kerbal     = HighLogic.CurrentGame.CrewRoster.Unowned.FirstOrDefault(a => a.name == FrozenCrew);

            if (kerbal != null)
            {
                Vessel vessel = FlightGlobals.Vessels.Find(v => v.id == vesselID);
                // Utilities.Log_Debug("vessel mainbody" + vessel.mainBody.name + " is homeworld? " + vessel.mainBody.isHomeWorld);

                if (vessel == null ||
                    (vessel.mainBody.isHomeWorld &&
                     (vessel.situation == Vessel.Situations.LANDED || vessel.situation == Vessel.Situations.PRELAUNCH || vessel.situation == Vessel.Situations.SPLASHED)))
                {
                    if (HighLogic.CurrentGame.Mode == Game.Modes.CAREER)
                    {
                        if (Funding.CanAfford(DFsettings.KSCcostToThawKerbal))
                        {
                            Funding.Instance.AddFunds(-DFsettings.KSCcostToThawKerbal, TransactionReasons.Vessels);
                            fundstaken = true;
                            Utilities.Log("Took funds to thaw kerbal");
                        }
                        else
                        {
                            Utilities.Log("Not enough funds to thaw kerbal");
                            ScreenMessages.PostScreenMessage("Insufficient funds to thaw " + kerbal.name + " at this time", 5.0f, ScreenMessageStyle.UPPER_LEFT);
                            return;
                        }
                    }
                    kerbal.type         = ProtoCrewMember.KerbalType.Crew;
                    kerbal.rosterStatus = ProtoCrewMember.RosterStatus.Assigned;
                    Utilities.Log_Debug("Kerbal " + kerbal.name + " " + kerbal.type + " " + kerbal.rosterStatus);
                    kerbal.ArchiveFlightLog();
                    kerbal.rosterStatus = ProtoCrewMember.RosterStatus.Available;
                    Utilities.Log_Debug("Kerbal " + kerbal.name + " " + kerbal.type + " " + kerbal.rosterStatus);
                    if (!fundstaken)
                    {
                        ScreenMessages.PostScreenMessage(kerbal.name + " was found and thawed out", 5.0f, ScreenMessageStyle.UPPER_LEFT);
                    }
                    else
                    {
                        ScreenMessages.PostScreenMessage(kerbal.name + " was found and thawed out " + DFsettings.KSCcostToThawKerbal.ToString("########0") + " funds deducted from account", 5.0f, ScreenMessageStyle.UPPER_CENTER);
                    }
                    DFgameSettings.KnownFrozenKerbals.Remove(kerbal.name);
                }
                else
                {
                    Utilities.Log("Cannot thaw, vessel still exists " + vessel.situation + " at " + vessel.mainBody.bodyName);
                    ScreenMessages.PostScreenMessage("Cannot thaw " + kerbal.name + " vessel still exists " + vessel.situation + " at " + vessel.mainBody.bodyName, 5.0f, ScreenMessageStyle.UPPER_CENTER);
                }
            }
        }
Exemple #3
0
        // Removes the given kerbonaut from the crew of the (unloaded) vessel and returns him to the crew-roster:
        public static void RecoverCrewMember(Vessel vessel, string kerbonautName)
        {
            // We can only manipulate the crew of an unloaded ship:
            if (vessel.loaded)
            {
                throw new Exception("TargetVessel.AddCrewMember can only be called on unloaded vessels");
            }
            try
            {
                // Find the part in which the kerbonaut is currently sitting:
                ProtoPartSnapshot sourcePart = null;
                ProtoCrewMember   kerbonaut  = null;
                foreach (var protoPart in vessel.protoVessel.protoPartSnapshots)
                {
                    if (protoPart.protoCrewNames.Contains(kerbonautName))
                    {
                        sourcePart = protoPart;
                        kerbonaut  = protoPart.protoModuleCrew.Find(x => x.name == kerbonautName);
                        break;
                    }
                }
                if (sourcePart == null || kerbonaut == null)
                {
                    // Maybe the plaayer has removed the kerbal from the vessel (eg EVA, docking, etc):
                    Debug.Log("[KSTS] unable to recover kerbonaut " + kerbonautName + " from vessel " + vessel.vesselName + ", kerbal not found on board");
                    ScreenMessages.PostScreenMessage("Crew-Transfer aborted: Kerbonaut " + kerbonautName + " not present on " + vessel.vesselName);
                    return;
                }

                // Remove the kerbal from the part:
                sourcePart.protoCrewNames.Remove(kerbonautName);
                sourcePart.protoModuleCrew.Remove(kerbonaut);

                // Add the kerbal back to the crew-roster:
                kerbonaut.rosterStatus = ProtoCrewMember.RosterStatus.Available;

                // Add the descent-phases to his flight log and archive his flight (commits the flight-current log to his career-log):
                kerbonaut.flightLog.AddEntry(FlightLog.EntryType.Land, Planetarium.fetch.Home.bodyName);
                kerbonaut.flightLog.AddEntry(FlightLog.EntryType.Recover);
                kerbonaut.ArchiveFlightLog();

                // Notyfy other mods about the modification of the vessel's crew:
                GameEvents.onVesselCrewWasModified.Fire(vessel);

                Debug.Log("[KSTS] recovered kerbonaut " + kerbonautName + " from vessel " + vessel.vesselName);
                ScreenMessages.PostScreenMessage("Kerbonaut " + kerbonautName + " recovered from " + vessel.vesselName);
            }
            catch (Exception e)
            {
                Debug.LogError("[KSTS] TargetVessel.RecoverCrewMember(" + vessel.vesselName + "," + kerbonautName + "): " + e.ToString());
            }
        }
Exemple #4
0
        protected void onVesselRecovered(ProtoVessel vessel, bool notSureWhatFor)
        {
            Utilities.Log("DeepFreezeEvents onVesselRecovered " + vessel.vesselID);
            List <string> frznKerbalkeys = new List <string>(DFgameSettings.KnownFrozenKerbals.Keys);

            foreach (string key in frznKerbalkeys)
            {
                KerbalInfo kerbalinfo = DFgameSettings.KnownFrozenKerbals[key];
                if (kerbalinfo.vesselID == vessel.vesselID)
                {
                    if (kerbalinfo.type == ProtoCrewMember.KerbalType.Unowned) //Frozen crew
                    {
                        if (Instance.DFsettings.AutoRecoverFznKerbals)
                        {
                            Utilities.Log_Debug("AutoRecover is ON");
                            Utilities.Log("Calling ThawFrozen Crew to thaw FrozenCrew " + key);
                            ThawFrozenCrew(key, vessel.vesselID);
                        }
                        else
                        {
                            Utilities.Log("DeepFreeze AutoRecovery of frozen kerbals is set to off. Must be thawed manually.");
                            Utilities.Log("DeepFreezeEvents frozenkerbal remains frozen =" + key);
                            ProtoCrewMember realkerbal = HighLogic.CurrentGame.CrewRoster.Unowned.FirstOrDefault(b => b.name == key);
                            if (realkerbal != null)
                            {
                                realkerbal.type         = ProtoCrewMember.KerbalType.Unowned;
                                realkerbal.rosterStatus = ProtoCrewMember.RosterStatus.Dead;
                                Utilities.Log_Debug("Kerbal " + realkerbal.name + " " + realkerbal.type + " " + realkerbal.rosterStatus);
                                ScreenMessages.PostScreenMessage(key + " was stored frozen at KSC", 5.0f, ScreenMessageStyle.UPPER_LEFT);
                            }
                        }
                    }
                    else // Tourist/Comatose crew
                    {
                        Utilities.Log_Debug("Comatose crew - reset to crew " + key);
                        ProtoCrewMember crew = HighLogic.CurrentGame.CrewRoster.Tourist.FirstOrDefault(c => c.name == key);
                        if (crew != null)
                        {
                            crew.type         = ProtoCrewMember.KerbalType.Crew;
                            crew.rosterStatus = ProtoCrewMember.RosterStatus.Assigned;
                            Utilities.Log_Debug("Kerbal " + crew.name + " " + crew.type + " " + crew.rosterStatus);
                            crew.ArchiveFlightLog();
                            crew.rosterStatus = ProtoCrewMember.RosterStatus.Available;
                            DFgameSettings.KnownFrozenKerbals.Remove(crew.name);
                        }
                    }
                }
            }
            var alarmsToDelete = new List <string>();

            alarmsToDelete.AddRange(Instance.DFgameSettings.knownKACAlarms.Where(e => e.Value.VesselID == vessel.vesselID).Select(e => e.Key).ToList());
            alarmsToDelete.ForEach(id => Instance.DFgameSettings.knownKACAlarms.Remove(id));
            var partsToDelete = new List <uint>();

            partsToDelete.AddRange(Instance.DFgameSettings.knownFreezerParts.Where(e => e.Value.vesselID == vessel.vesselID).Select(e => e.Key).ToList());
            partsToDelete.ForEach(id => Instance.DFgameSettings.knownFreezerParts.Remove(id));
            if (DFgameSettings.knownVessels.ContainsKey(vessel.vesselID))
            {
                DFgameSettings.knownVessels.Remove(vessel.vesselID);
            }
        }
        private void kHire()
        {
            if (HighLogic.CurrentGame.Mode == Game.Modes.CAREER)
            {
                double myFunds = Funding.Instance.Funds;
                Funding.Instance.AddFunds(-costMath(), TransactionReasons.CrewRecruited);
                Hire.Log.Info("KSI :: Total Funds removed " + costMath());
            }

            for (int i = 0; i < KBulki; i++)
            {
                ProtoCrewMember newKerb = HighLogic.CurrentGame.CrewRoster.GetNewKerbal(ProtoCrewMember.KerbalType.Crew);

                newKerb.ChangeName(KNames[KGender, i]);

                switch (KGender) // Sets gender
                {
                case 0: newKerb.gender = ProtoCrewMember.Gender.Male; break;

                case 1: newKerb.gender = ProtoCrewMember.Gender.Female; break;

                case 2: newKerb.gender = KNames2Gender[i]; break;

                default: break;
                }

                string career = traits.KCareerStrings[KCareer];
                // Sets the kerbal's career based on the KCareer switch.
                KerbalRoster.SetExperienceTrait(newKerb, career);

                // Hire.Log.Info("KSI :: KIA MIA Stat is: " + KDead);
                // Hire.Log.Info("KSI :: " + newKerb.experienceTrait.TypeName + " " + newKerb.name + " has been created in: " + loopcount.ToString() + " loops.");
                newKerb.rosterStatus    = ProtoCrewMember.RosterStatus.Available;
                newKerb.experience      = 0;
                newKerb.experienceLevel = 0;
                newKerb.courage         = KCourage / 100;
                newKerb.stupidity       = KStupidity / 100;
                if (KFearless)
                {
                    newKerb.isBadass = true;
                }

                if (KVeteran)
                {
                    newKerb.veteran = true;
                }

                // Hire.Log.Info("PSH :: Status set to Available, courage and stupidity set, fearless trait set.");

                if (KLevel == 1)
                {
                    newKerb.flightLog.AddEntry("Training1," + FlightGlobals.GetHomeBodyName());
                    newKerb.ArchiveFlightLog();
                    newKerb.experience      = 2;
                    newKerb.experienceLevel = 1;
                    // Hire.Log.Info("KSI :: Level set to 1.");
                }
                if (KLevel == 2)
                {
                    newKerb.flightLog.AddEntry("Training2," + FlightGlobals.GetHomeBodyName());
                    newKerb.ArchiveFlightLog();
                    newKerb.experience      = 8;
                    newKerb.experienceLevel = 2;
                    // Hire.Log.Info("KSI :: Level set to 2.");
                }
                if (ACLevel == 5 || kerExp == false)
                {
                    newKerb.experience      = 9999;
                    newKerb.experienceLevel = 5;
                    Hire.Log.Info("KSI :: Level set to 5 - Non-Career Mode default.");
                }
                GameEvents.onKerbalAdded.Fire(newKerb);       // old gameevent most likely to be used by other mods
                GameEvents.onKerbalAddComplete.Fire(newKerb); // new gameevent that seems relevant
            }
            // Refreshes the AC so that new kerbal shows on the available roster.
            Hire.Log.Info("PSH :: Hiring Function Completed.");


            GameEvents.onGUIAstronautComplexDespawn.Fire();
            GameEvents.onGUIAstronautComplexSpawn.Fire();
        }
        private void kHire()
        {
            if (HighLogic.CurrentGame.Mode == Game.Modes.CAREER)
            {
                double myFunds = Funding.Instance.Funds;
                Funding.Instance.AddFunds(-costMath(), TransactionReasons.CrewRecruited);
                Debug.Log("KSI :: Total Funds removed " + costMath());
            }

            for (int i = 0; i < KBulki; i++)
            {
                ProtoCrewMember.Gender?chosenGender = null;
                var selectedGender = KGendArray[KGender].text;
                if (selectedGender.Equals("Male"))
                {
                    chosenGender = ProtoCrewMember.Gender.Male;
                }
                else if (selectedGender.Equals("Female"))
                {
                    chosenGender = ProtoCrewMember.Gender.Female;
                }
                ProtoCrewMember newKerb = SpawnKerbal(chosenGender);

                string career = _recruitableKolonists[KCareer];
                // Sets the kerbal's career based on the KCareer switch.
                KerbalRoster.SetExperienceTrait(newKerb, career);

                // Debug.Log("KSI :: KIA MIA Stat is: " + KDead);
                // Debug.Log("KSI :: " + newKerb.experienceTrait.TypeName + " " + newKerb.name + " has been created in: " + loopcount.ToString() + " loops.");
                newKerb.rosterStatus = ProtoCrewMember.RosterStatus.Available;
                newKerb.experience   = 0;


                if (KolonyACOptions.CustomKerbonautsEnabled)
                {
                    newKerb.experienceLevel = 0;
                    newKerb.courage         = KCourage / 100;
                    newKerb.stupidity       = KStupidity / 100;
                    if (KFearless)
                    {
                        newKerb.isBadass = true;
                    }
                }

                // Debug.Log("PSH :: Status set to Available, courage and stupidity set, fearless trait set.");
                if (KLevel > 0)
                {
                    var logName       = RecruitLevel + KLevel;
                    var homeworldName = FlightGlobals.Bodies.Where(cb => cb.isHomeWorld).FirstOrDefault().name;
                    newKerb.flightLog.AddEntry(logName, homeworldName);
                    newKerb.ArchiveFlightLog();
                    newKerb.experience      = GetExperienceNeededFor(KLevel);
                    newKerb.experienceLevel = KLevel;
                }
                if (ACLevel == 5 || kerExp == false)
                {
                    newKerb.experience      = 9999;
                    newKerb.experienceLevel = 5;
                    Debug.Log("KSI :: Level set to 5 - Non-Career Mode default.");
                }
            }

            // Refreshes the AC so that new kerbal shows on the available roster.
            Debug.Log("PSH :: Hiring Function Completed.");
            GameEvents.onGUIAstronautComplexDespawn.Fire();
            GameEvents.onGUIAstronautComplexSpawn.Fire();
        }
Exemple #7
0
        private void kHire()
        {
            if (HighLogic.CurrentGame.Mode == Game.Modes.CAREER)
            {
                double myFunds = Funding.Instance.Funds;
                Funding.Instance.AddFunds(-costMath(), TransactionReasons.CrewRecruited);
                Debug.Log("KSI :: Total Funds removed " + costMath());
            }

            for (int i = 0; i < KBulki; i++)
            {
                ProtoCrewMember newKerb = HighLogic.CurrentGame.CrewRoster.GetNewKerbal(ProtoCrewMember.KerbalType.Crew);

                switch (KGender) // Sets gender
                {
                case 0: newKerb.gender = ProtoCrewMember.Gender.Male; break;

                case 1: newKerb.gender = ProtoCrewMember.Gender.Female; break;

                case 2: break;

                default: break;
                }
                string career = "";
                switch (KCareer) // Sets career
                {
                case 0: career = "Pilot"; break;

                case 1: career = "Scientist"; break;

                case 2: career = "Engineer"; break;

                default: break;    // throw an error?
                }
                // Sets the kerbal's career based on the KCareer switch.
                KerbalRoster.SetExperienceTrait(newKerb, career);

                // Debug.Log("KSI :: KIA MIA Stat is: " + KDead);
                // Debug.Log("KSI :: " + newKerb.experienceTrait.TypeName + " " + newKerb.name + " has been created in: " + loopcount.ToString() + " loops.");
                newKerb.rosterStatus    = ProtoCrewMember.RosterStatus.Available;
                newKerb.experience      = 0;
                newKerb.experienceLevel = 0;
                newKerb.courage         = KCourage / 100;
                newKerb.stupidity       = KStupidity / 100;
                if (KFearless)
                {
                    newKerb.isBadass = true;
                }
                // Debug.Log("PSH :: Status set to Available, courage and stupidity set, fearless trait set.");

                if (KLevel == 1)
                {
                    newKerb.flightLog.AddEntry("Orbit,Kerbin");
                    newKerb.flightLog.AddEntry("Suborbit,Kerbin");
                    newKerb.flightLog.AddEntry("Flight,Kerbin");
                    newKerb.flightLog.AddEntry("Land,Kerbin");
                    newKerb.flightLog.AddEntry("Recover");
                    newKerb.ArchiveFlightLog();
                    newKerb.experience      = 2;
                    newKerb.experienceLevel = 1;
                    // Debug.Log("KSI :: Level set to 1.");
                }
                if (KLevel == 2)
                {
                    newKerb.flightLog.AddEntry("Orbit,Kerbin");
                    newKerb.flightLog.AddEntry("Suborbit,Kerbin");
                    newKerb.flightLog.AddEntry("Flight,Kerbin");
                    newKerb.flightLog.AddEntry("Land,Kerbin");
                    newKerb.flightLog.AddEntry("Recover");
                    newKerb.flightLog.AddEntry("Flyby,Mun");
                    newKerb.flightLog.AddEntry("Orbit,Mun");
                    newKerb.flightLog.AddEntry("Land,Mun");
                    newKerb.flightLog.AddEntry("Flyby,Minmus");
                    newKerb.flightLog.AddEntry("Orbit,Minmus");
                    newKerb.flightLog.AddEntry("Land,Minmus");
                    newKerb.ArchiveFlightLog();
                    newKerb.experience      = 8;
                    newKerb.experienceLevel = 2;
                    // Debug.Log("KSI :: Level set to 2.");
                }
                if (ACLevel == 5 || kerExp == false)
                {
                    newKerb.experience      = 9999;
                    newKerb.experienceLevel = 5;
                    Debug.Log("KSI :: Level set to 5 - Non-Career Mode default.");
                }
            }
            // Refreshes the AC so that new kerbal shows on the available roster.
            Debug.Log("PSH :: Hiring Function Completed.");
            GameEvents.onGUIAstronautComplexDespawn.Fire();
            GameEvents.onGUIAstronautComplexSpawn.Fire();
        }
Exemple #8
0
        private void kHire()
        {
            ProtoCrewMember newKerb = HighLogic.CurrentGame.CrewRoster.GetNewKerbal(ProtoCrewMember.KerbalType.Crew);

            if ((KGender == 0) && (KCareer == 0))
            {
                while ((newKerb.experienceTrait.Title != "Pilot") || (newKerb.gender.ToString() != "Male"))
                {
                    HighLogic.CurrentGame.CrewRoster.Remove(newKerb);
                    newKerb = HighLogic.CurrentGame.CrewRoster.GetNewKerbal(ProtoCrewMember.KerbalType.Crew);
                }
            }
            if ((KGender == 0) && (KCareer == 1))
            {
                while ((newKerb.experienceTrait.Title != "Scientist") || (newKerb.gender.ToString() != "Male"))
                {
                    HighLogic.CurrentGame.CrewRoster.Remove(newKerb);
                    newKerb = HighLogic.CurrentGame.CrewRoster.GetNewKerbal(ProtoCrewMember.KerbalType.Crew);
                }
            }
            if ((KGender == 0) && (KCareer == 2))
            {
                while ((newKerb.experienceTrait.Title != "Engineer") || (newKerb.gender.ToString() != "Male"))
                {
                    HighLogic.CurrentGame.CrewRoster.Remove(newKerb);
                    newKerb = HighLogic.CurrentGame.CrewRoster.GetNewKerbal(ProtoCrewMember.KerbalType.Crew);
                }
            }
            if ((KGender == 1) && (KCareer == 0))
            {
                while ((newKerb.experienceTrait.Title != "Pilot") || (newKerb.gender.ToString() != "Female"))
                {
                    HighLogic.CurrentGame.CrewRoster.Remove(newKerb);
                    newKerb = HighLogic.CurrentGame.CrewRoster.GetNewKerbal(ProtoCrewMember.KerbalType.Crew);
                }
            }
            if ((KGender == 1) && (KCareer == 1))
            {
                while ((newKerb.experienceTrait.Title != "Scientist") || (newKerb.gender.ToString() != "Female"))
                {
                    HighLogic.CurrentGame.CrewRoster.Remove(newKerb);
                    newKerb = HighLogic.CurrentGame.CrewRoster.GetNewKerbal(ProtoCrewMember.KerbalType.Crew);
                }
            }
            if ((KGender == 1) && (KCareer == 2))
            {
                while ((newKerb.experienceTrait.Title != "Engineer") || (newKerb.gender.ToString() != "Female"))
                {
                    HighLogic.CurrentGame.CrewRoster.Remove(newKerb);
                    newKerb = HighLogic.CurrentGame.CrewRoster.GetNewKerbal(ProtoCrewMember.KerbalType.Crew);
                }
            }

            ScreenMessages.PostScreenMessage(newKerb.experienceTrait.TypeName + " " + newKerb.name + " has been created?");
            newKerb.rosterStatus    = ProtoCrewMember.RosterStatus.Available;
            newKerb.experience      = 0;
            newKerb.experienceLevel = 0;
            newKerb.courage         = KCourage / 100;
            newKerb.stupidity       = KStupidity / 100;
            if (KFearless)
            {
                newKerb.isBadass = true;
            }
            if (KLevel == 1)
            {
                newKerb.flightLog.AddEntry("Orbit,Kerbin");
                newKerb.flightLog.AddEntry("Suborbit,Kerbin");
                newKerb.flightLog.AddEntry("Flight,Kerbin");
                newKerb.flightLog.AddEntry("Land,Kerbin");
                newKerb.flightLog.AddEntry("Recover");
                newKerb.ArchiveFlightLog();
                newKerb.experience      = 2;
                newKerb.experienceLevel = 1;
            }
            if (KLevel == 2)
            {
                newKerb.flightLog.AddEntry("Orbit,Kerbin");
                newKerb.flightLog.AddEntry("Suborbit,Kerbin");
                newKerb.flightLog.AddEntry("Flight,Kerbin");
                newKerb.flightLog.AddEntry("Land,Kerbin");
                newKerb.flightLog.AddEntry("Recover");
                newKerb.flightLog.AddEntry("Flyby,Mun");
                newKerb.flightLog.AddEntry("Orbit,Mun");
                newKerb.flightLog.AddEntry("Land,Mun");
                newKerb.flightLog.AddEntry("Flyby,Minmus");
                newKerb.flightLog.AddEntry("Orbit,Minmus");
                newKerb.flightLog.AddEntry("Land,Minmus");
                newKerb.ArchiveFlightLog();
                newKerb.experience      = 8;
                newKerb.experienceLevel = 2;
            }
            if (ACLevel == 5)
            {
                newKerb.experience      = 9999;
                newKerb.experienceLevel = 5;
            }

            newKerb.rosterStatus = ProtoCrewMember.RosterStatus.Available;
            roster.GetNewKerbal(newKerb.type);
            KerbalRoster.SetExperienceTrait(newKerb);
            GameEvents.onGUIAstronautComplexSpawn.Fire();
            if (HighLogic.CurrentGame.Mode == Game.Modes.CAREER)
            {
                Funding.Instance.AddFunds(-costMath(), TransactionReasons.CrewRecruited);
            }
        }
Exemple #9
0
        private void kHire()
        {
            ProtoCrewMember newKerb   = HighLogic.CurrentGame.CrewRoster.GetNewKerbal(ProtoCrewMember.KerbalType.Crew);
            int             loopcount = 0;

            ProtoCrewMember.Gender gender = (KGender == 0)? ProtoCrewMember.Gender.Male : ProtoCrewMember.Gender.Female;
            string career = "";

            switch (KCareer)
            {
            case 0: career = "Pilot"; break;

            case 1: career = "Scientist"; break;

            case 2: career = "Engineer"; break;

            default: break;    // throw an error?
            }
            while ((newKerb.experienceTrait.Title != career) || (newKerb.gender != gender))
            {
                HighLogic.CurrentGame.CrewRoster.Remove(newKerb);
                newKerb = HighLogic.CurrentGame.CrewRoster.GetNewKerbal(ProtoCrewMember.KerbalType.Crew);
                loopcount++;
            }

            Debug.Log("KSI :: KIA MIA Stat is: " + KDead);
            Debug.Log("KSI :: " + newKerb.experienceTrait.TypeName + " " + newKerb.name + " has been created in: " + loopcount.ToString() + " loops.");
            newKerb.rosterStatus    = ProtoCrewMember.RosterStatus.Available;
            newKerb.experience      = 0;
            newKerb.experienceLevel = 0;
            newKerb.courage         = KCourage / 100;
            newKerb.stupidity       = KStupidity / 100;
            if (KFearless)
            {
                newKerb.isBadass = true;
            }
            Debug.Log("KSI :: Status set to Available, courage and stupidity set, fearless trait set.");

            if (KLevel == 1)
            {
                newKerb.flightLog.AddEntry("Orbit,Kerbin");
                newKerb.flightLog.AddEntry("Suborbit,Kerbin");
                newKerb.flightLog.AddEntry("Flight,Kerbin");
                newKerb.flightLog.AddEntry("Land,Kerbin");
                newKerb.flightLog.AddEntry("Recover");
                newKerb.ArchiveFlightLog();
                newKerb.experience      = 2;
                newKerb.experienceLevel = 1;
                Debug.Log("KSI :: Level set to 1.");
            }
            if (KLevel == 2)
            {
                newKerb.flightLog.AddEntry("Orbit,Kerbin");
                newKerb.flightLog.AddEntry("Suborbit,Kerbin");
                newKerb.flightLog.AddEntry("Flight,Kerbin");
                newKerb.flightLog.AddEntry("Land,Kerbin");
                newKerb.flightLog.AddEntry("Recover");
                newKerb.flightLog.AddEntry("Flyby,Mun");
                newKerb.flightLog.AddEntry("Orbit,Mun");
                newKerb.flightLog.AddEntry("Land,Mun");
                newKerb.flightLog.AddEntry("Flyby,Minmus");
                newKerb.flightLog.AddEntry("Orbit,Minmus");
                newKerb.flightLog.AddEntry("Land,Minmus");
                newKerb.ArchiveFlightLog();
                newKerb.experience      = 8;
                newKerb.experienceLevel = 2;
                Debug.Log("KSI :: Level set to 2.");
            }
            if (ACLevel == 5)
            {
                newKerb.experience      = 9999;
                newKerb.experienceLevel = 5;
                Debug.Log("KSI :: Level set to 5 - Non-Career Mode default.");
            }

            GameEvents.onGUIAstronautComplexSpawn.Fire();
            // Refreshes the AC so that new kerbal shows on the available roster.


            // GameEvents.OnCrewmemberHired.Fire(newKerb, HighLogic.CurrentGame.CrewRoster.GetActiveCrewCount());
            // The previous line was commented out because it was charging the cost determined by my mod plus the stock game cost in the previous event.
            // This lead to even higher costs than if you weren't even using my mod... even if you could hire level 2 kerbals. \


            if (HighLogic.CurrentGame.Mode == Game.Modes.CAREER)
            {
                double myFunds = Funding.Instance.Funds;
                Funding.Instance.AddFunds(-costMath(), TransactionReasons.CrewRecruited);
                Debug.Log("KSI :: Total Funds removed " + costMath());
            }
            Debug.Log("KSI :: Hiring Function Completed.");
        }
Exemple #10
0
        private void kHire()
        {
            System.Random rand = new System.Random();

            if (HighLogic.CurrentGame.Mode == Game.Modes.CAREER)
            {
                double myFunds = Funding.Instance.Funds;
                Funding.Instance.AddFunds(-costMath(), TransactionReasons.CrewRecruited);
                Hire.Log.Info("KSI :: Total Funds removed " + costMath());
            }

            for (int i = 0; i < KBulki; i++)
            {
                ProtoCrewMember newKerb = HighLogic.CurrentGame.CrewRoster.GetNewKerbal(ProtoCrewMember.KerbalType.Crew);

                newKerb.ChangeName(KNames[KGender, i]);

                switch (KGender) // Sets gender
                {
                case 0: newKerb.gender = ProtoCrewMember.Gender.Male; break;

                case 1: newKerb.gender = ProtoCrewMember.Gender.Female; break;

                case 2: newKerb.gender = KNames2Gender[i]; break;

                default: break;
                }

                string career = traits.traitTitles[KCareer].name;
                // Sets the kerbal's career based on the KCareer switch.
                KerbalRoster.SetExperienceTrait(newKerb, career);

                // Hire.Log.Info("KSI :: KIA MIA Stat is: " + KDead);
                // Hire.Log.Info("KSI :: " + newKerb.experienceTrait.Config.Name + " " + newKerb.name + " has been created in: " + loopcount.ToString() + " loops.");
                newKerb.rosterStatus    = ProtoCrewMember.RosterStatus.Available;
                newKerb.experience      = 0;
                newKerb.experienceLevel = 0;
                if (KBulki > 0) // Bulk hires get random stats
                {
                    // The equation gives 60% of results within +/-10% of GUI setting
                    newKerb.courage   = (float)Math.Min(1, Math.Max(0, (Math.Pow(2 * rand.NextDouble() - 1, 3) / 2) + KCourage / 100));
                    newKerb.stupidity = (float)Math.Min(1, Math.Max(0, (Math.Pow(2 * rand.NextDouble() - 1, 3) / 2) + KStupidity / 100));
                    // 5% chance of Badass
                    newKerb.isBadass = rand.NextDouble() > .95;
                    // No chance of vets in bulk hires.
                    newKerb.veteran = false;
                }
                else // use GUI values
                {
                    newKerb.courage   = KCourage / 100;
                    newKerb.stupidity = KStupidity / 100;
                    if (KFearless)
                    {
                        newKerb.isBadass = true;
                    }

                    if (KVeteran)
                    {
                        newKerb.veteran = true;
                    }
                }

                // Hire.Log.Info("PSH :: Status set to Available, courage and stupidity set, fearless trait set.");

                if (kerExp == false)
                {
                    newKerb.experience      = 9999;
                    newKerb.experienceLevel = 5;
                    Hire.Log.Info("KSI :: Level set to 5 - Kerbal Experince disabled.");
                }
                else
                {
                    switch (KLevel)
                    {
                    case 1:
                        newKerb.flightLog.AddEntry("Training1," + FlightGlobals.GetHomeBodyName());
                        newKerb.ArchiveFlightLog();
                        newKerb.experience      = 2;
                        newKerb.experienceLevel = 1;
                        // Hire.Log.Info("KSI :: Level set to 1.");
                        break;

                    case 2:
                        newKerb.flightLog.AddEntry("Training2," + FlightGlobals.GetHomeBodyName());
                        newKerb.ArchiveFlightLog();
                        newKerb.experience      = 8;
                        newKerb.experienceLevel = 2;
                        // Hire.Log.Info("KSI :: Level set to 2.");
                        break;

                    case 3:
                        newKerb.flightLog.AddEntry("Training3," + FlightGlobals.GetHomeBodyName());
                        newKerb.ArchiveFlightLog();
                        newKerb.experience      = 16;
                        newKerb.experienceLevel = 3;
                        // Hire.Log.Info("KSI :: Level set to 3.");
                        break;

                    case 4:
                        newKerb.flightLog.AddEntry("Training4," + FlightGlobals.GetHomeBodyName());
                        newKerb.ArchiveFlightLog();
                        newKerb.experience      = 32;
                        newKerb.experienceLevel = 4;
                        // Hire.Log.Info("KSI :: Level set to 4.");
                        break;

                    case 5:
                        newKerb.flightLog.AddEntry("Training5," + FlightGlobals.GetHomeBodyName());
                        newKerb.ArchiveFlightLog();
                        newKerb.experience      = 64;
                        newKerb.experienceLevel = 5;
                        break;
                    }
                }
                GameEvents.onKerbalAdded.Fire(newKerb);       // old gameevent most likely to be used by other mods
                GameEvents.onKerbalAddComplete.Fire(newKerb); // new gameevent that seems relevant
            }
            // Refreshes the AC so that new kerbal shows on the available roster.
            Hire.Log.Info("PSH :: Hiring Function Completed.");


            GameEvents.onGUIAstronautComplexDespawn.Fire();
            GameEvents.onGUIAstronautComplexSpawn.Fire();
        }
        private void OnKerbalTypeChange(ProtoCrewMember pcm, ProtoCrewMember.KerbalType oldType, ProtoCrewMember.KerbalType newType)
        {
            if (oldType == ProtoCrewMember.KerbalType.Applicant && newType == ProtoCrewMember.KerbalType.Crew)
            {
                // Check for correct trait
                if (!string.IsNullOrEmpty(trait) && pcm.experienceTrait.Config.Name != trait)
                {
                    return;
                }

                // Check for correct gender
                if (gender != null && pcm.gender != gender.Value)
                {
                    return;
                }

                CelestialBody homeworld = FlightGlobals.Bodies.Where(cb => cb.isHomeWorld).FirstOrDefault();

                Debug.Log("Strategia: Awarding experience to " + pcm.name);

                // Find existing entries
                int currentValue = 2;
                foreach (FlightLog.Entry entry in pcm.careerLog.Entries.Concat(pcm.flightLog.Entries).Where(e => e.type.Contains(SPECIAL_XP)))
                {
                    // Get the entry with the largest value
                    int entryValue = Convert.ToInt32(entry.type.Substring(SPECIAL_XP.Length, entry.type.Length - SPECIAL_XP.Length));
                    currentValue = Math.Max(currentValue, entryValue);
                }

                // Get the experience level
                int value = Parent.Level();
                string type = SPECIAL_XP + value.ToString();

                // Do the awarding
                pcm.flightLog.AddEntry(type, homeworld.name);
                pcm.ArchiveFlightLog();

                // Force the astronaut complex GUI to refresh so we actually see the experience
                AstronautComplex ac = UnityEngine.Object.FindObjectOfType<AstronautComplex>();
                if (ac != null)
                {
                    Debug.Log("NewKerbalExperience: CreateAvailableList");
                    MethodInfo updateListMethod = typeof(AstronautComplex).GetMethods(BindingFlags.NonPublic | BindingFlags.Instance).
                        Where(mi => mi.Name == "CreateAvailableList").First();
                    updateListMethod.Invoke(ac, new object[] { });

                    Debug.Log("NewKerbalExperience: AddItem_Available");
                    MethodInfo addToListMethod = typeof(AstronautComplex).GetMethods(BindingFlags.NonPublic | BindingFlags.Instance).
                        Where(mi => mi.Name == "AddItem_Available").First();
                    addToListMethod.Invoke(ac, new object[] { pcm });
                }
            }
        }
        public void TransferCareerLog(ProtoCrewMember to, ProtoCrewMember from)
        {
            // record current flightlog & reset, if applicable
            FlightLog current = null;
            if (to.flightLog.Entries.Count() > 0) {
                current = new FlightLog();
                foreach (FlightLog.Entry entry in to.flightLog.Entries)
                    current.Entries.Add(entry);
                to.flightLog = new FlightLog();
            }

            //transfer careerLog
            foreach (FlightLog flight in from.careerLog.GetFlights()) {
                foreach (FlightLog.Entry entry in flight.Entries)
                    to.flightLog.Entries.Add(entry);
                to.ArchiveFlightLog();
            }

            //rewrite flightLog, if applicable
            if (current != null)
                foreach (FlightLog.Entry entry in current.Entries)
                    to.flightLog.Entries.Add(entry);
        }
Exemple #13
0
        private void kHire()
        {
            if (HighLogic.CurrentGame.Mode == Game.Modes.CAREER)
            {
                double myFunds = Funding.Instance.Funds;
                Funding.Instance.AddFunds(-costMath(), TransactionReasons.CrewRecruited);
                Debug.Log("KSI :: Total Funds removed " + costMath());
            }

            for (int i = 0; i < KBulki; i++)
            {
                ProtoCrewMember newKerb = HighLogic.CurrentGame.CrewRoster.GetNewKerbal(ProtoCrewMember.KerbalType.Crew);

                switch (KGender) // Sets gender
                {
                case 0: newKerb.gender = ProtoCrewMember.Gender.Male; break;

                case 1: newKerb.gender = ProtoCrewMember.Gender.Female; break;

                case 2: break;

                default: break;
                }
                string career = "";
                switch (KCareer) // Sets career
                {
                case 0: career = "Pilot"; break;

                case 1: career = "Scientist"; break;

                case 2: career = "Engineer"; break;

                case 3: career = "Kolonist"; break;

                case 4: career = "Scout"; break;

                case 5: career = "Kolonist"; break;

                case 6: career = "Miner"; break;

                case 7: career = "Technician"; break;

                case 8: career = "Mechanic"; break;

                case 9: career = "Biologist"; break;

                case 10: career = "Geologist"; break;

                case 11: career = "Farmer"; break;

                case 12: career = "Medic"; break;

                case 13: career = "Quartermaster"; break;
                }
                // Sets the kerbal's career based on the KCareer switch.
                KerbalRoster.SetExperienceTrait(newKerb, career);

                // Debug.Log("KSI :: KIA MIA Stat is: " + KDead);
                // Debug.Log("KSI :: " + newKerb.experienceTrait.TypeName + " " + newKerb.name + " has been created in: " + loopcount.ToString() + " loops.");
                newKerb.rosterStatus    = ProtoCrewMember.RosterStatus.Available;
                newKerb.experience      = 0;
                newKerb.experienceLevel = 0;
                newKerb.courage         = KCourage / 100;
                newKerb.stupidity       = KStupidity / 100;
                if (KFearless)
                {
                    newKerb.isBadass = true;
                }
                // Debug.Log("PSH :: Status set to Available, courage and stupidity set, fearless trait set.");
                if (KLevel > 0)
                {
                    var logName       = RecruitLevel + KLevel;
                    var homeworldName = FlightGlobals.Bodies.Where(cb => cb.isHomeWorld).FirstOrDefault().name;
                    newKerb.flightLog.AddEntry(logName, homeworldName);
                    newKerb.ArchiveFlightLog();
                    newKerb.experience      = GetExperienceNeededFor(KLevel);
                    newKerb.experienceLevel = KLevel;
                }
                if (ACLevel == 5 || kerExp == false)
                {
                    newKerb.experience      = 9999;
                    newKerb.experienceLevel = 5;
                    Debug.Log("KSI :: Level set to 5 - Non-Career Mode default.");
                }
            }
            // Refreshes the AC so that new kerbal shows on the available roster.
            Debug.Log("PSH :: Hiring Function Completed.");
            GameEvents.onGUIAstronautComplexDespawn.Fire();
            GameEvents.onGUIAstronautComplexSpawn.Fire();
        }
Exemple #14
0
        protected string recruitAstronaut()
        {
            KerbalRoster    roster     = HighLogic.CurrentGame.CrewRoster;
            string          message    = string.Empty;
            ProtoCrewMember newRecruit = roster.GetNewKerbal();

            debugLog("New kerbal: " + newRecruit.name);

            newRecruit.type         = ProtoCrewMember.KerbalType.Crew;
            newRecruit.rosterStatus = ProtoCrewMember.RosterStatus.Available;

            if (statusType == BARISStatusTypes.badS)
            {
                newRecruit.isBadass = true;
            }

            //Adjust rank
            debugLog("New recruit rank: " + rank);
            if (rank >= 1)
            {
                newRecruit.experience      = 2;
                newRecruit.experienceLevel = 1;
                newRecruit.flightLog.AddEntry("Flight,Kerbin");
                newRecruit.flightLog.AddEntry("Suborbit,Kerbin");
                newRecruit.flightLog.AddEntry("Orbit,Kerbin");
                newRecruit.flightLog.AddEntry("Landed,Kerbin");
                newRecruit.flightLog.AddEntry("Recover");
                newRecruit.ArchiveFlightLog();
            }
            if (rank >= 2)
            {
                newRecruit.experience      = 8;
                newRecruit.experienceLevel = 2;
                newRecruit.flightLog.AddEntry("Flight,Kerbin");
                newRecruit.flightLog.AddEntry("Suborbit,Kerbin");
                newRecruit.flightLog.AddEntry("Orbit,Kerbin");
                newRecruit.flightLog.AddEntry("Flyby,Mun");
                newRecruit.flightLog.AddEntry("Orbit,Mun");
                newRecruit.flightLog.AddEntry("Landed,Mun");
                newRecruit.flightLog.AddEntry("Flyby,Minmus");
                newRecruit.flightLog.AddEntry("Orbit,Minmus");
                newRecruit.flightLog.AddEntry("Landed,Minmus");
                newRecruit.flightLog.AddEntry("Landed,Kerbin");
                newRecruit.flightLog.AddEntry("Recover");
                newRecruit.ArchiveFlightLog();
            }
            if (rank >= 3)
            {
                newRecruit.experience      = 16;
                newRecruit.experienceLevel = 3;
                newRecruit.flightLog.AddEntry("Flight,Kerbin");
                newRecruit.flightLog.AddEntry("Suborbit,Kerbin");
                newRecruit.flightLog.AddEntry("Orbit,Kerbin");
                newRecruit.flightLog.AddEntry("Flyby,Mun");
                newRecruit.flightLog.AddEntry("Orbit,Mun");
                newRecruit.flightLog.AddEntry("Landed,Mun");
                newRecruit.flightLog.AddEntry("PlantFlag,Mun");
                newRecruit.flightLog.AddEntry("Flyby,Minmus");
                newRecruit.flightLog.AddEntry("Orbit,Minmus");
                newRecruit.flightLog.AddEntry("Landed,Minmus");
                newRecruit.flightLog.AddEntry("PlantFlag,Minmus");
                newRecruit.flightLog.AddEntry("Orbit,Minmus");
                newRecruit.flightLog.AddEntry("Orbit,Sun");
                newRecruit.flightLog.AddEntry("Landed,Kerbin");
                newRecruit.flightLog.AddEntry("Recover");
                newRecruit.ArchiveFlightLog();
            }

            //Game events
            newRecruit.UpdateExperience();
            roster.Update(Planetarium.GetUniversalTime());
            GameEvents.onKerbalAdded.Fire(newRecruit);
            GameEvents.onKerbalLevelUp.Fire(newRecruit);
            GamePersistence.SaveGame("persistent", HighLogic.SaveFolder, SaveMode.APPEND);

            //Inform player
            message = newRecruit.name + Localizer.Format(BARISScenario.StatusRecruitedMsg);
            return(message);
        }