(ded4a3e0a) v0.9.0.7

This commit is contained in:
Joonas Rikkonen
2019-06-25 16:00:44 +03:00
parent e5ae622c77
commit 4a51db77b5
1777 changed files with 421528 additions and 917 deletions
@@ -9,6 +9,7 @@ namespace Barotrauma
class Entity : ISpatialEntity
{
public const ushort NullEntityID = 0;
public const ushort EntitySpawnerID = ushort.MaxValue;
private static Dictionary<ushort, Entity> dictionary = new Dictionary<ushort, Entity>();
public static List<Entity> GetEntityList()
@@ -43,12 +44,19 @@ namespace Barotrauma
}
set
{
if (this is EntitySpawner) { return; }
if (value == NullEntityID)
{
DebugConsole.ThrowError("Cannot set the ID of an entity to " + NullEntityID +
"! The value is reserved for entity events referring to a non-existent (e.g. removed) entity.\n" + Environment.StackTrace);
return;
}
if (value == EntitySpawnerID)
{
DebugConsole.ThrowError("Cannot set the ID of an entity to " + EntitySpawnerID +
"! The value is reserved for EntitySpawner.\n" + Environment.StackTrace);
return;
}
if (dictionary.TryGetValue(id, out Entity thisEntity) && thisEntity == this)
{
@@ -107,15 +115,17 @@ namespace Barotrauma
this.Submarine = submarine;
//give a unique ID
id = FindFreeID(submarine == null ? (ushort)1 : submarine.IdOffset);
id = this is EntitySpawner ?
EntitySpawnerID :
FindFreeID(submarine == null ? (ushort)1 : submarine.IdOffset);
dictionary.Add(id, this);
}
public static ushort FindFreeID(ushort idOffset = 0)
{
//ushort.MaxValue - 1 because 0 is a reserved value
if (dictionary.Count >= ushort.MaxValue - 1)
//ushort.MaxValue - 2 because 0 and ushort.MaxValue are reserved values
if (dictionary.Count >= ushort.MaxValue - 2)
{
throw new Exception("Maximum amount of entities (" + (ushort.MaxValue - 1) + ") reached!");
}
@@ -228,7 +228,11 @@ namespace Barotrauma
attacker = item.GetComponent<Projectile>()?.User;
if (attacker == null) attacker = item.GetComponent<MeleeWeapon>()?.User;
}
c.AddDamage(limb.WorldPosition, modifiedAfflictions, attack.Stun * distFactor, false, attacker: attacker);
//use a position slightly from the limb's position towards the explosion
//ensures that the attack hits the correct limb and that the direction of the hit can be determined correctly in the AddDamage methods
Vector2 hitPos = limb.WorldPosition + (worldPosition - limb.WorldPosition) / dist * 0.01f;
c.AddDamage(hitPos, modifiedAfflictions, attack.Stun * distFactor, false, attacker: attacker);
if (attack.StatusEffects != null && attack.StatusEffects.Any())
{
@@ -122,6 +122,8 @@ namespace Barotrauma
GapList.Add(this);
InsertToList();
DebugConsole.Log("Created gap (" + ID + ")");
}
public override MapEntity Clone()
@@ -242,6 +242,8 @@ namespace Barotrauma
WaterVolume = 0.0f;
InsertToList();
DebugConsole.Log("Created hull (" + ID + ")");
}
public static Rectangle GetBorders()
@@ -107,7 +107,7 @@ namespace Barotrauma
if (Screen.Selected == GameMain.SubEditorScreen)
{
MapEntity.SelectedList.Clear();
MapEntity.SelectedList.AddRange(entities);
entities.ForEach(e => MapEntity.AddSelection(e));
}
#endif
return entities;
@@ -1274,6 +1274,8 @@ namespace Barotrauma
}
}
DebugConsole.Log("Generating level resources...");
for (int i = 0; i < generationParams.ItemCount; i++)
{
var selectedPrefab = ToolBox.SelectWeightedRandom(
@@ -1286,6 +1288,7 @@ namespace Barotrauma
var selectedEdge = selectedCell.Edges.GetRandom(e => e.IsSolid && !e.OutsideLevel, Rand.RandSync.Server);
if (selectedEdge == null) continue;
float edgePos = Rand.Range(0.0f, 1.0f, Rand.RandSync.Server);
Vector2 selectedPos = Vector2.Lerp(selectedEdge.Point1, selectedEdge.Point2, edgePos);
Vector2 edgeNormal = selectedEdge.GetNormal(selectedCell);
@@ -1306,6 +1309,8 @@ namespace Barotrauma
#endif
}
}
DebugConsole.Log("Level resources generated");
}
public Vector2 GetRandomItemPos(PositionType spawnPosType, float randomSpread, float minDistFromSubs, float offsetFromWall = 10.0f)
@@ -1022,12 +1022,12 @@ namespace Barotrauma.RuinGeneration
{
targetEntity = ruinEntities.GetRandom(e =>
e.Room == targetRoom &&
e.Entity.prefab?.Identifier == connection.TargetEntityIdentifier)?.Entity;
e.Entity.prefab?.Identifier == connection.TargetEntityIdentifier, Rand.RandSync.Server)?.Entity;
}
}
else
{
targetEntity = ruinEntities.GetRandom(e => e.Entity.prefab?.Identifier == connection.TargetEntityIdentifier)?.Entity;
targetEntity = ruinEntities.GetRandom(e => e.Entity.prefab?.Identifier == connection.TargetEntityIdentifier, Rand.RandSync.Server)?.Entity;
}
if (targetEntity == null) continue;
@@ -57,6 +57,8 @@ namespace Barotrauma
linkedToID = new List<ushort>();
InsertToList();
DebugConsole.Log("Created linked submarine (" + ID + ")");
}
public static LinkedSubmarine CreateDummy(Submarine mainSub, Submarine linkedSub)
@@ -207,20 +207,22 @@ namespace Barotrauma
//clone links between the entities
for (int i = 0; i < clones.Count; i++)
{
if (entitiesToClone[i].linkedTo == null) continue;
if (entitiesToClone[i].linkedTo == null) { continue; }
foreach (MapEntity linked in entitiesToClone[i].linkedTo)
{
if (!entitiesToClone.Contains(linked)) continue;
if (!entitiesToClone.Contains(linked)) { continue; }
clones[i].linkedTo.Add(clones[entitiesToClone.IndexOf(linked)]);
}
}
//connect clone wires to the clone items
//connect clone wires to the clone items and refresh links between doors and gaps
for (int i = 0; i < clones.Count; i++)
{
var cloneItem = clones[i] as Item;
if (cloneItem == null) continue;
if (cloneItem == null) { continue; }
var door = cloneItem.GetComponent<Door>();
if (door != null) { door.RefreshLinkedGap(); }
var cloneWire = cloneItem.GetComponent<Wire>();
if (cloneWire == null) continue;
@@ -231,7 +233,7 @@ namespace Barotrauma
for (int n = 0; n < 2; n++)
{
if (originalWire.Connections[n] == null) continue;
if (originalWire.Connections[n] == null) { continue; }
var connectedItem = originalWire.Connections[n].Item;
if (connectedItem == null) continue;
@@ -555,7 +557,7 @@ namespace Barotrauma
}
}
[Serialize(1f, false), Editable(0.1f, 10f, DecimalCount = 3, ValueStep = 0.1f)]
[Serialize(1f, true), Editable(0.1f, 10f, DecimalCount = 3, ValueStep = 0.1f)]
public virtual float Scale { get; set; } = 1;
#endregion
}
@@ -183,6 +183,29 @@ namespace Barotrauma
}
}
protected Vector2 textureScale = Vector2.One;
[Editable(DecimalCount = 3, MinValueFloat = 0.01f, MaxValueFloat = 10f, ValueStep = 0.1f), Serialize("1.0, 1.0", false)]
public Vector2 TextureScale
{
get { return textureScale; }
set
{
textureScale = new Vector2(
MathHelper.Clamp(value.X, 0.01f, 10),
MathHelper.Clamp(value.Y, 0.01f, 10));
}
}
protected Vector2 textureOffset = Vector2.Zero;
[Editable(MinValueFloat = -1000f, MaxValueFloat = 1000f, ValueStep = 10f), Serialize("0.0, 0.0", true)]
public Vector2 TextureOffset
{
get { return textureOffset; }
set { textureOffset = value; }
}
private Rectangle defaultRect;
public override Rectangle Rect
@@ -296,9 +319,8 @@ namespace Barotrauma
defaultRect = rectangle;
rect = rectangle;
#if CLIENT
TextureScale = sp.TextureScale;
#endif
spriteColor = prefab.SpriteColor;
if (sp.IsHorizontal.HasValue)
{
@@ -355,6 +377,8 @@ namespace Barotrauma
}
InsertToList();
DebugConsole.Log("Created " + Name + " (" + ID + ")");
}
partial void InitProjSpecific();
@@ -365,7 +365,9 @@ namespace Barotrauma
{
using (MemoryStream mem = new MemoryStream(Convert.FromBase64String(previewImageData)))
{
PreviewImage = new Sprite(TextureLoader.FromStream(mem, preMultiplyAlpha: false), null, null);
var texture = TextureLoader.FromStream(mem, preMultiplyAlpha: false, path: filePath);
if (texture == null) { throw new Exception("PreviewImage texture returned null"); }
PreviewImage = new Sprite(texture, null, null);
}
}
catch (Exception e)
@@ -382,7 +384,6 @@ namespace Barotrauma
DockedTo = new List<Submarine>();
ID = ushort.MaxValue;
FreeID();
}
@@ -1405,7 +1406,7 @@ namespace Barotrauma
}
ID = (ushort)(ushort.MaxValue - Submarine.loaded.IndexOf(this));
ID = (ushort)(ushort.MaxValue - 1 - Submarine.loaded.IndexOf(this));
}
public static Submarine Load(XElement element, bool unloadPrevious)
@@ -1553,7 +1554,7 @@ namespace Barotrauma
if (MainSub == this) MainSub = null;
if (MainSubs[1] == this) MainSubs[1] = null;
DockedTo.Clear();
DockedTo?.Clear();
}
public void Dispose()
@@ -125,6 +125,8 @@ namespace Barotrauma
InsertToList();
WayPointList.Add(this);
DebugConsole.Log("Created waypoint (" + ID + ")");
currentHull = Hull.FindHull(WorldPosition);
}