/// <summary> /// Reads the current called method name and takes this method /// over to the assembly. The return value on a not successfull /// call is null. /// </summary> /// <param name="parameters">Object parameter list, given to the assembly method</param> /// <returns>Null on a non successfull call</returns> protected object invoke(object[] parameters) { if (this.assemblyLoaded) { // look 1 call behind to get the name of the method who is called StackTrace st = new StackTrace(); StackFrame sf = st.GetFrame(1); try { // invoke the method var result = assemblyType.InvokeMember(sf.GetMethod().Name, this.bFlags, null, this.instance, parameters); RTLog.Verbose("AddOn.InvokeResult for {0} with instance: {1} is '{2}'", RTLogLevel.Assembly, sf.GetMethod().Name, this.instance, result); return(result); } catch (Exception ex) { RTLog.Verbose("AddOn.InvokeException for {0} with instance: {1} is '{2}'", RTLogLevel.Assembly, sf.GetMethod().Name, this.instance, ex); } } // default value is null return(null); }
public static void AddSanctionedPilot(Guid id, Action <FlightCtrlState> autopilot) { if (RTCore.Instance == null) { return; } var satellite = RTCore.Instance.Satellites.Where(sat => sat.Guid.Equals(id)).FirstOrDefault(); if (satellite == null || satellite.SignalProcessor == null) { return; } foreach (var spu in satellite.SignalProcessors) { if (spu.FlightComputer == null || spu.FlightComputer.SanctionedPilots == null) { continue; } if (spu.FlightComputer.SanctionedPilots.Contains(autopilot)) { continue; } RTLog.Verbose("Flight: {0} Adding Sanctioned Pilot", RTLogLevel.API, id); spu.FlightComputer.SanctionedPilots.Add(autopilot); } }
public static bool ReceiveDataExec(ConfigNode data) { RTLog.Verbose("Received Data via Api.ReceiveDataExec", RTLogLevel.API); RTLog.Notify("Data: {0}", data); return(bool.Parse(data.GetValue("AbortCommand"))); }
public static bool HasConnectionToKSC(Guid id) { var satellite = RTCore.Instance.Satellites[id]; var connectedToKerbin = RTCore.Instance.Network[satellite].Any(r => RTCore.Instance.Network.GroundStations.ContainsKey(r.Goal.Guid)); RTLog.Verbose("Flight: {0} Has Connection to Kerbin: {1}", RTLogLevel.API, id, connectedToKerbin); return(connectedToKerbin); }
public static bool HasAnyConnection(Guid id) { var satellite = RTCore.Instance.Satellites[id]; var hasConnection = RTCore.Instance.Network[satellite].Any(); RTLog.Verbose("Flight: {0} Has Connection: {1}", RTLogLevel.API, id, hasConnection); return(hasConnection); }
public void reloadUpgradeableAntennas(int techlvl = 0) { if (this.UpgradeableCosAngle != String.Empty && this.UpgradeableDish != String.Empty && this.UpgradeableOmni != String.Empty) { return; } int missionControlTechLevel = techlvl; if (missionControlTechLevel == 0) { missionControlTechLevel = (int)((2 * ScenarioUpgradeableFacilities.GetFacilityLevel(SpaceCenterFacility.TrackingStation)) + 1); } // when the option is disabled, use always the thrid tech lvl if (!RTSettings.Instance.UpgradeableMissionControlAntennas) { missionControlTechLevel = 3; } RTLog.Verbose("Reload upgradeable Antennas, TechLvl: {0}", RTLogLevel.LVL4, missionControlTechLevel); if (this.UpgradeableOmni != String.Empty) { int missionControlTechLevelForOmni = missionControlTechLevel; string[] omniRanges = this.UpgradeableOmni.Split(';'); if (missionControlTechLevelForOmni > omniRanges.Count()) { missionControlTechLevelForOmni = omniRanges.Count(); } float.TryParse(omniRanges[missionControlTechLevelForOmni - 1], out this.Omni); } if (this.UpgradeableDish != String.Empty) { int missionControlTechLevelForDish = missionControlTechLevel; string[] dishRanges = this.UpgradeableOmni.Split(';'); if (missionControlTechLevelForDish > dishRanges.Count()) { missionControlTechLevelForDish = dishRanges.Count(); } float.TryParse(dishRanges[missionControlTechLevelForDish - 1], out this.Dish); } if (this.UpgradeableCosAngle != String.Empty) { int missionControlTechLevelForCAngle = missionControlTechLevel; string[] cAngleRanges = this.UpgradeableOmni.Split(';'); if (missionControlTechLevelForCAngle > cAngleRanges.Count()) { missionControlTechLevelForCAngle = cAngleRanges.Count(); } double.TryParse(cAngleRanges[missionControlTechLevelForCAngle - 1], out this.CosAngle); } }
public void InitMode(RemoteTech.FlightComputer.Commands.DriveCommand dc) { if (mVessel == null) { RTLog.Verbose("Vessel is null!"); return; } ForwardAxis = Vector3.zero; mRoverAlt = (float)mVessel.altitude; mRoverLat = (float)mVessel.latitude; mRoverLon = (float)mVessel.longitude; Delta = 0; DeltaT = 0; /* Explanation on targetRotation * Quaternion.Euler(x,y,z) - Returns a rotation that rotates z degrees around the z axis, * x degrees around the x axis, and y degrees around the y axis * in that order. * * Unity Q.Euler(0,0,0) isn't matched to KSP's rotation "(0,0,0)" (-90, varying UP-axis, 90) so need to * match the target rotation to the KSP's rotation. * * Rover-specific rotation is Forward (y) to HDG 0, Up (x) to North and * Right (z) to East. */ const float KSPRotXAxis = -90f, KSPRotZAxis = 90f; double AngleFromUpAxis = Mathf.Rad2Deg * Math.Atan(-mVessel.upAxis.z / -mVessel.upAxis.x); float KSPRotYAxis = (float)-AngleFromUpAxis; switch (dc.mode) { case RemoteTech.FlightComputer.Commands.DriveCommand.DriveMode.Turn: mRoverRot = mVessel.ReferenceTransform.rotation; break; case RemoteTech.FlightComputer.Commands.DriveCommand.DriveMode.Distance: targetRotation = Quaternion.Euler(KSPRotXAxis, KSPRotYAxis, KSPRotZAxis); break; case RemoteTech.FlightComputer.Commands.DriveCommand.DriveMode.DistanceHeading: targetRotation = Quaternion.Euler(KSPRotXAxis - dc.target2, KSPRotYAxis, KSPRotZAxis); break; case RemoteTech.FlightComputer.Commands.DriveCommand.DriveMode.Coord: mTargetLat = dc.target; mTargetLon = dc.target2; targetRotation = Quaternion.Euler(KSPRotXAxis - TargetHDG, KSPRotYAxis, KSPRotZAxis); break; } pidController.setPIDParameters(Kp, Ki, Kd); throttlePID.ResetI(); steerPID.ResetI(); mVessel.ActionGroups.SetGroup(KSPActionGroup.Brakes, false); }
public static void EnableInSPC(bool state) // its advised that modders who need RTCore active in the SPC should set this from the MainMenu Scene { enabledInSPC = state; // setting to true will only take effect after a scene change RTLog.Verbose("Flag for RemoteTech running in Space Center scene is set: {0}", RTLogLevel.API, enabledInSPC); if (!enabledInSPC && RTCore.Instance != null && HighLogic.LoadedScene == GameScenes.SPACECENTER) { RTLog.Verbose("RemoteTech is terminated in Space Center scene", RTLogLevel.API); RTCore.Instance.OnDestroy(); } }
/// <summary> /// Load and creates a command after saving a command. Returns null if no object /// has been loaded. /// </summary> /// <param name="n">Node with the command infos</param> /// <param name="fc">Current flightcomputer</param> public static ICommand LoadCommand(ConfigNode n, FlightComputer fc) { ICommand command = null; // switch the different commands switch (n.name) { case "AttitudeCommand": { command = new AttitudeCommand(); break; } case "ActionGroupCommand": { command = new ActionGroupCommand(); break; } case "BurnCommand": { command = new BurnCommand(); break; } case "ManeuverCommand": { command = new ManeuverCommand(); break; } case "CancelCommand": { command = new CancelCommand(); break; } case "TargetCommand": { command = new TargetCommand(); break; } case "EventCommand": { command = new EventCommand(); break; } case "DriveCommand": { command = new DriveCommand(); break; } case "ExternalAPICommand": { command = new ExternalAPICommand(); break; } case "PartActionCommand": { command = new PartActionCommand(); break; } case "StockAutopilotCommand": { command = new StockAutopilotCommand(); break; } case "HibernationCommand": { command = new HibernationCommand(); break; } case "AxisGroupCommand": { command = new AxisGroupCommand(); break; } case "PIDCommand": { command = new PIDCommand(); break; } case "FlightControlCommand": { command = new FlightControlCommand(); break; } } if (command != null) { ConfigNode.LoadObjectFromConfig(command, n); // additional loadings var result = command.Load(n, fc); RTLog.Verbose("Loading command {0}({1})={2}", RTLogLevel.LVL1, n.name, command.CmdGuid, result); // delete command if we can't load the command correctlys if (result == false) { command = null; } } return(command); }
public KerbalAlarmClockAddon() : base("KerbalAlarmClock", "KerbalAlarmClock.KerbalAlarmClock") { if (!AssemblyLoaded) { return; } KACWrapper.InitKACWrapper(); var message = KACWrapper.APIReady ? "KerbalAlarmClockAddon.loadInstance: Successfully loaded KAC!" : "KerbalAlarmClockAddon.loadInstance: Couldn't load Instance."; RTLog.Verbose(message, RTLogLevel.Assembly); }
public static bool HasLocalControl(Guid id) { var vessel = FlightGlobals.Vessels.FirstOrDefault(v => v.id == id); if (vessel == null) { return(false); } RTLog.Verbose("Flight: {0} HasLocalControl: {1}", RTLogLevel.API, id, vessel.HasLocalControl()); return(vessel.HasLocalControl()); }
public static double GetShortestSignalDelay(Guid id) { var satellite = RTCore.Instance.Satellites[id]; if (!RTCore.Instance.Network[satellite].Any()) { return(Double.PositiveInfinity); } var shortestDelay = RTCore.Instance.Network[satellite].Min().Delay; RTLog.Verbose("Flight: Shortest signal delay from {0} to {1}", RTLogLevel.API, id, shortestDelay); return(shortestDelay); }
private void loadInstance() { /// load KaC instance try { this.instance = this.assemblyType.GetField("APIInstance", BindingFlags.Public | BindingFlags.Static).GetValue(null); this.KaCApiReady = (bool)this.assemblyType.GetField("APIReady", BindingFlags.Public | BindingFlags.Static).GetValue(null); } catch (Exception ex) { RTLog.Verbose("AddOn.loadInstance exception: {0}", RTLogLevel.Assembly, ex); } }
public static double GetSignalDelayToKSC(Guid id) { var satellite = RTCore.Instance.Satellites[id]; if (!RTCore.Instance.Network[satellite].Any(r => RTCore.Instance.Network.GroundStations.ContainsKey(r.Goal.Guid))) { return(Double.PositiveInfinity); } var signalDelaytoKerbin = RTCore.Instance.Network[satellite].Where(r => RTCore.Instance.Network.GroundStations.ContainsKey(r.Goal.Guid)).Min().Delay; RTLog.Verbose("Connection from {0} to Kerbin Delay: {1}", RTLogLevel.API, id, signalDelaytoKerbin); return(signalDelaytoKerbin); }
public static bool HasLocalControl(Guid id) { var vessel = RTUtil.GetVesselById(id); if (vessel == null) { return(false); } RTLog.Verbose("Flight: {0} HasLocalControl: {1}", RTLogLevel.API, id, vessel.HasLocalControl()); return(vessel.HasLocalControl()); }
public static bool HasFlightComputer(Guid id) { var satellite = RTCore.Instance.Satellites[id]; if (satellite == null) { return(false); } var hasFlightComputer = satellite.FlightComputer != null; RTLog.Verbose("Flight: {0} HasFlightComputer: {1}", RTLogLevel.API, id, hasFlightComputer); return(hasFlightComputer); }
protected AddOn(string assemblyName, string assemblyType) { RTLog.Verbose("Connecting with {0} ...", RTLogLevel.Assembly, assemblyName); var loadedAssembly = AssemblyLoader.loadedAssemblies.FirstOrDefault(a => a.assembly.GetName().Name.Equals(assemblyName)); if (loadedAssembly != null) { RTLog.Notify("Successfull connected to Assembly {0}", RTLogLevel.Assembly, assemblyName); this.assemblyType = loadedAssembly.assembly.GetTypes().FirstOrDefault(t => t.FullName.Equals(assemblyType)); this.loaded = true; } }
/// <summary> /// Enforce or remove the power down on target vessel /// </summary> /// <returns>Indicator on whether this request is executed successfully</returns> public static bool SetPowerDownGuid(Guid id, bool flag, string reason = "") { if (RTCore.Instance == null) { return(false); } var satellite = RTCore.Instance.Satellites.Where(sat => sat.Guid.Equals(id)).FirstOrDefault(); if (satellite == null) { return(false); } satellite.PowerShutdownFlag = flag; RTLog.Verbose("Flight: {0} has power down flag updated due to reason '{2}': {1}", RTLogLevel.API, id, satellite.PowerShutdownFlag, reason); return(true); }
/// <summary> /// Enforce or remove the radio blackout on target vessel (e.g. coronal mass ejection) /// </summary> /// <returns>Indicator on whether this request is executed successfully</returns> public static bool SetRadioBlackoutGuid(Guid id, bool flag, string reason = "") { if (RTCore.Instance == null) { return(false); } var satellite = RTCore.Instance.Satellites.Where(sat => sat.Guid.Equals(id)).FirstOrDefault(); if (satellite == null) { return(false); } satellite.IsInRadioBlackout = flag; RTLog.Verbose("Flight: {0} has radio blackout flag updated due to reason '{2}': {1}", RTLogLevel.API, id, satellite.IsInRadioBlackout, reason); return(true); }
//exposed method called by other mods, passing a ConfigNode to RemoteTech public static bool QueueCommandToFlightComputer(ConfigNode externalData) { if (RTCore.Instance == null) { return(false); } //check we were actually passed a config node if (externalData == null) { return(false); } // check our min values if (!externalData.HasValue("GUIDString") && !externalData.HasValue("Executor") && !externalData.HasValue("ReflectionType")) { return(false); } try { Guid externalVesselId = new Guid(externalData.GetValue("GUIDString")); // you can only push a new external command if the vessel guid is the current active vessel if (FlightGlobals.ActiveVessel.id != externalVesselId) { RTLog.Verbose("Passed Guid is not the active Vessels guid", RTLogLevel.API); return(false); } // maybe we should look if this vessel hasLocal control or not. If so, we can execute the command // immediately // get the flight computer FlightComputer.FlightComputer computer = RTCore.Instance.Satellites[externalVesselId].FlightComputer; var extCmd = FlightComputer.Commands.ExternalAPICommand.FromExternal(externalData); computer.Enqueue(extCmd); return(true); } catch (Exception ex) { RTLog.Verbose(ex.Message, RTLogLevel.API); } return(false); }
/// <summary> Gets the name of a satellite.</summary> /// <param name="id">The satellite id.</param> /// <returns>name of the satellite with matching id if found, otherwise null</returns> public static string GetName(Guid id) { if (RTCore.Instance == null) { return(null); } var satellite = RTCore.Instance.Satellites[id]; if (satellite == null) { return(null); } string satellitename = satellite.Name; RTLog.Verbose("Flight: {0} is: {1}", RTLogLevel.API, id, satellitename); return(satellitename); }
/// <summary> /// Check if target vessel is currently in power down state /// </summary> /// <returns>Indicator on whether target vessel is in power down state</returns> public static bool GetPowerDownGuid(Guid id) { if (RTCore.Instance == null) { return(false); } var satellite = RTCore.Instance.Satellites.Where(sat => sat.Guid.Equals(id)).FirstOrDefault(); if (satellite == null) { return(false); } var flag = satellite.PowerShutdownFlag; RTLog.Verbose("Flight: {0} is in power down: {1}", RTLogLevel.API, id, flag); return(flag); }
/// <summary> /// Check if target vessel is currently in radio blackout /// </summary> /// <returns>Indicator on whether target vessel is in radio blackout</returns> public static bool GetRadioBlackoutGuid(Guid id) { if (RTCore.Instance == null) { return(false); } var satellite = RTCore.Instance.Satellites.Where(sat => sat.Guid.Equals(id)).FirstOrDefault(); if (satellite == null) { return(false); } var blackoutFlag = satellite.IsInRadioBlackout; RTLog.Verbose("Flight: {0} is in radio blackout: {1}", RTLogLevel.API, id, blackoutFlag); return(blackoutFlag); }
/// <summary> Gets the name of a satellite.</summary> /// <param name="id">The satellite id.</param> /// <returns>name of the satellite with matching id if found, otherwise null</returns> public static string GetName(Guid id) { if (RTCore.Instance == null) { return(null); } var satellite = RTCore.Instance.Network.Where(sat => sat.Guid.Equals(id)).FirstOrDefault(); if (satellite == null) { return(null); } string satellitename = satellite.Name; RTLog.Verbose("Flight: {0} is: {1}", RTLogLevel.API, id, satellitename); return(satellitename); }
public static void RemoveSanctionedPilot(Guid id, Action <FlightCtrlState> autopilot) { var satellite = RTCore.Instance.Satellites[id]; if (satellite == null) { return; } foreach (var spu in satellite.SignalProcessors) { if (spu.FlightComputer == null) { continue; } RTLog.Verbose("Flight: {0} Removing Sanctioned Pilot", RTLogLevel.API, id); spu.FlightComputer.SanctionedPilots.Remove(autopilot); } }
/// <summary> Determines if a satellite directly targets a ground station.</summary> /// <param name="id">The satellite id.</param> /// <returns>true if the satellite has an antenna with a ground station as its first link, false otherwise.</returns> public static bool HasDirectGroundStation(Guid id) { if (RTCore.Instance == null) { return(false); } var satellite = RTCore.Instance.Satellites.Where(sat => sat.Guid.Equals(id)).FirstOrDefault(); if (satellite == null) { return(false); } var targetsGroundStation = RTCore.Instance.Network[satellite].Any(r => RTCore.Instance.Network.GroundStations.ContainsKey(r.Links.FirstOrDefault().Target.Guid)); RTLog.Verbose("Flight: {0} Directly targets a ground station: {1}", RTLogLevel.API, id, targetsGroundStation); return(targetsGroundStation); }
public static bool HasConnectionToKSC(Guid id) { if (RTCore.Instance == null) { return(false); } var satellite = RTCore.Instance.Satellites.Where(sat => sat.Guid.Equals(id)).FirstOrDefault(); if (satellite == null) { return(false); } var connectedToKerbin = RTCore.Instance.Network[satellite].Any(r => RTCore.Instance.Network.GroundStations.ContainsKey(r.Goal.Guid)); RTLog.Verbose("Flight: {0} Has Connection to Kerbin: {1}", RTLogLevel.API, id, connectedToKerbin); return(connectedToKerbin); }
public static bool HasAnyConnection(Guid id) { if (RTCore.Instance == null) { return(false); } var satellite = RTCore.Instance.Satellites.Where(sat => sat.Guid.Equals(id)).FirstOrDefault(); if (satellite == null) { return(false); } var hasConnection = RTCore.Instance.Network[satellite].Any(); RTLog.Verbose("Flight: {0} Has Connection: {1}", RTLogLevel.API, id, hasConnection); return(hasConnection); }
/// <summary> /// Check if target vessel is currently in radio blackout /// </summary> /// <returns>Indicator on whether target vessel is in radio blackout</returns> public static bool GetRadioBlackoutGuid(Guid id) { if (RTCore.Instance == null) { return(false); } var satellite = RTCore.Instance.Satellites[id]; if (satellite == null) { return(false); } var blackoutFlag = satellite.IsInRadioBlackout; RTLog.Verbose("Flight: {0} is in radio blackout: {1}", RTLogLevel.API, id, blackoutFlag); return(blackoutFlag); }
/// <summary> /// Check if target vessel is currently in power down state /// </summary> /// <returns>Indicator on whether target vessel is in power down state</returns> public static bool GetPowerDownGuid(Guid id) { if (RTCore.Instance == null) { return(false); } var satellite = RTCore.Instance.Satellites[id]; if (satellite == null) { return(false); } var flag = satellite.PowerShutdownFlag; RTLog.Verbose("Flight: {0} is in power down: {1}", RTLogLevel.API, id, flag); return(flag); }