예제 #1
0
        protected override bool canAffordReconfigure(string templateName, bool deflatedModulesAutoPass = true)
        {
            WBIPathfinderScenario scenario = WBIPathfinderScenario.Instance;
            bool   canAfford    = base.canAffordReconfigure(templateName, deflatedModulesAutoPass);
            string requiredName = templateManager[templateName].GetValue("requiredResource");

            //If the vessel can't afford to reconfigure the module, then maybe the distribution manager can help.
            if (canAfford == false)
            {
                ScreenMessages.PostScreenMessage("Checking distributors...", 10.0f);
                if (string.IsNullOrEmpty(requiredName))
                {
                    return(true);
                }

                double distributedAmount = WBIDistributionManager.Instance.GetDistributedAmount(requiredName);
                if (distributedAmount >= reconfigureCost)
                {
                    ScreenMessages.PostScreenMessage("Distributors have enough " + requiredName, 10.0f);
                    return(true);
                }
            }

            //Add first time for redecoration
            if (!canAfford && scenario.HasShownToolTip(kSettingsWindow) == false)
            {
                scenario.SetToolTipShown(kSettingsWindow);

                WBIToolTipWindow toolTipWindow = new WBIToolTipWindow(kSettingsWindow, kPartsTip);
                toolTipWindow.SetVisible(true);
            }

            return(canAfford);
        }
 public override void OnAwake()
 {
     base.OnAwake();
     Instance = this;
     GameEvents.OnGameSettingsApplied.Add(onGameSettingsApplied);
     showDebugLog = PathfinderSettings.LoggingEnabled;
 }
예제 #3
0
        public override void OnStart(StartState state)
        {
            ModuleResourceHarvester harvester;

            base.OnStart(state);

            //Get the drills
            groundDrills = this.part.FindModulesImplementing <ModuleResourceHarvester>();

            //Setup the drills with the new resource to drill for.
            if (drillResources != null)
            {
                for (int index = 0; index < drillResources.Length; index++)
                {
                    harvester = groundDrills[index];
                    harvester.ResourceName    = drillResources[index];
                    harvester.StartActionName = "Start " + drillResources[index] + " Drill";
                    harvester.StopActionName  = "Stop " + drillResources[index] + " Drill";
                    harvester.Fields["ResourceStatus"].guiName = drillResources[index] + " rate";
                }
            }

            //Setup the window
            drillSwitchWindow = new DrillSwitchWindow();
            drillSwitchWindow.groundDrills     = groundDrills;
            drillSwitchWindow.part             = this.part;
            drillSwitchWindow.reconfigureCost  = reconfigureCost;
            drillSwitchWindow.requiredResource = requiredResource;
            drillSwitchWindow.requiredSkill    = requiredSkill;

            //Setup GUI
            Events["ShowDrillSwitchWindow"].guiActiveUnfocused = Utils.HasResearchedNode(PathfinderSettings.drillTechNode);

            //Tooltip
            if (HighLogic.LoadedSceneIsFlight == false)
            {
                return;
            }
            WBIPathfinderScenario scenario = WBIPathfinderScenario.Instance;

            if (scenario.HasShownToolTip(this.ClassName))
            {
                return;
            }
            scenario.SetToolTipShown(this.ClassName);

            WBIToolTipWindow toolTipWindow = new WBIToolTipWindow(kToolTipTitle, kDrillSwitchTooltip);

            toolTipWindow.SetVisible(true);
        }
예제 #4
0
        protected override void notEnoughParts()
        {
            base.notEnoughParts();

            WBIPathfinderScenario scenario = WBIPathfinderScenario.Instance;

            //Add first time for redecoration
            if (scenario.HasShownToolTip(kSettingsWindow) == false)
            {
                scenario.SetToolTipShown(kSettingsWindow);

                WBIToolTipWindow toolTipWindow = new WBIToolTipWindow(kSettingsWindow, kPartsTip);
                toolTipWindow.SetVisible(true);
            }
        }
