2019-09-23 07:58:56 +08:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Text;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using Microsoft.Xna.Framework;
|
|
|
|
|
|
|
|
namespace Revitalize.Framework.Managers
|
|
|
|
{
|
|
|
|
/// <summary>
|
2019-09-24 08:33:28 +08:00
|
|
|
/// A Fluid used for various mod purposes.
|
2019-09-23 07:58:56 +08:00
|
|
|
/// </summary>
|
2019-09-24 08:33:28 +08:00
|
|
|
public class Fluid
|
2019-09-23 07:58:56 +08:00
|
|
|
{
|
|
|
|
/// <summary>
|
2019-09-24 08:33:28 +08:00
|
|
|
/// The name of the Fluid.
|
2019-09-23 07:58:56 +08:00
|
|
|
/// </summary>
|
|
|
|
public string name;
|
|
|
|
/// <summary>
|
2019-09-24 08:33:28 +08:00
|
|
|
/// The color for the Fluid.
|
2019-09-23 07:58:56 +08:00
|
|
|
/// </summary>
|
|
|
|
public Color color;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Constructor.
|
|
|
|
/// </summary>
|
2019-09-24 08:33:28 +08:00
|
|
|
public Fluid()
|
2019-09-23 07:58:56 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Constructor.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="Name"></param>
|
2019-09-24 08:33:28 +08:00
|
|
|
/// <param name="FluidColor"></param>
|
|
|
|
public Fluid(string Name, Color FluidColor)
|
2019-09-23 07:58:56 +08:00
|
|
|
{
|
|
|
|
this.name = Name;
|
2019-09-24 08:33:28 +08:00
|
|
|
this.color = FluidColor;
|
2019-09-23 07:58:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
2019-09-24 08:33:28 +08:00
|
|
|
/// Fluid comparison check to see if two Fluids are the same.
|
2019-09-23 07:58:56 +08:00
|
|
|
/// </summary>
|
|
|
|
/// <param name="Other"></param>
|
|
|
|
/// <returns></returns>
|
2019-09-24 08:33:28 +08:00
|
|
|
public bool isFluidHomogenous(Fluid Other)
|
2019-09-23 07:58:56 +08:00
|
|
|
{
|
|
|
|
if (this.name.Equals(Other.name)) return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
2019-09-24 08:33:28 +08:00
|
|
|
/// Copys over the Fluid.
|
2019-09-23 07:58:56 +08:00
|
|
|
/// </summary>
|
|
|
|
/// <returns></returns>
|
2019-09-24 08:33:28 +08:00
|
|
|
public Fluid Copy()
|
2019-09-23 07:58:56 +08:00
|
|
|
{
|
2019-09-24 08:33:28 +08:00
|
|
|
return new Fluid(this.name, this.color);
|
2019-09-23 07:58:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-24 08:33:28 +08:00
|
|
|
public class MachineFluidTank
|
2019-09-23 07:58:56 +08:00
|
|
|
{
|
|
|
|
/// <summary>
|
2019-09-24 08:33:28 +08:00
|
|
|
/// The Fluid inside of the tank.
|
2019-09-23 07:58:56 +08:00
|
|
|
/// </summary>
|
2019-09-24 08:33:28 +08:00
|
|
|
public Fluid fluid;
|
2019-09-23 07:58:56 +08:00
|
|
|
/// <summary>
|
2019-09-24 08:33:28 +08:00
|
|
|
/// How much Fluid is inside the tank currently.
|
2019-09-23 07:58:56 +08:00
|
|
|
/// </summary>
|
|
|
|
public int amount;
|
|
|
|
/// <summary>
|
2019-09-24 08:33:28 +08:00
|
|
|
/// How much Fluid the tank can hold.
|
2019-09-23 07:58:56 +08:00
|
|
|
/// </summary>
|
|
|
|
public int capacity;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// The remaining capacity on the tank.
|
|
|
|
/// </summary>
|
2019-09-25 06:18:57 +08:00
|
|
|
|
2019-09-23 07:58:56 +08:00
|
|
|
public int remainingCapacity
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return this.capacity - this.amount;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Checks to see if this tank is full.
|
|
|
|
/// </summary>
|
|
|
|
public bool IsFull
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return this.amount == this.capacity;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Checks if there is fluid inside the tank.
|
|
|
|
/// </summary>
|
|
|
|
public bool IsEmpty
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return this.amount == 0;
|
|
|
|
}
|
|
|
|
}
|
2019-09-25 06:18:57 +08:00
|
|
|
|
|
|
|
public string getFluidDisplayString()
|
|
|
|
{
|
|
|
|
StringBuilder b = new StringBuilder();
|
|
|
|
if (this.fluid != null)
|
|
|
|
{
|
|
|
|
b.Append(this.fluid.name);
|
|
|
|
b.Append(": ");
|
|
|
|
}
|
|
|
|
b.Append(this.amount);
|
|
|
|
b.Append("/");
|
|
|
|
b.Append(this.capacity);
|
|
|
|
return b.ToString();
|
|
|
|
}
|
|
|
|
|
2019-09-23 07:58:56 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Constructor.
|
|
|
|
/// </summary>
|
2019-09-24 08:33:28 +08:00
|
|
|
public MachineFluidTank()
|
2019-09-23 07:58:56 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Constructor.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="Capacity"></param>
|
2019-09-24 08:33:28 +08:00
|
|
|
public MachineFluidTank(int Capacity)
|
2019-09-23 07:58:56 +08:00
|
|
|
{
|
|
|
|
this.capacity = Capacity;
|
|
|
|
this.amount = 0;
|
2019-09-24 08:33:28 +08:00
|
|
|
this.fluid = null;
|
2019-09-23 07:58:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Constructor.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="Capacity"></param>
|
|
|
|
/// <param name="Amount"></param>
|
2019-09-24 08:33:28 +08:00
|
|
|
/// <param name="Fluid"></param>
|
|
|
|
public MachineFluidTank(int Capacity, int Amount, Fluid Fluid)
|
2019-09-23 07:58:56 +08:00
|
|
|
{
|
|
|
|
this.capacity = Capacity;
|
|
|
|
this.amount = Amount;
|
2019-09-24 08:33:28 +08:00
|
|
|
this.fluid = Fluid;
|
2019-09-23 07:58:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
2019-09-24 08:33:28 +08:00
|
|
|
/// Checks to see if this tank can recieve this Fluid.
|
2019-09-23 07:58:56 +08:00
|
|
|
/// </summary>
|
|
|
|
/// <param name="L"></param>
|
|
|
|
/// <returns></returns>
|
2019-09-24 08:33:28 +08:00
|
|
|
public bool CanRecieveThisFluid(Fluid L)
|
2019-09-23 07:58:56 +08:00
|
|
|
{
|
|
|
|
if (this.IsFull) return false;
|
2019-09-24 08:33:28 +08:00
|
|
|
if (this.fluid == null) return true;
|
|
|
|
if (this.fluid.isFluidHomogenous(L)) return true;
|
2019-09-23 07:58:56 +08:00
|
|
|
if (this.IsEmpty) return true;
|
|
|
|
else return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
2019-09-24 08:33:28 +08:00
|
|
|
/// Takes in Fluid into this tank.
|
2019-09-23 07:58:56 +08:00
|
|
|
/// </summary>
|
|
|
|
/// <param name="L"></param>
|
|
|
|
/// <param name="Amount"></param>
|
2019-09-24 08:33:28 +08:00
|
|
|
public void intakeFluid(Fluid L, int Amount)
|
2019-09-23 07:58:56 +08:00
|
|
|
{
|
2019-09-24 08:33:28 +08:00
|
|
|
if (this.CanRecieveThisFluid(L))
|
2019-09-23 07:58:56 +08:00
|
|
|
{
|
2019-09-24 08:33:28 +08:00
|
|
|
if (this.fluid == null) this.fluid = L.Copy();
|
2019-09-25 06:18:57 +08:00
|
|
|
int intakeAmount = Math.Min(this.remainingCapacity, Amount);
|
|
|
|
this.amount = this.amount + intakeAmount;
|
|
|
|
|
2019-09-23 07:58:56 +08:00
|
|
|
}
|
|
|
|
else return;
|
|
|
|
}
|
|
|
|
/// <summary>
|
2019-09-24 08:33:28 +08:00
|
|
|
/// Consumes, aka reduces the internal Fluid on this tank by the amount given or the amount remaining in the tank.
|
2019-09-23 07:58:56 +08:00
|
|
|
/// </summary>
|
|
|
|
/// <param name="Amount"></param>
|
2019-09-24 08:33:28 +08:00
|
|
|
public void consumeFluid(int Amount)
|
2019-09-23 07:58:56 +08:00
|
|
|
{
|
|
|
|
if (this.IsEmpty) return;
|
2019-09-24 08:33:28 +08:00
|
|
|
if (this.fluid == null) return;
|
2019-09-23 07:58:56 +08:00
|
|
|
int consumeAmount = Math.Min(this.amount, Amount);
|
|
|
|
this.amount = this.amount - consumeAmount;
|
2019-09-24 08:33:28 +08:00
|
|
|
if (this.amount <= 0) this.fluid = null;
|
2019-09-23 07:58:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Checks to see if this tank has enough
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="L"></param>
|
|
|
|
/// <param name="Amount"></param>
|
|
|
|
/// <returns></returns>
|
2019-09-24 08:33:28 +08:00
|
|
|
public bool DoesThisTankHaveEnoughFluid(Fluid L, int Amount)
|
2019-09-23 07:58:56 +08:00
|
|
|
{
|
2019-09-24 08:33:28 +08:00
|
|
|
if (this.GetAmountOfFluidInThisTank(L) >= Amount) return true;
|
2019-09-23 07:58:56 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Drains the tank completly
|
|
|
|
/// </summary>
|
|
|
|
public void emptyTank()
|
|
|
|
{
|
2019-09-24 08:33:28 +08:00
|
|
|
this.fluid = null;
|
2019-09-23 07:58:56 +08:00
|
|
|
this.amount = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
2019-09-24 08:33:28 +08:00
|
|
|
/// Gets the amount of Fluid in this tank for the given Fluid.
|
2019-09-23 07:58:56 +08:00
|
|
|
/// </summary>
|
|
|
|
/// <param name="L"></param>
|
2019-09-24 08:33:28 +08:00
|
|
|
/// <returns> Returns 0 if the tank doesn't contain Fluid of the same type. Otherwise returns the amount stored in the tank.</returns>
|
|
|
|
public int GetAmountOfFluidInThisTank(Fluid L)
|
2019-09-23 07:58:56 +08:00
|
|
|
{
|
2019-09-24 08:33:28 +08:00
|
|
|
if (this.fluid == null) return 0;
|
|
|
|
if (this.fluid.isFluidHomogenous(L)) return this.amount;
|
2019-09-23 07:58:56 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
2019-09-24 08:33:28 +08:00
|
|
|
/// Gets the amount of Fluid this take can take in in acordance with the parameter Fluid.
|
2019-09-23 07:58:56 +08:00
|
|
|
/// </summary>
|
|
|
|
/// <param name="L"></param>
|
|
|
|
/// <returns></returns>
|
2019-09-24 08:33:28 +08:00
|
|
|
public int GetAmountOfFluidThisTankCanReceieve(Fluid L)
|
2019-09-23 07:58:56 +08:00
|
|
|
{
|
2019-09-24 08:33:28 +08:00
|
|
|
if (this.fluid == null) return this.capacity;
|
|
|
|
if (this.fluid.isFluidHomogenous(L)) return this.remainingCapacity;
|
2019-09-23 07:58:56 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
2019-09-24 08:33:28 +08:00
|
|
|
/// Checks to see if this tank contains this Fluid at all.
|
2019-09-23 07:58:56 +08:00
|
|
|
/// </summary>
|
|
|
|
/// <param name="L"></param>
|
|
|
|
/// <returns></returns>
|
2019-09-24 08:33:28 +08:00
|
|
|
public bool DoesTankContainThisFluid(Fluid L)
|
2019-09-23 07:58:56 +08:00
|
|
|
{
|
2019-09-24 08:33:28 +08:00
|
|
|
if (this.fluid == null) return false;
|
|
|
|
if (this.fluid.isFluidHomogenous(L)) return true;
|
2019-09-23 07:58:56 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2019-09-24 08:33:28 +08:00
|
|
|
public class FluidManagerV2
|
2019-09-23 07:58:56 +08:00
|
|
|
{
|
2019-09-24 08:33:28 +08:00
|
|
|
public MachineFluidTank inputTank1;
|
|
|
|
public MachineFluidTank inputTank2;
|
|
|
|
public MachineFluidTank outputTank;
|
2019-09-23 07:58:56 +08:00
|
|
|
|
2019-09-24 09:13:45 +08:00
|
|
|
public bool requiresUpdate;
|
2019-09-23 07:58:56 +08:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Does this machine allow the same fluid in both tanks?
|
|
|
|
/// </summary>
|
|
|
|
public bool allowDoubleInput;
|
|
|
|
|
2019-09-24 09:13:45 +08:00
|
|
|
public bool onlyOutput;
|
|
|
|
/// <summary>
|
|
|
|
/// The capacity for the fluid tanks.
|
|
|
|
/// </summary>
|
|
|
|
public int tankCapacity;
|
|
|
|
|
|
|
|
public Enums.FluidInteractionType fluidInteractionType;
|
|
|
|
|
|
|
|
public bool InteractsWithFluids
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return this.fluidInteractionType != Enums.FluidInteractionType.None;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-24 08:33:28 +08:00
|
|
|
public FluidManagerV2()
|
2019-09-23 07:58:56 +08:00
|
|
|
{
|
2019-09-24 08:33:28 +08:00
|
|
|
this.inputTank1 = new MachineFluidTank(0);
|
|
|
|
this.inputTank2 = new MachineFluidTank(0);
|
|
|
|
this.outputTank = new MachineFluidTank(0);
|
2019-09-24 09:13:45 +08:00
|
|
|
this.requiresUpdate = false;
|
|
|
|
this.fluidInteractionType = Enums.FluidInteractionType.None;
|
2019-09-23 07:58:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Constructor.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="Capacity"></param>
|
|
|
|
/// <param name="OnlyOutput"></param>
|
2019-09-24 08:33:28 +08:00
|
|
|
/// <param name="AllowDoubleInput">Can both input tanks store the same Fluid?</param>
|
2019-09-25 06:18:57 +08:00
|
|
|
public FluidManagerV2(int Capacity, bool OnlyOutput, Enums.FluidInteractionType LiquidInteractionType, bool AllowDoubleInput = false)
|
2019-09-23 07:58:56 +08:00
|
|
|
{
|
|
|
|
if (OnlyOutput)
|
|
|
|
{
|
2019-09-24 08:33:28 +08:00
|
|
|
this.outputTank = new MachineFluidTank(Capacity);
|
|
|
|
this.inputTank1 = new MachineFluidTank(0);
|
|
|
|
this.inputTank2 = new MachineFluidTank(0);
|
2019-09-23 07:58:56 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-09-24 08:33:28 +08:00
|
|
|
this.outputTank = new MachineFluidTank(Capacity);
|
|
|
|
this.inputTank1 = new MachineFluidTank(Capacity);
|
|
|
|
this.inputTank2 = new MachineFluidTank(Capacity);
|
2019-09-23 07:58:56 +08:00
|
|
|
}
|
2019-09-24 09:13:45 +08:00
|
|
|
this.onlyOutput = OnlyOutput;
|
2019-09-23 07:58:56 +08:00
|
|
|
this.allowDoubleInput = AllowDoubleInput;
|
2019-09-24 09:13:45 +08:00
|
|
|
this.requiresUpdate = false;
|
|
|
|
this.fluidInteractionType = LiquidInteractionType;
|
2019-09-23 07:58:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
2019-09-24 08:33:28 +08:00
|
|
|
/// Produces a given amount of Fluid and puts it into the output tank for this Fluid manager.
|
2019-09-23 07:58:56 +08:00
|
|
|
/// </summary>
|
|
|
|
/// <param name="L"></param>
|
|
|
|
/// <param name="Amount"></param>
|
2019-09-24 08:33:28 +08:00
|
|
|
public void produceFluid(Fluid L, int Amount)
|
2019-09-23 07:58:56 +08:00
|
|
|
{
|
2019-09-24 08:33:28 +08:00
|
|
|
if (this.outputTank.CanRecieveThisFluid(L))
|
2019-09-23 07:58:56 +08:00
|
|
|
{
|
2019-09-24 08:33:28 +08:00
|
|
|
this.outputTank.intakeFluid(L, Amount);
|
2019-09-24 09:13:45 +08:00
|
|
|
this.requiresUpdate = true;
|
2019-09-23 07:58:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
2019-09-24 08:33:28 +08:00
|
|
|
/// Intakes Fluid into the input takes on this Fluid manager.
|
2019-09-23 07:58:56 +08:00
|
|
|
/// </summary>
|
|
|
|
/// <param name="L"></param>
|
|
|
|
/// <param name="Amount"></param>
|
2019-09-24 08:33:28 +08:00
|
|
|
public void intakeFluid(Fluid L, int Amount)
|
2019-09-23 07:58:56 +08:00
|
|
|
{
|
|
|
|
int remainingAmount = Amount;
|
|
|
|
if (this.allowDoubleInput)
|
|
|
|
{
|
2019-09-25 06:18:57 +08:00
|
|
|
if (this.inputTank1.CanRecieveThisFluid(L) && remainingAmount > 0)
|
2019-09-23 07:58:56 +08:00
|
|
|
{
|
|
|
|
int allowedAmount = this.inputTank1.remainingCapacity;
|
2019-09-24 08:33:28 +08:00
|
|
|
this.inputTank1.intakeFluid(L, remainingAmount);
|
2019-09-23 07:58:56 +08:00
|
|
|
remainingAmount -= allowedAmount;
|
|
|
|
}
|
2019-09-25 06:18:57 +08:00
|
|
|
if (this.inputTank2.CanRecieveThisFluid(L) && remainingAmount > 0)
|
2019-09-23 07:58:56 +08:00
|
|
|
{
|
|
|
|
int allowedAmount = this.inputTank2.remainingCapacity;
|
2019-09-24 08:33:28 +08:00
|
|
|
this.inputTank2.intakeFluid(L, remainingAmount);
|
2019-09-23 07:58:56 +08:00
|
|
|
remainingAmount -= allowedAmount;
|
|
|
|
}
|
2019-09-24 09:13:45 +08:00
|
|
|
this.requiresUpdate = true;
|
2019-09-23 07:58:56 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
|
2019-09-25 06:18:57 +08:00
|
|
|
if (this.inputTank1.CanRecieveThisFluid(L) && remainingAmount > 0 && this.inputTank2.DoesTankContainThisFluid(L) == false)
|
2019-09-23 07:58:56 +08:00
|
|
|
{
|
|
|
|
int allowedAmount = this.inputTank1.remainingCapacity;
|
2019-09-24 08:33:28 +08:00
|
|
|
this.inputTank1.intakeFluid(L, remainingAmount);
|
2019-09-23 07:58:56 +08:00
|
|
|
remainingAmount -= allowedAmount;
|
2019-09-24 09:13:45 +08:00
|
|
|
this.requiresUpdate = true;
|
2019-09-23 07:58:56 +08:00
|
|
|
return;
|
|
|
|
}
|
2019-09-24 08:33:28 +08:00
|
|
|
if (this.inputTank2.CanRecieveThisFluid(L) && remainingAmount > 0 && this.inputTank1.DoesTankContainThisFluid(L) == false)
|
2019-09-23 07:58:56 +08:00
|
|
|
{
|
|
|
|
int allowedAmount = this.inputTank2.remainingCapacity;
|
2019-09-24 08:33:28 +08:00
|
|
|
this.inputTank2.intakeFluid(L, remainingAmount);
|
2019-09-23 07:58:56 +08:00
|
|
|
remainingAmount -= allowedAmount;
|
2019-09-24 09:13:45 +08:00
|
|
|
this.requiresUpdate = true;
|
2019-09-23 07:58:56 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
2019-09-24 08:33:28 +08:00
|
|
|
/// Consumes the Fluid in the input tanks. Mainly used for machine processing but shouldn't be drained outwards.
|
2019-09-23 07:58:56 +08:00
|
|
|
/// </summary>
|
|
|
|
/// <param name="L"></param>
|
|
|
|
/// <param name="Amount"></param>
|
2019-09-24 08:33:28 +08:00
|
|
|
public void consumeFluid(Fluid L, int Amount)
|
2019-09-23 07:58:56 +08:00
|
|
|
{
|
2019-09-24 08:33:28 +08:00
|
|
|
if (this.doTheInputTanksHaveEnoughFluid(L, Amount) == false) return;
|
2019-09-23 07:58:56 +08:00
|
|
|
|
|
|
|
int requiredAmount = Amount;
|
2019-09-24 08:33:28 +08:00
|
|
|
int tank1Amount = this.inputTank1.GetAmountOfFluidInThisTank(L);
|
2019-09-25 06:18:57 +08:00
|
|
|
int tank2Amount = this.inputTank2.GetAmountOfFluidInThisTank(L);
|
|
|
|
if (tank1Amount > 0 && requiredAmount > 0)
|
2019-09-23 07:58:56 +08:00
|
|
|
{
|
2019-09-24 08:33:28 +08:00
|
|
|
this.inputTank1.consumeFluid(requiredAmount);
|
2019-09-23 07:58:56 +08:00
|
|
|
requiredAmount -= tank1Amount;
|
2019-09-24 09:13:45 +08:00
|
|
|
this.requiresUpdate = true;
|
2019-09-23 07:58:56 +08:00
|
|
|
|
|
|
|
}
|
2019-09-25 06:18:57 +08:00
|
|
|
if (tank2Amount > 0 && requiredAmount > 0)
|
2019-09-23 07:58:56 +08:00
|
|
|
{
|
2019-09-24 08:33:28 +08:00
|
|
|
this.inputTank2.consumeFluid(requiredAmount);
|
2019-09-23 07:58:56 +08:00
|
|
|
requiredAmount -= tank2Amount;
|
2019-09-24 09:13:45 +08:00
|
|
|
this.requiresUpdate = true;
|
2019-09-23 07:58:56 +08:00
|
|
|
}
|
2019-09-24 08:33:28 +08:00
|
|
|
//Consumes Fluid from both tanks if double input is enabled. Otherwise it only drains from the appropriate tank.
|
2019-09-23 07:58:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void drainOutputTank(int Amount)
|
|
|
|
{
|
2019-09-24 08:33:28 +08:00
|
|
|
this.outputTank.consumeFluid(Amount);
|
|
|
|
if (this.outputTank.IsEmpty) this.outputTank.fluid = null;
|
2019-09-24 09:13:45 +08:00
|
|
|
this.requiresUpdate = true;
|
2019-09-23 07:58:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
2019-09-24 08:33:28 +08:00
|
|
|
/// Checks to see if the input tanks have enough Fluid combined to process the request.
|
2019-09-23 07:58:56 +08:00
|
|
|
/// </summary>
|
|
|
|
/// <param name="L"></param>
|
|
|
|
/// <param name="Amount"></param>
|
|
|
|
/// <returns></returns>
|
2019-09-24 08:33:28 +08:00
|
|
|
public bool doTheInputTanksHaveEnoughFluid(Fluid L, int Amount)
|
2019-09-23 07:58:56 +08:00
|
|
|
{
|
2019-09-24 08:33:28 +08:00
|
|
|
int tankTotals = this.inputTank1.GetAmountOfFluidInThisTank(L) + this.inputTank2.GetAmountOfFluidInThisTank(L);
|
2019-09-23 07:58:56 +08:00
|
|
|
if (tankTotals >= Amount) return true;
|
|
|
|
else return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
2019-09-24 08:33:28 +08:00
|
|
|
/// Gets the total amount of Fluid that the input tanks can recieve
|
2019-09-23 07:58:56 +08:00
|
|
|
/// </summary>
|
|
|
|
/// <param name="L"></param>
|
|
|
|
/// <returns></returns>
|
2019-09-24 08:33:28 +08:00
|
|
|
public int getMaxAmountOfFluidIntakePossible(Fluid L)
|
2019-09-23 07:58:56 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
if (this.allowDoubleInput)
|
|
|
|
{
|
|
|
|
int amount = 0;
|
2019-09-24 08:33:28 +08:00
|
|
|
amount += this.inputTank1.GetAmountOfFluidThisTankCanReceieve(L);
|
|
|
|
amount += this.inputTank2.GetAmountOfFluidThisTankCanReceieve(L);
|
2019-09-23 07:58:56 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-09-25 06:18:57 +08:00
|
|
|
if (this.inputTank1.CanRecieveThisFluid(L) && this.inputTank2.DoesTankContainThisFluid(L) == false)
|
2019-09-23 07:58:56 +08:00
|
|
|
{
|
2019-09-24 08:33:28 +08:00
|
|
|
return this.inputTank1.GetAmountOfFluidThisTankCanReceieve(L);
|
2019-09-23 07:58:56 +08:00
|
|
|
}
|
2019-09-24 08:33:28 +08:00
|
|
|
if (this.inputTank1.CanRecieveThisFluid(L) && this.inputTank2.DoesTankContainThisFluid(L) == false)
|
2019-09-23 07:58:56 +08:00
|
|
|
{
|
2019-09-24 08:33:28 +08:00
|
|
|
return this.inputTank2.GetAmountOfFluidThisTankCanReceieve(L);
|
2019-09-23 07:58:56 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
2019-09-24 08:33:28 +08:00
|
|
|
/// Checks to see if the input tanks on this Fluid manager have the capacity to take in this Fluid at all.
|
2019-09-23 07:58:56 +08:00
|
|
|
/// </summary>
|
|
|
|
/// <param name="L"></param>
|
|
|
|
/// <returns></returns>
|
2019-09-24 08:33:28 +08:00
|
|
|
public bool canRecieveThisFluid(Fluid L)
|
2019-09-23 07:58:56 +08:00
|
|
|
{
|
|
|
|
if (L == null) return false;
|
|
|
|
if (this.allowDoubleInput)
|
|
|
|
{
|
2019-09-24 08:33:28 +08:00
|
|
|
if (this.inputTank1.CanRecieveThisFluid(L) || this.inputTank2.CanRecieveThisFluid(L))
|
2019-09-23 07:58:56 +08:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-09-24 08:33:28 +08:00
|
|
|
if (this.inputTank1.CanRecieveThisFluid(L) && this.inputTank2.DoesTankContainThisFluid(L) == false)
|
2019-09-23 07:58:56 +08:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2019-09-24 08:33:28 +08:00
|
|
|
if (this.inputTank2.CanRecieveThisFluid(L) && this.inputTank1.DoesTankContainThisFluid(L) == false)
|
2019-09-23 07:58:56 +08:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2019-09-25 06:18:57 +08:00
|
|
|
|
2019-09-23 07:58:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
2019-09-24 08:33:28 +08:00
|
|
|
/// Takes the fluid in this output tank and tries to transfer it to another Fluid manager who has an tank available.
|
2019-09-23 07:58:56 +08:00
|
|
|
/// </summary>
|
|
|
|
/// <param name="Other"></param>
|
2019-09-24 08:33:28 +08:00
|
|
|
public void outputFluidToOtherSources(FluidManagerV2 Other)
|
2019-09-23 07:58:56 +08:00
|
|
|
{
|
2019-09-24 08:33:28 +08:00
|
|
|
if (this.outputTank.fluid == null) return;
|
|
|
|
if (Other.canRecieveThisFluid(this.outputTank.fluid))
|
2019-09-23 07:58:56 +08:00
|
|
|
{
|
2019-09-24 08:33:28 +08:00
|
|
|
int actualAmount = Math.Min(this.outputTank.amount, Other.getMaxAmountOfFluidIntakePossible(this.outputTank.fluid));
|
2019-09-25 06:18:57 +08:00
|
|
|
Other.intakeFluid(this.outputTank.fluid, actualAmount);
|
2019-09-23 07:58:56 +08:00
|
|
|
this.drainOutputTank(actualAmount);
|
|
|
|
}
|
|
|
|
}
|
2019-09-24 09:13:45 +08:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Checks to see if this output tank has the corresponding fluid and if the amount is greater than 0.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="F"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
public bool doesThisOutputTankContainThisFluid(Fluid F)
|
|
|
|
{
|
|
|
|
if (this.outputTank.GetAmountOfFluidInThisTank(F) > 0) return true;
|
|
|
|
else return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public FluidManagerV2 Copy()
|
|
|
|
{
|
2019-09-25 06:18:57 +08:00
|
|
|
return new FluidManagerV2(this.outputTank.capacity, this.onlyOutput, this.fluidInteractionType, this.allowDoubleInput);
|
2019-09-24 09:13:45 +08:00
|
|
|
}
|
2019-09-23 07:58:56 +08:00
|
|
|
}
|
|
|
|
}
|