Esempio n. 1
0
        /// <summary>
        /// Creates a new JP at a location offset from the parent star by X and Y AU.
        /// </summary>
        /// <param name="Par">Parent Star</param>
        /// <param name="X">X in AU offset from parent star.</param>
        /// <param name="Y">Y in AU offset from parent star.</param>
        public JumpPoint(Star Par, double X, double Y)
        {
            Parent = Par;
            XOffset = X;
            YOffset = Y;
            Position.System = Parent.Position.System;
            Position.X = Parent.Position.X + XOffset;
            Position.Y = Parent.Position.Y + YOffset;

            SSEntity = StarSystemEntityType.JumpPoint;

            Id = Guid.NewGuid();

            // Add ourselves to our system's list of JumpPoints.
            Position.System.JumpPoints.Add(this);

            // JumpPoints won't start off connected, which means that any attempt to transit them must create a new connection.
            Connect = null;

            Name = "JumpPoint #" + (Position.System.JumpPoints.Count);

            IsGated = false;
            if (Constants.GameSettings.JumpGatesOnEveryJumpPoint || Constants.GameSettings.JumpPointGatedChance > GameState.RNG.Next(101))
            {
                IsGated = true;
                Name = "(G)" + Name;
            }

            GateOwner = null;

            _legalOrders.Add(Constants.ShipTN.OrderType.StandardTransit);
            _legalOrders.Add(Constants.ShipTN.OrderType.TransitAndDivide);
            _legalOrders.Add(Constants.ShipTN.OrderType.SquadronTransit);

        }
Esempio n. 2
0
        public StarElement(Star a_oStar, GLEffect a_oDefaultEffect, Vector3 a_oPosition, System.Drawing.Color a_oColor, bool a_bPrimary = true)
            : base(a_oStar)
        {
            if (!a_bPrimary)
            {
                // Do Non Primary Star Stuff here (e.g. orbit circle).
                ///< @todo...

                m_oOrbitCircle = new CircleElement(a_oDefaultEffect, a_oPosition, a_oStar, a_oColor);
#warning As with planet, m_oOrbitCircle will not be added as a child.
            }
            else
                m_oOrbitCircle = null;


        }
Esempio n. 3
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]);
            }

        }
Esempio n. 4
0
            /// <summary>
            /// Returns the color of the provided star.
            /// </summary>
            public static Color LookupColor(Star star)
            {
                if (m_oStarColor == null)
                {
                    m_oStarColor = new StarColor();
                }

                if (star != null)
                {
                    string sClass = star.SpectralType.ToString() + star.SpectralSubDivision.ToString();
                    if (m_oStarColor.m_dicStarColors.ContainsKey(sClass))
                    {
                        return m_oStarColor.m_dicStarColors[sClass];
                    }
                    else
                    {
                        return Color.White; 
                    }
                }

                return Color.White;
            }
Esempio n. 5
0
        /// <summary>
        /// Handles connecting unconnected jump points.
        /// This function only handles the connection of JumpPoints to new JumpPoints/Systems
        /// </summary>
        public void CreateConnection()
        {
            int        systemIndex     = -1;
            StarSystem connectedSystem = null;

            if (Constants.GameSettings.JumpPointLocalGroupConnectionChance >= GameState.RNG.Next(101))
            {
                do
                {
                    // We will connect to an 'existing system'
                    // Note, existing system doesn't necessarily exist.
                    systemIndex = Position.System.SystemIndex + GameState.RNG.Next(-Constants.GameSettings.JumpPointLocalGroupSize / 2, (Constants.GameSettings.JumpPointLocalGroupSize / 2) + 1);
                    if (systemIndex < 0)
                    {
                        // Sorry, we gotta keep you positive.
                        systemIndex = Math.Abs(systemIndex);
                    }
                }
                // Prevent linking to self.
                while (systemIndex == Position.System.SystemIndex);
            }
            else
            {
                // Generating a 'new system'
                // Note, new system isn't necessarily non-existant.
                systemIndex = GameState.Instance.StarSystemCurrentIndex;
            }


            if (systemIndex >= GameState.Instance.StarSystemCurrentIndex)
            {
                if (systemIndex == GameState.Instance.StarSystemCurrentIndex)
                {
                    // We're connecting to the next system on the list.
                    // This system will be generated, so increase our current index.
                    // This can happen with either 'existing system' or 'new system'
                    // however, it is intended for 'new system' generation.
                    GameState.Instance.StarSystemCurrentIndex++;
                }

                while (systemIndex > GameState.Instance.StarSystems.Count)
                {
                    // We're connecting to an 'existing system' that doesn't exist.
                    // If systemIndex 15 was selected above, and we've only got 10 systems, fill in the gap with new systems.
                    SystemGen.CreateSystem("Unexplored System S-" + GameState.Instance.StarSystems.Count);

                    // Note, we didn't set our StarSystemCurrentIndex. This is intentional.
                    // When we make another connection, and we RNG a 'new system' connection, we may have just made the 'new system' here.
                    // Since we want 'existing system' to make 2 links once all JP's are explored, we ensure
                    // the 'new system' connection will actually connect to the 'existing system'.
                }
            }

            if (systemIndex == GameState.Instance.StarSystems.Count)
            {
                // Generate a new system.

                connectedSystem = SystemGen.CreateSystem("Unexplored System S-" + GameState.Instance.StarSystems.Count);
            }
            else
            {
                // Select an existing system.
                connectedSystem = GameState.Instance.StarSystems[systemIndex];
            }

            // Choose a random jump point in the new system.
            JumpPoint connectedJP = null;

            List <JumpPoint> systemJumpPoints = new List <JumpPoint>();

            systemJumpPoints.AddRange(connectedSystem.JumpPoints); // Deep copy so we don't ruin the connectedSystem.JumpPoints list.

            while (systemJumpPoints.Count > 0)
            {
                // Select a random jump point.
                int i = GameState.RNG.Next(systemJumpPoints.Count);
                if (systemJumpPoints[i].Connect == null)
                {
                    // If selected JP doesn't have a connection, we use it.
                    connectedJP = systemJumpPoints[i];
                    break;
                }

                // If selected JP has a connection, remove it from the list, and select another.
                systemJumpPoints.RemoveAt(i);
            }

            if (connectedJP == null)
            {
                // All JP's are already connected, create a new one.
                Star parentStar = connectedSystem.Stars[GameState.RNG.Next(connectedSystem.Stars.Count)];
                connectedJP = SystemGen.GenerateJumpPoint(connectedSystem);
            }

            // Connect us to them.
            Connect = connectedJP;
            Name    = Name + "(" + Connect.Position.System.Name + ")";

            // Connect them to us.
            Connect.Connect = this;
            Connect.Name    = Connect.Name + "(" + Position.System.Name + ")";
        }