Beispiel #1
0
        protected void calculateRemodelCostModifier(string skillRequired = kDefaultSkill)
        {
            int highestLevel = 0;

            //Check for a kerbal on EVA
            if (FlightGlobals.ActiveVessel.isEVA)
            {
                Vessel          vessel    = FlightGlobals.ActiveVessel;
                ProtoCrewMember astronaut = vessel.GetVesselCrew()[0];

                if (astronaut.HasEffect(skillRequired))
                {
                    reconfigureCostModifier = 1 - (baseSkillModifier * astronaut.experienceTrait.CrewMemberExperienceLevel());
                    return;
                }
            }

            //No kerbal on EVA. Check the vessel for the highest ranking kerbal onboard with the required skill.
            foreach (ProtoCrewMember protoCrew in this.vessel.GetVesselCrew())
            {
                if (protoCrew.HasEffect(skillRequired))
                {
                    if (protoCrew.experienceLevel > highestLevel)
                    {
                        highestLevel = protoCrew.experienceLevel;
                    }
                }
            }

            reconfigureCostModifier = 1 - (baseSkillModifier * highestLevel);
        }
        protected float calculateRepairCost()
        {
            if (this.part.vessel == null)
            {
                return(-1.0f);
            }

            float  repairUnits    = repairAmount;
            double totalResources = ResourceHelper.GetTotalResourceAmount(repairResource, this.part.vessel);

            //Anybody can repair the scope, but the right skill can reduce the cost by as much as 60%
            ProtoCrewMember astronaut = FlightGlobals.ActiveVessel.GetVesselCrew()[0];

            if (astronaut.HasEffect(repairSkill))
            {
                repairUnits = repairUnits * (0.9f - (astronaut.experienceTrait.CrewMemberExperienceLevel() * 0.1f));
            }

            //Now make sure the kerbal has enough resources to conduct repairs.
            //Get the resource definition
            PartResourceDefinition definition = ResourceHelper.DefinitionForResource(repairResource);

            if (definition == null)
            {
                return(-1.0f);
            }

            //make sure the ship has enough of the resource
            if (totalResources < repairUnits)
            {
                return(-1.0f);
            }

            return(repairUnits);
        }
Beispiel #3
0
        public override bool IsValid(ProtoCrewMember astronaut)
        {
            if (!base.IsValid(astronaut))
            {
                return(false);
            }

            return(astronaut.HasEffect(skillToCheck) == mustExist);
        }
        private float calculateCalibration(ProtoCrewMember c, int l)
        {
            int level = c.experienceTrait.CrewMemberExperienceLevel();

            int m = 0;

            if (c.HasEffect <ExternalExperimentSkill>())
            {
                m = 1;
            }
            else if (c.HasEffect <AutopilotSkill>())
            {
                m = 0;
            }
            else if (c.HasEffect <RepairSkill>())
            {
                m = -1;
            }
            else
            {
                m = -5;
            }

            level += m;

            float f = 1;

            int i = level - l;

            float mod = i * 0.25f;

            f += mod;

            if (f >= 2f)
            {
                f = 2f;
            }
            else if (f < 0.25f)
            {
                f = 0.25f;
            }

            return(f);
        }
        protected virtual bool hasSufficientSkill()
        {
            if (HighLogic.LoadedSceneIsFlight == false)
            {
                return(true);
            }
            if (!WBIMainSettings.RequiresSkillCheck)
            {
                return(true);
            }
            if (string.IsNullOrEmpty(upgradeSkill))
            {
                return(true);
            }
            if (Utils.IsExperienceEnabled() == false)
            {
                return(true);
            }
            bool   hasAtLeastOneCrew = false;
            string errorMessage      = string.Format(kInsufficientSkill + Utils.GetTraitsWithEffect(upgradeSkill), this.part.partInfo.title);

            //Make sure we have an experienced person either out on EVA performing the reconfiguration, or inside the module.
            //Check EVA first
            if (FlightGlobals.ActiveVessel.isEVA)
            {
                Vessel          vessel    = FlightGlobals.ActiveVessel;
                ProtoCrewMember astronaut = vessel.GetVesselCrew()[0];

                if (astronaut.HasEffect(upgradeSkill) == false)
                {
                    ScreenMessages.PostScreenMessage(errorMessage, 5.0f, ScreenMessageStyle.UPPER_CENTER);
                    return(false);
                }
                return(true);
            }

            //Now check the vessel
            foreach (ProtoCrewMember protoCrew in this.part.vessel.GetVesselCrew())
            {
                if (protoCrew.HasEffect(upgradeSkill))
                {
                    hasAtLeastOneCrew = true;
                    break;
                }
            }

            if (!hasAtLeastOneCrew)
            {
                ScreenMessages.PostScreenMessage(kInsufficientCrew, 5.0f, ScreenMessageStyle.UPPER_CENTER);
                return(false);
            }

            //Yup, we have sufficient skill.
            return(true);
        }
Beispiel #6
0
        protected void reconfigureDrill()
        {
            //If required, make sure we have the proper skill
            if (WBIMainSettings.RequiresSkillCheck)
            {
                if (FlightGlobals.ActiveVessel.isEVA && Utils.IsExperienceEnabled())
                {
                    Vessel          vessel    = FlightGlobals.ActiveVessel;
                    ProtoCrewMember astronaut = vessel.GetVesselCrew()[0];

                    if (astronaut.HasEffect(requiredSkill))
                    {
                        ScreenMessages.PostScreenMessage(string.Format(kInsufficientSkill, requiredSkill), 5.0f, ScreenMessageStyle.UPPER_CENTER);
                        return;
                    }
                }
            }

            //If needed, pay the cost to reconfigure
            if (WBIMainSettings.PayToReconfigure)
            {
                //Make sure we can afford it
                PartResourceDefinition definition = ResourceHelper.DefinitionForResource(requiredResource);

                //Pay for the reconfiguration cost.
                double partsPaid = this.part.RequestResource(definition.id, reconfigureCost, ResourceFlowMode.ALL_VESSEL);

                //Could we afford it?
                if (Math.Abs(partsPaid) / Math.Abs(reconfigureCost) < 0.999f)
                {
                    ScreenMessages.PostScreenMessage(string.Format(insufficientResourcesMsg, reconfigureCost, requiredResource), 6.0f, ScreenMessageStyle.UPPER_CENTER);

                    //Put back what we took
                    this.part.RequestResource(definition.id, -partsPaid, ResourceFlowMode.ALL_VESSEL);
                    return;
                }
            }

            //Now reconfigure the drill.
            ModuleResourceHarvester drill;
            string resourceName;

            for (int drillIndex = 0; drillIndex < groundDrills.Count; drillIndex++)
            {
                drill        = groundDrills[drillIndex];
                resourceName = resourceList[groundDrillResourceIndexes[drillIndex]];
                setupDrillGUI(drill, resourceName);
            }
            ScreenMessages.PostScreenMessage(kDrillReconfigured, 5.0f, ScreenMessageStyle.UPPER_CENTER);
        }
Beispiel #7
0
        public void ScrapPartEVA()
        {
            //Make sure that there are no kerbals on the part.
            if (this.part.protoModuleCrew.Count > 0)
            {
                ScreenMessages.PostScreenMessage(kPartIsOccupied, kMessageDuration, ScreenMessageStyle.UPPER_CENTER);
            }

            //Check for confirmation
            if (PathfinderSettings.ConfirmScrap && !scrapConfirmed)
            {
                scrapConfirmed = true;
                ScreenMessages.PostScreenMessage(kConfirmScrap, kMessageDuration, ScreenMessageStyle.UPPER_CENTER);
                return;
            }
            scrapConfirmed = false;

            if (FlightGlobals.ActiveVessel.isEVA)
            {
                Vessel          vessel    = FlightGlobals.ActiveVessel;
                ProtoCrewMember astronaut = vessel.GetVesselCrew()[0];

                //Check for skill & experience.
                if (astronaut.HasEffect(scrapSkill) == false)
                {
                    ScreenMessages.PostScreenMessage(string.Format(kInsufficientSkill, Utils.GetTraitsWithEffect(scrapSkill)), kMessageDuration, ScreenMessageStyle.UPPER_CENTER);
                    return;
                }
                if (Utils.IsExperienceEnabled())
                {
                    //Check for experience level
                    if (astronaut.experienceLevel < minimumPartRecycleSkill)
                    {
                        ScreenMessages.PostScreenMessage(string.Format(kInsufficientExperiencePart, minimumPartRecycleSkill), kMessageDuration, ScreenMessageStyle.UPPER_CENTER);
                        return;
                    }
                }

                //Ok, we're good to go, get the resource definition for the recycleResource.
                PartResourceDefinition def = ResourceHelper.DefinitionForResource(recycleResource);
                if (def == null)
                {
                    Debug.Log("[WBIPartScrapper] - Definition not found for " + recycleResource);
                    return;
                }

                //Recycle the part and its resources
                recyclePart(this.part, def, astronaut);
            }
        }
Beispiel #8
0
        public void ShowDrillSwitchWindow()
        {
            //Make sure we have an experienced engineer.
            if (FlightGlobals.ActiveVessel.isEVA && Utils.IsExperienceEnabled())
            {
                Vessel          vessel    = FlightGlobals.ActiveVessel;
                ProtoCrewMember astronaut = vessel.GetVesselCrew()[0];

                if (astronaut.HasEffect(requiredSkill) && WBIMainSettings.RequiresSkillCheck)
                {
                    ScreenMessages.PostScreenMessage(kEngineerNeeded, 5.0f, ScreenMessageStyle.UPPER_CENTER);
                    return;
                }
            }

            drillSwitchWindow.groundDrills = groundDrills;
            drillSwitchWindow.SetVisible(true);
        }
Beispiel #9
0
        internal void ComputeHome(ProtoCrewMember c, LifeSupportStatus cls)
        {
            var crewHomeString  = "indefinite";
            var lblHome         = "6FFF00";
            var useHabPenalties = LifeSupportManager.GetNoHomeEffect(c.name) > 0;

            if (useHabPenalties)
            {
                var homeTimeLeft = cls.MaxOffKerbinTime - Planetarium.GetUniversalTime();
                UpdateEarliestExpiration(homeTimeLeft);

                var isScout    = c.HasEffect("ExplorerSkill") && homeTimeLeft >= LifeSupportScenario.Instance.settings.GetSettings().ScoutHabTime;
                var isPermaHab = homeTimeLeft >= LifeSupportScenario.Instance.settings.GetSettings().PermaHabTime;

                if (isScout || isPermaHab)
                {
                    crewHomeString = "indefinite";
                }
                else if (homeTimeLeft < 0)
                {
                    lblHome        = "FF5E5E";
                    crewHomeString = "expired";
                }
                else
                {
                    crewHomeString = LifeSupportUtilities.SmartDurationDisplay(homeTimeLeft);
                    var secondsPerDay = LifeSupportUtilities.SecondsPerDay();
                    if (homeTimeLeft < secondsPerDay * 30) //15 days
                    {
                        lblHome = "FFE100";
                    }
                    if (homeTimeLeft < secondsPerDay * 15)
                    {
                        lblHome = "FFAE00";
                    }
                }
            }
            HomeLabel = String.Format("<color=#{0}>{1}</color>", lblHome, crewHomeString);
        }