예제 #5
0
        protected override bool canAffordReconfigure(string templateName)
        {
            WBIPathfinderScenario scenario = WBIPathfinderScenario.Instance;
            bool canAfford = base.canAffordReconfigure(templateName);

            //Add first time for redecoration
            if (!canAfford && scenario.HasShownToolTip(kSettingsWindow) == false)
            {
                scenario.SetToolTipShown(kSettingsWindow);

                WBIToolTipWindow toolTipWindow = new WBIToolTipWindow(kSettingsWindow, kPartsTip);
                toolTipWindow.SetVisible(true);
            }

            return(canAfford);
        }
예제 #6
0
        protected void checkAndShowToolTip()
        {
            //Now we can check to see if the tooltip for the current template has been shown.
            WBIPathfinderScenario scenario = WBIPathfinderScenario.Instance;

            if (scenario.HasShownToolTip(this.part.partInfo.title))
            {
                return;
            }

            string           toolTip       = kToolTipSend;
            WBIToolTipWindow toolTipWindow = new WBIToolTipWindow(this.part.partInfo.title, toolTip);

            toolTipWindow.SetVisible(true);

            //Cleanup
            scenario.SetToolTipShown(this.part.partInfo.title);
        }
예제 #7
0
        protected override bool canAffordReconfigure(string templateName, bool deflatedModulesAutoPass = true)
        {
            showInsufficientResourcesMsg = false;
            bool canAfford = base.canAffordReconfigure(templateName, deflatedModulesAutoPass);

            //If the vessel can't afford to reconfigure the module, then maybe the distribution manager can help.
            if (canAfford == false)
            {
                canAfford = true;

                string[] keys = inputList.Keys.ToArray();
                string   resourceName;
                double   distributedAmount;
                for (int index = 0; index < keys.Length; index++)
                {
                    resourceName      = keys[index];
                    distributedAmount = WBIDistributionManager.Instance.GetDistributedAmount(resourceName);
                    Log("Distributors have " + distributedAmount + " units of " + resourceName);

                    if (distributedAmount < inputList[resourceName])
                    {
                        string notEnoughPartsMsg = string.Format(kInsufficientParts, inputList[resourceName], resourceName);
                        ScreenMessages.PostScreenMessage(notEnoughPartsMsg, 5.0f, ScreenMessageStyle.UPPER_CENTER);
                        ScreenMessages.PostScreenMessage("No active distributors have " + resourceName + " to share. Make sure resource distribution is turned on, and a distributor is sharing " + resourceName + ".", 10.0f);
                        canAfford = false;
                        break;
                    }
                }
            }

            //Add first time for redecoration
            WBIPathfinderScenario scenario = WBIPathfinderScenario.Instance;

            if (!canAfford && scenario.HasShownToolTip(kSettingsWindow) == false)
            {
                scenario.SetToolTipShown(kSettingsWindow);

                WBIToolTipWindow toolTipWindow = new WBIToolTipWindow(kSettingsWindow, kPartsTip);
                toolTipWindow.SetVisible(true);
            }

            return(canAfford);
        }
예제 #8
0
        protected void checkAndShowToolTip()
        {
            //Now we can check to see if the tooltip for the current template has been shown.
            WBIPathfinderScenario scenario = WBIPathfinderScenario.Instance;

            if (scenario.HasShownToolTip(CurrentTemplateName) && scenario.HasShownToolTip(getMyPartName()))
            {
                return;
            }
            if (!CurrentTemplate.HasValue("toolTipTitle") && !CurrentTemplate.HasValue("toolTip"))
            {
                return;
            }

            //Tooltip for the current template has never been shown. Show it now.
            string toolTipTitle = CurrentTemplate.GetValue("toolTipTitle");
            string toolTip      = CurrentTemplate.GetValue("toolTip");

            if (string.IsNullOrEmpty(toolTipTitle))
            {
                toolTipTitle = partToolTipTitle;
            }

            //Add the very first part's tool tip.
            if (scenario.HasShownToolTip(getMyPartName()) == false)
            {
                toolTip = partToolTip + "\r\n\r\n" + toolTip;

                scenario.SetToolTipShown(getMyPartName());
            }

            if (string.IsNullOrEmpty(toolTip) == false)
            {
                WBIToolTipWindow toolTipWindow = new WBIToolTipWindow(toolTipTitle, toolTip);
                toolTipWindow.SetVisible(true);

                //Cleanup
                scenario.SetToolTipShown(CurrentTemplateName);
            }
        }
