Unstable 1.1.14.0

This commit is contained in:
Markus Isberg
2023-10-02 16:43:54 +03:00
parent 94f5a93a0c
commit cf8f0de659
606 changed files with 21906 additions and 11456 deletions
@@ -18,8 +18,6 @@ namespace Barotrauma.Items.Components
const int MaxNodes = 100;
const float MaxNodeDistance = 150.0f;
private bool waitForVoltageRecalculation;
public struct Node
{
public Vector2 WorldPosition;
@@ -140,10 +138,6 @@ namespace Barotrauma.Items.Components
if (GameMain.NetworkMember != null && GameMain.NetworkMember.IsClient) { return false; }
if (character != null && !CharacterUsable) { return false; }
CurrPowerConsumption = powerConsumption;
Voltage = 0.0f;
waitForVoltageRecalculation = true;
charging = true;
timer = Duration;
IsActive = true;
@@ -159,12 +153,6 @@ namespace Barotrauma.Items.Components
#if CLIENT
frameOffset = Rand.Int(electricitySprite.FrameCount);
#endif
if (waitForVoltageRecalculation)
{
waitForVoltageRecalculation = false;
return;
}
if (timer <= 0.0f)
{
if (reloadTimer > 0.0f)
@@ -179,40 +167,49 @@ namespace Barotrauma.Items.Components
timer -= deltaTime;
if (charging)
{
if (GetAvailableInstantaneousBatteryPower() >= PowerConsumption)
bool hasPower = false;
if (item.Connections == null)
{
List<PowerContainer> batteries = GetDirectlyConnectedBatteries();
float neededPower = PowerConsumption;
while (neededPower > 0.0001f && batteries.Count > 0)
//no connections and can't be wired = must be powered by something like batteries
hasPower = Voltage > MinVoltage;
}
else
{
hasPower = GetAvailableInstantaneousBatteryPower() >= PowerConsumption;
}
if (hasPower)
{
var batteries = GetDirectlyConnectedBatteries().Where(static b => !b.OutputDisabled && b.Charge > 0.0001f && b.MaxOutPut > 0.0001f);
int batteryCount = batteries.Count();
if (batteryCount > 0)
{
batteries.RemoveAll(b => b.Charge <= 0.0001f || b.MaxOutPut <= 0.0001f);
float takePower = neededPower / batteries.Count;
takePower = Math.Min(takePower, batteries.Min(b => Math.Min(b.Charge * 3600.0f, b.MaxOutPut)));
foreach (PowerContainer battery in batteries)
float neededPower = PowerConsumption;
while (neededPower > 0.0001f)
{
neededPower -= takePower;
battery.Charge -= takePower / 3600.0f;
#if SERVER
if (GameMain.Server != null) { battery.Item.CreateServerEvent(battery); }
#endif
float takePower = neededPower / batteryCount;
takePower = Math.Min(takePower, batteries.Min(b => Math.Min(b.Charge * 3600.0f, b.MaxOutPut)));
foreach (PowerContainer battery in batteries)
{
neededPower -= takePower;
battery.Charge -= takePower / 3600.0f;
#if SERVER
if (GameMain.Server != null) { battery.Item.CreateServerEvent(battery); }
#endif
}
}
}
Discharge();
}
else if (Voltage > MinVoltage)
{
Discharge();
}
}
}
/// <summary>
/// Discharge coil only draws power when charging
/// Discharge coil doesn't consume grid power, directly takes from the batteries on its grid instead.
/// </summary>
public override float GetCurrentPowerConsumption(Connection connection = null)
public override float GetCurrentPowerConsumption(Connection conn = null)
{
return charging && IsActive ? PowerConsumption : 0;
return 0;
}
public override void UpdateBroken(float deltaTime, Camera cam)
@@ -294,10 +291,24 @@ namespace Barotrauma.Items.Components
if (!submarinesInRange.Contains(structure.Submarine)) { continue; }
if (OutdoorsOnly)
{
//check if the structure is within a hull
//add a small offset away from the sub's center so structures right at the edge of a hull are still valid
Vector2 offset = Vector2.Normalize(structure.WorldPosition - structure.Submarine.WorldPosition);
if (Hull.FindHull(structure.Position + offset * Submarine.GridSize, useWorldCoordinates: false) != null) { continue; }
//check if there's a hull at either side of the wall
Vector2 normal = new Vector2(
(float)-Math.Sin(structure.IsHorizontal ? -structure.BodyRotation : MathHelper.PiOver2 - structure.BodyRotation),
(float)Math.Cos(structure.IsHorizontal ? -structure.BodyRotation : MathHelper.PiOver2 - structure.BodyRotation));
Vector2 structurePos = structure.Position;
float offsetAmount = Submarine.GridSize.X * 2;
if (structure.HasBody)
{
structurePos = ConvertUnits.ToDisplayUnits(structure.Bodies.First().Position);
offsetAmount = Math.Max(
offsetAmount,
structure.IsHorizontal ? structure.BodyHeight : structure.BodyWidth);
}
if (Hull.FindHull(structurePos + normal * offsetAmount, useWorldCoordinates: false) != null &&
Hull.FindHull(structurePos - normal * offsetAmount, useWorldCoordinates: false) != null)
{
continue;
}
}
}
@@ -586,7 +597,7 @@ namespace Barotrauma.Items.Components
case "trigger_in":
if (signal.value != "0")
{
item.Use(1.0f, null);
item.Use(1.0f);
}
break;
}