(5a377a8ee) Unstable v0.9.1000.0

This commit is contained in:
Juan Pablo Arce
2020-05-13 12:55:42 -03:00
parent b143329701
commit a1ca41aa5d
426 changed files with 14384 additions and 5708 deletions
@@ -13,7 +13,7 @@ namespace Barotrauma.Items.Components
//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 sends the output if both inputs have received a non-zero signal within the timeframe. If set to 0, the inputs must receive a signal at the same time.")]
[InGameEditable(DecimalCount = 2), Serialize(0.0f, true, description: "The item sends the output if both inputs have received a non-zero signal within the timeframe. If set to 0, the inputs must receive a signal at the same time.", alwaysUseInstanceValues: true)]
public float TimeFrame
{
get { return timeFrame; }
@@ -23,14 +23,14 @@ namespace Barotrauma.Items.Components
}
}
[InGameEditable, Serialize("1", true, description: "The signal sent when both inputs have received a non-zero signal.")]
[InGameEditable, Serialize("1", true, description: "The signal sent when the condition is met.", alwaysUseInstanceValues: true)]
public string Output
{
get { return output; }
set { output = value; }
}
[InGameEditable, Serialize("", true, description: "The signal sent when both inputs have not received a non-zero signal (if empty, no signal is sent).")]
[InGameEditable, Serialize("", true, description: "The signal sent when the condition is met (if empty, no signal is sent).", alwaysUseInstanceValues: true)]
public string FalseOutput
{
get { return falseOutput; }
@@ -15,7 +15,7 @@ namespace Barotrauma.Items.Components
//the output is sent if both inputs have received a signal within the timeframe
protected float timeFrame;
[Serialize(999999.0f, true, description: "The output of the item is restricted below this value."),
[Serialize(999999.0f, true, description: "The output of the item is restricted below this value.", alwaysUseInstanceValues: true),
InGameEditable(MinValueFloat = -999999.0f, MaxValueFloat = 999999.0f)]
public float ClampMax
{
@@ -23,7 +23,7 @@ namespace Barotrauma.Items.Components
set;
}
[Serialize(-999999.0f, true, description: "The output of the item is restricted above this value."),
[Serialize(-999999.0f, true, description: "The output of the item is restricted above this value.", alwaysUseInstanceValues: true),
InGameEditable(MinValueFloat = -999999.0f, MaxValueFloat = 999999.0f)]
public float ClampMin
{
@@ -32,8 +32,8 @@ namespace Barotrauma.Items.Components
}
[InGameEditable(DecimalCount = 2),
Serialize(0.0f, true, description: "The item must have received signals to both inputs within this timeframe to output the sum of the signals." +
" If set to 0, the inputs must be received at the same time.")]
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; }
@@ -21,7 +21,7 @@ namespace Barotrauma.Items.Components
private List<ushort> disconnectedWireIds;
[Editable, Serialize(false, true, description: "Locked connection panels cannot be rewired in-game.")]
[Editable, Serialize(false, true, description: "Locked connection panels cannot be rewired in-game.", alwaysUseInstanceValues: true)]
public bool Locked
{
get;
@@ -192,6 +192,8 @@ namespace Barotrauma.Items.Components
public bool CheckCharacterSuccess(Character character)
{
if (character == null) { return false; }
//no electrocution in sub editor
if (Screen.Selected == GameMain.SubEditorScreen) { return true; }
var powered = item.GetComponent<Powered>();
if (powered != null)
@@ -262,7 +264,18 @@ namespace Barotrauma.Items.Components
{
if (wire.OtherConnection(null) == null) //wire not connected to anything else
{
#if CLIENT
if (SubEditorScreen.IsSubEditor())
{
wire.Item.Remove();
}
else
{
wire.Item.Drop(null);
}
#else
wire.Item.Drop(null);
#endif
}
}
@@ -275,7 +288,18 @@ namespace Barotrauma.Items.Components
if (wire.OtherConnection(c) == null) //wire not connected to anything else
{
#if CLIENT
if (SubEditorScreen.IsSubEditor())
{
wire.Item.Remove();
}
else
{
wire.Item.Drop(null);
}
#else
wire.Item.Drop(null);
#endif
}
else
{
@@ -30,7 +30,7 @@ namespace Barotrauma.Items.Components
private DelayedSignal prevQueuedSignal;
private float delay;
[InGameEditable(MinValueFloat = 0.0f, MaxValueFloat = 60.0f, DecimalCount = 2), Serialize(1.0f, true, description: "How long the item delays the signals (in seconds).")]
[InGameEditable(MinValueFloat = 0.0f, MaxValueFloat = 60.0f, DecimalCount = 2), Serialize(1.0f, true, description: "How long the item delays the signals (in seconds).", alwaysUseInstanceValues: true)]
public float Delay
{
get { return delay; }
@@ -43,14 +43,14 @@ namespace Barotrauma.Items.Components
}
}
[InGameEditable, Serialize(false, true, description: "Should the component discard previously received signals when a new one is received.")]
[InGameEditable, Serialize(false, true, description: "Should the component discard previously received signals when a new one is received.", alwaysUseInstanceValues: true)]
public bool ResetWhenSignalReceived
{
get;
set;
}
[InGameEditable, Serialize(false, true, description: "Should the component discard previously received signals when the incoming signal changes.")]
[InGameEditable, Serialize(false, true, description: "Should the component discard previously received signals when the incoming signal changes.", alwaysUseInstanceValues: true)]
public bool ResetWhenDifferentSignalReceived
{
get;
@@ -15,21 +15,21 @@ namespace Barotrauma.Items.Components
//the output is sent if both inputs have received a signal within the timeframe
protected float timeFrame;
[InGameEditable, Serialize("1", true, description: "The signal this item outputs when the received signals are equal.")]
[InGameEditable, Serialize("1", true, description: "The signal this item outputs when the condition is met.", alwaysUseInstanceValues: true)]
public string Output
{
get { return output; }
set { output = value; }
}
[InGameEditable, Serialize("", true, description: "The signal this item outputs when the received signals are not equal.")]
[InGameEditable, Serialize("", true, description: "The signal this item outputs when the condition is not met.", alwaysUseInstanceValues: true)]
public string FalseOutput
{
get { return falseOutput; }
set { falseOutput = value; }
}
[InGameEditable(DecimalCount = 2), Serialize(0.0f, true, description: "The maximum amount of time between the received signals. If set to 0, the signals must be received at the same time.")]
[InGameEditable(DecimalCount = 2), Serialize(0.0f, true, description: "The maximum amount of time between the received signals. If set to 0, the signals must be received at the same time.", alwaysUseInstanceValues: true)]
public float TimeFrame
{
get { return timeFrame; }
@@ -6,7 +6,7 @@ namespace Barotrauma.Items.Components
class ExponentiationComponent : ItemComponent
{
private float exponent;
[InGameEditable, Serialize(1.0f, false, description: "The exponent of the operation.")]
[InGameEditable, Serialize(1.0f, false, description: "The exponent of the operation.", alwaysUseInstanceValues: true)]
public float Exponent
{
get
@@ -16,7 +16,7 @@ namespace Barotrauma.Items.Components
SquareRoot
}
[Serialize(FunctionType.Round, false, description: "Which kind of function to run the input through.")]
[Serialize(FunctionType.Round, false, description: "Which kind of function to run the input through.", alwaysUseInstanceValues: true)]
public FunctionType Function
{
get; set;
@@ -15,7 +15,7 @@ namespace Barotrauma.Items.Components
private float lightBrightness;
private float blinkFrequency;
private float range;
private float flicker;
private float flicker, flickerState;
private bool castShadows;
private bool drawBehindSubs;
@@ -25,7 +25,7 @@ namespace Barotrauma.Items.Components
public PhysicsBody ParentBody;
[Serialize(100.0f, true, description: "The range of the emitted light. Higher values are more performance-intensive."),
[Serialize(100.0f, true, description: "The range of the emitted light. Higher values are more performance-intensive.", alwaysUseInstanceValues: true),
Editable(MinValueFloat = 0.0f, MaxValueFloat = 2048.0f)]
public float Range
{
@@ -34,6 +34,7 @@ namespace Barotrauma.Items.Components
{
range = MathHelper.Clamp(value, 0.0f, 4096.0f);
#if CLIENT
item.ResetCachedVisibleSize();
if (light != null) { light.Range = range; }
#endif
}
@@ -42,7 +43,7 @@ namespace Barotrauma.Items.Components
public float Rotation;
[Editable, Serialize(true, true, description: "Should structures cast shadows when light from this light source hits them. " +
"Disabling shadows increases the performance of the game, and is recommended for lights with a short range.")]
"Disabling shadows increases the performance of the game, and is recommended for lights with a short range.", alwaysUseInstanceValues: true)]
public bool CastShadows
{
get { return castShadows; }
@@ -56,7 +57,7 @@ namespace Barotrauma.Items.Components
}
[Editable, Serialize(false, true, description: "Lights drawn behind submarines don't cast any shadows and are much faster to draw than shadow-casting lights. " +
"It's recommended to enable this on decorative lights outside the submarine's hull.")]
"It's recommended to enable this on decorative lights outside the submarine's hull.", alwaysUseInstanceValues: true)]
public bool DrawBehindSubs
{
get { return drawBehindSubs; }
@@ -69,7 +70,7 @@ namespace Barotrauma.Items.Components
}
}
[Editable, Serialize(false, true, description: "Is the light currently on.")]
[Editable, Serialize(false, true, description: "Is the light currently on.", alwaysUseInstanceValues: true)]
public bool IsOn
{
get { return IsActive; }
@@ -82,7 +83,7 @@ namespace Barotrauma.Items.Components
}
}
[Serialize(0.0f, false, description: "How heavily the light flickers. 0 = no flickering, 1 = the light will alternate between completely dark and full brightness.")]
[Editable, Serialize(0.0f, false, description: "How heavily the light flickers. 0 = no flickering, 1 = the light will alternate between completely dark and full brightness.")]
public float Flicker
{
get { return flicker; }
@@ -92,6 +93,13 @@ namespace Barotrauma.Items.Components
}
}
[Editable, Serialize(1.0f, false, description: "How fast the light flickers.")]
public float FlickerSpeed
{
get;
set;
}
[Editable, Serialize(0.0f, true, description: "How rapidly the light blinks on and off (in Hz). 0 = no blinking.")]
public float BlinkFrequency
{
@@ -102,7 +110,7 @@ namespace Barotrauma.Items.Components
}
}
[InGameEditable, Serialize("255,255,255,255", true, description: "The color of the emitted light (R,G,B,A).")]
[InGameEditable, Serialize("255,255,255,255", true, description: "The color of the emitted light (R,G,B,A).", alwaysUseInstanceValues: true)]
public Color LightColor
{
get { return lightColor; }
@@ -217,7 +225,7 @@ namespace Barotrauma.Items.Components
}
else
{
lightBrightness = MathHelper.Lerp(lightBrightness, Math.Min(Voltage, 1.0f), 0.1f);
lightBrightness = MathHelper.Lerp(lightBrightness, powerConsumption <= 0.0f ? 1.0f : Math.Min(Voltage, 1.0f), 0.1f);
}
if (blinkFrequency > 0.0f)
@@ -231,7 +239,10 @@ namespace Barotrauma.Items.Components
}
else
{
SetLightSourceState(true, lightBrightness * (1.0f - Rand.Range(0.0f, flicker)));
flickerState += deltaTime * FlickerSpeed;
flickerState %= 255;
float noise = PerlinNoise.GetPerlin(flickerState, flickerState * 0.5f) * flicker;
SetLightSourceState(true, lightBrightness * (1.0f - noise));
}
if (powerIn == null && powerConsumption > 0.0f) { Voltage -= deltaTime; }
@@ -254,7 +265,7 @@ namespace Barotrauma.Items.Components
switch (connection.Name)
{
case "toggle":
if (IgnoreContinuousToggle && lastToggleSignalTime < Timing.TotalTime - 0.1)
if (!IgnoreContinuousToggle || lastToggleSignalTime < Timing.TotalTime - 0.1)
{
IsOn = !IsOn;
}
@@ -4,7 +4,7 @@ namespace Barotrauma.Items.Components
{
class MemoryComponent : ItemComponent
{
[InGameEditable, Serialize("", true, description: "The currently stored signal the item outputs.")]
[InGameEditable, Serialize("", true, description: "The currently stored signal the item outputs.", alwaysUseInstanceValues: true)]
public string Value
{
get;
@@ -6,7 +6,7 @@ namespace Barotrauma.Items.Components
class ModuloComponent : ItemComponent
{
private float modulus;
[InGameEditable, Serialize(1.0f, false, description: "The modulus of the operation. Must be non-zero.")]
[InGameEditable, Serialize(1.0f, false, description: "The modulus of the operation. Must be non-zero.", alwaysUseInstanceValues: true)]
public float Modulus
{
get { return modulus; }
@@ -18,14 +18,14 @@ namespace Barotrauma.Items.Components
[Serialize(false, false, description: "Has the item currently detected movement. Intended to be used by StatusEffect conditionals (setting this value in XML has no effect).")]
public bool MotionDetected { get; set; }
[Editable, Serialize(false, true, description: "Should the sensor only detect the movement of humans?")]
[Editable, Serialize(false, true, description: "Should the sensor only detect the movement of humans?", alwaysUseInstanceValues: true)]
public bool OnlyHumans
{
get;
set;
}
[Editable, Serialize(false, true, description: "Should the sensor ignore the bodies of dead characters?")]
[Editable, Serialize(false, true, description: "Should the sensor ignore the bodies of dead characters?", alwaysUseInstanceValues: true)]
public bool IgnoreDead
{
get;
@@ -33,16 +33,19 @@ namespace Barotrauma.Items.Components
}
[InGameEditable, Serialize(0.0f, true, description: "Horizontal detection range.")]
[InGameEditable, Serialize(0.0f, true, description: "Horizontal detection range.", alwaysUseInstanceValues: true)]
public float RangeX
{
get { return rangeX; }
set
{
rangeX = MathHelper.Clamp(value, 0.0f, 1000.0f);
#if CLIENT
item.ResetCachedVisibleSize();
#endif
}
}
[InGameEditable, Serialize(0.0f, true, description: "Vertical movement detection range.")]
[InGameEditable, Serialize(0.0f, true, description: "Vertical movement detection range.", alwaysUseInstanceValues: true)]
public float RangeY
{
get { return rangeY; }
@@ -64,13 +67,13 @@ namespace Barotrauma.Items.Components
}
}
[InGameEditable, Serialize("1", true, description: "The signal the item outputs when it has detected movement.")]
[InGameEditable, Serialize("1", true, description: "The signal the item outputs when it has detected movement.", alwaysUseInstanceValues: true)]
public string Output { get; set; }
[InGameEditable, Serialize("", true, description: "The signal the item outputs when it has not detected movement.")]
[InGameEditable, Serialize("", true, description: "The signal the item outputs when it has not detected movement.", alwaysUseInstanceValues: true)]
public string FalseOutput { get; set; }
[Editable(DecimalCount = 3), Serialize(0.01f, true, description: "How fast the objects within the detector's range have to be moving (in m/s).")]
[Editable(DecimalCount = 3), Serialize(0.01f, true, description: "How fast the objects within the detector's range have to be moving (in m/s).", alwaysUseInstanceValues: true)]
public float MinimumVelocity
{
get;
@@ -129,7 +132,8 @@ namespace Barotrauma.Items.Components
foreach (Limb limb in c.AnimController.Limbs)
{
if (limb.LinearVelocity.LengthSquared() <= MinimumVelocity * MinimumVelocity) continue;
if (limb.IsSevered) { continue; }
if (limb.LinearVelocity.LengthSquared() <= MinimumVelocity * MinimumVelocity) { continue; }
if (MathUtils.CircleIntersectsRectangle(limb.WorldPosition, ConvertUnits.ToDisplayUnits(limb.body.GetMaxExtent()), detectRect))
{
MotionDetected = true;
@@ -23,14 +23,14 @@ namespace Barotrauma.Items.Components
[InGameEditable, Serialize(WaveType.Pulse, true, description: "What kind of a signal the item outputs." +
" Pulse: periodically sends out a signal of 1." +
" Sine: sends out a sine wave oscillating between -1 and 1." +
" Square: sends out a signal that alternates between 0 and 1.")]
" Square: sends out a signal that alternates between 0 and 1.", alwaysUseInstanceValues: true)]
public WaveType OutputType
{
get;
set;
}
[InGameEditable(DecimalCount = 2), Serialize(1.0f, true, description: "How fast the signal oscillates, or how fast the pulses are sent (in Hz).")]
[InGameEditable(DecimalCount = 2), Serialize(1.0f, true, description: "How fast the signal oscillates, or how fast the pulses are sent (in Hz).", alwaysUseInstanceValues: true)]
public float Frequency
{
get { return frequency; }
@@ -16,16 +16,16 @@ namespace Barotrauma.Items.Components
private bool nonContinuousOutputSent;
[InGameEditable, Serialize("1", true, description: "The signal this item outputs when the received signal matches the regular expression.")]
[InGameEditable, Serialize("1", true, description: "The signal this item outputs when the received signal matches the regular expression.", alwaysUseInstanceValues: true)]
public string Output { get; set; }
[Serialize("0", true, description: "The signal this item outputs when the received signal does not match the regular expression.")]
[Serialize("0", true, description: "The signal this item outputs when the received signal does not match the regular expression.", alwaysUseInstanceValues: true)]
public string FalseOutput { get; set; }
[InGameEditable, Serialize(true, true, description: "Should the component keep sending the output even after it stops receiving a signal, or only send an output when it receives a signal.")]
[InGameEditable, Serialize(true, true, description: "Should the component keep sending the output even after it stops receiving a signal, or only send an output when it receives a signal.", alwaysUseInstanceValues: true)]
public bool ContinuousOutput { get; set; }
[InGameEditable, Serialize("", true, description: "The regular expression used to check the incoming signals.")]
[InGameEditable, Serialize("", true, description: "The regular expression used to check the incoming signals.", alwaysUseInstanceValues: true)]
public string Expression
{
get { return expression; }
@@ -37,7 +37,7 @@ namespace Barotrauma.Items.Components
}
}
[Editable, Serialize(false, true, description: "Can the relay currently pass power and signals through it.")]
[Editable, Serialize(false, true, description: "Can the relay currently pass power and signals through it.", alwaysUseInstanceValues: true)]
public bool IsOn
{
get
@@ -4,12 +4,12 @@ namespace Barotrauma.Items.Components
{
class SignalCheckComponent : ItemComponent
{
[InGameEditable, Serialize("1", true, description: "The signal this item outputs when the received signal matches the target signal.")]
[InGameEditable, Serialize("1", true, description: "The signal this item outputs when the received signal matches the target signal.", alwaysUseInstanceValues: true)]
public string Output { get; set; }
[InGameEditable, Serialize("0", true, description: "The signal this item outputs when the received signal does not match the target signal.")]
[InGameEditable, Serialize("0", true, description: "The signal this item outputs when the received signal does not match the target signal.", alwaysUseInstanceValues: true)]
public string FalseOutput { get; set; }
[InGameEditable, Serialize("", true, description: "The value to compare the received signals against.")]
[InGameEditable, Serialize("", true, description: "The value to compare the received signals against.", alwaysUseInstanceValues: true)]
public string TargetSignal { get; set; }
public SignalCheckComponent(Item item, XElement element)
@@ -1,25 +1,51 @@
using System.Linq;
using System.Xml.Linq;
using System.Xml.Linq;
namespace Barotrauma.Items.Components
{
class SmokeDetector : ItemComponent
{
[Serialize(50.0f, false, description: "How large the fire has to be for the detector to react to it.")]
public float FireSizeThreshold
{
get; set;
}
const float FireCheckInterval = 1.0f;
private float fireCheckTimer;
private bool fireInRange;
[InGameEditable, Serialize("1", true, description: "The signal the item outputs when it has detected movement.", alwaysUseInstanceValues: true)]
public string Output { get; set; }
[InGameEditable, Serialize("0", true, description: "The signal the item outputs when it has not detected movement.", alwaysUseInstanceValues: true)]
public string FalseOutput { get; set; }
public SmokeDetector(Item item, XElement element)
: base (item, element)
: base(item, element)
{
IsActive = true;
}
private bool IsFireInRange()
{
if (item.CurrentHull == null || item.InWater) { return false; }
var connectedHulls = item.CurrentHull.GetConnectedHulls(includingThis: true, searchDepth: 10, ignoreClosedGaps: true);
foreach (Hull hull in connectedHulls)
{
foreach (FireSource fireSource in hull.FireSources)
{
if (fireSource.IsInDamageRange(item.WorldPosition, fireSource.DamageRange * 2.0f)) { return true; }
}
}
return false;
}
public override void Update(float deltaTime, Camera cam)
{
item.SendSignal(0, item.CurrentHull != null && item.CurrentHull.FireSources.Any(fs => fs.Size.X > FireSizeThreshold) ? "1" : "0", "signal_out", null);
fireCheckTimer -= deltaTime;
if (fireCheckTimer <= 0.0f)
{
fireInRange = IsFireInRange();
fireCheckTimer = FireCheckInterval;
}
item.SendSignal(0, fireInRange ? "1" : "0", "signal_out", null);
}
}
}
@@ -13,7 +13,7 @@ namespace Barotrauma.Items.Components
}
private string welcomeMessage;
[InGameEditable, Serialize("", true, "Message to be displayed on the terminal display when it is first opened.", translationTextTag = "terminalwelcomemsg.")]
[InGameEditable, Serialize("", true, "Message to be displayed on the terminal display when it is first opened.", translationTextTag = "terminalwelcomemsg.", AlwaysUseInstanceValues = true)]
public string WelcomeMessage
{
get { return welcomeMessage; }
@@ -19,14 +19,14 @@ namespace Barotrauma.Items.Components
protected float[] receivedSignal = new float[2];
[Serialize(FunctionType.Sin, false, description: "Which kind of function to run the input through.")]
[Serialize(FunctionType.Sin, false, description: "Which kind of function to run the input through.", alwaysUseInstanceValues: true)]
public FunctionType Function
{
get; set;
}
[InGameEditable, Serialize(false, true, description: "If set to true, the trigonometric function uses radians instead of degrees.")]
[InGameEditable, Serialize(false, true, description: "If set to true, the trigonometric function uses radians instead of degrees.", alwaysUseInstanceValues: true)]
public bool UseRadians
{
get; set;
@@ -10,10 +10,10 @@ namespace Barotrauma.Items.Components
private bool isInWater;
private float stateSwitchDelay;
[InGameEditable, Serialize("1", true, description: "The signal the item sends out when it's underwater.")]
[InGameEditable, Serialize("1", true, description: "The signal the item sends out when it's underwater.", alwaysUseInstanceValues: true)]
public string Output { get; set; }
[InGameEditable, Serialize("0", true, description: "The signal the item sends out when it's not underwater.")]
[InGameEditable, Serialize("0", true, description: "The signal the item sends out when it's not underwater.", alwaysUseInstanceValues: true)]
public string FalseOutput { get; set; }
public WaterDetector(Item item, XElement element)
@@ -9,7 +9,7 @@ namespace Barotrauma.Items.Components
{
partial class WifiComponent : ItemComponent
{
private static List<WifiComponent> list = new List<WifiComponent>();
private static readonly List<WifiComponent> list = new List<WifiComponent>();
private float range;
@@ -19,17 +19,23 @@ namespace Barotrauma.Items.Components
private string prevSignal;
[Serialize(Character.TeamType.None, true, description: "WiFi components can only communicate with components that have the same Team ID.")]
[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; }
[Editable, Serialize(20000.0f, false, description: "How close the recipient has to be to receive a signal from this WiFi component.")]
[Editable, Serialize(20000.0f, false, description: "How close the recipient has to be to receive a signal from this WiFi component.", alwaysUseInstanceValues: true)]
public float Range
{
get { return range; }
set { range = Math.Max(value, 0.0f); }
set
{
range = Math.Max(value, 0.0f);
#if CLIENT
item.ResetCachedVisibleSize();
#endif
}
}
[InGameEditable, Serialize(1, true, description: "WiFi components can only communicate with components that use the same channel.")]
[InGameEditable, Serialize(1, true, description: "WiFi components can only communicate with components that use the same channel.", alwaysUseInstanceValues: true)]
public int Channel
{
get { return channel; }
@@ -40,7 +46,7 @@ namespace Barotrauma.Items.Components
}
[Serialize(false, false, description: "Can the component communicate with wifi components in another team's submarine (e.g. enemy sub in Combat missions, respawn shuttle). Needs to be enabled on both the component transmitting the signal and the component receiving it.")]
[Serialize(false, false, description: "Can the component communicate with wifi components in another team's submarine (e.g. enemy sub in Combat missions, respawn shuttle). Needs to be enabled on both the component transmitting the signal and the component receiving it.", alwaysUseInstanceValues: true)]
public bool AllowCrossTeamCommunication
{
get;
@@ -48,7 +54,7 @@ namespace Barotrauma.Items.Components
}
[Editable, Serialize(false, false, description: "If enabled, any signals received from another chat-linked wifi component are displayed " +
"as chat messages in the chatbox of the player holding the item.")]
"as chat messages in the chatbox of the player holding the item.", alwaysUseInstanceValues: true)]
public bool LinkToChat
{
get;
@@ -105,12 +111,16 @@ namespace Barotrauma.Items.Components
public override void Update(float deltaTime, Camera cam)
{
chatMsgCooldown -= deltaTime;
if (chatMsgCooldown <= 0.0f)
{
IsActive = false;
}
}
public void TransmitSignal(int stepsTaken, string signal, Item source, Character sender, bool sendToChat, float signalStrength = 1.0f)
{
var senderComponent = source?.GetComponent<WifiComponent>();
if (senderComponent != null && !CanReceive(senderComponent)) return;
if (senderComponent != null && !CanReceive(senderComponent)) { return; }
bool chatMsgSent = false;
@@ -138,33 +148,32 @@ namespace Barotrauma.Items.Components
if (LinkToChat && wifiComp.LinkToChat && chatMsgCooldown <= 0.0f && sendToChat)
{
if (wifiComp.item.ParentInventory != null &&
wifiComp.item.ParentInventory.Owner != null &&
GameMain.NetworkMember != null)
wifiComp.item.ParentInventory.Owner != null)
{
string chatMsg = signal;
if (senderComponent != null)
{
chatMsg = ChatMessage.ApplyDistanceEffect(chatMsg, 1.0f - sentSignalStrength);
}
if (chatMsg.Length > ChatMessage.MaxLength) chatMsg = chatMsg.Substring(0, ChatMessage.MaxLength);
if (string.IsNullOrEmpty(chatMsg)) continue;
if (chatMsg.Length > ChatMessage.MaxLength) { chatMsg = chatMsg.Substring(0, ChatMessage.MaxLength); }
if (string.IsNullOrEmpty(chatMsg)) { continue; }
#if CLIENT
if (wifiComp.item.ParentInventory.Owner == Character.Controlled)
{
if (GameMain.Client == null)
GameMain.NetworkMember.AddChatMessage(signal, ChatMessageType.Radio, source == null ? "" : source.Name);
{
GameMain.GameSession?.CrewManager?.AddSinglePlayerChatMessage(source?.Name ?? "", signal, ChatMessageType.Radio, sender: null);
}
}
#endif
#if SERVER
#elif SERVER
if (GameMain.Server != null)
{
Client recipientClient = GameMain.Server.ConnectedClients.Find(c => c.Character == wifiComp.item.ParentInventory.Owner);
if (recipientClient != null)
{
GameMain.Server.SendDirectChatMessage(
ChatMessage.Create(source == null ? "" : source.Name, chatMsg, ChatMessageType.Radio, null), recipientClient);
ChatMessage.Create(source?.Name ?? "", chatMsg, ChatMessageType.Radio, null), recipientClient);
}
}
#endif
@@ -172,15 +181,31 @@ namespace Barotrauma.Items.Components
}
}
}
if (chatMsgSent) chatMsgCooldown = MinChatMessageInterval;
if (chatMsgSent)
{
chatMsgCooldown = MinChatMessageInterval;
IsActive = true;
}
prevSignal = signal;
}
public override void ReceiveSignal(int stepsTaken, string signal, Connection connection, Item source, Character sender, float power = 0.0f, float signalStrength = 1.0f)
{
if (connection == null || connection.Name != "signal_in") return;
TransmitSignal(stepsTaken, signal, source, sender, true, signalStrength);
if (connection == null) { return; }
switch (connection.Name)
{
case "signal_in":
TransmitSignal(stepsTaken, signal, source, sender, true, signalStrength);
break;
case "set_channel":
if (int.TryParse(signal, out int newChannel))
{
Channel = newChannel;
}
break;
}
}
protected override void RemoveComponentSpecific()
@@ -5,6 +5,9 @@ using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Xml.Linq;
#if CLIENT
using Microsoft.Xna.Framework.Input;
#endif
namespace Barotrauma.Items.Components
{
@@ -37,9 +40,11 @@ namespace Barotrauma.Items.Components
}
}
private bool shouldClearConnections = true;
const float MaxAttachDistance = 150.0f;
const float MinNodeDistance = 15.0f;
const float MinNodeDistance = 7.0f;
const int MaxNodeCount = 255;
const int MaxNodesPerNetworkEvent = 30;
@@ -177,6 +182,8 @@ namespace Barotrauma.Items.Components
newConnection.Item.Position :
newConnection.Item.Position - refSub.HiddenSubPosition;
nodePos = RoundNode(nodePos);
if (nodes.Count > 0 && nodes[0] == nodePos) { break; }
if (nodes.Count > 1 && nodes[nodes.Count - 1] == nodePos) { break; }
@@ -241,7 +248,7 @@ namespace Barotrauma.Items.Components
public override void Equip(Character character)
{
ClearConnections(character);
if (shouldClearConnections) { ClearConnections(character); }
IsActive = true;
}
@@ -253,7 +260,7 @@ namespace Barotrauma.Items.Components
public override void Drop(Character dropper)
{
ClearConnections(dropper);
if (shouldClearConnections) { ClearConnections(dropper); }
IsActive = false;
}
@@ -334,7 +341,12 @@ namespace Barotrauma.Items.Components
}
else
{
#if CLIENT
bool disableGrid = SubEditorScreen.IsSubEditor() && PlayerInput.IsShiftDown();
newNodePos = disableGrid ? item.Position : RoundNode(item.Position);
#else
newNodePos = RoundNode(item.Position);
#endif
if (sub != null) { newNodePos -= sub.HiddenSubPosition; }
canPlaceNode = true;
}
@@ -497,6 +509,9 @@ namespace Barotrauma.Items.Components
sectionExtents.Y = Math.Max(Math.Abs(nodes[i].Y - item.Position.Y), sectionExtents.Y);
}
}
#if CLIENT
item.ResetCachedVisibleSize();
#endif
}
public void ClearConnections(Character user = null)
@@ -507,7 +522,7 @@ namespace Barotrauma.Items.Components
foreach (Item item in Item.ItemList)
{
var connectionPanel = item.GetComponent<ConnectionPanel>();
if (connectionPanel != null && connectionPanel.DisconnectedWires.Contains(this))
if (connectionPanel != null && connectionPanel.DisconnectedWires.Contains(this) && !item.Removed)
{
#if SERVER
item.CreateServerEvent(connectionPanel);
@@ -526,18 +541,18 @@ namespace Barotrauma.Items.Components
if (connections[0] != null && connections[1] != null)
{
GameServer.Log(user.LogName + " disconnected a wire from " +
GameServer.Log(GameServer.CharacterLogName(user) + " disconnected a wire from " +
connections[0].Item.Name + " (" + connections[0].Name + ") to "+
connections[1].Item.Name + " (" + connections[1].Name + ")", ServerLog.MessageType.ItemInteraction);
}
else if (connections[0] != null)
{
GameServer.Log(user.LogName + " disconnected a wire from " +
GameServer.Log(GameServer.CharacterLogName(user) + " disconnected a wire from " +
connections[0].Item.Name + " (" + connections[0].Name + ")", ServerLog.MessageType.ItemInteraction);
}
else if (connections[1] != null)
{
GameServer.Log(user.LogName + " disconnected a wire from " +
GameServer.Log(GameServer.CharacterLogName(user) + " disconnected a wire from " +
connections[1].Item.Name + " (" + connections[1].Name + ")", ServerLog.MessageType.ItemInteraction);
}
}