public static void GetActualPosition()
 {
     foreach (SolarSystem ss in solarSystems)
     {
         if (ss.SystemPosition.X == PlayerShip.Position.X && ss.SystemPosition.Z == PlayerShip.Position.Z)
         {
             actualSystem = ss;
             SystemOwner(); // ottieni l'impero proprietario del sistema
         }
     }
 }
Esempio n. 2
0
 public Empire(SolarSystem startingSystem, Religion.ReligionType religion, string name)
 {
     knownSystems = new List<SolarSystem>();
     ownedSystems = new List<SolarSystem>();
     ownedSystems.Add(startingSystem);
     fleet = new List<Ship>();
     empireRelations = new List<Relation>();
     empireReligion = religion;
     empireName = name;
     if(rnd == null)
        rnd = new Random();
     missingSecondsToUpdate = rnd.Next(1, 60);
 }
Esempio n. 3
0
 public Empire(SolarSystem startingSystem)
 {
     knownSystems = new List<SolarSystem>();
     ownedSystems = new List<SolarSystem>();
     ownedSystems.Add(startingSystem);
     fleet = new List<Ship>();
     empireRelations = new List<Relation>();
     empireReligion = Religion.GetRandomReligion();
     empireName = NameGenerator.GetName(4);
     if(rnd == null)
        rnd = new Random();
     missingSecondsToUpdate = rnd.Next(1, 60);
 }
        public static void SetTarget()
        {
            galaxyCamera.UpdateCamera(PlayerShip.Position);
            pointedSystem = null;

            Vector2 clickPosition = new Vector2(0, 0);

            #if WINDOWS
            clickPosition = Mouse.GetState().Position.ToVector2();
            #endif

            if (TouchPanel.GetState().IsConnected)
            {
                TouchCollection touches = TouchPanel.GetState();
                if (touches.Count > 0)
                    foreach (var touch in touches)
                        SetTarget(touch.Position, true);
                else
                    SetTarget(clickPosition, false);
            }
            else
                SetTarget(clickPosition, false);
        }
        /// <summary>
        /// Metodo che crea un nuovo gioco
        /// </summary>
        public static void NewGame()
        {
            isLoading = true;
            // Crea una nuova lista e cancellala se era già stata creata in precedenza
            solarSystems = new List<SolarSystem>();
            solarSystems.Clear();
            // Fai lo stesso per gli imperi
            empires = new List<Empire>();
            empires.Clear();
            // Prendi il numero dei sistemi e degli imperi
            int systems = GameParams.starNumber;
            int numEmpires = GameParams.empireNumber;

            List<Vector3> vect = new List<Vector3>();
            for (int i = -1 * systems / 2; i < systems / 2; i++)
                for (int j = -1 * systems / 2; j < systems / 2; j++)
                    vect.Add(new Vector3(i * 32, 0, j * 32));

            vect.Remove(new Vector3(0, 0, 0));
            Random rnd = new Random();
            for (int i = 0; i < systems; i++)
            {
                int index = rnd.Next(0, vect.Count);
                Vector3 pos = vect[index];
                SolarSystem solar = new SolarSystem(pos);
                solarSystems.Add(solar);
                vect.RemoveAt(index);
            }
            vect.Clear();
            // Crea i pianeti per ogni sistema solare
            foreach (SolarSystem ss in solarSystems)
                ss.CreatePlanets();
            // Crea gli imperi
            CreateEmpires();
            //Crea il sistema solare di partenza per il giocatore
            SolarSystem startingSystem = new SolarSystem(new Vector3(0, 0, 0));
            startingSystem.IsDiscovered = true;
            startingSystem.CreatePlanets(true);
            if (GameParams.name == null)
                GameParams.name = NameGenerator.GetName();
            playerEmpire = new Empire(startingSystem, GameParams.religionType, GameParams.name);
            solarSystems.Add(startingSystem);
            foreach (Planet p in startingSystem.Planets)
                if (p.PlanetSettlement != null)
                    playerCapital = p;

            //empires.Add(playerEmpire);
            PlayerShip.Initialize(new Vector3(0, 50, 0), 1500, 500);

            isLoading = false;
        }
        /// <summary>
        /// Metodo che aggiorna il gioco
        /// </summary>
        /// <param name="gameTime">GameTime per ottenere i secondi di gioco</param>
        public static void Update(GameTime gameTime)
        {
            // Ottieni i secondi attuali di gioco e aggiorna la nave del giocatore
            int now = gameTime.TotalGameTime.Seconds;
            PlayerShip.Update();
            foreach (SolarSystem ss in solarSystems)
            {
                // Aggiorna le posizioni dei pianeti
                ss.UpdatePosition();
                if (ss.SystemPosition.X == PlayerShip.Position.X && ss.SystemPosition.Z == PlayerShip.Position.Z)
                {
                    actualSystem = ss;
                    SystemOwner(); // ottieni l'impero proprietario del sistema
                }
                // Aggiorna il sistema ogni 5 secondi (evita così sovraccarico di calcoli)
                if (now != lastSecondUpdate && now % 5 == 0)
                    ss.UpdateSystem();
            }
            // Aggiorna l'impero ogni secondo
            if (now != lastSecondUpdate && now % 1 == 0)
            {
                foreach (Empire e in empires)
                    e.Update();
            }

            lastSecondUpdate = now;
        }
 /// <summary>
 /// Metodo che controlla il proprietario del sistema specificato
 /// </summary>
 /// <param name="solarSys">Sistema solare</param>
 /// <returns>Impero proprietario</returns>
 public static Empire SystemOwner(SolarSystem solarSys)
 {
     Empire Owner = null;
     foreach (SolarSystem ss in playerEmpire.OwnedSystems)
         if (ss == solarSys)
             Owner = playerEmpire;
     if (Owner == null)
     {
         foreach (Empire e in empires)
         {
             foreach (SolarSystem ss in e.OwnedSystems)
                 if (ss == solarSys)
                     Owner = e;
         }
     }
     return Owner;
 }
        static void SetTarget(Vector2 startingPosition, bool FromTouch = false)
        {
            Matrix view = galaxyCamera.CameraView;
            Matrix projection = galaxyCamera.CameraProjection;
            Viewport viewport = graphicsDevice.Viewport;

            foreach (SolarSystem ss in GameManager.SolarSystems)
            {
                if (RayIntersectCalcolator.Intersects(startingPosition, StaticStarModels.GetModel(ss.StarType), ss.GetWorld(), view, projection, viewport))
                {
                    pointedSystem = ss;
                }
            }
            if ((Mouse.GetState().LeftButton == ButtonState.Pressed || FromTouch) && pointedSystem != null)
            {
                PlayerShip.SetDestination(pointedSystem.SystemPosition);
                if (GameParams.soundEnabled)
                    shipStart.Play();
            }
        }
        /// <summary>
        /// Metodo che legge il sistema solare da XML
        /// </summary>
        /// <param name="xr">Lettore XML</param>
        /// <returns>Istanza del SistemaSolare</returns>
        static SolarSystem ReadSystem(XmlReader xr)
        {
            List<Planet> planets = new List<Planet>();
            Planet actualPlanet = null;

            //Attributi del sistema
            string name = "", starType = "";
            bool discovered = false, inhabited = false;
            Vector3 position = new Vector3();

            while(xr.MoveToNextAttribute())
            {
                switch(xr.Name)
                {//NAME="Mestu" POSITION="{X:-64 Y:0 Z:-32}" TYPE="Red" DISCOVERED="True" INHABITED="True"
                    case "NAME":
                        name = xr.Value;
                        break;
                    case "POSITION":
                        position = NewVector3FromString(xr.Value);
                        break;
                    case "TYPE":
                        starType = xr.Value;
                        break;
                    case "DISCOVERED":
                        discovered = xr.ReadContentAsBoolean();
                        break;
                    case "INHABITED":
                        inhabited = xr.ReadContentAsBoolean();
                        break;
                }
            }

            while (xr.Read() && !(xr.Name == "SYSTEM" && xr.NodeType == XmlNodeType.EndElement))
            {
                if (xr.NodeType == XmlNodeType.EndElement)
                    continue;
                switch (xr.Name)
                {
                    case "PLANET":
                        actualPlanet = ReadPlanet(xr, position);
                        planets.Add(actualPlanet);
                        break;
                    case "SETTLEMENT":
                        actualPlanet.CreateSettlement(ReadSettlement(xr));
                        break;
                    case "PRODUCTS":
                        actualPlanet.PlanetSettlement.SetProducts(ReadProducts(xr));
                        break;
                }
            }

            SolarSystem ss = new SolarSystem(name, position, starType, discovered, inhabited, planets);
            return ss;
        }