示例#1
0
  Signal()
  {
    // enable global access
    instance = this;

    // keep it alive
    DontDestroyOnLoad(this);

    // determine nearest and furthest planets from home body
    CelestialBody sun = Sim.Sun();
    CelestialBody home = Lib.PlanetarySystem(FlightGlobals.GetHomeBody());
    CelestialBody near = null;
    CelestialBody far = null;
    double min_dist = double.MaxValue;
    double max_dist = double.MinValue;
    foreach(CelestialBody body in FlightGlobals.Bodies)
    {
      if (body == sun || body == home) continue;
      if (body.referenceBody != sun) continue;
      double dist = Math.Abs(home.orbit.semiMajorAxis - body.orbit.semiMajorAxis);
      if (dist < min_dist) { min_dist = dist; near = body; }
      if (dist > max_dist) { max_dist = dist; far = body; }
    }
    range_values.Add("orbit", home.sphereOfInfluence * 1.05);
    range_values.Add("home", home.sphereOfInfluence * 4.0 * 1.05);
    range_values.Add("near", (Sim.Apoapsis(home) + Sim.Apoapsis(near)) * 1.6);
    range_values.Add("far", (Sim.Apoapsis(home) + Sim.Apoapsis(far)) * 1.1);
    range_values.Add("extreme", (Sim.Apoapsis(home) + Sim.Apoapsis(far)) * 4.0);
  }
示例#2
0
 // calculate a cache entry for the vessel
 static vessel_info Compute(Vessel v)
 {
   vessel_info info = new vessel_info();
   info.position = Lib.VesselPosition(v);
   info.sunlight = Sim.RaytraceBody(v, Sim.Sun(), out info.sun_dir, out info.sun_dist);
   info.temperature = Sim.Temperature(v, info.sunlight);
   info.cosmic_radiation = Radiation.CosmicRadiation(v);
   info.belt_radiation = Radiation.BeltRadiation(v);
   info.storm_radiation = Radiation.StormRadiation(v, info.sunlight);
   info.env_radiation = info.cosmic_radiation + info.belt_radiation + info.storm_radiation;
   info.breathable = Sim.Breathable(v);
   foreach(var p in Kerbalism.rules)
   {
     Rule r = p.Value;
     if (r.resource_name.Length > 0)
     {
       var vmon = new vmon_cache();
       vmon.depletion = r.EstimateLifetime(v);
       double amount = Lib.GetResourceAmount(v, r.resource_name);
       double capacity = Lib.GetResourceCapacity(v, r.resource_name);
       vmon.level = capacity > double.Epsilon ? amount / capacity : 1.0; //< level is 1 with no capacity
       info.vmon.Add(p.Value.name, vmon);
     }
   }
   return info;
 }
示例#3
0
  public static environment_data analyze_environment(CelestialBody body, double altitude_mult)
  {
    // shortcuts
    CelestialBody sun = Sim.Sun();

    // calculate data
    environment_data env = new environment_data();
    env.body = body;
    env.altitude = body.Radius * altitude_mult;
    env.landed = env.altitude <= double.Epsilon;
    env.breathable = env.landed && body.atmosphereContainsOxygen;
    env.sun_dist = Sim.Apoapsis(Lib.PlanetarySystem(body)) - sun.Radius - body.Radius;
    Vector3d sun_dir = (sun.position - body.position).normalized;
    env.sun_flux = Sim.SolarFlux(env.sun_dist);
    env.body_flux = Sim.BodyFlux(body, body.position + sun_dir * (body.Radius + env.altitude));
    env.body_back_flux = Sim.BodyFlux(body, body.position - sun_dir * (body.Radius + env.altitude));
    env.background_temp = Sim.BackgroundTemperature();
    env.sun_temp = Sim.BlackBody(env.sun_flux);
    env.body_temp = Sim.BlackBody(env.body_flux);
    env.body_back_temp = Sim.BlackBody(env.body_back_flux);
    env.light_temp = env.background_temp + env.sun_temp + env.body_temp;
    env.shadow_temp = env.background_temp + env.body_back_temp;
    env.atmo_temp = body.GetTemperature(0.0);
    env.orbital_period = Sim.OrbitalPeriod(body, env.altitude);
    env.shadow_period = Sim.ShadowPeriod(body, env.altitude);
    env.shadow_time = env.shadow_period / env.orbital_period;
    env.temp_diff = env.landed && body.atmosphere
      ? Math.Abs(Settings.SurvivalTemperature - env.atmo_temp)
      : Lib.Mix(Math.Abs(Settings.SurvivalTemperature - env.light_temp), Math.Abs(Settings.SurvivalTemperature - env.shadow_temp), env.shadow_time);
    env.atmo_factor = env.landed ? Sim.AtmosphereFactor(body, 0.7071) : 1.0;

    // return data
    return env;
  }
