public UnexploredPlanetScreen(Planet p, Ship_Game.ScreenManager ScreenManager)
 {
     this.ScreenManager = ScreenManager;
     this.p = p;
     if (ScreenManager.GraphicsDevice.PresentationParameters.BackBufferWidth <= 1280)
     {
         this.LowRes = true;
     }
     Rectangle titleRect = new Rectangle(5, 44, 405, 80);
     if (this.LowRes)
     {
         titleRect.Width = 365;
     }
     this.TitleBar = new Menu2(ScreenManager, titleRect);
     this.TitlePos = new Vector2((float)(titleRect.X + titleRect.Width / 2) - Fonts.Laserian14.MeasureString(p.Name).X / 2f, (float)(titleRect.Y + titleRect.Height / 2 - Fonts.Laserian14.LineSpacing / 2));
     Rectangle leftRect = new Rectangle(5, titleRect.Y + titleRect.Height + 5, titleRect.Width, ScreenManager.GraphicsDevice.PresentationParameters.BackBufferHeight - (titleRect.Y + titleRect.Height) - (int)(0.4f * (float)ScreenManager.GraphicsDevice.PresentationParameters.BackBufferHeight));
     if (leftRect.Height < 350)
     {
         leftRect.Height = 350;
     }
     this.PlanetMenu = new Menu1(ScreenManager, leftRect);
     Rectangle psubRect = new Rectangle(leftRect.X + 20, leftRect.Y + 20, leftRect.Width - 40, leftRect.Height - 40);
     this.PlanetInfo = new Submenu(ScreenManager, psubRect);
     this.PlanetInfo.AddTab("Planet Info");
     this.PlanetIcon = new Rectangle(psubRect.X + psubRect.Width - 148, leftRect.Y + 55, 128, 128);
 }
 public Goal(Planet toColonize, Empire e)
 {
     this.empire = e;
     this.GoalName = "MarkForColonization";
     this.type = GoalType.Colonize;
     this.markedPlanet = toColonize;
     this.colonyShip = (Ship)null;
 }
 public void SetTarget(Planet p)
 {
     this.TargetPlanet = p;
     this.planetRadius = this.TargetPlanet.SO.WorldBoundingSphere.Radius;
     Vector3 vtt = (new Vector3(this.TargetPlanet.Position, 2500f ) + new Vector3(RandomMath2.RandomBetween(-500f, 500f) * p.scale, RandomMath2.RandomBetween(-500f, 500f) * p.scale, 0f)) - this.Position;
     vtt = Vector3.Normalize(vtt);
     this.Velocity = vtt * 1350f;
 }
 public Goal(Troop toCopy, Empire Owner, Planet p)
 {
     this.GoalName = "Build Troop";
     this.type = GoalType.DeepSpaceConstruction;
     this.PlanetBuildingAt = p;
     this.ToBuildUID = toCopy.Name;
     this.empire = Owner;
     this.type = GoalType.BuildTroop;
 }
 public void SetVisibility(bool vis, Ship_Game.ScreenManager ScreenManager, Planet p)
 {
     this.planet = p;
     if (this.InnerSO == null || this.OuterSO == null)
     {
         this.LoadContent(ScreenManager);
     }
     if (vis)
     {
         this.InnerSO.Visibility = ObjectVisibility.RenderedAndCastShadows;
         this.OuterSO.Visibility = ObjectVisibility.RenderedAndCastShadows;
         return;
     }
     this.InnerSO.Visibility = ObjectVisibility.None;
     this.OuterSO.Visibility = ObjectVisibility.None;
 }
 public ThreeStateButton(Planet.GoodState gstate, string good, Vector2 position)
 {
     this.Good = good;
     if (gstate == Planet.GoodState.IMPORT)
     {
         this.state = ThreeStateButton.State.In;
     }
     if (gstate == Planet.GoodState.EXPORT)
     {
         this.state = ThreeStateButton.State.Out;
     }
     if (gstate == Planet.GoodState.STORE)
     {
         this.state = ThreeStateButton.State.Store;
     }
     this.rect = new Rectangle((int)position.X, (int)position.Y, 32, 32);
     this.TextPos = new Vector2((float)(this.rect.X + 36), (float)(this.rect.Y + 16 - Fonts.Arial12Bold.LineSpacing / 2));
 }
 //private string fmt = "0.#";
 public OrbitalAssetsUIElement(Rectangle r, Ship_Game.ScreenManager sm, UniverseScreen screen, Planet p)
 {
     this.p = p;
     this.screen = screen;
     this.ScreenManager = sm;
     this.ElementRect = r;
     this.sel = new Selector(this.ScreenManager, r, Color.Black);
     base.TransitionOnTime = TimeSpan.FromSeconds(0.25);
     base.TransitionOffTime = TimeSpan.FromSeconds(0.25);
     this.SliderRect = new Rectangle(r.X + r.Width - 100, r.Y + r.Height - 40, 500, 40);
     this.clickRect = new Rectangle(this.ElementRect.X + this.ElementRect.Width - 16, this.ElementRect.Y + this.ElementRect.Height / 2 - 11, 11, 22);
     this.LeftRect = new Rectangle(r.X, r.Y + 44, 200, r.Height - 44);
     this.RightRect = new Rectangle(r.X + 200, r.Y + 44, 200, r.Height - 44);
     this.BombardButton = new DanButton(new Vector2((float)(this.LeftRect.X + 20), (float)(this.LeftRect.Y + 25)), Localizer.Token(1431))
     {
         IsToggle = true,
         ToggledText = Localizer.Token(1426)
     };
     this.LandTroops = new DanButton(new Vector2((float)(this.LeftRect.X + 20), (float)(this.LeftRect.Y + 75)), Localizer.Token(1432))
     {
         IsToggle = true,
         ToggledText = Localizer.Token(1433)
     };
     this.flagRect = new Rectangle(r.X + r.Width - 31, r.Y + 22 - 13, 26, 26);
     this.DefenseRect = new Rectangle(this.LeftRect.X + 12, this.LeftRect.Y + 18, 22, 22);
     this.SoftAttackRect = new Rectangle(this.LeftRect.X + 12, this.DefenseRect.Y + 22 + 5, 16, 16);
     this.HardAttackRect = new Rectangle(this.LeftRect.X + 12, this.SoftAttackRect.Y + 16 + 5, 16, 16);
     this.DefenseRect.X = this.DefenseRect.X - 3;
     this.ItemDisplayRect = new Rectangle(this.LeftRect.X + 85, this.LeftRect.Y + 5, 85, 85);
     OrbitalAssetsUIElement.TippedItem bomb = new OrbitalAssetsUIElement.TippedItem()
     {
         r = this.BombardButton.r,
         TIP_ID = 32
     };
     this.ToolTipItems.Add(bomb);
     bomb = new OrbitalAssetsUIElement.TippedItem()
     {
         r = this.LandTroops.r,
         TIP_ID = 36
     };
     this.ToolTipItems.Add(bomb);
 }
 public AO(Planet p, float Radius)
 {
     this.Radius = Radius;
     this.CoreWorld = p;
     this.CoreWorldGuid = p.guid;
     this.WhichFleet = p.Owner.GetUnusedKeyForFleet();
     p.Owner.GetFleetsDict().TryAdd(this.WhichFleet, this.CoreFleet);
     this.CoreFleet.Name = "Core Fleet";
     this.CoreFleet.Position = p.Position;
     this.CoreFleet.Owner = p.Owner;
     this.CoreFleet.IsCoreFleet = true;
     foreach (Planet planet in p.Owner.GetPlanets())
     {
         if (Vector2.Distance(planet.Position, this.CoreWorld.Position) >= Radius)
         {
             continue;
         }
         this.PlanetsInAO.Add(planet);
     }
 }
        public Ship Launch()
        {
            if (this.p == null)
            {
                return null;
            }
            foreach (PlanetGridSquare pgs in this.p.TilesList)
            {
                if (!pgs.TroopsHere.Contains(this))
                {
                    continue;
                }
                pgs.TroopsHere.Clear();
                this.p.TroopsHere.Remove(this);
            }
            Ship retShip = ResourceManager.CreateTroopShipAtPoint((this.Owner.data.DefaultTroopShip != null ? this.Owner.data.DefaultTroopShip : this.Owner.data.DefaultSmallTransport), this.Owner, this.p.Position, this);

            this.p = null;
            return retShip;
        }
        //private string Status_Text;
        public PlanetListScreenEntry(Planet p, int x, int y, int width1, int height, PlanetListScreen caller)
        {
            this.screen = caller;
            this.planet = p;
            this.TotalEntrySize = new Rectangle(x, y, width1 - 60, height);
            this.SysNameRect = new Rectangle(x, y, (int)((float)this.TotalEntrySize.Width * 0.12f), height);
            this.PlanetNameRect = new Rectangle(x + this.SysNameRect.Width, y, (int)((float)this.TotalEntrySize.Width * 0.25f), height);
            this.FertRect = new Rectangle(x + this.SysNameRect.Width + this.PlanetNameRect.Width, y, 100, height);
            this.RichRect = new Rectangle(x + this.SysNameRect.Width + this.PlanetNameRect.Width + this.FertRect.Width, y, 120, height);
            this.PopRect = new Rectangle(x + this.SysNameRect.Width + this.PlanetNameRect.Width + this.FertRect.Width + this.RichRect.Width, y, 200, height);
            this.OwnerRect = new Rectangle(x + this.SysNameRect.Width + this.PlanetNameRect.Width + this.FertRect.Width + this.RichRect.Width + this.PopRect.Width, y, 100, height);
            this.OrdersRect = new Rectangle(x + this.SysNameRect.Width + this.PlanetNameRect.Width + this.FertRect.Width + this.RichRect.Width + this.PopRect.Width + this.OwnerRect.Width, y, 100, height);
            //this.Status_Text = "";
            this.ShipIconRect = new Rectangle(this.PlanetNameRect.X + 5, this.PlanetNameRect.Y + 5, 50, 50);
            string shipName = this.planet.Name;
            this.ShipNameEntry.ClickableArea = new Rectangle(this.ShipIconRect.X + this.ShipIconRect.Width + 10, 2 + this.SysNameRect.Y + this.SysNameRect.Height / 2 - Fonts.Arial20Bold.LineSpacing / 2, (int)Fonts.Arial20Bold.MeasureString(shipName).X, Fonts.Arial20Bold.LineSpacing);
            this.ShipNameEntry.Text = shipName;
            float width = (float)((int)((float)this.FertRect.Width * 0.8f));
            while (width % 10f != 0f)
            {
                width = width + 1f;
            }

            Goal goal = new Goal();
            foreach (Goal g in Ship.universeScreen.player.GetGSAI().Goals)
            {
                if (g.GetMarkedPlanet() == null || g.GetMarkedPlanet() != p)
                {
                    continue;
                }
                this.marked = true;
            }

            if (this.marked)
                this.Colonize = new UIButton()
                {
                    Rect = new Rectangle(this.OrdersRect.X + 10, this.OrdersRect.Y + this.OrdersRect.Height / 2 - ResourceManager.TextureDict["EmpireTopBar/empiretopbar_btn_168px"].Height / 2, ResourceManager.TextureDict["EmpireTopBar/empiretopbar_btn_168px"].Width, ResourceManager.TextureDict["EmpireTopBar/empiretopbar_btn_168px"].Height),
                    NormalTexture = ResourceManager.TextureDict["EmpireTopBar/empiretopbar_btn_168px"],
                    HoverTexture = ResourceManager.TextureDict["EmpireTopBar/empiretopbar_btn_168px_hover"],
                    PressedTexture = ResourceManager.TextureDict["EmpireTopBar/empiretopbar_btn_168px_pressed"]
                };
            else
                this.Colonize = new UIButton()
                {
                    Rect = new Rectangle(this.OrdersRect.X + 10, this.OrdersRect.Y + this.OrdersRect.Height / 2 - ResourceManager.TextureDict["EmpireTopBar/empiretopbar_btn_168px"].Height / 2, ResourceManager.TextureDict["EmpireTopBar/empiretopbar_btn_168px"].Width, ResourceManager.TextureDict["EmpireTopBar/empiretopbar_btn_168px"].Height),
                    NormalTexture = ResourceManager.TextureDict["EmpireTopBar/empiretopbar_btn_168px_dip"],
                    HoverTexture = ResourceManager.TextureDict["EmpireTopBar/empiretopbar_btn_168px_dip_hover"],
                    PressedTexture = ResourceManager.TextureDict["EmpireTopBar/empiretopbar_btn_168px_dip_pressed"]
                };
            if (!this.marked)
                this.Colonize.Text = Localizer.Token(1425);
            else
                this.Colonize.Text = "Cancel Colonize";
            this.Colonize.Launches = Localizer.Token(1425);

            this.SendTroops = new UIButton()
            {
                Rect = new Rectangle(this.OrdersRect.X + this.Colonize.Rect.Width + 10, this.Colonize.Rect.Y, this.Colonize.Rect.Width, this.Colonize.Rect.Height),
                NormalTexture = ResourceManager.TextureDict["EmpireTopBar/empiretopbar_btn_168px_dip"],
                HoverTexture = ResourceManager.TextureDict["EmpireTopBar/empiretopbar_btn_168px_dip_hover"],
                PressedTexture = ResourceManager.TextureDict["EmpireTopBar/empiretopbar_btn_168px_dip_pressed"]
            };
        }
 private void DoMarkedColonizeGoal()
 {
     switch (this.Step)
     {
         case 0:
             bool flag1 = false;
             foreach (Ship ship in (List<Ship>)this.empire.GetShips())
             {
                 if (ship.isColonyShip && !ship.isPlayerShip() && (ship.GetAI() != null && ship.GetAI().State != AIState.Colonize))
                 {
                     this.colonyShip = ship;
                     flag1 = true;
                 }
             }
             Planet planet1 = (Planet)null;
             if (!flag1)
             {
                 List<Planet> list = new List<Planet>();
                 foreach (Planet planet2 in this.empire.GetPlanets())
                 {
                     if (planet2.HasShipyard)
                         list.Add(planet2);
                 }
                 int num1 = 9999999;
                 foreach (Planet planet2 in list)
                 {
                     int num2 = 0;
                     foreach (QueueItem queueItem in (List<QueueItem>)planet2.ConstructionQueue)
                         num2 += (int)(((double)queueItem.Cost - (double)queueItem.productionTowards) / (double)planet2.NetProductionPerTurn);
                     if (num2 < num1)
                     {
                         num1 = num2;
                         planet1 = planet2;
                     }
                 }
                 if (planet1 == null)
                     break;
                 if (this.empire.isPlayer && ResourceManager.ShipsDict.ContainsKey(this.empire.data.CurrentAutoColony))
                 {
                     planet1.ConstructionQueue.Add(new QueueItem()
                     {
                         isShip = true,
                         QueueNumber = planet1.ConstructionQueue.Count,
                         sData = ResourceManager.ShipsDict[this.empire.data.CurrentAutoColony].GetShipData(),
                         Goal = this,
                         Cost = ResourceManager.ShipsDict[this.empire.data.CurrentAutoColony].GetCost(this.empire)
                     });
                     this.PlanetBuildingAt = planet1;
                     ++this.Step;
                     break;
                 }
                 else
                 {
                     QueueItem queueItem = new QueueItem();
                     queueItem.isShip = true;
                     queueItem.QueueNumber = planet1.ConstructionQueue.Count;
                     if (ResourceManager.ShipsDict.ContainsKey(this.empire.data.DefaultColonyShip))
                     {
                         queueItem.sData = ResourceManager.ShipsDict[this.empire.data.DefaultColonyShip].GetShipData();
                     }
                     else
                     {
                         queueItem.sData = ResourceManager.ShipsDict[ResourceManager.GetEmpireByName(this.empire.data.Traits.Name).DefaultColonyShip].GetShipData();
                         this.empire.data.DefaultColonyShip = ResourceManager.GetEmpireByName(this.empire.data.Traits.Name).DefaultColonyShip;
                     }
                     queueItem.Goal = this;
                     queueItem.NotifyOnEmpty = false;
                     queueItem.Cost = ResourceManager.ShipsDict[this.empire.data.DefaultColonyShip].GetCost(this.empire);
                     planet1.ConstructionQueue.Add(queueItem);
                     this.PlanetBuildingAt = planet1;
                     ++this.Step;
                     break;
                 }
             }
             else
             {
                 this.Step = 2;
                 this.DoMarkedColonizeGoal();
                 break;
             }
         case 1:
             bool flag2 = false;
             foreach (QueueItem queueItem in (List<QueueItem>)this.PlanetBuildingAt.ConstructionQueue)
             {
                 if (queueItem.isShip && ResourceManager.ShipsDict[queueItem.sData.Name].isColonyShip)
                     flag2 = true;
             }
             if (!flag2)
             {
                 this.PlanetBuildingAt = (Planet)null;
                 this.Step = 0;
             }
             if (this.markedPlanet.Owner == null)
                 break;
             foreach (KeyValuePair<Empire, Relationship> Them in this.empire.GetRelations())
                 this.empire.GetGSAI().CheckClaim(Them, this.markedPlanet);
             this.empire.GetGSAI().Goals.QueuePendingRemoval(this);
             break;
         case 2:
             if (this.markedPlanet.Owner != null)
             {
                 foreach (KeyValuePair<Empire, Relationship> Them in this.empire.GetRelations())
                     this.empire.GetGSAI().CheckClaim(Them, this.markedPlanet);
                 this.empire.GetGSAI().Goals.QueuePendingRemoval(this);
                 break;
             }
             else
             {
                 bool flag3;
                 if (this.colonyShip == null)
                 {
                     flag3 = false;
                     foreach (Ship ship in (List<Ship>)this.empire.GetShips())
                     {
                         if (ship.isColonyShip && !ship.isPlayerShip() && (ship.GetAI() != null && ship.GetAI().State != AIState.Colonize))
                         {
                             this.colonyShip = ship;
                             flag3 = true;
                         }
                     }
                 }
                 else
                     flag3 = true;
                 if (flag3)
                 {
                     this.colonyShip.DoColonize(this.markedPlanet, this);
                     this.Step = 3;
                     break;
                 }
                 else
                 {
                     this.Step = 0;
                     break;
                 }
             }
         case 3:
             if (this.colonyShip == null)
             {
                 this.Step = 0;
                 break;
             }
             else if (this.colonyShip != null && this.colonyShip.Active && this.colonyShip.GetAI().State != AIState.Colonize)
             {
                 this.Step = 0;
                 break;
             }
             else if (this.colonyShip != null && !this.colonyShip.Active && this.markedPlanet.Owner == null)
             {
                 this.Step = 0;
                 break;
             }
             else
             {
                 if (this.markedPlanet.Owner == null)
                     break;
                 foreach (KeyValuePair<Empire, Relationship> Them in this.empire.GetRelations())
                     this.empire.GetGSAI().CheckClaim(Them, this.markedPlanet);
                 this.empire.GetGSAI().Goals.QueuePendingRemoval(this);
                 this.colonyShip.GetAI().State = AIState.AwaitingOrders;
                 this.Step = 4;
                 break;
             }
     }
 }
 private void DoFleetRequisition()
 {
     switch (this.Step)
     {
         case 0:
             Planet planet1 = (Planet)null;
             List<Planet> list = new List<Planet>();
             foreach (Planet planet2 in this.empire.GetPlanets())
             {
                 if (planet2.HasShipyard)
                     list.Add(planet2);
             }
             int num1 = 9999999;
             foreach (Planet planet2 in list)
             {
                 if (planet2.HasShipyard)
                 {
                     int num2 = 0;
                     foreach (QueueItem queueItem in (List<QueueItem>)planet2.ConstructionQueue)
                         num2 += (int)(((double)queueItem.Cost - (double)queueItem.productionTowards) / (double)planet2.NetProductionPerTurn);
                     if (planet2.ConstructionQueue.Count == 0)
                         num2 = (int)(((double)this.beingBuilt.GetCost(this.empire) - (double)planet2.ProductionHere) / (double)planet2.NetProductionPerTurn);
                     if (num2 < num1)
                     {
                         num1 = num2;
                         planet1 = planet2;
                     }
                 }
             }
             if (planet1 == null)
                 break;
             this.PlanetBuildingAt = planet1;
             planet1.ConstructionQueue.Add(new QueueItem()
             {
                 isShip = true,
                 QueueNumber = planet1.ConstructionQueue.Count,
                 sData = this.beingBuilt.GetShipData(),
                 Goal = this,
                 Cost = this.beingBuilt.GetCost(this.empire),
                 NotifyOnEmpty=false
             });
             ++this.Step;
             break;
         case 2:
             if (this.fleet != null)
             {
                 using (List<FleetDataNode>.Enumerator enumerator = this.fleet.DataNodes.GetEnumerator())
                 {
                     while (enumerator.MoveNext())
                     {
                         FleetDataNode current = enumerator.Current;
                         if (current.GoalGUID == this.guid)
                         {
                             if (this.fleet.Ships.Count == 0)
                                 this.fleet.Position = this.beingBuilt.Position + new Vector2(RandomMath.RandomBetween(-3000f, 3000f), RandomMath.RandomBetween(-3000f, 3000f));
                             current.SetShip(this.beingBuilt);
                             this.beingBuilt.fleet = this.fleet;
                             this.beingBuilt.RelativeFleetOffset = current.FleetOffset;
                             this.fleet.AddShip(this.beingBuilt);
                             current.GoalGUID = Guid.Empty;
                             this.beingBuilt.GetAI().OrderMoveToFleetPosition(this.fleet.Position + this.beingBuilt.FleetOffset, this.beingBuilt.fleet.facing, new Vector2(0.0f, -1f), true, this.fleet.speed, this.fleet);
                         }
                     }
                     break;
                 }
             }
             else
             {
                 this.empire.GetGSAI().Goals.QueuePendingRemoval(this);
                 break;
             }
     }
 }
        //Added by McShooterz: for refit to keep name
        public static Ship CreateShipAt(string key, Empire Owner, Planet p, bool DoOrbit, string RefitName, byte RefitLevel)
        {
            Ship newShip;
            //if (universeScreen.MasterShipList.pendingRemovals.TryPop(out newShip))
            //{
            //    newShip.ShipRecreate();
            //    newShip.Role = Ship_Game.ResourceManager.ShipsDict[key].Role;
            //    newShip.Name = Ship_Game.ResourceManager.ShipsDict[key].Name;
            //    newShip.BaseStrength = Ship_Game.ResourceManager.ShipsDict[key].BaseStrength;
            //    newShip.BaseCanWarp = Ship_Game.ResourceManager.ShipsDict[key].BaseCanWarp;
            //}
            //else
            newShip = new Ship()
            {
                Role = Ship_Game.ResourceManager.ShipsDict[key].Role,
                Name = Ship_Game.ResourceManager.ShipsDict[key].Name,
                BaseStrength = Ship_Game.ResourceManager.ShipsDict[key].BaseStrength,
                BaseCanWarp = Ship_Game.ResourceManager.ShipsDict[key].BaseCanWarp

            };
            newShip.LoadContent(GetContentManager());
            SceneObject newSO = new SceneObject();
            if (!Ship_Game.ResourceManager.ShipsDict[key].GetShipData().Animated)
            {
                newSO = new SceneObject(Ship_Game.ResourceManager.GetModel(Ship_Game.ResourceManager.ShipsDict[key].ModelPath).Meshes[0])
                {
                    ObjectType = ObjectType.Dynamic
                };
                newShip.SetSO(newSO);
            }
            else
            {
                SkinnedModel model = Ship_Game.ResourceManager.GetSkinnedModel(Ship_Game.ResourceManager.ShipsDict[key].ModelPath);
                newSO = new SceneObject(model.Model);
                newShip.SetAnimationController(new AnimationController(model.SkeletonBones), model);
            }
            newSO.ObjectType = ObjectType.Dynamic;
            newShip.SetSO(newSO);
            foreach (Thruster t in Ship_Game.ResourceManager.ShipsDict[key].GetTList())
            {
                Thruster thr = new Thruster()
                {
                    Parent = newShip,
                    tscale = t.tscale,
                    XMLPos = t.XMLPos
                };
                newShip.GetTList().Add(thr);
            }
            foreach (ModuleSlot slot in Ship_Game.ResourceManager.ShipsDict[key].ModuleSlotList)
            {
                ModuleSlot newSlot = new ModuleSlot();
                newSlot.SetParent(newShip);
                newSlot.SlotOptions = slot.SlotOptions;
                newSlot.Restrictions = slot.Restrictions;
                newSlot.Position = slot.Position;
                newSlot.facing = slot.facing;
                newSlot.state = slot.state;
                newSlot.InstalledModuleUID = slot.InstalledModuleUID;
                newShip.ModuleSlotList.AddLast(newSlot);
            }
            newShip.Position = p.Position;
            newShip.loyalty = Owner;

            newShip.Initialize();
            //Added by McShooterz: add automatic ship naming
            newShip.VanityName = RefitName;
            newShip.Level = RefitLevel;
            newShip.GetSO().World = Matrix.CreateTranslation(new Vector3(newShip.Center, 0f));
            lock (GlobalStats.ObjectManagerLocker)
            {
                Ship_Game.ResourceManager.universeScreen.ScreenManager.inter.ObjectManager.Submit(newShip.GetSO());
            }
            foreach (Thruster t in newShip.GetTList())
            {
                t.load_and_assign_effects(Ship_Game.ResourceManager.universeScreen.ScreenManager.Content, "Effects/ThrustCylinderB", "Effects/NoiseVolume", Ship_Game.ResourceManager.universeScreen.ThrusterEffect);
                t.InitializeForViewing();
            }
            if (newShip.Role == "fighter")
            {
                Ship level = newShip;
                level.Level += Owner.data.BonusFighterLevels;
            }
            Owner.AddShip(newShip);
            newShip.GetAI().State = AIState.AwaitingOrders;
            return newShip;
        }
 private float GetGroundStrOfPlanet(Planet p)
 {
     float num = 0.0f;
     foreach (PlanetGridSquare planetGridSquare in p.TilesList)
     {
         if (planetGridSquare.TroopsHere.Count > 0)
             num += (float)planetGridSquare.TroopsHere[0].Strength;
         else if (planetGridSquare.building != null && planetGridSquare.building.CombatStrength > 0)
             num += (float)planetGridSquare.building.CombatStrength;
     }
     return num;
 }
        public void DamageRelationship(Empire Us, Empire Them, string why, float Amount, Planet p)
        {
            if (Us.data.DiplomaticPersonality == null)
            {
                return;
            }
            #if PERF
            if (EmpireManager.GetEmpireByName(Us.GetUS().PlayerLoyalty)==Them)
                return;
            #endif

            if (GlobalStats.perf && EmpireManager.GetEmpireByName(Us.GetUS().PlayerLoyalty) == Them)
                return;
            string str = why;
            string str1 = str;
            if (str != null)
            {
                if (str1 == "Caught Spying")
                {
                    Relationship angerDiplomaticConflict = this;
                    angerDiplomaticConflict.Anger_DiplomaticConflict = angerDiplomaticConflict.Anger_DiplomaticConflict + Amount;
                    Relationship totalAnger = this;
                    totalAnger.TotalAnger = totalAnger.TotalAnger + Amount;
                    Relationship trust = this;
                    trust.Trust = trust.Trust - Amount;
                    Relationship spiesDetected = this;
                    spiesDetected.SpiesDetected = spiesDetected.SpiesDetected + 1;
                    if (Us.data.DiplomaticPersonality.Name == "Honorable" || Us.data.DiplomaticPersonality.Name == "Xenophobic")
                    {
                        Relationship relationship = this;
                        relationship.Anger_DiplomaticConflict = relationship.Anger_DiplomaticConflict + Amount;
                        Relationship totalAnger1 = this;
                        totalAnger1.TotalAnger = totalAnger1.TotalAnger + Amount;
                        Relationship trust1 = this;
                        trust1.Trust = trust1.Trust - Amount;
                    }
                    if (this.Treaty_Alliance)
                    {
                        Relationship timesSpiedOnAlly = this;
                        timesSpiedOnAlly.TimesSpiedOnAlly = timesSpiedOnAlly.TimesSpiedOnAlly + 1;
                        if (this.TimesSpiedOnAlly == 1)
                        {
                            if (EmpireManager.GetEmpireByName(Us.GetUS().PlayerLoyalty) == Them && !Us.isFaction)
                            {
                                Us.GetUS().ScreenManager.AddScreen(new DiplomacyScreen(Us, Them, "Caught_Spying_Ally_1", true));
                                return;
                            }
                        }
                        else if (this.TimesSpiedOnAlly > 1)
                        {
                            if (EmpireManager.GetEmpireByName(Us.GetUS().PlayerLoyalty) == Them && !Us.isFaction)
                            {
                                Us.GetUS().ScreenManager.AddScreen(new DiplomacyScreen(Us, Them, "Caught_Spying_Ally_2", true));
                            }
                            this.Treaty_Alliance = false;
                            this.Treaty_NAPact = false;
                            this.Treaty_OpenBorders = false;
                            this.Treaty_Trade = false;
                            this.Posture = Ship_Game.Gameplay.Posture.Hostile;
                            return;
                        }
                    }
                    else if (this.SpiesDetected == 1 && !this.AtWar && EmpireManager.GetEmpireByName(Us.GetUS().PlayerLoyalty) == Them && !Us.isFaction)
                    {
                        if (this.SpiesDetected == 1)
                        {
                            if (EmpireManager.GetEmpireByName(Us.GetUS().PlayerLoyalty) == Them && !Us.isFaction)
                            {
                                Us.GetUS().ScreenManager.AddScreen(new DiplomacyScreen(Us, Them, "Caught_Spying_1", true));
                                return;
                            }
                        }
                        else if (this.SpiesDetected == 2)
                        {
                            if (EmpireManager.GetEmpireByName(Us.GetUS().PlayerLoyalty) == Them && !Us.isFaction)
                            {
                                Us.GetUS().ScreenManager.AddScreen(new DiplomacyScreen(Us, Them, "Caught_Spying_2", true));
                                return;
                            }
                        }
                        else if (this.SpiesDetected >= 3)
                        {
                            if (EmpireManager.GetEmpireByName(Us.GetUS().PlayerLoyalty) == Them && !Us.isFaction)
                            {
                                Us.GetUS().ScreenManager.AddScreen(new DiplomacyScreen(Us, Them, "Caught_Spying_3", true));
                            }
                            this.Treaty_Alliance = false;
                            this.Treaty_NAPact = false;
                            this.Treaty_OpenBorders = false;
                            this.Treaty_Trade = false;
                            this.Posture = Ship_Game.Gameplay.Posture.Hostile;
                            return;
                        }
                    }
                }
                else if (str1 == "Caught Spying Failed")
                {
                    Relationship angerDiplomaticConflict1 = this;
                    angerDiplomaticConflict1.Anger_DiplomaticConflict = angerDiplomaticConflict1.Anger_DiplomaticConflict + Amount;
                    Relationship relationship1 = this;
                    relationship1.TotalAnger = relationship1.TotalAnger + Amount;
                    Relationship trust2 = this;
                    trust2.Trust = trust2.Trust - Amount;
                    if (Us.data.DiplomaticPersonality.Name == "Honorable" || Us.data.DiplomaticPersonality.Name == "Xenophobic")
                    {
                        Relationship angerDiplomaticConflict2 = this;
                        angerDiplomaticConflict2.Anger_DiplomaticConflict = angerDiplomaticConflict2.Anger_DiplomaticConflict + Amount;
                        Relationship totalAnger2 = this;
                        totalAnger2.TotalAnger = totalAnger2.TotalAnger + Amount;
                        Relationship relationship2 = this;
                        relationship2.Trust = relationship2.Trust - Amount;
                    }
                    Relationship spiesKilled = this;
                    spiesKilled.SpiesKilled = spiesKilled.SpiesKilled + 1;
                    if (this.Treaty_Alliance)
                    {
                        Relationship timesSpiedOnAlly1 = this;
                        timesSpiedOnAlly1.TimesSpiedOnAlly = timesSpiedOnAlly1.TimesSpiedOnAlly + 1;
                        if (this.TimesSpiedOnAlly == 1)
                        {
                            if (EmpireManager.GetEmpireByName(Us.GetUS().PlayerLoyalty) == Them && !Us.isFaction)
                            {
                                Us.GetUS().ScreenManager.AddScreen(new DiplomacyScreen(Us, Them, "Caught_Spying_Ally_1", true));
                                return;
                            }
                        }
                        else if (this.TimesSpiedOnAlly > 1)
                        {
                            if (EmpireManager.GetEmpireByName(Us.GetUS().PlayerLoyalty) == Them && !Us.isFaction)
                            {
                                Us.GetUS().ScreenManager.AddScreen(new DiplomacyScreen(Us, Them, "Caught_Spying_Ally_2", true));
                            }
                            this.Treaty_Alliance = false;
                            this.Treaty_NAPact = false;
                            this.Treaty_OpenBorders = false;
                            this.Treaty_Trade = false;
                            this.Posture = Ship_Game.Gameplay.Posture.Hostile;
                            return;
                        }
                    }
                    else if (EmpireManager.GetEmpireByName(Us.GetUS().PlayerLoyalty) == Them && !Us.isFaction)
                    {
                        Us.GetUS().ScreenManager.AddScreen(new DiplomacyScreen(Us, Them, "Killed_Spy_1", true));
                        return;
                    }
                }
                else if (str1 == "Insulted")
                {
                    Relationship angerDiplomaticConflict3 = this;
                    angerDiplomaticConflict3.Anger_DiplomaticConflict = angerDiplomaticConflict3.Anger_DiplomaticConflict + Amount;
                    Relationship totalAnger3 = this;
                    totalAnger3.TotalAnger = totalAnger3.TotalAnger + Amount;
                    Relationship trust3 = this;
                    trust3.Trust = trust3.Trust - Amount;
                    if (Us.data.DiplomaticPersonality.Name == "Honorable" || Us.data.DiplomaticPersonality.Name == "Xenophobic")
                    {
                        Relationship relationship3 = this;
                        relationship3.Anger_DiplomaticConflict = relationship3.Anger_DiplomaticConflict + Amount;
                        Relationship totalAnger4 = this;
                        totalAnger4.TotalAnger = totalAnger4.TotalAnger + Amount;
                        Relationship trust4 = this;
                        trust4.Trust = trust4.Trust - Amount;
                        return;
                    }
                }
                else if (str1 == "Colonized Owned System")
                {
                    List<Planet> OurTargetPlanets = new List<Planet>();
                    List<Planet> TheirTargetPlanets = new List<Planet>();
                    foreach (Goal g in Us.GetGSAI().Goals)
                    {
                        if (g.type != GoalType.Colonize)
                        {
                            continue;
                        }
                        OurTargetPlanets.Add(g.GetMarkedPlanet());
                    }
                    foreach (Planet theirp in Them.GetPlanets())
                    {
                        TheirTargetPlanets.Add(theirp);
                    }
                    bool MatchFound = false;
                    SolarSystem sharedSystem = null;
                    foreach (Planet planet in OurTargetPlanets)
                    {
                        foreach (Planet other in TheirTargetPlanets)
                        {
                            if (p == null || other == null || p.system != other.system)
                            {
                                continue;
                            }
                            sharedSystem = p.system;
                            MatchFound = true;
                            break;
                        }
                        if (!MatchFound || !Us.GetRelations()[Them].WarnedSystemsList.Contains(sharedSystem.guid))
                        {
                            continue;
                        }
                        return;
                    }
                    Relationship angerTerritorialConflict = this;
                    angerTerritorialConflict.Anger_TerritorialConflict = angerTerritorialConflict.Anger_TerritorialConflict + Amount;
                    Relationship relationship4 = this;
                    relationship4.Trust = relationship4.Trust - Amount;
                    if (this.Anger_TerritorialConflict < (float)Us.data.DiplomaticPersonality.Territorialism && !this.AtWar)
                    {
                        if (this.AtWar)
                        {
                            return;
                        }
                        if (EmpireManager.GetEmpireByName(Us.GetUS().PlayerLoyalty) == Them && !Us.isFaction)
                        {
                            if (!this.WarnedAboutShips)
                            {
                                Us.GetUS().ScreenManager.AddScreen(new DiplomacyScreen(Us, Them, "Colonized Warning", p));
                            }
                            else if (!this.AtWar)
                            {
                                Us.GetUS().ScreenManager.AddScreen(new DiplomacyScreen(Us, Them, "Warning Ships then Colonized", p));
                            }
                            this.turnsSinceLastContact = 0;
                            this.WarnedAboutColonizing = true;
                            this.contestedSystem = p.system;
                            this.contestedSystemGuid = p.system.guid;
                            return;
                        }
                    }
                }
                else
                {
                    if (str1 != "Destroyed Ship")
                    {
                        return;
                    }
                    if (this.Anger_MilitaryConflict == 0f && !this.AtWar)
                    {
                        Relationship angerMilitaryConflict = this;
                        angerMilitaryConflict.Anger_MilitaryConflict = angerMilitaryConflict.Anger_MilitaryConflict + Amount;
                        Relationship trust5 = this;
                        trust5.Trust = trust5.Trust - Amount;
                        if (EmpireManager.GetEmpireByName(Us.GetUS().PlayerLoyalty) == Them && !Us.isFaction)
                        {
                            if (this.Anger_MilitaryConflict < 2f)
                            {
                                Us.GetUS().ScreenManager.AddScreen(new DiplomacyScreen(Us, Them, "Aggression Warning"));
                            }
                            Relationship relationship5 = this;
                            relationship5.Trust = relationship5.Trust - Amount;
                        }
                    }
                    Relationship angerMilitaryConflict1 = this;
                    angerMilitaryConflict1.Anger_MilitaryConflict = angerMilitaryConflict1.Anger_MilitaryConflict + Amount;
                }
            }
        }
 public void SetPlanet(Planet p)
 {
     this.SelectedPlanet = p;
 }
 private float GetDistanceFromOurAO(Planet p)
 {
     IOrderedEnumerable<AO> sortedList =
         from area in this.AreasOfOperations
         orderby Vector2.Distance(p.Position, area.Position)
         select area;
     if (sortedList.Count<AO>() == 0)
     {
         return 0f;
     }
     return Vector2.Distance(p.Position, sortedList.First<AO>().Position);
 }
 public void InitializeMissilePlanet(float initialSpeed, Vector2 direction, GameplayObject Target, Ship_Game.Planet p)
 {
     this.direction = direction;
     this.Center = p.Position;
     this.zStart = -2500f;
     this.velocity = (initialSpeed * direction) + (this.owner != null ? this.owner.Velocity : Vector2.Zero);
     this.radius = 1f;
     this.velocityMaximum = initialSpeed + (this.owner != null ? this.owner.Velocity.Length() : 0f);
     this.duration = this.range / initialSpeed * 2f;
     this.initialDuration = this.duration;
     this.planet = p;
     if (this.weapon.Animated == 1)
     {
         this.switchFrames = this.initialDuration / (float)this.weapon.Frames;
         if (this.weapon.LoopAnimation == 1)
         {
             this.AnimationFrame = (int)((this.system != null ? this.system.RNG : Ship.universeScreen.DeepSpaceRNG)).RandomBetween(0f, (float)(this.weapon.Frames - 1));
         }
     }
     Projectile projectile1 = this;
     projectile1.particleDelay = projectile1.particleDelay + this.weapon.particleDelay;
     if (this.weapon.Tag_Guided)
     {
         this.missileAI = new MissileAI(this);
         this.missileAI.SetTarget(Target);
     }
     if (this.ProjSO !=null &&(this.WeaponType == "Missile" || this.WeaponType == "Drone" || this.WeaponType == "Rocket") && (this.system != null && this.system.isVisible || this.isInDeepSpace))
     {
         this.wasAddedToSceneGraph = true;
         lock (GlobalStats.ObjectManagerLocker)
         {
             Projectile.universeScreen.ScreenManager.inter.ObjectManager.Submit(this.ProjSO);
         }
     }
     if (this.system == null)
     {
         Projectile.universeScreen.DSProjectilesToAdd.Add(this);
         UniverseScreen.DeepSpaceManager.CollidableProjectiles.Add(this);
     }
     else
     {
         //lock (GlobalStats.BucketLock)
         {
             this.system.spatialManager.CollidableProjectiles.Add(this);
             this.system.spatialManager.RegisterObject(this);
             this.system.spatialManager.CollidableObjects.Add(this);
         }
     }
     base.Initialize();
 }
 public virtual void FireFromPlanet(Vector2 direction, Planet p, GameplayObject target)
 {
     if (target is ShipModule)
         (target as ShipModule).GetParent().InCombatTimer = 15f;
     Vector2 StartPos = p.Position;
     if (this.FireArc != 0)
     {
         float DegreesBetweenShots = (float)(this.FireArc / this.ProjectileCount);
         float angleToTarget = this.findAngleToTarget(direction);
         for (int i = 0; i < this.ProjectileCount; i++)
         {
             Vector2 newTarget = this.findTargetFromAngleAndDistance(StartPos, angleToTarget - (float)(this.FireArc / 2) + DegreesBetweenShots * (float)i, this.Range);
             Vector2 fireDirection = this.findVectorToTarget(StartPos, newTarget);
             fireDirection.Y = fireDirection.Y * -1f;
             this.CreateProjectilesFromPlanet(Vector2.Normalize(fireDirection), p, target);
         }
         return;
     }
     if (this.FireCone <= 0)
     {
         if (!this.isBeam)
         {
             for (int i = 0; i < this.ProjectileCount; i++)
             {
                 if (this.WeaponType != "Missile")
                 {
                     this.CreateProjectilesFromPlanet(direction, p, target);
                 }
                 else
                 {
                     this.CreateProjectilesFromPlanet(Vector2.Normalize(direction), p, target);
                 }
             }
         }
         return;
     }
     float spread = RandomMath2.RandomBetween((float)(-this.FireCone / 2), (float)(this.FireCone / 2));
     float angleToTarget2 = this.findAngleToTarget(direction);
     Vector2 newTarget2 = this.findTargetFromAngleAndDistance(StartPos, angleToTarget2 + spread, this.Range);
     Vector2 fireDirection2 = this.findVectorToTarget(StartPos, newTarget2);
     fireDirection2.Y = fireDirection2.Y * -1f;
     this.CreateProjectilesFromPlanet(Vector2.Normalize(fireDirection2), p, target);
 }
 protected virtual void CreateProjectilesFromPlanet(Vector2 direction, Planet p, GameplayObject target)
 {
     Projectile projectile = new Projectile(p, direction)
     {
         range = this.Range,
         weapon = this,
         explodes = this.explodes,
         damageAmount = this.DamageAmount
     };
     if (this.RangeVariance)
     {
         projectile.range *= RandomMath.RandomBetween(0.9f, 1.1f);
     }
     projectile.explodes = this.explodes;
     projectile.damageRadius = this.DamageRadius;
     projectile.explosionradiusmod = this.ExplosionRadiusVisual;
     projectile.Health = this.HitPoints;
     projectile.speed = this.ProjectileSpeed;
     projectile.WeaponEffectType = this.WeaponEffectType;
     projectile.WeaponType = this.WeaponType;
     projectile.LoadContent(this.ProjectileTexturePath, this.ModelPath);
     projectile.RotationRadsPerSecond = this.RotationRadsPerSecond;
     projectile.ArmorPiercing = (byte)this.ArmourPen;
     /*
     if (this.ShieldPenChance > 0)
     {
         projectile.IgnoresShields = RandomMath.RandomBetween(0, 100) <= this.ShieldPenChance;
     } */
     this.ModifyProjectile(projectile);
     if(this.Tag_Guided)
         projectile.InitializeMissilePlanet(projectile.speed, direction, target, p);
     else
         projectile.InitializePlanet(projectile.speed, direction, p.Position);
     projectile.Radius = this.ProjectileRadius;
     if (this.Animated == 1)
     {
         string remainder = 0.ToString("00000.##");
         projectile.texturePath = string.Concat(this.AnimationPath, remainder);
     }
     p.Projectiles.Add(projectile);
     this.planetEmitter = new AudioEmitter()
     {
         Position = new Vector3(p.Position, 2500f)
     };
     if (Weapon.universeScreen.viewState <= UniverseScreen.UnivScreenState.SystemView)
     {
         projectile.DieSound = true;
         if (!string.IsNullOrEmpty(this.ToggleSoundName) && !this.ToggleSoundOn)
         {
             this.ToggleSoundOn = true;
             this.ToggleCue = AudioManager.GetCue(this.ToggleSoundName);
             this.ToggleCue.Apply3D(Weapon.audioListener, this.planetEmitter);
             this.ToggleCue.Play();
             this.lastFireSound = 0f;
             //Added by McShooterz: Use sounds from new sound dictionary
             if (ResourceManager.SoundEffectDict.ContainsKey(this.fireCueName))
             {
                 AudioManager.PlaySoundEffect(ResourceManager.SoundEffectDict[fireCueName], Weapon.audioListener, this.planetEmitter, 0.5f);
             }
             else
             {
                 this.fireCue = AudioManager.GetCue(this.fireCueName);
                 if (!this.owner.isPlayerShip())
                 {
                     this.fireCue.Apply3D(Weapon.audioListener, this.planetEmitter);
                 }
                 if (this.fireCue != null)
                 {
                     this.fireCue.Play();
                 }
             }
         }
         if (!string.IsNullOrEmpty(ResourceManager.WeaponsDict[this.UID].dieCue))
         {
             projectile.dieCueName = ResourceManager.WeaponsDict[this.UID].dieCue;
         }
         if (!string.IsNullOrEmpty(this.InFlightCue))
         {
             projectile.InFlightCue = this.InFlightCue;
         }
         try
         {
             if (this.ToggleCue == null)
             {
                 this.planetEmitter.Position = new Vector3(p.Position, -2500f);
                 this.lastFireSound = 0f;
                 //Added by McShooterz: Use sounds from new sound dictionary
                 if (ResourceManager.SoundEffectDict.ContainsKey(this.fireCueName))
                 {
                     AudioManager.PlaySoundEffect(ResourceManager.SoundEffectDict[fireCueName], Weapon.audioListener, this.planetEmitter, 0.5f);
                 }
                 else
                 {
                     this.fireCue = AudioManager.GetCue(this.fireCueName);
                     this.fireCue.Apply3D(Weapon.audioListener, this.planetEmitter);
                     if (this.fireCue != null)
                     {
                         this.fireCue.Play();
                     }
                 }
             }
         }
         catch
         {
         }
     }
 }
 public void SetPlanet(Planet p)
 {
     if (p == null)
     {
         p = null;
         return;
     }
     this.p = p;
     if (!p.TroopsHere.Contains(this))
     {
         p.TroopsHere.Add(this);
     }
 }
 public static Ship CreateShipAt(string key, Empire Owner, Planet p, bool DoOrbit, string role, List<Troop> Troops)
 {
     Ship newShip = new Ship()
     {
         Role = role,
         BaseStrength = Ship_Game.ResourceManager.ShipsDict[key].BaseStrength,
         BaseCanWarp = Ship_Game.ResourceManager.ShipsDict[key].BaseCanWarp
     };
     if (role == "troop")
     {
         if (Troops.Count <= 0)
         {
             newShip.VanityName = "Troop Shuttle";
         }
         else
         {
             newShip.VanityName = Troops[0].Name;
         }
     }
     newShip.Name = Ship_Game.ResourceManager.ShipsDict[key].Name;
     newShip.LoadContent(GetContentManager());
     SceneObject newSO = new SceneObject();
     if (!Ship_Game.ResourceManager.ShipsDict[key].GetShipData().Animated)
     {
         newSO = new SceneObject(Ship_Game.ResourceManager.GetModel(Ship_Game.ResourceManager.ShipsDict[key].ModelPath).Meshes[0])
         {
             ObjectType = ObjectType.Dynamic
         };
     }
     else
     {
         SkinnedModel model = Ship_Game.ResourceManager.GetSkinnedModel(Ship_Game.ResourceManager.ShipsDict[key].ModelPath);
         newSO = new SceneObject(model.Model);
         newShip.SetAnimationController(new AnimationController(model.SkeletonBones), model);
     }
     newShip.SetSO(newSO);
     newShip.Position = p.Position;
     foreach (Thruster t in Ship_Game.ResourceManager.ShipsDict[key].GetTList())
     {
         Thruster thr = new Thruster()
         {
             Parent = newShip,
             tscale = t.tscale,
             XMLPos = t.XMLPos
         };
         newShip.GetTList().Add(thr);
     }
     foreach (ModuleSlot slot in Ship_Game.ResourceManager.ShipsDict[key].ModuleSlotList)
     {
         ModuleSlot newSlot = new ModuleSlot();
         newSlot.SetParent(newShip);
         newSlot.SlotOptions = slot.SlotOptions;
         newSlot.Restrictions = slot.Restrictions;
         newSlot.Position = slot.Position;
         newSlot.facing = slot.facing;
         newSlot.state = slot.state;
         newSlot.InstalledModuleUID = slot.InstalledModuleUID;
         newShip.ModuleSlotList.AddLast(newSlot);
     }
     if (newShip.Role == "fighter")
     {
         Ship level = newShip;
         level.Level = level.Level + Owner.data.BonusFighterLevels;
     }
     newShip.loyalty = Owner;
     newShip.Initialize();
     //Added by McShooterz: add automatic ship naming
     if (GlobalStats.ActiveModInfo != null && Ship_Game.ResourceManager.ShipNames.CheckForName(Owner.data.Traits.ShipType, newShip.Role))
         newShip.VanityName = Ship_Game.ResourceManager.ShipNames.GetName(Owner.data.Traits.ShipType, newShip.Role);
     newShip.GetSO().World = Matrix.CreateTranslation(new Vector3(newShip.Center, 0f));
     lock (GlobalStats.ObjectManagerLocker)
     {
         Ship_Game.ResourceManager.universeScreen.ScreenManager.inter.ObjectManager.Submit(newShip.GetSO());
     }
     foreach (Thruster t in newShip.GetTList())
     {
         t.load_and_assign_effects(Ship_Game.ResourceManager.universeScreen.ScreenManager.Content, "Effects/ThrustCylinderB", "Effects/NoiseVolume", Ship_Game.ResourceManager.universeScreen.ThrusterEffect);
         t.InitializeForViewing();
     }
     if (DoOrbit)
     {
         newShip.DoOrbit(p);
     }
     foreach (Troop t in Troops)
     {
         newShip.TroopList.Add(Ship_Game.ResourceManager.CopyTroop(t));
     }
     Owner.AddShip(newShip);
     return newShip;
 }
 public void SetMarkedPlanet(Planet p)
 {
     this.markedPlanet = p;
 }
        public bool WeCanAffordThis(Building building, Planet.ColonyType governor)
        {
            if (governor == ColonyType.TradeHub)
                return true;
            if (building == null)
                return false;
            Empire empire = this.Owner;
            float buildingMaintenance = empire.GetTotalBuildingMaintenance();
            float grossTaxes = empire.GrossTaxes;

            if (building.AllowInfantry && !this.BuildingList.Contains(building) &&( this.AllowInfantry || governor == ColonyType.Military))
                return false;

            //this.data.Traits.MaintMod * this.totalBuildingMaintenance
            foreach (QueueItem queueItem in (List<QueueItem>)this.ConstructionQueue)
            {
                if (queueItem.isBuilding)
                    buildingMaintenance += this.Owner.data.Traits.MaintMod * queueItem.Building.Maintenance;
            }
            buildingMaintenance += building.Maintenance + building.Maintenance * this.Owner.data.Traits.MaintMod;
            bool LowPri = buildingMaintenance / grossTaxes < .25f;
            bool MedPri = buildingMaintenance / grossTaxes < .60f;
            bool HighPri = buildingMaintenance / grossTaxes < .80f;
            float maintCost = this.GrossMoneyPT + this.Owner.data.Traits.TaxMod * this.GrossMoneyPT -building.Maintenance- (this.TotalMaintenanceCostsPerTurn + this.TotalMaintenanceCostsPerTurn * this.Owner.data.Traits.MaintMod);
            bool makingMoney = maintCost > 0 && this.Owner.data.TaxRate <.5 && this.Owner.GetAverageNetIncome() >0;// this.TotalMaintenanceCostsPerTurn  < this.GrossMoneyPT;
            int defensiveBuildings = this.BuildingList.Where(combat => combat.Strength > 0 || combat.PlanetaryShieldStrengthAdded >0 ).Count();
               int offensiveBuildings = this.BuildingList.Where(combat => combat.theWeapon !=null).Count();
            SystemCommander SC;
            //float defensiveNeeds =0;
            bool needDefense =false;
            if (this.Owner.GetGSAI().DefensiveCoordinator.DefenseDict.TryGetValue(this.system, out SC))
            {
                //defensiveNeeds = SC.RankImportance * .1f;
                if (makingMoney)
                    needDefense = SC.RankImportance > 10;//(this.BuildingList.Count / (defensiveBuildings + offensiveBuildings+1)) >defensiveNeeds;

            }

            if (!string.IsNullOrEmpty(building.ExcludesPlanetType) && building.ExcludesPlanetType == this.Type)
                return false;
            if (building.Maintenance <= 0.0f)
                return true;
            if (building.PlusTaxPercentage * this.GrossMoneyPT > building.Maintenance * 1.25f
                || building.CreditsPerColonist * (this.Population / 1000f) > building.Maintenance *1.25f

                )
                return true;
            if (building .Name == "Outpost" || building.WinsGame  )
                return true;
            if (building.PlusFoodPerColonist > 0)// && this.Fertility == 0)
            {

                if (this.Fertility == 0|| (this.NetFoodPerTurn >0 && this.FarmerPercentage <.3) &&!this.BuildingList.Contains(building))

                return false;

            }
            if (building.PlusFlatFoodAmount > 0 && this.NetFoodPerTurn > 0 && this.FarmerPercentage < .3 && !this.BuildingList.Contains(building))
                return false;

            bool iftrue = false;
            switch  (governor)
            {
                case ColonyType.Agricultural:
                    #region MyRegion
                    {
                        if (building.AllowShipBuilding && this.GetMaxProductionPotential()>20 )
                        {
                            return true;
                        }
                        if (this.Fertility > 0 && building.MinusFertilityOnBuild > 0 && this.Owner.data.Traits.Cybernetic <=0)
                            return false;
                        if (HighPri)
                        {
                            if (building.PlusFlatFoodAmount > 0
                                || (building.PlusFoodPerColonist > 0 && this.Population > 500f)
                                || building.Name == "Biospheres"
                                || this.developmentLevel > 4
                                || ((building.MaxPopIncrease > 0
                                || building.PlusFlatPopulation > 0 || building.PlusTerraformPoints > 0) && this.Population > this.MaxPopulation * .5f)
                                || building.PlusFlatFoodAmount > 0
                                || building.PlusFlatProductionAmount > 0
                                || (building.StorageAdded > 0 && this.FoodHere == MAX_STORAGE)
                                || (this.Owner.data.Traits.Cybernetic > 0 && (building.PlusProdPerRichness > 0 || building.PlusProdPerColonist > 0 || building.PlusFlatProductionAmount>0))

                                )
                                return true;
                                //iftrue = true;

                        }
                        if (!iftrue && MedPri)
                        {
                            if (

                                ( building.PlusTerraformPoints > 0 && this.Fertility <3)
                                || building.MaxPopIncrease > 0
                                || building.PlusFlatPopulation > 0
                                || this.developmentLevel > 3
                                )
                                return true;
                        }
                        if (LowPri && this.developmentLevel > 4 && makingMoney)
                        {
                            iftrue = true;
                        }
                        break;
                    }
                    #endregion
                case ColonyType.Core:
                    #region MyRegion
                    {
                        if (this.Fertility > 0 && building.MinusFertilityOnBuild > 0 && this.Owner.data.Traits.Cybernetic <= 0)
                            return false;
                        if (HighPri)
                        {

                            if (building.StorageAdded > 0
                                || ((building.PlusTerraformPoints > 0 && this.Fertility < 1) && this.MaxPopulation > 2000)
                                || ((building.MaxPopIncrease > 0 || building.PlusFlatPopulation > 0 ) && this.Population > this.MaxPopulation * .5f)
                                || building.PlusFlatFoodAmount > 0
                                || building.PlusFoodPerColonist > 0
                                || building.PlusFlatProductionAmount > 0
                                || building.PlusProdPerRichness >0
                                || building.PlusProdPerColonist >0
                                || building.PlusFlatResearchAmount>0
                                || building.PlusResearchPerColonist * this.Population / 1000 > building.Maintenance
                                //|| building.Name == "Biospheres"

                                || needDefense &&(defensiveBuildings <1 && building.PlanetaryShieldStrengthAdded>0)
                                || needDefense && (offensiveBuildings <1 && building.Strength >0)
                                || needDefense && (makingMoney && this.developmentLevel >4)
                                || (this.Owner.data.Traits.Cybernetic > 0 && (building.PlusProdPerRichness > 0 || building.PlusProdPerColonist > 0 || building.PlusFlatProductionAmount > 0))
                                )
                                return true;
                        }
                        if (MedPri && this.developmentLevel > 3 &&makingMoney )
                        {
                            if ((building.theWeapon != null || building.Strength > 0) && !needDefense)
                                return false;
                            iftrue = true;
                        }
                        if (!iftrue && LowPri && this.developmentLevel > 4 && makingMoney)
                        {

                            iftrue = true;
                        }
                        break;
                    }
                    #endregion

                case ColonyType.Industrial:
                    #region MyRegion
                    {
                        if (building.AllowShipBuilding && this.GetMaxProductionPotential() > 20)
                        {
                            return true;
                        }
                        if (HighPri)
                        {
                            if (building.PlusFlatProductionAmount > 0
                                || building.PlusProdPerRichness > 0
                                || building.PlusProdPerColonist > 0
                                //|| building.PlusFlatProductionAmount > 0
                                || (this.Fertility < 1f && building.PlusFlatFoodAmount > 0)
                                || building.StorageAdded > 0
                                || (this.Owner.data.Traits.Cybernetic > 0 && (building.PlusProdPerRichness > 0 || building.PlusProdPerColonist > 0 || building.PlusFlatProductionAmount > 0))
                                )
                                return true;
                        }
                        if (MedPri && this.developmentLevel > 2 && makingMoney)
                        {
                            if (building.PlusResearchPerColonist * this.Population/1000 >building.Maintenance
                            ||    ((building.MaxPopIncrease > 0 || building.PlusFlatPopulation > 0 ) && this.Population > this.MaxPopulation * .5f)
                            || (building.PlusTerraformPoints > 0 && this.Fertility < 1 && this.Population > this.MaxPopulation * .5f && this.MaxPopulation >2000)
                               || (building.PlusFlatFoodAmount > 0 && this.NetFoodPerTurn <0)
                                )

                            {
                                iftrue = true;
                            }

                        }
                        if (!iftrue && LowPri && this.developmentLevel > 3 && makingMoney)
                        {
                            if (this.developmentLevel < 3 && (building.theWeapon != null || building.Strength > 0) && !needDefense)
                                return false;
                            iftrue = true;
                        }
                        break;
                    }
                    #endregion
                case ColonyType.Military:
                    #region MyRegion
                    {
                        if (this.Fertility > 0 && building.MinusFertilityOnBuild > 0 && this.Owner.data.Traits.Cybernetic <= 0)
                            return false;
                        if (HighPri)
                        {
                            if (building.isWeapon
                                || building.IsSensor
                                || building.Defense > 0
                                || (this.Fertility < 1f && building.PlusFlatFoodAmount > 0)
                                || (this.MineralRichness < 1f && building.PlusFlatFoodAmount > 0)
                                || building.PlanetaryShieldStrengthAdded > 0
                                || (building.AllowShipBuilding  && this.GrossProductionPerTurn >1)
                                || (building.ShipRepair > 0&& this.GrossProductionPerTurn >1)
                                || building.Strength > 0
                                || (building.AllowInfantry && this.GrossProductionPerTurn >1)
                                || needDefense &&(building.theWeapon !=null || building.Strength >0)
                                || (this.Owner.data.Traits.Cybernetic > 0 && (building.PlusProdPerRichness > 0 || building.PlusProdPerColonist > 0 || building.PlusFlatProductionAmount > 0))
                                )
                                iftrue = true;
                        }
                        if (!iftrue && MedPri)
                        {
                            if (building.PlusFlatProductionAmount > 0
                                || building.PlusProdPerRichness > 0
                                || building.PlusProdPerColonist > 0
                                || building.PlusFlatProductionAmount > 0)
                                iftrue = true;
                        }
                        if (!iftrue && LowPri && this.developmentLevel > 4)
                        {
                            //if(building.Name!= "Biospheres")
                            iftrue = true;

                        }
                        break;
                    }
                    #endregion
                case ColonyType.Research:
                    #region MyRegion
                    {
                        if (building.AllowShipBuilding && this.GetMaxProductionPotential() > 20)
                        {
                            return true;
                        }
                        if (this.Fertility > 0 && building.MinusFertilityOnBuild > 0 && this.Owner.data.Traits.Cybernetic <= 0)
                            return false;
                        if (HighPri)
                        {
                            if (building.PlusFlatResearchAmount > 0
                                || (this.Fertility < 1f && building.PlusFlatFoodAmount > 0)
                                || building.PlusFlatProductionAmount >0
                                || building.PlusResearchPerColonist > 0
                                || (this.Owner.data.Traits.Cybernetic > 0 && (building.PlusFlatProductionAmount > 0 || building.PlusProdPerColonist > 0 ))
                                )
                                return true;

                        }
                        if ( MedPri && this.developmentLevel > 3 && makingMoney)
                        {
                            if (((building.MaxPopIncrease > 0 || building.PlusFlatPopulation > 0) && this.Population > this.MaxPopulation * .5f)
                            || (building.PlusTerraformPoints > 0 && this.Fertility < 1 && this.Population > this.MaxPopulation * .5f && this.MaxPopulation >2000)
                                || (building.PlusFlatFoodAmount > 0 && this.NetFoodPerTurn < 0)
                                )
                                return true;
                        }
                        if ( LowPri && this.developmentLevel > 4 && makingMoney)
                        {
                            if ((building.theWeapon != null || building.Strength > 0) && !needDefense)
                                return false;
                            return true;
                        }
                        break;
                    }
                    #endregion
            }
            return iftrue;
        }
 public void CheckClaim(KeyValuePair<Empire, Relationship> Them, Planet claimedPlanet)
 {
     if (this.empire == EmpireManager.GetEmpireByName(this.empire.GetUS().PlayerLoyalty))
     {
         return;
     }
     if (this.empire.isFaction)
     {
         return;
     }
     if (!Them.Value.Known)
     {
         return;
     }
     if (Them.Value.WarnedSystemsList.Contains(claimedPlanet.system.guid) && claimedPlanet.Owner == Them.Key && !Them.Value.AtWar)
     {
         bool TheyAreThereAlready = false;
         foreach (Planet p in claimedPlanet.system.PlanetList)
         {
             if (p.Owner == null || p.Owner != EmpireManager.GetEmpireByName(this.empire.GetUS().PlayerLoyalty))
             {
                 continue;
             }
             TheyAreThereAlready = true;
         }
         if (TheyAreThereAlready && Them.Key == EmpireManager.GetEmpireByName(this.empire.GetUS().PlayerLoyalty))
         {
             Relationship item = this.empire.GetRelations()[Them.Key];
             item.Anger_TerritorialConflict = item.Anger_TerritorialConflict + (5f + (float)Math.Pow(5, (double)this.empire.GetRelations()[Them.Key].NumberStolenClaims));
             this.empire.GetRelations()[Them.Key].UpdateRelationship(this.empire, Them.Key);
             Relationship numberStolenClaims = this.empire.GetRelations()[Them.Key];
             numberStolenClaims.NumberStolenClaims = numberStolenClaims.NumberStolenClaims + 1;
             if (this.empire.GetRelations()[Them.Key].NumberStolenClaims == 1 && !this.empire.GetRelations()[Them.Key].StolenSystems.Contains(claimedPlanet.guid))
             {
                 this.empire.GetUS().ScreenManager.AddScreen(new DiplomacyScreen(this.empire, EmpireManager.GetEmpireByName(this.empire.GetUS().PlayerLoyalty), "Stole Claim", claimedPlanet.system));
             }
             else if (this.empire.GetRelations()[Them.Key].NumberStolenClaims == 2 && !this.empire.GetRelations()[Them.Key].HaveWarnedTwice && !this.empire.GetRelations()[Them.Key].StolenSystems.Contains(claimedPlanet.system.guid))
             {
                 this.empire.GetUS().ScreenManager.AddScreen(new DiplomacyScreen(this.empire, EmpireManager.GetEmpireByName(this.empire.GetUS().PlayerLoyalty), "Stole Claim 2", claimedPlanet.system));
                 this.empire.GetRelations()[Them.Key].HaveWarnedTwice = true;
             }
             else if (this.empire.GetRelations()[Them.Key].NumberStolenClaims >= 3 && !this.empire.GetRelations()[Them.Key].HaveWarnedThrice && !this.empire.GetRelations()[Them.Key].StolenSystems.Contains(claimedPlanet.system.guid))
             {
                 this.empire.GetUS().ScreenManager.AddScreen(new DiplomacyScreen(this.empire, EmpireManager.GetEmpireByName(this.empire.GetUS().PlayerLoyalty), "Stole Claim 3", claimedPlanet.system));
                 this.empire.GetRelations()[Them.Key].HaveWarnedThrice = true;
             }
             this.empire.GetRelations()[Them.Key].StolenSystems.Add(claimedPlanet.system.guid);
         }
     }
 }
 public void SetPlanetWhereBuilding(Planet p)
 {
     this.PlanetBuildingAt = p;
 }
 public void AttackPlanet(Planet planet)
 {
     foreach (Ship ship in (List<Ship>)this.Ships)
     {
         if (ship.Role != "troop")
             ship.GetAI().OrderToOrbit(planet, true);
         else if (planet.Owner != null && planet.Owner == ship.loyalty)
             ship.GetAI().GoRebase(planet);
         else
             ship.GetAI().OrderToOrbit(planet, true);
     }
 }
 private void DoBuildConstructionShip()
 {
     switch (this.Step)
     {
         case 0:
             List<Planet> list = new List<Planet>();
             foreach (Planet planet in this.empire.GetPlanets())
             {
                 if (planet.HasShipyard)
                     list.Add(planet);
             }
             IOrderedEnumerable<Planet> orderedEnumerable = Enumerable.OrderByDescending<Planet, float>((IEnumerable<Planet>)list, (Func<Planet, float>)(planet => planet.ConstructionQueue.Count ));//Vector2.Distance(planet.Position, this.BuildPosition)));
             if (Enumerable.Count<Planet>((IEnumerable<Planet>)orderedEnumerable) <= 0)
                 break;
             this.PlanetBuildingAt = Enumerable.ElementAt<Planet>((IEnumerable<Planet>)orderedEnumerable, 0);
             QueueItem queueItem = new QueueItem();
             queueItem.isShip = true;
             queueItem.DisplayName = "Construction Ship";
             queueItem.QueueNumber = Enumerable.ElementAt<Planet>((IEnumerable<Planet>)orderedEnumerable, 0).ConstructionQueue.Count;
             queueItem.sData = ResourceManager.ShipsDict[EmpireManager.GetEmpireByName(Ship.universeScreen.PlayerLoyalty).data.CurrentConstructor].GetShipData();
             queueItem.Goal = this;
             queueItem.Cost = ResourceManager.ShipsDict[this.ToBuildUID].GetCost(this.empire);
             queueItem.NotifyOnEmpty = false;
             if (!string.IsNullOrEmpty(this.empire.data.CurrentConstructor) && ResourceManager.ShipsDict.ContainsKey(this.empire.data.CurrentConstructor))
             {
                 this.beingBuilt = ResourceManager.ShipsDict[this.empire.data.CurrentConstructor];
             }
             else
             {
                 this.beingBuilt = null;
                 string empiredefaultShip = this.empire.data.DefaultConstructor;
                 if (string.IsNullOrEmpty(empiredefaultShip))
                 {
                     empiredefaultShip = this.empire.data.DefaultSmallTransport;
                 }
                 ResourceManager.ShipsDict.TryGetValue(empiredefaultShip, out this.beingBuilt);
                 //if(this.beingBuilt == null)
                 //{
                 //    ResourceManager.ShipsDict.TryGetValue(ResourceManager.GetEmpireByName(this.empire.data.Traits.Name).DefaultSmallTransport, out this.beingBuilt);
                 //}
                 this.empire.data.DefaultConstructor = empiredefaultShip;
             }
             Enumerable.ElementAt<Planet>((IEnumerable<Planet>)orderedEnumerable, 0).ConstructionQueue.Add(queueItem);
             ++this.Step;
             break;
         case 4:
             this.empire.GetGSAI().Goals.QueuePendingRemoval(this);
             break;
     }
 }
 public void FlankAttackPlanet(Planet planet, List<Fleet.Squad> Flank)
 {
     foreach (Fleet.Squad squad in Flank)
     {
         foreach (Ship ship in (List<Ship>)squad.Ships)
         {
             if (ship.Role != "troop")
                 ship.GetAI().OrderToOrbit(planet, true);
             else if (planet.Owner != null && planet.Owner == ship.loyalty)
                 ship.GetAI().GoRebase(planet);
             else
                 ship.GetAI().OrderToOrbit(planet, true);
         }
     }
 }
        private void DoBuildOffensiveShipsGoal()
        {
            switch (this.Step)
            {
                case 0:
                    Planet planet1 = (Planet)null;
                    List<Planet> list = new List<Planet>();
                    foreach (Planet planet2 in this.empire.GetPlanets())
                    {
                        if (planet2.HasShipyard  && planet2.colonyType != Planet.ColonyType.Research)
                            list.Add(planet2);
                    }
                    int num1 = 9999999;
                    foreach (Planet planet2 in list)
                    {
                        int num2 = 0;
                        foreach (QueueItem queueItem in (List<QueueItem>)planet2.ConstructionQueue)
                            num2 += (int)((queueItem.Cost - queueItem.productionTowards) / planet2.GetMaxProductionPotential());//planet2.NetProductionPerTurn);
                        if (planet2.ConstructionQueue.Count == 0)
                            num2 = (int)((this.beingBuilt.GetCost(this.empire) - planet2.ProductionHere) / planet2.GetMaxProductionPotential());//planet2.NetProductionPerTurn);
                        if (num2 < num1)
                        {
                            num1 = num2;
                            planet1 = planet2;
                        }
                    }
                    if (planet1 == null)
                        break;
                    this.PlanetBuildingAt = planet1;
                        planet1.ConstructionQueue.Add(new QueueItem()
                    {
                        isShip = true,
                        QueueNumber = planet1.ConstructionQueue.Count,
                        sData = this.beingBuilt.GetShipData(),
                        Goal = this,
                        Cost = this.beingBuilt.GetCost(this.empire)

                    });
                    ++this.Step;
                    break;
                case 1:
                    {
                        if (this.PlanetBuildingAt == null || this.PlanetBuildingAt.ConstructionQueue.Count == 0)
                            break;
                        //if (this.PlanetBuildingAt.ConstructionQueue[0].Goal == this)
                        //{
                        //    if (this.PlanetBuildingAt.ProductionHere > PlanetBuildingAt.MAX_STORAGE * .5f)
                        //    {
                        //        this.PlanetBuildingAt.ApplyStoredProduction(0);
                        //    }
                        //}

                        break;
                    }
                case 2:
                    this.beingBuilt.GetAI().State = AIState.AwaitingOrders;
                    this.empire.GetGSAI().Goals.QueuePendingRemoval(this);
                    break;
            }
        }