Esempio n. 1
0
        public void Load(KerbalExt kerbal, ConfigNode node)
        {
            // Resuming a save can involve loading multiple saves before
            // loading the desired one, so ensure loading_kerbals is flushed
            // between loading passes.
            if (reset_loading_kerbals)
            {
                reset_loading_kerbals = false;
                loading_kerbals       = null;
            }

            if (node.HasValue(name))
            {
                var id = node.GetValue(name);
                kerbal[name] = id;
                AddLoadingKerbal(kerbal);
            }
            else
            {
                AddKerbal(kerbal);
                //if (!HighLogic.LoadedSceneIsEditor) {
                //	KerbalStats.current.StartCoroutine (WaitAndAddKerbal (kerbal));
                //}
            }
        }
Esempio n. 2
0
        public void AddKerbal(KerbalExt kerbal)
        {
            if (kerbal[name] != null)
            {
                // already added via an initialization race
                Debug.LogFormat("[Genome] AddKerbal: double add {0}",
                                kerbal.kerbal.name);
                return;
            }
            var genes = new GenePair[traits.Length];

            kerbal[name] = genes;
            if (kerbal.kerbal.name != null)
            {
                RebuildGenes(kerbal.kerbal, genes);
            }
            else
            {
                if (loading_kerbals == null)
                {
                    loading_kerbals = new List <KerbalExt> ();
                }
                loading_kerbals.Add(kerbal);
            }
        }
Esempio n. 3
0
        public void FinishTask(ProtoCrewMember pcm, double UT, string task)
        {
            KerbalExt kerbal = KerbalStats.current[pcm];
            var       exp    = kerbal[name] as Experience;

            exp.FinishTask(UT, task);
        }
Esempio n. 4
0
        public void SetSituation(ProtoCrewMember pcm, double UT,
                                 string body, string situation)
        {
            KerbalExt kerbal = KerbalStats.current[pcm];
            var       exp    = kerbal[name] as Experience;

            exp.SetSituation(UT, body, situation);
        }
Esempio n. 5
0
        public void BeginTask(ProtoCrewMember pcm, double UT, string task,
                              string body, string situation)
        {
            KerbalExt kerbal = KerbalStats.current[pcm];
            var       exp    = kerbal[name] as Experience;

            exp.BeginTask(UT, task, body, situation);
        }
Esempio n. 6
0
        public void Save(KerbalExt kerbal, ConfigNode node)
        {
            var genes = kerbal[name] as GenePair[];
            var gen   = new ConfigNode(name);

            node.AddNode(gen);
            WriteGenes(genes, gen);
        }
Esempio n. 7
0
        IEnumerator WaitAndAddKerbal(KerbalExt kerbal)
        {
            yield return(null);

            yield return(null);

            AddKerbal(kerbal);
        }
Esempio n. 8
0
        public void Save(KerbalExt kerbal, ConfigNode node)
        {
            Experience experience = kerbal[name] as Experience;
            var        exp        = new ConfigNode(name);

            node.AddNode(exp);
            experience.Save(exp);
        }
Esempio n. 9
0
 void AddLoadingKerbal(KerbalExt ext)
 {
     if (loading_kerbals == null || reset_loading_kerbals)
     {
         loading_kerbals       = new List <KerbalExt> ();
         reset_loading_kerbals = false;
     }
     loading_kerbals.Add(ext);
 }
Esempio n. 10
0
 public void Load(KerbalExt kerbal, ConfigNode node)
 {
     if (node.HasNode(name))
     {
         node = node.GetNode(name);
         var genes = ReadGenes(node);
         kerbal[name] = genes;
         RebuildGenes(kerbal.kerbal, genes);
     }
     else
     {
         AddKerbal(kerbal);
     }
 }
Esempio n. 11
0
        public void Load(KerbalExt kerbal, ConfigNode node)
        {
            var experience = new Experience();

            kerbal[name] = experience;
            if (node.HasNode(name))
            {
                var exp = node.GetNode(name);
                experience.Load(exp);
            }
            else
            {
                AddKerbal(kerbal);
            }
        }
