public LocationAndSituationParameter() { targetSituation = Vessel.Situations.ESCAPING; targetBody = null; noun = "potato"; this.successCounter = 0; }
public override bool Load(ConfigNode configNode) { // Load base class bool valid = base.Load(configNode); valid &= ConfigNodeUtil.ParseValue<Vessel.Situations>(configNode, "situation", x => situation = x, this, Vessel.Situations.ORBITING, ValidateSituations); valid &= ConfigNodeUtil.ParseValue<double>(configNode, "minAltitude", x => minAltitude = x, this, 0.0, x => Validation.GE(x, 0.0)); valid &= ConfigNodeUtil.ParseValue<double>(configNode, "maxAltitude", x => maxAltitude = x, this, double.MaxValue, x => Validation.GE(x, 0.0)); valid &= ConfigNodeUtil.ParseValue<double>(configNode, "minApA", x => minApoapsis = x, this, 0.0, x => Validation.GE(x, 0.0)); valid &= ConfigNodeUtil.ParseValue<double>(configNode, "maxApA", x => maxApoapsis = x, this, double.MaxValue, x => Validation.GE(x, 0.0)); valid &= ConfigNodeUtil.ParseValue<double>(configNode, "minPeA", x => minPeriapsis = x, this, 0.0, x => Validation.GE(x, 0.0)); valid &= ConfigNodeUtil.ParseValue<double>(configNode, "maxPeA", x => maxPeriapsis = x, this, double.MaxValue, x => Validation.GE(x, 0.0)); valid &= ConfigNodeUtil.ParseValue<double>(configNode, "minEccentricity", x => minEccentricity = x, this, 0.0, x => Validation.GE(x, 0.0)); valid &= ConfigNodeUtil.ParseValue<double>(configNode, "maxEccentricity", x => maxEccentricity = x, this, double.MaxValue, x => Validation.GE(x, 0.0)); valid &= ConfigNodeUtil.ParseValue<double>(configNode, "minInclination", x => minInclination = x, this, 0.0, x => Validation.Between(x, 0.0, 180.0)); valid &= ConfigNodeUtil.ParseValue<double>(configNode, "maxInclination", x => maxInclination = x, this, 180.0, x => Validation.Between(x, 0.0, 180.0)); valid &= ConfigNodeUtil.ParseValue<Duration>(configNode, "minPeriod", x => minPeriod = x, this, new Duration(0.0)); valid &= ConfigNodeUtil.ParseValue<Duration>(configNode, "maxPeriod", x => maxPeriod = x, this, new Duration(double.MaxValue)); // Validate target body valid &= ValidateTargetBody(configNode); // Validation minimum and groupings valid &= ConfigNodeUtil.AtLeastOne(configNode, new string[] { "minAltitude", "maxAltitude", "minApA", "maxApA", "minPeA", "maxPeA", "minEccentricity", "maxEccentricity", "minInclination", "maxInclination", "minPeriod", "maxPeriod" }, this); valid &= ConfigNodeUtil.MutuallyExclusive(configNode, new string[] { "minAltitude", "maxAltitude" }, new string[] { "minApA", "maxApA", "minPeA", "maxPeA" }, this); return valid; }
public LocationAndSituationParameter(CelestialBody targetBody, Vessel.Situations targetSituation, string noun) { this.targetBody = targetBody; this.targetSituation = targetSituation; this.noun = noun; this.successCounter = 0; }
public KLFVesselUpdate() { localPosition = new float[3]; localDirection = new float[3]; localVelocity = new float[3]; situation = Vessel.Situations.PRELAUNCH; timeScale = 1.0; }
// To create mission we need to udentity the ID // This needs to load missions public Mission(Guid id, String name, double time, Vessel.Situations situation) { KDebug.Log("Mission is creating by Id: " + id.ToString(), KDebug.Type.LOAD); this.missionId = id; this.missionName = name; this.missionApproved = true; this.missionTime = time; this.missionSituation = situation; }
public VesselInfo(string vesselName, Vessel.Situations situation, VesselType vesseltype, double currentTime) { this.vesselName = vesselName; lastUpdate = currentTime; lastFood = currentTime; lastWater = currentTime; lastOxygen = currentTime; lastElectricity = currentTime; hibernating = false; numFrozenCrew = 0; vesselSituation = situation; vesselIsPreLaunch = situation == Vessel.Situations.PRELAUNCH; vesselType = vesseltype; recoveryvessel = false; }
// Mission is created only if the have a Vessel // Check the vessel, if ok - create the mission public Mission(Vessel ves) { if (this.is_vessel_fits_to_mission(ves)) { KDebug.Log("Mission is creating by Vessel: " + ves.ToString(), KDebug.Type.CREATE); this.missionId = Mission.mission_id(ves); this.missionApproved = true; this.missionName = ves.GetName(); // Name of the mission is the name of the Vessel this.missionSituation = ves.situation; this.missionTime = Mission.mission_time(); // Static call if (String.IsNullOrEmpty(this.missionName) ) this.missionName = ves.name; // Let's see the unknown created vessels } else this.missionApproved = false; // No mission is created, we should not use this mission object }
public String GetScopeForSituationAndBody(Vessel.Situations situation, String body) { return(GetScopeForSituationAndBody(situation.ToString(), body)); }
public void LateUpdate() { if (display != null) { FlightGlobals.SpeedDisplayModes mode = FlightGlobals.speedDisplayMode; switch (mode) { case FlightGlobals.SpeedDisplayModes.Surface: Vessel.Situations situation = FlightGlobals.ActiveVessel.situation; VesselType vesselType = FlightGlobals.ActiveVessel.vesselType; double spd = FlightGlobals.ship_srfSpeed; string speedText = spd.ToString("F1") + mps; #region all VesselTypes and Situations //VesselType.Base; //Situations.LANDED //VesselType.Debris //Situations.SPLASHED //VesselType.EVA //Situations.PRELAUNCH //VesselType.Flag //Situations.FLYING //VesselType.Lander //Situations.SUB_ORBITAL //VesselType.Plane; //Situations.ORBITING //VesselType.Probe //Situations.ESCAPING //VesselType.Relay //Situations.DOCKED //VesselType.Rover //VesselType.Ship //VesselType.SpaceObject //VesselType.Station //VesselType.Unknown #endregion switch (vesselType) { case VesselType.Plane: case VesselType.Rover: // Boat or Submarine if (situation == Vessel.Situations.SPLASHED) { if (FlightGlobals.ActiveVessel.altitude < -20 && settings.radar) // Submarine { titleText = Surf3 + Formatter.Distance_short(FlightGlobals.ActiveVessel.altitude - FlightGlobals.ActiveVessel.terrainAltitude) + " " + (spd * kn_ms).ToString("F1") + kn; } else // Boat { titleText = Surf5 + (spd * kn_ms).ToString("F1") + knots; } } // Plane (not LANDED) else if (vesselType == VesselType.Plane && situation != Vessel.Situations.LANDED && situation != Vessel.Situations.PRELAUNCH) { bool isATM = FlightGlobals.ActiveVessel.atmDensity > 0.0; double speedIAS = FlightGlobals.ActiveVessel.indicatedAirSpeed; if (settings.radar) { if (settings.mach) { if (isATM) { titleText = Surf3 + Formatter.Distance_short(FlightGlobals.ActiveVessel.radarAltitude) + " " + Localizer.Format("#SpeedUnitAnnex_mach", FlightGlobals.ActiveVessel.mach.ToString("F1")); } else { titleText = Surf5 + Formatter.Distance_long(FlightGlobals.ActiveVessel.radarAltitude); } } else { titleText = Surf3 + Formatter.Distance_short(FlightGlobals.ActiveVessel.radarAltitude) + " " + (spd * kn_ms).ToString("F1") + kn; } } else { if (settings.mach) { if (isATM) { titleText = Surf5 + Localizer.Format("#SpeedUnitAnnex_mach", FlightGlobals.ActiveVessel.mach.ToString("F1")); } else { titleText = Surface; } } else { titleText = Surf5 + (spd * kn_ms).ToString("F1") + knots; } } if (settings.ias && speedIAS > 0) { speedText += " " + speedIAS.ToString("F1"); } } // Rover (and LANDED Plane) // and rover-carrier if ksp detect them as rover // All mistake at ksp detecting vessel type can be fixed by some additional checking (ex. altitude for rover-carrier) // but it make unclear to user, which values is showed up. else //if FlightGlobals.ActiveVessel.radarAltitude < 100) { if (settings.kmph) { titleText = Surf5 + (spd * kmph_ms).ToString("F1") + kmph; } else { titleText = Surf5 + (spd * mph_ms).ToString("F1") + mph; } } break; case VesselType.EVA: if (settings.radar) { double alt = FlightGlobals.ActiveVessel.radarAltitude; if (situation == Vessel.Situations.SPLASHED) { alt += 0.21; } else { alt -= 0.27; } titleText = Surf3 + Formatter.Distance_short(alt) + " " + FlightGlobals.ActiveVessel.GetDisplayName(); } else { titleText = Surf3 + FlightGlobals.ActiveVessel.GetDisplayName(); } if (titleText.Length > 17) { titleText = titleText.Substring(0, 16) + "..."; } break; case VesselType.Flag: titleText = Surf3 + FlightGlobals.ActiveVessel.GetDisplayName(); if (titleText.Length > 17) { titleText = titleText.Substring(0, 16) + "..."; } break; // Other: Rocket, Lander, Base etc default: if (settings.radar) { titleText = Surf5 + Formatter.Distance_long(FlightGlobals.ActiveVessel.radarAltitude); } else { titleText = Surface; } break; } display.textTitle.text = titleText; display.textSpeed.text = speedText; break; case FlightGlobals.SpeedDisplayModes.Orbit: if (FlightGlobals.ActiveVessel.vesselType == VesselType.EVA && settings.orbit_EVA) { if (settings.orbit_time) { titleText = FlightGlobals.ActiveVessel.GetDisplayName(); } else { titleText = Orb + FlightGlobals.ActiveVessel.GetDisplayName(); } if (titleText.Length > 17) { titleText = titleText.Substring(0, 16) + "..."; } display.textTitle.text = titleText; } else { double SOI_MASL = FlightGlobals.getMainBody().sphereOfInfluence - FlightGlobals.getMainBody().Radius; bool Ap_ok = FlightGlobals.getMainBody().atmosphereDepth < FlightGlobals.ship_orbit.ApA && FlightGlobals.ship_orbit.ApA < SOI_MASL; bool Pe_ok = FlightGlobals.getMainBody().atmosphereDepth < FlightGlobals.ship_orbit.PeA && FlightGlobals.ship_orbit.PeA < SOI_MASL; string Ap = Formatter.Distance_k(FlightGlobals.ship_orbit.ApA); string Pe = Formatter.Distance_k(FlightGlobals.ship_orbit.PeA); string Apsises = (Ap_ok ? "<color=#00ff00ff>" : "<color=#00ff009f>") + Ap + (Pe_ok ? "Â <color=#00ff00ff>" : "Â <color=#00ff009f>") + Pe; if (settings.orbit_time) { //double tTr = FlightGlobals.ship_orbit.timeToTransition1; string TimeApsis; bool Apsis_ok; if (FlightGlobals.ship_orbit.timeToAp < FlightGlobals.ship_orbit.timeToPe) { Apsis_ok = Ap_ok; TimeApsis = Formatter.Time(FlightGlobals.ship_orbit.timeToAp, Ap_pre); } else { Apsis_ok = Pe_ok; TimeApsis = Formatter.Time(FlightGlobals.ship_orbit.timeToPe, Pe_pre); } display.textTitle.text = Apsises + (Apsis_ok ? "Â <color=#ffffffff>" : "Â <color=#ffffff9f>") + TimeApsis; } else { display.textTitle.text = Orb + Apsises; } } display.textSpeed.text = FlightGlobals.ship_obtSpeed.ToString("F1") + mps; break; case FlightGlobals.SpeedDisplayModes.Target: ITargetable obj = FlightGlobals.fetch.VesselTarget; #region all Target // ITargetable -> CelestialBody; // FlightCoMTracker; // ModuleDockingNode; // PositionTarget; // Vessel; #endregion string name; if (obj is ModuleDockingNode) { name = obj.GetVessel().GetDisplayName(); } else { name = obj.GetDisplayName(); } if (name.Length > 1 && name.Substring(name.Length - 2, 1) == "^") { name = name.Substring(0, name.Length - 2); } if (settings.targetDistance) { // from Docking Port Alignment Indicator Transform selfTransform = FlightGlobals.ActiveVessel.ReferenceTransform; Transform targetTransform = FlightGlobals.fetch.VesselTarget.GetTransform(); Vector3 targetToOwnship = selfTransform.position - targetTransform.position; float distanceToTarget = targetToOwnship.magnitude; titleText = Trg + Formatter.Distance_short(distanceToTarget) + " " + name; } else { titleText = Trg + name; } if (titleText.Length <= 17) { display.textTitle.text = titleText; } else { display.textTitle.text = titleText.Substring(0, 16) + "..."; } if (FlightGlobals.ship_tgtSpeed < 0.195) { display.textSpeed.text = FlightGlobals.ship_tgtSpeed.ToString("F2") + mps; } else { display.textSpeed.text = FlightGlobals.ship_tgtSpeed.ToString("F1") + mps; } break; } // need to be there, for every tick. Doesn't work in the Start() or onSetSpeedMode() display.textTitle.alignment = TMPro.TextAlignmentOptions.MidlineLeft; } }
public override void OnStart(PartModule.StartState state) { if (state != StartState.Editor && vessel == FlightGlobals.ActiveVessel) { part.force_activate(); check_active_chatterer(); get_latest_version(); load_settings(); // must run once before loading chatter to get volume level vessel_prev_sit = vessel.situation; vessel_prev_stage = vessel.currentStage; if (vessel.GetCrewCapacity() == 0) load_all_beeps(); else { load_all_chatter(); initialize_new_exchange(); } load_all_launches(); } }
public void Update() { //Insta-... key setup if (insta_chatter_key_just_changed && Input.GetKeyUp(insta_chatter_key)) insta_chatter_key_just_changed = false; if (insta_sstv_key_just_changed && Input.GetKeyUp(insta_sstv_key)) insta_sstv_key_just_changed = false; mute_check(); radio_check(); launcherButtonTexture_check(); if (FlightGlobals.ActiveVessel != null) { vessel = FlightGlobals.ActiveVessel; //set num_beep_pages for use in windows num_beep_pages = beepsource_list.Count / 10; if (beepsource_list.Count % 10 != 0) num_beep_pages++; prev_num_pages = num_beep_pages; //sample selector one-time play if (OTP_playing && OTP_source.audiosource.isPlaying == false) { if (debugging) Debug.Log("[CHATR] one-time play has finished"); OTP_playing = false; OTP_source.audiosource.clip = OTP_stored_clip; //if (debugging) Debug.Log("[CHATR] OTP_source.current_clip = " + OTP_source.current_clip); //set_beep_clip(OTP_source); } //update remotetech info if needed if (remotetech_toggle) { rt_update_timer += Time.deltaTime; if (rt_update_timer > 2f) { updateRemoteTechData(); rt_update_timer = 0; } } /////////////////////// /////////////////////// //Do AAE //BACKGROUND if (aae_backgrounds_exist) { //if vessel not qualified to have onboard noises, stop background audio if (vessel.GetCrewCapacity() < 1 || vessel.vesselType != VesselType.Ship && vessel.vesselType != VesselType.Station && vessel.vesselType != VesselType.Base && vessel.vesselType != VesselType.Lander) { foreach (BackgroundSource src in backgroundsource_list) { if (src.audiosource.isPlaying == true) { src.audiosource.Stop(); } } } //check if user chose to have only background when on IVA, and then check if in IVA else if ((aae_backgrounds_onlyinIVA && (CameraManager.Instance.currentCameraMode == CameraManager.CameraMode.IVA || CameraManager.Instance.currentCameraMode == CameraManager.CameraMode.Internal)) || !aae_backgrounds_onlyinIVA) { foreach (BackgroundSource src in backgroundsource_list) { if (src.audiosource.isPlaying == false) { src.audiosource.loop = true; src.audiosource.Play(); } } } else //else stop background audio { foreach (BackgroundSource src in backgroundsource_list) { if (src.audiosource.isPlaying == true) { src.audiosource.Stop(); } } } } //SOUNDSCAPE if (aae_soundscapes_exist) { if (aae_soundscape_freq == 0) { //turned off aae_soundscape.Stop(); } else if (aae_soundscape_freq == 4) { //don't play soundscapes when within kerbin atmo if (vessel.mainBody.bodyName != "Kerbin" || (vessel.mainBody.bodyName == "Kerbin" && (vessel.situation == Vessel.Situations.ORBITING || vessel.situation == Vessel.Situations.ESCAPING))) { //continuous loop of clips if (aae_soundscape.isPlaying == false) { if (debugging) Debug.Log("[CHATR] playing next soundscape clip in continuous loop..."); set_soundscape_clip(); aae_soundscape.Play(); } } } else { //don't play soundscapes when within kerbin atmo if (vessel.mainBody.bodyName != "Kerbin" || (vessel.mainBody.bodyName == "Kerbin" && (vessel.situation == Vessel.Situations.ORBITING || vessel.situation == Vessel.Situations.ESCAPING))) { //run timer until timer_limit is reached, then play a random clip if (aae_soundscape.isPlaying == false) { aae_soundscape_timer += Time.deltaTime; if (aae_soundscape_timer > aae_soundscape_timer_limit) { if (debugging) Debug.Log("[CHATR] soundscape1 timer limit reached, playing next clip..."); set_soundscape_clip(); aae_soundscape.Play(); aae_soundscape_timer = 0; //reset timer new_soundscape_loose_timer_limit(); //roll new timer limit } } } } } //EVA BREATHING if (aae_breathing_exist) { if (vessel.vesselType == VesselType.EVA && aae_breathing.isPlaying == false) { if (debugging) Debug.Log("[CHATR] breathingsource.Play() loop has started"); aae_breathing.Play(); } if (vessel.vesselType != VesselType.EVA && aae_breathing.isPlaying) { if (debugging) Debug.Log("[CHATR] No longer EVA, breathingsource.Stop()"); aae_breathing.Stop(); } } //WIND if (aae_wind_exist) { //check that body has atmosphere, vessel is within it if (vessel.mainBody.atmosphere && vessel.atmDensity > 0 && (CameraManager.Instance.currentCameraMode != CameraManager.CameraMode.IVA && CameraManager.Instance.currentCameraMode != CameraManager.CameraMode.Internal)) { //set volume according to atmosphere density aae_wind.volume = aae_wind_vol_slider * Math.Min((float)vessel.atmDensity, 1); //play the audio if not playing already if (aae_wind.isPlaying == false) { if (debugging) Debug.Log("[CHATR] aae_wind.Play()"); aae_wind.loop = true; aae_wind.Play(); } } else { //stop when out of atmosphere if (aae_wind.isPlaying) { if (debugging) Debug.Log("[CHATR] aae_wind.Stop()"); if (aae_wind.isPlaying) aae_wind.Stop(); } } } //END AAE ///////////////////////////////////////////// ///////////////////////////////////////////// //START SSTV //do SSTV if (sstv_exists) { //insta-sstv activated if ((remotetech_toggle == false || (remotetech_toggle && inRadioContact)) && (insta_sstv_key_just_changed == false && Input.GetKeyDown(insta_sstv_key) && sstv.isPlaying == false)) { if (debugging) Debug.Log("[CHATR] beginning exchange,insta-SSTV"); if (exchange_playing) { //stop and reset any currently playing chatter exchange_playing = false; initial_chatter.Stop(); response_chatter.Stop(); initialize_new_exchange(); } if (all_sstv_clips.Count > 0) { //get new clip, play it, set and get timers sstv.clip = all_sstv_clips[rand.Next(0, all_sstv_clips.Count)]; sstv.Play(); sstv_timer = 0; new_sstv_loose_timer_limit(); } else Debug.LogWarning("[CHATR] No SSTV clips to play"); } //timed/on science sstv if (all_sstv_clips.Count > 0) { //timed : if clips exist, do things if (sstv_freq > 0) { sstv_timer += Time.deltaTime; if (sstv_timer > sstv_timer_limit) { sstv_timer = 0; new_sstv_loose_timer_limit(); if (sstv.isPlaying == false && (remotetech_toggle == false || (remotetech_toggle && inRadioContact))) { //get a random one and play if (exchange_playing) { //stop and reset any currently playing chatter exchange_playing = false; initial_chatter.Stop(); response_chatter.Stop(); initialize_new_exchange(); } sstv.clip = all_sstv_clips[rand.Next(0, all_sstv_clips.Count)]; sstv.Play(); //sstv_timer = 0; //new_sstv_loose_timer_limit(); } } } //on science transmitted if (all_sstv_clips.Count > 0 && sstv_on_science_toggle == true) { if (science_transmitted == true) { if (sstv.isPlaying == false && (remotetech_toggle == false || (remotetech_toggle && inRadioContact))) { //stop and reset any currently playing chatter if (exchange_playing) { exchange_playing = false; initial_chatter.Stop(); response_chatter.Stop(); initialize_new_exchange(); } //get a random one and play sstv.clip = all_sstv_clips[rand.Next(0, all_sstv_clips.Count)]; sstv.Play(); if (debugging) Debug.Log("[CHATR] beginning exchange,science-SSTV..."); } science_transmitted = false; } } } } //END SSTV ///////////////////////////////////////////// ///////////////////////////////////////////// //START BEEPS //do beeps if (beeps_exists) { if (dict_probe_samples.Count > 0 && OTP_playing == false && (remotetech_toggle == false || (remotetech_toggle == true && inRadioContact))) //don't do any beeps here while OTP is playing { foreach (BeepSource bm in beepsource_list) { if (bm.precise) { //precise beeps if (bm.precise_freq == -1) { //beeps turned off at slider //bm.audiosource.Stop(); //squashed bug: this was breaking the one-time play button bm.audiosource.loop = false; ; //instead of Stop(), just turn loop off in case it's on } else if (bm.precise_freq == 0) { //looped beeps //disable looped sounds during chatter if ((disable_beeps_during_chatter && (initial_chatter.isPlaying || response_chatter.isPlaying)) || sstv.isPlaying) { bm.audiosource.Stop(); } else { bm.audiosource.loop = true; if (bm.audiosource.isPlaying == false) { bm.audiosource.Play(); SetAppLauncherButtonTexture(chatterer_button_SSTV); } } } else { //timed beeps if (bm.audiosource.loop) { //if looping stop playing and set loop to off bm.audiosource.Stop(); bm.audiosource.loop = false; } //then check the time bm.timer += Time.deltaTime; if (bm.timer > bm.precise_freq) { bm.timer = 0; //randomize beep if set to random (0) if (bm.randomizeBeep) { bm.current_clip = "Random"; set_beep_clip(bm); } //play beep unless disable == true && exchange_playing == true if (sstv.isPlaying || ((initial_chatter.isPlaying || response_chatter.isPlaying) && disable_beeps_during_chatter)) return; //no beep under these conditions else { //if (debugging) Debug.Log("[CHATR] timer limit reached, playing source " + bm.beep_name); bm.audiosource.Play(); //else beep SetAppLauncherButtonTexture(chatterer_button_SSTV); } } } } else { //imprecise beeps // // // //play a beep //roll a new loose limit if (bm.loose_freq == 0) { //beeps turned off at slider //bm.audiosource.Stop(); //squashed bug: this was breaking the one-time play button bm.audiosource.loop = false; ; //instead of Stop(), just turn loop off in case it's on } else { bm.timer += Time.deltaTime; if (bm.timer > bm.loose_timer_limit) { bm.timer = 0; //reset timer new_beep_loose_timer_limit(bm); //set a new loose limit //randomize beep if set to random (0) if (bm.randomizeBeep) { bm.current_clip = "Random"; set_beep_clip(bm); } if (sstv.isPlaying || ((initial_chatter.isPlaying || response_chatter.isPlaying) && disable_beeps_during_chatter)) return; //no beep under these conditions else { bm.audiosource.Play(); //else beep SetAppLauncherButtonTexture(chatterer_button_SSTV); } } } } } } } //END BEEPS ///////////////////////////////////////////// ///////////////////////////////////////////// //START CHATTER //do chatter if (chatter_exists) { if (vessel.GetCrewCount() > 0) { //Has crew onboard //do insta-chatter if chatter is off if (insta_chatter_key_just_changed == false && Input.GetKeyDown(insta_chatter_key) && exchange_playing == false && sstv.isPlaying == false) { //no chatter or sstv playing, play insta-chatter if (debugging) Debug.Log("[CHATR] beginning exchange,insta-chatter"); begin_exchange(0); } //exchange_playing check added because insta-chatter response was blocked when chatter is turned off if (chatter_freq > 0 || exchange_playing) { //Chatter is on //consume_resources(); if (exchange_playing) { //Exchange in progress if (initial_chatter.isPlaying == false) { //initial chatter has finished playing //wait some seconds and respond secs_since_initial_chatter += Time.deltaTime; if (secs_since_initial_chatter > response_delay_secs) { //if (debugging) Debug.Log("[CHATR] response delay has elapsed..."); if (response_chatter.isPlaying == false) { //play response clip if not already playing //print("response not currently playing..."); if (response_chatter_started) { //has started flag is tripped but no chatter playing //response has ended if (debugging) Debug.Log("[CHATR] response has finished"); exchange_playing = false; response_chatter_started = false; return; } if (response_chatter_set.Count > 0 && (remotetech_toggle == false || (remotetech_toggle == true && inRadioContact))) { if (debugging) Debug.Log("[CHATR] playing response"); response_chatter_started = true; if (initial_chatter_source == 1 && quindar_toggle) { quindar1.Play(); //print("playing response first quindar"); response_chatter.PlayDelayed(quindar1.clip.length); //print("playing response chatter"); quindar2.PlayDelayed(quindar1.clip.length + response_chatter.clip.length); //print("playing response second quindar"); } else response_chatter.Play(); } else if (response_chatter_set.Count > 0 && remotetech_toggle == true && !inRadioContact) { if (exchange_playing == true) { if (debugging) Debug.Log("[CHATR] No connection, no response ... you are alone !"); exchange_playing = false; } } else { if (debugging) Debug.LogWarning("[CHATR] response_chatter_set has no audioclips, abandoning exchange"); exchange_playing = false; //exchange is over } } } } } else { //No exchange currently playing secs_since_last_exchange += Time.deltaTime; if (secs_since_last_exchange > secs_between_exchanges && sstv.isPlaying == false) { if (debugging) Debug.Log("[CHATR] beginning exchange,auto"); begin_exchange(0); } if (vessel.parts.Count != vessel_part_count || vessel_prev_stage != vessel.currentStage && sstv.isPlaying == false) { //IMPROVE this so it doesn't chatter every vessel switch //part count or stage has changed if (debugging) Debug.Log("[CHATR] beginning exchange,parts/staging"); pod_begins_exchange = true; begin_exchange(rand.Next(0, 3)); //delay Play for 0-2 seconds for randomness } if (vessel.vesselType != VesselType.EVA && vessel.situation != vessel_prev_sit && sstv.isPlaying == false) { //situation (lander, orbiting, etc) has changed if (debugging) Debug.Log("[CHATR] beginning exchange,event::prev = " + vessel_prev_sit + " ::new = " + vessel.situation.ToString()); pod_begins_exchange = true; begin_exchange(rand.Next(0, 3)); //delay Play for 0-2 seconds for randomness } } } } } vessel_prev_sit = vessel.situation; vessel_prev_stage = vessel.currentStage; vessel_part_count = vessel.parts.Count; } else { //FlightGlobals.ActiveVessel is null if (gui_running) stop_GUI(); } }
protected override bool Generate() { //ISRU fails generation on duplicates, so we can't have many out at once. int totalContracts = ContractSystem.Instance.GetCurrentContracts <ISRUContract>().Count(); if (totalContracts >= FPConfig.ISRU.MaximumExistent) { return(false); } if (TechUnlocked() == false) { return(false); } System.Random generator = new System.Random(this.MissionSeed); List <CelestialBody> bodies = GetBodies_Reached(false, true); if (bodies.Count == 0) { return(false); } while (true) { targetBody = bodies[generator.Next(0, bodies.Count)]; if (CelestialIsForbidden(targetBody)) { bodies.Remove(targetBody); if (bodies.Count == 0) { return(false); } continue; } else { break; } } float fundsMultiplier = 1; float scienceMultiplier = 1; float reputationMultiplier = 1; switch (this.prestige) { case ContractPrestige.Trivial: gatherGoal = FPConfig.ISRU.TrivialExtractAmount; if (generator.Next(0, 100) < FPConfig.ISRU.TrivialDeliveryChance) { deliveryBody = Util.RandomNeighbor(MissionSeed, targetBody, false); isDelivering = true; } break; case ContractPrestige.Significant: gatherGoal = FPConfig.ISRU.SignificantExtractAmount; fundsMultiplier = FPConfig.ISRU.Funds.SignificantMultiplier; scienceMultiplier = FPConfig.ISRU.Science.SignificantMultiplier; reputationMultiplier = FPConfig.ISRU.Reputation.SignificantMultiplier; if (generator.Next(0, 100) < FPConfig.ISRU.SignificantDeliveryChance) { deliveryBody = Util.RandomNeighbor(MissionSeed, targetBody, false); isDelivering = true; } break; case ContractPrestige.Exceptional: gatherGoal = FPConfig.ISRU.ExceptionalExtractAmount; fundsMultiplier = FPConfig.ISRU.Funds.ExceptionalMultiplier; scienceMultiplier = FPConfig.ISRU.Science.ExceptionalMultiplier; reputationMultiplier = FPConfig.ISRU.Reputation.ExceptionalMultiplier; if (generator.Next(0, 100) < FPConfig.ISRU.ExceptionalDeliveryChance) { deliveryBody = Util.RandomNeighbor(MissionSeed, targetBody, false); isDelivering = true; } break; } if (deliveryBody == null) { isDelivering = false; } targetResource = ChooseResource(); if (isDelivering) { fundsMultiplier *= FPConfig.ISRU.Funds.DeliveryMultiplier; scienceMultiplier *= FPConfig.ISRU.Science.DeliveryMultiplier; reputationMultiplier *= FPConfig.ISRU.Reputation.DeliveryMultiplier; } //Spice this up just a tad, to make contracts more varied. float wobble = (float)generator.NextDouble() * 0.25f; if (generator.Next(0, 100) > 50) { wobble = 1 + wobble; } else { wobble = 1 - wobble; } fundsMultiplier *= wobble; scienceMultiplier *= wobble; reputationMultiplier *= wobble; gatherGoal *= wobble; gatherGoal = Mathf.Round(gatherGoal / 50) * 50; this.AddParameter(new ResourceExtractionParameter(targetResource, gatherGoal, targetBody), null); if (isDelivering) { deliverySituation = Util.ApplicableSituation(MissionSeed, deliveryBody, false); this.AddParameter(new ResourcePossessionParameter(targetResource, gatherGoal), null); this.AddParameter(new LocationAndSituationParameter(deliveryBody, deliverySituation, targetResource), null); this.AddParameter(new KillControlsParameter(10), null); } base.AddKeywords(new string[] { "ISRU" }); base.SetExpiry(FPConfig.ISRU.Expire.MinimumExpireDays, FPConfig.ISRU.Expire.MaximumExpireDays); base.SetDeadlineDays(FPConfig.ISRU.Expire.DeadlineDays, targetBody); base.SetFunds(Mathf.Round(FPConfig.ISRU.Funds.BaseAdvance * fundsMultiplier), Mathf.Round(FPConfig.ISRU.Funds.BaseReward * fundsMultiplier), Mathf.Round(FPConfig.ISRU.Funds.BaseFailure * fundsMultiplier), targetBody); base.SetScience(Mathf.Round(FPConfig.ISRU.Science.BaseReward * scienceMultiplier), targetBody); base.SetReputation(Mathf.Round(FPConfig.ISRU.Reputation.BaseReward * reputationMultiplier), Mathf.Round(FPConfig.ISRU.Reputation.BaseFailure * reputationMultiplier), targetBody); //Prevent duplicate contracts shortly before finishing up. foreach (ISRUContract active in ContractSystem.Instance.GetCurrentContracts <ISRUContract>()) { if (active.targetBody == this.targetBody) { return(false); } } return(true); }
private void SwitchToSituation(Vessel.Situations situation) { SwitchSituation(situation, situation); }
internal static string SituationEligible(Vessel vessel) { Vessel.Situations situation = vessel.situation; switch (situation) { case Vessel.Situations.LANDED: if (!HighLogic.CurrentGame.Parameters.CustomParams <OptionsB>().yesLanded) { return(Localizer.Format("#SimpleLogistics_msgSituation", Localizer.Format("#SimpleLogistics_Landed"))); } break; case Vessel.Situations.PRELAUNCH: if (!HighLogic.CurrentGame.Parameters.CustomParams <OptionsB>().yesPreLaunch) { return(Localizer.Format("#SimpleLogistics_msgSituation", Localizer.Format("#SimpleLogistics_PreLaunch"))); } break; case Vessel.Situations.SPLASHED: if (!HighLogic.CurrentGame.Parameters.CustomParams <OptionsB>().yesSplashed) { return(Localizer.Format("#SimpleLogistics_msgSituation", Localizer.Format("#SimpleLogistics_Splashed"))); } break; case Vessel.Situations.ORBITING: if (!HighLogic.CurrentGame.Parameters.CustomParams <OptionsB>().yesOrbiting) { return(Localizer.Format("#SimpleLogistics_msgSituation", Localizer.Format("#SimpleLogistics_Orbiting"))); } break; case Vessel.Situations.FLYING: if (!HighLogic.CurrentGame.Parameters.CustomParams <OptionsB>().yesFlying) { return(Localizer.Format("#SimpleLogistics_msgSituation", Localizer.Format("#SimpleLogistics_Flying"))); } break; case Vessel.Situations.SUB_ORBITAL: if (!HighLogic.CurrentGame.Parameters.CustomParams <OptionsB>().yesSubOrbital) { return(Localizer.Format("#SimpleLogistics_msgSituation", Localizer.Format("#SimpleLogistics_SubOrbital"))); } break; case Vessel.Situations.ESCAPING: if (!HighLogic.CurrentGame.Parameters.CustomParams <OptionsB>().yesEscaping) { return(Localizer.Format("#SimpleLogistics_msgSituation", Localizer.Format("#SimpleLogistics_Escaping"))); } break; case Vessel.Situations.DOCKED: if (!HighLogic.CurrentGame.Parameters.CustomParams <OptionsB>().yesLanded) { return(Localizer.Format("#SimpleLogistics_msgSituation", Localizer.Format("#SimpleLogistics_Docked"))); } break; } return(String.Empty); }
public override bool Load(ConfigNode configNode) { // Load base class bool valid = base.Load(configNode); valid &= ConfigNodeUtil.ParseValue <Vessel.Situations>(configNode, "situation", x => situation = x, this, Vessel.Situations.ORBITING, ValidateSituations); valid &= ConfigNodeUtil.ParseValue <double>(configNode, "minAltitude", x => minAltitude = x, this, 0.0, x => Validation.GE(x, 0.0)); valid &= ConfigNodeUtil.ParseValue <double>(configNode, "maxAltitude", x => maxAltitude = x, this, double.MaxValue, x => Validation.GE(x, 0.0)); valid &= ConfigNodeUtil.ParseValue <double>(configNode, "minApA", x => minApoapsis = x, this, 0.0, x => Validation.GE(x, 0.0)); valid &= ConfigNodeUtil.ParseValue <double>(configNode, "maxApA", x => maxApoapsis = x, this, double.MaxValue, x => Validation.GE(x, 0.0)); valid &= ConfigNodeUtil.ParseValue <double>(configNode, "minPeA", x => minPeriapsis = x, this, 0.0, x => Validation.GE(x, 0.0)); valid &= ConfigNodeUtil.ParseValue <double>(configNode, "maxPeA", x => maxPeriapsis = x, this, double.MaxValue, x => Validation.GE(x, 0.0)); valid &= ConfigNodeUtil.ParseValue <double>(configNode, "minEccentricity", x => minEccentricity = x, this, 0.0, x => Validation.GE(x, 0.0)); valid &= ConfigNodeUtil.ParseValue <double>(configNode, "maxEccentricity", x => maxEccentricity = x, this, double.MaxValue, x => Validation.GE(x, 0.0)); valid &= ConfigNodeUtil.ParseValue <double>(configNode, "minInclination", x => minInclination = x, this, 0.0, x => Validation.Between(x, 0.0, 180.0)); valid &= ConfigNodeUtil.ParseValue <double>(configNode, "maxInclination", x => maxInclination = x, this, 180.0, x => Validation.Between(x, 0.0, 180.0)); valid &= ConfigNodeUtil.ParseValue <double>(configNode, "minArgumentOfPeriapsis", x => minArgumentOfPeriapsis = x, this, 0.0, x => Validation.Between(x, 0.0, 360.0)); valid &= ConfigNodeUtil.ParseValue <double>(configNode, "maxArgumentOfPeriapsis", x => maxArgumentOfPeriapsis = x, this, 360.0, x => Validation.Between(x, 0.0, 360.0)); valid &= ConfigNodeUtil.ParseValue <Duration>(configNode, "minPeriod", x => minPeriod = x, this, new Duration(0.0)); valid &= ConfigNodeUtil.ParseValue <Duration>(configNode, "maxPeriod", x => maxPeriod = x, this, new Duration(double.MaxValue)); // Validate target body valid &= ValidateTargetBody(configNode); // Validation minimum and groupings valid &= ConfigNodeUtil.AtLeastOne(configNode, new string[] { "minAltitude", "maxAltitude", "minApA", "maxApA", "minPeA", "maxPeA", "minEccentricity", "maxEccentricity", "minInclination", "maxInclination", "minPeriod", "maxPeriod", "minArgumentOfPeriapsis", "maxArgumentOfPeriapsis" }, this); valid &= ConfigNodeUtil.MutuallyExclusive(configNode, new string[] { "minAltitude", "maxAltitude" }, new string[] { "minApA", "maxApA", "minPeA", "maxPeA" }, this); return(valid); }
/// <summary> /// Draws a playlist viewer and editor GUI. /// </summary> /// <param name="windowID"></param> public void PlaylistGui(int windowID) { _playlistScrollPosition = GUILayout.BeginScrollView(_playlistScrollPosition, GUILayout.MinHeight(Screen.height / 1.25f)); SoundtrackEditor sted = SoundtrackEditor.Instance; List<Playlist> playlists = sted.Playlists; for (int i = 0; i < playlists.Count; i++) { string playlistName = playlists[i].name; GUILayout.BeginHorizontal(); if (!_expandedPlaylists.ContainsKey(playlistName)) _expandedPlaylists.Add(playlistName, false); bool isExpanded = _expandedPlaylists[playlistName]; if (GUILayout.Button(isExpanded ? " - " : " + ")) _expandedPlaylists[playlistName] = !isExpanded; GUILayout.Label("<b>" + playlistName + (sted.CurrentPlaylist == playlists[i] ? " â–º" : "") + " </b>"); GUILayout.FlexibleSpace(); if (GUILayout.Button("Edit")) { _editorGuiVisible = true; _editingPlaylistOriginal = playlists[i]; _editingPlaylist = new Playlist(playlists[i]); _previousSituation = playlists[i].playWhen.situation; _previousCameraMode = playlists[i].playWhen.cameraMode; _previousScene = playlists[i].playWhen.scene; } GUILayout.EndHorizontal(); if (_expandedPlaylists[playlistName]) { for (int j = 0; j < playlists[i].tracks.Count; j++) { string prefix = sted.CurrentPlaylist != null && sted.CurrentPlaylist.name == playlists[i].name && sted.CurrentClip != null && sted.CurrentClip.name == playlists[i].tracks[j] ? " â–º " : " "; // Indent. The 'â–º' is very wide in KSP's font. GUILayout.Label(prefix + playlists[i].tracks[j]); } } } GUILayout.EndScrollView(); GUILayout.BeginHorizontal(); if (GUILayout.Button(" New ")) { _editingPlaylist = new Playlist(); _editorGuiVisible = true; } GUILayout.EndHorizontal(); // Close button GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button(" Close ")) _playlistGuiVisible = false; GUILayout.EndHorizontal(); GUI.DragWindow(); }
public static void LoadNode(ConfigNode node, string nameOfClass, string nameOfValue, ref Vessel.Situations situation, Vessel.Situations defaultSituation) { bool hasValue = node.HasValue(nameOfValue); bool parsed = false; if (hasValue) { int loadedSituationInteger = 0; parsed = int.TryParse(node.GetValue(nameOfValue), out loadedSituationInteger); situation = (Vessel.Situations)loadedSituationInteger; } if (!hasValue || !parsed) { switch (defaultSituation) { case Vessel.Situations.PRELAUNCH: Debug.LogWarning("Fine Print" + nameOfClass + " failed to load " + nameOfValue + ", initializing with default of PRELAUNCH!"); break; case Vessel.Situations.SPLASHED: Debug.LogWarning("Fine Print" + nameOfClass + " failed to load " + nameOfValue + ", initializing with default of SPLASHED!"); break; case Vessel.Situations.SUB_ORBITAL: Debug.LogWarning("Fine Print" + nameOfClass + " failed to load " + nameOfValue + ", initializing with default of SUB_ORBITAL!"); break; case Vessel.Situations.ORBITING: Debug.LogWarning("Fine Print" + nameOfClass + " failed to load " + nameOfValue + ", initializing with default of ORBITING!"); break; case Vessel.Situations.LANDED: Debug.LogWarning("Fine Print" + nameOfClass + " failed to load " + nameOfValue + ", initializing with default of LANDED!"); break; case Vessel.Situations.FLYING: Debug.LogWarning("Fine Print" + nameOfClass + " failed to load " + nameOfValue + ", initializing with default of FLYING!"); break; case Vessel.Situations.ESCAPING: Debug.LogWarning("Fine Print" + nameOfClass + " failed to load " + nameOfValue + ", initializing with default of ESCAPING!"); break; case Vessel.Situations.DOCKED: Debug.LogWarning("Fine Print" + nameOfClass + " failed to load " + nameOfValue + ", initializing with default of DOCKED!"); break; default: Debug.LogWarning("Fine Print" + nameOfClass + " failed to load " + nameOfValue + ", initializing with default of UNKNOWN!"); break; } situation = defaultSituation; resetBoard(); } }
public void LateUpdate() { if (display == null) { return; } if (FlightGlobals.ActiveVessel == null) { return; } FlightGlobals.SpeedDisplayModes mode = FlightGlobals.speedDisplayMode; #region all VesselTypes and Situations //VesselType.Base; //Situations.LANDED //VesselType.Debris //Situations.SPLASHED //VesselType.EVA //Situations.PRELAUNCH //VesselType.Flag //Situations.FLYING //VesselType.Lander //Situations.SUB_ORBITAL //VesselType.Plane; //Situations.ORBITING //VesselType.Probe //Situations.ESCAPING //VesselType.Relay //Situations.DOCKED //VesselType.Rover //VesselType.Ship //VesselType.SpaceObject //VesselType.Station //VesselType.Unknown #endregion switch (mode) { case FlightGlobals.SpeedDisplayModes.Surface: string titleText; Vessel.Situations situation = FlightGlobals.ActiveVessel.situation; VesselType vesselType = FlightGlobals.ActiveVessel.vesselType; double spd = FlightGlobals.ship_srfSpeed; string srfSpeedText = spd.ToString("F1") + mps; switch (vesselType) { case VesselType.Plane: case VesselType.Rover: // Boat or Submarine if (situation == Vessel.Situations.SPLASHED) { // Submarine if (FlightGlobals.ActiveVessel.altitude < BoatSubmarineBorderAlt && settings.radar) { titleText = Surf3 + Formatter.Distance_short(AGL()) + " " + (spd * kn_ms).ToString("F1") + kn; } // Boat else { titleText = Surf5 + (spd * kn_ms).ToString("F1") + knots; } } // Plane (not LANDED) else if (vesselType == VesselType.Plane && situation != Vessel.Situations.LANDED && situation != Vessel.Situations.PRELAUNCH) { bool isATM = FlightGlobals.ActiveVessel.atmDensity > 0.0; double speedIAS = FlightGlobals.ActiveVessel.indicatedAirSpeed; if (settings.radar) { double radar = FlightGlobals.ActiveVessel.radarAltitude; if (settings.mach) { if (isATM) { titleText = Surf3 + Formatter.Distance_short(radar) + " " + Localizer.Format("#SpeedUnitAnnex_mach", FlightGlobals.ActiveVessel.mach.ToString("F1")); } else { titleText = Surf5 + Formatter.Distance_long(radar); } } else { titleText = Surf3 + Formatter.Distance_short(radar) + " " + (spd * kn_ms).ToString("F1") + kn; } } else { if (settings.mach) { if (isATM) { titleText = Surf5 + Localizer.Format("#SpeedUnitAnnex_mach", FlightGlobals.ActiveVessel.mach.ToString("F1")); } else { titleText = Surface; } } else { titleText = Surf5 + (spd * kn_ms).ToString("F1") + knots; } } if (settings.ias && speedIAS > 0) { srfSpeedText += " " + speedIAS.ToString("F1"); } } // Rover (and LANDED Plane) // and rover-carrier if ksp detect them as rover else { if (settings.kmph) { titleText = Surf5 + (spd * kmph_ms).ToString("F1") + kmph; } else { titleText = Surf5 + (spd * mph_ms).ToString("F1") + mph; } } // All mistake at ksp detecting vessel type can be fixed by // some additional checking (ex. altitude for rover-carrier) // but it make unclear to user, which values is showed up. break; case VesselType.EVA: titleText = Surf3 + (settings.radar?RadarAltitudeEVA_str():"") + FinalName; break; case VesselType.Flag: titleText = Surf3 + FinalName; break; // Other: Rocket, Lander, Base etc default: if (settings.radar) { titleText = Surf5 + Formatter.Distance_long(RadarAltitude()); } else { titleText = Surface; } break; } display.textTitle.text = titleText; display.textSpeed.text = srfSpeedText; break; case FlightGlobals.SpeedDisplayModes.Orbit: if (FlightGlobals.ActiveVessel.vesselType == VesselType.EVA && settings.orbit_EVA) { display.textTitle.text = (settings.orbit_time ? "" : Orb) + FinalName; } else { double SOI_MASL = FlightGlobals.getMainBody().sphereOfInfluence - FlightGlobals.getMainBody().Radius; bool Ap_ok = FlightGlobals.getMainBody().atmosphereDepth < FlightGlobals.ship_orbit.ApA && FlightGlobals.ship_orbit.ApA < SOI_MASL; bool Pe_ok = FlightGlobals.getMainBody().atmosphereDepth < FlightGlobals.ship_orbit.PeA && FlightGlobals.ship_orbit.PeA < SOI_MASL; string Ap = Formatter.Distance_k(FlightGlobals.ship_orbit.ApA); string Pe = Formatter.Distance_k(FlightGlobals.ship_orbit.PeA); string Apsises = String.Format("<color={0}>{1}</color> <color={2}>{3}</color>", Ap_ok ? "#00ff00ff" : "#00ff009f", Ap, Pe_ok ? "#00ff00ff" : "#00ff009f", Pe); if (settings.orbit_time) { string TimeApsis; bool Apsis_ok; if (FlightGlobals.ship_orbit.timeToAp < FlightGlobals.ship_orbit.timeToPe) { Apsis_ok = Ap_ok; TimeApsis = Formatter.Time(FlightGlobals.ship_orbit.timeToAp, Ap_pre); } else { Apsis_ok = Pe_ok; TimeApsis = Formatter.Time(FlightGlobals.ship_orbit.timeToPe, Pe_pre); } display.textTitle.text = String.Format("{0} <color={1}>{2}</color>", Apsises, Apsis_ok ? "#ffffffff" : "#ffffff9f", TimeApsis); } else { display.textTitle.text = Orb + Apsises; } } display.textSpeed.text = FlightGlobals.ship_obtSpeed.ToString("F1") + mps; break; case FlightGlobals.SpeedDisplayModes.Target: #region all Target // 1.5.1 // ITargetable -> CelestialBody; // FlightCoMTracker; // ModuleDockingNode; // PositionTarget; // Vessel; #endregion ITargetable obj = FlightGlobals.fetch.VesselTarget; if (obj == null) { display.textTitle.text = NoTrg; return; } string distanceToTarget = ""; if (settings.targetDistance) { distanceToTarget = CalcTargetDistance(obj); } if (Target != obj) { TargetName = CutName(Trg + distanceToTarget, GetTargetName(obj)); Target = obj; } display.textTitle.text = Trg + distanceToTarget + TargetName; if (FlightGlobals.ship_tgtSpeed < 0.195) { display.textSpeed.text = FlightGlobals.ship_tgtSpeed.ToString("F2") + mps; } else { display.textSpeed.text = FlightGlobals.ship_tgtSpeed.ToString("F1") + mps; } break; } // need to be there, for every tick. Doesn't work in the Start() or onSetSpeedMode() display.textTitle.alignment = TMPro.TextAlignmentOptions.MidlineLeft; }
/// <summary> /// Gets the repair requirements from the Failure module for display to the user /// </summary> /// <returns>A List of all repair requirements for attempting repair of the part</returns> public List <RepairRequirements> GetRepairRequirements() { if (!Failed) { return(null); } if (!TestFlightEnabled) { return(null); } if (repairConfig == null) { return(null); } List <RepairRequirements> requirements = new List <RepairRequirements>(); Vessel.Situations situation = this.vessel.situation; // In flight if (!repairConfig.canBeRepairedInFlight) { RepairRequirements requirement = new RepairRequirements(); requirement.requirementMessage = "Vessel must not be in flight"; if (situation == Vessel.Situations.DOCKED || situation == Vessel.Situations.LANDED || situation == Vessel.Situations.PRELAUNCH || situation == Vessel.Situations.SPLASHED) { requirement.requirementMet = true; } else { requirement.requirementMet = false; } requirements.Add(requirement); } // Splashed down if (!repairConfig.canBeRepairedOnSplashed) { RepairRequirements requirement = new RepairRequirements(); requirement.requirementMessage = "Vessel must not be in water"; if (situation == Vessel.Situations.SPLASHED) { requirement.requirementMet = false; } else { requirement.requirementMet = true; } requirements.Add(requirement); } // Requires EVA // TODO // Don't know how to do this yet // Remote repair if (!repairConfig.canBeRepairedByRemote) { RepairRequirements requirement = new RepairRequirements(); requirement.requirementMessage = "Vessel must not be under remote control"; if (this.vessel.GetCrewCount() <= 0) { requirement.requirementMet = false; } else { requirement.requirementMet = true; } requirements.Add(requirement); } // Replacement part if (repairConfig.replacementPart != "NONE") { RepairRequirements requirement = new RepairRequirements(); if (repairConfig.replacementPartOptional) { requirement.requirementMessage = "Having a replacement " + repairConfig.replacementPart + " on board would be a bonus"; requirement.optionalRequirement = true; requirement.repairBonus = repairConfig.replacementPartBonus; } else { requirement.requirementMessage = "Need a replacement " + repairConfig.replacementPart; } if (HasReplacementPart(repairConfig.replacementPart)) { requirement.requirementMet = true; } else { requirement.requirementMet = false; } requirements.Add(requirement); } return(requirements); }
public void set_situation(Vessel.Situations situation) { this.missionSituation = situation; }
public String GetScopeForSituationAndBody(Vessel.Situations situation, CelestialBody body) { return(GetScopeForSituationAndBody(situation.ToString(), body.GetName())); }
protected override void OnLoad(ConfigNode node) { base.OnLoad(node); title = node.GetValue("title"); situation = (Vessel.Situations)Enum.Parse(typeof(Vessel.Situations), node.GetValue("situation")); }
/* * (C) Copyright 2013, Taranis Elsu * CC BY-NC-SA 3.0 */ public void RebuildPartsLists(Vessel vessel, Dictionary<string, ResourceInfo> resources) { //Debug.Log("Rebuilding resource lists."); List<string> toDelete = new List<string>(); //Debug.Log("Rebuilding before toDelete."); foreach (KeyValuePair<string, ResourceInfo> resourceEntry in resources) { resourceEntry.Value.parts.RemoveAll(partInfo => !vessel.parts.Contains(partInfo.part)); if (resourceEntry.Value.parts.Count == 0) { toDelete.Add(resourceEntry.Key); } } //Debug.Log("Rebuilding before Remove."); foreach (string resource in toDelete) { resources.Remove(resource); } //Debug.Log("Rebuilding before vessel.parts."); foreach (Part part in vessel.parts) { foreach (PartResource resource in part.Resources) { //Debug.Log("Rebuilding resource.resourceName="+resource.resourceName); if (resources.ContainsKey(resource.resourceName)) { List<ResourcePartMap> resourceParts = resources[resource.resourceName].parts; ResourcePartMap partInfo = resourceParts.Find(info => info.part.Equals(part)); if (partInfo == null) { resourceParts.Add(new ResourcePartMap(resource, part)); } else { // Make sure we are still pointing at the right resource instance. This is a fix for compatibility with StretchyTanks. partInfo.resource = resource; } } else { ResourceInfo resourceInfo = new ResourceInfo(); resourceInfo.parts.Add(new ResourcePartMap(resource, part)); resources[resource.resourceName] = resourceInfo; } } } //Debug.Log("Rebuilding before vessel.parts.Count."); numberOfParts = vessel.parts.Count; currentVessel = vessel; vesselSituation = vessel.situation; //Debug.Log("Rebuilding rnumberOfParts=" + numberOfParts); //Debug.Log("Rebuilding currentVessel=" + currentVessel); //Debug.Log("Rebuilding vesselSituation=" + vesselSituation); //Debug.Log("Rebuilding done"); }
public override void OnUpdate() { if (vessel == FlightGlobals.ActiveVessel) { check_active_chatterer(); if (active_chatterer) { cfg_update_timer += Time.deltaTime; if (cfg_update_timer >= 5f) { write_settings(); cfg_update_timer = 0f; } if (gui_running == false) start_GUI(); if (vessel.GetCrewCapacity() == 0 && beep_freq != 61) //unmanned craft and beep freq is not OFF (61) { beep_timer += Time.deltaTime; if (beep_timer > beep_freq) { beep_timer = 0; all_beep_clips[current_beep_clip].Play(); } } else if (vessel.GetCrewCapacity() > 0) { if (key_just_changed && Input.GetKeyUp(insta_chatter_key)) key_just_changed = false; if (key_just_changed == false && Input.GetKeyDown(insta_chatter_key) && exchange_playing == false) { print("beginning exchange,insta-chatter"); begin_exchange(0); } if (vessel.GetCrewCount() > 0 && chatter_freq > 0) { if (exchange_playing == false) { secs_since_last_exchange += Time.deltaTime; if (secs_since_last_exchange > secs_between_exchanges) { print("beginning exchange,auto"); begin_exchange(0); } } } if (vessel.currentStage != vessel_prev_stage && exchange_playing == false) { print("beginning exchange,staging"); pod_begins_exchange = true; begin_exchange(Convert.ToUInt64(44100 * rand.Next(0, 3))); //delay Play for 0-2 seconds for randonmess } if (vessel.situation != vessel_prev_sit && exchange_playing == false) { //print("vessel.situation: " + vessel.situation.ToString() + " ::: vessel_prev_sit: " + vessel_prev_sit.ToString()); print("beginning exchange,event"); pod_begins_exchange = true; begin_exchange(Convert.ToUInt64(44100 * rand.Next(0, 3))); //delay Play for 0-2 seconds for randonmess } if (exchange_playing) { if (initial_chatter_set[initial_chatter_index].isPlaying == false) { secs_since_initial_chatter += Time.deltaTime; if (secs_since_initial_chatter > response_delay_secs) { print("response delay has elapsed..."); if (response_chatter_set[response_chatter_index].isPlaying == false) { //play response clip if not already playing response_chatter_set[response_chatter_index].Play(); print("playing response chatter..."); exchange_playing = false; } } } } } } if (vessel_prev_sit == Vessel.Situations.PRELAUNCH && vessel.situation != Vessel.Situations.PRELAUNCH) { print("beginning launch"); play_launch_clip(); } vessel_prev_sit = vessel.situation; vessel_prev_stage = vessel.currentStage; } }
public void LateUpdate() { if (display == null) { return; } if (FlightGlobals.ActiveVessel == null) { return; } if (settings == null) { settings = HighLogic.CurrentGame.Parameters.CustomParams <SpeedUnitAnnexSettings>(); } //Log("{0:F1}, {1:F1}={2:F1}, {3:F1}, {4:F1}={5:F1}", // FlightGlobals.ActiveVessel.heightFromTerrain == FlightGlobals.ship_altitude - FlightGlobals.ActiveVessel.terrainAltitude, // FlightGlobals.ActiveVessel.heightFromTerrain, FlightGlobals.ship_altitude - FlightGlobals.ActiveVessel.terrainAltitude, // FlightGlobals.ship_altitude == FlightGlobals.ActiveVessel.altitude, FlightGlobals.ship_altitude, FlightGlobals.ActiveVessel.altitude); FlightGlobals.SpeedDisplayModes mode = FlightGlobals.speedDisplayMode; #region all VesselTypes and Situations //VesselType.Base; //Situations.LANDED //VesselType.Debris //Situations.SPLASHED //VesselType.EVA //Situations.PRELAUNCH //VesselType.Flag //Situations.FLYING //VesselType.Lander //Situations.SUB_ORBITAL //VesselType.Plane; //Situations.ORBITING //VesselType.Probe //Situations.ESCAPING //VesselType.Relay //Situations.DOCKED //VesselType.Rover //VesselType.Ship //VesselType.SpaceObject //VesselType.Station //VesselType.Unknown #endregion switch (mode) { case FlightGlobals.SpeedDisplayModes.Surface: string titleText; Vessel.Situations situation = FlightGlobals.ActiveVessel.situation; VesselType vesselType = FlightGlobals.ActiveVessel.vesselType; double spd = FlightGlobals.ship_srfSpeed; string srfSpeedText = spd.ToString("F1") + mps_s; switch (vesselType) { case VesselType.Plane: case VesselType.Rover: // Boat or Submarine if (situation == Vessel.Situations.SPLASHED) { // Submarine if (FlightGlobals.ActiveVessel.altitude < BoatSubmarineBorderAlt && settings.radar) { titleText = Surf3 + Formatter.Distance_short(AGL()) + " " + (spd * knTOms).ToString("F1") + kn_s; } // Boat else { titleText = Surf5 + (spd * knTOms).ToString("F1") + knots_s; } } // Plane (not LANDED) else if (vesselType == VesselType.Plane && situation != Vessel.Situations.LANDED && situation != Vessel.Situations.PRELAUNCH) { bool isATM = FlightGlobals.ActiveVessel.atmDensity > 0.0; if (settings.radar) { double radar = FlightGlobals.ActiveVessel.radarAltitude; if (settings.aircraft == MachNum) { if (isATM) { titleText = Surf3 + Formatter.Distance_short(radar) + " " + Localizer.Format("#SpeedUnitAnnex_mach", FlightGlobals.ActiveVessel.mach.ToString("F1")); } else { titleText = Surf5 + Formatter.Distance_long(radar); } } else if (settings.aircraft == knots) { titleText = Surf3 + Formatter.Distance_short(radar) + " " + (spd * knTOms).ToString("F1") + kn_s; } else if (settings.aircraft == kmph) { titleText = Surf3 + Formatter.Distance_short(radar) + " " + (spd * kmphTOms).ToString("F1") + kmph_s; } else // settings.aircraft == mph { titleText = Surf3 + Formatter.Distance_short(radar) + " " + (spd * mphTOms).ToString("F1") + mph_s; } } else { if (settings.aircraft == MachNum) { if (isATM) { titleText = Surf5 + Localizer.Format("#SpeedUnitAnnex_mach", FlightGlobals.ActiveVessel.mach.ToString("F1")); } else { titleText = Surf_full; } } else if (settings.aircraft == knots) { titleText = Surf5 + (spd * knTOms).ToString("F1") + knots_s; } else if (settings.aircraft == kmph) { titleText = Surf5 + (spd * kmphTOms).ToString("F1") + kmph_s; } else // settings.aircraft == mph { titleText = Surf5 + (spd * mphTOms).ToString("F1") + mph_s; } } if (settings.ias) { double speedIAS = 0; if (isLoadedFAR) { speedIAS = FAR_ActiveVesselIAS(); } else { speedIAS = FlightGlobals.ActiveVessel.indicatedAirSpeed; } if (speedIAS > 0) { srfSpeedText += " " + speedIAS.ToString("F1"); } } } // Rover (and LANDED Plane) else { if (settings.rover == kmph) { titleText = Surf5 + (spd * kmphTOms).ToString("F1") + kmph_s; } else // settings.rover == mph { titleText = Surf5 + (spd * mphTOms).ToString("F1") + mph_s; } } break; case VesselType.EVA: titleText = Surf3 + (settings.radar ? RadarAltitudeEVA_str() : "") + FinalName; break; case VesselType.Flag: titleText = Surf3 + FinalName; break; // Other: Rocket, Lander, Base etc default: if (settings.radar) { titleText = Surf5 + Formatter.Distance_long(RadarAltitude()); } else { titleText = Surf_full; } break; } if (settings.color_vertical) { if (FlightGlobals.ship_verticalSpeed < -epsilon) { display.textSpeed.color = Color.red; } else { display.textSpeed.color = Color.green; } } if (settings.split_vertical) { srfSpeedText = String.Format("{0:F1} {1} {2:F1}", FlightGlobals.ActiveVessel.horizontalSrfSpeed, mps_s, FlightGlobals.ship_verticalSpeed ); } display.textTitle.text = titleText; display.textSpeed.text = srfSpeedText; break; case FlightGlobals.SpeedDisplayModes.Orbit: if (FlightGlobals.ActiveVessel.vesselType == VesselType.EVA && settings2.orbit_EVA) { display.textTitle.text = (settings2.orbit_ApPe && settings2.orbit_time ? "" : Orb) + FinalName; } else if (settings2.orbit_ApPe || settings2.orbit_time) { double SOI_MASL = FlightGlobals.getMainBody().sphereOfInfluence - FlightGlobals.getMainBody().Radius; bool Ap_ok = FlightGlobals.getMainBody().atmosphereDepth < FlightGlobals.ship_orbit.ApA && FlightGlobals.ship_orbit.ApA < SOI_MASL; bool Pe_ok = FlightGlobals.getMainBody().atmosphereDepth < FlightGlobals.ship_orbit.PeA && FlightGlobals.ship_orbit.PeA < SOI_MASL; if (settings2.orbit_ApPe) { string Ap = Formatter.Distance_k(FlightGlobals.ship_orbit.ApA); string Pe = Formatter.Distance_k(FlightGlobals.ship_orbit.PeA); string Apsises = String.Format("<color={0}>{1}</color> <color={2}>{3}</color>", Ap_ok ? "#00ff00ff" : "#00ff009f", Ap, Pe_ok ? "#00ff00ff" : "#00ff009f", Pe); string TimeApsis; bool Apsis_ok; if (settings2.orbit_time) { if (FlightGlobals.ship_orbit.timeToAp < FlightGlobals.ship_orbit.timeToPe) { Apsis_ok = Ap_ok; TimeApsis = Formatter.Time(FlightGlobals.ship_orbit.timeToAp, A_prefix); } else { Apsis_ok = Pe_ok; TimeApsis = Formatter.Time(FlightGlobals.ship_orbit.timeToPe, P_prefix); } display.textTitle.text = String.Format("{0} <color={1}>{2}</color>", Apsises, Apsis_ok ? "#ffffffff" : "#ffffff9f", TimeApsis); } else { display.textTitle.text = Orb + Apsises; } } else if (settings2.orbit_time) { string TimeApsis; bool Apsis_ok; if (FlightGlobals.ship_orbit.timeToAp < FlightGlobals.ship_orbit.timeToPe) { Apsis_ok = Ap_ok; TimeApsis = Formatter.TimeLong(FlightGlobals.ship_orbit.timeToAp, ApT_prefix); } else { Apsis_ok = Pe_ok; TimeApsis = Formatter.TimeLong(FlightGlobals.ship_orbit.timeToPe, PeT_prefix); } display.textTitle.text = String.Format("<color={0}>{1}</color>", Apsis_ok ? "#00ff00ff" : "#00ff009f", TimeApsis); } } else { display.textTitle.text = Orb_full; } display.textSpeed.text = FlightGlobals.ship_obtSpeed.ToString("F1") + mps_s; break; case FlightGlobals.SpeedDisplayModes.Target: #region all Target // 1.6.0 // ITargetable: // * CelestialBody // * FlightCoMTracker // * ModuleDockingNode // * PositionTarget: // * DirectionTarget // * Vessel #endregion ITargetable obj = FlightGlobals.fetch.VesselTarget; if (obj == null) { display.textTitle.text = NoTrg; return; } bool isMDN = obj is ModuleDockingNode; if (settings2.targetAngles && isMDN) { Vector3 angles = GetOrientationDeviation(obj); if (settings2.targetInteger) { display.textTitle.text = Trg + Formatter.Angle(angles.x, true, 5) + Formatter.Angle(angles.y, true, 5) + Formatter.Angle(angles.z, true, 5); } else { display.textTitle.text = Formatter.Angle(angles.x) + Formatter.Angle(angles.y) + Formatter.Angle(angles.z); } } else { string TargetAngle = ""; string distanceToTarget = ""; if (settings2.targetAngle && isMDN) { Vector3 angles = GetOrientationDeviation(obj); if (settings2.targetInteger) { TargetAngle = Formatter.Angle(angles.z, true, 5); } else { TargetAngle = Formatter.Angle(angles.z); } } if (settings2.targetDistance) { distanceToTarget = CalcTargetDistance(obj); } bool isAngleAndDistance = settings2.targetDistance && settings2.targetAngle && isMDN; if (settings2.targetName && !isAngleAndDistance) { if (Target != obj) { TargetName = CutName(Trg + distanceToTarget + TargetAngle, GetTargetName(obj)); Target = obj; } display.textTitle.text = Trg + distanceToTarget + TargetName + TargetAngle; } else { display.textTitle.text = Trg + distanceToTarget + " " + TargetAngle; // 2 spaces } } if (FlightGlobals.ship_tgtSpeed < 0.195) { display.textSpeed.text = FlightGlobals.ship_tgtSpeed.ToString("F2") + mps_s; } else { display.textSpeed.text = FlightGlobals.ship_tgtSpeed.ToString("F1") + mps_s; } break; } // need to be there, for every tick. Doesn't work in the Start() or onSetSpeedMode() display.textTitle.alignment = TMPro.TextAlignmentOptions.MidlineLeft; }
public void Update() { if (transponder == null) { return; } Vessel vsl = transponder.vessel; name = vsl.vesselName; altitude = vsl.altitude; situation = vsl.situation; // Velocity/CoM stuff taken from MechJeb2 Vector3d CoM = Vector3d.zero; Vector3d obtVel = Vector3d.zero; double mass = 0; for (int i = 0; i < vsl.parts.Count; i++) { Part p = vsl.parts[i]; if (p.rb != null) { mass += p.rb.mass; CoM = CoM + (p.rb.worldCenterOfMass * p.rb.mass); obtVel += p.rb.velocity * p.rb.mass; } } CoM /= mass; if (vsl.packed) { obtVel = vsl.obt_velocity; } else { // XXX This could be a problem for non-active vessels... obtVel = obtVel / mass + Krakensbane.GetFrameVelocity () + vsl.orbit.GetRotFrameVel(vsl.orbit.referenceBody).xzy; } velocity = (obtVel - vsl.mainBody.getRFrmVel (CoM)).magnitude; }
private bool Landed(Vessel.Situations situationToCheck) { return(situationToCheck == Vessel.Situations.LANDED || situationToCheck == Vessel.Situations.SPLASHED); }
public static bool IsLandedOrSplashed(this Vessel.Situations situation) => (situation & (Vessel.Situations.LANDED | Vessel.Situations.SPLASHED)) != 0;
public ReachSituationCustom(Vessel.Situations situation, string title) : base() { this.title = title != null ? title : "Situation: " + ReachSituation.GetTitleStringShort(situation); this.situation = situation; }
protected override void OnParameterLoad(ConfigNode node) { try { base.OnParameterLoad(node); situation = ConfigNodeUtil.ParseValue<Vessel.Situations>(node, "situation", Vessel.Situations.ORBITING); minAltitude = ConfigNodeUtil.ParseValue<double>(node, "minAltitude"); maxAltitude = ConfigNodeUtil.ParseValue<double>(node, "maxAltitude", double.MaxValue); minApoapsis = ConfigNodeUtil.ParseValue<double>(node, "minApoapsis"); maxApoapsis = ConfigNodeUtil.ParseValue<double>(node, "maxApoapsis", double.MaxValue); minPeriapsis = ConfigNodeUtil.ParseValue<double>(node, "minPeriapsis"); maxPeriapsis = ConfigNodeUtil.ParseValue<double>(node, "maxPeriapsis", double.MaxValue); minEccentricity = ConfigNodeUtil.ParseValue<double>(node, "minEccentricity"); maxEccentricity = ConfigNodeUtil.ParseValue<double>(node, "maxEccentricity", double.MaxValue); minInclination = ConfigNodeUtil.ParseValue<double>(node, "minInclination"); maxInclination = ConfigNodeUtil.ParseValue<double>(node, "maxInclination", double.MaxValue); minPeriod = ConfigNodeUtil.ParseValue<double>(node, "minPeriod"); maxPeriod = ConfigNodeUtil.ParseValue<double>(node, "maxPeriod", double.MaxValue); targetBody = ConfigNodeUtil.ParseValue<CelestialBody>(node, "targetBody", (CelestialBody)null); displayNotes = ConfigNodeUtil.ParseValue<bool?>(node, "displayNotes", (bool?)false).Value; if (node.HasNode("ORBIT")) { orbit = new OrbitSnapshot(node.GetNode("ORBIT")).Load(); deviationWindow = ConfigNodeUtil.ParseValue<double>(node, "deviationWindow"); } CreateDelegates(); } finally { ParameterDelegate<Vessel>.OnDelegateContainerLoad(node); } }
public static void Update() { _update = false; if (FlightGlobals.ActiveVessel == null || FlightGlobals.ActiveVessel.targetObject == null || FlightGlobals.ActiveVessel.targetObject.GetOrbit() == null || FlightGlobals.ActiveVessel.targetObject.GetOrbit().referenceBody == null || FlightGlobals.ActiveVessel.orbit == null || FlightGlobals.ActiveVessel.orbit.referenceBody == null) { _updated = false; return; } _updated = true; Orbit active = _activeVessel.orbit; Orbit target = _targetObject.GetOrbit(); _trueShipOrbit = active; _showAngle = false; _showPhasing = false; _shipOrbit = null; _targetOrbit = null; if (active.referenceBody == target.referenceBody) { _shipOrbit = active; _targetOrbit = target; } else { if (active.referenceBody == Planetarium.fetch.Sun) { _shipOrbit = active; _targetOrbit = target; } else { _showAngle = true; } _showPhasing = true; DrillDownOrbits(active, target); } Vessel.Situations sit = _activeVessel.situation; if ((sit |= Vessel.Situations.LANDED | Vessel.Situations.SPLASHED | Vessel.Situations.PRELAUNCH) == 0) { _vesselIntersect = false; _bodyIntersect = false; } else { if (!_isVessel && !_isCelestial) { _vesselIntersect = false; _bodyIntersect = false; } else { OrbitTargeter oTargeter = _activeVessel.orbitTargeter; PatchedConicSolver solver = _activeVessel.patchedConicSolver; if (oTargeter == null || solver == null) { _vesselIntersect = false; _bodyIntersect = false; } else if (!MapView.MapIsEnabled) { if (_isVessel) { _bodyIntersect = false; Vessel tgt = _targetObject.GetVessel(); if (tgt == null || tgt.LandedOrSplashed) { _vesselIntersect = false; return; } Orbit _refPatch = null; if (solver.maneuverNodes.Count > 0) { _refPatch = GetReferencePatch(oTargeter, solver, target.referenceBody, null, true); } else { _refPatch = BasicOrbitReflection.GetRefPatch(oTargeter); } Orbit _tgtRefPatch = BasicOrbitReflection.GetTargetRefPatch(oTargeter); _vesselIntersect = GetClosestVessel(_refPatch, _tgtRefPatch); } else { _vesselIntersect = false; double Pe = GetLowestPeA(solver); if (Pe < BasicExtensions.AlmostMaxValue) { _closestDist = Pe; _bodyIntersect = true; } else { Orbit _refPatch = null; if (solver.maneuverNodes.Count > 0) { _refPatch = GetReferencePatch(oTargeter, solver, _targetBody, target.referenceBody, false); } else { _refPatch = BasicOrbitReflection.GetRefPatch(oTargeter); } if (_refPatch != null && _refPatch.closestTgtApprUT <= 0) { _bodyIntersect = false; return; } Orbit _tgtRefPatch = BasicOrbitReflection.GetTargetRefPatch(oTargeter); _bodyIntersect = GetClosestCelestial(_refPatch, _tgtRefPatch); } } } else { if (_markers == null || _markers.Count <= 0) { _markers = BasicOrbitReflection.GetOrbitMarkers(oTargeter); } if (_markers == null || _markers.Count <= 0) { _vesselIntersect = false; _bodyIntersect = false; } else if (_isVessel) { _bodyIntersect = false; if (solver.maneuverNodes.Count > 0) { Orbit _refPatch = GetReferencePatch(oTargeter, solver, target.referenceBody, null, true); Orbit _tgtRefPatch = BasicOrbitReflection.GetTargetRefPatch(oTargeter); _vesselIntersect = GetClosestVessel(_refPatch, _tgtRefPatch); } else { OrbitTargeter.ISectMarker _intersectOne = null; OrbitTargeter.ISectMarker _intersectTwo = null; for (int i = _markers.Count - 1; i >= 0; i--) { OrbitTargeter.Marker m = _markers[i]; if (m == null) { continue; } if (!(m is OrbitTargeter.ISectMarker)) { continue; } int num = ((OrbitTargeter.ISectMarker)m).num; if (num == 1) { _intersectOne = m as OrbitTargeter.ISectMarker; } else if (num == 2) { _intersectTwo = m as OrbitTargeter.ISectMarker; } } OrbitTargeter.ISectMarker _closestIntersect = null; if (_intersectOne != null && _intersectTwo != null) { _closestIntersect = _intersectOne.separation > _intersectTwo.separation ? _intersectTwo : _intersectOne; } else if (_intersectOne != null) { _closestIntersect = _intersectOne; } else if (_intersectTwo != null) { _closestIntersect = _intersectTwo; } else { _closestIntersect = null; } if (_closestIntersect == null) { _vesselIntersect = false; } else { _vesselIntersect = true; _closestDist = _closestIntersect.separation * 1000; _closestRelVel = _closestIntersect.relSpeed; _closestTime = _closestIntersect.UT; } } } else { _vesselIntersect = false; double Pe = GetLowestPeA(solver); if (Pe < BasicExtensions.AlmostMaxValue) { _closestDist = Pe; _bodyIntersect = true; } else { if (solver.maneuverNodes.Count > 0) { Orbit _refPatch = GetReferencePatch(oTargeter, solver, _targetBody, target.referenceBody, false); Orbit _tgtRefPatch = BasicOrbitReflection.GetTargetRefPatch(oTargeter); _bodyIntersect = GetClosestCelestial(_refPatch, _tgtRefPatch); } else { OrbitTargeter.ClApprMarker _approach = null; for (int i = _markers.Count - 1; i >= 0; i--) { OrbitTargeter.Marker m = _markers[i]; if (m == null) { continue; } if (!(m is OrbitTargeter.ClApprMarker)) { continue; } _approach = m as OrbitTargeter.ClApprMarker; } if (_approach == null) { _bodyIntersect = false; } else { _bodyIntersect = true; _closestDist = _approach.separation * 1000; _closestTime = (_approach.dT * -1) + Planetarium.GetUniversalTime(); } } } } } } } }
// call automation scripts and transfer data public void update(Vessel environment, double elapsed_s) { // do nothing if there is no EC left on the vessel resource_info ec = ResourceCache.Info(environment, "ElectricCharge"); if (ec.amount <= double.Epsilon) { return; } // get current states vessel_info vi = Cache.VesselInfo(environment); Vessel.Situations situation = environment.situation; bool sunlight = vi.sunlight > double.Epsilon; bool power = ec.level >= 0.15; //< 15% bool radiation = vi.radiation <= 0.00001388; //< 0.05 rad/h bool signal = vi.link.linked; // check for state changes and call scripts if (situation != prev_situation) { switch(situation) { case Vessel.Situations.LANDED: case Vessel.Situations.SPLASHED: execute("run", "auto/situation_landed", string.Empty, environment); break; case Vessel.Situations.FLYING: execute("run", "auto/situation_atmo", string.Empty, environment); break; case Vessel.Situations.ORBITING: case Vessel.Situations.SUB_ORBITAL: case Vessel.Situations.ESCAPING: execute("run", "auto/situation_space", string.Empty, environment); break; } } if (sunlight != prev_sunlight) { execute("run", sunlight ? "auto/sun_visible" : "auto/sun_occluded", string.Empty, environment); } if (power != prev_power) { execute("run", power ? "auto/power_nominal" : "auto/power_low", string.Empty, environment); } if (radiation != prev_radiation) { execute("run", radiation ? "auto/radiation_nominal" : "auto/radiation_high", string.Empty, environment); } if (signal != prev_signal) { execute("run", signal ? "auto/signal_linked" : "auto/signal_unlinked", string.Empty, environment); } // remember previous state prev_situation = situation; prev_sunlight = sunlight; prev_power = power; prev_signal = signal; prev_radiation = radiation; // create network devices boot_network(environment); // transmit all files flagged for transmission to their destination List<string> to_remove = new List<string>(); foreach(var pair in files) { // if file must be sent string filename = pair.Key; File file = pair.Value; if (file.send.Length > 0) { // get target File target; if (files.TryGetValue(file.send, out target)) { // target is alive, get it NetworkDevice nd = target.device as NetworkDevice; Computer remote_machine = DB.VesselData(nd.id()).computer; // zero-data files are transmitted instantly if (file.data <= double.Epsilon) { // add file to remote machine, overwrite as necessary if (remote_machine.files.ContainsKey(filename)) { remote_machine.files.Remove(filename); } remote_machine.files.Add(filename, new File(file.content)); // flag local file for removal to_remove.Add(filename); } // science data files are transmitted over time else { // TODO: [SCIENCE] send science data file // remember: subtract amount from file.value until it is zero, then remove the file if reach zero } } else { // the target doesn't exist, don't send but keep it in case it comes alive later } } } // delete local files flagged for removal foreach(string s in to_remove) files.Remove(s); // delete network devices cleanup(); }
public void Update() { //Insta-... key setup if (insta_chatter_key_just_changed && Input.GetKeyUp(insta_chatter_key)) insta_chatter_key_just_changed = false; if (insta_sstv_key_just_changed && Input.GetKeyUp(insta_sstv_key)) insta_sstv_key_just_changed = false; ////Icon relocation //if (changing_icon_pos && Input.GetMouseButtonDown(0)) //{ // ui_icon_pos = new Rect(Input.mousePosition.x - 15f, Screen.height - Input.mousePosition.y - 15f, 30f, 30f); // changing_icon_pos = false; //} mute_check(); radio_check(); if (FlightGlobals.ActiveVessel != null) { vessel = FlightGlobals.ActiveVessel; //set num_beep_pages for use in windows num_beep_pages = beepsource_list.Count / 10; if (beepsource_list.Count % 10 != 0) num_beep_pages++; prev_num_pages = num_beep_pages; //sample selector one-time play if (OTP_playing && OTP_source.audiosource.isPlaying == false) { if (debugging) Debug.Log("[CHATR] one-time play has finished"); OTP_playing = false; OTP_source.audiosource.clip = OTP_stored_clip; //if (debugging) Debug.Log("[CHATR] OTP_source.current_clip = " + OTP_source.current_clip); //set_beep_clip(OTP_source); } //RUN-ONCE if (run_once) { //get null refs trying to set these in Awake() so do them once here prev_vessel = vessel; vessel_prev_sit = vessel.situation; vessel_prev_stage = vessel.currentStage; vessel_part_count = vessel.parts.Count; run_once = false; if (use_vessel_settings) { if (debugging) Debug.Log("[CHATR] Update() run-once :: calling load_vessel_settings_node()"); load_vessel_settings_node(); //load and search for settings for this vessel if (debugging) Debug.Log("[CHATR] Update() run-once :: calling search_vessel_settings_node()"); search_vessel_settings_node(); } } if (vessel != prev_vessel) { //active vessel has changed if (debugging) Debug.Log("[CHATR] ActiveVessel has changed::prev = " + prev_vessel.vesselName + ", curr = " + vessel.vesselName); //stop_audio("all"); //play a new clip any time vessel changes and new vessel has crew or is EVA //if (((power_available && vessel.GetCrewCount() > 0) || vessel.vesselType == VesselType.EVA) && chatter_freq > 0) //{ //new active vessel has crew onboard or is EVA //play an auto clip //pod_begins_exchange = true; //begin_exchange(0); //} if (use_vessel_settings) { ConfigNode all_but_prev_vessel = new ConfigNode(); //if (debugging) Debug.Log("[CHATR] Update() :: checking each vessel_id in vessel_settings_node"); //if (debugging) Debug.Log("[CHATR] prev_vessel.id = " + prev_vessel.id.ToString()); foreach (ConfigNode _vessel in vessel_settings_node.nodes) { //search for previous vessel id if (_vessel.HasValue("vessel_id")) { string val = _vessel.GetValue("vessel_id"); //if (debugging) Debug.Log("[CHATR] node vessel_id = " + val); if (val != prev_vessel.id.ToString()) { //vessel_settings_node.RemoveNode(prev_vessel.id.ToString()); //if (debugging) Debug.Log("[CHATR] prev_vessel old node removed"); //temp_vessels_string = prev_vessel.id.ToString(); all_but_prev_vessel.AddNode(_vessel); //if (debugging) Debug.Log("[CHATR] Update() :: node vessel_id != prev_vessel.id :: node vessel added to all_but_prev_vessel"); } //else //{ // all_but_prev_vessel.AddNode(cn); //} } } //foreach (ConfigNode cn in vessel_settings_node.nodes) //{ //vessel_settings_node.RemoveNodes(""); // if (debugging) Debug.Log("[CHATR] old nodes removed"); //} vessel_settings_node = all_but_prev_vessel; //if (debugging) Debug.Log("[CHATR] Update() :: vessel_settings node = all_but_prev_vessel"); new_vessel_node(prev_vessel); //if (debugging) Debug.Log("[CHATR] Update() :: new node created using prev_vessel and added to vessel_settings node"); //save_vessel_settings_node(); vessel_settings_node.Save(settings_path + "vessels.cfg"); //if (debugging) Debug.Log("[CHATR] Update() :: vessel_settings node saved to vessel_settings.cfg"); load_vessel_settings_node(); //reload with current vessel settings search_vessel_settings_node(); //search for current vessel } vessel_prev_sit = vessel.situation; vessel_prev_stage = vessel.currentStage; //don't update vessel_part_count here! if (vessel != prev_vessel && prev_vessel.vesselType == VesselType.EVA && (vessel.vesselType == VesselType.Ship || vessel.vesselType == VesselType.Lander || vessel.vesselType == VesselType.Station || vessel.vesselType == VesselType.Base)) { if (aae_airlock_exist) { aae_airlock.Play(); if (debugging) Debug.Log("[CHATR] Returning from EVA, playing Airlock sound..."); } } // prev_vessel = vessel; //airlock sound //todo fix airlock sound here //sound plays after naut is already outside if (vessel != prev_vessel && vessel.vesselType == VesselType.EVA && (prev_vessel.vesselType == VesselType.Ship || prev_vessel.vesselType == VesselType.Lander || prev_vessel.vesselType == VesselType.Station || prev_vessel.vesselType == VesselType.Base)) { if (aae_airlock_exist) { aae_airlock.Play(); if (debugging) Debug.Log("[CHATR] Going on EVA, playing Airlock sound..."); } } prev_vessel = vessel; } if (gui_running == false) start_GUI(); //write settings every x seconds cfg_update_timer += Time.deltaTime; if (cfg_update_timer >= 7f) { cfg_update_timer = 0; //DEBUG //if (debugging) Debug.Log("[CHATR] searching all GameObjects for 'rbr'..."); //int x = 0; //var allSources = FindObjectsOfType(typeof(GameObject)) as GameObject[]; //foreach (var source in allSources) //{ // if (source.name.Length > 3) // { // if (source.name.Substring(0, 3) == "rbr") // { // if (debugging) Debug.Log("[CHATR] source.name = " + source.name); // x++; // } // } //} //if (debugging) Debug.Log("[CHATR] " + x.ToString() + " rbr GameObjects exist"); save_plugin_settings(); if (use_vessel_settings) write_vessel_settings(); //update vessel_settings.cfg //cfg_update_timer = 0; } //update remotetech info if needed if (remotetech_toggle) { rt_update_timer += Time.deltaTime; if (rt_update_timer > 2f) { updateRemoteTechData(); rt_update_timer = 0; } } //consume_resources(); //try to use a little ElectricCharge /////////////////////// /////////////////////// //Do AAE //if (AAE_exists) //{ //BACKGROUND if (aae_backgrounds_exist) { //if EVA, stop background audio if (vessel.vesselType == VesselType.EVA) { foreach (BackgroundSource src in backgroundsource_list) { src.audiosource.Stop(); } } else { //else play background audio foreach (BackgroundSource src in backgroundsource_list) { if (src.audiosource.isPlaying == false) { src.audiosource.loop = true; src.audiosource.Play(); } } } } //SOUNDSCAPE if (aae_soundscapes_exist) { if (aae_soundscape_freq == 0) { //turned off aae_soundscape.Stop(); } else if (aae_soundscape_freq == 4) { //don't play soundscapes when within kerbin atmo if (vessel.mainBody.bodyName != "Kerbin" || (vessel.mainBody.bodyName == "Kerbin" && (vessel.situation == Vessel.Situations.ORBITING || vessel.situation == Vessel.Situations.ESCAPING))) { //continuous loop of clips if (aae_soundscape.isPlaying == false) { if (debugging) Debug.Log("[CHATR] playing next soundscape clip in continuous loop..."); set_soundscape_clip(); aae_soundscape.Play(); } } } else { //don't play soundscapes when within kerbin atmo if (vessel.mainBody.bodyName != "Kerbin" || (vessel.mainBody.bodyName == "Kerbin" && (vessel.situation == Vessel.Situations.ORBITING || vessel.situation == Vessel.Situations.ESCAPING))) { //run timer until timer_limit is reached, then play a random clip if (aae_soundscape.isPlaying == false) { aae_soundscape_timer += Time.deltaTime; if (aae_soundscape_timer > aae_soundscape_timer_limit) { if (debugging) Debug.Log("[CHATR] soundscape1 timer limit reached, playing next clip..."); set_soundscape_clip(); aae_soundscape.Play(); aae_soundscape_timer = 0; //reset timer new_soundscape_loose_timer_limit(); //roll new timer limit } } } } } //EVA BREATHING if (aae_breathing_exist) { if (vessel.vesselType == VesselType.EVA && aae_breathing.isPlaying == false) { if (debugging) Debug.Log("[CHATR] breathingsource.Play() loop has started"); aae_breathing.Play(); } if (vessel.vesselType != VesselType.EVA && aae_breathing.isPlaying) { if (debugging) Debug.Log("[CHATR] No longer EVA, breathingsource.Stop()"); aae_breathing.Stop(); } } //WIND if (aae_wind_exist) { //check that body has atmosphere, vessel is within it if (vessel.mainBody.atmosphere && vessel.altitude < vessel.mainBody.maxAtmosphereAltitude) { //set volume according to atmosphere density aae_wind.volume = aae_wind_vol_slider * Math.Min((float)vessel.atmDensity, 1); //play the audio if not playing already if (aae_wind.isPlaying == false) { if (debugging) Debug.Log("[CHATR] aae_wind.Play()"); aae_wind.loop = true; aae_wind.Play(); } } else { //stop when out of atmosphere if (aae_wind.isPlaying) { if (debugging) Debug.Log("[CHATR] aae_wind.Stop()"); if (aae_wind.isPlaying) aae_wind.Stop(); } } } //add the suspenseful music track on loop //conditions? //vessel.situation == suborbital, true alt <= 10000m, descent speed > 10m/s if (vessel.situation == Vessel.Situations.SUB_ORBITAL && vessel.heightFromTerrain < 10000f && vessel.verticalSpeed < -10f) { //start suspense loop //todo add suspense loop //landingsource.loop = true; //landingsource.Play(); } //} //END AAE ///////////////////////////////////////////// ///////////////////////////////////////////// //START SSTV //do SSTV if (sstv_exists) { //insta-sstv activated if (insta_sstv_key_just_changed == false && Input.GetKeyDown(insta_sstv_key) && sstv.isPlaying == false) { if (debugging) Debug.Log("[CHATR] beginning exchange,insta-SSTV"); if (exchange_playing) { //stop and reset any currently playing chatter exchange_playing = false; initial_chatter.Stop(); response_chatter.Stop(); initialize_new_exchange(); } if (all_sstv_clips.Count > 0) { //get new clip, play it, set and get timers sstv.clip = all_sstv_clips[rand.Next(0, all_sstv_clips.Count)]; sstv.Play(); sstv_timer = 0; new_sstv_loose_timer_limit(); } else Debug.LogWarning("[CHATR] No SSTV clips to play"); } //timed sstv if (all_sstv_clips.Count > 0) { //if clips exist, do things if (sstv_freq > 0) { sstv_timer += Time.deltaTime; if (sstv_timer > sstv_timer_limit) { sstv_timer = 0; new_sstv_loose_timer_limit(); if (sstv.isPlaying == false) { //get a random one and play if (exchange_playing) { //stop and reset any currently playing chatter exchange_playing = false; initial_chatter.Stop(); response_chatter.Stop(); initialize_new_exchange(); } sstv.clip = all_sstv_clips[rand.Next(0, all_sstv_clips.Count)]; sstv.Play(); //sstv_timer = 0; //new_sstv_loose_timer_limit(); } } } } } //END SSTV ///////////////////////////////////////////// ///////////////////////////////////////////// //START BEEPS //do beeps if (beeps_exists) { if (dict_probe_samples.Count > 0 && OTP_playing == false) //don't do any beeps here while OTP is playing { foreach (BeepSource bm in beepsource_list) { if (bm.precise) { //precise beeps if (bm.precise_freq == -1) { //beeps turned off at slider //bm.audiosource.Stop(); //squashed bug: this was breaking the one-time play button bm.audiosource.loop = false; ; //instead of Stop(), just turn loop off in case it's on } else if (bm.precise_freq == 0) { //looped beeps //disable looped sounds during chatter if ((disable_beeps_during_chatter && (initial_chatter.isPlaying || response_chatter.isPlaying)) || sstv.isPlaying) { bm.audiosource.Stop(); } else { bm.audiosource.loop = true; if (bm.audiosource.isPlaying == false) bm.audiosource.Play(); } } else { //timed beeps if (bm.audiosource.loop) { //if looping stop playing and set loop to off bm.audiosource.Stop(); bm.audiosource.loop = false; } //then check the time bm.timer += Time.deltaTime; if (bm.timer > bm.precise_freq) { bm.timer = 0; //randomize beep if set to random (0) if (bm.current_clip == "Random") { //bm.audiosource.clip = all_beep_clips[rand.Next(0, all_beep_clips.Count)]; set_beep_clip(bm); } //play beep unless disable == true && exchange_playing == true if (sstv.isPlaying || ((initial_chatter.isPlaying || response_chatter.isPlaying) && disable_beeps_during_chatter)) return; //no beep under these conditions //if (disable_beeps_during_chatter == false || (disable_beeps_during_chatter == true && exchange_playing == false)) else { //if (debugging) Debug.Log("[CHATR] timer limit reached, playing source " + bm.beep_name); bm.audiosource.Play(); //else beep } } } } else { //imprecise beeps // // // //play a beep //roll a new loose limit if (bm.loose_freq == 0) { //beeps turned off at slider //bm.audiosource.Stop(); //squashed bug: this was breaking the one-time play button bm.audiosource.loop = false; ; //instead of Stop(), just turn loop off in case it's on } else { bm.timer += Time.deltaTime; if (bm.timer > bm.loose_timer_limit) { bm.timer = 0; //reset timer new_beep_loose_timer_limit(bm); //set a new loose limit //randomize beep if set to random (0) if (bm.current_clip == "Random") { //bm.audiosource.clip = all_beep_clips[rand.Next(0, all_beep_clips.Count)]; set_beep_clip(bm); } if (sstv.isPlaying || ((initial_chatter.isPlaying || response_chatter.isPlaying) && disable_beeps_during_chatter)) return; //no beep under these conditions //if (disable_beeps_during_chatter == false || (disable_beeps_during_chatter == true && exchange_playing == false) || sstv.isPlaying == false) else bm.audiosource.Play(); //else beep } } } } } } //END BEEPS ///////////////////////////////////////////// ///////////////////////////////////////////// //START CHATTER //do chatter if (chatter_exists) { if (vessel.GetCrewCount() > 0) { //Has crew onboard //do insta-chatter if chatter is off if (insta_chatter_key_just_changed == false && Input.GetKeyDown(insta_chatter_key) && exchange_playing == false && sstv.isPlaying == false) { //no chatter or sstv playing, play insta-chatter if (debugging) Debug.Log("[CHATR] beginning exchange,insta-chatter"); begin_exchange(0); } //exchange_playing check added because insta-chatter response was blocked when chatter is turned off if (chatter_freq > 0 || exchange_playing) { //Chatter is on //consume_resources(); if (exchange_playing) { //Exchange in progress if (initial_chatter.isPlaying == false) { //initial chatter has finished playing //wait some seconds and respond secs_since_initial_chatter += Time.deltaTime; if (secs_since_initial_chatter > response_delay_secs) { //if (debugging) Debug.Log("[CHATR] response delay has elapsed..."); if (response_chatter.isPlaying == false) { //play response clip if not already playing //print("response not currently playing..."); if (response_chatter_started) { //has started flag is tripped but no chatter playing //response has ended if (debugging) Debug.Log("[CHATR] response has finished"); exchange_playing = false; response_chatter_started = false; return; } if (response_chatter_set.Count > 0) { if (debugging) Debug.Log("[CHATR] playing response"); response_chatter_started = true; if (initial_chatter_source == 1 && quindar_toggle) { quindar1.Play(); //print("playing response first quindar"); response_chatter.PlayDelayed(quindar1.clip.length); //print("playing response chatter"); quindar2.PlayDelayed(quindar1.clip.length + response_chatter.clip.length); //print("playing response second quindar"); } else response_chatter.Play(); } else { if (debugging) Debug.LogWarning("[CHATR] response_chatter_set has no audioclips, abandoning exchange"); exchange_playing = false; //exchange is over } //print("playing response chatter..."); //exchange_playing = false; //exchange is over } } } } else { //No exchange currently playing secs_since_last_exchange += Time.deltaTime; if (secs_since_last_exchange > secs_between_exchanges && sstv.isPlaying == false) { if (debugging) Debug.Log("[CHATR] beginning exchange,auto"); begin_exchange(0); } if (vessel.parts.Count != vessel_part_count || vessel_prev_stage != vessel.currentStage && sstv.isPlaying == false) { //IMPROVE this so it doesn't chatter every vessel switch //part count or stage has changed if (debugging) Debug.Log("[CHATR] beginning exchange,parts/staging"); pod_begins_exchange = true; begin_exchange(rand.Next(0, 3)); //delay Play for 0-2 seconds for randomness } if (vessel.vesselType != VesselType.EVA && vessel.situation != vessel_prev_sit && sstv.isPlaying == false) { //situation (lander, orbiting, etc) has changed if (debugging) Debug.Log("[CHATR] beginning exchange,event::prev = " + vessel_prev_sit + " ::new = " + vessel.situation.ToString()); pod_begins_exchange = true; begin_exchange(rand.Next(0, 3)); //delay Play for 0-2 seconds for randomness } } } } } vessel_prev_sit = vessel.situation; vessel_prev_stage = vessel.currentStage; vessel_part_count = vessel.parts.Count; } else { //FlightGlobals.ActiveVessel is null if (gui_running) stop_GUI(); } }
void Awake() { this.Log("Awake"); configFilename = IOUtils.GetFilePathFor(this.GetType(), "FuelBalancer.cfg"); settings = new Settings(); settingsWindow = new SettingsWindow(settings); helpWindow = new HelpWindow(); mainWindow = new MainWindow(this, settings, settingsWindow, helpWindow); button = new ButtonWrapper(new Rect(Screen.width * 0.7f, 0, 32, 32), "ThunderAerospace/TacFuelBalancer/Textures/button", "FB", "TAC Fuel Balancer", OnIconClicked); resources = new Dictionary<string, ResourceInfo>(); numberOfParts = 0; vesselSituation = Vessel.Situations.PRELAUNCH; }
void OnVesselChange(Vessel data) { if (FlightGlobals.ActiveVessel != null) { vessel = FlightGlobals.ActiveVessel; if (prev_vessel != null) //prev_vessel = null on first flight load, so check this to avoid EXP throw { //active vessel has changed if (debugging) Debug.Log("[CHATR] OnVesselChange() :: prev = " + prev_vessel.vesselName + ", curr = " + vessel.vesselName); stop_audio("all"); if (use_vessel_settings) { ConfigNode all_but_prev_vessel = new ConfigNode(); if (debugging) Debug.Log("[CHATR] checking each vessel_id in vessel_settings_node"); if (debugging) Debug.Log("[CHATR] prev_vessel.id = " + prev_vessel.id.ToString()); foreach (ConfigNode _vessel in vessel_settings_node.nodes) { //search for previous vessel id if (_vessel.HasValue("vessel_id")) { string val = _vessel.GetValue("vessel_id"); //if (debugging) Debug.Log("[CHATR] node vessel_id = " + val); if (val != prev_vessel.id.ToString()) { //vessel_settings_node.RemoveNode(prev_vessel.id.ToString()); //if (debugging) Debug.Log("[CHATR] prev_vessel old node removed"); //temp_vessels_string = prev_vessel.id.ToString(); all_but_prev_vessel.AddNode(_vessel); if (debugging) Debug.Log("[CHATR] OnVesselChange() :: node vessel_id != prev_vessel.id :: node vessel added to all_but_prev_vessel"); } //else //{ // all_but_prev_vessel.AddNode(cn); //} } } //foreach (ConfigNode cn in vessel_settings_node.nodes) //{ //vessel_settings_node.RemoveNodes(""); // if (debugging) Debug.Log("[CHATR] old nodes removed"); //} vessel_settings_node = all_but_prev_vessel; //if (debugging) Debug.Log("[CHATR] OnVesselChange() :: vessel_settings node = all_but_prev_vessel"); new_vessel_node(prev_vessel); //if (debugging) Debug.Log("[CHATR] OnVesselChange() :: new node created using prev_vessel and added to vessel_settings node"); //save_vessel_settings_node(); vessel_settings_node.Save(settings_path + "vessels.cfg"); if (debugging) Debug.Log("[CHATR] OnVesselChange() :: vessel_settings node saved to vessel_settings.cfg"); load_vessel_settings_node(); //reload with current vessel settings search_vessel_settings_node(); //search for current vessel } vessel_prev_sit = vessel.situation; vessel_prev_stage = vessel.currentStage; //don't update vessel_part_count here! prev_vessel = vessel; } else //Sets these values on first flight load { prev_vessel = vessel; vessel_prev_sit = vessel.situation; vessel_prev_stage = vessel.currentStage; vessel_part_count = vessel.parts.Count; if (use_vessel_settings) { if (debugging) Debug.Log("[CHATR] OnVesselChange() FirstLoad :: calling load_vessel_settings_node()"); load_vessel_settings_node(); //load and search for settings for this vessel if (debugging) Debug.Log("[CHATR] OnVesselChange() FirstLoad :: calling search_vessel_settings_node()"); search_vessel_settings_node(); } } } }
public static void Update(bool target) { _update = false; _multipleManeuvers = false; if (FlightGlobals.ActiveVessel == null || FlightGlobals.ActiveVessel.patchedConicSolver == null) { _updated = false; return; } PatchedConicSolver solver = FlightGlobals.ActiveVessel.patchedConicSolver; _node = solver.maneuverNodes[0]; if (_node != null || _node.patch == null) { _maneuverTotal = _node.DeltaV.magnitude; _maneuverRemaining = _node.GetBurnVector(_node.patch).magnitude; if (BasicOrbitReflection.BetterBurnTimeLoaded) { if (_bbVesselModule == null || _bbVesselReference != FlightGlobals.ActiveVessel) { for (int i = FlightGlobals.ActiveVessel.vesselModules.Count - 1; i >= 0; i--) { VesselModule vMod = FlightGlobals.ActiveVessel.vesselModules[i]; if (vMod == null) { continue; } if (vMod.GetType().Name != _bbModuleName) { continue; } _bbVesselModule = vMod; _bbVesselReference = FlightGlobals.ActiveVessel; break; } } if (_bbVesselModule != null) { string type = _bbVesselModule.Fields[_bbTypeName].GetValue(_bbVesselModule).ToString(); if (type == "Maneuver") { _burnLength = _bbVesselModule.Fields[_bbLengthName].GetValue <double>(_bbVesselModule); _burnTime = _bbVesselModule.Fields[_bbTimeName].GetValue <double>(_bbVesselModule); if (double.IsNaN(_burnLength) || double.IsNaN(_burnTime)) { _bbTimeLoaded = false; _burnTime = _node.UT; _burnLength = 0; } else { double half = _burnLength / 2; _burnTime -= half; _bbTimeLoaded = true; } } else { _bbTimeLoaded = false; _burnTime = _node.UT; } } else { _bbTimeLoaded = false; _burnTime = _node.UT; } } else { _burnTime = _node.UT; } _showAngle = false; _showPhasing = false; _targetInclination = false; if (target) { if (!BasicTargetting.IsVessel && !BasicTargetting.IsCelestial) { _vesselIntersect = false; _bodyIntersect = false; } else { Orbit targetOrbit = FlightGlobals.ActiveVessel.targetObject.GetOrbit(); Orbit active = FlightGlobals.ActiveVessel.orbit; _targetPhasingOrbit = null; if (active.referenceBody == targetOrbit.referenceBody) { _phasingNodePatch = active; _targetPhasingOrbit = targetOrbit; _targetInclination = true; } else { if (active.referenceBody != Planetarium.fetch.Sun) { _showAngle = true; } _showPhasing = true; DrillDownOrbits(_node.patch, targetOrbit); } Vessel.Situations sit = FlightGlobals.ActiveVessel.situation; if ((sit |= Vessel.Situations.LANDED | Vessel.Situations.SPLASHED | Vessel.Situations.PRELAUNCH) == 0) { _vesselIntersect = false; _bodyIntersect = false; } else { OrbitTargeter oTargeter = FlightGlobals.ActiveVessel.orbitTargeter; if (oTargeter == null || solver == null) { _vesselIntersect = false; _bodyIntersect = false; } else if (!MapView.MapIsEnabled) { if (BasicTargetting.IsVessel) { _bodyIntersect = false; Vessel tgt = FlightGlobals.ActiveVessel.targetObject.GetVessel(); if (tgt == null || tgt.LandedOrSplashed) { _vesselIntersect = false; return; } Orbit _refPatch = BasicOrbitReflection.GetRefPatch(oTargeter); Orbit _tgtRefPatch = BasicOrbitReflection.GetTargetRefPatch(oTargeter); _vesselIntersect = GetClosestVessel(_refPatch, _tgtRefPatch); } else { _vesselIntersect = false; double Pe = GetLowestPeA(solver, BasicTargetting.TargetBody, _node.patch); if (Pe < BasicExtensions.AlmostMaxValue) { _closestDist = Pe; _bodyIntersect = true; } else { Orbit _refPatch = BasicOrbitReflection.GetRefPatch(oTargeter); Orbit _tgtRefPatch = BasicOrbitReflection.GetTargetRefPatch(oTargeter); if (_refPatch != null && _refPatch.closestTgtApprUT <= 0) { _bodyIntersect = false; return; } _bodyIntersect = GetClosestCelestial(_refPatch, _tgtRefPatch); } } } else { if (BasicTargetting.Markers == null || BasicTargetting.Markers.Count <= 0) { BasicTargetting.Markers = BasicOrbitReflection.GetOrbitMarkers(oTargeter); } if (BasicTargetting.IsVessel) { _bodyIntersect = false; OrbitTargeter.ISectMarker _intersectOne = null; OrbitTargeter.ISectMarker _intersectTwo = null; for (int i = BasicTargetting.Markers.Count - 1; i >= 0; i--) { OrbitTargeter.Marker m = BasicTargetting.Markers[i]; if (m == null) { continue; } if (!(m is OrbitTargeter.ISectMarker)) { continue; } int num = ((OrbitTargeter.ISectMarker)m).num; if (num == 1) { _intersectOne = m as OrbitTargeter.ISectMarker; } else if (num == 2) { _intersectTwo = m as OrbitTargeter.ISectMarker; } } OrbitTargeter.ISectMarker _closestIntersect = null; if (_intersectOne != null && _intersectTwo != null) { _closestIntersect = _intersectOne.separation > _intersectTwo.separation ? _intersectTwo : _intersectOne; } else if (_intersectOne != null) { _closestIntersect = _intersectOne; } else if (_intersectTwo != null) { _closestIntersect = _intersectTwo; } else { _closestIntersect = null; } if (_closestIntersect == null) { _vesselIntersect = false; } else { _vesselIntersect = true; _closestDist = _closestIntersect.separation * 1000; _closestRelVel = _closestIntersect.relSpeed; _closestTime = _closestIntersect.UT; } } else { _vesselIntersect = false; double Pe = GetLowestPeA(solver, BasicTargetting.TargetBody, _node.patch); if (Pe < BasicExtensions.AlmostMaxValue) { _closestDist = Pe; _bodyIntersect = true; } else { OrbitTargeter.ClApprMarker _approach = null; for (int i = BasicTargetting.Markers.Count - 1; i >= 0; i--) { OrbitTargeter.Marker m = BasicTargetting.Markers[i]; if (m == null) { continue; } if (!(m is OrbitTargeter.ClApprMarker)) { continue; } _approach = m as OrbitTargeter.ClApprMarker; } if (_approach == null) { _bodyIntersect = false; } else { _bodyIntersect = true; _closestDist = _approach.separation * 1000; _closestTime = (_approach.dT * -1) + Planetarium.GetUniversalTime(); } } } } } } } if (solver.maneuverNodes.Count > 1) { _multipleManeuvers = true; _allManeuverRemaining = 0; _allManeuverTotal = 0; for (int i = solver.maneuverNodes.Count - 1; i >= 0; i--) { ManeuverNode n = solver.maneuverNodes[i]; if (n == null || n.patch == null) { continue; } _allManeuverTotal += n.DeltaV.magnitude; _allManeuverRemaining += n.GetBurnVector(n.patch).magnitude; } } _updated = true; } }
public override void OnUpdate() { if (HighLogic.LoadedSceneIsEditor) { updateEditor(); return; } // we launched if (lastSituation == Vessel.Situations.PRELAUNCH && vessel.situation != Vessel.Situations.PRELAUNCH) { OnLaunch(); } checkTimer(); lastSituation = vessel.situation; }
public String GetScopeForSituation(Vessel.Situations situation) { return(GetScopeForSituationAndBody(situation.ToString(), this.vessel.mainBody)); }
protected override bool Generate() { //ISRU fails generation on duplicates, so we can't have many out at once. int totalContracts = ContractSystem.Instance.GetCurrentContracts<ISRUContract>().Count(); if (totalContracts >= FPConfig.ISRU.MaximumExistent) return false; if (TechUnlocked() == false) return false; System.Random generator = new System.Random(this.MissionSeed); List<CelestialBody> bodies = GetBodies_Reached(false, true); if (bodies.Count == 0) return false; while (true) { targetBody = bodies[generator.Next(0, bodies.Count)]; if (CelestialIsForbidden(targetBody)) { bodies.Remove(targetBody); if (bodies.Count == 0) return false; continue; } else break; } float fundsMultiplier = 1; float scienceMultiplier = 1; float reputationMultiplier = 1; switch (this.prestige) { case ContractPrestige.Trivial: gatherGoal = FPConfig.ISRU.TrivialExtractAmount; if (generator.Next(0, 100) < FPConfig.ISRU.TrivialDeliveryChance) { deliveryBody = Util.RandomNeighbor(MissionSeed, targetBody, false); isDelivering = true; } break; case ContractPrestige.Significant: gatherGoal = FPConfig.ISRU.SignificantExtractAmount; fundsMultiplier = FPConfig.ISRU.Funds.SignificantMultiplier; scienceMultiplier = FPConfig.ISRU.Science.SignificantMultiplier; reputationMultiplier = FPConfig.ISRU.Reputation.SignificantMultiplier; if (generator.Next(0, 100) < FPConfig.ISRU.SignificantDeliveryChance) { deliveryBody = Util.RandomNeighbor(MissionSeed, targetBody, false); isDelivering = true; } break; case ContractPrestige.Exceptional: gatherGoal = FPConfig.ISRU.ExceptionalExtractAmount; fundsMultiplier = FPConfig.ISRU.Funds.ExceptionalMultiplier; scienceMultiplier = FPConfig.ISRU.Science.ExceptionalMultiplier; reputationMultiplier = FPConfig.ISRU.Reputation.ExceptionalMultiplier; if (generator.Next(0, 100) < FPConfig.ISRU.ExceptionalDeliveryChance) { deliveryBody = Util.RandomNeighbor(MissionSeed, targetBody, false); isDelivering = true; } break; } if (deliveryBody == null) isDelivering = false; targetResource = ChooseResource(); if (isDelivering) { fundsMultiplier *= FPConfig.ISRU.Funds.DeliveryMultiplier; scienceMultiplier *= FPConfig.ISRU.Science.DeliveryMultiplier; reputationMultiplier *= FPConfig.ISRU.Reputation.DeliveryMultiplier; } //Spice this up just a tad, to make contracts more varied. float wobble = (float)generator.NextDouble() * 0.25f; if (generator.Next(0, 100) > 50) wobble = 1 + wobble; else wobble = 1 - wobble; fundsMultiplier *= wobble; scienceMultiplier *= wobble; reputationMultiplier *= wobble; gatherGoal *= wobble; gatherGoal = Mathf.Round(gatherGoal / 50) * 50; this.AddParameter(new ResourceExtractionParameter(targetResource, gatherGoal, targetBody), null); if (isDelivering) { deliverySituation = Util.ApplicableSituation(MissionSeed, deliveryBody, false); this.AddParameter(new ResourcePossessionParameter(targetResource, gatherGoal), null); this.AddParameter(new LocationAndSituationParameter(deliveryBody, deliverySituation,targetResource), null); this.AddParameter(new KillControlsParameter(10), null); } base.AddKeywords(new string[] { "ISRU" }); base.SetExpiry(FPConfig.ISRU.Expire.MinimumExpireDays, FPConfig.ISRU.Expire.MaximumExpireDays); base.SetDeadlineDays(FPConfig.ISRU.Expire.DeadlineDays, targetBody); base.SetFunds(Mathf.Round(FPConfig.ISRU.Funds.BaseAdvance * fundsMultiplier), Mathf.Round(FPConfig.ISRU.Funds.BaseReward * fundsMultiplier), Mathf.Round(FPConfig.ISRU.Funds.BaseFailure * fundsMultiplier), targetBody); base.SetScience(Mathf.Round(FPConfig.ISRU.Science.BaseReward * scienceMultiplier), targetBody); base.SetReputation(Mathf.Round(FPConfig.ISRU.Reputation.BaseReward * reputationMultiplier), Mathf.Round(FPConfig.ISRU.Reputation.BaseFailure * reputationMultiplier), targetBody); //Prevent duplicate contracts shortly before finishing up. foreach (ISRUContract active in ContractSystem.Instance.GetCurrentContracts<ISRUContract>()) { if (active.targetBody == this.targetBody) return false; } return true; }
public Prerequisites(Prerequisites p) { bodyName = p.bodyName; paused = p.paused; scene = p.scene; situation = p.situation; cameraMode = p.cameraMode; inAtmosphere = p.inAtmosphere; timeOfDay = p.timeOfDay; maxVelocitySurface = p.maxVelocitySurface; minVelocitySurface = p.minVelocitySurface; maxVelocityOrbital = p.maxVelocityOrbital; minVelocityOrbital = p.minVelocityOrbital; maxAltitude = p.maxAltitude; minAltitude = p.minAltitude; }