2024-08-13 15:17:34 +00:00
|
|
|
using System.Text.Json.Serialization;
|
|
|
|
|
2022-02-18 17:45:28 +00:00
|
|
|
namespace MultiversalDiplomacy.Model;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Represents a locus of connectivity in a province. Land-locked and ocean/sea provinces
|
|
|
|
/// have one location. Coastal provinces have a land location and some number of named
|
|
|
|
/// water locations.
|
|
|
|
/// </summary>
|
|
|
|
public class Location
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// The province to which this location belongs.
|
2024-08-13 15:17:34 +00:00
|
|
|
/// </summary>
|
|
|
|
[JsonIgnore]
|
2022-02-18 17:45:28 +00:00
|
|
|
public Province Province { get; }
|
|
|
|
|
2024-08-13 15:17:34 +00:00
|
|
|
public string ProvinceName => Province.Name;
|
|
|
|
|
2022-02-18 17:45:28 +00:00
|
|
|
/// <summary>
|
|
|
|
/// The location's full human-readable name.
|
|
|
|
/// </summary>
|
2024-08-14 13:55:40 +00:00
|
|
|
public string Name { get; }
|
2022-02-18 17:45:28 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// The location's shorthand abbreviation.
|
|
|
|
/// </summary>
|
2024-08-14 13:55:40 +00:00
|
|
|
public string Abbreviation { get; }
|
2022-02-18 17:45:28 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// The location's type.
|
|
|
|
/// </summary>
|
|
|
|
public LocationType Type { get; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// The locations that border this location.
|
|
|
|
/// </summary>
|
2024-08-13 15:17:34 +00:00
|
|
|
[JsonIgnore]
|
2022-02-18 17:45:28 +00:00
|
|
|
public IEnumerable<Location> Adjacents => this.AdjacentList;
|
|
|
|
private List<Location> AdjacentList { get; set; }
|
|
|
|
|
2024-08-14 14:39:49 +00:00
|
|
|
/// <summary>
|
|
|
|
/// The unique name of this location in the map.
|
|
|
|
/// </summary>
|
2024-08-15 13:52:08 +00:00
|
|
|
public string Key => $"{this.ProvinceName}/{this.Abbreviation}";
|
2024-08-14 14:39:49 +00:00
|
|
|
|
2024-08-14 13:55:40 +00:00
|
|
|
public Location(Province province, string name, string abbreviation, LocationType type)
|
2022-02-18 17:45:28 +00:00
|
|
|
{
|
|
|
|
this.Province = province;
|
|
|
|
this.Name = name;
|
|
|
|
this.Abbreviation = abbreviation;
|
|
|
|
this.Type = type;
|
|
|
|
this.AdjacentList = new List<Location>();
|
|
|
|
}
|
|
|
|
|
2024-08-16 05:00:25 +00:00
|
|
|
public static (string province, string location) SplitKey(string locationKey)
|
|
|
|
{
|
|
|
|
var split = locationKey.Split(['/'], 2);
|
|
|
|
return (split[0], split[1]);
|
|
|
|
}
|
|
|
|
|
2022-03-16 00:36:47 +00:00
|
|
|
public override string ToString()
|
|
|
|
{
|
2024-08-14 13:55:40 +00:00
|
|
|
return this.Name == "land" || this.Name == "water"
|
2022-03-16 00:36:47 +00:00
|
|
|
? $"{this.Province.Name} ({this.Type})"
|
|
|
|
: $"{this.Province.Name} ({this.Type}:{this.Name}]";
|
|
|
|
}
|
|
|
|
|
2022-02-18 17:45:28 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Set another location as bordering this location.
|
|
|
|
/// </summary>
|
|
|
|
public void AddBorder(Location other)
|
|
|
|
{
|
|
|
|
if (!this.AdjacentList.Contains(other)) this.AdjacentList.Add(other);
|
|
|
|
if (!other.AdjacentList.Contains(this)) other.AdjacentList.Add(this);
|
|
|
|
}
|
|
|
|
}
|