private void CacheControllable() { if (commNetParams == null && HighLogic.CurrentGame != null && HighLogic.CurrentGame.Parameters != null) { commNetParams = HighLogic.CurrentGame.Parameters.CustomParams <CommNet.CommNetParams>(); } if (Vessel == null) { SafeHouse.Logger.LogError("kOSVesselModule.CacheControllable called with null parentVessel, contact kOS developers"); workAroundControllable = false; } else if (!Vessel.packed && !Vessel.IsControllable && commNetParams != null && commNetParams.requireSignalForControl) { // HACK: Get around inability to affect throttle if connection is lost and require if (isControllableField == null) { isControllableField = Vessel.GetType().GetField("isControllable", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); } if (isControllableField != null) // given the above line, this shouldn't be null unless the KSP version changed. { isControllableField.SetValue(Vessel, true); workAroundControllable = true; } } else { workAroundControllable = false; } }
private void cacheControllable() { if (commNetParams == null) { commNetParams = HighLogic.CurrentGame.Parameters.CustomParams <CommNet.CommNetParams>(); } if (!parentVessel.IsControllable && commNetParams != null && commNetParams.requireSignalForControl) { // HACK: Get around inability to affect throttle if connection is lost and require if (isControllableField == null) { isControllableField = parentVessel.GetType().GetField("isControllable", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); } isControllableField.SetValue(parentVessel, true); workAroundControllable = true; } else { workAroundControllable = false; } }
public void Start() { CommNet.CommNetParams commNetParams = HighLogic.CurrentGame.Parameters.CustomParams <CommNet.CommNetParams>(); List <ModuleDataTransmitter> MDTs = part.Modules.OfType <ModuleDataTransmitter>().ToList(); List <ModuleDeployableAntenna> MDAs = part.Modules.OfType <ModuleDeployableAntenna>().ToList(); if (MDTs.Count != 1) { foreach (var mdt in MDTs) { mdt.Fields["powerText"].SetValue( Formatter.ValueShort(mdt.antennaPower * commNetParams.rangeModifier) + (mdt.antennaCombinable ? string.Format(" ({0}, {1}: {2})", Localizer.Format("#CAE_PAW_Combinability"), Localizer.Format("#CAE_PAW_Combinab_Exponent_Short"), mdt.antennaCombinableExponent) : "") , mdt); } foreach (var field in Fields) { field.guiActive = false; field.guiActiveEditor = false; } return; } var moduleDT = MDTs[0]; //ModuleDeployableAntenna // status | Status | Retracted Retracting.. Extended Extending.. //moduleDA.status //statusText Antenna State Idle //moduleDT.statusText; if (MDAs.Count == 1) { var moduleDA = MDAs[0]; moduleDA.Fields["status"].group.name = "CommNetA"; moduleDA.Fields["status"].group.displayName = "#CommNetA_Name"; moduleDA.Fields["status"].guiActiveEditor = true; } moduleDT.Fields["statusText"].group.name = "CommNetA"; moduleDT.Fields["statusText"].group.displayName = "#CommNetA_Name"; //moduleDT.Fields["statusText"].guiActiveEditor = true; moduleDT.Fields["powerText"].guiActive = false; moduleDT.Fields["powerText"].guiActiveEditor = false; double antennaPowerModified = moduleDT.antennaPower * commNetParams.rangeModifier; AntennaRatingStr = Formatter.ValueShort(antennaPowerModified); AntennaTypeStr = Formatter.ToTitleCase(moduleDT.antennaType.displayDescription()); DataResourceCostStr = Localizer.Format("#CAE_EC_Mit", moduleDT.DataResourceCost.ToString("#.##")); BandwidthStr = Localizer.Format("#CAE_Mit_S", (moduleDT.packetSize / moduleDT.packetInterval).ToString("#.##")); PacketStr = Localizer.Format("#CAE_Mit", moduleDT.packetSize.ToString("#.#")) + " & " + Localizer.Format("#CAE_EC", moduleDT.packetResourceCost.ToString("#.##")); if (moduleDT.antennaCombinable) { AntennaRatingStr += " " + Localizer.Format("#autoLOC_236248"); CombinabilityExponentStr = moduleDT.antennaCombinableExponent.ToString(); } else { Fields["CombinabilityExponentStr"].guiName = "#CAE_PAW_Combinability"; CombinabilityExponentStr = Localizer.Format("#autoLOC_439840"); } if (moduleDT.antennaType == AntennaType.INTERNAL) { Events["VesselRatingUpdate"].active = true; foreach (var f in Fields) { if (f.name != "AntennaTypeStr" && f.name != "AntennaRatingStr") { f.guiActive = false; f.guiActiveEditor = false; } } } }
private void Start() { commNetParams = HighLogic.CurrentGame.Parameters.CustomParams <CommNet.CommNetParams>(); int TrackingLevels = 3; CBK cbk = new CBK(); if (cbk.founded) { TrackingLevels = cbk.levelsTracking; } float[] TrackingStationFloats = new float[TrackingLevels]; //{ 0.0f, 0.5f, 1.0f }; for (int i = 0; i < TrackingLevels; i++) { TrackingStationFloats[i] = (float)i / (TrackingLevels - 1); } float CurrentTrackingStationFloat = ScenarioUpgradeableFacilities.GetFacilityLevel(SpaceCenterFacility.TrackingStation); CurrentTrackingStationIndex = TrackingStationFloats.IndexOf(CurrentTrackingStationFloat); double[] DSNPowerModified = new double[TrackingLevels]; string[] DSNPowerModified_str = new string[TrackingLevels]; for (int i = 0; i < TrackingLevels; i++) { double dsnPower = GameVariables.Instance.GetDSNRange(TrackingStationFloats[i]); DSNPowerModified[i] = dsnPower /* * commNetParams.DSNModifier*/; DSNPowerModified_str[i] = Formatter.ValueExtraShortSpaced(DSNPowerModified[i]); } List <AvailablePart> partsDT = PartLoader.LoadedPartsList.Where (p => p.partPrefab.Modules.OfType <ModuleDataTransmitter>().Any()).ToList(); double BuiltInPowerModified = GetPowerMostCommonInternalAntenna(partsDT) * commNetParams.rangeModifier; string BuiltInPowerModified_str = Formatter.ValueExtraShortSpaced(BuiltInPowerModified); foreach (AvailablePart part in partsDT) { List <ModuleDataTransmitter> modules = part.partPrefab.Modules.OfType <ModuleDataTransmitter>().ToList(); if (modules.Count == 0) { continue; } var modinfos = part.moduleInfos.Where(i => modules[0].GUIName.Contains(i.moduleName)).ToList(); if (modules.Count != modinfos.Count) { continue; } for (int index = 0; index < modules.Count; index++) { ModuleDataTransmitter moduleDT = modules[index]; AvailablePart.ModuleInfo modinfo = modinfos[index]; double antennaPowerModified = moduleDT.antennaPower * commNetParams.rangeModifier; string[] DSNranges_str = new string[TrackingLevels]; double[] DSNranges = new double[TrackingLevels]; for (int i = 0; i < TrackingLevels; i++) { DSNranges[i] = Math.Sqrt(DSNPowerModified[i] * antennaPowerModified); } if (moduleDT.CommType != AntennaType.INTERNAL) { string BuiltInranges_str = Formatter.DistanceShort(Math.Sqrt(BuiltInPowerModified * antennaPowerModified)); for (int i = 0; i < TrackingLevels; i++) { DSNranges_str[i] = Formatter.DistanceShort(DSNranges[i]); } modinfo.info = Localizer.Format("#autoLOC_7001005", Formatter.ToTitleCase(moduleDT.antennaType.displayDescription())) + Localizer.Format("#autoLOC_7001006", Formatter.ValueShort(antennaPowerModified)) + (moduleDT.CommCombinable ? Localizer.Format("#CAE_Combinability_Exponent", moduleDT.CommCombinableExponent) : Localizer.Format("#CAE_Not_Combinable")) + Localizer.Format("#CAE_Title_vs"); if (moduleDT.CommType == AntennaType.RELAY) { modinfo.info += BuiltInPowerModified_str + Localizer.Format("#CAE_Built_In") + Localizer.Format("#CAE_Spaces") + BuiltInranges_str + "\n"; } for (int i = 0; i < TrackingLevels; i++) { modinfo.info += SmartAlphaChannel(i) + DSNPowerModified_str[i] + Localizer.Format("#CAE_DSN_LN", i + 1) + Localizer.Format("#CAE_Spaces") + DSNranges_str[i] + SmartAlphaChannel(i, false) + "\n"; } modinfo.info += Localizer.Format("#autoLOC_236840" /*\n<b>Packet size: </b><<1>> Mits\n*/, moduleDT.packetSize.ToString("F1")).TrimEnd() + " & " + Localizer.Format("#CAE_EC", moduleDT.packetResourceCost.ToString("#.##")) + "\n" + Localizer.Format("#autoLOC_236841" /*<b>Bandwidth: </b><<1>> Mits/sec\n*/, (moduleDT.packetSize / moduleDT.packetInterval).ToString("F2")) + "\n" + Localizer.Format("#autoLOC_236842" /*\n\nWhen Transmitting:*/).Trim() + Localizer.Format("#CAE_Consumption", Localizer.Format("#CAE_EC_Mit", moduleDT.DataResourceCost.ToString("#.#"))) ; } else // INTERNAL { for (int i = 0; i < TrackingLevels; i++) { DSNranges_str[i] = Formatter.DistanceExtraShort(DSNranges[i]); } string type = Formatter.ToTitleCase(moduleDT.CommType.displayDescription()); //Internal - ok if (type.Length > 8) { type = type.Substring(0, 7) + "."; } modinfo.info = Localizer.Format("#CAE_Type", type) + ", " + Localizer.Format("#CAE_Rating", Formatter.ValueShort(antennaPowerModified)) + (moduleDT.CommCombinable ? ", e:" + moduleDT.CommCombinableExponent : "") + Localizer.Format("#CAE_DSN_Short") + " "; if (TrackingLevels % 4 == 0) { modinfo.info += "<nobr>"; } for (int i = 0; i < TrackingLevels; i++) { modinfo.info += SmartAlphaChannel(i) + DSNranges_str[i] + (i != (TrackingLevels - 1)?", ":"") + SmartAlphaChannel(i, false); } if (TrackingLevels % 4 == 0) { modinfo.info += "</nobr>"; } modinfo.info += Localizer.Format("#CAE_Orange", Localizer.Format("#autoLOC_236846")); // #autoLOC_236846 = \n<i>Cannot transmit science</i>\n } } } }
private void cacheControllable() { if (commNetParams == null) commNetParams = HighLogic.CurrentGame.Parameters.CustomParams<CommNet.CommNetParams>(); if (!parentVessel.IsControllable && commNetParams != null && commNetParams.requireSignalForControl) { // HACK: Get around inability to affect throttle if connection is lost and require if (isControllableField == null) isControllableField = parentVessel.GetType().GetField("isControllable", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); isControllableField.SetValue(parentVessel, true); workAroundControllable = true; } else { workAroundControllable = false; } }
private void HandleServerSettings(byte[] messageData) { using (MessageReader mr = new MessageReader(messageData)) { WarpWorker.fetch.warpMode = (WarpMode)mr.Read<int>(); Client.fetch.gameMode = (GameMode)mr.Read<int>(); Client.fetch.serverAllowCheats = mr.Read<bool>(); numberOfKerbals = mr.Read<int>(); numberOfVessels = mr.Read<int>(); ScreenshotWorker.fetch.screenshotHeight = mr.Read<int>(); AsteroidWorker.fetch.maxNumberOfUntrackedAsteroids = mr.Read<int>(); ChatWorker.fetch.consoleIdentifier = mr.Read<string>(); Client.fetch.serverDifficulty = (GameDifficulty)mr.Read<int>(); VesselWorker.fetch.safetyBubbleDistance = mr.Read<float>(); if (Client.fetch.serverDifficulty != GameDifficulty.CUSTOM) { Client.fetch.serverParameters = GameParameters.GetDefaultParameters(Client.fetch.ConvertGameMode(Client.fetch.gameMode), (GameParameters.Preset)Client.fetch.serverDifficulty); } else { GameParameters newParameters = new GameParameters(); GameParameters.AdvancedParams newAdvancedParameters = new GameParameters.AdvancedParams(); CommNet.CommNetParams newCommNetParameters = new CommNet.CommNetParams(); newParameters.Difficulty.AllowStockVessels = mr.Read<bool>(); newParameters.Difficulty.AutoHireCrews = mr.Read<bool>(); newParameters.Difficulty.BypassEntryPurchaseAfterResearch = mr.Read<bool>(); newParameters.Difficulty.IndestructibleFacilities = mr.Read<bool>(); newParameters.Difficulty.MissingCrewsRespawn = mr.Read<bool>(); newParameters.Difficulty.ReentryHeatScale = mr.Read<float>(); newParameters.Difficulty.ResourceAbundance = mr.Read<float>(); newParameters.Flight.CanQuickLoad = newParameters.Flight.CanRestart = newParameters.Flight.CanLeaveToEditor = mr.Read<bool>(); newParameters.Career.FundsGainMultiplier = mr.Read<float>(); newParameters.Career.FundsLossMultiplier = mr.Read<float>(); newParameters.Career.RepGainMultiplier = mr.Read<float>(); newParameters.Career.RepLossMultiplier = mr.Read<float>(); newParameters.Career.RepLossDeclined = mr.Read<float>(); newParameters.Career.ScienceGainMultiplier = mr.Read<float>(); newParameters.Career.StartingFunds = mr.Read<float>(); newParameters.Career.StartingReputation = mr.Read<float>(); newParameters.Career.StartingScience = mr.Read<float>(); //New KSP 1.2 Settings newParameters.Difficulty.RespawnTimer = mr.Read<float>(); newParameters.Difficulty.EnableCommNet = mr.Read<bool>(); newParameters.CustomParams<GameParameters.AdvancedParams>().EnableKerbalExperience = mr.Read<bool>(); newParameters.CustomParams<GameParameters.AdvancedParams>().ImmediateLevelUp = mr.Read<bool>(); newParameters.CustomParams<GameParameters.AdvancedParams>().AllowNegativeCurrency = mr.Read<bool>(); newParameters.CustomParams<GameParameters.AdvancedParams>().ResourceTransferObeyCrossfeed = mr.Read<bool>(); newParameters.CustomParams<GameParameters.AdvancedParams>().BuildingImpactDamageMult = mr.Read<float>(); newParameters.CustomParams<GameParameters.AdvancedParams>().PartUpgradesInCareer = newParameters.CustomParams<GameParameters.AdvancedParams>().PartUpgradesInSandbox = mr.Read<bool>(); newParameters.CustomParams<GameParameters.AdvancedParams>().PressurePartLimits = newParameters.CustomParams<GameParameters.AdvancedParams>().GPartLimits = newParameters.CustomParams<GameParameters.AdvancedParams>().GKerbalLimits = mr.Read<bool>(); newParameters.CustomParams<GameParameters.AdvancedParams>().KerbalGToleranceMult = mr.Read<float>(); newParameters.CustomParams<CommNet.CommNetParams>().requireSignalForControl = mr.Read<bool>(); newParameters.CustomParams<CommNet.CommNetParams>().plasmaBlackout = mr.Read<bool>(); newParameters.CustomParams<CommNet.CommNetParams>().rangeModifier = mr.Read<float>(); newParameters.CustomParams<CommNet.CommNetParams>().DSNModifier = mr.Read<float>(); newParameters.CustomParams<CommNet.CommNetParams>().occlusionMultiplierVac = mr.Read<float>(); newParameters.CustomParams<CommNet.CommNetParams>().occlusionMultiplierAtm = mr.Read<float>(); newParameters.CustomParams<CommNet.CommNetParams>().enableGroundStations = mr.Read<bool>(); Client.fetch.serverParameters = newParameters; } } }