(5a377a8ee) Unstable v0.9.1000.0
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user