Esempio n. 1
0
 public void Downgrade()
 {
     KCTDebug.Log($"Downgrading {CommonName} to level {CurrentLevel}");
     if (IsLaunchpad)
     {
         KSC.LaunchPads[LaunchpadID].level = CurrentLevel;
         if (KCTGameStates.ActiveKSCName != KSC.KSCName || KCTGameStates.ActiveKSC.ActiveLaunchPadID != LaunchpadID)
         {
             return;
         }
     }
     foreach (UpgradeableFacility facility in GetFacilityReferences())
     {
         KCTEvents.AllowedToUpgrade = true;
         facility.SetLevel(CurrentLevel);
     }
 }
Esempio n. 2
0
        public KCT_TechItem(RDTech techNode)
        {
            scienceCost   = techNode.scienceCost;
            techName      = techNode.title;
            techID        = techNode.techID;
            progress      = 0;
            protoNode     = ResearchAndDevelopment.Instance.GetTechState(techID);
            UnlockedParts = new List <string>();
            foreach (AvailablePart p in techNode.partsPurchased)
            {
                UnlockedParts.Add(p.name);
            }

            KCTDebug.Log("techID = " + techID);
            //KCTDebug.Log("BuildRate = " + BuildRate);
            KCTDebug.Log("TimeLeft = " + TimeLeft);
        }
Esempio n. 3
0
        internal T getMember <T>(string name)
        {
            MemberInfo member = _menu.GetType().GetMember(name, BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.FlattenHierarchy)?.FirstOrDefault();

            if (member == null)
            {
                KCTDebug.Log($"Member was null when trying to find '{name}'", true);
                return(default(T));
            }
            object o = KCT_Utilities.GetMemberInfoValue(member, _menu);

            if (o is T)
            {
                return((T)o);
            }
            return(default(T));
        }
Esempio n. 4
0
 public void launchScreenOpenEvent(GameEvents.VesselSpawnInfo v)
 {
     if (!KCT_GUI.PrimarilyDisabled)
     {
         // PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), "Warning!", "To launch vessels you must first build them in the VAB or SPH, then launch them through the main KCT window in the Space Center!", "Ok", false, HighLogic.UISkin);
         //open the build list to the right page
         string selection = "VAB";
         if (v.craftSubfolder.Contains("SPH"))
         {
             selection = "SPH";
         }
         KCT_GUI.ClickOn();
         KCT_GUI.SelectList("");
         KCT_GUI.SelectList(selection);
         KCTDebug.Log("Opening the GUI to the " + selection);
     }
 }
Esempio n. 5
0
 private void UpdateRFTanks()
 {
     foreach (ConfigNode cn in shipNode.GetNodes("PART"))
     {
         foreach (ConfigNode module in cn.GetNodes("MODULE"))
         {
             if (module.GetValue("name") == "ModuleFuelTanks")
             {
                 if (module.HasValue("timestamp"))
                 {
                     KCTDebug.Log("Updating RF timestamp on a part");
                     module.SetValue("timestamp", Planetarium.GetUniversalTime().ToString());
                 }
             }
         }
     }
 }
