コード例 #1
0
        public void Start()
        {
            rcs = part.GetComponent<ModuleRCSFX>();

            thrustMaterials = new List<Material>();
            foreach (Transform t in rcs.thrusterTransforms)
            {
                thrustMaterials.Add(t.GetComponentInChildren<MeshRenderer>().material);
            }
        }
コード例 #2
0
        public void Start()
        {
            rcs = part.GetComponent <ModuleRCSFX>();

            thrustMaterials = new List <Material>();
            foreach (Transform t in rcs.thrusterTransforms)
            {
                thrustMaterials.Add(t.GetComponentInChildren <MeshRenderer>().material);
            }
        }
コード例 #3
0
ファイル: RCSController.cs プロジェクト: zorg2044/Waterfall
        public override void Initialize(ModuleWaterfallFX host)
        {
            base.Initialize(host);

            rcsController = host.GetComponents <ModuleRCSFX>().ToList().First();
            if (rcsController == null)
            {
                rcsController = host.GetComponent <ModuleRCSFX>();
            }

            if (rcsController == null)
            {
                Utils.LogError("[RCSController] Could not find ModuleRCSFX on Initialize");
            }
        }
コード例 #4
0
        public override void OnStart(StartState state)
        {
            base.OnStart(state);

            //Get rotor transforms
            rotorTransform = this.part.FindModelTransform(rotorTransformName);

            //Setup RCS
            rcsModule = this.part.FindModuleImplementing <ModuleRCSFX>();

            //Setup events
            WBIRotationController rotationController = this.part.FindModuleImplementing <WBIRotationController>();

            if (rotationController != null)
            {
                mirrorRotation = rotationController.mirrorRotation;
                rotationController.onRotatorMirrored += MirrorRotation;
            }

            //Get the rotation axis
            if (string.IsNullOrEmpty(rotorRotationAxis) == false)
            {
                string[] axisValues = rotorRotationAxis.Split(',');
                float    value;
                if (axisValues.Length == 3)
                {
                    if (float.TryParse(axisValues[0], out value))
                    {
                        rotationAxis.x = value;
                    }
                    if (float.TryParse(axisValues[1], out value))
                    {
                        rotationAxis.y = value;
                    }
                    if (float.TryParse(axisValues[2], out value))
                    {
                        rotationAxis.z = value;
                    }
                }
            }

            //Set gui visible state
            SetGUIVisible(guiVisible);

            //Rotor transforms
            setupRotorTransforms();
        }
コード例 #5
0
ファイル: ModuleRCSFX.cs プロジェクト: enceos/ExplorationPack
    public override void OnLoad(ConfigNode node)
    {
        ModuleRCSFX prefab = null;

        if (part != null && part.partInfo != null)
        {
            prefab = (ModuleRCSFX)part.partInfo.partPrefab.Modules["ModuleRCSFX"];
        }

        if (prefab != null && prefab.propellants != null)
        {
            _props = prefab.propellants;
        }
        else
        {
            LoadPropellants(node);
        }
    }
コード例 #6
0
		void Process_rcsfx(ModuleRCSFX mrfx)
		{
			// calculate thrust fuel flow
			double thrust_flow = mrfx.maxFuelFlow * 1e3 * mrfx.thrustPercentage * mrfx.thrusterPower;

			// search fuel types
			foreach (Propellant fuel in mrfx.propellants)
			{
				switch (fuel.name)
				{
					case "ElectricCharge":  // mainly used for Ion RCS
						Resource("ElectricCharge").Consume(thrust_flow * fuel.ratio, "rcs");
						break;
					case "LqdHydrogen":     // added for cryotanks and any other supported mod that uses Liquid Hydrogen
						Resource("LqdHydrogen").Consume(thrust_flow * fuel.ratio, "rcs");
						break;
				}
			}
		}
