public static int TerraformPlanet(Planet planet, int money, int scienceLevel, bool automaticTerraform = false)
 {
     //Prendiamo il livello di scienza e troviamo il costo per alzare lo score come 512 / log del livello(+1 x evitare problemi)
     double lg = Math.Log(scienceLevel + 1);
     int costPerUnit = (int)(512 / lg);
     int units = money / costPerUnit; //trova di quanto si può alzare il terrascore al max a seconda dei soldi disponibili
     int ts = 32 - planet.Terrascore; //punteggio terrascore mancante al massimo
     if (units > ts) //Se è possibile superare il max x la disponibilità economica, allora raggiungi il max
         units = ts;
     if (automaticTerraform)
         planet.Terrascore += units;
     return units * costPerUnit; //ritorna il costo totale
 }
Example #2
0
 public Empire(string name, Religion.ReligionType religion, List<SolarSystem> knownSys, List<SolarSystem> ownedSys, List<Ship> fleet,
     List<Relation> relations, Planet capital)
 {
     empireName = name;
     empireReligion = religion;
     knownSystems = knownSys;
     ownedSystems = ownedSys;
     this.fleet = fleet;
     empireRelations = relations;
     capitalPlanet = capital;
     if (rnd == null)
         rnd = new Random();
     missingSecondsToUpdate = rnd.Next(1, 60);
 }
 public static void EnterSystem()
 {
     if (!GameManager.ActualSystem.IsDiscovered && GameManager.ActualSystemOwner != null)
     {
         GameManager.ActualSystemOwner.CreateNewRelation(GameManager.PlayerEmpire);
         GameManager.PlayerEmpire.CreateNewRelation(GameManager.ActualSystemOwner);
     }
     GameManager.ActualSystem.IsDiscovered = true;
     actualPlanet = null;
     foreach(Planet p in GameManager.ActualSystem.Planets)
     {
         if((actualPlanet != null && p.Terrascore > actualPlanet.Terrascore) || (actualPlanet == null && p.Terrascore > 0))
         {
             actualPlanet = p;
         }
     }
 }
        /// <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 si occupa dell'inizializzazione del gioco da file
        /// </summary>
        /// <param name="filePath">Percorso del file</param>
        public static void LoadGame(string filePath)
        {
            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();

            LoadGameClass.LoadFile(filePath);
            foreach(SolarSystem ss in PlayerEmpire.OwnedSystems)
                foreach (Planet p in ss.Planets)
                    if (p.PlanetSettlement != null)
                        playerCapital = p;
            GameWindow.SetState(LoadGameClass.State);
            GetActualPosition();
            isLoading = false;
        }
