Esempio n. 1
0
        public override void OnLoad(ConfigNode node)
        {
            base.OnLoad(node);

            EntryCostDatabase.Load(node.GetNode("Unlocks"));

            EntryCostDatabase.UpdatePartEntryCosts();

            if (HighLogic.CurrentGame.Mode == Game.Modes.CAREER)
            {
                foreach (ConfigNode n in node.GetNodes("TLUpgrade"))
                {
                    TLUpgrade tU = null;
                    if (n.HasValue("name"))
                    {
                        string tlName = n.GetValue("name");
                        if (techLevelUpgrades.TryGetValue(tlName, out tU))
                        {
                            tU.Load(n);
                        }
                        else
                        {
                            tU = new TLUpgrade(n);
                            techLevelUpgrades[tlName] = tU;
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        public bool PurchaseConfig(string cfgName)
        {
            if (ConfigUnlocked(cfgName))
            {
                return(false);
            }

            double cfgCost = ConfigEntryCost(cfgName);

            if (!HighLogic.CurrentGame.Parameters.Difficulty.BypassEntryPurchaseAfterResearch)
            {
                if (Funding.Instance.Funds < cfgCost)
                {
                    return(false);
                }

                Funding.Instance.AddFunds(-cfgCost, TransactionReasons.RnDPartPurchase);
            }

            EntryCostDatabase.SetUnlocked(cfgName);

            EntryCostDatabase.UpdatePartEntryCosts();

            return(true);
        }
Esempio n. 3
0
        public void Start()
        {
            EntryCostManager.FillUpgrades();

            EntryCostDatabase.Initialize();

            EntryCostDatabase.UpdatePartEntryCosts();
        }
Esempio n. 4
0
        public override void OnSave(ConfigNode node)
        {
            base.OnSave(node);
            if (HighLogic.CurrentGame.Mode == Game.Modes.CAREER)
            {
                foreach (TLUpgrade tU in techLevelUpgrades.Values)
                {
                    tU.Save(node.AddNode("TLUpgrade"));
                }

                EntryCostDatabase.Save(node.AddNode("Unlocks"));
            }
        }
        public void Start()
        {
            EntryCostManager.FillUpgrades();

            EntryCostDatabase.Initialize();

            EntryCostDatabase.UpdatePartEntryCosts();

            // KSP's Funding binds to the same event and is used for deducting funds for entry purchases.
            // RF will need to bind to the event before KSP itself does to process ECMs right after KSP has updated the funding.
            // Note that KSP fires events in a reverse while loop.
            GameEvents.OnPartPurchased.Add(OnPartPurchased);
        }
Esempio n. 6
0
        public static void UpdateEntryCost(AvailablePart ap)
        {
            string name = GetPartName(ap);

            EntryCostDatabase.ClearTracker();

            PartEntryCostHolder h;

            if (holders.TryGetValue(name, out h))
            {
                ap.SetEntryCost(h.GetCost());
            }
        }
Esempio n. 7
0
        public int GetCost()
        {
            if (EntryCostDatabase.IsUnlocked(name))
            {
                return(0);
            }

            int c = cost;

            foreach (string s in children)
            {
                c += EntryCostDatabase.GetCost(s);
            }

            return(c);
        }
Esempio n. 8
0
        public override void OnAwake()
        {
            base.OnAwake();

            if (_instance != null)
            {
                Object.Destroy(this);
                return;
            }
            _instance = this;

            if (configUpgrades == null) // just in case
            {
                FillUpgrades();
            }

            EntryCostDatabase.Initialize(); // should not be needed though.

            GameEvents.OnPartPurchased.Add(new EventData <AvailablePart> .OnEvent(onPartPurchased));
        }
Esempio n. 9
0
        public void onPartPurchased(AvailablePart ap)
        {
            EntryCostDatabase.SetUnlocked(ap);

            StartCoroutine(updatePartEntryCosts());

            Part part = ap.partPrefab;

            if (part != null)
            {
                for (int i = part.Modules.Count - 1; i >= 0; --i)
                {
                    PartModule m = part.Modules[i];
                    if (m is ModuleEngineConfigs)
                    {
                        ModuleEngineConfigs mec = m as ModuleEngineConfigs;
                        mec.CheckConfigs();
                        for (int j = mec.configs.Count - 1; j >= 0; --j)
                        {
                            ConfigNode cfg = mec.configs[j];
                            if (cfg.HasValue("name"))
                            {
                                string cfgName = cfg.GetValue("name");

                                // TL upgrades
                                if (mec.techLevel >= 0)
                                {
                                    string tUName = Utilities.GetPartName(ap) + cfgName;
                                    SetTLUnlocked(tUName, mec.techLevel);
                                }
                            }
                        }
                    }
                }
            }
        }
Esempio n. 10
0
 public double ConfigEntryCost(string cfgName)
 {
     EntryCostDatabase.ClearTracker();
     return(EntryCostDatabase.GetCost(cfgName));
 }
Esempio n. 11
0
 public bool ConfigUnlocked(string cfgName)
 {
     return(EntryCostDatabase.IsUnlocked(cfgName));
 }
Esempio n. 12
0
        protected IEnumerator updatePartEntryCosts()
        {
            yield return(new WaitForEndOfFrame());

            EntryCostDatabase.UpdatePartEntryCosts();
        }
Esempio n. 13
0
 public double EntryCost()
 {
     return(EntryCostDatabase.GetCost(name));
 }