Пример #1
0
 public virtual void renewtoStart()
 {
     this.cmbt_loc    = new PointXd(0, 0, 0);
     this.cmbt_vel    = new PointXd(0, 0, 0);
     this.cmbt_head   = new Compass(0);
     this.cmbt_att    = new Compass(0);
     this.cmbt_thrust = new PointXd(0, 0, 0);
     this.cmbt_accel  = new PointXd(0, 0, 0);
     strategy.renewtostart();
     waypointTarget = null;
     weaponTarget   = new List <CombatObject>();
 }
Пример #2
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));
        }
Пример #3
0
        public virtual void helm()
        {
            CombatWaypoint wpt             = this.waypointTarget;
            Compass        angletoWaypoint = new Compass(this.cmbt_loc, this.waypointTarget.cmbt_loc); //relitive to me.

            Tuple <Compass, bool?> nav = Nav(angletoWaypoint);
            Compass angletoturn        = nav.Item1;
            bool?   thrustToWaypoint   = nav.Item2;

            //PointXd vectortowaypoint = this.cmbt_loc - this.waypointTarget.cmbt_loc;

            Fix16 acceleration = maxfowardThrust * cmbt_mass;
            Fix16 startV       = NMath.distance(cmbt_vel, wpt.cmbt_vel);
            Fix16 distance     = NMath.distance(cmbt_loc, wpt.cmbt_loc); // XXX - why is distance between (0,0,0) and (0,1000,0) equal to 181 in Combat_Helm0 test?!

            Fix16[] ttt = NMath.quadratic(acceleration, startV, distance);

            turnship(angletoturn, angletoWaypoint);

            thrustship(angletoturn, true);
        }
Пример #4
0
 public override void calc(CombatObject comObj)
 {
     base.calc(comObj);
     output = new CombatWaypoint((PointXd)inputs[0], (PointXd)inputs[1]);
 }
Пример #5
0
 public void calcWaypoint()
 {
     this.waypointTarget = this.strategy.calcWaypiont(this);
 }
Пример #6
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));
        }
Пример #7
0
        public CombatWaypoint calcWaypiont(CombatObject comObj)
        {
            CombatWaypoint wp = (CombatWaypoint)waypointObj.getNewOutput(comObj);

            return(wp);
        }