Example #1
0
        private void BuildVesselAndShipNodeConfigs(BuildListVessel blv, ref ConfigNode node)
        {
            var storageItem = new BuildListStorageItem();

            storageItem.FromBuildListVessel(blv);
            var cnTemp = new ConfigNode("KCTVessel");

            cnTemp = ConfigNode.CreateConfigFromObject(storageItem, cnTemp);
            var shipNode = new ConfigNode("ShipNode");

            blv.ShipNode.CopyTo(shipNode);
            cnTemp.AddNode(shipNode);
            node.AddNode(cnTemp);
        }
Example #2
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);
        }
Example #3
0
        public ConfigNode AsConfigNode()
        {
            KCTDebug.Log("Saving KSC " + KSCName);
            var node = new ConfigNode("KSC");

            node.AddValue("KSCName", KSCName);
            node.AddValue("ActiveLPID", ActiveLaunchPadID);

            var cnVABUp = new ConfigNode("VABUpgrades");

            foreach (int upgrade in VABUpgrades)
            {
                cnVABUp.AddValue("Upgrade", upgrade.ToString());
            }
            node.AddNode(cnVABUp);

            var cnSPHUp = new ConfigNode("SPHUpgrades");

            foreach (int upgrade in SPHUpgrades)
            {
                cnSPHUp.AddValue("Upgrade", upgrade.ToString());
            }
            node.AddNode(cnSPHUp);

            var cnRDUp = new ConfigNode("RDUpgrades");

            foreach (int upgrade in RDUpgrades)
            {
                cnRDUp.AddValue("Upgrade", upgrade.ToString());
            }
            node.AddNode(cnRDUp);

            var cnVABl = new ConfigNode("VABList");

            foreach (BuildListVessel blv in VABList)
            {
                blv.BuildListIndex = BuildList.IndexOf(blv);
                var storageItem = new BuildListStorageItem();
                storageItem.FromBuildListVessel(blv);
                var cnTemp = new ConfigNode("KCTVessel");
                cnTemp = ConfigNode.CreateConfigFromObject(storageItem, cnTemp);
                var shipNode = new ConfigNode("ShipNode");
                blv.ShipNode.CopyTo(shipNode);
                cnTemp.AddNode(shipNode);
                cnVABl.AddNode(cnTemp);
            }
            node.AddNode(cnVABl);

            var cnSPHl = new ConfigNode("SPHList");

            foreach (BuildListVessel blv in SPHList)
            {
                blv.BuildListIndex = BuildList.IndexOf(blv);
                var storageItem = new BuildListStorageItem();
                storageItem.FromBuildListVessel(blv);
                var cnTemp = new ConfigNode("KCTVessel");
                cnTemp = ConfigNode.CreateConfigFromObject(storageItem, cnTemp);
                var shipNode = new ConfigNode("ShipNode");
                blv.ShipNode.CopyTo(shipNode);
                cnTemp.AddNode(shipNode);
                cnSPHl.AddNode(cnTemp);
            }
            node.AddNode(cnSPHl);

            var cnVABWh = new ConfigNode("VABWarehouse");

            foreach (BuildListVessel blv in VABWarehouse)
            {
                var storageItem = new BuildListStorageItem();
                storageItem.FromBuildListVessel(blv);
                var cnTemp = new ConfigNode("KCTVessel");
                cnTemp = ConfigNode.CreateConfigFromObject(storageItem, cnTemp);
                var shipNode = new ConfigNode("ShipNode");
                blv.ShipNode.CopyTo(shipNode);
                cnTemp.AddNode(shipNode);
                cnVABWh.AddNode(cnTemp);
            }
            node.AddNode(cnVABWh);

            var cnSPHWh = new ConfigNode("SPHWarehouse");

            foreach (BuildListVessel blv in SPHWarehouse)
            {
                var storageItem = new BuildListStorageItem();
                storageItem.FromBuildListVessel(blv);
                var cnTemp = new ConfigNode("KCTVessel");
                cnTemp = ConfigNode.CreateConfigFromObject(storageItem, cnTemp);
                var shipNode = new ConfigNode("ShipNode");
                blv.ShipNode.CopyTo(shipNode);
                cnTemp.AddNode(shipNode);
                cnSPHWh.AddNode(cnTemp);
            }
            node.AddNode(cnSPHWh);

            var cnUpgradeables = new ConfigNode("KSCTech");

            foreach (FacilityUpgrade buildingTech in KSCTech)
            {
                var storageItem = new FacilityUpgradeStorageItem();
                storageItem.FromFacilityUpgrade(buildingTech);
                var cn = new ConfigNode("UpgradingBuilding");
                cn = ConfigNode.CreateConfigFromObject(storageItem, cn);
                cnUpgradeables.AddNode(cn);
            }
            node.AddNode(cnUpgradeables);

            var cnVABPlans = new ConfigNode("VABPlans");

            foreach (BuildListVessel blv in VABPlans.Values)
            {
                var storageItem = new BuildListStorageItem();
                storageItem.FromBuildListVessel(blv);
                var cnTemp = new ConfigNode("KCTVessel");
                cnTemp = ConfigNode.CreateConfigFromObject(storageItem, cnTemp);
                var shipNode = new ConfigNode("ShipNode");
                blv.ShipNode.CopyTo(shipNode);
                cnTemp.AddNode(shipNode);
                cnVABPlans.AddNode(cnTemp);
            }
            node.AddNode(cnVABPlans);

            var cnSPHPlans = new ConfigNode("SPHPlans");

            foreach (BuildListVessel blv in SPHPlans.Values)
            {
                var storageItem = new BuildListStorageItem();
                storageItem.FromBuildListVessel(blv);
                var cnTemp = new ConfigNode("KCTVessel");
                cnTemp = ConfigNode.CreateConfigFromObject(storageItem, cnTemp);
                var shipNode = new ConfigNode("ShipNode");
                blv.ShipNode.CopyTo(shipNode);
                cnTemp.AddNode(shipNode);
                cnSPHPlans.AddNode(cnTemp);
            }
            node.AddNode(cnSPHPlans);

            var cnRR = new ConfigNode("Recon_Rollout");

            foreach (ReconRollout rr in Recon_Rollout)
            {
                var storageItem = new ReconRolloutStorageItem();
                storageItem.FromReconRollout(rr);
                var rrCN = new ConfigNode("Recon_Rollout_Item");
                rrCN = ConfigNode.CreateConfigFromObject(storageItem, rrCN);
                cnRR.AddNode(rrCN);
            }
            node.AddNode(cnRR);

            var cnAP = new ConfigNode("Airlaunch_Prep");

            foreach (AirlaunchPrep ap in AirlaunchPrep)
            {
                var storageItem = new AirlaunchPrepStorageItem();
                storageItem.FromAirlaunchPrep(ap);
                var cn = new ConfigNode("Airlaunch_Prep_Item");
                cn = ConfigNode.CreateConfigFromObject(storageItem, cn);
                cnAP.AddNode(cn);
            }
            node.AddNode(cnAP);

            var cnLPs = new ConfigNode("LaunchPads");

            foreach (KCT_LaunchPad lp in LaunchPads)
            {
                ConfigNode lpCN = lp.AsConfigNode();
                lpCN.AddNode(lp.DestructionNode);
                cnLPs.AddNode(lpCN);
            }
            node.AddNode(cnLPs);

            //Cache the regular rates
            var cnCachedVABRates = new ConfigNode("VABRateCache");

            foreach (double rate in VABRates)
            {
                cnCachedVABRates.AddValue("rate", rate);
            }
            node.AddNode(cnCachedVABRates);

            var cnCachedSPHRates = new ConfigNode("SPHRateCache");

            foreach (double rate in SPHRates)
            {
                cnCachedSPHRates.AddValue("rate", rate);
            }
            node.AddNode(cnCachedSPHRates);
            return(node);
        }