Esempio n. 1
0
        public void Launch(bool fillFuel = false)
        {
            HighLogic.CurrentGame.editorFacility = GetEditorFacility() == EditorFacilities.VAB ? EditorFacility.VAB : EditorFacility.SPH;

            string tempFile = $"{KSPUtil.ApplicationRootPath}saves/{HighLogic.SaveFolder}/Ships/temp.craft";

            UpdateRFTanks();
            if (fillFuel)
            {
                FillUnlockedFuelTanks();
            }
            ShipNode.Save(tempFile);
            string launchSite = LaunchSite;

            if (launchSite == "LaunchPad")
            {
                KCT_LaunchPad pad = null;
                if (LaunchSiteID >= 0)
                {
                    pad = KCTGameStates.ActiveKSC.LaunchPads[LaunchSiteID];
                }
                else
                {
                    pad = KCTGameStates.ActiveKSC.ActiveLPInstance;
                }

                launchSite = pad.launchSiteName;
            }
            FlightDriver.StartWithNewLaunch(tempFile, Flag, launchSite, new VesselCrewManifest());
            if (KCTGameStates.AirlaunchParams != null)
            {
                KCTGameStates.AirlaunchParams.KSPVesselId = null;
            }
        }
Esempio n. 2
0
 public static void DrawRenameWindow(int windowID)
 {
     GUILayout.BeginVertical();
     GUILayout.Label("Name:");
     _newName = GUILayout.TextField(_newName);
     GUILayout.BeginHorizontal();
     if (GUILayout.Button("Save"))
     {
         if (!_isRenamingLaunchPad)
         {
             BuildListVessel b = Utilities.FindBLVesselByID(_selectedVesselId);
             b.ShipName = _newName; //Change the name from our point of view
             b.ShipNode.SetValue("ship", _newName);
         }
         else
         {
             KCT_LaunchPad lp = KCTGameStates.ActiveKSC.ActiveLPInstance;
             lp.Rename(_newName);
         }
         GUIStates.ShowRename         = false;
         _centralWindowPosition.width = 150;
         _centralWindowPosition.x     = (Screen.width - 150) / 2;
         GUIStates.ShowBuildList      = true;
     }
     if (GUILayout.Button("Cancel"))
     {
         _centralWindowPosition.width = 150;
         _centralWindowPosition.x     = (Screen.width - 150) / 2;
         GUIStates.ShowRename         = false;
         GUIStates.ShowBuildList      = true;
     }
     GUILayout.EndHorizontal();
     GUILayout.EndVertical();
     CenterWindow(ref _centralWindowPosition);
 }
Esempio n. 3
0
        public static void DrawDismantlePadWindow(int windowID)
        {
            GUILayout.BeginVertical();
            GUILayout.Label("Are you sure you want to dismantle the currently selected launch pad? This cannot be undone!");
            GUILayout.BeginHorizontal();

            if (GUILayout.Button("Yes"))
            {
                if (KCTGameStates.ActiveKSC.LaunchPadCount < 2)
                {
                    return;
                }

                KCT_LaunchPad lpToDel = KCTGameStates.ActiveKSC.ActiveLPInstance;
                if (!lpToDel.Delete(out string err))
                {
                    ScreenMessages.PostScreenMessage("Dismantle failed: " + err, 5f, ScreenMessageStyle.UPPER_CENTER);
                }

                GUIStates.ShowDismantlePad = false;
                GUIStates.ShowBuildList    = true;
            }

            if (GUILayout.Button("No"))
            {
                _centralWindowPosition.width = 150;
                _centralWindowPosition.x     = (Screen.width - 150) / 2;
                GUIStates.ShowDismantlePad   = false;
                GUIStates.ShowBuildList      = true;
            }

            GUILayout.EndHorizontal();
            GUILayout.EndVertical();
            CenterWindow(ref _centralWindowPosition);
        }
Esempio n. 4
0
        private static void LoadPadNamesAndCosts()
        {
            KCT_LaunchPad lp           = KCTGameStates.ActiveKSC.ActiveLPInstance;
            var           list         = lp.GetUpgradeableFacilityReferences();
            var           upgdFacility = list[0];
            var           padUpgdLvls  = upgdFacility.UpgradeLevels;

            _padLvlOptions = new string[padUpgdLvls.Length];
            _padCosts      = new double[padUpgdLvls.Length];

            for (int i = 0; i < padUpgdLvls.Length; i++)
            {
                float limit  = GameVariables.Instance.GetCraftMassLimit((float)i / (float)upgdFacility.MaxLevel, true);
                var   sLimit = limit == float.MaxValue ? "unlimited" : $"max {limit} tons";
                _padLvlOptions[i] = $"Level {i + 1} ({sLimit})";

                if (i > 0)
                {
                    var lvl = padUpgdLvls[i];
                    _padCosts[i] = _padCosts[i - 1] + lvl.levelCost;
                }
                else
                {
                    // Use the KCT formula for determining the cost of first level
                    _padCosts[0] = _costOfNewLP;
                }
            }
        }
Esempio n. 5
0
        public void IncrementProgress(double UTDiff)
        {
            if (!IsComplete())
            {
                AddProgress(GetBuildRate() * UTDiff);
            }
            if (HighLogic.LoadedScene == GameScenes.SPACECENTER && (IsComplete() || !PresetManager.Instance.ActivePreset.GeneralSettings.KSCUpgradeTimes))
            {
                if (ScenarioUpgradeableFacilities.Instance != null && !KCTGameStates.ErroredDuringOnLoad)
                {
                    KCT_LaunchPad lp = KSC.LaunchPads[LaunchpadIndex];
                    lp.isOperational   = true;
                    lp.DestructionNode = new ConfigNode("DestructionState");
                    UpgradeProcessed   = true;

                    try
                    {
                        KCTEvents.OnPadConstructionComplete?.Fire(this, lp);
                    }
                    catch (Exception ex)
                    {
                        Debug.LogException(ex);
                    }
                }
            }
        }
