Esempio n. 1
0
        public void Combat_physicsTest2()
        {
            Combat_setupbattle();

            battle.Start();

            Compass startHeading   = new Compass(0, false);
            Compass angletoTurn    = new Compass(0, false);
            PointXd expectedResult = new PointXd(0, 0.5, 0);

            // (1/2 * a * t^2) = (0.5 * a * t * t) = 0.5 * 1 * 1 * 1)

            testComObj.cmbt_loc    = new PointXd(0, 0, 0);
            testComObj.cmbt_head   = new Compass(startHeading.Degrees, false);
            testComObj.cmbt_thrust = new PointXd(0, 100, 0);

            //thrust is 100N mass is 100N = (f / m = a) 100/100 = 1m/s/s

            for (int i = 0; i < Battle_Space.TicksPerSecond; i++)
            {
                battle.SimNewtonianPhysics(testComObj); //run * TicksPerSecond to get 1 simsecond.
            }
            battle.End(battle.CurrentTick);
            AssertPointWithinTolerance(expectedResult, testComObj.cmbt_loc, 1);
        }
Esempio n. 2
0
        public static Fix16 seekerTimeToTarget(CombatObject attacker, CombatObject target, SeekingWeaponInfo skrinfo)
        {
            //Fix16 distance_toTarget = Trig.distance(attacker.cmbt_loc, target.cmbt_loc);
            PointXd px = new PointXd(attacker.cmbt_loc - target.cmbt_loc);
            Fix16   distance_toTarget = px.Length;
            //SeekingWeaponInfo seekerinfo = (SeekingWeaponInfo)weapon.Template.ComponentTemplate.WeaponInfo;
            int   hitpoints    = skrinfo.SeekerDurability;
            Fix16 mass         = hitpoints * 0.1;
            int   wpnskrspd    = skrinfo.SeekerSpeed;
            Fix16 Thrust       = calcFowardThrust(skrinfo);
            Fix16 acceleration = Thrust / mass * -1; //*-1 because we should be accelerating towards the target, not away.
            Fix16 startV       = seekerClosingSpeed_base(attacker, target);
            //Fix16 endV = ???
            Fix16 baseTimetoTarget = distance_toTarget / startV;

            //Fix16 deltaV = baseTimetoTarget
            //Fix16[] ttt = NMath.quadratic(acceleration, startV, distance_toTarget);
            Fix64[] ttt2 = NMath.quadratic64(acceleration, startV, distance_toTarget);

            Fix16 TimetoTarget;

            if (ttt2[2] == 1)
            {
                TimetoTarget = Fix16.Max((Fix16)ttt2[0], (Fix16)ttt2[1]);
            }
            else
            {
                TimetoTarget = (Fix16)ttt2[0];
            }
#if DEBUG
            Console.WriteLine("SeekerTimeToTarget = " + TimetoTarget);
#endif
            return(TimetoTarget);
        }
Esempio n. 3
0
        public void Combat_Nav10()
        {
            setupEnvironment0();
            Console.WriteLine("Nav test 0");

            battle.Start();

            Compass        startHeading    = new Compass(0, false);
            Compass        angletoWaypoint = new Compass(0, false);
            PointXd        waypntloc       = new PointXd(0, 1000, 0);
            PointXd        waypndVel       = new PointXd(0, 1000, 0);
            CombatWaypoint waypoint        = new CombatWaypoint(waypntloc, waypndVel);

            bool    expectedToWaypoint        = true;
            Compass expectedHeading           = new Compass(0);
            Tuple <Compass, bool> expectednav = new Tuple <Compass, bool>(expectedHeading, expectedToWaypoint);
            CombatVehicle         testComObj  = battle.CombatVehicles.ToArray()[0];

            testComObj.cmbt_loc       = new PointXd(0, 0, 0);
            testComObj.cmbt_vel       = new PointXd(0, 0, 0);
            testComObj.cmbt_head      = new Compass(startHeading.Degrees, false);
            testComObj.waypointTarget = waypoint;

            Tuple <Compass, bool?> nav = testComObj.testNav(angletoWaypoint);

            battle.End(battle.CurrentTick);
            Assert.AreEqual(expectednav.Item1.Degrees, nav.Item1.Degrees);
            Assert.AreEqual(expectednav.Item2, nav.Item2);
        }
