示例#1
0
        public override void OnStart(StartState state)
        {
            Debug.Log("[KSPI]: OnStart MSRGC " + part.name);

            _actinideDefinition     = PartResourceLibrary.Instance.GetDefinition(ResourceSettings.Config.Actinides);
            _protactiniumDefinition = PartResourceLibrary.Instance.GetDefinition(ResourceSettings.Config.Protactinium233);

            // legacy rule to make old systems function
            var legacyThorium = part.Resources[ResourceSettings.Config.ThoriumTetraflouride];

            if (legacyThorium != null && legacyThorium.amount > 0)
            {
                var uranium233 = part.Resources[ResourceSettings.Config.Uranium233];
                if (uranium233 != null && uranium233.amount <= 0)
                {
                    uranium233.maxAmount = Math.Max(legacyThorium.maxAmount, uranium233.maxAmount);
                    uranium233.amount    = uranium233.maxAmount;
                }
            }

            // start as normal
            base.OnStart(state);

            if (part.vessel != null)
            {
                _managedTransferableActinideStores.AddRange(
                    part.vessel.FindPartModulesImplementing <FNResourceTransfer>()
                    .Where(m => m.resourceName == _actinideDefinition.displayName));

                _managedTransferableProtactiniumStores.AddRange(
                    part.vessel.FindPartModulesImplementing <FNResourceTransfer>()
                    .Where(m => m.resourceName == _protactiniumDefinition.displayName));
            }

            fuelModeStr = CurrentFuelMode.ModeGUIName;

            _manualRestartEvent = Events[nameof(ManualRestart)];

            Events[nameof(DumpActinides)].guiActive        = canDumpActinides;
            Events[nameof(SwitchMode)].guiActiveEditor     = Events[nameof(SwitchMode)].guiActive = Events[nameof(SwitchMode)].guiActiveUnfocused = CheckFuelModes() > 1;
            Events[nameof(SwapFuelMode)].guiActive         = Events[nameof(SwapFuelMode)].guiActiveUnfocused = fuelModes.Count > 1;
            Events[nameof(EditorSwapFuel)].guiActiveEditor = fuelModes.Count > 1;

            if (!CurrentFuelMode.Variants.Any(m => m.FuelRatio > 0))
            {
                return;
            }

            ReactorFuelMode currentVariant = CurrentFuelMode.Variants.First(m => m.FuelRatio > 0);

            var firstReactorFuel = currentVariant.ReactorFuels.First();

            var initialReactorFuel = part.Resources.Get(firstReactorFuel.ResourceName);

            if (initialReactorFuel != null)
            {
                if (reactorMainFuelMaxAmount == 0)
                {
                    reactorMainFuelMaxAmount = initialReactorFuel.maxAmount;
                }
                reactorMainFuelDensityInTon = firstReactorFuel.DensityInTon;
            }
            else
            {
                if (reactorMainFuelMaxAmount == 0)
                {
                    // assume the densest resource is nuclear fuel
                    var densestFuel = part.Resources.OrderByDescending(m => m.info.density).FirstOrDefault();
                    if (densestFuel != null)
                    {
                        reactorMainFuelMaxAmount = densestFuel.maxAmount;
                    }
                    else
                    {
                        reactorMainFuelMaxAmount = part.mass * 100;
                    }
                }
            }

            foreach (var fuelMode in fuelModes)
            {
                foreach (var reactorFuel in fuelMode.Variants.First().ReactorFuels)
                {
                    var resource = part.Resources.Get(reactorFuel.ResourceName);
                    if (resource == null)
                    {
                        // non-tweakable resources
                        part.Resources.Add(reactorFuel.ResourceName, 0, 0, true, false, false, true, 0);
                    }
                }
            }
        }
        public override void OnStart(StartState state)
        {
            Debug.Log("[KSPI]: OnStart MSRGC " + part.name);

            // start as normal
            base.OnStart(state);

            fuelModeStr = CurrentFuelMode.ModeGUIName;

            _manualRestartEvent = Events[nameof(ManualRestart)];

            Events[nameof(DumpActinides)].guiActive        = canDumpActinides;
            Events[nameof(SwitchMode)].guiActiveEditor     = Events[nameof(SwitchMode)].guiActive = Events[nameof(SwitchMode)].guiActiveUnfocused = CheckFuelModes() > 1;
            Events[nameof(SwapFuelMode)].guiActive         = Events[nameof(SwapFuelMode)].guiActiveUnfocused = fuelModes.Count > 1;
            Events[nameof(EditorSwapFuel)].guiActiveEditor = fuelModes.Count > 1;

            if (!CurrentFuelMode.Variants.Any(m => m.FuelRatio > 0))
            {
                return;
            }

            ReactorFuelMode currentVariant = CurrentFuelMode.Variants.First(m => m.FuelRatio > 0);

            var firstReactorFuel = currentVariant.ReactorFuels.First();

            var initialReactorFuel = part.Resources.Get(firstReactorFuel.ResourceName);

            if (initialReactorFuel != null)
            {
                if (reactorMainFuelMaxAmount == 0)
                {
                    reactorMainFuelMaxAmount = initialReactorFuel.maxAmount;
                }
                reactorMainFuelDensityInTon = firstReactorFuel.DensityInTon;
            }
            else
            {
                if (reactorMainFuelMaxAmount == 0)
                {
                    // assume the densest resource is nuclear fuel
                    PartResource densestFuel = part.Resources.OrderByDescending(m => m.info.density).FirstOrDefault();
                    if (densestFuel != null)
                    {
                        reactorMainFuelMaxAmount = densestFuel.maxAmount;
                    }
                    else
                    {
                        reactorMainFuelMaxAmount = part.mass * 100;
                    }
                }
            }

            foreach (var fuelMode in fuelModes)
            {
                foreach (var reactorFuel in fuelMode.Variants.First().ReactorFuels)
                {
                    var resource = part.Resources.Get(reactorFuel.ResourceName);
                    if (resource == null)
                    {
                        // non-tweakable resources
                        part.Resources.Add(reactorFuel.ResourceName, 0, 0, true, false, false, true, 0);
                    }
                }
            }
        }