/// <summary> /// Turn on or off the specific antenna /// </summary> public void toggleAntenna(CNCAntennaPartInfo partInfo, bool inUse) { if (!partInfo.canComm) // antenna is not deployed { ScreenMessage msg = new ScreenMessage(Localizer.Format("#CNC_ScreenMsg_toggleAntenna", partInfo.name), CNCSettings.ScreenMessageDuration, ScreenMessageStyle.UPPER_CENTER); //string.Format("Antenna '{0}' is not deployed.", ) ScreenMessages.PostScreenMessage(msg); CNCLog.Verbose("Cannot set the non-deployed antenna '{0}' of CommNet vessel '{1}' to {2}", partInfo.name, this.Vessel.GetName(), inUse); return; } partInfo.inUse = inUse; if (this.Vessel.loaded) { partInfo.partReference.FindModuleImplementing <CNConstellationAntennaModule>().InUse = inUse; } else { var cncAntMod = partInfo.partSnapshotReference.FindModule("CNConstellationAntennaModule"); if (cncAntMod != null) { cncAntMod.moduleValues.SetValue("InUse", inUse); } } CNCLog.Verbose("Set the antenna '{0}' of CommNet vessel '{1}' to {2}", partInfo.name, this.Vessel.GetName(), inUse); }
/// <summary> /// Replace one frequency in the particular antenna /// </summary> public void updateFrequency(CNCAntennaPartInfo partInfo, short newFrequency) { if (!Constellation.isFrequencyValid(newFrequency)) { CNCLog.Error("New frequency {0} is out of the range [0,{1}]!", newFrequency, short.MaxValue); return; } partInfo.frequency = newFrequency; if (this.Vessel.loaded) { partInfo.partReference.FindModuleImplementing <CNConstellationAntennaModule>().Frequency = newFrequency; } else { var cncAntMod = partInfo.partSnapshotReference.FindModule("CNConstellationAntennaModule"); if (cncAntMod != null) { cncAntMod.moduleValues.SetValue("Frequency", newFrequency); } } CNCLog.Verbose("Update the antenna of CommNet vessel '{0}' to {1}", this.Vessel.GetName(), newFrequency); }
/// <summary> /// Read the part data of an unloaded/loaded vessel and store in data structures /// </summary> protected List <CNCAntennaPartInfo> readAntennaData() { List <CNCAntennaPartInfo> antennas = new List <CNCAntennaPartInfo>(); int numParts = (!this.vessel.loaded) ? this.vessel.protoVessel.protoPartSnapshots.Count : this.vessel.Parts.Count; //inspect each part for (int partIndex = 0; partIndex < numParts; partIndex++) { Part thisPart; ProtoPartSnapshot partSnapshot = null; if (this.Vessel.loaded) { thisPart = this.vessel.Parts[partIndex]; } else { partSnapshot = this.vessel.protoVessel.protoPartSnapshots[partIndex]; thisPart = partSnapshot.partInfo.partPrefab; } bool populatedAntennaInfo = false; CNCAntennaPartInfo newAntennaPartInfo = new CNCAntennaPartInfo();; ProtoPartModuleSnapshot partModuleSnapshot = null; //inspect each module of the part for (int moduleIndex = 0; moduleIndex < thisPart.Modules.Count; moduleIndex++) { PartModule thisPartModule = thisPart.Modules[moduleIndex]; if (thisPartModule is CNConstellationAntennaModule) // is it CNConstellationAntennaModule? { if (!this.Vessel.loaded) { partModuleSnapshot = partSnapshot.FindModule(thisPartModule, moduleIndex); newAntennaPartInfo.frequency = short.Parse(partModuleSnapshot.moduleValues.GetValue("Frequency")); string oname = partModuleSnapshot.moduleValues.GetValue("OptionalName"); newAntennaPartInfo.name = (oname.Length == 0) ? partSnapshot.partInfo.title : oname; newAntennaPartInfo.inUse = bool.Parse(partModuleSnapshot.moduleValues.GetValue("InUse")); newAntennaPartInfo.CosAngle = double.Parse(partModuleSnapshot.moduleValues.GetValue("CosAngle")); } else { CNConstellationAntennaModule antennaMod = (CNConstellationAntennaModule)thisPartModule; newAntennaPartInfo.frequency = antennaMod.Frequency; newAntennaPartInfo.name = antennaMod.Name; newAntennaPartInfo.inUse = antennaMod.InUse; } populatedAntennaInfo = true; } else if (thisPartModule is ICommAntenna) // is it ModuleDataTransmitter? { ICommAntenna thisAntenna = thisPartModule as ICommAntenna; if (!this.Vessel.loaded) { partModuleSnapshot = partSnapshot.FindModule(thisPartModule, moduleIndex); } newAntennaPartInfo.antennaPower = (!this.vessel.loaded) ? thisAntenna.CommPowerUnloaded(partModuleSnapshot) : thisAntenna.CommPower; newAntennaPartInfo.antennaCombinable = thisAntenna.CommCombinable; newAntennaPartInfo.antennaCombinableExponent = thisAntenna.CommCombinableExponent; newAntennaPartInfo.antennaType = thisAntenna.CommType; newAntennaPartInfo.partReference = thisPart; //unique ID for part is not available newAntennaPartInfo.partSnapshotReference = partSnapshot; newAntennaPartInfo.canComm = (!this.vessel.loaded) ? thisAntenna.CanCommUnloaded(partModuleSnapshot) : thisAntenna.CanComm(); populatedAntennaInfo = true; } } if (populatedAntennaInfo) // valid info? { antennas.Add(newAntennaPartInfo); CNCLog.Debug("CommNet Vessel '{0}' has antenna '{1}' of {2} and {3} power (w/o range modifier)", this.Vessel.GetName(), newAntennaPartInfo.name, newAntennaPartInfo.frequency, newAntennaPartInfo.antennaPower); } } return(antennas); }