public override void OnStart(PartModule.StartState state) 
        {
            // 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 = { FNResourceManager.FNRESOURCE_WASTEHEAT };
            this.resources_to_supply = resources_to_supply;

            attachedRCS = this.part.FindModuleImplementing<ModuleRCS>();
            oldThrustLimiter = thrustLimiter;
            oldPowerEnabled = powerEnabled;
            efficencyModifier = (float)g0 * 0.5f / 1000.0f / efficency;
            efficencyStr = (efficency * 100).ToString() + "%";

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

            // initialize propellant
            _propellants = ElectricEnginePropellant.GetPropellantsEngineForType(type);
            SetupPropellants(true, _propellants.Count);
            currentThrustMultiplier = hasSufficientPower ? Current_propellant.ThrustMultiplier : Current_propellant.ThrustMultiplierCold;

            base.OnStart(state);
         }
Ejemplo n.º 2
0
 internal RCS (Part part)
 {
     Part = part;
     rcs = part.InternalPart.Module<ModuleRCS> ();
     if (rcs == null)
         throw new ArgumentException ("Part does not have a ModuleRCS PartModule");
 }
Ejemplo n.º 3
0
        float getResourceMass()
        {
            float resourceMass = 0;
            var   counted      = new HashSet <string> ();

            foreach (PartModule pm in RCSBuildAid.RCS)
            {
                ModuleRCS rcs = (ModuleRCS)pm;
                if (!counted.Contains(rcs.resourceName))
                {
                    float        res = 0;
                    DCoMResource dcomRes;
                    if (DCoMMarker.Resource.TryGetValue(rcs.resourceName, out dcomRes))
                    {
                        res = (float)dcomRes.mass;
                    }
                    resourceMass += res;
                    counted.Add(rcs.resourceName);
                    PartResourceDefinition resInfo =
                        PartResourceLibrary.Instance.GetDefinition(rcs.resourceName);
                    switch (resInfo.resourceFlowMode)
                    {
                    case ResourceFlowMode.ALL_VESSEL:
                    case ResourceFlowMode.STAGE_PRIORITY_FLOW:
                        break;

                    default:
                        sanity = false;
                        break;
                    }
                }
            }
            return(resourceMass);
        }
Ejemplo n.º 4
0
 void calcRCSIsp(ref float num, ref float den)
 {
     foreach (PartModule pm in RCSBuildAid.RCS)
     {
         if (pm == null)
         {
             continue;
         }
         ModuleForces forces = pm.GetComponent <ModuleForces> ();
         if (forces && forces.enabled)
         {
             ModuleRCS mod = (ModuleRCS)pm;
             float     v1  = mod.atmosphereCurve.Evaluate(0f);
             foreach (VectorGraphic vector in forces.vectors)
             {
                 Vector3 thrust = vector.value;
                 float   v2     = Vector3.Dot(v1 * thrust.normalized,
                                              RCSBuildAid.VesselForces.Thrust().normalized * -1);
                 /* calculating weighted mean, RCS thrust magnitude is already "weighted" */
                 num += thrust.magnitude * v2;
                 den += thrust.magnitude;
             }
         }
     }
 }
Ejemplo n.º 5
0
 protected override void FailPart()
 {
     rcs = part.FindModuleImplementing <ModuleRCS>();
     if (rcs == null)
     {
         return;
     }
     if (rcs.vessel != FlightGlobals.ActiveVessel)
     {
         return;
     }
     rcs.rcsEnabled = false;
     if (UPFM.highlight)
     {
         UPFM.SetFailedHighlight();
     }
     if (message)
     {
         return;
     }
     message     = true;
     postMessage = true;
     ScreenMessages.PostScreenMessage("RCS Failure!");
     Debug.Log("[UPFM]: " + SYP.ID + " RCS has failed");
 }
Ejemplo n.º 6
0
 protected override void DI_Start(StartState state)
 {
     if (HighLogic.LoadedSceneIsFlight)
     {
         rcsModule = this.part.Modules.OfType <ModuleRCS>().Single();
     }
 }
Ejemplo n.º 7
0
 protected override void Overrides()
 {
     Fields["displayChance"].guiName = "Chance of RCS Failure";
     Fields["safetyRating"].guiName  = "RCS Safety Rating";
     failureType = "RCS Failure";
     rcs         = part.FindModuleImplementing <ModuleRCS>();
 }
