Ejemplo n.º 1
0
        private bool OverrideFacilityDescriptions()
        {
            if (ScenarioUpgradeableFacilities.Instance == null)
            {
                return(false);
            }

            try
            {
                Dictionary <string, ScenarioUpgradeableFacilities.ProtoUpgradeable> upgrades = ScenarioUpgradeableFacilities.protoUpgradeables;
                foreach (ScenarioUpgradeableFacilities.ProtoUpgradeable upgrade in upgrades.Values)
                {
                    foreach (UpgradeableFacility facilityUpgrade in upgrade.facilityRefs)
                    {
                        for (int i = 0; i < facilityUpgrade.UpgradeLevels.Length; i++)
                        {
                            UpgradeableObject.UpgradeLevel upgradeLevel = facilityUpgrade.UpgradeLevels[i];
                            UpdateFacilityLevelStats(upgradeLevel, i);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.LogException(ex);
                return(false);
            }

            return(true);
        }
Ejemplo n.º 2
0
        private void UpdateFacilityLevelStats(UpgradeableObject.UpgradeLevel lvl, int lvlIdx)
        {
            // levelText appears to be unused by KSP itself. We can use it to store original level stats.
            // Restoring old values is necessary because those persist between scene changes but some of them are based on current KCT settings.
            if (lvl.levelText == null)
            {
                lvl.levelText            = ScriptableObject.CreateInstance <KSCUpgradeableLevelText>();
                lvl.levelText.facility   = lvl.levelStats.facility;
                lvl.levelText.linePrefix = lvl.levelStats.linePrefix;
                lvl.levelText.textBase   = lvl.levelStats.textBase;
            }
            else
            {
                lvl.levelStats.textBase = lvl.levelText.textBase;
            }

            KCTDebug.Log($"Overriding level stats text for {lvl.levelStats.facility} lvl {lvlIdx}");

            SpaceCenterFacility facilityType = lvl.levelStats.facility;

            if (facilityType == SpaceCenterFacility.VehicleAssemblyBuilding ||
                facilityType == SpaceCenterFacility.SpaceplaneHangar)
            {
                if (PresetManager.Instance.ActivePreset.GeneralSettings.CommonBuildLine &&
                    facilityType == SpaceCenterFacility.SpaceplaneHangar)
                {
                    lvl.levelStats.linePrefix = string.Empty;
                    lvl.levelStats.textBase   = "Upgrade the VAB instead";
                }
                else
                {
                    lvl.levelStats.textBase += $"\n{lvlIdx + 1} build queue{(lvlIdx > 0 ? "s" : string.Empty)}";
                    if (lvlIdx > 0)
                    {
                        lvl.levelStats.textBase += $"\n+{lvlIdx * 25}% build rate";
                    }
                }
            }
            else if (facilityType == SpaceCenterFacility.ResearchAndDevelopment &&
                     lvlIdx > 0)
            {
                lvl.levelStats.textBase += $"\n+{lvlIdx * 25}% research rate";
            }
            else if (facilityType == SpaceCenterFacility.Administration)
            {
                lvl.levelStats.linePrefix = string.Empty;
                lvl.levelStats.textBase   = "This facility is currently unused";
            }
            else if (facilityType == SpaceCenterFacility.AstronautComplex &&
                     lvlIdx > 0)
            {
                lvl.levelStats.textBase += $"\n{lvlIdx * 25}% shorter R&R times";
                lvl.levelStats.textBase += $"\n{lvlIdx * 25}% shorter training times";
            }
            else if (facilityType == SpaceCenterFacility.LaunchPad)
            {
                lvl.levelStats.linePrefix = string.Empty;
                lvl.levelStats.textBase   = "<color=\"red\"><b>Launchpads cannot be upgraded. Build a new launchpad from the KCT Build List tab instead.</b></color>";
            }
        }
Ejemplo n.º 3
0
        // With the help of NoMoreGrind code by nlight
        private void LoadUpgradesPrices()
        {
            log("Loading new upgrades prices");

            foreach (UpgradeableFacility facility in GameObject.FindObjectsOfType <UpgradeableFacility>())
            {
                SpaceCenterFacility facilityType = (SpaceCenterFacility)Enum.Parse(typeof(SpaceCenterFacility), facility.name);

                float[] prices       = getFacilityUpgradePrices(facilityType);
                int     levels       = getFacilityLevels(facilityType);
                int[]   levelsVisual = getFacilityLevelsVisual(facilityType);

                if (prices == null)
                {
                    log("No upgrades prices set for " + facilityType + ". Skipping");
                    continue;
                }

                if (levels != prices.Length)
                {
                    log("Wrong numbers of upgrade price for " + facility + " expecting " + levels + " and have " + prices.Length + ". Check your configs");
                    continue;
                }

                UpgradeableObject.UpgradeLevel[] upgradeLevels = facility.UpgradeLevels;

                if (facility.UpgradeLevels[facility.FacilityLevel].Spawned)
                {
                    facility.UpgradeLevels[facility.FacilityLevel].Despawn();
                }

                UpgradeableObject.UpgradeLevel[] newUpgradeLevels = new UpgradeableObject.UpgradeLevel[levels];

                for (int i = 0; i < levels; i++)
                {
                    int originalLevel = Math.Min(i, upgradeLevels.Length - 1);

                    UpgradeableObject.UpgradeLevel level = new UpgradeableObject.UpgradeLevel();
                    var sourceLvl = upgradeLevels[originalLevel];

                    level.levelCost        = prices[i];
                    level.levelText        = sourceLvl.levelText;
                    level.levelStats       = sourceLvl.levelStats;
                    level.facilityPrefab   = sourceLvl.facilityPrefab;
                    level.facilityInstance = null;

                    if (levelsVisual.Length == levels)
                    {
                        log(facility.name + " Copying level " + (levelsVisual[i] - 1) + " for level " + (i + 1));
                        //level.facilityPrefab = Instantiate(upgradeLevels[levelsVisual[i] - 1].facilityPrefab);
                        level.facilityPrefab = upgradeLevels[levelsVisual[i] - 1].facilityPrefab;
                    }
                    else
                    {
                        log("Wrong levelsVisual length " + levelsVisual.Length + " for " + facility.name + " expected " + levels);
                    }

                    newUpgradeLevels[i] = level;
                }

                facility.UpgradeLevels = newUpgradeLevels;
                facility.SetupLevels();
                facility.setLevel(facility.FacilityLevel);
            }
            log("New upgrades prices are Loaded");
        }
Ejemplo n.º 4
0
        private void LoadUpgradesPrices()
        {
            log("Loading new upgrades prices");

            foreach (UpgradeableFacility facility in GameObject.FindObjectsOfType <UpgradeableFacility>())
            {
                SpaceCenterFacility facilityType;
                try
                {
                    facilityType = (SpaceCenterFacility)Enum.Parse(typeof(SpaceCenterFacility), facility.name);
                }
                catch (ArgumentException)
                {
                    // Mods can add new Facilities that are not in the stock enum list.
                    continue;
                }

                float[] prices       = getFacilityUpgradePrices(facilityType);
                int     levels       = getFacilityLevels(facilityType);
                int[]   levelsVisual = getFacilityLevelsVisual(facilityType);

                if (prices == null)
                {
                    log("No upgrades prices set for " + facilityType + ". Skipping");
                    continue;
                }

                if (levels != prices.Length)
                {
                    log("Wrong numbers of upgrade price for " + facility + " expecting " + levels + " and have " + prices.Length + ". Check your configs");
                    continue;
                }

                UpgradeableObject.UpgradeLevel[] upgradeLevels = facility.UpgradeLevels;

                for (int i = 0; i < upgradeLevels.Length; i++)
                {
                    UpgradeableObject.UpgradeLevel oldLevel = upgradeLevels[i];
                    if (oldLevel.Spawned)
                    {
                        oldLevel.Despawn();
                    }
                }

                UpgradeableObject.UpgradeLevel[] newUpgradeLevels = new UpgradeableObject.UpgradeLevel[levels];

                for (int i = 0; i < levels; i++)
                {
                    int originalLevel = Math.Min(i, upgradeLevels.Length - 1);

                    UpgradeableObject.UpgradeLevel level = new UpgradeableObject.UpgradeLevel();
                    var sourceLvl = upgradeLevels[originalLevel];

                    level.Setup(facility);
                    level.levelCost        = prices[i];
                    level.levelText        = sourceLvl.levelText;
                    level.levelStats       = sourceLvl.levelStats;
                    level.facilityPrefab   = sourceLvl.facilityPrefab;
                    level.facilityInstance = null;

                    // Only redo the visual on the first load. Doing it on the next loads would mess up the order.
                    if (!varLoaded)
                    {
                        if (levelsVisual.Length == levels)
                        {
                            //log(facility.name + " Copying level " + (levelsVisual[i] - 1) + " for level " + (i + 1));
                            level.facilityPrefab = upgradeLevels[levelsVisual[i] - 1].facilityPrefab;
                        }
                        else
                        {
                            log("Wrong levelsVisual length " + levelsVisual.Length + " for " + facility.name + " expected " + levels);
                        }
                    }
                    newUpgradeLevels[i] = level;
                }

                facility.UpgradeLevels = newUpgradeLevels;

                // Use the current save state to (re)init the facility
                if (ScenarioUpgradeableFacilities.protoUpgradeables.TryGetValue(facility.id, out ScenarioUpgradeableFacilities.ProtoUpgradeable protoUpgradeable))
                {
                    facility.Load(protoUpgradeable.configNode);
                }
                else
                {
                    facility.SetupLevels();
                    facility.setLevel(facility.FacilityLevel);
                }
            }
            if (!varLoaded)
            {
                log("New upgrades prices are Loaded");
            }
            varLoaded = true;
        }