Ejemplo n.º 1
0
        public List <StarSystem> FindPath(StarSystem start, StarSystem finish, Ship ship)
        {
            List <StarSystem> path = new List <StarSystem>();

            path.Add(start);

            //If our destination is within jump distance, return the path with just start/finish
            if (start.Coordinates.Distance(finish.Coordinates) <= ship.JumpRadius)
            {
                path.Add(finish);
                return(path);
            }

            bool pathFinished = false;

            while (!pathFinished)
            {
                List <StarSystem> weightedList = new List <StarSystem>();

                foreach (StarSystem testSystem in GameManager.Systems)
                {
                    StarSystem currentSystem = path[path.Count - 1];
                    if (currentSystem.ID == testSystem.ID)
                    {
                        continue;
                    }
                    if (pathContains(path, testSystem))
                    {
                        continue;
                    }

                    double value = 0;

                    double distToFinish = currentSystem.Coordinates.Distance(finish.Coordinates);
                    double testToFinish = testSystem.Coordinates.Distance(finish.Coordinates);
                    double distToTest   = currentSystem.Coordinates.Distance(testSystem.Coordinates);

                    //The test system is the destination
                    if (testSystem.ID == finish.ID)
                    {
                        if (currentSystem.Coordinates.Distance(testSystem.Coordinates) < ship.JumpRadius)
                        {
                            path.Add(testSystem);
                            return(path);
                        }
                        value += 100.0;
                    }
                    else
                    {
                        //If the system gets us closer to our destination
                        Vector2 firstDirection  = finish.Coordinates - currentSystem.Coordinates;
                        Vector2 secondDirection = testSystem.Coordinates - currentSystem.Coordinates;

                        firstDirection.Normalize();
                        secondDirection.Normalize();

                        float dot = Vector2.Dot(firstDirection, secondDirection);
                        value += (int)(dot * 100.0);
                    }

                    value += (distToTest <= ship.JumpRadius) ? 25.0 : -40.0;
                    value += (distToTest < distToFinish) ? 20.0 : 0.0;

                    //Modify value based on distance
                    double dist = currentSystem.Coordinates.Distance(testSystem.Coordinates);
                    value += 1 - dist / 30.0;
                    testSystem.WeightedValue = value;

                    weightedList.Add(testSystem);
                }

                weightedList.Sort();
                StarSystem chosenSystem = weightedList[weightedList.Count - 1];
                path.Add(chosenSystem);

                if (chosenSystem.ID == finish.ID)
                {
                    return(path);
                }
            }

            throw new NotImplementedException();
        }
Ejemplo n.º 2
0
 public void MoveTo(StarSystem system)
 {
     MoveAlongPath(GameManager.Pathfinder.FindPath(Ship.CurrentSystem, system, Ship));
 }
Ejemplo n.º 3
0
        public void GenerateGalaxy()
        {
            //Game simulates 10 days, starting the game 1/1/2347
            galacticDate = new DateTime(2346, 12, 22);

            cleanUpGalaxy();

            //Sol System
            StarSystem solSystem = new StarSystem("Sol")
            {
                Coordinates = OpenTK.Vector2.Zero
            };

            solSystem.StarColor = OpenTK.Graphics.Color4.Yellow;

            //Terra
            Planetoid terra = new Planetoid(solSystem, "Terra");
            Planetoid luna  = new Planetoid(solSystem, "Luna", terra);

            //Mars
            Planetoid mars   = new Planetoid(solSystem, "Mars");
            Planetoid phobos = new Planetoid(solSystem, "Phobos", mars);
            Planetoid deimos = new Planetoid(solSystem, "Deimos", mars);

            //Jupiter
            Planetoid jupiter  = new Planetoid(solSystem, "Jupiter");
            Planetoid io       = new Planetoid(solSystem, "Io", jupiter);
            Planetoid europa   = new Planetoid(solSystem, "Europa", jupiter);
            Planetoid ganymede = new Planetoid(solSystem, "Ganymede", jupiter);
            Planetoid callisto = new Planetoid(solSystem, "Callisto", jupiter);

            solSystem.Planetoids.Add(terra);
            solSystem.Planetoids.Add(mars);
            solSystem.Planetoids.Add(jupiter);

            systems.Add(solSystem);
            systems.AddRange(Factories.GalaxyFactory.GenerateGalaxy(250, 500));

            //Generate Factions
            int numFactions = RNG.Next(5, 10);

            for (int i = 0; i < numFactions; i++)
            {
                Faction faction = Factories.FactionFactory.GenerateRandomFaction(this);

                //Build markets, stations, and factories.  Add ships.
                int numSystems = RNG.Next(3, 6);
                for (int k = 0; k < numSystems; k++)
                {
                    StarSystem system = systems[RNG.Next(0, systems.Count)];

                    //Ensure planets exist in the system
                    while (system.Planetoids.Count == 0 || system.HasMarket)
                    {
                        system = systems[RNG.Next(0, systems.Count)];
                    }

                    system.BuildMarket(faction);

                    foreach (Planetoid planet in system.Planetoids)
                    {
                        planet.BuildStation(faction);

                        //Try to build a factory
                        if (RNG.Next(0, 100) < 50)
                        {
                            Product product = Factories.ProductFactory.ProductList[RNG.Next(0, Factories.ProductFactory.ProductList.Length)];
                            planet.BuildFactory(faction, product);
                        }
                        else
                        {
                            Blueprint blueprint = new Blueprint(Factories.ModFactory.ModList[RNG.Next(0, Factories.ModFactory.ModList.Count)]);
                            planet.BuildFactory(faction, blueprint);
                        }
                    }
                }

                //Add a number of ships
                int numShips = RNG.Next(35, 50);
                for (int k = 0; k < numShips; k++)
                {
                    Ship ship = Factories.ShipFactory.ConstructRandomShip();
                    ship.Name = Factories.ShipFactory.GenerateRandomShipName();

                    ship.SetPilot(new Pilot(this, "Mark Webber", ship, false));
                    ship.SetCurrentSystem(Systems[0]); //Default to Sol system (for now)

                    faction.RegisterShip(ship);
                    Ships.Add(ship);
                }

                factions.Add(faction);
            }
        }
Ejemplo n.º 4
0
 public PilotFinishedTravelingEventArgs(Ship ship, Pilot pilot, StarSystem system)
 {
     Ship        = ship;
     Pilot       = pilot;
     Destination = system;
 }