Esempio n. 1
0
 void update_state()
 {
     try
     {
         //get asteroid hatch
         var hatch = entrance.ConnectedPartWithModule <SingleUseGrappleNode>();
         grapple_node = hatch.Modules.GetModule <SingleUseGrappleNode>();
         storage      = hatch.Modules.GetModule <HangarStorageDynamic>();
         if (grapple_node == null || storage == null)
         {
             throw new Exception();
         }
         //get asteroid
         asteroid      = hatch.GetModuleInAttachedPart <ModuleAsteroid>();
         asteroid_info = asteroid.part.Modules.GetModule <ModuleAsteroidInfo>();
         EnableModule();
     }
     catch
     {
         asteroid      = null;
         asteroid_info = null;
         grapple_node  = null;
         storage       = null;
         DisableModule();
     }
     IsActivated &= can_convert();
 }
        public void dumpResources()
        {
            ModuleAsteroidInfo            summary   = part.FindModuleImplementing <ModuleAsteroidInfo> ();
            List <ModuleAsteroidResource> resources =
                part.FindModulesImplementing <ModuleAsteroidResource> ();

            if (summary != null)
            {
                double resourceMass = summary.currentMassVal - summary.massThresholdVal;

                System.Text.StringBuilder report = new System.Text.StringBuilder();
                report.AppendLine(Localizer.Format(
                                      "#autoLOC_CustomAsteroids_LogResourceHeader",
                                      part.FindModuleImplementing <ModuleAsteroid> ().AsteroidName));
                report.AppendLine(Localizer.Format("#autoLOC_CustomAsteroids_GuiClass")
                                  + ": " + composition);
                report.AppendLine(Localizer.Format(
                                      "#autoLOC_CustomAsteroids_LogResourceSummary",
                                      string.Format("{0:F1}", resourceMass),
                                      string.Format("{0:F1}", summary.currentMassVal),
                                      string.Format("{0:P1}", resourceMass / summary.currentMassVal)));
                report.AppendLine();

                foreach (ModuleAsteroidResource resource in resources)
                {
                    report.AppendLine(Localizer.Format(
                                          "#autoLOC_CustomAsteroids_LogResourceName",
                                          resource.resourceName));
                    report.AppendLine(Localizer.Format(
                                          "#autoLOC_CustomAsteroids_LogResourceAmount",
                                          string.Format("{0:F1}", resource.abundance * resourceMass),
                                          string.Format("{0:P1}", resource.displayAbundance)));
                    if (resource.abundance < 1e-6)
                    {
                        report.AppendLine(Localizer.Format(
                                              "#autoLOC_CustomAsteroids_LogResourceFreq",
                                              string.Format("{0:D}", resource.presenceChance)));
                    }
                    report.AppendLine(Localizer.Format(
                                          "#autoLOC_CustomAsteroids_LogResourceDistrib",
                                          string.Format("{0:D}", resource.lowRange),
                                          string.Format("{0:D}", resource.highRange)));
                    report.AppendLine();
                }

                Debug.Log(report.ToString());
                ScreenMessages.PostScreenMessage(
                    Localizer.Format("#autoLOC_CustomAsteroids_LogResourceEnd"),
                    5.0f, ScreenMessageStyle.UPPER_CENTER);
            }
        }
