Esempio n. 1
0
        // execute a script
        public void Execute(Vessel v, ScriptType type)
        {
            // do nothing if there is no EC left on the vessel
            ResourceInfo ec = ResourceCache.GetResource(v, "ElectricCharge");

            if (ec.Amount <= double.Epsilon)
            {
                return;
            }

            // get the script
            Script script;

            if (scripts.TryGetValue(type, out script))
            {
                // execute the script
                script.Execute(GetModuleDevices(v));

                // show message to the user
                // - unless the script is empty (can happen when being edited)
                if (script.states.Count > 0 && v.KerbalismData().cfg_script)
                {
                    Message.Post(Lib.BuildString(Localizer.Format("#KERBALISM_UI_scriptvessel"), " <b>", v.vesselName, "</b>"));
                }
            }
        }
Esempio n. 2
0
        // analyze a sample
        static void Analyze(Vessel v, string filename, double amount)
        {
            // get vessel drive
            Drive drive = DB.Vessel(v).drive;

            // get sample
            Sample sample = drive.samples[filename];

            // analyze, and produce data
            amount = Math.Min(amount, sample.size);
            bool completed = amount >= sample.size - double.Epsilon;

            drive.Delete_Sample(filename, amount);
            drive.Record_File(filename, amount);

            // if the analysis is completed
            if (completed)
            {
                // inform the user
                Message.Post
                (
                    Lib.BuildString("<color=cyan><b>ANALYSIS COMPLETED</b></color>\nOur laboratory on <b>", v.vesselName, "</b> analyzed <b>", Science.Experiment(filename).name, "</b>"),
                    "The results can be transmitted now"
                );

                // record landmark event
                if (!Lib.Landed(v))
                {
                    DB.landmarks.space_analysis = true;
                }
            }
        }
Esempio n. 3
0
        // show warning message when a vessel cross a radiation belt
        public static void beltWarnings(Vessel v, vessel_info vi, vessel_data vd)
        {
            // if there is a radiation rule
            if (Kerbalism.rad_rule != null)
            {
                // we only show the warning for manned vessels, or for all vessels the first time its crossed
                bool must_warn = vi.crew_count > 0 || DB.Landmarks().belt_crossing == 0;

                // show the message
                if (vi.inside_belt && vd.msg_belt < 1 && must_warn)
                {
                    Message.Post(Lib.BuildString("<b>", v.vesselName, "</b> is crossing <i>", v.mainBody.bodyName, " radiation belt</i>"), "Exposed to extreme radiation");
                    vd.msg_belt = 1;
                }
                else if (!vi.inside_belt && vd.msg_belt > 0)
                {
                    // no message after crossing the belt
                    vd.msg_belt = 0;
                }
            }

            // record first belt crossing
            if (vi.inside_belt)
            {
                DB.Landmarks().belt_crossing = 1;
            }
        }
Esempio n. 4
0
        [KSPEvent(guiActive = true, guiActiveUnfocused = true, guiName = "#KERBALISM_Greenhouse_EmergencyHarvest", active = false, groupName = "Greenhouse", groupDisplayName = "#KERBALISM_Group_Greenhouse")]        //Greenhouse
#endif
        // emergency harvest
        public void EmergencyHarvest()
        {
            // disable for dead eva kerbals
            Vessel v = FlightGlobals.ActiveVessel;

            if (v == null || EVA.IsDead(v))
            {
                return;
            }

            // calculate reduced harvest size
            double reduced_harvest = crop_size * growth * 0.5;

            // produce reduced quantity of food, proportional to current growth
            ResourceCache.Produce(vessel, crop_resource, reduced_harvest, ResourceBroker.Greenhouse);

            // reset growth
            growth = 0.0;

            // show message
            Message.Post(Lib.BuildString(Local.Greenhouse_msg_1.Format("<color=ffffff>" + vessel.vesselName + "</color> "), Local.Greenhouse_msg_3.Format(" <color=ffffff>" + reduced_harvest.ToString("F0") + " " + crop_resource + "</color>")));         //"On <<1>>""emergency harvest produced"

            // record first harvest
            if (!Lib.Landed(vessel))
            {
                DB.landmarks.space_harvest = true;
            }
        }
