Motion sensor component, ruins have doors and hatches with randomly placed motion sensors that close them automatically

This commit is contained in:
Regalis
2016-05-07 09:09:09 +03:00
parent 03626c997b
commit ef05650c01
11 changed files with 207 additions and 11 deletions

View File

@@ -122,6 +122,7 @@
<Compile Include="Source\Items\Components\Holdable\Propulsion.cs" />
<Compile Include="Source\Items\Components\Machines\Deconstructor.cs" />
<Compile Include="Source\Items\Components\Signal\DelayComponent.cs" />
<Compile Include="Source\Items\Components\Signal\MotionSensor.cs" />
<Compile Include="Source\Items\Components\Signal\RelayComponent.cs" />
<Compile Include="Source\Items\Components\Signal\WaterDetector.cs" />
<Compile Include="Source\Items\Components\Signal\WifiComponent.cs" />
@@ -1048,6 +1049,9 @@
<None Include="Content\effects.mgfx">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Content\Items\Artifacts\aliendoor.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Content\Items\Artifacts\alienweapon.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>

Binary file not shown.

View File

@@ -144,4 +144,61 @@
</ItemContainer>
</Item>
<Item
name="Alien Hatch"
category="Alien"
linkable="true"
pickdistance="150.0">
<Sprite texture="Content/Map/ruins.png" sourcerect="0,842,260,54" depth="0.01" origin="0.5,0.5"/>
<Door canbeselected="true" horizontal="true">
<Sprite texture="Content/Map/ruins.png" sourcerect="747,0,260,95" depth="0.05" origin="0.0,0.5"/>
<sound file="aliendoor.ogg" type="OnUse" range="1000.0"/>
</Door>
<ConnectionPanel selectkey="Action" canbeselected = "true" msg="Rewire [Screwdriver]">
<requireditem name="Screwdriver" type="Equipped"/>
<input name="toggle"/>
<input name="set_state"/>
<output name="state_out"/>
</ConnectionPanel>
</Item>
<Item
name="Alien Door"
category="Alien"
linkable="true"
pickdistance="150.0">
<Sprite texture="Content/Map/ruins.png" sourcerect="842,192,54,259" depth="0.8" origin="0.5,0.5"/>
<Door canbeselected="true">
<Sprite texture="Content/Map/ruins.png" sourcerect="746,101,93,259" depth="0.6" origin="0.5,0.0"/>
<sound file="aliendoor.ogg" type="OnUse" range="3000.0"/>
</Door>
<ConnectionPanel selectkey="Action" canbeselected = "true" msg="Rewire [Screwdriver]">
<requireditem name="Screwdriver" type="Equipped"/>
<input name="toggle"/>
<input name="set_state"/>
<output name="state_out"/>
</ConnectionPanel>
</Item>
<Item
name="Alien Motion Sensor"
linkable="true"
category="Alien"
pickdistance="150.0">
<Sprite texture="Content/Map/ruins.png" sourcerect="55,608,81,103" depth="0.8" origin="0.5,0.5"/>
<MotionSensor range="300" output="0"/>
<ConnectionPanel selectkey="Action" canbeselected = "true" msg="Rewire [Screwdriver]">
<requireditem name="Screwdriver" type="Equipped"/>
<output name="state_out"/>
</ConnectionPanel>
</Item>
</Items>

View File

@@ -20,5 +20,7 @@
<item prefab="Sulphurite Shard" alignment="Center,Right,Top,Bottom,Left" type="Prop" commonness="5"/>
<item prefab="Ancient Weapon" alignment="Center,Right,Top,Bottom,Left" type="Prop" commonness="1"/>
<item prefab="Alien Door" alignment="Center" type="Door"/>
<item prefab="Alien Hatch" alignment="Center" type="Hatch"/>
</Structures>

View File