Esempio n. 3
0
        public void ScanAsteroid()
        {
            ModuleAnimateGeneric   animation        = this.part.FindModuleImplementing <ModuleAnimateGeneric>();
            ModuleAsteroidAnalysis asteroidAnalysis = this.part.FindModuleImplementing <ModuleAsteroidAnalysis>();
            ModuleAsteroid         asteroid         = null;
            ModuleAsteroidInfo     asteroidInfo     = null;

            //Make sure we have an analysis module
            if (asteroidAnalysis == null)
            {
                ScreenMessages.PostScreenMessage(kNoAnalysisModule, kMessageDuration, ScreenMessageStyle.UPPER_CENTER);
                return;
            }

            //See if we can find the asteroid modules
            asteroid = this.part.vessel.FindPartModuleImplementing <ModuleAsteroid>();
            if (asteroid == null)
            {
                ScreenMessages.PostScreenMessage(kNoPotato, kMessageDuration, ScreenMessageStyle.UPPER_CENTER);
                return;
            }
            asteroidInfo = asteroid.part.FindModuleImplementing <ModuleAsteroidInfo>();
            if (asteroidInfo == null)
            {
                ScreenMessages.PostScreenMessage(kNoPotato, kMessageDuration, ScreenMessageStyle.UPPER_CENTER);
                return;
            }

            //Good to go
            //Extend the arm if needed.
            if (animation != null)
            {
                if (animation.Events["Toggle"].guiName == animation.startEventGUIName)
                {
                    animation.Toggle();
                }
            }

            //Display the window
            scannerInfo.asteroid     = asteroid;
            scannerInfo.asteroidInfo = asteroidInfo;
            scannerInfo.SetVisible(true);
        }
        protected override ConversionRecipe PrepareRecipe(double deltaTime)
        {
            this._status      = "Connected";
            this._potato      = this.GetAttachedPotato();
            this._drilledMass = 0;
            if (this._potato == null)
            {
                this._status     = cacheAutoLOC_258405;
                this.IsActivated = false;
                return(null);
            }
            if (this.DirectAttach && !base.part.children.Contains(this._potato) && !(base.part.parent == this._potato))
            {
                this._status     = cacheAutoLOC_258412;
                this.IsActivated = false;
                return(null);
            }
            if (!this.RockOnly && !this._potato.Modules.Contains("ModuleAsteroidResource"))
            {
                this._status     = cacheAutoLOC_258419;
                this.IsActivated = false;
                return(null);
            }
            List <ModuleAsteroidResource> moduleAsteroidResources = this._potato.FindModulesImplementing <ModuleAsteroidResource>();

            if (!this.CheckForImpact())
            {
                this._status     = cacheAutoLOC_258428;
                this.IsActivated = false;
                return(null);
            }
            this._info = this._potato.FindModuleImplementing <ModuleAsteroidInfo>();
            if (this._info == null)
            {
                this._status     = cacheAutoLOC_258436;
                this.IsActivated = false;
                return(null);
            }
            if (this._info.massThresholdVal >= this._info.currentMassVal)
            {
                this._status     = cacheAutoLOC_258443;
                this.IsActivated = false;
                return(null);
            }
            if (this.ResBroker.AmountAvailable(base.part, "ElectricCharge", deltaTime, ResourceFlowMode.NULL) <= deltaTime * (double)this.PowerConsumption)
            {
                this._status     = cacheAutoLOC_258451;
                this.IsActivated = false;
                return(null);
            }
            this.UpdateConverterStatus();
            if (!this.IsActivated)
            {
                return(null);
            }
            double efficiencyMultiplier = this.GetEfficiencyMultiplier();
            bool   flag  = false;
            int    count = moduleAsteroidResources.Count;
            int    num   = 0;

            while (true)
            {
                if (num < count)
                {
                    ModuleAsteroidResource item = moduleAsteroidResources[num];
                    if (this.ResBroker.StorageAvailable(base.part, item.resourceName, deltaTime, item._flowMode, (double)this.FillAmount) > deltaTime * (double)item.abundance * (double)this.Efficiency * efficiencyMultiplier)
                    {
                        flag = true;
                        break;
                    }
                    else
                    {
                        num++;
                    }
                }
                else
                {
                    break;
                }
            }
            this.recipe.Clear();
            if (!flag)
            {
                this._status = cacheAutoLOC_258501;
            }
            else
            {
                List <ResourceRatio> inputs        = this.recipe.Inputs;
                ResourceRatio        resourceRatio = new ResourceRatio()
                {
                    ResourceName = "ElectricCharge",
                    Ratio        = (double)this.PowerConsumption,
                    FlowMode     = ResourceFlowMode.NULL
                };
                inputs.Add(resourceRatio);
                for (int i = 0; i < count; i++)
                {
                    ModuleAsteroidResource moduleAsteroidResource = moduleAsteroidResources[i];
                    if ((double)moduleAsteroidResource.abundance > 1E-09)
                    {
                        PartResourceDefinition definition = PartResourceLibrary.Instance.GetDefinition(moduleAsteroidResource.resourceName);
                        double num1 = deltaTime * (double)moduleAsteroidResource.abundance * (double)this.Efficiency * efficiencyMultiplier;
                        double num2 = this._info.currentMassVal - this._info.massThresholdVal;
                        double num3 = num2 / (double)definition.density;
                        double num4 = Math.Min(num1, num3);
                        GTI_ModuleAsteroidDrill moduleAsteroidDrill = this;
                        moduleAsteroidDrill._drilledMass = moduleAsteroidDrill._drilledMass + (double)definition.density * num4;
                        ResourceRatio resourceRatio1 = new ResourceRatio()
                        {
                            ResourceName = moduleAsteroidResource.resourceName,
                            Ratio        = num4 / deltaTime,
                            DumpExcess   = true,
                            FlowMode     = ResourceFlowMode.NULL
                        };
                        this.recipe.Outputs.Add(resourceRatio1);
                    }
                }
            }
            return(this.recipe);
        }