Esempio n. 5
0
 public static void ShowMessage(Vessel v, string type)
 {
     if (DB.Ready() && DB.VesselData(v.id).cfg_malfunction == 1)
     {
         Message.Post(Severity.warning, Lib.BuildString("<b>", type, "</b> malfunctioned on <b>", v.vesselName, "</b>"));
     }
 }
Esempio n. 6
0
        [KSPEvent(guiActive = true, guiActiveEditor = true, guiName = "_", active = true, groupName = "Habitat", groupDisplayName = "#KERBALISM_Group_Habitat")]//Habitat
#endif
        public void Toggle()
        {
            // if manned, we can't depressurize
            if (Lib.IsCrewed(part) && (state == State.enabled || state == State.pressurizing))
            {
                Message.Post(Local.Habitat_postmsg.Format(Lib.PartName(part)));//"Can't disable <b><<1>> habitat</b> while crew is inside"//Lib.BuildString("Can't disable <b>", , " habitat</b> while crew is inside"
                return;
            }

            // Need be equalized
            needEqualize = true;
            FixIVA       = true;

            // Every time that toggle bot be clicked, it will change the flow, better then call it every frame
            // state switching
            switch (state)
            {
            // Make Set_flow be called only once throgh the Toggle
            case State.enabled: Set_flow(false); state = State.depressurizing; break;

            case State.disabled: Set_flow(true); state = State.pressurizing; break;

            case State.pressurizing: Set_flow(false); state = State.depressurizing; break;

            case State.depressurizing: Set_flow(true); state = State.pressurizing; break;
            }

            // refresh VAB/SPH ui
            if (Lib.IsEditor())
            {
                GameEvents.onEditorShipModified.Fire(EditorLogic.fetch.ship);
            }
        }
Esempio n. 7
0
        public void Inspect()
        {
            // disable for dead eva kerbals
            Vessel v = FlightGlobals.ActiveVessel;

            if (v == null || EVA.IsDead(v))
            {
                return;
            }

            // get normalized time to failure
            double time_k = (Planetarium.GetUniversalTime() - last) / (next - last);

            // notify user
            if (time_k < 0.2)
            {
                Message.Post("It is practically new");
            }
            else if (time_k < 0.4)
            {
                Message.Post("It is still in good shape");
            }
            else if (time_k < 0.6)
            {
                Message.Post("It will keep working for some more time");
            }
            else if (time_k < 0.8)
            {
                Message.Post("It is reaching its operational limits");
            }
            else
            {
                Message.Post("It could fail at any moment now");
            }
        }
Esempio n. 8
0
        // execute a script
        public void execute(Vessel v, ScriptType type)
        {
            // do nothing if there is no EC left on the vessel
            resource_info ec = ResourceCache.Info(v, "ElectricCharge");

            if (ec.amount <= double.Epsilon)
            {
                return;
            }

            // get the script
            Script script;

            if (scripts.TryGetValue(type, out script))
            {
                // execute the script
                script.execute(boot(v));

                // show message to the user
                // - unless the script is empty (can happen when being edited)
                if (script.states.Count > 0 && DB.Vessel(v).cfg_script)
                {
                    Message.Post(Lib.BuildString("Script called on vessel <b>", v.vesselName, "</b>"));
                }
            }
        }
Esempio n. 9
0
        public void ToggleWindow()
        {
            // in flight
            if (Lib.IsFlight())
            {
                // disable for dead eva kerbals
                Vessel v = FlightGlobals.ActiveVessel;
                if (v == null || EVA.IsDead(v))
                {
                    return;
                }

                // check trait
                if (!reconfigure_cs.Check(v))
                {
                    Message.Post(Localizer.Format("#KERBALISM_Configure_noconfigure"), reconfigure_cs.Warning());
                    return;
                }

                // warn the user about potential resource loss
                if (Resource_loss())
                {
                    Message.Post(Severity.warning, Localizer.Format("#KERBALISM_Configure_dumpexcess"));
                }
            }

            // open the window
            UI.Open(Window_body);
        }