Esempio n. 6
0
        private static void LoadPadNamesAndCosts()
        {
            var upgdFacility = KCT_LaunchPad.GetUpgradeableFacilityReference();
            var padUpgdLvls  = upgdFacility.UpgradeLevels;

            _padLvlOptions = new string[padUpgdLvls.Length + 1];
            _padLvlOptions[padUpgdLvls.Length] = "Custom";
            _padCosts = new double[padUpgdLvls.Length];
            _padSizes = new Vector3[padUpgdLvls.Length];
            _padTons  = new float[padUpgdLvls.Length];

            for (int i = 0; i < padUpgdLvls.Length; i++)
            {
                float normalizedLevel = (float)i / (float)upgdFacility.MaxLevel;
                float limit           = GameVariables.Instance.GetCraftMassLimit(normalizedLevel, true);
                _padTons[i] = limit;
                var sLimit = limit == float.MaxValue ? "unlimited" : $"max {limit} tons";
                _padLvlOptions[i] = $"Level {i + 1} ({sLimit})";

                Vector3 sizeLimit = GameVariables.Instance.GetCraftSizeLimit(normalizedLevel, true);
                _padSizes[i] = sizeLimit;

                if (i > 0)
                {
                    var lvl = padUpgdLvls[i];
                    _padCosts[i] = _padCosts[i - 1] + lvl.levelCost;
                }
                else
                {
                    // Use the KCT formula for determining the cost of first level
                    _padCosts[0] = _costOfNewLP;
                }
            }
        }
Esempio n. 7
0
        public static void CreateNewPad(string padName, int padLevel)
        {
            KCT_LaunchPad lp = ActiveKSC.ActiveLPInstance;

            if (lp.GetUpgradeableFacilityReferences()?[0]?.UpgradeLevels is UpgradeableObject.UpgradeLevel[] padUpgdLvls)
            {
                padLevel = UnityEngine.Mathf.Clamp(padLevel, 1, padUpgdLvls.Length);
                ActiveKSC.LaunchPads.Add(new KCT_LaunchPad(padName, padLevel));
            }
        }
Esempio n. 8
0
        public List <string> MeetsFacilityRequirements(bool highestFacility = true)
        {
            List <string> failedReasons = new List <string>();

            if (!Utilities.CurrentGameIsCareer())
            {
                return(failedReasons);
            }

            ShipTemplate template = new ShipTemplate();

            template.LoadShip(ShipNode);

            if (Type == ListType.VAB)
            {
                KCT_LaunchPad selectedPad = highestFacility ? KCTGameStates.ActiveKSC.GetHighestLevelLaunchPad() : KCTGameStates.ActiveKSC.ActiveLPInstance;
                float         launchpadNormalizedLevel = 1f * selectedPad.level / KCTGameStates.BuildingMaxLevelCache["LaunchPad"];

                double totalMass = GetTotalMass();
                if (totalMass > GameVariables.Instance.GetCraftMassLimit(launchpadNormalizedLevel, true))
                {
                    failedReasons.Add($"Mass limit exceeded, currently at {totalMass:N} tons");
                }
                if (ExtractedPartNodes.Count > GameVariables.Instance.GetPartCountLimit(ScenarioUpgradeableFacilities.GetFacilityLevel(SpaceCenterFacility.VehicleAssemblyBuilding), true))
                {
                    failedReasons.Add("Part Count limit exceeded");
                }
                CraftWithinSizeLimits sizeCheck = new CraftWithinSizeLimits(template, SpaceCenterFacility.LaunchPad, GameVariables.Instance.GetCraftSizeLimit(launchpadNormalizedLevel, true));
                if (!sizeCheck.Test())
                {
                    failedReasons.Add("Size limits exceeded");
                }
            }
            else if (Type == ListType.SPH)
            {
                double totalMass = GetTotalMass();
                if (totalMass > GameVariables.Instance.GetCraftMassLimit(ScenarioUpgradeableFacilities.GetFacilityLevel(SpaceCenterFacility.Runway), false))
                {
                    failedReasons.Add($"Mass limit exceeded, currently at {totalMass:N} tons");
                }
                if (ExtractedPartNodes.Count > GameVariables.Instance.GetPartCountLimit(ScenarioUpgradeableFacilities.GetFacilityLevel(SpaceCenterFacility.SpaceplaneHangar), false))
                {
                    failedReasons.Add("Part Count limit exceeded");
                }
                CraftWithinSizeLimits sizeCheck = new CraftWithinSizeLimits(template, SpaceCenterFacility.Runway, GameVariables.Instance.GetCraftSizeLimit(ScenarioUpgradeableFacilities.GetFacilityLevel(SpaceCenterFacility.Runway), false));
                if (!sizeCheck.Test())
                {
                    failedReasons.Add("Size limits exceeded");
                }
            }

            return(failedReasons);
        }
Esempio n. 9
0
        /// <summary>
        /// Finds the highest level LaunchPad on the KSC
        /// </summary>
        /// <returns>The instance of the highest level LaunchPad</returns>
        public KCT_LaunchPad GetHighestLevelLaunchPad()
        {
            KCT_LaunchPad highest = LaunchPads.First(p => p.isOperational);

            foreach (var pad in LaunchPads)
            {
                if (pad.isOperational && pad.level > highest.level)
                {
                    highest = pad;
                }
            }
            return(highest);
        }