示例#4
0
  // get vessel info from the cache, or compute a new one and add it to the cache
  public static vessel_info VesselInfo(Vessel v)
  {
    // get the info from the cache, if it exist
    vessel_info info;
    if (instance.vessels.TryGetValue(v.id, out info)) return info;

    // compute vessel info
    info = new vessel_info();
    info.position = Lib.VesselPosition(v);
    info.sunlight = Sim.RaytraceBody(v, Sim.Sun(), out info.sun_dir, out info.sun_dist);
    info.temperature = Sim.Temperature(v, info.sunlight);
    info.cosmic_radiation = Radiation.CosmicRadiation(v);
    info.belt_radiation = Radiation.BeltRadiation(v);
    info.storm_radiation = Radiation.StormRadiation(v, info.sunlight);
    info.radiation = (info.cosmic_radiation + info.belt_radiation + info.storm_radiation) * (1.0 - Radiation.Shielding(v));

    // store vessel info in the cache
    instance.vessels.Add(v.id, info);

    // return the vessel info
    return info;
  }
示例#5
0
        Signal()
        {
            // enable global access
            instance = this;

            // keep it alive
            DontDestroyOnLoad(this);

            // determine nearest and furthest planets from home body
            CelestialBody sun      = Sim.Sun();
            CelestialBody home     = Lib.PlanetarySystem(FlightGlobals.GetHomeBody());
            CelestialBody near     = null;
            CelestialBody far      = null;
            double        min_dist = double.MaxValue;
            double        max_dist = double.MinValue;

            foreach (CelestialBody body in FlightGlobals.Bodies)
            {
                if (body == sun || body == home)
                {
                    continue;
                }
                if (body.referenceBody != sun)
                {
                    continue;
                }
                double dist = Math.Abs(home.orbit.semiMajorAxis - body.orbit.semiMajorAxis);
                if (dist < min_dist)
                {
                    min_dist = dist; near = body;
                }
                if (dist > max_dist)
                {
                    max_dist = dist; far = body;
                }
            }

            // generate default antenna scopes
            range_values.Add("orbit", home.sphereOfInfluence * 1.05);
            range_values.Add("home", home.sphereOfInfluence * 4.0 * 1.05);
            range_values.Add("near", (Sim.Apoapsis(home) + Sim.Apoapsis(near)) * 1.6);
            range_values.Add("far", (Sim.Apoapsis(home) + Sim.Apoapsis(far)) * 1.1);
            range_values.Add("extreme", (Sim.Apoapsis(home) + Sim.Apoapsis(far)) * 4.0);
            range_values.Add("medium", (range_values["near"] + range_values["far"]) * 0.5);

            // parse user-defined antenna scopes
            var user_scopes = Lib.ParseConfigs("AntennaScope");

            foreach (var scope in user_scopes)
            {
                string scope_name  = Lib.ConfigValue(scope, "name", "").Trim();
                double scope_range = Lib.ConfigValue(scope, "range", 0.0);

                if (scope_name.Length > 0 && scope_range > double.Epsilon)
                {
                    if (!range_values.ContainsKey(scope_name))
                    {
                        range_values.Add(scope_name, scope_range);
                        Lib.Log("Added user-defined antenna scope '" + scope_name + "' with range " + Lib.HumanReadableRange(scope_range));
                    }
                    else
                    {
                        range_values[scope_name] = scope_range;
                        Lib.Log("Using user-defined range " + Lib.HumanReadableRange(scope_range) + " for antenna scope '" + scope_name + "'");
                    }
                }
            }
        }