public PlanetDrawing(Planet planet)
		{
			Planet = planet;
			Label = new MapLabel(planet.Position);
			if (GalaxyMap.Instance.Galaxy.GetOwner(planet) == null) {
				Label.Text = Planet.Name;
			} else {
				Label.Text = Planet.Name + Environment.NewLine + GalaxyMap.Instance.Galaxy.GetOwner(planet).Name +
				             Environment.NewLine + Map.GetHumanName(planet.MapName);
			}
		}
		void AddPlanet(PointF locationF)
		{
			var planets = GalaxyMap.Instance.Galaxy.Planets;
			int ID = planets.Count > 0 ? planets.Select(p => p.ID).Max() + 1 : 1;
			var planet = new Planet {ID = ID};
			var names = Resources.stars.Replace("\r\n", "\n").Split('\n').Except(planets.Select(p => p.Name)).ToArray();
            planet.Name = names[Program.Random.Next(names.Length)];
			planet.Position = locationF;
			planets.Add(planet);
			GalaxyMap.Instance.PlanetDrawings.Add(new PlanetDrawing(planet));
            Program.MainForm.Text = GalaxyMap.Instance.Galaxy.Planets.Count().ToString();
			Redraw();
		}
 public PlanetDrawing(Planet planet, double galaxyWidth, double galaxyHeight)
 {
     InitializeComponent();
     Position = new Point(planet.Position.X*galaxyWidth, planet.Position.Y*galaxyHeight);
     PlanetName = planet.Name;
 }
 public Faction GetFaction(Planet planet)
 {
     if (planet == null) {
         throw new ArgumentNullException("planet");
     }
     return planet.FactionName == null ? null : GetFaction(planet.FactionName);
 }
		void KillFleetsAndUpgrades(Faction victoriousFaction, Planet planet)
		{
			// kill orbiting spacefleets
			var fleetsToKill = new List<SpaceFleet>();
			foreach (var fleet in Galaxy.Fleets.Where(x => x.TargetPlanetID == planet.ID)) {
				PointF loc;
				if (fleet.GetCurrentPosition(out loc, Galaxy.Turn)) {
					if (Galaxy.GetPlayer(fleet.OwnerName).FactionName != victoriousFaction.Name) {
						fleetsToKill.Add(fleet);
					}
				}
			}
			if (fleetsToKill.Count > 0) {
				var f = fleetsToKill.TakeRandom(); // pick random one to kill
				Galaxy.Fleets.Remove(f);
				List<UpgradeDef> upgrades;
				if (UpgradeData.TryGetValue(f.OwnerName, out upgrades)) {
					var upgrade = upgrades.SingleOrDefault(u => u.UnitChoice == "fleet_blockade");
					if (upgrade != null) {
						upgrades.Remove(upgrade);
					}
				}
			}

			// occupied planet - delete deployed structures
			if (planet.OwnerName != null && Galaxy.GetPlayer(planet.OwnerName).FactionName != planet.FactionName) {
				RemoveAllUpgradesFromPlanet(planet.ID);
			}
		}