public static void RemoveProviderValve(ValveBase valveBase) { Logger.LogFormat("==Enter WarpSpaceManager.RemoveProviderValve(valveBase={0})", valveBase); ValveChannels providers = getChannelsForConduitType(valveBase.conduitType); foreach (var channel in providers) { channel.Value.Remove(valveBase); } Logger.Log("==Exit WarpSpaceManager.RemoveProviderValve"); }
public static void RemoveProviderValve(ValveBase valveBase) { Logger.LogFormat("==Enter WarpSpaceManager.RemoveProviderValve(valveBase={0})", valveBase); ValveChannels providers = getChannelsForConduitType(valveBase.conduitType); int totalWarpGates = 0; foreach (var channel in providers) { channel.Value.Remove(valveBase); totalWarpGates += channel.Value.Count; } if (totalWarpGates == 0) { UnregisterConduitUpdate(); } Logger.Log("==Exit WarpSpaceManager.RemoveProviderValve"); }
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 SetProviderValveChannel(ValveBase valveBase, int newChannel) { Logger.LogFormat("==Enter WaprSpaceManager.SetProviderValveChannel(valveBase={0}, valveChannel={1})", valveBase.GetInstanceID(), newChannel); ValveChannels providers = getChannelsForConduitType(valveBase.conduitType); foreach (var item in providers) { if (null != item.Value) { item.Value.Remove(valveBase); } } ValvesList valves; if (!providers.TryGetValue(newChannel, out valves)) { valves = new ValvesList(getFlowManager(valveBase.conduitType)); providers[newChannel] = valves; } valves.Add(valveBase); Logger.Log("==Exit WaprSpaceManager.SetProviderValveChannel"); }
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"); }