Пример #1
0
        public void TaskGroupFuelOrdersTest()
        {
            Faction PlayerFaction1 = new Faction(0);

            StarSystem System1 = SystemGen.CreateSol();

            SystemBody pl1 = new SystemBody(System1.Stars[0], SystemBody.PlanetType.Terrestrial);
            SystemBody pl2 = new SystemBody(System1.Stars[0], SystemBody.PlanetType.Terrestrial);
            SystemBody pl3 = new SystemBody(System1.Stars[0], SystemBody.PlanetType.Terrestrial);
            System1.Stars[0].Planets.Add(pl1);
            System1.Stars[0].Planets.Add(pl2);
            System1.Stars[0].Planets.Add(pl3);

            System1.Stars[0].Planets[0].Position.X = 1.0;
            System1.Stars[0].Planets[0].Position.Y = 1.0;

            System1.Stars[0].Planets[1].Position.X = 0.0;
            System1.Stars[0].Planets[1].Position.Y = 3.0;

            System1.Stars[0].Planets[2].Position.X = 0.0;
            System1.Stars[0].Planets[2].Position.Y = 0.0;


            PlayerFaction1.AddNewShipDesign("Blucher");
            PlayerFaction1.AddNewShipDesign("Tribal");
            PlayerFaction1.AddNewShipDesign("Ohio");

            PlayerFaction1.ShipDesigns[0].AddEngine(PlayerFaction1.ComponentList.Engines[0], 1);
            PlayerFaction1.ShipDesigns[0].AddCrewQuarters(PlayerFaction1.ComponentList.CrewQuarters[0], 2);
            PlayerFaction1.ShipDesigns[0].AddFuelStorage(PlayerFaction1.ComponentList.FuelStorage[0], 10);
            PlayerFaction1.ShipDesigns[0].AddEngineeringSpaces(PlayerFaction1.ComponentList.EngineeringSpaces[0], 2);
            PlayerFaction1.ShipDesigns[0].AddOtherComponent(PlayerFaction1.ComponentList.OtherComponents[0], 1);
            PlayerFaction1.ShipDesigns[0].IsTanker = true;

            PlayerFaction1.ShipDesigns[1].AddEngine(PlayerFaction1.ComponentList.Engines[0], 1);
            PlayerFaction1.ShipDesigns[1].AddCrewQuarters(PlayerFaction1.ComponentList.CrewQuarters[0], 2);
            PlayerFaction1.ShipDesigns[1].AddFuelStorage(PlayerFaction1.ComponentList.FuelStorage[0], 10);
            PlayerFaction1.ShipDesigns[1].AddEngineeringSpaces(PlayerFaction1.ComponentList.EngineeringSpaces[0], 2);
            PlayerFaction1.ShipDesigns[1].AddOtherComponent(PlayerFaction1.ComponentList.OtherComponents[0], 1);
            PlayerFaction1.ShipDesigns[1].IsTanker = true;

            PlayerFaction1.ShipDesigns[2].AddEngine(PlayerFaction1.ComponentList.Engines[0], 1);
            PlayerFaction1.ShipDesigns[2].AddCrewQuarters(PlayerFaction1.ComponentList.CrewQuarters[0], 2);
            PlayerFaction1.ShipDesigns[2].AddFuelStorage(PlayerFaction1.ComponentList.FuelStorage[0], 1);
            PlayerFaction1.ShipDesigns[2].AddEngineeringSpaces(PlayerFaction1.ComponentList.EngineeringSpaces[0], 2);
            PlayerFaction1.ShipDesigns[2].AddOtherComponent(PlayerFaction1.ComponentList.OtherComponents[0], 1);
            PlayerFaction1.ShipDesigns[2].IsTanker = false;

            PlayerFaction1.AddNewTaskGroup("P1 TG 01", System1.Stars[0].Planets[2], System1);
            PlayerFaction1.AddNewTaskGroup("P1 TG 02", System1.Stars[0].Planets[1], System1);
            PlayerFaction1.AddNewTaskGroup("P1 TG 03", System1.Stars[0].Planets[1], System1);

            PlayerFaction1.TaskGroups[0].AddShip(PlayerFaction1.ShipDesigns[0], "Test Ship 1");
            PlayerFaction1.TaskGroups[0].AddShip(PlayerFaction1.ShipDesigns[2], "Test Ship 2");
            PlayerFaction1.TaskGroups[1].AddShip(PlayerFaction1.ShipDesigns[1], "Test Ship 3");
            PlayerFaction1.TaskGroups[2].AddShip(PlayerFaction1.ShipDesigns[2], "Test Ship 4");

            PlayerFaction1.TaskGroups[0].Ships[0].Refuel(50000.0f);
            PlayerFaction1.TaskGroups[0].Ships[1].Refuel(50000.0f);
            PlayerFaction1.TaskGroups[1].Ships[0].Refuel(1000000.0f);

            Population P1 = new Population(System1.Stars[0].Planets[0], PlayerFaction1,0);
            Population P2 = new Population(System1.Stars[0].Planets[1], PlayerFaction1,0);

            System1.Stars[0].Planets[0].Populations[0].FuelStockpile = 10000000.0f;
            System1.Stars[0].Planets[1].Populations[0].FuelStockpile = 10.0f;

            PlayerFaction1.TaskGroups[1].IsOrbiting = false;
            PlayerFaction1.TaskGroups[1].Contact.Position.X = 3.0;
            PlayerFaction1.TaskGroups[1].Contact.Position.Y = 0.0;

            Order RefuelFromColony = new Order(Constants.ShipTN.OrderType.RefuelFromColony, -1, -1, -1, System1.Stars[0].Planets[0].Populations[0]);
            PlayerFaction1.TaskGroups[0].IssueOrder(RefuelFromColony);

            Order RefuelFromTargetFleet = new Order(Constants.ShipTN.OrderType.RefuelFromTargetFleet, -1, -1, -1, PlayerFaction1.TaskGroups[1]);
            PlayerFaction1.TaskGroups[0].IssueOrder(RefuelFromTargetFleet);

            Order RefuelTargetFleet = new Order(Constants.ShipTN.OrderType.RefuelTargetFleet, -1, -1, -1, PlayerFaction1.TaskGroups[2]);
            PlayerFaction1.TaskGroups[0].IssueOrder(RefuelTargetFleet);

            Order RefuelFromOwnTankers = new Order(Constants.ShipTN.OrderType.RefuelFromOwnTankers, -1, -1, -1, System1.Stars[0].Planets[1].Populations[0]);
            PlayerFaction1.TaskGroups[0].IssueOrder(RefuelFromOwnTankers);

            Order UnloadFuelToPop = new Order(Constants.ShipTN.OrderType.UnloadFuelToPlanet, -1, -1, -1, System1.Stars[0].Planets[1].Populations[0]);
            PlayerFaction1.TaskGroups[0].IssueOrder(UnloadFuelToPop);

            uint tickCount = 0;

            while (PlayerFaction1.TaskGroups[0].TaskGroupOrders.Count > 0)
            {
                Console.WriteLine("===================={0} {1} {2}====================", tickCount, PlayerFaction1.TaskGroups[0].TaskGroupOrders.Count, PlayerFaction1.TaskGroups[0].TimeRequirement);
                Console.WriteLine("X,Y: {0}/{1}", PlayerFaction1.TaskGroups[0].Contact.Position.X, PlayerFaction1.TaskGroups[0].Contact.Position.Y);
                Console.WriteLine("Fuel:s1:{0} s2:{1} s3:{2} s4:{3} P1:{4} P2:{5}", PlayerFaction1.TaskGroups[0].Ships[0].CurrentFuel, PlayerFaction1.TaskGroups[0].Ships[1].CurrentFuel,
                    PlayerFaction1.TaskGroups[1].Ships[0].CurrentFuel, PlayerFaction1.TaskGroups[2].Ships[0].CurrentFuel, System1.Stars[0].Planets[0].Populations[0].FuelStockpile,
                    System1.Stars[0].Planets[1].Populations[0].FuelStockpile);

                PlayerFaction1.TaskGroups[0].FollowOrders(Constants.TimeInSeconds.Hour);
                tickCount = tickCount + Constants.TimeInSeconds.Hour;
            }

            Console.WriteLine("===================={0} {1} {2}====================", tickCount, PlayerFaction1.TaskGroups[0].TaskGroupOrders.Count, PlayerFaction1.TaskGroups[0].TimeRequirement);
            Console.WriteLine("X,Y: {0}/{1}", PlayerFaction1.TaskGroups[0].Contact.Position.X, PlayerFaction1.TaskGroups[0].Contact.Position.Y);
            Console.WriteLine("Fuel:s1:{0} s2:{1} s3:{2} s4:{3} P1:{4} P2:{5}", PlayerFaction1.TaskGroups[0].Ships[0].CurrentFuel, PlayerFaction1.TaskGroups[0].Ships[1].CurrentFuel,
                PlayerFaction1.TaskGroups[1].Ships[0].CurrentFuel, PlayerFaction1.TaskGroups[2].Ships[0].CurrentFuel, System1.Stars[0].Planets[0].Populations[0].FuelStockpile,
                System1.Stars[0].Planets[1].Populations[0].FuelStockpile);

        }