Esempio n. 10
0
        /// <summary>
        /// Finds the highest level LaunchPad on the KSC
        /// </summary>
        /// <returns>The instance of the highest level LaunchPad</returns>
        public KCT_LaunchPad GetHighestLevelLaunchPad()
        {
            KCT_LaunchPad highest = LaunchPads[0];

            foreach (KCT_LaunchPad pad in LaunchPads)
            {
                if (pad.level > highest.level)
                {
                    highest = pad;
                }
            }
            return(highest);
        }
Esempio n. 11
0
        /// <summary>
        /// Finds the highest level LaunchPad on the KSC
        /// </summary>
        /// <returns>The instance of the highest level LaunchPad</returns>
        public KCT_LaunchPad GetHighestLevelLaunchPad()
        {
            KCT_LaunchPad highest = LaunchPads[0];

            for (int i = LaunchPads.Count - 1; i >= 0; i--)
            {
                KCT_LaunchPad pad = LaunchPads[i];
                if (pad.level > highest.level)
                {
                    highest = pad;
                }
            }
            return(highest);
        }
Esempio n. 12
0
        public KCT_KSC FromConfigNode(ConfigNode node)
        {
            VABUpgrades.Clear();
            SPHUpgrades.Clear();
            RDUpgrades.Clear();
            VABList.Clear();
            VABWarehouse.Clear();
            SPHList.Clear();
            SPHWarehouse.Clear();
            KSCTech.Clear();
            //TechList.Clear();
            Recon_Rollout.Clear();
            VABRates.Clear();
            SPHRates.Clear();



            this.KSCName = node.GetValue("KSCName");
            if (!int.TryParse(node.GetValue("ActiveLPID"), out this.ActiveLaunchPadID))
            {
                this.ActiveLaunchPadID = 0;
            }
            ConfigNode vabup = node.GetNode("VABUpgrades");

            foreach (string upgrade in vabup.GetValues("Upgrade"))
            {
                this.VABUpgrades.Add(int.Parse(upgrade));
            }
            ConfigNode sphup = node.GetNode("SPHUpgrades");

            foreach (string upgrade in sphup.GetValues("Upgrade"))
            {
                this.SPHUpgrades.Add(int.Parse(upgrade));
            }
            ConfigNode rdup = node.GetNode("RDUpgrades");

            foreach (string upgrade in rdup.GetValues("Upgrade"))
            {
                this.RDUpgrades.Add(int.Parse(upgrade));
            }

            ConfigNode tmp = node.GetNode("VABList");

            foreach (ConfigNode vessel in tmp.GetNodes("KCTVessel"))
            {
                KCT_BuildListStorage.BuildListItem listItem = new KCT_BuildListStorage.BuildListItem();
                ConfigNode.LoadObjectFromConfig(listItem, vessel);
                KCT_BuildListVessel blv = listItem.ToBuildListVessel();
                blv.shipNode = vessel.GetNode("ShipNode");
                blv.KSC      = this;
                this.VABList.Add(blv);
            }

            tmp = node.GetNode("SPHList");
            foreach (ConfigNode vessel in tmp.GetNodes("KCTVessel"))
            {
                KCT_BuildListStorage.BuildListItem listItem = new KCT_BuildListStorage.BuildListItem();
                ConfigNode.LoadObjectFromConfig(listItem, vessel);
                KCT_BuildListVessel blv = listItem.ToBuildListVessel();
                blv.shipNode = vessel.GetNode("ShipNode");
                blv.KSC      = this;
                this.SPHList.Add(blv);
            }

            tmp = node.GetNode("VABWarehouse");
            foreach (ConfigNode vessel in tmp.GetNodes("KCTVessel"))
            {
                KCT_BuildListStorage.BuildListItem listItem = new KCT_BuildListStorage.BuildListItem();
                ConfigNode.LoadObjectFromConfig(listItem, vessel);
                KCT_BuildListVessel blv = listItem.ToBuildListVessel();
                blv.shipNode = vessel.GetNode("ShipNode");
                blv.KSC      = this;
                this.VABWarehouse.Add(blv);
            }

            tmp = node.GetNode("SPHWarehouse");
            foreach (ConfigNode vessel in tmp.GetNodes("KCTVessel"))
            {
                KCT_BuildListStorage.BuildListItem listItem = new KCT_BuildListStorage.BuildListItem();
                ConfigNode.LoadObjectFromConfig(listItem, vessel);
                KCT_BuildListVessel blv = listItem.ToBuildListVessel();
                blv.shipNode = vessel.GetNode("ShipNode");
                blv.KSC      = this;
                this.SPHWarehouse.Add(blv);
            }

            /* tmp = node.GetNode("TechList");
             * foreach (ConfigNode techNode in tmp.GetNodes("Tech"))
             * {
             *   KCT_TechStorageItem techStorageItem = new KCT_TechStorageItem();
             *   ConfigNode.LoadObjectFromConfig(techStorageItem, techNode);
             *   KCT_TechItem techItem = techStorageItem.ToTechItem();
             *   techItem.protoNode = new ProtoTechNode(techNode.GetNode("ProtoNode"));
             *   this.TechList.Add(techItem);
             * }*/

            tmp = node.GetNode("Recon_Rollout");
            foreach (ConfigNode RRCN in tmp.GetNodes("Recon_Rollout_Item"))
            {
                KCT_Recon_Rollout tempRR = new KCT_Recon_Rollout();
                ConfigNode.LoadObjectFromConfig(tempRR, RRCN);
                Recon_Rollout.Add(tempRR);
            }

            if (node.HasNode("KSCTech"))
            {
                tmp = node.GetNode("KSCTech");
                foreach (ConfigNode upBuild in tmp.GetNodes("UpgradingBuilding"))
                {
                    KCT_UpgradingBuilding tempUP = new KCT_UpgradingBuilding();
                    ConfigNode.LoadObjectFromConfig(tempUP, upBuild);
                    KSCTech.Add(tempUP);
                }
            }

            if (node.HasNode("LaunchPads"))
            {
                LaunchPads.Clear();
                tmp = node.GetNode("LaunchPads");
                foreach (ConfigNode LP in tmp.GetNodes("KCT_LaunchPad"))
                {
                    KCT_LaunchPad tempLP = new KCT_LaunchPad("LP0");
                    ConfigNode.LoadObjectFromConfig(tempLP, LP);
                    tempLP.DestructionNode = LP.GetNode("DestructionState");
                    LaunchPads.Add(tempLP);
                }
            }

            if (node.HasNode("VABRateCache"))
            {
                foreach (string rate in node.GetNode("VABRateCache").GetValues("rate"))
                {
                    double r;
                    if (double.TryParse(rate, out r))
                    {
                        VABRates.Add(r);
                    }
                }
            }

            if (node.HasNode("SPHRateCache"))
            {
                foreach (string rate in node.GetNode("SPHRateCache").GetValues("rate"))
                {
                    double r;
                    if (double.TryParse(rate, out r))
                    {
                        SPHRates.Add(r);
                    }
                }
            }

            return(this);
        }
