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); }
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)); }