/// <summary> /// Helper method determines if the region has enough parquets satisfying the given predicate /// to meet or exceed the given threshold. /// </summary> /// <param name="in_region">The region to test.</param> /// <param name="in_predicate">A predicate indicating if the parquet should be counted.</param> /// <param name="in_threshold">A total number of parquets that must be met for the region to qualify.</param> /// <returns><c>true</c>, if enough parquets satisfy the conditions given, <c>false</c> otherwise.</returns> private static bool CountMeetsOrExceedsThreshold(MapRegion in_region, Predicate <ParquetParent> in_predicate, int in_threshold) { var count = 0; foreach (var parquet in in_region.GetAllParquets()) { if (in_predicate(parquet)) { count++; } } return(count >= in_threshold); }
/// <summary> /// Reads the region stored at the given location. /// </summary> /// <param name="in_path">The location of the region to load.</param> public void LoadMapRegion(string in_path) { // TODO Convert this to use multiplatform utils. var serialized = File.ReadAllText(in_path); if (MapRegion.TryDeserializeFromString(serialized, out var result)) { _currentRegion = result; } else { Error.Handle($"Could not load region from {in_path}"); } }
/// <summary> /// Determines which <see cref="T:ParquetClassLibrary.Sandbox.Biome"/> the /// given <see cref="T:ParquetClassLibrary.Sandbox.MapRegion"/> corresponds to. /// </summary> /// <param name="in_region">The region to investigate.</param> /// <returns>The appropriate <see cref="T:ParquetClassLibrary.Sandbox.Biome"/>.</returns> public static Biome GetBiome(this MapRegion in_region) { var result = Biome.Field; if (in_region.HasBuildings()) { result = Biome.Town; } else { switch (in_region.ElevationLocal) { case Elevation.AboveGround: if (in_region.IsHeavenly()) { result = Biome.Heavens; } else { result = Biome.Alpine; } break; case Elevation.LevelGround: if (in_region.IsVolcanic()) { result = Biome.Volcano; } else if (in_region.IsCoastal()) { result = Biome.Seaside; } else if (in_region.IsDeserted()) { result = Biome.Desert; } else if (in_region.IsFrozen()) { result = Biome.Tundra; } else if (in_region.IsSwampy()) { result = Biome.Swamp; } else if (in_region.IsForested()) { result = Biome.Forest; } break; case Elevation.BelowGround: if (in_region.IsVolcanic()) { result = Biome.Inferno; } else { result = Biome.Cavern; } break; } } return(result); }
/// <summary> /// Determines if the region has enough buildings to qualify as a town. /// </summary> /// <param name="in_region">The region to test.</param> /// <returns><c>true</c>, if the region meets the criteria, <c>false</c> otherwise.</returns> internal static bool HasBuildings(this MapRegion in_region) { // TODO Implement this! return(false); }
/// <summary> /// Determines if the region has enough trees to qualify as a forest. /// </summary> /// <param name="in_region">The region to test.</param> /// <returns><c>true</c>, if the region meets the criteria, <c>false</c> otherwise.</returns> internal static bool IsForested(this MapRegion in_region) { return(CountMeetsOrExceedsThreshold(in_region, p => p.AddsToBiome.IsForested(), landThreshold)); }
/// <summary> /// Determines if the region has enough flowing water to qualify as oceanic. /// </summary> /// <param name="in_region">The region to test.</param> /// <returns><c>true</c>, if the region meets the criteria, <c>false</c> otherwise.</returns> internal static bool IsCoastal(this MapRegion in_region) { return(CountMeetsOrExceedsThreshold(in_region, p => p.AddsToBiome.IsCoastal(), fluidThreshold)); }