Esempio n. 13
0
        public KCT_KSC FromConfigNode(ConfigNode node)
        {
            VABUpgrades.Clear();
            SPHUpgrades.Clear();
            RDUpgrades.Clear();
            VABList.Clear();
            VABWarehouse.Clear();
            SPHList.Clear();
            SPHWarehouse.Clear();
            KSCTech.Clear();
            //TechList.Clear();
            Recon_Rollout.Clear();

            this.KSCName = node.GetValue("KSCName");
            if (!int.TryParse(node.GetValue("ActiveLPID"), out this.ActiveLaunchPadID))
                this.ActiveLaunchPadID = 0;
            ConfigNode vabup = node.GetNode("VABUpgrades");
            foreach (string upgrade in vabup.GetValues("Upgrade"))
            {
                this.VABUpgrades.Add(int.Parse(upgrade));
            }
            ConfigNode sphup = node.GetNode("SPHUpgrades");
            foreach (string upgrade in sphup.GetValues("Upgrade"))
            {
                this.SPHUpgrades.Add(int.Parse(upgrade));
            }
            ConfigNode rdup = node.GetNode("RDUpgrades");
            foreach (string upgrade in rdup.GetValues("Upgrade"))
            {
                this.RDUpgrades.Add(int.Parse(upgrade));
            }

            ConfigNode tmp = node.GetNode("VABList");
            foreach (ConfigNode vessel in tmp.GetNodes("KCTVessel"))
            {
                KCT_BuildListStorage.BuildListItem listItem = new KCT_BuildListStorage.BuildListItem();
                ConfigNode.LoadObjectFromConfig(listItem, vessel);
                KCT_BuildListVessel blv = listItem.ToBuildListVessel();
                blv.shipNode = vessel.GetNode("ShipNode");
                this.VABList.Add(blv);
            }

            tmp = node.GetNode("SPHList");
            foreach (ConfigNode vessel in tmp.GetNodes("KCTVessel"))
            {
                KCT_BuildListStorage.BuildListItem listItem = new KCT_BuildListStorage.BuildListItem();
                ConfigNode.LoadObjectFromConfig(listItem, vessel);
                KCT_BuildListVessel blv = listItem.ToBuildListVessel();
                blv.shipNode = vessel.GetNode("ShipNode");
                this.SPHList.Add(blv);
            }

            tmp = node.GetNode("VABWarehouse");
            foreach (ConfigNode vessel in tmp.GetNodes("KCTVessel"))
            {
                KCT_BuildListStorage.BuildListItem listItem = new KCT_BuildListStorage.BuildListItem();
                ConfigNode.LoadObjectFromConfig(listItem, vessel);
                KCT_BuildListVessel blv = listItem.ToBuildListVessel();
                blv.shipNode = vessel.GetNode("ShipNode");
                this.VABWarehouse.Add(blv);
            }

            tmp = node.GetNode("SPHWarehouse");
            foreach (ConfigNode vessel in tmp.GetNodes("KCTVessel"))
            {
                KCT_BuildListStorage.BuildListItem listItem = new KCT_BuildListStorage.BuildListItem();
                ConfigNode.LoadObjectFromConfig(listItem, vessel);
                KCT_BuildListVessel blv = listItem.ToBuildListVessel();
                blv.shipNode = vessel.GetNode("ShipNode");
                this.SPHWarehouse.Add(blv);
            }

               /* tmp = node.GetNode("TechList");
            foreach (ConfigNode techNode in tmp.GetNodes("Tech"))
            {
                KCT_TechStorageItem techStorageItem = new KCT_TechStorageItem();
                ConfigNode.LoadObjectFromConfig(techStorageItem, techNode);
                KCT_TechItem techItem = techStorageItem.ToTechItem();
                techItem.protoNode = new ProtoTechNode(techNode.GetNode("ProtoNode"));
                this.TechList.Add(techItem);
            }*/

            tmp = node.GetNode("Recon_Rollout");
            foreach (ConfigNode RRCN in tmp.GetNodes("Recon_Rollout_Item"))
            {
                KCT_Recon_Rollout tempRR = new KCT_Recon_Rollout();
                ConfigNode.LoadObjectFromConfig(tempRR, RRCN);
                Recon_Rollout.Add(tempRR);
            }

            if (node.HasNode("KSCTech"))
            {
                tmp = node.GetNode("KSCTech");
                foreach (ConfigNode upBuild in tmp.GetNodes("UpgradingBuilding"))
                {
                    KCT_UpgradingBuilding tempUP = new KCT_UpgradingBuilding();
                    ConfigNode.LoadObjectFromConfig(tempUP, upBuild);
                    KSCTech.Add(tempUP);
                }
            }

            if (node.HasNode("LaunchPads"))
            {
                LaunchPads.Clear();
                tmp = node.GetNode("LaunchPads");
                foreach (ConfigNode LP in tmp.GetNodes("KCT_LaunchPad"))
                {
                    KCT_LaunchPad tempLP = new KCT_LaunchPad("LP0");
                    ConfigNode.LoadObjectFromConfig(tempLP, LP);
                    tempLP.DestructionNode = LP.GetNode("DestructionState");
                    LaunchPads.Add(tempLP);
                }
            }

            return this;
        }
