HoldStrength uses season string

This commit is contained in:
Tim Van Baak 2024-08-14 22:40:40 -07:00
parent 64f48064fc
commit 601ce2d297
2 changed files with 18 additions and 11 deletions

View File

@ -8,7 +8,7 @@ public class MovementDecisions
public Dictionary<Unit, IsDislodged> IsDislodged { get; }
public Dictionary<MoveOrder, HasPath> HasPath { get; }
public Dictionary<SupportOrder, GivesSupport> GivesSupport { get; }
public Dictionary<(Province, Season), HoldStrength> HoldStrength { get; }
public Dictionary<(Province, string), HoldStrength> HoldStrength { get; }
public Dictionary<MoveOrder, AttackStrength> AttackStrength { get; }
public Dictionary<MoveOrder, DefendStrength> DefendStrength { get; }
public Dictionary<MoveOrder, PreventStrength> PreventStrength { get; }
@ -91,15 +91,18 @@ public class MovementDecisions
.Distinct()
.ToList();
(Province province, Season season) UnitPoint(Unit unit)
=> (world.Map.GetLocation(unit.Location).Province, unit.Season);
(Province province, Season season) MovePoint(MoveOrder move)
=> (move.Province, world.Seasons[move.Season]);
(Province province, string season) UnitPoint(Unit unit)
=> (world.Map.GetLocation(unit.Location).Province, unit.Season.Designation);
(Province province, string season) MovePoint(MoveOrder move)
=> (move.Province, move.Season);
// Create a hold strength decision with an associated order for every province with a unit.
foreach (UnitOrder order in relevantOrders)
{
HoldStrength[UnitPoint(order.Unit)] = new(UnitPoint(order.Unit), order);
HoldStrength[UnitPoint(order.Unit)] = new(
world.Map.GetLocation(order.Unit.Location).Province,
order.Unit.Season,
order);
}
bool IsIncoming(UnitOrder me, MoveOrder other)
@ -150,7 +153,7 @@ public class MovementDecisions
DoesMove[move] = new(move, opposingMove, competing);
// Ensure a hold strength decision exists for the destination.
HoldStrength.Ensure(MovePoint(move), () => new(MovePoint(move)));
HoldStrength.Ensure(MovePoint(move), () => new(move.Province, world.Seasons[move.Season]));
}
else if (order is SupportOrder support)
{
@ -158,7 +161,9 @@ public class MovementDecisions
GivesSupport[support] = new(support, incoming);
// Ensure a hold strength decision exists for the target's province.
HoldStrength.Ensure(UnitPoint(support.Target), () => new(UnitPoint(support.Target)));
HoldStrength.Ensure(UnitPoint(support.Target), () => new(
world.Map.GetLocation(support.Target.Location).Province,
support.Target.Season));
if (support is SupportHoldOrder supportHold)
{
@ -167,7 +172,9 @@ public class MovementDecisions
else if (support is SupportMoveOrder supportMove)
{
// Ensure a hold strength decision exists for the target's destination.
HoldStrength.Ensure(supportMove.Point, () => new(supportMove.Point));
HoldStrength.Ensure(
(supportMove.Province, supportMove.Season.Designation),
() => new(supportMove.Province, supportMove.Season));
}
}
}

View File

@ -774,7 +774,7 @@ public class MovementPhaseAdjudicator : IPhaseAdjudicator
// 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
// to dislodge it.
UnitOrder? destOrder = decisions.HoldStrength[(decision.Order.Province, world.Seasons[decision.Order.Season])].Order;
UnitOrder? destOrder = decisions.HoldStrength[(decision.Order.Province, decision.Order.Season)].Order;
DoesMove? destMoveAway = destOrder is MoveOrder moveAway
? decisions.DoesMove[moveAway]
: null;
@ -953,7 +953,7 @@ public class MovementPhaseAdjudicator : IPhaseAdjudicator
// strength.
NumericAdjudicationDecision defense = decision.OpposingMove != null
? decisions.DefendStrength[decision.OpposingMove]
: decisions.HoldStrength[(decision.Order.Province, world.Seasons[decision.Order.Season])];
: decisions.HoldStrength[(decision.Order.Province, decision.Order.Season)];
progress |= ResolveDecision(defense, world, decisions, depth + 1);
// If the attack doesn't beat the defense, resolve the move to false.