public void TGActiveTest() { EngineDefTN EngDef = new EngineDefTN("25 EP Nuclear Thermal Engine", 5, 1.0f, 1.0f, 1.0f, 1, 5, -1.0f); ActiveSensorDefTN ActDef1 = new ActiveSensorDefTN("Search 5M - 5000", 1.0f, 10, 5, 100, false, 1.0f, 1); ActiveSensorDefTN ActDef2 = new ActiveSensorDefTN("Search 500k - 1", 1.0f, 10, 5, 1, false, 1.0f, 1); ActiveSensorDefTN ActDef3 = new ActiveSensorDefTN("Search 2.2M - 1000", 1.0f, 10, 5, 20, false, 1.0f, 1); ActiveSensorDefTN ActDef4 = new ActiveSensorDefTN("Search 7M - 10000", 1.0f, 10, 5, 200, false, 1.0f, 1); GeneralComponentDefTN CrewQ = new GeneralComponentDefTN("Crew Quarters", 1.0f, 0, 10.0m, ComponentTypeTN.Crew); GeneralComponentDefTN FuelT = new GeneralComponentDefTN("Fuel Storage", 1.0f, 0, 10.0m, ComponentTypeTN.Fuel); GeneralComponentDefTN EBay = new GeneralComponentDefTN("Engineering Spaces", 1.0f, 5, 10.0m, ComponentTypeTN.Engineering); GeneralComponentDefTN Bridge = new GeneralComponentDefTN("Bridge", 1.0f, 5, 10.0m, ComponentTypeTN.Bridge); Faction FID = new Faction(0); StarSystem System = SystemGen.CreateSol(); SystemBody planet = new SystemBody(System.Stars[0], SystemBody.PlanetType.Terrestrial);; System.Stars[0].Planets.Add(planet); TaskGroupTN TaskGroup1 = new TaskGroupTN("Taskforce 001", FID, planet, System); for (int loop = 0; loop < 4; loop++) { ShipClassTN test = new ShipClassTN("Ship", FID); test.AddCrewQuarters(CrewQ, 2); test.AddFuelStorage(FuelT, 2); test.AddEngineeringSpaces(EBay, 2); Console.WriteLine("Bridge isn't present: {0} {1}", test.OtherComponents.IndexOf(Bridge), test.HasBridge); test.AddOtherComponent(Bridge, 1); Console.WriteLine("Bridge is present: {0} {1}", test.OtherComponents.IndexOf(Bridge), test.HasBridge); switch (loop) { case 0: test.AddActiveSensor(ActDef2, 2); break; case 1: test.AddActiveSensor(ActDef1, 2); break; case 2: test.AddActiveSensor(ActDef3, 2); break; case 3: test.AddActiveSensor(ActDef4, 2); break; } TaskGroup1.AddShip(test, "Test Ship"); TaskGroup1.SetActiveSensor(loop, 0, true); TaskGroup1.SetActiveSensor(loop, 1, true); } LinkedListNode<int> EM = TaskGroup1.EMSortList.First; for (int loop = 0; loop < 4; loop++) { Console.WriteLine("{0} {1}", TaskGroup1.Ships[loop].CurrentEMSignature, EM.Value); EM = EM.Next; } for (int loop = 0; loop < Constants.ShipTN.ResolutionMax; loop++) { Console.WriteLine("{0} | {1}", TaskGroup1.TaskGroupLookUpST[loop], loop); } TaskGroup1.SetActiveSensor(2, 0, false); TaskGroup1.SetActiveSensor(2, 1, false); Console.WriteLine("--------------------------------------------"); EM = TaskGroup1.EMSortList.First; for (int loop = 0; loop < 4; loop++) { Console.WriteLine("{0} {1}", TaskGroup1.Ships[loop].CurrentEMSignature, EM.Value); EM = EM.Next; } for (int loop = 0; loop < Constants.ShipTN.ResolutionMax; loop++) { Console.WriteLine("{0} | {1}", TaskGroup1.TaskGroupLookUpST[loop], loop); } }
/// <summary> /// Given a ship in this taskgroup, transfer said ship to TaskGroupTo /// </summary> /// <param name="Ship">Ship present in this taskgroup that should be transfered</param> /// <param name="TaskGroupTo">Taskgroup that will receive this ship</param> public void TransferShipToTaskGroup(ShipTN Ship, TaskGroupTN TaskGroupTo) { /// <summary> /// This ship is not in the taskgroup so return immediately. /// </summary> if (Ships.Contains(Ship) == false) return; BindingList<int> activeSensorIndices = new BindingList<int>(); for (int activeIterator = 0; activeIterator < Ship.ShipASensor.Count; activeIterator++) { /// <summary> /// This active sensor is both active and intact, so preserve its index, and set isActive to false(the sensor will be reactivated in its new TG. /// Destroyed sensors can keep their isActive state, as when they are repaired the repair function should handle reactivating them. /// </summary> if (Ship.ShipASensor[activeIterator].isActive == true && Ship.ShipASensor[activeIterator].isDestroyed == false) { activeSensorIndices.Add(activeIterator); Ship.ShipASensor[activeIterator].isActive = false; } } /// <summary> /// Move the ship between the two. /// </summary> RemoveShipFrom(Ship); TaskGroupTo.AddShipTo(Ship); /// <summary> /// reactivate any sensors that were active in the previous taskgroup. /// </summary> int ShipIndex = TaskGroupTo.Ships.IndexOf(Ship); foreach(int activeIndex in activeSensorIndices) TaskGroupTo.SetActiveSensor(ShipIndex, activeIndex, true); }