Esempio n. 14
0
        public KSCItem FromConfigNode(ConfigNode node)
        {
            VABUpgrades.Clear();
            SPHUpgrades.Clear();
            RDUpgrades.Clear();
            VABList.Clear();
            VABWarehouse.Clear();
            SPHList.Clear();
            SPHWarehouse.Clear();
            VABPlans.Clear();
            SPHPlans.Clear();
            KSCTech.Clear();
            Recon_Rollout.Clear();
            AirlaunchPrep.Clear();
            VABRates.Clear();
            SPHRates.Clear();

            KSCName = node.GetValue("KSCName");
            if (!int.TryParse(node.GetValue("ActiveLPID"), out ActiveLaunchPadID))
            {
                ActiveLaunchPadID = 0;
            }
            ConfigNode vabUp = node.GetNode("VABUpgrades");

            foreach (string upgrade in vabUp.GetValues("Upgrade"))
            {
                VABUpgrades.Add(int.Parse(upgrade));
            }
            ConfigNode sphUp = node.GetNode("SPHUpgrades");

            foreach (string upgrade in sphUp.GetValues("Upgrade"))
            {
                SPHUpgrades.Add(int.Parse(upgrade));
            }
            ConfigNode rdUp = node.GetNode("RDUpgrades");

            foreach (string upgrade in rdUp.GetValues("Upgrade"))
            {
                RDUpgrades.Add(int.Parse(upgrade));
            }

            ConfigNode tmp = node.GetNode("VABList");

            foreach (ConfigNode cn in tmp.GetNodes("KCTVessel"))
            {
                var listItem = new BuildListStorageItem();
                ConfigNode.LoadObjectFromConfig(listItem, cn);
                BuildListVessel blv = listItem.ToBuildListVessel();
                blv.ShipNode = cn.GetNode("ShipNode");
                blv.KSC      = this;
                VABList.Add(blv);
            }

            tmp = node.GetNode("SPHList");
            foreach (ConfigNode cn in tmp.GetNodes("KCTVessel"))
            {
                var listItem = new BuildListStorageItem();
                ConfigNode.LoadObjectFromConfig(listItem, cn);
                BuildListVessel blv = listItem.ToBuildListVessel();
                blv.ShipNode = cn.GetNode("ShipNode");
                blv.KSC      = this;
                SPHList.Add(blv);
            }

            BuildList.Sort((a, b) => a.BuildListIndex.CompareTo(b.BuildListIndex));

            tmp = node.GetNode("VABWarehouse");
            foreach (ConfigNode cn in tmp.GetNodes("KCTVessel"))
            {
                var listItem = new BuildListStorageItem();
                ConfigNode.LoadObjectFromConfig(listItem, cn);
                BuildListVessel blv = listItem.ToBuildListVessel();
                blv.ShipNode = cn.GetNode("ShipNode");
                blv.KSC      = this;
                VABWarehouse.Add(blv);
            }

            tmp = node.GetNode("SPHWarehouse");
            foreach (ConfigNode cn in tmp.GetNodes("KCTVessel"))
            {
                var listItem = new BuildListStorageItem();
                ConfigNode.LoadObjectFromConfig(listItem, cn);
                BuildListVessel blv = listItem.ToBuildListVessel();
                blv.ShipNode = cn.GetNode("ShipNode");
                blv.KSC      = this;
                SPHWarehouse.Add(blv);
            }

            if (node.TryGetNode("VABPlans", ref tmp))
            {
                if (tmp.HasNode("KCTVessel"))
                {
                    foreach (ConfigNode cn in tmp.GetNodes("KCTVessel"))
                    {
                        var listItem = new BuildListStorageItem();
                        ConfigNode.LoadObjectFromConfig(listItem, cn);
                        BuildListVessel blv = listItem.ToBuildListVessel();
                        blv.ShipNode = cn.GetNode("ShipNode");
                        blv.KSC      = this;
                        if (VABPlans.ContainsKey(blv.ShipName))
                        {
                            VABPlans.Remove(blv.ShipName);
                        }

                        VABPlans.Add(blv.ShipName, blv);
                    }
                }
            }

            if (node.TryGetNode("SPHPlans", ref tmp))
            {
                if (tmp.HasNode("KCTVessel"))
                {
                    foreach (ConfigNode cn in tmp.GetNodes("KCTVessel"))
                    {
                        var listItem = new BuildListStorageItem();
                        ConfigNode.LoadObjectFromConfig(listItem, cn);
                        BuildListVessel blv = listItem.ToBuildListVessel();
                        blv.ShipNode = cn.GetNode("ShipNode");
                        blv.KSC      = this;
                        if (SPHPlans.ContainsKey(blv.ShipName))
                        {
                            SPHPlans.Remove(blv.ShipName);
                        }
                        SPHPlans.Add(blv.ShipName, blv);
                    }
                }
            }

            tmp = node.GetNode("Recon_Rollout");
            foreach (ConfigNode RRCN in tmp.GetNodes("Recon_Rollout_Item"))
            {
                var tempRR = new ReconRolloutStorageItem();
                ConfigNode.LoadObjectFromConfig(tempRR, RRCN);
                Recon_Rollout.Add(tempRR.ToReconRollout());
            }

            if (node.TryGetNode("Airlaunch_Prep", ref tmp))
            {
                foreach (ConfigNode cn in tmp.GetNodes("Airlaunch_Prep_Item"))
                {
                    var storageItem = new AirlaunchPrepStorageItem();
                    ConfigNode.LoadObjectFromConfig(storageItem, cn);
                    AirlaunchPrep.Add(storageItem.ToAirlaunchPrep());
                }
            }

            if (node.HasNode("KSCTech"))
            {
                tmp = node.GetNode("KSCTech");
                foreach (ConfigNode cn in tmp.GetNodes("UpgradingBuilding"))
                {
                    var storageItem = new FacilityUpgradeStorageItem();
                    ConfigNode.LoadObjectFromConfig(storageItem, cn);
                    KSCTech.Add(storageItem.ToFacilityUpgrade());
                }
            }

            if (node.HasNode("LaunchPads"))
            {
                LaunchPads.Clear();
                tmp = node.GetNode("LaunchPads");
                foreach (ConfigNode cn in tmp.GetNodes("KCT_LaunchPad"))
                {
                    var tempLP = new KCT_LaunchPad("LP0");
                    ConfigNode.LoadObjectFromConfig(tempLP, cn);
                    tempLP.DestructionNode = cn.GetNode("DestructionState");
                    LaunchPads.Add(tempLP);
                }
            }

            if (node.HasNode("VABRateCache"))
            {
                foreach (string rate in node.GetNode("VABRateCache").GetValues("rate"))
                {
                    if (double.TryParse(rate, out double r))
                    {
                        VABRates.Add(r);
                    }
                }
            }

            if (node.HasNode("SPHRateCache"))
            {
                foreach (string rate in node.GetNode("SPHRateCache").GetValues("rate"))
                {
                    if (double.TryParse(rate, out double r))
                    {
                        SPHRates.Add(r);
                    }
                }
            }

            return(this);
        }
