Store order history by timeline designation instead of reference
This commit is contained in:
parent
ef4e130dbb
commit
2f4c8b2a38
|
@ -61,25 +61,25 @@ public class MovementDecisions
|
|||
case MoveOrder move:
|
||||
AdvanceTimeline.Ensure(
|
||||
move.Season,
|
||||
() => new(move.Season, world.OrderHistory[move.Season].Orders));
|
||||
() => new(move.Season, world.OrderHistory[move.Season.Designation].Orders));
|
||||
AdvanceTimeline[move.Season].Orders.Add(move);
|
||||
break;
|
||||
|
||||
case SupportHoldOrder supportHold:
|
||||
AdvanceTimeline.Ensure(
|
||||
supportHold.Target.Season,
|
||||
() => new(supportHold.Target.Season, world.OrderHistory[supportHold.Target.Season].Orders));
|
||||
() => new(supportHold.Target.Season, world.OrderHistory[supportHold.Target.Season.Designation].Orders));
|
||||
AdvanceTimeline[supportHold.Target.Season].Orders.Add(supportHold);
|
||||
break;
|
||||
|
||||
case SupportMoveOrder supportMove:
|
||||
AdvanceTimeline.Ensure(
|
||||
supportMove.Target.Season,
|
||||
() => new(supportMove.Target.Season, world.OrderHistory[supportMove.Target.Season].Orders));
|
||||
() => new(supportMove.Target.Season, world.OrderHistory[supportMove.Target.Season.Designation].Orders));
|
||||
AdvanceTimeline[supportMove.Target.Season].Orders.Add(supportMove);
|
||||
AdvanceTimeline.Ensure(
|
||||
supportMove.Season,
|
||||
() => new(supportMove.Season, world.OrderHistory[supportMove.Season].Orders));
|
||||
() => new(supportMove.Season, world.OrderHistory[supportMove.Season.Designation].Orders));
|
||||
AdvanceTimeline[supportMove.Season].Orders.Add(supportMove);
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -386,11 +386,11 @@ public class MovementPhaseAdjudicator : IPhaseAdjudicator
|
|||
}
|
||||
|
||||
// Record the adjudication results to the season's order history
|
||||
Dictionary<Season, OrderHistory> newHistory = new();
|
||||
Dictionary<string, OrderHistory> newHistory = [];
|
||||
foreach (UnitOrder unitOrder in decisions.OfType<IsDislodged>().Select(d => d.Order))
|
||||
{
|
||||
newHistory.Ensure(unitOrder.Unit.Season, () => new());
|
||||
OrderHistory history = newHistory[unitOrder.Unit.Season];
|
||||
newHistory.Ensure(unitOrder.Unit.Season.Designation, () => new());
|
||||
OrderHistory history = newHistory[unitOrder.Unit.Season.Designation];
|
||||
// TODO does this add every order to every season??
|
||||
history.Orders.Add(unitOrder);
|
||||
history.IsDislodgedOutcomes[unitOrder.Unit] = dislodges[unitOrder.Unit].Outcome == true;
|
||||
|
@ -401,7 +401,7 @@ public class MovementPhaseAdjudicator : IPhaseAdjudicator
|
|||
}
|
||||
|
||||
// Log the new order history
|
||||
foreach ((Season season, OrderHistory history) in newHistory)
|
||||
foreach ((string season, OrderHistory history) in newHistory)
|
||||
{
|
||||
string verb = world.OrderHistory.ContainsKey(season) ? "Updating" : "Adding";
|
||||
logger.Log(1, "{0} history for {1}", verb, season);
|
||||
|
@ -411,7 +411,7 @@ public class MovementPhaseAdjudicator : IPhaseAdjudicator
|
|||
}
|
||||
}
|
||||
|
||||
IEnumerable<KeyValuePair<Season, OrderHistory>> updatedHistory = world.OrderHistory
|
||||
IEnumerable<KeyValuePair<string, OrderHistory>> updatedHistory = world.OrderHistory
|
||||
.Where(kvp => !newHistory.ContainsKey(kvp.Key))
|
||||
.Concat(newHistory);
|
||||
|
||||
|
@ -496,7 +496,7 @@ public class MovementPhaseAdjudicator : IPhaseAdjudicator
|
|||
IEnumerable<MoveOrder> newIncomingMoves = decision.Orders
|
||||
.OfType<MoveOrder>()
|
||||
.Where(order => order.Season == decision.Season
|
||||
&& !world.OrderHistory[order.Season].DoesMoveOutcomes.ContainsKey(order));
|
||||
&& !world.OrderHistory[order.Season.Designation].DoesMoveOutcomes.ContainsKey(order));
|
||||
foreach (MoveOrder moveOrder in newIncomingMoves)
|
||||
{
|
||||
DoesMove doesMove = decisions.DoesMove[moveOrder];
|
||||
|
@ -513,7 +513,7 @@ public class MovementPhaseAdjudicator : IPhaseAdjudicator
|
|||
// 1. The outcome of a dislodge decision is changed,
|
||||
// 2. The outcome of an intra-timeline move decision is changed, or
|
||||
// 3. The outcome of an inter-timeline move decision with that season as the destination is changed.
|
||||
OrderHistory history = world.OrderHistory[decision.Season];
|
||||
OrderHistory history = world.OrderHistory[decision.Season.Designation];
|
||||
bool anyUnresolved = false;
|
||||
foreach (UnitOrder order in decision.Orders)
|
||||
{
|
||||
|
|
|
@ -13,7 +13,7 @@ public class OrderHistory
|
|||
public Dictionary<MoveOrder, bool> DoesMoveOutcomes;
|
||||
|
||||
public OrderHistory()
|
||||
: this(new(), new(), new())
|
||||
: this([], [], [])
|
||||
{}
|
||||
|
||||
public OrderHistory(
|
||||
|
|
|
@ -12,7 +12,7 @@ public class World
|
|||
/// <summary>
|
||||
/// The map variant of the game.
|
||||
/// </summary>
|
||||
public readonly Map Map;
|
||||
public Map Map { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The game map.
|
||||
|
@ -52,7 +52,7 @@ public class World
|
|||
/// <summary>
|
||||
/// Orders given to units in each season.
|
||||
/// </summary>
|
||||
public ReadOnlyDictionary<Season, OrderHistory> OrderHistory { get; }
|
||||
public ReadOnlyDictionary<string, OrderHistory> OrderHistory { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Immutable game options.
|
||||
|
@ -67,7 +67,7 @@ public class World
|
|||
ReadOnlyCollection<Season> seasons,
|
||||
ReadOnlyCollection<Unit> units,
|
||||
ReadOnlyCollection<RetreatingUnit> retreatingUnits,
|
||||
ReadOnlyDictionary<Season, OrderHistory> orderHistory,
|
||||
ReadOnlyDictionary<string, OrderHistory> orderHistory,
|
||||
Options options)
|
||||
{
|
||||
this.Map = map;
|
||||
|
@ -88,7 +88,7 @@ public class World
|
|||
ReadOnlyCollection<Season>? seasons = null,
|
||||
ReadOnlyCollection<Unit>? units = null,
|
||||
ReadOnlyCollection<RetreatingUnit>? retreatingUnits = null,
|
||||
ReadOnlyDictionary<Season, OrderHistory>? orderHistory = null,
|
||||
ReadOnlyDictionary<string, OrderHistory>? orderHistory = null,
|
||||
Options? options = null)
|
||||
: this(
|
||||
previous.Map,
|
||||
|
@ -110,7 +110,7 @@ public class World
|
|||
new([Season.MakeRoot()]),
|
||||
new([]),
|
||||
new([]),
|
||||
new(new Dictionary<Season, OrderHistory>()),
|
||||
new(new Dictionary<string, OrderHistory>()),
|
||||
new Options());
|
||||
}
|
||||
|
||||
|
@ -124,7 +124,7 @@ public class World
|
|||
IEnumerable<Season>? seasons = null,
|
||||
IEnumerable<Unit>? units = null,
|
||||
IEnumerable<RetreatingUnit>? retreats = null,
|
||||
IEnumerable<KeyValuePair<Season, OrderHistory>>? orders = null)
|
||||
IEnumerable<KeyValuePair<string, OrderHistory>>? orders = null)
|
||||
=> new(
|
||||
previous: this,
|
||||
seasons: seasons == null
|
||||
|
|
Loading…
Reference in New Issue