@@ -109,16 +109,17 @@
<bunk sprite="Content/Map/testroom.png" fliphorizontal="true" sourcerect="0,546,173,129"
width="173" height="129" depth = "0.9"/>
<RuinWallHorizontal category="Alien" sprite="Content/Map/ruins.png" sourcerect="0,896,832,128" depth ="0.95" castshadow="true"
width = "128" height ="128" resizehorizontal="true" body="true" health="500"/>
<RuinWallVertical category="Alien" sprite="Content/Map/ruins.png" sourcerect="896,0,128,832" depth ="0.94" castshadow="true"
<RuinWallVertical category="Alien" sprite="Content/Map/ruins.png" sourcerect="896,192,128,832" depth ="0.94" castshadow="true"
width = "128" height ="128" resizevertical="true" body="true" health="500"/>
<RuinWallHorizontalSmall category="Alien" sprite="Content/Map/ruins.png" sourcerect="0,842,832,54" depth ="0.95" castshadow="true"
width = "128" height ="54" resizehorizontal="true" body="true" health="500"/>
<RuinWallVerticalSmall category="Alien" sprite="Content/Map/ruins.png" sourcerect="842,0,54,832" depth ="0.96" castshadow="true"
<RuinWallVerticalSmall category="Alien" sprite="Content/Map/ruins.png" sourcerect="842,192,54,832" depth ="0.96" castshadow="true"
width = "54" height ="128" resizevertical="true" body="true" health="500"/>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 MiB

After

Width:  |  Height:  |  Size: 1.6 MiB

View File