예제 #9
0
        protected void checkAndShowToolTip()
        {
            //Check tooltips
            WBIPathfinderScenario scenario = WBIPathfinderScenario.Instance;
            string experimentName          = getExperimentName(currentExperiment);
            string experimentTip;

            //Add first time for redecoration
            if (scenario.HasShownToolTip(experimentName) == false)
            {
                scenario.SetToolTipShown(experimentName);

                switch (currentExperiment)
                {
                default:
                case GeologyLabExperiments.SoilAnalysis:
                    experimentTip = kTTSoilAnalysis;
                    break;

                case GeologyLabExperiments.MetallurgyAnalysis:
                    experimentTip = kTTMetalAnalysis;
                    break;

                case GeologyLabExperiments.ChemicalAnalysis:
                    experimentTip = kTTChemAnalysis;
                    break;

                case GeologyLabExperiments.BiomeAnalysis:
                    experimentTip = kTTBiomeAnalysis;
                    break;
                }

                WBIToolTipWindow toolTipWindow = new WBIToolTipWindow(kTTTitle + experimentName, experimentTip);
                toolTipWindow.SetVisible(true);
            }
        }
예제 #10
0
 public override void OnAwake()
 {
     base.OnAwake();
     Instance = this;
 }
예제 #11
0
 public override void OnAwake()
 {
     base.OnAwake();
     Instance = this;
 }
예제 #12
0
 public override void OnAwake()
 {
     base.OnAwake();
     Instance = this;
     GameEvents.OnGameSettingsApplied.Add(onGameSettingsApplied);
 }
