Beispiel #1
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);
        }
Beispiel #2
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;
                    }
                }
            }
        }
Beispiel #3
0
 /// <summary>
 /// This function removes a waypoint from the system waypoint list, it is called in SystemMap.cs and connects the UI to the backend.
 /// </summary>
 /// <param name="Remove"></param>
 public void RemoveWaypoint(Waypoint Remove)
 {
     if (Waypoints.Count == 1)
         Waypoints.Clear();
     else
         Waypoints.Remove(Remove);
 }
Beispiel #4
0
 /// <summary>
 /// This function adds a waypoint to the system waypoint list, it is called by SystemMap.cs and connects the UI waypoint to the back end waypoints.
 /// </summary>
 /// <param name="X">System Position X in AU</param>
 /// <param name="Y">System Position Y in AU</param>
 public void AddWaypoint(String Title, double X, double Y, int FactionID)
 {
     Waypoint NewWP = new Waypoint(Title, this, X, Y, FactionID);
     Waypoints.Add(NewWP);
 }
Beispiel #5
0
        /// <summary>
        /// Constructor for way point related orders
        /// </summary>
        /// <param name="TypeOrder">Type</param>
        /// <param name="SecondaryOrder">Any secondary order specification such as installation type.</param>
        /// <param name="TertiaryOrder"> Any Tertiary order such as limits.</param>
        /// <param name="Delay">Delay in seconds before performing this order.</param>
        /// <param name="WPOrder">The Way Point in question.</param>
        public Order(Constants.ShipTN.OrderType TypeOrder, int SecondaryOrder, int TertiaryOrder, int Delay, Waypoint WPOrder)
        {
            TypeOf = TypeOrder;
            Target = WPOrder;
            Secondary = SecondaryOrder;
            Tertiary = TertiaryOrder;
            WayPoint = WPOrder;
            OrderDelay = Delay;


            OrderTimeRequirement = -1;

            Name = TypeOrder.ToString() + " " + WPOrder.Name.ToString();
        }