Esempio n. 4
0
        public void Combat_Nav12()
        {
            setupEnvironment0();

            battle.Start();

            Compass        startHeading    = new Compass(0, false);
            Compass        angletoWaypoint = new Compass(0, false);
            PointXd        waypntloc       = new PointXd(0, 10, 0);
            PointXd        waypndVel       = new PointXd(0, 0, 0);
            CombatWaypoint waypoint        = new CombatWaypoint(waypntloc, waypndVel);

            bool    expectedThrustToWaypoint  = false;
            Compass expectedHeading           = new Compass(180, false);
            Tuple <Compass, bool> expectednav = new Tuple <Compass, bool>(expectedHeading, expectedThrustToWaypoint);
            CombatVehicle         testComObj  = battle.CombatVehicles.ToArray()[0];

            testComObj.cmbt_loc        = new PointXd(0, 0, 0);
            testComObj.cmbt_vel        = new PointXd(0, 5, 0);
            testComObj.maxfowardThrust = 150;
            testComObj.maxStrafeThrust = 37.5;
            testComObj.maxRotate       = new Compass(45, false);
            testComObj.cmbt_head       = new Compass(startHeading.Degrees, false);
            testComObj.waypointTarget  = waypoint;

            Tuple <Compass, bool?> nav = testComObj.testNav(angletoWaypoint);

            battle.End(battle.CurrentTick);
            Assert.AreEqual(expectednav.Item1.Degrees, nav.Item1.Degrees);
            Assert.AreEqual(expectednav.Item2, nav.Item2);
        }
Esempio n. 5
0
        public void Combat_physicsTest0()
        {
            Combat_setupbattle();

            Console.WriteLine("Physics test 0: thrust is 100N mass is 100N = (f / m = a) 100/100 = 1m/s/s ");

            battle.Start();


            Compass startHeading   = new Compass(0, false);
            Compass angletoTurn    = new Compass(0, false);
            PointXd expectedResult = new PointXd(0, 1, 0);


            testComObj.cmbt_loc    = new PointXd(0, 0, 0);
            testComObj.cmbt_head   = new Compass(startHeading.Degrees, false);
            testComObj.cmbt_thrust = new PointXd(0, 100, 0);

            //thrust is 100N mass is 100N = (f / m = a) 100/100 = 1m/s


            //battle.ProcessTick(ref tick, ref cmdFreqCounter);

            battle.SimNewtonianPhysics(testComObj);
            battle.End(battle.CurrentTick);
            Assert.AreEqual(expectedResult, testComObj.cmbt_accel);
        }
Esempio n. 6
0
        public void Combat_Helm0()
        {
            Combat_setupbattle();

            Console.WriteLine("Helm test 0");

            battle.Start();

            Compass startHeading = new Compass(0, false);

            PointXd        waypntloc = new PointXd(0, 1000, 0);
            PointXd        waypndVel = new PointXd(0, 1000, 0);
            CombatWaypoint waypoint  = new CombatWaypoint(waypntloc, waypndVel);

            PointXd expectedThrustResult = new PointXd(0, 100, 0);
            Compass expectedHeading      = new Compass(startHeading.Degrees);// + (spinrate.Degrees / Battle_Space.TicksPerSecond), false);

            // Ship heading 0 Angle to turn 0
            // ship should thrust 100%
            testComObj.cmbt_loc       = new PointXd(0, 0, 0);
            testComObj.cmbt_vel       = new PointXd(0, 0, 0);
            testComObj.cmbt_head      = new Compass(startHeading.Degrees, false);
            testComObj.waypointTarget = waypoint;
            //battle.ProcessTick(ref tick, ref cmdFreqCounter);

            testComObj.helm();
            battle.End(battle.CurrentTick);
            AssertPointWithinTolerance(expectedThrustResult, testComObj.cmbt_thrust, 1);
            AssertAngleWithinTolerance(expectedHeading, testComObj.cmbt_head, 0.01);
        }