Ejemplo n.º 8
0
        protected void findParentRCS(Part parentPart)
        {
            string    parentPartName = null;
            ModuleRCS rcsModule      = null;

            if (parentPart == null)
            {
                return;
            }

            //Find parent part. If it has RCS, then disable its RCS.
            if (parentPart.partInfo != null)
            {
                parentPartName = parentPart.partInfo.name.Replace('.', '_');
                if (disableRCSOnParts.Contains(parentPartName))
                {
                    rcsModule = parentPart.FindModuleImplementing <ModuleRCS>();
                    if (rcsModule == null)
                    {
                        return;
                    }
                    rcsModule.rcsEnabled = false;
                    parentRCS            = rcsModule;
                    wasAttached          = this.part.isAttached;
                }

                else
                {
                    //Walk up the chain
                    findParentRCS(parentPart.parent);
                }
            }
        }
 public override void OnStart(PartModule.StartState state) {
     String[] resources_to_supply = { FNResourceManager.FNRESOURCE_WASTEHEAT };
     attachedRCS = this.part.Modules["ModuleRCS"] as ModuleRCS;
     this.resources_to_supply = resources_to_supply;
     base.OnStart(state);
     if (state == StartState.Editor) return;
 }
        List <Propellant> GetEnginePropellants(PartModule engine)
        {
            string typename = engine.GetType().ToString();

            if (typename.Equals("ModuleEnginesFX"))
            {
                ModuleEnginesFX e = (ModuleEnginesFX)engine;
                return(e.propellants);
            }
            else if (typename.Equals("ModuleEngines"))
            {
                ModuleEngines e = (ModuleEngines)engine;
                return(e.propellants);
            }
            else if (typename.Equals("ModuleRCSFX"))
            {
                ModuleRCS e = (ModuleRCS)engine;
                return(e.propellants);
            }
            else if (typename.Equals("ModuleRCS"))
            {
                ModuleRCS e = (ModuleRCS)engine;
                return(e.propellants);
            }
            return(null);
        }
Ejemplo n.º 11
0
        public static void updateRCSFuelType(FuelTypeISP fuelType, Part part, int rcsModuleIndex)
        {
            if (rcsModuleIndex < 0)
            {
                return;
            }
            ModuleRCS[] modules = part.GetComponents <ModuleRCS>();
            int         len     = modules.Length;

            if (rcsModuleIndex < len)
            {
                ModuleRCS rcsModule = modules[rcsModuleIndex];
                rcsModule.propellants.Clear();
                ConfigNode pNode = fuelType.fuelPreset.getPropellantNode(ResourceFlowMode.ALL_VESSEL_BALANCE);
                if (fuelType.atmosphereCurve != null)
                {
                    pNode.AddNode("atmosphereCurve", fuelType.atmosphereCurve.getNode("atmosphereCurve"));
                }
                rcsModule.OnLoad(pNode);
            }
            else
            {
                SSTULog.error("Could not update fuel type - ModuleRCS could not be found for index: " + rcsModuleIndex + "  There are not enough modules present in the part: " + len);
            }
        }
Ejemplo n.º 12
0
 public Thruster(Vector3 pos, Vector3[] thrustDirections, Part p, ModuleRCS pm)
 {
     this.pos = pos;
     this.thrustDirections = thrustDirections;
     this.originalForce    = pm.thrusterPower;
     this.part             = p;
     this.partModule       = pm;
 }
Ejemplo n.º 13
0
 public Thruster(Vector3 pos, Vector3[] thrustDirections, Part p, ModuleRCS pm)
 {
     this.pos = pos;
     this.thrustDirections = thrustDirections;
     this.originalForce = pm.thrusterPower;
     this.part = p;
     this.partModule = pm;
 }
Ejemplo n.º 14
0
 protected override void Init()
 {
     module = GetComponent <ModuleRCS> ();
     if (module == null)
     {
         throw new Exception("Missing ModuleRCS component.");
     }
 }
 private void SetRcsInfo()
 {
     moduleRcs = selectedPart.GetModule <ModuleRCS>();
     if (moduleRcs != null)
     {
         infoItems.Add(PartInfoItem.Create("Thruster Power", moduleRcs.thrusterPower.ToForce()));
         infoItems.Add(PartInfoItem.Create("Specific Impulse", Units.ConcatF(moduleRcs.atmosphereCurve.Evaluate(1.0f), moduleRcs.atmosphereCurve.Evaluate(0.0f)) + "s"));
     }
 }
