public EmpireManager(GameMain gameMain) { _gameMain = gameMain; _empires = new List<Empire>(); empireIter = -1; //combatsToProcess = new List<CombatToProcess>(); }
public Empire(string emperorName, int empireID, Race race, PlayerType type, Color color, GameMain gameMain) : this() { Reserves = 0; TaxRate = 0; this.empireName = emperorName; this.empireID = empireID; this.type = type; EmpireColor = color; try { TechnologyManager.SetComputerTechs(gameMain.MasterTechnologyManager.GetRandomizedComputerTechs()); TechnologyManager.SetConstructionTechs(gameMain.MasterTechnologyManager.GetRandomizedConstructionTechs()); TechnologyManager.SetForceFieldTechs(gameMain.MasterTechnologyManager.GetRandomizedForceFieldTechs()); TechnologyManager.SetPlanetologyTechs(gameMain.MasterTechnologyManager.GetRandomizedPlanetologyTechs()); TechnologyManager.SetPropulsionTechs(gameMain.MasterTechnologyManager.GetRandomizedPropulsionTechs()); TechnologyManager.SetWeaponTechs(gameMain.MasterTechnologyManager.GetRandomizedWeaponTechs()); } catch (Exception e) { MessageBox.Show(e.Message); } EmpireRace = race; }
public bool Initialize(GameMain gameMain, out string reason) { _gameMain = gameMain; _taskButtons = new BBStretchButton[7]; int width = gameMain.ScreenWidth / 7; int offset = gameMain.ScreenWidth - (width * 7); //account for integer rounding _top = gameMain.ScreenHeight - 50; int x = 0; for (int i = 0; i < _taskButtons.Length; i++) { _taskButtons[i] = new BBStretchButton(); } if (!_taskButtons[0].Initialize("Game Menu", ButtonTextAlignment.CENTER, StretchableImageType.ThinBorderBG, StretchableImageType.ThinBorderFG, x, _top, width, 50, gameMain.Random, out reason)) { return false; } x += width; if (!_taskButtons[1].Initialize("Design Ships", ButtonTextAlignment.CENTER, StretchableImageType.ThinBorderBG, StretchableImageType.ThinBorderFG, x, _top, width, 50, gameMain.Random, out reason)) { return false; } x += width; if (!_taskButtons[2].Initialize("Fleets Overview", ButtonTextAlignment.CENTER, StretchableImageType.ThinBorderBG, StretchableImageType.ThinBorderFG, x, _top, width, 50, gameMain.Random, out reason)) { return false; } x += width; if (!_taskButtons[3].Initialize("Diplomacy", ButtonTextAlignment.CENTER, StretchableImageType.ThinBorderBG, StretchableImageType.ThinBorderFG, x, _top, width, 50, gameMain.Random, out reason)) { return false; } x += width; if (!_taskButtons[4].Initialize("Planets Overview", ButtonTextAlignment.CENTER, StretchableImageType.ThinBorderBG, StretchableImageType.ThinBorderFG, x, _top, width, 50, gameMain.Random, out reason)) { return false; } x += width; if (!_taskButtons[5].Initialize("Manage Research", ButtonTextAlignment.CENTER, StretchableImageType.ThinBorderBG, StretchableImageType.ThinBorderFG, x, _top, width, 50, gameMain.Random, out reason)) { return false; } x += width; if (!_taskButtons[6].Initialize("End Turn", ButtonTextAlignment.CENTER, StretchableImageType.ThinBorderBG, StretchableImageType.ThinBorderFG, x, _top, width + offset, 50, gameMain.Random, out reason)) { return false; } _hide = false; reason = null; return true; }
public void Load(XElement empireToLoad, GameMain gameMain) { empireID = int.Parse(empireToLoad.Attribute("ID").Value); empireName = empireToLoad.Attribute("Name").Value; EmpireColor = Color.FromArgb(int.Parse(empireToLoad.Attribute("Color").Value)); EmpireRace = gameMain.RaceManager.GetRace(empireToLoad.Attribute("Race").Value); type = bool.Parse(empireToLoad.Attribute("IsHumanPlayer").Value) ? PlayerType.HUMAN : PlayerType.CPU; lastSelectedSystem = gameMain.Galaxy.GetStarWithID(int.Parse(empireToLoad.Attribute("SelectedSystem").Value)); TechnologyManager.Load(empireToLoad, gameMain.MasterTechnologyManager); FleetManager.Load(empireToLoad, this, gameMain); }
public bool Load(XElement root, GameMain gameMain) { var galaxyElement = root.Element("Galaxy"); if (galaxyElement == null) { return false; } GalaxySize = int.Parse(galaxyElement.Attribute("Width").Value); starSystems = new List<StarSystem>(); _quickLookupSystem = new Dictionary<int, StarSystem>(); var starsElement = galaxyElement.Element("Stars"); foreach (var star in starsElement.Elements()) { string name = star.Attribute("Name").Value; string description = star.Attribute("Description").Value; int id = int.Parse(star.Attribute("ID").Value); int xPos = int.Parse(star.Attribute("XPos").Value); int yPos = int.Parse(star.Attribute("YPos").Value); string[] color = star.Attribute("Color").Value.Split(new[] {','}); float[] starColor = new float[4]; for (int i = 0; i < 4; i++) { starColor[i] = float.Parse(color[i]); } StarSystem newStar = new StarSystem(name, id, xPos, yPos, Color.FromArgb((int)(255 * starColor[3]), (int)(255 * starColor[0]), (int)(255 * starColor[1]), (int)(255 * starColor[2])), description, gameMain.Random); newStar.ExploredByIDs = star.Attribute("ExploredBy").Value; foreach (var planetElement in star.Elements()) { string planetName = planetElement.Attribute("Name").Value; string type = planetElement.Attribute("Type").Value; int owner = -1; if (!string.IsNullOrEmpty(planetElement.Attribute("Owner").Value)) { owner = int.Parse(planetElement.Attribute("Owner").Value); } int populationMax = int.Parse(planetElement.Attribute("MaxPopulation").Value); var newPlanet = new Planet(planetName, type, populationMax, null, newStar, gameMain.Random); newPlanet.OwnerID = owner; newPlanet.Factories = float.Parse(planetElement.Attribute("Buildings").Value); newPlanet.EnvironmentAmount = int.Parse(planetElement.Attribute("EnvironmentPercentage").Value); newPlanet.InfrastructureAmount = int.Parse(planetElement.Attribute("InfrastructurePercentage").Value); newPlanet.DefenseAmount = int.Parse(planetElement.Attribute("DefensePercentage").Value); newPlanet.ConstructionAmount = int.Parse(planetElement.Attribute("ConstructionPercentage").Value); newPlanet.ResearchAmount = int.Parse(planetElement.Attribute("ResearchPercentage").Value); newPlanet.EnvironmentLocked = bool.Parse(planetElement.Attribute("EnvironmentLocked").Value); newPlanet.InfrastructureLocked = bool.Parse(planetElement.Attribute("InfrastructureLocked").Value); newPlanet.DefenseLocked = bool.Parse(planetElement.Attribute("DefenseLocked").Value); newPlanet.ConstructionLocked = bool.Parse(planetElement.Attribute("ConstructionLocked").Value); newPlanet.ResearchLocked = bool.Parse(planetElement.Attribute("ResearchLocked").Value); newPlanet.ShipBeingBuiltID = int.Parse(planetElement.Attribute("ShipBuilding").Value); newPlanet.ShipConstructionAmount = float.Parse(planetElement.Attribute("AmountBuilt").Value); newPlanet.RelocateToSystemID = int.Parse(planetElement.Attribute("RelocatingTo").Value); var transferTo = planetElement.Element("TransferTo"); if (transferTo != null) { newPlanet.TransferSystemID = new KeyValuePair<int, int>(int.Parse(transferTo.Attribute("StarSystem").Value), int.Parse(transferTo.Attribute("Amount").Value)); } var races = planetElement.Element("Races"); foreach (var race in races.Elements()) { newPlanet.AddRacePopulation(gameMain.RaceManager.GetRace(race.Attribute("RaceName").Value), float.Parse(race.Attribute("Amount").Value)); } newStar.Planets.Add(newPlanet); } starSystems.Add(newStar); _quickLookupSystem.Add(newStar.ID, newStar); } //Now match up IDs to actual classes foreach (var starSystem in starSystems) { foreach (var planet in starSystem.Planets) { if (planet.RelocateToSystemID != -1) { planet.RelocateToSystem = new TravelNode {StarSystem = _quickLookupSystem[planet.RelocateToSystemID]}; planet.RelocateToSystemID = -1; } if (!planet.TransferSystemID.Equals(new KeyValuePair<int, int>())) { planet.TransferSystem = new KeyValuePair<TravelNode, int>(new TravelNode { StarSystem = _quickLookupSystem[planet.TransferSystemID.Key] }, planet.TransferSystemID.Value); } } } return true; }
private static Equipment LoadEquipment(string equipmentName, GameMain gameMain) { bool useSecondary = equipmentName.EndsWith("|Sec"); string actualTechName = useSecondary ? equipmentName.Substring(0, equipmentName.Length - 4) : equipmentName; return new Equipment(gameMain.MasterTechnologyManager.GetTechnologyWithName(actualTechName), useSecondary); }
public void Load(XElement shipDesign, GameMain gameMain) { Name = shipDesign.Attribute("Name").Value; DesignID = int.Parse(shipDesign.Attribute("DesignID").Value); Size = int.Parse(shipDesign.Attribute("Size").Value); WhichStyle = int.Parse(shipDesign.Attribute("WhichStyle").Value); Engine = new KeyValuePair<Equipment, float>(LoadEquipment(shipDesign.Attribute("Engine").Value, gameMain), float.Parse(shipDesign.Attribute("NumOfEngines").Value)); Armor = LoadEquipment(shipDesign.Attribute("Armor").Value, gameMain); Shield = LoadEquipment(shipDesign.Attribute("Shield").Value, gameMain); Computer = LoadEquipment(shipDesign.Attribute("Computer").Value, gameMain); ECM = LoadEquipment(shipDesign.Attribute("ECM").Value, gameMain); int iter = 0; foreach (var weapon in shipDesign.Elements("Weapon")) { if (weapon.Attribute("Name").Value == "null") { Weapons[iter] = new KeyValuePair<Equipment, int>(); } else { var weaponTech = LoadEquipment(weapon.Attribute("Name").Value, gameMain); weaponTech.UseSecondary = bool.Parse(weapon.Attribute("IsSecondary").Value); Weapons[iter] = new KeyValuePair<Equipment, int>(weaponTech, int.Parse(weapon.Attribute("NumOfMounts").Value)); } iter++; } iter = 0; foreach (var special in shipDesign.Elements("Special")) { if (special.Attribute("Name").Value == "null") { Specials[iter] = null; } else { var specialTech = LoadEquipment(special.Attribute("Name").Value, gameMain); Specials[iter] = specialTech; } iter++; } }
public void Load(XElement empireDoc, Empire empire, GameMain gameMain) { var currentDesigns = empireDoc.Element("CurrentShipDesigns"); foreach (var currentDesign in currentDesigns.Elements()) { var currentShip = new Ship(); currentShip.Load(currentDesign, gameMain); currentShip.Owner = empire; CurrentDesigns.Add(currentShip); } /*var obsoleteDesigns = empireDoc.Element("ObsoleteShipDesigns"); foreach (var obsoleteDesign in obsoleteDesigns.Elements()) { var obsoleteShip = new Ship(); obsoleteShip.Load(obsoleteDesign, gameMain); obsoleteShip.Owner = empire; ObsoleteDesigns.Add(obsoleteShip); }*/ var fleets = empireDoc.Element("Fleets"); foreach (var fleet in fleets.Elements()) { var newFleet = new Fleet(); newFleet.Load(fleet, this, empire, gameMain); _fleets.Add(newFleet); } }
public void Load(XElement fleet, FleetManager fleetManager, Empire empire, GameMain gameMain) { _empire = empire; _galaxyX = float.Parse(fleet.Attribute("X").Value); _galaxyY = float.Parse(fleet.Attribute("Y").Value); _adjacentSystem = gameMain.Galaxy.GetStarWithID(int.Parse(fleet.Attribute("AdjacentSystem").Value)); var travelNodes = fleet.Element("TravelNodes"); if (travelNodes != null) { _travelNodes = new List<TravelNode>(); StarSystem startingPlace = null; foreach (var travelNode in travelNodes.Elements()) { var destination = gameMain.Galaxy.GetStarWithID(int.Parse(travelNode.Attribute("Destination").Value)); if (startingPlace == null) { _travelNodes.Add(gameMain.Galaxy.GenerateTravelNode(_galaxyX, _galaxyY, destination)); } else { _travelNodes.Add(gameMain.Galaxy.GenerateTravelNode(startingPlace, destination)); } startingPlace = destination; } } foreach (var ship in fleet.Elements("Ship")) { AddShips(fleetManager.GetShipWithDesignID(int.Parse(ship.Attribute("ShipDesign").Value)), int.Parse(ship.Attribute("NumberOfShips").Value)); } foreach (var transport in fleet.Elements("Transport")) { AddTransport(gameMain.RaceManager.GetRace(transport.Attribute("Race").Value), int.Parse(transport.Attribute("Count").Value)); } }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); try { List<DirectoryInfo> dataSets = new List<DirectoryInfo>(); try { //Check to see if there's data in program directory that's not copied to general application data folder DirectoryInfo di = new DirectoryInfo(Path.Combine(Application.StartupPath, "Data")); DirectoryInfo target = new DirectoryInfo(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Beyond Beyaan")); if (!target.Exists) { target.Create(); } foreach (var directory in di.GetDirectories()) { CopyOrUpdateDirectory(directory, new DirectoryInfo(Path.Combine(target.FullName, directory.Name))); } //Get list of available datasets from general application data folder foreach (var directory in target.GetDirectories()) { //Sanity check to ensure that it's a valid dataset dataSets.Add(directory); } } catch (Exception exception) { MessageBox.Show(string.Format("Failed to copy directories. Error: {0}", exception.Message)); Close(); return; } if (dataSets.Count == 0) { MessageBox.Show(Resources.BeyondBeyaan_OnLoad_There_are_no_available_datasets_to_choose_from___Ensure_that_the_program_is_installed_correctly_); Close(); return; } dataSets.Sort((a, b) => String.Compare(a.Name, b.Name, StringComparison.CurrentCultureIgnoreCase)); Gorgon.Initialize(true, false); VideoMode videoMode; DirectoryInfo dataset; bool fullScreen; bool showTutorial; using (Configuration configuration = new Configuration()) { configuration.FillResolutionList(); configuration.FillDatasetList(dataSets); configuration.ShowDialog(this); if (configuration.DialogResult != DialogResult.OK) { Close(); return; } videoMode = configuration.VideoMode; fullScreen = configuration.FullScreen; dataset = dataSets[configuration.DataSetIndex]; showTutorial = configuration.ShowTutorial; } Gorgon.SetMode(this, videoMode.Width, videoMode.Height, BackBufferFormats.BufferRGB888, !fullScreen); Gorgon.Idle += new FrameEventHandler(Gorgon_Idle); Gorgon.FastResize = false; //Gorgon.FrameStatsVisible = true; input = Input.LoadInputPlugIn(Environment.CurrentDirectory + @"\GorgonInput.DLL", "Gorgon.RawInput"); input.Bind(this); keyboard = input.Keyboard; keyboard.Enabled = true; keyboard.Exclusive = false; keyboard.KeyDown += keyboard_KeyDown; string reason; FileInfo fileInfo = new FileInfo(Path.Combine(dataset.FullName, "configuration.xml")); if (!GameConfiguration.Initialize(fileInfo, out reason)) { MessageBox.Show(string.Format("Error loading configuration, reason: {0}", reason)); Close(); return; } gameMain = new GameMain(); if (!gameMain.Initalize(Gorgon.Screen.Width, Gorgon.Screen.Height, dataset, showTutorial, this, out reason)) { MessageBox.Show(string.Format("Error loading game resources, error message: {0}", reason)); Close(); return; } Gorgon.Go(); } catch (Exception exception) { HandleException(exception); } }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); try { List <DirectoryInfo> dataSets = new List <DirectoryInfo>(); try { //Check to see if there's data in program directory that's not copied to general application data folder DirectoryInfo di = new DirectoryInfo(Path.Combine(Application.StartupPath, "Data")); DirectoryInfo target = new DirectoryInfo(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Beyond Beyaan")); if (!target.Exists) { target.Create(); } foreach (var directory in di.GetDirectories()) { CopyOrUpdateDirectory(directory, new DirectoryInfo(Path.Combine(target.FullName, directory.Name))); } //Get list of available datasets from general application data folder foreach (var directory in target.GetDirectories()) { //Sanity check to ensure that it's a valid dataset dataSets.Add(directory); } } catch (Exception exception) { MessageBox.Show(string.Format("Failed to copy directories. Error: {0}", exception.Message)); Close(); return; } if (dataSets.Count == 0) { MessageBox.Show(Resources.BeyondBeyaan_OnLoad_There_are_no_available_datasets_to_choose_from___Ensure_that_the_program_is_installed_correctly_); Close(); return; } dataSets.Sort((a, b) => String.Compare(a.Name, b.Name, StringComparison.CurrentCultureIgnoreCase)); Gorgon.Initialize(true, false); VideoMode videoMode; DirectoryInfo dataset; bool fullScreen; bool showTutorial; using (Configuration configuration = new Configuration()) { configuration.FillResolutionList(); configuration.FillDatasetList(dataSets); configuration.ShowDialog(this); if (configuration.DialogResult != DialogResult.OK) { Close(); return; } videoMode = configuration.VideoMode; fullScreen = configuration.FullScreen; dataset = dataSets[configuration.DataSetIndex]; showTutorial = configuration.ShowTutorial; } Gorgon.SetMode(this, videoMode.Width, videoMode.Height, BackBufferFormats.BufferRGB888, !fullScreen); Gorgon.Idle += new FrameEventHandler(Gorgon_Idle); Gorgon.FastResize = false; //Gorgon.FrameStatsVisible = true; input = Input.LoadInputPlugIn(Environment.CurrentDirectory + @"\GorgonInput.DLL", "Gorgon.RawInput"); input.Bind(this); keyboard = input.Keyboard; keyboard.Enabled = true; keyboard.Exclusive = false; keyboard.KeyDown += keyboard_KeyDown; string reason; FileInfo fileInfo = new FileInfo(Path.Combine(dataset.FullName, "configuration.xml")); if (!GameConfiguration.Initialize(fileInfo, out reason)) { MessageBox.Show(string.Format("Error loading configuration, reason: {0}", reason)); Close(); return; } gameMain = new GameMain(); if (!gameMain.Initalize(Gorgon.Screen.Width, Gorgon.Screen.Height, dataset, showTutorial, this, out reason)) { MessageBox.Show(string.Format("Error loading game resources, error message: {0}", reason)); Close(); return; } Gorgon.Go(); } catch (Exception exception) { HandleException(exception); } }