public ProtoAntenna(Vessel v, ProtoPartSnapshot p, ProtoPartModuleSnapshot ppms) { ConfigNode n = new ConfigNode(); ppms.Save(n); Name = p.partInfo.title; Consumption = 0; Guid = v.id; mProtoPart = p; mProtoModule = ppms; try { mDishTarget = new Guid(n.GetValue("RTAntennaTarget")); } catch (ArgumentException) { mDishTarget = Guid.Empty; } double temp_double; float temp_float; bool temp_bool; Dish = Single.TryParse(n.GetValue("RTDishRange"), out temp_float) ? temp_float : 0.0f; Radians = Double.TryParse(n.GetValue("RTDishRadians"), out temp_double) ? temp_double : 0.0; Omni = Single.TryParse(n.GetValue("RTOmniRange"), out temp_float) ? temp_float : 0.0f; Powered = Boolean.TryParse(n.GetValue("IsRTPowered"), out temp_bool) ? temp_bool : false; Activated = Boolean.TryParse(n.GetValue("IsRTActive"), out temp_bool) ? temp_bool : false; RTLog.Notify(ToString()); }
/// <summary> /// Unregisters the specified signal processor. /// </summary> /// <param name="key">The key the signal processor was registered under.</param> /// <param name="spu">The signal processor.</param> public void Unregister(Guid key, ISignalProcessor spu) { RTLog.Notify("SatelliteManager: Unregister({0})", spu); // Return if nothing to unregister. if (!mLoadedSpuCache.ContainsKey(key)) { return; } // Find instance of the signal processor. int instance_id = mLoadedSpuCache[key].FindIndex(x => x == spu); if (instance_id != -1) { // Remove satellite if no signal processors remain. if (mLoadedSpuCache[key].Count == 1) { if (mSatelliteCache.ContainsKey(key)) { VesselSatellite sat = mSatelliteCache[key]; OnUnregister(sat); mSatelliteCache.Remove(key); } mLoadedSpuCache[key].RemoveAt(instance_id); mLoadedSpuCache.Remove(key); } else { mLoadedSpuCache[key].RemoveAt(instance_id); } } }
public ProtoSignalProcessor(ProtoPartModuleSnapshot ppms, Vessel v) { mVessel = v; Powered = ppms.GetBool("IsRTPowered"); IsCommandStation = Powered && v.HasCommandStation() && v.GetVesselCrew().Count >= 6; RTLog.Notify("ProtoSignalProcessor(Powered: {0}, HasCommandStation: {1}, Crew: {2})", Powered, v.HasCommandStation(), v.GetVesselCrew().Count); }
/// <summary> /// Registers a signal processor for the vessel. /// </summary> /// <param name="vessel">The vessel.</param> /// <param name="spu">The signal processor.</param> /// <returns>Guid key under which the signal processor was registered.</returns> public Guid Register(Vessel vessel, ISignalProcessor spu) { Guid key = vessel.id; RTLog.Notify("SatelliteManager: Register({0})", spu); if (!mLoadedSpuCache.ContainsKey(key)) { UnregisterProto(vessel.id); mLoadedSpuCache[key] = new List <ISignalProcessor>(); } // Add if non duplicate ISignalProcessor instance = mLoadedSpuCache[key].Find(x => x == spu); if (instance == null) { mLoadedSpuCache[key].Add(spu); // Create a new satellite if it's the only loaded signal processor. if (mLoadedSpuCache[key].Count == 1) { mSatelliteCache[key] = new VesselSatellite(mLoadedSpuCache[key]); OnRegister(mSatelliteCache[key]); } } return(key); }
/// <summary> /// Registers a signal processor for the vessel. /// </summary> /// <param name="vessel">The vessel.</param> /// <param name="spu">The signal processor.</param> /// <returns>Guid key under which the signal processor was registered.</returns> public Guid Register(Vessel vessel, ISignalProcessor spu) { RTLog.Notify("SatelliteManager: Register({0})", spu); var key = vessel.id; if (!_loadedSpuCache.ContainsKey(key)) { UnregisterProto(vessel.id); _loadedSpuCache[key] = new List <ISignalProcessor>(); } // Add if non duplicate var signalProcessor = _loadedSpuCache[key].Find(x => x == spu); if (signalProcessor != null) { return(key); } _loadedSpuCache[key].Add(spu); // Create a new satellite if it's the only loaded signal processor. if (_loadedSpuCache[key].Count != 1) { return(key); } _satelliteCache[key] = new VesselSatellite(_loadedSpuCache[key]); OnRegister(_satelliteCache[key]); return(key); }
public void Start() { if (Instance != null) { Destroy(this); return; } Instance = this; Satellites = new SatelliteManager(); Antennas = new AntennaManager(); Network = new NetworkManager(); Renderer = NetworkRenderer.CreateAndAttach(); FilterOverlay = new FilterOverlay(); FocusOverlay = new FocusOverlay(); TimeQuadrantPatcher = new TimeQuadrantPatcher(); TimeQuadrantPatcher.Patch(); FlightUIPatcher.Patch(); RTLog.Notify("RTCore loaded successfully."); foreach (var vessel in FlightGlobals.Vessels) { Satellites.RegisterProto(vessel); Antennas.RegisterProtos(vessel); } }
public static void LoadImage(out Texture2D texture, String fileName) { try { Assembly myAssembly = Assembly.GetExecutingAssembly(); Stream resStream = myAssembly.GetManifestResourceStream("RemoteTech.Resources." + fileName); if (resStream.Length <= 0) { RTLog.Notify("LoadImageFromRessource({0}) failed", fileName); throw new Exception("No ImageRessource found"); } RTLog.Notify("LoadImageFromRessource({0}) success", fileName); // create a byte array from the stream ressource byte[] imageStream = new byte[resStream.Length]; resStream.Read(imageStream, 0, (int)resStream.Length); // apply the image stream to a new Texture2D object texture = new Texture2D(4, 4, TextureFormat.ARGB32, false); texture.LoadImage(imageStream); imageStream = null; resStream.Close(); } catch (Exception) { texture = new Texture2D(32, 32); texture.SetPixels32(Enumerable.Repeat((Color32)Color.magenta, 32 * 32).ToArray()); texture.Apply(); } }
public void Start() { if (Instance != null) { Destroy(this); return; } Instance = this; ctrlLockAddon = new AddOns.ControlLockAddon(); Satellites = new SatelliteManager(); Antennas = new AntennaManager(); Network = new NetworkManager(); Renderer = NetworkRenderer.CreateAndAttach(); FilterOverlay = new FilterOverlay(); FocusOverlay = new FocusOverlay(); TimeWarpDecorator = new TimeWarpDecorator(); FlightUIPatcher.Patch(); RTLog.Notify("RTCore {0} loaded successfully.", RTUtil.Version); foreach (var vessel in FlightGlobals.Vessels) { Satellites.RegisterProto(vessel); Antennas.RegisterProtos(vessel); } }
public void RegisterProtos(Vessel v) { Guid key = v.id; RTLog.Notify("AntennaManager: RegisterProtos({0}, {1})", v.vesselName, key); if (mLoadedAntennaCache.ContainsKey(key)) { return; } foreach (ProtoPartSnapshot pps in v.protoVessel.protoPartSnapshots) { foreach (ProtoPartModuleSnapshot ppms in pps.modules.Where(ppms => ppms.IsAntenna())) { if (!mProtoAntennaCache.ContainsKey(key)) { mProtoAntennaCache[key] = new List <IAntenna>(); } ProtoAntenna proto = new ProtoAntenna(v, pps, ppms); mProtoAntennaCache[key].Add(proto); OnRegister(proto); } } }
public override void OnLoad(ConfigNode node) { base.OnLoad(node); if (node.HasValue("RTAntennaTarget")) { try { Target = new Guid(node.GetValue("RTAntennaTarget")); } catch (FormatException) { Target = Guid.Empty; } } if (node.HasValue("DishAngle")) { RTDishRadians = Math.Cos(DishAngle / 2 * Math.PI / 180); } if (node.HasValue("DeployFxModules")) { mDeployFxModuleIndices = KSPUtil.ParseArray <Int32>(node.GetValue("DeployFxModules"), new ParserMethod <Int32>(Int32.Parse)); } if (node.HasValue("ProgressFxModules")) { mProgressFxModuleIndices = KSPUtil.ParseArray <Int32>(node.GetValue("ProgressFxModules"), new ParserMethod <Int32>(Int32.Parse)); } if (node.HasNode("TRANSMITTER")) { RTLog.Notify("ModuleRTAntenna: Found TRANSMITTER block."); mTransmitterConfig = node.GetNode("TRANSMITTER"); mTransmitterConfig.AddValue("name", "ModuleRTDataTransmitter"); } }
public NetworkManager() { Graph = new Dictionary <Guid, List <NetworkLink <ISatellite> > >(); // Load all planets into a dictionary; Planets = new Dictionary <Guid, CelestialBody>(); foreach (CelestialBody cb in FlightGlobals.Bodies) { Planets[cb.Guid()] = cb; } // Load all ground stations into a dictionary; GroundStations = new Dictionary <Guid, ISatellite>(); foreach (ISatellite sat in RTSettings.Instance.GroundStations) { try { GroundStations.Add(sat.Guid, sat); OnSatelliteRegister(sat); } catch (Exception e) // Already exists. { RTLog.Notify("A ground station cannot be loaded: " + e.Message); } } RTCore.Instance.Satellites.OnRegister += OnSatelliteRegister; RTCore.Instance.Satellites.OnUnregister += OnSatelliteUnregister; RTCore.Instance.OnPhysicsUpdate += OnPhysicsUpdate; }
/// <summary> /// Load a preset configuration into the RemoteTech settings object. /// </summary> public static Settings LoadPreset(Settings previousSettings, string presetCfgUrl) { var newPreSetSettings = new Settings(); var successLoadPreSet = false; // Exploit KSP's GameDatabase to find third-party mods' RemoteTechSetting node (from GameData/ExampleMod/RemoteTechSettings.cfg) var rtSettingCfGs = GameDatabase.Instance.GetConfigs("RemoteTechSettings"); for (var i = 0; i < rtSettingCfGs.Length; i++) { var rtSettingCfg = rtSettingCfGs[i]; if (!rtSettingCfg.url.Equals(presetCfgUrl)) { continue; } // Preserve important information of RT, such as the single ID var importantInfoNode = new ConfigNode(); importantInfoNode.AddValue("MapFilter", previousSettings.MapFilter); importantInfoNode.AddValue("ActiveVesselGuid", previousSettings.ActiveVesselGuid); importantInfoNode.AddValue("NoTargetGuid", previousSettings.NoTargetGuid); successLoadPreSet = ConfigNode.LoadObjectFromConfig(newPreSetSettings, rtSettingCfg.config); RTLog.Notify("Load the preset cfg into object with {0}: LOADED {1}", newPreSetSettings, successLoadPreSet ? "OK" : "FAIL"); // Restore backups ConfigNode.LoadObjectFromConfig(newPreSetSettings, importantInfoNode); break; } return(successLoadPreSet?newPreSetSettings: previousSettings); }
public AntennaManager() { GameEvents.onVesselGoOnRails.Add(OnVesselGoOnRails); OnRegister += a => RTLog.Notify("AntennaManager: OnRegister({0})", a.Name); OnUnregister += a => RTLog.Notify("AntennaManager: OnUnregister({0})", a.Name); }
public void Unregister(Guid key, IAntenna antenna) { RTLog.Notify("AntennaManager: Unregister({0})", antenna); if (!mLoadedAntennaCache.ContainsKey(key)) { return; } int instance_id = mLoadedAntennaCache[key].FindIndex(x => x == antenna); if (instance_id != -1) { mLoadedAntennaCache[key].RemoveAt(instance_id); if (mLoadedAntennaCache[key].Count == 0) { mLoadedAntennaCache.Remove(key); } OnUnregister(antenna); Vessel vessel = RTUtil.GetVesselById(key); if (vessel != null) { // trigger the onRails on more time // to reregister the antenna as a protoSat this.OnVesselGoOnRails(vessel); } } }
public static ISignalProcessor GetSignalProcessor(this Vessel v) { RTLog.Notify("GetSignalProcessor({0}): Check", v.vesselName); ISignalProcessor result = null; if (v.loaded && v.parts.Count > 0) { var partModuleList = v.Parts.SelectMany(p => p.Modules.Cast <PartModule>()).Where(pm => pm.IsSignalProcessor()).ToList(); // try to look for a moduleSPU result = partModuleList.FirstOrDefault(pm => pm.moduleName == "ModuleSPU") as ISignalProcessor ?? partModuleList.FirstOrDefault() as ISignalProcessor; } else { var protoPartList = v.protoVessel.protoPartSnapshots.SelectMany(x => x.modules).Where(ppms => ppms.IsSignalProcessor()).ToList(); // try to look for a moduleSPU on a unloaded vessel var protoPartProcessor = protoPartList.FirstOrDefault(ppms => ppms.moduleName == "ModuleSPU") ?? protoPartList.FirstOrDefault(); // convert the found protoPartSnapshots to a ProtoSignalProcessor if (protoPartProcessor != null) { result = new ProtoSignalProcessor(protoPartProcessor, v); } } return(result); }
/// <summary> /// Registers a protosatellite compiled from the unloaded vessel data. /// </summary> /// <param name="vessel">The vessel.</param> public void RegisterProto(Vessel vessel) { Guid key = vessel.protoVessel.vesselID; RTLog.Notify("SatelliteManager: RegisterProto({0}, {1})", vessel.vesselName, key); // Return if there are still signal processors loaded. if (_loadedSpuCache.ContainsKey(vessel.id)) { _loadedSpuCache.Remove(vessel.id); } var spu = vessel.GetSignalProcessor(); if (spu == null) { return; } var protos = new List <ISignalProcessor> { spu }; _satelliteCache[key] = new VesselSatellite(protos); OnRegister(_satelliteCache[key]); }
public static bool HasCommandStation(this Vessel v) { RTLog.Notify("HasCommandStation({0})", v.vesselName); if (v.loaded && v.parts.Count > 0) { return(v.Parts.SelectMany(p => p.Modules.Cast <PartModule>()).Any(pm => pm.IsCommandStation())); } return(v.protoVessel.protoPartSnapshots.SelectMany(x => x.modules).Any(pm => pm.IsCommandStation())); }
public SatelliteManager() { GameEvents.onVesselCreate.Add(OnVesselCreate); GameEvents.onVesselDestroy.Add(OnVesselDestroy); GameEvents.onVesselGoOnRails.Add(OnVesselOnRails); OnRegister += vs => RTLog.Notify("SatelliteManager: OnRegister({0})", vs); OnUnregister += vs => RTLog.Notify("SatelliteManager: OnUnregister({0})", vs); }
private void OnSatelliteUnregister(ISatellite s) { RTLog.Notify("NetworkManager: SatelliteUnregister({0})", s); Graph.Remove(s.Guid); foreach (var list in Graph.Values) { list.RemoveAll(l => l.Target == s); } mConnectionCache.Remove(s); }
public override void OnLoad(ConfigNode node) { base.OnLoad(node); if (node.HasNode("TRANSMITTER")) { RTLog.Notify("ModuleRTAntennaPassive: Found TRANSMITTER block."); mTransmitterConfig = node.GetNode("TRANSMITTER"); mTransmitterConfig.AddValue("name", "ModuleRTDataTransmitter"); } }
/// <summary> /// Load a preset config into the remotetech settings object. /// </summary> private static Settings LoadPreset(Settings settings, UrlDir.UrlConfig curSet) { settings.PreSets.Add(curSet.url); RTLog.Notify("Override RTSettings with configs from {0}", curSet.url); settings.backupFields(); ConfigNode.LoadObjectFromConfig(settings, curSet.config); settings.restoreBackups(); return(settings); }
private void RemoveTransmitter() { RTLog.Notify("ModuleRTAntenna: Remove TRANSMITTER success."); if (mTransmitter == null) { return; } part.RemoveModule((PartModule)mTransmitter); mTransmitter = null; }
public void Save() { try { ConfigNode save = new ConfigNode(); ConfigNode.CreateConfigFromObject(this, 0, save); save.Save(File); } catch (Exception e) { RTLog.Notify("An error occurred while attempting to save: " + e.Message); } }
/* * Methods */ /// <summary>Build a new instance of VesselSatellite.</summary> /// <param name="signalProcessors">List of signal processor for this satellites. Can't be null.</param> public VesselSatellite(List <ISignalProcessor> signalProcessors) { if (signalProcessors == null) { RTLog.Notify("VesselSatellite constructor: signalProcessor parameter is null", RTLogLevel.LVL4); throw new ArgumentNullException(); } SignalProcessors = signalProcessors; }
public void OnDestroy() { RTLog.Notify("ModuleSPUPassive: OnDestroy"); GameEvents.onVesselWasModified.Remove(OnVesselModified); GameEvents.onPartUndock.Remove(OnPartUndock); if (RTCore.Instance != null) { RTCore.Instance.Satellites.Unregister(mRegisteredId, this); mRegisteredId = Guid.Empty; } }
private void OnDestroy() { RTLog.Notify("ModuleRTAntenna: OnDestroy"); GameEvents.onVesselWasModified.Remove(OnVesselModified); GameEvents.onPartUndock.Remove(OnPartUndock); if (RTCore.Instance != null && mRegisteredId != Guid.Empty) { RTCore.Instance.Antennas.Unregister(mRegisteredId, this); mRegisteredId = Guid.Empty; } }
/// <summary>Searches a ProtoPartModuleSnapshot for an integer field.</summary> /// <returns>True if the member <paramref name="valueName"/> exists, false otherwise.</returns> /// <param name="ppms">The <see cref="ProtoPartModuleSnapshot"/> to query.</param> /// <param name="valueName">The name of a member in the ProtoPartModuleSnapshot.</param> /// <param name="value">The value of the member <paramref name="valueName"/> on success. An undefined value on failure.</param> public static bool GetInt(this ProtoPartModuleSnapshot ppms, string valueName, out int value) { value = 0; var result = ppms.moduleValues.TryGetValue(valueName, ref value); if (!result) { RTLog.Notify($"No integer '{value}' in ProtoPartModule '{ppms.moduleName}'"); } return(result); }
/// <summary> /// Saves the current RTSettings object to the RemoteTech_Settings.cfg /// </summary> public void Save() { try { ConfigNode details = new ConfigNode("RemoteTechSettings"); ConfigNode.CreateConfigFromObject(this, 0, details); ConfigNode save = new ConfigNode(); save.AddNode(details); save.Save(File); } catch (Exception e) { RTLog.Notify("An error occurred while attempting to save: " + e.Message); } }
private void onLevelWasLoaded(GameScenes scene) { if (scene == GameScenes.SPACECENTER) { if (RTSettings.Instance.firstStart) { // open here the option dialog for the first start RTLog.Notify("First start of RemoteTech!"); this.OptionWindow.Show(); RTSettings.Instance.firstStart = false; } } }
public void Dispose() { RTLog.Notify("FlightComputer: Dispose"); if (Vessel != null) { Vessel.OnFlyByWire -= OnFlyByWirePre; Vessel.OnFlyByWire -= OnFlyByWirePost; } if (mWindow != null) { mWindow.Hide(); } }