diff --git a/Assets/Scripts/ServerShared/Entity.cs b/Assets/Scripts/ServerShared/Entity.cs index 7fb5d4174..80bce7a01 100644 --- a/Assets/Scripts/ServerShared/Entity.cs +++ b/Assets/Scripts/ServerShared/Entity.cs @@ -213,8 +213,11 @@ public abstract class Entity private readonly List _pingReturns = new List(); internal IReadOnlyList PingReturns => _pingReturns; // What this observer has seen each ship's items do (ruling visibility-per-capability-reveal), keyed (subject, - // item). Written only by Sense and PublishInbox through RecordReveal; memory of the sitting, never decayed. + // item). Written only by RecordReveal (an act enters) and EndReveals (an end the observer perceives, or a departed + // subject's entries aged past BearingMemory), cleared by Deactivate (ruling reveal-ends-on-perception). private readonly Dictionary> _reveals = new Dictionary>(); + private readonly List _endedItems = new List(); + private readonly List _agedSubjects = new List(); public ReactiveProperty CurrentSecurityLevel = new ReactiveProperty(SecurityLevel.Open); public ReadOnlyReactiveProperty PresencePermitted; @@ -265,7 +268,6 @@ public abstract class Entity { if (Target.Value.Entity == remove.Value) SetTarget(TargetRef.None); EntityInfoGathered.Remove(remove.Value); - _reveals.Remove(remove.Value); EntityHostility.Remove(remove.Value); VisibleEntities.Remove(remove.Value); VisibleEnemies.Remove(remove.Value); @@ -865,9 +867,7 @@ public abstract class Entity foreach (var paint in _paintInbox) { _incomingPaints.Add(paint.Warning); - // An emitter that left the zone (died, warped, docked) since it painted is no longer a subject: its - // warning still lasts its tick, but it is not recorded as a contact. - if (Zone.Entities.Contains(paint.Emitter)) RecordReveal(paint.Emitter, paint.Item, SignatureChannel.Emission); + RecordReveal(paint.Emitter, paint.Item, SignatureChannel.Emission); } _paintInbox.Clear(); _pingReturns.Clear(); @@ -890,21 +890,35 @@ public abstract class Entity _paintInbox.Add(new PendingPaint(new PaintWarning(normalize((emitter.Position - Position).xz), item?.Data, mode, strength), emitter, item)); } - // The one writer of the reveal book (callers: Sense and PublishInbox, both in this file): this observer saw - // `item` of `subject` act on `channel`, now, from this bearing. An item-less act (hull radiation, a consumable) - // reveals nothing. A later act of the same item replaces the earlier one. + // The reveal book's one way in and its one membership gate (callers: Sense and PublishInbox, both in this file): + // this observer saw `item` of `subject` act on `channel`, now, from this bearing. An item-less act (hull + // radiation, a consumable) reveals nothing, and neither does a subject that is not in the zone: a departed + // subject's entries are never created or refreshed, from any caller. A later act of the same item replaces the + // earlier one. internal void RecordReveal(Entity subject, EquippedItem item, SignatureChannel channel) { - if (!_active || item == null) return; + if (!_active || item == null || !Zone.Entities.Contains(subject)) return; if (!_reveals.TryGetValue(subject, out var book)) _reveals[subject] = book = new Dictionary(); book[item] = new Reveal(item, channel, normalize((subject.Position - Position).xz), Zone.Time); } + // The book's one way out (caller: Sense): `item` null ends every reveal of `subject`, otherwise that item's. + // The subject's key goes with its last entry. + private void EndReveals(Entity subject, EquippedItem item) + { + if (!_reveals.TryGetValue(subject, out var book)) return; + if (item != null) book.Remove(item); + else book.Clear(); + if (book.Count == 0) _reveals.Remove(subject); + } + // What this observer has seen `subject`'s items do: each item's latest act, and nothing the subject's present - // gear or Durability says (ruling contact-reads-book-aim-reads-live): an item destroyed out of this observer's - // sight stays revealed until the subject leaves the zone or this observer deactivates. Whether an item can be - // aimed at now is FireControl.IsRevealed's question, not this one. + // gear or Durability says (ruling contact-reads-book-aim-reads-live). A reveal ends only on what this observer + // perceives (ruling reveal-ends-on-perception): the destruction of an item of a ship it identifies, the death, + // dock or warp of a subject its instruments could see leave, or, for a subject that has left the zone, the + // freshest entry aging past BearingMemory; Deactivate clears it all. Whether an item can be aimed at now is + // FireControl.IsRevealed's question, not this one. public IEnumerable RevealsOf(Entity subject) => _reveals.TryGetValue(subject, out var book) ? book.Values : Enumerable.Empty(); @@ -950,7 +964,38 @@ public abstract class Entity if (perSignature < 0f) perSignature = PassiveInfo(other.Position.xz, 1f); if (signature.Strength * perSignature > threshold) RecordReveal(other, signature.Item, signature.Channel); } + // The observer resolves this ship's gear (ContactOf's own Identified gate), so it perceives an item of it + // destroyed. Ending after recording: a destroyed item's lingering flash cannot re-enter the book. + if (EntityInfoGathered.TryGetValue(other, out var info) && info >= ItemManager.GameplaySettings.TargetGearInfoThreshold + && _reveals.TryGetValue(other, out var book)) + { + _endedItems.Clear(); + foreach (var item in book.Keys) + if (item.EquippableItem.Durability < .01f) _endedItems.Add(item); + for (var j = 0; j < _endedItems.Count; j++) EndReveals(other, _endedItems[j]); + } } + // A subject that left the zone (death, dock, warp, any removal) is perceived gone under the light-act gate: as + // bright as its non-Emission signature was at removal, from where it was. A re-admitted subject did not leave. + var departures = Zone.Departures; + for (var i = 0; i < departures.Count; i++) + { + var departure = departures[i]; + if (!_reveals.ContainsKey(departure.Subject) || entities.Contains(departure.Subject)) continue; + if (departure.Signature * PassiveInfo(departure.Position, 1f) > threshold) EndReveals(departure.Subject, null); + } + // What stays of a departed subject is memory: pruned once its freshest entry is as old as ContactOf stops + // remembering it. + var memory = ItemManager.GameplaySettings.BearingMemory; + _agedSubjects.Clear(); + foreach (var pair in _reveals) + { + if (entities.Contains(pair.Key)) continue; + var freshest = float.MinValue; + foreach (var reveal in pair.Value.Values) freshest = Math.Max(freshest, reveal.Time); + if (Zone.Time - freshest >= memory) _agedSubjects.Add(pair.Key); + } + for (var i = 0; i < _agedSubjects.Count; i++) EndReveals(_agedSubjects[i], null); } public Entity(ItemManager itemManager, Zone zone, EquippableItem hull, EntitySettings settings) diff --git a/Assets/Scripts/ServerShared/Sensing.cs b/Assets/Scripts/ServerShared/Sensing.cs index 9c846a694..129513dda 100644 --- a/Assets/Scripts/ServerShared/Sensing.cs +++ b/Assets/Scripts/ServerShared/Sensing.cs @@ -93,9 +93,26 @@ public readonly struct Reveal } } +// A subject's removal from a zone as the zone recorded it (death, dock, warp, any removal): where it was and how +// bright its light was (its signature outside the Emission channel). Judged by each observer's Sense under the +// light-act gate; notification only, one tick long, it decides nothing. +public readonly struct Departure +{ + public readonly Entity Subject; + public readonly float2 Position; + public readonly float Signature; + + public Departure(Entity subject, float2 position, float signature) + { + Subject = subject; + Position = position; + Signature = signature; + } +} + // How much an observer holds of one subject, derived on read by Entity.ContactOf from its track, its reveals and // the zone clock. Detected: tracked, or a reveal younger than GameplaySettings.BearingMemory. Tracked: exactly -// membership of VisibleEntities. Classified: detected, with any live reveal. Identified: the track has reached +// membership of VisibleEntities. Classified: detected, with any reveal in the book. Identified: the track has reached // TargetGearInfoThreshold. Bearing is the true bearing while tracked, else the freshest reveal's. public readonly struct Contact { diff --git a/Assets/Scripts/ServerShared/Zone.cs b/Assets/Scripts/ServerShared/Zone.cs index 6ce39a3c3..97554a9ad 100644 --- a/Assets/Scripts/ServerShared/Zone.cs +++ b/Assets/Scripts/ServerShared/Zone.cs @@ -72,6 +72,9 @@ public class Zone return false; } + private readonly List _departures = new List(); + internal IReadOnlyList Departures => _departures; + public float Time { get => (float) _time; @@ -109,6 +112,9 @@ public class Zone // every join, whichever caller admits the entity (deserialization below, a jump, a spawned turret) -- // ObserveAdd fires for all of them. Forbidden writer: no presentation may remove an entity from Zone. Entities.ObserveAdd().Subscribe(add => add.Value.Death.Subscribe(_ => { Entities.Remove(add.Value); add.Value.Deactivate(); })); + // The one record of a removal for observers (ruling reveal-ends-on-perception): read by the next Sense pass. + Entities.ObserveRemove().Subscribe(remove => _departures.Add(new Departure(remove.Value, remove.Value.Position.xz, + remove.Value.Visibility - remove.Value.SignatureOn(SignatureChannel.Emission)))); Targets.Add(new EntityTargets()); @@ -230,6 +236,7 @@ public class Zone foreach (var entity in entities) entity.PublishInbox(); foreach (var entity in entities) entity.Update(deltaTime); foreach (var entity in entities) entity.Sense(); + _departures.Clear(); StepMines(deltaTime); StepClouds(deltaTime); diff --git a/tests/Aetheria.Shared.Tests/ContactRevealTests.cs b/tests/Aetheria.Shared.Tests/ContactRevealTests.cs index d2fced007..6099af42c 100644 --- a/tests/Aetheria.Shared.Tests/ContactRevealTests.cs +++ b/tests/Aetheria.Shared.Tests/ContactRevealTests.cs @@ -502,23 +502,173 @@ public sealed class ContactRevealTests : IDisposable Assert.False(contact.Identified); } - // ---- RevealsLeaveWithTheSubjectAndTheObserver ---- + // ---- A subject leaves ---- + private Action SenseOf(Entity observer) => + (Action) Delegate.CreateDelegate(typeof(Action), observer, typeof(Entity).GetMethod("Sense", BindingFlags.Instance | BindingFlags.NonPublic)); + + // The ways a ship leaves a zone: removed by anything, the warp path (Deactivate, then Remove) and death. + private static void Leave(Zone zone, Entity e, string how) + { + switch (how) + { + case "remove": zone.Entities.Remove(e); break; + case "warp": e.Deactivate(); zone.Entities.Remove(e); break; + case "death": e.Hull.Durability = 0f; e.HullDamage.OnNext(1f); break; + default: throw new Exception("fixture: " + how); + } + Assert.DoesNotContain(e, zone.Entities); + } + + private static float Freshest(Entity observer, Entity subject) => observer.RevealsOf(subject).Max(r => r.Time); + + // Ruling reveal-ends-on-perception: a ship leaving the zone does not by itself empty any book. Out of this + // observer's sight (the light it showed at removal is below the observer's gate) its reveals stay, unrefreshed, + // and the contact stays Detected on the freshest bearing, exactly until that bearing is BearingMemory old; then + // the book drops the ship. A live quiet ship's old reveal is another matter: it stays in the book. [Fact] - public void RevealsLeaveWithTheSubject() + public void AnUnseenDepartureKeepsTheContactUntilTheBearingLapses() { var e = Add(float3(0, 0, 100), new[] { "Gun", "Gun" }); var o = Add(float3(0, 0, 0), new[] { "Eye" }); + var q = Add(float3(40, 0, 100), new[] { "Gun" }); var guns = Guns(e); Fire(e, guns[0]); Fire(e, guns[1]); + Fire(q, Guns(q)[0]); + var memory = _items.GameplaySettings.BearingMemory; + var times = o.RevealsOf(e).ToDictionary(r => r.Item, r => r.Time); + var freshest = times.Values.Max(); + var bearing = o.ContactOf(e).Bearing; + e.SetSignature(new object(), SignatureChannel.Reflection, 1f, guns[0]); + Assert.True(e.Visibility * o.PassiveInfo(e.Position.xz, 1f) <= _items.GameplaySettings.TargetDetectionInfoThreshold, "fixture: its last light is below o's gate"); + Assert.Equal(2, times.Count); + + _zone.Entities.Remove(e); Assert.Equal(2, o.RevealsOf(e).Count()); + var lapsed = false; + var ticks = 0; + while (!lapsed && ticks++ < 100) + { + Tick(.1f); + var within = _zone.Time - freshest < memory; + lapsed = !within; + Assert.Equal(within, o.RevealsOf(e).Count() == 2); // exactly while the bearing is remembered + Assert.Equal(within, o.ContactOf(e).Detected); + Assert.Equal(within ? 1 : 0, RevealBookSubjects(o) - 1); // the quiet live ship's key stays either way + if (!within) continue; + var contact = o.ContactOf(e); + Assert.True(contact.Classified && !contact.Tracked); + AssertBearing(bearing.x, bearing.y, contact.Bearing); + foreach (var reveal in o.RevealsOf(e)) Assert.Equal(times[reveal.Item], reveal.Time); // never refreshed + } + + Assert.True(lapsed, "fixture: the bearing lapsed"); + Assert.Empty(o.RevealsOf(e)); + Assert.False(o.ContactOf(e).Detected); + Assert.Equal(1, RevealBookSubjects(o)); // only the live ship's key + + for (var i = 0; i < 30; i++) Tick(.2f); // q, live and quiet, was revealed 6 s ago, far more than twice the memory + Assert.Single(o.RevealsOf(q)); + Assert.False(o.ContactOf(q).Detected); + } + + // The same departure seen: every way a ship leaves is one departure fact, judged when the observer next senses. + // A strong ear (sensitivity 4) and a weak eye (2) at the same place, listed on either side of the ship, both hold + // both reveals right after the removal; after the next tick only the observer whose gate the ship's light at + // removal passes (signature 2 x info 8/d = .16 against .08) has let them go. + [Theory] + [InlineData("remove", false)] + [InlineData("remove", true)] + [InlineData("warp", false)] + [InlineData("death", false)] + [InlineData("death", true)] + public void ASeenDepartureEndsEveryRevealOfTheSubject(string how, bool strongFirst) + { + Entity strong = null, weak = null; + if (strongFirst) strong = Add(float3(-1, 0, 0), new[] { "Ear" }); + else weak = Add(float3(1, 0, 0), new[] { "Eye" }); + var e = Add(float3(0, 0, 100), new[] { "Gun", "Gun" }); + if (strongFirst) weak = Add(float3(1, 0, 0), new[] { "Eye" }); + else strong = Add(float3(-1, 0, 0), new[] { "Ear" }); + var guns = Guns(e); + Fire(e, guns[0]); + Fire(e, guns[1]); + foreach (var observer in new[] { strong, weak }) Assert.Equal(2, observer.RevealsOf(e).Count()); + e.SetSignature(new object(), SignatureChannel.Reflection, 2f, guns[0]); + var threshold = _items.GameplaySettings.TargetDetectionInfoThreshold; + Assert.True(e.Visibility * strong.PassiveInfo(e.Position.xz, 1f) > threshold, "fixture: the ear passes the gate"); + Assert.True(e.Visibility * weak.PassiveInfo(e.Position.xz, 1f) <= threshold, "fixture: the eye fails it"); + + Leave(_zone, e, how); + + Assert.Equal(2, strong.RevealsOf(e).Count()); // nothing ends at the removal itself + Assert.Equal(2, weak.RevealsOf(e).Count()); + Tick(.1f); + + Assert.Empty(strong.RevealsOf(e)); + Assert.Equal(0, RevealBookSubjects(strong)); + Assert.False(strong.ContactOf(e).Detected); + Assert.Equal(2, weak.RevealsOf(e).Count()); + Assert.True(weak.ContactOf(e).Detected); + } + + // The gate at its edge, at one fixed distance: the light at removal a hair above the observer's threshold ends + // the reveals, a hair below does not. The factor is the production gate's own: threshold over the observer's + // passive info on the spot where the ship was. + [Theory] + [InlineData(1.01f, true)] + [InlineData(.99f, false)] + public void ADepartureEndsRevealsOnlyAboveTheLightActGate(float against, bool ended) + { + var e = Add(float3(0, 0, 100), new[] { "Gun" }); + var o = Add(float3(0, 0, 0), new[] { "Eye" }); + Fire(e, Guns(e)[0]); + Assert.Single(o.RevealsOf(e)); + var gate = _items.GameplaySettings.TargetDetectionInfoThreshold / o.PassiveInfo(e.Position.xz, 1f); + e.SetSignature(new object(), SignatureChannel.Reflection, gate * against, Guns(e)[0]); + Assert.Equal(gate * against, e.Visibility, 3); + + _zone.Entities.Remove(e); + Tick(.1f); + + Assert.Equal(ended ? 0 : 1, o.RevealsOf(e).Count()); + } + + // A signature on the Emission channel (paint strength, a ping) is not light: it does not make a departure seen. + [Fact] + public void AnEmissionSignatureDoesNotMakeADepartureSeen() + { + var e = Add(float3(0, 0, 100), new[] { "Gun" }); + var o = Add(float3(0, 0, 0), new[] { "Eye" }); + Fire(e, Guns(e)[0]); + e.SetSignature(new object(), SignatureChannel.Emission, 1000f, Guns(e)[0]); + + _zone.Entities.Remove(e); + Tick(.1f); + + Assert.Single(o.RevealsOf(e)); + } + + // A ship removed and put back before anyone senses has not left: its reveals stand, and its next act refreshes them. + [Fact] + public void AReAdmittedSubjectHasNotDeparted() + { + var e = Add(float3(0, 0, 100), new[] { "Gun" }); + var o = Add(float3(0, 0, 0), new[] { "Eye" }); + var gun = Guns(e)[0]; + var at = Fire(e, gun); + e.SetSignature(new object(), SignatureChannel.Reflection, 1000f, gun); // bright enough for any gate + _zone.Entities.Remove(e); _zone.Entities.Add(e); + Tick(.1f); - Assert.Empty(o.RevealsOf(e)); // gone with the subject, and not back with it - Assert.Equal(0, RevealBookSubjects(o)); // and the book no longer holds the ship at all + Assert.Equal(at, Assert.Single(o.RevealsOf(e)).Time); + var later = Fire(e, gun); + Assert.True(later > at); + Assert.Equal(later, Assert.Single(o.RevealsOf(e)).Time); } private static int RevealBookSubjects(Entity observer) => @@ -526,7 +676,9 @@ public sealed class ContactRevealTests : IDisposable // Ruling contact-reads-book-aim-reads-live: what an observer knows of a ship comes from its own book. A gun // destroyed by a third party out of its sight changes none of its levels and stays in its reveal list, while - // the aiming read, which asks about the item now, refuses the dead gun and still serves the live one. + // the aiming read, which asks about the item now, refuses the dead gun and still serves the live one. No Sense + // runs after the destruction here (the aiming read needs info 1, at which a Sense would perceive it); the + // unseen case with a Sense is AnIdentifiedObserverSeesGearDestroyed's below-threshold case. [Fact] public void GearDestroyedOutOfSightLeavesWhatTheObserverKnowsAlone() { @@ -558,8 +710,60 @@ public sealed class ContactRevealTests : IDisposable Assert.True(o.ContactOf(e).Classified); } - // A paint inboxed in the tick its emitter leaves the zone is published the next tick, and is no longer the - // act of a subject in the zone: it warns for its tick and records no reveal, so the observer holds no ghost. + // Ruling reveal-ends-on-perception: an observer that resolves a ship's gear (its track at TargetGearInfoThreshold) + // perceives an item of it destroyed, and the reveal of that item ends in the same Sense pass. One that does not + // resolve it perceives nothing. + [Theory] + [InlineData(.8f, 1, 1, 1)] + [InlineData(.8f, 2, 0, 0)] + [InlineData(.79f, 1, 2, 1)] + [InlineData(.79f, 2, 2, 1)] + public void AnIdentifiedObserverSeesGearDestroyed(float info, int destroyed, int remaining, int classifiedKeys) + { + var e = Add(float3(0, 0, 100), new[] { "Gun", "Gun" }); + var o = Add(float3(0, 0, 0), new[] { "Eye" }); + var guns = Guns(e); + Fire(e, guns[0]); + Fire(e, guns[1]); + o.VisibleEntities.Add(e); // tracked, so what the track holds is not the question + o.EntityInfoGathered[e] = info; + var sense = SenseOf(o); + for (var i = 0; i < destroyed; i++) guns[i].EquippableItem.Durability = 0f; + + sense(); + + Assert.Equal(remaining, o.RevealsOf(e).Count()); + var contact = o.ContactOf(e); + Assert.True(contact.Detected); + Assert.Equal(remaining > 0, contact.Classified); + Assert.Equal(remaining > 0 ? classifiedKeys : 0, RevealBookSubjects(o)); + if (remaining == 1 && info >= .8f) Assert.Same(guns[1], o.RevealsOf(e).Single().Item); + } + + // The same through a real tick: a gun destroyed while its flash still shows, seen by an observer that identifies + // the ship, is not in the book after the tick. + [Fact] + public void ADestroyedGunStillFlashingIsNotRecordedByAnIdentifyingObserver() + { + var e = Add(float3(0, 0, 60), new[] { "Gun", "Gun" }); + var o = Add(float3(0, 0, 0), new[] { "Eye" }); + var guns = Guns(e); + Fire(e, guns[0]); + Fire(e, guns[1]); + e.SetSignature(new object(), SignatureChannel.Reflection, 1000f, guns[0]); // the dying gun's glare outlasts the tick + guns[0].EquippableItem.Durability = 0f; + for (var i = 0; i < 20 && Track(o, e) < .8f; i++) Tick(.01f); + Assert.True(Track(o, e) >= .8f, "fixture: o identifies e"); + + Tick(.01f); + + Assert.DoesNotContain(o.RevealsOf(e), r => r.Item == guns[0]); + Assert.Contains(o.RevealsOf(e), r => r.Item == guns[1]); + } + + // A paint inboxed in the tick its emitter leaves the zone is published the next tick, and is no longer the act of + // a subject in the zone: it warns for its tick and neither creates nor refreshes a reveal. The reveal the + // locker's earlier paint made stays what it was, as a departure out of sight (below the observer's gate) leaves it. [Fact] public void APaintFromAShipThatHasLeftTheZoneRevealsNothing() { @@ -570,16 +774,18 @@ public sealed class ContactRevealTests : IDisposable locker.SetTarget(o); locker.Aim = normalize(o.Position - locker.Position); for (var tick = 0; tick < 10 && !o.RevealsOf(locker).Any(); tick++) Tick(.5f); - Assert.Single(o.RevealsOf(locker)); // fixture: the lock paints every tick, and the first one is recorded + var first = Assert.Single(o.RevealsOf(locker)); // fixture: the lock paints every tick, and the first one is recorded + Assert.True(locker.Visibility * o.PassiveInfo(locker.Position.xz, 1f) <= _items.GameplaySettings.TargetDetectionInfoThreshold, "fixture: its departure is below o's gate"); _zone.Entities.Remove(locker); // dies, warps or docks while its latest paint is still in o's inbox - Assert.Empty(o.RevealsOf(locker)); + var inboxed = ((System.Collections.IList) typeof(Entity).GetField("_paintInbox", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(o)).Count; + Assert.True(inboxed > 0 || o.IncomingPaints.Count > 0, "fixture: a paint is in flight"); Tick(.1f); Assert.Single(o.IncomingPaints); // fixture: the stale paint was published - Assert.Empty(o.RevealsOf(locker)); - Assert.False(o.ContactOf(locker).Detected); - Assert.Equal(0, RevealBookSubjects(o)); + var after = Assert.Single(o.RevealsOf(locker)); + Assert.Equal(first.Time, after.Time); + Assert.Equal(1, RevealBookSubjects(o)); } // Ruling sensor-stat-set 4: a painted target always learns the emitter's class, whichever the mode. A ping @@ -609,6 +815,30 @@ public sealed class ContactRevealTests : IDisposable AssertBearing(0f, 1f, reveal.Bearing); } + // A search paint (a ping crossing the observer) from a pinger that has left the zone before the paint is + // published warns once and creates no reveal and no key. + [Fact] + public void ASearchPaintFromAPingerThatHasLeftCreatesNoReveal() + { + var p = Add(float3(0, 0, 100), new[] { "Eye" }); + var o = Add(float3(0, 0, 0), new[] { "Eye" }); + var sensor = (Sensor) p.Equipment.Single(i => i.Behaviors.Any(b => b is Sensor)).Behaviors.Single(b => b is Sensor); + Tick(.01f); + sensor.Ping(); + var inbox = (System.Collections.IList) typeof(Entity).GetField("_paintInbox", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(o); + for (var tick = 0; tick < 100 && inbox.Count == 0; tick++) Tick(.1f); + Assert.NotEmpty(inbox); // fixture: the ping crossed o and its paint waits to be published + + _zone.Entities.Remove(p); + Tick(.1f); + + Assert.Single(o.IncomingPaints); + Assert.Equal(PaintMode.Search, o.IncomingPaints.Single().Mode); + Assert.Empty(o.RevealsOf(p)); + Assert.Equal(0, RevealBookSubjects(o)); + Assert.False(o.ContactOf(p).Detected); + } + // An observer's own gear is not another ship's act: a ship that fires its own gun, with its own sensor at the // very place of the light, records nothing of itself, while a neighbour does record the gun. [Fact] @@ -716,9 +946,19 @@ public sealed class ContactRevealTests : IDisposable gunItems.Add(item); } var o = Add(float3(0, 0, 0), new[] { "Eye" }); - var sense = (Action) Delegate.CreateDelegate(typeof(Action), o, typeof(Entity).GetMethod("Sense", BindingFlags.Instance | BindingFlags.NonPublic)); + var sense = SenseOf(o); for (var i = 0; i < 10; i++) sense(); Assert.Equal(19, _zone.Entities.Where(x => x != o).Count(x => o.RevealsOf(x).Any())); // fixture: every ship is revealed + // One of them is identified by o (its destroyed gun is ended in the pass), and one has left, quiet, so its + // entries await the prune and its departure sits in the zone's list. + var identified = gunItems.Select(g => _zone.Entities.Single(x => x.Equipment.Contains(g))).First(); + o.EntityInfoGathered[identified] = 1f; + var departed = _zone.Entities.Single(x => x.Equipment.Contains(gunItems[18])); + foreach (var source in departed.VisibilitySources.Keys.ToArray()) departed.SetSignature(source, SignatureChannel.Reflection, 0f, gunItems[18]); + _zone.Entities.Remove(departed); + Assert.Single((System.Collections.IList) typeof(Zone).GetProperty("Departures", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(_zone)); + sense(); + Assert.Single(o.RevealsOf(departed)); // fixture: awaiting its prune var before = GC.GetAllocatedBytesForCurrentThread(); for (var i = 0; i < 600; i++) sense();