Exemplo n.º 1
0
        void DoFocusedHarvesting(double scale)
        {
            if (HarvestType == HarvesterType.Atmosphere && part.vessel.atmDensity > 0.0001d)
            {
                if (part.vessel.atmDensity < 0.0001d)
                {
                    ScoopUI = Localizer.Format("#LOC_SpaceDust_ModuleSpaceDustHarvester_Field_Scoop_NeedsAtmo");
                    return;
                }
                Vector3d worldVelocity = part.vessel.srf_velocity;
                double   mach          = part.vessel.mach;

                Vector3 intakeVector;
                if (HarvestIntakeTransform == null)
                {
                    intakeVector = this.transform.forward;
                }
                else
                {
                    intakeVector = HarvestIntakeTransform.forward;
                }

                double dot          = Vector3d.Dot(worldVelocity, intakeVector);
                float  intakeVolume = (float)(worldVelocity.magnitude * MathExtensions.Clamp(dot, 0d, 1d) * IntakeVelocityScale.Evaluate((float)mach) + IntakeSpeedStatic) * IntakeArea;
                IntakeSpeed = Localizer.Format("#LOC_SpaceDust_ModuleSpaceDustHarvester_Field_IntakeSpeed_Normal", Utils.ToSI(intakeVolume, "G2"));
                ScoopUI     = "";

                for (int i = 0; i < resources.Count; i++)
                {
                    double resourceSample = SpaceDustResourceMap.Instance.SampleResource(resources[i].Name,
                                                                                         part.vessel.mainBody,
                                                                                         vessel.altitude + part.vessel.mainBody.Radius,
                                                                                         vessel.latitude,
                                                                                         vessel.longitude);

                    if (resourceSample > resources[i].MinHarvestValue)
                    {
                        double resAmt = resourceSample * intakeVolume * 1d / resources[i].density * resources[i].BaseEfficiency * scale;
                        if (ScoopUI != "")
                        {
                            ScoopUI += "\n";
                        }
                        ScoopUI += Localizer.Format("#LOC_SpaceDust_ModuleSpaceDustHarvester_Field_Scoop_Resource", resources[i].Name, resAmt.ToString("G5"));
                        part.RequestResource(resources[i].Name, -resAmt * TimeWarp.fixedDeltaTime, ResourceFlowMode.ALL_VESSEL, false);
                    }
                }
                if (ScoopUI == "")
                {
                    ScoopUI = Localizer.Format("#LOC_SpaceDust_ModuleSpaceDustHarvester_Field_Scoop_Resource_None");
                }
            }

            if (HarvestType == HarvesterType.Exosphere && part.vessel.atmDensity < 0.0001d)
            {
                if (part.vessel.atmDensity > 0.0001d)
                {
                    ScoopUI = Localizer.Format("#LOC_SpaceDust_ModuleSpaceDustHarvester_Field_Scoop_NeedsVacuum");
                    return;
                }



                double orbitSpeedAtAlt = Math.Sqrt(part.vessel.mainBody.gravParameter / (part.vessel.altitude + part.vessel.mainBody.Radius));

                Vector3d worldVelocity = part.vessel.obt_velocity;
                Vector3  intakeVector;
                if (HarvestIntakeTransform == null)
                {
                    intakeVector = this.transform.forward;
                }
                else
                {
                    intakeVector = HarvestIntakeTransform.forward;
                }


                double dot          = Vector3d.Dot(worldVelocity.normalized, intakeVector.normalized);
                float  intakeVolume = (float)(worldVelocity.magnitude * MathExtensions.Clamp(dot, 0d, 1d) + IntakeSpeedStatic) * IntakeArea;
                IntakeSpeed = Localizer.Format("#LOC_SpaceDust_ModuleSpaceDustHarvester_Field_IntakeSpeed_Normal", intakeVolume.ToString("G2"));

                ScoopUI = "";

                for (int i = 0; i < resources.Count; i++)
                {
                    double resourceSample = SpaceDustResourceMap.Instance.SampleResource(resources[i].Name,
                                                                                         part.vessel.mainBody,
                                                                                         vessel.altitude + part.vessel.mainBody.Radius,
                                                                                         vessel.latitude,
                                                                                         vessel.longitude);

                    if (resourceSample * intakeVolume * resources[i].BaseEfficiency > resources[i].MinHarvestValue)
                    {
                        double resAmt = resourceSample * intakeVolume * 1d / resources[i].density * resources[i].BaseEfficiency * scale;
                        ScoopUI += Localizer.Format("#LOC_SpaceDust_ModuleSpaceDustHarvester_Field_Scoop_Resource", resources[i].Name, resAmt.ToString("G3"));
                        part.RequestResource(resources[i].Name, -resAmt * TimeWarp.fixedDeltaTime, ResourceFlowMode.ALL_VESSEL, false);
                    }
                }
                if (ScoopUI == "")
                {
                    ScoopUI = Localizer.Format("#LOC_SpaceDust_ModuleSpaceDustHarvester_Field_Scoop_Resource_None");
                }
            }
        }