v0.11.0.9

This commit is contained in:
Joonas Rikkonen
2020-12-09 16:34:16 +02:00
parent bbf06f0984
commit f433a7ba10
325 changed files with 13947 additions and 3652 deletions
@@ -2,7 +2,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Xml.Linq;
using Barotrauma.Extensions;
using Barotrauma.Networking;
@@ -10,6 +9,7 @@ using FarseerPhysics;
using FarseerPhysics.Dynamics;
using Microsoft.Xna.Framework;
using Vector2 = Microsoft.Xna.Framework.Vector2;
using Vector4 = Microsoft.Xna.Framework.Vector4;
namespace Barotrauma.Items.Components
{
@@ -138,19 +138,25 @@ namespace Barotrauma.Items.Components
public TileSide Sides = TileSide.None;
public TileSide BlockedSides = TileSide.None;
public readonly FoliageConfig FlowerConfig;
public readonly FoliageConfig LeafConfig;
public FoliageConfig FlowerConfig;
public FoliageConfig LeafConfig;
public int FailedGrowthAttempts;
public Rectangle Rect;
public Vector2 Position;
public Color HealthColor = Color.Transparent;
public float DecayDelay;
private float VineStep;
private float FlowerStep;
private readonly float diameter;
public Vector2 offset;
public VineTileType Type;
public readonly Dictionary<TileSide, Vector2> AdjacentPositions;
public static int Size = 32;
public float VineStep;
public float FlowerStep;
private float growthStep;
public float GrowthStep
{
get => growthStep;
@@ -166,17 +172,12 @@ namespace Barotrauma.Items.Components
}
}
private readonly float diameter;
private Vector2 offset;
public Color HealthColor = Color.Transparent;
public float DecayDelay;
private readonly Growable Parent;
public VineTileType Type;
private readonly Growable? Parent;
public readonly Dictionary<TileSide, Vector2> AdjacentPositions;
public static int Size = 32;
public VineTile(Growable parent, Vector2 position, VineTileType type, FoliageConfig? flowerConfig = null, FoliageConfig? leafConfig = null, Rectangle? rect = null)
public VineTile(Growable? parent, Vector2 position, VineTileType type, FoliageConfig? flowerConfig = null, FoliageConfig? leafConfig = null, Rectangle? rect = null)
{
FlowerConfig = flowerConfig ?? FoliageConfig.EmptyConfig;
LeafConfig = leafConfig ?? FoliageConfig.EmptyConfig;
@@ -197,7 +198,9 @@ namespace Barotrauma.Items.Components
public void UpdateScale(float deltaTime)
{
if (Parent.Decayed && GrowthStep > 1.0f)
bool decayed = Parent?.Decayed ?? false;
if (decayed && GrowthStep > 1.0f)
{
if (DecayDelay > 0)
{
@@ -209,7 +212,7 @@ namespace Barotrauma.Items.Components
}
}
if (GrowthStep >= 2.0f || Parent.Decayed) { return; }
if (GrowthStep >= 2.0f || decayed) { return; }
GrowthStep += deltaTime;
@@ -282,13 +285,26 @@ namespace Barotrauma.Items.Components
}
}
int value = pool[Growable.RandomInt(0, possible, random)];
int value;
if (Parent == null)
{
value = pool[Growable.RandomInt(0, possible, random)];
}
else
{
var (x, y, z, w) = Parent.GrowthWeights;
float[] weights = { x, y, z, w };
value = pool.RandomElementByWeight(i => weights[i]);
}
return (TileSide) (1 << value);
}
public bool CanGrowMore() => (Sides | BlockedSides).Count() < 4;
public bool IsSideBlocked(TileSide side) => BlockedSides.IsBitSet(side) || Sides.IsBitSet(side);
public static Rectangle CreatePlantRect(Vector2 pos) => new Rectangle((int) pos.X - Size / 2, (int) pos.Y + Size / 2, Size, Size);
}
@@ -313,6 +329,11 @@ namespace Barotrauma.Items.Components
return count;
}
public static TileSide GetOppositeSide(this TileSide side)
{
return (TileSide) (1 << ((int) Math.Log2((int) side) + 2) % 4);
}
}
internal partial class Growable : ItemComponent, IServerSerializable
@@ -371,6 +392,9 @@ namespace Barotrauma.Items.Components
[Serialize("0.26,0.27,0.29,1.0", true, "Tint of a dead plant.")]
public Color DeadTint { get; set; }
[Serialize("1,1,1,1", true, "Probability for the plant to grow in a direction.")]
public Vector4 GrowthWeights { get; set; }
private const float increasedDeathSpeed = 10f;
private bool accelerateDeath;
private float health;
@@ -666,7 +690,23 @@ namespace Barotrauma.Items.Components
TileSide side = oldVines.GetRandomFreeSide(random);
if (side == TileSide.None) { continue; }
if (side == TileSide.None)
{
oldVines.FailedGrowthAttempts++;
continue;
}
if (GrowthWeights != Vector4.One)
{
var (x, y, z, w) = GrowthWeights;
float[] weights = { x, y, z, w };
int index = (int) Math.Log2((int) side);
if (MathUtils.NearlyEqual(weights[index], 0f))
{
oldVines.FailedGrowthAttempts++;
continue;
}
}
Vector2 pos = oldVines.AdjacentPositions[side];
Rectangle rect = VineTile.CreatePlantRect(pos);
@@ -705,8 +745,7 @@ namespace Barotrauma.Items.Components
// if the X value is bigger than Y it's to the left or right of us and then check if X is negative or positive to determine if it's right or left
TileSide connectingSide = absDistX > absDistY ? distX > 0 ? TileSide.Right : TileSide.Left : distY > 0 ? TileSide.Top : TileSide.Bottom;
// We use log2 to find the index and offset that index by 2 since the opposite side is always 2 offsets away
TileSide oppositeSide = (TileSide) (1 << ((int) Math.Log2((int) connectingSide) + 2) % 4);
TileSide oppositeSide = connectingSide.GetOppositeSide();
if (otherVine.BlockedSides.IsBitSet(connectingSide))
{
@@ -810,9 +849,9 @@ namespace Barotrauma.Items.Components
return element;
}
public override void Load(XElement componentElement, bool usePrefabValues)
public override void Load(XElement componentElement, bool usePrefabValues, IdRemap idRemap)
{
base.Load(componentElement, usePrefabValues);
base.Load(componentElement, usePrefabValues, idRemap);
flowerTiles = componentElement.GetAttributeIntArray("flowertiles", new int[0]);
Decayed = componentElement.GetAttributeBool("decayed", false);