Beispiel #1
0
        /// <summary>Re-applies GUI name string from the action attributes.</summary>
        /// <param name="actions">The actions to process.</param>
        static void UpdateStockActions(BaseActionList actions)
        {
            var ownerType = actions.module != null
        ? actions.module.GetType()
        : actions.part.GetType();

            foreach (var kspAction in actions)
            {
                var info = ownerType.GetMethod(
                    kspAction.name,
                    BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic,
                    null /* default binder */,
                    new[] { typeof(KSPActionParam) },
                    null /* no modifiers */);
                if (info == null)
                {
                    DebugEx.Error("Cannot get action: {0}.{1}", ownerType.FullName, kspAction.name);
                    continue;
                }
                info = info.GetBaseDefinition(); // Only the base has the right attributes.
                SetupArgumentFromAttribute(
                    info, typeof(KSPAction), nameof(KSPAction.guiName),
                    x => {
                    kspAction.guiName = x;
                });
            }
        }
Beispiel #2
0
        private void invokeAction(PartModule pm, string actionName)
        {
            printDebug("Invoking action " + actionName + " on part " + pm.part.name);
            BaseActionList bal = new BaseActionList(pm.part, pm);             //create a BaseActionList bal with the available actions on the part. p being our current part, pm being our current partmodule

            if (bal.Count == 0)
            {
                return;
            }
            foreach (BaseAction ba in bal)                                                                 //start cycling through baseActions in the BaseActionList
            {
                if (ba.guiName == actionName)                                                              //Trigger is a bool set to true via a GUI button on-screen (code not shown)
                {
                    KSPActionParam ap = new KSPActionParam(KSPActionGroup.None, KSPActionType.Deactivate); //an important line, see post
                    ba.Invoke(ap);                                                                         //Invoke the "Extend Panel" command (our current ba. variable) with the ActionParameter from the previous line.
                }
            }
        }
        internal static void invokeAction(PartModule pm, string actionName)
        {
            Log.detail("Invoking action {0} on part {1}", actionName, pm.part.name);
            // https://forum.kerbalspaceprogram.com/index.php?/topic/65106-trigger-a-parts-action-from-code/
            BaseActionList bal = new BaseActionList(pm.part, pm);             //create a BaseActionList bal with the available actions on the part.

            //p being our current part, pm being our current partmodule
            if (bal.Count == 0)
            {
                return;
            }
            foreach (BaseAction ba in bal)                                                                 //start cycling through baseActions in the BaseActionList
            {
                if (ba.guiName == actionName)                                                              //Trigger is a bool set to true via a GUI button on-screen (code not shown)
                {
                    KSPActionParam ap = new KSPActionParam(KSPActionGroup.None, KSPActionType.Deactivate); //an important line, see post
                    ba.Invoke(ap);                                                                         //Invoke the "Extend Panel" command (our current ba. variable) with the ActionParameter from the previous line.
                }
            }
        }
 public extern BaseAction(BaseActionList listParent, string name, BaseActionDelegate onEvent, KSPAction actionAttr);
