Exemplo n.º 1
0
        public void TestMovesMaxPossible()
        {
            var ship = new Ship(new Corporation());
            var hardPoint = new HardPoint(ship, HardPointPosition.Right);

            var aimAt = new Location(1, -1, 0); // 45* back
            Assert.IsTrue(hardPoint.AimAt(aimAt), "Position: {0:n2}", hardPoint.Inclination);

            // assert we moved 45*
            Assert.AreEqual(Math.Round(Math.PI / 4, 4), Math.Round(Vector.Angle(hardPoint.Origin, hardPoint.Orientation), 4));

            // assert we moved back
            Assert.Less(hardPoint.Orientation.Y, 0d);

            aimAt = new Location(1, 1, 0); // 45* forward
            Assert.IsFalse(hardPoint.AimAt(aimAt), "Position: {0:n2}", hardPoint.Inclination);

            // assert we moved back to origin
            Assert.AreEqual(hardPoint.Origin, hardPoint.Orientation);

            aimAt = new Location(1, 1, 0); // 45* forward
            Assert.IsTrue(hardPoint.AimAt(aimAt), "Position: {0:n2}", hardPoint.Inclination);

            // assert we moved 45*
            Assert.AreEqual(Math.Round(Math.PI / 4, 4), Math.Round(Vector.Angle(hardPoint.Origin, hardPoint.Orientation), 4));

            // assert we moved back
            Assert.Greater(hardPoint.Orientation.Y, 0d);

            aimAt = new Location(1, -1, 0); // 45* back
            Assert.IsFalse(hardPoint.AimAt(aimAt), "Position: {0:n2}", hardPoint.Inclination);

            // assert we moved back to origin
            Assert.AreEqual(hardPoint.Origin, hardPoint.Orientation);
        }
Exemplo n.º 2
0
        public void Extremes()
        {
            var ship = new Ship(new Corporation());
            var hardPoint = new HardPoint(ship, HardPointPosition.Right);

            var aimAt = new Location(-1, 1, 0); // 135* forward
            Assert.IsFalse(hardPoint.AimAt(aimAt), "Position: {0:n2}", hardPoint.Inclination);

            hardPoint = new HardPoint(ship, HardPointPosition.Front) { Speed = 1d };

            aimAt = new Location(0, -1, 0); // 180* backward
            Assert.IsFalse(hardPoint.AimAt(aimAt), "Position: {0:n2}", hardPoint.Inclination);
        }
Exemplo n.º 3
0
        public void AdvanceHardPointAttackCounter()
        {
            var hp = new HardPoint(null, HardPointPosition.Top);
            hp.EquipWeapon(new Weapon { WeaponInfo = _w1 });

            int attacks = GetAttackCount(hp, 10, 1d);
            Assert.That(attacks, Is.EqualTo(10));

            attacks = GetAttackCount(hp, 10, 1.25);
            Assert.That(attacks, Is.EqualTo(12));

            attacks = GetAttackCount(hp, 10, 0.7d);
            Assert.That(attacks, Is.EqualTo(6));
        }
Exemplo n.º 4
0
        public void Aims()
        {
            var hp = new HardPoint(_ship, HardPointPosition.Top);
            hp.AimAt(_leftTarget);
            Assert.That(hp.Inclination, Is.EqualTo(90d));

            hp.AimAt(_rightTarget);
            Assert.That(hp.Inclination, Is.EqualTo(90d));

            hp.AimAt(_frontTarget);
            Assert.That(hp.Inclination, Is.EqualTo(0d));

            hp.AimAt(_rearTarget);
            Assert.That(hp.Inclination, Is.EqualTo(180d));
        }
Exemplo n.º 5
0
        public void MaxExtents()
        {
            var ship = new Ship(new Corporation());
            var hardPoint = new HardPoint(ship, HardPointPosition.Right);

            var aimAt = new Location(1, 1, 0); // 45* forward
            Assert.IsTrue(hardPoint.AimAt(aimAt), "Position: {0:n2}", hardPoint.Inclination);

            hardPoint.Reset();

            aimAt = new Location(1, -1, 0); // 45* behind
            Assert.IsTrue(hardPoint.AimAt(aimAt), "Position: {0:n2}", hardPoint.Inclination);

            // now test we can't move further downward
            aimAt = new Location(1, -1.1d, 0);
            Assert.IsFalse(hardPoint.AimAt(aimAt), "Position: {0:n2}", hardPoint.Inclination);
        }