Esempio n. 6
0
 private void UpdateRFTanks()
 {
     foreach (var cn in ShipNode.GetNodes("PART"))
     {
         foreach (var module in cn.GetNodes("MODULE"))
         {
             if (module.GetValue("name") == "ModuleFuelTanks")
             {
                 if (module.HasValue("timestamp"))
                 {
                     KCTDebug.Log("Updating RF timestamp on a part");
                     module.SetValue("timestamp", Utilities.GetUT().ToString());
                 }
             }
         }
     }
 }
        protected void LoadTree()
        {
            if (HighLogic.CurrentGame.Mode == Game.Modes.SCIENCE_SANDBOX || HighLogic.CurrentGame.Mode == Game.Modes.CAREER)
            {
                string fullPath = KSPUtil.ApplicationRootPath + HighLogic.CurrentGame.Parameters.Career.TechTreeUrl;
                KCTDebug.Log($"Loading tech tree from {fullPath}");

                ConfigNode fileNode = ConfigNode.Load(fullPath);
                if (fileNode != null && fileNode.HasNode("TechTree"))
                {
                    techNameToTitle.Clear();

                    ConfigNode   treeNode = fileNode.GetNode("TechTree");
                    ConfigNode[] ns       = treeNode.GetNodes("RDNode");
                    foreach (ConfigNode n in ns)
                    {
                        if (n.HasValue("id"))
                        {
                            string techID = n.GetValue("id");

                            if (n.HasValue("title"))
                            {
                                techNameToTitle[techID] = n.GetValue("title");
                            }

                            ConfigNode[]  parents = n.GetNodes("Parent");
                            List <string> pList   = new List <string>();
                            foreach (ConfigNode p in parents)
                            {
                                if (p.HasValue("parentID"))
                                {
                                    pList.Add(p.GetValue("parentID"));
                                }
                            }
                            techNameToParents[techID] = pList;

                            if (n.HasValue("anyToUnlock"))
                            {
                                techNameToAnyToUnlock[techID] = n.GetValue("anyToUnlock");
                            }
                        }
                    }
                }
            }
        }
Esempio n. 8
0
        public void RecalculateBuildRates()
        {
            VABRates.Clear();
            SPHRates.Clear();
            double rate  = 0.1;
            int    index = 0;

            // These loops could clean up a little, is it intended to add a rate=0 in the loop as the last entry?
            while (rate > 0)
            {
                rate = MathParser.ParseBuildRateFormula(BuildListVessel.ListType.VAB, index, this);
                if (rate >= 0)
                {
                    VABRates.Add(rate);
                }
                index++;
            }
            rate  = 0.1;
            index = 0;
            while (rate > 0)
            {
                rate = MathParser.ParseBuildRateFormula(BuildListVessel.ListType.SPH, index, this);
                if (rate >= 0)
                {
                    SPHRates.Add(rate);
                }
                index++;
            }

            var m = StringBuilderCache.Acquire();

            m.AppendLine("VAB Rates:");
            foreach (double v in VABRates)
            {
                m.AppendLine($"{v}");
            }

            m.AppendLine("SPH Rates:");
            foreach (double v in SPHRates)
            {
                m.AppendLine($"{v}");
            }

            KCTDebug.Log(m.ToStringAndRelease());
        }
Esempio n. 9
0
        private void SYReady()
        {
            if (HighLogic.LoadedSceneIsEditor && KCTGameStates.EditorShipEditingMode && KCTGameStates.EditedVessel != null)
            {
                KCTDebug.Log("Removing SY tracking of this vessel.");
                string id = ScrapYardWrapper.GetPartID(KCTGameStates.EditedVessel.ExtractedPartNodes[0]);
                ScrapYardWrapper.SetProcessedStatus(id, false);

                KCTDebug.Log("Adding parts back to inventory for editing...");
                foreach (ConfigNode partNode in KCTGameStates.EditedVessel.ExtractedPartNodes)
                {
                    if (ScrapYardWrapper.PartIsFromInventory(partNode))
                    {
                        ScrapYardWrapper.AddPartToInventory(partNode, false);
                    }
                }
            }
        }
Esempio n. 10
0
 public void Downgrade()
 {
     KCTDebug.Log("Downgrading " + commonName + " to level " + currentLevel);
     if (isLaunchpad)
     {
         KSC.LaunchPads[launchpadID].level = currentLevel;
         if (KCT_GameStates.activeKSCName != KSC.KSCName || KCT_GameStates.ActiveKSC.ActiveLaunchPadID != launchpadID)
         {
             return;
         }
     }
     foreach (Upgradeables.UpgradeableFacility facility in GetFacilityReferences())
     {
         KCT_Events.allowedToUpgrade = true;
         facility.SetLevel(currentLevel);
     }
     //KCT_Events.allowedToUpgrade = false;
 }
