Faction Test v1.0.1.0

This commit is contained in:
Regalis11
2023-02-16 15:01:28 +02:00
parent caa5a2f762
commit 2c5a7923b0
309 changed files with 7502 additions and 4335 deletions
@@ -18,9 +18,9 @@ namespace Barotrauma
public const ushort ReservedIDStart = ushort.MaxValue - 3;
public const ushort MaxEntityCount = ushort.MaxValue - 2; //ushort.MaxValue - 2 because 0 and ushort.MaxValue are reserved values
public const ushort MaxEntityCount = ushort.MaxValue - 4; //ushort.MaxValue - 4 because the 4 values above are reserved values
private static Dictionary<ushort, Entity> dictionary = new Dictionary<ushort, Entity>();
private static readonly Dictionary<ushort, Entity> dictionary = new Dictionary<ushort, Entity>();
public static IReadOnlyCollection<Entity> GetEntities()
{
return dictionary.Values;
@@ -85,6 +85,28 @@ namespace Barotrauma
this.Submarine = submarine;
spawnTime = Timing.TotalTime;
if (dictionary.Count >= MaxEntityCount)
{
Dictionary<Identifier, int> entityCounts = new Dictionary<Identifier, int>();
foreach (var entity in dictionary)
{
if (entity.Value is MapEntity me)
{
if (entityCounts.ContainsKey(me.Prefab.Identifier))
{
entityCounts[me.Prefab.Identifier]++;
}
else
{
entityCounts[me.Prefab.Identifier] = 1;
}
}
}
string errorMsg = $"Maximum amount of entities ({MaxEntityCount}) exceeded! Largest numbers of entities: " +
string.Join(", ", entityCounts.OrderByDescending(kvp => kvp.Value).Take(10).Select(kvp => $"{kvp.Key}: {kvp.Value}"));
throw new Exception(errorMsg);
}
//give a unique ID
ID = DetermineID(id, submarine);