private IChargedParticleSource FindChargedParticleSource(Part currentpart, int stackdepth, int parentdepth)
        {
            if (currentpart == null)
            {
                return(null);
            }

            if (stackdepth == 0)
            {
                return(currentpart.FindModulesImplementing <IChargedParticleSource>().FirstOrDefault());
            }

            foreach (var attachNodes in currentpart.attachNodes.Where(atn => atn.attachedPart != null))
            {
                IChargedParticleSource particleSource = FindChargedParticleSource(attachNodes.attachedPart, (stackdepth - 1), parentdepth);

                if (particleSource != null)
                {
                    return(particleSource);
                }
            }

            if (parentdepth > 0)
            {
                IChargedParticleSource particleSource = FindChargedParticleSource(currentpart.parent, (stackdepth - 1), (parentdepth - 1));

                if (particleSource != null)
                {
                    return(particleSource);
                }
            }

            return(null);
        }
		public override void OnStart(PartModule.StartState state) 
        {
            var wasteheatPowerResource = part.Resources.list.FirstOrDefault(r => r.resourceName == FNResourceManager.FNRESOURCE_WASTEHEAT);
            // calculate WasteHeat Capacity
            if (wasteheatPowerResource != null)
            {
                var ratio = wasteheatPowerResource.amount / wasteheatPowerResource.maxAmount;
                wasteheatPowerResource.maxAmount = part.mass * 1.0e+5 * wasteHeatMultiplier;
                wasteheatPowerResource.amount = wasteheatPowerResource.maxAmount * ratio;
            }
            
            if (state == StartState.Editor) return;

			_attached_engine = this.part.Modules["ModuleEnginesFX"] as ModuleEnginesFX;

            if (_attached_engine != null)
                _attached_engine.Fields["finalThrust"].guiFormat = "F5";
            else
                UnityEngine.Debug.Log("[KSPI] - InterstellarMagneticNozzleControllerFX.OnStart no ModuleEnginesFX found for MagneticNozzle!");

            _attached_reactor = BreadthFirstSearchForChargedParticleSource(10, 1);

            if (_attached_reactor == null)
                UnityEngine.Debug.Log("[KSPI] - InterstellarMagneticNozzleControllerFX.OnStart no IChargedParticleSource found for MagneticNozzle!");
		}
예제 #3
0
        public override void OnStart(PartModule.StartState state)
        {
            // calculate WasteHeat Capacity
            var wasteheatPowerResource = part.Resources.FirstOrDefault(r => r.resourceName == ResourceManager.FNRESOURCE_WASTEHEAT);

            if (wasteheatPowerResource != null)
            {
                var wasteheat_ratio = Math.Min(wasteheatPowerResource.amount / wasteheatPowerResource.maxAmount, 0.95);
                wasteheatPowerResource.maxAmount = part.mass * 2.0e+4 * wasteHeatMultiplier;
                wasteheatPowerResource.amount    = wasteheatPowerResource.maxAmount * wasteheat_ratio;
            }

            if (state == StartState.Editor)
            {
                return;
            }

            _attached_engine          = this.part.FindModuleImplementing <ModuleEnginesFX>();
            _attached_warpable_engine = _attached_engine as ModuleEnginesWarp;

            if (_attached_engine != null)
            {
                _attached_engine.Fields["finalThrust"].guiFormat = "F5";
            }
            else
            {
                Debug.Log("[KSPI] - InterstellarMagneticNozzleControllerFX.OnStart no ModuleEnginesFX found for MagneticNozzle!");
            }

            // first try to look in part
            _attached_reactor = this.part.FindModuleImplementing <IChargedParticleSource>();

            // try to find nearest
            if (_attached_reactor == null)
            {
                _attached_reactor = BreadthFirstSearchForChargedParticleSource(10, 1);
            }

            if (_attached_reactor == null)
            {
                Debug.Log("[KSPI] - InterstellarMagneticNozzleControllerFX.OnStart no IChargedParticleSource found for MagneticNozzle!");
                return;
            }

            double joules_per_amu = _attached_reactor.CurrentMeVPerChargedProduct * 1e6 * GameConstants.ELECTRON_CHARGE / GameConstants.dilution_factor;

            calculatedIsp = Math.Sqrt(joules_per_amu * 2.0 / GameConstants.ATOMIC_MASS_UNIT) / PluginHelper.GravityConstant;

            minimum_isp          = calculatedIsp * _attached_reactor.MinimumChargdIspMult;
            maximum_isp          = calculatedIsp * _attached_reactor.MaximumChargedIspMult;
            max_power_multiplier = Math.Log10(maximum_isp / minimum_isp);

            throtleExponent = Math.Abs(Math.Log10(_attached_reactor.MinimumChargdIspMult / _attached_reactor.MaximumChargedIspMult));

            exchanger_thrust_divisor = radius > _attached_reactor.Radius
                ? _attached_reactor.Radius * _attached_reactor.Radius / radius / radius
                : radius * radius / _attached_reactor.Radius / _attached_reactor.Radius;
        }
		public override void OnStart(PartModule.StartState state) {
            if (state == StartState.Editor) return;

			_attached_engine = this.part.Modules["ModuleEnginesFX"] as ModuleEnginesFX;

            if (_attached_engine != null)
                _attached_engine.Fields["finalThrust"].guiFormat = "F5";

            List<IChargedParticleSource> source_list = part.attachNodes.Where(atn => atn.attachedPart != null).SelectMany(atn => atn.attachedPart.FindModulesImplementing<IChargedParticleSource>()).ToList();
            _attached_reactor = source_list.FirstOrDefault();
		}
