public void getSpaceshipData() { Ship_Controller sc = GameObject.Find("GameController").GetComponent <GameController>().PlayerShip.GetComponent <Ship_Controller>(); hullID = sc.hullID; armorID = sc.armorID; engineID = sc.engineID; weapon1ID = sc.weapon1ID; weapon2ID = sc.weapon2ID; weapon3ID = sc.weapon3ID; weapon4ID = sc.weapon4ID; }
private void setOutputSpaceship() { Ship_Controller sc = gameController.GetComponent <GameController>().PlayerShip.GetComponent <Ship_Controller>(); sc.setSpaceship(builder); /* * sc.hullID = builder.hullID; * sc.armorID = builder.armorID; * sc.engineID = builder.engineID; * sc.weapon1ID = builder.weapon1ID; * sc.weapon2ID = builder.weapon2ID; * sc.weapon3ID = builder.weapon3ID; * sc.weapon4ID = builder.weapon4ID; */ }
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); } }
public void changeArmor() { transform.root.GetComponent <Shoot_System>().weapons = new GameObject[4]; if (hull != null) { Destroy(hull); } sc = transform.parent.GetComponent <Ship_Controller>(); hull = Resources.Load <GameObject>("Ship_Parts/Hull/Hull " + sc.hullID); hull = Instantiate(hull, transform.position, transform.rotation); hull.transform.parent = gameObject.transform; if (engine != null) { Destroy(engine); } engine = Resources.Load <GameObject>("Ship_Parts/Window/Window " + sc.engineID); engine = Instantiate(engine, transform.position, transform.rotation); engine.transform.parent = gameObject.transform; if (weapon1 != null) { Destroy(weapon1); } if (weapon2 != null) { Destroy(weapon2); } if (weapon1 != null) { Destroy(weapon3); } if (weapon3 != null) { Destroy(weapon4); } if (armor != null) { Destroy(armor); } armor = Resources.Load <GameObject>("Ship_Parts/Armor/Armor " + sc.armorID); armor = Instantiate(armor, transform.position, transform.rotation); armor.transform.parent = gameObject.transform; if (armor.GetComponent <Armor>().weapon1location != null) { Transform location = armor.GetComponent <Armor>().weapon1location.transform; weapon1 = Resources.Load <GameObject>("Ship_Parts/Weapon/Weapon " + sc.weapon1ID); weapon1 = Instantiate(weapon1, location.position, location.rotation); weapon1.GetComponent <Shoot_Controller>().isPlayer = sc.isPlayer; weapon1.transform.parent = gameObject.transform; } if (armor.GetComponent <Armor>().weapon2location != null) { Transform location = armor.GetComponent <Armor>().weapon2location.transform; weapon2 = Resources.Load <GameObject>("Ship_Parts/Weapon/Weapon " + sc.weapon2ID); weapon2 = Instantiate(weapon2, location.position, location.rotation); weapon2.GetComponent <Shoot_Controller>().isPlayer = sc.isPlayer; weapon2.transform.parent = gameObject.transform; } if (armor.GetComponent <Armor>().weapon3location != null) { Transform location = armor.GetComponent <Armor>().weapon3location.transform; weapon3 = Resources.Load <GameObject>("Ship_Parts/Weapon/Weapon " + sc.weapon3ID); weapon3 = Instantiate(weapon3, location.position, location.rotation); weapon3.GetComponent <Shoot_Controller>().isPlayer = sc.isPlayer; weapon3.transform.parent = gameObject.transform; } if (armor.GetComponent <Armor>().weapon4location != null) { Transform location = armor.GetComponent <Armor>().weapon4location.transform; weapon4 = Resources.Load <GameObject>("Ship_Parts/Weapon/Weapon " + sc.weapon4ID); weapon4 = Instantiate(weapon4, location.position, location.rotation); weapon4.GetComponent <Shoot_Controller>().isPlayer = sc.isPlayer; weapon4.transform.parent = gameObject.transform; } }
static double GetDistance(Vector3D location) { return(Vector3D.Subtract(Ship_Controller.GetPosition(), location).Length()); }
//public float getShootCoolDown() //{ // return _shootCooldown; //} //public int getCurrentXp() //{ // if (_controller.GetComponent<Player>() != null) // { // return _controller.GetComponent<Player>()._currentXp; // } // else // { // return 0; // } //} #endregion ACCESSORS public void SetUpBoat(Ship_Controller pController) { _controller = pController; }