Пример #1
0
        private static CrewTagModifier GetPlanetSkillModifier(StarSystem currentSystem, Dictionary <string, CrewTagModifier> modifiers)
        {
            CrewTagModifier tagModifiers = new CrewTagModifier();

            foreach (string tag in currentSystem.Tags)
            {
                modifiers.TryGetValue(tag, out CrewTagModifier modifier);
                if (modifier != null)
                {
                    Mod.Log.Debug?.Write($"  tag: {tag} has scarcity =>  " +
                                         $"aerospace: {modifier.Aerospace}  mechTechs: {modifier.MechTechs}  mechwarriors: {modifier.MechWarriors}  medTechs: {modifier.MedTechs}  vehicleCrews: {modifier.VehicleCrews}");
                    tagModifiers.Aerospace    += modifier.Aerospace;
                    tagModifiers.MechWarriors += modifier.MechWarriors;
                    tagModifiers.MechTechs    += modifier.MechTechs;
                    tagModifiers.MedTechs     += modifier.MedTechs;
                    tagModifiers.VehicleCrews += modifier.VehicleCrews;
                }
            }

            return(tagModifiers);
        }
Пример #2
0
        private static PilotDef GenerateSkilledCrew(StarSystem starSystem, bool isMechWarrior)
        {
            string callsign = RandomUnusedCallsign();

            CrewTagModifier planetModifiers = starSystem.GetPlanetSkillDistModifier();
            float           planetMod       = isMechWarrior ? planetModifiers.MechWarriors : planetModifiers.VehicleCrews;
            int             skillIdx        = GaussianHelper.RandomCrewSkill(planetMod, 0);

            Mod.Log.Debug?.Write($" - generated skillIdx: {skillIdx} using planetModifier: {planetMod}");

            // Divide skill points by 4 to generate a median for each skill
            float totalSkillPoints = isMechWarrior ?
                                     Mod.Config.HiringHall.MechWarriors.SkillToExpertiseThresholds[skillIdx] :
                                     Mod.Config.HiringHall.VehicleCrews.SkillToExpertiseThresholds[skillIdx];

            // Normalize to the basic 10/10/10/10 max if we pull the highest index
            if (totalSkillPoints > 40)
            {
                totalSkillPoints = 40;
            }
            float medianSkillPoints = totalSkillPoints / 4;
            // Reduce the median by -2 to allow for random add below
            float adjustedMedian = (float)Math.Max(0, medianSkillPoints - 2);

            Mod.Log.Debug?.Write($" - skillPoints =>  total: {totalSkillPoints} median: {medianSkillPoints}  adjusted: {adjustedMedian}");

            // Each skill can vary +2.0 from adjusted, then rounded to an integer.
            int piloting = (int)Math.Round(adjustedMedian + (Mod.Random.NextDouble() * 2));
            int gunnery  = (int)Math.Round(adjustedMedian + (Mod.Random.NextDouble() * 2));
            int guts     = (int)Math.Round(adjustedMedian + (Mod.Random.NextDouble() * 2));
            int tactics  = (int)Math.Round(adjustedMedian + (Mod.Random.NextDouble() * 2));

            Mod.Log.Debug?.Write($" - skills =>  piloting: {piloting}  gunnery: {gunnery}  guts: {guts}  tactics: {tactics}");

            // TODO: randomize health +/- 1?
            int health = 3;

            PilotDef pilotDef = new PilotDef(new HumanDescriptionDef(), gunnery, piloting, guts, tactics, injuries: 0, health,
                                             lethalInjury: false, morale: 1, voice: "", new List <string>(), AIPersonality.Undefined, 0, 0, 0);
            PilotDef generatedDef = GenerateCrew(starSystem, callsign, pilotDef);

            // Add the necessary tags here *in addition* to in CrewDetails to support Abilifier (it needs the tag before
            //   the call to SetPilotAbilities)
            if (!isMechWarrior)
            {
                generatedDef.PilotTags.Add(ModTags.Tag_CU_NoMech_Crew);
                generatedDef.PilotTags.Add(ModTags.Tag_CU_Vehicle_Crew);
            }
            else
            {
                // TODO: Are there any mechwarrior tags?
            }


            // Abilities must be set AFTER the pilotDef is created, to allow Abilifier a chance to hook into them
            // TODO: Randomize ability selections
            GenerateAbilityDefs(generatedDef, new Dictionary <string, int>()
            {
                { ModConsts.Skill_Gunnery, gunnery },
                { ModConsts.Skill_Guts, guts },
                { ModConsts.Skill_Piloting, piloting },
                { ModConsts.Skill_Tactics, tactics },
            },
                                isMechWarrior ? Mod.Config.HiringHall.MechWarriors : Mod.Config.HiringHall.VehicleCrews
                                );

            generatedDef.ForceRefreshAbilityDefs();

            return(generatedDef);
        }