public override string DoScience(Vector3 TargetPosition, bool IsSmallOptics, float FOV, Texture2D Screenshot) { Vessel TargetVessel = FlightGlobals.fetch.VesselTarget.GetVessel(); //If target is not an asteroid if (TargetVessel == null || TargetVessel.vesselType != VesselType.SpaceObject) { return(Type + ": Invalid target type!"); } //if target is not in telescope view else if (TargetPosition == new Vector3(-1, -1, 0)) { return(Type + ": Target not in scope field of view."); } else if (FOV > 0.5f) { return(Type + ": Scope not zoomed in far enough."); } else if (CactEyeAPI.CheckOccult(TargetVessel) != "") { return(Type + ": Target is occulted by another body."); } else { float SciencePoints = 0f; string TargetName = TargetVessel.name; ScienceExperiment AsteroidExperiment = ResearchAndDevelopment.GetExperiment(ExperimentID); ScienceSubject AsteroidSubject = ResearchAndDevelopment.GetExperimentSubject(AsteroidExperiment, ExperimentSituations.InSpaceHigh, FlightGlobals.ActiveVessel.mainBody, ""); SciencePoints += AsteroidExperiment.baseValue * AsteroidExperiment.dataScale * maxScience; //These two lines cause a bug where the experiment gives an infinite supply of science points. //WideFieldSubject.scientificValue = 1f; //WideFieldSubject.science = 0f; if (CactEyeConfig.DebugMode) { Debug.Log("CactEye 2: SciencePoints: " + SciencePoints.ToString()); } if (IsSmallOptics) { SciencePoints *= 0.1f; } ScienceData Data = new ScienceData(SciencePoints, 1f, 0f, AsteroidSubject.id, Type + " " + TargetName + " Observation"); StoredData.Add(Data); ReviewData(Data, Screenshot); return(""); } }
/* ************************************************************************************************ * Function Name: OnUpdate * Input: None * Output: None * Purpose: This function will run once every frame. It is used for some event handling, and for * updating information such as the scope orientation and position. It will also check for the * condition of when the telescope is pointed at the sun, and will damage the scope if it * detects excessive sun exposure. * ************************************************************************************************/ public override void OnUpdate() { //Enable Repair Scope context menu option if the scope is damaged. if (IsDamaged) { IsFunctional = false; Events["FixScope"].active = true; } //If the scope isn't damage, then toggle scope functionality based on the aperture. else { if (opticsAnimate != null && !IsSmallOptics) { if (opticsAnimate.animTime < 0.5 && IsFunctional) { IsFunctional = false; } if (opticsAnimate.animTime > 0.5 && !IsFunctional) { IsFunctional = true; } } //If the aperture is opened and the Sun is not occulted. if (IsFunctional && CactEyeAPI.CheckOccult(FlightGlobals.Bodies[0]) == "") { //Check if we're pointing at the sun Vector3d Heading = (FlightGlobals.Bodies[0].position - FlightGlobals.ship_position).normalized; if (Vector3d.Dot(transform.up, Heading) > 0.9 && CactEyeConfig.SunDamage) { ScreenMessages.PostScreenMessage("Telescope pointed directly at sun, optics damaged and processors fried!", 6, ScreenMessageStyle.UPPER_CENTER); BreakScope(); DestroyProcessors(); //Destroy all the processors, should be fun :) } else if (Vector3d.Dot(transform.up, Heading) > 0.85) { ScreenMessages.PostScreenMessage("Telescope is getting close to the sun. Please make course adjustements before an equipment failure happens!", 6, ScreenMessageStyle.UPPER_CENTER); } } } //Send updated position information to the telescope gui object. if (TelescopeControlMenu != null) { TelescopeControlMenu.UpdatePosition(part.FindModelTransform(CameraTransformName)); } }
/* ************************************************************************************************ * Function Name: DoScience * Input: Position of the target, whether or not we're dealing with the FungEye or CactEye optics, * the current field of view, and a screenshot. * Output: None * Purpose: This function will generate a science report based on the input parameters. This is an * override of a function prototype. This will generate a science report based on the target * celestial body. Science reports will only be generated if the target is a celestial body, * if the target is not the sun, if the target is visible in the scope, and if the telescope * is zoomed in far enough. * ************************************************************************************************/ public override string DoScience(Vector3 TargetPosition, float scienceMultiplier, float FOV, Texture2D Screenshot) { CelestialBody Target = FlightGlobals.Bodies.Find(n => n.GetName() == FlightGlobals.fetch.VesselTarget.GetName()); CelestialBody Home = this.vessel.mainBody; //Sandbox or Career mode logic handled by gui. //if (HighLogic.CurrentGame.Mode == Game.Modes.SANDBOX) //{ // //CactEyeGUI.DisplayText("Science experiments unavailable in sandbox mode!"); // return; //} if (FlightGlobals.fetch.VesselTarget.GetType().Name != "CelestialBody") { //Invalid target type if (CactEyeConfig.DebugMode) { Debug.Log("CactEye 2: Wide Field Camera: Invalid Target Type."); } return(Type + ": Invalid Target Type."); } else if (Target == FlightGlobals.Bodies[0]) { //Cannot target the sun if (CactEyeConfig.DebugMode) { Debug.Log("CactEye 2: Wide Field Camera: Cannot target the sun."); } return(Type + ": Cannot target the sun."); } else if (TargetPosition == new Vector3(-1, -1, 0)) { //target not in scope if (CactEyeConfig.DebugMode) { Debug.Log("CactEye 2: Wide Field Camera: Target not in scope."); } return(Type + ": Target not in scope field of view."); } //This has a tendency to be rather tempermental. If a player is getting false "Scope not zoomed in far enough" errors, //then the values here will need to be adjusted. else if (FOV > CactEyeAPI.bodySize[Target] * 50f) { //Scope not zoomed in far enough if (CactEyeConfig.DebugMode) { Debug.Log("CactEye 2: Wide Field Camera: Scope not zoomed in far enough."); Debug.Log("CactEye 2: Wide Field Camera: " + FOV.ToString()); Debug.Log("CactEye 2: Wide Field Camera: " + (CactEyeAPI.bodySize[Target] * 50f).ToString()); } return(Type + ": Scope not zoomed in far enough."); } //Check to see if target is blocked. else if (CactEyeAPI.CheckOccult(Target) != "") { if (CactEyeConfig.DebugMode) { Debug.Log("CactEye 2: Target is occulted by another body."); } return(Type + ": Target is occulted by another body."); } else { float SciencePoints = 0f; string TargetName = Target.name; ScienceExperiment WideFieldExperiment; ScienceSubject WideFieldSubject; bool withParent; CelestialBody parentBody; ExperimentID = "CactEyePlanetary" + TargetName; try { WideFieldExperiment = ResearchAndDevelopment.GetExperiment(ExperimentID); WideFieldSubject = ResearchAndDevelopment.GetExperimentSubject(WideFieldExperiment, ExperimentSituations.InSpaceHigh, Home, ""); SciencePoints = WideFieldExperiment.baseValue * WideFieldExperiment.dataScale * maxScience * scienceMultiplier; if (CactEyeConfig.DebugMode) { Debug.Log("CactEye 2: SciencePoints: " + SciencePoints.ToString()); } //Different scopes have different multipliers for the science gains. // SciencePoints *= scienceMultiplier; ScienceData Data = new ScienceData(SciencePoints, 1f, 0f, WideFieldSubject.id, Type + " " + TargetName + " Observation"); StoredData.Add(Data); ReviewData(Data, Screenshot); if (RBWrapper.APIRBReady) { Debug.Log("CactEye 2: Wrapper ready"); RBWrapper.CelestialBodyInfo cbi; RBWrapper.RBactualAPI.CelestialBodies.TryGetValue(Target, out cbi); if (!cbi.isResearched) { int RBFoundScience = (int)(8f * WideFieldExperiment.dataScale); RBWrapper.RBactualAPI.FoundBody(RBFoundScience, Target, out withParent, out parentBody); } else { System.Random rnd = new System.Random(); RBWrapper.RBactualAPI.Research(Target, rnd.Next(1, 11)); } } else { Debug.Log("CactEye 2: Wrapper not ready"); } } catch (Exception e) { Debug.Log("CactEye 2: Excpetion 5: Was not able to find Experiment with ExperimentID: " + ExperimentID.ToString()); Debug.Log(e.ToString()); return("An error occurred. Please post on the Official CactEye 2 thread on the Kerbal Forums."); } return(""); } }
/* ************************************************************************************************ * Function Name: DoScience * Input: Position of the target, whether or not we're dealing with the FungEye or CactEye optics, * the current field of view, and a screenshot. * Output: None * Purpose: This function will generate a science report based on the input parameters. This is an * override of a function prototype. This will generate a science report based on the target * celestial body. Science reports will only be generated if the target is a celestial body, * if the target is not the sun, if the target is visible in the scope, and if the telescope * is zoomed in far enough. * ************************************************************************************************/ public override string DoScience(Vector3 TargetPosition, bool IsSmallOptics, float FOV, Texture2D Screenshot) { CelestialBody Target = FlightGlobals.Bodies.Find(n => n.GetName() == FlightGlobals.fetch.VesselTarget.GetName()); //Sandbox or Career mode logic handled by gui. //if (HighLogic.CurrentGame.Mode == Game.Modes.SANDBOX) //{ // //CactEyeGUI.DisplayText("Science experiments unavailable in sandbox mode!"); // return; //} if (FlightGlobals.fetch.VesselTarget.GetType().Name != "CelestialBody") { //Invalid target type if (CactEyeConfig.DebugMode) { Debug.Log("CactEye 2: Wide Field Camera: Invalid Target Type."); } return(Type + ": Invalid Target Type."); } else if (Target == FlightGlobals.Bodies[0]) { //Cannot target the sun if (CactEyeConfig.DebugMode) { Debug.Log("CactEye 2: Wide Field Camera: Cannot target the sun."); } return(Type + ": Cannot target the sun."); } else if (TargetPosition == new Vector3(-1, -1, 0)) { //target not in scope if (CactEyeConfig.DebugMode) { Debug.Log("CactEye 2: Wide Field Camera: Target not in scope."); } return(Type + ": Target not in scope field of view."); } //This has a tendency to be rather tempermental. If a player is getting false "Scope not zoomed in far enough" errors, //then the values here will need to be adjusted. else if (FOV > CactEyeAPI.bodySize[Target] * 50f) { //Scope not zoomed in far enough if (CactEyeConfig.DebugMode) { Debug.Log("CactEye 2: Wide Field Camera: Scope not zoomed in far enough."); Debug.Log("CactEye 2: Wide Field Camera: " + FOV.ToString()); Debug.Log("CactEye 2: Wide Field Camera: " + (CactEyeAPI.bodySize[Target] * 50f).ToString()); } return(Type + ": Scope not zoomed in far enough."); } //Check to see if target is blocked. else if (CactEyeAPI.CheckOccult(Target) != "") { if (CactEyeConfig.DebugMode) { Debug.Log("CactEye 2: Target is occulted by another body."); } return(Type + ": Target is occulted by another body."); } else { float SciencePoints = 0f; string TargetName = Target.name; ScienceExperiment WideFieldExperiment; ScienceSubject WideFieldSubject; try { WideFieldExperiment = ResearchAndDevelopment.GetExperiment(ExperimentID); WideFieldSubject = ResearchAndDevelopment.GetExperimentSubject(WideFieldExperiment, ExperimentSituations.InSpaceHigh, Target, ""); SciencePoints += WideFieldExperiment.baseValue * WideFieldExperiment.dataScale * maxScience; if (CactEyeConfig.DebugMode) { Debug.Log("CactEye 2: SciencePoints: " + SciencePoints.ToString()); } if (IsSmallOptics) { SciencePoints *= 0.1f; } ScienceData Data = new ScienceData(SciencePoints, 1f, 0f, WideFieldSubject.id, Type + " " + TargetName + " Observation"); StoredData.Add(Data); ReviewData(Data, Screenshot); } catch (Exception e) { Debug.Log("CactEye 2: Excpetion 5: Was not able to find Experiment with ExperimentID: " + ExperimentID.ToString()); Debug.Log(e.ToString()); return("An error occurred. Please post on the Official CactEye 2 thread on the Kerbal Forums."); } return(""); } }