public void TrackAnotherShip() { const double toDegrees = (0.5/Math.PI)*360d; var universe = new Universe(); var ship = new Ship(new Corporation() { Location = universe }.Recruit()) { Name="GG", Speed = 0.5d, Location = universe }; var track = new Ship(new Corporation() { Location = universe }.Recruit()) { Name="BG", Speed = 100d, UniversalCoordinates = new Vector(100, -1000, 0), Location = universe }; var hardPoint = new HardPoint(ship, HardPointPosition.Right); ship.Destination = new Vector(0, 10, 0); track.Destination = new Vector(100, 1000, 0); ulong tick = 0; while (ship.HasDestination) { ship.Tick(tick); track.Tick(tick); Vector target = (track.UniversalCoordinates - ship.UniversalCoordinates); Console.WriteLine("Distance to target: {0:n2}, Hardpoint angle to target: {1:n2}* (delta: {2:n2}*)", target.Magnitude, Vector.Angle(hardPoint.Origin, target) * toDegrees, Vector.Angle(hardPoint.Orientation, target) * toDegrees); bool inRange = hardPoint.InRange(track); bool canTrack = hardPoint.CanTrack(track); bool isTracking = hardPoint.AimAt(track); Console.WriteLine("{0} {1} target {2}", ship.Name, isTracking ? "has" : "does not have", (inRange) ? (canTrack ? hardPoint.Inclination.ToString("n2")+"*" : "[Out of position]") : "[Out of range]"); tick++; } }
private void CanTrack(HardPointPosition position, CanTrackResult expected) { var hp = new HardPoint(_ship, position); Assert.That(hp.CanTrack(_leftTarget), Is.EqualTo(expected.Left), "Can track left"); Assert.That(hp.CanTrack(_rightTarget), Is.EqualTo(expected.Right), "Can track right"); Assert.That(hp.CanTrack(_frontTarget), Is.EqualTo(expected.Front), "Can track front"); Assert.That(hp.CanTrack(_rearTarget), Is.EqualTo(expected.Rear), "Can track rear"); Assert.That(hp.CanTrack(_sideTarget), Is.EqualTo(expected.LeftTop), "Can track left-top"); }