Пример #2
0
        public void TGOrdersTest()
        {
            EngineDefTN EngDef = new EngineDefTN("25 EP Nuclear Thermal Engine", 5, 1.0f, 1.0f, 1.0f, 1, 5, -1.0f);

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


            Waypoint WP1 = new Waypoint("WP TG Orders", System, 0.1, 0.1, 0);

            planet.Position.X = 0.0;
            planet.Position.Y = 0.0;


            TaskGroupTN TaskGroup1 = new TaskGroupTN("Taskforce 001", FID, planet, System);

            ShipClassTN test = new ShipClassTN("Ship", FID);
            test.AddCrewQuarters(CrewQ, 2);
            test.AddFuelStorage(FuelT, 2);
            test.AddEngineeringSpaces(EBay, 2);
            test.AddOtherComponent(Bridge, 1);
            test.AddEngine(EngDef, 1);

            TaskGroup1.AddShip(test, "Test Ship");

            TaskGroup1.Ships[0].Refuel(200000.0f);

            Order TGOrder = new Order(Constants.ShipTN.OrderType.MoveTo, -1, -1, 0, WP1);

            TaskGroup1.IssueOrder(TGOrder);

            Console.WriteLine("Fuel Remaining:{0}", TaskGroup1.Ships[0].CurrentFuel);

            while (TaskGroup1.TaskGroupOrders.Count != 0)
            {
                TaskGroup1.FollowOrders(5);
                Console.WriteLine("{0} {1} | {2} {3}", Distance.ToKm(TaskGroup1.Contact.Position.X), Distance.ToKm(TaskGroup1.Contact.Position.Y), TaskGroup1.Contact.Position.X, TaskGroup1.Contact.Position.Y);
            }

            Console.WriteLine("Fuel Remaining:{0}", TaskGroup1.Ships[0].CurrentFuel);
        }
Пример #3
0
        public void ColonyOrdersTest()
        {
            Faction PlayerFaction1 = new Faction(0);

            StarSystem System1 = SystemGen.CreateSol();

            SystemBody pl1 = new SystemBody(System1.Stars[0], SystemBody.PlanetType.Terrestrial);
            SystemBody pl2 = new SystemBody(System1.Stars[0], SystemBody.PlanetType.Terrestrial);
            System1.Stars[0].Planets.Add(pl1);
            System1.Stars[0].Planets.Add(pl2);

            System1.Stars[0].Planets[0].Position.X = 1.0;
            System1.Stars[0].Planets[0].Position.Y = 1.0;

            System1.Stars[0].Planets[1].Position.X = 2.0;
            System1.Stars[0].Planets[1].Position.Y = 2.0;


            PlayerFaction1.AddNewShipDesign("Blucher");

            PlayerFaction1.ShipDesigns[0].AddEngine(PlayerFaction1.ComponentList.Engines[0], 1);
            PlayerFaction1.ShipDesigns[0].AddCrewQuarters(PlayerFaction1.ComponentList.CrewQuarters[0], 2);
            PlayerFaction1.ShipDesigns[0].AddFuelStorage(PlayerFaction1.ComponentList.FuelStorage[0], 2);
            PlayerFaction1.ShipDesigns[0].AddEngineeringSpaces(PlayerFaction1.ComponentList.EngineeringSpaces[0], 2);
            PlayerFaction1.ShipDesigns[0].AddOtherComponent(PlayerFaction1.ComponentList.OtherComponents[0], 1);
            PlayerFaction1.ShipDesigns[0].AddColonyBay(PlayerFaction1.ComponentList.ColonyBayDef[0], 1);
            PlayerFaction1.ShipDesigns[0].AddCargoHandlingSystem(PlayerFaction1.ComponentList.CargoHandleSystemDef[0], 1);

            PlayerFaction1.AddNewTaskGroup("P1 TG 01", System1.Stars[0].Planets[0], System1);

            PlayerFaction1.TaskGroups[0].AddShip(PlayerFaction1.ShipDesigns[0], "Test Ship");

            PlayerFaction1.TaskGroups[0].Ships[0].Refuel(200000.0f);

            Population P1 = new Population(System1.Stars[0].Planets[0], PlayerFaction1,0);
            Population P2 = new Population(System1.Stars[0].Planets[1], PlayerFaction1,0);

            System1.Stars[0].Planets[0].Populations[0].CivilianPopulation = 5.0f;
            System1.Stars[0].Planets[1].Populations[0].CivilianPopulation = 1.0f;

            Order Load = new Order(Constants.ShipTN.OrderType.LoadColonists, -1, 9000, 0, System1.Stars[0].Planets[0].Populations[0]);
            Order Unload = new Order(Constants.ShipTN.OrderType.UnloadColonists, -1, 9000, 0, System1.Stars[0].Planets[1].Populations[0]);

            PlayerFaction1.TaskGroups[0].IssueOrder(Load);
            PlayerFaction1.TaskGroups[0].IssueOrder(Unload);

            while (PlayerFaction1.TaskGroups[0].TaskGroupOrders.Count > 0)
            {
                Console.WriteLine("Current Order Time: {0} {1}", PlayerFaction1.TaskGroups[0].TimeRequirement,
    PlayerFaction1.TaskGroups[0].TaskGroupOrders[0].orderTimeRequirement);

                PlayerFaction1.TaskGroups[0].FollowOrders(Constants.TimeInSeconds.TwentyMinutes);

                Console.WriteLine("Order Count: {0}", PlayerFaction1.TaskGroups[0].TaskGroupOrders.Count);
            }

            Console.WriteLine("Population on P1 and P2:{0} {1}", System1.Stars[0].Planets[0].Populations[0].CivilianPopulation,
    System1.Stars[0].Planets[1].Populations[0].CivilianPopulation);
        }
