Unstable 0.17.0.0
This commit is contained in:
+102
-101
@@ -1,164 +1,209 @@
|
||||
using Barotrauma.Extensions;
|
||||
using Microsoft.Xna.Framework;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
class OutpostGenerationParams : ISerializableEntity
|
||||
class OutpostGenerationParams : PrefabWithUintIdentifier, ISerializableEntity
|
||||
{
|
||||
public static List<OutpostGenerationParams> Params { get; private set; }
|
||||
|
||||
public readonly static PrefabCollection<OutpostGenerationParams> OutpostParams = new PrefabCollection<OutpostGenerationParams>();
|
||||
|
||||
public virtual string Name { get; private set; }
|
||||
|
||||
public string Identifier { get; private set; }
|
||||
|
||||
private readonly List<string> allowedLocationTypes = new List<string>();
|
||||
|
||||
private readonly HashSet<Identifier> allowedLocationTypes = new HashSet<Identifier>();
|
||||
|
||||
/// <summary>
|
||||
/// Identifiers of the location types this outpost can appear in. If empty, can appear in all types of locations.
|
||||
/// </summary>
|
||||
public IEnumerable<string> AllowedLocationTypes
|
||||
public IEnumerable<Identifier> AllowedLocationTypes
|
||||
{
|
||||
get { return allowedLocationTypes; }
|
||||
}
|
||||
|
||||
[Serialize(10, isSaveable: true), Editable(MinValueInt = 1, MaxValueInt = 50)]
|
||||
[Serialize(10, IsPropertySaveable.Yes), Editable(MinValueInt = 1, MaxValueInt = 50)]
|
||||
public int TotalModuleCount
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[Serialize(200.0f, isSaveable: true), Editable(MinValueFloat = 0.0f, MaxValueFloat = 1000.0f)]
|
||||
[Serialize(200.0f, IsPropertySaveable.Yes), Editable(MinValueFloat = 0.0f, MaxValueFloat = 1000.0f)]
|
||||
public float MinHallwayLength
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[Serialize(false, isSaveable: true), Editable]
|
||||
[Serialize(false, IsPropertySaveable.Yes), Editable]
|
||||
public bool AlwaysDestructible
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[Serialize(false, isSaveable: true), Editable]
|
||||
[Serialize(false, IsPropertySaveable.Yes), Editable]
|
||||
public bool AlwaysRewireable
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[Serialize(false, isSaveable: true), Editable]
|
||||
[Serialize(false, IsPropertySaveable.Yes), Editable]
|
||||
public bool AllowStealing
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[Serialize(true, isSaveable: true), Editable]
|
||||
[Serialize(true, IsPropertySaveable.Yes), Editable]
|
||||
public bool SpawnCrewInsideOutpost
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[Serialize(true, isSaveable: true), Editable]
|
||||
|
||||
[Serialize(true, IsPropertySaveable.Yes), Editable]
|
||||
public bool LockUnusedDoors
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[Serialize(true, isSaveable: true), Editable]
|
||||
[Serialize(true, IsPropertySaveable.Yes), Editable]
|
||||
public bool RemoveUnusedGaps
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[Serialize(0.0f, isSaveable: true), Editable(MinValueFloat = 0.0f, MaxValueFloat = 100.0f)]
|
||||
[Serialize(0.0f, IsPropertySaveable.Yes), Editable(MinValueFloat = 0.0f, MaxValueFloat = 100.0f)]
|
||||
public float MinWaterPercentage
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[Serialize(0.0f, isSaveable: true), Editable(MinValueFloat = 0.0f, MaxValueFloat = 100.0f)]
|
||||
[Serialize(0.0f, IsPropertySaveable.Yes), Editable(MinValueFloat = 0.0f, MaxValueFloat = 100.0f)]
|
||||
public float MaxWaterPercentage
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
[Serialize("", isSaveable: true), Editable]
|
||||
[Serialize("", IsPropertySaveable.Yes), Editable]
|
||||
public string ReplaceInRadiation { get; set; }
|
||||
|
||||
private readonly Dictionary<string, int> moduleCounts = new Dictionary<string, int>();
|
||||
private readonly Dictionary<Identifier, int> moduleCounts = new Dictionary<Identifier, int>();
|
||||
|
||||
public IEnumerable<KeyValuePair<string, int>> ModuleCounts
|
||||
public IReadOnlyDictionary<Identifier, int> ModuleCounts
|
||||
{
|
||||
get { return moduleCounts; }
|
||||
}
|
||||
|
||||
private readonly List<List<HumanPrefab>> humanPrefabLists = new List<List<HumanPrefab>>();
|
||||
|
||||
public Dictionary<string, SerializableProperty> SerializableProperties { get; private set; }
|
||||
|
||||
protected OutpostGenerationParams(XElement element, string filePath)
|
||||
private class NpcCollection : IReadOnlyList<HumanPrefab>
|
||||
{
|
||||
Identifier = element.GetAttributeString("identifier", "");
|
||||
Name = element.GetAttributeString("name", Identifier);
|
||||
allowedLocationTypes = element.GetAttributeStringArray("allowedlocationtypes", Array.Empty<string>()).ToList();
|
||||
SerializableProperties = SerializableProperty.DeserializeProperties(this, element);
|
||||
private class Entry
|
||||
{
|
||||
private readonly HumanPrefab humanPrefab = null;
|
||||
private readonly Identifier setIdentifier = Identifier.Empty;
|
||||
private readonly Identifier npcIdentifier = Identifier.Empty;
|
||||
|
||||
public Entry(HumanPrefab humanPrefab)
|
||||
{
|
||||
this.humanPrefab = humanPrefab;
|
||||
}
|
||||
|
||||
if (element == null) { return; }
|
||||
foreach (XElement subElement in element.Elements())
|
||||
public Entry(Identifier setIdentifier, Identifier npcIdentifier)
|
||||
{
|
||||
this.setIdentifier = setIdentifier;
|
||||
this.npcIdentifier = npcIdentifier;
|
||||
}
|
||||
|
||||
public HumanPrefab HumanPrefab
|
||||
=> humanPrefab ?? NPCSet.Get(setIdentifier, npcIdentifier);
|
||||
}
|
||||
|
||||
private readonly List<Entry> entries = new List<Entry>();
|
||||
|
||||
public void Add(HumanPrefab humanPrefab)
|
||||
=> entries.Add(new Entry(humanPrefab));
|
||||
|
||||
|
||||
public void Add(Identifier setIdentifier, Identifier npcIdentifier)
|
||||
=> entries.Add(new Entry(setIdentifier, npcIdentifier));
|
||||
|
||||
public IEnumerator<HumanPrefab> GetEnumerator()
|
||||
{
|
||||
foreach (var entry in entries)
|
||||
{
|
||||
yield return entry.HumanPrefab;
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
||||
|
||||
public int Count => entries.Count;
|
||||
|
||||
public HumanPrefab this[int index] => entries[index].HumanPrefab;
|
||||
}
|
||||
|
||||
private readonly ImmutableArray<IReadOnlyList<HumanPrefab>> humanPrefabCollections;
|
||||
|
||||
public Dictionary<Identifier, SerializableProperty> SerializableProperties { get; private set; }
|
||||
|
||||
#warning TODO: this shouldn't really accept any ContentFile, issue is that RuinConfigFile and OutpostConfigFile are separate derived classes
|
||||
public OutpostGenerationParams(ContentXElement element, ContentFile file) : base(file, element.GetAttributeIdentifier("identifier", ""))
|
||||
{
|
||||
Name = element.GetAttributeString("name", Identifier.Value);
|
||||
allowedLocationTypes = element.GetAttributeIdentifierArray("allowedlocationtypes", Array.Empty<Identifier>()).ToHashSet();
|
||||
SerializableProperties = SerializableProperty.DeserializeProperties(this, element);
|
||||
|
||||
var humanPrefabCollections = new List<IReadOnlyList<HumanPrefab>>();
|
||||
foreach (var subElement in element.Elements())
|
||||
{
|
||||
switch (subElement.Name.ToString().ToLowerInvariant())
|
||||
{
|
||||
case "modulecount":
|
||||
string moduleFlag = (subElement.GetAttributeString("flag", null) ?? subElement.GetAttributeString("moduletype", "")).ToLowerInvariant();
|
||||
Identifier moduleFlag = subElement.GetAttributeIdentifier("flag", subElement.GetAttributeIdentifier("moduletype", ""));
|
||||
moduleCounts[moduleFlag] = subElement.GetAttributeInt("count", 0);
|
||||
break;
|
||||
case "npcs":
|
||||
humanPrefabLists.Add(new List<HumanPrefab>());
|
||||
foreach (XElement npcElement in subElement.Elements())
|
||||
var newCollection = new NpcCollection();
|
||||
foreach (var npcElement in subElement.Elements())
|
||||
{
|
||||
string from = npcElement.GetAttributeString("from", string.Empty);
|
||||
|
||||
// ReSharper disable once ConvertIfStatementToConditionalTernaryExpression
|
||||
if (!string.IsNullOrWhiteSpace(from))
|
||||
Identifier from = npcElement.GetAttributeIdentifier("from", Identifier.Empty);
|
||||
|
||||
if (from != Identifier.Empty)
|
||||
{
|
||||
HumanPrefab prefab = NPCSet.Get(from, npcElement.GetAttributeString("identifier", string.Empty));
|
||||
if (prefab != null)
|
||||
{
|
||||
humanPrefabLists.Last().Add(prefab);
|
||||
}
|
||||
newCollection.Add(from, npcElement.GetAttributeIdentifier("identifier", Identifier.Empty));
|
||||
}
|
||||
else
|
||||
{
|
||||
humanPrefabLists.Last().Add(new HumanPrefab(npcElement, filePath));
|
||||
newCollection.Add(new HumanPrefab(npcElement, file));
|
||||
}
|
||||
}
|
||||
humanPrefabCollections.Add(newCollection);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
this.humanPrefabCollections = humanPrefabCollections.ToImmutableArray();
|
||||
}
|
||||
|
||||
public int GetModuleCount(string moduleFlag)
|
||||
public int GetModuleCount(Identifier moduleFlag)
|
||||
{
|
||||
if (string.IsNullOrEmpty(moduleFlag) || moduleFlag == "none") { return int.MaxValue; }
|
||||
if (moduleFlag == Identifier.Empty || moduleFlag == "none") { return int.MaxValue; }
|
||||
return moduleCounts.ContainsKey(moduleFlag) ? moduleCounts[moduleFlag] : 0;
|
||||
}
|
||||
|
||||
public void SetModuleCount(string moduleFlag, int count)
|
||||
public void SetModuleCount(Identifier moduleFlag, int count)
|
||||
{
|
||||
if (string.IsNullOrEmpty(moduleFlag) || moduleFlag == "none") { return; }
|
||||
if (moduleFlag == Identifier.Empty || moduleFlag == "none") { return; }
|
||||
if (count <= 0)
|
||||
{
|
||||
moduleCounts.Remove(moduleFlag);
|
||||
@@ -169,66 +214,22 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
public void SetAllowedLocationTypes(IEnumerable<string> allowedLocationTypes)
|
||||
public void SetAllowedLocationTypes(IEnumerable<Identifier> allowedLocationTypes)
|
||||
{
|
||||
this.allowedLocationTypes.Clear();
|
||||
foreach (string locationType in allowedLocationTypes)
|
||||
foreach (Identifier locationType in allowedLocationTypes)
|
||||
{
|
||||
if (locationType.Equals("any", StringComparison.OrdinalIgnoreCase)) { continue; }
|
||||
if (locationType == "any") { continue; }
|
||||
this.allowedLocationTypes.Add(locationType);
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<HumanPrefab> GetHumanPrefabs(Rand.RandSync randSync)
|
||||
public IReadOnlyList<HumanPrefab> GetHumanPrefabs(Rand.RandSync randSync)
|
||||
{
|
||||
if (humanPrefabLists == null || !humanPrefabLists.Any()) { return Enumerable.Empty<HumanPrefab>(); }
|
||||
return humanPrefabLists.GetRandom(randSync);
|
||||
if (!humanPrefabCollections.Any()) { return Array.Empty<HumanPrefab>(); }
|
||||
return humanPrefabCollections.GetRandom(randSync);
|
||||
}
|
||||
|
||||
public static void LoadPresets()
|
||||
{
|
||||
Params = new List<OutpostGenerationParams>();
|
||||
var files = GameMain.Instance.GetFilesOfType(ContentType.OutpostConfig);
|
||||
foreach (ContentFile file in files)
|
||||
{
|
||||
XDocument doc = XMLExtensions.TryLoadXml(file.Path);
|
||||
if (doc?.Root == null) { continue; }
|
||||
var mainElement = doc.Root;
|
||||
if (doc.Root.IsOverride())
|
||||
{
|
||||
Params.Clear();
|
||||
DebugConsole.NewMessage($"Overriding all outpost generation parameters with '{file.Path}'", Color.Yellow);
|
||||
}
|
||||
|
||||
foreach (XElement element in mainElement.Elements())
|
||||
{
|
||||
bool isOverride = element.IsOverride();
|
||||
XElement sourceElement = isOverride ? element.FirstElement() : element;
|
||||
string elementName = sourceElement.Name.ToString().ToLowerInvariant();
|
||||
string identifier = sourceElement.GetAttributeString("identifier", null);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(identifier))
|
||||
{
|
||||
DebugConsole.ThrowError($"No identifier defined for the outpost config '{elementName}' in file '{file.Path}'");
|
||||
continue;
|
||||
}
|
||||
var existingParams = Params.Find(p => p.Identifier == identifier);
|
||||
if (existingParams != null)
|
||||
{
|
||||
if (isOverride)
|
||||
{
|
||||
DebugConsole.NewMessage($"Overriding outpost config '{identifier}' using the file '{file.Path}'", Color.Yellow);
|
||||
Params.Remove(existingParams);
|
||||
}
|
||||
else
|
||||
{
|
||||
DebugConsole.ThrowError($"Duplicate outpost config: '{identifier}' defined in {elementName} of '{file.Path}'");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
Params.Add(new OutpostGenerationParams(element, file.Path));
|
||||
}
|
||||
}
|
||||
}
|
||||
public override void Dispose() { }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user