Add model for retreating unit information
This commit is contained in:
parent
a162e6c7ef
commit
d6d9102f05
32
MultiversalDiplomacy/Model/RetreatingUnit.cs
Normal file
32
MultiversalDiplomacy/Model/RetreatingUnit.cs
Normal 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)";
|
||||
}
|
||||
}
|
@ -27,6 +27,11 @@ public class World
|
||||
/// </summary>
|
||||
public ReadOnlyCollection<Unit> Units { get; }
|
||||
|
||||
/// <summary>
|
||||
/// All retreating units in the multiverse.
|
||||
/// </summary>
|
||||
public ReadOnlyCollection<RetreatingUnit> RetreatingUnits { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Immutable game options.
|
||||
/// </summary>
|
||||
@ -37,12 +42,14 @@ public class World
|
||||
ReadOnlyCollection<Power> powers,
|
||||
ReadOnlyCollection<Season> seasons,
|
||||
ReadOnlyCollection<Unit> units,
|
||||
ReadOnlyCollection<RetreatingUnit> retreatingUnits,
|
||||
Options options)
|
||||
{
|
||||
this.Provinces = provinces;
|
||||
this.Powers = powers;
|
||||
this.Seasons = seasons;
|
||||
this.Units = units;
|
||||
this.RetreatingUnits = retreatingUnits;
|
||||
this.Options = options;
|
||||
}
|
||||
|
||||
@ -55,6 +62,7 @@ public class World
|
||||
new(powers.ToList()),
|
||||
new(new List<Season>()),
|
||||
new(new List<Unit>()),
|
||||
new(new List<RetreatingUnit>()),
|
||||
new Options());
|
||||
|
||||
/// <summary>
|
||||
@ -67,7 +75,13 @@ public class World
|
||||
/// Create a new world with new seasons.
|
||||
/// </summary>
|
||||
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>
|
||||
/// Create a new world with an initial season.
|
||||
@ -79,7 +93,13 @@ public class World
|
||||
/// Create a new world with new units.
|
||||
/// </summary>
|
||||
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>
|
||||
/// 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>
|
||||
/// A standard Diplomacy game setup.
|
||||
/// </summary>
|
||||
|
Loading…
Reference in New Issue
Block a user