//[KSPAction("SCIENCE")] //public void scienceee(KSPActionParam param) //{ // observation(); //} //[KSPEvent(guiActive = true, guiName = "Observe", active = true)] public void observation() { if (storedData.Count > 0) { CactEyeGUI.DisplayText("Processor already contains experiment data!"); return; } if (HighLogic.CurrentGame.Mode == Game.Modes.SANDBOX) { CactEyeGUI.DisplayText("Science experiments unavailable in sandbox mode!"); return; } var target = FlightGlobals.fetch.VesselTarget; if (target == null) { CactEyeGUI.DisplayText("You must select a target!"); return; } if (target.GetType().Name == "CelestialBody" && techType == "Planetary") { CelestialBody targetBody = FlightGlobals.Bodies.Find(n => n.GetName() == target.GetName()); string oBody = CactEyeVars.CheckOccult(targetBody); if (oBody != "") { CactEyeGUI.DisplayText("Target is behind " + oBody + "!"); return; } else if (targetBody == FlightGlobals.Bodies[0]) { CactEyeGUI.DisplayText("Cannot target the sun!"); return; } else if (opticsModule.GetTargetPos(targetBody.transform.position, 500f) == new Vector3(-1, -1, 0)) { CactEyeGUI.DisplayText("Target not in telescope sights!"); return; } else if (opticsModule.fov > CactEyeVars.bodySize[targetBody] * 50f) { CactEyeGUI.DisplayText("Telescope not zoomed in far enough!"); return; } else { doScience(FlightGlobals.Bodies.Find(n => n.GetName() == target.GetName())); } } else if (target.GetType().Name == "Vessel" && techType == "Asteroid") { Vessel targetVessel = target.GetVessel(); if (techType == "Asteroid" && targetVessel.vesselType == VesselType.SpaceObject && targetVessel.DiscoveryInfo.trackingStatus.Value == "Tracking") { if (CactEyeVars.GetPlanetBody(vessel.mainBody) == FlightGlobals.Bodies[1]) { string oBody = CactEyeVars.CheckOccult(targetVessel); if (oBody != "") { CactEyeGUI.DisplayText("Target is behind " + oBody + "!"); return; } else if (opticsModule.GetTargetPos(targetVessel.GetWorldPos3D(), 500f) == new Vector3(-1, -1, 0)) { CactEyeGUI.DisplayText("Target not in telescope sights!"); return; } else if (opticsModule.fov > 0.5f) { CactEyeGUI.DisplayText("Telescope not zoomed in far enough!"); return; } else { doScience(targetVessel); } } else { CactEyeGUI.DisplayText("Telescope must be near Kerbin to perform asteroid experiment!"); return; } } else { CactEyeGUI.DisplayText("Target not valid!"); return; } } else if (techType == "Occultation") { CelestialBody planetBody = CactEyeVars.GetPlanetBody(vessel.mainBody); if (occType != "None") { print(occTime - Planetarium.GetUniversalTime()); if (occTime - Planetarium.GetUniversalTime() < 60) //target time is 30 seconds before limit, experiment should be within 30 seconds before or after target { if (occType == "Asteroid" && target.GetType().Name == "Vessel") { Vessel targetVessel = target.GetVessel(); if (targetVessel == CactEyeVars.occultationExpAsteroids[planetBody]) { string oBody = CactEyeVars.CheckOccult(targetVessel); if (oBody != "") { CactEyeGUI.DisplayText("Target is behind " + oBody + "!"); return; } else if (opticsModule.GetTargetPos(targetVessel.GetWorldPos3D(), 500f) == new Vector3(-1, -1, 0)) { CactEyeGUI.DisplayText("Target not in telescope sights!"); return; } else if (opticsModule.fov > 0.5f) { CactEyeGUI.DisplayText("Telescope not zoomed in far enough!"); return; } else { doScience(targetVessel); } } else { CactEyeGUI.DisplayText("Incorrect target!"); return; } } else if (occType != "Asteroid" && target.GetType().Name == "CelestialBody") { CelestialBody targetBody = FlightGlobals.Bodies.Find(n => n.GetName() == target.GetName()); if (targetBody != CactEyeVars.occultationExpBodies[planetBody]) { CactEyeGUI.DisplayText("Incorrect target!"); return; } string oBody = CactEyeVars.CheckOccult(targetBody); if (oBody != "") { CactEyeGUI.DisplayText("Target is behind " + oBody + "!"); return; } else if (opticsModule.GetTargetPos(targetBody.transform.position, 500f) == new Vector3(-1, -1, 0)) { CactEyeGUI.DisplayText("Target not in telescope sights!"); return; } else if (opticsModule.fov > CactEyeVars.bodySize[targetBody] * 50f) { CactEyeGUI.DisplayText("Telescope not zoomed in far enough!"); return; } else { doScience(FlightGlobals.Bodies.Find(n => n.GetName() == target.GetName())); } } } else { CactEyeGUI.DisplayText("Occultation experiment must be performed within thirty seconds of target time!"); return; } } else { CactEyeGUI.DisplayText("Occultation experiment not available!"); return; } } else { CactEyeGUI.DisplayText("Target not valid!"); return; } }
public override void OnUpdate() { base.OnUpdate(); timer += (float)(Planetarium.GetUniversalTime() - storedTime); isFunctional = checkSetup(); UpdateVarsEntries(); ////If the aperture has opened/closed, recalculate stuff //if (opticsModule != null) //{ // if (opticsModule.isFunctional != storedOpticsState) // { // checkSetup(); // } //} if (isFunctional && isActive) { if (opticsModule != null) { if (opticsModule.isSmallOptics) { discoveryRate = 0.5f * maxDiscoveryRate; } else { discoveryRate = maxDiscoveryRate; } } } else { discoveryRate = 0f; } if (isFunctional && isActive && storedData.Count() == 0) { //Events["observation"].active = true; Events["eventReviewScience"].active = false; Events["eventDumpData"].active = false; } else { //Events["observation"].active = false; Events["eventReviewScience"].active = true; Events["eventDumpData"].active = true; } //If the sun is visible and the telescope is pointed at it, bad things should happen! if (opticsModule != null && opticsModule.isFunctional) { if (CactEyeVars.CheckOccult(FlightGlobals.Bodies[0]) == "") { Vector3d heading = (FlightGlobals.Bodies[0].position - FlightGlobals.ship_position).normalized; if (Vector3d.Dot(opticsModule.part.transform.up, heading) > 0.90) { CactEyeGUI.DisplayText("WARNING: Telescope pointing dangerously close to the sun!"); } if (Vector3d.Dot(opticsModule.part.transform.up, heading) > 0.95) { ScreenMessages.PostScreenMessage("Telescope pointed directly at sun, optics damaged and processor fried!", 6, ScreenMessageStyle.UPPER_CENTER); opticsModule.BreakScope(); CactEyeGUI.pMList.Remove(this); part.explode(); //officially the best function ever } } } if (!fullRecovery) { if ((vessel.situation == Vessel.Situations.LANDED || vessel.situation == Vessel.Situations.SPLASHED) && storedData.Count > 0) { ScreenMessages.PostScreenMessage("Only data from high tech processors taken with full optics is recoverable!", 6, ScreenMessageStyle.UPPER_CENTER); ScreenMessages.PostScreenMessage("Telescope data lost!", 6, ScreenMessageStyle.UPPER_CENTER); eventDumpData(); } } storedTime = Planetarium.GetUniversalTime(); }