Esempio n. 7
0
 /// <summary>
 /// for creating bullets and other non AI or acelerating things. used by the renderer to move and display.
 /// </summary>
 /// <param name="position"> ship position this is fiired from </param>
 /// <param name="vector">direction this is going</param>
 public CombatNode(PointXd position, PointXd vector, long ID, string IDPrefix)
 {
     this.cmbt_loc  = position;
     this.cmbt_vel  = vector;
     this.cmbt_head = new Compass((Fix16)0);
     this.ID        = ID;
     this.IDPrefix  = IDPrefix;
 }
Esempio n. 8
0
        public void distance()
        {
            PointXd p1             = new PointXd(0, 0, 0);
            PointXd p2             = new PointXd(0, 10, 0);
            Fix16   expectedResult = 10;

            Assert.AreEqual(expectedResult, NMath.distance(p1, p2));
        }
Esempio n. 9
0
 protected CombatControlledObject(ICombatant start, ICombatant working, PointXd position, PointXd vector, int battleseed, string IDprefix)
     : base(working, position, vector, start.ID, IDprefix)
 {
     //StartCombatant = working; wtf?
     StartCombatant   = start;
     WorkingCombatant = working;
     newDice(battleseed);
     RefreshWeapons();
 }
Esempio n. 10
0
 public CombatObject(ITargetable workingObject, PointXd position, PointXd vector, long ID, string IDprefix)
     : base(position, vector, ID, IDprefix)
 {
     WorkingObject       = workingObject;
     this.waypointTarget = new CombatWaypoint();
     weaponTarget        = new List <CombatObject>(1); //eventualy this should be something with the multiplex tracking component.
     this.cmbt_thrust    = new PointXd(0, 0, 0);
     this.cmbt_accel     = new PointXd(0, 0, 0);
     this.maxRotate      = new Compass(0);
 }
Esempio n. 11
0
        public override void calc(CombatObject comObj)
        {
            base.calc(comObj);
            CombatObject formateObj = (CombatObject)inputs[0];
            Fix16        range      = (Fix16)inputs[1];
            Compass      angle      = (Compass)inputs[2];
            //angle.Degrees += formateObj.cmbt_head.Degrees;
            PointXd formatePoint = Trig.sides_ab(range, angle.Radians);

            formatePoint += formateObj.cmbt_loc;
            output        = formatePoint;
        }
Esempio n. 12
0
        public void closingRate()
        {
            //easy test
            PointXd p1 = new PointXd(-10, 0, 0);
            PointXd v1 = new PointXd(5, 0, 0);

            PointXd p2 = new PointXd(10, 0, 0);
            PointXd v2 = new PointXd(0, 0, 0);

            Fix16 expectedResult = 5;

            Assert.AreEqual(expectedResult, NMath.closingRate(p1, v1, p2, v2));

            //edge case, parrellel.
            p1 = new PointXd(-0, -5, 0);
            v1 = new PointXd(0, 0, 0);

            p2 = new PointXd(0, 0, 0);
            v2 = new PointXd(1, -1, 0);

            expectedResult = 1;

            Assert.AreEqual(expectedResult, NMath.closingRate(p1, v1, p2, v2));

            //edge case, parrellel.
            p1 = new PointXd(-10, 0, 0);
            v1 = new PointXd(10, 0, 0);

            p2 = new PointXd(10, 0, 0);
            v2 = new PointXd(10, 0, 0);

            expectedResult = 0;

            Assert.AreEqual(expectedResult, NMath.closingRate(p1, v1, p2, v2));

            //moving away from each other.
            p1 = new PointXd(-10, 0, 0);
            v1 = new PointXd(-10, 0, 0);

            p2 = new PointXd(10, 0, 0);
            v2 = new PointXd(0, 0, 0);

            expectedResult = -10;

            Assert.AreEqual(expectedResult, NMath.closingRate(p1, v1, p2, v2));
        }