Esempio n. 10
0
        public void Inspect()
        {
            Vessel v = FlightGlobals.ActiveVessel;

            if (v == null || !v.isEVA || EVA.KerbalData(v).eva_dead)
            {
                return;
            }

            double time_k = (Planetarium.GetUniversalTime() - start) / (epoch - start);

            if (time_k < 0.2)
            {
                Message.Post("It is practically new");
            }
            else if (time_k < 0.4)
            {
                Message.Post("It is still in good shape");
            }
            else if (time_k < 0.6)
            {
                Message.Post("It will keep working for some more time");
            }
            else if (time_k < 0.8)
            {
                Message.Post("It is reaching its operational limits");
            }
            else
            {
                Message.Post("It could fail at any moment now");
            }
        }
Esempio n. 11
0
  public void Repair()
  {
    // do nothing if something is wrong, or the eva kerbal is dead
    Vessel v = FlightGlobals.ActiveVessel;
    if (v == null || !v.isEVA || EVA.IsDead(v)) return;

    // if the kerbal isn't an engineer, show a message and do nothing
    if (v.GetVesselCrew()[0].trait != "Engineer")
    {
      Message.Post("Only <b>Engineers</b> can repair parts");
      return;
    }

    // restore full functionality
    Apply(Math.Pow(2.0, (double)malfunctions));

    // reset malfunctions counter
    malfunctions = 0;

    // reset age and lifetime
    age = 0.0;
    lifetime = 0.0;

    // show a message
    Message.Post(Severity.relax, PrepareMsg(repair_msg, v, malfunctions));
  }
Esempio n. 12
0
        public void CleanExperiments()
        {
            bool message = false;

            var stockExperiments = vessel.FindPartModulesImplementing <ModuleScienceExperiment>();

            foreach (ModuleScienceExperiment m in stockExperiments)
            {
                if (m.resettable && m.Inoperable)
                {
                    m.ResetExperiment();
                    message = true;
                }
            }

            var kerbalismExperiments = vessel.FindPartModulesImplementing <Experiment>();

            foreach (Experiment m in kerbalismExperiments)
            {
                message |= m.Reset(false);
            }


            // inform the user
            if (message)
            {
                Message.Post(localized_cleaned);
            }
        }
Esempio n. 13
0
        private static void SubjectXmitCompleted(File file, int timesCompleted, Vessel v)
        {
            // fire science transmission game event. This is used by stock contracts and a few other things.
            GameEvents.OnScienceRecieved.Fire(timesCompleted == 1 ? (float)file.subjectData.ScienceMaxValue : 0f, file.subjectData.RnDSubject, v.protoVessel, false);

            // fire our API event
            // Note (GOT) : disabled, nobody is using it and i'm not sure what is the added value compared to the stock event,
            // unless we fire it for every transmission tick, and in this case this is a very bad idea from a performance standpoint
            // API.OnScienceReceived.Notify(credits, subject, pv, true);

            // notify the player
            string subjectResultText;

            if (string.IsNullOrEmpty(file.resultText))
            {
                subjectResultText = Lib.TextVariant(
                    Local.SciencresultText1,                    //"Our researchers will jump on it right now"
                    Local.SciencresultText2,                    //"This cause some excitement"
                    Local.SciencresultText3,                    //"These results are causing a brouhaha in R&D"
                    Local.SciencresultText4,                    //"Our scientists look very confused"
                    Local.SciencresultText5);                   //"The scientists won't believe these readings"
            }
            else
            {
                subjectResultText = file.resultText;
            }
            subjectResultText = Lib.WordWrapAtLength(subjectResultText, 70);
            Message.Post(Lib.BuildString(
                             file.subjectData.FullTitle,
                             " ", Local.Scienctransmitted_title, "\n",                                                                                                          //transmitted
                             timesCompleted == 1 ? Lib.HumanReadableScience(file.subjectData.ScienceMaxValue, false) : Lib.Color(Local.Nosciencegain, Lib.Kolor.Orange, true)), //"no science gain : we already had this data"
                         subjectResultText);
        }