Beispiel #10
0
        protected override bool hasSufficientSkill(string templateName)
        {
            if (HighLogic.LoadedSceneIsFlight == false)
            {
                return(true);
            }
            if (!WBIMainSettings.RequiresSkillCheck)
            {
                return(true);
            }
            if (templateManager[templateName] == null)
            {
                return(true);
            }
            string skillRequired = templateManager[templateName].GetValue(kReconfigureSkillField);

            if (string.IsNullOrEmpty(skillRequired))
            {
                return(true);
            }
            bool hasAtLeastOneCrew = false;

            if (string.IsNullOrEmpty(skillRequired))
            {
                calculateRemodelCostModifier();
                return(true);
            }

            //Make sure we have an experienced person either out on EVA performing the reconfiguration, or inside the module.
            //Check EVA first
            if (FlightGlobals.ActiveVessel.isEVA)
            {
                Vessel          vessel    = FlightGlobals.ActiveVessel;
                ProtoCrewMember astronaut = vessel.GetVesselCrew()[0];

                if (astronaut.HasEffect(skillRequired) == false)
                {
                    string[]      traits     = Utils.GetTraitsWithEffect(skillRequired);
                    StringBuilder traitsList = new StringBuilder();
                    foreach (string trait in traits)
                    {
                        traitsList.Append(trait + ",");
                    }

                    ScreenMessages.PostScreenMessage(kInsufficientSkill + traitsList.ToString().TrimEnd(new char[] { ',' }), 5.0f, ScreenMessageStyle.UPPER_CENTER);
                    return(false);
                }

                calculateRemodelCostModifier(skillRequired);
                return(true);
            }

            //Now check the vessel
            foreach (ProtoCrewMember protoCrew in this.part.vessel.GetVesselCrew())
            {
                if (protoCrew.HasEffect(skillRequired))
                {
                    hasAtLeastOneCrew = true;
                    break;
                }
            }

            if (!hasAtLeastOneCrew)
            {
                ScreenMessages.PostScreenMessage(kInsufficientCrew, 5.0f, ScreenMessageStyle.UPPER_CENTER);
                return(false);
            }

            //Yup, we have sufficient skill.
            calculateRemodelCostModifier(skillRequired);
            return(true);
        }
