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