public void Recalc(Component c) { if (c is Sink) { Sink sinkComponent = (Sink)c; if (sinkComponent.PipesConnected[0] != null) { if (sinkComponent.PipesConnected[0] is Splitter) { if (sinkComponent.PipesConnected[0] is AdjustableSplitter) { if (sinkComponent.PipesConnected[0].PipesConnected[1] == sinkComponent) { sinkComponent.FlowOnInput = ((AdjustableSplitter)sinkComponent.PipesConnected[0]).FlowOnOutputA; sinkComponent.compFlow = sinkComponent.FlowOnInput; } else if (sinkComponent.PipesConnected[0].PipesConnected[2] == sinkComponent) { sinkComponent.FlowOnInput += ((AdjustableSplitter)sinkComponent.PipesConnected[0]).FlowOnOutputB; sinkComponent.compFlow = sinkComponent.FlowOnInput; } } else if (sinkComponent.PipesConnected[0] is Splitter) { if (sinkComponent.PipesConnected[0].PipesConnected[1] == sinkComponent) { sinkComponent.FlowOnInput = sinkComponent.PipesConnected[0].compFlow - sinkComponent.PipesConnected[1].compFlow / 2; sinkComponent.compFlow = sinkComponent.FlowOnInput; } else if (sinkComponent.PipesConnected[0].PipesConnected[2] == sinkComponent) { sinkComponent.FlowOnInput = sinkComponent.PipesConnected[1].compFlow / 2; sinkComponent.compFlow = sinkComponent.FlowOnInput; } } } else { sinkComponent.FlowOnInput = sinkComponent.PipesConnected[0].compFlow; sinkComponent.compFlow = sinkComponent.FlowOnInput; return; } } } else if (c is Merger) { int tempOldFlowA = 0; int tempOldFlowB = 0; Merger mergerComponent = (Merger)c; if (mergerComponent.PipesConnected[1] != null && mergerComponent.PipesConnected[2] != null) { if (mergerComponent.PipesConnected[1] is AdjustableSplitter) { if (mergerComponent.PipesConnected[1].PipesConnected[1] == mergerComponent) { tempOldFlowA = ((AdjustableSplitter)mergerComponent.PipesConnected[1]).FlowOnOutputA; } else if (mergerComponent.PipesConnected[1].PipesConnected[2] == mergerComponent) { tempOldFlowA = ((AdjustableSplitter)mergerComponent.PipesConnected[1]).FlowOnOutputB; } } else if (mergerComponent.PipesConnected[1] is Splitter) { if (mergerComponent.PipesConnected[1].PipesConnected[1] == mergerComponent) { tempOldFlowA = mergerComponent.PipesConnected[1].compFlow - mergerComponent.PipesConnected[1].compFlow / 2; } else if (mergerComponent.PipesConnected[1].PipesConnected[2] == mergerComponent) { tempOldFlowA = mergerComponent.PipesConnected[1].compFlow / 2; } } ////////////////////////// if (mergerComponent.PipesConnected[2] is AdjustableSplitter) { if (mergerComponent.PipesConnected[2].PipesConnected[1] == mergerComponent) { tempOldFlowB = ((AdjustableSplitter)mergerComponent.PipesConnected[2]).FlowOnOutputA; } else if (mergerComponent.PipesConnected[2].PipesConnected[2] == mergerComponent) { tempOldFlowB = ((AdjustableSplitter)mergerComponent.PipesConnected[2]).FlowOnOutputB; } } else if (mergerComponent.PipesConnected[2] is Splitter) { if (mergerComponent.PipesConnected[2].PipesConnected[1] == mergerComponent) { tempOldFlowB = mergerComponent.PipesConnected[2].compFlow - mergerComponent.PipesConnected[2].compFlow / 2; } else if (mergerComponent.PipesConnected[2].PipesConnected[2] == mergerComponent) { tempOldFlowB = mergerComponent.PipesConnected[2].compFlow / 2; } } if (tempOldFlowA != 0 && tempOldFlowB != 0) { mergerComponent.SumOfFlows = tempOldFlowA + tempOldFlowB; mergerComponent.compFlow = mergerComponent.SumOfFlows; } else if (tempOldFlowA != 0) { mergerComponent.SumOfFlows = tempOldFlowA + mergerComponent.PipesConnected[2].compFlow; mergerComponent.compFlow = mergerComponent.SumOfFlows; } else if (tempOldFlowB != 0) { mergerComponent.SumOfFlows = mergerComponent.PipesConnected[1].compFlow + tempOldFlowB; mergerComponent.compFlow = mergerComponent.SumOfFlows; } else { mergerComponent.SumOfFlows = mergerComponent.PipesConnected[1].compFlow + mergerComponent.PipesConnected[2].compFlow; mergerComponent.compFlow = mergerComponent.SumOfFlows; } } else if (mergerComponent.PipesConnected[1] != null) { if (mergerComponent.PipesConnected[1] is Splitter) { if (mergerComponent.PipesConnected[1] is AdjustableSplitter) { if (mergerComponent.PipesConnected[1].PipesConnected[1] == mergerComponent) { mergerComponent.SumOfFlows = ((AdjustableSplitter)mergerComponent.PipesConnected[1]).FlowOnOutputA; mergerComponent.compFlow = mergerComponent.SumOfFlows; } else if (mergerComponent.PipesConnected[1].PipesConnected[2] == mergerComponent) { mergerComponent.SumOfFlows = ((AdjustableSplitter)mergerComponent.PipesConnected[1]).FlowOnOutputB; mergerComponent.compFlow = mergerComponent.SumOfFlows; } } else if (mergerComponent.PipesConnected[1] is Splitter) { if (mergerComponent.PipesConnected[1].PipesConnected[1] == mergerComponent) { mergerComponent.SumOfFlows = mergerComponent.PipesConnected[1].compFlow - mergerComponent.PipesConnected[1].compFlow / 2; mergerComponent.compFlow = mergerComponent.SumOfFlows; } else if (mergerComponent.PipesConnected[1].PipesConnected[2] == mergerComponent) { mergerComponent.SumOfFlows = mergerComponent.PipesConnected[1].compFlow / 2; mergerComponent.compFlow = mergerComponent.SumOfFlows; } } } else { mergerComponent.SumOfFlows = mergerComponent.PipesConnected[1].compFlow; mergerComponent.compFlow = mergerComponent.SumOfFlows; } } else if (mergerComponent.PipesConnected[2] != null) { if (mergerComponent.PipesConnected[2] is Splitter) { if (mergerComponent.PipesConnected[2] is AdjustableSplitter) { if (mergerComponent.PipesConnected[2].PipesConnected[1] == mergerComponent) { mergerComponent.SumOfFlows = ((AdjustableSplitter)mergerComponent.PipesConnected[2]).FlowOnOutputA; mergerComponent.compFlow = mergerComponent.SumOfFlows; } else if (mergerComponent.PipesConnected[2].PipesConnected[2] == mergerComponent) { mergerComponent.SumOfFlows = ((AdjustableSplitter)mergerComponent.PipesConnected[2]).FlowOnOutputB; mergerComponent.compFlow = mergerComponent.SumOfFlows; } } else if (mergerComponent.PipesConnected[2] is Splitter) { if (mergerComponent.PipesConnected[2].PipesConnected[1] == mergerComponent) { mergerComponent.SumOfFlows = mergerComponent.PipesConnected[2].compFlow - mergerComponent.PipesConnected[2].compFlow / 2; mergerComponent.compFlow = mergerComponent.SumOfFlows; } else if (mergerComponent.PipesConnected[2].PipesConnected[2] == mergerComponent) { mergerComponent.SumOfFlows = mergerComponent.PipesConnected[2].compFlow / 2; mergerComponent.compFlow = mergerComponent.SumOfFlows; } } } else { mergerComponent.SumOfFlows = mergerComponent.PipesConnected[2].compFlow; mergerComponent.compFlow = mergerComponent.SumOfFlows; } } else { mergerComponent.SumOfFlows = 0; mergerComponent.compFlow = mergerComponent.SumOfFlows; } if (mergerComponent.PipesConnected[0] != null) { mergerComponent.PipesConnected[0].compFlow = mergerComponent.SumOfFlows; Recalc(mergerComponent.PipesConnected[0]); } return; } else if (c is AdjustableSplitter) { AdjustableSplitter adjustableSplitterComponent = (AdjustableSplitter)c; if (adjustableSplitterComponent.PipesConnected[0] != null) { if (adjustableSplitterComponent.PipesConnected[0] is AdjustableSplitter) { if (adjustableSplitterComponent.PipesConnected[0].PipesConnected[1] == adjustableSplitterComponent) { adjustableSplitterComponent.InputLevel = ((AdjustableSplitter)adjustableSplitterComponent.PipesConnected[0]).FlowOnOutputA; adjustableSplitterComponent.compFlow = adjustableSplitterComponent.InputLevel; } else if (adjustableSplitterComponent.PipesConnected[0].PipesConnected[2] == adjustableSplitterComponent) { adjustableSplitterComponent.InputLevel = ((AdjustableSplitter)adjustableSplitterComponent.PipesConnected[0]).FlowOnOutputB; adjustableSplitterComponent.compFlow = adjustableSplitterComponent.InputLevel; } } else if (adjustableSplitterComponent.PipesConnected[0] is Splitter) { adjustableSplitterComponent.InputLevel = adjustableSplitterComponent.PipesConnected[0].compFlow / 2; adjustableSplitterComponent.compFlow = adjustableSplitterComponent.InputLevel; } else { adjustableSplitterComponent.InputLevel = adjustableSplitterComponent.PipesConnected[0].compFlow; adjustableSplitterComponent.compFlow = adjustableSplitterComponent.InputLevel; } adjustableSplitterComponent.FlowOnOutputA = adjustableSplitterComponent.compFlow * adjustableSplitterComponent.Proportion / 100; adjustableSplitterComponent.FlowOnOutputB = adjustableSplitterComponent.compFlow - adjustableSplitterComponent.FlowOnOutputA; } else if (adjustableSplitterComponent.PipesConnected[0] == null) { adjustableSplitterComponent.InputLevel = 0; adjustableSplitterComponent.compFlow = adjustableSplitterComponent.InputLevel; } if (adjustableSplitterComponent.PipesConnected[1] != null && adjustableSplitterComponent.PipesConnected[2] != null) { if (adjustableSplitterComponent.InputLevel != 0) { adjustableSplitterComponent.PipesConnected[1].compFlow = adjustableSplitterComponent.InputLevel * adjustableSplitterComponent.Proportion / 100; adjustableSplitterComponent.FlowOnOutputA = adjustableSplitterComponent.PipesConnected[1].compFlow; adjustableSplitterComponent.PipesConnected[2].compFlow = adjustableSplitterComponent.InputLevel - adjustableSplitterComponent.PipesConnected[1].compFlow; adjustableSplitterComponent.FlowOnOutputB = adjustableSplitterComponent.PipesConnected[2].compFlow; Recalc(adjustableSplitterComponent.PipesConnected[1]); Recalc(adjustableSplitterComponent.PipesConnected[2]); } else if (adjustableSplitterComponent.InputLevel == 0) { adjustableSplitterComponent.PipesConnected[1].compFlow = adjustableSplitterComponent.InputLevel; adjustableSplitterComponent.FlowOnOutputA = adjustableSplitterComponent.PipesConnected[1].compFlow; adjustableSplitterComponent.PipesConnected[2].compFlow = adjustableSplitterComponent.InputLevel; adjustableSplitterComponent.FlowOnOutputB = adjustableSplitterComponent.PipesConnected[2].compFlow; Recalc(adjustableSplitterComponent.PipesConnected[1]); Recalc(adjustableSplitterComponent.PipesConnected[2]); } } else if (adjustableSplitterComponent.PipesConnected[1] != null) { adjustableSplitterComponent.PipesConnected[1].compFlow = adjustableSplitterComponent.InputLevel * adjustableSplitterComponent.Proportion / 100; adjustableSplitterComponent.FlowOnOutputA = adjustableSplitterComponent.PipesConnected[1].compFlow; Recalc(adjustableSplitterComponent.PipesConnected[1]); } else if (adjustableSplitterComponent.PipesConnected[2] != null) { adjustableSplitterComponent.PipesConnected[2].compFlow = adjustableSplitterComponent.InputLevel - (adjustableSplitterComponent.InputLevel * adjustableSplitterComponent.Proportion / 100); adjustableSplitterComponent.FlowOnOutputB = adjustableSplitterComponent.PipesConnected[2].compFlow; Recalc(adjustableSplitterComponent.PipesConnected[2]); } return; } else if (c is Splitter) { Splitter splitterComponent = (Splitter)c; if (splitterComponent.PipesConnected[0] != null) { if (splitterComponent.PipesConnected[0] is AdjustableSplitter) { if (splitterComponent.PipesConnected[0].PipesConnected[1] == splitterComponent) { splitterComponent.InputLevel = ((AdjustableSplitter)splitterComponent.PipesConnected[0]).FlowOnOutputA; splitterComponent.compFlow = splitterComponent.InputLevel; } else if (splitterComponent.PipesConnected[0].PipesConnected[2] == splitterComponent) { splitterComponent.InputLevel = ((AdjustableSplitter)splitterComponent.PipesConnected[0]).FlowOnOutputB; splitterComponent.compFlow = splitterComponent.InputLevel; } } else if (splitterComponent.PipesConnected[0] is Splitter) { splitterComponent.InputLevel = splitterComponent.PipesConnected[0].compFlow / 2; splitterComponent.compFlow = splitterComponent.InputLevel; } else { splitterComponent.InputLevel = splitterComponent.PipesConnected[0].compFlow; splitterComponent.compFlow = splitterComponent.InputLevel; } } else if (splitterComponent.PipesConnected[0] == null) { splitterComponent.InputLevel = 0; splitterComponent.compFlow = splitterComponent.InputLevel; } if (splitterComponent.PipesConnected[1] != null && splitterComponent.PipesConnected[2] != null) { if (splitterComponent.InputLevel != 0) { splitterComponent.PipesConnected[1].compFlow = splitterComponent.InputLevel / 2; splitterComponent.PipesConnected[2].compFlow = splitterComponent.InputLevel - splitterComponent.PipesConnected[1].compFlow; Recalc(splitterComponent.PipesConnected[1]); Recalc(splitterComponent.PipesConnected[2]); } else if (splitterComponent.InputLevel == 0) { splitterComponent.PipesConnected[1].compFlow = splitterComponent.InputLevel; splitterComponent.PipesConnected[2].compFlow = splitterComponent.InputLevel; Recalc(splitterComponent.PipesConnected[1]); Recalc(splitterComponent.PipesConnected[2]); } } else if (splitterComponent.PipesConnected[1] != null) { splitterComponent.PipesConnected[1].compFlow = splitterComponent.InputLevel / 2; Recalc(splitterComponent.PipesConnected[1]); } else if (splitterComponent.PipesConnected[2] != null) { splitterComponent.PipesConnected[2].compFlow = splitterComponent.InputLevel / 2; Recalc(splitterComponent.PipesConnected[2]); } return; } if (c is Pump) { Pump pumpComponent = (Pump)c; if (pumpComponent.PipesConnected[0] != null) { pumpComponent.PipesConnected[0].compFlow = pumpComponent.CurrentFlow; Recalc(pumpComponent.PipesConnected[0]); } } }