A reference to the character who triggered a signal is passed to all the recipients of the signal. Allows more accurate server logging: using doors, docking ports or turrets is now properly logged.

This commit is contained in:
Regalis
2017-04-28 18:10:47 +03:00
parent 64c109f13b
commit 89941229f8
28 changed files with 120 additions and 81 deletions
@@ -57,10 +57,10 @@ namespace Barotrauma.Items.Components
string signalOut = sendOutput ? output : falseOutput;
if (string.IsNullOrEmpty(signalOut)) return;
item.SendSignal(0, signalOut, "signal_out");
item.SendSignal(0, signalOut, "signal_out", null);
}
public override void ReceiveSignal(int stepsTaken, string signal, Connection connection, Item sender, float power=0.0f)
public override void ReceiveSignal(int stepsTaken, string signal, Connection connection, Item source, Character sender, float power=0.0f)
{
switch (connection.Name)
{
@@ -155,7 +155,7 @@ namespace Barotrauma.Items.Components
Wires[index] = wire;
}
public void SendSignal(int stepsTaken, string signal, Item sender, float power)
public void SendSignal(int stepsTaken, string signal, Item source, Character sender, float power)
{
for (int i = 0; i < MaxLinked; i++)
{
@@ -163,11 +163,11 @@ namespace Barotrauma.Items.Components
Connection recipient = Wires[i].OtherConnection(this);
if (recipient == null) continue;
if (recipient.item == this.item || recipient.item == sender) continue;
if (recipient.item == this.item || recipient.item == source) continue;
foreach (ItemComponent ic in recipient.item.components)
{
ic.ReceiveSignal(stepsTaken, signal, recipient, this.item, power);
ic.ReceiveSignal(stepsTaken, signal, recipient, item, sender, power);
}
foreach (StatusEffect effect in recipient.effects)
@@ -42,11 +42,11 @@ namespace Barotrauma.Items.Components
{
var signalOut = signalQueue.Dequeue();
item.SendSignal(0, signalOut.Item1, "signal_out");
item.SendSignal(0, signalOut.Item1, "signal_out", null);
}
}
public override void ReceiveSignal(int stepsTaken, string signal, Connection connection, Item sender, float power=0.0f)
public override void ReceiveSignal(int stepsTaken, string signal, Connection connection, Item source, Character sender, float power=0.0f)
{
switch (connection.Name)
{
@@ -193,9 +193,9 @@ namespace Barotrauma.Items.Components
light.Remove();
}
public override void ReceiveSignal(int stepsTaken, string signal, Connection connection, Item sender, float power=0.0f)
public override void ReceiveSignal(int stepsTaken, string signal, Connection connection, Item source, Character sender, float power=0.0f)
{
base.ReceiveSignal(stepsTaken, signal, connection, sender, power);
base.ReceiveSignal(stepsTaken, signal, connection, source, sender, power);
switch (connection.Name)
{
@@ -54,15 +54,15 @@ namespace Barotrauma.Items.Components
{
if (motionDetected)
{
item.SendSignal(1, output, "state_out");
item.SendSignal(1, output, "state_out", null);
}
else if (!string.IsNullOrWhiteSpace(falseOutput))
{
item.SendSignal(1, falseOutput, "state_out");
item.SendSignal(1, falseOutput, "state_out", null);
}
updateTimer -= deltaTime;
if (updateTimer>0.0f) return;
if (updateTimer > 0.0f) return;
motionDetected = false;
updateTimer = UpdateInterval;
@@ -9,11 +9,11 @@ namespace Barotrauma.Items.Components
{
}
public override void ReceiveSignal(int stepsTaken, string signal, Connection connection, Item sender, float power=0.0f)
public override void ReceiveSignal(int stepsTaken, string signal, Connection connection, Item source, Character sender, float power=0.0f)
{
if (connection.Name != "signal_in") return;
item.SendSignal(stepsTaken, signal=="0" ? "1" : "0", "signal_out");
item.SendSignal(stepsTaken, signal=="0" ? "1" : "0", "signal_out", sender);
}
}
}
@@ -21,7 +21,7 @@ namespace Barotrauma.Items.Components
string signalOut = sendOutput ? output : falseOutput;
if (string.IsNullOrEmpty(signalOut)) return;
item.SendSignal(0, signalOut, "signal_out");
item.SendSignal(0, signalOut, "signal_out", null);
}
}
}
@@ -14,8 +14,7 @@ namespace Barotrauma.Items.Components
{
if (item.CurrentHull == null) return;
item.SendSignal(0, ((int)item.CurrentHull.OxygenPercentage).ToString(), "signal_out");
item.SendSignal(0, ((int)item.CurrentHull.OxygenPercentage).ToString(), "signal_out", null);
}
}
@@ -40,7 +40,7 @@ namespace Barotrauma.Items.Components
catch
{
item.SendSignal(0, "ERROR", "signal_out");
item.SendSignal(0, "ERROR", "signal_out", null);
return;
}
}
@@ -67,17 +67,17 @@ namespace Barotrauma.Items.Components
}
catch
{
item.SendSignal(0, "ERROR", "signal_out");
item.SendSignal(0, "ERROR", "signal_out", null);
previousResult = false;
return;
}
}
item.SendSignal(0, previousResult ? output : "0", "signal_out");
item.SendSignal(0, previousResult ? output : "0", "signal_out", null);
}
public override void ReceiveSignal(int stepsTaken, string signal, Connection connection, Item sender, float power = 0.0f)
public override void ReceiveSignal(int stepsTaken, string signal, Connection connection, Item source, Character sender, float power = 0.0f)
{
switch (connection.Name)
{
@@ -49,10 +49,10 @@ namespace Barotrauma.Items.Components
{
base.Update(deltaTime, cam);
item.SendSignal(0, IsOn ? "1" : "0", "state_out");
item.SendSignal(0, IsOn ? "1" : "0", "state_out", null);
}
public override void ReceiveSignal(int stepsTaken, string signal, Connection connection, Item sender, float power=0.0f)
public override void ReceiveSignal(int stepsTaken, string signal, Connection connection, Item source, Character sender, float power=0.0f)
{
if (connection.IsPower && connection.Name.Contains("_out")) return;
@@ -71,7 +71,7 @@ namespace Barotrauma.Items.Components
if (connectionNumber > 0) outConnection += connectionNumber;
item.SendSignal(stepsTaken, signal, outConnection, power);
item.SendSignal(stepsTaken, signal, outConnection, sender, power);
}
else if (connection.Name == "toggle")
{
@@ -33,7 +33,7 @@ namespace Barotrauma.Items.Components
{
}
public override void ReceiveSignal(int stepsTaken, string signal, Connection connection, Item sender, float power=0.0f)
public override void ReceiveSignal(int stepsTaken, string signal, Connection connection, Item source, Character sender, float power=0.0f)
{
switch (connection.Name)
{
@@ -41,7 +41,7 @@ namespace Barotrauma.Items.Components
string signalOut = (signal == targetSignal) ? output : falseOutput;
if (string.IsNullOrWhiteSpace(signalOut)) return;
item.SendSignal(stepsTaken, signalOut, "signal_out");
item.SendSignal(stepsTaken, signalOut, "signal_out", sender);
break;
case "set_output":
@@ -12,7 +12,7 @@ namespace Barotrauma.Items.Components
public override void Update(float deltaTime, Camera cam)
{
item.SendSignal(0, item.InWater ? "1" : "0", "signal_out");
item.SendSignal(0, item.InWater ? "1" : "0", "signal_out", null);
}
}
}
@@ -50,7 +50,7 @@ namespace Barotrauma.Items.Components
return HasRequiredContainedItems(true);
}
public void Transmit(string signal)
/*public void Transmit(string signal)
{
if (!CanTransmit()) return;
@@ -59,9 +59,9 @@ namespace Barotrauma.Items.Components
{
var connections = w.item.Connections;
w.ReceiveSignal(1, signal, connections == null ? null : connections.Find(c => c.Name == "signal_in"), item);
w.ReceiveSignal(1, signal, connections == null ? null : connections.Find(c => c.Name == "signal_in"), item, null);
}
}
}*/
private List<WifiComponent> GetReceiversInRange()
{
@@ -77,9 +77,9 @@ namespace Barotrauma.Items.Components
return Vector2.Distance(item.WorldPosition, sender.item.WorldPosition) <= sender.Range;
}
public override void ReceiveSignal(int stepsTaken, string signal, Connection connection, Item sender, float power=0.0f)
public override void ReceiveSignal(int stepsTaken, string signal, Connection connection, Item source, Character sender, float power=0.0f)
{
var senderComponent = sender.GetComponent<WifiComponent>();
var senderComponent = source.GetComponent<WifiComponent>();
if (senderComponent != null && !CanReceive(senderComponent)) return;
if (LinkToChat)
@@ -107,7 +107,7 @@ namespace Barotrauma.Items.Components
foreach (WifiComponent wifiComp in receivers)
{
wifiComp.item.SendSignal(stepsTaken, signal, "signal_out");
wifiComp.item.SendSignal(stepsTaken, signal, "signal_out", sender);
}
break;
}