v0.10.5.1

This commit is contained in:
Juan Pablo Arce
2020-09-22 11:31:56 -03:00
parent 44032d0ae0
commit 0002ad2c50
343 changed files with 12276 additions and 5023 deletions
@@ -62,7 +62,10 @@ namespace Barotrauma.Items.Components
timeSinceReceived[i] += deltaTime;
}
float output = Calculate(receivedSignal[0], receivedSignal[1]);
item.SendSignal(0, MathHelper.Clamp(output, ClampMin, ClampMax).ToString("G", CultureInfo.InvariantCulture), "signal_out", null);
if (MathUtils.IsValid(output))
{
item.SendSignal(0, MathHelper.Clamp(output, ClampMin, ClampMax).ToString("G", CultureInfo.InvariantCulture), "signal_out", null);
}
}
protected abstract float Calculate(float signal1, float signal2);
@@ -0,0 +1,17 @@
using System.Xml.Linq;
namespace Barotrauma.Items.Components
{
class ConcatComponent : StringComponent
{
public ConcatComponent(Item item, XElement element)
: base(item, element)
{
}
protected override string Calculate(string signal1, string signal2)
{
return signal1 + signal2;
}
}
}
@@ -1,6 +1,4 @@
using System;
using System.Globalization;
using System.Xml.Linq;
using System.Xml.Linq;
namespace Barotrauma.Items.Components
{
@@ -13,6 +11,7 @@ namespace Barotrauma.Items.Components
protected override float Calculate(float signal1, float signal2)
{
if (MathUtils.NearlyEqual(signal2, 0)) { return float.NaN; }
return signal1 / signal2;
}
}
@@ -56,8 +56,10 @@ namespace Barotrauma.Items.Components
item.SendSignal(0, Math.Abs(value).ToString("G", CultureInfo.InvariantCulture), "signal_out", null);
break;
case FunctionType.SquareRoot:
double square = value > 0 ? Math.Sqrt(value) : 0;
item.SendSignal(0, square.ToString("G", CultureInfo.InvariantCulture), "signal_out", null);
if (value > 0)
{
item.SendSignal(0, Math.Sqrt(value).ToString("G", CultureInfo.InvariantCulture), "signal_out", null);
}
break;
default:
throw new NotImplementedException($"Function {Function} has not been implemented.");
@@ -208,7 +208,8 @@ namespace Barotrauma.Items.Components
else
{
#if CLIENT
light.Rotation = -Rotation;
light.Rotation = -Rotation - MathHelper.ToRadians(item.Rotation);
light.LightSpriteEffect = item.SpriteEffects;
#endif
}
@@ -265,11 +266,14 @@ namespace Barotrauma.Items.Components
switch (connection.Name)
{
case "toggle":
if (!IgnoreContinuousToggle || lastToggleSignalTime < Timing.TotalTime - 0.1)
if (signal != "0")
{
IsOn = !IsOn;
if (!IgnoreContinuousToggle || lastToggleSignalTime < Timing.TotalTime - 0.1)
{
IsOn = !IsOn;
}
lastToggleSignalTime = Timing.TotalTime;
}
lastToggleSignalTime = Timing.TotalTime;
break;
case "set_state":
IsOn = signal != "0";
@@ -1,14 +1,24 @@
using System.Xml.Linq;
using Barotrauma.Networking;
using System.Xml.Linq;
namespace Barotrauma.Items.Components
{
class MemoryComponent : ItemComponent
partial class MemoryComponent : ItemComponent, IServerSerializable
{
const int MaxValueLength = 256;
private string value;
[InGameEditable, Serialize("", true, description: "The currently stored signal the item outputs.", alwaysUseInstanceValues: true)]
public string Value
{
get;
set;
get { return value; }
set
{
if (value == null) { return; }
this.value = value.Length <= MaxValueLength ? value : value.Substring(0, MaxValueLength);
}
}
protected bool writeable = true;
@@ -24,15 +34,22 @@ namespace Barotrauma.Items.Components
item.SendSignal(0, Value, "signal_out", null);
}
partial void OnStateChanged();
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; }
if (writeable)
{
if (Value == signal) { return; }
Value = signal;
OnStateChanged();
}
break;
case "signal_store":
writeable = (signal == "1");
writeable = signal == "1";
break;
}
}
@@ -0,0 +1,72 @@
using Microsoft.Xna.Framework;
using System;
using System.Globalization;
using System.Xml.Linq;
namespace Barotrauma.Items.Components
{
abstract class StringComponent : ItemComponent
{
//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(DecimalCount = 2),
Serialize(0.0f, true, description: "The item must have received signals to both inputs within this timeframe to output the result." +
" If set to 0, the inputs must be received at the same time.", alwaysUseInstanceValues: true)]
public float TimeFrame
{
get { return timeFrame; }
set
{
timeFrame = Math.Max(0.0f, value);
}
}
public StringComponent(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];
}
sealed public override void Update(float deltaTime, Camera cam)
{
for (int i = 0; i < timeSinceReceived.Length; i++)
{
if (timeSinceReceived[i] > timeFrame)
{
IsActive = false;
return;
}
timeSinceReceived[i] += deltaTime;
}
string output = Calculate(receivedSignal[0], receivedSignal[1]);
item.SendSignal(0, output, "signal_out", null);
}
protected abstract string Calculate(string signal1, string signal2);
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;
IsActive = true;
break;
case "signal_in2":
receivedSignal[1] = signal;
timeSinceReceived[1] = 0.0f;
IsActive = true;
break;
}
}
}
}
@@ -62,9 +62,15 @@ namespace Barotrauma.Items.Components
break;
case FunctionType.Tan:
if (!UseRadians) { value = MathHelper.ToRadians(value); }
item.SendSignal(0, ((float)Math.Tan(value)).ToString("G", CultureInfo.InvariantCulture), "signal_out", null);
//tan is undefined if the value is (π / 2) + πk, where k is any integer
if (!MathUtils.NearlyEqual(value % MathHelper.Pi, MathHelper.PiOver2))
{
item.SendSignal(0, ((float)Math.Tan(value)).ToString("G", CultureInfo.InvariantCulture), "signal_out", null);
}
break;
case FunctionType.Asin:
//asin is only defined in the range [-1,1]
if (value >= -1.0f && value <= 1.0f)
{
float angle = (float)Math.Asin(value);
if (!UseRadians) { angle = MathHelper.ToDegrees(angle); }
@@ -72,6 +78,8 @@ namespace Barotrauma.Items.Components
}
break;
case FunctionType.Acos:
//acos is only defined in the range [-1,1]
if (value >= -1.0f && value <= 1.0f)
{
float angle = (float)Math.Acos(value);
if (!UseRadians) { angle = MathHelper.ToDegrees(angle); }
@@ -12,6 +12,8 @@ namespace Barotrauma.Items.Components
{
private static readonly List<WifiComponent> list = new List<WifiComponent>();
const int ChannelMemorySize = 10;
private float range;
private int channel;
@@ -20,6 +22,8 @@ namespace Barotrauma.Items.Components
private string prevSignal;
private int[] channelMemory = new int[ChannelMemorySize];
[Serialize(Character.TeamType.None, true, description: "WiFi components can only communicate with components that have the same Team ID.", alwaysUseInstanceValues: true)]
public Character.TeamType TeamID { get; set; }
@@ -36,7 +40,7 @@ namespace Barotrauma.Items.Components
}
}
[InGameEditable, Serialize(1, true, description: "WiFi components can only communicate with components that use the same channel.", alwaysUseInstanceValues: true)]
[InGameEditable, Serialize(0, true, description: "WiFi components can only communicate with components that use the same channel.", alwaysUseInstanceValues: true)]
public int Channel
{
get { return channel; }
@@ -83,6 +87,18 @@ namespace Barotrauma.Items.Components
{
list.Add(this);
IsActive = true;
channelMemory = element.GetAttributeIntArray("channelmemory", new int[ChannelMemorySize]);
}
public override void OnItemLoaded()
{
if (channelMemory.All(m => m == 0))
{
for (int i = 0; i < channelMemory.Length; i++)
{
channelMemory[i] = i;
}
}
}
public bool CanTransmit()
@@ -118,6 +134,24 @@ namespace Barotrauma.Items.Components
}
}
public int GetChannelMemory(int index)
{
if (index < 0 || index >= ChannelMemorySize)
{
return 0;
}
return channelMemory[index];
}
public void SetChannelMemory(int index, int value)
{
if (index < 0 || index >= ChannelMemorySize)
{
return;
}
channelMemory[index] = MathHelper.Clamp(value, 0, 10000);
}
public void TransmitSignal(int stepsTaken, string signal, Item source, Character sender, bool sendToChat, float signalStrength = 1.0f)
{
var senderComponent = source?.GetComponent<WifiComponent>();
@@ -220,5 +254,12 @@ namespace Barotrauma.Items.Components
base.RemoveComponentSpecific();
list.Remove(this);
}
public override XElement Save(XElement parentElement)
{
var element = base.Save(parentElement);
element.Add(new XAttribute("channelmemory", string.Join(',', channelMemory)));
return element;
}
}
}
@@ -87,7 +87,14 @@ namespace Barotrauma.Items.Components
get;
set;
}
[Serialize(false, false, description: "If enabled, the wire will not be visible in connection panels outside the submarine editor.")]
public bool HiddenInGame
{
get;
set;
}
public Wire(Item item, XElement element)
: base(item, element)
{
@@ -673,12 +680,13 @@ namespace Barotrauma.Items.Components
closestDist = 0.0f;
int closestIndex = -1;
maxDist *= maxDist;
for (int i = 0; i < nodes.Count-1; i++)
{
if ((Math.Abs(nodes[i].X - nodes[i + 1].X)<5 || Math.Sign(mousePos.X - nodes[i].X) != Math.Sign(mousePos.X - nodes[i + 1].X)) &&
(Math.Abs(nodes[i].Y - nodes[i + 1].Y)<5 || Math.Sign(mousePos.Y - nodes[i].Y) != Math.Sign(mousePos.Y - nodes[i + 1].Y)))
{
float dist = MathUtils.LineToPointDistance(nodes[i], nodes[i + 1], mousePos);
float dist = MathUtils.LineToPointDistanceSquared(nodes[i], nodes[i + 1], mousePos);
if (dist > maxDist) continue;
if (closestIndex == -1 || dist < closestDist)
@@ -688,12 +696,15 @@ namespace Barotrauma.Items.Components
}
}
}
closestDist = (float)Math.Sqrt(closestDist);
return closestIndex;
}
public override void FlipX(bool relativeToSub)
{
if (item.ParentInventory != null) { return; }
Vector2 refPos = item.Submarine == null ?
Vector2.Zero :
item.Position - item.Submarine.HiddenSubPosition;