Esempio n. 11
0
 public void launchScreenOpenEvent(GameEvents.VesselSpawnInfo v)
 {
     if (!KCT_GUI.PrimarilyDisabled)
     {
         //KCT_GameStates.flightSimulated = true; //no longer needed b/c that gui wont appear anymore!
         // PopupDialog.SpawnPopupDialog("Warning!", "To launch vessels you must first build them in the VAB or SPH, then launch them through the main KCT window in the Space Center!", "Ok", false, HighLogic.Skin);
         //open the build list to the right page
         string selection = "VAB";
         if (v.craftSubfolder.Contains("SPH"))
         {
             selection = "SPH";
         }
         KCT_GUI.ClickOn();
         KCT_GUI.SelectList("");
         KCT_GUI.SelectList(selection);
         KCTDebug.Log("Opening the GUI to the " + selection);
     }
 }
Esempio n. 12
0
        public new void Start()
        {
            base.Start();
            if (KCT_GUI.IsPrimarilyDisabled)
            {
                return;
            }

            KCTDebug.Log("KCT_TS, Start");
            if (FindObjectOfType <SpaceTracking>() is SpaceTracking trackingStation)
            {
                _originalCallback = trackingStation.RecoverButton.onClick;
                _flyCallback      = trackingStation.FlyButton.onClick;

                trackingStation.RecoverButton.onClick = new Button.ButtonClickedEvent();
                trackingStation.RecoverButton.onClick.AddListener(NewRecoveryFunctionTrackingStation);
            }
        }
Esempio n. 13
0
        public new void Start()
        {
            base.Start();
            if (KCT_GUI.PrimarilyDisabled)
            {
                return;
            }
            KCTDebug.Log("KCT_Flight, Start");
            var altimeter = UnityEngine.Object.FindObjectOfType <AltimeterSliderButtons>();

            if (altimeter != null)
            {
                originalCallback = altimeter.vesselRecoveryButton.onClick;

                altimeter.vesselRecoveryButton.onClick = new Button.ButtonClickedEvent();
                altimeter.vesselRecoveryButton.onClick.AddListener(RecoverVessel);
            }
        }
Esempio n. 14
0
        private ValidationResult ProcessFundsChecks(BuildListVessel blv)
        {
            if (CheckAvailableFunds)
            {
                double totalCost = blv.GetTotalCost();
                double prevFunds = Funding.Instance.Funds;
                if (totalCost > prevFunds)
                {
                    KCTDebug.Log($"Tried to add {blv.ShipName} to build list but not enough funds.");
                    KCTDebug.Log($"Vessel cost: {Utilities.GetTotalVesselCost(blv.ShipNode)}, Current funds: {prevFunds}");
                    var msg = new ScreenMessage("Not Enough Funds To Build!", 4f, ScreenMessageStyle.UPPER_CENTER);
                    ScreenMessages.PostScreenMessage(msg);

                    return(ValidationResult.Fail);
                }
            }

            return(ValidationResult.Success);
        }
Esempio n. 15
0
        public void Update()
        {
            // Move constantly-checked things that don't need physics precision to here.
            if (HighLogic.LoadedScene == GameScenes.TRACKSTATION)
            {
                Utilities.SetActiveKSCToRSS();
            }

            ERClobberer.PollForChanges();

            if (!KCT_GUI.IsPrimarilyDisabled && HighLogic.LoadedScene == GameScenes.SPACECENTER &&
                VesselSpawnDialog.Instance?.Visible == true)
            {
                VesselSpawnDialog.Instance.ButtonClose();
                KCTDebug.Log("Attempting to close spawn dialog!");
            }

            UpdateRndScreen();
        }
