Reduce Order.Power to string

This commit is contained in:
Tim Van Baak 2024-08-15 07:30:43 -07:00
parent 161e0a1ddb
commit 2e6e6c55b8
16 changed files with 27 additions and 27 deletions

View File

@ -77,13 +77,13 @@ internal static class AdjudicatorHelpers
{ {
InvalidateIfNotMatching( InvalidateIfNotMatching(
order => order switch { order => order switch {
ConvoyOrder convoy => convoy.Power == convoy.Unit.Power, ConvoyOrder convoy => convoy.Power == convoy.Unit.Power.Name,
DisbandOrder disband => disband.Power == disband.Unit.Power, DisbandOrder disband => disband.Power == disband.Unit.Power.Name,
HoldOrder hold => hold.Power == hold.Unit.Power, HoldOrder hold => hold.Power == hold.Unit.Power.Name,
MoveOrder move => move.Power == move.Unit.Power, MoveOrder move => move.Power == move.Unit.Power.Name,
RetreatOrder retreat => retreat.Power == retreat.Unit.Power, RetreatOrder retreat => retreat.Power == retreat.Unit.Power.Name,
SupportHoldOrder support => support.Power == support.Unit.Power, SupportHoldOrder support => support.Power == support.Unit.Power.Name,
SupportMoveOrder support => support.Power == support.Unit.Power, SupportMoveOrder support => support.Power == support.Unit.Power.Name,
// Any order not given to a unit, by definition, cannot be given to a unit of the // Any order not given to a unit, by definition, cannot be given to a unit of the
// wrong power // wrong power
_ => true, _ => true,

View File

@ -262,7 +262,7 @@ public class MovementPhaseAdjudicator : IPhaseAdjudicator
.Where(unit => !orderedUnits.Contains(unit)) .Where(unit => !orderedUnits.Contains(unit))
.ToList(); .ToList();
List<HoldOrder> implicitHolds = unorderedUnits List<HoldOrder> implicitHolds = unorderedUnits
.Select(unit => new HoldOrder(unit.Power, unit)) .Select(unit => new HoldOrder(unit.Power.Name, unit))
.ToList(); .ToList();
validationResults = validationResults validationResults = validationResults
.Concat(implicitHolds.Select(o => o.Validate(ValidationReason.Valid))) .Concat(implicitHolds.Select(o => o.Validate(ValidationReason.Valid)))

View File

@ -17,7 +17,7 @@ public class BuildOrder : Order
/// </summary> /// </summary>
public UnitType Type { get; } public UnitType Type { get; }
public BuildOrder(Power power, Location location, UnitType type) public BuildOrder(string power, Location location, UnitType type)
: base (power) : base (power)
{ {
this.Location = location; this.Location = location;

View File

@ -27,7 +27,7 @@ public class ConvoyOrder : UnitOrder
/// </summary> /// </summary>
public Province Province => this.Location.Province; public Province Province => this.Location.Province;
public ConvoyOrder(Power power, Unit unit, Unit target, Season season, Location location) public ConvoyOrder(string power, Unit unit, Unit target, Season season, Location location)
: base (power, unit) : base (power, unit)
{ {
this.Target = target; this.Target = target;

View File

@ -7,6 +7,6 @@ namespace MultiversalDiplomacy.Orders;
/// </summary> /// </summary>
public class DisbandOrder : UnitOrder public class DisbandOrder : UnitOrder
{ {
public DisbandOrder(Power power, Unit unit) public DisbandOrder(string power, Unit unit)
: base (power, unit) {} : base (power, unit) {}
} }

View File

@ -7,7 +7,7 @@ namespace MultiversalDiplomacy.Orders;
/// </summary> /// </summary>
public class HoldOrder : UnitOrder public class HoldOrder : UnitOrder
{ {
public HoldOrder(Power power, Unit unit) public HoldOrder(string power, Unit unit)
: base (power, unit) {} : base (power, unit) {}
public override string ToString() public override string ToString()

View File

@ -23,7 +23,7 @@ public class MoveOrder : UnitOrder
/// </summary> /// </summary>
public Province Province => this.Location.Province; public Province Province => this.Location.Province;
public MoveOrder(Power power, Unit unit, string season, Location location) public MoveOrder(string power, Unit unit, string season, Location location)
: base (power, unit) : base (power, unit)
{ {
this.Season = season; this.Season = season;

View File

@ -22,9 +22,9 @@ public abstract class Order
/// <summary> /// <summary>
/// The power that submitted this order. /// The power that submitted this order.
/// </summary> /// </summary>
public Power Power { get; } public string Power { get; }
public Order(Power power) public Order(string power)
{ {
this.Power = power; this.Power = power;
} }

View File

@ -12,7 +12,7 @@ public class RetreatOrder : UnitOrder
/// </summary> /// </summary>
public Location Location { get; } public Location Location { get; }
public RetreatOrder(Power power, Unit unit, Location location) public RetreatOrder(string power, Unit unit, Location location)
: base (power, unit) : base (power, unit)
{ {
this.Location = location; this.Location = location;

View File

@ -7,7 +7,7 @@ namespace MultiversalDiplomacy.Orders;
/// </summary> /// </summary>
public class SupportHoldOrder : SupportOrder public class SupportHoldOrder : SupportOrder
{ {
public SupportHoldOrder(Power power, Unit unit, Unit target) public SupportHoldOrder(string power, Unit unit, Unit target)
: base (power, unit, target) : base (power, unit, target)
{ {
} }

View File

@ -27,7 +27,7 @@ public class SupportMoveOrder : SupportOrder
/// </summary> /// </summary>
public (Province province, Season season) Point => (this.Province, this.Season); public (Province province, Season season) Point => (this.Province, this.Season);
public SupportMoveOrder(Power power, Unit unit, Unit target, Season season, Location location) public SupportMoveOrder(string power, Unit unit, Unit target, Season season, Location location)
: base(power, unit, target) : base(power, unit, target)
{ {
this.Season = season; this.Season = season;

View File

@ -12,7 +12,7 @@ public abstract class SupportOrder : UnitOrder
/// </summary> /// </summary>
public Unit Target { get; } public Unit Target { get; }
public SupportOrder(Power power, Unit unit, Unit target) public SupportOrder(string power, Unit unit, Unit target)
: base (power, unit) : base (power, unit)
{ {
this.Target = target; this.Target = target;

View File

@ -17,7 +17,7 @@ public class SustainOrder : Order
/// </summary> /// </summary>
public int Timeline { get; } public int Timeline { get; }
public SustainOrder(Power power, Location timeCenter, int timeline) public SustainOrder(string power, Location timeCenter, int timeline)
: base (power) : base (power)
{ {
this.TimeCenter = timeCenter; this.TimeCenter = timeCenter;

View File

@ -22,7 +22,7 @@ public abstract class UnitOrder : Order
/// </summary> /// </summary>
public Unit Unit { get; } public Unit Unit { get; }
public UnitOrder(Power power, Unit unit) : base(power) public UnitOrder(string power, Unit unit) : base(power)
{ {
this.Unit = unit; this.Unit = unit;
} }

View File

@ -402,7 +402,7 @@ public class TestCaseBuilder
public IOrderDefinedContext<HoldOrder> Holds() public IOrderDefinedContext<HoldOrder> Holds()
{ {
HoldOrder order = new HoldOrder(this.PowerContext.Power, this.Unit); HoldOrder order = new HoldOrder(this.PowerContext.Power.Name, this.Unit);
this.Builder.OrderList.Add(order); this.Builder.OrderList.Add(order);
return new OrderDefinedContext<HoldOrder>(this, order); return new OrderDefinedContext<HoldOrder>(this, order);
} }
@ -417,7 +417,7 @@ public class TestCaseBuilder
: this.Builder.World.Map.GetWater(provinceName, coast); : this.Builder.World.Map.GetWater(provinceName, coast);
Season destSeason = season ?? this.SeasonContext.Season; Season destSeason = season ?? this.SeasonContext.Season;
MoveOrder moveOrder = new MoveOrder( MoveOrder moveOrder = new MoveOrder(
this.PowerContext.Power, this.PowerContext.Power.Name,
this.Unit, this.Unit,
destSeason.Key, destSeason.Key,
destination); destination);
@ -494,7 +494,7 @@ public class TestCaseBuilder
{ {
Location location = this.Builder.World.Map.GetLand(provinceName); Location location = this.Builder.World.Map.GetLand(provinceName);
ConvoyOrder order = new ConvoyOrder( ConvoyOrder order = new ConvoyOrder(
this.PowerContext.Power, this.PowerContext.Power.Name,
this.UnitContext.Unit, this.UnitContext.Unit,
this.Target, this.Target,
this.SeasonContext.Season, this.SeasonContext.Season,
@ -569,7 +569,7 @@ public class TestCaseBuilder
public IOrderDefinedContext<SupportHoldOrder> Hold() public IOrderDefinedContext<SupportHoldOrder> Hold()
{ {
SupportHoldOrder order = new SupportHoldOrder( SupportHoldOrder order = new SupportHoldOrder(
this.PowerContext.Power, this.PowerContext.Power.Name,
this.UnitContext.Unit, this.UnitContext.Unit,
this.Target); this.Target);
this.Builder.OrderList.Add(order); this.Builder.OrderList.Add(order);
@ -586,7 +586,7 @@ public class TestCaseBuilder
: this.Builder.World.Map.GetWater(provinceName, coast); : this.Builder.World.Map.GetWater(provinceName, coast);
Season targetDestSeason = season ?? this.Target.Season; Season targetDestSeason = season ?? this.Target.Season;
SupportMoveOrder order = new SupportMoveOrder( SupportMoveOrder order = new SupportMoveOrder(
this.PowerContext.Power, this.PowerContext.Power.Name,
this.UnitContext.Unit, this.UnitContext.Unit,
this.Target, this.Target,
targetDestSeason, targetDestSeason,

View File

@ -124,7 +124,7 @@ class TestCaseBuilderTest
Assert.That(orderMun, Is.Not.Null, "Expected order reference"); Assert.That(orderMun, Is.Not.Null, "Expected order reference");
Assert.That( Assert.That(
orderMun.Order.Power, orderMun.Order.Power,
Is.EqualTo(setup.World.Map.GetPower("Germany")), Is.EqualTo("Germany"),
"Wrong power"); "Wrong power");
Assert.That( Assert.That(
orderMun.Order.Unit.Location, orderMun.Order.Unit.Location,