public void OnDestroy() { if (this == vessel.GetMasterMechJeb() && (vessel == null || vessel.isActiveVessel)) { OnSave(null); } GameEvents.onShowUI.Remove(OnShowGUI); GameEvents.onHideUI.Remove(OnHideGUI); GameEvents.onVesselChange.Remove(UnlockControl); if (weLockedInputs) { UnlockControl(); ManeuverGizmo.HasMouseFocus = false; } foreach (ComputerModule module in GetComputerModules <ComputerModule>()) { try { module.OnDestroy(); } catch (Exception e) { Log.err(e, "module {0} threw an exception in OnDestroy: ", module.GetType().Name, e); } } if (vessel != null) { vessel.OnFlyByWire -= OnFlyByWire; } controlledVessel = null; }
private void EngageTranslatronControl(MechJebModuleThrustController.TMode mode) { MechJebCore masterMechJeb = vessel.GetMasterMechJeb(); if (masterMechJeb != null) { MechJebModuleTranslatron moduleTranslatron = masterMechJeb.GetComputerModule <MechJebModuleTranslatron>(); if (moduleTranslatron != null && !moduleTranslatron.hidden) { if ((thrust.users.Count > 1) && !thrust.users.Contains(moduleTranslatron)) { return; } moduleTranslatron.SetMode(mode); } else { Log.err("couldn't find MechJebModuleTranslatron for translatron control via action group."); } } else { Log.err("couldn't find the master MechJeb module for the current vessel."); } }
private void EngageSmartASSOrbitalControl(MechJebModuleSmartASS.Target target) { MechJebCore masterMechJeb = this.vessel.GetMasterMechJeb(); if (masterMechJeb != null) { MechJebModuleSmartASS masterSmartASS = masterMechJeb.GetComputerModule <MechJebModuleSmartASS>(); if (masterSmartASS != null && !masterSmartASS.hidden) { masterSmartASS.mode = MechJebModuleSmartASS.Mode.ORBITAL; masterSmartASS.target = target; masterSmartASS.Engage(); } else { //Log.err(Localizer.Format("#MechJeb_LogError_msg1"));//"MechJeb couldn't find MechJebModuleSmartASS for orbital control via action group." Log.err("couldn't find MechJebModuleSmartASS for orbital control via action group."); } } else { //Log.err(Localizer.Format("#MechJeb_LogError_msg0"));//"MechJeb couldn't find the master MechJeb module for the current vessel." Log.err("couldn't find the master MechJeb module for the current vessel."); } }
public static FieldInfo getFieldByReflection(String assemblyString, String className, String fieldName, BindingFlags flags = BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static) { string assemblyName = ""; foreach (AssemblyLoader.LoadedAssembly loaded in AssemblyLoader.loadedAssemblies) { if (loaded.assembly.GetName().Name == assemblyString) { assemblyName = loaded.assembly.FullName; } } if (assemblyName == "") { Log.err("ReflectionUtils: could not find assembly {0}", assemblyString); return(null); } Type type = Type.GetType(className + ", " + assemblyName); if (type == null) { Log.err("ReflectionUtils: could not find type {0}, {1}", className, assemblyName); return(null); } return(type.GetField(fieldName, flags)); }
public static MethodInfo getMethodByReflection(String assemblyString, String className, String methodName, BindingFlags flags, Type[] args) { string assemblyName = ""; foreach (AssemblyLoader.LoadedAssembly loaded in AssemblyLoader.loadedAssemblies) { if (loaded.assembly.GetName().Name == assemblyString) { assemblyName = loaded.assembly.FullName; } } if (assemblyName == "") { Log.err("ReflectionUtils: could not find assembly {0}", assemblyString); return(null); } Type type = Type.GetType(className + ", " + assemblyName); if (type == null) { Log.err("ReflectionUtils: could not find type {0}, {1}", className, assemblyName); return(null); } return(type.GetMethod(methodName, flags, null, args, null)); }
protected void RunSimulation(object o) { try { CelestialBody simBody = HighLogic.LoadedSceneIsEditor ? editorBody : vessel.mainBody; double staticPressureKpa = (HighLogic.LoadedSceneIsEditor || !liveSLT ? (simBody.atmosphere ? simBody.GetPressure(altSLT) : 0) : vessel.staticPressurekPa); double atmDensity = (HighLogic.LoadedSceneIsEditor || !liveSLT ? simBody.GetDensity(simBody.GetPressure(altSLT), simBody.GetTemperature(0)) : vessel.atmDensity) / 1.225; double mach = HighLogic.LoadedSceneIsEditor ? this.mach : vessel.mach; //Run the simulation newAtmoStats = sims[0].SimulateAllStages(1.0f, staticPressureKpa, atmDensity, mach); newVacStats = sims[1].SimulateAllStages(1.0f, 0.0, 0.0, mach); } catch (Exception e) { Log.err(e, "Exception in MechJebModuleStageStats.RunSimulation(): {0}", e.Message); } //see how long the simulation took stopwatch.Stop(); long millisecondsToCompletion = stopwatch.ElapsedMilliseconds; stopwatch.Reset(); //set the delay before the next simulation millisecondsBetweenSimulations = 2 * millisecondsToCompletion; //start the stopwatch that will count off this delay stopwatch.Start(); resultReady = true; simulationRunning = false; }
private void Drive(FlightCtrlState s) { Profiler.BeginSample("vesselState"); ready = vesselState.Update(vessel); Profiler.EndSample(); Profiler.BeginSample("MechJebCore.Drive"); if (this == vessel.GetMasterMechJeb()) { foreach (ComputerModule module in GetComputerModules <ComputerModule>()) { Profiler.BeginSample(module.profilerName); try { if (module.enabled) { module.Drive(s); } } catch (Exception e) { Log.err(e, "module {0} threw an exception in Drive: {1}", module.GetType().Name, e); } Profiler.EndSample(); } } Profiler.EndSample(); }
public void LoadConfig(int slot, bool notify, bool forceSlotName) { if (vessel == null) { return; } if (slot != 9) { this.selectedSlot = slot; //Select the slot for the UI. Except slot 9 (temp) } string slotName = this.getSaveSlotName(forceSlotName); ConfigNode node = new ConfigNode("MechJebScriptSettings"); if (File.Exists <MechJebCore>("mechjeb_settings_script_" + slotName + "_" + slot + ".cfg")) { try { node = ConfigNode.Load(IOUtils.GetFilePathFor(this.GetType(), "mechjeb_settings_script_" + slotName + "_" + slot + ".cfg")); } catch (Exception e) { Log.err("MechJebModuleScript.LoadConfig caught an exception trying to load mechjeb_settings_script_{0}_{1}.cfg: ", slotName, slot, e); } } else if (notify) { this.setFlashMessage("ERROR: File not found: mechjeb_settings_script_" + slotName + "_" + slot + ".cfg", 1); } if (node == null) { return; } actionsList.LoadConfig(node); }
IEnumerator Start() { // We do this in MainMenu because something is going on in that scene that kills anything loaded with a bundle if (diffuseAmbient) { Log.info("Shaders already loaded"); } Log.info("Loading Shaders Bundles"); // Load the font asset bundle AssetBundleCreateRequest bundleLoadRequest = AssetBundle.LoadFromFileAsync(shaderPath); yield return(bundleLoadRequest); AssetBundle assetBundle = bundleLoadRequest.assetBundle; if (assetBundle == null) { Log.err("Failed to load AssetBundle {0}", shaderPath); yield break; } AssetBundleRequest assetLoadRequest = assetBundle.LoadAssetAsync <Shader>(diffuseAmbientName); yield return(assetLoadRequest); diffuseAmbient = assetLoadRequest.asset as Shader; assetLoadRequest = assetBundle.LoadAssetAsync <Shader>(diffuseAmbientIgnoreZName); yield return(assetLoadRequest); diffuseAmbientIgnoreZ = assetLoadRequest.asset as Shader; assetBundle.Unload(false); Log.info("Loaded Shaders Bundles"); comboBoxBackground = new Texture2D(16, 16, TextureFormat.RGBA32, false); comboBoxBackground.wrapMode = TextureWrapMode.Clamp; for (int x = 0; x < comboBoxBackground.width; x++) { for (int y = 0; y < comboBoxBackground.height; y++) { if (x == 0 || x == comboBoxBackground.width - 1 || y == 0 || y == comboBoxBackground.height - 1) { comboBoxBackground.SetPixel(x, y, new Color(0, 0, 0, 1)); } else { comboBoxBackground.SetPixel(x, y, new Color(0.05f, 0.05f, 0.05f, 0.95f)); } } } comboBoxBackground.Apply(); }
protected void StartSimulation() { Profiler.BeginSample("StartSimulation"); try { simulationRunning = true; resultReady = false; stopwatch.Start(); //starts a timer that times how long the simulation takes //Create two FuelFlowSimulations, one for vacuum and one for atmosphere List <Part> parts = (HighLogic.LoadedSceneIsEditor ? EditorLogic.fetch.ship.parts : vessel.parts); if (HighLogic.LoadedSceneIsEditor) { if (needRebuild > 0) { PartSet.BuildPartSets(parts, null); needRebuild--; } } else { vessel.UpdateResourceSetsIfDirty(); } Profiler.BeginSample("StartSimulation_Init"); sims[0].Init(parts, dVLinearThrust); sims[1].Init(parts, dVLinearThrust); Profiler.EndSample(); //Run the simulation in a separate thread ThreadPool.QueueUserWorkItem(RunSimulation, sims); //Profiler.BeginSample("StartSimulation_Run"); //RunSimulation(sims); //Profiler.EndSample(); } catch (Exception e) { Log.err(e, "Exception in MechJebModuleStageStats.StartSimulation(): {0}\n", e.StackTrace); // Stop timing the simulation stopwatch.Stop(); millisecondsBetweenSimulations = 500; stopwatch.Reset(); // Start counting down the time to the next simulation stopwatch.Start(); simulationRunning = false; } Profiler.EndSample(); }
public override void OnStart(PartModule.StartState state) { if (HighLogic.LoadedSceneIsEditor) { ready = true; } if (state == PartModule.StartState.None) { return; //don't do anything when we start up in the loading screen } //OnLoad doesn't get called for parts created in editor, so do that manually so //that we can load global settings. //However, if you press ctrl-Z, a new PartModule object gets created, on which the //game DOES call OnLoad, and then OnStart. So before calling OnLoad from OnStart, //check whether we have loaded any computer modules. //if (state == StartState.Editor && computerModules.Count == 0) // Seems to happend when launching without comming from the VAB too. if (unorderedComputerModules.Count == 0) { OnLoad(null); } GameEvents.onShowUI.Add(OnShowGUI); GameEvents.onHideUI.Add(OnHideGUI); GameEvents.onVesselChange.Add(UnlockControl); lastSettingsSaveTime = Time.time; foreach (ComputerModule module in GetComputerModules <ComputerModule>()) { //especially important to wrap OnStart in a try-catch so that a failure in one module //doesn't prevent others from initializing. try { module.OnStart(state); } catch (Exception e) { Log.err(e, "module {0} threw an exception in OnStart: {1}", module.GetType().Name, e); } } if (vessel != null && this != vessel.GetMasterMechJeb()) { vessel.OnFlyByWire -= OnFlyByWire; //just a safety precaution to avoid duplicates vessel.OnFlyByWire += OnFlyByWire; controlledVessel = vessel; } }
public override void OnInactive() { foreach (ComputerModule module in GetComputerModules <ComputerModule>()) { try { module.OnInactive(); } catch (Exception e) { Log.err(e, "module {0} threw an exception in OnInactive: {1}", module.GetType().Name, e); } } }
//Returns the vector from the primary to the orbiting body at apoapsis //Better than using -Orbit.eccVec because that is zero for circular orbits public static Vector3d SwappedRelativePositionAtApoapsis(this Orbit o) { Vector3d vectorToAN = Quaternion.AngleAxis(-(float)o.LAN, Planetarium.up) * Planetarium.right; Vector3d vectorToPe = Quaternion.AngleAxis((float)o.argumentOfPeriapsis, o.SwappedOrbitNormal()) * vectorToAN; Vector3d ret = -o.ApR * vectorToPe; if (double.IsNaN(ret.x)) { Log.err("OrbitExtensions.SwappedRelativePositionAtApoapsis got a NaN result!"); Log.err("o.LAN = {0}", o.LAN); Log.err("o.inclination = {0}", o.inclination); Log.err("o.argumentOfPeriapsis = {0}", o.argumentOfPeriapsis); Log.err("o.SwappedOrbitNormal() = {0}", o.SwappedOrbitNormal()); } return(ret); }
public override void OnAwake() { Dispatcher.CreateDispatcher(); foreach (ComputerModule module in GetComputerModules <ComputerModule>()) { try { module.OnAwake(); } catch (Exception e) { Log.err(e, "module {0} threw an exception in OnAwake: {1}", module.GetType().Name, e); } } }
private void OnGUI() { if (!showGui || this != vessel.GetMasterMechJeb() || (!FlightGlobals.ready && HighLogic.LoadedSceneIsFlight) || !ready) { return; } Profiler.BeginSample("MechJebCore.OnGUI"); if (HighLogic.LoadedSceneIsEditor || (FlightGlobals.ready && (vessel == FlightGlobals.ActiveVessel) && (part.State != PartStates.DEAD))) { Matrix4x4 previousGuiMatrix = GUI.matrix; GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, new Vector3(GuiUtils.scale, GuiUtils.scale, 1)); GuiUtils.ComboBox.DrawGUI(); GuiUtils.LoadSkin((GuiUtils.SkinType)settings.skinId); GUI.skin = GuiUtils.skin; foreach (DisplayModule module in GetComputerModules <DisplayModule>()) { Profiler.BeginSample(module.profilerName); try { if (module.enabled) { module.DrawGUI(HighLogic.LoadedSceneIsEditor); } } catch (Exception e) { Log.err(e, "module {0} threw an exception in DrawGUI: {1}", module.GetType().Name, e); } Profiler.EndSample(); } PreventClickthrough(); GUI.matrix = previousGuiMatrix; for (int i = 0; i < postDrawQueue.Count; i++) { postDrawQueue[i](); } } Profiler.EndSample(); }
public ManeuverParameters MakeNode(Orbit o, double universalTime, MechJebModuleTargetController target) { errorMessage = ""; try { return(MakeNodeImpl(o, universalTime, target)); } catch (OperationException e) { errorMessage = e.Message; return(null); } catch (Exception e) { errorMessage = "An error occurred while creating the node."; Log.err(e, this); return(null); } }
/// <summary> /// Queues an action to be invoked on the main game thread. /// </summary> /// <param name="action">The action to be queued.</param> public static void InvokeAsync(Action action) { if (!_instanceExists) { Log.err("No Dispatcher exists in the scene. Actions will not be invoked!"); return; } if (isMainThread) { // Don't bother queuing work on the main thread; just execute it. action(); } else { lock (_lockObject) { _actions.Enqueue(action); } } }
static void KTTI(double xarg, double s0s, double a, int kmax, out double t, out double A, out double D, out double E) { double u1 = USS(xarg, a, kmax); double zs = 2 * u1; E = 1 - 0.5 * a * zs * zs; if (((1.0 + E) / 2.0) < 0) { Log.err("uh oh!"); } double w = Math.Sqrt((1.0 + E) / 2.0); D = w * zs; A = D * D; double B = 2 * (E + s0s * D); double Q = QCF(w); t = D * (B + A * Q); }
/// <summary> /// Creates feature button and puts it to <see cref="featureButtons"/> list. /// </summary> /// <param name="module">Feature related module.</param> /// <param name="nameId">Feature unique name.</param> /// <param name="tooltip">The tooltip for button.</param> /// <param name="onClick">The button click handler.</param> /// <param name="isActive">Super light weight function to check whether the feature is activated at the moment.</param> public void CreateFeatureButton(DisplayModule module, string nameId, string tooltip, ClickHandler onClick, Func <bool> isActive) { var texturePath = "MechJeb2/Icons/" + nameId; var texturePathActive = texturePath + "_active"; var button = new Button(); button.button = ToolbarManager.Instance.add("MechJeb2", nameId); if (GameDatabase.Instance.GetTexture(texturePath, false) == null) { button.texturePath = Qmark; Log.err("No icon for {0}", nameId); } else { button.texturePath = texturePath; } if (GameDatabase.Instance.GetTexture(texturePathActive, false) == null) { button.texturePathActive = texturePath; } else { button.texturePathActive = texturePathActive; } button.button.ToolTip = tooltip; button.button.OnClick += onClick; featureButtons.Add(() => { button.button.TexturePath = isActive() ? button.texturePathActive : button.texturePath; }, button); button.button.Visible = module.showInCurrentScene; button.button.TexturePath = button.texturePath; }
public virtual void OnLoad(ConfigNode local, ConfigNode type, ConfigNode global) { try { if (global != null) { ConfigNode.LoadObjectFromConfig(this, global, (int)Pass.Global); } if (type != null) { ConfigNode.LoadObjectFromConfig(this, type, (int)Pass.Type); } if (local != null) { ConfigNode.LoadObjectFromConfig(this, local, (int)Pass.Local); } } catch (Exception e) { Log.err(e, "caught exception in OnLoad for {0} : {1}", this.GetType().Name, e); } }
private void TryStartSimulation(bool doErrorSim) { try { if (!vessel.LandedOrSplashed) { // We should be running simulations periodically. If one is not running right now, // check if enough time has passed since the last one to start a new one: if (!simulationRunning && (stopwatch.ElapsedMilliseconds > millisecondsBetweenSimulations || !stopwatch.IsRunning)) { // variabledt generate too much instability of the landing site with atmo. // variabledt = !(mainBody.atmosphere && core.landing.enabled); // the altitude may induce some instability but allow for greater precision of the display in manual flight //variabledt = !mainBody.atmosphere || vessel.terrainAltitude < 1000 ; //if (!variabledt) // dt = 0.5; stopwatch.Stop(); stopwatch.Reset(); StartSimulation(false); } // We also periodically run simulations containing deliberate errors if we have been asked to do so by the landing autopilot. if (doErrorSim && this.runErrorSimulations && !errorSimulationRunning && (errorStopwatch.ElapsedMilliseconds >= millisecondsBetweenErrorSimulations || !errorStopwatch.IsRunning)) { errorStopwatch.Stop(); errorStopwatch.Reset(); StartSimulation(true); } } } catch (Exception ex) { Log.err(ex, this); } }
private void SetTranslatronSpeed(float speed, bool relative = false) { MechJebCore masterMechJeb = vessel.GetMasterMechJeb(); if (masterMechJeb != null) { MechJebModuleTranslatron moduleTranslatron = masterMechJeb.GetComputerModule <MechJebModuleTranslatron>(); if (moduleTranslatron != null && !moduleTranslatron.hidden) { thrust.trans_spd_act = (relative ? thrust.trans_spd_act : 0) + speed; } else { Log.err("couldn't find MechJebModuleTranslatron for translatron control via action group."); } } else { Log.err("couldn't find the master MechJeb module for the current vessel."); } }
/// <summary> /// Queues an action to be invoked on the main game thread and blocks the /// current thread until the action has been executed. /// </summary> /// <param name="action">The action to be queued.</param> public static void Invoke(Action action) { if (!_instanceExists) { Log.err("No Dispatcher exists in the scene. Actions will not be invoked!"); return; } bool hasRun = false; InvokeAsync(() => { action(); hasRun = true; }); // Lock until the action has run while (!hasRun) { Thread.Sleep(5); } }
override public void activateAction() { base.activateAction(); if (this.selectedPartIndex < this.kosModules.Count) { if (openTerminal) { this.kosModules[this.selectedPartIndex].GetType().InvokeMember("OpenWindow", System.Reflection.BindingFlags.InvokeMethod, null, this.kosModules[this.selectedPartIndex], null); } sharedObjects = this.kosModules[this.selectedPartIndex].GetType().GetField("shared", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).GetValue(this.kosModules[this.selectedPartIndex]); if (sharedObjects != null) { interpreter = sharedObjects.GetType().GetProperty("Interpreter").GetValue(sharedObjects, null); if (interpreter != null) { interpreter.GetType().InvokeMember("ProcessCommand", System.Reflection.BindingFlags.InvokeMethod | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance, null, interpreter, new object[] { command }); if (!this.waitFinish) { this.endAction(); } } else { Log.err("---- NO Interpreter OBJECT ----"); this.endAction(); } } else { Log.err("---- NO SHARED OBJECT ----"); this.endAction(); } } else { this.endAction(); } }
public virtual void OnSave(ConfigNode local, ConfigNode type, ConfigNode global) { try { if (global != null) { ConfigNode.CreateConfigFromObject(this, (int)Pass.Global, null).CopyTo(global); } if (type != null) { ConfigNode.CreateConfigFromObject(this, (int)Pass.Type, null).CopyTo(type); } if (local != null) { ConfigNode.CreateConfigFromObject(this, (int)Pass.Local, null).CopyTo(local); } dirty = false; } catch (Exception e) { Log.err(e, "caught exception in OnSave for {0} : {1}", this.GetType().Name, e); } }
public void OnTranslatronToggleHSAction(KSPActionParam param) { MechJebCore masterMechJeb = vessel.GetMasterMechJeb(); if (masterMechJeb != null) { MechJebModuleTranslatron moduleTranslatron = masterMechJeb.GetComputerModule <MechJebModuleTranslatron>(); if (moduleTranslatron != null && !moduleTranslatron.hidden) { thrust.trans_kill_h = !thrust.trans_kill_h; } else { //Log.err(Localizer.Format("#MechJeb_LogError_msg2"));//"MechJeb couldn't find MechJebModuleTranslatron for translatron control via action group." Log.err("couldn't find MechJebModuleTranslatron for translatron control via action group."); } } else { Log.err("couldn't find the master MechJeb module for the current vessel."); } }
public void LoadScriptModuleConfig() { string slotName = this.getSaveSlotName(false); if (File.Exists <MechJebCore>("mechjeb_settings_script_" + slotName + "_conf.cfg")) { ConfigNode node = null; try { node = ConfigNode.Load(IOUtils.GetFilePathFor(this.GetType(), "mechjeb_settings_script_" + slotName + "_conf.cfg")); } catch (Exception e) { Log.err(e, "MechJebModuleScript.LoadConfig caught an exception trying to load mechjeb_settings_script_{0}_conf.cfg: {1}", slotName, e); } if (node == null) { return; } ConfigNode.LoadObjectFromConfig(this, node); } this.updateScriptsNames(); }
public void LoadConfig(ConfigNode node) { this.clearAll(); //Load custom info scripts, which are stored in our ConfigNode: ConfigNode[] scriptNodes = node.GetNodes(); foreach (ConfigNode scriptNode in scriptNodes) { MechJebModuleScriptAction obj = null; if (scriptNode.name.CompareTo(MechJebModuleScriptActionSmartASS.NAME) == 0) { obj = new MechJebModuleScriptActionSmartASS(scriptModule, core, this); } else if (scriptNode.name.CompareTo(MechJebModuleScriptActionAscent.NAME) == 0) { obj = new MechJebModuleScriptActionAscent(scriptModule, core, this); } else if (scriptNode.name.CompareTo(MechJebModuleScriptActionTimer.NAME) == 0) { obj = new MechJebModuleScriptActionTimer(scriptModule, core, this); } else if (scriptNode.name.CompareTo(MechJebModuleScriptActionCrewTransfer.NAME) == 0) { obj = new MechJebModuleScriptActionCrewTransfer(scriptModule, core, this); } else if (scriptNode.name.CompareTo(MechJebModuleScriptActionDockingAutopilot.NAME) == 0) { obj = new MechJebModuleScriptActionDockingAutopilot(scriptModule, core, this); } else if (scriptNode.name.CompareTo(MechJebModuleScriptActionPause.NAME) == 0) { obj = new MechJebModuleScriptActionPause(scriptModule, core, this); } else if (scriptNode.name.CompareTo(MechJebModuleScriptActionStaging.NAME) == 0) { obj = new MechJebModuleScriptActionStaging(scriptModule, core, this); } else if (scriptNode.name.CompareTo(MechJebModuleScriptActionTargetDock.NAME) == 0) { obj = new MechJebModuleScriptActionTargetDock(scriptModule, core, this); } else if (scriptNode.name.CompareTo(MechJebModuleScriptActionTarget.NAME) == 0) { obj = new MechJebModuleScriptActionTarget(scriptModule, core, this); } else if (scriptNode.name.CompareTo(MechJebModuleScriptActionControlFrom.NAME) == 0) { obj = new MechJebModuleScriptActionControlFrom(scriptModule, core, this); } else if (scriptNode.name.CompareTo(MechJebModuleScriptActionUndock.NAME) == 0) { obj = new MechJebModuleScriptActionUndock(scriptModule, core, this); } else if (scriptNode.name.CompareTo(MechJebModuleScriptActionDockingShield.NAME) == 0) { obj = new MechJebModuleScriptActionDockingShield(scriptModule, core, this); } else if (scriptNode.name.CompareTo(MechJebModuleScriptActionQuicksave.NAME) == 0) { obj = new MechJebModuleScriptActionQuicksave(scriptModule, core, this); } else if (scriptNode.name.CompareTo(MechJebModuleScriptActionRCS.NAME) == 0) { obj = new MechJebModuleScriptActionRCS(scriptModule, core, this); } else if (scriptNode.name.CompareTo(MechJebModuleScriptActionActiveVessel.NAME) == 0) { obj = new MechJebModuleScriptActionActiveVessel(scriptModule, core, this); } else if (scriptNode.name.CompareTo(MechJebModuleScriptActionActivateEngine.NAME) == 0) { obj = new MechJebModuleScriptActionActivateEngine(scriptModule, core, this); } else if (scriptNode.name.CompareTo(MechJebModuleScriptActionSAS.NAME) == 0) { obj = new MechJebModuleScriptActionSAS(scriptModule, core, this); } else if (scriptNode.name.CompareTo(MechJebModuleScriptActionThrottle.NAME) == 0) { obj = new MechJebModuleScriptActionThrottle(scriptModule, core, this); } else if (scriptNode.name.CompareTo(MechJebModuleScriptActionExecuteNode.NAME) == 0) { obj = new MechJebModuleScriptActionExecuteNode(scriptModule, core, this); } else if (scriptNode.name.CompareTo(MechJebModuleScriptActionManoeuver.NAME) == 0) { obj = new MechJebModuleScriptActionManoeuver(scriptModule, core, this); } else if (scriptNode.name.CompareTo(MechJebModuleScriptActionLanding.NAME) == 0) { obj = new MechJebModuleScriptActionLanding(scriptModule, core, this); } else if (scriptNode.name.CompareTo(MechJebModuleScriptActionWarp.NAME) == 0) { obj = new MechJebModuleScriptActionWarp(scriptModule, core, this); } else if (scriptNode.name.CompareTo(MechJebModuleScriptActionTolerance.NAME) == 0) { obj = new MechJebModuleScriptActionTolerance(scriptModule, core, this); } else if (scriptNode.name.CompareTo(MechJebModuleScriptActionWaitFor.NAME) == 0) { obj = new MechJebModuleScriptActionWaitFor(scriptModule, core, this); } else if (scriptNode.name.CompareTo(MechJebModuleScriptActionFor.NAME) == 0) { obj = new MechJebModuleScriptActionFor(scriptModule, core, this); } else if (scriptNode.name.CompareTo(MechJebModuleScriptActionIf.NAME) == 0) { obj = new MechJebModuleScriptActionIf(scriptModule, core, this); } else if (scriptNode.name.CompareTo(MechJebModuleScriptActionWhile.NAME) == 0) { obj = new MechJebModuleScriptActionWhile(scriptModule, core, this); } else if (scriptNode.name.CompareTo(MechJebModuleScriptActionParallel.NAME) == 0) { obj = new MechJebModuleScriptActionParallel(scriptModule, core, this); } else if (scriptNode.name.CompareTo(MechJebModuleScriptActionActionGroup.NAME) == 0) { obj = new MechJebModuleScriptActionActionGroup(scriptModule, core, this); } else if (scriptNode.name.CompareTo(MechJebModuleScriptActionLoadScript.NAME) == 0) { obj = new MechJebModuleScriptActionLoadScript(scriptModule, core, this); } else if (scriptNode.name.CompareTo(MechJebModuleScriptActionRendezvous.NAME) == 0) { obj = new MechJebModuleScriptActionRendezvous(scriptModule, core, this); } else if (scriptNode.name.CompareTo(MechJebModuleScriptActionRendezvousAP.NAME) == 0) { obj = new MechJebModuleScriptActionRendezvousAP(scriptModule, core, this); } else if (scriptNode.name.CompareTo(MechJebModuleScriptActionIRSequencer.NAME) == 0) { obj = new MechJebModuleScriptActionIRSequencer(scriptModule, core, this); } else if (scriptNode.name.CompareTo(MechJebModuleScriptActionKos.NAME) == 0) { obj = new MechJebModuleScriptActionKos(scriptModule, core, this); } else { Log.err("MechJebModuleScript.LoadConfig : Unknown node {0}", scriptNode.name); } if (obj != null) { ConfigNode.LoadObjectFromConfig(obj, scriptNode); obj.postLoad(scriptNode); this.addAction(obj); } } }
void InitDocking() { lastTarget = core.target.Target; try { vesselBoundingBox = vessel.GetBoundingBox(); targetBoundingBox = lastTarget.GetVessel().GetBoundingBox(); if (!overrideTargetSize) { targetSize = targetBoundingBox.size.magnitude; } else { targetSize = (float)overridenTargetSize.val; } if (!overrideSafeDistance) { safeDistance = vesselBoundingBox.size.magnitude + targetSize + 0.5f; } else { safeDistance = (float)overridenSafeDistance.val; } if (core.target.Target is ModuleDockingNode) { acquireRange = ((ModuleDockingNode)core.target.Target).acquireRange * 0.5; } else { acquireRange = 0.25; } } catch (Exception e) { Log.err(e, this); } if (zSep < 0) //we're behind the target { // If we're more than half our own bounding box size behind the target port then use wrong side behavior // Still needs improvement. The reason for these changes is that to prevent wrong side behavior when our // port slipped behind the target by a fractional amount. The result is that rather than avoiding the // target ship we end up trying to pass right through it. // What's really needed here is code that compares bounding box positions to determine if we just try to back up or change sides completely. if (Math.Abs(zSep) > vesselBoundingBox.size.magnitude * 0.5f) { dockingStep = DockingStep.WRONG_SIDE_BACKING_UP; } else { dockingStep = DockingStep.BACKING_UP; // Just back straight up. } } else if (lateralSep.magnitude > dockingcorridorRadius) // in front but far from docking axis { if (zSep < targetSize) { dockingStep = DockingStep.BACKING_UP; } else { dockingStep = DockingStep.MOVING_TO_START; } } else { dockingStep = DockingStep.DOCKING; } }
public override void OnLoad(ConfigNode sfsNode) { if (GuiUtils.skin == null) { //GuiUtils.skin = new GUISkin(); new GameObject("zombieGUILoader", typeof(ZombieGUILoader)); } try { bool generateDefaultWindows = false; base.OnLoad(sfsNode); //is this necessary? // With the Unity 4.6 upgrade of KSP 1.0 we inherited a serialization problem // with object with high depth like config nodes // so the partmodule config node passed was not ok. // So we use a static dir to save the part config node. if (!savedConfig.ContainsKey(part.name)) { if (HighLogic.LoadedScene == GameScenes.LOADING) { savedConfig.Add(part.name, sfsNode); } } else { partSettings = savedConfig[part.name]; } LoadComputerModules(); ConfigNode global = new ConfigNode("MechJebGlobalSettings"); if (File.Exists <MechJebCore>("mechjeb_settings_global.cfg")) { try { global = ConfigNode.Load(IOUtils.GetFilePathFor(this.GetType(), "mechjeb_settings_global.cfg")); } catch (Exception e) { Log.err(e, "MechJebCore.OnLoad caught an exception trying to load mechjeb_settings_global.cfg: {0}", e); generateDefaultWindows = true; } } else { generateDefaultWindows = true; } ConfigNode type = new ConfigNode("MechJebTypeSettings"); string vesselName = vessel != null?string.Join("_", vessel.vesselName.Split(System.IO.Path.GetInvalidFileNameChars())) : ""; // Strip illegal char from the filename if ((vessel != null) && File.Exists <MechJebCore>("mechjeb_settings_type_" + vesselName + ".cfg")) { try { type = ConfigNode.Load(IOUtils.GetFilePathFor(this.GetType(), "mechjeb_settings_type_" + vesselName + ".cfg")); } catch (Exception e) { Log.err(e, "MechJebCore.OnLoad caught an exception trying to load mechjeb_settings_type_{0}.cfg: {1}", vesselName, e); } } ConfigNode local = new ConfigNode("MechJebLocalSettings"); if (sfsNode != null && sfsNode.HasNode("MechJebLocalSettings")) { local = sfsNode.GetNode("MechJebLocalSettings"); } else if (partSettings != null && partSettings.HasNode("MechJebLocalSettings")) { local = partSettings.GetNode("MechJebLocalSettings"); } else if (sfsNode == null) // capture current Local settings { foreach (ComputerModule module in GetComputerModules <ComputerModule>()) { try { module.OnSave(local.AddNode(module.GetType().Name), null, null); } catch (Exception e) { Log.err(e, "module {0} threw an exception in OnLoad: {1}", module.GetType().Name, e); } } } Log.dbg("OnLoad: loading from\n\tLocal: {0}\n\tType: {1}\n\tGlobal: {0}", local, type, global); // Remove any currently loaded custom windows MechJebModuleCustomInfoWindow win; while ((win = GetComputerModule <MechJebModuleCustomInfoWindow>()) != null) { RemoveComputerModule(win); } foreach (ComputerModule module in GetComputerModules <ComputerModule>()) { try { string name = module.GetType().Name; ConfigNode moduleLocal = local.HasNode(name) ? local.GetNode(name) : null; ConfigNode moduleType = type.HasNode(name) ? type.GetNode(name) : null; ConfigNode moduleGlobal = global.HasNode(name) ? global.GetNode(name) : null; module.OnLoad(moduleLocal, moduleType, moduleGlobal); } catch (Exception e) { Log.err("module threw an exception in OnLoad: {0} {1}", module.GetType().Name, e); } } LoadDelayedModules(); if (generateDefaultWindows) { GetComputerModule <MechJebModuleCustomWindowEditor>().AddDefaultWindows(); } } catch (ReflectionTypeLoadException ex) { Log.err("caught a ReflectionTypeLoadException. Those DLL meeds maintenance and can cause serious collateral effects on the system if not fixed:"); var brokenAssembly = ex.Types.Where(x => x != null).Select(x => x.Assembly).Distinct(); foreach (Assembly assembly in brokenAssembly) { Log.err("{0} {1} {2}", assembly.GetName().Name, assembly.GetName().Version, assembly.Location.Remove(0, Path.GetFullPath(KSPUtil.ApplicationRootPath).Length) ); } } catch (Exception e) { Log.err(e, "caught exception in core OnLoad: {0}", e); } }