2024-08-13 15:17:34 +00:00
|
|
|
using System.Text.Json.Serialization;
|
|
|
|
|
2022-02-18 20:13:23 +00:00
|
|
|
namespace MultiversalDiplomacy.Model;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Represents a unit at a particular point in time.
|
|
|
|
/// </summary>
|
|
|
|
public class Unit
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// The previous iteration of a unit. This is null if the unit was just built.
|
|
|
|
/// </summary>
|
|
|
|
public Unit? Past { get; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// The location on the map where the unit is.
|
|
|
|
/// </summary>
|
|
|
|
public Location Location { get; }
|
|
|
|
|
2024-08-14 14:39:49 +00:00
|
|
|
public string LocationId => Location.Designation;
|
|
|
|
|
2022-03-30 19:52:57 +00:00
|
|
|
/// <summary>
|
|
|
|
/// The province where the unit is.
|
|
|
|
/// </summary>
|
2024-08-13 15:17:34 +00:00
|
|
|
[JsonIgnore]
|
2022-03-30 19:52:57 +00:00
|
|
|
public Province Province => this.Location.Province;
|
|
|
|
|
2022-02-18 20:13:23 +00:00
|
|
|
/// <summary>
|
|
|
|
/// The season in time when the unit is.
|
|
|
|
/// </summary>
|
|
|
|
public Season Season { get; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// The allegiance of the unit.
|
|
|
|
/// </summary>
|
|
|
|
public Power Power { get; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// The type of unit.
|
|
|
|
/// </summary>
|
|
|
|
public UnitType Type { get; }
|
|
|
|
|
2022-03-29 00:41:38 +00:00
|
|
|
/// <summary>
|
|
|
|
/// The unit's spatiotemporal location as a province-season tuple.
|
|
|
|
/// </summary>
|
2022-03-30 19:52:57 +00:00
|
|
|
public (Province province, Season season) Point => (this.Province, this.Season);
|
2022-03-29 00:41:38 +00:00
|
|
|
|
2022-02-18 20:13:23 +00:00
|
|
|
private Unit(Unit? past, Location location, Season season, Power power, UnitType type)
|
|
|
|
{
|
|
|
|
this.Past = past;
|
|
|
|
this.Location = location;
|
|
|
|
this.Season = season;
|
|
|
|
this.Power = power;
|
|
|
|
this.Type = type;
|
|
|
|
}
|
|
|
|
|
2022-03-16 00:36:47 +00:00
|
|
|
public override string ToString()
|
|
|
|
{
|
2022-11-04 00:32:39 +00:00
|
|
|
return $"{this.Power.Name[0]} {this.Type.ToShort()} {(this.Province, this.Season).ToShort()}";
|
2022-03-16 00:36:47 +00:00
|
|
|
}
|
|
|
|
|
2022-02-18 20:13:23 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Create a new unit. No validation is performed; the adjudicator should only call this
|
|
|
|
/// method after accepting a build order.
|
|
|
|
/// </summary>
|
|
|
|
public static Unit Build(Location location, Season season, Power power, UnitType type)
|
2024-08-13 15:17:34 +00:00
|
|
|
=> new(past: null, location, season, power, type);
|
2022-02-18 20:13:23 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Advance this unit's timeline to a new location and season.
|
|
|
|
/// </summary>
|
|
|
|
public Unit Next(Location location, Season season)
|
2024-08-13 15:17:34 +00:00
|
|
|
=> new(past: this, location, season, this.Power, this.Type);
|
2022-02-18 20:13:23 +00:00
|
|
|
}
|