Ejemplo n.º 16
0
 void Awake()
 {
     module = GetComponent <ModuleRCS> ();
     if (module == null)
     {
         throw new Exception("Missing ModuleRCS component.");
     }
     base.Awake(module);
 }
Ejemplo n.º 17
0
 public bool Add(ModuleRCS m)
 {
     if (m == null)
     {
         return(false);
     }
     RCS.Add(new RCSWrapper(m));
     return(true);
 }
Ejemplo n.º 18
0
 public override void OnStart(PartModule.StartState state)
 {
     String[] resources_to_supply = { FNResourceManager.FNRESOURCE_WASTEHEAT };
     attachedRCS = this.part.Modules["ModuleRCS"] as ModuleRCS;
     this.resources_to_supply = resources_to_supply;
     base.OnStart(state);
     if (state == StartState.Editor)
     {
         return;
     }
 }
Ejemplo n.º 19
0
        private void updateRCSThrust()
        {
            rcsBlockModule.renameRCSThrustTransforms(rcsThrustTransformName);
            ModuleRCS rcsModule = part.GetComponent <ModuleRCS>();

            if (rcsModule != null)
            {
                ModelRCSModuleData data = rcsBlockModule.layoutOptions.definition.rcsModuleData;
                float thrust            = data.getThrust(rcsBlockModule.moduleVerticalScale);
                rcsModule.thrusterPower = thrust;
            }
        }
Ejemplo n.º 20
0
        private void updateRCSThrust()
        {
            ModuleRCS rcsModule = part.GetComponent <ModuleRCS>();

            if (rcsModule != null)
            {
                if (rcsThrust < 0)
                {
                    rcsThrust = rcsModule.thrusterPower;
                }
                rcsModule.thrusterPower = Mathf.Pow(currentScale, thrustScalePower) * rcsThrust;
            }
        }
Ejemplo n.º 21
0
        private void updateRCSFuelType()
        {
            if (!updateFuel)
            {
                return;
            }
            ModuleRCS rcsModule = part.GetComponent <ModuleRCS>();

            if (rcsModule != null)
            {
                rcsModule.propellants.Clear();
                ConfigNode pNode = fuelType.getPropellantNode(ResourceFlowMode.ALL_VESSEL_BALANCE);
                rcsModule.OnLoad(pNode);
            }
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Get engine thrust
        /// </summary>
        /// <param name="rcs">The rcs thruster (can be null - returns zero in that case)</param>
        /// <param name="atmPressure">
        ///   Atmospheric pressure (defaults to pressure at current location if omitted/null,
        ///   1.0 means Earth/Kerbin sea level, 0.0 is vacuum)</param>
        /// <returns>The thrust</returns>
        public static float GetThrust(this ModuleRCS rcs, double?atmPressure = null, bool useThrustLimit = false)
        {
            if (rcs == null)
            {
                return(0f);
            }
            float throttle = 1.0f;

            if (useThrustLimit)
            {
                throttle = throttle * rcs.thrustPercentage / 100.0f;
            }
            // thrust is fuel flow rate times isp times g
            // Assume min fuel flow is 0 as it's not exposed.
            return((float)(rcs.maxFuelFlow * throttle * GetIsp(rcs, atmPressure) * rcs.G));
        }
Ejemplo n.º 23
0
        private void updateRCSThrust()
        {
            if (modelTransform == null)
            {
                return;
            }                                      //don't adjust thrust when not responsible for model scaling
            ModuleRCS rcsModule = part.GetComponent <ModuleRCS>();

            if (rcsModule != null)
            {
                if (rcsThrust < 0)
                {
                    rcsThrust = rcsModule.thrusterPower;
                }
                rcsModule.thrusterPower = Mathf.Pow(currentScale, thrustScalePower) * rcsThrust;
            }
        }
Ejemplo n.º 24
0
 //turns the RCS off.
 public override void FailPart()
 {
     rcs = part.FindModuleImplementing <ModuleRCS>();
     if (rcs == null)
     {
         return;
     }
     rcs.rcsEnabled = false;
     if (OhScrap.highlight)
     {
         OhScrap.SetFailedHighlight();
     }
     if (hasFailed)
     {
         return;
     }
 }
Ejemplo n.º 25
0
        protected void setupGUI()
        {
            //Hide seat GUI
            seat = this.part.FindModuleImplementing <KerbalSeat>();
            seat.Events["BoardSeat"].guiActive          = false;
            seat.Events["BoardSeat"].guiActiveEditor    = false;
            seat.Events["BoardSeat"].guiActiveUnfocused = false;

            //Hide probe command GUI
            wingCommander = this.part.FindModuleImplementing <ModuleCommand>();
            wingCommander.Events["MakeReference"].guiActive          = false;
            wingCommander.Events["MakeReference"].guiActiveUnfocused = false;
            wingCommander.Events["RenameVessel"].guiActive           = false;

            //Hide decoupler GUI
            decoupler = this.part.FindModuleImplementing <ModuleDecouple>();
            decoupler.Events["Decouple"].guiActive          = false;
            decoupler.Events["Decouple"].guiActiveEditor    = false;
            decoupler.Events["Decouple"].guiActiveUnfocused = false;

            //Hide MultiModeEngine toggle button
            multiModeEngine = this.part.FindModuleImplementing <MultiModeEngine>();
            multiModeEngine.Events["ModeEvent"].guiActive          = false;
            multiModeEngine.Events["ModeEvent"].guiActiveEditor    = false;
            multiModeEngine.Events["ModeEvent"].guiActiveUnfocused = false;

            //Hide the Close Intake button.
            ModuleResourceIntake intake = this.part.FindModuleImplementing <ModuleResourceIntake>();

            intake.Events["Deactivate"].guiActive = false;

            //Hide RCS GUI
            ModuleRCS rcs = this.part.FindModuleImplementing <ModuleRCS>();

            rcs.Fields["realISP"].guiActive    = false;
            rcs.Fields["rcsEnabled"].guiActive = false;

            //Hide hover engine gui
            hoverEngine = this.part.FindModuleImplementing <WBIMultiEngineHover>();
            hoverEngine.SetGUIVisible(false);

            //Set fuel type
            resourceSwitcher = this.part.FindModuleImplementing <WBIResourceSwitcher>();
            resourceSwitcher.Fields["shortName"].guiName = "Fuel Type";
        }
Ejemplo n.º 26
0
 private void updateRCSModule()
 {
     if (rcsThrust < 0)
     {
         ModuleRCS mod = part.GetComponent <ModuleRCS>();
         if (mod != null)
         {
             rcsThrust = mod.thrusterPower;
         }
     }
     if (rcsThrust > 0)
     {
         rcsModule.model.renameThrustTransforms(rcsThrustTransformName);
         float scale  = currentTankDiameter / upperModule.model.modelDefinition.diameter;
         float thrust = rcsThrust * scale * scale;
         SSTUModularRCS.updateRCSModules(part, !rcsModule.model.dummyModel, thrust, true, true, true, true, true, true);
     }
 }
Ejemplo n.º 27
0
        private void AnalyzeRCS()
        {
            torqueRcs.Reset();

            EachKey(rcs, p => {
                List <ModuleRCS> mlist = p.Modules.GetModules <ModuleRCS>();

                for (int m = 0; m < mlist.Count; m++)
                {
                    Vector3 pos;
                    Vector3 neg;
                    ModuleRCS rw = mlist[m];
                    rw.GetPotentialTorque(out pos, out neg);
                    torqueRcs.Add(pos);
                    torqueRcs.Add(-neg);
                }
            });
        }
Ejemplo n.º 28
0
		void Process_rcs(ModuleRCS mr)
		{
			// calculate thrust fuel flow
			double thrust_flow = mr.maxFuelFlow * 1e3 * mr.thrustPercentage * mr.thrusterPower;

			// search fuel types
			foreach (Propellant fuel in mr.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;
				}
			}
		}
Ejemplo n.º 29
0
 private void updateRCSModule()
 {
     modularRCSControl = part.GetComponent <SSTUModularRCS>();
     if (modularRCSControl != null)
     {
         modularRCSControl.Start();
     }
     if (rcsThrust < 0)
     {
         ModuleRCS rcs = part.GetComponent <ModuleRCS>();
         if (rcs != null)
         {
             rcsThrust = rcs.thrusterPower;
         }
     }
     if (rcsThrust >= 0)
     {
         float thrust = rcsThrust * Mathf.Pow(coreModule.model.currentDiameterScale, 2);
         SSTUModularRCS.updateRCSModules(part, !rcsModule.model.dummyModel, thrust, true, true, true, true, true, true);
     }
 }