예제 #5
0
        public override void OnStart(PartModule.StartState state)
        {
            var wasteheatPowerResource = part.Resources.list.FirstOrDefault(r => r.resourceName == FNResourceManager.FNRESOURCE_WASTEHEAT);

            // calculate WasteHeat Capacity
            if (wasteheatPowerResource != null)
            {
                var ratio = wasteheatPowerResource.amount / wasteheatPowerResource.maxAmount;
                wasteheatPowerResource.maxAmount = part.mass * 1.0e+5 * wasteHeatMultiplier;
                wasteheatPowerResource.amount    = wasteheatPowerResource.maxAmount * ratio;
            }

            if (state == StartState.Editor)
            {
                return;
            }

            _attached_engine          = this.part.FindModuleImplementing <ModuleEnginesFX>(); //this.part.Modules["ModuleEnginesFX"] as ModuleEnginesFX;
            _attached_warpable_engine = _attached_engine as ModuleEnginesWarp;

            if (_attached_engine != null)
            {
                _attached_engine.Fields["finalThrust"].guiFormat = "F5";
            }
            else
            {
                UnityEngine.Debug.Log("[KSPI] - InterstellarMagneticNozzleControllerFX.OnStart no ModuleEnginesFX found for MagneticNozzle!");
            }

            // first try to look in part
            _attached_reactor = this.part.FindModuleImplementing <IChargedParticleSource>();

            // try to find nearest
            if (_attached_reactor == null)
            {
                _attached_reactor = BreadthFirstSearchForChargedParticleSource(10, 1);
            }

            if (_attached_reactor == null)
            {
                UnityEngine.Debug.Log("[KSPI] - InterstellarMagneticNozzleControllerFX.OnStart no IChargedParticleSource found for MagneticNozzle!");
                return;
            }

            double joules_per_amu = _attached_reactor.CurrentMeVPerChargedProduct * 1e6 * GameConstants.ELECTRON_CHARGE / GameConstants.dilution_factor;

            calculatedIsp = Math.Sqrt(joules_per_amu * 2.0 / GameConstants.ATOMIC_MASS_UNIT) / PluginHelper.GravityConstant;

            throtleExponent = Mathf.Abs(Mathf.Log10(_attached_reactor.MinimumChargdIspMult / _attached_reactor.MaximumChargedIspMult));

            exchanger_thrust_divisor = radius > _attached_reactor.GetRadius()
                ? _attached_reactor.GetRadius() * _attached_reactor.GetRadius() / radius / radius
                : radius * radius / _attached_reactor.GetRadius() / _attached_reactor.GetRadius(); // Does this really need to be done each update? Or at all since it uses particles instead of thermal power?
        }