Esempio n. 13
0
        public void Combat_Missle()
        {
            setupEnvironment1();

            battle.Start();

            Compass        startHeading    = new Compass(0, false);
            Compass        angletoWaypoint = new Compass(0, false);
            PointXd        waypntloc       = new PointXd(0, 0, 0);
            PointXd        waypndVel       = new PointXd(0, 0, 0);
            CombatWaypoint waypoint        = new CombatWaypoint(waypntloc, waypndVel);

            bool    expectedThrustToWaypoint  = true;
            Compass expectedHeading           = new Compass(0, false);
            Tuple <Compass, bool> expectednav = new Tuple <Compass, bool>(expectedHeading, expectedThrustToWaypoint);


            CombatVehicle attacker = battle.CombatVehicles.ToArray()[0];

            attacker.cmbt_loc       = new PointXd(0, -100, 0);
            attacker.cmbt_vel       = new PointXd(0, 0, 0);
            attacker.cmbt_head      = new Compass(startHeading.Degrees, false);
            attacker.waypointTarget = waypoint;
            CombatWeapon wpn = attacker.Weapons.ToArray()[0];

            CombatVehicle target = battle.CombatVehicles.ToArray()[1];

            target.cmbt_loc       = new PointXd(0, 100, 0);
            target.cmbt_vel       = new PointXd(0, 0, 0);
            target.cmbt_head      = new Compass(180, false);
            target.waypointTarget = waypoint;

            attacker.weaponTarget[0] = target;

            CombatSeeker testSeeker = new CombatSeeker(attacker, wpn, -1);

            battle.CombatNodes.Add(testSeeker);

            Tuple <Compass, bool?> nav = testSeeker.testNav(angletoWaypoint);

            battle.End(battle.CurrentTick);
            Assert.AreEqual(expectednav.Item1.Degrees, nav.Item1.Degrees);
            Assert.AreEqual(expectednav.Item2, nav.Item2);
        }
Esempio n. 14
0
        protected override Tuple <Compass, bool?> Nav(Compass angletoWaypoint)
        {
            Compass angletoturn   = new Compass();
            bool?   thrustTowards = true;

            CombatWaypoint wpt = this.waypointTarget;

            angletoturn = new Compass(angletoWaypoint.Degrees - this.cmbt_head.Degrees, false);
            PointXd vectortowaypoint = this.cmbt_loc - this.waypointTarget.cmbt_loc;

            //this stuff doesn't actualy do anything yet:
            Fix16 acceleration = maxfowardThrust / cmbt_mass;
            Fix16 startSpeed   = NMath.distance(cmbt_vel, wpt.cmbt_vel);
            Fix16 distance     = vectortowaypoint.Length;

            Fix16 closingSpeed = NMath.closingRate(this.cmbt_loc, this.cmbt_vel, this.waypointTarget.cmbt_loc, this.waypointTarget.cmbt_vel);
            Fix16 timetowpt    = distance / closingSpeed;


            Fix64[] ttt2 = NMath.quadratic64(acceleration, startSpeed, distance);

            Fix16 TimetoTarget;

            if (ttt2[2] == 1)
            {
                TimetoTarget = Fix16.Max((Fix16)ttt2[0], (Fix16)ttt2[1]);
            }
            else
            {
                TimetoTarget = (Fix16)ttt2[0];
            }
            Fix16 endV = startSpeed + acceleration * TimetoTarget;

            //above doesn't actualy do anything yet.
#if DEBUG
            Console.WriteLine("seeker ttt: " + TimetoTarget);
            Console.WriteLine("timetowpt: " + timetowpt);
            Console.WriteLine("seeker distance: " + distance);
            Console.WriteLine("seeker startV: " + startSpeed);
            Console.WriteLine("seeker endV: " + endV);
#endif

            return(new Tuple <Compass, bool?>(angletoturn, thrustTowards));
        }