Esempio n. 12
0
        public void FinishAllTasks(ProtoCrewMember pcm, double UT)
        {
            KerbalExt kerbal = KerbalStats.current[pcm];

            if (kerbal == null)
            {
                // The kerbal has been removed by the game. Very likely a
                // tourist that has been recovered after completing the tour.
                return;
            }
            var exp = kerbal[name] as Experience;

            foreach (var task in exp.Current)
            {
                exp.FinishTask(UT, task);
            }
        }
Esempio n. 13
0
        public string Get(KerbalExt kerbal, string parms)
        {
            string task      = null;
            string body      = null;
            string situation = null;

            if (parms != "")
            {
                string [] param_list = parms.Split(',');
                for (int i = 0; i < param_list.Count(); i++)
                {
                    string [] args = param_list[i].Split('=');
                    if (args.Count() == 2)
                    {
                        if (args[0] == "task")
                        {
                            task = args[1];
                        }
                        else if (args[0] == "body")
                        {
                            body = args[1];
                        }
                        else if (args[0] == "situation")
                        {
                            situation = args[1];
                        }
                        else
                        {
                            Debug.LogError("[KS] ExperienceTracker.Get: invalid keyword" + args[0]);
                        }
                    }
                    else
                    {
                        Debug.LogError("[KS] ExperienceTracker.Get: invalid param" + param_list[i]);
                    }
                }
            }
            double UT  = Planetarium.GetUniversalTime();
            var    exp = (kerbal[name] as Experience).GetExperience(UT, task, body, situation);

            return(exp.ToString("G17"));
        }
Esempio n. 14
0
        public void Save(KerbalExt kerbal, ConfigNode node)
        {
            // Ensure loading_kerbals gets flushed. The problem is that
            // onGameStateCreated is fired before the kerbal roster is created
            // for new games, and then not fired again until after loading
            // the new game once the space center has been entered. Load and
            // Save are never interleaved, so this is a good way of "detecting"
            // the end of the new game creation.
            reset_loading_kerbals = true;

            if (kerbal[name] == null)
            {
                // If the id is null, then the Progeny scenario never loaded
                // before saving. It is very likelly a new save was created.
                // The id will be set eventually when the scenario does load.
                Debug.LogFormat("[ProgenyTracker] not saving null id for {0}",
                                kerbal.kerbal.name);
                return;
            }
            node.AddValue(name, kerbal[name] as string);
        }
Esempio n. 15
0
        public override void OnLoad(ConfigNode config)
        {
            var game = HighLogic.CurrentGame;

            Debug.Log(String.Format("[KS] OnLoad (scenario)"));
            var roster = config.GetNode("Roster");

            KerbalExt.Clear();

            if (roster != null)
            {
                var kerbal_list = roster.GetNodes("KerbalExt");
                for (int i = 0; i < kerbal_list.Count(); i++)
                {
                    var             kerbal = kerbal_list[i];
                    ProtoCrewMember pcm    = game.CrewRoster[i];
                    var             ext    = new KerbalExt();
                    ext.Load(pcm, kerbal);
                    Master.current.SetExt(pcm, ext);
                }
            }
        }
Esempio n. 16
0
        public void AddKerbal(KerbalExt ext)
        {
            if (ProgenyScenario.current == null)
            {
                Debug.LogFormat("[ProgenyTracker] AddKerbal: delaying add");
                AddLoadingKerbal(ext);
                return;
            }
            Debug.LogFormat("[ProgenyTracker] AddKerbal: adding kerbal");
            Zygote kerbal;

            if (ext.kerbal.gender == ProtoCrewMember.Gender.Female)
            {
                kerbal = new Female(ext.kerbal);
            }
            else
            {
                kerbal = new Male(ext.kerbal);
            }
            kerbal_ids[ext.kerbal.name] = kerbal.id;
            ProgenyScenario.current.AddKerbal(kerbal);
            ext[name] = kerbal.id;
            CheckLocation(ext.kerbal);
        }
