Exemple #1
0
        private Func <float> FindSuitableMemberOnEnginesModule()
        {
            const BindingFlags bindingFlags = BindingFlags.Instance | BindingFlags.Public;

            var methodInfo = engineController.GetType()
                             .GetMethods(bindingFlags)
                             .FirstOrDefault(m => m.Name == memberName && m.GetParameters().Length == 0);

            if (methodInfo != null)
            {
                return(() => Convert.ToSingle(methodInfo.Invoke(engineController, new object[0])));
            }

            var propertyInfo = engineController.GetType()
                               .GetProperty(memberName, bindingFlags);

            if (propertyInfo != null)
            {
                return(() => (float)propertyInfo.GetValue(engineController));
            }

            var fieldInfo = engineController.GetType()
                            .GetField(memberName, bindingFlags);

            if (fieldInfo != null)
            {
                return(() => Convert.ToSingle(fieldInfo.GetValue(engineController)));
            }

            Utils.LogError($"[{nameof(CustomPullController)}]: Could not find any public instance method, property or field named {memberName} to use with {nameof(CustomPullController)} named {name}, effect controller will not do anything");
            return(() => 0);
        }
Exemple #2
0
    public void InitWithEngine(Part part, string engineID)
    {
        ModuleEngines _engine = null;

        foreach (PartModule pm in part.Modules)
        {
            _engine = pm as ModuleEngines;
            if (_engine != null && (engineID == "" || _engine.engineID.ToLowerInvariant() == engineID.ToLowerInvariant()))
            {
                break;
            }
        }
        if (_engine != null)
        {
            engine = _engine;
            string tName = engine.GetType().Name;
            if (tName == "ModuleEnginesRF" || tName.Contains("ModuleEnginesAJE"))
            {
                engineType = EngineModuleType.SOLVERENGINE;
            }
            else
            {
                engineType = EngineModuleType.ENGINE;
            }

            _minFuelFlow = engine.minFuelFlow;
            _maxFuelFlow = engine.maxFuelFlow;
            _g           = engine.g;
        }
        else
        {
            engineType = EngineModuleType.UNKNOWN;
        }
    }
    protected override bool SetupModule()
    {
        foreach (PartModule cModule in part.Modules)
        {
            if (cModule.GetType() != typeof(ModuleEngines))
            {
                continue;
            }

            _Engine = cModule as ModuleEngines;
            break;
        }

        if (_Engine != null)
        {
            _Thrust = _Engine.GetType().GetField("finalThrust");

            if (UseMaxThrust)
            {
                this.MaxValue = _Engine.maxThrust;
            }
        }

        return(base.SetupModule());
    }
Exemple #4
0
 // Reduce fuel flow
 public void SetFuelFlowMult(float multiplier)
 {
     if (engineType == EngineModuleType.UNKNOWN)
     {
         return;
     }
     if (engineType == EngineModuleType.SOLVERENGINE)
     {
         engine.GetType().GetField("flowMult").SetValue(engine, multiplier);
     }
     else
     {
         engine.minFuelFlow = _minFuelFlow * multiplier;
         engine.maxFuelFlow = _maxFuelFlow * multiplier;
     }
 }
    protected override bool SetupModule()
    {
        foreach (PartModule cModule in part.Modules)
        {
            if (cModule.GetType() != typeof(ModuleEngines))
                continue;

            _Engine = cModule as ModuleEngines;
            break;
        }

        if (_Engine != null)
        {
            _Thrust = _Engine.GetType().GetField("finalThrust");

            if(UseMaxThrust)
                this.MaxValue = _Engine.maxThrust;
        }

        return base.SetupModule();
    }