コード例 #7
0
        public override void Initialize(ModuleWaterfallFX host)
        {
            base.Initialize(host);

            rcsController = host.GetComponents <ModuleRCSFX>().ToList().Find(x => x.thrusterTransformName == thrusterTransformName);
            if (rcsController == null)
            {
                rcsController = host.GetComponent <ModuleRCSFX>();
            }

            if (rcsController == null)
            {
                Utils.LogError("[RCSController] Could not find ModuleRCSFX on Initialize");
                return;
            }

            currentThrottle = new List <float>(rcsController.thrusterTransforms.Count);
            for (int i = 0; i < rcsController.thrusterTransforms.Count; i++)
            {
                currentThrottle.Add(0f);
            }
        }
コード例 #8
0
        public override void OnStart(StartState state)
        {
            base.OnStart(state);

            rcsModule = this.part.FindModuleImplementing <ModuleRCSFX>();
            if (rcsModule == null)
            {
                return;
            }

            if (HighLogic.CurrentGame.Mode == Game.Modes.CAREER || HighLogic.CurrentGame.Mode == Game.Modes.SCIENCE_SANDBOX)
            {
                setObject(-1);
                checkForUpgrade();
            }

            else
            {
                rcsModule.moduleIsEnabled = true;
                rcsModule.enabled         = true;
                rcsModule.isEnabled       = true;
                setObject(0);
            }
        }
        public override void OnStart(StartState state)
        {
            var rcs = part.FindModulesImplementing <ModuleRCSFX>();
            int fm;

            _attachedRcs = (rcsIndex >= rcs.Count) ? null : rcs[rcsIndex];

            if (partMass == 0)
            {
                partMass = part.mass;
            }

            resourcesToSupply = new [] { ResourceSettings.Config.WasteHeatInMegawatt };

            _oldPowerEnabled = powerEnabled;
            efficiencyStr    = efficiency.ToString("P1");

            if (!string.IsNullOrEmpty(AnimationName))
            {
                _rcsStates = PluginHelper.SetUpAnimation(AnimationName, part);
            }

            // Only allow _propellants that are compatible with this engine type
            _propellants.Clear();
            foreach (var propellant in ElectricEnginePropellant.GetPropellantsEngineForType(type))
            {
                if ((propellant.SupportedEngines & type) != 0)
                {
                    _propellants.Add(propellant);
                }
            }

            if (_propellants.Count < 1)
            {
                Debug.LogError("[KSPI]: No _propellants available for RCS type " + type + "!");
            }

            _delayedVerificationPropellant = true;
            // find correct fuel mode index
            if (!string.IsNullOrEmpty(fuel_mode_name))
            {
                foreach (var propellant in _propellants)
                {
                    if (propellant.PropellantName != fuel_mode_name)
                    {
                        continue;
                    }

                    Debug.Log("[KSPI]: ElectricRCSController set fuel mode " + fuel_mode_name);
                    CurrentPropellant = propellant;
                    break;
                }
            }

            if (CurrentPropellant != null && (fm = _propellants.IndexOf(CurrentPropellant)) >= 0)
            {
                fuel_mode = fm;
            }
            SetPropellant(true);

            base.OnStart(state);

            _powerConsumptionStrField           = Fields[nameof(powerConsumptionStr)];
            _powerConsumptionStrField.guiActive = showConsumption;

            maxStoredPower = bufferMult * maxThrust * powerMult * maxIsp * PhysicsGlobals.GravitationalAcceleration / (efficiency * 1000.0);
        }