Esempio n. 15
0
File: KCT_KSC.cs Progetto: tivec/KCT
        public KCT_KSC FromConfigNode(ConfigNode node)
        {
            VABUpgrades.Clear();
            SPHUpgrades.Clear();
            RDUpgrades.Clear();
            VABList.Clear();
            VABWarehouse.Clear();
            SPHList.Clear();
            SPHWarehouse.Clear();
            VABPlans.Clear();
            SPHPlans.Clear();
            KSCTech.Clear();
            //TechList.Clear();
            Recon_Rollout.Clear();
            AirlaunchPrep.Clear();
            VABRates.Clear();
            SPHRates.Clear();

            this.KSCName = node.GetValue("KSCName");
            if (!int.TryParse(node.GetValue("ActiveLPID"), out this.ActiveLaunchPadID))
            {
                this.ActiveLaunchPadID = 0;
            }
            ConfigNode vabup = node.GetNode("VABUpgrades");

            foreach (string upgrade in vabup.GetValues("Upgrade"))
            {
                this.VABUpgrades.Add(int.Parse(upgrade));
            }
            ConfigNode sphup = node.GetNode("SPHUpgrades");

            foreach (string upgrade in sphup.GetValues("Upgrade"))
            {
                this.SPHUpgrades.Add(int.Parse(upgrade));
            }
            ConfigNode rdup = node.GetNode("RDUpgrades");

            foreach (string upgrade in rdup.GetValues("Upgrade"))
            {
                this.RDUpgrades.Add(int.Parse(upgrade));
            }

            ConfigNode tmp = node.GetNode("VABList");

            foreach (ConfigNode vessel in tmp.GetNodes("KCTVessel"))
            {
                KCT_BuildListStorage.BuildListItem listItem = new KCT_BuildListStorage.BuildListItem();
                ConfigNode.LoadObjectFromConfig(listItem, vessel);
                KCT_BuildListVessel blv = listItem.ToBuildListVessel();
                blv.shipNode = vessel.GetNode("ShipNode");
                blv.KSC      = this;
                this.VABList.Add(blv);
            }

            tmp = node.GetNode("SPHList");
            foreach (ConfigNode vessel in tmp.GetNodes("KCTVessel"))
            {
                KCT_BuildListStorage.BuildListItem listItem = new KCT_BuildListStorage.BuildListItem();
                ConfigNode.LoadObjectFromConfig(listItem, vessel);
                KCT_BuildListVessel blv = listItem.ToBuildListVessel();
                blv.shipNode = vessel.GetNode("ShipNode");
                blv.KSC      = this;
                this.SPHList.Add(blv);
            }

            tmp = node.GetNode("VABWarehouse");
            foreach (ConfigNode vessel in tmp.GetNodes("KCTVessel"))
            {
                KCT_BuildListStorage.BuildListItem listItem = new KCT_BuildListStorage.BuildListItem();
                ConfigNode.LoadObjectFromConfig(listItem, vessel);
                KCT_BuildListVessel blv = listItem.ToBuildListVessel();
                blv.shipNode = vessel.GetNode("ShipNode");
                blv.KSC      = this;
                this.VABWarehouse.Add(blv);
            }

            tmp = node.GetNode("SPHWarehouse");
            foreach (ConfigNode vessel in tmp.GetNodes("KCTVessel"))
            {
                KCT_BuildListStorage.BuildListItem listItem = new KCT_BuildListStorage.BuildListItem();
                ConfigNode.LoadObjectFromConfig(listItem, vessel);
                KCT_BuildListVessel blv = listItem.ToBuildListVessel();
                blv.shipNode = vessel.GetNode("ShipNode");
                blv.KSC      = this;
                this.SPHWarehouse.Add(blv);
            }

            if (node.TryGetNode("VABPlans", ref tmp))
            {
                if (tmp.HasNode("KCTVessel"))
                {
                    foreach (ConfigNode vessel in tmp.GetNodes("KCTVessel"))
                    {
                        KCT_BuildListStorage.BuildListItem listItem = new KCT_BuildListStorage.BuildListItem();
                        ConfigNode.LoadObjectFromConfig(listItem, vessel);
                        KCT_BuildListVessel blv = listItem.ToBuildListVessel();
                        blv.shipNode = vessel.GetNode("ShipNode");
                        blv.KSC      = this;
                        if (this.VABPlans.ContainsKey(blv.shipName))
                        {
                            this.VABPlans.Remove(blv.shipName);
                        }

                        this.VABPlans.Add(blv.shipName, blv);
                    }
                }
            }

            if (node.TryGetNode("SPHPlans", ref tmp))
            {
                if (tmp.HasNode("KCTVessel"))
                {
                    foreach (ConfigNode vessel in tmp.GetNodes("KCTVessel"))
                    {
                        KCT_BuildListStorage.BuildListItem listItem = new KCT_BuildListStorage.BuildListItem();
                        ConfigNode.LoadObjectFromConfig(listItem, vessel);
                        KCT_BuildListVessel blv = listItem.ToBuildListVessel();
                        blv.shipNode = vessel.GetNode("ShipNode");
                        blv.KSC      = this;
                        if (this.SPHPlans.ContainsKey(blv.shipName))
                        {
                            this.SPHPlans.Remove(blv.shipName);
                        }
                        this.SPHPlans.Add(blv.shipName, blv);
                    }
                }
            }

            tmp = node.GetNode("Recon_Rollout");
            foreach (ConfigNode RRCN in tmp.GetNodes("Recon_Rollout_Item"))
            {
                KCT_Recon_Rollout tempRR = new KCT_Recon_Rollout();
                ConfigNode.LoadObjectFromConfig(tempRR, RRCN);
                Recon_Rollout.Add(tempRR);
            }

            if (node.TryGetNode("Airlaunch_Prep", ref tmp))
            {
                foreach (ConfigNode APCN in tmp.GetNodes("Airlaunch_Prep_Item"))
                {
                    KCT_AirlaunchPrep temp = new KCT_AirlaunchPrep();
                    ConfigNode.LoadObjectFromConfig(temp, APCN);
                    AirlaunchPrep.Add(temp);
                }
            }

            if (node.HasNode("KSCTech"))
            {
                tmp = node.GetNode("KSCTech");
                foreach (ConfigNode upBuild in tmp.GetNodes("UpgradingBuilding"))
                {
                    KCT_UpgradingBuilding tempUP = new KCT_UpgradingBuilding();
                    tempUP.Load(upBuild);
                    KSCTech.Add(tempUP);
                }
            }

            if (node.HasNode("LaunchPads"))
            {
                LaunchPads.Clear();
                tmp = node.GetNode("LaunchPads");
                foreach (ConfigNode LP in tmp.GetNodes("KCT_LaunchPad"))
                {
                    KCT_LaunchPad tempLP = new KCT_LaunchPad("LP0");
                    ConfigNode.LoadObjectFromConfig(tempLP, LP);
                    tempLP.DestructionNode = LP.GetNode("DestructionState");
                    LaunchPads.Add(tempLP);
                }
            }

            if (node.HasNode("VABRateCache"))
            {
                foreach (string rate in node.GetNode("VABRateCache").GetValues("rate"))
                {
                    double r;
                    if (double.TryParse(rate, out r))
                    {
                        VABRates.Add(r);
                    }
                }
            }

            if (node.HasNode("SPHRateCache"))
            {
                foreach (string rate in node.GetNode("SPHRateCache").GetValues("rate"))
                {
                    double r;
                    if (double.TryParse(rate, out r))
                    {
                        SPHRates.Add(r);
                    }
                }
            }

            return(this);
        }
