/* * Shift the water */ public virtual WaterObject OnFlow(WaterObject inflow) { if (inflow == null) { WaterObject myWater = null; if (this.Water != null) { myWater = this.Water.Copy(); } this.Water = null; return(myWater); } if (this.Water == null) { this.Water = inflow.Copy(); return(null); } WaterObject cpy = this.Water.Copy(); this.Water = inflow.Copy(); return(cpy); }
/// <summary> /// Makes time move (tick) forward for the modules. Ticking time forward allows for the water to flow through /// the system. /// </summary> public List <WaterObject> TickModules() { List <WaterObject> waterLeaving = new List <WaterObject>(); // Flow water through the reservoir, to start flow through everything else try { for (int i = 0; i < MapCapacity; i++) { this.Reservoir.Tick(); WaterObject water = this.Reservoir.OnFlow(new WaterObject()); var currentModule = this.Reservoir.NextModule; while (currentModule != null) { currentModule.Tick(); water = currentModule.OnFlow(water); currentModule = currentModule.NextModule; } if (water != null) { waterLeaving.Add(water.Copy()); // Add the water that came from the last module } } } catch (Exception e) { } return(waterLeaving); }
// Fill the reservoir public override WaterObject OnFlow(WaterObject inflow) { if (inflow != null) { Water.Enqueue(inflow.Copy()); } if (this.IsEmpty || this.DrainBroken) { return(null); } return(Water.Dequeue()); }