c2e39cc...409d4d9
commit 409d4d96ead69028a164274637d23e350acb73fb Merge: 95169f539 26e89c63d Author: EdusFF <pitkanen.eetu@gmail.com> Date: Mon Mar 11 15:13:27 2019 +0200 Merge branch 'dev' of github.com:Regalis11/Barotrauma into dev commit 95169f53937f9a7e168a884171eaa21ae7f08023 Author: EdusFF <pitkanen.eetu@gmail.com> Date: Mon Mar 11 15:13:11 2019 +0200 Modified: ServerMessage structure to allow _ ; in player & submarine names commit 26e89c63dc8da771aea9f09978a630a6cff60a6f Merge: b7646d06d fb0b821bc Author: Joonas Rikkonen <poe.regalis@gmail.com> Date: Mon Mar 11 14:42:44 2019 +0200 Merge branch 'kuraiookami-logicExpantion' into dev # Conflicts: # Barotrauma/BarotraumaShared/SharedContent.projitems commit fb0b821bc97891cdeec8f2c740a12119696393ea Author: Joonas Rikkonen <poe.regalis@gmail.com> Date: Mon Mar 11 14:41:21 2019 +0200 Use invariant culture when parsing floats or converting them to strings in signal components commit f0c8afba934b41358cf5d59a22b87caf33f98a61 Author: Joonas Rikkonen <poe.regalis@gmail.com> Date: Mon Mar 11 14:00:44 2019 +0200 Update new signal components to use identifiers & added names and descriptions to the text file, use invariant culture in equalscomponent, memorycomponent doesn't require the signals to be floats commit 674d9ec804fc4770b602d4b09240b08cafc8ccec Merge: 3ea33fb54 242e2429f Author: Joonas Rikkonen <poe.regalis@gmail.com> Date: Mon Mar 11 12:01:27 2019 +0200 Merge branch 'logicExpantion' of https://github.com/kuraiookami/Barotrauma into kuraiookami-logicExpantion # Conflicts: # Barotrauma/BarotraumaShared/BarotraumaShared.projitems # Barotrauma/BarotraumaShared/Content/Items/Electricity/poweritems.xml # Barotrauma/BarotraumaShared/Content/Items/Electricity/signalitems.xml # Barotrauma/BarotraumaShared/Source/Items/Components/Power/PowerContainer.cs # Barotrauma/BarotraumaShared/Source/Items/Components/Signal/AdderComponent.cs commit b7646d06d53fb05227276e6286d0e15da5dc9080 Author: Joonas Rikkonen <poe.regalis@gmail.com> Date: Mon Mar 11 11:37:33 2019 +0200 Re-enabled multiplayer campaign commit cf7258f6410a5995c881ec6e95eb9def5cd90ad4 Author: Joonas Rikkonen <poe.regalis@gmail.com> Date: Mon Mar 11 11:28:48 2019 +0200 Fixed item interfaces getting repositioned every frame when the editing HUD is open. Closes #1212 commit e8906239c779cf71de694bc65c81058e5cae16ef Author: Joonas Rikkonen <poe.regalis@gmail.com> Date: Mon Mar 11 11:12:05 2019 +0200 Fixed VoipCapture creating new "could not start voice capture" popups constantly if there's no suitable capture device. Closes #1262 commit a30f47fbe47fde4fccb0453c1773a76d730d226b Author: Joonas Rikkonen <poe.regalis@gmail.com> Date: Sun Mar 10 19:04:59 2019 +0200 Disable audio instead of crashing if no audio device is found. Closes #1214 commit 242e2429fd2c3ed199ac26b55e2cbdc8636e73f9 Author: Darkwolf <Darkwolf0101@gmail.com> Date: Mon Jan 21 21:26:57 2019 -0600 Expansion of Barotrauma's logic system. Changed: - AdderComponent and children can clamp their output - Powercontainer signals for charge,charge% and charge rate Added: - ColorComponent: Dynamic signals for light set_color inputs - MemoryComponent: Stores and sends a signal that is edge latched - DivideComponent: Standard division - MultiplyComponent: Standard multiplication - SubtractComponent: Standard subtraction - XorComponent: Exclusive or - EqualsComponent: Equals comparison - GreaterComponent: Greater than comparison
This commit is contained in:
@@ -3,6 +3,7 @@ using Lidgren.Network;
|
||||
using Microsoft.Xna.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Barotrauma.Items.Components
|
||||
@@ -204,6 +205,15 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
Charge -= CurrPowerOutput / 3600.0f;
|
||||
}
|
||||
item.SendSignal(0, Charge.ToString(), "charge", null);
|
||||
item.SendSignal(0, ((Charge / capacity) * 100).ToString(), "charge_%", null);
|
||||
item.SendSignal(0, ((RechargeSpeed / maxRechargeSpeed) * 100).ToString(), "charge_rate", null);
|
||||
|
||||
foreach (Pair<Powered, Connection> connected in directlyConnected)
|
||||
{
|
||||
connected.First.ReceiveSignal(0, "", connected.Second, source: item, sender: null,
|
||||
power: gridLoad <= 0.0f ? 1.0f : CurrPowerOutput / gridLoad);
|
||||
}
|
||||
|
||||
foreach (Pair<Powered, Connection> connected in directlyConnected)
|
||||
{
|
||||
@@ -259,6 +269,15 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
public override void ReceiveSignal(int stepsTaken, string signal, Connection connection, Item source, Character sender, float power, float signalStrength = 1.0f)
|
||||
{
|
||||
if (connection.Name == "set_rate")
|
||||
{
|
||||
float tempSpeed;
|
||||
if (float.TryParse(signal, NumberStyles.Any, CultureInfo.InvariantCulture, out tempSpeed))
|
||||
{
|
||||
if (!MathUtils.IsValid(tempSpeed)) return;
|
||||
RechargeSpeed = MathHelper.Clamp(tempSpeed / 100.0f, 0.0f, 1.0f) * MaxRechargeSpeed;
|
||||
}
|
||||
}
|
||||
if (!connection.IsPower) return;
|
||||
|
||||
if (connection.Name == "power_in")
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Microsoft.Xna.Framework;
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Xml.Linq;
|
||||
|
||||
@@ -10,11 +11,24 @@ namespace Barotrauma.Items.Components
|
||||
protected float[] timeSinceReceived;
|
||||
|
||||
protected float[] receivedSignal;
|
||||
|
||||
|
||||
|
||||
//the output is sent if both inputs have received a signal within the timeframe
|
||||
protected float timeFrame;
|
||||
|
||||
|
||||
[InGameEditable(MinValueFloat = -999999.0f, MaxValueFloat = 999999.0f), Serialize(999999.0f, true)]
|
||||
public float ClampMax
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[InGameEditable(MinValueFloat = -999999.0f, MaxValueFloat = 999999.0f), Serialize(-999999.0f, true)]
|
||||
public float ClampMin
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[InGameEditable(DecimalCount = 2), Serialize(0.0f, true)]
|
||||
public float TimeFrame
|
||||
{
|
||||
@@ -43,7 +57,8 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
if (sendOutput)
|
||||
{
|
||||
item.SendSignal(0, (receivedSignal[0] + receivedSignal[1]).ToString(), "signal_out", null);
|
||||
float output = receivedSignal[0] + receivedSignal[1];
|
||||
item.SendSignal(0, MathHelper.Clamp(output, ClampMin, ClampMax).ToString("G", CultureInfo.InvariantCulture), "signal_out", null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Barotrauma.Items.Components
|
||||
{
|
||||
class ColorComponent : ItemComponent
|
||||
{
|
||||
protected float[] receivedSignal;
|
||||
|
||||
private string output = "0,0,0,0";
|
||||
|
||||
public ColorComponent(Item item, XElement element)
|
||||
: base(item, element)
|
||||
{
|
||||
receivedSignal = new float[4];
|
||||
IsActive = true;
|
||||
}
|
||||
|
||||
public override void Update(float deltaTime, Camera cam)
|
||||
{
|
||||
item.SendSignal(0, output, "signal_out", null);
|
||||
}
|
||||
|
||||
private void UpdateOutput()
|
||||
{
|
||||
output = receivedSignal[0].ToString("G", CultureInfo.InvariantCulture);
|
||||
output += "," + receivedSignal[1].ToString("G", CultureInfo.InvariantCulture);
|
||||
output += "," + receivedSignal[2].ToString("G", CultureInfo.InvariantCulture);
|
||||
output += "," + receivedSignal[3].ToString("G", CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
public override void ReceiveSignal(int stepsTaken, string signal, Connection connection, Item source, Character sender, float power = 0.0f, float signalStrength = 1.0f)
|
||||
{
|
||||
switch (connection.Name)
|
||||
{
|
||||
case "signal_r":
|
||||
float.TryParse(signal, NumberStyles.Float, CultureInfo.InvariantCulture, out receivedSignal[0]);
|
||||
UpdateOutput();
|
||||
break;
|
||||
case "signal_g":
|
||||
float.TryParse(signal, NumberStyles.Float, CultureInfo.InvariantCulture, out receivedSignal[1]);
|
||||
UpdateOutput();
|
||||
break;
|
||||
case "signal_b":
|
||||
float.TryParse(signal, NumberStyles.Float, CultureInfo.InvariantCulture, out receivedSignal[2]);
|
||||
UpdateOutput();
|
||||
break;
|
||||
case "signal_a":
|
||||
float.TryParse(signal, NumberStyles.Float, CultureInfo.InvariantCulture, out receivedSignal[3]);
|
||||
UpdateOutput();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Barotrauma.Items.Components
|
||||
{
|
||||
class DivideComponent : AdderComponent
|
||||
{
|
||||
public DivideComponent(Item item, XElement element)
|
||||
: base(item, element)
|
||||
{
|
||||
IsActive = true;
|
||||
}
|
||||
|
||||
public override void Update(float deltaTime, Camera cam)
|
||||
{
|
||||
bool sendOutput = true;
|
||||
for (int i = 0; i < timeSinceReceived.Length; i++)
|
||||
{
|
||||
if (timeSinceReceived[i] > timeFrame) sendOutput = false;
|
||||
timeSinceReceived[i] += deltaTime;
|
||||
}
|
||||
if (sendOutput)
|
||||
{
|
||||
item.SendSignal(0, (receivedSignal[0] / receivedSignal[1]).ToString("G", CultureInfo.InvariantCulture), "signal_out", null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
using System;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Barotrauma.Items.Components
|
||||
{
|
||||
class EqualsComponent : ItemComponent
|
||||
{
|
||||
protected string output, falseOutput;
|
||||
|
||||
//an array to keep track of how long ago a signal was received on both inputs
|
||||
protected float[] timeSinceReceived;
|
||||
|
||||
protected string[] receivedSignal;
|
||||
|
||||
//the output is sent if both inputs have received a signal within the timeframe
|
||||
protected float timeFrame;
|
||||
|
||||
[InGameEditable, Serialize("1", true)]
|
||||
public string Output
|
||||
{
|
||||
get { return output; }
|
||||
set { output = value; }
|
||||
}
|
||||
|
||||
[InGameEditable, Serialize("", true)]
|
||||
public string FalseOutput
|
||||
{
|
||||
get { return falseOutput; }
|
||||
set { falseOutput = value; }
|
||||
}
|
||||
|
||||
[InGameEditable(DecimalCount = 2), Serialize(0.0f, true)]
|
||||
public float TimeFrame
|
||||
{
|
||||
get { return timeFrame; }
|
||||
set
|
||||
{
|
||||
timeFrame = Math.Max(0.0f, value);
|
||||
}
|
||||
}
|
||||
|
||||
public EqualsComponent(Item item, XElement element)
|
||||
: base(item, element)
|
||||
{
|
||||
timeSinceReceived = new float[] { Math.Max(timeFrame * 2.0f, 0.1f), Math.Max(timeFrame * 2.0f, 0.1f) };
|
||||
receivedSignal = new string[2];
|
||||
IsActive = true;
|
||||
}
|
||||
|
||||
public override void Update(float deltaTime, Camera cam)
|
||||
{
|
||||
bool sendOutput = false;
|
||||
for (int i = 0; i < timeSinceReceived.Length; i++)
|
||||
{
|
||||
if (timeSinceReceived[i] <= timeFrame) sendOutput = true;
|
||||
timeSinceReceived[i] += deltaTime;
|
||||
}
|
||||
|
||||
if (sendOutput)
|
||||
{
|
||||
string signalOut = receivedSignal[0] == receivedSignal[1] ? output : falseOutput;
|
||||
if (string.IsNullOrEmpty(signalOut)) return;
|
||||
|
||||
item.SendSignal(0, signalOut, "signal_out", null);
|
||||
}
|
||||
}
|
||||
|
||||
public override void ReceiveSignal(int stepsTaken, string signal, Connection connection, Item source, Character sender, float power = 0.0f, float signalStrength = 1.0f)
|
||||
{
|
||||
switch (connection.Name)
|
||||
{
|
||||
case "signal_in1":
|
||||
receivedSignal[0] = signal;
|
||||
timeSinceReceived[0] = 0.0f;
|
||||
break;
|
||||
case "signal_in2":
|
||||
receivedSignal[1] = signal;
|
||||
timeSinceReceived[1] = 0.0f;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
using System.Globalization;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Barotrauma.Items.Components
|
||||
{
|
||||
class GreaterComponent : EqualsComponent
|
||||
{
|
||||
private float val1, val2;
|
||||
|
||||
public GreaterComponent(Item item, XElement element)
|
||||
: base(item, element)
|
||||
{
|
||||
IsActive = true;
|
||||
}
|
||||
|
||||
public override void Update(float deltaTime, Camera cam)
|
||||
{
|
||||
bool sendOutput = false;
|
||||
for (int i = 0; i < timeSinceReceived.Length; i++)
|
||||
{
|
||||
if (timeSinceReceived[i] <= timeFrame) sendOutput = true;
|
||||
timeSinceReceived[i] += deltaTime;
|
||||
}
|
||||
|
||||
if (sendOutput)
|
||||
{
|
||||
string signalOut = val1 > val2 ? output : falseOutput;
|
||||
if (string.IsNullOrEmpty(signalOut)) return;
|
||||
|
||||
item.SendSignal(0, signalOut, "signal_out", null);
|
||||
}
|
||||
}
|
||||
|
||||
public override void ReceiveSignal(int stepsTaken, string signal, Connection connection, Item source, Character sender, float power = 0.0f, float signalStrength = 1.0f)
|
||||
{
|
||||
base.ReceiveSignal(stepsTaken, signal, connection, source, sender, power, signalStrength);
|
||||
float.TryParse(receivedSignal[0], NumberStyles.Float, CultureInfo.InvariantCulture, out val1);
|
||||
float.TryParse(receivedSignal[1], NumberStyles.Float, CultureInfo.InvariantCulture, out val2);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Barotrauma.Items.Components
|
||||
{
|
||||
class MemoryComponent : ItemComponent
|
||||
{
|
||||
[InGameEditable, Serialize("", true)]
|
||||
public string Value
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
protected bool writeable = true;
|
||||
|
||||
public MemoryComponent(Item item, XElement element)
|
||||
: base(item, element)
|
||||
{
|
||||
IsActive = true;
|
||||
}
|
||||
|
||||
public override void Update(float deltaTime, Camera cam)
|
||||
{
|
||||
item.SendSignal(0, Value, "signal_out", null);
|
||||
}
|
||||
|
||||
public override void ReceiveSignal(int stepsTaken, string signal, Connection connection, Item source, Character sender, float power = 0.0f, float signalStrength = 1.0f)
|
||||
{
|
||||
switch (connection.Name)
|
||||
{
|
||||
case "signal_in":
|
||||
if (writeable) { Value = signal; }
|
||||
break;
|
||||
case "signal_store":
|
||||
writeable = (signal == "1");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using System.Globalization;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Barotrauma.Items.Components
|
||||
{
|
||||
class MultiplyComponent : AdderComponent
|
||||
{
|
||||
public MultiplyComponent(Item item, XElement element)
|
||||
: base(item, element)
|
||||
{
|
||||
IsActive = true;
|
||||
}
|
||||
|
||||
public override void Update(float deltaTime, Camera cam)
|
||||
{
|
||||
bool sendOutput = true;
|
||||
for (int i = 0; i < timeSinceReceived.Length; i++)
|
||||
{
|
||||
if (timeSinceReceived[i] > timeFrame) sendOutput = false;
|
||||
timeSinceReceived[i] += deltaTime;
|
||||
}
|
||||
if (sendOutput)
|
||||
{
|
||||
item.SendSignal(0, (receivedSignal[0] * receivedSignal[1]).ToString("G", CultureInfo.InvariantCulture), "signal_out", null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using System.Globalization;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Barotrauma.Items.Components
|
||||
{
|
||||
class SubtractComponent : AdderComponent
|
||||
{
|
||||
public SubtractComponent(Item item, XElement element)
|
||||
: base(item, element)
|
||||
{
|
||||
IsActive = true;
|
||||
}
|
||||
|
||||
public override void Update(float deltaTime, Camera cam)
|
||||
{
|
||||
bool sendOutput = true;
|
||||
for (int i = 0; i < timeSinceReceived.Length; i++)
|
||||
{
|
||||
if (timeSinceReceived[i] > timeFrame) sendOutput = false;
|
||||
timeSinceReceived[i] += deltaTime;
|
||||
}
|
||||
if (sendOutput)
|
||||
{
|
||||
item.SendSignal(0, (receivedSignal[0] - receivedSignal[1]).ToString("G", CultureInfo.InvariantCulture), "signal_out", null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Barotrauma.Items.Components
|
||||
{
|
||||
class XorComponent : AndComponent
|
||||
{
|
||||
public XorComponent(Item item, XElement element)
|
||||
: base(item, element)
|
||||
{
|
||||
IsActive = true;
|
||||
}
|
||||
|
||||
public override void Update(float deltaTime, Camera cam)
|
||||
{
|
||||
int sendOutput = 0;
|
||||
for (int i = 0; i < timeSinceReceived.Length; i++)
|
||||
{
|
||||
if (timeSinceReceived[i] <= timeFrame) sendOutput += 1;
|
||||
timeSinceReceived[i] += deltaTime;
|
||||
}
|
||||
|
||||
string signalOut = sendOutput == 1 ? output : falseOutput;
|
||||
if (string.IsNullOrEmpty(signalOut)) return;
|
||||
|
||||
item.SendSignal(0, signalOut, "signal_out", null);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user