Пример #4
0
        public void CollierOrdersTest()
        {
            Faction PlayerFaction1 = new Faction(0);

            StarSystem System1 = SystemGen.CreateSol();

            SystemBody pl1 = new SystemBody(System1.Stars[0], SystemBody.PlanetType.Terrestrial);
            SystemBody pl2 = new SystemBody(System1.Stars[0], SystemBody.PlanetType.Terrestrial);
            System1.Stars[0].Planets.Add(pl1);
            System1.Stars[0].Planets.Add(pl2);

            System1.Stars[0].Planets[0].Position.X = 1.0;
            System1.Stars[0].Planets[0].Position.Y = 1.0;

            System1.Stars[0].Planets[1].Position.X = 2.0;
            System1.Stars[0].Planets[1].Position.Y = 2.0;


            PlayerFaction1.AddNewShipDesign("Blucher");

            MissileEngineDefTN TestMissileEngine = new MissileEngineDefTN("Testbed", 5.0f, 1.0f, 1.0f, 1.0f);
            OrdnanceSeriesTN Series = new OrdnanceSeriesTN("BLANK STANDIN");
            OrdnanceDefTN TestMissile = new OrdnanceDefTN("Test Missile", Series, 1.0f, 0, 1.0f, 1.0f, 0, 0.0f, 0, 0.0f, 0, 0.0f, 0, 0.0f, 0, 1, 0, 0.0f, 0.0f, 0, false, 0, false, 0, TestMissileEngine, 1);

            PlayerFaction1.ShipDesigns[0].AddEngine(PlayerFaction1.ComponentList.Engines[0], 1);
            PlayerFaction1.ShipDesigns[0].AddCrewQuarters(PlayerFaction1.ComponentList.CrewQuarters[0], 2);
            PlayerFaction1.ShipDesigns[0].AddFuelStorage(PlayerFaction1.ComponentList.FuelStorage[0], 2);
            PlayerFaction1.ShipDesigns[0].AddEngineeringSpaces(PlayerFaction1.ComponentList.EngineeringSpaces[0], 2);
            PlayerFaction1.ShipDesigns[0].AddOtherComponent(PlayerFaction1.ComponentList.OtherComponents[0], 1);
            PlayerFaction1.ShipDesigns[0].AddMagazine(PlayerFaction1.ComponentList.MagazineDef[0], 1);

            PlayerFaction1.ShipDesigns[0].SetPreferredOrdnance(TestMissile, 3);

            PlayerFaction1.AddNewTaskGroup("P1 TG 01", System1.Stars[0].Planets[0], System1);

            PlayerFaction1.TaskGroups[0].AddShip(PlayerFaction1.ShipDesigns[0], "Test Ship");

            PlayerFaction1.TaskGroups[0].Ships[0].Refuel(200000.0f);

            Population P1 = new Population(System1.Stars[0].Planets[0], PlayerFaction1,0);
            Population P2 = new Population(System1.Stars[0].Planets[1], PlayerFaction1,0);

            System1.Stars[0].Planets[0].Populations[0].LoadMissileToStockpile(TestMissile, 4);


            Order Load = new Order(Constants.ShipTN.OrderType.LoadOrdnanceFromColony, -1, -1, 0, System1.Stars[0].Planets[0].Populations[0]);
            Order Unload = new Order(Constants.ShipTN.OrderType.UnloadOrdnanceToColony, -1, -1, 0, System1.Stars[0].Planets[1].Populations[0]);

            PlayerFaction1.TaskGroups[0].IssueOrder(Load);
            PlayerFaction1.TaskGroups[0].IssueOrder(Unload);

            bool CK = System1.Stars[0].Planets[1].Populations[0].MissileStockpile.ContainsKey(TestMissile);
            Console.WriteLine("Missiles on P1 and P2:{0} {1}", System1.Stars[0].Planets[0].Populations[0].MissileStockpile[TestMissile],
                CK);


            while (PlayerFaction1.TaskGroups[0].TaskGroupOrders.Count > 0)
            {
                Console.WriteLine("Current Order Time: {0} {1}", PlayerFaction1.TaskGroups[0].TimeRequirement,
    PlayerFaction1.TaskGroups[0].TaskGroupOrders[0].orderTimeRequirement);

                PlayerFaction1.TaskGroups[0].FollowOrders(Constants.TimeInSeconds.TwentyMinutes);

                Console.WriteLine("Order Count: {0}", PlayerFaction1.TaskGroups[0].TaskGroupOrders.Count);
            }

            bool CK1 = System1.Stars[0].Planets[0].Populations[0].MissileStockpile.ContainsKey(TestMissile);
            bool CK2 = System1.Stars[0].Planets[1].Populations[0].MissileStockpile.ContainsKey(TestMissile);
            Console.WriteLine("Missiles on P1 and P2:{0} {1}", CK1,
                            CK2);

            if (CK1 == true)
            {
                Console.WriteLine("P1 Missiles {0}", System1.Stars[0].Planets[0].Populations[0].MissileStockpile[TestMissile]);
            }

            if (CK2 == true)
            {
                Console.WriteLine("P2 Missiles {0}", System1.Stars[0].Planets[1].Populations[0].MissileStockpile[TestMissile]);
            }

            CK = PlayerFaction1.TaskGroups[0].Ships[0].ShipOrdnance.ContainsKey(TestMissile);
            Console.WriteLine("Missile count on Ships[0] after unload :{0}", CK);
        }
