Exemple #1
0
        internal void handleUpgrade()
        {
            int oldLevel = getMember <int>("level");

            Log.Trace($"Upgrading from level {oldLevel}");

            string facilityID = GetFacilityID();

            UpgradingBuilding upgrading = new UpgradingBuilding(facilityID, oldLevel + 1, oldLevel, facilityID.Split('/').Last());

            upgrading.isLaunchpad = facilityID.ToLower().Contains("launchpad");
            if (upgrading.isLaunchpad)
            {
                upgrading.launchpadID = GameStates.ActiveKSC.ActiveLaunchPadID;
                if (upgrading.launchpadID > 0)
                {
                    upgrading.commonName += GameStates.ActiveKSC.ActiveLPInstance.name;
                }
            }

            if (!upgrading.AlreadyInProgress())
            {
                float cost = getMember <float>("upgradeCost");

                if (Funding.CanAfford(cost))
                {
                    Funding.Instance.AddFunds(-cost, TransactionReasons.Structures);
                    GameStates.ActiveKSC.KSCTech.Add(upgrading);
                    upgrading.SetBP(cost);
                    upgrading.cost = cost;

                    ScreenMessages.PostScreenMessage("Facility upgrade requested!", 4.0f, ScreenMessageStyle.UPPER_CENTER);
                    Log.Trace($"Facility {facilityID} upgrade requested to lvl {oldLevel + 1} for {cost} funds, resulting in a BP of {upgrading.BP}");
                }
                else
                {
                    Log.Trace("Couldn't afford to upgrade.");
                    ScreenMessages.PostScreenMessage("Not enough funds to upgrade facility!", 4.0f, ScreenMessageStyle.UPPER_CENTER);
                }
            }
            else if (oldLevel + 1 != upgrading.currentLevel)
            {
                ScreenMessages.PostScreenMessage("Facility is already being upgraded!", 4.0f, ScreenMessageStyle.UPPER_CENTER);
                Log.Trace($"Facility {facilityID} tried to upgrade to lvl {oldLevel+1} but already in list!");
            }

            _menu.Dismiss(KSCFacilityContextMenu.DismissAction.None);
        }
Exemple #2
0
        public SpaceCenterConstruction FromConfigNode(ConfigNode node)
        {
            const string logBlockName = nameof(SpaceCenterConstruction) + "." + nameof(AsConfigNode);

            using (EntryExitLogger.EntryExitLog(logBlockName, EntryExitLoggerOptions.All))
            {
                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"))
                {
                    BuildListStorage.BuildListItem listItem = new BuildListStorage.BuildListItem();
                    ConfigNode.LoadObjectFromConfig(listItem, vessel);
                    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"))
                {
                    BuildListStorage.BuildListItem listItem = new BuildListStorage.BuildListItem();
                    ConfigNode.LoadObjectFromConfig(listItem, vessel);
                    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"))
                {
                    BuildListStorage.BuildListItem listItem = new BuildListStorage.BuildListItem();
                    ConfigNode.LoadObjectFromConfig(listItem, vessel);
                    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"))
                {
                    BuildListStorage.BuildListItem listItem = new BuildListStorage.BuildListItem();
                    ConfigNode.LoadObjectFromConfig(listItem, vessel);
                    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"))
                {
                    Recon_Rollout tempRR = new 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"))
                    {
                        UpgradingBuilding tempUP = new 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"))
                    {
                        LaunchPad tempLP = new 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);
            }
        }