5dplomacy/MultiversalDiplomacy/Model/Province.cs

108 lines
3.2 KiB
C#
Raw Permalink Normal View History

namespace MultiversalDiplomacy.Model;
/// <summary>
/// Represents a single province as it exists across all timelines.
/// </summary>
public class Province
{
/// <summary>
/// The province's full human-readable name.
/// </summary>
public string Name { get; }
/// <summary>
/// The province's shorthand abbreviation.
/// </summary>
public string[] Abbreviations { get; }
/// <summary>
/// Whether the province contains a supply center.
/// </summary>
public bool IsSupplyCenter { get; }
/// <summary>
/// Whether the province contains a time center.
/// </summary>
public bool IsTimeCenter { get; }
/// <summary>
/// The occupiable locations in this province. Only one location can be occupied at a time.
/// </summary>
public IEnumerable<Location> Locations => LocationList;
private List<Location> LocationList { get; set; }
2024-08-25 03:50:08 +00:00
/// <summary>
/// The province's name and abbreviations as a single enumeration.
/// </summary>
public IEnumerable<string> AllNames => Abbreviations.Append(Name);
public Province(string name, string[] abbreviations, bool isSupply, bool isTime)
{
this.Name = name;
this.Abbreviations = abbreviations;
this.IsSupplyCenter = isSupply;
this.IsTimeCenter = isTime;
2024-08-14 13:55:40 +00:00
this.LocationList = [];
}
public override string ToString()
{
return this.Name;
}
2024-08-27 02:43:12 +00:00
/// <summary>
/// Whether a name is the name or abbreviation of this province.
/// </summary>
public bool Is(string name)
=> name.EqualsAnyCase(Name) || Abbreviations.Any(name.EqualsAnyCase);
/// <summary>
/// Create a new province with no supply center.
/// </summary>
public static Province Empty(string name, params string[] abbreviations)
2024-08-14 13:55:40 +00:00
=> new(name, abbreviations, isSupply: false, isTime: false);
/// <summary>
/// Create a new province with a supply center.
/// </summary>
public static Province Supply(string name, params string[] abbreviations)
2024-08-14 13:55:40 +00:00
=> new(name, abbreviations, isSupply: true, isTime: false);
/// <summary>
/// Create a new province with a time center.
/// </summary>
public static Province Time(string name, params string[] abbreviations)
2024-08-14 13:55:40 +00:00
=> new(name, abbreviations, isSupply: true, isTime: true);
/// <summary>
/// Create a new land location in this province.
/// </summary>
public Province AddLandLocation()
{
2024-08-14 13:55:40 +00:00
Location location = new(this, "land", "l", LocationType.Land);
this.LocationList.Add(location);
return this;
}
/// <summary>
/// Create a new ocean location.
/// </summary>
public Province AddOceanLocation()
{
2024-08-14 13:55:40 +00:00
Location location = new(this, "water", "w", LocationType.Water);
this.LocationList.Add(location);
return this;
}
/// <summary>
/// Create a new coastal location. Coastal locations must have names to disambiguate them
/// from the single land location in coastal provinces.
/// </summary>
public Province AddCoastLocation(string name, string abbreviation)
{
2024-08-14 13:55:40 +00:00
Location location = new(this, name, abbreviation, LocationType.Water);
this.LocationList.Add(location);
return this;
}
}