Unstable 0.14.5.0
This commit is contained in:
@@ -525,7 +525,15 @@ namespace Barotrauma
|
||||
|
||||
public string GetOptionName(string id)
|
||||
{
|
||||
return Prefab == null ? OptionNames[id] : Prefab.OptionNames[id];
|
||||
if (Prefab == null)
|
||||
{
|
||||
if (OptionNames.ContainsKey(id)) { return OptionNames[id]; }
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Prefab.OptionNames.ContainsKey(id)) { return Prefab.OptionNames[id]; }
|
||||
}
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
public string GetOptionName(int index)
|
||||
|
||||
@@ -37,7 +37,14 @@ namespace Barotrauma
|
||||
|
||||
private static bool IsThalamus(MapEntityPrefab entityPrefab, string tag) => entityPrefab.HasSubCategory("thalamus") || entityPrefab.Tags.Contains(tag);
|
||||
|
||||
public WreckAI(Submarine wreck)
|
||||
public static WreckAI Create(Submarine wreck)
|
||||
{
|
||||
var wreckAI = new WreckAI(wreck);
|
||||
if (wreckAI.Config == null) { return null; }
|
||||
return wreckAI;
|
||||
}
|
||||
|
||||
private WreckAI(Submarine wreck)
|
||||
{
|
||||
Wreck = wreck;
|
||||
Config = WreckAIConfig.GetRandom();
|
||||
|
||||
@@ -2990,11 +2990,14 @@ namespace Barotrauma
|
||||
Spawner.AddToRemoveQueue(this);
|
||||
}
|
||||
|
||||
public void DespawnNow()
|
||||
public void DespawnNow(bool createNetworkEvents = true)
|
||||
{
|
||||
despawnTimer = GameMain.Config.CorpseDespawnDelay;
|
||||
UpdateDespawn(1.0f, ignoreThresholds: true);
|
||||
Spawner.Update();
|
||||
if (createNetworkEvents)
|
||||
{
|
||||
Spawner.Update();
|
||||
}
|
||||
}
|
||||
|
||||
public static void RemoveByPrefab(CharacterPrefab prefab)
|
||||
|
||||
@@ -627,7 +627,10 @@ namespace Barotrauma
|
||||
Kill();
|
||||
}
|
||||
#if CLIENT
|
||||
selectedLimbIndex = -1;
|
||||
if (CharacterHealth.OpenHealthWindow != this)
|
||||
{
|
||||
selectedLimbIndex = -1;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -154,5 +154,22 @@ namespace Barotrauma.Extensions
|
||||
{
|
||||
if (value != null) { source.Add(value); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns whether a given collection has at least a certain amount
|
||||
/// of elements for which the predicate returns true.
|
||||
/// </summary>
|
||||
/// <param name="source">Input collection</param>
|
||||
/// <param name="amount">How many elements to match before stopping</param>
|
||||
/// <param name="predicate">Predicate used to evaluate the elements</param>
|
||||
public static bool AtLeast<T>(this IEnumerable<T> source, int amount, Predicate<T> predicate)
|
||||
{
|
||||
foreach (T elem in source)
|
||||
{
|
||||
if (predicate(elem)) { amount--; }
|
||||
if (amount <= 0) { return true; }
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -599,7 +599,7 @@ namespace Barotrauma
|
||||
if (c.IsDead)
|
||||
{
|
||||
CrewManager.RemoveCharacterInfo(c.Info);
|
||||
c.DespawnNow();
|
||||
c.DespawnNow(createNetworkEvents: false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -783,7 +783,7 @@ namespace Barotrauma.Items.Components
|
||||
case "set_fissionrate":
|
||||
if (PowerOn && float.TryParse(signal.value, NumberStyles.Float, CultureInfo.InvariantCulture, out float newFissionRate))
|
||||
{
|
||||
targetFissionRate = newFissionRate;
|
||||
targetFissionRate = MathHelper.Clamp(newFissionRate, 0.0f, 100.0f);
|
||||
if (GameMain.NetworkMember?.IsServer ?? false) { unsentChanges = true; }
|
||||
#if CLIENT
|
||||
FissionRateScrollBar.BarScroll = targetFissionRate / 100.0f;
|
||||
@@ -793,7 +793,7 @@ namespace Barotrauma.Items.Components
|
||||
case "set_turbineoutput":
|
||||
if (PowerOn && float.TryParse(signal.value, NumberStyles.Float, CultureInfo.InvariantCulture, out float newTurbineOutput))
|
||||
{
|
||||
targetTurbineOutput = newTurbineOutput;
|
||||
targetTurbineOutput = MathHelper.Clamp(newTurbineOutput, 0.0f, 100.0f);
|
||||
if (GameMain.NetworkMember?.IsServer ?? false) { unsentChanges = true; }
|
||||
#if CLIENT
|
||||
TurbineOutputScrollBar.BarScroll = targetTurbineOutput / 100.0f;
|
||||
|
||||
@@ -359,7 +359,7 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
//other junction boxes don't need to receive the signal in the pass-through signal connections
|
||||
//because we relay it straight to the connected items without going through the whole chain of junction boxes
|
||||
if (ic is PowerTransfer && !(ic is RelayComponent) && connection.Name.Contains("signal")) { continue; }
|
||||
if (ic is PowerTransfer && !(ic is RelayComponent)) { continue; }
|
||||
ic.ReceiveSignal(signal, recipient);
|
||||
}
|
||||
|
||||
|
||||
@@ -19,5 +19,22 @@ namespace Barotrauma.Items.Components
|
||||
this.power = power;
|
||||
this.strength = strength;
|
||||
}
|
||||
|
||||
internal Signal WithStepsTaken(int stepsTaken)
|
||||
{
|
||||
Signal retVal = this;
|
||||
retVal.stepsTaken = stepsTaken;
|
||||
return retVal;
|
||||
}
|
||||
|
||||
public static bool operator==(Signal a, Signal b) =>
|
||||
a.value == b.value &&
|
||||
a.stepsTaken == b.stepsTaken &&
|
||||
a.sender == b.sender &&
|
||||
a.source == b.source &&
|
||||
MathUtils.NearlyEqual(a.power, b.power) &&
|
||||
MathUtils.NearlyEqual(a.strength, b.strength);
|
||||
|
||||
public static bool operator!=(Signal a, Signal b) => !(a == b);
|
||||
}
|
||||
}
|
||||
|
||||
+8
-3
@@ -64,6 +64,7 @@ namespace Barotrauma.Items.Components
|
||||
public override void ReceiveSignal(Signal signal, Connection connection)
|
||||
{
|
||||
float.TryParse(signal.value, NumberStyles.Float, CultureInfo.InvariantCulture, out float value);
|
||||
bool sendOutputImmediately = true;
|
||||
switch (Function)
|
||||
{
|
||||
case FunctionType.Sin:
|
||||
@@ -105,11 +106,13 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
timeSinceReceived[0] = 0.0f;
|
||||
float.TryParse(signal.value, NumberStyles.Float, CultureInfo.InvariantCulture, out receivedSignal[0]);
|
||||
sendOutputImmediately = false;
|
||||
}
|
||||
else if (connection.Name == "signal_in_y")
|
||||
{
|
||||
timeSinceReceived[1] = 0.0f;
|
||||
float.TryParse(signal.value, NumberStyles.Float, CultureInfo.InvariantCulture, out receivedSignal[1]);
|
||||
sendOutputImmediately = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -121,9 +124,11 @@ namespace Barotrauma.Items.Components
|
||||
default:
|
||||
throw new NotImplementedException($"Function {Function} has not been implemented.");
|
||||
}
|
||||
|
||||
signal.value = value.ToString("G", CultureInfo.InvariantCulture);
|
||||
item.SendSignal(signal, "signal_out");
|
||||
if (sendOutputImmediately)
|
||||
{
|
||||
signal.value = value.ToString("G", CultureInfo.InvariantCulture);
|
||||
item.SendSignal(signal, "signal_out");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2005,26 +2005,36 @@ namespace Barotrauma
|
||||
SendSignal(signal, connection);
|
||||
}
|
||||
|
||||
private readonly HashSet<(Signal Signal, Connection Connection)> delayedSignals = new HashSet<(Signal Signal, Connection Connection)>();
|
||||
|
||||
public void SendSignal(Signal signal, Connection connection)
|
||||
{
|
||||
LastSentSignalRecipients.Clear();
|
||||
if (connections == null || connection == null) { return; }
|
||||
|
||||
signal.stepsTaken++;
|
||||
|
||||
|
||||
//if the signal has been passed through this item multiple times already, interrupt it to prevent infinite loops
|
||||
if (signal.stepsTaken > 5 && signal.source != null)
|
||||
{
|
||||
if (signal.source.LastSentSignalRecipients.AtLeast(3, recipient => recipient == connection))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//use a coroutine to prevent infinite loops by creating a one
|
||||
//frame delay if the "signal chain" gets too long
|
||||
if (signal.stepsTaken > 10)
|
||||
{
|
||||
//if the signal has been passed through this item multiple times already, interrupt it to prevent infinite loops
|
||||
if (signal.source != null)
|
||||
//if there's an equal signal waiting to be sent
|
||||
//to the same connection, don't add a new one
|
||||
signal.stepsTaken = 0;
|
||||
if (!delayedSignals.Contains((signal, connection)))
|
||||
{
|
||||
if (signal.source.LastSentSignalRecipients.Count(recipient => recipient == connection) > 2)
|
||||
{
|
||||
return;
|
||||
}
|
||||
delayedSignals.Add((signal, connection));
|
||||
CoroutineManager.StartCoroutine(DelaySignal(signal, connection));
|
||||
}
|
||||
//use a coroutine to prevent infinite loops by creating a one
|
||||
//frame delay if the "signal chain" gets too long
|
||||
CoroutineManager.StartCoroutine(DelaySignal(signal, connection));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -2045,7 +2055,8 @@ namespace Barotrauma
|
||||
//wait one frame
|
||||
yield return CoroutineStatus.Running;
|
||||
|
||||
signal.stepsTaken = 0;
|
||||
delayedSignals.Remove((signal, connection));
|
||||
|
||||
signal.source = this;
|
||||
connection.SendSignal(signal);
|
||||
|
||||
|
||||
@@ -374,7 +374,7 @@ namespace Barotrauma
|
||||
public WreckAI WreckAI { get; private set; }
|
||||
public bool CreateWreckAI()
|
||||
{
|
||||
WreckAI = new WreckAI(this);
|
||||
WreckAI = WreckAI.Create(this);
|
||||
return WreckAI != null;
|
||||
}
|
||||
|
||||
@@ -1570,7 +1570,7 @@ namespace Barotrauma
|
||||
Rectangle dimensions = CalculateDimensions();
|
||||
element.Add(new XAttribute("dimensions", XMLExtensions.Vector2ToString(dimensions.Size.ToVector2())));
|
||||
var cargoContainers = GetCargoContainers();
|
||||
element.Add(new XAttribute("cargocapacity", cargoContainers.Sum(c => c.freeSlots)));
|
||||
element.Add(new XAttribute("cargocapacity", cargoContainers.Sum(c => c.container.Capacity)));
|
||||
element.Add(new XAttribute("recommendedcrewsizemin", Info.RecommendedCrewSizeMin));
|
||||
element.Add(new XAttribute("recommendedcrewsizemax", Info.RecommendedCrewSizeMax));
|
||||
element.Add(new XAttribute("recommendedcrewexperience", Info.RecommendedCrewExperience ?? ""));
|
||||
|
||||
Reference in New Issue
Block a user