예제 #13
0
        public void CheckGoldStrike()
        {
            string[]              strikeResourceKeys = null;
            int                   resourceIndex;
            GoldStrikeData        strikeData          = null;
            WBIPathfinderScenario scenario            = WBIPathfinderScenario.Instance;
            string                resourceName        = string.Empty;
            double                resourceAmount      = 0f;
            float                 analysisRoll        = 0f;
            float                 successTargetNumber = prospectChance;
            int                   chancesRemaining    = 0;
            string                navigationID        = string.Empty;
            GoldStrikeLode        lode      = null;
            string                biomeName = string.Empty;
            int                   planetID  = -1;

            //Do we have gold strike resources?
            if (scenario.goldStrikeResources.Count() == 0)
            {
                ScreenMessages.PostScreenMessage("There are no Gold Strike resources to prospect!", kMessageDisplayTime, ScreenMessageStyle.UPPER_CENTER);
                debugLog("No resources to prospect");
                return;
            }

            //Do we have a valid situation?
            if (SituationIsValid() == false)
            {
                return;
            }

            //Ok, we can prospect at this location.
            GoldStrikeUtils.GetBiomeAndPlanet(out biomeName, out planetID, this.part.vessel, asteroid);
            setLastLocation();
            chancesRemaining = updateChancesRemaining();

            //Time to see if we find anything.
            //Tally up the % chance we have to make a successful prospect.
            //prospectChance: base chance to find a prospect. Some parts are better than others.
            //prospectSkillBonus: multiplied by the EVA prospector's skill level. Default is 1.0.
            //labBonus: For each Pathfinder geology lab in the vicinity, give one point per crew member staffing the lab that has the prospectSkill.
            //For each non-Pathfinder geology lab in the vicinity, give half a point per crew member staffing the lab that has the prospectSkill.
            //Chance = prospectChance + prospectSkillBonus + labBonus.
            //Ex: A 3-star scientist on EVA makes a prospect check. skillBonus = 3; prospectSkillBonus = 1.0. Total skill bonus = 3.0.
            //Inside the Bison are two scientists staffing a geology lab (non-pathfinder). labBonus = 2 * 0.5 = 1
            //Gold Digger has a base 10% chance of finding a prospect.
            //successTargetNumber = 10 + 3 + 1 = 14.
            successTargetNumber = prospectChance + GetProspectBonus();
            debugLog("Base chance to succeed: " + prospectChance);
            debugLog("successTargetNumber: " + successTargetNumber);

            //Roll the chance and check it.
            analysisRoll  = UnityEngine.Random.Range(1, 6);
            analysisRoll += UnityEngine.Random.Range(1, 6);
            analysisRoll += UnityEngine.Random.Range(1, 6);
            analysisRoll *= 5.5556f;
            debugLog("analysisRoll: " + analysisRoll);

            //If we didn't succeed then we're done.
            if (analysisRoll > successTargetNumber)
            {
                debugLog("Prospect failed; didn't roll low enough.");
                ScreenMessages.PostScreenMessage("Nothing of value here, try another location. " + chancesRemaining + " chances remain in the " + biomeName, kMessageDisplayTime, ScreenMessageStyle.UPPER_CENTER);
                return;
            }

            //Success! Get the resource name and strike data.
            strikeResourceKeys = scenario.goldStrikeResources.Keys.ToArray();
            resourceIndex      = UnityEngine.Random.Range(0, strikeResourceKeys.Length - 1);
            resourceName       = strikeResourceKeys[resourceIndex];
            strikeData         = scenario.goldStrikeResources[resourceName];
            debugLog("strikeResourceKeys count: " + strikeResourceKeys.Length);
            debugLog("resourceIndex: " + resourceIndex);
            debugLog("strikeData: " + strikeData.ToString());

            //Now, generate the resource amount to add to the map
            resourceAmount = UnityEngine.Random.Range(strikeData.minAmount, strikeData.maxAmount);
            debugLog("resourceAmount: " + resourceAmount);

            //If we hit the motherlode then factor that in.
            //The motherloade is 5% of the target number.
            if (analysisRoll <= (successTargetNumber * kMotherlodeFactor))
            {
                resourceAmount *= strikeData.motherlodeMultiplier;
                debugLog("resourceAmount after motherlode: " + resourceAmount);
                ScreenMessages.PostScreenMessage(string.Format("Congratulations! You found a {0:s} motherlode with {1:f2} units available to mine!", resourceName, resourceAmount),
                                                 kMessageDisplayTime, ScreenMessageStyle.UPPER_CENTER);
            }

            else
            {
                ScreenMessages.PostScreenMessage(string.Format("Congratulations! You found a {0:s} lode with {1:f2} units available to mine!", resourceName, resourceAmount),
                                                 kMessageDisplayTime, ScreenMessageStyle.UPPER_CENTER);
            }
            ScreenMessages.PostScreenMessage(chancesRemaining + " chances remain to find another lode in the " + biomeName, kMessageDisplayTime, ScreenMessageStyle.UPPER_LEFT);

            //Play the jingle
            playJingle();

            //Now set up the lode
            debugLog("Adding new lode entry to " + FlightGlobals.currentMainBody.name + " with flight global index " + FlightGlobals.currentMainBody.flightGlobalsIndex);
            debugLog("Biome: " + biomeName);
            debugLog("Lon/Lat: " + this.part.vessel.longitude + "/" + this.part.vessel.latitude);
            lode = scenario.AddLode(planetID, biomeName,
                                    this.part.vessel.longitude, this.part.vessel.latitude, resourceName, resourceAmount);

            //Set waypoint
            if (lode != null)
            {
                setWaypoint(resourceName, lode);
            }
        }