Esempio n. 14
0
  // trigger malfunction for unloaded module
  public static void Break(Vessel v, ProtoPartModuleSnapshot m)
  {
    // get data
    uint malfunctions = Lib.GetProtoValue<uint>(m, "malfunctions");
    double lifetime = Lib.GetProtoValue<double>(m, "lifetime");
    double age = Lib.GetProtoValue<double>(m, "age");
    string malfunction_msg = m.moduleValues.GetValue("malfunction_msg");

    // limit number of malfunctions per-component
    if (malfunctions >= 2u) return;

    // increase malfunction
    ++malfunctions;

    // reset age and lifetime
    age = 0.0;
    lifetime = 0.0;

    // show message
    if (DB.Ready() && DB.VesselData(v.id).cfg_malfunction == 1)
    {
      Message.Post(Severity.warning, PrepareMsg(malfunction_msg, v, malfunctions));
    }

    // record first malfunction
    if (DB.Ready()) DB.NotificationData().first_malfunction = 1;

    // save data
    Lib.SetProtoValue<uint>(m, "malfunctions", malfunctions);
    Lib.SetProtoValue<double>(m, "lifetime", lifetime);
    Lib.SetProtoValue<double>(m, "age", age);
  }
Esempio n. 15
0
        public void Repair()
        {
            Vessel v = FlightGlobals.ActiveVessel;

            if (v == null || !v.isEVA || EVA.KerbalData(v).eva_dead)
            {
                return;
            }
            ProtoCrewMember c = v.GetVesselCrew()[0];

            if (trait.Length > 0 && c.trait != trait)
            {
                Message.Post(Lib.BuildString("Only <b>", trait, "s</b> can repair this component"));
                return;
            }
            if (c.experienceLevel < level)
            {
                Message.Post(Lib.BuildString("<b>", c.name, "</b> doesn't have enough experience"));
                return;
            }

            component.Apply(Math.Pow(2.0, malfunctions));
            malfunctions = 0;

            Message.Post(Lib.BuildString("<b>", type, "</b> repaired"), repair_subtext[Lib.RandomInt(repair_subtext.Length)]);
        }
Esempio n. 16
0
        public void EmergencyHarvest()
        {
            // disable for dead eva kerbals
            Vessel v = FlightGlobals.ActiveVessel;

            if (v == null || EVA.IsDead(v))
            {
                return;
            }

            // calculate reduced harvest size
            double reduced_harvest = crop_size * growth * 0.5;

            // produce reduced quantity of food, proportional to current growth
            ResourceCache.Produce(vessel, crop_resource, reduced_harvest);

            // reset growth
            growth = 0.0;

            // show message
            Message.Post(Lib.BuildString("On <color=ffffff>", vessel.vesselName, "</color> an emergency harved produced <color=ffffff>",
                                         reduced_harvest.ToString("F0"), " ", crop_resource, "</color>"));

            // record first harvest
            if (!Lib.Landed(vessel))
            {
                DB.landmarks.space_harvest = true;
            }
        }
Esempio n. 17
0
        public void Toggle()
        {
            // if manned, we can't depressurize
            if (Lib.IsManned(part) && (state == State.enabled || state == State.pressurizing))
            {
                Message.Post(Lib.BuildString("Can't disable <b>", Lib.PartName(part), " habitat</b> while crew is inside"));
                return;
            }

            // Need be equalized
            needEqualize = true;
            FixIVA       = true;

            // Every time that toggle bot be clicked, it will change the flow, better then call it every frame
            // state switching
            switch (state)
            {
            // Make Set_flow be called only once throgh the Toggle
            case State.enabled:        Set_flow(false); state = State.depressurizing; break;

            case State.disabled:       Set_flow(true);  state = State.pressurizing;   break;

            case State.pressurizing:   Set_flow(false); state = State.depressurizing; break;

            case State.depressurizing: Set_flow(true);  state = State.pressurizing;   break;
            }
        }