Beispiel #5
0
        //============================================================================================================================================
        public void EngageGear()
        {
            //Look through each part that is enabled
            foreach (Part EnabledPart in EnabledPartList) {
                //Check to see if it is a certain module type
                //---------------------------------------------------------------------------------------------------------------------
                //Landing Gear Module
                if (EnabledPart.Modules.Contains ("ModuleLandingGear")) {
                    //Create new Instance of ModuleLandingGear to reference
                    ModuleLandingGear MLG = new ModuleLandingGear ();
                    MLG = EnabledPart.FindModuleImplementing<ModuleLandingGear> ();
                    //Increase count by 1 of enabled parts for GUI display
                    RoboBrakes_GearEnabledCount++;
                    //Create a list of actions that are available to this particular part & it's modules
                    BaseActionList BAL = new BaseActionList (EnabledPart, MLG);
                    //Cycle throught each action
                    foreach (BaseAction BA in BAL) {
                        //Find the 'Brakes' action
                        if (BA.guiName == "Brakes") {
                            //Engage brakes (or other action) when triggered
                            if ((RoboBrakes_AUTOMATICBRAKE_ACTIVE == true && RoboBrakes_GEARAUTO == true) | (RoboBrakes_OVERRIDEBRAKE_ACTIVE == true && RoboBrakes_GEAROVERRIDE == true)) {
                                //Create Action Parameter for enabling brakes (or other action) - I don't full understand this, but it is needed to activate the action
                                KSPActionParam AP = new KSPActionParam (KSPActionGroup.None, KSPActionType.Activate);
                                //Perform said action
                                BA.Invoke (AP);
                            } else {
                                //Create Action Parameter for disabling brakes (or other action)
                                KSPActionParam AP = new KSPActionParam (KSPActionGroup.None, KSPActionType.Deactivate);
                                //Perform said action
                                BA.Invoke (AP);
                            }
                        }
                    }
                }

                //---------------------------------------------------------------------------------------------------------------------
                //Advanced Landing Gear Module
                if (EnabledPart.Modules.Contains ("ModuleAdvancedLandingGear")) {
                    ModuleAdvancedLandingGear MALG = new ModuleAdvancedLandingGear ();
                    MALG = EnabledPart.FindModuleImplementing<ModuleAdvancedLandingGear> ();
                    RoboBrakes_GearEnabledCount++;
                    BaseActionList BAL = new BaseActionList (EnabledPart, MALG);
                    foreach (BaseAction BA in BAL) {
                        if (BA.guiName == "Brakes") {
                            if ((RoboBrakes_AUTOMATICBRAKE_ACTIVE == true && RoboBrakes_GEARAUTO == true) | (RoboBrakes_OVERRIDEBRAKE_ACTIVE == true && RoboBrakes_GEAROVERRIDE == true)) {
                                KSPActionParam AP = new KSPActionParam (KSPActionGroup.None, KSPActionType.Activate);
                                BA.Invoke (AP);
                            } else {
                                KSPActionParam AP = new KSPActionParam (KSPActionGroup.None, KSPActionType.Deactivate);
                                BA.Invoke (AP);
                            }
                        }
                    }
                }

                //---------------------------------------------------------------------------------------------------------------------
                //Fixed Landing Gear Module
                if (EnabledPart.Modules.Contains ("ModuleLandingGearFixed")) {
                    ModuleLandingGearFixed MLGF = new ModuleLandingGearFixed ();
                    MLGF = EnabledPart.FindModuleImplementing<ModuleLandingGearFixed> ();
                    //These Gear are always down
                    RoboBrakes_GearEnabledCount++;
                    BaseActionList BAL = new BaseActionList (EnabledPart, MLGF);
                    foreach (BaseAction BA in BAL) {
                        if (BA.guiName == "Brakes") {
                            if ((RoboBrakes_AUTOMATICBRAKE_ACTIVE == true && RoboBrakes_GEARAUTO == true) | (RoboBrakes_OVERRIDEBRAKE_ACTIVE == true && RoboBrakes_GEAROVERRIDE == true)) {
                                KSPActionParam AP = new KSPActionParam (KSPActionGroup.None, KSPActionType.Activate);
                                BA.Invoke (AP);
                            } else {
                                KSPActionParam AP = new KSPActionParam (KSPActionGroup.None, KSPActionType.Deactivate);
                                BA.Invoke (AP);
                            }
                        }
                    }
                }
            }
        }