Beispiel #11
0
        public float GetProspectBonus()
        {
            //skillBonus: multiplied by the EVA prospector's skill level. Default is 1.0.
            //labBonus: For each geology lab in the vicinity, bonus is 0.5 * crew skill per crewmember that has the prospectSkill.
            //anomalyBonus: If the prospector is near an anomaly, then they get an anomaly bonus.
            //asteroidBonus: If the prospector has captured an asteroid, then they get an asteroid bonus.
            //Ex: A 3-star scientist on EVA makes a prospect check. skillBonus = 3; prospectSkillBonus = 1.0. Total skill bonus = 3.0.
            //Inside the Bison there are two level-1 scientists staffing a geology lab. labBonus = 2 * 0.5 = 1

            float skillBonus    = GoldStrikeSettings.BonusPerSkillPoint;
            float prospectBonus = 0f;
            float labBonus      = 0f;
            float asteroidBonus = 0f;

            Vessel[] vessels;
            Vessel   vessel;

            ProtoCrewMember[] crewMembers;
            ProtoCrewMember   crewMember;

            WBIGeoLab[] geoLabs;
            WBIGeoLab   geoLab;
            ProtoVessel protoVessel;

            //If an experienced prospector is taking the core sample, then the prospector's experience will
            //affect the analysis.
            if (FlightGlobals.ActiveVessel.isEVA && Utils.IsExperienceEnabled())
            {
                vessel = FlightGlobals.ActiveVessel;
                ProtoCrewMember astronaut = vessel.GetVesselCrew()[0];

                if (astronaut.HasEffect(prospectSkill))
                {
                    prospectBonus = astronaut.experienceTrait.CrewMemberExperienceLevel() * skillBonus;
                }
            }

            //Factor in lab bonus
            //Bonus is 0.5 * crew skill (max 2.5) per crewmember
            vessels = FlightGlobals.VesselsLoaded.ToArray();
            for (int index = 0; index < vessels.Length; index++)
            {
                vessel = vessels[index];

                //Geology lab
                List <WBIGeoLab> geologyLabs = vessel.FindPartModulesImplementing <WBIGeoLab>();
                if (geologyLabs.Count > 0)
                {
                    geoLabs = geologyLabs.ToArray();
                    for (int labIndex = 0; labIndex < geoLabs.Length; labIndex++)
                    {
                        geoLab = geoLabs[labIndex];
                        if (geoLab.part.protoModuleCrew.Count > 0)
                        {
                            crewMembers = geoLab.part.protoModuleCrew.ToArray();
                            for (int crewIndex = 0; crewIndex < crewMembers.Length; crewIndex++)
                            {
                                crewMember = crewMembers[crewIndex];
                                if (crewMember.HasEffect(prospectSkill))
                                {
                                    labBonus += kLabSkillBonus * crewMember.experienceTrait.CrewMemberExperienceLevel();
                                }
                            }
                        }
                    }
                }

                //GoldStrike bonus: Some parts give a bonus- but it costs science data to do so.
                List <WBIGoldStrikeBonus> goldStrikeBonuses = vessel.FindPartModulesImplementing <WBIGoldStrikeBonus>();
                WBIGoldStrikeBonus        goldStrikeBonus;
                if (goldStrikeBonuses.Count > 0)
                {
                    for (int bonusIndex = 0; bonusIndex < goldStrikeBonuses.Count; bonusIndex++)
                    {
                        goldStrikeBonus = goldStrikeBonuses[bonusIndex];
                        if (goldStrikeBonus.prospectingDataAmount >= goldStrikeBonus.dataCostPerBonus && goldStrikeBonus.prospectingDataAmount > 0f)
                        {
                            labBonus += (goldStrikeBonus.prospectingDataAmount / goldStrikeBonus.dataCostPerBonus) * goldStrikeBonus.Bonus;
                            goldStrikeBonus.prospectingDataAmount = 0f;
                        }
                    }
                }
            }

            //Unloaded vessels lab bonus
            vessels = FlightGlobals.VesselsUnloaded.ToArray();
            float calculatedBonus       = 0f;
            float prospectingDataAmount = 0f;
            float dataCostPerBonus      = 1.0f;

            for (int index = 0; index < vessels.Length; index++)
            {
                vessel      = vessels[index];
                protoVessel = vessel.protoVessel;

                //Only applies to vessels of the same body that are landed.
                if (vessel.mainBody != this.part.vessel.mainBody)
                {
                    continue;
                }
                if (vessel.situation != Vessel.Situations.LANDED && vessel.situation != Vessel.Situations.PRELAUNCH)
                {
                    continue;
                }

                //Find all the geology labs & parts that give a bonus to Gold Strike
                foreach (ProtoPartSnapshot partSnapshot in protoVessel.protoPartSnapshots)
                {
                    foreach (ProtoPartModuleSnapshot moduleSnapshot in partSnapshot.modules)
                    {
                        calculatedBonus       = 0f;
                        prospectingDataAmount = 0f;
                        dataCostPerBonus      = 1.0f;

                        if (moduleSnapshot.moduleName == "WBIGeologyLab" || moduleSnapshot.moduleName == "WBIGeoLab")
                        {
                            foreach (ProtoCrewMember protoCrewMember in partSnapshot.protoModuleCrew)
                            {
                                if (protoCrewMember.HasEffect(prospectSkill))
                                {
                                    labBonus += kLabSkillBonus * protoCrewMember.experienceTrait.CrewMemberExperienceLevel();
                                }
                            }
                        }

                        else if (moduleSnapshot.moduleName == "WBIGoldStrikeBonus")
                        {
                            if (moduleSnapshot.moduleValues.HasValue("calculatedBonus"))
                            {
                                calculatedBonus = float.Parse(moduleSnapshot.moduleValues.GetValue("calculatedBonus"));
                            }
                            if (moduleSnapshot.moduleValues.HasValue("prospectingDataAmount"))
                            {
                                prospectingDataAmount = float.Parse(moduleSnapshot.moduleValues.GetValue("prospectingDataAmount"));
                            }
                            if (moduleSnapshot.moduleValues.HasValue("dataCostPerBonus"))
                            {
                                dataCostPerBonus = float.Parse(moduleSnapshot.moduleValues.GetValue("dataCostPerBonus"));
                            }

                            if (prospectingDataAmount >= dataCostPerBonus && prospectingDataAmount > 0)
                            {
                                labBonus += (prospectingDataAmount / dataCostPerBonus) * calculatedBonus;
                                prospectingDataAmount = 0f;
                                moduleSnapshot.moduleValues.SetValue("prospectingDataAmount", 0f);
                            }
                        }
                    }
                }
            }

            //Location bonus
            anomalyBonus = 0;
            anomalyBonus = getAnomalyBonus();

            //Asteroid bonus
            if (asteroid != null)
            {
                asteroidBonus = kAsteroidBonus;
            }

            debugLog("Prospector bonus: " + prospectBonus + " labBonus: " + labBonus + " anomalyBonus: " + anomalyBonus + " asteroidBonus: " + asteroidBonus);
            return(Mathf.RoundToInt(prospectBonus + labBonus + anomalyBonus + asteroidBonus));
        }