Esempio n. 15
0
        protected void thrustship(Compass angletoturn, bool?thrustToWaypoint)
        {
            this.cmbt_thrust.ZEROIZE();
            strafeship(thrustToWaypoint);
            //main foward thrust - still needs some work, ie it doesnt know when to turn it off when close to a waypoint.
            Fix16 thrustby = (Fix16)0;

            if (thrustToWaypoint != null)
            {
                if (angletoturn.Degrees >= (Fix16)0 && angletoturn.Degrees < (Fix16)90)
                {
                    thrustby = (Fix16)this.maxfowardThrust * GetThrustEfficiency(angletoturn);
                }
                else if (angletoturn.Degrees > (Fix16)270 && angletoturn.Degrees < (Fix16)360)
                {
                    Compass angle = new Compass((Fix16)360 - angletoturn.Degrees);
                    angle.normalize();
                    thrustby = (Fix16)this.maxfowardThrust * GetThrustEfficiency(angletoturn);
                }

                //PointXd fowardthrust = new PointXd(comObj.cmbt_face + thrustby);
                PointXd fowardthrust = new PointXd(Trig.sides_ab(thrustby, this.cmbt_head.Radians));
                this.cmbt_thrust += fowardthrust;
            }
            else
            {
                //match velocity with waypoint
                PointXd wayptvel = this.waypointTarget.cmbt_vel;
                PointXd ourvel   = this.cmbt_vel;

                thrustby = (Fix16)this.maxfowardThrust * GetThrustEfficiency(angletoturn);

                PointXd fowardthrust = new PointXd(Trig.intermediatePoint(ourvel, wayptvel, thrustby));
                this.cmbt_thrust += fowardthrust;
            }
#if DEBUG
            Console.WriteLine("Thrust By " + thrustby);
#endif
        }
Esempio n. 16
0
        public void Combat_ThrustShip1()
        {
            Combat_setupbattle();

            Console.WriteLine("Thrust test 1");

            battle.Start();

            Compass startHeading   = new Compass(0, false);
            Compass angletoTurn    = new Compass(180, false);
            PointXd expectedResult = new PointXd(0, 0, 0);
            bool    toWaypoint     = false;

            // Ship heading 0 Angle to turn 180
            // ship should thrust 0%
            testComObj.cmbt_loc  = new PointXd(0, 0, 0);
            testComObj.cmbt_head = new Compass(startHeading.Degrees, false);
            //battle.ProcessTick(ref tick, ref cmdFreqCounter);

            testComObj.testThrustShip(angletoTurn, toWaypoint);
            battle.End(battle.CurrentTick);
            Assert.AreEqual(expectedResult, testComObj.cmbt_thrust);
        }
Esempio n. 17
0
        public void Combat_ThrustShip2()
        {
            Combat_setupbattle();

            Console.WriteLine("Thrust test 2");

            battle.Start();


            Compass startHeading   = new Compass(0, false);
            Compass angletoTurn    = new Compass(45, false);
            PointXd expectedResult = new PointXd(0, 70.70159912109375, 0);
            bool    toWaypoint     = true;

            // Ship heading 0 Angle to turn 45
            // ship should thrust 70.70159912109375%
            testComObj.cmbt_loc  = new PointXd(0, 0, 0);
            testComObj.cmbt_head = new Compass(startHeading.Degrees, false);

            testComObj.testThrustShip(angletoTurn, toWaypoint);
            battle.End(battle.CurrentTick);
            Assert.AreEqual(expectedResult, testComObj.cmbt_thrust);
        }
Esempio n. 18
0
        public void Combat_ReplayTest02()
        {
            setupEnvironment1();

            battle.Start();
            battle.Resolve();
            CombatObject battlecomobj = battle.CombatObjects.ToArray()[0];

            PointXd loc1        = new PointXd(battlecomobj.cmbt_loc);
            long    diceit1     = battlecomobj.getDice().Iteration;
            int     numenemies1 = battlecomobj.empire.ownships.Count();

            battle.SetUpPieces(); //this should be replay setup now.

            PointXd loc2        = new PointXd(battlecomobj.cmbt_loc);
            long    diceit2     = battlecomobj.getDice().Iteration;
            int     numenemies2 = battlecomobj.empire.ownships.Count();

            Assert.AreEqual(true, battle.IsReplay);
            Assert.AreNotEqual(loc1, loc2);
            Assert.AreNotEqual(diceit1, diceit2);
            Assert.AreNotEqual(numenemies1, numenemies2);
        }
