public void Update() { // get range double range = Signal.Range(scope, penalty, Signal.ECC()); // update rmb ui status RangeStatus = Lib.HumanReadableRange(range); RelayStatus = relay ? "Active" : "Disabled"; // when in flight if (HighLogic.LoadedSceneIsFlight) { // determine currect packet cost // note: we set it to max float if out of range, to indirectly specify antenna score if (transmission_distance <= range) { this.packetResourceCost = (float)(min_transmission_cost + (max_transmission_cost - min_transmission_cost) * transmission_distance / range); } else { this.packetResourceCost = float.MaxValue; } // update rmb ui status CostStatus = this.packetResourceCost.ToString("F2") + " EC/Mbit"; } }
public void Update() { // do nothing if tech tree is not ready if (!Lib.TechReady()) return; // get range double range = Signal.Range(scope, Signal.ECC()); // update rmb ui status RangeStatus = Lib.HumanReadableRange(range); RelayStatus = relay ? "Active" : "Disabled"; // when in flight if (HighLogic.LoadedSceneIsFlight) { // remove incomplete data toggle Events["TransmitIncompleteToggle"].active = false; // get vessel info from the cache vessel_info info = Cache.VesselInfo(vessel); // proper antenna mechanics for valid vessels if (info.is_valid) { // shortcut link_data link = info.link; // enable/disable science transmission can_transmit = link.linked; // determine currect packet cost // note: we set it to max float if out of range, to indirectly specify antenna score if (link.distance <= range) { this.packetResourceCost = (float)(min_transmission_cost + (max_transmission_cost - min_transmission_cost) * link.distance / range); CostStatus = Lib.BuildString(this.packetResourceCost.ToString("F2"), " EC/Mbit"); } else { this.packetResourceCost = float.MaxValue; CostStatus = ""; } } // sane defaults for invalid vessels else { can_transmit = false; this.packetResourceCost = float.MaxValue; CostStatus = ""; } } }
public static signal_data analyze_signal(List<Part> parts) { // store data signal_data signal = new signal_data(); // get error correcting code factor signal.ecc = Signal.ECC(); // scan the parts foreach(Part p in parts) { // for each module foreach(PartModule m in p.Modules) { // antenna if (m.moduleName == "Antenna") { Antenna mm = (Antenna)m; // calculate actual range double range = Signal.Range(mm.scope, mm.penalty, signal.ecc); // maintain 2nd best antenna signal.second_best_range = range > signal.range ? signal.range : Math.Max(signal.second_best_range, range); // keep track of best antenna if (range > signal.range) { signal.range = range; signal.transmission_cost_min = mm.min_transmission_cost; signal.transmission_cost_max = mm.max_transmission_cost; } // keep track of best relay antenna if (mm.relay && range > signal.relay_range) { signal.relay_range = range; signal.relay_cost = mm.relay_cost; } } } } // return data return signal; }
public antenna_data(Vessel v) { // [disabled] EVA kerbals have an implicit antenna //if (v.isEVA) //{ // range = 1000.0; //< 1Km // return; //} // get error-correcting code factor // note: this could possibly get called when tech tree is not ready double ecc = Signal.ECC(); // get ec available // note: this is the amount available at previous simulation step double ec_amount = ResourceCache.Info(v, "ElectricCharge").amount; // if the vessel is loaded if (v.loaded) { // choose the best antenna foreach (Antenna a in v.FindPartModulesImplementing <Antenna>()) { // calculate real range double real_range = Signal.Range(a.scope, ecc); // maintain best range range = Math.Max(range, real_range); // maintain best relay if (a.relay && real_range > relay_range && ec_amount >= a.relay_cost) { relay_range = real_range; relay_cost = a.relay_cost; } } } // if the vessel isn't loaded else { // choose the best antenna foreach (ProtoPartSnapshot p in v.protoVessel.protoPartSnapshots) { foreach (ProtoPartModuleSnapshot m in p.modules) { // early exit if (m.moduleName != "Antenna") { continue; } // get the antenna module prefab Part part_prefab = PartLoader.getPartInfoByName(p.partName).partPrefab; Antenna a = Lib.FindModuleAs <Antenna>(part_prefab, "Antenna"); if (!a) { continue; } // calculate real range double real_range = Signal.Range(a.scope, ecc); // maintain best range range = Math.Max(range, real_range); // maintain best relay if (Lib.Proto.GetBool(m, "relay") && real_range > relay_range && ec_amount >= a.relay_cost) { relay_range = real_range; relay_cost = a.relay_cost; } } } } }