コード例 #1
0
        public static void manageRescueMission(Vessel v)
        {
            // true if we detected this was a rescue mission vessel
            bool detected = false;

            // deal with rescue missions
            foreach (ProtoCrewMember c in Lib.CrewList(v))
            {
                // get kerbal data
                KerbalData kd = DB.Kerbal(c.name);

                // flag the kerbal as not rescue at prelaunch
                if (v.situation == Vessel.Situations.PRELAUNCH)
                {
                    kd.rescue = false;
                }

                // if the kerbal belong to a rescue mission
                if (kd.rescue)
                {
                    // remember it
                    detected = true;

                    // flag the kerbal as non-rescue
                    // note: enable life support mechanics for the kerbal
                    kd.rescue = false;

                    // show a message
                    Message.Post(Lib.BuildString("We found <b>", c.name, "</b>"), Lib.BuildString((c.gender == ProtoCrewMember.Gender.Male ? "He" : "She"), "'s still alive!"));
                }
            }

            // gift resources
            if (detected)
            {
                var reslib = PartResourceLibrary.Instance.resourceDefinitions;
                var parts  = Lib.GetPartsRecursively(v.rootPart);

                // give the vessel some propellant usable on eva
                string monoprop_name   = Lib.EvaPropellantName();
                double monoprop_amount = Lib.EvaPropellantCapacity();
                foreach (var part in parts)
                {
                    if (part.CrewCapacity > 0 || part.FindModuleImplementing <KerbalEVA>() != null)
                    {
                        if (Lib.Capacity(part, monoprop_name) <= double.Epsilon)
                        {
                            Lib.AddResource(part, monoprop_name, 0.0, monoprop_amount);
                        }
                        break;
                    }
                }
                ResourceCache.Produce(v, monoprop_name, monoprop_amount);

                // give the vessel some supplies
                Profile.SetupRescue(v);
            }
        }
コード例 #2
0
        public void BuildHabitatInfos()
        {
            if (habitatInfos != null)
            {
                return;
            }
            if (part.transform == null)
            {
                return;
            }
            var emitterPosition = part.transform.position;

            List <Habitat> habitats;

            if (Lib.IsEditor())
            {
                habitats = new List <Habitat>();

                List <Part> parts = Lib.GetPartsRecursively(EditorLogic.RootPart);
                foreach (var p in parts)
                {
                    var habitat = p.FindModuleImplementing <Habitat>();
                    if (habitat != null)
                    {
                        habitats.Add(habitat);
                    }
                }
            }
            else
            {
                habitats = vessel.FindPartModulesImplementing <Habitat>();
            }

            habitatInfos = new List <HabitatInfo>();

            foreach (var habitat in habitats)
            {
                var habitatPosition = habitat.part.transform.position;
                var vector          = habitatPosition - emitterPosition;

                HabitatInfo spi = new HabitatInfo(habitat, vector.magnitude);
                habitatInfos.Add(spi);
            }
        }