Esempio n. 19
0
        public CombatSeeker(CombatObject attacker, CombatWeapon launcher, int ID)
            : base(null, new PointXd(attacker.cmbt_loc), new PointXd(attacker.cmbt_vel), ID, "SKR")
        {
            WorkingObject = this;
            SeekingWeaponInfo skrinfo = (SeekingWeaponInfo)launcher.weapon.Template.ComponentTemplate.WeaponInfo;

            Hitpoints = MaxHitpoints = skrinfo.SeekerDurability;
            cmbt_mass = (Fix16)Hitpoints * 0.1;//(Fix16)s.MaxHitpoints; // sure why not?


            maxfowardThrust = calcFowardThrust(skrinfo);
            maxStrafeThrust = calcStrafeThrust(skrinfo);
            maxRotate       = calcRotate(skrinfo);


            cmbt_thrust = new PointXd(0, 0, 0);
            cmbt_accel  = new PointXd(0, 0, 0);

            newDice(ID);
#if DEBUG
            Console.WriteLine("MaxAccel = " + maxfowardThrust / cmbt_mass);
#endif
            this.launcher = launcher;
        }
Esempio n. 20
0
 /// <summary>
 /// This event is for the object under fire.
 /// </summary>
 /// <param name="tick"></param>
 /// <param name="obj"></param>
 /// <param name="endpoint"></param>
 /// <param name="hit">whether this ship is hit or if the shot is a miss</param>
 public CombatTakeFireEvent(int tick, CombatObject obj, PointXd endpoint, bool hit)
     : base(tick, obj, endpoint)
 {
     this.IsHit = hit;
 }
Esempio n. 21
0
 public CombatDestructionEvent(int tick, CombatObject obj, PointXd point)
     : base(tick, obj, point)
 {
 }
Esempio n. 22
0
 public CombatLocationEvent(int tick, CombatObject obj, PointXd cmbt_loc)
     : base(tick, obj)
 {
     this.Location = cmbt_loc;
 }
Esempio n. 23
0
 /// <summary>
 /// this event is for the object that is firing apon something else
 /// </summary>
 /// <param name="tick"></param>
 /// <param name="obj"></param>
 /// <param name="loc"></param>
 /// <param name="weapon"></param>
 /// <param name="targetevent">the event for the target ship</param>
 public CombatFireOnTargetEvent(int tick, CombatObject obj, PointXd loc, CombatWeapon weapon, CombatTakeFireEvent targetevent)
     : base(tick, obj, loc)
 {
     this.Weapon        = weapon;
     this.TakeFireEvent = targetevent;
 }
Esempio n. 24
0
 public MockCombatObject(ITargetable workingObject, PointXd position, PointXd vector, long ID, string IDprefix)
     : base(workingObject, position, vector, ID, IDprefix)
 {
 }
Esempio n. 25
0
        /// <summary>
        /// Asserts that two points are "close enough" within a certain tolerance.
        /// </summary>
        /// <param name="expected"></param>
        /// <param name="actual"></param>
        private void AssertPointWithinTolerance(PointXd expected, PointXd actual, Fix16 tolerance)
        {
            var dist = (actual - expected).Length;

            Assert.IsTrue(dist <= tolerance, "distance between points must not be greater than " + tolerance + "; was " + dist);
        }
