/// <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); }
public Antenna_Info(Vessel v) { List <AntennaPartInfo> adaptorsInfoList = new List <AntennaPartInfo>(); int numParts = (!v.loaded) ? v.protoVessel.protoPartSnapshots.Count : v.Parts.Count; for (int partIndex = 0; partIndex < numParts; partIndex++) { Part part; ProtoPartSnapshot protoPart = null; if (v.loaded) { part = v.Parts[partIndex]; } else { protoPart = v.protoVessel.protoPartSnapshots[partIndex]; part = PartLoader.getPartInfoByName(protoPart.partName).partPrefab; } bool hasInfo = false; AntennaPartInfo antennaPartInfo = new AntennaPartInfo(); ProtoPartModuleSnapshot protoPartModule = null; // Inspect each module of the part for (int moduleIndex = 0; moduleIndex < part.Modules.Count; moduleIndex++) { NetworkAdaptor antennaMod = new NetworkAdaptor(); PartModule pModule = part.Modules[moduleIndex]; if (pModule is NetworkAdaptor) { if (v.loaded) { antennaMod = (NetworkAdaptor)pModule; antennaPartInfo.frequency = antennaMod.frequency; antennaPartInfo.ecCost = antennaMod.ecCost; antennaPartInfo.rate = antennaMod.rate; antennaPartInfo.name = part.partInfo.title; } else { ProtoPartModuleSnapshot netAdaptor = FlightGlobals.FindProtoPartByID(protoPart.flightID).FindModule("NetworkAdaptor"); antennaPartInfo.frequency = Lib.Proto.GetShort(netAdaptor, "frequency"); antennaPartInfo.ecCost = Lib.Proto.GetDouble(netAdaptor, "ecCost"); antennaPartInfo.rate = Lib.Proto.GetDouble(netAdaptor, "rate"); antennaPartInfo.name = protoPart.partInfo.title; } hasInfo = true; } else if (pModule is ICommAntenna) { ICommAntenna antenna = pModule as ICommAntenna; // This method only works when v.Loaded, otherwise this brings a wrong deployState ModuleDeployableAntenna anim = part.FindModuleImplementing <ModuleDeployableAntenna>(); // Assume extended if there is no animator if (anim != null) { if (!v.loaded) { // This method works to !v.Loaded ProtoPartModuleSnapshot deployState = FlightGlobals.FindProtoPartByID(protoPart.flightID).FindModule("ModuleDeployableAntenna"); antennaPartInfo.deployState = Lib.KCOMMNET.String_to_DeployState(Lib.Proto.GetString(deployState, "deployState")); } else { antennaPartInfo.deployState = anim.deployState; } } else { antennaPartInfo.deployState = ModuleDeployablePart.DeployState.EXTENDED; } if (!v.loaded) { protoPartModule = protoPart.FindModule(pModule, moduleIndex); } antennaPartInfo.antennaPower = (!v.loaded) ? antenna.CommPowerUnloaded(protoPartModule) : antenna.CommPower; antennaPartInfo.antennaCombinable = antenna.CommCombinable; antennaPartInfo.antennaCombinableExponent = antenna.CommCombinableExponent; antennaPartInfo.antennaType = antenna.CommType; //antennaPartInfo.partReference = part; //antennaPartInfo.partSnapshotReference = protoPart; antennaPartInfo.canComm = (!v.loaded) ? antenna.CanCommUnloaded(protoPartModule) : antenna.CanComm(); hasInfo = true; } } if (hasInfo) { adaptorsInfoList.Add(antennaPartInfo); } } freqSortedList = adaptorsInfoList.OrderBy(a => a.frequency).ToList(); // order by frequency adaptorsSortedList = adaptorsInfoList.OrderBy(a => a.name).ToList(); // order by device name AntennaCalc(freqSortedList); }