Пример #1
0
 public void AddShipDesign(Ship newShipDesign)
 {
     Ship ship = new Ship(newShipDesign); //Make a copy so it don't get modified by accident
     ship.DesignID = _currentShipDesignID;
     _currentShipDesignID++;
     CurrentDesigns.Add(ship);
 }
Пример #2
0
 public Ship(Ship shipToCopy)
 {
     Name = shipToCopy.Name;
     DesignID = shipToCopy.DesignID;
     Owner = shipToCopy.Owner;
     Size = shipToCopy.Size;
     WhichStyle = shipToCopy.WhichStyle;
     Engine = new KeyValuePair<Equipment, float>(shipToCopy.Engine.Key, shipToCopy.Engine.Value);
     Shield = shipToCopy.Shield;
     Armor = shipToCopy.Armor;
     Computer = shipToCopy.Computer;
     ECM = shipToCopy.ECM;
     Array.Copy(shipToCopy.Weapons, Weapons, Weapons.Length);
     Array.Copy(shipToCopy.Specials, Specials, Specials.Length);
 }
Пример #3
0
 //For iterating through ship design when clicking on construction button in planet UI
 public Ship GetNextShipDesign(Ship previousDesign)
 {
     int iter = CurrentDesigns.IndexOf(previousDesign) + 1; //Even if not found (which results in -1), it will be the next ship
     if (iter >= CurrentDesigns.Count)
     {
         iter = 0; //Start over from beginning
     }
     return CurrentDesigns[iter];
 }
Пример #4
0
        public void SetupStarterFleet(StarSystem homeSystem)
        {
            Technology retroEngine = null;
            Technology titaniumArmor = null;
            Technology laser = null;
            Technology nuclearMissile = null;
            Technology nuclearBomb = null;

            foreach (var tech in _empire.TechnologyManager.ResearchedPropulsionTechs)
            {
                if (tech.Speed == 1)
                {
                    retroEngine = tech;
                    break;
                }
            }
            foreach (var tech in _empire.TechnologyManager.ResearchedConstructionTechs)
            {
                if (tech.Armor == Technology.TITANIUM_ARMOR)
                {
                    titaniumArmor = tech;
                    break;
                }
            }
            foreach (var tech in _empire.TechnologyManager.ResearchedWeaponTechs)
            {
                if (tech.TechName == "Laser")
                {
                    laser = tech;
                }
                else if (tech.TechName == "Nuclear Missile")
                {
                    nuclearMissile = tech;
                }
                else if (tech.TechName == "Nuclear Bomb")
                {
                    nuclearBomb = tech;
                }
            }
            Ship scout = new Ship();
            scout.Name = "Scout";
            scout.Owner = _empire;
            scout.Size = Ship.SMALL;
            scout.WhichStyle = 0;
            scout.Armor = new Equipment(titaniumArmor, false);
            foreach (var tech in _empire.TechnologyManager.ResearchedConstructionTechs)
            {
                if (tech.ReserveFuelTanks)
                {
                    scout.Specials[0] = new Equipment(tech, false);
                    break;
                }
            }
            scout.Engine = new KeyValuePair<Equipment, float>(new Equipment(retroEngine, false), scout.PowerUsed / (retroEngine.Speed * 10));
            scout.DesignID = _currentShipDesignID;
            CurrentDesigns.Add(scout);
            _currentShipDesignID++;

            Ship fighter = new Ship();
            fighter.Name = "Fighter";
            fighter.Owner = _empire;
            fighter.Size = Ship.SMALL;
            fighter.WhichStyle = 1;
            fighter.Weapons[0] = new KeyValuePair<Equipment, int>(new Equipment(laser, false), 1);
            fighter.Armor = new Equipment(titaniumArmor, false);
            fighter.Engine = new KeyValuePair<Equipment, float>(new Equipment(retroEngine, false), fighter.PowerUsed / (retroEngine.Speed * 10));
            CurrentDesigns.Add(fighter);
            _currentShipDesignID++;

            Ship destroyer = new Ship();
            destroyer.Name = "Destroyer";
            destroyer.Owner = _empire;
            destroyer.Size = Ship.MEDIUM;
            destroyer.WhichStyle = 0;
            destroyer.Weapons[0] = new KeyValuePair<Equipment, int>(new Equipment(nuclearMissile, false), 1);
            destroyer.Weapons[1] = new KeyValuePair<Equipment, int>(new Equipment(laser, false), 3);
            destroyer.Armor = new Equipment(titaniumArmor, false);
            destroyer.Engine = new KeyValuePair<Equipment, float>(new Equipment(retroEngine, false), destroyer.PowerUsed / (retroEngine.Speed * 10));
            CurrentDesigns.Add(destroyer);
            _currentShipDesignID++;

            Ship bomber = new Ship();
            bomber.Name = "Bomber";
            bomber.Owner = _empire;
            bomber.Size = Ship.MEDIUM;
            bomber.WhichStyle = 1;
            bomber.Weapons[0] = new KeyValuePair<Equipment, int>(new Equipment(nuclearBomb, false), 2);
            bomber.Weapons[1] = new KeyValuePair<Equipment, int>(new Equipment(laser, false), 2);
            bomber.Armor = new Equipment(titaniumArmor, false);
            bomber.Engine = new KeyValuePair<Equipment, float>(new Equipment(retroEngine, false), bomber.PowerUsed / (retroEngine.Speed * 10));
            CurrentDesigns.Add(bomber);
            _currentShipDesignID++;

            Ship colonyShip = new Ship();
            colonyShip.Name = "Colony Ship";
            colonyShip.Owner = _empire;
            colonyShip.Size = Ship.LARGE;
            colonyShip.WhichStyle = 0;
            colonyShip.Armor = new Equipment(titaniumArmor, false);
            foreach (var tech in _empire.TechnologyManager.ResearchedPlanetologyTechs)
            {
                if (tech.Colony == Technology.STANDARD_COLONY)
                {
                    colonyShip.Specials[0] = new Equipment(tech, false);
                    break;
                }
            }
            colonyShip.Engine = new KeyValuePair<Equipment, float>(new Equipment(retroEngine, false), colonyShip.PowerUsed / (retroEngine.Speed * 10));
            colonyShip.DesignID = _currentShipDesignID;
            CurrentDesigns.Add(colonyShip);
            _currentShipDesignID++;

            LastShipDesign = new Ship(scout); //Make a copy so we don't accidentally modify the original ship

            Fleet starterFleet = new Fleet();
            starterFleet.GalaxyX = homeSystem.X;
            starterFleet.GalaxyY = homeSystem.Y;
            starterFleet.AdjacentSystem = homeSystem;
            starterFleet.Empire = _empire;
            starterFleet.AddShips(CurrentDesigns[0], 2);
            starterFleet.AddShips(CurrentDesigns[4], 1);
            _fleets.Add(starterFleet);
        }
