Remove Location reference from Unit
This commit is contained in:
parent
e1772ce60b
commit
885628900b
|
@ -92,7 +92,7 @@ public class MovementDecisions
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
(Province province, Season season) Point(Unit unit)
|
(Province province, Season season) Point(Unit unit)
|
||||||
=> (world.Map.GetLocation(unit.LocationId).Province, unit.Season);
|
=> (world.Map.GetLocation(unit.Location).Province, unit.Season);
|
||||||
|
|
||||||
// Create a hold strength decision with an associated order for every province with a unit.
|
// Create a hold strength decision with an associated order for every province with a unit.
|
||||||
foreach (UnitOrder order in relevantOrders)
|
foreach (UnitOrder order in relevantOrders)
|
||||||
|
|
|
@ -77,7 +77,7 @@ public class MovementPhaseAdjudicator : IPhaseAdjudicator
|
||||||
|
|
||||||
// Trivial check: a unit cannot move to where it already is.
|
// Trivial check: a unit cannot move to where it already is.
|
||||||
AdjudicatorHelpers.InvalidateIfNotMatching(
|
AdjudicatorHelpers.InvalidateIfNotMatching(
|
||||||
order => !(order.Location.Designation == order.Unit.LocationId && order.Season == order.Unit.Season),
|
order => !(order.Location.Designation == order.Unit.Location && order.Season == order.Unit.Season),
|
||||||
ValidationReason.DestinationMatchesOrigin,
|
ValidationReason.DestinationMatchesOrigin,
|
||||||
ref moveOrders,
|
ref moveOrders,
|
||||||
ref validationResults);
|
ref validationResults);
|
||||||
|
@ -138,7 +138,7 @@ public class MovementPhaseAdjudicator : IPhaseAdjudicator
|
||||||
// Trivial check: cannot convoy a unit to its own location
|
// Trivial check: cannot convoy a unit to its own location
|
||||||
AdjudicatorHelpers.InvalidateIfNotMatching(
|
AdjudicatorHelpers.InvalidateIfNotMatching(
|
||||||
order => !(
|
order => !(
|
||||||
order.Location.Designation == order.Target.LocationId
|
order.Location.Designation == order.Target.Location
|
||||||
&& order.Season == order.Target.Season),
|
&& order.Season == order.Target.Season),
|
||||||
ValidationReason.DestinationMatchesOrigin,
|
ValidationReason.DestinationMatchesOrigin,
|
||||||
ref convoyOrders,
|
ref convoyOrders,
|
||||||
|
@ -337,7 +337,7 @@ public class MovementPhaseAdjudicator : IPhaseAdjudicator
|
||||||
Season moveSeason = doesMove.Order.Season;
|
Season moveSeason = doesMove.Order.Season;
|
||||||
if (doesMove.Outcome == true && createdFutures.ContainsKey(moveSeason))
|
if (doesMove.Outcome == true && createdFutures.ContainsKey(moveSeason))
|
||||||
{
|
{
|
||||||
Unit next = doesMove.Order.Unit.Next(doesMove.Order.Location, createdFutures[moveSeason]);
|
Unit next = doesMove.Order.Unit.Next(doesMove.Order.Location.Designation, createdFutures[moveSeason]);
|
||||||
logger.Log(3, "Advancing unit to {0}", next);
|
logger.Log(3, "Advancing unit to {0}", next);
|
||||||
createdUnits.Add(next);
|
createdUnits.Add(next);
|
||||||
}
|
}
|
||||||
|
@ -366,7 +366,7 @@ public class MovementPhaseAdjudicator : IPhaseAdjudicator
|
||||||
if (isDislodged.Outcome == false)
|
if (isDislodged.Outcome == false)
|
||||||
{
|
{
|
||||||
// Non-dislodged units continue into the future.
|
// Non-dislodged units continue into the future.
|
||||||
Unit next = order.Unit.Next(world.Map.GetLocation(order.Unit), future);
|
Unit next = order.Unit.Next(world.Map.GetLocation(order.Unit).Designation, future);
|
||||||
logger.Log(3, "Advancing unit to {0}", next);
|
logger.Log(3, "Advancing unit to {0}", next);
|
||||||
createdUnits.Add(next);
|
createdUnits.Add(next);
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ public static class PathFinder
|
||||||
// belong to another power or were not given convoy orders; it will simply fail.
|
// belong to another power or were not given convoy orders; it will simply fail.
|
||||||
IDictionary<(string location, Season season), Unit> fleets = world.Units
|
IDictionary<(string location, Season season), Unit> fleets = world.Units
|
||||||
.Where(unit => unit.Type == UnitType.Fleet)
|
.Where(unit => unit.Type == UnitType.Fleet)
|
||||||
.ToDictionary(unit => (unit.LocationId, unit.Season));
|
.ToDictionary(unit => (unit.Location, unit.Season));
|
||||||
|
|
||||||
// Verify that the origin is a coastal province.
|
// Verify that the origin is a coastal province.
|
||||||
if (world.Map.GetLocation(movingUnit).Type != LocationType.Land) return false;
|
if (world.Map.GetLocation(movingUnit).Type != LocationType.Land) return false;
|
||||||
|
|
|
@ -67,7 +67,7 @@ public class Map
|
||||||
=> LocationLookup[designation];
|
=> LocationLookup[designation];
|
||||||
|
|
||||||
public Location GetLocation(Unit unit)
|
public Location GetLocation(Unit unit)
|
||||||
=> GetLocation(unit.LocationId);
|
=> GetLocation(unit.Location);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get the sole land location of a province.
|
/// Get the sole land location of a province.
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
using System.Text.Json.Serialization;
|
|
||||||
|
|
||||||
namespace MultiversalDiplomacy.Model;
|
namespace MultiversalDiplomacy.Model;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -15,9 +13,7 @@ public class Unit
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The location on the map where the unit is.
|
/// The location on the map where the unit is.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Location Location { get; }
|
public string Location { get; }
|
||||||
|
|
||||||
public string LocationId => Location.Designation;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The season in time when the unit is.
|
/// The season in time when the unit is.
|
||||||
|
@ -34,7 +30,7 @@ public class Unit
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public UnitType Type { get; }
|
public UnitType Type { get; }
|
||||||
|
|
||||||
private Unit(Unit? past, Location location, Season season, Power power, UnitType type)
|
private Unit(Unit? past, string location, Season season, Power power, UnitType type)
|
||||||
{
|
{
|
||||||
this.Past = past;
|
this.Past = past;
|
||||||
this.Location = location;
|
this.Location = location;
|
||||||
|
@ -44,18 +40,18 @@ public class Unit
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
=> $"{Power.Name[0]} {Type.ToShort()} {Season.Timeline}-{LocationId}@{Season.Turn}";
|
=> $"{Power.Name[0]} {Type.ToShort()} {Season.Timeline}-{Location}@{Season.Turn}";
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create a new unit. No validation is performed; the adjudicator should only call this
|
/// Create a new unit. No validation is performed; the adjudicator should only call this
|
||||||
/// method after accepting a build order.
|
/// method after accepting a build order.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static Unit Build(Location location, Season season, Power power, UnitType type)
|
public static Unit Build(string location, Season season, Power power, UnitType type)
|
||||||
=> new(past: null, location, season, power, type);
|
=> new(past: null, location, season, power, type);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Advance this unit's timeline to a new location and season.
|
/// Advance this unit's timeline to a new location and season.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Unit Next(Location location, Season season)
|
public Unit Next(string location, Season season)
|
||||||
=> new(past: this, location, season, this.Power, this.Type);
|
=> new(past: this, location, season, this.Power, this.Type);
|
||||||
}
|
}
|
||||||
|
|
|
@ -204,7 +204,7 @@ public class World
|
||||||
: splits.Length == 3
|
: splits.Length == 3
|
||||||
? Map.GetWater(splits[2])
|
? Map.GetWater(splits[2])
|
||||||
: Map.GetWater(splits[2], splits[3]);
|
: Map.GetWater(splits[2], splits[3]);
|
||||||
Unit unit = Unit.Build(location, this.RootSeason, power, type);
|
Unit unit = Unit.Build(location.Designation, this.RootSeason, power, type);
|
||||||
return unit;
|
return unit;
|
||||||
});
|
});
|
||||||
return this.Update(units: units);
|
return this.Update(units: units);
|
||||||
|
|
|
@ -179,7 +179,7 @@ public class MovementAdjudicatorTest
|
||||||
// Confirm the unit was created
|
// Confirm the unit was created
|
||||||
Assert.That(updated.Units.Count, Is.EqualTo(2));
|
Assert.That(updated.Units.Count, Is.EqualTo(2));
|
||||||
Unit second = updated.Units.Single(u => u.Past != null);
|
Unit second = updated.Units.Single(u => u.Past != null);
|
||||||
Assert.That(second.LocationId, Is.EqualTo(mun.Order.Unit.LocationId));
|
Assert.That(second.Location, Is.EqualTo(mun.Order.Unit.Location));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
|
|
@ -270,7 +270,7 @@ public class TestCaseBuilder
|
||||||
}
|
}
|
||||||
|
|
||||||
// Not found
|
// Not found
|
||||||
Unit newUnit = Unit.Build(location, season, power, type);
|
Unit newUnit = Unit.Build(location.Designation, season, power, type);
|
||||||
this.World = this.World.Update(units: this.World.Units.Append(newUnit));
|
this.World = this.World.Update(units: this.World.Units.Append(newUnit));
|
||||||
return newUnit;
|
return newUnit;
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,7 @@ class TestCaseBuilderTest
|
||||||
Assert.That(fleetSTP.Power.Name, Is.EqualTo("Russia"), "Unit created with wrong power");
|
Assert.That(fleetSTP.Power.Name, Is.EqualTo("Russia"), "Unit created with wrong power");
|
||||||
Assert.That(fleetSTP.Type, Is.EqualTo(UnitType.Fleet), "Unit created with wrong type");
|
Assert.That(fleetSTP.Type, Is.EqualTo(UnitType.Fleet), "Unit created with wrong type");
|
||||||
Assert.That(
|
Assert.That(
|
||||||
fleetSTP.LocationId,
|
fleetSTP.Location,
|
||||||
Is.EqualTo(setup.World.Map.GetWater("STP", "wc").Designation),
|
Is.EqualTo(setup.World.Map.GetWater("STP", "wc").Designation),
|
||||||
"Unit created on wrong coast");
|
"Unit created on wrong coast");
|
||||||
}
|
}
|
||||||
|
@ -127,7 +127,7 @@ class TestCaseBuilderTest
|
||||||
Is.EqualTo(setup.World.Map.GetPower("Germany")),
|
Is.EqualTo(setup.World.Map.GetPower("Germany")),
|
||||||
"Wrong power");
|
"Wrong power");
|
||||||
Assert.That(
|
Assert.That(
|
||||||
orderMun.Order.Unit.LocationId,
|
orderMun.Order.Unit.Location,
|
||||||
Is.EqualTo(setup.World.Map.GetLand("Mun").Designation),
|
Is.EqualTo(setup.World.Map.GetLand("Mun").Designation),
|
||||||
"Wrong unit");
|
"Wrong unit");
|
||||||
|
|
||||||
|
|
|
@ -15,13 +15,13 @@ public class UnitTests
|
||||||
Tyr = world.Map.GetLand("Tyr");
|
Tyr = world.Map.GetLand("Tyr");
|
||||||
Power pw1 = world.Map.GetPower("Austria");
|
Power pw1 = world.Map.GetPower("Austria");
|
||||||
Season a0 = world.RootSeason;
|
Season a0 = world.RootSeason;
|
||||||
Unit u1 = Unit.Build(Mun, a0, pw1, UnitType.Army);
|
Unit u1 = Unit.Build(Mun.Designation, a0, pw1, UnitType.Army);
|
||||||
|
|
||||||
world = world.ContinueOrFork(a0, out Season a1);
|
world = world.ContinueOrFork(a0, out Season a1);
|
||||||
Unit u2 = u1.Next(Boh, a1);
|
Unit u2 = u1.Next(Boh.Designation, a1);
|
||||||
|
|
||||||
_ = world.ContinueOrFork(a1, out Season a2);
|
_ = world.ContinueOrFork(a1, out Season a2);
|
||||||
Unit u3 = u2.Next(Tyr, a2);
|
Unit u3 = u2.Next(Tyr.Designation, a2);
|
||||||
|
|
||||||
Assert.That(u3.Past, Is.EqualTo(u2), "Missing unit past");
|
Assert.That(u3.Past, Is.EqualTo(u2), "Missing unit past");
|
||||||
Assert.That(u2.Past, Is.EqualTo(u1), "Missing unit past");
|
Assert.That(u2.Past, Is.EqualTo(u1), "Missing unit past");
|
||||||
|
@ -31,8 +31,8 @@ public class UnitTests
|
||||||
Assert.That(u2.Season, Is.EqualTo(a1), "Unexpected unit season");
|
Assert.That(u2.Season, Is.EqualTo(a1), "Unexpected unit season");
|
||||||
Assert.That(u3.Season, Is.EqualTo(a2), "Unexpected unit season");
|
Assert.That(u3.Season, Is.EqualTo(a2), "Unexpected unit season");
|
||||||
|
|
||||||
Assert.That(u1.LocationId, Is.EqualTo(Mun.Designation), "Unexpected unit location");
|
Assert.That(u1.Location, Is.EqualTo(Mun.Designation), "Unexpected unit location");
|
||||||
Assert.That(u2.LocationId, Is.EqualTo(Boh.Designation), "Unexpected unit location");
|
Assert.That(u2.Location, Is.EqualTo(Boh.Designation), "Unexpected unit location");
|
||||||
Assert.That(u3.LocationId, Is.EqualTo(Tyr.Designation), "Unexpected unit location");
|
Assert.That(u3.Location, Is.EqualTo(Tyr.Designation), "Unexpected unit location");
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue