Esempio n. 1
0
 public void Reconcilate(EmpireManager empireManager)
 {
     foreach (var star in starSystems)
     {
         //Set the empire
         foreach (var planet in star.Planets)
         {
             if (planet.OwnerID != -1)
             {
                 planet.Owner   = empireManager.GetEmpire(planet.OwnerID);
                 planet.OwnerID = -1;                         //Clear out the ID
                 planet.Owner.PlanetManager.AddOwnedPlanet(planet);
                 planet.ShipBeingBuilt = planet.Owner.FleetManager.GetShipWithDesignID(planet.ShipBeingBuiltID);
             }
         }
         star.UpdateOwners();
         if (string.IsNullOrEmpty(star.ExploredByIDs))
         {
             //No empires explored this star yet.
             continue;
         }
         string[] exploredBy = star.ExploredByIDs.Split(new[] { ',' });
         foreach (var explored in exploredBy)
         {
             star.AddEmpireExplored(empireManager.GetEmpire(int.Parse(explored)));
         }
     }
 }
Esempio n. 2
0
        public void SaveGame(string filename)
        {
            XDocument saveGame = new XDocument();

            using (XmlWriter writer = saveGame.CreateWriter())
            {
                writer.WriteStartDocument();
                writer.WriteStartElement("SaveGameData");
                Galaxy.Save(writer);
                EmpireManager.Save(writer);
                writer.WriteEndElement();
                writer.WriteEndDocument();
            }
            try
            {
                string path = Path.Combine(GameDataSet.FullName, "Saves");
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                path = Path.Combine(path, filename + ".BB");
                saveGame.Save(path);
            }
            catch (Exception e)
            {
                MessageBox.Show("Failed to save file, reason: " + e.Message);
            }
        }
Esempio n. 3
0
 public void ClearAll()
 {
     //Used when exiting out of current game (new game for example)
     EmpireManager = new EmpireManager(this);
     _situationReport.Clear();
     _newGame.Clear();
 }
Esempio n. 4
0
        public bool LoadGame(string filename)
        {
            string path = Path.Combine(GameDataSet.FullName, "Saves");

            if (!Directory.Exists(path))
            {
                //No folder exists, impossible to load anything
                return(false);
            }
            try
            {
                XDocument doc  = XDocument.Load(Path.Combine(path, filename));
                XElement  root = doc.Root;
                if (!Galaxy.Load(root, this))
                {
                    return(false);
                }
                if (!EmpireManager.Load(root))
                {
                    return(false);
                }
                Galaxy.Reconcilate(EmpireManager);
                if (_galaxyScreen != null)
                {
                    _galaxyScreen.ResetCamera();
                }
                if (_processingTurnScreen != null)
                {
                    _processingTurnScreen.ResetCamera();
                }
                ChangeToScreen(Screen.Galaxy);
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Esempio n. 5
0
        public bool Initalize(int screenWidth, int screenHeight, DirectoryInfo dataSet, bool showTutorial, Form parentForm, out string reason)
        {
            _parentForm = parentForm;

            Random = new Random();

            MousePos = new Point();

            ScreenWidth = screenWidth;
            ScreenHeight = screenHeight;
            GameDataSet = dataSet;

            Galaxy = new Galaxy();
            EmpireManager = new EmpireManager(this);

            ShipShader = GorgonLibrary.Graphics.FXShader.FromFile("ColorShader.fx", GorgonLibrary.Graphics.ShaderCompileOptions.OptimizationLevel3);
            StarShader = GorgonLibrary.Graphics.FXShader.FromFile("StarShader.fx", GorgonLibrary.Graphics.ShaderCompileOptions.OptimizationLevel3);

            if (!SpriteManager.Initialize(GameDataSet, out reason))
            {
                return false;
            }
            if (!FontManager.Initialize(GameDataSet, out reason))
            {
                return false;
            }
            RaceManager = new RaceManager();
            if (!RaceManager.Initialize(GameDataSet, Random, out reason))
            {
                return false;
            }
            AIManager = new AIManager();
            if (!AIManager.Initialize(GameDataSet, out reason))
            {
                return false;
            }
            MasterTechnologyManager = new MasterTechnologyManager();
            if (!MasterTechnologyManager.Initialize(this, out reason))
            {
                return false;
            }
            _mainGameMenu = new MainGameMenu();
            if (!_mainGameMenu.Initialize(this, out reason))
            {
                return false;
            }

            _screenInterface = _mainGameMenu;
            _currentScreen = Screen.MainMenu;

            _situationReport = new SituationReport(this);

            Cursor = SpriteManager.GetSprite("Cursor", Random);
            if (Cursor == null)
            {
                reason = "Cursor is not defined in sprites.xml";
                return false;
            }

            reason = string.Empty;
            return true;
        }
Esempio n. 6
0
 public void ClearAll()
 {
     //Used when exiting out of current game (new game for example)
     EmpireManager = new EmpireManager(this);
     _situationReport.Clear();
     _newGame.Clear();
 }
Esempio n. 7
0
 public void Reconcilate(EmpireManager empireManager)
 {
     foreach (var star in starSystems)
     {
         //Set the empire
         foreach (var planet in star.Planets)
         {
             if (planet.OwnerID != -1)
             {
                 planet.Owner = empireManager.GetEmpire(planet.OwnerID);
                 planet.OwnerID = -1; //Clear out the ID
                 planet.Owner.PlanetManager.AddOwnedPlanet(planet);
                 planet.ShipBeingBuilt = planet.Owner.FleetManager.GetShipWithDesignID(planet.ShipBeingBuiltID);
             }
         }
         star.UpdateOwners();
         if (string.IsNullOrEmpty(star.ExploredByIDs))
         {
             //No empires explored this star yet.
             continue;
         }
         string[] exploredBy = star.ExploredByIDs.Split(new[] { ',' });
         foreach (var explored in exploredBy)
         {
             star.AddEmpireExplored(empireManager.GetEmpire(int.Parse(explored)));
         }
     }
 }
Esempio n. 8
0
        public bool Initalize(int screenWidth, int screenHeight, DirectoryInfo dataSet, bool showTutorial, Form parentForm, out string reason)
        {
            _parentForm = parentForm;

            Random = new Random();

            MousePos = new Point();

            ScreenWidth  = screenWidth;
            ScreenHeight = screenHeight;
            GameDataSet  = dataSet;

            Galaxy        = new Galaxy();
            EmpireManager = new EmpireManager(this);

            ShipShader = GorgonLibrary.Graphics.FXShader.FromFile("ColorShader.fx", GorgonLibrary.Graphics.ShaderCompileOptions.OptimizationLevel3);
            StarShader = GorgonLibrary.Graphics.FXShader.FromFile("StarShader.fx", GorgonLibrary.Graphics.ShaderCompileOptions.OptimizationLevel3);

            if (!SpriteManager.Initialize(GameDataSet, out reason))
            {
                return(false);
            }
            if (!FontManager.Initialize(GameDataSet, out reason))
            {
                return(false);
            }
            RaceManager = new RaceManager();
            if (!RaceManager.Initialize(GameDataSet, Random, out reason))
            {
                return(false);
            }
            AIManager = new AIManager();
            if (!AIManager.Initialize(GameDataSet, out reason))
            {
                return(false);
            }
            MasterTechnologyManager = new MasterTechnologyManager();
            if (!MasterTechnologyManager.Initialize(this, out reason))
            {
                return(false);
            }
            _mainGameMenu = new MainGameMenu();
            if (!_mainGameMenu.Initialize(this, out reason))
            {
                return(false);
            }

            _screenInterface = _mainGameMenu;
            _currentScreen   = Screen.MainMenu;

            _situationReport = new SituationReport(this);

            Cursor = SpriteManager.GetSprite("Cursor", Random);
            if (Cursor == null)
            {
                reason = "Cursor is not defined in sprites.xml";
                return(false);
            }

            reason = string.Empty;
            return(true);
        }
Esempio n. 9
0
        public void ChangeToScreen(Screen whichScreen)
        {
            switch (whichScreen)
            {
            case Screen.MainMenu:
                if (_mainGameMenu == null)
                {
                    _mainGameMenu = new MainGameMenu();
                    string reason;
                    if (!_mainGameMenu.Initialize(this, out reason))
                    {
                        MessageBox.Show("Exception in loading Main Menu. Reason: " + reason);
                        _parentForm.Close();
                    }
                }
                _screenInterface = _mainGameMenu;
                break;

            case Screen.NewGame:
                if (_newGame == null)
                {
                    _newGame = new NewGame();
                    string reason;
                    if (!_newGame.Initialize(this, out reason))
                    {
                        MessageBox.Show("Exception in loading New Game Menu. Reason: " + reason);
                        _parentForm.Close();
                    }
                }
                _screenInterface = _newGame;
                break;

            case Screen.Galaxy:
                if (_galaxyScreen == null)
                {
                    _galaxyScreen = new GalaxyScreen();
                    string reason;
                    if (!_galaxyScreen.Initialize(this, out reason))
                    {
                        MessageBox.Show("Exception in loading Galaxy Screen. Reason: " + reason);
                        _parentForm.Close();
                    }
                }
                _galaxyScreen.CenterScreen();
                _screenInterface = _galaxyScreen;
                break;

            case Screen.Diplomacy:
                if (_diplomacyScreen == null)
                {
                    _diplomacyScreen = new DiplomacyScreen();
                    string reason;
                    if (!_diplomacyScreen.Initialize(this, out reason))
                    {
                        MessageBox.Show("Exception in loading Diplomacy Screen. Reason: " + reason);
                        _parentForm.Close();
                    }
                }
                _diplomacyScreen.SetupScreen();
                _screenInterface = _diplomacyScreen;
                break;

            case Screen.ProcessTurn:
                EmpireManager.CurrentEmpire.ClearTurnData();
                if (_processingTurnScreen == null)
                {
                    _processingTurnScreen = new ProcessingTurnScreen();
                    string reason;
                    if (!_processingTurnScreen.Initialize(this, out reason))
                    {
                        MessageBox.Show("Exception in loading Processing Turn Screen. Reason: " + reason);
                        _parentForm.Close();
                    }
                }
                if (!EmpireManager.ProcessNextEmpire())
                {
                    _situationReport.Refresh();
                    ChangeToScreen(Screen.Galaxy);
                    break;
                }
                _screenInterface = _processingTurnScreen;
                break;

            case Screen.Battle:
                /*if (_spaceCombat == null)
                 * {
                 *      _spaceCombat = new SpaceCombat();
                 *      _spaceCombat.Initialize(this);
                 * }
                 * _spaceCombat.SetupScreen();
                 * _screenInterface = _spaceCombat;*/
                break;
            }
            _currentScreen = whichScreen;
        }