예제 #6
0
        public override void OnStart(PartModule.StartState state)
        {
            resourceBuffers = new ResourceBuffers();
            resourceBuffers.AddConfiguration(new ResourceBuffers.TimeBasedConfig(ResourceManager.FNRESOURCE_WASTEHEAT, wasteHeatMultiplier, 2.0e+4, true));
            resourceBuffers.UpdateVariable(ResourceManager.FNRESOURCE_WASTEHEAT, this.part.mass);
            resourceBuffers.Init(this.part);

            if (state == StartState.Editor)
            {
                return;
            }

            _attached_warpable_engine = this.part.FindModuleImplementing <ModuleEnginesWarp>();
            _attached_engine          = _attached_warpable_engine;

            if (_attached_engine != null)
            {
                _attached_engine.Fields["finalThrust"].guiFormat = "F5";
            }
            else
            {
                Debug.Log("[KSPI] - InterstellarMagneticNozzleControllerFX.OnStart no ModuleEnginesFX found for MagneticNozzle!");
            }

            // first try to look in part
            _attached_reactor = this.part.FindModuleImplementing <IChargedParticleSource>();

            // try to find nearest
            if (_attached_reactor == null)
            {
                _attached_reactor = BreadthFirstSearchForChargedParticleSource(10, 1);
            }

            if (_attached_reactor == null)
            {
                Debug.Log("[KSPI] - InterstellarMagneticNozzleControllerFX.OnStart no IChargedParticleSource found for MagneticNozzle!");
                return;
            }

            double joules_per_amu = _attached_reactor.CurrentMeVPerChargedProduct * 1e6 * GameConstants.ELECTRON_CHARGE / GameConstants.dilution_factor;

            calculatedIsp = Math.Sqrt(joules_per_amu * 2.0 / GameConstants.ATOMIC_MASS_UNIT) / PluginHelper.GravityConstant;

            minimum_isp          = calculatedIsp * _attached_reactor.MinimumChargdIspMult;
            maximum_isp          = calculatedIsp * _attached_reactor.MaximumChargedIspMult;
            max_power_multiplier = Math.Log10(maximum_isp / minimum_isp);

            throtleExponent = Math.Abs(Math.Log10(_attached_reactor.MinimumChargdIspMult / _attached_reactor.MaximumChargedIspMult));

            exchanger_thrust_divisor = radius > _attached_reactor.Radius
                ? _attached_reactor.Radius * _attached_reactor.Radius / radius / radius
                : radius * radius / _attached_reactor.Radius / _attached_reactor.Radius;
        }
        private IChargedParticleSource BreadthFirstSearchForChargedParticleSource(int stackdepth, int parentdepth)
        {
            for (int currentDepth = 0; currentDepth <= stackdepth; currentDepth++)
            {
                IChargedParticleSource particleSource = FindChargedParticleSource(part, currentDepth, parentdepth);

                if (particleSource != null)
                {
                    _attached_reactor_distance = currentDepth;
                    return(particleSource);
                }
            }
            return(null);
        }
        private void ConnectToReactor()
        {
            // first try to look in part
            _attached_reactor = this.part.FindModuleImplementing <IChargedParticleSource>();

            // try to find nearest
            if (_attached_reactor == null)
            {
                _attached_reactor = BreadthFirstSearchForChargedParticleSource(10, 1);
            }

            if (_attached_reactor != null)
            {
                _attached_reactor.ConnectWithEngine(this);
            }
        }
예제 #9
0
        public override void OnStart(PartModule.StartState state)
        {
            if (state == StartState.Editor)
            {
                return;
            }

            _attached_engine = this.part.Modules["ModuleEnginesFX"] as ModuleEnginesFX;

            if (_attached_engine != null)
            {
                _attached_engine.Fields["finalThrust"].guiFormat = "F5";
            }

            List <IChargedParticleSource> source_list = part.attachNodes.Where(atn => atn.attachedPart != null).SelectMany(atn => atn.attachedPart.FindModulesImplementing <IChargedParticleSource>()).ToList();

            _attached_reactor = source_list.FirstOrDefault();
        }