Beispiel #12
0
        public void ScrapVessel()
        {
            //Make sure the vessel isn't occupied.
            if (this.part.vessel.GetCrewCount() > 0)
            {
                ScreenMessages.PostScreenMessage(kVesselIsOccupied, kMessageDuration, ScreenMessageStyle.UPPER_CENTER);
                return;
            }

            //Check for confirmation
            if (PathfinderSettings.ConfirmScrap && !scrapConfirmed)
            {
                scrapConfirmed = true;
                ScreenMessages.PostScreenMessage(kConfirmScrap, kMessageDuration, ScreenMessageStyle.UPPER_CENTER);
                return;
            }
            scrapConfirmed = false;

            if (FlightGlobals.ActiveVessel.isEVA)
            {
                Vessel          vessel    = FlightGlobals.ActiveVessel;
                ProtoCrewMember astronaut = vessel.GetVesselCrew()[0];

                //Check for skill & experience.
                if (astronaut.HasEffect(scrapSkill) == false)
                {
                    ScreenMessages.PostScreenMessage(string.Format(kInsufficientSkill, Utils.GetTraitsWithEffect(scrapSkill)), kMessageDuration, ScreenMessageStyle.UPPER_CENTER);
                    return;
                }
                if (Utils.IsExperienceEnabled())
                {
                    //Check for experience level
                    if (astronaut.experienceLevel < minimumVesselRecycleSkill)
                    {
                        ScreenMessages.PostScreenMessage(string.Format(kInsufficientExperienceVessel, minimumVesselRecycleSkill), kMessageDuration, ScreenMessageStyle.UPPER_CENTER);
                        return;
                    }
                }

                //Ok, we're good to go, get the resource definition for the recycleResource.
                PartResourceDefinition def = ResourceHelper.DefinitionForResource(recycleResource);
                if (def == null)
                {
                    Debug.Log("[WBIPartScrapper] - Definition not found for " + recycleResource);
                    return;
                }

                //Recycle all parts in the vessel.
                List <Part> doomedParts = new List <Part>();
                foreach (Part doomed in this.part.vessel.parts)
                {
                    if (doomed != this.part)
                    {
                        doomedParts.Add(doomed);
                    }
                }
                foreach (Part doomed in doomedParts)
                {
                    recyclePart(doomed, def, astronaut);
                }

                //Final recycle
                recyclePart(this.part, def, astronaut);
            }
        }