Example #6
0
 public void SetEmpireCapital(Planet p)
 {
     if (p.PlanetSettlement.Type == Settlement.SettlementType.CAPITAL)
         capitalPlanet = p;
 }
 static void DrawBackground(Planet planet)
 {
     if (GameManager.ActualSystemOwner == null || GameManager.ActualSystemOwner == GameManager.PlayerEmpire)
     {
         //Risorse
         spriteBatch.DrawString(font, "Risorse: " + planet.Resources.ToString("#,0."), new Vector2(110, 180), Color.Black);
         //Disegna livello terrascore
         spriteBatch.DrawString(font, "Terrascore: " + planet.Terrascore.ToString(), new Vector2(110, 230), Color.Black);
         spriteBatch.Draw(bar, new Vector2(110, 250), Color.Gray);
         Color barColor;
         if (planet.Terrascore < 16)
             barColor = Color.Red;
         else if (planet.Terrascore < 24)
             barColor = Color.Yellow;
         else
             barColor = Color.LimeGreen;
         spriteBatch.Draw(bar, new Rectangle(110, 250, bar.Width * planet.Terrascore / 32, bar.Height), barColor);
     }
     else
     {
         string txt = "Questo pianeta non è colonizzabile poiché\nun altro impero è il proprietario del sistema.";
         spriteBatch.DrawString(font, txt, new Vector2(GraphicSettings.CenterScreen.X - font.MeasureString(txt).X / 2, 180), Color.Black);
     }
 }
        public static void Draw(Planet planet)
        {
            spriteBatch.Begin();

            spriteBatch.Draw(rectangle, relativeScreen, Color.White);
            spriteBatch.DrawString(font, planet.Name, new Vector2(GraphicSettings.CenterScreen.X - font.MeasureString(planet.Name).X / 2, 110), Color.Red);
            closeButton.DrawButton(spriteBatch);

            spriteBatch.DrawString(font, GameManager.ActualSystem.Name, new Vector2(GraphicSettings.CenterScreen.X - font.MeasureString(GameManager.ActualSystem.Name).X / 2, 140), Color.Black);

            switch(state)
            {
                case PanelState.WAIT:
                    DrawBackground(planet);
                    DrawButtons(dishabitedButtons);
                    break;
                case PanelState.TERRAFORM:
                    DrawBackground(planet);
                    DrawButtons(dishabitedButtons);
                    selectionBox.DrawItem(spriteBatch);
                    break;
                case PanelState.FOUNDCOLONY:
                    DrawBackground(planet);
                    DrawButtons(colonyButtons);
                    break;
                case PanelState.AWAITCONFIRM:
                    DrawBackground(planet);
                    DrawButtons(ChoiceButtons);
                    string txt = "Per creare questa colonia dovrai pagare " + prize + ". Confermi?";
                    int xt = (int)font.MeasureString(txt).X;
                    int yt = (int)font.MeasureString(txt).Y;
                    int cx = (int)GraphicSettings.CenterScreen.X;
                    int cy = (int)GraphicSettings.CenterScreen.Y;
                    spriteBatch.DrawString(font, txt, new Vector2(cx - xt / 2, cy - yt - 10), Color.Black);
                    break;
            }

            spriteBatch.End();
        }
        public static void Draw(Planet planet)
        {
            spriteBatch.Begin();

            switch(state)
            {
                case PanelState.WAIT:
                    spriteBatch.Draw(rectangle, relativeScreen, Color.White);

                    spriteBatch.DrawString(font, planet.Name, new Vector2(GraphicSettings.CenterScreen.X - font.MeasureString(planet.Name).X / 2, 110), Color.Red);
                    closeButton.DrawButton(spriteBatch);

                    DrawIfInhabited(planet);
                    break;
                case PanelState.COMMERCE:
                    GameSystemDesigner.Draw();
                    CommerceUIDesigner.Draw();
                    break;
                case PanelState.GIFT:
                    spriteBatch.Draw(rectangle, relativeScreen, Color.White);
                    DrawIfInhabited(planet);
                    selectionBox.DrawItem(spriteBatch);
                    break;
            }

            spriteBatch.End();
        }
        private static void DrawIfInhabited(Planet planet)
        {
            int Width = GraphicSettings.ScreenBounds.Width;
            int Height = GraphicSettings.ScreenBounds.Height;

            spriteBatch.DrawString(font, "Impero " + GameManager.ActualSystemOwner.EmpireName, new Vector2(GraphicSettings.CenterScreen.X - font.MeasureString("Impero " + GameManager.ActualSystemOwner.EmpireName).X / 2, 140), Color.Black);
            //Disegna livello scienza
            spriteBatch.DrawString(font, "Livello scienza: " + LevelManager.ActualLevel(planet.PlanetSettlement.ScienceLevel).ToString(), new Vector2(110, 180), Color.Black);
            spriteBatch.Draw(bar, new Vector2(110, 200), Color.Gray);
            spriteBatch.Draw(bar, new Rectangle(110, 200, (int)((float)bar.Width * LevelManager.PercentLevel(planet.PlanetSettlement.ScienceLevel)), bar.Height), Color.LimeGreen);
            //Disegna livello commercio
            spriteBatch.DrawString(font, "Livello commercio: " + LevelManager.ActualLevel(planet.PlanetSettlement.CommerceLevel).ToString(), new Vector2(110, 230), Color.Black);
            spriteBatch.Draw(bar, new Vector2(110, 250), Color.Gray);
            spriteBatch.Draw(bar, new Rectangle(110, 250, (int)((float)bar.Width * LevelManager.PercentLevel(planet.PlanetSettlement.CommerceLevel)), bar.Height), Color.MonoGameOrange);
            //Disegna livell tecnologico
            spriteBatch.DrawString(font, "Livello tecnologico: " + LevelManager.ActualLevel(planet.PlanetSettlement.TecnoLevel).ToString(), new Vector2(110, 280), Color.Black);
            spriteBatch.Draw(bar, new Vector2(110, 300), Color.Gray);
            spriteBatch.Draw(bar, new Rectangle(110, 300, (int)((float)bar.Width * LevelManager.PercentLevel(planet.PlanetSettlement.TecnoLevel)), bar.Height), Color.MidnightBlue);
            //Disegna il numero di abitanti
            spriteBatch.DrawString(font, "Abitanti: " + ((long)planet.PlanetSettlement.Inhabitants * 1000).ToString("#,0."), new Vector2(110, 330), Color.Black);

            spriteBatch.DrawString(font, "Risorse: " + planet.Resources.ToString("#,0."), new Vector2(110, 360), Color.Black);

            //Disegna livello terrascore
            spriteBatch.DrawString(font, "Terrascore: " + planet.Terrascore.ToString(), new Vector2(110, 390), Color.Black);
            spriteBatch.Draw(bar, new Vector2(110, 410), Color.Gray);
            Color barColor;
            if(planet.Terrascore < 16)
                barColor = Color.Red;
            else if (planet.Terrascore < 24)
                barColor = Color.Yellow;
            else
                barColor = Color.LimeGreen;
            spriteBatch.Draw(bar, new Rectangle(110, 410, bar.Width * planet.Terrascore / 32, bar.Height), barColor);

            foreach (Button b in inhabitedButtons)
                b.DrawButton(spriteBatch);
        }
 public static void LoadWindowComponents(Planet commercePlanet)
 {
     selectedButton = "Buy";
     selectionItemOpened = false;
     planet = commercePlanet;
     LoadCommerceButtons();
     LoadInstrumentsButtons();
 }
        public static void SetTarget()
        {
            galaxyCamera.UpdateCamera(PlayerShip.Position);
            pointedPlanet = null;
            ///Se il giocatore ha cliccato con il mouse controlla se interseca un pianeta

            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);
        }
        static void SetTarget(Vector2 startingPosition, bool FromTouch = false)
        {
            Matrix view = galaxyCamera.CameraView;
            Matrix projection = galaxyCamera.CameraProjection;
            Viewport viewport = graphicsDevice.Viewport;

            foreach (Planet p in GameManager.ActualSystem.Planets)
            {
                if (RayIntersectCalcolator.Intersects(startingPosition, StaticStarModels.GetModel(p.PlanetType), p.GetWorld(), view, projection, viewport))
                {
                    pointedPlanet = p;
                }
            }
            if ((Mouse.GetState().LeftButton == ButtonState.Pressed || FromTouch) && pointedPlanet != null)
            {
                actualPlanet = pointedPlanet;
                PlayerShip.SetDestination(pointedPlanet.PlanetPosition);
                if (GameParams.soundEnabled)
                    shipStart.Play();
            }
            else if (actualPlanet != null)
                PlayerShip.SetPosition(actualPlanet.PlanetPosition);
        }
        public void CreatePlanets(bool playerStartingSystem = false)
        {
            planets = new List<Planet>();
            for (int i = 1; i < 10; i++)
            {
                if (rnd.Next(0, 3) != 0) // non si crea il pianeta
                    continue;
                bool habitable = i < 4 || i > 6 ? false : true; //Se i è tra 4 e 6 il pianeta è abitabile
                int score = habitable ? rnd.Next(0, 32) : 0; //e gli si da un terrascore
                Vector3 startPosition = systemPosition;
                startPosition.X += i * 60; //posizione iniziale del pianeta
                string type;
                if (i <= 6)
                    type = "Type" + rnd.Next(1, 10); //Tipo del pianeta, se in posizione fino a 6 è roccioso, altrimenti gassoso
                else
                    type = "Gas" + rnd.Next(1, 9);
                Planet p = new Planet(habitable, score, startPosition, systemPosition, type, i * 60);//Crea il pianeta
                planets.Add(p); //ed aggiungilo alla lista
            }
            if(playerStartingSystem)
            {
                bool created = false;
                foreach(Planet p in planets)
                    if(p.IsHabitable)
                    {
                        p.Terrascore = 32;
                        Settlement settlement = new Settlement(Settlement.SettlementType.CAPITAL, GameParams.religionType);
                        p.CreateSettlement(settlement);
                        created = true;
                        break;
                    }
                if(!created)
                {
                    Vector3 startPosition = systemPosition;
                    startPosition.X += rnd.Next(4,7) * 60; //posizione iniziale del pianeta
                    string type = "Type" + rnd.Next(1, 10); //Tipo del pianeta, se in posizione fino a 6 è roccioso, altrimenti gassoso

                    Planet p = new Planet(true, 32, startPosition, systemPosition, type, startPosition.X - systemPosition.X);//Crea il pianeta
                    Settlement settlement = new Settlement(Settlement.SettlementType.CAPITAL, GameParams.religionType);
                    p.CreateSettlement(settlement);
                    planets.Add(p); //ed aggiungilo alla lista
                }
            }
        }
 public static void EnterPlanet(Planet planet)
 {
     actualPlanet = planet;
 }