Add model for retreating unit information

This commit is contained in:
Jaculabilis 2022-03-24 07:25:51 -07:00
parent a162e6c7ef
commit d6d9102f05
2 changed files with 63 additions and 2 deletions

View File

@ -0,0 +1,32 @@
using System.Collections.ObjectModel;
namespace MultiversalDiplomacy.Model;
/// <summary>
/// Represents a unit that was dislodged and must retreat to another province.
/// </summary>
public class RetreatingUnit
{
/// <summary>
/// The unit that was dislodged.
/// </summary>
public Unit Unit { get; }
/// <summary>
/// Locations to which the dislodged unit may retreat. A dislodged unit may not retreat into
/// a province contested or held by another unit, nor into the province from which originated
/// the dislodging unit.
/// </summary>
public ReadOnlyCollection<(Season season, Location location)> ValidRetreats { get; }
public RetreatingUnit(Unit unit, List<(Season season, Location location)> validRetreats)
{
this.Unit = unit;
this.ValidRetreats = new(validRetreats);
}
public override string ToString()
{
return $"{this.Unit} (retreating)";
}
}

View File

@ -27,6 +27,11 @@ public class World
/// </summary> /// </summary>
public ReadOnlyCollection<Unit> Units { get; } public ReadOnlyCollection<Unit> Units { get; }
/// <summary>
/// All retreating units in the multiverse.
/// </summary>
public ReadOnlyCollection<RetreatingUnit> RetreatingUnits { get; }
/// <summary> /// <summary>
/// Immutable game options. /// Immutable game options.
/// </summary> /// </summary>
@ -37,12 +42,14 @@ public class World
ReadOnlyCollection<Power> powers, ReadOnlyCollection<Power> powers,
ReadOnlyCollection<Season> seasons, ReadOnlyCollection<Season> seasons,
ReadOnlyCollection<Unit> units, ReadOnlyCollection<Unit> units,
ReadOnlyCollection<RetreatingUnit> retreatingUnits,
Options options) Options options)
{ {
this.Provinces = provinces; this.Provinces = provinces;
this.Powers = powers; this.Powers = powers;
this.Seasons = seasons; this.Seasons = seasons;
this.Units = units; this.Units = units;
this.RetreatingUnits = retreatingUnits;
this.Options = options; this.Options = options;
} }
@ -55,6 +62,7 @@ public class World
new(powers.ToList()), new(powers.ToList()),
new(new List<Season>()), new(new List<Season>()),
new(new List<Unit>()), new(new List<Unit>()),
new(new List<RetreatingUnit>()),
new Options()); new Options());
/// <summary> /// <summary>
@ -67,7 +75,13 @@ public class World
/// Create a new world with new seasons. /// Create a new world with new seasons.
/// </summary> /// </summary>
public World WithSeasons(IEnumerable<Season> seasons) public World WithSeasons(IEnumerable<Season> seasons)
=> new World(this.Provinces, this.Powers, new(seasons.ToList()), this.Units, this.Options); => new World(
this.Provinces,
this.Powers,
new(seasons.ToList()),
this.Units,
this.RetreatingUnits,
this.Options);
/// <summary> /// <summary>
/// Create a new world with an initial season. /// Create a new world with an initial season.
@ -79,7 +93,13 @@ public class World
/// Create a new world with new units. /// Create a new world with new units.
/// </summary> /// </summary>
public World WithUnits(IEnumerable<Unit> units) public World WithUnits(IEnumerable<Unit> units)
=> new World(this.Provinces, this.Powers, this.Seasons, new(units.ToList()), this.Options); => new World(
this.Provinces,
this.Powers,
this.Seasons,
new(units.ToList()),
this.RetreatingUnits,
this.Options);
/// <summary> /// <summary>
/// Create a new world with new units created from unit specs. Units specs are in the format /// Create a new world with new units created from unit specs. Units specs are in the format
@ -140,6 +160,15 @@ public class World
); );
} }
public World WithRetreats(IEnumerable<RetreatingUnit> retreatingUnits)
=> new World(
this.Provinces,
this.Powers,
this.Seasons,
this.Units,
new(retreatingUnits.ToList()),
this.Options);
/// <summary> /// <summary>
/// A standard Diplomacy game setup. /// A standard Diplomacy game setup.
/// </summary> /// </summary>