Faction play 1: typed doctrine on Faction and one flight per faction per zone
FactionDoctrine/RoleDoctrine (Faction key 17), Flight as the only writer of members' Target and Task, hail/grace/compliance, FollowTask/FollowState, agent removal on Entities removal, doctrine-catalog command, FlightTests. Not yet built or run; verification follows in later commits. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
4d664b537f
commit
8f42265de3
24 changed files with 812 additions and 42 deletions
|
|
@ -273,7 +273,7 @@ public sealed class FireControlPerWeaponTests : IDisposable
|
|||
var r = Build(SideThenForward);
|
||||
var group = r.Shooter.WeaponGroups.Single(g => g.weapons.Count == 2).weapons;
|
||||
Assert.True(ReferenceEquals(group[0], r.Guns[0].Weapon), "fixture: the side mount leads the group");
|
||||
r.Zone.Agents.Add(new Minion(r.Shooter));
|
||||
r.Zone.Agents.Add(new Minion(r.Shooter, FactionDoctrine.Default(r.Shooter.ItemManager.GameplaySettings).Combatant));
|
||||
|
||||
r.Zone.Update(1f);
|
||||
r.Zone.Update(1f);
|
||||
|
|
@ -288,7 +288,7 @@ public sealed class FireControlPerWeaponTests : IDisposable
|
|||
public void CombatFiresAFusedWeaponAtADesignatedTargetOutOfArc()
|
||||
{
|
||||
var r = Build(SideThenForward, fuse: WeaponFuse.Proximity, blast: 4f);
|
||||
r.Zone.Agents.Add(new Minion(r.Shooter));
|
||||
r.Zone.Agents.Add(new Minion(r.Shooter, FactionDoctrine.Default(r.Shooter.ItemManager.GameplaySettings).Combatant));
|
||||
|
||||
r.Zone.Update(1f);
|
||||
r.Zone.Update(1f);
|
||||
|
|
@ -328,7 +328,7 @@ public sealed class FireControlPerWeaponTests : IDisposable
|
|||
if (reason == Withheld.NoTarget) target = null;
|
||||
if (reason == Withheld.NotVisible) r.Shooter.VisibleEntities.Remove(r.Target);
|
||||
|
||||
Assert.False(FireControl.AgentFires(r.Gun.Weapon, r.Shooter, target));
|
||||
Assert.False(FireControl.AgentFires(r.Gun.Weapon, r.Shooter, target, r.Shooter.ItemManager.GameplaySettings.AgentMinHitProbability));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -337,7 +337,7 @@ public sealed class FireControlPerWeaponTests : IDisposable
|
|||
// Accuracy 0 prices every direct hit at zero; the fused weapon is unmoved.
|
||||
var r = Build(SideMount, fuse: WeaponFuse.Proximity, blast: 4f, accuracy: 0f);
|
||||
|
||||
Assert.True(FireControl.AgentFires(r.Gun.Weapon, r.Shooter, r.Target));
|
||||
Assert.True(FireControl.AgentFires(r.Gun.Weapon, r.Shooter, r.Target, r.Shooter.ItemManager.GameplaySettings.AgentMinHitProbability));
|
||||
}
|
||||
|
||||
// A weapon that fires at what it hits keeps the AgentMinHitProbability threshold, per weapon.
|
||||
|
|
@ -351,7 +351,7 @@ public sealed class FireControlPerWeaponTests : IDisposable
|
|||
var p = FireControl.HitProbability(r.Gun.Weapon, r.Shooter, r.Target);
|
||||
Assert.True(p > .3f && p < .7f, $"fixture: the shot must price near the accuracy, priced {p}");
|
||||
|
||||
Assert.Equal(fires, FireControl.AgentFires(r.Gun.Weapon, r.Shooter, r.Target));
|
||||
Assert.Equal(fires, FireControl.AgentFires(r.Gun.Weapon, r.Shooter, r.Target, r.Shooter.ItemManager.GameplaySettings.AgentMinHitProbability));
|
||||
}
|
||||
|
||||
// ==== Ruling 2: the HUD forecast is Fire's own decision ====
|
||||
|
|
@ -566,7 +566,7 @@ public sealed class FireControlPerWeaponTests : IDisposable
|
|||
{
|
||||
var r = Build(fuse: WeaponFuse.Proximity, blast: 30f, range: range, targetRange: 20f);
|
||||
|
||||
Assert.Equal(fires, FireControl.AgentFires(r.Gun.Weapon, r.Shooter, r.Target));
|
||||
Assert.Equal(fires, FireControl.AgentFires(r.Gun.Weapon, r.Shooter, r.Target, r.Shooter.ItemManager.GameplaySettings.AgentMinHitProbability));
|
||||
}
|
||||
|
||||
// Combat's group pick counts only weapons that can fire: the refused gun's group out-damages the decoy's, so a
|
||||
|
|
@ -577,7 +577,7 @@ public sealed class FireControlPerWeaponTests : IDisposable
|
|||
{
|
||||
var r = Build(fuse: WeaponFuse.Proximity, blast: 30f, range: 29.5f, targetRange: 20f, decoy: true);
|
||||
Assert.True(r.Gun.Weapon.RangeDamagePerSecond(20f) > r.Decoy.Weapon.RangeDamagePerSecond(20f), "fixture: the refused gun is the stronger group");
|
||||
r.Zone.Agents.Add(new Minion(r.Shooter));
|
||||
r.Zone.Agents.Add(new Minion(r.Shooter, FactionDoctrine.Default(r.Shooter.ItemManager.GameplaySettings).Combatant));
|
||||
|
||||
r.Zone.Update(1f);
|
||||
r.Zone.Update(1f);
|
||||
|
|
@ -594,7 +594,7 @@ public sealed class FireControlPerWeaponTests : IDisposable
|
|||
{
|
||||
var r = Build(range: 10f, targetRange: 20f, decoy: true);
|
||||
Assert.True(r.Gun.Weapon.RangeDamagePerSecond(20f) > r.Decoy.Weapon.RangeDamagePerSecond(20f), "fixture: the short gun is the stronger group");
|
||||
r.Zone.Agents.Add(new Minion(r.Shooter));
|
||||
r.Zone.Agents.Add(new Minion(r.Shooter, FactionDoctrine.Default(r.Shooter.ItemManager.GameplaySettings).Combatant));
|
||||
|
||||
r.Zone.Update(1f);
|
||||
r.Zone.Update(1f);
|
||||
|
|
@ -611,7 +611,7 @@ public sealed class FireControlPerWeaponTests : IDisposable
|
|||
var r = Build(range: 60f, targetRange: 60f);
|
||||
// The agent is driven directly, not through the zone, so the shooter stays exactly at max range: the first
|
||||
// update leaves the root state for combat, the second is combat deciding.
|
||||
var agent = new Minion(r.Shooter);
|
||||
var agent = new Minion(r.Shooter, FactionDoctrine.Default(r.Shooter.ItemManager.GameplaySettings).Combatant);
|
||||
agent.Update(.01f);
|
||||
agent.Update(.01f);
|
||||
|
||||
|
|
@ -630,8 +630,33 @@ public sealed class FireControlPerWeaponTests : IDisposable
|
|||
var atThreshold = Build(accuracy: .5f, minHit: price);
|
||||
var overThreshold = Build(accuracy: .5f, minHit: MathF.BitIncrement(price));
|
||||
|
||||
Assert.True(FireControl.AgentFires(atThreshold.Gun.Weapon, atThreshold.Shooter, atThreshold.Target));
|
||||
Assert.False(FireControl.AgentFires(overThreshold.Gun.Weapon, overThreshold.Shooter, overThreshold.Target));
|
||||
Assert.True(FireControl.AgentFires(atThreshold.Gun.Weapon, atThreshold.Shooter, atThreshold.Target, atThreshold.Shooter.ItemManager.GameplaySettings.AgentMinHitProbability));
|
||||
Assert.False(FireControl.AgentFires(overThreshold.Gun.Weapon, overThreshold.Shooter, overThreshold.Target, overThreshold.Shooter.ItemManager.GameplaySettings.AgentMinHitProbability));
|
||||
}
|
||||
|
||||
// The threshold is the doctrine's, passed in: the settings global (zero here) decides nothing for a pilot. Kills: a
|
||||
// reintroduced read of AgentMinHitProbability inside AgentFires.
|
||||
[Fact]
|
||||
public void TheDoctrinesThresholdDecidesFire()
|
||||
{
|
||||
var r = Build(accuracy: .5f, minHit: 0f);
|
||||
var price = FireControl.HitProbability(r.Gun.Weapon, r.Shooter, r.Target);
|
||||
Assert.True(price > 0f);
|
||||
|
||||
Assert.True(FireControl.AgentFires(r.Gun.Weapon, r.Shooter, r.Target, price));
|
||||
Assert.False(FireControl.AgentFires(r.Gun.Weapon, r.Shooter, r.Target, MathF.BitIncrement(price)));
|
||||
}
|
||||
|
||||
// A long and a short weapon: the exponent biases the preferred range outward. Kills: the optimum read from the
|
||||
// settings global instead of the member's RoleDoctrine.
|
||||
[Fact]
|
||||
public void TheDoctrinesExponentMovesTheOptimumRange()
|
||||
{
|
||||
var r = Build(range: 400f, decoy: true);
|
||||
float Optimum(float exponent) =>
|
||||
new CombatState(new Minion(r.Shooter, new RoleDoctrine { RangeExponent = exponent, MinHitProbability = .2f })).OptimumRange;
|
||||
|
||||
Assert.True(Optimum(0f) < Optimum(1f));
|
||||
}
|
||||
|
||||
// A round refused on a Range that fell between the trigger and the round is still free: the burst is paid
|
||||
|
|
|
|||
|
|
@ -211,7 +211,7 @@ public sealed class FireControlTests : IDisposable
|
|||
// decision at all (Cut 1's regression), not AgentMinHitProbability tuning -- zero the threshold so an
|
||||
// unaided shot still counts as "worth it."
|
||||
items.GameplaySettings.AgentMinHitProbability = 0f;
|
||||
zone.Agents.Add(new Minion(shooter));
|
||||
zone.Agents.Add(new Minion(shooter, FactionDoctrine.Default(shooter.ItemManager.GameplaySettings).Combatant));
|
||||
return (shooter, target, zone);
|
||||
}
|
||||
|
||||
|
|
|
|||
332
tests/Aetheria.Shared.Tests/FlightTests.cs
Normal file
332
tests/Aetheria.Shared.Tests/FlightTests.cs
Normal file
|
|
@ -0,0 +1,332 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using CultMath;
|
||||
using GameCult.Caching;
|
||||
using UniRx;
|
||||
using Xunit;
|
||||
|
||||
// The flight (Agents/Flight.cs) is the only writer of its members' Target and Task. These tests drive it on the
|
||||
// IffAndCombatTests world. Perception is the sensors' output (VisibleEnemies, EntityInfoGathered), which
|
||||
// IffAndCombatTests covers separately, so the tests set it directly; a grudge is a real IFF override.
|
||||
public sealed class FlightTests : IDisposable
|
||||
{
|
||||
private readonly IffAndCombatTests _world = new IffAndCombatTests();
|
||||
private readonly ItemManager _items;
|
||||
private readonly Zone _zone;
|
||||
|
||||
public FlightTests() => (_items, _zone) = _world.BuildWorld();
|
||||
|
||||
public void Dispose() => _world.Dispose();
|
||||
|
||||
private static readonly Faction Hostile = new Faction { Name = "Hostile" };
|
||||
|
||||
private static Faction WithDoctrine(EngageOn on, float grace = 0, string hail = null, float comply = 0) => new Faction
|
||||
{
|
||||
Name = "Escort",
|
||||
Doctrine = new FactionDoctrine
|
||||
{
|
||||
EngageOn = on, Grace = grace, Hail = hail, ComplySpeed = comply,
|
||||
Combatant = new RoleDoctrine { RangeExponent = .25f, MinHitProbability = .2f }
|
||||
}
|
||||
};
|
||||
|
||||
private Ship Pilot(Faction faction, float x = 0)
|
||||
{
|
||||
var ship = _world.NewShip(_items, _zone, faction, piloted: true);
|
||||
ship.Position = new float3(x, 0, 0);
|
||||
return ship;
|
||||
}
|
||||
|
||||
private Ship Track(float x = 100)
|
||||
{
|
||||
var track = _world.NewShip(_items, _zone, Hostile);
|
||||
track.Position = new float3(x, 0, 0);
|
||||
return track;
|
||||
}
|
||||
|
||||
private static void See(Ship member, Entity track)
|
||||
{
|
||||
member.EntityInfoGathered[track] = 1;
|
||||
member.VisibleEnemies.Add(track);
|
||||
}
|
||||
|
||||
private void Tick(float dt)
|
||||
{
|
||||
foreach (var flight in _zone.Flights.ToArray()) flight.Update(dt);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ADefaultDoctrineEngagesTheVisibleEnemyAsMinionDid()
|
||||
{
|
||||
var member = Pilot(new Faction { Name = "Plain" });
|
||||
var track = Track();
|
||||
See(member, track);
|
||||
|
||||
Tick(.1f);
|
||||
Assert.Same(track, member.Target.Value.Entity);
|
||||
|
||||
member.VisibleEnemies.Remove(track);
|
||||
Tick(.1f);
|
||||
Assert.True(member.Target.Value.IsNone);
|
||||
Assert.IsType<PatrolOrbitsTask>(_zone.Agents.Single().Task);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void OnlyTheFlightWritesTheTarget()
|
||||
{
|
||||
var member = Pilot(new Faction { Name = "Plain" });
|
||||
See(member, Track());
|
||||
|
||||
Assert.True(member.Target.Value.IsNone);
|
||||
Tick(.1f);
|
||||
Assert.False(member.Target.Value.IsNone);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IdentifiedWaitsForTheGearTier()
|
||||
{
|
||||
_items.GameplaySettings.TargetGearInfoThreshold = .8f;
|
||||
var faction = WithDoctrine(EngageOn.Identified);
|
||||
var a = Pilot(faction);
|
||||
var b = Pilot(faction, 10);
|
||||
var track = Track();
|
||||
See(a, track);
|
||||
See(b, track);
|
||||
a.EntityInfoGathered[track] = .7f;
|
||||
b.EntityInfoGathered[track] = .7f;
|
||||
|
||||
Tick(.1f);
|
||||
Assert.True(a.Target.Value.IsNone);
|
||||
Assert.True(b.Target.Value.IsNone);
|
||||
|
||||
b.EntityInfoGathered[track] = .9f;
|
||||
Tick(.1f);
|
||||
Assert.Same(track, a.Target.Value.Entity);
|
||||
Assert.Same(track, b.Target.Value.Entity);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ProvokedEngagesOnlyTheGrudgedTrack()
|
||||
{
|
||||
var member = Pilot(WithDoctrine(EngageOn.Provoked));
|
||||
var calm = Track(80);
|
||||
var grudged = Track(120);
|
||||
See(member, calm);
|
||||
See(member, grudged);
|
||||
member.SetIff(grudged, true);
|
||||
|
||||
Tick(.1f);
|
||||
|
||||
Assert.Same(grudged, member.Target.Value.Entity);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NeverIgnoresEvenAGrudge()
|
||||
{
|
||||
var member = Pilot(WithDoctrine(EngageOn.Never));
|
||||
var track = Track();
|
||||
See(member, track);
|
||||
member.SetIff(track, true);
|
||||
|
||||
Tick(.1f);
|
||||
|
||||
Assert.True(member.Target.Value.IsNone);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GraceHailsOnceFromTheNearestThenEngages()
|
||||
{
|
||||
var faction = WithDoctrine(EngageOn.Detection, grace: 5, hail: "Hold.");
|
||||
var near = Pilot(faction, 90);
|
||||
var far = Pilot(faction, 0);
|
||||
var track = Track(100);
|
||||
See(near, track);
|
||||
See(far, track);
|
||||
|
||||
Tick(.1f);
|
||||
|
||||
Assert.True(near.Messages.ContainsKey("Hold."));
|
||||
Assert.False(far.Messages.ContainsKey("Hold."));
|
||||
Assert.True(near.Target.Value.IsNone && far.Target.Value.IsNone);
|
||||
Assert.All(_zone.Agents, a => Assert.IsType<FollowTask>(a.Task));
|
||||
|
||||
Tick(4.8f);
|
||||
Assert.True(near.Target.Value.IsNone && far.Target.Value.IsNone);
|
||||
|
||||
Tick(.4f);
|
||||
Assert.Same(track, near.Target.Value.Entity);
|
||||
Assert.Same(track, far.Target.Value.Entity);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ASlowTrackComplies()
|
||||
{
|
||||
var faction = WithDoctrine(EngageOn.Detection, grace: 5, hail: "Hold.", comply: 10);
|
||||
var member = Pilot(faction);
|
||||
var track = Track();
|
||||
See(member, track);
|
||||
|
||||
Tick(.1f);
|
||||
Tick(5.1f);
|
||||
Assert.True(member.Target.Value.IsNone);
|
||||
Assert.IsType<FollowTask>(_zone.Agents.Single().Task);
|
||||
|
||||
member.Messages.Clear();
|
||||
track.Velocity = new float2(20, 0);
|
||||
Tick(.1f);
|
||||
Assert.Same(track, member.Target.Value.Entity);
|
||||
Assert.Empty(member.Messages);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AGrudgeSkipsTheGrace()
|
||||
{
|
||||
var member = Pilot(WithDoctrine(EngageOn.Detection, grace: 5, hail: "Hold."));
|
||||
var track = Track();
|
||||
See(member, track);
|
||||
|
||||
Tick(.1f);
|
||||
Assert.True(member.Target.Value.IsNone);
|
||||
|
||||
member.SetIff(track, true);
|
||||
Tick(.1f);
|
||||
Assert.Same(track, member.Target.Value.Entity);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FollowClosesWhenFarAndOpensWhenNear()
|
||||
{
|
||||
var far = Pilot(null);
|
||||
var near = Pilot(null);
|
||||
var anchor = Track();
|
||||
|
||||
float TurnAfterFollowing(Ship ship, float3 anchorAt)
|
||||
{
|
||||
anchor.Position = anchorAt;
|
||||
var minion = new Minion(ship, FactionDoctrine.Default(_items.GameplaySettings).Combatant)
|
||||
{ Task = new FollowTask { Anchor = anchor, Standoff = 100 } };
|
||||
minion.Update(.1f);
|
||||
minion.Update(.1f);
|
||||
return ship.Turn;
|
||||
}
|
||||
|
||||
// The hull faces +z. Anchor 300 ahead: the desired velocity is dead ahead, no turn. Anchor 20 ahead: inside the
|
||||
// standoff, the desired velocity is astern, and the pilot turns to it.
|
||||
Assert.Equal(0, TurnAfterFollowing(far, new float3(0, 0, 300)), 3);
|
||||
Assert.NotEqual(0, TurnAfterFollowing(near, new float3(0, 0, 20)), 3);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ATaskChangeLeavesThePatrolSubstate()
|
||||
{
|
||||
var ship = Pilot(null);
|
||||
var anchor = Track();
|
||||
var minion = new Minion(ship, FactionDoctrine.Default(_items.GameplaySettings).Combatant)
|
||||
{ Task = new PatrolOrbitsTask { Circuit = new CultRecordKey[1] } };
|
||||
for (var i = 0; i < 4; i++) minion.Update(.1f);
|
||||
Assert.IsType<MoveToOrbitState>(CurrentState(minion));
|
||||
|
||||
minion.Task = new FollowTask { Anchor = anchor, Standoff = 50 };
|
||||
minion.Update(.1f);
|
||||
|
||||
Assert.IsType<FollowState>(CurrentState(minion));
|
||||
}
|
||||
|
||||
private static BaseState CurrentState(Agent agent) =>
|
||||
(BaseState) typeof(Agent).GetField("_currentState", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(agent);
|
||||
|
||||
[Fact]
|
||||
public void RemovalTakesTheAgentAndTheFlightMember()
|
||||
{
|
||||
var faction = new Faction { Name = "Plain" };
|
||||
var dies = Pilot(faction);
|
||||
var leaves = Pilot(faction, 10);
|
||||
var stays = Pilot(faction, 20);
|
||||
var player = _world.NewShip(_items, _zone, faction, isPlayerShip: true);
|
||||
var flight = _zone.Flights.Single();
|
||||
Assert.Equal(3, flight.Count);
|
||||
|
||||
dies.Hull.Durability = 0;
|
||||
dies.HullDamage.OnNext(1f);
|
||||
_zone.Entities.Remove(leaves);
|
||||
|
||||
Assert.Equal(new[] { stays }, _zone.Agents.Select(a => a.Ship));
|
||||
Assert.Equal(1, flight.Count);
|
||||
Assert.DoesNotContain(_zone.Agents, a => a.Ship == player);
|
||||
}
|
||||
|
||||
private static string TempCatalog() => Path.Combine(Path.GetTempPath(), "aetheria-doctrine-" + Guid.NewGuid().ToString("N") + ".cc");
|
||||
|
||||
[Fact]
|
||||
public void TheDoctrineRoundTrips()
|
||||
{
|
||||
var path = TempCatalog();
|
||||
try
|
||||
{
|
||||
using (var cache = AetheriaStores.Open(path, catalogWritable: true))
|
||||
{
|
||||
cache.Upsert(new TestCatalogGlobal { Name = "Temperament" });
|
||||
cache.Upsert(new Faction
|
||||
{
|
||||
Name = "Armed",
|
||||
Doctrine = new FactionDoctrine
|
||||
{
|
||||
EngageOn = EngageOn.Trespass, Grace = 6, Hail = "Hold.", ComplySpeed = 10,
|
||||
Combatant = new RoleDoctrine { RangeExponent = .05f, MinHitProbability = .15f, HoldStandoff = 40 }
|
||||
}
|
||||
});
|
||||
cache.Upsert(new Faction { Name = "Bare" });
|
||||
cache.FlushAsync().Wait();
|
||||
}
|
||||
|
||||
using (var cache = AetheriaStores.Open(path))
|
||||
{
|
||||
var armed = cache.GetAll<Faction>().Single(f => f.Name == "Armed").Doctrine;
|
||||
Assert.Equal(EngageOn.Trespass, armed.EngageOn);
|
||||
Assert.Equal(6f, armed.Grace);
|
||||
Assert.Equal("Hold.", armed.Hail);
|
||||
Assert.Equal(10f, armed.ComplySpeed);
|
||||
Assert.Equal(.05f, armed.Combatant.RangeExponent);
|
||||
Assert.Equal(.15f, armed.Combatant.MinHitProbability);
|
||||
Assert.Equal(40f, armed.Combatant.HoldStandoff);
|
||||
Assert.Null(cache.GetAll<Faction>().Single(f => f.Name == "Bare").Doctrine);
|
||||
}
|
||||
}
|
||||
finally { File.Delete(path); }
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TheCatalogCommandNamesAMissingFaction()
|
||||
{
|
||||
var path = TempCatalog();
|
||||
try
|
||||
{
|
||||
using (var cache = AetheriaStores.Open(path, catalogWritable: true))
|
||||
{
|
||||
cache.Upsert(new TestCatalogGlobal { Name = "Temperament" });
|
||||
foreach (var name in new[] { "Zhestokost", "Lucent Media", "Aeronautics Unlimited" }) cache.Upsert(new Faction { Name = name });
|
||||
cache.FlushAsync().Wait();
|
||||
}
|
||||
|
||||
var output = new StringWriter();
|
||||
using (var cache = AetheriaStores.Open(path, catalogWritable: true))
|
||||
{
|
||||
DoctrineCatalog.Run(cache, apply: true, output);
|
||||
cache.FlushAsync().Wait();
|
||||
}
|
||||
|
||||
Assert.Contains("Pirates: no Faction record, doctrine not written", output.ToString());
|
||||
using (var cache = AetheriaStores.Open(path, catalogWritable: true))
|
||||
{
|
||||
Assert.All(cache.GetAll<Faction>(), f => Assert.NotNull(f.Doctrine));
|
||||
Assert.Equal(EngageOn.Trespass, cache.GetAll<Faction>().Single(f => f.Name == "Zhestokost").Doctrine.EngageOn);
|
||||
cache.Upsert(new Faction { Name = "Pirates" });
|
||||
DoctrineCatalog.Run(cache, apply: true, new StringWriter());
|
||||
Assert.Equal(8f, cache.GetAll<Faction>().Single(f => f.Name == "Pirates").Doctrine.Grace);
|
||||
}
|
||||
}
|
||||
finally { File.Delete(path); }
|
||||
}
|
||||
}
|
||||
|
|
@ -48,7 +48,7 @@ public sealed class IffAndCombatTests : IDisposable
|
|||
// A world with one empty zone (no faction/security machinery engaged: GalaxyZone.Owner is null and
|
||||
// every test ship is non-player, so PresencePermitted stays at its default true and derived hostility
|
||||
// between non-owner factions is always false). Individual tests layer overrides/factions on top.
|
||||
private (ItemManager items, Zone zone) BuildWorld()
|
||||
internal (ItemManager items, Zone zone) BuildWorld()
|
||||
{
|
||||
_openCache = AetheriaStores.Open(Catalog, catalogWritable: true);
|
||||
var ledger = new ProvenanceLedger();
|
||||
|
|
@ -69,7 +69,7 @@ public sealed class IffAndCombatTests : IDisposable
|
|||
TargetDetectionInfoThreshold = .5f
|
||||
};
|
||||
|
||||
private Ship NewShip(ItemManager items, Zone zone, Faction faction = null, bool isPlayerShip = false, bool equipGun = false)
|
||||
internal Ship NewShip(ItemManager items, Zone zone, Faction faction = null, bool isPlayerShip = false, bool equipGun = false, bool piloted = false)
|
||||
{
|
||||
var hullRef = items.ItemData.RefOf<ItemData>(items.ItemData.GetByName<HullData>("Skiff"));
|
||||
var hull = new EquippableItem { Data = hullRef, Durability = 1, Lot = 1 };
|
||||
|
|
@ -82,14 +82,19 @@ public sealed class IffAndCombatTests : IDisposable
|
|||
Assert.True(ship.TryEquip(gun, HardpointCell));
|
||||
}
|
||||
|
||||
zone.Entities.Add(ship);
|
||||
ship.Activate();
|
||||
// A piloted ship joins as every piloted admission does (Zone.Admit), and so gets its agent and its flight.
|
||||
if (piloted) zone.Admit(ship, true);
|
||||
else
|
||||
{
|
||||
zone.Entities.Add(ship);
|
||||
ship.Activate();
|
||||
}
|
||||
return ship;
|
||||
}
|
||||
|
||||
// Marks entity `observer` as having detected `target`, the same way Sensor ramps EntityInfoGathered
|
||||
// past TargetDetectionInfoThreshold in the real game.
|
||||
private static void Detect(Entity observer, Entity target) => observer.EntityInfoGathered[target] = 1;
|
||||
internal static void Detect(Entity observer, Entity target) => observer.EntityInfoGathered[target] = 1;
|
||||
|
||||
[Fact]
|
||||
public void OverrideDecidesOutrightOverDerivedRule()
|
||||
|
|
|
|||
|
|
@ -623,9 +623,9 @@ public sealed class MineTests : IDisposable
|
|||
}
|
||||
lab.Zone.Update(1f);
|
||||
|
||||
Assert.False(FireControl.AgentFires(lab.Weapon, lab.Layer, null));
|
||||
Assert.False(FireControl.AgentFires(lab.Weapon, lab.Layer, far));
|
||||
Assert.True(FireControl.AgentFires(lab.Weapon, lab.Layer, near));
|
||||
Assert.False(FireControl.AgentFires(lab.Weapon, lab.Layer, null, lab.Layer.ItemManager.GameplaySettings.AgentMinHitProbability));
|
||||
Assert.False(FireControl.AgentFires(lab.Weapon, lab.Layer, far, lab.Layer.ItemManager.GameplaySettings.AgentMinHitProbability));
|
||||
Assert.True(FireControl.AgentFires(lab.Weapon, lab.Layer, near, lab.Layer.ItemManager.GameplaySettings.AgentMinHitProbability));
|
||||
Assert.False(FireControl.Refuses(lab.Weapon, lab.Layer));
|
||||
}
|
||||
|
||||
|
|
@ -667,7 +667,7 @@ public sealed class MineTests : IDisposable
|
|||
lab.Zone.Update(1f);
|
||||
|
||||
Assert.False(FireControl.Refuses(lab.Weapon, lab.Layer));
|
||||
Assert.True(FireControl.AgentFires(lab.Weapon, lab.Layer, near));
|
||||
Assert.True(FireControl.AgentFires(lab.Weapon, lab.Layer, near, lab.Layer.ItemManager.GameplaySettings.AgentMinHitProbability));
|
||||
var mine = LayOne(lab);
|
||||
Assert.Equal(150f, mine.BlastRadius);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue