Exemple #1
0
        /// <summary>
        /// Adds a new jump point to the system. Since JPs can't be destroyed there is no corresponding remove function. Perhaps there should be.
        /// </summary>
        /// <param name="parentStar">Star to attach this JP to.</param>
        /// <param name="Position.XAU">X offset from Star Position</param>
        /// <param name="Position.YAU">Y offset from Star Position.</param>
        /// <returns>Newly Created Jumpoint</returns>
        public JumpPoint CreateJumpPoint(Star parentStar, double XOffsetAU, double YOffsetAU)
        {
            JumpPoint NewJP = new JumpPoint(this, parentStar, XOffsetAU, YOffsetAU);

            JumpPoints.Add(NewJP);
            return(NewJP);
        }
Exemple #2
0
        /// <summary>
        /// Constructor for Jump 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="JPOrder">The Jump Point in question.</param>
        public Orders(Constants.ShipTN.OrderType TypeOrder, int SecondaryOrder, int TertiaryOrder, int Delay, JumpPoint JPOrder)
        {
            TypeOf     = TypeOrder;
            Target     = JPOrder;
            Secondary  = SecondaryOrder;
            Tertiary   = TertiaryOrder;
            JumpPoint  = JPOrder;
            OrderDelay = Delay;


            OrderTimeRequirement = -1;

            Name = TypeOrder.ToString() + " " + JPOrder.Name.ToString();
        }
Exemple #3
0
        public static JumpPoint CreateJumpPoint(StarSystem system, Star parent, double minDistance, double maxDistance)
        {
            // Determine a location for the new JP.
            double offsetX = ((maxDistance - minDistance) * GameState.RNG.Next(76) / 100) + minDistance;
            double offsetY = ((maxDistance - minDistance) * GameState.RNG.Next(76) / 100) + minDistance;

            // Randomly flip the sign of the offsets.
            if (GameState.RNG.Next(2) == 0)
            {
                offsetX = -offsetX;
            }
            if (GameState.RNG.Next(2) == 0)
            {
                offsetY = -offsetY;
            }

            JumpPoint newJumpPoint = new JumpPoint(system, parent, offsetX, offsetY);

            system.JumpPoints.Add(newJumpPoint);
            return(newJumpPoint);
        }
Exemple #4
0
        public void FactionSystemTest()
        {
            Faction PlayerFaction1 = new Faction(0);
            Faction PlayerFaction2 = new Faction(1);

            StarSystem System1 = SystemGen.CreateSol();
            StarSystem System2 = SystemGen.CreateSystem("Alpha Centauri");

            SystemBody Start1 = new SystemBody(System1.Stars[0], SystemBody.PlanetType.Terrestrial);
            Start1.Position.X = 1.0;
            Start1.Position.Y = 1.0;


            SystemBody Start2 = new SystemBody(System1.Stars[0], SystemBody.PlanetType.Terrestrial);
            Start2.Position.X = 1.0005;
            Start2.Position.Y = 1.0005;



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

            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].AddActiveSensor(PlayerFaction1.ComponentList.ActiveSensorDef[0], 1);
            PlayerFaction1.ShipDesigns[0].AddPassiveSensor(PlayerFaction1.ComponentList.PassiveSensorDef[0], 1);
            PlayerFaction1.ShipDesigns[0].AddPassiveSensor(PlayerFaction1.ComponentList.PassiveSensorDef[1], 1);

            PlayerFaction2.ShipDesigns[0].AddEngine(PlayerFaction2.ComponentList.Engines[0], 1);
            PlayerFaction2.ShipDesigns[0].AddCrewQuarters(PlayerFaction2.ComponentList.CrewQuarters[0], 2);
            PlayerFaction2.ShipDesigns[0].AddFuelStorage(PlayerFaction2.ComponentList.FuelStorage[0], 2);
            PlayerFaction2.ShipDesigns[0].AddEngineeringSpaces(PlayerFaction2.ComponentList.EngineeringSpaces[0], 2);
            PlayerFaction2.ShipDesigns[0].AddOtherComponent(PlayerFaction2.ComponentList.OtherComponents[0], 1);
            PlayerFaction2.ShipDesigns[0].AddActiveSensor(PlayerFaction2.ComponentList.ActiveSensorDef[0], 1);
            PlayerFaction2.ShipDesigns[0].AddPassiveSensor(PlayerFaction2.ComponentList.PassiveSensorDef[0], 1);
            PlayerFaction2.ShipDesigns[0].AddPassiveSensor(PlayerFaction2.ComponentList.PassiveSensorDef[1], 1);

            PlayerFaction1.AddNewTaskGroup("P1 TG 01", Start1, System1);
            PlayerFaction2.AddNewTaskGroup("P2 TG 01", Start2, 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);


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

            PlayerFaction1.AddNewContactList(System2);
            PlayerFaction2.AddNewContactList(System2);

            PlayerFaction1.TaskGroups[0].SetActiveSensor(0, 0, true);
            PlayerFaction2.TaskGroups[0].SetActiveSensor(0, 0, true);

            GameState.Instance.CurrentSecond = 5;

            Console.WriteLine("Time: 0 {0} {1}", PlayerFaction1.TaskGroups[0].Contact.Position.System.Name, PlayerFaction2.TaskGroups[0].Contact.Position.System.Name);
            Console.WriteLine("{0} {1}", PlayerFaction1.TaskGroups[0].Ships[0].ThermalDetection[1], PlayerFaction2.TaskGroups[0].Ships[0].ThermalDetection[0]);
            Console.WriteLine("{0} {1}", PlayerFaction1.TaskGroups[0].Ships[0].EMDetection[1], PlayerFaction2.TaskGroups[0].Ships[0].EMDetection[0]);
            Console.WriteLine("{0} {1}", PlayerFaction1.TaskGroups[0].Ships[0].ActiveDetection[1], PlayerFaction2.TaskGroups[0].Ships[0].ActiveDetection[0]);

            PlayerFaction1.SensorSweep();
            PlayerFaction2.SensorSweep();

            Console.WriteLine("Time: 5 {0} {1}", PlayerFaction1.TaskGroups[0].Contact.Position.System.Name, PlayerFaction2.TaskGroups[0].Contact.Position.System.Name);
            Console.WriteLine("{0} {1}", PlayerFaction1.TaskGroups[0].Ships[0].ThermalDetection[1], PlayerFaction2.TaskGroups[0].Ships[0].ThermalDetection[0]);
            Console.WriteLine("{0} {1}", PlayerFaction1.TaskGroups[0].Ships[0].EMDetection[1], PlayerFaction2.TaskGroups[0].Ships[0].EMDetection[0]);
            Console.WriteLine("{0} {1}", PlayerFaction1.TaskGroups[0].Ships[0].ActiveDetection[1], PlayerFaction2.TaskGroups[0].Ships[0].ActiveDetection[0]);

            PlayerFaction1.TaskGroups[0].SetActiveSensor(0, 0, false);
            PlayerFaction2.TaskGroups[0].SetActiveSensor(0, 0, false);

            GameState.Instance.CurrentSecond = 10;

            PlayerFaction1.SensorSweep();
            PlayerFaction2.SensorSweep();

            Console.WriteLine("Time: 10 {0} {1}", PlayerFaction1.TaskGroups[0].Contact.Position.System.Name, PlayerFaction2.TaskGroups[0].Contact.Position.System.Name);
            Console.WriteLine("{0} {1}", PlayerFaction1.TaskGroups[0].Ships[0].ThermalDetection[1], PlayerFaction2.TaskGroups[0].Ships[0].ThermalDetection[0]);
            Console.WriteLine("{0} {1}", PlayerFaction1.TaskGroups[0].Ships[0].EMDetection[1], PlayerFaction2.TaskGroups[0].Ships[0].EMDetection[0]);
            Console.WriteLine("{0} {1}", PlayerFaction1.TaskGroups[0].Ships[0].ActiveDetection[1], PlayerFaction2.TaskGroups[0].Ships[0].ActiveDetection[0]);

            PlayerFaction1.TaskGroups[0].SetActiveSensor(0, 0, true);
            PlayerFaction2.TaskGroups[0].SetActiveSensor(0, 0, true);

            //this isn't needed, but also shouldn't crash now that its fixed. to test uncomment this out and run nunit or whatever tester.
            //SystemGen.GenerateJumpPoint(System1);
            //SystemGen.GenerateJumpPoint(System2);

            JumpPoint JP1 = new JumpPoint(System1.Stars[0], 0.1, 0.2);
            System1.JumpPoints.Add(JP1);
            JumpPoint JP2 = new JumpPoint(System2.Stars[0], 0.2, 0.1);
            System2.JumpPoints.Add(JP2);

            System1.JumpPoints[0].Connect = System2.JumpPoints[0];
            System2.JumpPoints[0].Connect = System1.JumpPoints[0];

            SystemPosition newPos = System1.JumpPoints[0].Connect.Position;

            PlayerFaction1.TaskGroups[0].Position.System.SystemContactList.Remove(PlayerFaction1.TaskGroups[0].Contact);
            newPos.System.SystemContactList.Add(PlayerFaction1.TaskGroups[0].Contact);

            PlayerFaction1.TaskGroups[0].Position = newPos;
            PlayerFaction1.TaskGroups[0].Contact.UpdateLocationAfterTransit();

            PlayerFaction2.TaskGroups[0].Position.System.SystemContactList.Remove(PlayerFaction2.TaskGroups[0].Contact);
            newPos.System.SystemContactList.Add(PlayerFaction2.TaskGroups[0].Contact);

            PlayerFaction2.TaskGroups[0].Position = newPos;
            PlayerFaction2.TaskGroups[0].Contact.UpdateLocationAfterTransit();

            GameState.Instance.CurrentSecond = 15;

            PlayerFaction1.SensorSweep();
            PlayerFaction2.SensorSweep();

            Console.WriteLine("Time: 15 {0} {1}", PlayerFaction1.TaskGroups[0].Contact.Position.System.Name, PlayerFaction2.TaskGroups[0].Contact.Position.System.Name);
            Console.WriteLine("{0} {1}", PlayerFaction1.TaskGroups[0].Ships[0].ThermalDetection[1], PlayerFaction2.TaskGroups[0].Ships[0].ThermalDetection[0]);
            Console.WriteLine("{0} {1}", PlayerFaction1.TaskGroups[0].Ships[0].EMDetection[1], PlayerFaction2.TaskGroups[0].Ships[0].EMDetection[0]);
            Console.WriteLine("{0} {1}", PlayerFaction1.TaskGroups[0].Ships[0].ActiveDetection[1], PlayerFaction2.TaskGroups[0].Ships[0].ActiveDetection[0]);
        }
