Ejemplo n.º 1
0
        public void UpdateVarsEntries()
        {
            CelestialBody pBody = CactEyeVars.GetPlanetBody(vessel.mainBody);

            if (!CactEyeVars.occultationExpTypes.ContainsKey(pBody))
            {
                print("WAITING");
                return;
            }
            else
            {
                occType = CactEyeVars.occultationExpTypes[pBody];
                occTime = CactEyeVars.occultationExpTimes[pBody];
                if (occType == "Asteroid")
                {
                    occAst = CactEyeVars.occultationExpAsteroids[pBody].id.ToString("N");
                }
                else
                {
                    occBody = CactEyeVars.occultationExpBodies[pBody].bodyName;
                }
            }
        }
Ejemplo n.º 2
0
        //[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;
            }
        }
Ejemplo n.º 3
0
        private void mainGUI(int windowID)
        {
            if (procModule == null && pMList.Count != 0)
            {
                procModule = pMList[0];
            }

            GUILayout.BeginVertical(GUILayout.ExpandHeight(true));

            if (procModule != null)
            {
                if (opticsModule != null && tex != null)
                {
                    if (!opticsModule.isDamaged)
                    {
                        if (!opticsModule.isSmallOptics ^ opticsModule.smallApertureOpen)
                        {
                            GUILayout.BeginHorizontal(GUILayout.ExpandWidth(false));

                            GUI.skin.GetStyle("Label").alignment = TextAnchor.UpperLeft;
                            GUILayout.Label("Zoom");

                            //Formatting zoom amount
                            string zoom;
                            if (opticsModule.fov > 0.064)
                            {
                                zoom = "X " + string.Format("{0:##0.0}", 64 / opticsModule.fov);
                            }
                            else
                            {
                                zoom = "X " + string.Format("{0:0.00E+0}", (64 / opticsModule.fov));
                                int pow = int.Parse(zoom.Substring(zoom.Length - 1));
                                if (pow > 9)
                                {
                                    print("ERROR: Telescope zooms in more than 10^" + pow + "!!!");
                                }
                                zoom  = zoom.Replace("E+", "x10");
                                zoom  = zoom.Remove(zoom.Length - 1);
                                zoom += uPow[pow];
                            }

                            GUI.skin.GetStyle("Label").alignment = TextAnchor.UpperRight;
                            GUILayout.Label(zoom);

                            GUILayout.EndHorizontal();


                            GUILayout.BeginHorizontal(GUILayout.ExpandWidth(false));

                            GUI.skin.GetStyle("Label").alignment = TextAnchor.UpperCenter;
                            fov = GUILayout.HorizontalSlider(fov, 0f, 1f);
                            //print("minFOV: " + procModule.minFOV + " || ^1/3: " + Mathf.Pow(procModule.minFOV, 1f / 3f));
                            opticsModule.fov = 0.5f * Mathf.Pow(4f - fov * (4f - Mathf.Pow(procModule.minFOV, 1f / 3f)), 3);

                            GUILayout.EndHorizontal();


                            GUILayout.Space(texRect.height);
                            tex = opticsModule.outputTex;
                            GUI.Box(new Rect(texRect.xMin - 2, texRect.yMin - 2, texRect.width + 4, texRect.height + 4), "");
                            GUI.DrawTexture(texRect, tex);
                            //GUILayout.Box("", GUILayout.Width(texRect.width), GUILayout.Height(texRect.height));
                            GUI.DrawTexture(new Rect(texRect.xMin, texRect.yMax - 32f, 128f, 32f), preview);
                            GUI.DrawTexture(new Rect(texRect.xMin + (0.5f * texRect.width) - 64, texRect.yMin + (0.5f * texRect.height) - 64, 128, 128), crosshair);
                            if (timer < 5f)
                            {
                                GUI.skin.GetStyle("Label").alignment = TextAnchor.UpperLeft;
                                GUI.Label(new Rect(texRect.xMin, texRect.yMin, 480, 50), new GUIContent(dispText));
                            }

                            if (FlightGlobals.fetch.VesselTarget != null)
                            {
                                string  targetName = FlightGlobals.fetch.VesselTarget.GetName();
                                Vector2 vec        = opticsModule.GetTargetPos(FlightGlobals.fetch.VesselTarget.GetTransform().position, texRect.width);

                                if (vec.x > 16 && vec.y > 16 && vec.x < texRect.width - 16 && vec.y < texRect.height - 16)
                                {
                                    GUI.DrawTexture(new Rect(vec.x + texRect.xMin - 16, vec.y + texRect.yMin - 16, 32, 32), targetPointer);
                                    Vector2 size = GUI.skin.GetStyle("Label").CalcSize(new GUIContent(targetName));
                                    if (vec.x > 0.5 * size.x && vec.x < texRect.width - (0.5 * size.x) && vec.y < texRect.height - 16 - size.y)
                                    {
                                        GUI.skin.GetStyle("Label").alignment = TextAnchor.UpperCenter;
                                        GUI.Label(new Rect(vec.x + texRect.xMin - (0.5f * size.x), vec.y + texRect.yMin + 20, size.x, size.y), targetName);
                                    }
                                }

                                if (procModule.techType == "Planetary" && procModule.isActive && procModule.isFunctional)
                                {
                                    if (GUI.Button(new Rect(texRect.xMax - 36, texRect.yMax - 36, 32, 32), save))
                                    {
                                        DisplayText("Saved screenshot to " + opticsModule.GetTex(true, targetName));
                                    }
                                }
                            }
                        }
                        else
                        {
                            GUILayout.BeginHorizontal();
                            GUILayout.Label("FungEye optics aperture closed.");
                            GUILayout.EndHorizontal();
                            GUILayout.BeginHorizontal();
                            GUILayout.Label("Note that you can never close the aperture again once you open them with these optics!");
                            GUILayout.EndHorizontal();
                        }
                    }
                    else
                    {
                        GUILayout.BeginHorizontal();
                        GUILayout.Label("Optics module has been damaged by the sun! Repair must be made to optics module during an EVA.");
                        //print("FONT SIZE: " + GUI.skin.GetStyle("Label").fontSize);
                        GUILayout.EndHorizontal();
                    }
                }
                else
                {
                    GUILayout.BeginHorizontal();
                    GUILayout.Label("No optics detected!");
                    GUILayout.EndHorizontal();
                }

                GUILayout.Space(10f);

                GUILayout.BeginHorizontal(GUILayout.ExpandWidth(false));

                GUI.skin.GetStyle("Label").alignment = TextAnchor.MiddleCenter;
                string targetstring;
                if (FlightGlobals.fetch.VesselTarget == null)
                {
                    targetstring = "No target selected";
                }
                else
                {
                    targetstring = "Target: " + FlightGlobals.fetch.VesselTarget.GetName();
                }

                GUILayout.Label(targetstring, GUILayout.Height(30f), GUILayout.Width(370f));

                if (GUILayout.Button("Select Target", GUILayout.Height(30f)))
                {
                    targetOpen = !targetOpen;
                }

                GUILayout.EndHorizontal();

                GUILayout.Space(10f);

                GUILayout.BeginHorizontal(GUILayout.ExpandWidth(false));

                GUI.skin.GetStyle("Label").alignment = TextAnchor.MiddleLeft;
                GUILayout.Label("Processor: ", GUILayout.Width(100f), GUILayout.Height(30f));

                GUI.skin.GetStyle("Label").alignment = TextAnchor.MiddleCenter;
                if (GUILayout.Button(procModule.pName, GUILayout.Height(30f)))
                {
                    int pI = pMList.IndexOf(procModule) + 1;
                    if (pI > pMList.Count - 1)
                    {
                        procModule = pMList[0];
                    }
                    else
                    {
                        procModule = pMList[pI];
                    }
                }

                GUILayout.Space(15);
                GUILayout.Label(procModule.status, GUILayout.Height(30f));
                GUILayout.FlexibleSpace();
                if (procModule.isFunctional)
                {
                    if (GUILayout.Button(procModule.isActive ? "Disable" : "Activate", GUILayout.Height(30f), GUILayout.Width(80f)))
                    {
                        procModule.toggle(null);
                    }
                }

                GUILayout.EndHorizontal();

                if (procModule.isActive && procModule.isFunctional && HighLogic.CurrentGame.Mode != Game.Modes.SANDBOX)
                {
                    GUILayout.BeginHorizontal();
                    GUILayout.Label("", GUILayout.Width(100f), GUILayout.Height(30f));

                    if (procModule.GetScienceCount() == 0)
                    {
                        if (GUILayout.Button("Make Observation", GUILayout.Height(30f)))
                        {
                            procModule.observation();
                        }
                    }
                    else
                    {
                        if (GUILayout.Button("Review Data", GUILayout.Height(30f)))
                        {
                            procModule.eventReviewScience();
                        }
                        GUILayout.Space(80);
                        if (GUILayout.Button("Dump Data", GUILayout.Height(30f)))
                        {
                            procModule.eventReviewScience();
                        }
                    }

                    GUILayout.EndHorizontal();

                    if (procModule.techType == "Occultation")
                    {
                        GUILayout.BeginHorizontal();
                        GUILayout.Label("", GUILayout.Width(100f), GUILayout.Height(30f));

                        CelestialBody planetBody = CactEyeVars.GetPlanetBody(FlightGlobals.ActiveVessel.mainBody);

                        if (planetBody != null)
                        {
                            if (!CactEyeVars.occultationExpTypes.ContainsKey(planetBody))
                            {
                                CactEyeVars.GenerateOccultationExp(planetBody);
                            }

                            if (CactEyeVars.occultationExpTypes[planetBody] == "Asteroid")
                            {
                                GUILayout.Label("Next occultation: " + CactEyeVars.occultationExpAsteroids[planetBody].vesselName + ", at " + CactEyeVars.GetOccultationExpTimeString(planetBody), GUILayout.Height(30f));
                            }
                            else
                            {
                                GUILayout.Label("Next occultation: " + CactEyeVars.occultationExpBodies[planetBody].bodyName + ", at " + CactEyeVars.GetOccultationExpTimeString(planetBody), GUILayout.Height(30f));
                            }

                            //I sure wish I could put a button here to auto create a KAC alarm. Hint hint TriggerAu - make a KAC wrapper!
                        }
                        else
                        {
                            GUILayout.Label("Occultation experiment not available in solar orbit!");
                        }

                        GUILayout.EndHorizontal();
                    }
                }

                if (HighLogic.CurrentGame.Mode == Game.Modes.SANDBOX)
                {
                    GUILayout.FlexibleSpace();
                    GUILayout.BeginHorizontal();
                    GUILayout.Label("Science experiments unavailable in sandbox mode!");
                    GUILayout.EndHorizontal();
                }

                if (gMList.Count != 0)
                {
                    GUILayout.FlexibleSpace();

                    GUILayout.BeginHorizontal(GUILayout.ExpandWidth(false));

                    GUI.skin.GetStyle("Label").alignment = TextAnchor.MiddleLeft;
                    GUILayout.Label("Gyro Speed: ", GUILayout.Width(100f), GUILayout.Height(30f));

                    GUI.skin.GetStyle("Label").alignment = TextAnchor.MiddleCenter;
                    gSel = GUILayout.SelectionGrid(gSel, gModes, 3, GUILayout.Height(30f));

                    if (gSel != gSelSt)
                    {
                        if (gSel == 0)
                        {
                            foreach (CactEyeGyro gM in gMList)
                            {
                                gM.normScale(null);
                            }
                        }
                        if (gSel == 1)
                        {
                            foreach (CactEyeGyro gM in gMList)
                            {
                                gM.redScale(null);
                            }
                        }
                        if (gSel == 2)
                        {
                            foreach (CactEyeGyro gM in gMList)
                            {
                                gM.fineScale(null);
                            }
                        }

                        gSelSt = gSel;
                    }

                    GUILayout.EndHorizontal();
                }
            }
            else
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label("No processors detected!");
                GUILayout.EndHorizontal();
            }

            GUILayout.EndVertical();

            GUI.DragWindow();
            GUI.skin.GetStyle("Label").alignment = TextAnchor.UpperLeft;
        }