Esempio n. 16
0
        internal KerbalConstructionTime()
        {
            instance = this;

            KCT_GameStates.settings.Load(); //Load the settings file, if it exists

            string SavedFile = KSPUtil.ApplicationRootPath + "/saves/" + HighLogic.SaveFolder + "/KCT_Settings.cfg";

            if (!System.IO.File.Exists(SavedFile))
            {
                KCT_GameStates.firstStart = true;
            }

            if (KCT_PresetManager.Instance == null)
            {
                KCT_PresetManager.Instance = new KCT_PresetManager();
            }
            KCT_PresetManager.Instance.SetActiveFromSaveData();

            if (ToolbarManager.ToolbarAvailable && ToolbarManager.Instance != null && KCT_GameStates.settings.PreferBlizzyToolbar)
            {
                KCTDebug.Log("Adding Toolbar Button");
                KCT_GameStates.kctToolbarButton = ToolbarManager.Instance.add("Kerbal_Construction_Time", "MainButton");
                if (KCT_GameStates.kctToolbarButton != null)
                {
                    if (KCT_PresetManager.PresetLoaded() && !KCT_PresetManager.Instance.ActivePreset.generalSettings.Enabled)
                    {
                        KCT_GameStates.kctToolbarButton.Visibility = new GameScenesVisibility(GameScenes.SPACECENTER);
                    }
                    else
                    {
                        KCT_GameStates.kctToolbarButton.Visibility = new GameScenesVisibility(new GameScenes[] { GameScenes.SPACECENTER, GameScenes.FLIGHT, GameScenes.TRACKSTATION, GameScenes.EDITOR });
                    }
                    KCT_GameStates.kctToolbarButton.TexturePath = KCT_Utilities.GetButtonTexture();
                    KCT_GameStates.kctToolbarButton.ToolTip     = "Kerbal Construction Time";
                    KCT_GameStates.kctToolbarButton.OnClick    += ((e) =>
                    {
                        KCT_GUI.ClickToggle();
                    });
                }
            }
        }
Esempio n. 17
0
        public void FacilityUpgradedEvent(Upgradeables.UpgradeableFacility facility, int lvl)
        {
            if (KCT_GUI.IsPrimarilyDisabled)
            {
                return;
            }

            KCTDebug.Log($"Facility {facility.id} upgraded to lvl {lvl}");
            AllowedToUpgrade = false;
            foreach (KSCItem ksc in KCTGameStates.KSCs)
            {
                ksc.RecalculateBuildRates();
                ksc.RecalculateUpgradedBuildRates();
            }
            for (int i = KCTGameStates.TechList.Count - 1; i >= 0; i--)
            {
                TechItem tech = KCTGameStates.TechList[i];
                tech.UpdateBuildRate(KCTGameStates.TechList.IndexOf(tech));
            }
        }
Esempio n. 18
0
        internal T getMember <T>(int index)
        {
            IEnumerable <MemberInfo> memberList = _menu.GetType().GetMembers(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.FlattenHierarchy).Where(m => m.ToString().Contains(typeof(T).ToString()));

            KCTDebug.Log($"Found {memberList.Count()} matches for {typeof(T)}");
            MemberInfo member = memberList.Count() >= index?memberList.ElementAt(index) : null;

            if (member == null)
            {
                KCTDebug.Log($"Member was null when trying to find element at index {index} for type '{typeof(T).ToString()}'", true);
                return(default(T));
            }
            object o = KCT_Utilities.GetMemberInfoValue(member, _menu);

            if (o is T)
            {
                return((T)o);
            }
            return(default(T));
        }
Esempio n. 19
0
        public new void Start()
        {
            base.Start();
            if (KCT_GUI.PrimarilyDisabled)
            {
                return;
            }

            KCTDebug.Log("KCT_Flight, Start");
            SpaceTracking trackingStation = UnityEngine.Object.FindObjectOfType <SpaceTracking>();

            if (trackingStation != null)
            {
                originalCallback = trackingStation.RecoverButton.onClick;
                flyCallback      = trackingStation.FlyButton.onClick;

                trackingStation.RecoverButton.onClick = new Button.ButtonClickedEvent();
                trackingStation.RecoverButton.onClick.AddListener(NewRecoveryFunctionTrackingStation);
            }
        }