Beispiel #6
0
        //============================================================================================================================================
        public void EngageAero()
        {
            //FAR Compatibility =)
            //Skip this if FAR isn't being used
            if (assemblyFARUsed == true) {
                foreach (Part EnabledPart in EnabledPartList) {
                    if (EnabledPart.Modules.Contains ("FARControllableSurface")) {
                        AeroFARModuleReference = EnabledPart.Modules ["FARControllableSurface"];
                        if (AeroFARModuleReference.Fields.GetValue ("isSpoiler").ToString() == "True") {
                            RoboBrakes_AeroEnabledCount++;
                            BaseActionList BAL = new BaseActionList (EnabledPart, AeroFARModuleReference);
                            foreach (BaseAction BA in BAL) {
                                if ((RoboBrakes_AUTOMATICBRAKE_ACTIVE == true && RoboBrakes_AEROAUTO == true) | (RoboBrakes_OVERRIDEBRAKE_ACTIVE == true && RoboBrakes_AEROOVERRIDE == true)) {
                                    if (BA.guiName == "Activate Spoiler") {
                                        KSPActionParam AP = new KSPActionParam (KSPActionGroup.None, KSPActionType.Activate);
                                        BA.Invoke (AP);
                                    }
                                } else {
                                    if (BA.guiName == "Activate Spoiler") {
                                        KSPActionParam AP = new KSPActionParam (KSPActionGroup.None, KSPActionType.Deactivate);
                                        BA.Invoke (AP);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            foreach (Part EnabledPart in EnabledPartList) {
                //---------------------------------------------------------------------------------------------------------------------
                //Control Surface Module
                if (EnabledPart.Modules.Contains ("ModuleControlSurface")) {
                    ModuleControlSurface MCS = new ModuleControlSurface ();
                    MCS = EnabledPart.FindModuleImplementing<ModuleControlSurface> ();
                    RoboBrakes_AeroEnabledCount++;
                    BaseActionList BAL = new BaseActionList (EnabledPart, MCS);
                    foreach (BaseAction BA in BAL) {
                        if ((RoboBrakes_AUTOMATICBRAKE_ACTIVE == true && RoboBrakes_AEROAUTO == true) | (RoboBrakes_OVERRIDEBRAKE_ACTIVE == true && RoboBrakes_AEROOVERRIDE == true)) {
                            if (BA.guiName == "Extend") {
                                KSPActionParam AP = new KSPActionParam (KSPActionGroup.None, KSPActionType.Activate);
                                BA.Invoke (AP);
                            }
                        } else {
                            if (BA.guiName == "Retract") {
                                KSPActionParam AP = new KSPActionParam (KSPActionGroup.None, KSPActionType.Activate);
                                BA.Invoke (AP);
                            }
                        }
                    }
                }

                //---------------------------------------------------------------------------------------------------------------------
                //Module Aero Surface
                if (EnabledPart.Modules.Contains ("ModuleAeroSurface")) {
                    ModuleAeroSurface MAS = new ModuleAeroSurface ();
                    MAS = EnabledPart.FindModuleImplementing<ModuleAeroSurface> ();
                    RoboBrakes_AeroEnabledCount++;
                    BaseActionList BAL = new BaseActionList (EnabledPart, MAS);
                    foreach (BaseAction BA in BAL) {
                        if ((RoboBrakes_AUTOMATICBRAKE_ACTIVE == true && RoboBrakes_AEROAUTO == true) | (RoboBrakes_OVERRIDEBRAKE_ACTIVE == true && RoboBrakes_AEROOVERRIDE == true)) {
                            if (BA.guiName == "Extend") {
                                KSPActionParam AP = new KSPActionParam (KSPActionGroup.None, KSPActionType.Activate);
                                BA.Invoke (AP);
                            }
                        } else {
                            if (BA.guiName == "Retract") {
                                KSPActionParam AP = new KSPActionParam (KSPActionGroup.None, KSPActionType.Activate);
                                BA.Invoke (AP);
                            }
                        }
                    }
                }
            }
        }
 public extern BaseAction(BaseActionList listParent, string name, BaseActionDelegate onEvent, KSPAction actionAttr);
Beispiel #8
0
 public static string FormatActions(BaseActionList actions)
 {
     return(actions.Aggregate("", (s, a) => s + string.Format("{0} ({1}, active: {2}); ",
                                                              a.guiName, a.actionGroup, a.active)));
 }