Esempio n. 17
0
        private double KerbalContribution(ProtoCrewMember crew)
        {
            string expstr     = KerbalExt.Get(crew, "experience:task=Workshop");
            float  experience = 0;

            if (expstr != null)
            {
                float.TryParse(expstr, out experience);
            }

            double contribution;

            if (crew.isBadass)
            {
                contribution = Baddass(crew.stupidity, crew.courage, experience);
            }
            else
            {
                contribution = Normal(crew.stupidity, crew.courage, experience);
            }
            bool hasConstructionSkill = crew.GetEffect <ELConstructionSkill> () != null;

            if (!hasConstructionSkill)
            {
                if (!enableUnskilled)
                {
                    // can't work here, but may not know to keep out of the way.
                    contribution = Math.Min(contribution, 0);
                }
                if (crew.experienceLevel >= 3)
                {
                    // can resist "ooh, what does this button do?"
                    contribution = Math.Max(contribution, 0);
                }
            }
            else
            {
                switch (crew.experienceLevel)
                {
                case 0:
                    if (!enableSkilled && !SupportInexperienced)
                    {
                        // can't work here, but knows to keep out of the way.
                        contribution = 0;
                    }
                    break;

                case 1:
                    break;

                case 2:
                    if (SupportInexperienced)
                    {
                        // He's learned the ropes.
                        contribution = HyperCurve(contribution);
                    }
                    break;

                default:
                    // He's learned the ropes very well.
                    contribution = HyperCurve(contribution);
                    break;
                }
            }

            /*
             * Debug.LogFormat ("[EL Workshop] Kerbal: "
             + "{0} s:{1} c:{2} b:{3} e:{4}({5}) c:{6} hs:{7} l:{8} es:{9} si:{10}",
             +                               crew.name, crew.stupidity, crew.courage,
             +                               crew.isBadass, experience, expstr,
             +                               contribution, hasConstructionSkill,
             +                               crew.experienceLevel,
             +                               enableSkilled, SupportInexperienced);
             */
            return(contribution);
        }
Esempio n. 18
0
        private float KerbalContribution(ProtoCrewMember crew, float stupidity,
                                         float courage, bool isBadass)
        {
            string expstr     = KerbalExt.Get(crew, "experience:task=Workshop");
            float  experience = 0;

            if (expstr != null)
            {
                float.TryParse(expstr, out experience);
            }

            float contribution;

            if (isBadass)
            {
                contribution = Baddass(stupidity, courage, experience);
            }
            else
            {
                contribution = Normal(stupidity, courage, experience);
            }
            if (useSkill)
            {
                if (!EL_Utils.HasSkill <ExConstructionSkill> (crew))
                {
                    if (!enableUnskilled)
                    {
                        // can't work here, but may not know to keep out of the way.
                        contribution = Mathf.Min(contribution, 0);
                    }
                    if (crew.experienceLevel >= 3)
                    {
                        // can resist "ooh, what does this button do?"
                        contribution = Mathf.Max(contribution, 0);
                    }
                }
                else
                {
                    switch (crew.experienceLevel)
                    {
                    case 0:
                        if (!enableSkilled && !SupportInexperienced)
                        {
                            // can't work here, but knows to keep out of the way.
                            contribution = 0;
                        }
                        break;

                    case 1:
                        break;

                    case 2:
                        if (SupportInexperienced)
                        {
                            // He's learned the ropes.
                            contribution = HyperCurve(contribution);
                        }
                        break;

                    default:
                        // He's learned the ropes very well.
                        contribution = HyperCurve(contribution);
                        break;
                    }
                }
            }
            Debug.Log(String.Format("[EL Workshop] Kerbal: "
                                    + "{0} {1} {2} {3} {4}({5}) {6} {7} {8} {9} {10}",
                                    crew.name, stupidity, courage, isBadass,
                                    experience, expstr, contribution,
                                    EL_Utils.HasSkill <ExConstructionSkill> (crew),
                                    crew.experienceLevel,
                                    enableSkilled, SupportInexperienced));
            return(contribution);
        }
Esempio n. 19
0
        public static GenePair[] GetGenes(ProtoCrewMember pcm)
        {
            KerbalExt kerbal = KerbalStats.current[pcm];

            return(kerbal[extname] as GenePair[]);
        }
Esempio n. 20
0
 public string Get(KerbalExt kerbal, string parms)
 {
     return(null);
 }
Esempio n. 21
0
 public void AddKerbal(KerbalExt kerbal)
 {
     kerbal[name] = new Experience();
 }
Esempio n. 22
0
 public void RemoveKerbal(KerbalExt kerbal)
 {
 }