private void DoDeploy(ArtificialIntelligence.ShipGoal shipgoal)
 {
     if (shipgoal.goal == null)
     {
         return;
     }
     if (shipgoal.goal.TetherTarget != Guid.Empty && Vector2.Distance(ArtificialIntelligence.universeScreen.PlanetsDict[shipgoal.goal.TetherTarget].Position + shipgoal.goal.TetherOffset, this.Owner.Center) > 200f)
     {
         shipgoal.goal.BuildPosition = ArtificialIntelligence.universeScreen.PlanetsDict[shipgoal.goal.TetherTarget].Position + shipgoal.goal.TetherOffset;
         this.OrderDeepSpaceBuild(shipgoal.goal);
         return;
     }
     Ship platform = ResourceManager.CreateShipAtPoint(shipgoal.goal.ToBuildUID, this.Owner.loyalty, shipgoal.goal.BuildPosition);
     if (platform == null)
     {
         return;
     }
     foreach (SpaceRoad road in this.Owner.loyalty.SpaceRoadsList)
     {
         foreach (RoadNode node in road.RoadNodesList)
         {
             if (node.Position != shipgoal.goal.BuildPosition)
             {
                 continue;
             }
             node.Platform = platform;
             if (!StatTracker.SnapshotsDict.ContainsKey(ArtificialIntelligence.universeScreen.StarDate.ToString("#.0")))
             {
                 continue;
             }
             NRO nro = new NRO()
             {
                 Node = node.Position,
                 Radius = 300000f,
                 StarDateMade = ArtificialIntelligence.universeScreen.StarDate
             };
             StatTracker.SnapshotsDict[ArtificialIntelligence.universeScreen.StarDate.ToString("#.0")][EmpireManager.EmpireList.IndexOf(this.Owner.loyalty)].EmpireNodes.Add(nro);
         }
     }
     if (shipgoal.goal.TetherTarget != Guid.Empty)
     {
         platform.TetherToPlanet(ArtificialIntelligence.universeScreen.PlanetsDict[shipgoal.goal.TetherTarget]);
         platform.TetherOffset = shipgoal.goal.TetherOffset;
     }
     this.Owner.loyalty.GetGSAI().Goals.Remove(shipgoal.goal);
     this.Owner.QueueTotalRemoval();
 }
 private void Colonize(Planet TargetPlanet)
 {
     if (Vector2.Distance(this.Owner.Center, TargetPlanet.Position) > 2000f)
     {
         this.OrderQueue.RemoveFirst();
         this.OrderColonization(TargetPlanet);
         this.State = AIState.Colonize;
         return;
     }
     if (TargetPlanet.Owner != null || !TargetPlanet.habitable)
     {
         if (this.ColonizeGoal != null)
         {
             Goal colonizeGoal = this.ColonizeGoal;
             colonizeGoal.Step = colonizeGoal.Step + 1;
             this.Owner.loyalty.GetGSAI().Goals.QueuePendingRemoval(this.ColonizeGoal);
         }
         this.State = AIState.AwaitingOrders;
         this.OrderQueue.Clear();
         return;
     }
     this.ColonizeTarget = TargetPlanet;
     this.ColonizeTarget.Owner = this.Owner.loyalty;
     this.ColonizeTarget.system.OwnerList.Add(this.Owner.loyalty);
     this.ColonizeTarget.colonyType = this.Owner.loyalty.AssessColonyNeeds(this.ColonizeTarget);
     if (this.Owner.loyalty == EmpireManager.GetEmpireByName(ArtificialIntelligence.universeScreen.PlayerLoyalty))
     {
         ArtificialIntelligence.universeScreen.NotificationManager.AddColonizedNotification(this.ColonizeTarget, EmpireManager.GetEmpireByName(ArtificialIntelligence.universeScreen.PlayerLoyalty));
         this.ColonizeTarget.colonyType = Planet.ColonyType.Colony;
     }
     //lock (GlobalStats.OwnedPlanetsLock)
     {
         this.Owner.loyalty.AddPlanet(this.ColonizeTarget);
     }
     this.ColonizeTarget.InitializeSliders(this.Owner.loyalty);
     this.ColonizeTarget.ExploredDict[this.Owner.loyalty] = true;
     List<string> BuildingsAdded = new List<string>();
     foreach (ModuleSlot slot in this.Owner.ModuleSlotList)
     {
         if (slot.module == null || slot.module.ModuleType != ShipModuleType.Colony || slot.module.DeployBuildingOnColonize == null || BuildingsAdded.Contains(slot.module.DeployBuildingOnColonize))
         {
             continue;
         }
         Building building = ResourceManager.GetBuilding(slot.module.DeployBuildingOnColonize);
         bool ok = true;
         if (building.Unique)
         {
             foreach (Building b in this.ColonizeTarget.BuildingList)
             {
                 if (b.Name != building.Name)
                 {
                     continue;
                 }
                 ok = false;
                 break;
             }
         }
         if (!ok)
         {
             continue;
         }
         BuildingsAdded.Add(slot.module.DeployBuildingOnColonize);
         this.ColonizeTarget.BuildingList.Add(building);
         this.ColonizeTarget.AssignBuildingToTileOnColonize(building);
     }
     Planet colonizeTarget = this.ColonizeTarget;
     colonizeTarget.TerraformPoints = colonizeTarget.TerraformPoints + this.Owner.loyalty.data.EmpireFertilityBonus;
     this.ColonizeTarget.Crippled_Turns = 0;
     if (StatTracker.SnapshotsDict.ContainsKey(ArtificialIntelligence.universeScreen.StarDate.ToString("#.0")))
     {
         StatTracker.SnapshotsDict[ArtificialIntelligence.universeScreen.StarDate.ToString("#.0")][EmpireManager.EmpireList.IndexOf(this.Owner.loyalty)].Events.Add(string.Concat(this.Owner.loyalty.data.Traits.Name, " colonized ", this.ColonizeTarget.Name));
         NRO nro = new NRO()
         {
             Node = this.ColonizeTarget.Position,
             Radius = 300000f,
             StarDateMade = ArtificialIntelligence.universeScreen.StarDate
         };
         StatTracker.SnapshotsDict[ArtificialIntelligence.universeScreen.StarDate.ToString("#.0")][EmpireManager.EmpireList.IndexOf(this.Owner.loyalty)].EmpireNodes.Add(nro);
     }
     foreach (Goal g in this.Owner.loyalty.GetGSAI().Goals)
     {
         if (g.type != GoalType.Colonize || g.GetMarkedPlanet() != this.ColonizeTarget)
         {
             continue;
         }
         this.Owner.loyalty.GetGSAI().Goals.QueuePendingRemoval(g);
         break;
     }
     this.Owner.loyalty.GetGSAI().Goals.ApplyPendingRemovals();
     if (this.ColonizeTarget.system.OwnerList.Count > 1)
     {
         foreach (Planet p in this.ColonizeTarget.system.PlanetList)
         {
             if (p.Owner == this.ColonizeTarget.Owner || p.Owner == null)
             {
                 continue;
             }
             this.Owner.loyalty.GetPlanets().thisLock.EnterReadLock();
             {
                 if (p.Owner.GetRelations().ContainsKey(this.Owner.loyalty) && !p.Owner.GetRelations()[this.Owner.loyalty].Treaty_OpenBorders)
                 {
                     p.Owner.DamageRelationship(this.Owner.loyalty, "Colonized Owned System", 20f, p);
                 }
             }
             this.Owner.loyalty.GetPlanets().thisLock.ExitReadLock();
         }
     }
     foreach (ModuleSlot slot in this.Owner.ModuleSlotList)
     {
         if (slot.module.ModuleType != ShipModuleType.Colony)
         {
             continue;
         }
         Planet foodHere = this.ColonizeTarget;
         foodHere.FoodHere = foodHere.FoodHere + slot.module.numberOfFood;
         Planet productionHere = this.ColonizeTarget;
         productionHere.ProductionHere = productionHere.ProductionHere + slot.module.numberOfEquipment;
         Planet population = this.ColonizeTarget;
         population.Population = population.Population + slot.module.numberOfColonists;
     }
     //Added by McShooterz: Remove troops from planet
     bool TroopsRemoved = false;
     bool PlayerTroopsRemoved = false;
     for (int i = 0; i < this.ColonizeTarget.TroopsHere.Count; i++)
     {
         Troop troop = this.ColonizeTarget.TroopsHere[i];
         if (troop != null && troop.GetOwner() != null && !troop.GetOwner().isFaction && troop.GetOwner() != this.ColonizeTarget.Owner && this.ColonizeTarget.Owner.GetRelations().ContainsKey(troop.GetOwner()) && !this.ColonizeTarget.Owner.GetRelations()[troop.GetOwner()].AtWar)
         {
             troop.Launch();
             TroopsRemoved = true;
             if (troop.GetOwner().isPlayer)
                 PlayerTroopsRemoved = true;
         }
     }
     if (TroopsRemoved)
     {
         if (PlayerTroopsRemoved)
             universeScreen.NotificationManager.AddTroopsRemovedNotification(this.ColonizeTarget);
         else if (this.ColonizeTarget.Owner.isPlayer)
             universeScreen.NotificationManager.AddForeignTroopsRemovedNotification(this.ColonizeTarget);
     }
     this.Owner.QueueTotalRemoval();
 }