Пример #5
0
        public void OrdnanceTest()
        {
            /// <summary>
            /// Need to hook missiles into the distance table calculations, as well as sensor model.
            /// </summary>


            /// <summary>
            ///The Damage table MUST be initialized.
            /// </summary>
            DamageValuesTN.init();

            /// <summary>
            /// Factions ARE necessary.
            /// </summary>
            Faction PlayerFaction1 = new Faction(0);
            Faction PlayerFaction2 = new Faction(1);

            /// <summary>
            /// No StarSystem no contacts!
            /// </summary>
            StarSystem System1 = new StarSystem("This is not Sol", 0);
            System1.Populations = new BindingList<Population>();
            Star S1 = new Star();
            System1.Stars.Add(S1);

            PlayerFaction1.AddNewContactList(System1);
            PlayerFaction2.AddNewContactList(System1);

            /// <summary>
            /// No global RNG, no Damage or tohit.
            /// </summary>
            Random RNG = new Random();

            /// <summary>
            /// Planets and populations are needed for house keeping.
            /// </summary>
            SystemBody pl1 = new SystemBody(System1.Stars[0], SystemBody.PlanetType.Terrestrial);
            SystemBody pl2 = new SystemBody(System1.Stars[0], SystemBody.PlanetType.Terrestrial);
            pl1.Position.System = System1;
            pl2.Position.System = System1;
            System1.Stars[0].Planets.Add(pl1);
            System1.Stars[0].Planets.Add(pl2);

            Population P1 = new Population(System1.Stars[0].Planets[0], PlayerFaction1,0);
            Population P2 = new Population(System1.Stars[0].Planets[1], PlayerFaction2,0);

            System1.Stars[0].Planets[0].Position.X = 1.0;
            System1.Stars[0].Planets[0].Position.Y = 1.0;

            System1.Stars[0].Planets[1].Position.X = 1.04;
            System1.Stars[0].Planets[1].Position.Y = 1.04;


            PlayerFaction1.AddNewShipDesign("Blucher");
            PlayerFaction2.AddNewShipDesign("Tribal");

            MissileEngineDefTN TestMissileEngine = new MissileEngineDefTN("Testbed", 5.0f, 4.0f, 1.0f, 1.0f);

            OrdnanceSeriesTN Series = new OrdnanceSeriesTN("BLANK STANDIN");
            OrdnanceDefTN TestMissile = new OrdnanceDefTN("Test Missile", Series, 1.0f, 0, 1.0f, 1.0f, 0, 0.0f, 0, 0.0f, 0, 0.0f, 0, 0.0f, 0, 1, 0, 0.0f, 0.0f, 0, false, 0, false, 0, TestMissileEngine, 1);

            ActiveSensorDefTN Spotter = new ActiveSensorDefTN("Spotter", 6.0f, 12, 6, 19, false, 1.0f, 0);
            ActiveSensorDefTN FControl = new ActiveSensorDefTN("FCtrl", 6.0f, 12, 6, 19, true, 1.0f, 0);

            PlayerFaction1.ShipDesigns[0].AddEngine(PlayerFaction1.ComponentList.Engines[0], 1);
            PlayerFaction1.ShipDesigns[0].AddCrewQuarters(PlayerFaction1.ComponentList.CrewQuarters[0], 2);
            PlayerFaction1.ShipDesigns[0].AddFuelStorage(PlayerFaction1.ComponentList.FuelStorage[0], 2);
            PlayerFaction1.ShipDesigns[0].AddEngineeringSpaces(PlayerFaction1.ComponentList.EngineeringSpaces[0], 2);
            PlayerFaction1.ShipDesigns[0].AddOtherComponent(PlayerFaction1.ComponentList.OtherComponents[0], 1);
            PlayerFaction1.ShipDesigns[0].AddMagazine(PlayerFaction1.ComponentList.MagazineDef[0], 1);
            PlayerFaction1.ShipDesigns[0].AddLauncher(PlayerFaction1.ComponentList.MLauncherDef[0], 1);
            PlayerFaction1.ShipDesigns[0].AddMFC(FControl, 1);
            PlayerFaction1.ShipDesigns[0].AddActiveSensor(Spotter, 1);

            PlayerFaction2.ShipDesigns[0].AddEngine(PlayerFaction1.ComponentList.Engines[0], 1);
            PlayerFaction2.ShipDesigns[0].AddCrewQuarters(PlayerFaction1.ComponentList.CrewQuarters[0], 2);
            PlayerFaction2.ShipDesigns[0].AddFuelStorage(PlayerFaction1.ComponentList.FuelStorage[0], 2);
            PlayerFaction2.ShipDesigns[0].AddEngineeringSpaces(PlayerFaction1.ComponentList.EngineeringSpaces[0], 2);
            PlayerFaction2.ShipDesigns[0].AddOtherComponent(PlayerFaction1.ComponentList.OtherComponents[0], 1);
            PlayerFaction2.ShipDesigns[0].NewArmor("Duranium", 5, 4);

            PlayerFaction1.ShipDesigns[0].SetPreferredOrdnance(TestMissile, 3);

            PlayerFaction1.AddNewTaskGroup("P1 TG 01", System1.Stars[0].Planets[0], System1);
            PlayerFaction2.AddNewTaskGroup("P2 TG 01", System1.Stars[0].Planets[1], System1);


            PlayerFaction1.TaskGroups[0].AddShip(PlayerFaction1.ShipDesigns[0], "Test Ship 1");
            PlayerFaction2.TaskGroups[0].AddShip(PlayerFaction2.ShipDesigns[0], "Test Ship 2");


            PlayerFaction1.TaskGroups[0].Ships[0].Refuel(200000.0f);
            PlayerFaction2.TaskGroups[0].Ships[0].Refuel(200000.0f);

            System1.Stars[0].Planets[0].Populations[0].LoadMissileToStockpile(TestMissile, 4);

            Order Load = new Order(Constants.ShipTN.OrderType.LoadOrdnanceFromColony, -1, -1, 0, System1.Stars[0].Planets[0].Populations[0]);

            PlayerFaction1.TaskGroups[0].IssueOrder(Load);

            while (PlayerFaction1.TaskGroups[0].TaskGroupOrders.Count > 0)
            {
                PlayerFaction1.TaskGroups[0].FollowOrders(Constants.TimeInSeconds.TwentyMinutes);
            }

            /// <summary>
            /// Magazine loading isn't handled anywhere.
            /// </summary>
            PlayerFaction1.TaskGroups[0].Ships[0].ShipMLaunchers[0].loadedOrdnance = TestMissile;

            PlayerFaction1.TaskGroups[0].Ships[0].ShipMLaunchers[0].AssignMFC(PlayerFaction1.TaskGroups[0].Ships[0].ShipMFC[0]);
            PlayerFaction1.TaskGroups[0].Ships[0].ShipMFC[0].assignLaunchTube(PlayerFaction1.TaskGroups[0].Ships[0].ShipMLaunchers[0]);

            PlayerFaction1.TaskGroups[0].Ships[0].ShipMFC[0].assignTarget(PlayerFaction2.TaskGroups[0].Ships[0]);
            PlayerFaction1.TaskGroups[0].Ships[0].ShipMFC[0].openFire = true;
            PlayerFaction1.TaskGroups[0].SetActiveSensor(0, 0, true);


            GameState.Instance.CurrentSecond += 10;
            GameState.Instance.LastTimestep = 10;

            PlayerFaction1.SensorSweep();



            bool ret = PlayerFaction1.TaskGroups[0].Ships[0].ShipFireWeapons(RNG);


            Console.WriteLine("Did we fire: {0} Detected Contacts:{1}", ret, PlayerFaction1.DetectedContactLists.Count);


            bool done = false;
            while (!done)
            {
                Console.WriteLine("TimeStep:{0} {1} Detected Contacts:{2}", GameState.Instance.CurrentSecond, GameState.Instance.LastTimestep, PlayerFaction1.DetectedContactLists.Count);

                PlayerFaction1.SensorSweep();

                PlayerFaction1.MissileGroups[0].ProcessOrder((uint)GameState.Instance.LastTimestep, RNG);

                Console.WriteLine("{0} {1} {2} {3} {4} {5} {6} {7}", PlayerFaction1.MissileGroups[0].currentHeading, PlayerFaction1.MissileGroups[0].currentSpeedX,
                    PlayerFaction1.MissileGroups[0].currentSpeedY, PlayerFaction1.MissileGroups[0].timeReq, PlayerFaction1.MissileGroups[0].dx, PlayerFaction1.MissileGroups[0].dy,
                    PlayerFaction1.MissileGroups[0].missiles.Count, PlayerFaction1.MissileGroups[0].missilesDestroyed);

                GameState.Instance.CurrentSecond += 5;
                GameState.Instance.LastTimestep = 5;






                if (PlayerFaction1.MissileGroups[0].missiles.Count == PlayerFaction1.MissileGroups[0].missilesDestroyed)
                {
                    PlayerFaction1.MissileGroups.Clear();
                    done = true;
                }
            }


            Console.WriteLine("Armor:");
            for (int loop = 0; loop < PlayerFaction2.TaskGroups[0].Ships[0].ShipArmor.armorColumns.Count; loop++)
            {
                Console.WriteLine("{0} ", PlayerFaction2.TaskGroups[0].Ships[0].ShipArmor.armorColumns[loop]);
            }

        }