Beispiel #13
0
        public override VesselControlState UpdateControlSourceState()
        {
            this.commCapable = false;
            bool isHibernating = this.IsHibernating;

            var        ksList = this.part.Modules.OfType <KerbalSeat>();
            KerbalSeat ks     = this.part.Modules.OfType <KerbalSeat>().First();

            //  KerbalEVA kev;
            // Part seatParent = null;

            if (ks == null)
            {
                Log.Error("Can't find KerbalSeat in part: " + this.part.partInfo.title);
                this.controlSrcStatusText = "No Crew";
                this.moduleState          = ModuleCommand.ModuleControlState.NotEnoughCrew;
                return(VesselControlState.Kerbal);
            }
            this.pilots = (this.crewCount = (this.totalCrewCount = 0));
            // Kerbal kerbal = null;
            ProtoCrewMember pcm = null;

#if false
            foreach (var k in ksList)
            {
                if (k.Occupant != null)
                {
                    foreach (var k2 in k.Occupant.Modules.OfType <KerbalEVA>())
                    {
                        if (k2 != null)
                        {
                            seatParent = getModulePartParent("KerbalEVA", keva);
                        }
                    }
                }
            }
#endif

            if (ks.Occupant != null)
            {
                KerbalEVA keva = ks.Occupant.Modules.OfType <KerbalEVA>().FirstOrDefault();

                if (keva != null)
                {
                    var seatParentList = getModulePartParent("KerbalEVA", keva);

                    if (seatParentList != null)
                    {
                        foreach (var seatParent in seatParentList)
                        {
                            Log.Info("seatParent: " + seatParent.partInfo.title + "  seatParent.protoModuleCrew.count: " + seatParent.protoModuleCrew.Count().ToString());
                            foreach (var p in seatParent.protoModuleCrew)
                            {
                                Log.Info("Looking for: " + ks.Occupant.partInfo.title + "      p.name: " + p.name);
                                if (p.name == ks.Occupant.partInfo.title)
                                {
                                    // Look for a crew member, if possible
                                    if (pcm == null || (pcm != null && pcm.type == ProtoCrewMember.KerbalType.Tourist && p.type == ProtoCrewMember.KerbalType.Crew))
                                    {
                                        pcm = p;
                                    }
                                    // If not a pilot, keep looking
                                    if (p.type == ProtoCrewMember.KerbalType.Crew && p.HasEffect <FullVesselControlSkill>() && !p.inactive)
                                    {
                                        pcm = p;
                                        break;
                                    }
                                    //if (pcm.type == ProtoCrewMember.KerbalType.Crew && pcm.HasEffect<FullVesselControlSkill>() && !pcm.inactive)
                                    //break;
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                Log.Info("No occupant in any seat");
                Log.Info("this.vessel.name: " + this.vessel.name);
                Log.Info("FlightGlobals.ActiveVessel.name: " + FlightGlobals.ActiveVessel.name);

                this.controlSrcStatusText = "No Crew";
                this.moduleState          = ModuleCommand.ModuleControlState.NotEnoughCrew;
                return(VesselControlState.Kerbal);
            }


            if (pcm != null)
            {
                if (pcm.HasEffect <FullVesselControlSkill>() && !pcm.inactive)
                {
                    this.pilots = 1;
                }
                if (pcm.type != ProtoCrewMember.KerbalType.Tourist)
                {
                    this.totalCrewCount = 1;
                    if (!pcm.inactive)
                    {
                        this.crewCount = 1;
                    }
                }
            }
            else
            {
                if (ks.Occupant != null)
                {
                    Log.Error("Unable to find Kerbal: " + ks.Occupant.partInfo.title + " in crew list");
                }
                else
                {
                    Log.Error("Unable to find Kerbal in crew list");
                }
                this.controlSrcStatusText = "No Crew";
                this.moduleState          = ModuleCommand.ModuleControlState.NotEnoughCrew;
                return(VesselControlState.Kerbal);
            }

            if (this.crewCount == 0)
            {
                if (pcm.type == ProtoCrewMember.KerbalType.Tourist)
                {
                    this.controlSrcStatusText = "Tourists Need Crew";
                    this.moduleState          = ModuleCommand.ModuleControlState.TouristCrew;
                    return(VesselControlState.Kerbal);
                }
                this.controlSrcStatusText = "No Crew";
                this.moduleState          = ModuleCommand.ModuleControlState.NotEnoughCrew;
                return(VesselControlState.Kerbal);
            }

            bool pilotNeededNotAvail = this.requiresPilot && this.pilots == 0;
            this.commCapable = true;
            if (CommNetScenario.CommNetEnabled && CommNetScenario.Instance != null)
            {
                bool connectionNeededAndConnected = this.Connection != null && this.Connection.IsConnected;

                if (!this.remoteControl && !connectionNeededAndConnected && pilotNeededNotAvail)
                {
                    if (this.controlSrcStatusText != "No Pilot")
                    {
                        this.controlSrcStatusText = "No Pilot";
                    }

                    this.moduleState = ModuleCommand.ModuleControlState.PartialManned;
                    return(VesselControlState.KerbalPartial);
                }
                if (!connectionNeededAndConnected)
                {
                    if (this.totalCrewCount == 0)
                    {
                        if (this.SignalRequired || !this.remoteControl)
                        {
                            if (this.controlSrcStatusText != "No Telemetry")
                            {
                                this.controlSrcStatusText = "No Telemetry";
                            }

                            this.moduleState = ModuleCommand.ModuleControlState.NoControlPoint;
                            return(VesselControlState.Probe);
                        }
                        if (this.requiresTelemetry)
                        {
                            if (this.controlSrcStatusText != "Partial Control")
                            {
                                this.controlSrcStatusText = "Partial Control";
                            }

                            this.moduleState = ModuleCommand.ModuleControlState.PartialProbe;
                            return(VesselControlState.ProbePartial);
                        }
                    }
                }
            }

            if (isHibernating)
            {
                if (this.controlSrcStatusText != "Hibernating")
                {
                    this.controlSrcStatusText = "Hibernating";
                }

                if (this.minimumCrew > 0)
                {
                    this.moduleState = ModuleCommand.ModuleControlState.PartialManned;
                    return(VesselControlState.KerbalPartial);
                }
                this.moduleState = ModuleCommand.ModuleControlState.PartialProbe;
                return(VesselControlState.ProbePartial);
            }
            else
            {
                if (this.controlSrcStatusText != "Operational")
                {
                    this.controlSrcStatusText = "Operational";
                }
                this.moduleState = ModuleCommand.ModuleControlState.Nominal;
                if (this.minimumCrew > 0)
                {
                    return(VesselControlState.KerbalFull);
                }
                return(VesselControlState.ProbeFull);
            }
        }
Beispiel #14
0
        protected virtual void performAnalysis()
        {
            CBAttributeMapSO.MapAttribute biome = Utils.GetCurrentBiome(this.part.vessel);
            float  experienceLevel    = 0f;
            float  experienceModifier = 0f;
            float  analysisRoll       = 0f;
            string analysisResultMessage;
            float  efficiencyModifier = 0f;
            float  currentModifier    = 0f;

            //Decrement the attempts remaining count
            int samplesLeft = getSamplesLeft() - 1;

            if (samplesLeft <= 0)
            {
                samplesLeft = 0;
            }
            WBIPathfinderScenario.Instance.SetCoreSamplesRemaining(this.part.vessel.mainBody.flightGlobalsIndex, biome.name, (HarvestTypes)resourceType, samplesLeft);
            coreSampleStatus = samplesLeft.ToString();

            //Dirty the GUI
            MonoUtilities.RefreshContextWindows(this.part);

            //If an experienced scientist is taking the core sample, then the scientist's experience will
            //affect the analysis.
            if (FlightGlobals.ActiveVessel.isEVA && Utils.IsExperienceEnabled())
            {
                Vessel          vessel    = FlightGlobals.ActiveVessel;
                ProtoCrewMember astronaut = vessel.GetVesselCrew()[0];

                if (astronaut.HasEffect(analysisSkill))
                {
                    experienceLevel = astronaut.experienceTrait.CrewMemberExperienceLevel();
                }
            }

            //Add in the science lab bonus
            experienceLevel += getGeologyLabBonus();

            //Seed the random number generator
            UnityEngine.Random.InitState(System.Environment.TickCount);

            //Roll 3d6 to approximate a bell curve, then convert it to a value between 1 and 100.
            analysisRoll  = UnityEngine.Random.Range(1, 6);
            analysisRoll += UnityEngine.Random.Range(1, 6);
            analysisRoll += UnityEngine.Random.Range(1, 6);
            analysisRoll *= 5.5556f;

            //Now add the experience modifier
            experienceModifier = experienceLevel * kExperiencePercentModifier;
            analysisRoll      += experienceModifier;

            //Did we strike gold?
            if (goldStrike != null)
            {
                goldStrike.CheckGoldStrike();
            }

            //Since we're using a bell curve, anything below maxWorsenRoll worsens the biome's extraction rates.
            //Anything above minImprovementRoll improves the biome's extraction rates.
            //A skilled scientist can affect the modifier by as much as 5%.
            if (analysisRoll <= maxWorsenRoll)
            {
                //Calculate the modifier
                efficiencyModifier = -kBaseEfficiencyModifier * (1.0f - (experienceLevel / 100f));

                //Format the result message
                analysisResultMessage = string.Format(kResourceExtractionWorsened, Math.Abs((efficiencyModifier * 100.0f))) + biome.name;

                //Save the modifier
                currentModifier = WBIPathfinderScenario.Instance.GetEfficiencyModifier(this.part.vessel.mainBody.flightGlobalsIndex,
                                                                                       biome.name, (HarvestTypes)resourceType, EfficiencyData.kExtractionMod);
                WBIPathfinderScenario.Instance.SetEfficiencyData(this.part.vessel.mainBody.flightGlobalsIndex,
                                                                 biome.name, (HarvestTypes)resourceType, EfficiencyData.kExtractionMod, currentModifier + efficiencyModifier);
            }

            //Good result!
            else if (analysisRoll >= minImprovementRoll)
            {
                //Calculate the modifier
                efficiencyModifier = kBaseEfficiencyModifier * (1.0f + (experienceLevel / 100f));

                //Format the result message
                analysisResultMessage = string.Format(kResourceExtractionImproved, Math.Abs((efficiencyModifier * 100.0f))) + biome.name;

                //Save the modifier
                currentModifier = WBIPathfinderScenario.Instance.GetEfficiencyModifier(this.part.vessel.mainBody.flightGlobalsIndex,
                                                                                       biome.name, (HarvestTypes)resourceType, EfficiencyData.kExtractionMod);
                WBIPathfinderScenario.Instance.SetEfficiencyData(this.part.vessel.mainBody.flightGlobalsIndex,
                                                                 biome.name, (HarvestTypes)resourceType, EfficiencyData.kExtractionMod, currentModifier + efficiencyModifier);
            }

            else
            {
                analysisResultMessage = kResourceExtractionUnchanged + biome.name;
            }

            //Inform the player of the result.
            ScreenMessages.PostScreenMessage(analysisResultMessage, 5.0f, ScreenMessageStyle.UPPER_CENTER);
            DeployExperiment();


            //First timers: show the tooltip.
            if (WBIPathfinderScenario.Instance.HasShownToolTip(kToolTip) == false)
            {
                WBIPathfinderScenario.Instance.SetToolTipShown(kToolTip);

                WBIToolTipWindow introWindow = new WBIToolTipWindow(kFirstCoreSampleTitle, kFirstCoreSampleMsg);
                introWindow.SetVisible(true);
            }
        }
Beispiel #15
0
        private void CheckVesselCrew(Vessel v)
        {
            if (!HighLogic.LoadedSceneIsFlight)
            {
                return;
            }

            if (!_inFlight)
            {
                _simpleRestrictions  = true;
                _complexRestrictions = true;
                _readoutsAvailable   = false;
                return;
            }

            if (!_settings.CrewRestrictions)
            {
                _simpleRestrictions  = false;
                _complexRestrictions = false;
                _readoutsAvailable   = true;
                return;
            }

            _simpleRestrictions  = true;
            _complexRestrictions = true;

            if (v != null)
            {
                List <ProtoCrewMember> crew = v.GetVesselCrew();

                for (int i = crew.Count - 1; i >= 0; i--)
                {
                    ProtoCrewMember kerbal = crew[i];

                    if (_settings.CrewTypeRestrictions)
                    {
                        for (int j = BasicDeltaV_Settings.Instance.SkillTypes.Count - 1; j >= 0; j--)
                        {
                            string skill = BasicDeltaV_Settings.Instance.SkillTypes[j];

                            if (!kerbal.HasEffect(skill))
                            {
                                continue;
                            }

                            if (_settings.CrewLevelRestrictions)
                            {
                                int level = kerbal.experienceLevel;

                                if (level >= _settings.SimpleRestrictionLevel)
                                {
                                    _simpleRestrictions = false;
                                }

                                if (level >= _settings.ComplexRestrictionLevel)
                                {
                                    _complexRestrictions = false;
                                }

                                if (!_simpleRestrictions && !_complexRestrictions)
                                {
                                    break;
                                }
                            }
                            else
                            {
                                _simpleRestrictions  = false;
                                _complexRestrictions = false;
                                break;
                            }
                        }
                    }
                    else
                    {
                        if (_settings.CrewLevelRestrictions)
                        {
                            int level = kerbal.experienceLevel;

                            if (level >= _settings.SimpleRestrictionLevel)
                            {
                                _simpleRestrictions = false;
                            }

                            if (level >= _settings.ComplexRestrictionLevel)
                            {
                                _complexRestrictions = false;
                            }

                            if (!_simpleRestrictions && !_complexRestrictions)
                            {
                                break;
                            }
                        }
                        else
                        {
                            _simpleRestrictions  = false;
                            _complexRestrictions = false;
                            break;
                        }
                    }

                    if (!_simpleRestrictions && !_complexRestrictions)
                    {
                        break;
                    }
                }
            }
            else
            {
                //_simpleRestrictions = _settings.CareerRestrictions && ScenarioUpgradeableFacilities.GetFacilityLevel(SpaceCenterFacility.TrackingStation) < 0.5f;
                //_complexRestrictions = _settings.CareerRestrictions && ScenarioUpgradeableFacilities.GetFacilityLevel(SpaceCenterFacility.TrackingStation) < 0.75f;
                _simpleRestrictions  = true;
                _complexRestrictions = true;
            }

            //BasicLogging("Crew Status Check - Simple Restrictions: {0}, Complex Restrictions: {1}", _simpleRestrictions, _complexRestrictions);

            if (_simpleRestrictions && _complexRestrictions)
            {
                _readoutsAvailable = false;
            }
            else
            {
                _readoutsAvailable = true;
            }
        }
Beispiel #16
0
        public float GetProspectBonus()
        {
            float skillBonus    = GoldStrikeSettings.BonusPerSkillPoint;
            float prospectBonus = 0f;
            float labBonus      = 0f;

            Vessel[] vessels;
            Vessel   vessel;

            ProtoCrewMember[] crewMembers;
            ProtoCrewMember   crewMember;

            WBIPathfinderLab[] pathfinderLabs;
            WBIPathfinderLab   pathfinderLab;

            WBIGeoLab[] geoLabs;
            WBIGeoLab   geoLab;
            ProtoVessel protoVessel;

            //If an experienced prospector is taking the core sample, then the prospector's experience will
            //affect the analysis.
            if (FlightGlobals.ActiveVessel.isEVA && Utils.IsExperienceEnabled())
            {
                vessel = FlightGlobals.ActiveVessel;
                ProtoCrewMember astronaut = vessel.GetVesselCrew()[0];

                if (astronaut.HasEffect(prospectSkill))
                {
                    prospectBonus = astronaut.experienceTrait.CrewMemberExperienceLevel() * skillBonus;
                }
            }

            //Factor in lab bonus
            //Bonus is 0.5 * crew skill (max 2.5) per crewmember
            vessels = FlightGlobals.VesselsLoaded.ToArray();
            for (int index = 0; index < vessels.Length; index++)
            {
                vessel = vessels[index];

                List <WBIPathfinderLab> wbiGeologyLabs = vessel.FindPartModulesImplementing <WBIPathfinderLab>();
                if (wbiGeologyLabs.Count > 0)
                {
                    pathfinderLabs = wbiGeologyLabs.ToArray();
                    for (int labIndex = 0; labIndex < pathfinderLabs.Length; labIndex++)
                    {
                        pathfinderLab = pathfinderLabs[labIndex];
                        if (pathfinderLab.part.protoModuleCrew.Count > 0)
                        {
                            crewMembers = pathfinderLab.part.protoModuleCrew.ToArray();
                            for (int crewIndex = 0; crewIndex < crewMembers.Length; crewIndex++)
                            {
                                crewMember = crewMembers[crewIndex];
                                if (crewMember.HasEffect(prospectSkill))
                                {
                                    labBonus += kLabSkillBonus * crewMember.experienceTrait.CrewMemberExperienceLevel();
                                }
                            }
                        }
                    }
                }

                List <WBIGeoLab> geologyLabs = vessel.FindPartModulesImplementing <WBIGeoLab>();
                if (geologyLabs.Count > 0)
                {
                    geoLabs = geologyLabs.ToArray();
                    for (int labIndex = 0; labIndex < geoLabs.Length; labIndex++)
                    {
                        geoLab = geoLabs[labIndex];
                        if (geoLab.part.protoModuleCrew.Count > 0)
                        {
                            crewMembers = geoLab.part.protoModuleCrew.ToArray();
                            for (int crewIndex = 0; crewIndex < crewMembers.Length; crewIndex++)
                            {
                                crewMember = crewMembers[crewIndex];
                                if (crewMember.HasEffect(prospectSkill))
                                {
                                    labBonus += kLabSkillBonus * crewMember.experienceTrait.CrewMemberExperienceLevel();
                                }
                            }
                        }
                    }
                }
            }

            //Unloaded vessels
            vessels = FlightGlobals.VesselsUnloaded.ToArray();
            for (int index = 0; index < vessels.Length; index++)
            {
                vessel      = vessels[index];
                protoVessel = vessel.protoVessel;

                //Only applies to vessels of the same body that are landed.
                if (vessel.mainBody != this.part.vessel.mainBody)
                {
                    continue;
                }
                if (vessel.situation != Vessel.Situations.LANDED && vessel.situation != Vessel.Situations.PRELAUNCH)
                {
                    continue;
                }

                //Find all the pathfinder labs
                foreach (ProtoPartSnapshot partSnapshot in protoVessel.protoPartSnapshots)
                {
                    foreach (ProtoPartModuleSnapshot moduleSnapshot in partSnapshot.modules)
                    {
                        if (moduleSnapshot.moduleName == "WBIGeologyLab" || moduleSnapshot.moduleName == "WBIGeoLab")
                        {
                            foreach (ProtoCrewMember protoCrewMember in partSnapshot.protoModuleCrew)
                            {
                                if (protoCrewMember.HasEffect(prospectSkill))
                                {
                                    labBonus += kLabSkillBonus * protoCrewMember.experienceTrait.CrewMemberExperienceLevel();
                                }
                            }
                        }
                    }
                }
            }

            debugLog("Prospector bonus: " + prospectBonus + " labBonus: " + labBonus);
            return(prospectBonus + labBonus);
        }