Jump to content

trying to change Trait"Civilian" -> Eng/Pil/Sci


Recommended Posts

 

Here is the code - everything works, except nothing changes.

/*
?  Based upon KerbalRecruitment from the 'CivilianPopulation' mod for Kerbal Space Program
    https://github.com/linuxgurugamer/CivilianPopulation

    LinuxGuruGamer
    CC BY-NC 4.0 (Attribution-NonCommercial 4.0 International) (https://creativecommons.org/licenses/by-nc/4.0/)
    specifically: https://github.com/linuxgurugamer/CivilianPopulation

    This file has been modified extensively and is released under the same license.

*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using KSP;

namespace MoarKerbals
{
    public class KerbalRecruitment : PartModule
    {
        enum KerbalJob
        {
            Pilot,
            Engineer,
            Scientist
        }

        [KSPEvent(guiName = "Recruit Kerbal", active = true, guiActive = true)]
        void recruitKerbal()
        {
            //Debug.Log(debuggingClass.modName + "Kerbal Recruitment Button pressed!");
            ScreenMessages.PostScreenMessage("Kerbal Recruitment Button pressed!", 3.5f, ScreenMessageStyle.UPPER_CENTER);
            bool changedTrait = false;
            List<ProtoCrewMember> vesselCrew = vessel.GetVesselCrew();
            foreach (ProtoCrewMember crewMember in vesselCrew)
            {
                Log.dbg(crewMember.name + " : " + crewMember.trait + ": " + crewMember.type, 3.5f, ScreenMessageStyle.UPPER_CENTER);
                //if (crewMember.trait == debuggingClass.civilianTrait && changedTrait == false)
                if (crewMember.trait == "Civilian" && changedTrait == false)
                {
                    crewMember.trait = getRandomTrait();
                    //crewMember.Save(.this);
                    crewMember.type = ProtoCrewMember.KerbalType.Crew;
                    //crewMember.trait = KerbalJob.Engineer;
                    changedTrait = true;
                    //HighLogic.CurrentGame.CrewRoster.Save(HighLogic.CurrentGame());
                    Utilities.msg(crewMember.name + " is now a " + crewMember.trait + "!", 3.5f, ScreenMessageStyle.UPPER_CENTER);
                    //      Debug.Log(debuggingClass.modName + crewMember.name + " is now a " + crewMember.trait + "!");
                }
            }
            if (changedTrait) GameEvents.onVesselChange.Fire(FlightGlobals.ActiveVessel);
        }

        private string getRandomTrait()
        {
            int numberOfClasses = 3;
            string kerbalTrait = "";
            int randNum;
            System.Random newRand = new System.Random();
            randNum = newRand.Next() % numberOfClasses;
            if (randNum == 0)
                kerbalTrait = "Pilot";
            if (randNum == 1)
                kerbalTrait = "Engineer";
            if (randNum == 2)
                kerbalTrait = "Scientist";
            ScreenMessages.PostScreenMessage("Created trait:  " + kerbalTrait, 3.5f, ScreenMessageStyle.UPPER_CENTER);
           // Debug.Log(debuggingClass.modName + "Created trait:  " + kerbalTrait);
            return kerbalTrait;
        }
        public override string GetInfo()
        {
            string display = "\r\nInput:\r\n One Civilian Kerbal";

            display += "\r\nOutput:\r\n Pilot, Engineer, Scientest Kerbal (random) eating a MinmusMint icecream cone.";
            return display;
        }
    }
}

Suggestions?

I believe it to be in the assignment of a new trait - and the saving of the kerbal. Beyond my space addled brain.

Thank you in advance!

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...