@@ -127,13 +127,14 @@ namespace Barotrauma.Items.Components
// isOpen = false;
foreach (XElement subElement in element.Elements())
{
string texturePath = ToolBox.GetAttributeString(subElement, "texture", "");
switch (subElement.Name.ToString().ToLowerInvariant())
{
case "sprite":
doorSprite = new Sprite(subElement, Path.GetDirectoryName(item.Prefab.ConfigFile));
doorSprite = new Sprite(subElement, texturePath.Contains("/") ? "" : Path.GetDirectoryName(item.Prefab.ConfigFile));
break;
case "weldedsprite":
weldedSprite = new Sprite(subElement, Path.GetDirectoryName(item.Prefab.ConfigFile));
weldedSprite = new Sprite(subElement, texturePath.Contains("/") ? "" : Path.GetDirectoryName(item.Prefab.ConfigFile));
break;
}
}
@@ -336,7 +337,7 @@ namespace Barotrauma.Items.Components
pos.Y = -pos.Y;
spriteBatch.Draw(doorSprite.Texture, pos,
new Rectangle(doorSprite.SourceRect.X, (int)(doorSprite.size.Y * openState),
new Rectangle(doorSprite.SourceRect.X, (int)(doorSprite.SourceRect.Y + doorSprite.size.Y * openState),
(int)doorSprite.size.X, (int)(doorSprite.size.Y * (1.0f - openState))),
color, 0.0f, doorSprite.Origin, 1.0f, SpriteEffects.None, doorSprite.Depth);
}
@@ -346,6 +347,7 @@ namespace Barotrauma.Items.Components
public override void OnMapLoaded()
{
LinkedGap.ConnectedDoor = this;
LinkedGap.Open = openState;
Vector2[] corners = GetConvexHullCorners(doorRect);

View File

@@ -0,0 +1,91 @@
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace Barotrauma.Items.Components
{
class MotionSensor : ItemComponent
{
private const float UpdateInterval = 0.1f;
private string output, falseOutput;
private bool motionDetected;
private float range;
private float updateTimer;
[InGameEditable, HasDefaultValue(0.0f, true)]
public float Range
{
get { return range; }
set
{
range = MathHelper.Clamp(value, 0.0f, 500.0f);
}
}
[InGameEditable, HasDefaultValue("1", true)]
public string Output
{
get { return output; }
set { output = value; }
}
[InGameEditable, HasDefaultValue("", true)]
public string FalseOutput
{
get { return falseOutput; }
set { falseOutput = value; }
}
public MotionSensor(Item item, XElement element)
: base (item, element)
{
IsActive = true;
}
public override void Update(float deltaTime, Camera cam)
{
if (motionDetected)
{
item.SendSignal(1, output, "state_out");
}
else if (!string.IsNullOrWhiteSpace(falseOutput))
{
item.SendSignal(1, falseOutput, "state_out");
}
updateTimer -= deltaTime;
if (updateTimer>0.0f) return;
motionDetected = false;
updateTimer = UpdateInterval;
if (item.body != null && item.body.Enabled)
{
if (Math.Abs(item.body.LinearVelocity.X) > 0.01f || Math.Abs(item.body.LinearVelocity.Y) > 0.1f)
{
motionDetected = true;
}
}
foreach (Character c in Character.CharacterList)
{
if (Math.Abs(c.WorldPosition.X - item.WorldPosition.X) < range &&
Math.Abs(c.WorldPosition.Y - item.WorldPosition.Y) < range)
{
if (!c.AnimController.Limbs.Any(l => l.body.FarseerBody.Awake)) continue;
motionDetected = true;
break;
}
}
}
}
}

View File

@@ -175,11 +175,12 @@ namespace Barotrauma
Rand.SetSyncedSeed(ToolBox.StringToInt(seed));
float brightness = Rand.Range(1.0f, 1.3f, false);
backgroundColor = Color.Lerp(new Color(11, 18, 26), new Color(11, 26, 18), Rand.Range(0.0f, 1.0f, false)) * brightness;
backgroundColor = Color.Lerp(new Color(11, 18, 26), new Color(50, 46, 20), Rand.Range(0.0f, 1.0f, false)) * brightness;
backgroundColor = new Color(backgroundColor, 1.0f);
float avgValue = (backgroundColor.R + backgroundColor.G + backgroundColor.G) / 3;
GameMain.LightManager.AmbientLight = new Color(backgroundColor*(40.0f/avgValue), 1.0f);
float minWidth = Submarine.Loaded == null ? 0.0f : Math.Max(Submarine.Borders.Width, Submarine.Borders.Height);
minWidth = Math.Max(minWidth, 6500.0f);
@@ -789,7 +790,7 @@ namespace Barotrauma
public void Update (float deltaTime)
{
if (Submarine.Loaded!=null)
if (Submarine.Loaded != null)
{
WrappingWall.UpdateWallShift(Submarine.Loaded.WorldPosition, wrappingWalls);
}
@@ -879,6 +880,8 @@ namespace Barotrauma
if (renderer!=null) renderer.Dispose();
renderer = null;
ruins.Clear();
for (int side = 0; side < 2; side++)
{
for (int i = 0; i < 2; i++)

View File

@@ -412,6 +412,42 @@ namespace Barotrauma.RuinGeneration
}
}
var sensorPrefab = ItemPrefab.list.Find(ip => ip.Name == "Alien Motion Sensor") as ItemPrefab;
var wirePrefab = ItemPrefab.list.Find(ip => ip.Name == "Wire") as ItemPrefab;
foreach (Corridor corridor in corridors)
{
var door = RuinStructure.GetRandom(corridor.IsHorizontal ? RuinStructureType.Door : RuinStructureType.Hatch, Alignment.Center);
if (door == null) continue;
var item = new Item(door.Prefab as ItemPrefab, corridor.Center - new Vector2(door.Prefab.sprite.size.X, -door.Prefab.sprite.size.Y)/2.0f, null);
item.MoveWithLevel = true;
item.GetComponent<Items.Components.Door>().IsOpen = Rand.Range(0.0f, 1.0f, false) < 0.8f;
if (sensorPrefab == null || wirePrefab == null) continue;
var sensorRoom = corridor.ConnectedRooms.FirstOrDefault(r => r != null && rooms.Contains(r));
if (sensorRoom == null) continue;
var sensor = new Item(sensorPrefab, new Vector2(
Rand.Range(sensorRoom.Rect.X, sensorRoom.Rect.Right, false),
Rand.Range(sensorRoom.Rect.Y, sensorRoom.Rect.Bottom,false)), null);
sensor.MoveWithLevel = true;
var wire = new Item(wirePrefab, sensorRoom.Center, null).GetComponent<Items.Components.Wire>();
wire.Item.MoveWithLevel = false;
var conn1 = item.Connections.Find(c => c.Name == "set_state");
conn1.AddLink(0, wire);
wire.Connect(conn1, false);
var conn2 = sensor.Connections.Find(c => c.Name == "state_out");
conn2.AddLink(0, wire);
wire.Connect(conn2, false);
}
return shapes;
}

View File

@@ -10,7 +10,7 @@ namespace Barotrauma.RuinGeneration
[Flags]
enum RuinStructureType
{
Wall = 1, CorridorWall = 2, Prop = 4, Back = 8
Wall = 1, CorridorWall = 2, Prop = 4, Back = 8, Door=16, Hatch=32
}
class RuinStructure