Exemple #5
0
        /// <summary>
        /// Adds a new jump point to the system. Since JPs can't be destroyed there is no corresponding remove function. Perhaps there should be.
        /// </summary>
        /// <param name="XSystemAU">X Location in AU of JP.</param>
        /// <param name="YSystemAU">Y Location in AU of JP.</param>
        public void AddJumpPoint(double XSystemAU, double YSystemAU)
        {
            JumpPoint NewJP = new JumpPoint(this, XSystemAU, YSystemAU);

            JumpPoints.Add(NewJP);
        }
Exemple #6
0
        private void CreateJumpPoint(SceenElement parent, JumpPoint oJumpPoint)
        {
            SceenElement oJumpPointElement = new JumpPointElement(oJumpPoint);
            oJumpPointElement.EntityID = oJumpPoint.Id;

            Vector3 v3JPPos = new Vector3((float)oJumpPoint.Position.X, (float)oJumpPoint.Position.Y, 0.0f);

            GLQuad oJPQuad = new GLUtilities.GLQuad(SceenDefaultEffect,
                                                            v3JPPos,
                                                            new Vector2(0.0001f, 0.0001f),                   // what size is a jump point anyway???
                                                            Color.Cyan,
                                                            UIConstants.Textures.DEFAULT_JUMPPOINT_ICON);

            GLUtilities.GLFont oNameLable = new GLUtilities.GLFont(SceenDefaultEffect, v3JPPos,
            UIConstants.DEFAULT_TEXT_SIZE, Color.Cyan, UIConstants.Textures.DEFAULT_GLFONT2, oJumpPoint.Name);

            oJumpPointElement.Lable = oNameLable;
            oJumpPointElement.PrimaryPrimitive = oJPQuad;
            oJumpPointElement.AddPrimitive(oJPQuad);
            oJumpPointElement.RealSize = new Vector2(0.0001f, 0.0001f);
            parent.AddChildElement(oJumpPointElement);
        }