Пример #6
0
        /// <summary>
        /// Fire Weapons fires each ship's weapons at their target, or if there is no target redirects the taskgroup to the center of the map.
        /// </summary>
        /// <param name="P">Factions</param>
        /// <param name="factionCount">Count of factions</param>
        /// <param name="MoveToCenter">Order to move to center of map</param>
        /// <param name="tick">Current sim tick</param>
        /// <param name="RNG">"Global" random.</param>
        /// <param name="done">boolean that determines if the simulation is finished.</param>
        /// <returns></returns>
        bool FireWeapons(BindingList<Faction> P, int factionCount, Order MoveToCenter, int tick, Random RNG, bool done)
        {
            for (int loop = 0; loop < factionCount; loop++)
            {
                for (int loop2 = 0; loop2 < P[loop].TaskGroups.Count; loop2++)
                {
                    for (int loop3 = 0; loop3 < P[loop].TaskGroups[loop2].Ships.Count; loop3++)
                    {
                        if (P[loop].TaskGroups[loop2].Ships[loop3].IsDestroyed == false)
                        {
                            ShipTN target = P[loop].TaskGroups[loop2].Ships[loop3].ShipBFC[0].getTarget().ship;

                            if (target != null)
                            {
                                if (target.IsDestroyed == true)
                                {
                                    target = null;
                                    P[loop].TaskGroups[loop2].clearAllOrders();
                                    if (P[loop].TaskGroups[loop2].Contact.Position.X != 0.0 && P[loop].TaskGroups[loop2].Contact.Position.Y != 0.0)
                                        P[loop].TaskGroups[loop2].IssueOrder(MoveToCenter);
                                }
                            }

                            if (target != null)
                            {
                                if (P[loop].DetectedContactLists.ContainsKey(target.ShipsTaskGroup.Contact.Position.System))
                                {
                                    if (P[loop].DetectedContactLists[target.ShipsTaskGroup.Contact.Position.System].DetectedContacts.ContainsKey(target))
                                    {
                                        if (P[loop].DetectedContactLists[target.ShipsTaskGroup.Contact.Position.System].DetectedContacts[target].active == true)
                                        {
                                            if (P[loop].TaskGroups[loop2].Ships[loop3].IsDestroyed == false)
                                            {
                                                P[loop].TaskGroups[loop2].Ships[loop3].ShipFireWeapons(RNG);
                                            }
                                        }
                                        else
                                        {
                                            P[loop].TaskGroups[loop2].clearAllOrders();
                                            if (P[loop].TaskGroups[loop2].Contact.Position.X != 0.0 && P[loop].TaskGroups[loop2].Contact.Position.Y != 0.0)
                                                P[loop].TaskGroups[loop2].IssueOrder(MoveToCenter);
                                        }
                                    }
                                    else
                                    {
                                        P[loop].TaskGroups[loop2].clearAllOrders();
                                        if (P[loop].TaskGroups[loop2].Contact.Position.X != 0.0 && P[loop].TaskGroups[loop2].Contact.Position.Y != 0.0)
                                            P[loop].TaskGroups[loop2].IssueOrder(MoveToCenter);
                                    }
                                }
                                int SC;
                                P[loop].TaskGroups[loop2].Ships[loop3].RechargeBeamWeapons(5, out SC);
                            }
                        }
                    }
                }

                /// <summary>
                /// Get ending condition here: no more targets anywhere.
                /// </summary>

                if (P[loop].TaskGroups.Count != 0)
                {
                    if (P[loop].DetectedContactLists[P[loop].TaskGroups[0].Contact.Position.System].DetectedContacts.Count == 0 && P[loop].TaskGroups[0].TaskGroupOrders.Count == 0)
                    {
                        if (loop == (factionCount - 1) && done == true)
                        {
                            done = true;
                        }
                        else if (loop != (factionCount - 1))
                        {
                            done = true;
                        }
                        else
                        {
                            done = false;
                        }

                    }
                    else
                    {
                        done = false;
                    }
                }
                else
                {
                    done = true;
                }
                Console.WriteLine("***{0} {1} {2}***", loop, done, P[loop].DetectedContactLists[P[loop].TaskGroups[0].Contact.Position.System].DetectedContacts.Count);
            }

            return done;
        }
Пример #7
0
        public void SimulationTest()
        {
            /// <summary>
            /// initialize damage and rng here:
            /// </summary>
            DamageValuesTN.init();
            Random RNG = new Random();

            StarSystem Sol = SystemGen.CreateSol();

            BindingList<Faction> P = new BindingList<Faction>();
            int factionCount = 16;
            int TGCount = 10;
            int ShipCount = 8;

            /// <summary>
            /// Create all the factions here. later add new ships and tgs here as well.
            /// </summary>
            createFactions(P, Sol, factionCount, TGCount, ShipCount, RNG);


            /// <summary>
            /// Order every ship to proceed to the center.
            /// </summary>
            Waypoint Center = new Waypoint("WP Center", Sol, 0.0, 0.0, 0);

            Order MoveToCenter = new Order(Constants.ShipTN.OrderType.MoveTo, 0, 0, 0, Center);

            initShips(P, MoveToCenter, factionCount, TGCount, ShipCount);



            bool done = false;
            GameState.Instance.CurrentSecond = 0;
            int ShipsDestroyed = 0;
            int TGDestroyed = 0;

            /// <summary>
            /// Run the simulation:
            /// </summary>
            while (!done)
            {
                Console.WriteLine("Tick {0} ShipsDestroyed {1} TGDestroyed {2} ", GameState.Instance.CurrentSecond, ShipsDestroyed, TGDestroyed);
                /// <summary>
                /// Do sensor loop.
                /// Follow orders.
                /// I need to be able to know what targets are available. In system? per taskgroup?
                /// Dictionary in faction of system, and binding list of contacts?
                /// Attempt to fire.
                /// If one ship is destroyed exit loop.
                /// </summary>


                /// <summary>
                /// 1st do the sensor sweep:
                /// </summary>
                for (int loop = 0; loop < factionCount; loop++)
                {
                    P[loop].SensorSweep();
                }


                /// <summary>
                /// Target selection:
                /// As with follow orders more taskgroups means another loop, likewise for if different ships in each TG want different targets.
                /// What conditions cause target loss? destruction of target and disappearance of target from sensors.
                /// </summary>
                TargetAcquisition(P, factionCount);


                /// <summary>
                /// Follow orders here.
                /// </summary>
                for (int loop = 0; loop < factionCount; loop++)
                {
                    for (int loop2 = 0; loop2 < P[loop].TaskGroups.Count; loop2++)
                    {
                        /// <summary>
                        /// Adding new taskgroups means adding a loop here to run through them all.
                        /// </summary>
                        if (P[loop].TaskGroups[loop2].TaskGroupOrders.Count != 0)
                            P[loop].TaskGroups[loop2].FollowOrders((uint)GameState.Instance.LastTimestep);
                    }
                }

                /// <summary>
                /// attempt to fire weapons at target here.
                /// Initiative will have to be implemented here for "fairness". right now lower P numbers have the advantage.
                /// </summary>
                //done = FireWeapons(P, factionCount, MoveToCenter, tick, RNG, done);



                /// <summary>
                /// Advance the game tick:
                /// </summary>
                GameState.Instance.CurrentSecond += 5;

                /// <summary>
                /// Ending print report and preliminary ship/tg destruction handler.
                /// </summary>
                for (int loop = 0; loop < factionCount; loop++)
                {
                    for (int loop2 = 0; loop2 < P[loop].TaskGroups.Count; loop2++)
                    {
                        for (int loop3 = 0; loop3 < P[loop].TaskGroups[loop2].Ships.Count; loop3++)
                        {
                            if (P[loop].TaskGroups[loop2].Ships[loop3].ShipArmor.isDamaged == true)
                            {
                                Console.WriteLine("{0}{1}{2}", loop, loop2, loop3);
                                for (int loop4 = 0; loop4 < P[loop].TaskGroups[loop2].Ships[loop3].ShipArmor.armorColumns.Count; loop4++)
                                    Console.Write("{0} ", P[loop].TaskGroups[loop2].Ships[loop3].ShipArmor.armorColumns[loop4]);

                                Console.WriteLine("P{0}DC {1} | IsDestroyed:{2}", loop, P[loop].TaskGroups[loop2].Ships[loop3].DestroyedComponents.Count,
                                    P[loop].TaskGroups[loop2].Ships[loop3].IsDestroyed);
                            }

                            if (P[loop].TaskGroups[loop2].Ships[loop3].IsDestroyed == true)
                            {
                                for (int loop4 = 0; loop4 < factionCount; loop4++)
                                {
                                    StarSystem CurSystem = P[loop].TaskGroups[loop2].Contact.Position.System;
                                    if (P[loop4].DetectedContactLists.ContainsKey(CurSystem))
                                    {
                                        if (P[loop4].DetectedContactLists[CurSystem].DetectedContacts.ContainsKey(P[loop].TaskGroups[loop2].Ships[loop3]))
                                        {
                                            P[loop4].DetectedContactLists[CurSystem].DetectedContacts.Remove(P[loop].TaskGroups[loop2].Ships[loop3]);
                                        }
                                    }
                                }
                                bool nodeGone = P[loop].TaskGroups[loop2].Ships[loop3].OnDestroyed();
                                P[loop].TaskGroups[loop2].Ships[loop3].ShipClass.ShipsInClass.Remove(P[loop].TaskGroups[loop2].Ships[loop3]);
                                P[loop].TaskGroups[loop2].Ships[loop3].ShipsTaskGroup.Ships.Remove(P[loop].TaskGroups[loop2].Ships[loop3]);

                                ShipsDestroyed++;

                                if (loop3 != (P[loop].TaskGroups[loop2].Ships.Count - 1))
                                    loop3--;

                                if (P[loop].TaskGroups[loop2].Ships.Count == 0)
                                {
                                    P[loop].TaskGroups[loop2].clearAllOrders();
                                    P[loop].TaskGroups[loop2].Contact.Position.System.SystemContactList.Remove(P[loop].TaskGroups[loop2].Contact);
                                    P[loop].TaskGroups.Remove(P[loop].TaskGroups[loop2]);

                                    TGDestroyed++;

                                    if (loop2 != (P[loop].TaskGroups.Count - 1))
                                        loop2--;

                                    break;
                                }

                                P[loop].DetectedContactLists[P[loop].TaskGroups[loop2].Contact.Position.System].DetectedContacts.Clear();
                            }
                        }
                        if (P[loop].TaskGroups.Count == 0)
                            break;
                    }
                }
            }
        }