コード例 #10
0
        public override void OnStart(PartModule.StartState state)
        {
            definitionMegajoule = PartResourceLibrary.Instance.GetDefinition(ResourceManager.FNRESOURCE_MEGAJOULES);

            try
            {
                attachedRCS = this.part.FindModuleImplementing <ModuleRCSFX>();

                if (!isInitialised)
                {
                    precisionFactorLimiter = attachedRCS.precisionFactor * 100;
                    fullThrustMinLimiter   = attachedRCS.fullThrustMin * 100;
                    useThrotleEnabled      = attachedRCS.useThrottle;
                    fullThrustEnabled      = attachedRCS.fullThrust;
                    useLeverEnabled        = attachedRCS.useLever;
                }

                attachedRCS.precisionFactor = precisionFactorLimiter / 100;
                attachedRCS.fullThrustMin   = fullThrustMinLimiter / 100;
                attachedRCS.useThrottle     = useThrotleEnabled;
                attachedRCS.fullThrust      = fullThrustEnabled;
                attachedRCS.useLever        = useLeverEnabled;

                // old legacy stuff
                if (baseThrust == 0 && maxThrust > 0)
                {
                    baseThrust = maxThrust;
                }

                if (partMass == 0)
                {
                    partMass = part.mass;
                }

                if (String.IsNullOrEmpty(displayName))
                {
                    displayName = part.partInfo.title;
                }

                String[] resources_to_supply = { ResourceManager.FNRESOURCE_WASTEHEAT };
                this.resources_to_supply = resources_to_supply;

                oldThrustLimiter = thrustLimiter;
                oldPowerEnabled  = powerEnabled;
                //efficiencyModifier = g0 * 0.5 / 1000 / efficiency;
                efficiencyStr = (efficiency * 100).ToString() + "%";

                if (!String.IsNullOrEmpty(AnimationName))
                {
                    rcsStates = PluginHelper.SetUpAnimation(AnimationName, this.part);
                }

                // initialize propellant
                _propellants = ElectricEnginePropellant.GetPropellantsEngineForType(type);

                delayedVerificationPropellant = true;
                // find correct fuel mode index
                if (!String.IsNullOrEmpty(fuel_mode_name))
                {
                    Debug.Log("[KSPI] - ElectricRCSController OnStart loaded fuelmode " + fuel_mode_name);
                    Current_propellant = _propellants.FirstOrDefault(p => p.PropellantName == fuel_mode_name);
                }
                if (Current_propellant != null && _propellants.Contains(Current_propellant))
                {
                    fuel_mode = _propellants.IndexOf(Current_propellant);
                    Debug.Log("[KSPI] - ElectricRCSController OnStart index of fuelmode " + Current_propellant.PropellantGUIName + " = " + fuel_mode);
                }

                base.OnStart(state);

                Fields["electricalPowerConsumptionStr"].guiActive = showConsumption;
            }
            catch (Exception e)
            {
                Debug.LogError("[KSPI] - ElectricRCSController OnStart Error: " + e.Message);
                throw;
            }
        }
