Build 0.20.4.0

This commit is contained in:
Markus Isberg
2022-11-11 17:57:23 +02:00
parent edaf4b09fe
commit 54712b5dc9
201 changed files with 7618 additions and 2020 deletions
@@ -1,3 +1,5 @@
using Barotrauma.Extensions;
using System.Collections.Generic;
using System.Collections.Immutable;
namespace Barotrauma
@@ -18,6 +20,14 @@ namespace Barotrauma
public readonly ImmutableHashSet<int> AllowedZones;
private readonly SubmarineAvailability? submarineAvailability;
private readonly ImmutableHashSet<SubmarineAvailability> submarineAvailabilityOverrides;
public readonly record struct SubmarineAvailability(
Identifier LocationType,
SubmarineClass Class = SubmarineClass.Undefined,
int MaxTier = 0);
public Biome(ContentXElement element, LevelGenerationParametersFile file) : base(file, ParseIdentifier(element))
{
OldIdentifier = element.GetAttributeIdentifier("oldidentifier", Identifier.Empty);
@@ -34,6 +44,26 @@ namespace Barotrauma
AllowedZones = element.GetAttributeIntArray("AllowedZones", new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }).ToImmutableHashSet();
MinDifficulty = element.GetAttributeFloat("MinDifficulty", 0);
maxDifficulty = element.GetAttributeFloat("MaxDifficulty", 100);
var submarineAvailabilityOverrides = new HashSet<SubmarineAvailability>();
if (element.GetChildElement("submarines") is ContentXElement availabilityElement)
{
submarineAvailability = GetAvailability(availabilityElement);
foreach (var overrideElement in availabilityElement.GetChildElements("override"))
{
var availabilityOverride = GetAvailability(overrideElement);
submarineAvailabilityOverrides.Add(availabilityOverride);
}
}
this.submarineAvailabilityOverrides = submarineAvailabilityOverrides.ToImmutableHashSet();
static SubmarineAvailability GetAvailability(ContentXElement element)
{
return new SubmarineAvailability(
LocationType: element.GetAttributeIdentifier("locationtype", Identifier.Empty),
Class: element.GetAttributeEnum("class", SubmarineClass.Undefined),
MaxTier: element.GetAttributeInt("maxtier", 0));
}
}
public static Identifier ParseIdentifier(ContentXElement element)
@@ -47,6 +77,31 @@ namespace Barotrauma
return identifier;
}
public int HighestSubmarineTierAvailable(SubmarineClass subClass, Identifier locationType)
{
if (!submarineAvailability.HasValue)
{
// If the availability is not explicitly defined, make all subs available
return SubmarineInfo.HighestTier;
}
int maxTier = submarineAvailability.Value.MaxTier;
if (submarineAvailabilityOverrides.FirstOrNull(a => a.LocationType == locationType && a.Class == subClass) is SubmarineAvailability locationAndClassOverride)
{
maxTier = locationAndClassOverride.MaxTier;
}
else if (submarineAvailabilityOverrides.FirstOrNull(a => a.LocationType == locationType && a.Class == SubmarineClass.Undefined) is SubmarineAvailability locationOverride)
{
maxTier = locationOverride.MaxTier;
}
else if (submarineAvailabilityOverrides.FirstOrNull(a => a.LocationType == Identifier.Empty && a.Class == subClass) is SubmarineAvailability classOverride)
{
maxTier = classOverride.MaxTier;
}
return maxTier;
}
public bool IsSubmarineAvailable(SubmarineInfo info, Identifier locationType) => info.Tier <= HighestSubmarineTierAvailable(info.SubmarineClass, locationType);
public override void Dispose() { }
}
}