Example #1
0
 public override void OnUpdate()
 {
     try
     {
         body = FlightGlobals.currentMainBody.bodyName;
         lat  = Utilities.Rad2Lat(FlightGlobals.ship_latitude).ToString();
         lon  = Utilities.Rad2Lon(FlightGlobals.ship_longitude).ToString();
         var dn = RegolithResourceMap.GetDepletionNode(FlightGlobals.ship_latitude, FlightGlobals.ship_longitude);
         depNode = string.Format("x:{0}/y:{1}", dn.x, dn.y);
         var bmap = FlightGlobals.currentMainBody.BiomeMap;
         if (bmap != null)
         {
             var bdata = bmap.GetAtt(FlightGlobals.ship_latitude, FlightGlobals.ship_longitude);
             bioName = bdata.name;
         }
     }
     catch (Exception e)
     {
         //Swallow - probably a biome issue
     }
 }
        protected override ConversionRecipe PrepareRecipe(double deltaTime)
        {
            try
            {
                if (!HighLogic.LoadedSceneIsFlight)
                {
                    return(null);
                }

                if (HarvesterType == 0 && !vessel.Landed)
                {
                    status = "must land first";
                    print("[REGO] Shutting down because vehicle is not landed");
                    IsActivated = false;
                    return(null);
                }
                if (HarvesterType == 1 && !vessel.Splashed)
                {
                    status = "must be splashed down";
                    print("[REGO] Shutting down because vehicle is not splashed");
                    IsActivated = false;
                    return(null);
                }

                //Handle state change
                UpdateConverterStatus();
                if (!IsActivated)
                {
                    return(null);
                }


                var abundance = RegolithResourceMap
                                .GetAbundance(vessel.latitude, vessel.longitude, ResourceName,
                                              FlightGlobals.currentMainBody.flightGlobalsIndex, HarvesterType, vessel.altitude);
                //print("[RD] Abundance: " + abundance);
                //print("[RD] Efficiency: " + Efficiency);
                var rate = abundance * Efficiency;
                //print("[RD] Rate: " + rate);
                if (HarvesterType == 2) //Account for altitude and airspeed
                {
                    double atmDensity = vessel.atmDensity;
                    //print("[RD] atmDensity: " + atmDensity);
                    double airSpeed = part.vessel.srf_velocity.magnitude + 40.0;
                    //print("[RD] airSpeed: " + airSpeed);
                    double totalIntake = airSpeed * atmDensity;
                    //print("[RD] totalIntake: " + totalIntake);
                    rate *= (float)totalIntake;
                    //print("[RD] rate: " + rate);
                }
                _resFlow = rate;

                //Setup our recipe
                var recipe = LoadRecipe(rate);
                return(recipe);
            }
            catch (Exception e)
            {
                print("[REGO] - Error in - REGO_ModuleCrustalHarvester_ConversionRecipe - " + e.Message);
                return(null);
            }
        }