예제 #14
0
        public void CheckGoldStrike()
        {
            string[]              strikeResourceKeys = null;
            int                   resourceIndex;
            GoldStrikeData        strikeData          = null;
            WBIPathfinderScenario scenario            = WBIPathfinderScenario.Instance;
            string                resourceName        = string.Empty;
            double                resourceAmount      = 0f;
            float                 analysisRoll        = 0f;
            float                 successTargetNumber = prospectChance;
            string                navigationID        = string.Empty;
            GoldStrikeLode        lode      = null;
            string                biomeName = string.Empty;
            int                   planetID  = -1;

            //Do we have gold strike resources?
            if (scenario.goldStrikeResources.Count() == 0)
            {
                ScreenMessages.PostScreenMessage("There are no Gold Strike resources to prospect!", kMessageDisplayTime, ScreenMessageStyle.UPPER_CENTER);
                debugLog("No resources to prospect");
                return;
            }

            //Do we have a valid situation?
            if (SituationIsValid() == false)
            {
                return;
            }

            //Update our location.
            asteroid = this.part.vessel.FindPartModuleImplementing <ModuleAsteroid>();
            GoldStrikeUtils.GetBiomeAndPlanet(out biomeName, out planetID, this.part.vessel, asteroid);
            vesselModule.UpdateLastProspectLocation();

            //Time to see if we find anything.
            //prospectChance: base chance to find a prospect. Some parts are better than others.
            //prospectBonus: Various situations contribute to the success of the attempt.
            successTargetNumber = 100 - (prospectChance + GetProspectBonus());
            debugLog("successTargetNumber: " + successTargetNumber);

            //Roll the chance and check it.
            analysisRoll = UnityEngine.Random.Range(1, 100);
            debugLog("analysisRoll: " + analysisRoll);

            //If we didn't succeed then we're done.
            if (analysisRoll < successTargetNumber && !WBIPathfinderScenario.debugProspectAlwaysSuccessful)
            {
                debugLog("Prospect failed; didn't roll high enough.");
                ScreenMessages.PostScreenMessage("Nothing of value here, try another location. ", kMessageDisplayTime, ScreenMessageStyle.UPPER_CENTER);
                return;
            }

            //Success! Get the resource name and strike data.
            //If we're near an anomaly then we need a roll table.
            if (anomalyBonus > 0)
            {
                SortedDictionary <int, GoldStrikeData> sortedResources = new SortedDictionary <int, GoldStrikeData>();
                strikeResourceKeys = scenario.goldStrikeResources.Keys.ToArray();

                //Add any resources that have an anomaly chance into the sorted resources
                for (int index = 0; index < strikeResourceKeys.Length; index++)
                {
                    resourceName = strikeResourceKeys[index];
                    strikeData   = scenario.goldStrikeResources[resourceName];
                    if (strikeData.anomalyChance > 0)
                    {
                        sortedResources.Add(strikeData.anomalyChance, strikeData);
                    }
                }

                //Roll a 1-100
                int pressenceRoll = UnityEngine.Random.Range(1, 100);

                //See if we have any strike data
                strikeData = null;
                foreach (KeyValuePair <int, GoldStrikeData> pair in sortedResources)
                {
                    if (pressenceRoll < pair.Key)
                    {
                        strikeData = pair.Value;
                        break;
                    }
                }

                //If we don't have any strike data then pick a random resource
                if (strikeData == null)
                {
                    resourceIndex = UnityEngine.Random.Range(0, strikeResourceKeys.Length - 1);
                    resourceName  = strikeResourceKeys[resourceIndex];
                    strikeData    = scenario.goldStrikeResources[resourceName];
                }
            }

            else
            {
                strikeResourceKeys = scenario.goldStrikeResources.Keys.ToArray();
                resourceIndex      = UnityEngine.Random.Range(0, strikeResourceKeys.Length - 1);
                resourceName       = strikeResourceKeys[resourceIndex];
                strikeData         = scenario.goldStrikeResources[resourceName];
                debugLog("strikeResourceKeys count: " + strikeResourceKeys.Length);
                debugLog("resourceIndex: " + resourceIndex);
            }
            debugLog("strikeData: " + strikeData.ToString());

            //Play the jingle
            playJingle();

            //Setup a planetary surface lode
            if (asteroid == null)
            {
                debugLog("Setting up surface lode");
                //Now, generate the resource amount to add to the map
                resourceAmount = UnityEngine.Random.Range(strikeData.minAmount, strikeData.maxAmount);
                debugLog("resourceAmount: " + resourceAmount);

                //If we hit the motherlode then factor that in.
                //The motherloade is 5% of the target number.
                if (analysisRoll <= (successTargetNumber * kMotherlodeFactor))
                {
                    resourceAmount *= strikeData.motherlodeMultiplier;
                    debugLog("resourceAmount after motherlode: " + resourceAmount);
                    ScreenMessages.PostScreenMessage(string.Format("Congratulations! You found a {0:s} motherlode with {1:f2} units available to mine!", resourceName, resourceAmount),
                                                     kMessageDisplayTime, ScreenMessageStyle.UPPER_CENTER);
                }

                else
                {
                    ScreenMessages.PostScreenMessage(string.Format("Congratulations! You found a {0:s} lode with {1:f2} units available to mine!", resourceName, resourceAmount),
                                                     kMessageDisplayTime, ScreenMessageStyle.UPPER_CENTER);
                }
                if (!string.IsNullOrEmpty(anomalyName))
                {
                    ScreenMessages.PostScreenMessage("Special cache found at " + anomalyName, kMessageDisplayTime, ScreenMessageStyle.UPPER_CENTER);
                }

                debugLog("Adding new lode entry to " + FlightGlobals.currentMainBody.name + " with flight global index " + FlightGlobals.currentMainBody.flightGlobalsIndex);
                debugLog("Biome: " + biomeName);
                debugLog("Lon/Lat: " + this.part.vessel.longitude + "/" + this.part.vessel.latitude);
                lode = scenario.AddLode(planetID, biomeName,
                                        this.part.vessel.longitude, this.part.vessel.latitude, resourceName, resourceAmount);
            }

            //Setup an asteroid lode
            else
            {
                debugLog("Setting up asteroid lode");
                float abundance = 0.01f;

                //Get the resource module for the lode.
                ModuleAsteroidResource   lodeResource    = null;
                ModuleAsteroidResource[] resourceModules = asteroid.part.FindModulesImplementing <ModuleAsteroidResource>().ToArray();
                for (int index = 0; index < resourceModules.Length; index++)
                {
                    if (resourceModules[index].resourceName == resourceName)
                    {
                        debugLog("ModuleAsteroidResource found for " + resourceName);
                        lodeResource = resourceModules[index];
                        break;
                    }
                }
                if (lodeResource == null)
                {
                    debugLog("ModuleAsteroidResource NOT found for " + resourceName);
                    return;
                }

                //Adjust abundance for motherlode
                if (analysisRoll <= (successTargetNumber * kMotherlodeFactor))
                {
                    abundance *= strikeData.motherlodeMultiplier;
                }
                debugLog("abundance increase: " + abundance);

                //Display appropriate message
                ScreenMessages.PostScreenMessage(string.Format("Congratulations! A careful scan of {0:s} has revealed an increased abundance of {1:s}", asteroid.AsteroidName, resourceName),
                                                 kMessageDisplayTime, ScreenMessageStyle.UPPER_CENTER);

                //Update resource module
                debugLog("Old abundance: " + lodeResource.abundance);
                lodeResource.abundance        += abundance;
                lodeResource.displayAbundance += abundance;
                debugLog("New abundance: " + lodeResource.abundance);

                debugLog("Adding new lode entry for asteroid: " + asteroid.AsteroidName);
                lode = scenario.AddLode(asteroid, resourceName, lodeResource.displayAbundance);
            }

            //Update any drills in the area.
            scenario.UpdateDrillLodes(asteroid);

            //Set waypoint
            if (lode != null && asteroid == null)
            {
                setWaypoint(resourceName, lode);
            }
        }