Ejemplo n.º 30
0
        // The part loop in VesselState could expose this, but it gets disabled when the RCS action group is disabled.
        // This method is also useful when the RCS AG is off.
        public static bool hasEnabledRCSModules(this Vessel vessel)
        {
            var rcsModules = vessel.FindPartModulesImplementing <ModuleRCS>();

            for (int m = 0; m < rcsModules.Count; m++)
            {
                ModuleRCS rcs = rcsModules[m];

                if (rcs == null)
                {
                    continue;
                }

                if (rcs.rcsEnabled && rcs.isEnabled && !rcs.isJustForShow)
                {
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 31
0
        public override void OnStart(StartState state)
        {
            base.OnStart(state);

            if (HighLogic.LoadedSceneIsFlight == false)
            {
                return;
            }

            rcsModule             = this.part.FindModuleImplementing <ModuleRCS>();
            originalThrusterPower = rcsModule.thrusterPower;

            //Set landing gear action
            ModuleAnimateGeneric kickstandAnim = this.part.FindModuleImplementing <ModuleAnimateGeneric>();

            kickstandAnim.Actions[0].actionGroup = KSPActionGroup.Gear;

            //Setup the GUI
            setupGUI();

            //Get the primary and secondary engine
            List <ModuleEnginesFX> engineList = this.part.FindModulesImplementing <ModuleEnginesFX>();

            foreach (ModuleEnginesFX engine in engineList)
            {
                if (engine.engineID == multiModeEngine.primaryEngineID)
                {
                    primaryEngine = engine;
                }
                else if (engine.engineID == multiModeEngine.secondaryEngineID)
                {
                    secondaryEngine = engine;
                }
            }

            //Setup the engine mode
            setupEngineMode();
        }
Ejemplo n.º 32
0
        public override void updateMultiMode(bool silentUpdate = false)
        {
            GTIDebug.Log("GTI_MultiModeRCS: updateMultiMode() --> Begin", iDebugLevel.High);
            if (!silentUpdate)
            {
                writeScreenMessage();
            }

            for (int i = 0; i < modes.Count; i++)
            {
                if (i == modes[currentModuleRCSindex].moduleIndex)
                {
                    currentModuleRCS         = ModuleRCSs[i];
                    currentModuleRCSindex    = i;
                    ModuleRCSs[i].rcsEnabled = true;
                }
                else
                {
                }
            }


            throw new NotImplementedException();
        }
 public override void OnAwake()
 {
     RCS = part.FindModuleImplementing<ModuleRCS>();
 }
Ejemplo n.º 34
0
 protected override void DI_Start(StartState state)
 {
     if (HighLogic.LoadedSceneIsFlight)
     {
         rcsModule = this.part.Modules.OfType<ModuleRCS>().Single();
     }
 }
 public RCSWrapper(ModuleRCS rcs)
 {
     zeroIsp = rcs.atmosphereCurve.Evaluate(0f);
     this.rcs = rcs;
 }
 private void SetRcsInfo()
 {
     moduleRcs = selectedPart.GetModule<ModuleRCS>();
     if (moduleRcs != null)
     {
         infoItems.Add(PartInfoItem.Create("Thruster Power", moduleRcs.thrusterPower.ToForce()));
         infoItems.Add(PartInfoItem.Create("Specific Impulse", Units.ConcatF(moduleRcs.atmosphereCurve.Evaluate(1.0f), moduleRcs.atmosphereCurve.Evaluate(0.0f)) + "s"));
     }
 }
        public override void OnStart(PartModule.StartState state)
        {
            // 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 = { FNResourceManager.FNRESOURCE_WASTEHEAT };
            this.resources_to_supply = resources_to_supply;

            attachedRCS = this.part.FindModuleImplementing<ModuleRCS>();
            oldThrustLimiter = thrustLimiter;
            oldPowerEnabled = powerEnabled;
            efficencyModifier = (float)g0 * 0.5f / 1000.0f / efficency;
            efficencyStr = (efficency * 100).ToString() + "%";

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

            // initialize propellant
            _propellants = ElectricEnginePropellant.GetPropellantsEngineForType(type);
            SetupPropellants(true, _propellants.Count);
            currentThrustMultiplier = hasSufficientPower ? Current_propellant.ThrustMultiplier : Current_propellant.ThrustMultiplierCold;

            base.OnStart(state);
        }
        public override void OnStart(PartModule.StartState state)
        {
            try
            {
                attachedRCS = this.part.FindModuleImplementing<ModuleRCS>();
                attachedModuleRCSFX = attachedRCS as FNModuleRCSFX;

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

                if (attachedModuleRCSFX != null)
                {
                    attachedModuleRCSFX.Fields["RCS"].guiActive = true;
                    attachedModuleRCSFX.Fields["enableYaw"].guiActive = true;
                    attachedModuleRCSFX.Fields["enablePitch"].guiActive = true;
                    attachedModuleRCSFX.Fields["enableRoll"].guiActive = true;
                    attachedModuleRCSFX.Fields["enableX"].guiActive = true;
                    attachedModuleRCSFX.Fields["enableY"].guiActive = true;
                    attachedModuleRCSFX.Fields["enableZ"].guiActive = true;
                    attachedModuleRCSFX.fullThrust = fullThrustEnabled;
                    attachedModuleRCSFX.fullThrustMin = fullThrustMinLimiter / 100;
                    attachedModuleRCSFX.useLever = useLeverEnabled;
                    attachedModuleRCSFX.precisionFactor = precisionFactorLimiter / 100;
                }

                // 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 = { FNResourceManager.FNRESOURCE_WASTEHEAT };
                this.resources_to_supply = resources_to_supply;

                oldThrustLimiter = thrustLimiter;
                oldPowerEnabled = powerEnabled;
                efficencyModifier = (float)g0 * 0.5f / 1000.0f / efficency;
                efficencyStr = (efficency * 100).ToString() + "%";

                if (!String.IsNullOrEmpty(AnimationName))
                    rcsStates = 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("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("ElectricRCSController OnStart index of fuelmode " + Current_propellant.PropellantGUIName + " = " + fuel_mode);
                }

                base.OnStart(state);

                Fields["electricalPowerConsumptionStr"].guiActive = showConsumption;
            }
            catch (Exception e)
            {
                Debug.LogError("ElectricRCSController OnStart Error: " + e.Message);
                throw;
            }
        }
Ejemplo n.º 39
0
 protected override void Init()
 {
     module = GetComponent<ModuleRCS> ();
     if (module == null) {
         throw new Exception ("Missing ModuleRCS component.");
     }
 }
Ejemplo n.º 40
0
        virtual public void SetConfiguration(string newConfiguration = null)
        {
            if (newConfiguration == null)
                newConfiguration = configuration;
            ConfigNode newConfig = configs.Find (c => c.GetValue ("name").Equals (newConfiguration));
            if (newConfig != null) {

                // for asmi
                if (useConfigAsTitle)
                    part.partInfo.title = configuration;

                configuration = newConfiguration;
                config = new ConfigNode ("MODULE");
                newConfig.CopyTo (config);
                config.name = "MODULE";

                // fix for HotRockets etc.
                if (type.Equals("ModuleEngines") && part.Modules.Contains("ModuleEnginesFX") && !part.Modules.Contains("ModuleEngines"))
                    type = "ModuleEnginesFX";
                if (type.Equals("ModuleEnginesFX") && part.Modules.Contains("ModuleEngines") && !part.Modules.Contains("ModuleEnginesFX"))
                    type = "ModuleEngines";
                // fix for ModuleRCSFX etc
                if (type.Equals("ModuleRCS") && part.Modules.Contains("ModuleRCSFX") && !part.Modules.Contains("ModuleRCS"))
                    type = "ModuleRCSFX";
                if (type.Equals("ModuleRCSFX") && part.Modules.Contains("ModuleRCS") && !part.Modules.Contains("ModuleRCSFX"))
                    type = "ModuleRCS";

                config.SetValue("name", type);

                #if DEBUG
                print ("replacing " + type + " with:");
                print (newConfig.ToString ());
                #endif

                pModule = null;
                if (part.Modules.Contains(type))
                {
                    if (type.Equals("ModuleEnginesFX"))
                    {
                        if (engineID != "")
                        {
                            foreach (ModuleEnginesFX mFX in part.Modules.OfType<ModuleEnginesFX>())
                            {
                                if (mFX.engineID.Equals(engineID))
                                    pModule = (PartModule)mFX;
                            }
                        }
                        else if (moduleIndex >= 0)
                        {
                            int tmpIdx = 0;
                            pModule = null;
                            foreach (PartModule pM in part.Modules)
                            {
                                if (pM.GetType().Equals(type))
                                {
                                    if (tmpIdx == moduleIndex)
                                        pModule = pM;
                                    tmpIdx++;
                                }
                            }
                        }
                        else
                            pModule = part.Modules[type];
                    }
                    else
                        pModule = part.Modules[type];

                    if ((object)pModule == null)
                    {
                        Debug.Log("*RF* Could not find appropriate module of type " + type + ", with ID=" + engineID + " and index " + moduleIndex);
                        return;
                    }
                    // clear all FloatCurves
                    Type mType = pModule.GetType();
                    foreach (FieldInfo field in mType.GetFields())
                    {
                        if (field.FieldType == typeof(FloatCurve) && (field.Name.Equals("atmosphereCurve") || field.Name.Equals("velocityCurve")))
                        {
                            //print("*MFS* resetting curve " + field.Name);
                            field.SetValue(pModule, new FloatCurve());
                        }
                    }
                    // clear propellant gauges
                    foreach (FieldInfo field in mType.GetFields(BindingFlags.NonPublic | BindingFlags.Instance))
                    {
                        if (field.FieldType == typeof(Dictionary<Propellant, VInfoBox>))
                        {
                            Dictionary<Propellant, VInfoBox> boxes = (Dictionary<Propellant, VInfoBox>)(field.GetValue(pModule));
                            if (boxes == null)
                                continue;
                            foreach (VInfoBox v in boxes.Values)
                            {
                                if (v == null) //just in case...
                                    continue;
                                try
                                {
                                    part.stackIcon.RemoveInfo(v);
                                }
                                catch (Exception e)
                                {
                                    print("*MFS* Trying to remove info box: " + e.Message);
                                }
                            }
                            boxes.Clear();
                        }
                    }
                }
                if (type.Equals("ModuleRCS") || type.Equals("ModuleRCSFX"))
                {
                    ModuleRCS rcs = (ModuleRCS)pModule;
                    if (rcs != null)
                    {
                        rcs.G = 9.80665f;
                        /*bool oldRes = config.HasValue("resourceName");
                        string resource = "";
                        if (oldRes)
                        {
                            resource = config.GetValue("resourceName");
                            rcs.resourceName = resource;
                        }*/
                        DoConfig(config);
                        if (config.HasNode("PROPELLANT"))
                        {
                            rcs.propellants.Clear();
                        }
                        pModule.Load(config);
                        /*if (oldRes)
                        {
                            rcs.resourceName = resource;
                            rcs.SetResource(resource);
                        }*/
                        // PROPELLANT handling is automatic.
                        fastRCS = rcs;
                        if(type.Equals("ModuleRCS") && !part.Modules.Contains("ModuleRCSFX"))
                            fastType = ModuleType.MODULERCS;
                        else
                            fastType = ModuleType.MODULERCSFX;
                    }
                }
                else
                { // is an ENGINE
                    if (type.Equals("ModuleEngines"))
                    {
                        ModuleEngines mE = (ModuleEngines)pModule;
                        if (mE != null)
                        {
                            configMaxThrust = mE.maxThrust;
                            configMinThrust = mE.minThrust;
                            fastEngines = mE;
                            fastType = ModuleType.MODULEENGINES;
                            mE.g = 9.80665f;
                            if (config.HasNode("PROPELLANT"))
                            {
                                mE.propellants.Clear();
                            }
                        }
                        if (config.HasValue("maxThrust"))
                        {
                            float thr;
                            if(float.TryParse(config.GetValue("maxThrust"), out thr))
                                configMaxThrust = thr;
                        }
                        if (config.HasValue("minThrust"))
                        {
                            float thr;
                            if(float.TryParse(config.GetValue("minThrust"), out thr))
                                configMinThrust = thr;
                        }
                    }
                    else if (type.Equals("ModuleEnginesFX"))
                    {
                        ModuleEnginesFX mE = (ModuleEnginesFX)pModule;
                        if (mE != null)
                        {
                            configMaxThrust = mE.maxThrust;
                            configMinThrust = mE.minThrust;
                            fastEnginesFX = mE;
                            fastType = ModuleType.MODULEENGINESFX;
                            mE.g = 9.80665f;
                            if (config.HasNode("PROPELLANT"))
                            {
                                mE.propellants.Clear();
                            }
                        }
                        if (config.HasValue("maxThrust"))
                        {
                            float thr;
                            if (float.TryParse(config.GetValue("maxThrust"), out thr))
                                configMaxThrust = thr;
                        }
                        if (config.HasValue("minThrust"))
                        {
                            float thr;
                            if (float.TryParse(config.GetValue("minThrust"), out thr))
                                configMinThrust = thr;
                        }
                    }
                    DoConfig(config);
                    if(pModule != null)
                        pModule.Load (config);
                    if (config.HasNode("ModuleEngineIgnitor") && part.Modules.Contains("ModuleEngineIgnitor"))
                    {
                        ConfigNode eiNode = config.GetNode("ModuleEngineIgnitor");
                        if (eiNode.HasValue("ignitionsAvailable"))
                        {
                            int ignitions;
                            if (int.TryParse(eiNode.GetValue("ignitionsAvailable"), out ignitions))
                            {
                                if (ignitions < 0)
                                {
                                    ignitions = techLevel + ignitions;
                                    if (ignitions < 1)
                                        ignitions = 1;
                                }
                                else if (ignitions == 0)
                                    ignitions = -1;

                                eiNode.SetValue("ignitionsAvailable", ignitions.ToString());
                                if (eiNode.HasValue("ignitionsRemained"))
                                    eiNode.SetValue("ignitionsRemained", ignitions.ToString());
                                else
                                    eiNode.AddValue("ignitionsRemained", ignitions.ToString());
                            }
                        }
                        if (!HighLogic.LoadedSceneIsEditor && !(HighLogic.LoadedSceneIsFlight && vessel != null && vessel.situation == Vessel.Situations.PRELAUNCH)) // fix for prelaunch
                        {
                            int remaining = (int)(part.Modules["ModuleEngineIgnitor"].GetType().GetField("ignitionsRemained").GetValue(part.Modules["ModuleEngineIgnitor"]));
                            if(eiNode.HasValue("ignitionsRemained"))
                                eiNode.SetValue("ignitionsRemained", remaining.ToString());
                            else
                                eiNode.AddValue("ignitionsRemained", remaining.ToString());
                        }
                        ConfigNode tNode = new ConfigNode("MODULE");
                        eiNode.CopyTo(tNode);
                        tNode.SetValue("name", "ModuleEngineIgnitor");
                        part.Modules["ModuleEngineIgnitor"].Load(tNode);
                    }
                }
                if (part.Resources.Contains("ElectricCharge") && part.Resources["ElectricCharge"].maxAmount < 0.1)
                { // hacking around a KSP bug here
                    part.Resources["ElectricCharge"].amount = 0;
                    part.Resources["ElectricCharge"].maxAmount = 0.1;
                }
                if (config.HasValue("cost"))
                    configCost = float.Parse(config.GetValue("cost"));
                UpdateTweakableMenu();
                // Check for and enable the thrust curve
                useThrustCurve = false;
                Fields["thrustCurveDisplay"].guiActive = false;
                if (config.HasNode("thrustCurve") && config.HasValue("curveResource"))
                {
                    curveResource = config.GetValue("curveResource");
                    if (curveResource != "")
                    {
                        double ratio = 0.0;
                        switch (fastType)
                        {
                            case ModuleType.MODULEENGINES:
                                configHeat = fastEngines.heatProduction;
                                for (int i = 0; i < fastEngines.propellants.Count; i++ )
                                    if (fastEngines.propellants[i].name.Equals(curveResource))
                                        curveProp = i;
                                if (curveProp >= 0)
                                    ratio = fastEngines.propellants[curveProp].totalResourceAvailable / fastEngines.propellants[curveProp].totalResourceCapacity;
                                break;

                            case ModuleType.MODULEENGINESFX:
                                configHeat = fastEnginesFX.heatProduction;
                                for (int i = 0; i < fastEnginesFX.propellants.Count; i++)
                                    if (fastEnginesFX.propellants[i].name.Equals(curveResource))
                                        curveProp = i;
                                if (curveProp >= 0)
                                    ratio = fastEnginesFX.propellants[curveProp].totalResourceAvailable / fastEnginesFX.propellants[curveProp].totalResourceCapacity;
                                break;

                            case ModuleType.MODULERCS:
                                for (int i = 0; i < fastRCS.propellants.Count; i++)
                                    if (fastRCS.propellants[i].name.Equals(curveResource))
                                        curveProp = i;
                                if (curveProp >= 0)
                                    ratio = fastRCS.propellants[curveProp].totalResourceAvailable / fastRCS.propellants[curveProp].totalResourceCapacity;
                                break;
                        }
                        if (curveProp != -1)
                        {
                            useThrustCurve = true;
                            configThrustCurve = new FloatCurve();
                            configThrustCurve.Load(config.GetNode("thrustCurve"));
                            print("*RF* Found thrust curve for " + part.name);
                            Fields["thrustCurveDisplay"].guiActive = true;
                        }
                        
                    }
                }
            }
            
        }