コード例 #11
0
        private void partModuleUpdate(PartModule pm)
        {
            if (!(pm is ModuleRCSFX))
            {
                return;
            }

            //MechJebCore.print("ModuleRCSFX");

            ModuleRCSFX rcs = (ModuleRCSFX)pm;

            if (!rcs.rcsEnabled || part.ShieldedFromAirstream || !vessel.ActionGroups[KSPActionGroup.RCS])
            {
                return;
            }

            //Vector3 CoM = vesselState.CoM + vessel.rb_velocity * Time.fixedDeltaTime;
            Vector3 CoM = vessel.CoM + vessel.rb_velocity * Time.fixedDeltaTime;

            //Vector3 inputAngular = vessel.ReferenceTransform.rotation * new Vector3(rcs.enablePitch ? 1f : 0f, rcs.enableRoll ? 1f : 0f, rcs.enableYaw ? 1f : 0);
            //Vector3 inputLinear  = vessel.ReferenceTransform.rotation * new Vector3(rcs.enableX ? 1f : 0f, rcs.enableZ ? 1f : 0f, rcs.enableY ? 1f : 0f);

            Vector3 inputAngular = vessel.ReferenceTransform.rotation * Vector3.one;
            Vector3 inputLinear  = vessel.ReferenceTransform.rotation * Vector3.one;

            int xformCount = rcs.thrusterTransforms.Count;

            double thrustBase = rcs.flowMult * rcs.fuelFlow * rcs.realISP * rcs.G * rcs.ispMult;

            for (int i = 0; i < xformCount; ++i)
            {
                Transform xform = rcs.thrusterTransforms[i];
                if (xform.position != Vector3.zero)
                {
                    Vector3 position = xform.position;
                    Vector3 relPos   = position - CoM;

                    Vector3 thruster = rcs.useZaxis ? xform.forward : xform.up;

                    inputLinear  = thruster;
                    inputAngular = Vector3.Cross(thruster.normalized, relPos.normalized).normalized;
                    Vector3 torque = Vector3.Cross(inputAngular, relPos.normalized);

                    float thrust = Mathf.Max(Vector3.Dot(thruster, torque), 0f);
                    thrust += Mathf.Max(Vector3.Dot(thruster, inputLinear), 0f);

                    //if (thrust <= 0f)
                    //{
                    //    print("Ignore " + thrust.ToString("F2") + " " + Vector3.Dot(thruster, torque).ToString("F2") + " " + Vector3.Dot(thruster, inputLinear.normalized).ToString("F2"));
                    //    continue;
                    //}

                    if (FlightInputHandler.fetch.precisionMode)
                    {
                        if (rcs.useLever)
                        {
                            float leverDistance = rcs.GetLeverDistance(-thruster, CoM);

                            if (leverDistance > 1)
                            {
                                thrust /= leverDistance;
                            }
                        }
                        else
                        {
                            thrust *= rcs.precisionFactor;
                        }
                    }

                    float thrustForce = (float)thrustBase * thrust;

                    thruster.Scale(new Vector3d(rcs.enablePitch ? 1f : 0f, rcs.enableRoll ? 1f : 0f, rcs.enableYaw ? 1f : 0));

                    Vector3 force = vessel.GetTransform().InverseTransformDirection(-thrustForce * thruster);

                    force.Scale(new Vector3(rcs.enableX ? 1f : 0f, rcs.enableZ ? 1f : 0f, rcs.enableY ? 1f : 0f));

                    vesselState.rcsThrustAvailable.Add(force);

                    Vector3 thrusterTorque = Vector3.Cross(relPos, force);
                    // Convert in vessel local coordinate

                    vesselState.rcsTorqueAvailable.Add(vessel.GetTransform().InverseTransformDirection(thrusterTorque));
                }
            }
        }
コード例 #12
0
        private void setThrustLimit(float limit)
        {
            foreach (var part in FlightGlobals.ActiveVessel.Parts)
            {
                foreach (PartModule m in part.Modules)
                {
                    // Do the "all active" and "all inactive" here
                    if (m is ModuleEngines)
                    {
                        ModuleEngines me = (ModuleEngines)m;
                        if ((me.EngineIgnited && allActiveEngines) ||
                            (!me.EngineIgnited && allInactiveEngines))
                        {
                            me.thrustPercentage = limit;
                        }
                    }
                    if (m is ModuleEnginesFX && m.isEnabled) // Squad, y u have separate module for NASA engines? :c
                    {
                        ModuleEnginesFX me = (ModuleEnginesFX)m;
                        if ((me.EngineIgnited && allActiveEngines) ||
                            (!me.EngineIgnited && allInactiveEngines))
                        {
                            me.thrustPercentage = limit;
                        }
                    }

                    // Do the RCS here
                    if (m is ModuleRCS)
                    {
                        ModuleRCS me = (ModuleRCS)m;

                        me.thrustPercentage = limit;
                    }
                    if (m is ModuleRCSFX && m.isEnabled) // Squad, y u have separate module for NASA engines? :c
                    {
                        ModuleRCSFX me = (ModuleRCSFX)m;

                        me.thrustPercentage = limit;
                    }

                    // Do the enginetype here

                    string engineType = "";
                    GetEngineType(m, ref engineType);
                    foreach (var et in engineTypes)
                    {
                        if (et.update)
                        {
                            if (engineType == et.engineType)
                            {
                                if (m is ModuleEngines)
                                {
                                    ModuleEngines me = (ModuleEngines)m;
                                    me.thrustPercentage = limit;
                                }
                                if (m is ModuleEnginesFX)
                                {
                                    ModuleEnginesFX me = (ModuleEnginesFX)m;
                                    me.thrustPercentage = limit;
                                }
                            }
                        }
                    }
                }
            }
        }