Example #1
0
        protected override void OnCompleted()
        {
            List <CelestialBody> PotentialDiscovery = new List <CelestialBody>();

            foreach (CelestialBody body in Database.instance.BodyList)
            {
                if (!Database.instance.CelestialBodies[body].isResearched && RBRange.WithinObsRange(body.transform))
                {
                    PotentialDiscovery.Add(body);
                }
            }
            if (PotentialDiscovery.Count > 0)
            {
                int           discovered = Random.Range(0, PotentialDiscovery.Count - 1);
                bool          withParent;
                CelestialBody parentBody;
                ResearchBodiesController.FoundBody(Database.instance.RB_SettingsParms.ScienceReward, PotentialDiscovery[discovered], out withParent, out parentBody);
                return;
            }
            Vector2   anchormin = new Vector2(0.5f, 0.5f);
            Vector2   anchormax = new Vector2(0.5f, 0.5f);
            string    msg       = "Despite our best efforts, we were unable to find anything intersting in the sky.";
            string    title     = "Research Bodies";
            UISkinDef skin      = HighLogic.UISkin;

            DialogGUIBase[] dialogGUIBase = new DialogGUIBase[1];
            dialogGUIBase[0] = new DialogGUIButton("Ok", delegate { });
            PopupDialog.SpawnPopupDialog(anchormin, anchormax,
                                         new MultiOptionDialog(title, msg, title, skin, dialogGUIBase), false, HighLogic.UISkin, true,
                                         string.Empty);
        }