Пример #8
0
        /// <summary>
        /// Target Acquisition assigns new targets to ships that have destroyed their current target.
        /// </summary>
        /// <param name="P">Faction list.</param>
        /// <param name="factionCount"># of factions</param>
        void TargetAcquisition(BindingList<Faction> P, int factionCount)
        {
            for (int loop = 0; loop < factionCount; loop++)
            {
                for (int loop2 = 0; loop2 < P[loop].TaskGroups.Count; loop2++)
                {
                    for (int loop3 = 0; loop3 < P[loop].TaskGroups[loop2].Ships.Count; loop3++)
                    {

                        if (P[loop].TaskGroups[loop2].Ships[loop3].ShipBFC[0].target != null)
                        {
                            if (P[loop].TaskGroups[loop2].Ships[loop3].ShipBFC[0].target.ship.IsDestroyed == true)
                                P[loop].TaskGroups[loop2].Ships[loop3].ShipBFC[0].target = null;
                        }

                        if (P[loop].TaskGroups[loop2].Ships[loop3].ShipBFC[0].target == null && P[loop].TaskGroups[loop2].Ships[loop3].ShipBFC[0].isDestroyed == false)
                        {
                            ShipTN newTarget = P[loop].TaskGroups[loop2].getNewTarget();

                            if (newTarget != null)
                            {
                                P[loop].TaskGroups[loop2].Ships[loop3].ShipBFC[0].assignTarget(newTarget);
                                P[loop].TaskGroups[loop2].Ships[loop3].ShipBFC[0].openFire = true;


                                bool inOrderList = false;
                                for (int loop4 = 0; loop4 < P[loop].TaskGroups[loop2].TaskGroupOrders.Count; loop4++)
                                {
                                    if (P[loop].TaskGroups[loop2].TaskGroupOrders[loop4].target == newTarget.ShipsTaskGroup)
                                    {
                                        inOrderList = true;
                                        break;
                                    }
                                }

                                if (inOrderList == false)
                                {
                                    Order MoveToTarget = new Order(Constants.ShipTN.OrderType.MoveTo, 0, 0, 0, newTarget.ShipsTaskGroup);
                                    P[loop].TaskGroups[loop2].clearAllOrders();
                                    P[loop].TaskGroups[loop2].IssueOrder(MoveToTarget);
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #9
0
        /// <summary>
        /// InitShips stars all taskgroups moving towards the center of the map, and links all beam weapons(currently just 1 weapon to 1 bfc)
        /// </summary>
        /// <param name="P">Faction List</param>
        /// <param name="MoveToCenter">Order to move to center.</param>
        /// <param name="factionCount"># of factions.</param>
        /// <param name="TGCount"># of tgs.</param>
        /// <param name="ShipCount"># of ships</param>
        void initShips(BindingList<Faction> P, Order MoveToCenter, int factionCount, int TGCount, int ShipCount)
        {
            for (int loop = 0; loop < factionCount; loop++)
            {
                for (int loop2 = 0; loop2 < TGCount; loop2++)
                {
                    P[loop].TaskGroups[loop2].IsOrbiting = false;
                    P[loop].TaskGroups[loop2].IssueOrder(MoveToCenter);

                    /// <summary>
                    /// Weapon linking is also handled here for the time being, adding more weapons will be problematic.
                    /// </summary>
                    for (int loop3 = 0; loop3 < ShipCount; loop3++)
                    {
                        P[loop].TaskGroups[loop2].Ships[loop3].LinkWeaponToBeamFC(P[loop].TaskGroups[loop2].Ships[loop3].ShipBFC[0], P[loop].TaskGroups[loop2].Ships[loop3].ShipBeam[0]);
                        P[loop].TaskGroups[loop2].Ships[loop3].LinkWeaponToBeamFC(P[loop].TaskGroups[loop2].Ships[loop3].ShipBFC[0], P[loop].TaskGroups[loop2].Ships[loop3].ShipBeam[1]);
                    }
                }
            }
        }
Пример #10
0
        public void ComponentLoadUnloadTest()
        {
            Faction PlayerFaction1 = new Faction(0);

            StarSystem System1 = SystemGen.CreateSol();

            SystemBody pl1 = new SystemBody(System1.Stars[0], SystemBody.PlanetType.Terrestrial);
            SystemBody pl2 = new SystemBody(System1.Stars[0], SystemBody.PlanetType.Terrestrial);
            System1.Stars[0].Planets.Add(pl1);
            System1.Stars[0].Planets.Add(pl2);

            System1.Stars[0].Planets[0].Position.X = 1.0;
            System1.Stars[0].Planets[0].Position.Y = 1.0;

            System1.Stars[0].Planets[1].Position.X = 2.0;
            System1.Stars[0].Planets[1].Position.Y = 2.0;


            PlayerFaction1.AddNewShipDesign("Blucher");

            PlayerFaction1.ShipDesigns[0].AddEngine(PlayerFaction1.ComponentList.Engines[0], 1);
            PlayerFaction1.ShipDesigns[0].AddCrewQuarters(PlayerFaction1.ComponentList.CrewQuarters[0], 2);
            PlayerFaction1.ShipDesigns[0].AddFuelStorage(PlayerFaction1.ComponentList.FuelStorage[0], 2);
            PlayerFaction1.ShipDesigns[0].AddEngineeringSpaces(PlayerFaction1.ComponentList.EngineeringSpaces[0], 2);
            PlayerFaction1.ShipDesigns[0].AddOtherComponent(PlayerFaction1.ComponentList.OtherComponents[0], 1);
            PlayerFaction1.ShipDesigns[0].AddCargoHold(PlayerFaction1.ComponentList.CargoHoldDef[1], 1);
            PlayerFaction1.ShipDesigns[0].AddCargoHandlingSystem(PlayerFaction1.ComponentList.CargoHandleSystemDef[0], 1);

            PlayerFaction1.AddNewTaskGroup("P1 TG 01", System1.Stars[0].Planets[0], System1);

            PlayerFaction1.TaskGroups[0].AddShip(PlayerFaction1.ShipDesigns[0], "Test Ship");

            PlayerFaction1.TaskGroups[0].Ships[0].Refuel(200000.0f);

            Population P1 = new Population(System1.Stars[0].Planets[0], PlayerFaction1,0);
            Population P2 = new Population(System1.Stars[0].Planets[1], PlayerFaction1,0);

            System1.Stars[0].Planets[0].Populations[0].AddComponentsToStockpile(PlayerFaction1.ComponentList.Engines[0], 500.0f);

            /// <summary>
            /// The 1st 0 after the ordertype is for the ComponentStockpile[0] and CargoComponentList[0] index respectively.
            /// </summary>
            Order Load = new Order(Constants.ShipTN.OrderType.LoadShipComponent, 0, 0, 0, System1.Stars[0].Planets[0].Populations[0]);
            Order Unload = new Order(Constants.ShipTN.OrderType.UnloadShipComponent, 0, 0, 0, System1.Stars[0].Planets[1].Populations[0]);

            PlayerFaction1.TaskGroups[0].IssueOrder(Load);
            PlayerFaction1.TaskGroups[0].IssueOrder(Unload);


            Console.WriteLine("Engine Components on on P1 and P2:{0} {1}", System1.Stars[0].Planets[0].Populations[0].ComponentStockpileCount[0],
                System1.Stars[0].Planets[1].Populations[0].ComponentStockpileCount.Count);


            while (PlayerFaction1.TaskGroups[0].TaskGroupOrders.Count > 0)
            {
                Console.WriteLine("Current Order Time: {0} {1}", PlayerFaction1.TaskGroups[0].TimeRequirement,
                   PlayerFaction1.TaskGroups[0].TaskGroupOrders[0].orderTimeRequirement);

                PlayerFaction1.TaskGroups[0].FollowOrders(Constants.TimeInSeconds.TwentyMinutes);

                Console.WriteLine("Order Count: {0}", PlayerFaction1.TaskGroups[0].TaskGroupOrders.Count);
            }

            Console.WriteLine("Engine Components on on P1 and P2:{0} {1}", System1.Stars[0].Planets[0].Populations[0].ComponentStockpileCount[0],
                System1.Stars[0].Planets[1].Populations[0].ComponentStockpileCount[0]);

            Console.WriteLine("CargoList count on Ships[0] after unload :{0}", PlayerFaction1.TaskGroups[0].Ships[0].CargoComponentList.Count);
        }
Пример #11
0
        /// <summary>
        /// Adds the selected order to the task group's list of orders. This function is going to get giant.
        /// Not handled: Order filtering, delays, secondary and tertiary orders.
        /// As for adding new things here, look at the logic for how they were added to the SystemLocationListBox to derive how to get to them for this code.
        /// Don't forget filtering of destinations by survey status.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AddMoveButton_Clicked(object sender, EventArgs e)
        {
            /// <summary>
            /// Planets, Contacts, TG, WP
            /// </summary>
            int PlaceIndex = m_oTaskGroupPanel.SystemLocationsListBox.SelectedIndex;

            Order NewOrder = null;

            /// <summary>
            /// If AddMove is clicked with no system location it will bomb.
            /// </summary>
            if (PlaceIndex != -1)
            {
                List<Guid> GID = SystemLocationGuidDict.Keys.ToList();
                SystemListObject selected = SystemLocationDict[GID[PlaceIndex]];


                int ActionIndex = m_oTaskGroupPanel.AvailableActionsListBox.SelectedIndex;

                /// <summary>
                /// if AddMove is clicked with no selection action it will bomb.
                /// </summary>
                if (ActionIndex != -1)
                {
                    Constants.ShipTN.OrderType selected_ordertype = (Constants.ShipTN.OrderType)m_oTaskGroupPanel.AvailableActionsListBox.SelectedItem;

                    /// <summary>
                    /// Now figure out what the hell order this would be.
                    /// </summary>
                    var entity = selected.Entity;
                    var etype = selected.EntityType;
#warning handle secondary,tertiary, and order delays. also handle taskgroup split condition for move to contact orders if not already done so.
                    switch (etype)
                    {

                        case SystemListObject.ListEntityType.Contacts:
                            ShipTN shipcontact = (ShipTN)entity;//CurrentFaction.DetectedContactLists
                            NewOrder = new Order(selected_ordertype, -1, -1, 0, shipcontact.ShipsTaskGroup); //the task group? what if the TG splits?
                            shipcontact.TaskGroupsOrdered.Add(CurrentTaskGroup);
                            break;
                        case SystemListObject.ListEntityType.Planets:
                            SystemBody planet = (SystemBody)entity;
                            NewOrder = new Order(selected_ordertype, -1, -1, 0, planet);
                            break;
                        case SystemListObject.ListEntityType.JumpPoint:
                            JumpPoint jp = (JumpPoint)entity;
                            NewOrder = new Order(selected_ordertype, -1, -1, 0, jp);
                            break;
                        case SystemListObject.ListEntityType.Colonies:
                            Population popTargetOfOrder = (Population)entity;
                            NewOrder = new Order(selected_ordertype, -1, -1, 0, popTargetOfOrder);
                            break;
                        case SystemListObject.ListEntityType.TaskGroups:
                            TaskGroupTN TargetOfOrder = (TaskGroupTN)entity;
                            NewOrder = new Order(selected_ordertype, -1, -1, 0, TargetOfOrder);
                            TargetOfOrder.TaskGroupsOrdered.Add(CurrentTaskGroup);
                            break;
                        case SystemListObject.ListEntityType.Waypoints:
                            Waypoint waypoint = (Waypoint)entity;
                            NewOrder = new Order(selected_ordertype, -1, -1, 0, waypoint);
                            break;
                    }
                    if (NewOrder != null)
                        CurrentTaskGroup.IssueOrder(NewOrder, SelectedOrderIndex);
                }
            }
            if (SelectedOrderIndex != -1 && SelectedOrderIndex < CurrentTaskGroup.TaskGroupOrders.Count)
                SelectedOrderIndex += 1;
            BuildPlottedMoveList();
            BuildSystemLocationList();
            CalculateTimeDistance();
        }
Пример #12
0
        /// <summary>
        /// Places an order into the que of orders.
        /// </summary>
        /// <param name="Order">Order is the order to be carried out.</param>
        /// <param name="Destination">Destination of the waypoint/planet/TaskGroup we are moving towards.</param>
        /// <param name="Secondary">Secondary will be an enum ID for facility type,component,troop formation, or tractorable ship/shipyard. -1 if not present.</param>
        public void IssueOrder(Order OrderToTaskGroup, int index = -1)
        {
            if (TaskGroupOrders.Count == 0)
            {
                NewOrders = true;
                DrawTravelLine = 0;
            }
            if (index == -1)
                TaskGroupOrders.Add(OrderToTaskGroup);
            else
                TaskGroupOrders.Insert(index, OrderToTaskGroup);

            int OrderCount = TaskGroupOrders.Count - 1;
            double dX = 0.0, dY = 0.0, dZ;

            if (TaskGroupOrders[OrderCount].typeOf == Constants.ShipTN.OrderType.StandardTransit ||
                TaskGroupOrders[OrderCount].typeOf == Constants.ShipTN.OrderType.SquadronTransit ||
                TaskGroupOrders[OrderCount].typeOf == Constants.ShipTN.OrderType.TransitAndDivide)
            {
                if (TaskGroupOrders[OrderCount].jumpPoint.Connect == null)
                {
                    CanOrder = Constants.ShipTN.OrderState.DisallowOrdersUnknownJump;
                }
            }

            if (CanOrder != Constants.ShipTN.OrderState.AcceptOrders)
            {
                return;
            }

            if (OrderCount == 0)
            {
                if (IsOrbiting)
                    GetPositionFromOrbit();

                /// <summary>
                /// planets (and populations on planets) positions are stored relative to their star.
                /// As of 0.3 this is not the case anymore. they are calculated relative to their parent star, but their position is set in their data structure.
                /// Totally unnecessary if statement block by the way.
                /// </summary>
                if (TaskGroupOrders[OrderCount].target.SSEntity == StarSystemEntityType.Body)
                {
                    dX = Math.Abs(TaskGroupOrders[OrderCount].target.Position.X  - Contact.Position.X);
                    dY = Math.Abs(TaskGroupOrders[OrderCount].target.Position.Y  - Contact.Position.Y);
                }
                else if (TaskGroupOrders[OrderCount].target.SSEntity == StarSystemEntityType.Population)
                {
                    dX = Math.Abs(TaskGroupOrders[OrderCount].pop.Planet.Position.X - Contact.Position.X);
                    dY = Math.Abs(TaskGroupOrders[OrderCount].pop.Planet.Position.Y - Contact.Position.Y);
                }
                else
                {
                    dX = Math.Abs(TaskGroupOrders[OrderCount].target.Position.X - Contact.Position.X);
                    dY = Math.Abs(TaskGroupOrders[OrderCount].target.Position.Y - Contact.Position.Y);
                }

            }
            else if (TaskGroupOrders[OrderCount - 1].typeOf == Constants.ShipTN.OrderType.StandardTransit ||
                     TaskGroupOrders[OrderCount - 1].typeOf == Constants.ShipTN.OrderType.SquadronTransit ||
                     TaskGroupOrders[OrderCount - 1].typeOf == Constants.ShipTN.OrderType.TransitAndDivide)
            {

                /// <summary>
                /// planets (and populations on planets) positions are stored relative to their star.
                /// As of 0.3 this is not the case anymore. they are calculated relative to their parent star, but their position is set in their data structure.
                /// Totally unnecessary if statement block by the way.
                /// </summary>
                if (TaskGroupOrders[OrderCount].target.SSEntity == StarSystemEntityType.Body)
                {
                    dX = Math.Abs(TaskGroupOrders[OrderCount].target.Position.X  - TaskGroupOrders[OrderCount - 1].jumpPoint.Connect.Position.X);
                    dY = Math.Abs(TaskGroupOrders[OrderCount].target.Position.Y  - TaskGroupOrders[OrderCount - 1].jumpPoint.Connect.Position.Y);
                }
                else if (TaskGroupOrders[OrderCount].target.SSEntity == StarSystemEntityType.Population)
                {
                    dX = Math.Abs(TaskGroupOrders[OrderCount].pop.Planet.Position.X  - TaskGroupOrders[OrderCount - 1].jumpPoint.Connect.Position.X);
                    dY = Math.Abs(TaskGroupOrders[OrderCount].pop.Planet.Position.Y  - TaskGroupOrders[OrderCount - 1].jumpPoint.Connect.Position.Y);
                }
                else
                {
                    dX = Math.Abs(TaskGroupOrders[OrderCount].target.Position.X - TaskGroupOrders[OrderCount - 1].jumpPoint.Connect.Position.X);
                    dY = Math.Abs(TaskGroupOrders[OrderCount].target.Position.Y - TaskGroupOrders[OrderCount - 1].jumpPoint.Connect.Position.Y);
                }
            }
            else
            {
                dX = Math.Abs(TaskGroupOrders[OrderCount].target.Position.X - TaskGroupOrders[OrderCount - 1].target.Position.X);
                dY = Math.Abs(TaskGroupOrders[OrderCount].target.Position.Y - TaskGroupOrders[OrderCount - 1].target.Position.Y);

                /// <summary>
                /// planets (and populations on planets) positions are stored relative to their star.
                /// Not any more etc,etc. The starting taskgroup is still too slow to catch a secondary star, but you can ambush them with waypoints placed along their orbits now.
                /// </summary>
                if (TaskGroupOrders[OrderCount].target.SSEntity == StarSystemEntityType.Body)
                {
                    dX = TaskGroupOrders[OrderCount].target.Position.X;
                    dY = TaskGroupOrders[OrderCount].target.Position.Y;
                }
                else if (TaskGroupOrders[OrderCount].target.SSEntity == StarSystemEntityType.Population)
                {
                    dX = TaskGroupOrders[OrderCount].pop.Planet.Position.X;
                    dY = TaskGroupOrders[OrderCount].pop.Planet.Position.Y;
                }
                else
                {
                    dX = TaskGroupOrders[OrderCount].target.Position.X;
                    dY = TaskGroupOrders[OrderCount].target.Position.Y;
                }

                if (TaskGroupOrders[OrderCount - 1].target.SSEntity == StarSystemEntityType.Body)
                {
                    dX = Math.Abs(dX - TaskGroupOrders[OrderCount - 1].target.Position.X);
                    dY = Math.Abs(dY - TaskGroupOrders[OrderCount - 1].target.Position.Y);
                }
                else if (TaskGroupOrders[OrderCount - 1].target.SSEntity == StarSystemEntityType.Population)
                {
                    dX = Math.Abs(dX - TaskGroupOrders[OrderCount - 1].pop.Planet.Position.X);
                    dY = Math.Abs(dY - TaskGroupOrders[OrderCount - 1].pop.Planet.Position.Y);
                }
                else
                {
                    dX = Math.Abs(dX - TaskGroupOrders[OrderCount - 1].target.Position.X);
                    dY = Math.Abs(dY - TaskGroupOrders[OrderCount - 1].target.Position.Y);
                }

            }
            dZ = Math.Sqrt(((dX * dX) + (dY * dY)));
            TotalOrderDistance = TotalOrderDistance + dZ;
        }