Esempio n. 5
0
        protected void setupResources()
        {
            //If we've already done the resource swap them we're done.
            if (resourcesConverted)
            {
                return;
            }

            //Find the Ore, water, and guaranteed resources (if any)
            ModuleAsteroidResource[]      asteroidResources = this.part.FindModulesImplementing <ModuleAsteroidResource>().ToArray();
            ModuleAsteroidResource        oreResource       = null;
            ModuleAsteroidResource        waterResource     = null;
            List <ModuleAsteroidResource> extraResources    = new List <ModuleAsteroidResource>();
            PartResourceDefinitionList    definitions       = PartResourceLibrary.Instance.resourceDefinitions;

            for (int index = 0; index < asteroidResources.Length; index++)
            {
                if (asteroidResources[index].resourceName == "Ore")
                {
                    oreResource = asteroidResources[index];
                }
                else if (asteroidResources[index].resourceName == waterResourceName)
                {
                    //Does definition exist?
                    if (definitions.Contains(asteroidResources[index].resourceName))
                    {
                        waterResource = asteroidResources[index];
                    }
                }

                //If the resource is guaranteed then add it to the guarantee list.
                else if (string.IsNullOrEmpty(guaranteeResources) == false)
                {
                    if (guaranteeResources.Contains(asteroidResources[index].resourceName) && definitions.Contains(asteroidResources[index].resourceName))
                    {
                        extraResources.Add(asteroidResources[index]);
                    }
                }
            }
            if (oreResource == null)
            {
                Debug.Log("[ModuleKomet] - oreResource is null, cannot setup resources.");
                return;
            }
            if (waterResource == null)
            {
                Debug.Log("[ModuleKomet] - waterResource is null, cannot setup resources.");
                return;
            }

            //Adjust the abundance for the guaranteed resources to at least the minimum
            float guaranteedResourcePercent = minimumResourcePercent / 100.0f;

            ModuleAsteroidResource[] resExtras = extraResources.ToArray();
            for (int index = 0; index < resExtras.Length; index++)
            {
                resExtras[index].abundance += guaranteedResourcePercent;

                //Reduce ore percentage accordingly.
                oreResource.abundance -= guaranteedResourcePercent;
//                Debug.Log("[ModuleKomet] - " + resExtras[index].resourceName + " abundance: " + resExtras[index].abundance);
            }

            //Adjust the Water and Ore abundance
            float waterAbundancePercent = (waterPercentage / 100.0f) * oreResource.abundance;

            oreResource.abundance    = oreResource.abundance = waterAbundancePercent;
            waterResource.abundance += waterAbundancePercent;
//            Debug.Log("[ModuleKomet] - oreResource abundance: " + oreResource.abundance);
//            Debug.Log("[ModuleKomet] - waterResource abundance: " + waterResource.abundance);

            ModuleAsteroidInfo asteroidInfo = this.part.FindModuleImplementing <ModuleAsteroidInfo>();

            Debug.Log(asteroidInfo.resources);

            //Set the converted flag.
            resourcesConverted = true;
        }