This commit is contained in:
Evil Factory
2022-02-24 14:30:39 -03:00
364 changed files with 10838 additions and 3966 deletions
@@ -3,12 +3,10 @@ using FarseerPhysics;
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Xml.Linq;
using Barotrauma.Networking;
namespace Barotrauma
{
@@ -20,14 +18,17 @@ namespace Barotrauma
protected List<ushort> linkedToID;
public List<ushort> unresolvedLinkedToID;
private const int GapUpdateInterval = 4;
private static int gapUpdateTimer;
/// <summary>
/// List of upgrades this item has
/// </summary>
protected readonly List<Upgrade> Upgrades = new List<Upgrade>();
public HashSet<string> disallowedUpgrades = new HashSet<string>();
[Editable, Serialize("", true)]
public string DisallowedUpgrades
{
@@ -101,7 +102,7 @@ namespace Barotrauma
return !DrawBelowWater;
}
}
public virtual bool Linkable
{
get { return false; }
@@ -231,6 +232,9 @@ namespace Barotrauma
protected set;
} = true;
[Serialize("", true, "Submarine editor layer")]
public string Layer { get; set; }
/// <summary>
/// The index of the outpost module this entity originally spawned in (-1 if not an outpost item)
/// </summary>
@@ -242,7 +246,7 @@ namespace Barotrauma
{
get { return ""; }
}
public MapEntity(MapEntityPrefab prefab, Submarine submarine, ushort id) : base(submarine, id)
{
this.prefab = prefab;
@@ -303,7 +307,7 @@ namespace Barotrauma
{
return GetUpgrade(identifier) != null;
}
public Upgrade GetUpgrade(string identifier)
{
return Upgrades.Find(upgrade => upgrade.Identifier == identifier);
@@ -329,7 +333,7 @@ namespace Barotrauma
}
DebugConsole.Log($"Set (ID: {ID} {prefab.Name})'s \"{upgrade.Prefab.Name}\" upgrade to level {upgrade.Level}");
}
/// <summary>
/// Adds a new upgrade to the item
/// </summary>
@@ -407,6 +411,7 @@ namespace Barotrauma
}
//connect clone wires to the clone items and refresh links between doors and gaps
List<Wire> orphanedWires = new List<Wire>();
for (int i = 0; i < clones.Count; i++)
{
if (!(clones[i] is Item cloneItem)) { continue; }
@@ -435,11 +440,11 @@ namespace Barotrauma
disconnectedFromClone.DisconnectedWires.Add(cloneWire);
if (cloneWire.Item.body != null) { cloneWire.Item.body.Enabled = false; }
cloneWire.IsActive = false;
continue;
continue;
}
var connectedItem = originalWire.Connections[n].Item;
if (connectedItem == null) { continue; }
if (connectedItem == null || !entitiesToClone.Contains(connectedItem)) { continue; }
//index of the item the wire is connected to
int itemIndex = entitiesToClone.IndexOf(connectedItem);
@@ -466,6 +471,20 @@ namespace Barotrauma
(clones[itemIndex] as Item).Connections[connectionIndex].TryAddLink(cloneWire);
cloneWire.Connect((clones[itemIndex] as Item).Connections[connectionIndex], false);
}
if ((cloneWire.Connections[0] == null || cloneWire.Connections[1] == null) && cloneItem.GetComponent<DockingPort>() == null)
{
if (!clones.Any(c => (c as Item)?.GetComponent<ConnectionPanel>()?.DisconnectedWires.Contains(cloneWire) ?? false))
{
orphanedWires.Add(cloneWire);
}
}
}
foreach (var orphanedWire in orphanedWires)
{
orphanedWire.Item.Remove();
clones.Remove(orphanedWire.Item);
}
return clones;
@@ -535,59 +554,48 @@ namespace Barotrauma
linkedTo.Clear();
}
}
static int tick = 0;
/// <summary>
/// Call Update() on every object in Entity.list
/// </summary>
public static void UpdateAll(float deltaTime, Camera cam)
{
tick++;
if (tick % GameMain.Lua.game.mapEntityUpdateRate == 0)
foreach (Hull hull in Hull.hullList)
{
hull.Update(deltaTime, cam);
}
#if CLIENT
Hull.UpdateCheats(deltaTime, cam);
#endif
foreach (Hull hull in Hull.hullList)
{
hull.Update(deltaTime * GameMain.Lua.game.mapEntityUpdateRate, cam);
}
foreach (Structure structure in Structure.WallList)
{
structure.Update(deltaTime * GameMain.Lua.game.mapEntityUpdateRate, cam);
}
//update gaps in random order, because otherwise in rooms with multiple gaps
//the water/air will always tend to flow through the first gap in the list,
//which may lead to weird behavior like water draining down only through
//one gap in a room even if there are several
foreach (Gap gap in Gap.GapList.OrderBy(g => Rand.Int(int.MaxValue)))
{
gap.Update(deltaTime * GameMain.Lua.game.mapEntityUpdateRate, cam);
}
Powered.UpdatePower(deltaTime * GameMain.Lua.game.mapEntityUpdateRate);
foreach (Item item in Item.ItemList)
{
if (GameMain.Lua.game.updatePriorityItems.Contains(item)) continue;
item.Update(deltaTime * GameMain.Lua.game.mapEntityUpdateRate, cam);
}
foreach (Structure structure in Structure.WallList)
{
structure.Update(deltaTime, cam);
}
foreach (var item in GameMain.Lua.game.updatePriorityItems)
//update gaps in random order, because otherwise in rooms with multiple gaps
//the water/air will always tend to flow through the first gap in the list,
//which may lead to weird behavior like water draining down only through
//one gap in a room even if there are several
gapUpdateTimer++;
if (gapUpdateTimer >= GapUpdateInterval)
{
if (item.Removed) continue;
foreach (Gap gap in Gap.GapList.OrderBy(g => Rand.Int(int.MaxValue)))
{
gap.Update(deltaTime * GapUpdateInterval, cam);
}
gapUpdateTimer = 0;
}
Powered.UpdatePower(deltaTime);
foreach (Item item in Item.ItemList)
{
item.Update(deltaTime, cam);
}
if (tick % GameMain.Lua.game.mapEntityUpdateRate == 0)
{
UpdateAllProjSpecific(deltaTime * GameMain.Lua.game.mapEntityUpdateRate);
UpdateAllProjSpecific(deltaTime);
Spawner?.Update();
}
Spawner?.Update();
}
static partial void UpdateAllProjSpecific(float deltaTime);
@@ -743,11 +751,11 @@ namespace Barotrauma
foreach (ushort i in e.linkedToID)
{
if (FindEntityByID(i) is MapEntity linked)
if (FindEntityByID(i) is MapEntity linked)
{
e.linkedTo.Add(linked);
}
else
e.linkedTo.Add(linked);
}
else
{
#if DEBUG
DebugConsole.ThrowError($"Linking the entity \"{e.Name}\" to another entity failed. Could not find an entity with the ID \"{i}\".");
@@ -788,7 +796,7 @@ namespace Barotrauma
/// <summary>
/// Gets all linked entities of specific type.
/// </summary>
private static void GetLinkedEntitiesRecursive<T>(MapEntity mapEntity, HashSet<T> linkedTargets, ref int depth, int? maxDepth = null, Func<T, bool> filter = null)
private static void GetLinkedEntitiesRecursive<T>(MapEntity mapEntity, HashSet<T> linkedTargets, ref int depth, int? maxDepth = null, Func<T, bool> filter = null)
where T : MapEntity
{
if (depth > maxDepth) { return; }
@@ -806,4 +814,4 @@ namespace Barotrauma
}
}
}
}
}