Esempio n. 20
0
        public void FacilityUpgradedEvent(Upgradeables.UpgradeableFacility facility, int lvl)
        {
            if (KCT_GUI.PrimarilyDisabled)
            {
                bool isLaunchpad = facility.id.ToLower().Contains("launchpad");
                if (!isLaunchpad)
                {
                    return;
                }

                //is a launch pad
                KCT_GameStates.ActiveKSC.ActiveLPInstance.Upgrade(lvl);
            }

            KCTDebug.Log("Facility " + facility.id + " upgraded to lvl " + lvl);
            if (facility.id.ToLower().Contains("launchpad"))
            {
                if (!allowedToUpgrade)
                {
                    KCT_GameStates.ActiveKSC.ActiveLPInstance.Upgrade(lvl); //also repairs the launchpad
                }
                else
                {
                    KCT_GameStates.ActiveKSC.ActiveLPInstance.level = lvl;
                }
            }
            allowedToUpgrade = false;
            foreach (KCT_KSC ksc in KCT_GameStates.KSCs)
            {
                ksc.RecalculateBuildRates();
                ksc.RecalculateUpgradedBuildRates();
            }
            for (int i = KCT_GameStates.TechList.Count - 1; i >= 0; i--)
            {
                KCT_TechItem tech = KCT_GameStates.TechList[i];

                //foreach (KCT_TechItem tech in KCT_GameStates.TechList)
                //{
                tech.UpdateBuildRate(KCT_GameStates.TechList.IndexOf(tech));
            }
        }
Esempio n. 21
0
        private void ProcessSimulation()
        {
            HighLogic.CurrentGame.Parameters.Flight.CanAutoSave = false;

            SimulationParams simParams = KCTGameStates.SimulationParams;

            if (FlightGlobals.ActiveVessel.loaded && !FlightGlobals.ActiveVessel.packed && !simParams.IsVesselMoved)
            {
                if (simParams.DisableFailures)
                {
                    Utilities.ToggleFailures(!simParams.DisableFailures);
                }

                if (!simParams.SimulateInOrbit || !FlightDriver.CanRevertToPrelaunch)
                {
                    // Either the player does not want to start in orbit or they saved and then loaded back into that save
                    simParams.IsVesselMoved = true;
                    return;
                }

                int secondsForMove = simParams.DelayMoveSeconds;
                if (_simMoveDeferTime == DateTime.MaxValue)
                {
                    _simMoveDeferTime = DateTime.Now;
                }
                else if (DateTime.Now.CompareTo(_simMoveDeferTime.AddSeconds(secondsForMove)) > 0)
                {
                    KCTDebug.Log($"Moving vessel to orbit. {simParams.SimulationBody.bodyName}:{simParams.SimOrbitAltitude}:{simParams.SimInclination}");
                    HyperEdit_Utilities.PutInOrbitAround(simParams.SimulationBody, simParams.SimOrbitAltitude, simParams.SimInclination);
                    simParams.IsVesselMoved = true;
                    _simMoveDeferTime       = DateTime.MaxValue;
                }

                if (_simMoveDeferTime != DateTime.MaxValue && _simMoveSecondsRemain != (_simMoveDeferTime.AddSeconds(secondsForMove) - DateTime.Now).Seconds)
                {
                    double remaining = (_simMoveDeferTime.AddSeconds(secondsForMove) - DateTime.Now).TotalSeconds;
                    ScreenMessages.PostScreenMessage($"Moving vessel in {Math.Round(remaining)} seconds", (float)(remaining - Math.Floor(remaining)), ScreenMessageStyle.UPPER_CENTER);
                    _simMoveSecondsRemain = (int)remaining;
                }
            }
        }