Esempio n. 18
0
        public static void KeyboardInput()
        {
            // mute/unmute messages with keyboard
            if (Input.GetKeyDown(KeyCode.Pause))
            {
                if (!Message.IsMuted())
                {
                    Message.Post("Messages muted", "Be careful out there");
                    Message.Mute();
                }
                else
                {
                    Message.Unmute();
                    Message.Post("Messages unmuted");
                }
            }

            // toggle body info window with keyboard
            if (MapView.MapIsEnabled && Input.GetKeyDown(KeyCode.B))
            {
                UI.Open(BodyInfo.Body_info);
            }

            // call action scripts
            // - avoid creating vessel data for invalid vessels
            Vessel v = FlightGlobals.ActiveVessel;

            if (v == null)
            {
                return;
            }
            VesselData vd = v.KerbalismData();

            if (!vd.IsSimulated)
            {
                return;
            }

            // call scripts with 1-5 key
            if (Input.GetKeyDown(KeyCode.Alpha1) || Input.GetKeyDown(KeyCode.Keypad1))
            {
                vd.computer.Execute(v, ScriptType.action1);
            }
            if (Input.GetKeyDown(KeyCode.Alpha2) || Input.GetKeyDown(KeyCode.Keypad2))
            {
                vd.computer.Execute(v, ScriptType.action2);
            }
            if (Input.GetKeyDown(KeyCode.Alpha3) || Input.GetKeyDown(KeyCode.Keypad3))
            {
                vd.computer.Execute(v, ScriptType.action3);
            }
            if (Input.GetKeyDown(KeyCode.Alpha4) || Input.GetKeyDown(KeyCode.Keypad4))
            {
                vd.computer.Execute(v, ScriptType.action4);
            }
            if (Input.GetKeyDown(KeyCode.Alpha5) || Input.GetKeyDown(KeyCode.Keypad5))
            {
                vd.computer.Execute(v, ScriptType.action5);
            }
        }
Esempio n. 19
0
		void TechResearched(GameEvents.HostTargetAction<RDTech, RDTech.OperationResult> data)
		{
			if (data.target != RDTech.OperationResult.Successful) return;

			// collect unique configure-related unlocks
			HashSet<string> labels = new HashSet<string>();
			foreach (AvailablePart p in PartLoader.LoadedPartsList)
			{
				foreach (Configure cfg in p.partPrefab.FindModulesImplementing<Configure>())
				{
					foreach (ConfigureSetup setup in cfg.Setups())
					{
						if (setup.tech == data.host.techID)
						{

							labels.Add(Lib.BuildString(setup.name, " in ", cfg.title));
						}
					}
				}

				// add unique configure-related unlocks
				foreach (string label in labels)
				{
					Message.Post
					(
					  "<color=#00ffff><b>PROGRESS</b></color>\nOur scientists just made a breakthrough",
					  Lib.BuildString("We now have access to <b>", label, "</b>")
					);
				}
			}
		}
Esempio n. 20
0
        // analyze a sample
        private static void Analyze(Vessel v, string filename, double amount)
        {
            // get vessel drive
            Drive drive = DB.Vessel(v).drive;

            // get sample
            Sample sample = drive.samples[filename];

            // analyze, and produce data
            amount = Math.Min(amount, sample.size);
            bool completed = amount >= sample.size - double.Epsilon;

            drive.Delete_sample(filename, amount);
            drive.Record_file(filename, amount);

            // if the analysis is completed
            if (completed)
            {
                // inform the user
                Message.Post(Lib.BuildString(Lib.Color("cyan", Localizer.Format("#KERBALISM_Laboratory_Analysis"), true), "\n",
                                             Localizer.Format("#KERBALISM_Laboratory_Analyzed", Lib.Bold(v.vesselName), Lib.Bold(Science.Experiment(filename).name))), localized_results);

                // record landmark event
                if (!Lib.Landed(v))
                {
                    DB.landmarks.space_analysis = true;
                }
            }
        }
Esempio n. 21
0
        public void ToggleWindow()
        {
            // in flight
            if (Lib.IsFlight())
            {
                // disable for dead eva kerbals
                Vessel v = FlightGlobals.ActiveVessel;
                if (v == null || EVA.IsDead(v))
                {
                    return;
                }

                // check trait
                if (!reconfigure_cs.Check(v))
                {
                    Message.Post("Can't reconfigure the component", reconfigure_cs.Warning());
                    return;
                }

                // warn the user about potential resource loss
                if (Resource_Loss())
                {
                    Message.Post(Severity.warning, "Reconfiguring will dump resources in excess of capacity.");
                }
            }

            // open the window
            UI.Open(Window_Body);
        }
