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

@@ -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