Esempio n. 22
0
        public static object GetPrivateMemberValue(this Type type, string name, object instance, int index = -1)
        {
            BindingFlags flags = BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.FlattenHierarchy;
            object       value = Utilities.GetMemberInfoValue(type.GetMember(name, flags).FirstOrDefault(), instance);

            if (value != null)
            {
                return(value);
            }

            KCTDebug.Log($"Could not get value by name '{name}', getting by index '{index}'");
            if (index >= 0)
            {
                List <MemberInfo> members = type.GetMembers(flags).ToList();
                if (members.Count > index)
                {
                    return(Utilities.GetMemberInfoValue(members[index], instance));
                }
            }
            throw new Exception($"No members found for name '{name}' at index '{index}' for type '{type}'");
        }
Esempio n. 23
0
        public void RecalculateBuildRates()
        {
            VABRates.Clear();
            SPHRates.Clear();
            double rate  = 0.1;
            int    index = 0;

            while (rate > 0)
            {
                rate = KCT_MathParsing.ParseBuildRateFormula(KCT_BuildListVessel.ListType.VAB, index, this);
                if (rate >= 0)
                {
                    VABRates.Add(rate);
                }
                index++;
            }
            rate  = 0.1;
            index = 0;
            while (rate > 0)
            {
                rate = KCT_MathParsing.ParseBuildRateFormula(KCT_BuildListVessel.ListType.SPH, index, this);
                if (rate >= 0)
                {
                    SPHRates.Add(rate);
                }
                index++;
            }

            KCTDebug.Log("VAB Rates:");
            foreach (double v in VABRates)
            {
                KCTDebug.Log(v);
            }

            KCTDebug.Log("SPH Rates:");
            foreach (double v in SPHRates)
            {
                KCTDebug.Log(v);
            }
        }
Esempio n. 24
0
 public KCT_Recon_Rollout(Vessel vessel, RolloutReconType type, string id, string launchSite)
 {
     RRType       = type;
     associatedID = id;
     launchPadID  = launchSite;
     KCTDebug.Log("New recon_rollout at launchsite: " + launchPadID);
     //BP = vessel.GetTotalMass() * KCT_GameStates.timeSettings.ReconditioningEffect * KCT_GameStates.timeSettings.OverallMultiplier; //1 day per 50 tons (default) * overall multiplier
     //BP = KCT_MathParsing.GetStandardFormulaValue("Reconditioning", new Dictionary<string, string>() {{"M", vessel.GetTotalMass().ToString()}, {"O", KCT_PresetManager.Instance.ActivePreset.timeSettings.OverallMultiplier.ToString()},
     //    {"E", KCT_PresetManager.Instance.ActivePreset.timeSettings.ReconditioningEffect.ToString()}, {"X", KCT_PresetManager.Instance.ActivePreset.timeSettings.MaxReconditioning.ToString()}});
     //if (BP > KCT_GameStates.timeSettings.MaxReconditioning) BP = KCT_GameStates.timeSettings.MaxReconditioning;
     progress = 0;
     if (type == RolloutReconType.Reconditioning)
     {
         BP = KCT_MathParsing.ParseReconditioningFormula(new KCT_BuildListVessel(vessel), true);
         //BP *= (1 - KCT_PresetManager.Instance.ActivePreset.timeSettings.RolloutReconSplit);
         name = "LaunchPad Reconditioning";
     }
     else if (type == RolloutReconType.Rollout)
     {
         BP = KCT_MathParsing.ParseReconditioningFormula(new KCT_BuildListVessel(vessel), false);
         //BP *= KCT_PresetManager.Instance.ActivePreset.timeSettings.RolloutReconSplit;
         name = "Vessel Rollout";
     }
     else if (type == RolloutReconType.Rollback)
     {
         BP = KCT_MathParsing.ParseReconditioningFormula(new KCT_BuildListVessel(vessel), false);
         //BP *= KCT_PresetManager.Instance.ActivePreset.timeSettings.RolloutReconSplit;
         name     = "Vessel Rollback";
         progress = BP;
     }
     else if (type == RolloutReconType.Recovery)
     {
         //BP *= KCT_PresetManager.Instance.ActivePreset.timeSettings.RolloutReconSplit;
         BP   = KCT_MathParsing.ParseReconditioningFormula(new KCT_BuildListVessel(vessel), false);
         name = "Vessel Recovery";
         double KSCDistance = (float)SpaceCenter.Instance.GreatCircleDistance(SpaceCenter.Instance.cb.GetRelSurfaceNVector(vessel.latitude, vessel.longitude));
         double maxDist     = SpaceCenter.Instance.cb.Radius * Math.PI;
         BP += BP * (KSCDistance / maxDist);
     }
 }