Esempio n. 22
0
 static void Safemode_msg(Vessel v, string title)
 {
     Message.Post
     (
         Lib.BuildString("There has been a problem with <b>", title, "</b> on <b>", v.vesselName, "</b>"),
         "We were able to fix it remotely, this time"
     );
 }
Esempio n. 23
0
 public void OnSubjectCompleted()
 {
     if (ExpInfo.UnlockResourceSurvey)
     {
         ResourceMap.Instance.UnlockPlanet(Situation.Body.flightGlobalsIndex);
         Message.Post(Localizer.Format("#autoLOC_259361", Situation.BodyTitle) + "</color>");
     }
 }
Esempio n. 24
0
        public static void Update(Vessel v, Vessel_Info vi, VesselData vd, double elapsed_s)
        {
            // do nothing if storms are disabled
            if (!Features.SpaceWeather)
            {
                return;
            }

            // only consider vessels in interplanetary space
            if (v.mainBody.flightGlobalsIndex != 0)
            {
                return;
            }

            // skip unmanned vessels
            if (vi.crew_count == 0)
            {
                return;
            }

            // generate storm time if necessary
            if (vd.storm_time <= double.Epsilon)
            {
                vd.storm_time = Settings.StormMinTime + (Settings.StormMaxTime - Settings.StormMinTime) * Lib.RandomDouble();
            }

            // accumulate age
            vd.storm_age += elapsed_s * Storm_Frequency(vi.sun_dist);

            // if storm is over
            if (vd.storm_age > vd.storm_time && vd.storm_state == 2)
            {
                vd.storm_age   = 0.0;
                vd.storm_time  = 0.0;
                vd.storm_state = 0;

                // send message
                Message.Post(Severity.relax, Lib.BuildString("The solar storm around <b>", v.vesselName, "</b> is over"));
            }
            // if storm is in progress
            else if (vd.storm_age > vd.storm_time - Settings.StormDuration && vd.storm_state == 1)
            {
                vd.storm_state = 2;

                // send message
                Message.Post(Severity.danger, Lib.BuildString("The coronal mass ejection hit <b>", v.vesselName, "</b>"),
                             Lib.BuildString("Storm duration: ", Lib.HumanReadableDuration(TimeLeftCME(vd.storm_time, vd.storm_age))));
            }
            // if storm is incoming
            else if (vd.storm_age > vd.storm_time - Settings.StormDuration - Time_to_Impact(vi.sun_dist) && vd.storm_state == 0)
            {
                vd.storm_state = 1;

                // send message
                Message.Post(Severity.warning, Lib.BuildString("Our observatories report a coronal mass ejection directed toward <b>", v.vesselName, "</b>"),
                             Lib.BuildString("Time to impact: ", Lib.HumanReadableDuration(TimeBeforeCME(vd.storm_time, vd.storm_age))));
            }
        }
Esempio n. 25
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);
            }
        }
Esempio n. 26
0
        // analyze a sample
        private static Status Analyze(Vessel v, string filename, double amount)
        {
            Sample sample = null;

            foreach (var d in DB.Vessel(v).drives.Values)
            {
                if (d.samples.ContainsKey(filename))
                {
                    sample = d.samples[filename];
                }
                break;
            }

            var drive = DB.Vessel(v).BestDrive(amount);

            bool completed = sample == null;

            if (sample != null)
            {
                // analyze, and produce dataamount = Math.Min(amount, sample.size);
                completed = amount >= sample.size - double.Epsilon;
                bool recorded = drive.Record_file(filename, amount, false);
                if (recorded)
                {
                    drive.Delete_sample(filename, amount);
                }
                else
                {
                    Message.Post(
                        Lib.Color("red", Lib.BuildString(Localizer.Format("#KERBALISM_Laboratory_Analysis"), " stopped")),
                        "Not enough space on hard drive"
                        );

                    return(Status.NO_STORAGE);
                }
            }

            // if the analysis is completed
            if (completed)
            {
                // inform the user
                Message.Post(Lib.BuildString(Lib.Color("cyan", Localizer.Format("#KERBALISM_Laboratory_Analysis"), true), "\n",
                                             Localizer.Format("#KERBALISM_Laboratory_Analyzed", Lib.Bold(v.vesselName), Lib.Bold(Science.Experiment(filename).name))), localized_results);

                if (PreferencesBasic.Instance.transmitScience)
                {
                    drive.Transmit_file(filename);
                }

                // record landmark event
                if (!Lib.Landed(v))
                {
                    DB.landmarks.space_analysis = true;
                }
            }

            return(Status.RUNNING);
        }
