private static bool Prefix(ValveBase __instance, float dt, int ___inputCell, int ___outputCell) { if (__instance.conduitType != LiquidWarpConfig.CONDUIT_TYPE && __instance.conduitType != GasWarpConfig.CONDUIT_TYPE) { return(true); } int channelNo = Mathf.RoundToInt(__instance.CurrentFlow * 1000.0f); // simple cast to int sometimes gives invalid result Logger.LogFormat(" === ValveBase.ConduitUpdate({0}) Prefix conduitType={1}, inputCell={2}, outputCell={3}, channelNo={4}", dt, __instance.conduitType, ___inputCell, ___outputCell, channelNo); if (channelNo == 10000) { // Channel number is set to MaxFlow (10k), which means WarpGate is disabled return(false); } ConduitFlow flowManager = null; if (__instance.conduitType == LiquidWarpConfig.CONDUIT_TYPE) { flowManager = Conduit.GetFlowManager(ConduitType.Liquid); } else if (__instance.conduitType == GasWarpConfig.CONDUIT_TYPE) { flowManager = Conduit.GetFlowManager(ConduitType.Gas); } if (!flowManager.HasConduit(___inputCell) || !flowManager.HasConduit(___outputCell)) { __instance.UpdateAnim(); } if (flowManager.HasConduit(___outputCell) && !flowManager.IsConduitFull(___outputCell)) { WarpSpaceManager.RequestFluidFromChannel(__instance, channelNo); __instance.UpdateAnim(); return(false); } return(false); }
private static void UpdateConduitsOfWarpGates(float dt, ConduitType warpGateType) { try { ConduitFlow flowManager = getFlowManager(warpGateType); if (flowManager == null) { Logger.Log("unable to determine correct ConduitType."); return; } ValveChannels channels = getChannelsForConduitType(warpGateType); foreach (KeyValuePair <int, ValvesList> warpChannel in channels) { if (warpChannel.Key == 10000) { continue; } var warpValves = warpChannel.Value; var startRequestor = warpValves.getCurrentRequestor(); if (startRequestor == null) { continue; } do { int destinationCell = warpValves.getCurrentRequestor().GetOutputCell(); if (!flowManager.IsConduitFull(destinationCell) && !RequestFluid(warpValves)) { break; } warpValves.getNextRequestor(); } while (startRequestor != warpValves.getCurrentRequestor()); } } catch (Exception ex) { Logger.LogFormat("Exception in WarpSpaceManager.UpdateConduitsOfWarpGates: {0}\n{1}", ex.Message, ex.StackTrace); } }
public static void RequestFluidFromChannel(ValveBase requestor, int channelNo) { Logger.LogFormat("==Entry WarpSpaceManager.RequestFluidFromChannel(requestor={0}, channelNo={1})", requestor.GetInstanceID(), channelNo); try { ConduitFlow flowManager = null; if (requestor.conduitType == LiquidWarpConfig.CONDUIT_TYPE) { flowManager = Conduit.GetFlowManager(ConduitType.Liquid); } else if (requestor.conduitType == GasWarpConfig.CONDUIT_TYPE) { flowManager = Conduit.GetFlowManager(ConduitType.Gas); } else { Logger.Log("unable to determine correct ConduitType."); return; } ValveChannels channels = getChannelsForConduitType(requestor.conduitType); ValvesList providers; if (!channels.TryGetValue(channelNo, out providers) || (providers.Count == 0)) { Logger.LogFormat("No providers for channel {0} found.", channelNo); return; } ValveBase provider = providers.getNext(); ValveBase start = provider; if (null == provider) { Logger.Log("You should never see this message! provider is null"); return; } int toCell = (int)valveBaseOutputCellFieldInfo.GetValue(requestor); ConduitFlow.ConduitContents requestorContents = flowManager.GetContents(toCell); // Fill input cell from various providers, in case when provider's conduit is not full do { Logger.LogFormat("Trying to request from valveBase {0}", provider.GetInstanceID()); int fromCell = (int)valveBaseInputCellFieldInfo.GetValue(provider); if (provider != requestor && flowManager.HasConduit(fromCell)) { ConduitFlow.ConduitContents providerContents = flowManager.GetContents(fromCell); float addedMass = flowManager.AddElement(toCell, providerContents.element, providerContents.mass, providerContents.temperature, providerContents.diseaseIdx, providerContents.diseaseCount); Game.Instance.accumulators.Accumulate(provider.AccumulatorHandle, addedMass); if (addedMass > 0f) { Logger.LogFormat("Adding Element to cell: requestor={0} provider={1} actually added mass={2}, element type={3}", requestor.GetInstanceID(), provider.GetInstanceID(), addedMass, providerContents.element); flowManager.RemoveElement(fromCell, addedMass); Game.Instance.accumulators.Accumulate(requestor.AccumulatorHandle, addedMass); } } if (flowManager.IsConduitFull(toCell)) { break; } provider = providers.getNext(); } while (provider != start); } catch (Exception ex) { Logger.LogFormat("Exception in WarpSpaceManager.RequestFluidFromChannel: {0}\n{1}", ex.Message, ex.StackTrace); } Logger.Log("==Exit WarpSpaceManager.RequestFluidFromChannel"); }