Exemple #7
0
        /// <summary>
        /// list of legal orders a taskgroup or unit can use againsed this entity ie when this entity is the target.
        /// </summary>
        public List <Constants.ShipTN.OrderType> LegalOrders(Faction faction)
        {
            List <Constants.ShipTN.OrderType> legalOrders = new List <Constants.ShipTN.OrderType>();

            //generic orders a selected tg targeting anything will have all these options if the selecteed tg can do these.
            legalOrders.Add(Constants.ShipTN.OrderType.MoveTo);
            legalOrders.Add(Constants.ShipTN.OrderType.ExtendedOrbit);
            legalOrders.Add(Constants.ShipTN.OrderType.Picket);
            legalOrders.Add(Constants.ShipTN.OrderType.SendMessage);
            legalOrders.Add(Constants.ShipTN.OrderType.EqualizeFuel);
            legalOrders.Add(Constants.ShipTN.OrderType.EqualizeMSP);
            legalOrders.Add(Constants.ShipTN.OrderType.ActivateTransponder);
            legalOrders.Add(Constants.ShipTN.OrderType.DeactivateTransponder);
            legalOrders.Add(Constants.ShipTN.OrderType.ActivateSensors);
            legalOrders.Add(Constants.ShipTN.OrderType.DeactivateSensors);
            legalOrders.Add(Constants.ShipTN.OrderType.ActivateShields);
            legalOrders.Add(Constants.ShipTN.OrderType.DeactivateShields);
            legalOrders.Add(Constants.ShipTN.OrderType.DivideFleetToSingleShips);
            legalOrders.Add(Constants.ShipTN.OrderType.DetachNonGeoSurvey);
            legalOrders.Add(Constants.ShipTN.OrderType.DetachNonGravSurvey);
            legalOrders.Add(Constants.ShipTN.OrderType.RefuelFromOwnTankers);
            legalOrders.Add(Constants.ShipTN.OrderType.DetachTankers);
            legalOrders.Add(Constants.ShipTN.OrderType.ResupplyFromOwnSupplyShips);
            legalOrders.Add(Constants.ShipTN.OrderType.DetachSupplyShips);
            legalOrders.Add(Constants.ShipTN.OrderType.ReloadFromOwnColliers);
            legalOrders.Add(Constants.ShipTN.OrderType.DetachColliers);
            legalOrders.Add(Constants.ShipTN.OrderType.ReleaseAt);

            if (this is JumpPoint)
            {
                JumpPoint thisjp = (JumpPoint)this;
                legalOrders.Add(Constants.ShipTN.OrderType.StandardTransit);
                legalOrders.Add(Constants.ShipTN.OrderType.TransitAndDivide);
                legalOrders.Add(Constants.ShipTN.OrderType.SquadronTransit);
                if (!thisjp.IsGated)
                {
                    legalOrders.Add(Constants.ShipTN.OrderType.BuildJumpGate);
                }
            }
            if (this is Planet)
            {
                Planet planet = (Planet)this;
                if (planet.GeoSurveyList.ContainsKey(faction) == true)
                {
                    if (planet.GeoSurveyList[faction] == false)
                    {
                        legalOrders.Add(Constants.ShipTN.OrderType.GeoSurvey);
                    }
                }
            }
            if (this is Population)
            {
                Population pop = (Population)this;
                if (faction == pop.Faction)
                {
                    legalOrders.Add(Constants.ShipTN.OrderType.LoadCrewFromColony);
                    if (pop.FuelStockpile > 0)
                    {
                        legalOrders.Add(Constants.ShipTN.OrderType.RefuelFromColony);
                    }
                    if (pop.MaintenanceSupplies > 0)
                    {
                        legalOrders.Add(Constants.ShipTN.OrderType.ResupplyFromColony);
                    }
                    if (Array.Exists(pop.Installations, x => x.Type == Installation.InstallationType.MaintenanceFacility))
                    {
                        legalOrders.Add(Constants.ShipTN.OrderType.BeginOverhaul);
                    }
                    if (pop.Installations.Count() > 0)
                    {
                        legalOrders.Add(Constants.ShipTN.OrderType.LoadInstallation);
                    }
                    if (pop.ComponentStockpile.Count() > 0)
                    {
                        legalOrders.Add(Constants.ShipTN.OrderType.LoadShipComponent);
                    }
                    legalOrders.Add(Constants.ShipTN.OrderType.LoadAllMinerals);
                    legalOrders.Add(Constants.ShipTN.OrderType.UnloadAllMinerals);
                    legalOrders.Add(Constants.ShipTN.OrderType.LoadMineral);
                    legalOrders.Add(Constants.ShipTN.OrderType.LoadMineralWhenX);
                    legalOrders.Add(Constants.ShipTN.OrderType.UnloadMineral);
                    legalOrders.Add(Constants.ShipTN.OrderType.LoadOrUnloadMineralsToReserve);
                    if (pop.CivilianPopulation > 0)
                    {
                        legalOrders.Add(Constants.ShipTN.OrderType.LoadColonists);
                    }
                    legalOrders.Add(Constants.ShipTN.OrderType.UnloadColonists);
                    legalOrders.Add(Constants.ShipTN.OrderType.UnloadFuelToPlanet);
                    legalOrders.Add(Constants.ShipTN.OrderType.UnloadSuppliesToPlanet);
                    if (Array.Exists(pop.Installations, x => x.Type == Installation.InstallationType.OrdnanceFactory) || pop.MissileStockpile.Count > 0)
                    {
                        legalOrders.Add(Constants.ShipTN.OrderType.LoadMineral);
                    }
                    legalOrders.Add(Constants.ShipTN.OrderType.LoadOrdnanceFromColony);
                    legalOrders.Add(Constants.ShipTN.OrderType.UnloadOrdnanceToColony);
                }
            }
            if (this is SystemContact)
            {
                legalOrders.Add(Constants.ShipTN.OrderType.Follow);
            }
            if (this is TaskGroupTN)
            {
                TaskGroupTN tg         = (TaskGroupTN)this;
                ShipTN[]    shipsArray = tg.Ships.ToArray();
                legalOrders.Add(Constants.ShipTN.OrderType.Follow);
                legalOrders.Add(Constants.ShipTN.OrderType.Join);
                legalOrders.Add(Constants.ShipTN.OrderType.Absorb);
                legalOrders.Add(Constants.ShipTN.OrderType.RefuelTargetFleet);
                legalOrders.Add(Constants.ShipTN.OrderType.ResupplyTargetFleet);
                legalOrders.Add(Constants.ShipTN.OrderType.ReloadTargetFleet);

                if (Array.Exists(shipsArray, x => x.ShipClass.IsTanker)) //if this fleet is targeted and has a IsTanker.
                {
                    legalOrders.Add(Constants.ShipTN.OrderType.RefuelFromTargetFleet);
                }
                if (Array.Exists(shipsArray, x => x.ShipClass.IsSupply))//if this fleet is targeted and has a IsSupply.
                {
                    legalOrders.Add(Constants.ShipTN.OrderType.ResupplyFromTargetFleet);
                }
                if (Array.Exists(shipsArray, x => x.ShipClass.IsCollier))//if this fleet is targeted and has a IsCollier.
                {
                    legalOrders.Add(Constants.ShipTN.OrderType.ReloadFromTargetFleet);
                }

                legalOrders.Add(Constants.ShipTN.OrderType.LandOnAssignedMothership);
                legalOrders.Add(Constants.ShipTN.OrderType.LandOnMotherShipNoAssign);
                legalOrders.Add(Constants.ShipTN.OrderType.LandOnMothershipAssign);
                legalOrders.Add(Constants.ShipTN.OrderType.TractorSpecifiedShip);
                legalOrders.Add(Constants.ShipTN.OrderType.TractorSpecifiedShipyard);
            }
            return(legalOrders);
        }
Exemple #8
0
        /// <summary>
        /// Constructor for Jump 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="JPOrder">The Jump Point in question.</param>
        public Order(Constants.ShipTN.OrderType TypeOrder, int SecondaryOrder, int TertiaryOrder, int Delay, JumpPoint JPOrder)
        {
            TypeOf = TypeOrder;
            Target = JPOrder;
            Secondary = SecondaryOrder;
            Tertiary = TertiaryOrder;
            JumpPoint = JPOrder;
            OrderDelay = Delay;


            OrderTimeRequirement = -1;

            Name = TypeOrder.ToString() + " " + JPOrder.Name.ToString();
        }
 public JumpPointElement(JumpPoint jp)
     : base()
 {
     m_oJumpPoint = jp;
 }
Exemple #10
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 + ")";
        }