Пример #5
0
 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);
     }
 }
Пример #6
0
 public void ObsoleteShipDesign(Ship shipToObsolete)
 {
     float totalScrappedValue = 0;
     foreach (var fleet in _fleets)
     {
         if (fleet.Ships.ContainsKey(shipToObsolete))
         {
             totalScrappedValue += fleet.Ships[shipToObsolete] * shipToObsolete.Cost * 0.25f;
             fleet.SubtractShips(shipToObsolete, -1);
         }
     }
     ClearEmptyFleets();
     CurrentDesigns.Remove(shipToObsolete);
     //ObsoleteDesigns.Add(shipToObsolete);
     _empire.Reserves += totalScrappedValue;
 }
Пример #7
0
 public int GetShipCount(Ship design)
 {
     int amount = 0;
     //Gets the count of ships with this design in the empire
     foreach (var fleet in _fleets)
     {
         if (fleet.Ships.ContainsKey(design))
         {
             amount += fleet.Ships[design];
         }
     }
     return amount;
 }
Пример #8
0
 public void Colonize(Empire whichEmpire)
 {
     _owner = whichEmpire;
     whichEmpire.PlanetManager.AddOwnedPlanet(this);
     _racePopulations = new Dictionary<Race, float>();
     _racePopulations.Add(whichEmpire.EmpireRace, 2);
     _races.Add(whichEmpire.EmpireRace);
     SetOutputAmount(OUTPUT_TYPE.INFRASTRUCTURE, 100, true);
     _shipBeingBuilt = whichEmpire.FleetManager.CurrentDesigns[0];
     System.UpdateOwners();
 }
Пример #9
0
 public void SubtractShips(Ship ship, int amount)
 {
     if (ships.ContainsKey(ship))
     {
         if (amount == -1)
         {
             //Remove this ship totally
             ships.Remove(ship);
             _orderedShips.Remove(ship);
             UpdateSpeed();
         }
         else
         {
             ships[ship] -= amount;
         }
     }
 }
Пример #10
0
 public void ColonizePlanet(Ship whichShip)
 {
     //This assumes that whichShip is not null, adjacentSystem is not null, and everything has already been validated (i.e. ship has correct colony pod)
     ships[whichShip]--;
     if (ships[whichShip] == 0)
     {
         //only one ship, so remove the entry for it
         ships.Remove(whichShip);
         _orderedShips.Remove(whichShip);
     }
     _adjacentSystem.Planets[0].Colonize(_empire);
 }
Пример #11
0
 /*private float CalculatePathCost(List<TravelNode> nodes)
 {
     float amount = 0;
     for (int i = 0; i < nodes.Count; i++)
     {
         float x;
         float y;
         if (i == 0)
         {
             x = (_galaxyX - nodes[i].StarSystem.X);
             y = (_galaxyY - nodes[i].StarSystem.Y);
         }
         else
         {
             x = nodes[i - 1].StarSystem.X - nodes[i].StarSystem.X;
             y = nodes[i - 1].StarSystem.Y - nodes[i].StarSystem.Y;
         }
         amount += (float)Math.Sqrt(x * x + y * y);
     }
     return amount;
 }*/
 public void AddShips(Ship ship, int amount)
 {
     if (ships.ContainsKey(ship))
     {
         ships[ship] += amount;
     }
     else
     {
         ships.Add(ship, amount);
         _orderedShips.Add(ship);
         UpdateSpeed();
     }
 }