Example #2
0
        protected override void OnCompleted()
        {
            foreach (CelestialBody body in Database.instance.BodyList)
            {
                if (Database.instance.CelestialBodies[body].isResearched && Database.instance.CelestialBodies[body].researchState < 100)
                {
                    if (RBRange.WithinObsRange(body.transform))
                    {
                        ResearchBodiesController.Research(body, 10);
                        return;
                    }
                }
            }
            Vector2   anchormin = new Vector2(0.5f, 0.5f);
            Vector2   anchormax = new Vector2(0.5f, 0.5f);
            string    msg       = "Despite our best efforts, we were unable to find anything new that's interesting in the sky.";
            string    title     = "Research Bodies";
            UISkinDef skin      = HighLogic.UISkin;

            DialogGUIBase[] dialogGUIBase = new DialogGUIBase[1];
            dialogGUIBase[0] = new DialogGUIButton("Ok", delegate { });
            PopupDialog.SpawnPopupDialog(anchormin, anchormax,
                                         new MultiOptionDialog(title, msg, title, skin, dialogGUIBase), false, HighLogic.UISkin, true,
                                         string.Empty);
        }
        public void Awake()
        {
            instance          = this;
            _startwindowId    = Utilities.getnextrandomInt();
            _hoverwindowId    = Utilities.getnextrandomInt();
            _RBwindowId       = Utilities.getnextrandomInt();
            _settingswindowId = Utilities.getnextrandomInt();

            RBMenuAppLToolBar = new AppLauncherToolBar("ResearchBodies", "ResearchBodies",
                                                       Textures.PathToolbarIconsPath + "/RBToolBaricon",
                                                       ApplicationLauncher.AppScenes.SPACECENTER,
                                                       (Texture)Textures.ApplauncherIcon, (Texture)Textures.ApplauncherIcon,
                                                       GameScenes.SPACECENTER);
        }
        void DrawWindow(int windowID)
        {
            GUIContent closeContent = new GUIContent(Textures.BtnRedCross, Localizer.Format("#autoLOC_RBodies_00050"));
            Rect       closeRect    = new Rect(windowRect.width - 21, 4, 16, 16);

            if (GUI.Button(closeRect, closeContent, Textures.ClosebtnStyle))
            {
                showGUI = !showGUI;
                return;
            }
            GUILayout.BeginVertical();
            scrollViewBodiesVector = GUILayout.BeginScrollView(scrollViewBodiesVector, GUILayout.MaxHeight(200f));
            GUILayout.BeginVertical();
            GUILayout.Label(Localizer.Format("#autoLOC_RBodies_00024"), Textures.sectionTitleStyle); //#autoLOC_RBodies_00024 = Available Bodies
            foreach (var body in Database.instance.CelestialBodies)
            {
                if (body.Value.isResearched)
                {
                    GUILayout.Label(body.Key.GetDisplayName().LocalizeRemoveGender() + " - " + body.Value.researchState.ToString("N0") + "%", Textures.PartListPartStyle);
                }
            }
            GUILayout.EndVertical();
            GUILayout.EndScrollView();

            scrollViewVector = GUILayout.BeginScrollView(scrollViewVector);
            GUILayout.BeginVertical();
            GUILayout.Label(Localizer.Format("#autoLOC_RBodies_00021", electricChargeRequest.ToString())); //#autoLOC_RBodies_00021 = Each use of the Telescope will use <<1>> Electric Charge
            if (GUILayout.Button(Localizer.Format("#autoLOC_RBodies_00022")))                              //#autoLOC_RBodies_00022 = Track Bodies
            {
                foundBody                = false;
                withParent               = false;
                foundBodyTooWeak         = false;
                searchButtonDisplayTimer = Planetarium.GetUniversalTime();
                searchButtonDisplay      = true;
                nothing = Database.instance.NothingHere[random.Next(Database.instance.NothingHere.Count)];
                BodiesInView.Clear();
                //Check part dependency.. Unusual, But ok.
                if (requiresPart)
                {
                    bool local = false;
                    foreach (Part part in this.vessel.Parts)
                    {
                        if (part.name.Contains(requiredPart))
                        {
                            local = true;
                        }
                    }
                    if (!local)
                    {
                        canResearch = false;
                        ScreenMessages.PostScreenMessage(Localizer.Format("#autoLOC_RBodies_00020", requiredPart), 5.0f, ScreenMessageStyle.UPPER_CENTER); //#autoLOC_RBodies_00020 = The vessel must have a <<1>> part attached to it!
                    }
                }

                if (canResearch)                                                                                           //Part check is OK
                {
                    var totalElecreceived = Utilities.RequestResource(this.part, "ElectricCharge", electricChargeRequest); //get power
                    if (totalElecreceived >= electricChargeRequest * 0.99)                                                 //If we got power
                    {
                        var randomMax = Database.instance.chances + difficulty;                                            //Calculate the randomness (sic) and if we found something. This needs to be replaced with something better.
                        var randomNum = random.Next(randomMax);
                        if (randomNum == 1 || randomNum == 2)
                        {
                            //Scan the list of CB's and find anything in range?
                            foreach (CelestialBody body in Database.instance.BodyList)
                            {
                                hostPos   = this.part.transform.position;
                                targetPos = body.transform.position;
                                angle     = Vector3.Angle(targetPos - hostPos, this.part.transform.up);
                                distance  = Vector3d.Distance(body.transform.position, this.vessel.transform.position);
                                //Is it within the acceptable Angle?
                                if (angle <= viewAngle)
                                {
                                    //Is it within the maximum tracking distance of this part?
                                    if (distance <= maxTrackDistance)
                                    {
                                        if (!IsViewObstructed(this.part.transform, body.transform))
                                        {
                                            BodiesInView.Add(body); //We got one!
                                        }
                                    }
                                    //Too far away.
                                    else
                                    {
                                        foundBodyTooWeak = true;
                                    }
                                }
                            }
                            if (BodiesInView.Count > 0)  //did we find anything?
                            {
                                //Remove any already researched.
                                BodiesInViewResearched.Clear();
                                for (int i = BodiesInView.Count - 1; i >= 0; --i)
                                {
                                    if (Database.instance.CelestialBodies[BodiesInView[i]].isResearched)
                                    {
                                        BodiesInViewResearched.Add(BodiesInView[i]);
                                    }
                                }
                                BodiesInViewResearched.ForEach(id => BodiesInView.Remove(id));
                                if (BodiesInView.Count > 0)                                                            //Do we still have any? If so:
                                {
                                    bodyFound = BodiesInView[random.Next(BodiesInView.Count)];                         //Randomly pick one.
                                    foundBody = true;
                                    ScreenMessages.PostScreenMessage(Localizer.Format("#autoLOC_RBodies_00051"), 15f); //#autoLOC_RBodies_00051 = Celestial Body Discovered!
                                    difficulty = startingdifficulty;                                                   //Reset the difficulty factor to the starting factor now that we found something.
                                    ResearchBodiesController.FoundBody(scienceReward, bodyFound, out withParent, out parentBody);
                                }
                            }
                        }
                        else
                        {
                            //We didn't find anything. Reduce the difficulty by one until we do.
                            foundBody = false;
                            if (randomMax > 2)
                            {
                                difficulty--;
                            }
                        }
                    }
                    else  // There wasn't enough EC!
                    {
                        ScreenMessages.PostScreenMessage(Localizer.Format("#autoLOC_RBodies_00048"), 5.0f, ScreenMessageStyle.UPPER_CENTER); //#autoLOC_RBodies_00048 = Not enough Electric Charge to operate the telescope.
                    }
                }
            } //endif button

            //Populate RB GUI if found.
            if (searchButtonDisplay)
            {
                if (Planetarium.GetUniversalTime() - searchButtonDisplayTimer > 60)
                {
                    searchButtonDisplayTimer = 0;
                    searchButtonDisplay      = false;
                }
                //Populate text box on discovery.
                if (foundBody)      //Did we end up finding anything?
                {
                    if (withParent) //And was a parent body also discovered?
                    {
                        GUILayout.Label(Localizer.Format("#autoLOC_RBodies_discovery_" + bodyFound.bodyName));
                        GUILayout.Label(Localizer.Format("#autoLOC_RBodies_discovery_" + parentBody.bodyName));
                    }
                    else
                    {
                        GUILayout.Label(Localizer.Format("#autoLOC_RBodies_discovery_" + bodyFound.bodyName));
                    }
                }
                else  //Nope, didn't find anything.
                {
                    if (foundBodyTooWeak) //Was there something just out of telescope range?
                    {
                        GUILayout.Label(Localizer.Format("#autoLOC_RBodies_00023"), HighLogic.Skin.label); //#autoLOC_RBodies_00023 = A faint signal has been detected but we need a more powerful Telescope.
                    }
                    else  //Nope there was absolutely nothing to see here.
                    {
                        GUILayout.Label(Localizer.Format(nothing), HighLogic.Skin.label);
                    }
                }
            }

            GUILayout.EndVertical();
            GUILayout.EndScrollView();
            GUILayout.EndVertical();
            GUI.DragWindow();
        }
Example #5
0
 public void Awake()
 {
     instance    = this;
     _RBwindowId = Utilities.getnextrandomInt();
 }