Esempio n. 26
0
        protected override Tuple <Compass, bool?> Nav(Compass angletoWaypoint)
        {
#if DEBUG
            Console.WriteLine("NAV FUNCTION FOR " + this.WorkingObject);
#endif

            Compass angletoturn      = new Compass();
            bool?   thrustToWaypoint = true;


            this.debuginfo += "HelmInfo:" + "\r\n";
            var    ship = this.WorkingCombatant;
            string name = ship.Name;
            //rotate ship
            Fix16 timetoturn = (Fix16)0;
            //Compass angletoturn = new Compass(Trig.angleto(comObj.cmbt_face, comObj.waypointTarget.cmbt_loc));
            CombatWaypoint wpt = this.waypointTarget;

#if DEBUG
            Console.WriteLine("Waypoint is " + wpt);
#endif

            angletoturn.Degrees = angletoWaypoint.Degrees - this.cmbt_head.Degrees;
            var     bearingToTurn    = angletoturn.Degrees <= 180 ? angletoturn.Degrees : angletoturn.Degrees - 360;
            PointXd vectortowaypoint = this.cmbt_loc - this.waypointTarget.cmbt_loc;

#if DEBUG
            Console.WriteLine("Current location is " + cmbt_loc);
            Console.WriteLine("Waypoint location is " + waypointTarget.cmbt_loc);
            Console.WriteLine("So the vector to waypoint is " + vectortowaypoint);
            Console.WriteLine("And the waypoint is " + vectortowaypoint.Length + " away.");

            Console.WriteLine("Current velocity is " + cmbt_vel);
            Console.WriteLine("Current speed is " + cmbt_vel.Length);
            Console.WriteLine("Waypoint velocity is " + waypointTarget.cmbt_vel);
            Console.WriteLine("So we need to change our velocity by " + (waypointTarget.cmbt_vel - cmbt_vel));
#endif

            //if (comObj.lastVectortoWaypoint != null)
            //    angletoturn.Radians = Trig.angleA(vectortowaypoint - comObj.lastVectortoWaypoint);

            timetoturn = (angletoturn.Degrees / this.maxRotate.Degrees); // seconds
            Fix16 oneEightytime = (180 / this.maxRotate.Degrees);        // seconds

#if DEBUG
            Console.WriteLine("Current heading is " + cmbt_head);
            Console.WriteLine("Angle to waypoint is " + angletoWaypoint);
            Console.WriteLine("So we need to turn by " + bearingToTurn + " degrees");
            Console.WriteLine("We can turn at " + this.maxRotate + " per second.");
            Console.WriteLine("So we can rotate to face the target in " + timetoturn + " seconds.");
            Console.WriteLine("And we can do a 180 in " + oneEightytime + " seconds.");
#endif

            //PointXd offsetVector = comObj.waypointTarget.cmbt_vel - comObj.cmbt_vel; // O = a - b
            //PointXd combinedVelocity = comObj.cmbt_vel - comObj.waypointTarget.cmbt_vel;
            //PointXd distancePnt = comObj.waypointTarget.cmbt_loc - comObj.cmbt_loc;
            //double closingSpeed = Trig.dotProduct(combinedVelocity, distancePnt);
            Fix16 closingSpeed = NMath.closingRate(this.cmbt_loc, this.cmbt_vel, this.waypointTarget.cmbt_loc, this.waypointTarget.cmbt_vel);

#if DEBUG
            Console.WriteLine("We are approaching/departing our target at a relative speed of " + closingSpeed);
#endif

            Fix16 myspeed = this.cmbt_vel.Length;                                 //seconds

            Fix16 maxFowardAcceleration = this.maxfowardThrust / this.cmbt_mass;  //seconds

            Fix16 timetokill_ClosingSpeed = closingSpeed / maxFowardAcceleration; //t = v / a in seconds.


            Fix16 maxStrafeAcceleration = this.maxStrafeThrust / this.cmbt_mass;

            Fix16 timetokill_ClosingSpeed_strafe = closingSpeed / maxStrafeAcceleration;              //in seconds.
            Fix16 timetokill_MySpeed             = myspeed / (this.maxfowardThrust / this.cmbt_mass); //in seconds.

#if DEBUG
            Console.WriteLine("Forward/strafe accel is " + maxFowardAcceleration + "/" + maxStrafeAcceleration);
            Console.WriteLine("Can kill closing speed in this many seconds using forward/strafe accel: " + timetokill_ClosingSpeed + "/" + timetokill_ClosingSpeed_strafe);
            Console.WriteLine("Can come to a complete stop in " + timetokill_MySpeed + " seconds.");
#endif

            Fix16 distance = vectortowaypoint.Length;


            // TODO - should we divide by ticks per second here, so we can close in one tick?
            Fix16 nominaldistance = maxStrafeAcceleration * timetokill_ClosingSpeed_strafe; //this.maxStrafeThrust; (I think this should be acceleration, not thrust.

            //Fix16 nominaltime = strafetimetokill_ClosingSpeed
            Fix16 timetowpt = distance / closingSpeed;
#if DEBUG
            Console.WriteLine("Time to waypoint (if we were in a 1D universe): " + timetowpt);
#endif

            string helmdo = "";

            if (closingSpeed > (Fix16)0) //getting closer?
            {
#if DEBUG
                Console.WriteLine("***Approaching target!***");
#endif

                /*if (timetowpt <= timetokill_ClosingSpeed_strafe)  // close to the waypoint (within strafe thrust range)
                 * {
                 *  thrustToWaypoint = null; // should attempt to match speed using strafe thrust
                 * }*/
                if (timetowpt <= timetokill_ClosingSpeed + oneEightytime) // if/when we're going to overshoot the waypoint.
                {
                    if (timetowpt < timetokill_ClosingSpeed_strafe)       //if time to waypoint is less than time to kill speed with strafe thrusters
                    {
#if DEBUG
                        Console.WriteLine("***Going too fast! Slow down!***");
#endif
                        thrustToWaypoint = false; // thrust AWAY from the waypoint! slow down!
                    }
                    else
                    {
#if DEBUG
                        Console.WriteLine("***Going just the right speed...***");
#endif
                        helmdo           = "null" + "\r\n";
                        thrustToWaypoint = null; // driiift! iiiin! spaaaace! should use only strafe thrust to match speed
                    }
                }
                else
                {
#if DEBUG
                    Console.WriteLine("***We can go faster! Speed it up!***");
#endif
                    // accelerate toward the target, since we still have time to slow down later
                    thrustToWaypoint = true;
                }
            }
            else
            {
#if DEBUG
                Console.WriteLine("***Not approaching target! Need to get closer!***");
#endif
                thrustToWaypoint = true;// getting farther away or maintaining distance, just thrust toward the target
            }

            if (thrustToWaypoint == false)
            {
                helmdo = "Initiating Turnaround" + "\r\n";                                             //turn around and thrust the other way
                angletoturn.Degrees = (angletoWaypoint.Degrees - (Fix16)180) - this.cmbt_head.Degrees; //turn around and thrust the other way
                angletoturn.normalize();
            }
            else if (thrustToWaypoint == null)
            {
                // TODO - shouldn't this be using delta V between target and ship instead of target V?
                // and shouldn't the angle be relative?
                angletoturn.Radians = Trig.angleA(this.waypointTarget.cmbt_vel);
            }

            this.debuginfo += "timetowpt:\t" + timetowpt.ToString() + "\r\n";
            this.debuginfo += "strafetime:\t" + timetokill_ClosingSpeed_strafe.ToString() + "\r\n";
            this.debuginfo += "speedkilltime:\t" + timetokill_ClosingSpeed.ToString() + "\r\n";
            this.debuginfo += "180time:\t" + oneEightytime.ToString() + "\r\n";
            this.debuginfo += "ThrustTo:\t" + thrustToWaypoint.ToString() + "\r\n";
            this.debuginfo += helmdo + "\r\n";

            return(new Tuple <Compass, bool?>(angletoturn, thrustToWaypoint));
        }
Esempio n. 27
0
 public void setLocation(PointXd location)
 {
     base.Location = location;
 }
Esempio n. 28
0
 public CombatWaypoint(PointXd cmbt_loc)
 {
     this.cmbt_loc = cmbt_loc;
     this.cmbt_vel = new PointXd(0, 0, 0);
 }
Esempio n. 29
0
 public CombatWaypoint(PointXd cmbt_loc, PointXd cmbt_vel)
 {
     this.cmbt_loc = cmbt_loc;
     this.cmbt_vel = cmbt_vel;
 }