Exemplo n.º 6
0
        private int GetAttackCount(HardPoint hp, int numberOfRounds, double speed)
        {
            int attack = 0;

            hp.AttackCounter = 0;
            _w1.Speed = speed;

            for (int i = 0; i < numberOfRounds; i++)
            {
                hp.AttackCounter += hp.Weapon.WeaponInfo.Speed;
                while (hp.AttackCounter >= 1d)
                {
                    attack++;
                    hp.AttackCounter -= 1;
                }
            }

            return attack;
        }
Exemplo n.º 7
0
        public void TestMovesToExtent()
        {
            var ship = new Ship(new Corporation());
            var hardPoint = new HardPoint(ship, HardPointPosition.Right);

            var aimAt = new Location(0, 1, 0); // 90* forward
            Assert.IsFalse(hardPoint.AimAt(aimAt), "Position: {0:n2}", hardPoint.Inclination);

            // assert we moved 45*
            Assert.AreEqual(Math.Round(Math.PI / 4, 4), Math.Round(Vector.Angle(hardPoint.Origin, hardPoint.Orientation), 4));

            // assert we moved forward
            Assert.Greater(hardPoint.Orientation.Y, 0d);

            // now make sure the hard point knows this =)
            Assert.AreEqual(45d, hardPoint.Inclination);

            hardPoint.Reset();

            aimAt = new Location(0, -1, 0); // 90* back
            Assert.IsFalse(hardPoint.AimAt(aimAt), "Position: {0:n2}", hardPoint.Inclination);

            // assert we moved 45*
            Assert.AreEqual(Math.Round(Math.PI / 4, 4), Math.Round(Vector.Angle(hardPoint.Origin, hardPoint.Orientation), 4));

            // assert we moved back
            Assert.Less(hardPoint.Orientation.Y, 0d);

            // now make sure the hard point knows this =)
            Assert.AreEqual(-45d, hardPoint.Inclination);
        }
Exemplo n.º 8
0
        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++;
            }
        }
Exemplo n.º 9
0
        public void NotFastEnough()
        {
            const double pi = System.Math.PI;
            const double tolerance = 0.01;

            var hp = new HardPoint(_ship, HardPointPosition.Left) { Speed = 0.25 };

            var pointDown = hp.Origin.RotateZ(pi/4);

            hp.Inclination.ShouldBe(0, tolerance);

            hp.AimAt(pointDown).ShouldBe(false);
            hp.Inclination.ShouldBe(45.0/2, tolerance);

            hp.AimAt(pointDown).ShouldBe(true);
            hp.Inclination.ShouldBe(45.0, tolerance);

            var nowPointUp = hp.Origin.RotateZ(-pi/4);

            hp.AimAt(nowPointUp).ShouldBe(false);
            hp.Inclination.ShouldBe(45.0/2, tolerance);

            hp.AimAt(nowPointUp);//.ShouldBe(false);
            hp.Inclination.ShouldBe(0, tolerance);
        }
Exemplo n.º 10
0
 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");
 }
Exemplo n.º 11
0
        public void OutOfRange()
        {
            const double pi = System.Math.PI;
            const double tolerance = 0.01;

            var hp = new HardPoint(_ship, HardPointPosition.Left) { Speed = 0.25 };

            var pointDown = hp.Origin.RotateZ(pi);

            hp.Inclination.ShouldBe(0, tolerance);

            hp.AimAt(pointDown).ShouldBe(false);
            hp.Inclination.ShouldBe(45.0/2, tolerance);

            hp.AimAt(pointDown).ShouldBe(true);
            hp.Inclination.ShouldBe(45.0, tolerance);

            // stop moving down -- limit of range
            hp.AimAt(pointDown).ShouldBe(false);
            hp.Inclination.ShouldBe(45.0, tolerance);
        }