Compare commits
2 Commits
5b32786904
...
864a933ba0
Author | SHA1 | Date |
---|---|---|
Tim Van Baak | 864a933ba0 | |
Tim Van Baak | c6f10868ae |
|
@ -121,7 +121,41 @@ public class AdjudicationQueryScriptHandler(
|
|||
|
||||
case "holds":
|
||||
case "dislodged":
|
||||
return ScriptResult.Fail($"Unknown assertion \"{args[0]}\"", this);
|
||||
re = new(World);
|
||||
prov = new($"^{re.FullLocation}$", RegexOptions.IgnoreCase);
|
||||
match = prov.Match(args[1]);
|
||||
if (!match.Success) return ScriptResult.Fail($"Could not parse province from \"{args[1]}\"", this);
|
||||
|
||||
timeline = match.Groups[1].Length > 0
|
||||
? match.Groups[1].Value
|
||||
: Season.First.Timeline;
|
||||
seasonsInTimeline = World.Timelines.Seasons.Where(season => season.Timeline == timeline);
|
||||
if (!seasonsInTimeline.Any()) return ScriptResult.Fail($"No seasons in timeline {timeline}", this);
|
||||
|
||||
turn = match.Groups[4].Length > 0
|
||||
? int.Parse(match.Groups[4].Value)
|
||||
// If turn is unspecified, use the second-latest turn in the timeline,
|
||||
// since we want to assert against the subjects of the orders just adjudicated,
|
||||
// and adjudication created a new set of seasons.
|
||||
: seasonsInTimeline.Max(season => season.Turn) - 1;
|
||||
season = new(timeline, turn);
|
||||
|
||||
province = World.Map.Provinces.Single(province => province.Is(match.Groups[2].Value));
|
||||
|
||||
var matchingDislodges = Adjudications.Where(adj
|
||||
=> adj is IsDislodged dislodge
|
||||
&& dislodge.Order.Unit.Season == season
|
||||
&& World.Map.GetLocation(dislodge.Order.Unit.Location).ProvinceName == province.Name);
|
||||
if (!matchingDislodges.Any()) return ScriptResult.Fail("No matching dislodge decisions");
|
||||
var isDislodged = matchingDislodges.Cast<IsDislodged>().First();
|
||||
|
||||
if (args[0] == "holds" && isDislodged.Outcome != false) {
|
||||
return ScriptResult.Fail($"Adjudication {isDislodged} is true");
|
||||
}
|
||||
if (args[0] == "dislodged" && isDislodged.Outcome != true) {
|
||||
return ScriptResult.Fail($"Adjudication {isDislodged} is false");
|
||||
}
|
||||
return ScriptResult.Succeed(this);
|
||||
|
||||
case "moves":
|
||||
case "no-move":
|
||||
|
@ -163,7 +197,41 @@ public class AdjudicationQueryScriptHandler(
|
|||
|
||||
case "support-given":
|
||||
case "support-cut":
|
||||
return ScriptResult.Fail($"Unknown assertion \"{args[0]}\"", this);
|
||||
re = new(World);
|
||||
prov = new($"^{re.FullLocation}$", RegexOptions.IgnoreCase);
|
||||
match = prov.Match(args[1]);
|
||||
if (!match.Success) return ScriptResult.Fail($"Could not parse province from \"{args[1]}\"", this);
|
||||
|
||||
timeline = match.Groups[1].Length > 0
|
||||
? match.Groups[1].Value
|
||||
: Season.First.Timeline;
|
||||
seasonsInTimeline = World.Timelines.Seasons.Where(season => season.Timeline == timeline);
|
||||
if (!seasonsInTimeline.Any()) return ScriptResult.Fail($"No seasons in timeline {timeline}", this);
|
||||
|
||||
turn = match.Groups[4].Length > 0
|
||||
? int.Parse(match.Groups[4].Value)
|
||||
// If turn is unspecified, use the second-latest turn in the timeline,
|
||||
// since we want to assert against the subjects of the orders just adjudicated,
|
||||
// and adjudication created a new set of seasons.
|
||||
: seasonsInTimeline.Max(season => season.Turn) - 1;
|
||||
season = new(timeline, turn);
|
||||
|
||||
province = World.Map.Provinces.Single(province => province.Is(match.Groups[2].Value));
|
||||
|
||||
var matchingSupports = Adjudications.Where(adj
|
||||
=> adj is GivesSupport sup
|
||||
&& sup.Order.Unit.Season == season
|
||||
&& World.Map.GetLocation(sup.Order.Unit.Location).ProvinceName == province.Name);
|
||||
if (!matchingSupports.Any()) return ScriptResult.Fail("No matching support decisions");
|
||||
var supports = matchingSupports.Cast<GivesSupport>().First();
|
||||
|
||||
if (args[0] == "support-given" && supports.Outcome != true) {
|
||||
return ScriptResult.Fail($"Adjudication {supports} is false");
|
||||
}
|
||||
if (args[0] == "support-cut" && supports.Outcome != false) {
|
||||
return ScriptResult.Fail($"Adjudication {supports} is true");
|
||||
}
|
||||
return ScriptResult.Succeed(this);
|
||||
|
||||
default:
|
||||
return ScriptResult.Fail($"Unknown assertion \"{args[0]}\"", this);
|
||||
|
|
Loading…
Reference in New Issue