Enable hold strength across parallel worlds

This commit is contained in:
Jaculabilis 2022-03-28 17:41:38 -07:00
parent ff64b459ca
commit aa9c9c548b
6 changed files with 34 additions and 16 deletions

View File

@ -6,13 +6,20 @@ namespace MultiversalDiplomacy.Adjudicate.Decision;
public class HoldStrength : NumericAdjudicationDecision public class HoldStrength : NumericAdjudicationDecision
{ {
public Province Province { get; } public Province Province { get; }
public Season Season { get; }
public UnitOrder? Order { get; } public UnitOrder? Order { get; }
public List<SupportHoldOrder> Supports { get; } public List<SupportHoldOrder> Supports { get; }
public HoldStrength(Province province, UnitOrder? order = null) public HoldStrength(Province province, Season season, UnitOrder? order = null)
{ {
this.Province = province; this.Province = province;
this.Season = season;
this.Order = order; this.Order = order;
this.Supports = new(); this.Supports = new();
} }
public HoldStrength((Province province, Season season) point, UnitOrder? order = null)
: this(point.province, point.season, order)
{
}
} }

View File

@ -8,7 +8,7 @@ public class MovementDecisions
public Dictionary<Unit, IsDislodged> IsDislodged { get; } public Dictionary<Unit, IsDislodged> IsDislodged { get; }
public Dictionary<MoveOrder, HasPath> HasPath { get; } public Dictionary<MoveOrder, HasPath> HasPath { get; }
public Dictionary<SupportOrder, GivesSupport> GivesSupport { get; } public Dictionary<SupportOrder, GivesSupport> GivesSupport { get; }
public Dictionary<Province, HoldStrength> HoldStrength { get; } public Dictionary<(Province, Season), HoldStrength> HoldStrength { get; }
public Dictionary<MoveOrder, AttackStrength> AttackStrength { get; } public Dictionary<MoveOrder, AttackStrength> AttackStrength { get; }
public Dictionary<MoveOrder, DefendStrength> DefendStrength { get; } public Dictionary<MoveOrder, DefendStrength> DefendStrength { get; }
public Dictionary<MoveOrder, PreventStrength> PreventStrength { get; } public Dictionary<MoveOrder, PreventStrength> PreventStrength { get; }
@ -46,8 +46,7 @@ public class MovementDecisions
// Ensure a hold strength decision exists. Overwrite any previous once, since it may // Ensure a hold strength decision exists. Overwrite any previous once, since it may
// have been created without an order by a previous move or support. // have been created without an order by a previous move or support.
Province province = order.Unit.Location.Province; this.HoldStrength[order.Unit.Point] = new(order.Unit.Point, order);
this.HoldStrength[province] = new(province, order);
if (order is MoveOrder move) if (order is MoveOrder move)
{ {
@ -78,10 +77,9 @@ public class MovementDecisions
this.DoesMove[move] = new(move, opposingMove, competing); this.DoesMove[move] = new(move, opposingMove, competing);
// Ensure a hold strength decision exists for the destination. // Ensure a hold strength decision exists for the destination.
Province dest = move.Location.Province; if (!this.HoldStrength.ContainsKey(move.Point))
if (!this.HoldStrength.ContainsKey(dest))
{ {
this.HoldStrength[dest] = new(dest); this.HoldStrength[move.Point] = new(move.Point);
} }
} }
else if (order is SupportOrder support) else if (order is SupportOrder support)
@ -90,23 +88,21 @@ public class MovementDecisions
this.GivesSupport[support] = new(support, incoming); this.GivesSupport[support] = new(support, incoming);
// Ensure a hold strength decision exists for the target's province. // Ensure a hold strength decision exists for the target's province.
Province target = support.Target.Location.Province; if (!this.HoldStrength.ContainsKey(support.Target.Point))
if (!this.HoldStrength.ContainsKey(target))
{ {
this.HoldStrength[target] = new(target); this.HoldStrength[support.Target.Point] = new(support.Target.Point);
} }
if (support is SupportHoldOrder supportHold) if (support is SupportHoldOrder supportHold)
{ {
this.HoldStrength[target].Supports.Add(supportHold); this.HoldStrength[support.Target.Point].Supports.Add(supportHold);
} }
else if (support is SupportMoveOrder supportMove) else if (support is SupportMoveOrder supportMove)
{ {
// Ensure a hold strength decision exists for the target's destination. // Ensure a hold strength decision exists for the target's destination.
Province dest = supportMove.Location.Province; if (!this.HoldStrength.ContainsKey(supportMove.Point))
if (!this.HoldStrength.ContainsKey(dest))
{ {
this.HoldStrength[dest] = new(dest); this.HoldStrength[supportMove.Point] = new(supportMove.Point);
} }
} }
} }

View File

@ -584,7 +584,7 @@ public class MovementPhaseAdjudicator : IPhaseAdjudicator
// If there is a head to head battle, a unit at the destination that isn't moving away, or // If there is a head to head battle, a unit at the destination that isn't moving away, or
// a unit at the destination that will fail to move away, then the attacking unit will have // a unit at the destination that will fail to move away, then the attacking unit will have
// to dislodge it. // to dislodge it.
UnitOrder? destOrder = decisions.HoldStrength[decision.Order.Location.Province].Order; UnitOrder? destOrder = decisions.HoldStrength[decision.Order.Point].Order;
DoesMove? destMoveAway = destOrder is MoveOrder moveAway DoesMove? destMoveAway = destOrder is MoveOrder moveAway
? decisions.DoesMove[moveAway] ? decisions.DoesMove[moveAway]
: null; : null;
@ -757,7 +757,7 @@ public class MovementPhaseAdjudicator : IPhaseAdjudicator
// strength. // strength.
NumericAdjudicationDecision defense = decision.OpposingMove != null NumericAdjudicationDecision defense = decision.OpposingMove != null
? decisions.DefendStrength[decision.OpposingMove] ? decisions.DefendStrength[decision.OpposingMove]
: decisions.HoldStrength[decision.Order.Location.Province]; : decisions.HoldStrength[decision.Order.Point];
progress |= ResolveDecision(defense, world, decisions); progress |= ResolveDecision(defense, world, decisions);
// If the attack doesn't beat the defense, resolve the move to false. // If the attack doesn't beat the defense, resolve the move to false.

View File

@ -30,6 +30,11 @@ public class Unit
/// </summary> /// </summary>
public UnitType Type { get; } public UnitType Type { get; }
/// <summary>
/// The unit's spatiotemporal location as a province-season tuple.
/// </summary>
public (Province province, Season season) Point => (this.Location.Province, this.Season);
private Unit(Unit? past, Location location, Season season, Power power, UnitType type) private Unit(Unit? past, Location location, Season season, Power power, UnitType type)
{ {
this.Past = past; this.Past = past;

View File

@ -17,6 +17,11 @@ public class MoveOrder : UnitOrder
/// </summary> /// </summary>
public Location Location { get; } public Location Location { get; }
/// <summary>
/// The destination's spatiotemporal location as a province-season tuple.
/// </summary>
public (Province province, Season season) Point => (this.Location.Province, this.Season);
public MoveOrder(Power power, Unit unit, Season season, Location location) public MoveOrder(Power power, Unit unit, Season season, Location location)
: base (power, unit) : base (power, unit)
{ {

View File

@ -17,6 +17,11 @@ public class SupportMoveOrder : SupportOrder
/// </summary> /// </summary>
public Location Location { get; } public Location Location { get; }
/// <summary>
/// The target's destination's spatiotemporal location as a province-season tuple.
/// </summary>
public (Province province, Season season) Point => (this.Location.Province, this.Season);
public SupportMoveOrder(Power power, Unit unit, Unit target, Season season, Location location) public SupportMoveOrder(Power power, Unit unit, Unit target, Season season, Location location)
: base(power, unit, target) : base(power, unit, target)
{ {