Merge branch 'master' into new-netcode
Conflicts: Subsurface/Properties/AssemblyInfo.cs Subsurface/Source/Characters/Animation/HumanoidAnimController.cs Subsurface/Source/Characters/Character.cs Subsurface/Source/Items/Components/Door.cs Subsurface/Source/Items/Components/Power/PowerContainer.cs Subsurface/Source/Items/Components/Signal/Wire.cs Subsurface/Source/Items/Item.cs Subsurface/Source/Networking/ChatMessage.cs Subsurface/Source/Networking/GameClient.cs Subsurface/Source/Networking/GameServer.cs Subsurface/Source/Networking/GameServerLogin.cs Subsurface/Source/Networking/GameServerSettings.cs Subsurface/Source/Networking/NetworkMember.cs
This commit is contained in:
@@ -110,7 +110,14 @@ namespace Barotrauma
|
||||
List<Entity> list = new List<Entity>(dictionary.Values);
|
||||
foreach (Entity e in list)
|
||||
{
|
||||
e.Remove();
|
||||
try
|
||||
{
|
||||
e.Remove();
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
DebugConsole.ThrowError("Error while removing entity \"" + e.ToString() + "\"", exception);
|
||||
}
|
||||
}
|
||||
dictionary.Clear();
|
||||
}
|
||||
|
||||
@@ -114,6 +114,11 @@ namespace Barotrauma
|
||||
InsertToList();
|
||||
}
|
||||
|
||||
public override MapEntity Clone()
|
||||
{
|
||||
return new Gap(rect, isHorizontal, Submarine);
|
||||
}
|
||||
|
||||
public override void Move(Vector2 amount)
|
||||
{
|
||||
base.Move(amount);
|
||||
@@ -210,7 +215,7 @@ namespace Barotrauma
|
||||
isHorizontal ? new Vector2(rect.Height / 16.0f, 1.0f) : new Vector2(rect.Width / 16.0f, 1.0f));
|
||||
}
|
||||
|
||||
if (isSelected)
|
||||
if (IsSelected)
|
||||
{
|
||||
GUI.DrawRectangle(sb,
|
||||
new Vector2(WorldRect.X - 5, -WorldRect.Y - 5),
|
||||
@@ -247,7 +252,7 @@ namespace Barotrauma
|
||||
|
||||
lerpedFlowForce = Vector2.Lerp(lerpedFlowForce, flowForce, deltaTime);
|
||||
|
||||
if (LerpedFlowForce.Length() > 100.0f && flowTargetHull != null && flowTargetHull.Volume < flowTargetHull.FullVolume)
|
||||
if (LerpedFlowForce.LengthSquared() > 10000.0f && flowTargetHull != null && flowTargetHull.Volume < flowTargetHull.FullVolume)
|
||||
{
|
||||
//UpdateFlowForce();
|
||||
|
||||
@@ -526,7 +531,7 @@ namespace Barotrauma
|
||||
|
||||
//a variable affecting the water flow through the gap
|
||||
//the larger the gap is, the faster the water flows
|
||||
float sizeModifier = size * open;
|
||||
float sizeModifier = size * open * open;
|
||||
|
||||
float delta = Hull.MaxCompress * sizeModifier * deltaTime;
|
||||
|
||||
@@ -557,12 +562,10 @@ namespace Barotrauma
|
||||
if (hull1.Volume < hull1.FullVolume - Hull.MaxCompress &&
|
||||
hull1.Surface < rect.Y)
|
||||
{
|
||||
|
||||
|
||||
if (rect.X > hull1.Rect.X + hull1.Rect.Width / 2.0f)
|
||||
{
|
||||
float vel = ((rect.Y - rect.Height / 2) - (hull1.Surface + hull1.WaveY[hull1.WaveY.Length - 1])) * 0.1f;
|
||||
|
||||
vel *= Math.Min(Math.Abs(flowForce.X) / 200.0f, 1.0f);
|
||||
|
||||
hull1.WaveVel[hull1.WaveY.Length - 1] += vel;
|
||||
hull1.WaveVel[hull1.WaveY.Length - 2] += vel;
|
||||
@@ -570,11 +573,11 @@ namespace Barotrauma
|
||||
else
|
||||
{
|
||||
float vel = ((rect.Y - rect.Height / 2) - (hull1.Surface + hull1.WaveY[0])) * 0.1f;
|
||||
|
||||
vel *= Math.Min(Math.Abs(flowForce.X) / 200.0f, 1.0f);
|
||||
|
||||
hull1.WaveVel[0] += vel;
|
||||
hull1.WaveVel[1] += vel;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -261,6 +261,11 @@ namespace Barotrauma
|
||||
|
||||
return rect;
|
||||
}
|
||||
|
||||
public override MapEntity Clone()
|
||||
{
|
||||
return new Hull(MapEntityPrefab.list.Find(m => m.Name == "Hull"), rect, Submarine);
|
||||
}
|
||||
|
||||
public static EntityGrid GenerateEntityGrid(Submarine submarine)
|
||||
{
|
||||
@@ -330,7 +335,7 @@ namespace Barotrauma
|
||||
base.Remove();
|
||||
hullList.Remove(this);
|
||||
|
||||
if (Submarine == null || !Submarine.Loading)
|
||||
if (Submarine == null || (!Submarine.Loading && !Submarine.Unloading))
|
||||
{
|
||||
Item.UpdateHulls();
|
||||
Gap.UpdateHulls();
|
||||
@@ -605,7 +610,7 @@ namespace Barotrauma
|
||||
|
||||
}
|
||||
|
||||
if ((isSelected || isHighlighted) && editing)
|
||||
if ((IsSelected || isHighlighted) && editing)
|
||||
{
|
||||
GUI.DrawRectangle(spriteBatch,
|
||||
new Vector2(drawRect.X + 5, -drawRect.Y + 5),
|
||||
|
||||
@@ -54,7 +54,7 @@ namespace Barotrauma
|
||||
public const int GridCellSize = 2000;
|
||||
private List<VoronoiCell>[,] cellGrid;
|
||||
|
||||
private WrappingWall[,] wrappingWalls;
|
||||
//private WrappingWall[,] wrappingWalls;
|
||||
|
||||
//private float shaftHeight;
|
||||
|
||||
@@ -97,10 +97,10 @@ namespace Barotrauma
|
||||
get { return ruins; }
|
||||
}
|
||||
|
||||
public WrappingWall[,] WrappingWalls
|
||||
{
|
||||
get { return wrappingWalls; }
|
||||
}
|
||||
//public WrappingWall[,] WrappingWalls
|
||||
//{
|
||||
// get { return wrappingWalls; }
|
||||
//}
|
||||
|
||||
public string Seed
|
||||
{
|
||||
@@ -187,11 +187,11 @@ namespace Barotrauma
|
||||
minWidth = Math.Max(minWidth, 6500.0f);
|
||||
|
||||
startPosition = new Vector2(
|
||||
Rand.Range(minWidth * 2, minWidth * 4, false),
|
||||
Rand.Range(minWidth, minWidth * 2, false),
|
||||
Rand.Range(borders.Height * 0.5f, borders.Height - minWidth * 2, false));
|
||||
|
||||
endPosition = new Vector2(
|
||||
borders.Width - Rand.Range(minWidth * 2, minWidth * 4, false),
|
||||
borders.Width - Rand.Range(minWidth, minWidth * 2, false),
|
||||
Rand.Range(borders.Height * 0.5f, borders.Height - minWidth * 2, false));
|
||||
|
||||
List<Vector2> pathNodes = new List<Vector2>();
|
||||
@@ -211,8 +211,12 @@ namespace Barotrauma
|
||||
|
||||
pathNodes.Add(new Vector2(endPosition.X, borders.Height));
|
||||
|
||||
List<List<Vector2>> smallTunnels = new List<List<Vector2>>();
|
||||
if (pathNodes.Count <= 2)
|
||||
{
|
||||
pathNodes.Add((startPosition + endPosition) / 2);
|
||||
}
|
||||
|
||||
List<List<Vector2>> smallTunnels = new List<List<Vector2>>();
|
||||
for (int i = 0; i < generationParams.SmallTunnelCount; i++)
|
||||
{
|
||||
var tunnelStartPos = pathNodes[Rand.Range(2, pathNodes.Count - 2, false)];
|
||||
@@ -421,7 +425,8 @@ namespace Barotrauma
|
||||
|
||||
cellGrid[x, y].Add(cell);
|
||||
}
|
||||
|
||||
|
||||
ruins = new List<Ruin>();
|
||||
for (int i = 0; i<generationParams.RuinCount; i++)
|
||||
{
|
||||
GenerateRuin(mainPath);
|
||||
@@ -440,6 +445,7 @@ namespace Barotrauma
|
||||
|
||||
renderer.PlaceSprites(generationParams.BackgroundSpriteAmount);
|
||||
|
||||
/*
|
||||
wrappingWalls = new WrappingWall[2, 2];
|
||||
|
||||
Rectangle ignoredArea = new Rectangle((int)startPosition.X, 0, (int)(endPosition.X - startPosition.X), borders.Height);
|
||||
@@ -465,7 +471,7 @@ namespace Barotrauma
|
||||
{
|
||||
cells.AddRange(wrappingWalls[side, i].Cells);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
ShaftBody = BodyFactory.CreateEdge(GameMain.World,
|
||||
ConvertUnits.ToSimUnits(new Vector2(borders.X, 0)),
|
||||
@@ -725,8 +731,6 @@ namespace Barotrauma
|
||||
}
|
||||
|
||||
var ruin = new Ruin(closestPathCell, cells, new Rectangle((ruinPos - ruinSize * 0.5f).ToPoint(), ruinSize.ToPoint()));
|
||||
|
||||
ruins = new List<Ruin>();
|
||||
ruins.Add(ruin);
|
||||
|
||||
ruin.RuinShapes.Sort((shape1, shape2) => shape2.DistanceFromEntrance.CompareTo(shape1.DistanceFromEntrance));
|
||||
@@ -809,10 +813,11 @@ namespace Barotrauma
|
||||
|
||||
public void Update(float deltaTime)
|
||||
{
|
||||
/*
|
||||
if (Submarine.MainSub != null)
|
||||
{
|
||||
WrappingWall.UpdateWallShift(Submarine.MainSub.WorldPosition, wrappingWalls);
|
||||
}
|
||||
}*/
|
||||
|
||||
if (Hull.renderer != null)
|
||||
{
|
||||
@@ -884,6 +889,7 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
if (wrappingWalls == null) return cells;
|
||||
|
||||
for (int side = 0; side < 2; side++)
|
||||
@@ -899,7 +905,7 @@ namespace Barotrauma
|
||||
cells.Add(cell);
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
return cells;
|
||||
}
|
||||
@@ -918,6 +924,7 @@ namespace Barotrauma
|
||||
ruins = null;
|
||||
}
|
||||
|
||||
/*
|
||||
if (wrappingWalls!=null)
|
||||
{
|
||||
for (int side = 0; side < 2; side++)
|
||||
@@ -929,7 +936,7 @@ namespace Barotrauma
|
||||
}
|
||||
|
||||
wrappingWalls = null;
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
cells = null;
|
||||
|
||||
@@ -219,6 +219,7 @@ namespace Barotrauma
|
||||
|
||||
graphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, (int)Math.Floor(bodyVertices.VertexCount / 3.0f));
|
||||
|
||||
/*
|
||||
for (int side = 0; side < 2; side++)
|
||||
{
|
||||
for (int i = 0; i < 2; i++)
|
||||
@@ -234,7 +235,7 @@ namespace Barotrauma
|
||||
PrimitiveType.TriangleList, 0,
|
||||
(int)Math.Floor(level.WrappingWalls[side, i].BodyVertices.VertexCount / 3.0f));
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
graphicsDevice.SetVertexBuffer(wallVertices);
|
||||
@@ -243,7 +244,7 @@ namespace Barotrauma
|
||||
basicEffect.CurrentTechnique = basicEffect.Techniques["BasicEffect_Texture"];
|
||||
basicEffect.CurrentTechnique.Passes[0].Apply();
|
||||
graphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, (int)Math.Floor(wallVertices.VertexCount / 3.0f));
|
||||
|
||||
/*
|
||||
for (int side = 0; side < 2; side++)
|
||||
{
|
||||
for (int i = 0; i < 2; i++)
|
||||
@@ -260,7 +261,7 @@ namespace Barotrauma
|
||||
(int)Math.Floor(level.WrappingWalls[side, i].WallVertices.VertexCount / 3.0f));
|
||||
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -44,13 +44,24 @@ namespace Barotrauma.Lights
|
||||
|
||||
class ConvexHullList
|
||||
{
|
||||
private List<ConvexHull> list;
|
||||
|
||||
public readonly Submarine Submarine;
|
||||
public List<ConvexHull> List;
|
||||
public List<ConvexHull> List
|
||||
{
|
||||
get { return list; }
|
||||
set
|
||||
{
|
||||
Debug.Assert(value != null);
|
||||
Debug.Assert(!list.Contains(null));
|
||||
list = value;
|
||||
}
|
||||
}
|
||||
|
||||
public ConvexHullList(Submarine submarine)
|
||||
{
|
||||
Submarine = submarine;
|
||||
List = new List<ConvexHull>();
|
||||
list = new List<ConvexHull>();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,8 @@ namespace Barotrauma.Lights
|
||||
|
||||
private float range;
|
||||
|
||||
public SpriteEffects SpriteEffect = SpriteEffects.None;
|
||||
|
||||
private Texture2D texture;
|
||||
|
||||
public Sprite LightSprite;
|
||||
@@ -164,15 +166,15 @@ namespace Barotrauma.Lights
|
||||
|
||||
private List<ConvexHull> GetHullsInRange(Submarine sub)
|
||||
{
|
||||
//find the current list of hulls in range
|
||||
var chList = hullsInRange.Find(x => x.Submarine == sub);
|
||||
|
||||
//not found -> create one
|
||||
if (chList == null)
|
||||
{
|
||||
chList = new ConvexHullList(sub);
|
||||
hullsInRange.Add(chList);
|
||||
}
|
||||
List<ConvexHull> list = chList.List;
|
||||
|
||||
|
||||
Vector2 lightPos = position;
|
||||
if (ParentSub == null)
|
||||
@@ -183,15 +185,12 @@ namespace Barotrauma.Lights
|
||||
if (NeedsHullUpdate)
|
||||
{
|
||||
var fullChList = ConvexHull.HullLists.Find(x => x.Submarine == sub);
|
||||
|
||||
list = fullChList.List.FindAll(ch => MathUtils.CircleIntersectsRectangle(lightPos, range, ch.BoundingBox));
|
||||
chList.List = list;
|
||||
chList.List = fullChList.List.FindAll(ch => MathUtils.CircleIntersectsRectangle(lightPos, range, ch.BoundingBox));
|
||||
}
|
||||
}
|
||||
//light is outside, convexhull inside a sub
|
||||
else
|
||||
{
|
||||
//todo: check
|
||||
lightPos -= sub.Position;
|
||||
|
||||
Rectangle subBorders = sub.Borders;
|
||||
@@ -201,7 +200,7 @@ namespace Barotrauma.Lights
|
||||
if (!MathUtils.CircleIntersectsRectangle(lightPos, range, subBorders)) return null;
|
||||
|
||||
var fullChList = ConvexHull.HullLists.Find(x => x.Submarine == sub);
|
||||
list = fullChList.List.FindAll(ch => MathUtils.CircleIntersectsRectangle(lightPos, range, ch.BoundingBox));
|
||||
chList.List = fullChList.List.FindAll(ch => MathUtils.CircleIntersectsRectangle(lightPos, range, ch.BoundingBox));
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -215,15 +214,13 @@ namespace Barotrauma.Lights
|
||||
if (NeedsHullUpdate)
|
||||
{
|
||||
var fullChList = ConvexHull.HullLists.Find(x => x.Submarine == sub);
|
||||
|
||||
list = fullChList.List.FindAll(ch => MathUtils.CircleIntersectsRectangle(lightPos, range, ch.BoundingBox));
|
||||
chList.List = list;
|
||||
chList.List = fullChList.List.FindAll(ch => MathUtils.CircleIntersectsRectangle(lightPos, range, ch.BoundingBox));
|
||||
}
|
||||
}
|
||||
//light and convexhull are inside different subs
|
||||
else
|
||||
{
|
||||
if (sub.DockedTo.Contains(ParentSub) && !NeedsHullUpdate) return list;
|
||||
if (sub.DockedTo.Contains(ParentSub) && !NeedsHullUpdate) return chList.List;
|
||||
|
||||
lightPos -= (sub.Position - ParentSub.Position);
|
||||
|
||||
@@ -234,12 +231,11 @@ namespace Barotrauma.Lights
|
||||
if (!MathUtils.CircleIntersectsRectangle(lightPos, range, subBorders)) return null;
|
||||
|
||||
var fullChList = ConvexHull.HullLists.Find(x => x.Submarine == sub);
|
||||
list = fullChList.List.FindAll(ch => MathUtils.CircleIntersectsRectangle(lightPos, range, ch.BoundingBox));
|
||||
chList.List = list;
|
||||
chList.List = fullChList.List.FindAll(ch => MathUtils.CircleIntersectsRectangle(lightPos, range, ch.BoundingBox));
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
return chList.List;
|
||||
}
|
||||
|
||||
public static List<ConvexHull> GetHullsInRange(Vector2 position, float range, Submarine ParentSub)
|
||||
@@ -318,13 +314,14 @@ namespace Barotrauma.Lights
|
||||
overrideLightTexture.Draw(spriteBatch,
|
||||
drawPos, color * (color.A / 255.0f),
|
||||
overrideLightTexture.Origin, -Rotation,
|
||||
new Vector2(overrideLightTexture.size.X / overrideLightTexture.SourceRect.Width, overrideLightTexture.size.Y / overrideLightTexture.SourceRect.Height));
|
||||
new Vector2(overrideLightTexture.size.X / overrideLightTexture.SourceRect.Width, overrideLightTexture.size.Y / overrideLightTexture.SourceRect.Height),
|
||||
SpriteEffect);
|
||||
}
|
||||
}
|
||||
|
||||
if (LightSprite != null)
|
||||
{
|
||||
LightSprite.Draw(spriteBatch, drawPos, Color, LightSprite.Origin);
|
||||
LightSprite.Draw(spriteBatch, drawPos, Color, LightSprite.Origin, -Rotation, 1, SpriteEffect);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ namespace Barotrauma
|
||||
if (!editing || wallVertices == null) return;
|
||||
|
||||
Color color = (isHighlighted) ? Color.Orange : Color.Green;
|
||||
if (isSelected) color = Color.Red;
|
||||
if (IsSelected) color = Color.Red;
|
||||
|
||||
Vector2 pos = Position;
|
||||
|
||||
|
||||
@@ -358,7 +358,7 @@ namespace Barotrauma
|
||||
}
|
||||
|
||||
rect.Inflate(8, 8);
|
||||
GUI.DrawRectangle(spriteBatch, rect, Color.Black, 8);
|
||||
GUI.DrawRectangle(spriteBatch, rect, Color.Black, false, 0.0f, 8);
|
||||
GUI.DrawRectangle(spriteBatch, rect, Color.LightGray);
|
||||
|
||||
for (int i = 0; i < locations.Count; i++)
|
||||
|
||||
@@ -1,24 +1,41 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
using FarseerPhysics;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
using System.Collections.ObjectModel;
|
||||
using Barotrauma.Items.Components;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
class MapEntity : Entity
|
||||
abstract class MapEntity : Entity
|
||||
{
|
||||
public static List<MapEntity> mapEntityList = new List<MapEntity>();
|
||||
|
||||
//which entities have been selected for editing
|
||||
public static List<MapEntity> selectedList = new List<MapEntity>();
|
||||
private static List<MapEntity> selectedList = new List<MapEntity>();
|
||||
public static List<MapEntity> SelectedList
|
||||
{
|
||||
get
|
||||
{
|
||||
return selectedList;
|
||||
}
|
||||
}
|
||||
private static List<MapEntity> copiedList = new List<MapEntity>();
|
||||
|
||||
protected static GUIComponent editingHUD;
|
||||
|
||||
public static GUIComponent EditingHUD
|
||||
{
|
||||
get
|
||||
{
|
||||
return editingHUD;
|
||||
}
|
||||
}
|
||||
|
||||
protected static Vector2 selectionPos = Vector2.Zero;
|
||||
protected static Vector2 selectionSize = Vector2.Zero;
|
||||
|
||||
@@ -37,7 +54,7 @@ namespace Barotrauma
|
||||
//is the mouse inside the rect
|
||||
protected bool isHighlighted;
|
||||
|
||||
protected bool isSelected;
|
||||
//protected bool isSelected;
|
||||
|
||||
private static bool disableSelect;
|
||||
public static bool DisableSelect
|
||||
@@ -149,7 +166,11 @@ namespace Barotrauma
|
||||
if (aiTarget == null) return 0.0f;
|
||||
return aiTarget.SoundRange;
|
||||
}
|
||||
set { aiTarget.SoundRange = value; }
|
||||
set
|
||||
{
|
||||
if (aiTarget == null) return;
|
||||
aiTarget.SoundRange = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float SightRange
|
||||
@@ -169,8 +190,7 @@ namespace Barotrauma
|
||||
|
||||
public bool IsSelected
|
||||
{
|
||||
get { return isSelected; }
|
||||
set { isSelected = value; }
|
||||
get { return selectedList.Contains(this); }
|
||||
}
|
||||
|
||||
protected bool ResizeHorizontal
|
||||
@@ -202,6 +222,68 @@ namespace Barotrauma
|
||||
{
|
||||
return (Submarine.RectContains(WorldRect, position));
|
||||
}
|
||||
|
||||
public virtual MapEntity Clone()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public static List<MapEntity> Clone(List<MapEntity> entitiesToClone)
|
||||
{
|
||||
List<MapEntity> clones = new List<MapEntity>();
|
||||
foreach (MapEntity e in entitiesToClone)
|
||||
{
|
||||
Debug.Assert(e != null);
|
||||
clones.Add(e.Clone());
|
||||
Debug.Assert(clones.Last() != null);
|
||||
}
|
||||
|
||||
Debug.Assert(clones.Count == entitiesToClone.Count);
|
||||
|
||||
//clone links between the entities
|
||||
for (int i = 0; i < clones.Count; i++)
|
||||
{
|
||||
foreach (MapEntity linked in entitiesToClone[i].linkedTo)
|
||||
{
|
||||
if (!entitiesToClone.Contains(linked)) continue;
|
||||
|
||||
clones[i].linkedTo.Add(clones[entitiesToClone.IndexOf(linked)]);
|
||||
}
|
||||
}
|
||||
|
||||
//connect clone wires to the clone items
|
||||
for (int i = 0; i < clones.Count; i++)
|
||||
{
|
||||
var cloneItem = clones[i] as Item;
|
||||
if (cloneItem == null) continue;
|
||||
|
||||
var cloneWire = cloneItem.GetComponent<Wire>();
|
||||
if (cloneWire == null) continue;
|
||||
|
||||
var originalWire = ((Item)entitiesToClone[i]).GetComponent<Wire>();
|
||||
|
||||
cloneWire.SetNodes(originalWire.GetNodes());
|
||||
|
||||
for (int n = 0; n < 2; n++)
|
||||
{
|
||||
if (originalWire.Connections[n] == null) continue;
|
||||
|
||||
var connectedItem = originalWire.Connections[n].Item;
|
||||
if (connectedItem == null) continue;
|
||||
|
||||
//index of the item the wire is connected to
|
||||
int itemIndex = entitiesToClone.IndexOf(connectedItem);
|
||||
//index of the connection in the connectionpanel of the target item
|
||||
int connectionIndex = connectedItem.Connections.IndexOf(originalWire.Connections[n]);
|
||||
|
||||
(clones[itemIndex] as Item).GetComponent<ConnectionPanel>().Connections[connectionIndex].TryAddLink(cloneWire);
|
||||
cloneWire.Connect((clones[itemIndex] as Item).Connections[connectionIndex], false);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return clones;
|
||||
}
|
||||
|
||||
protected void InsertToList()
|
||||
{
|
||||
@@ -229,6 +311,18 @@ namespace Barotrauma
|
||||
|
||||
public virtual void DrawDamage(SpriteBatch spriteBatch, Effect damageEffect) {}
|
||||
|
||||
/// <summary>
|
||||
/// Remove the entity from the entity list without removing links to other entities
|
||||
/// </summary>
|
||||
public virtual void ShallowRemove()
|
||||
{
|
||||
base.Remove();
|
||||
|
||||
mapEntityList.Remove(this);
|
||||
|
||||
if (aiTarget != null) aiTarget.Remove();
|
||||
}
|
||||
|
||||
public override void Remove()
|
||||
{
|
||||
base.Remove();
|
||||
@@ -288,7 +382,6 @@ namespace Barotrauma
|
||||
foreach (MapEntity e in mapEntityList)
|
||||
{
|
||||
e.isHighlighted = false;
|
||||
e.isSelected = false;
|
||||
}
|
||||
|
||||
if (DisableSelect)
|
||||
@@ -308,10 +401,40 @@ namespace Barotrauma
|
||||
|
||||
if (PlayerInput.KeyDown(Keys.Delete))
|
||||
{
|
||||
foreach (MapEntity e in selectedList) e.Remove();
|
||||
selectedList.ForEach(e => e.Remove());
|
||||
selectedList.Clear();
|
||||
}
|
||||
|
||||
if (PlayerInput.KeyDown(Keys.LeftControl) || PlayerInput.KeyDown(Keys.RightControl))
|
||||
{
|
||||
if (PlayerInput.GetKeyboardState.IsKeyDown(Keys.C) &&
|
||||
PlayerInput.GetOldKeyboardState.IsKeyUp(Keys.C))
|
||||
{
|
||||
CopyEntities(selectedList);
|
||||
}
|
||||
else if (PlayerInput.GetKeyboardState.IsKeyDown(Keys.X) &&
|
||||
PlayerInput.GetOldKeyboardState.IsKeyUp(Keys.X))
|
||||
{
|
||||
CopyEntities(selectedList);
|
||||
|
||||
selectedList.ForEach(e => e.Remove());
|
||||
selectedList.Clear();
|
||||
}
|
||||
else if (copiedList.Count > 0 &&
|
||||
PlayerInput.GetKeyboardState.IsKeyDown(Keys.V) &&
|
||||
PlayerInput.GetOldKeyboardState.IsKeyUp(Keys.V))
|
||||
{
|
||||
var clones = Clone(copiedList);
|
||||
|
||||
Vector2 center = Vector2.Zero;
|
||||
clones.ForEach(c => center += c.WorldPosition);
|
||||
center /= clones.Count;
|
||||
|
||||
selectedList = new List<MapEntity>(clones);
|
||||
selectedList.ForEach(c => c.Move(cam.WorldViewCenter - center));
|
||||
}
|
||||
}
|
||||
|
||||
Vector2 position = cam.ScreenToWorld(PlayerInput.MousePosition);
|
||||
|
||||
MapEntity highLightedEntity = null;
|
||||
@@ -327,21 +450,15 @@ namespace Barotrauma
|
||||
{
|
||||
if (e.IsMouseOn(position)) highLightedEntity = e;
|
||||
}
|
||||
e.isSelected = false;
|
||||
}
|
||||
|
||||
if (highLightedEntity != null) highLightedEntity.isHighlighted = true;
|
||||
|
||||
}
|
||||
|
||||
foreach (MapEntity e in selectedList)
|
||||
{
|
||||
e.isSelected = true;
|
||||
}
|
||||
|
||||
|
||||
//started moving selected entities
|
||||
if (startMovingPos != Vector2.Zero)
|
||||
{
|
||||
{
|
||||
if (PlayerInput.LeftButtonReleased())
|
||||
{
|
||||
//mouse released -> move the entities to the new position of the mouse
|
||||
@@ -351,11 +468,22 @@ namespace Barotrauma
|
||||
|
||||
if (moveAmount != Vector2.Zero)
|
||||
{
|
||||
foreach (MapEntity e in selectedList) e.Move(moveAmount);
|
||||
//clone
|
||||
if (PlayerInput.KeyDown(Keys.LeftControl) || PlayerInput.KeyDown(Keys.RightControl))
|
||||
{
|
||||
var clones = Clone(selectedList);
|
||||
selectedList = clones;
|
||||
selectedList.ForEach(c => c.Move(moveAmount));
|
||||
}
|
||||
else // move
|
||||
{
|
||||
foreach (MapEntity e in selectedList) e.Move(moveAmount);
|
||||
}
|
||||
}
|
||||
|
||||
startMovingPos = Vector2.Zero;
|
||||
startMovingPos = Vector2.Zero;
|
||||
}
|
||||
|
||||
}
|
||||
//started dragging a "selection rectangle"
|
||||
else if (selectionPos != Vector2.Zero)
|
||||
@@ -402,6 +530,25 @@ namespace Barotrauma
|
||||
{
|
||||
selectedList = newSelection;
|
||||
}
|
||||
|
||||
//select wire if both items it's connected to are selected
|
||||
var selectedItems = selectedList.Where(e => e is Item).Cast<Item>().ToList();
|
||||
foreach (Item item in selectedItems)
|
||||
{
|
||||
if (item.Connections == null) continue;
|
||||
foreach (Connection c in item.Connections)
|
||||
{
|
||||
foreach (Wire w in c.Wires)
|
||||
{
|
||||
if (w == null || selectedList.Contains(w.Item)) continue;
|
||||
|
||||
if (w.OtherConnection(c) != null && selectedList.Contains(w.OtherConnection(c).Item))
|
||||
{
|
||||
selectedList.Add(w.Item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
selectionPos = Vector2.Zero;
|
||||
selectionSize = Vector2.Zero;
|
||||
@@ -410,7 +557,6 @@ namespace Barotrauma
|
||||
//default, not doing anything specific yet
|
||||
else
|
||||
{
|
||||
|
||||
if (PlayerInput.LeftButtonHeld() &&
|
||||
PlayerInput.KeyUp(Keys.Space))
|
||||
{
|
||||
@@ -422,12 +568,10 @@ namespace Barotrauma
|
||||
|
||||
selectionPos = position;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Draw the "selection rectangle" and outlines of entities that are being dragged (if any)
|
||||
/// </summary>
|
||||
@@ -504,10 +648,6 @@ namespace Barotrauma
|
||||
|
||||
public static void DeselectAll()
|
||||
{
|
||||
foreach (MapEntity e in selectedList)
|
||||
{
|
||||
e.isSelected = false;
|
||||
}
|
||||
selectedList.Clear();
|
||||
}
|
||||
|
||||
@@ -516,10 +656,27 @@ namespace Barotrauma
|
||||
{
|
||||
DeselectAll();
|
||||
|
||||
entity.isSelected = true;
|
||||
selectedList.Add(entity);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// copies a list of entities to the "clipboard" (copiedList)
|
||||
/// </summary>
|
||||
private static void CopyEntities(List<MapEntity> entities)
|
||||
{
|
||||
List<MapEntity> prevEntities = new List<MapEntity>(mapEntityList);
|
||||
|
||||
copiedList = Clone(entities);
|
||||
|
||||
//find all new entities created during cloning
|
||||
var newEntities = mapEntityList.Except(prevEntities).ToList();
|
||||
|
||||
//do a "shallow remove" (removes the entities from the game without removing links between them)
|
||||
// -> items will stay in their containers
|
||||
newEntities.ForEach(e => e.ShallowRemove());
|
||||
}
|
||||
|
||||
public virtual void FlipX()
|
||||
{
|
||||
if (Submarine == null)
|
||||
@@ -533,6 +690,11 @@ namespace Barotrauma
|
||||
|
||||
Move(-relative * 2.0f);
|
||||
}
|
||||
|
||||
public virtual void AddToGUIUpdateList()
|
||||
{
|
||||
if (editingHUD != null) editingHUD.AddToGUIUpdateList();
|
||||
}
|
||||
|
||||
public virtual void UpdateEditing(Camera cam) { }
|
||||
|
||||
@@ -631,26 +793,7 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static List<MapEntity> FindMapEntities(Vector2 pos)
|
||||
{
|
||||
List<MapEntity> foundEntities = new List<MapEntity>();
|
||||
foreach (MapEntity e in mapEntityList)
|
||||
{
|
||||
if (Submarine.RectContains(e.rect, pos)) foundEntities.Add(e);
|
||||
}
|
||||
return foundEntities;
|
||||
}
|
||||
|
||||
public static MapEntity FindMapEntity(Vector2 pos)
|
||||
{
|
||||
foreach (MapEntity e in mapEntityList)
|
||||
{
|
||||
if (Submarine.RectContains(e.rect, pos)) return e;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Find entities whose rect intersects with the "selection rect"
|
||||
/// </summary>
|
||||
|
||||
@@ -258,7 +258,6 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (prefab.CastShadow)
|
||||
{
|
||||
GenerateConvexHull();
|
||||
@@ -267,6 +266,11 @@ namespace Barotrauma
|
||||
InsertToList();
|
||||
}
|
||||
|
||||
public override MapEntity Clone()
|
||||
{
|
||||
return new Structure(rect, prefab, Submarine);
|
||||
}
|
||||
|
||||
private void CreateStairBodies()
|
||||
{
|
||||
bodies = new List<Body>();
|
||||
@@ -486,14 +490,13 @@ namespace Barotrauma
|
||||
Draw(spriteBatch, false, false, damageEffect);
|
||||
}
|
||||
|
||||
private static float prevCutoff;
|
||||
|
||||
private void Draw(SpriteBatch spriteBatch, bool editing, bool back = true, Effect damageEffect = null)
|
||||
{
|
||||
if (prefab.sprite == null) return;
|
||||
|
||||
Color color = (isHighlighted) ? Color.Orange : Color.White;
|
||||
if (isSelected && editing)
|
||||
if (IsSelected && editing)
|
||||
{
|
||||
color = Color.Red;
|
||||
|
||||
@@ -525,14 +528,14 @@ namespace Barotrauma
|
||||
{
|
||||
float newCutoff = Math.Min((sections[i].damage / prefab.MaxHealth), 0.65f);
|
||||
|
||||
if (Math.Abs(newCutoff - prevCutoff) > 0.01f)
|
||||
if (Math.Abs(newCutoff - Submarine.DamageEffectCutoff) > 0.01f)
|
||||
{
|
||||
damageEffect.Parameters["aCutoff"].SetValue(newCutoff);
|
||||
damageEffect.Parameters["cCutoff"].SetValue(newCutoff * 1.2f);
|
||||
|
||||
damageEffect.CurrentTechnique.Passes[0].Apply();
|
||||
|
||||
prevCutoff = newCutoff;
|
||||
Submarine.DamageEffectCutoff = newCutoff;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -760,11 +763,10 @@ namespace Barotrauma
|
||||
|
||||
if(CastShadow) GenerateConvexHull();
|
||||
}
|
||||
|
||||
sections[sectionIndex].gap.Open = (damage / prefab.MaxHealth - 0.5f) * 2.0f;
|
||||
}
|
||||
|
||||
if (sections[sectionIndex].gap != null)
|
||||
sections[sectionIndex].gap.Open = (damage/prefab.MaxHealth - 0.5f)*2;
|
||||
|
||||
|
||||
bool hadHole = SectionBodyDisabled(sectionIndex);
|
||||
sections[sectionIndex].damage = MathHelper.Clamp(damage, 0.0f, prefab.MaxHealth);
|
||||
|
||||
|
||||
@@ -362,7 +362,7 @@ namespace Barotrauma
|
||||
worldBorders.Location += sub.WorldPosition.ToPoint();
|
||||
worldBorders.Y = -worldBorders.Y;
|
||||
|
||||
GUI.DrawRectangle(spriteBatch, worldBorders, Color.White, 5);
|
||||
GUI.DrawRectangle(spriteBatch, worldBorders, Color.White, false, 0, 5);
|
||||
|
||||
if (sub.subBody.MemPos.Count < 2) continue;
|
||||
|
||||
@@ -383,6 +383,9 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static float DamageEffectCutoff;
|
||||
|
||||
public static void DrawDamageable(SpriteBatch spriteBatch, Effect damageEffect, bool editing = false)
|
||||
{
|
||||
var entitiesToRender = !editing && visibleEntities != null ? visibleEntities : MapEntity.mapEntityList;
|
||||
@@ -396,6 +399,8 @@ namespace Barotrauma
|
||||
{
|
||||
damageEffect.Parameters["aCutoff"].SetValue(0.0f);
|
||||
damageEffect.Parameters["cCutoff"].SetValue(0.0f);
|
||||
|
||||
DamageEffectCutoff = 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -929,6 +934,7 @@ namespace Barotrauma
|
||||
{
|
||||
try
|
||||
{
|
||||
ToolBox.IsProperFilenameCase(file);
|
||||
doc = XDocument.Load(file);
|
||||
}
|
||||
|
||||
@@ -1035,13 +1041,10 @@ namespace Barotrauma
|
||||
if (item.Submarine != this) continue;
|
||||
|
||||
var wire = item.GetComponent<Items.Components.Wire>();
|
||||
if (wire == null) continue;
|
||||
|
||||
for (int i = 0; i < wire.Nodes.Count; i++)
|
||||
if (wire != null)
|
||||
{
|
||||
wire.Nodes[i] -= center;
|
||||
wire.MoveNodes(-center);
|
||||
}
|
||||
wire.UpdateSections();
|
||||
}
|
||||
|
||||
for (int i = 0; i < MapEntity.mapEntityList.Count; i++)
|
||||
|
||||
@@ -243,6 +243,21 @@ namespace Barotrauma
|
||||
return;
|
||||
}
|
||||
|
||||
//if outside left or right edge of the level
|
||||
if (Position.X < 0 || Position.X > Level.Loaded.Size.X)
|
||||
{
|
||||
Rectangle worldBorders = Borders;
|
||||
worldBorders.Location += Position.ToPoint();
|
||||
|
||||
//push the sub back below the upper "barrier" of the level
|
||||
if (worldBorders.Y > Level.Loaded.Size.Y)
|
||||
{
|
||||
Body.LinearVelocity = new Vector2(
|
||||
Body.LinearVelocity.X,
|
||||
Math.Min(Body.LinearVelocity.Y, ConvertUnits.ToSimUnits(Level.Loaded.Size.Y - worldBorders.Y)));
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------
|
||||
|
||||
Vector2 totalForce = CalculateBuoyancy();
|
||||
|
||||
@@ -113,6 +113,16 @@ namespace Barotrauma
|
||||
currentHull = Hull.FindHull(WorldPosition);
|
||||
}
|
||||
|
||||
public override MapEntity Clone()
|
||||
{
|
||||
var clone = new WayPoint(rect, Submarine);
|
||||
clone.idCardTags = idCardTags;
|
||||
clone.spawnType = spawnType;
|
||||
clone.assignedJob = assignedJob;
|
||||
|
||||
return clone;
|
||||
}
|
||||
|
||||
public override bool IsMouseOn(Vector2 position)
|
||||
{
|
||||
if (IsHidden()) return false;
|
||||
@@ -134,7 +144,7 @@ namespace Barotrauma
|
||||
drawPos.Y = -drawPos.Y;
|
||||
|
||||
Color clr = currentHull == null ? Color.Blue : Color.White;
|
||||
if (isSelected) clr = Color.Red;
|
||||
if (IsSelected) clr = Color.Red;
|
||||
if (isHighlighted) clr = Color.DarkRed;
|
||||
|
||||
int iconX = iconIndices[(int)spawnType]*IconSize % iconTexture.Width;
|
||||
@@ -434,7 +444,7 @@ namespace Barotrauma
|
||||
|
||||
foreach (Structure stairs in stairList)
|
||||
{
|
||||
WayPoint[] stairPoints = new WayPoint[2];
|
||||
WayPoint[] stairPoints = new WayPoint[3];
|
||||
|
||||
stairPoints[0] = new WayPoint(
|
||||
new Vector2(stairs.Rect.X - 32.0f,
|
||||
@@ -453,8 +463,10 @@ namespace Barotrauma
|
||||
stairPoints[i].ConnectTo(closest);
|
||||
}
|
||||
}
|
||||
|
||||
stairPoints[0].ConnectTo(stairPoints[1]);
|
||||
|
||||
stairPoints[2] = new WayPoint((stairPoints[0].Position + stairPoints[1].Position)/2, SpawnType.Path, submarine);
|
||||
stairPoints[0].ConnectTo(stairPoints[2]);
|
||||
stairPoints[2].ConnectTo(stairPoints[1]);
|
||||
}
|
||||
|
||||
foreach (Item item in Item.ItemList)
|
||||
|
||||
Reference in New Issue
Block a user