Ejemplo n.º 4
0
        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();
        }
Ejemplo n.º 5
0
        public string GetTex(bool isFull, string targetName = "Photo")
        {
            RenderTexture currentRT = RenderTexture.active;

            if (isFull)
            {
                RenderTexture.active = rtFull;
            }
            else
            {
                RenderTexture.active = rtLow;
            }

            foreach (Camera c in cameras)
            {
                if (isFull)
                {
                    c.pixelRect     = fullRect;
                    c.targetTexture = rtFull;
                }
                else
                {
                    c.pixelRect     = smallRect;
                    c.targetTexture = rtLow;
                }

                if (c.name.Contains("0"))
                {
                    c.transform.position = camTrans.position;
                }
                c.transform.forward  = camTrans.forward;
                c.transform.rotation = camTrans.rotation;
                c.fieldOfView        = fov;

                c.Render();

                if (!c.name.Contains("0"))
                {
                    foreach (Renderer r in skyboxRenderers)
                    {
                        r.enabled = false;
                    }
                    foreach (ScaledSpaceFader s in scaledSpaceFaders)
                    {
                        s.r.enabled = true;
                    }
                    c.Render();
                    foreach (Renderer r in skyboxRenderers)
                    {
                        r.enabled = true;
                    }
                }
            }

            if (isFull)
            {
                fullTex.ReadPixels(fullRect, 0, 0);
                fullTex.Apply();

                byte[] bytes = fullTex.EncodeToPNG();

                if (!System.IO.Directory.Exists(CactEyeVars.root + "Screenshots/CactEye"))
                {
                    System.IO.Directory.CreateDirectory(CactEyeVars.root + "Screenshots/CactEye");
                }
                string filename = "Screenshots/CactEye/" + HighLogic.SaveFolder + "_" + targetName + "_" + CactEyeVars.Time() + ".png";

                System.IO.File.WriteAllBytes(CactEyeVars.root + filename, bytes);

                print("CactEye: saved screenshot to " + filename);

                RenderTexture.active = currentRT;
                return(filename);
            }
            else
            {
                outputTex.ReadPixels(smallRect, 0, 0);

                //grayscale!
                Color[] texColors = outputTex.GetPixels();
                for (int i = 0; i < texColors.Length; i++)
                {
                    float grayValue = texColors[i].grayscale;
                    texColors[i] = new Color(grayValue, grayValue, grayValue, texColors[i].a);
                }
                outputTex.SetPixels(texColors);
                outputTex.Apply();

                RenderTexture.active = currentRT;
                return("");
            }
        }