public IEnumerator NetworkInitialized() { yield return(new WaitForSeconds(2)); Lib.DebugLog("NetworkInitialized"); Communications.NetworkInitialized = true; }
public void ToggleActions(PartModule partModule, bool value) { Lib.DebugLog("Part '{0}'.'{1}', setting actions to {2}", partModule.part.partInfo.title, partModule.moduleName, value ? "ON" : "OFF"); foreach (BaseAction ac in partModule.Actions) { ac.active = value; } }
public void Stop() { Lib.DebugLog("Stopping Transformation"); if (transf != null) { rotationRateGoal = 0.0f; } }
public void Play() { Lib.DebugLog("Playing Transformation"); if (transf != null) { rotationRateGoal = 1.0f; } }
public override void OnUpdate() { if (!Lib.IsFlight() || module == null) { return; } // get energy from cache resources = ResourceCache.Info(vessel, "ElectricCharge"); hasEnergy = resources.amount > double.Epsilon; // Update UI only if hasEnergy has changed or if is broken state has changed if (isBroken) { if (isBroken != lastBrokenState) { lastBrokenState = isBroken; Update_UI(!isBroken); } } else if (hasEnergyChanged != hasEnergy) { Lib.DebugLog("Energy state has changed: {0}", hasEnergy); hasEnergyChanged = hasEnergy; lastBrokenState = false; // Update UI Update_UI(hasEnergy); } // Constantly Update UI for special modules if (isBroken) { Constant_OnGUI(!isBroken); } else { Constant_OnGUI(hasEnergy); } if (!hasEnergy || isBroken) { actualCost = 0; isConsuming = false; } else { isConsuming = GetIsConsuming(); } }
// enable/disable dialog "Transfer crew" on UI public void RefreshDialog() { Lib.DebugLog("Refreshing Dialog"); if (HighLogic.LoadedSceneIsEditor) { GameEvents.onEditorPartEvent.Fire(ConstructionEventType.PartTweaked, part); GameEvents.onEditorShipModified.Fire(EditorLogic.fetch.ship); } else if (HighLogic.LoadedSceneIsFlight) { GameEvents.onVesselWasModified.Fire(this.vessel); } part.CheckTransferDialog(); MonoUtilities.RefreshContextWindows(part); }
// Support Connected Living Space void SetPassable(bool isPassable) { if (hasCLS) { // for each module foreach (PartModule m in part.Modules) { if (m.moduleName == "ModuleConnectedLivingSpace") { Lib.DebugLog("Part '{0}', CLS has been {1}", part.partInfo.title, isPassable ? "enabled" : "disabled"); Lib.ReflectionValue(m, "passable", isPassable); } } } Lib.DebugLog("CrewCapacity: '{0}'", part.CrewCapacity); Lib.DebugLog("CrewTransferAvailable: '{0}'", isPassable); part.crewTransferAvailable = isPassable; }
// Enable/Disable IVA void UpdateIVA(bool ative) { if (Lib.IsFlight()) { if (vessel.isActiveVessel) { if (ative) { Lib.DebugLog("Part '{0}', Spawning IVA.", part.partInfo.title); part.SpawnIVA(); } else { Lib.DebugLog("Part '{0}', Destroying IVA.", part.partInfo.title); part.DespawnIVA(); } RefreshDialog(); } } }
public Transformator(Part p, string transf_name, float SpinRate, float spinAccel) { transf = null; name = string.Empty; part = p; if (transf_name.Length > 0) { Lib.DebugLog("Looking for : {0}", transf_name); Transform[] transfArray = p.FindModelTransforms(transf_name); if (transfArray.Length > 0) { Lib.DebugLog("Transform has been found"); name = transf_name; transf = transfArray[0]; this.SpinRate = SpinRate; this.spinAccel = spinAccel; baseAngles = transf.localRotation; } } }
public override void GUI_Update(bool isEnabled) { Lib.DebugLog("Buttons is '{0}' for '{1}' landingGear", (isEnabled == true ? "ON" : "OFF"), landingGear.part.partInfo.title); landingGear.Events["EventToggle"].active = isEnabled; }
// constructor /// <summary> Creates a <see cref="ConnectionInfo"/> object for the specified vessel from it's antenna modules</summary> public ConnectionInfo(Vessel v, bool powered, bool storm) { // set RemoteTech powered and storm state if (RemoteTech.Enabled) { RemoteTech.SetPoweredDown(v.id, !powered); RemoteTech.SetCommsBlackout(v.id, storm); } // return no connection if there is no ec left if (!powered) { // hysteresis delay if ((DB.Vessel(v).hyspos_signal >= 5.0)) { DB.Vessel(v).hyspos_signal = 5.0; DB.Vessel(v).hysneg_signal = 0.0; return; } DB.Vessel(v).hyspos_signal += 0.1; } else { // hysteresis delay DB.Vessel(v).hysneg_signal += 0.1; if (!(DB.Vessel(v).hysneg_signal >= 5.0)) { return; } DB.Vessel(v).hysneg_signal = 5.0; DB.Vessel(v).hyspos_signal = 0.0; } // CommNet or simple signal system if (!RemoteTech.Enabled) { List <ModuleDataTransmitter> transmitters; // if vessel is loaded if (v.loaded) { // find transmitters transmitters = v.FindPartModulesImplementing <ModuleDataTransmitter>(); if (transmitters != null) { foreach (ModuleDataTransmitter t in transmitters) { if (t.antennaType == AntennaType.INTERNAL) // do not include internal data rate, ec cost only { internal_cost += t.DataResourceCost * t.DataRate; } else { // do we have an animation ModuleDeployableAntenna animation = t.part.FindModuleImplementing <ModuleDeployableAntenna>(); if (animation != null) { // only include data rate and ec cost if transmitter is extended if (animation.deployState == ModuleDeployablePart.DeployState.EXTENDED) { rate += t.DataRate; external_cost += t.DataResourceCost * t.DataRate; } } // no animation else { rate += t.DataRate; external_cost += t.DataResourceCost * t.DataRate; } } } } } // if vessel is not loaded else { // find proto transmitters foreach (ProtoPartSnapshot p in v.protoVessel.protoPartSnapshots) { // get part prefab (required for module properties) Part part_prefab = PartLoader.getPartInfoByName(p.partName).partPrefab; transmitters = part_prefab.FindModulesImplementing <ModuleDataTransmitter>(); if (transmitters != null) { foreach (ModuleDataTransmitter t in transmitters) { if (t.antennaType == AntennaType.INTERNAL) // do not include internal data rate, ec cost only { internal_cost += t.DataResourceCost * t.DataRate; } else { // do we have an animation ProtoPartModuleSnapshot m = p.FindModule("ModuleDeployableAntenna"); if (m != null) { // only include data rate and ec cost if transmitter is extended string deployState = Lib.Proto.GetString(m, "deployState"); if (deployState == "EXTENDED") { rate += t.DataRate; external_cost += t.DataResourceCost * t.DataRate; } } // no animation else { rate += t.DataRate; external_cost += t.DataResourceCost * t.DataRate; } } } } } } // if CommNet is enabled if (HighLogic.fetch.currentGame.Parameters.Difficulty.EnableCommNet) { // are we connected to DSN if (v.connection != null) { if (v.connection.IsConnected) { linked = true; status = v.connection.ControlPath.First.hopType == CommNet.HopType.Home ? LinkStatus.direct_link : LinkStatus.indirect_link; strength = v.connection.SignalStrength; rate = rate * strength; target_name = Lib.Ellipsis(Localizer.Format(v.connection.ControlPath.First.end.displayName).Replace("Kerbin", "DSN"), 20); return; } // is loss of connection due to plasma blackout else if (Lib.ReflectionValue <bool>(v.connection, "inPlasma")) // calling InPlasma causes a StackOverflow :( { status = LinkStatus.plasma; rate = 0.0; internal_cost = 0.0; external_cost = 0.0; return; } } // no connection rate = 0.0; internal_cost = 0.0; external_cost = 0.0; return; } // the simple stupid always connected signal system linked = true; status = LinkStatus.direct_link; strength = 1; // 100 % target_name = "DSN: KSC"; return; } // RemoteTech signal system else { // if vessel is loaded if (v.loaded) { // find transmitters foreach (Part p in v.parts) { foreach (PartModule m in p.Modules) { // calculate internal (passive) transmitter ec usage @ 0.5W each if (m.moduleName == "ModuleRTAntennaPassive") { internal_cost += 0.0005; } // calculate external transmitters else if (m.moduleName == "ModuleRTAntenna") { // only include data rate and ec cost if transmitter is active if (Lib.ReflectionValue <bool>(m, "IsRTActive")) { rate += (Lib.ReflectionValue <float>(m, "RTPacketSize") / Lib.ReflectionValue <float>(m, "RTPacketInterval")); external_cost += m.resHandler.inputResources.Find(r => r.name == "ElectricCharge").rate; } } } } } // if vessel is not loaded else { // find proto transmitters foreach (ProtoPartSnapshot p in v.protoVessel.protoPartSnapshots) { // get part prefab (required for module properties) Part part_prefab = PartLoader.getPartInfoByName(p.partName).partPrefab; int index = 0; // module index foreach (ProtoPartModuleSnapshot m in p.modules) { // calculate internal (passive) transmitter ec usage @ 0.5W each if (m.moduleName == "ModuleRTAntennaPassive") { internal_cost += 0.0005; } // calculate external transmitters else if (m.moduleName == "ModuleRTAntenna") { // only include data rate and ec cost if transmitter is active skip if index is out of range if (Lib.Proto.GetBool(m, "IsRTActive") && index < part_prefab.Modules.Count) { // get module prefab PartModule pm = part_prefab.Modules.GetModule(index); if (pm != null) { rate += (Lib.ReflectionValue <float>(pm, "RTPacketSize") / Lib.ReflectionValue <float>(pm, "RTPacketInterval")); external_cost += pm.resHandler.inputResources.Find(r => r.name == "ElectricCharge").rate; } else { Lib.DebugLog(String.Format("ConnectionInfo: Could not find PartModule ModuleRTAntenna for part {0} on unloaded vessel {1}, using default values as a workaround", p.partName, v.vesselName)); rate += 6.6666; // 6.67 Mb/s external_cost += 0.025; // 25 W/s } } } index++; } } } // are we connected if (RemoteTech.Connected(v.id)) { linked = RemoteTech.ConnectedToKSC(v.id); status = RemoteTech.TargetsKSC(v.id) ? LinkStatus.direct_link : LinkStatus.indirect_link; strength = RemoteTech.GetSignalDelay(v.id); target_name = status == LinkStatus.direct_link ? Lib.Ellipsis("DSN: " + (RemoteTech.NameTargetsKSC(v.id) ?? ""), 20): Lib.Ellipsis(RemoteTech.NameFirstHopToKSC(v.id) ?? "", 20); return; } // is loss of connection due to a blackout else if (RemoteTech.GetCommsBlackout(v.id)) { status = storm ? LinkStatus.storm : LinkStatus.plasma; rate = 0.0; internal_cost = 0.0; external_cost = 0.0; return; } // no connection rate = 0.0; internal_cost = 0.0; external_cost = 0.0; return; } }
public AntennaInfoRT(Vessel v, bool powered, bool storm) { RemoteTech.SetPoweredDown(v.id, !powered); RemoteTech.SetCommsBlackout(v.id, storm); // if vessel is loaded, don't calculate ec, RT already handle it. if (v.loaded) { // find transmitters foreach (Part p in v.parts) { foreach (PartModule m in p.Modules) { // calculate internal (passive) transmitter ec usage @ 0.5W each if (m.moduleName == "ModuleRTAntennaPassive") { ec += 0.0005; } // calculate external transmitters else if (m.moduleName == "ModuleRTAntenna") { // only include data rate and ec cost if transmitter is active if (Lib.ReflectionValue <bool>(m, "IsRTActive")) { rate += (Lib.ReflectionValue <float>(m, "RTPacketSize") / Lib.ReflectionValue <float>(m, "RTPacketInterval")); } } } } } // if vessel is not loaded else { // find proto transmitters foreach (ProtoPartSnapshot p in v.protoVessel.protoPartSnapshots) { // get part prefab (required for module properties) Part part_prefab = PartLoader.getPartInfoByName(p.partName).partPrefab; foreach (ProtoPartModuleSnapshot m in p.modules) { // calculate internal (passive) transmitter ec usage @ 0.5W each if (m.moduleName == "ModuleRTAntennaPassive") { ec += 0.0005; } // calculate external transmitters else if (m.moduleName == "ModuleRTAntenna") { // only include data rate and ec cost if transmitter is active if (Lib.Proto.GetBool(m, "IsRTActive")) { bool mFound = false; // get all modules in prefab foreach (PartModule pm in part_prefab.Modules) { if (pm.moduleName == m.moduleName) { mFound = true; ModuleResource mResource = pm.resHandler.inputResources.Find(r => r.name == "ElectricCharge"); float? packet_size = Lib.SafeReflectionValue <float>(pm, "RTPacketSize"); float? packet_Interval = Lib.SafeReflectionValue <float>(pm, "RTPacketInterval"); // workaround for old savegames if (mResource == null || packet_size == null || packet_Interval == null) { Lib.DebugLog("Old SaveGame PartModule ModuleRTAntenna for part '{0}' on unloaded vessel '{1}', using default values as a workaround", p.partName, v.vesselName); Lib.DebugLog("ElectricCharge isNull: '{0}', RTPacketSize isNull: '{1}', RTPacketInterval isNull: '{2}'", mResource == null, packet_size == null, packet_Interval == null); rate += 6.6666; // 6.67 Mb/s in 100% factor ec += 0.025; // 25 W/s } else { rate += (float)packet_size / (float)packet_Interval; ec += mResource.rate; } } } if (!mFound) { Lib.DebugLog("Could not find PartModule ModuleRTAntenna for part {0} on unloaded vessel {1}, using default values as a workaround", p.partName, v.vesselName); rate += 6.6666; // 6.67 Mb/s in 100% factor ec += 0.025; // 25 W/s } } } } } } Init(v, powered, storm); }
/// <summary> Returns true if a failure should be triggered. </summary> protected bool IgnitionCheck() { if (!PreferencesReliability.Instance.engineFailures) { return(false); } // don't check for a couple of seconds after the vessel was loaded. // when loading a quicksave with the engines running, the engine state // is off at first which would cost an ignition and possibly trigger a failure if (Time.time < Kerbalism.gameLoadTime + 3) { return(false); } ignitions++; vessel.KerbalismData().ResetReliabilityStatus(); bool fail = false; bool launchpad = vessel.situation == Vessel.Situations.PRELAUNCH || ignitions <= 1 && vessel.situation == Vessel.Situations.LANDED; if (turnon_failure_probability > 0) { // q = quality indicator var q = quality ? Settings.QualityScale : 1.0; if (launchpad) { q /= 2.5; // the very first ignition is more likely to fail } q += Lib.Clamp(ignitions - 1, 0.0, 6.0) / 20.0; // subsequent ignition failures become less and less likely, reducing by up to 30% if (Lib.RandomDouble() < (turnon_failure_probability * PreferencesReliability.Instance.ignitionFailureChance) / q) { fail = true; #if DEBUG_RELIABILITY Lib.DebugLog("Ignition check: " + part.partInfo.title + " ignitions " + ignitions + " turnon failure"); #endif } } // if (rated_ignitions > 0) { int total_ignitions = EffectiveIgnitions(quality, rated_ignitions); if (ignitions >= total_ignitions * 0.9) { needMaintenance = true; } if (ignitions > total_ignitions) { var q = (quality ? Settings.QualityScale : 1.0) * Lib.RandomDouble(); q /= PreferencesReliability.Instance.ignitionFailureChance; q /= (ignitions - total_ignitions); // progressively increase the odds of a failure with every extra ignition #if DEBUG_RELIABILITY Lib.Log("Reliability: ignition exceeded q=" + q + " ignitions=" + ignitions + " total_ignitions=" + total_ignitions); #endif if (q < 0.3) { fail = true; } } } if (fail) { enforce_breakdown = true; explode = Lib.RandomDouble() < 0.1; next = Planetarium.GetUniversalTime() + Lib.RandomDouble() * 2.0; var fuelSystemFailureProbability = 0.1; if (launchpad) { fuelSystemFailureProbability = 0.5; } if (Lib.RandomDouble() < fuelSystemFailureProbability) { // broken fuel line -> delayed kaboom explode = true; next += Lib.RandomDouble() * 10 + 4; FlightLogger.fetch?.LogEvent(part.partInfo.title + " fuel system leak caused destruction of the engine"); } else { FlightLogger.fetch?.LogEvent(part.partInfo.title + " failure on ignition"); } } return(fail); }