public static string PrintOut() { string output = "TARGETS:"; Vector3D position = Ship_Controller.GetPosition(); List <Entry> content = GetContentAsSortedList(); int i = 0; foreach (Entry entry in content) { output += "\n" + ((i + 1 < 10) ? " " + (i + 1) : "" + (i + 1)) + ") " + RelationToAbbreviation(entry.Relation) + " " + TypeToAbbreviation(entry.Type) + " " + new Bearing(position, Ship_Controller.WorldMatrix, entry.Location).ToString() + " " + Convert(entry.Location); i++; } return(output); }
double CalculateThreat(Entry entry) { if (!entry.Relation.Equals(Relation.FRIEND) && (Ship_Controller != null || Program.MyInstance.SetShipController())) { Vector3D EnPos = entry.Position, EnVel = entry.Velocity, MyPos = Ship_Controller.GetPosition(), MyVel = Ship_Controller.GetShipVelocities().LinearVelocity, DangerousHeading; if (!EnVel.IsValid()) { throw new Exception("Enemy's velocity vector is invalid."); } double EnSpd = EnVel.Length(), MySpd = MyVel.Length(), Distance, baseThreat = entry.Relation.Equals(Relation.HOSTILE) ? 1d : (AEGISTargetsNeutrals? 1d:0d); //AEGISTargetsNeutrals DangerousHeading = Vector3D.Subtract(EnPos, MyPos); Distance = DangerousHeading.Length(); if (Distance == 0) { Distance = 0.1d; } // since we've written down lengths of the velocity vectors, we can safely normalize them now. EnVel = Vector3D.Normalize(EnVel); MyVel = Vector3D.Normalize(MyVel); if (EnSpd <= 10) { return(baseThreat * ((Distance >= 1000)? 0d:(1000 / Distance))); } // the object either does not move or moves at low speeds, so it is not an active danger to the ship (probably) else { Vector3D AbsDev1, // Absolute Deviation, a Vector between Enemy-Us and Enemy-Estimated position after SecondsToImpact seconds AbsDev2, EnProjPos, MyProjPos; double SecondsToImpact1, SecondsToImpact2; // Variant One - Detecting blindly following objects (also true if the ship is stationary) SecondsToImpact1 = Distance / EnSpd; EnProjPos = Vector3D.Add(EnPos, Vector3D.Multiply(EnVel, EnSpd * SecondsToImpact1)); AbsDev1 = Vector3D.Subtract(EnProjPos, MyPos); // 500m or less should probably trigger a response // Variant Two - Detecting objects that either predict or will find themselves on the path of the ship MyProjPos = ApplyTarSpd(EnPos, Vector3D.Multiply(EnVel, EnSpd), MyPos, Vector3D.Multiply(MyVel, MySpd)); SecondsToImpact2 = MySpd > 0 ? (Vector3D.Subtract(MyPos, MyProjPos).Length() / MySpd) : 60; EnProjPos = Vector3D.Add(EnPos, Vector3D.Multiply(EnVel, EnSpd * SecondsToImpact2)); AbsDev2 = Vector3D.Subtract(EnProjPos, MyProjPos); double threat, adjAbsDev = MySpd > 0 ? AbsDev2.Length() : AbsDev1.Length(), worstCaseSTI = MySpd > 0 ? (SecondsToImpact1 < SecondsToImpact2 ? SecondsToImpact1 : SecondsToImpact2) : SecondsToImpact1; if ((AbsDev1.Length() <= 500 || AbsDev2.Length() <= 500)) { if (Distance >= 1000) { baseThreat = 100d; AddToAMT(entry); } PriorityMessage("HOSTILE\nOBJECT ON\nINTERCEPT\nCOURSE\n" + new Bearing(Ship_Controller.Position, Ship_Controller.WorldMatrix, EnPos).ToString()); } else { baseThreat *= entry.Relation.Equals(Relation.HOSTILE) ? 10 : 1; } threat = 10 * ((baseThreat * EnSpd * EnSpd) / (adjAbsDev * worstCaseSTI)); return(threat > 1d ? threat : 1d); } } else { return(entry.Relation.Equals(Relation.HOSTILE) ? 1d : 0d); } }
static double GetDistance(Vector3D location) { return(Vector3D.Subtract(Ship_Controller.GetPosition(), location).Length()); }