public void AutoArrange()
        {
            this.CenterShips.Clear();
            this.LeftShips.Clear();
            this.RightShips.Clear();
            this.ScreenShips.Clear();
            this.RearShips.Clear();
            this.CenterFlank.Clear();
            this.LeftFlank.Clear();
            this.RightFlank.Clear();
            this.ScreenFlank.Clear();
            this.RearFlank.Clear();
            this.AllFlanks.Add(this.CenterFlank);
            this.AllFlanks.Add(this.LeftFlank);
            this.AllFlanks.Add(this.RightFlank);
            this.AllFlanks.Add(this.ScreenFlank);
            this.AllFlanks.Add(this.RearFlank);
            BatchRemovalCollection<Ship> removalCollection = new BatchRemovalCollection<Ship>();
            foreach (Ship ship in (List<Ship>)this.Ships)
                removalCollection.Add(ship);
            foreach (Ship ship in (List<Ship>)removalCollection)
            {
                if (ship.Role == "scout")
                {
                    this.ScreenShips.Add(ship);
                    removalCollection.QueuePendingRemoval(ship);
                }
                if (ship.Role == "freighter")
                {
                    this.RearShips.Add(ship);
                    removalCollection.QueuePendingRemoval(ship);
                }
                if (ship.Role == "capital" || ship.Role == "carrier" || ship.Role == "cruiser")
                {
                    this.CenterShips.Add(ship);
                    removalCollection.QueuePendingRemoval(ship);
                }
            }
            removalCollection.ApplyPendingRemovals();
            IOrderedEnumerable<Ship> orderedEnumerable1 = Enumerable.OrderBy<Ship, float>((IEnumerable<Ship>)this.Ships, (Func<Ship, float>)(ship => ship.speed));
            this.speed = Enumerable.Count<Ship>((IEnumerable<Ship>)orderedEnumerable1) > 0 ? Enumerable.ElementAt<Ship>((IEnumerable<Ship>)orderedEnumerable1, 0).speed : 200f;
            IOrderedEnumerable<Ship> orderedEnumerable2 = Enumerable.OrderByDescending<Ship, float>((IEnumerable<Ship>)removalCollection, (Func<Ship, float>)(ship => ship.GetStrength() + (float)ship.Size));
            int num1 = 0;
            foreach (Ship ship in (IEnumerable<Ship>)orderedEnumerable2)
            {
                if (num1 < 4)
                {
                    this.CenterShips.Add(ship);
                    ++num1;
                }
                else if (num1 < 7)
                {
                    this.LeftShips.Add(ship);
                    ++num1;
                }
                else if (num1 < 11)
                {
                    this.RightShips.Add(ship);
                    ++num1;
                }
                else if (num1 < 15)
                {
                    this.ScreenShips.Add(ship);
                    ship.FleetCombatStatus = FleetCombatStatus.Maintain;

                    ++num1;
                }
                if (num1 == 15)
                    num1 = 0;
            }
            IOrderedEnumerable<Ship> orderedEnumerable3 = Enumerable.OrderByDescending<Ship, int>((IEnumerable<Ship>)this.CenterShips, (Func<Ship, int>)(ship => ship.Size));
            Fleet.Squad squad1 = new Fleet.Squad();
            squad1.Fleet = this;
            for (int index = 0; index < Enumerable.Count<Ship>((IEnumerable<Ship>)orderedEnumerable3); ++index)
            {
                if (squad1.Ships.Count < 4)
                    squad1.Ships.Add(Enumerable.ElementAt<Ship>((IEnumerable<Ship>)orderedEnumerable3, index));
                if (squad1.Ships.Count == 4 || index == Enumerable.Count<Ship>((IEnumerable<Ship>)orderedEnumerable3) - 1)
                {
                    this.CenterFlank.Add(squad1);
                    squad1 = new Fleet.Squad();
                    squad1.Fleet = this;
                }
            }
            IOrderedEnumerable<Ship> orderedEnumerable4 = Enumerable.OrderByDescending<Ship, float>((IEnumerable<Ship>)this.LeftShips, (Func<Ship, float>)(ship => ship.speed));
            Fleet.Squad squad2 = new Fleet.Squad();
            squad2.Fleet = this;
            for (int index = 0; index < Enumerable.Count<Ship>((IEnumerable<Ship>)orderedEnumerable4); ++index)
            {
                if (squad2.Ships.Count < 4)
                    squad2.Ships.Add(Enumerable.ElementAt<Ship>((IEnumerable<Ship>)orderedEnumerable4, index));
                if (squad2.Ships.Count == 4 || index == Enumerable.Count<Ship>((IEnumerable<Ship>)orderedEnumerable4) - 1)
                {
                    this.LeftFlank.Add(squad2);
                    squad2 = new Fleet.Squad();
                    squad2.Fleet = this;
                }
            }
            IOrderedEnumerable<Ship> orderedEnumerable5 = Enumerable.OrderByDescending<Ship, float>((IEnumerable<Ship>)this.RightShips, (Func<Ship, float>)(ship => ship.speed));
            Fleet.Squad squad3 = new Fleet.Squad();
            squad3.Fleet = this;
            for (int index = 0; index < Enumerable.Count<Ship>((IEnumerable<Ship>)orderedEnumerable5); ++index)
            {
                if (squad3.Ships.Count < 4)
                    squad3.Ships.Add(Enumerable.ElementAt<Ship>((IEnumerable<Ship>)orderedEnumerable5, index));
                if (squad3.Ships.Count == 4 || index == Enumerable.Count<Ship>((IEnumerable<Ship>)orderedEnumerable5) - 1)
                {
                    this.RightFlank.Add(squad3);
                    squad3 = new Fleet.Squad();
                    squad3.Fleet = this;
                }
            }
            IOrderedEnumerable<Ship> orderedEnumerable6 = Enumerable.OrderByDescending<Ship, float>((IEnumerable<Ship>)this.ScreenShips, (Func<Ship, float>)(ship => ship.speed));
            Fleet.Squad squad4 = new Fleet.Squad();
            squad4.Fleet = this;
            for (int index = 0; index < Enumerable.Count<Ship>((IEnumerable<Ship>)orderedEnumerable6); ++index)
            {
                if (squad4.Ships.Count < 4)
                    squad4.Ships.Add(Enumerable.ElementAt<Ship>((IEnumerable<Ship>)orderedEnumerable6, index));
                if (squad4.Ships.Count == 4 || index == Enumerable.Count<Ship>((IEnumerable<Ship>)orderedEnumerable6) - 1)
                {
                    this.ScreenFlank.Add(squad4);
                    squad4 = new Fleet.Squad();
                    squad4.Fleet = this;
                }
            }
            IOrderedEnumerable<Ship> orderedEnumerable7 = Enumerable.OrderByDescending<Ship, float>((IEnumerable<Ship>)this.RearShips, (Func<Ship, float>)(ship => ship.speed));
            Fleet.Squad squad5 = new Fleet.Squad();
            squad5.Fleet = this;
            for (int index = 0; index < Enumerable.Count<Ship>((IEnumerable<Ship>)orderedEnumerable7); ++index)
            {
                if (squad5.Ships.Count < 4)
                    squad5.Ships.Add(Enumerable.ElementAt<Ship>((IEnumerable<Ship>)orderedEnumerable7, index));
                if (squad5.Ships.Count == 4 || index == Enumerable.Count<Ship>((IEnumerable<Ship>)orderedEnumerable7) - 1)
                {
                    this.RearFlank.Add(squad5);
                    squad5 = new Fleet.Squad();
                    squad5.Fleet = this;
                }
            }
            this.Position = this.findAveragePosition();
            int num2 = 0;
            int num3 = 0;
            for (int index = 0; index < this.CenterFlank.Count; ++index)
            {
                if (index == 0)
                    this.CenterFlank[index].Offset = new Vector2(0.0f, 0.0f);
                else if (index % 2 == 1)
                {
                    ++num2;
                    this.CenterFlank[index].Offset = new Vector2((float)(num2 * -1400), 0.0f);
                }
                else
                {
                    ++num3;
                    this.CenterFlank[index].Offset = new Vector2((float)(num3 * 1400), 0.0f);
                }
            }
            int num4 = 0;
            int num5 = 0;
            for (int index = 0; index < this.ScreenFlank.Count; ++index)
            {
                if (index == 0)
                    this.ScreenFlank[index].Offset = new Vector2(0.0f, -2500f);
                else if (index % 2 == 1)
                {
                    ++num4;
                    this.ScreenFlank[index].Offset = new Vector2((float)(num4 * -1400), -2500f);
                }
                else
                {
                    ++num5;
                    this.ScreenFlank[index].Offset = new Vector2((float)(num5 * 1400), -2500f);
                }
            }
            int num6 = 0;
            int num7 = 0;
            for (int index = 0; index < this.RearFlank.Count; ++index)
            {
                if (index == 0)
                    this.RearFlank[index].Offset = new Vector2(0.0f, 2500f);
                else if (index % 2 == 1)
                {
                    ++num6;
                    this.RearFlank[index].Offset = new Vector2((float)(num6 * -1400), 2500f);
                }
                else
                {
                    ++num7;
                    this.RearFlank[index].Offset = new Vector2((float)(num7 * 1400), 2500f);
                }
            }
            for (int index = 0; index < this.LeftFlank.Count; ++index)
                this.LeftFlank[index].Offset = new Vector2((float)(-this.CenterFlank.Count * 1400 - (this.LeftFlank.Count == 1 ? 1400 : index * 1400)), 0.0f);
            for (int index = 0; index < this.RightFlank.Count; ++index)
                this.RightFlank[index].Offset = new Vector2((float)(this.CenterFlank.Count * 1400 + (this.RightFlank.Count == 1 ? 1400 : index * 1400)), 0.0f);
            this.AutoAssembleFleet(0.0f, new Vector2(0.0f, -1f));
            foreach (Ship s in (List<Ship>)this.Ships)
            {
                if (!s.InCombat)
                {
                    lock (s.GetAI().wayPointLocker)
                        s.GetAI().OrderThrustTowardsPosition(this.Position + s.FleetOffset, this.facing, new Vector2(0.0f, -1f), true);
                }
                FleetDataNode fleetDataNode = new FleetDataNode();
                fleetDataNode.SetShip(s);
                fleetDataNode.ShipName = s.Name;
                fleetDataNode.FleetOffset = s.RelativeFleetOffset;
                fleetDataNode.OrdersOffset = s.RelativeFleetOffset;
                this.DataNodes.Add(fleetDataNode);

            }

            //foreach (List<Fleet.Squad> list in this.AllFlanks)
            ////Parallel.ForEach(this.AllFlanks, list =>
            //{
            //    foreach (Fleet.Squad squad6 in list)
            //    {

            //        foreach (Ship ship in (List<Ship>)squad6.Ships)
            //        {
            //            foreach (FleetDataNode fleetDataNode in (List<FleetDataNode>)this.DataNodes)
            //            {
            //                if (ship == fleetDataNode.GetShip())
            //                    squad6.DataNodes.Add(fleetDataNode);
            //            }
            //        }
            //    }
            //}//);
        }
        private void SetCombatStatus(float elapsedTime)
        {
            //if(this.State==AIState.Scrap)
            //{
            //    this.Target = null;
            //    this.Owner.InCombatTimer = 0f;
            //    this.Owner.InCombat = false;
            //    this.TargetQueue.Clear();
            //    return;

            //}
            float radius = 30000f;
            Vector2 senseCenter = this.Owner.Center;
            if (UseSensorsForTargets)
            {
                if (this.Owner.Mothership != null)
                {
                    if (Vector2.Distance(this.Owner.Center, this.Owner.Mothership.Center) <= this.Owner.Mothership.SensorRange - this.Owner.SensorRange)
                    {
                        senseCenter = this.Owner.Mothership.Center;
                        radius = this.Owner.Mothership.SensorRange;
                    }
                }
                else
                {
                    radius = this.Owner.SensorRange;
                    if (this.Owner.inborders) radius += 10000;
                }
            }
            if (this.Owner.fleet != null)
            {
                if (!this.hasPriorityTarget)
                {
                    this.Target = this.ScanForCombatTargets(senseCenter, radius);
                }
                else
                {
                    this.ScanForCombatTargets(senseCenter, radius);
                }
            }
            else if (!this.hasPriorityTarget)
            {
            //#if DEBUG
            //                if (this.State == AIState.Intercept && this.Target != null)
            //                    System.Diagnostics.Debug.WriteLine(this.Target);
            //#endif
                this.Target = this.ScanForCombatTargets(senseCenter, radius);
            }
            else
            {
                this.ScanForCombatTargets(senseCenter, radius);
            }
            if (this.State == AIState.Resupply)
            {
                return;
            }
            if (((this.Owner.Role == "freighter" && this.Owner.CargoSpace_Max > 0) || this.Owner.Role == "scout" || this.Owner.Role == "construction" || this.Owner.Role == "troop" || this.IgnoreCombat || this.State == AIState.Resupply || this.State == AIState.ReturnToHangar || this.State == AIState.Colonize) || this.Owner.VanityName == "Resupply Shuttle")
            {
                return;
            }
            if (this.Owner.fleet != null && this.State == AIState.FormationWarp)
            {
                bool doreturn = true;
                if (this.Owner.fleet != null && this.State == AIState.FormationWarp && Vector2.Distance(this.Owner.Center, this.Owner.fleet.Position + this.Owner.FleetOffset) < 15000f)
                {
                    doreturn = false;
                }
                if (doreturn)
                {
                    //if (this.Owner.engineState == Ship.MoveState.Sublight && this.NearbyShips.Count > 0)
                    //{
                    //    this.Owner.ShieldsUp = true;
                    //}
                    return;
                }
            }
            if (this.Owner.fleet != null)
            {
                foreach (FleetDataNode datanode in this.Owner.fleet.DataNodes)
                {
                    if (datanode.GetShip() != this.Owner)
                    {
                        continue;
                    }
                    this.node = datanode;
                    break;
                }
            }
            if (this.Target != null && !this.Owner.InCombat)
            {
                this.Owner.InCombatTimer = 15f;
                if (!this.HasPriorityOrder && this.OrderQueue.Count > 0 && this.OrderQueue.ElementAt<ArtificialIntelligence.ShipGoal>(0).Plan != ArtificialIntelligence.Plan.DoCombat)
                {
                    ArtificialIntelligence.ShipGoal combat = new ArtificialIntelligence.ShipGoal(ArtificialIntelligence.Plan.DoCombat, Vector2.Zero, 0f);
                    this.State = AIState.Combat;
                    this.OrderQueue.AddFirst(combat);
                    return;
                }
                else if (!this.HasPriorityOrder)
                {
                    ArtificialIntelligence.ShipGoal combat = new ArtificialIntelligence.ShipGoal(ArtificialIntelligence.Plan.DoCombat, Vector2.Zero, 0f);
                    this.State = AIState.Combat;
                    this.OrderQueue.AddFirst(combat);
                    return;
                }
                else
                {
                    if (!this.HasPriorityOrder || this.CombatState == CombatState.HoldPosition || this.OrderQueue.Count != 0)
                        return;
                    ArtificialIntelligence.ShipGoal combat = new ArtificialIntelligence.ShipGoal(ArtificialIntelligence.Plan.DoCombat, Vector2.Zero, 0f);
                    this.State = AIState.Combat;
                    this.OrderQueue.AddFirst(combat);

                }
            }
        }
 private void SetCombatStatusorig(float elapsedTime)
 {
     if (this.Owner.fleet != null)
     {
         if (!this.hasPriorityTarget)
         {
             this.Target = this.ScanForCombatTargets(this.Owner.Center, 30000f);
         }
         else
         {
             this.ScanForCombatTargets(this.Owner.Center, 30000f);
         }
     }
     else if (!this.hasPriorityTarget)
     {
         this.Target = this.ScanForCombatTargets(this.Owner.Center, 30000f);
     }
     else
     {
         this.ScanForCombatTargets(this.Owner.Center, 30000f);
     }
     if (this.State == AIState.Resupply)
     {
         return;
     }
     if ((this.Owner.Role == "freighter" || this.Owner.Role == "scout" || this.Owner.Role == "construction" || this.Owner.Role == "troop" || this.IgnoreCombat || this.State == AIState.Resupply || this.State == AIState.ReturnToHangar) && !this.Owner.IsSupplyShip)
     {
         return;
     }
     if (this.Owner.fleet != null && this.State == AIState.FormationWarp)
     {
         bool doreturn = true;
         if (this.Owner.fleet != null && this.State == AIState.FormationWarp && Vector2.Distance(this.Owner.Center, this.Owner.fleet.Position + this.Owner.FleetOffset) < 15000f)
         {
             doreturn = false;
         }
         if (doreturn)
         {
             return;
         }
     }
     if (this.Owner.fleet != null)
     {
         foreach (FleetDataNode datanode in this.Owner.fleet.DataNodes)
         {
             if (datanode.GetShip() != this.Owner)
             {
                 continue;
             }
             this.node = datanode;
             break;
         }
     }
     if (this.Target != null && !this.Owner.InCombat)
     {
         this.Owner.InCombat = true;
         this.Owner.InCombatTimer = 15f;
         if (!this.HasPriorityOrder && this.OrderQueue.Count > 0 && this.OrderQueue.ElementAt<ArtificialIntelligence.ShipGoal>(0).Plan != ArtificialIntelligence.Plan.DoCombat)
         {
             ArtificialIntelligence.ShipGoal combat = new ArtificialIntelligence.ShipGoal(ArtificialIntelligence.Plan.DoCombat, Vector2.Zero, 0f);
             this.State = AIState.Combat;
             this.OrderQueue.AddFirst(combat);
             return;
         }
         if (!this.HasPriorityOrder)
         {
             ArtificialIntelligence.ShipGoal combat = new ArtificialIntelligence.ShipGoal(ArtificialIntelligence.Plan.DoCombat, Vector2.Zero, 0f);
             this.State = AIState.Combat;
             this.OrderQueue.AddFirst(combat);
             return;
         }
         if (this.HasPriorityOrder && this.CombatState != Ship_Game.Gameplay.CombatState.HoldPosition && this.OrderQueue.Count == 0)
         {
             ArtificialIntelligence.ShipGoal combat = new ArtificialIntelligence.ShipGoal(ArtificialIntelligence.Plan.DoCombat, Vector2.Zero, 0f);
             this.State = AIState.Combat;
             this.OrderQueue.AddFirst(combat);
             return;
         }
     }
     else if (this.Target == null)
     {
         this.Owner.InCombat = false;
     }
 }
 public override void HandleInput(InputState input)
 {
     if (this.close.HandleInput(input))
     {
         this.ExitScreen();
         return;
     }
     if (input.CurrentKeyboardState.IsKeyDown(Keys.J) && !input.LastKeyboardState.IsKeyDown(Keys.J) && !GlobalStats.TakingInput)
     {
         AudioManager.PlayCue("echo_affirm");
         this.ExitScreen();
         return;
     }
     this.current = Mouse.GetState();
     Vector2 MousePos = new Vector2((float)input.CurrentMouseState.X, (float)input.CurrentMouseState.Y);
     if (this.SelectedNodeList.Count != 1 && this.FleetToEdit != -1)
     {
         if (!HelperFunctions.CheckIntersection(this.FleetNameEntry.ClickableArea, MousePos))
         {
             this.FleetNameEntry.Hover = false;
         }
         else
         {
             this.FleetNameEntry.Hover = true;
             if (input.CurrentMouseState.LeftButton == ButtonState.Pressed && input.LastMouseState.LeftButton == ButtonState.Released)
             {
                 this.FleetNameEntry.HandlingInput = true;
                 return;
             }
         }
     }
     if (!this.FleetNameEntry.HandlingInput)
     {
         GlobalStats.TakingInput = false;
     }
     else
     {
         GlobalStats.TakingInput = true;
         this.FleetNameEntry.HandleTextInput(ref EmpireManager.GetEmpireByName(this.EmpireUI.screen.PlayerLoyalty).GetFleetsDict()[this.FleetToEdit].Name);
     }
     if (input.CurrentKeyboardState.IsKeyDown(Keys.D1) && input.LastKeyboardState.IsKeyUp(Keys.D1))
     {
         AudioManager.PlayCue("echo_affirm");
         this.ChangeFleet(1);
     }
     else if (input.CurrentKeyboardState.IsKeyDown(Keys.D2) && input.LastKeyboardState.IsKeyUp(Keys.D2))
     {
         AudioManager.PlayCue("echo_affirm");
         this.ChangeFleet(2);
     }
     else if (input.CurrentKeyboardState.IsKeyDown(Keys.D3) && input.LastKeyboardState.IsKeyUp(Keys.D3))
     {
         AudioManager.PlayCue("echo_affirm");
         this.ChangeFleet(3);
     }
     else if (input.CurrentKeyboardState.IsKeyDown(Keys.D4) && input.LastKeyboardState.IsKeyUp(Keys.D4))
     {
         AudioManager.PlayCue("echo_affirm");
         this.ChangeFleet(4);
     }
     else if (input.CurrentKeyboardState.IsKeyDown(Keys.D5) && input.LastKeyboardState.IsKeyUp(Keys.D5))
     {
         AudioManager.PlayCue("echo_affirm");
         this.ChangeFleet(5);
     }
     else if (input.CurrentKeyboardState.IsKeyDown(Keys.D6) && input.LastKeyboardState.IsKeyUp(Keys.D6))
     {
         AudioManager.PlayCue("echo_affirm");
         this.ChangeFleet(6);
     }
     else if (input.CurrentKeyboardState.IsKeyDown(Keys.D7) && input.LastKeyboardState.IsKeyUp(Keys.D7))
     {
         AudioManager.PlayCue("echo_affirm");
         this.ChangeFleet(7);
     }
     else if (input.CurrentKeyboardState.IsKeyDown(Keys.D8) && input.LastKeyboardState.IsKeyUp(Keys.D8))
     {
         AudioManager.PlayCue("echo_affirm");
         this.ChangeFleet(8);
     }
     else if (input.CurrentKeyboardState.IsKeyDown(Keys.D9) && input.LastKeyboardState.IsKeyUp(Keys.D9))
     {
         AudioManager.PlayCue("echo_affirm");
         this.ChangeFleet(9);
     }
     foreach (KeyValuePair<int, Rectangle> rect in this.FleetsRects)
     {
         if (!HelperFunctions.CheckIntersection(rect.Value, MousePos) || input.CurrentMouseState.LeftButton != ButtonState.Pressed || input.LastMouseState.LeftButton != ButtonState.Released)
         {
             continue;
         }
         AudioManager.PlayCue("echo_affirm");
         this.FleetToEdit = rect.Key;
         this.ChangeFleet(this.FleetToEdit);
     }
     if (this.FleetToEdit != -1)
     {
         this.sub_ships.HandleInput(this);
         if (this.ShipSL.HandleInput(input))
         {
             return;
         }
     }
     if (this.SelectedNodeList.Count == 1)
     {
         this.SelectedNodeList[0].AttackShieldedWeight = this.Slider_Shield.HandleInput(input);
         this.SelectedNodeList[0].DPSWeight = this.Slider_DPS.HandleInput(input);
         this.SelectedNodeList[0].VultureWeight = this.Slider_Vulture.HandleInput(input);
         this.SelectedNodeList[0].ArmoredWeight = this.Slider_Armor.HandleInput(input);
         this.SelectedNodeList[0].DefenderWeight = this.Slider_Defend.HandleInput(input);
         this.SelectedNodeList[0].AssistWeight = this.Slider_Assist.HandleInput(input);
         this.SelectedNodeList[0].SizeWeight = this.Slider_Size.HandleInput(input);
         if (HelperFunctions.CheckIntersection(this.OperationsRect, MousePos))
         {
             this.dragTimer = 0f;
             return;
         }
         if (HelperFunctions.CheckIntersection(this.PrioritiesRect, MousePos))
         {
             this.dragTimer = 0f;
             this.SelectedNodeList[0].OrdersRadius = this.OperationalRadius.HandleInput(input);
             return;
         }
         if (HelperFunctions.CheckIntersection(this.SelectedStuffRect, MousePos))
         {
             foreach (ToggleButton button in this.OrdersButtons)
             {
                 if (!HelperFunctions.CheckIntersection(button.r, MousePos))
                 {
                     button.Hover = false;
                 }
                 else
                 {
                     button.Hover = true;
                     if (input.CurrentMouseState.LeftButton != ButtonState.Pressed || input.LastMouseState.LeftButton != ButtonState.Released)
                     {
                         continue;
                     }
                     foreach (ToggleButton b in this.OrdersButtons)
                     {
                         b.Active = false;
                     }
                     string action = button.Action;
                     string str = action;
                     if (action != null)
                     {
                         if (str == "attack")
                         {
                             this.SelectedNodeList[0].CombatState = CombatState.AttackRuns;
                         }
                         else if (str == "arty")
                         {
                             this.SelectedNodeList[0].CombatState = CombatState.Artillery;
                         }
                         else if (str == "hold")
                         {
                             this.SelectedNodeList[0].CombatState = CombatState.HoldPosition;
                         }
                         else if (str == "orbit_left")
                         {
                             this.SelectedNodeList[0].CombatState = CombatState.OrbitLeft;
                         }
                         else if (str == "broadside_left")
                         {
                             this.SelectedNodeList[0].CombatState = CombatState.BroadsideLeft;
                         }
                         else if (str == "orbit_right")
                         {
                             this.SelectedNodeList[0].CombatState = CombatState.OrbitRight;
                         }
                         else if (str == "broadside_right")
                         {
                             this.SelectedNodeList[0].CombatState = CombatState.BroadsideRight;
                         }
                         else if (str == "evade")
                         {
                             this.SelectedNodeList[0].CombatState = CombatState.Evade;
                         }
                     }
                     if (this.SelectedNodeList[0].GetShip() == null)
                     {
                         continue;
                     }
                     this.SelectedNodeList[0].GetShip().GetAI().CombatState = this.SelectedNodeList[0].CombatState;
                     button.Active = true;
                     AudioManager.PlayCue("echo_affirm");
                     break;
                 }
             }
             return;
         }
     }
     else if (this.SelectedNodeList.Count > 1)
     {
         FleetDataNode fleetDataNode = new FleetDataNode();
         this.Slider_DPS.HandleInput(input);
         this.Slider_Vulture.HandleInput(input);
         this.Slider_Armor.HandleInput(input);
         this.Slider_Defend.HandleInput(input);
         this.Slider_Assist.HandleInput(input);
         this.Slider_Size.HandleInput(input);
         foreach (FleetDataNode node in this.SelectedNodeList)
         {
             node.DPSWeight = this.Slider_DPS.amount;
             node.VultureWeight = this.Slider_Vulture.amount;
             node.ArmoredWeight = this.Slider_Armor.amount;
             node.DefenderWeight = this.Slider_Defend.amount;
             node.AssistWeight = this.Slider_Assist.amount;
             node.SizeWeight = this.Slider_Size.amount;
         }
         if (HelperFunctions.CheckIntersection(this.OperationsRect, MousePos))
         {
             this.dragTimer = 0f;
             return;
         }
         if (HelperFunctions.CheckIntersection(this.PrioritiesRect, MousePos))
         {
             this.dragTimer = 0f;
             this.SelectedNodeList[0].OrdersRadius = this.OperationalRadius.HandleInput(input);
             return;
         }
         if (HelperFunctions.CheckIntersection(this.SelectedStuffRect, MousePos))
         {
             foreach (ToggleButton button in this.OrdersButtons)
             {
                 if (!HelperFunctions.CheckIntersection(button.r, MousePos))
                 {
                     button.Hover = false;
                 }
                 else
                 {
                     button.Hover = true;
                     if (input.CurrentMouseState.LeftButton != ButtonState.Pressed || input.LastMouseState.LeftButton != ButtonState.Released)
                     {
                         continue;
                     }
                     foreach (ToggleButton b in this.OrdersButtons)
                     {
                         b.Active = false;
                     }
                     AudioManager.PlayCue("echo_affirm");
                     button.Active = true;
                     foreach (FleetDataNode node in this.SelectedNodeList)
                     {
                         string action1 = button.Action;
                         string str1 = action1;
                         if (action1 != null)
                         {
                             if (str1 == "attack")
                             {
                                 node.CombatState = CombatState.AttackRuns;
                             }
                             else if (str1 == "arty")
                             {
                                 node.CombatState = CombatState.Artillery;
                             }
                             else if (str1 == "hold")
                             {
                                 node.CombatState = CombatState.HoldPosition;
                             }
                             else if (str1 == "orbit_left")
                             {
                                 node.CombatState = CombatState.OrbitLeft;
                             }
                             else if (str1 == "broadside_left")
                             {
                                 node.CombatState = CombatState.BroadsideLeft;
                             }
                             else if (str1 == "orbit_right")
                             {
                                 node.CombatState = CombatState.OrbitRight;
                             }
                             else if (str1 == "broadside_right")
                             {
                                 node.CombatState = CombatState.BroadsideRight;
                             }
                             else if (str1 == "evade")
                             {
                                 node.CombatState = CombatState.Evade;
                             }
                         }
                         if (node.GetShip() == null)
                         {
                             continue;
                         }
                         node.GetShip().GetAI().CombatState = node.CombatState;
                     }
                 }
             }
             return;
         }
     }
     else if (this.FleetToEdit != -1 && this.SelectedNodeList.Count == 0 && HelperFunctions.CheckIntersection(this.SelectedStuffRect, MousePos))
     {
         if (this.RequisitionForces.HandleInput(input))
         {
             base.ScreenManager.AddScreen(new RequisitionScreen(this));
         }
         if (this.SaveDesign.HandleInput(input))
         {
             base.ScreenManager.AddScreen(new SaveFleetDesignScreen(this.fleet));
         }
         if (this.LoadDesign.HandleInput(input))
         {
             base.ScreenManager.AddScreen(new LoadSavedFleetDesignScreen(this));
         }
     }
     if (this.ActiveShipDesign != null)
     {
         if (input.CurrentMouseState.LeftButton == ButtonState.Pressed && input.LastMouseState.LeftButton == ButtonState.Released)
         {
             Viewport viewport = base.ScreenManager.GraphicsDevice.Viewport;
             Vector3 nearPoint = viewport.Unproject(new Vector3(MousePos.X, MousePos.Y, 0f), this.projection, this.view, Matrix.Identity);
             Viewport viewport1 = base.ScreenManager.GraphicsDevice.Viewport;
             Vector3 farPoint = viewport1.Unproject(new Vector3(MousePos.X, MousePos.Y, 1f), this.projection, this.view, Matrix.Identity);
             Vector3 direction = farPoint - nearPoint;
             direction.Normalize();
             Ray pickRay = new Ray(nearPoint, direction);
             float k = -pickRay.Position.Z / pickRay.Direction.Z;
             Vector3 pickedPosition = new Vector3(pickRay.Position.X + k * pickRay.Direction.X, pickRay.Position.Y + k * pickRay.Direction.Y, 0f);
             FleetDataNode node = new FleetDataNode()
             {
                 FleetOffset = new Vector2(pickedPosition.X, pickedPosition.Y),
                 ShipName = this.ActiveShipDesign.Name
             };
             this.fleet.DataNodes.Add(node);
             if (this.AvailableShips.Contains(this.ActiveShipDesign))
             {
                 if (this.fleet.Ships.Count == 0)
                 {
                     this.fleet.Position = this.ActiveShipDesign.Position;
                 }
                 node.SetShip(this.ActiveShipDesign);
                 node.GetShip().GetSO().World = Matrix.CreateTranslation(new Vector3(node.FleetOffset, 0f));
                 node.GetShip().RelativeFleetOffset = node.FleetOffset;
                 this.AvailableShips.Remove(this.ActiveShipDesign);
                 node.GetShip().fleet = this.fleet;
                 this.fleet.AddShip(node.GetShip());
                 if (this.sub_ships.Tabs[1].Selected)
                 {
                     ScrollList.Entry toremove = null;
                     foreach (ScrollList.Entry e in this.ShipSL.Copied)
                     {
                         if (!(e.item is Ship) || e.item as Ship != this.ActiveShipDesign)
                         {
                             continue;
                         }
                         toremove = e;
                         break;
                     }
                     if (toremove != null)
                     {
                         foreach (ScrollList.Entry e in this.ShipSL.Copied)
                         {
                             e.SubEntries.Remove(toremove);
                         }
                         this.ShipSL.Entries.Remove(toremove);
                         this.ShipSL.Copied.Remove(toremove);
                         this.ShipSL.Update();
                     }
                 }
                 this.ActiveShipDesign = null;
             }
             if (!input.CurrentKeyboardState.IsKeyDown(Keys.LeftShift))
             {
                 this.ActiveShipDesign = null;
             }
         }
         if (input.CurrentMouseState.RightButton == ButtonState.Pressed && input.LastMouseState.RightButton == ButtonState.Released)
         {
             this.ActiveShipDesign = null;
         }
     }
     if (this.FleetToEdit != -1)
     {
         foreach (ScrollList.Entry e in this.ShipSL.Copied)
         {
             if (!(e.item is ModuleHeader))
             {
                 if (!HelperFunctions.CheckIntersection(e.clickRect, MousePos) || input.CurrentMouseState.LeftButton != ButtonState.Pressed || input.LastMouseState.LeftButton != ButtonState.Released)
                 {
                     continue;
                 }
                 this.ActiveShipDesign = e.item as Ship;
                 this.SelectedNodeList.Clear();
                 this.SelectedSquad = null;
             }
             else
             {
                 (e.item as ModuleHeader).HandleInput(input, e);
             }
         }
     }
     this.HandleEdgeDetection(input);
     this.HandleSelectionBox(input);
     if (input.ScrollIn)
     {
         FleetDesignScreen desiredCamHeight = this;
         desiredCamHeight.DesiredCamHeight = desiredCamHeight.DesiredCamHeight - 1500f;
     }
     if (input.ScrollOut)
     {
         FleetDesignScreen fleetDesignScreen = this;
         fleetDesignScreen.DesiredCamHeight = fleetDesignScreen.DesiredCamHeight + 1500f;
     }
     if (this.DesiredCamHeight < 3000f)
     {
         this.DesiredCamHeight = 3000f;
     }
     else if (this.DesiredCamHeight > 100000f)
     {
         this.DesiredCamHeight = 100000f;
     }
     bool dragging = false;
     if (input.CurrentMouseState.RightButton == ButtonState.Pressed && input.LastMouseState.RightButton == ButtonState.Released)
     {
         dragging = true;
         this.startDrag = MousePos;
     }
     if (input.CurrentMouseState.RightButton == ButtonState.Pressed && input.LastMouseState.RightButton == ButtonState.Pressed)
     {
         dragging = true;
         this.endDrag = MousePos;
         if (Vector2.Distance(this.startDrag, this.endDrag) > 10f)
         {
             this.CamVelocity = HelperFunctions.FindVectorToTarget(this.endDrag, this.startDrag);
             this.CamVelocity = Vector2.Normalize(this.CamVelocity) * Vector2.Distance(this.startDrag, this.endDrag);
         }
     }
     if (!dragging)
     {
         this.CamVelocity = Vector2.Zero;
     }
     if (this.CamVelocity.Length() > 150f)
     {
         this.CamVelocity = Vector2.Normalize(this.CamVelocity) * 150f;
     }
     if (float.IsNaN(this.CamVelocity.X) || float.IsNaN(this.CamVelocity.Y))
     {
         this.CamVelocity = Vector2.Zero;
     }
     if (input.CurrentKeyboardState.IsKeyDown(Keys.Back) || input.CurrentKeyboardState.IsKeyDown(Keys.Delete))
     {
         if (this.SelectedSquad != null)
         {
             this.fleet.CenterFlank.Remove(this.SelectedSquad);
             this.fleet.LeftFlank.Remove(this.SelectedSquad);
             this.fleet.RearFlank.Remove(this.SelectedSquad);
             this.fleet.RightFlank.Remove(this.SelectedSquad);
             this.fleet.ScreenFlank.Remove(this.SelectedSquad);
             this.SelectedSquad = null;
             this.SelectedNodeList.Clear();
         }
         if (this.SelectedNodeList.Count > 0)
         {
             foreach (List<Fleet.Squad> flanks in this.fleet.AllFlanks)
             {
                 foreach (Fleet.Squad squad in flanks)
                 {
                     foreach (FleetDataNode node in this.SelectedNodeList)
                     {
                         if (!squad.DataNodes.Contains(node))
                         {
                             continue;
                         }
                         squad.DataNodes.QueuePendingRemoval(node);
                         if (node.GetShip() == null)
                         {
                             continue;
                         }
                         squad.Ships.QueuePendingRemoval(node.GetShip());
                     }
                     squad.DataNodes.ApplyPendingRemovals();
                     squad.Ships.ApplyPendingRemovals();
                 }
             }
             foreach (FleetDataNode node in this.SelectedNodeList)
             {
                 this.fleet.DataNodes.Remove(node);
                 if (node.GetShip() == null)
                 {
                     continue;
                 }
                 node.GetShip().GetSO().World = Matrix.CreateTranslation(new Vector3(node.GetShip().RelativeFleetOffset, -500000f));
                 this.fleet.Ships.Remove(node.GetShip());
                 node.GetShip().fleet = null;
             }
             this.SelectedNodeList.Clear();
             this.PopulateShipSL();
         }
     }
     if (input.Escaped)
     {
         FleetDesignScreen.Open = false;
         this.ExitScreen();
     }
     this.previous = this.current;
 }