Esempio n. 27
0
        public static void Update(Vessel v, VesselData vd, double elapsed_s)
        {
            // do nothing if storms are disabled
            if (!Features.SpaceWeather)
            {
                return;
            }

            // only consider vessels in interplanetary space
            if (!Lib.IsSun(v.mainBody))
            {
                return;
            }

            // disregard EVAs
            if (v.isEVA)
            {
                return;
            }

            var bd = vd.stormData;

            CreateStorm(bd, v.mainBody, vd.EnvMainSun.Distance);

            if (vd.cfg_storm)
            {
                switch (bd.storm_state)
                {
                case 0:     // no storm
                    if (bd.msg_storm == 2)
                    {
                        // send message
                        Message.Post(Severity.relax, Local.Storm_msg4.Format("<b>" + v.vesselName + "</b>")); //Lib.BuildString("The solar storm around <<1>> is over")
                        vd.msg_signal = false;                                                                // used to avoid sending 'signal is back' messages en-masse after the storm is over
                    }
                    break;

                case 2:     // storm in progress
                    if (bd.msg_storm < 2)
                    {
                        Message.Post(Severity.danger, Local.Storm_msg5.Format("<b>", v.vesselName, "</b>"),                                //Lib.BuildString("The coronal mass ejection hit <<1>>)
                                     Lib.BuildString(Local.Storm_msg1text, " ", Lib.HumanReadableDuration(bd.displayed_duration)));        //"Storm duration:"
                    }
                    break;

                case 1:     // storm incoming
                    if (bd.msg_storm < 1 && bd.display_warning)
                    {
                        var tti = bd.storm_time - Planetarium.GetUniversalTime();
                        Message.Post(Severity.warning, Local.Storm_msg6.Format("<b>" + v.vesselName + "</b>"),                              //Lib.BuildString("Our observatories report a coronal mass ejection directed toward <<1>>)
                                     Lib.BuildString(Local.Storm_msg2text, " ", Lib.HumanReadableDuration(tti)));                           //"Time to impact:
                    }
                    break;
                }
            }
            bd.msg_storm = bd.storm_state;
        }
Esempio n. 28
0
        void Start()
        {
            // get dialog
            dialog = gameObject.GetComponentInParent <ExperimentsResultDialog>();
            if (dialog == null)
            {
                Destroy(gameObject); return;
            }

            // prevent rendering
            dialog.gameObject.SetActive(false);

            // for each page
            // - some mod may collect multiple experiments at once
            while (dialog.pages.Count > 0)
            {
                // get page
                var page = dialog.pages[0];

                // get science data
                ScienceData data = page.pageData;

                // collect and deduce all info necessary
                MetaData meta = new MetaData(data, page.host);

                // record data in the drive
                Drive drive = DB.Vessel(meta.vessel).drive;
                if (!meta.is_sample)
                {
                    drive.Record_file(data.subjectID, data.dataAmount);
                }
                else
                {
                    drive.Record_sample(data.subjectID, data.dataAmount);
                }

                // render experiment inoperable if necessary
                if (!meta.is_rerunnable)
                {
                    meta.experiment.SetInoperable();
                }

                // dump the data
                page.OnDiscardData(data);

                // inform the user
                Message.Post
                (
                    Lib.BuildString("<b>", Science.Experiment(data.subjectID).fullname, "</b> recorded"),
                    !meta.is_rerunnable ? Localizer.Format("#KERBALISM_Science_inoperable") : string.Empty
                );
            }

            // dismiss the dialog
            dialog.Dismiss();
        }