コード例 #3
0
        void manageResqueMission(Vessel v)
        {
            // true if we detected this was a resque mission vessel
            bool detected = false;

            // deal with resque missions
            foreach (ProtoCrewMember c in v.GetVesselCrew())
            {
                // get kerbal data
                kerbal_data kd = DB.KerbalData(c.name);

                // flag the kerbal as not resque at prelaunch
                if (v.situation == Vessel.Situations.PRELAUNCH)
                {
                    kd.resque = 0;
                }

                // if the kerbal belong to a resque mission
                if (kd.resque == 1)
                {
                    // remember it
                    detected = true;

                    // flag the kerbal as non-resque
                    // note: enable life support mechanics for the kerbal
                    kd.resque = 0;

                    // show a message
                    Message.Post(Lib.BuildString("We found <b>", c.name, "</b>"), Lib.BuildString((c.gender == ProtoCrewMember.Gender.Male ? "He" : "She"), "'s still alive!"));
                }
            }

            // gift resources
            if (detected)
            {
                var reslib = PartResourceLibrary.Instance.resourceDefinitions;
                var parts  = Lib.GetPartsRecursively(v.rootPart);

                // give the vessel some monoprop
                string monoprop_name = v.isEVA ? "EVA Propellant" : detected_mods.RealFuels ? "Hydrazine" : "MonoPropellant";
                foreach (var part in parts)
                {
                    if (part.CrewCapacity > 0 || part.FindModuleImplementing <KerbalEVA>() != null)
                    {
                        if (part.Resources.list.Find(k => k.resourceName == monoprop_name) == null)
                        {
                            Lib.SetupResource(part, monoprop_name, 0.0, Settings.MonoPropellantOnResque);
                        }
                        break;
                    }
                }
                ResourceCache.Produce(v, monoprop_name, Settings.MonoPropellantOnResque);

                // give the vessel some supplies
                foreach (Rule r in rules)
                {
                    if (r.resource_name.Length == 0 || r.on_resque <= double.Epsilon || !reslib.Contains(r.resource_name))
                    {
                        continue;
                    }
                    foreach (var part in parts)
                    {
                        if (part.CrewCapacity > 0 || part.FindModuleImplementing <KerbalEVA>() != null)
                        {
                            if (part.Resources.list.Find(k => k.resourceName == r.resource_name) == null)
                            {
                                Lib.SetupResource(part, r.resource_name, 0.0, r.on_resque);
                            }
                            break;
                        }
                    }
                    ResourceCache.Produce(v, r.resource_name, r.on_resque);
                }
            }
        }
コード例 #4
0
  public void render()
  {
    // if there is something in the editor
    if (EditorLogic.RootPart != null)
    {
      // store situations and altitude multipliers
      string[] situations = {"Landed", "Low Orbit", "Orbit", "High Orbit"};
      double[] altitude_mults = {0.0, 0.33, 1.0, 3.0};

      // get body, situation and altitude multiplier
      CelestialBody body = FlightGlobals.Bodies[body_index];
      string situation = situations[situation_index];
      double altitude_mult = altitude_mults[situation_index];

      // get parts recursively
      List<Part> parts = Lib.GetPartsRecursively(EditorLogic.RootPart);

      // analyze
      environment_data env = analyze_environment(body, altitude_mult);
      crew_data crew = analyze_crew(parts);
      food_data food = analyze_food(parts, env, crew);
      oxygen_data oxygen = analyze_oxygen(parts, env, crew);
      signal_data signal = analyze_signal(parts);
      qol_data qol = analyze_qol(parts, env, crew, signal);
      radiation_data radiation = analyze_radiation(parts, env, crew);
      ec_data ec = analyze_ec(parts, env, crew, food, oxygen, signal);
      reliability_data reliability = analyze_reliability(parts, ec, signal);

      // render menu
      GUILayout.BeginHorizontal(row_style);
      if (GUILayout.Button(body.name, leftmenu_style)) { body_index = (body_index + 1) % FlightGlobals.Bodies.Count; if (body_index == 0) ++body_index; }
      if (GUILayout.Button("["+ (page + 1) + "/2]", midmenu_style)) { page = (page + 1) % 2; }
      if (GUILayout.Button(situation, rightmenu_style)) { situation_index = (situation_index + 1) % situations.Length; }
      GUILayout.EndHorizontal();

      // page 1/2
      if (page == 0)
      {
        // render
        render_ec(ec);
        render_food(food);
        render_oxygen(oxygen);
        render_qol(qol);
      }
      // page 2/2
      else
      {
        // render
        render_radiation(radiation, env, crew);
        render_reliability(reliability, crew);
        render_signal(signal, env, crew);
        render_environment(env);
      }
    }
    // if there is nothing in the editor
    else
    {
      // render quote
      GUILayout.FlexibleSpace();
      GUILayout.BeginHorizontal();
      GUILayout.Label("<i>In preparing for space, I have always found that\nplans are useless but planning is indispensable.\nWernher von Kerman</i>", quote_style);
      GUILayout.EndHorizontal();
      GUILayout.Space(10.0f);
    }
  }