Esempio n. 25
0
        public void SetActiveFromSaveData()
        {
            if (Config == null)
            {
                Config = new LRTRHomeWorldParameters();
                foreach (ConfigNode stg in GameDatabase.Instance.GetConfigNodes("HOMEWORLDPARAMETERS"))
                {
                    Config.Load(stg);
                }
            }

            if (File.Exists(SettingsFilePath))
            {
                KCT_Preset saved  = new KCT_Preset(SettingsFilePath);
                KCT_Preset source = FindPresetByShortName(saved.ShortName);
                if (source != null) //Get settings from the original preset, if it exists
                {
                    ActivePreset = source;
                    KCTDebug.Log("Loading settings from preset, rather than save. Name: " + ActivePreset.Name);
                }
                else
                {
                    ActivePreset = saved;
                    KCTDebug.Log("Loading saved settings.");
                }
            }
            else
            {
                KCT_Preset defaultSettings = FindPresetByShortName(Config.kctPresetShortName);
                if (defaultSettings != null)
                {
                    ActivePreset = defaultSettings;
                }
                else
                {
                    ActivePreset = new KCT_Preset("UNINIT", "UNINIT", "NA", "NA");
                }
            }
        }
Esempio n. 26
0
        public void Upgrade()
        {
            KCTDebug.Log("Upgrading " + commonName + " to level " + upgradeLevel);
            if (isLaunchpad)
            {
                KSC.LaunchPads[launchpadID].level           = upgradeLevel;
                KSC.LaunchPads[launchpadID].DestructionNode = new ConfigNode("DestructionState");
                if (KCT_GameStates.activeKSCName != KSC.KSCName || KCT_GameStates.ActiveKSC.ActiveLaunchPadID != launchpadID)
                {
                    UpgradeProcessed = true;
                    return;
                }
                KSC.LaunchPads[launchpadID].Upgrade(upgradeLevel);
            }
            foreach (Upgradeables.UpgradeableFacility facility in GetFacilityReferences())
            {
                KCT_Events.allowedToUpgrade = true;
                facility.SetLevel(upgradeLevel);
            }
            UpgradeProcessed = ((int)(ScenarioUpgradeableFacilities.GetFacilityLevel(id) * 2) == upgradeLevel);

            //KCT_Events.allowedToUpgrade = false;
        }
Esempio n. 27
0
        private void UpdateRFTanks()
        {
            var nodes = ShipNode.GetNodes("PART");

            for (int i = nodes.Count() - 1; i >= 0; i--)
            {
                ConfigNode cn = nodes[i];

                var modules = cn.GetNodes("MODULE");
                for (int im = modules.Count() - 1; im >= 0; im--)
                {
                    ConfigNode module = modules[im];
                    if (module.GetValue("name") == "ModuleFuelTanks")
                    {
                        if (module.HasValue("timestamp"))
                        {
                            KCTDebug.Log("Updating RF timestamp on a part");
                            module.SetValue("timestamp", Utilities.GetUT().ToString());
                        }
                    }
                }
            }
        }
