1 using Microsoft.Xna.Framework;
3 using System.Collections.Generic;
4 using System.Globalization;
16 private int minWidth, maxWidth;
17 private int minHeight, maxHeight;
19 private int minBranchCount, maxBranchCount;
31 public readonly Dictionary<Identifier, float>
OverrideCommonness =
new Dictionary<Identifier, float>();
43 get {
return minWidth; }
44 set { minWidth = Math.Max(value, 1000); }
50 get {
return maxWidth; }
51 set { maxWidth = Math.Max(value, minWidth); }
57 get {
return minHeight; }
58 set { minHeight = Math.Max(value, 1000); }
64 get {
return maxHeight; }
65 set { maxHeight = Math.Max(value, minHeight); }
71 get {
return minBranchCount; }
72 set { minBranchCount = Math.Max(value, 0); }
78 get {
return maxBranchCount; }
79 set { maxBranchCount = Math.Max(value, minBranchCount); }
89 [
Serialize(0.1f,
IsPropertySaveable.Yes, description:
"What portion of the empty cells in the cave should be turned into destructible walls? For example, 0.1 = 10%."),
Editable(MinValueFloat = 0, MaxValueFloat = 1.0f, DecimalCount = 2 )]
101 var caveParams =
CaveParams.OrderBy(p => p.UintIdentifier).ToList();
102 if (caveParams.All(p => p.GetCommonness(level.
LevelData, abyss) <= 0.0f))
104 return caveParams.First();
106 return ToolBox.SelectWeightedRandom(caveParams.ToList(), caveParams.Select(p => p.GetCommonness(level.
LevelData, abyss)).ToList(), rand);
116 if (levelData?.
Biome !=
null)
120 return biomeCommonness;
131 foreach (var subElement
in element.Elements())
133 switch (subElement.Name.ToString().ToLowerInvariant())
141 case "overridecommonness":
142 Identifier levelType = subElement.GetAttributeIdentifier(
"leveltype",
"");
152 public void Save(XElement element)
157 bool elementFound =
false;
158 foreach (var subElement
in element.Elements())
160 if (subElement.NameAsIdentifier() ==
"overridecommonness"
161 && subElement.GetAttributeIdentifier(
"leveltype",
"") == overrideCommonness.Key)
163 subElement.Attribute(
"commonness").Value = overrideCommonness.Value.ToString(
"G", CultureInfo.InvariantCulture);
170 element.Add(
new XElement(
"overridecommonness",
171 new XAttribute(
"leveltype", overrideCommonness.Key),
172 new XAttribute(
"commonness", overrideCommonness.Value.ToString(
"G", CultureInfo.InvariantCulture))));
float DestructibleWallRatio
static CaveGenerationParams GetRandom(Level level, bool abyss, Rand.RandSync rand)
void Save(XElement element)
float GetCommonness(LevelData levelData, bool abyss)
readonly Dictionary< Identifier, float > OverrideCommonness
Overrides the commonness of the object in a specific level type. Key = name of the level type,...
Dictionary< Identifier, SerializableProperty > SerializableProperties
readonly Sprite WallEdgeSprite
static readonly PrefabCollection< CaveGenerationParams > CaveParams
readonly Sprite WallSprite
CaveGenerationParams(ContentXElement element, CaveGenerationParametersFile file)
LevelGenerationParams GenerationParams
readonly LevelData LevelData
readonly Identifier Identifier
Prefab that has a property serves as a deterministic hash of a prefab's identifier....
static Dictionary< Identifier, SerializableProperty > DeserializeProperties(object obj, XElement element=null)
static void SerializeProperties(ISerializableEntity obj, XElement element, bool saveIfDefault=false, bool ignoreEditable=false)