Esempio n. 29
0
        public void update(Vessel v, vessel_info vi, vessel_data vd, vessel_resources resources, double elapsed_s)
        {
            // do nothing if signal mechanic is disabled
            if (!Kerbalism.features.signal)
            {
                return;
            }

            // get link data
            link_data link = vi.link;

            // consume relay ec
            // note: this is the only way to do it with new signal and resource systems
            if (vi.antenna.relay_range > 0.0)
            {
                foreach (Vessel w in FlightGlobals.Vessels)
                {
                    vessel_info wi = Cache.VesselInfo(w);
                    if (wi.is_valid)
                    {
                        if (wi.link.path.Contains(v))
                        {
                            resources.Consume(v, "ElectricCharge", vi.antenna.relay_cost * elapsed_s);
                            break;
                        }
                    }
                }
            }

            // maintain and send messages
            // - do nothing if db isn't ready
            // - do not send messages for vessels without an antenna
            if (link.status != link_status.no_antenna)
            {
                if (vd.msg_signal < 1 && !link.linked)
                {
                    vd.msg_signal = 1;
                    if (vd.cfg_signal == 1 && !vi.blackout) //< do not send message during storms
                    {
                        Message.Post(Severity.warning, Lib.BuildString("Signal lost with <b>", v.vesselName, "</b>"),
                                     vi.crew_count == 0 && Settings.RemoteControlLink ? "Remote control disabled" : "Data transmission disabled");
                    }
                }
                else if (vd.msg_signal > 0 && link.linked)
                {
                    vd.msg_signal = 0;
                    if (vd.cfg_signal == 1 && !Storm.JustEnded(v, elapsed_s)) //< do not send messages after a storm
                    {
                        var path = link.path;
                        Message.Post(Severity.relax, Lib.BuildString("<b>", v.vesselName, "</b> signal is back"),
                                     path.Count == 0 ? "We got a direct link with the space center" : Lib.BuildString("Relayed by <b>", path[path.Count - 1].vesselName, "</b>"));
                    }
                }
            }
        }
Esempio n. 30
0
        public static void KeyboardInput()
        {
            // mute/unmute messages with keyboard
            if (Input.GetKeyDown(KeyCode.Pause))
            {
                if (!Message.IsMuted())
                {
                    Message.Post("Messages muted", "Be careful out there");
                    Message.Mute();
                }
                else
                {
                    Message.Unmute();
                    Message.Post("Messages unmuted");
                }
            }

            // toggle body info window with keyboard
            if (MapView.MapIsEnabled && Input.GetKeyDown(KeyCode.B))
            {
                UI.open(BodyInfo.body_info);
            }

            // call action scripts
            // - avoid creating vessel data for invalid vessels
            Vessel v = FlightGlobals.ActiveVessel;

            if (v != null && DB.vessels.ContainsKey(Lib.RootID(v)))
            {
                // get computer
                Computer computer = DB.Vessel(v).computer;

                // call scripts with 1-5 key
                if (Input.GetKeyDown(KeyCode.Alpha1) || Input.GetKeyDown(KeyCode.Keypad1))
                {
                    computer.execute(v, ScriptType.action1);
                }
                if (Input.GetKeyDown(KeyCode.Alpha2) || Input.GetKeyDown(KeyCode.Keypad2))
                {
                    computer.execute(v, ScriptType.action2);
                }
                if (Input.GetKeyDown(KeyCode.Alpha3) || Input.GetKeyDown(KeyCode.Keypad3))
                {
                    computer.execute(v, ScriptType.action3);
                }
                if (Input.GetKeyDown(KeyCode.Alpha4) || Input.GetKeyDown(KeyCode.Keypad4))
                {
                    computer.execute(v, ScriptType.action4);
                }
                if (Input.GetKeyDown(KeyCode.Alpha5) || Input.GetKeyDown(KeyCode.Keypad5))
                {
                    computer.execute(v, ScriptType.action5);
                }
            }
        }