Esempio n. 28
0
        public void FindPresetFiles()
        {
            PresetPaths.Clear();
            //Check the KCT folder first
            foreach (string dir2 in Directory.GetDirectories(KSPUtil.ApplicationRootPath + "GameData/KerbalConstructionTime"))
            {
                if (dir2.Contains("KCT_Presets")) //Found a presets folder
                {
                    //Add all the files in the folder
                    foreach (string file in Directory.GetFiles(dir2, "*.cfg"))
                    {
                        KCTDebug.Log("Found preset at " + file);
                        PresetPaths.Add(file);
                    }
                }
            }

            foreach (string dir in Directory.GetDirectories(KSPUtil.ApplicationRootPath + "GameData/"))
            {
                if (dir.Contains("KerbalConstructionTime"))
                {
                    continue;                                         //Don't check the KCT folder again
                }
                foreach (string dir2 in Directory.GetDirectories(dir))
                {
                    if (dir2.Contains("KCT_Presets")) //Found a presets folder
                    {
                        //Add all the files in the folder
                        foreach (string file in Directory.GetFiles(dir2, "*.cfg"))
                        {
                            KCTDebug.Log("Found preset at " + file);
                            PresetPaths.Add(file);
                        }
                    }
                }
            }
        }
Esempio n. 29
0
        public IEnumerator OnContextMenuSpawn()
        {
            yield return(new WaitForFixedUpdate());

            if (KCT_PresetManager.Instance.ActivePreset.generalSettings.KSCUpgradeTimes && _menu != null)
            {
                SpaceCenterBuilding hostBuilding = getMember <SpaceCenterBuilding>("host");
                KCTDebug.Log("Trying to override upgrade button of menu for " + hostBuilding.facilityName);
                Button button = getMember <Button>("UpgradeButton");
                if (button == null)
                {
                    KCTDebug.Log("Could not find UpgradeButton by name, using index instead.", true);
                    button = getMember <UnityEngine.UI.Button>(2);
                }

                if (button != null)
                {
                    KCTDebug.Log("Found upgrade button, overriding it.");
                    button.onClick = new Button.ButtonClickedEvent();    //Clear existing KSP listener
                    button.onClick.AddListener(HandleUpgrade);

                    if (KCT_PresetManager.Instance.ActivePreset.generalSettings.DisableLPUpgrades &&
                        GetFacilityID().ToLower().Contains("launchpad"))
                    {
                        button.interactable = false;
                        var hov = button.gameObject.GetComponent <UIOnHover>();
                        hov.gameObject.DestroyGameObject();

                        _menu.levelStatsText.text = "<color=red><b>Launchpads cannot be upgraded. Build a new launchpad from the KCT menu instead.</b></color>";
                    }
                }
                else
                {
                    throw new Exception("UpgradeButton not found. Cannot override.");
                }
            }
        }
Esempio n. 30
0
        public IEnumerator OnContextMenuSpawn()
        {
            yield return(new WaitForFixedUpdate());

            if (PresetManager.Instance.ActivePreset.GeneralSettings.KSCUpgradeTimes && _menu != null)
            {
                SpaceCenterBuilding hostBuilding = GetMember <SpaceCenterBuilding>("host");
                KCTDebug.Log($"Trying to override upgrade button of menu for {hostBuilding.facilityName}");
                Button button = GetMember <Button>("UpgradeButton");
                if (button == null)
                {
                    KCTDebug.Log("Could not find UpgradeButton by name, using index instead.");
                    button = GetMember <Button>(2);
                }

                if (button != null)
                {
                    KCTDebug.Log("Found upgrade button, overriding it.");
                    button.onClick = new Button.ButtonClickedEvent();    //Clear existing KSP listener
                    button.onClick.AddListener(HandleUpgrade);

                    if ((PresetManager.Instance.ActivePreset.GeneralSettings.DisableLPUpgrades &&
                         GetFacilityID().IndexOf("launchpad", StringComparison.OrdinalIgnoreCase) >= 0) ||
                        (PresetManager.Instance.ActivePreset.GeneralSettings.CommonBuildLine &&
                         GetFacilityID().IndexOf("SpaceplaneHangar", StringComparison.OrdinalIgnoreCase) >= 0))
                    {
                        button.interactable = false;
                        var hov = button.gameObject.GetComponent <UIOnHover>();
                        hov.gameObject.DestroyGameObject();
                    }
                }
                else
                {
                    throw new Exception("UpgradeButton not found. Cannot override.");
                }
            }
        }