Faction Test 100.4.0.0

This commit is contained in:
Markus Isberg
2022-11-14 18:28:28 +02:00
parent 87426b68b2
commit c772b61fc1
412 changed files with 16984 additions and 5530 deletions
@@ -4,9 +4,7 @@ using FarseerPhysics.Dynamics;
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using Barotrauma.IO;
using System.Linq;
using System.Xml.Linq;
#if CLIENT
using Barotrauma.Lights;
#endif
@@ -16,6 +14,10 @@ namespace Barotrauma.Items.Components
{
partial class Door : Pickable, IDrawableComponent, IServerSerializable
{
private static readonly HashSet<Door> doorList = new HashSet<Door>();
public static IReadOnlyCollection<Door> DoorList { get { return doorList; } }
private Gap linkedGap;
private bool isOpen;
@@ -92,6 +94,9 @@ namespace Barotrauma.Items.Components
public PhysicsBody Body { get; private set; }
//the fixture that's part of the submarine's collider (= fixture that things outside the sub can collide with if the door is outside hulls)
public Fixture OutsideSubmarineFixture;
private float RepairThreshold
{
get { return item.GetComponent<Repairable>() == null ? 0.0f : item.MaxCondition; }
@@ -165,7 +170,7 @@ namespace Barotrauma.Items.Components
set
{
isOpen = value;
OpenState = (isOpen) ? 1.0f : 0.0f;
OpenState = isOpen ? 1.0f : 0.0f;
}
}
@@ -227,6 +232,7 @@ namespace Barotrauma.Items.Components
}
IsActive = true;
doorList.Add(this);
}
public override void OnItemLoaded()
@@ -366,6 +372,8 @@ namespace Barotrauma.Items.Components
return;
}
bool isClosing = false;
if ((!IsStuck && !IsJammed) || !isOpen)
{
@@ -391,11 +399,20 @@ namespace Barotrauma.Items.Components
if (isClosing)
{
if (OpenState < 0.9f) { PushCharactersAway(); }
if (CheckSubmarinesInDoorWay())
{
PredictedState = null;
isOpen = true;
}
}
else
{
bool wasEnabled = Body.Enabled;
Body.Enabled = Impassable || openState < 1.0f;
if (OutsideSubmarineFixture != null)
{
OutsideSubmarineFixture.CollidesWith = Body.Enabled ? SubmarineBody.CollidesWith : Category.None;
}
if (wasEnabled && !Body.Enabled && IsHorizontal)
{
//when opening a hatch, force characters above it to refresh the floor position
@@ -439,6 +456,10 @@ namespace Barotrauma.Items.Components
}
PushCharactersAway();
}
if (OutsideSubmarineFixture != null && Body.Enabled)
{
OutsideSubmarineFixture.CollidesWith = SubmarineBody.CollidesWith;
}
#if CLIENT
UpdateConvexHulls();
#endif
@@ -459,6 +480,10 @@ namespace Barotrauma.Items.Components
ce = ce.Next;
}
}
if (OutsideSubmarineFixture != null)
{
OutsideSubmarineFixture.CollidesWith = Category.None;
}
linkedGap.Open = 1.0f;
IsOpen = false;
#if CLIENT
@@ -534,6 +559,36 @@ namespace Barotrauma.Items.Components
convexHull?.Remove();
convexHull2?.Remove();
#endif
doorList.Remove(this);
}
private bool CheckSubmarinesInDoorWay()
{
if (linkedGap != null && linkedGap.IsRoomToRoom) { return false; }
Rectangle doorRect = item.WorldRect;
if (IsHorizontal)
{
doorRect.Width = (int)(item.Rect.Width * (1.0f - openState));
}
else
{
doorRect.Height = (int)(item.Rect.Height * (1.0f - openState));
}
foreach (Submarine sub in Submarine.Loaded)
{
if (sub == item.Submarine || sub.DockedTo.Contains(item.Submarine)) { continue; }
Rectangle worldBorders = sub.Borders;
worldBorders.Location += sub.WorldPosition.ToPoint();
if (!Submarine.RectsOverlap(worldBorders, doorRect)) { continue; }
foreach (Hull hull in sub.GetHulls(alsoFromConnectedSubs: false))
{
if (Submarine.RectsOverlap(hull.WorldRect, doorRect)) { return true; }
}
}
return false;
}
bool itemPosErrorShown;
@@ -557,7 +612,6 @@ namespace Barotrauma.Items.Components
Vector2 currSize = IsHorizontal ?
new Vector2(item.Rect.Width * (1.0f - openState), doorSprite.size.Y * item.Scale) :
new Vector2(doorSprite.size.X * item.Scale, item.Rect.Height * (1.0f - openState));
Vector2 simSize = ConvertUnits.ToSimUnits(currSize);
foreach (Character c in Character.CharacterList)