Separate recharge and power_out connections in batteries (todo: configure recharge connections as power connections)

This commit is contained in:
Regalis
2016-02-05 22:10:51 +02:00
parent 6db3062cc8
commit ec7bd3523c
3 changed files with 78 additions and 22 deletions
@@ -55,6 +55,7 @@
</StatusEffect> </StatusEffect>
<requireditem name="Screwdriver" type="Equipped"/> <requireditem name="Screwdriver" type="Equipped"/>
<input name="power"/> <input name="power"/>
<input name="recharge"/>
</ConnectionPanel> </ConnectionPanel>
<ItemContainer capacity="3" hideitems="true"> <ItemContainer capacity="3" hideitems="true">
@@ -12,6 +12,8 @@ namespace Barotrauma.Items.Components
float charge; float charge;
float rechargeVoltage, outputVoltage;
//how fast the battery can be recharged //how fast the battery can be recharged
float maxRechargeSpeed; float maxRechargeSpeed;
@@ -21,6 +23,12 @@ namespace Barotrauma.Items.Components
float maxOutput; float maxOutput;
public float CurrPowerOutput
{
get;
private set;
}
[Editable, HasDefaultValue(10.0f, true)] [Editable, HasDefaultValue(10.0f, true)]
public float MaxOutPut public float MaxOutPut
{ {
@@ -112,6 +120,7 @@ namespace Barotrauma.Items.Components
foreach (Connection c in item.Connections) foreach (Connection c in item.Connections)
{ {
if (c.Name.Contains("recharge")) continue;
foreach (Connection c2 in c.Recipients) foreach (Connection c2 in c.Recipients)
{ {
PowerTransfer pt = c2.Item.GetComponent<PowerTransfer>(); PowerTransfer pt = c2.Item.GetComponent<PowerTransfer>();
@@ -122,32 +131,37 @@ namespace Barotrauma.Items.Components
} }
float gridRate = voltage; //float gridRate = voltage;
if (gridRate>minVoltage) //if (gridRate>minVoltage)
{ //{
ApplyStatusEffects(ActionType.OnActive, deltaTime, null); // ApplyStatusEffects(ActionType.OnActive, deltaTime, null);
} //}
//recharge //recharge
if (gridRate >= chargeRate) //if (gridRate >= chargeRate)
//{
if (charge >= capacity)
{ {
if (charge >= capacity) rechargeVoltage = 0.0f;
{ charge = capacity;
currPowerConsumption = 0.0f;
charge = capacity;
return;
}
currPowerConsumption = MathHelper.Lerp(currPowerConsumption, rechargeSpeed, 0.05f); CurrPowerConsumption = 0.0f;
Charge += currPowerConsumption*voltage / 3600.0f;
} }
else
{
currPowerConsumption = MathHelper.Lerp(currPowerConsumption, rechargeSpeed, 0.05f);
Charge += currPowerConsumption * rechargeVoltage / 3600.0f;
}
//}
//provide power to the grid //provide power to the grid
else if (gridLoad > 0.0f) if (gridLoad > 0.0f)
{ {
if (charge <= 0.0f) if (charge <= 0.0f)
{ {
currPowerConsumption = 0.0f; CurrPowerOutput = 0.0f;
charge = 0.0f; charge = 0.0f;
return; return;
} }
@@ -157,21 +171,34 @@ namespace Barotrauma.Items.Components
// -maxOutput * chargeRate, // -maxOutput * chargeRate,
// 0.1f); // 0.1f);
currPowerConsumption = MathHelper.Lerp( if (outputVoltage < 1.0f)
currPowerConsumption, {
-Math.Min(maxOutput * chargeRate, gridLoad - (gridLoad * voltage)), CurrPowerOutput = MathHelper.Lerp(
CurrPowerOutput, Math.Min(maxOutput * chargeRate, gridLoad), 0.05f);
}
else
{
CurrPowerOutput = MathHelper.Lerp(CurrPowerOutput, 0.0f, 0.05f);
}
CurrPowerOutput = MathHelper.Lerp(
CurrPowerOutput,
Math.Min(maxOutput * chargeRate, gridLoad - (gridLoad * outputVoltage)),
0.05f); 0.05f);
//powerConsumption = MathHelper.Lerp( //powerConsumption = MathHelper.Lerp(
// powerConsumption, // powerConsumption,
// -Math.Min(maxOutput * chargeRate, gridLoad - (power)), // -Math.Min(maxOutput * chargeRate, gridLoad - (power)),
// 0.1f); // 0.1f);
//powerConsumption = Math.Min(powerConsumption, 0.0f); //powerConsumption = Math.Min(powerConsumption, 0.0f);
charge -= -currPowerConsumption / chargeRate / 3600.0f; charge -= CurrPowerOutput / 3600.0f;
} }
voltage = 0.0f; rechargeVoltage = 0.0f;
outputVoltage = 0.0f;
} }
public override bool AIOperate(float deltaTime, Character character, AIObjectiveOperateItem objective) public override bool AIOperate(float deltaTime, Character character, AIObjectiveOperateItem objective)
@@ -181,6 +208,22 @@ namespace Barotrauma.Items.Components
return true; return true;
} }
public override void ReceiveSignal(string signal, Connection connection, Item sender, float power)
{
if (!connection.IsPower) return;
if (connection.Name.Contains("recharge"))
{
rechargeVoltage = power;
}
else
{
outputVoltage = power;
}
//if (currPowerConsumption == 0.0f) voltage = 0.0f;
//if (connection.IsPower) voltage = power;
}
public override void Draw(SpriteBatch spriteBatch, bool editing) public override void Draw(SpriteBatch spriteBatch, bool editing)
{ {
base.Draw(spriteBatch); base.Draw(spriteBatch);
@@ -113,7 +113,7 @@ namespace Barotrauma.Items.Components
if (!c.IsPower) continue; if (!c.IsPower) continue;
foreach (Connection recipient in c.Recipients) foreach (Connection recipient in c.Recipients)
{ {
if (recipient == null || !recipient.IsPower) continue; if (recipient == null || !c.IsPower) continue;
Item it = recipient.Item; Item it = recipient.Item;
if (it == null) continue; if (it == null) continue;
@@ -124,11 +124,23 @@ namespace Barotrauma.Items.Components
if (powered == null) continue; if (powered == null) continue;
PowerTransfer powerTransfer = powered as PowerTransfer; PowerTransfer powerTransfer = powered as PowerTransfer;
PowerContainer powerContainer = powered as PowerContainer;
if (powerTransfer != null) if (powerTransfer != null)
{ {
if (powerTransfer.updateTimer>0) continue; if (powerTransfer.updateTimer>0) continue;
powerTransfer.CheckJunctions(deltaTime); powerTransfer.CheckJunctions(deltaTime);
} }
else if (powerContainer != null)
{
if (recipient.Name.Contains("recharge"))
{
fullLoad += powerContainer.CurrPowerConsumption;
}
else
{
fullPower += powerContainer.CurrPowerOutput;
}
}
else else
{ {
connectedList.Add(powered); connectedList.Add(powered);