diff --git a/GeneralMods/Revitalize/Framework/Managers/LiquidManagerV2.cs b/GeneralMods/Revitalize/Framework/Managers/LiquidManagerV2.cs
new file mode 100644
index 00000000..3c6468b6
--- /dev/null
+++ b/GeneralMods/Revitalize/Framework/Managers/LiquidManagerV2.cs
@@ -0,0 +1,475 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Microsoft.Xna.Framework;
+
+namespace Revitalize.Framework.Managers
+{
+ ///
+ /// A liquid used for various mod purposes.
+ ///
+ public class Liquid
+ {
+ ///
+ /// The name of the liquid.
+ ///
+ public string name;
+ ///
+ /// The color for the liquid.
+ ///
+ public Color color;
+
+ ///
+ /// Constructor.
+ ///
+ public Liquid()
+ {
+
+ }
+
+ ///
+ /// Constructor.
+ ///
+ ///
+ ///
+ public Liquid(string Name, Color LiquidColor)
+ {
+ this.name = Name;
+ this.color = LiquidColor;
+ }
+
+ ///
+ /// Liquid comparison check to see if two liquids are the same.
+ ///
+ ///
+ ///
+ public bool isLiquidHomogenous(Liquid Other)
+ {
+ if (this.name.Equals(Other.name)) return true;
+ return false;
+ }
+
+ ///
+ /// Copys over the liquid.
+ ///
+ ///
+ public Liquid Copy()
+ {
+ return new Liquid(this.name, this.color);
+ }
+ }
+
+ public class MachineLiquidTank
+ {
+ ///
+ /// The liquid inside of the tank.
+ ///
+ public Liquid liquid;
+ ///
+ /// How much liquid is inside the tank currently.
+ ///
+ public int amount;
+ ///
+ /// How much liquid the tank can hold.
+ ///
+ public int capacity;
+
+ ///
+ /// The remaining capacity on the tank.
+ ///
+
+ public int remainingCapacity
+ {
+ get
+ {
+ return this.capacity - this.amount;
+ }
+ }
+
+ ///
+ /// Checks to see if this tank is full.
+ ///
+ public bool IsFull
+ {
+ get
+ {
+ return this.amount == this.capacity;
+ }
+ }
+
+ ///
+ /// Checks if there is fluid inside the tank.
+ ///
+ public bool IsEmpty
+ {
+ get
+ {
+ return this.amount == 0;
+ }
+ }
+ ///
+ /// Constructor.
+ ///
+ public MachineLiquidTank()
+ {
+
+ }
+
+ ///
+ /// Constructor.
+ ///
+ ///
+ public MachineLiquidTank(int Capacity)
+ {
+ this.capacity = Capacity;
+ this.amount = 0;
+ this.liquid = null;
+ }
+
+ ///
+ /// Constructor.
+ ///
+ ///
+ ///
+ ///
+ public MachineLiquidTank(int Capacity, int Amount, Liquid Liquid)
+ {
+ this.capacity = Capacity;
+ this.amount = Amount;
+ this.liquid = Liquid;
+ }
+
+ ///
+ /// Checks to see if this tank can recieve this liquid.
+ ///
+ ///
+ ///
+ public bool CanRecieveThisLiquid(Liquid L)
+ {
+ if (this.IsFull) return false;
+ if (this.liquid == null) return true;
+ if (this.liquid.isLiquidHomogenous(L)) return true;
+ if (this.IsEmpty) return true;
+ else return false;
+ }
+
+ ///
+ /// Takes in liquid into this tank.
+ ///
+ ///
+ ///
+ public void intakeLiquid(Liquid L, int Amount)
+ {
+ if (this.CanRecieveThisLiquid(L))
+ {
+ if (this.liquid == null) this.liquid = L.Copy();
+ else
+ {
+ int intakeAmount=Math.Min(this.remainingCapacity, Amount);
+ this.amount = this.amount + intakeAmount;
+ }
+ }
+ else return;
+ }
+ ///
+ /// Consumes, aka reduces the internal liquid on this tank by the amount given or the amount remaining in the tank.
+ ///
+ ///
+ public void consumeLiquid(int Amount)
+ {
+ if (this.IsEmpty) return;
+ if (this.liquid == null) return;
+ int consumeAmount = Math.Min(this.amount, Amount);
+ this.amount = this.amount - consumeAmount;
+ if (this.amount <= 0) this.liquid = null;
+ }
+
+ ///
+ /// Checks to see if this tank has enough
+ ///
+ ///
+ ///
+ ///
+ public bool DoesThisTankHaveEnoughLiquid(Liquid L, int Amount)
+ {
+ if (this.GetAmountOfLiquidInThisTank(L) >= Amount) return true;
+ return false;
+ }
+
+ ///
+ /// Drains the tank completly
+ ///
+ public void emptyTank()
+ {
+ this.liquid = null;
+ this.amount = 0;
+ }
+
+ ///
+ /// Gets the amount of liquid in this tank for the given liquid.
+ ///
+ ///
+ /// Returns 0 if the tank doesn't contain liquid of the same type. Otherwise returns the amount stored in the tank.
+ public int GetAmountOfLiquidInThisTank(Liquid L)
+ {
+ if (this.liquid == null) return 0;
+ if (this.liquid.isLiquidHomogenous(L)) return this.amount;
+ return 0;
+ }
+
+ ///
+ /// Gets the amount of liquid this take can take in in acordance with the parameter liquid.
+ ///
+ ///
+ ///
+ public int GetAmountOfLiquidThisTankCanReceieve(Liquid L)
+ {
+ if (this.liquid == null) return this.capacity;
+ if (this.liquid.isLiquidHomogenous(L)) return this.remainingCapacity;
+ return 0;
+ }
+
+ ///
+ /// Checks to see if this tank contains this liquid at all.
+ ///
+ ///
+ ///
+ public bool DoesTankContainThisLiquid(Liquid L)
+ {
+ if (this.liquid == null) return false;
+ if (this.liquid.isLiquidHomogenous(L)) return true;
+ return false;
+ }
+
+ }
+ public class LiquidManagerV2
+ {
+ public MachineLiquidTank inputTank1;
+ public MachineLiquidTank inputTank2;
+ public MachineLiquidTank outputTank;
+
+ public bool needsUpdate;
+
+ ///
+ /// Does this machine allow the same fluid in both tanks?
+ ///
+ public bool allowDoubleInput;
+
+ public LiquidManagerV2()
+ {
+ this.inputTank1 = new MachineLiquidTank(0);
+ this.inputTank2 = new MachineLiquidTank(0);
+ this.outputTank = new MachineLiquidTank(0);
+ this.needsUpdate = false;
+ }
+
+ ///
+ /// Constructor.
+ ///
+ ///
+ ///
+ /// Can both input tanks store the same liquid?
+ public LiquidManagerV2(int Capacity, bool OnlyOutput, bool AllowDoubleInput=false)
+ {
+ if (OnlyOutput)
+ {
+ this.outputTank = new MachineLiquidTank(Capacity);
+ this.inputTank1 = new MachineLiquidTank(0);
+ this.inputTank2 = new MachineLiquidTank(0);
+
+ }
+ else
+ {
+ this.outputTank = new MachineLiquidTank(Capacity);
+ this.inputTank1 = new MachineLiquidTank(Capacity);
+ this.inputTank2 = new MachineLiquidTank(Capacity);
+ }
+ this.allowDoubleInput = AllowDoubleInput;
+ this.needsUpdate = false;
+ }
+
+ ///
+ /// Produces a given amount of liquid and puts it into the output tank for this liquid manager.
+ ///
+ ///
+ ///
+ public void produceLiquid(Liquid L, int Amount)
+ {
+ if (this.outputTank.CanRecieveThisLiquid(L))
+ {
+ this.outputTank.intakeLiquid(L, Amount);
+ this.needsUpdate = true;
+ }
+ }
+
+ ///
+ /// Intakes liquid into the input takes on this liquid manager.
+ ///
+ ///
+ ///
+ public void intakeLiquid(Liquid L, int Amount)
+ {
+ int remainingAmount = Amount;
+ if (this.allowDoubleInput)
+ {
+ if (this.inputTank1.CanRecieveThisLiquid(L) && remainingAmount>0)
+ {
+ int allowedAmount = this.inputTank1.remainingCapacity;
+ this.inputTank1.intakeLiquid(L, remainingAmount);
+ remainingAmount -= allowedAmount;
+ }
+ if (this.inputTank2.CanRecieveThisLiquid(L)&& remainingAmount>0)
+ {
+ int allowedAmount = this.inputTank2.remainingCapacity;
+ this.inputTank2.intakeLiquid(L, remainingAmount);
+ remainingAmount -= allowedAmount;
+ }
+ this.needsUpdate = true;
+ }
+ else
+ {
+
+ if (this.inputTank1.CanRecieveThisLiquid(L) && remainingAmount > 0 && this.inputTank2.DoesTankContainThisLiquid(L)==false)
+ {
+ int allowedAmount = this.inputTank1.remainingCapacity;
+ this.inputTank1.intakeLiquid(L, remainingAmount);
+ remainingAmount -= allowedAmount;
+ this.needsUpdate = true;
+ return;
+ }
+ if (this.inputTank2.CanRecieveThisLiquid(L) && remainingAmount > 0 && this.inputTank1.DoesTankContainThisLiquid(L) == false)
+ {
+ int allowedAmount = this.inputTank2.remainingCapacity;
+ this.inputTank2.intakeLiquid(L, remainingAmount);
+ remainingAmount -= allowedAmount;
+ this.needsUpdate = true;
+ return;
+ }
+ }
+
+ }
+
+ ///
+ /// Consumes the liquid in the input tanks. Mainly used for machine processing but shouldn't be drained outwards.
+ ///
+ ///
+ ///
+ public void consumeLiquid(Liquid L, int Amount)
+ {
+ if (this.doTheInputTanksHaveEnoughLiquid(L, Amount) == false) return;
+
+ int requiredAmount = Amount;
+ int tank1Amount = this.inputTank1.GetAmountOfLiquidInThisTank(L);
+ int tank2Amount= this.inputTank2.GetAmountOfLiquidInThisTank(L);
+ if (tank1Amount > 0 && requiredAmount>0)
+ {
+ this.inputTank1.consumeLiquid(requiredAmount);
+ requiredAmount -= tank1Amount;
+ this.needsUpdate = true;
+
+ }
+ if(tank2Amount>0 && requiredAmount > 0)
+ {
+ this.inputTank2.consumeLiquid(requiredAmount);
+ requiredAmount -= tank2Amount;
+ this.needsUpdate = true;
+ }
+ //Consumes liquid from both tanks if double input is enabled. Otherwise it only drains from the appropriate tank.
+ }
+
+ public void drainOutputTank(int Amount)
+ {
+ this.outputTank.consumeLiquid(Amount);
+ if (this.outputTank.IsEmpty) this.outputTank.liquid = null;
+ this.needsUpdate = true;
+ }
+
+ ///
+ /// Checks to see if the input tanks have enough liquid combined to process the request.
+ ///
+ ///
+ ///
+ ///
+ public bool doTheInputTanksHaveEnoughLiquid(Liquid L, int Amount)
+ {
+ int tankTotals = this.inputTank1.GetAmountOfLiquidInThisTank(L) + this.inputTank2.GetAmountOfLiquidInThisTank(L);
+ if (tankTotals >= Amount) return true;
+ else return false;
+ }
+
+ ///
+ /// Gets the total amount of liquid that the input tanks can recieve
+ ///
+ ///
+ ///
+ public int getMaxAmountOfLiquidIntakePossible(Liquid L)
+ {
+
+ if (this.allowDoubleInput)
+ {
+ int amount = 0;
+ amount += this.inputTank1.GetAmountOfLiquidThisTankCanReceieve(L);
+ amount += this.inputTank2.GetAmountOfLiquidThisTankCanReceieve(L);
+ }
+ else
+ {
+ if(this.inputTank1.CanRecieveThisLiquid(L) && this.inputTank2.DoesTankContainThisLiquid(L) == false)
+ {
+ return this.inputTank1.GetAmountOfLiquidThisTankCanReceieve(L);
+ }
+ if (this.inputTank1.CanRecieveThisLiquid(L) && this.inputTank2.DoesTankContainThisLiquid(L) == false)
+ {
+ return this.inputTank2.GetAmountOfLiquidThisTankCanReceieve(L);
+ }
+ }
+ return 0;
+ }
+
+ ///
+ /// Checks to see if the input tanks on this liquid manager have the capacity to take in this liquid at all.
+ ///
+ ///
+ ///
+ public bool canRecieveThisLiquid(Liquid L)
+ {
+ if (L == null) return false;
+ if (this.allowDoubleInput)
+ {
+ if (this.inputTank1.CanRecieveThisLiquid(L) || this.inputTank2.CanRecieveThisLiquid(L))
+ {
+ return true;
+ }
+ }
+ else
+ {
+ if (this.inputTank1.CanRecieveThisLiquid(L) && this.inputTank2.DoesTankContainThisLiquid(L) == false)
+ {
+ return false;
+ }
+ if (this.inputTank2.CanRecieveThisLiquid(L) && this.inputTank1.DoesTankContainThisLiquid(L) == false)
+ {
+ return true;
+ }
+ }
+ return false;
+
+ }
+
+ ///
+ /// Takes the fluid in this output tank and tries to transfer it to another liquid manager who has an tank available.
+ ///
+ ///
+ public void outputLiquidToOtherSources(LiquidManagerV2 Other)
+ {
+ if (this.outputTank.liquid == null) return;
+ if (Other.canRecieveThisLiquid(this.outputTank.liquid))
+ {
+ int actualAmount = Math.Min(this.outputTank.amount, Other.getMaxAmountOfLiquidIntakePossible(this.outputTank.liquid));
+ Other.intakeLiquid(this.outputTank.liquid,actualAmount);
+ this.drainOutputTank(actualAmount);
+ }
+ }
+ }
+}
diff --git a/GeneralMods/Revitalize/Framework/Utilities/LiquidManager.cs b/GeneralMods/Revitalize/Framework/Utilities/LiquidManager.cs
deleted file mode 100644
index 290ba787..00000000
--- a/GeneralMods/Revitalize/Framework/Utilities/LiquidManager.cs
+++ /dev/null
@@ -1,321 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using Microsoft.Xna.Framework;
-
-namespace Revitalize.Framework.Utilities
-{
- public class Liquid
- {
- public string name;
- public Color liquidColor;
- public int amount;
- public int capacity;
-
- public string liquidDisplayString
- {
- get
- {
- StringBuilder b = new StringBuilder();
- b.Append(this.amount);
- b.Append("/");
- b.Append(this.capacity);
- return b.ToString();
- }
- }
-
- public int capacityRemaining
- {
- get
- {
- return this.capacity - this.amount;
- }
- }
-
- ///
- /// Returns the energy remaining as a percent value.
- ///
- public double liquidPercentRemaining
- {
- get
- {
- return (double)this.amount / (double)this.capacity;
- }
- }
-
- public bool IsEmpty
- {
- get
- {
- return this.amount == 0;
- }
- }
-
- public bool IsFull
- {
- get
- {
- return this.amount == this.capacity;
- }
- }
-
-
- public Liquid()
- {
-
- }
-
- public Liquid(string Name, Color liquidColor, int Capacity)
- {
- this.name = Name;
- this.liquidColor = liquidColor;
- this.capacity = Capacity;
- }
-
- public Liquid(string Name, Color liquidColor, int Amount, int Capacity)
- {
- this.name = Name;
- this.liquidColor = liquidColor;
- this.capacity = Capacity;
- this.amount = Amount;
- }
-
- public void produceLiquid(int amount)
- {
- this.amount = Math.Min(this.capacity, this.amount + amount);
- }
-
- public void consumeLiquid(int amount)
- {
- this.amount = Math.Max(0, this.amount - amount);
- }
-
-
- ///
- /// Checks to see if this energy source has enough energy remaining.
- ///
- ///
- ///
- public bool hasEnoughLiquid(int Required)
- {
- return this.amount >= Required;
- }
-
- public Liquid Copy()
- {
- return new Liquid(this.name, this.liquidColor, 0, this.capacity);
- }
- }
-
- public class LiquidManager
- {
-
-
-
- public bool requiresUpdate;
- ///
- /// How does this energy manager interface energy systems.
- ///
- public Enums.LiquidInteractionType liquidInteractionType;
-
- ///
- /// Checks to see if this energy manager consumes energy.
- ///
- public bool consumesLiquid
- {
- get
- {
- return this.liquidInteractionType == Enums.LiquidInteractionType.Consumes;
- }
- }
- ///
- /// Checks to see if this energy manager produces energy.
- ///
- public bool producesLiquid
- {
- get
- {
- return this.liquidInteractionType == Enums.LiquidInteractionType.Produces;
- }
- }
-
- ///
- /// Checks to see if this energy manager transfers energy.
- ///
- public bool transfersLiquid
- {
- get
- {
- return this.liquidInteractionType == Enums.LiquidInteractionType.Transfers;
- }
- }
-
- public int MaxPossibleAmountOfLiquids;
- public Dictionary liquids;
- public List acceptedLiquid;
-
- public LiquidManager()
- {
-
- }
-
- public LiquidManager(Enums.LiquidInteractionType LiquidType) : this(1, LiquidType)
- {
- }
-
- public LiquidManager(int NumberOfPossibleFluids, Enums.LiquidInteractionType liquidInteractionType)
- {
- this.liquidInteractionType = liquidInteractionType;
- this.MaxPossibleAmountOfLiquids = NumberOfPossibleFluids;
- this.liquids = new Dictionary();
- }
-
-
- public void consumeLiquid(int amount, string LiquidName)
- {
-
- this.GetLiquid(LiquidName, out Liquid selfLiquid);
- if (selfLiquid == null) return;
-
- selfLiquid.consumeLiquid(amount);
- this.requiresUpdate = true;
- if (selfLiquid.IsEmpty)
- {
- this.liquids.Remove(selfLiquid.name);
- }
- }
-
- public void produceLiquid(int amount, string LiquidName,Liquid L)
- {
- this.GetLiquid(LiquidName, out Liquid selfLiquid);
- if (selfLiquid == null)
- {
- this.AddLiquid(L);
- this.GetLiquid(LiquidName, out Liquid selfLiquid2);
- selfLiquid2.produceLiquid(amount);
- this.requiresUpdate = true;
- return;
- }
-
- selfLiquid.produceLiquid(amount);
- this.requiresUpdate = true;
- }
-
- public void AddLiquid(Liquid M)
- {
- if (this.liquids.ContainsKey(M.name))
- {
- this.liquids[M.name].produceLiquid(M.amount);
- this.requiresUpdate = true;
- }
- else
- {
- if (this.canReceieveThisLiquid(M))
- {
- this.liquids.Add(M.name, M);
- }
- }
- }
-
- public void GetLiquid(string Name, out Liquid Liquid)
- {
- Liquid = new Liquid();
- if (this.liquids.ContainsKey(Name))
- {
- this.liquids.TryGetValue(Name, out Liquid);
- }
- }
-
- public void transferLiquidFromAnother(LiquidManager other, string LiquidName, int amount)
- {
- other.GetLiquid(LiquidName, out Liquid OtherLiquid);
- if (OtherLiquid == null) return;
- if (this.canReceieveThisLiquid(OtherLiquid))
- {
- int actualAmount = Math.Min(amount, OtherLiquid.amount);
-
- this.GetLiquid(LiquidName, out Liquid SelfLiquid);
-
- int selfCapacity = SelfLiquid!=null? SelfLiquid.capacityRemaining:OtherLiquid.amount;
- this.produceLiquid(actualAmount, OtherLiquid.name,OtherLiquid.Copy());
- other.consumeLiquid(Math.Min(actualAmount, selfCapacity),OtherLiquid.name);
- }
- else
- {
- return;
- }
- }
-
- public void transferLiquidToAnother(LiquidManager other, string LiquidName, int amount)
- {
- this.GetLiquid(LiquidName, out Liquid SelfLiquid);
- if (SelfLiquid == null) return;
- if (other.canReceieveThisLiquid(SelfLiquid))
- {
- int actualAmount = Math.Min(amount, SelfLiquid.amount);
-
- this.GetLiquid(LiquidName, out Liquid OtherLiquid);
- int selfCapacity =OtherLiquid != null ? OtherLiquid.capacityRemaining : SelfLiquid.amount;
-
- other.produceLiquid(Math.Min(actualAmount, selfCapacity), SelfLiquid.name,SelfLiquid.Copy());
- this.consumeLiquid(Math.Min(actualAmount, selfCapacity),SelfLiquid.name);
- }
- else
- {
- return;
- }
- }
-
- public LiquidManager Copy()
- {
- return new LiquidManager(this.MaxPossibleAmountOfLiquids, this.liquidInteractionType);
- }
-
- public bool canReceieveThisLiquid(Liquid M)
- {
- if (M == null) return false;
- if (this.liquids.Count < this.MaxPossibleAmountOfLiquids) return true;
- if (this.liquids.Values.ToList().FindAll(L => L.name == M.name).Count > 0) return true;
- if (this.acceptedLiquid.FindAll(L => L.name == M.name).Count > 0) return true;
-
- return false;
- }
-
- public bool hasLiquid(string Name)
- {
- if (this.liquids.ContainsKey(Name))
- {
- return true;
- }
- else return false;
- }
-
- public bool doesLiquidHaveVolume(string Name)
- {
- if (this.liquids.ContainsKey(Name))
- {
- if (this.liquids[Name].amount > 0) return true;
- return false;
- }
- else return false;
- }
-
- public bool doesLiquidHaveEnough(string LiquidName,int Amount)
- {
- this.GetLiquid(LiquidName, out Liquid selfLiquid);
- if (selfLiquid == null) return false;
- if (selfLiquid.amount >= Amount) return true;
- else return false;
- }
-
- public bool canThisLiquidReceiveMoreVolume(string LiquidName, int Amount)
- {
- this.GetLiquid(LiquidName, out Liquid selfLiquid);
- if (selfLiquid == null) return false;
- if (selfLiquid.IsFull) return false;
- else return true;
- }
-
- }
-}
diff --git a/GeneralMods/Revitalize/Revitalize.csproj b/GeneralMods/Revitalize/Revitalize.csproj
index fed97860..5064cbbf 100644
--- a/GeneralMods/Revitalize/Revitalize.csproj
+++ b/GeneralMods/Revitalize/Revitalize.csproj
@@ -88,6 +88,7 @@
+
@@ -183,7 +184,6 @@
-