Esempio n. 16
0
        public static void DrawNewPadWindow(int windowID)
        {
            if (_padCosts == null || _padLvlOptions == null)
            {
                LoadPadNamesAndCosts();
            }

            GUILayout.BeginVertical();
            GUILayout.Label("Name:");
            _newName = GUILayout.TextField(_newName);

            GUILayout.Label("Pad level:");
            _selectedPadIdx = GUILayout.SelectionGrid(_selectedPadIdx, _padLvlOptions, 2);

            Vector3 unlimitedSizeThreshold = new Vector3(70, 130, 70);

            double  curPadCost;
            float   fractionalPadLvl = -1;
            float   tonnageLimit     = 0;
            Vector3 curPadSize       = Vector3.zero;

            int  customPadIdx = _padLvlOptions.Length - 1;
            bool isCustom     = _selectedPadIdx == customPadIdx;

            if (isCustom)
            {
                curPadCost = 0;

                GUILayout.Label("Tonnage limit:");
                _tonnageLimit = GUILayout.TextField(_tonnageLimit);
                if (float.TryParse(_tonnageLimit, out tonnageLimit) && tonnageLimit >= _padTons[0])
                {
                    float unlimitedTonnageThreshold = PresetManager.Instance.ActivePreset.GeneralSettings.PadUnlimitedTonnageThreshold;
                    if (tonnageLimit >= unlimitedTonnageThreshold)
                    {
                        int padLvl = _padLvlOptions.Length - 2;
                        tonnageLimit     = unlimitedTonnageThreshold;
                        curPadSize       = _padSizes[padLvl];
                        curPadCost       = _padCosts[padLvl];
                        fractionalPadLvl = padLvl;
                    }
                    else
                    {
                        for (int i = 1; i < _padTons.Length; i++)
                        {
                            if (tonnageLimit < _padTons[i])
                            {
                                float lowerBound          = _padTons[i - 1];
                                float upperBound          = Math.Min(_padTons[i], unlimitedTonnageThreshold);
                                float fractionOverFullLvl = (tonnageLimit - lowerBound) / (upperBound - lowerBound);
                                fractionalPadLvl = (i - 1) + fractionOverFullLvl;

                                var s1 = _padSizes[i - 1];
                                var s2 = Vector3.Min(_padSizes[i], unlimitedSizeThreshold);
                                curPadSize = s1 + (s2 - s1) * fractionOverFullLvl;

                                var c1 = _padCosts[i - 1];
                                var c2 = _padCosts[i];
                                curPadCost = c1 + (c2 - c1) * fractionOverFullLvl;
                                break;
                            }
                        }
                    }
                }
            }
            else
            {
                fractionalPadLvl = _selectedPadIdx;
                curPadSize       = _padSizes[_selectedPadIdx];
                curPadCost       = _padCosts[_selectedPadIdx];
                tonnageLimit     = _padTons[_selectedPadIdx];
            }

            if (curPadSize != Vector3.zero)
            {
                if (curPadSize.y == float.MaxValue)
                {
                    GUILayout.Label($"Size limit: unlimited");
                }
                else
                {
                    GUILayout.Label($"Size limit: {curPadSize.x:#.#}x{curPadSize.y:#.#}m");
                }
            }

            if (curPadCost > 0)
            {
                double curPadBuildTime = FacilityUpgrade.CalculateBuildTime(curPadCost, SpaceCenterFacility.LaunchPad);
                string sBuildTime      = KSPUtil.PrintDateDelta(curPadBuildTime, includeTime: false);
                GUILayout.Label($"It will cost {Math.Round(curPadCost):N} funds to build the new launchpad. " +
                                $"Estimated construction time is {sBuildTime}.");
            }

            GUILayout.Label("Would you like to build it?");
            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Yes") && ValidatePadCreationParameters(_newName, fractionalPadLvl, tonnageLimit, curPadSize))
            {
                GUIStates.ShowNewPad          = false;
                _centralWindowPosition.height = 1;
                _centralWindowPosition.width  = 150;
                _centralWindowPosition.x      = (Screen.width - 150) / 2;
                GUIStates.ShowBuildList       = true;

                if (!Utilities.CurrentGameIsCareer())
                {
                    KCTDebug.Log("Building new launchpad!");
                    KCTGameStates.ActiveKSC.LaunchPads.Add(new KCT_LaunchPad(_newName, fractionalPadLvl, tonnageLimit, curPadSize));
                }
                else if (Funding.CanAfford((float)curPadCost))
                {
                    KCTDebug.Log("Building new launchpad!");
                    Utilities.SpendFunds(curPadCost, TransactionReasons.StructureConstruction);
                    var lp = new KCT_LaunchPad(_newName, fractionalPadLvl, tonnageLimit, curPadSize);
                    KCTGameStates.ActiveKSC.LaunchPads.Add(lp);

                    var padConstr = new PadConstruction
                    {
                        LaunchpadIndex = KCTGameStates.ActiveKSC.LaunchPads.Count - 1,
                        Cost           = curPadCost,
                        Name           = _newName
                    };
                    padConstr.SetBP(curPadCost);
                    KCTGameStates.ActiveKSC.PadConstructions.Add(padConstr);

                    try
                    {
                        KCTEvents.OnPadConstructionQueued?.Fire(padConstr, lp);
                    }
                    catch (Exception ex)
                    {
                        Debug.LogException(ex);
                    }
                }
                else
                {
                    ScreenMessages.PostScreenMessage("Not enough funds to build this launchpad.");
                }

                _padCosts      = null;
                _padLvlOptions = null;
                _costOfNewLP   = int.MinValue;
            }

            if (GUILayout.Button("No"))
            {
                _centralWindowPosition.height = 1;
                _centralWindowPosition.width  = 150;
                _centralWindowPosition.x      = (Screen.width - 150) / 2;
                _padCosts               = null;
                _padLvlOptions          = null;
                GUIStates.ShowNewPad    = false;
                GUIStates.ShowBuildList = true;
            }

            GUILayout.EndHorizontal();
            GUILayout.EndVertical();
            CenterWindow(ref _centralWindowPosition);
        }