Faction Test 100.4.0.0

This commit is contained in:
Markus Isberg
2022-11-14 18:28:28 +02:00
parent 87426b68b2
commit c772b61fc1
412 changed files with 16984 additions and 5530 deletions
@@ -1,3 +1,6 @@
using System;
using Barotrauma.Extensions;
using System.Collections.Generic;
using System.Collections.Immutable;
namespace Barotrauma
@@ -11,13 +14,24 @@ namespace Barotrauma
public readonly LocalizedString Description;
public readonly bool IsEndBiome;
public readonly int EndBiomeLocationCount;
public readonly float MinDifficulty;
private readonly float maxDifficulty;
public float ActualMaxDifficulty => maxDifficulty;
public float AdjustedMaxDifficulty => maxDifficulty - 0.1f;
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);
@@ -31,9 +45,31 @@ namespace Barotrauma
element.GetAttributeString("description", ""));
IsEndBiome = element.GetAttributeBool("endbiome", false);
EndBiomeLocationCount = Math.Max(1, element.GetAttributeInt("endbiomelocationcount", 1));
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 +83,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() { }
}
}