예제 #10
0
        public override void OnStart(PartModule.StartState state)
        {
            var wasteheatPowerResource = part.Resources.list.FirstOrDefault(r => r.resourceName == FNResourceManager.FNRESOURCE_WASTEHEAT);

            // calculate WasteHeat Capacity
            if (wasteheatPowerResource != null)
            {
                var ratio = wasteheatPowerResource.amount / wasteheatPowerResource.maxAmount;
                wasteheatPowerResource.maxAmount = part.mass * 1.0e+5 * wasteHeatMultiplier;
                wasteheatPowerResource.amount    = wasteheatPowerResource.maxAmount * ratio;
            }

            if (state == StartState.Editor)
            {
                return;
            }

            _attached_engine          = this.part.FindModuleImplementing <ModuleEnginesFX>(); //this.part.Modules["ModuleEnginesFX"] as ModuleEnginesFX;
            _attached_warpable_engine = _attached_engine as ModuleEnginesWarp;

            if (_attached_engine != null)
            {
                _attached_engine.Fields["finalThrust"].guiFormat = "F5";
            }
            else
            {
                UnityEngine.Debug.Log("[KSPI] - InterstellarMagneticNozzleControllerFX.OnStart no ModuleEnginesFX found for MagneticNozzle!");
            }

            _attached_reactor = BreadthFirstSearchForChargedParticleSource(10, 1);

            if (_attached_reactor == null)
            {
                UnityEngine.Debug.Log("[KSPI] - InterstellarMagneticNozzleControllerFX.OnStart no IChargedParticleSource found for MagneticNozzle!");
            }

            exchanger_thrust_divisor = radius > _attached_reactor.getRadius()
                ? _attached_reactor.getRadius() * _attached_reactor.getRadius() / radius / radius
                : radius * radius / _attached_reactor.getRadius() / _attached_reactor.getRadius(); // Does this really need to be done each update? Or at all since it uses particles instead of thermal power?
        }
        public override void OnStart(PartModule.StartState state)
        {
            var wasteheatPowerResource = part.Resources.list.FirstOrDefault(r => r.resourceName == FNResourceManager.FNRESOURCE_WASTEHEAT);
            // calculate WasteHeat Capacity
            if (wasteheatPowerResource != null)
            {
                var ratio = wasteheatPowerResource.amount / wasteheatPowerResource.maxAmount;
                wasteheatPowerResource.maxAmount = part.mass * 1.0e+5 * wasteHeatMultiplier;
                wasteheatPowerResource.amount = wasteheatPowerResource.maxAmount * ratio;
            }

            if (state == StartState.Editor) return;

            _attached_engine = this.part.FindModuleImplementing<ModuleEnginesFX>();  //this.part.Modules["ModuleEnginesFX"] as ModuleEnginesFX;
            _attached_warpable_engine = _attached_engine as ModuleEnginesWarp;

            if (_attached_engine != null)
                _attached_engine.Fields["finalThrust"].guiFormat = "F5";
            else
                UnityEngine.Debug.Log("[KSPI] - InterstellarMagneticNozzleControllerFX.OnStart no ModuleEnginesFX found for MagneticNozzle!");

            // first try to look in part
            _attached_reactor = this.part.FindModuleImplementing<IChargedParticleSource>();

            // try to find nearest
            if (_attached_reactor == null)
                _attached_reactor = BreadthFirstSearchForChargedParticleSource(10, 1);

            if (_attached_reactor == null)
            {
                UnityEngine.Debug.Log("[KSPI] - InterstellarMagneticNozzleControllerFX.OnStart no IChargedParticleSource found for MagneticNozzle!");
                return;
            }

            double joules_per_amu = _attached_reactor.CurrentMeVPerChargedProduct * 1e6 * GameConstants.ELECTRON_CHARGE / GameConstants.dilution_factor;
            calculatedIsp = Math.Sqrt(joules_per_amu * 2.0 / GameConstants.ATOMIC_MASS_UNIT) / PluginHelper.GravityConstant;

            throtleExponent = Mathf.Abs(Mathf.Log10(_attached_reactor.MinimumChargdIspMult / _attached_reactor.MaximumChargedIspMult));

            exchanger_thrust_divisor = radius > _attached_reactor.GetRadius()
                ? _attached_reactor.GetRadius() * _attached_reactor.GetRadius() / radius / radius
                : radius * radius / _attached_reactor.GetRadius() / _attached_reactor.GetRadius(); // Does this really need to be done each update? Or at all since it uses particles instead of thermal power?
        }
        public override void OnStart(PartModule.StartState state)
        {
            var wasteheatPowerResource = part.Resources.list.FirstOrDefault(r => r.resourceName == FNResourceManager.FNRESOURCE_WASTEHEAT);
            // calculate WasteHeat Capacity
            if (wasteheatPowerResource != null)
            {
                var ratio = wasteheatPowerResource.amount / wasteheatPowerResource.maxAmount;
                wasteheatPowerResource.maxAmount = part.mass * 1.0e+5 * wasteHeatMultiplier;
                wasteheatPowerResource.amount = wasteheatPowerResource.maxAmount * ratio;
            }

            if (state == StartState.Editor) return;

            _attached_engine = this.part.FindModuleImplementing<ModuleEnginesFX>();  //this.part.Modules["ModuleEnginesFX"] as ModuleEnginesFX;
            _attached_warpable_engine = _attached_engine as ModuleEnginesWarp;

            if (_attached_engine != null)
                _attached_engine.Fields["finalThrust"].guiFormat = "F5";
            else
                UnityEngine.Debug.Log("[KSPI] - InterstellarMagneticNozzleControllerFX.OnStart no ModuleEnginesFX found for MagneticNozzle!");

            _attached_reactor = BreadthFirstSearchForChargedParticleSource(10, 1);

            if (_attached_reactor == null)
                UnityEngine.Debug.Log("[KSPI] - InterstellarMagneticNozzleControllerFX.OnStart no IChargedParticleSource found for MagneticNozzle!");

            exchanger_thrust_divisor = radius > _attached_reactor.getRadius()
                ? _attached_reactor.getRadius() * _attached_reactor.getRadius() / radius / radius
                : radius * radius / _attached_reactor.getRadius() / _attached_reactor.getRadius(); // Does this really need to be done each update? Or at all since it uses particles instead of thermal power?
        }