//added by gremlin deveksmod Spy Handleinput
        public void HandleInput(InputState input)
        {
            string Names;
            this.AgentSL.HandleInput(input);
            if (this.SelectedAgent != null)
            {
                this.OpsSL.HandleInput(input);
            }
            if (HelperFunctions.CheckIntersection(this.RecruitButton.r, input.CursorPosition))
            {
                ToolTip.CreateTooltip(Localizer.Token(2180), this.ScreenManager);
            }
            if (this.RecruitButton.HandleInput(input))
            {
                if (EmpireManager.GetEmpireByName(Ship.universeScreen.PlayerLoyalty).Money < (ResourceManager.AgentMissionData.AgentCost + ResourceManager.AgentMissionData.TrainingCost) || spyLimitCount <= 0)//EmpireManager.GetEmpireByName(Ship.universeScreen.PlayerLoyalty).data.AgentList.Count >= EmpireManager.GetEmpireByName(Ship.universeScreen.PlayerLoyalty).GetPlanets().Count)
                {
                    AudioManager.PlayCue("UI_Misc20");
                }
                else
                {
                    Empire empireByName = EmpireManager.GetEmpireByName(Ship.universeScreen.PlayerLoyalty);
                    empireByName.Money -= ResourceManager.AgentMissionData.AgentCost;
                    Names = (!File.Exists(string.Concat("Content/NameGenerators/spynames_", EmpireManager.GetEmpireByName(Ship.universeScreen.PlayerLoyalty).data.Traits.ShipType, ".txt")) ? File.ReadAllText("Content/NameGenerators/spynames_Humans.txt") : File.ReadAllText(string.Concat("Content/NameGenerators/spynames_", EmpireManager.GetEmpireByName(Ship.universeScreen.PlayerLoyalty).data.Traits.ShipType, ".txt")));
                    string[] Tokens = Names.Split(new char[] { ',' });
                    Agent a = new Agent();
                    a.Name = AgentComponent.GetName(Tokens);
                    //Added new agent information
                    a.Age = RandomMath.RandomBetween(20, 30);
                    int RandomPlanetIndex = HelperFunctions.GetRandomIndex(EmpireManager.GetEmpireByName(Ship.universeScreen.PlayerLoyalty).GetPlanets().Count);
                    a.HomePlanet = EmpireManager.GetEmpireByName(Ship.universeScreen.PlayerLoyalty).GetPlanets()[RandomPlanetIndex].Name;
                    EmpireManager.GetEmpireByName(Ship.universeScreen.PlayerLoyalty).data.AgentList.Add(a);
                    this.AgentSL.AddItem(a);
                    a.AssignMission(AgentMission.Training, empireByName, "");

                }
            }
            this.selector = null;
            for (int i = this.AgentSL.indexAtTop; i < this.AgentSL.Entries.Count && i < this.AgentSL.indexAtTop + this.AgentSL.entriesToDisplay; i++)
            {
                try
                {
                    ScrollList.Entry e = this.AgentSL.Entries[i];
                    if (HelperFunctions.CheckIntersection(e.clickRect, input.CursorPosition))
                    {
                        this.selector = new Selector(this.ScreenManager, e.clickRect);
                        if (input.InGameSelect)
                        {
                            this.SelectedAgent = e.item as Agent;
                            foreach (ScrollList.Entry entry in this.OpsSL.Entries)
                            {
                                (entry.item as MissionEntry).Initialize();
                            }
                            AudioManager.PlayCue("sd_ui_accept_alt3");
                        }
                    }
                }
                catch
                {
                }
            }
            if (this.SelectedAgent != null)
            {
                for (int i = this.OpsSL.indexAtTop; i < this.OpsSL.Entries.Count && i < this.OpsSL.indexAtTop + this.OpsSL.entriesToDisplay; i++)
                {
                    try
                    {
                        ScrollList.Entry e = this.OpsSL.Entries[i];
                        (e.item as MissionEntry).HandleInput(input);
                        if (HelperFunctions.CheckIntersection(e.clickRect, input.CursorPosition))
                        {
                            if (!HelperFunctions.CheckIntersection((e.item as MissionEntry).DoMission.Rect, input.CursorPosition))
                            {
                                ToolTip.CreateTooltip(Localizer.Token((e.item as MissionEntry).DescriptionIndex), this.ScreenManager);
                            }
                            else
                            {
                                ToolTip.CreateTooltip(Localizer.Token(2198), Ship.universeScreen.ScreenManager);
                            }
                        }
                    }
                    catch
                    {
                    }
                }
            }
            if (CBAutoRepeat != null && cbSpyMute != null)
            {
                CBAutoRepeat.HandleInput(input);
                cbSpyMute.HandleInput(input);
            }
        }
 public void HandleInputorig(InputState input)
 {
     string Names;
     this.AgentSL.HandleInput(input);
     if (this.SelectedAgent != null)
     {
         this.OpsSL.HandleInput(input);
     }
     if (HelperFunctions.CheckIntersection(this.RecruitButton.r, input.CursorPosition))
     {
         ToolTip.CreateTooltip(Localizer.Token(2180), this.ScreenManager);
     }
     if (this.RecruitButton.HandleInput(input))
     {
         if (EmpireManager.GetEmpireByName(Ship.universeScreen.PlayerLoyalty).Money < 250f)
         {
             AudioManager.PlayCue("UI_Misc20");
         }
         else
         {
             Empire empireByName = EmpireManager.GetEmpireByName(Ship.universeScreen.PlayerLoyalty);
             empireByName.Money = empireByName.Money - 250f;
             Names = (!File.Exists(string.Concat("Content/NameGenerators/spynames_", EmpireManager.GetEmpireByName(Ship.universeScreen.PlayerLoyalty).data.Traits.ShipType, ".txt")) ? File.ReadAllText("Content/NameGenerators/spynames_Humans.txt") : File.ReadAllText(string.Concat("Content/NameGenerators/spynames_", EmpireManager.GetEmpireByName(Ship.universeScreen.PlayerLoyalty).data.Traits.ShipType, ".txt")));
             string[] Tokens = Names.Split(new char[] { ',' });
             Agent a = new Agent()
             {
                 Name = AgentComponent.GetName(Tokens)
             };
             EmpireManager.GetEmpireByName(Ship.universeScreen.PlayerLoyalty).data.AgentList.Add(a);
             this.AgentSL.AddItem(a);
         }
     }
     this.selector = null;
     for (int i = this.AgentSL.indexAtTop; i < this.AgentSL.Entries.Count && i < this.AgentSL.indexAtTop + this.AgentSL.entriesToDisplay; i++)
     {
         try
         {
             ScrollList.Entry e = this.AgentSL.Entries[i];
             if (HelperFunctions.CheckIntersection(e.clickRect, input.CursorPosition))
             {
                 this.selector = new Selector(this.ScreenManager, e.clickRect);
                 if (input.InGameSelect)
                 {
                     this.SelectedAgent = e.item as Agent;
                     foreach (ScrollList.Entry entry in this.OpsSL.Entries)
                     {
                         (entry.item as MissionEntry).Initialize();
                     }
                     AudioManager.PlayCue("sd_ui_accept_alt3");
                 }
             }
         }
         catch
         {
         }
     }
     if (this.SelectedAgent != null)
     {
         for (int i = this.OpsSL.indexAtTop; i < this.OpsSL.Entries.Count && i < this.OpsSL.indexAtTop + this.OpsSL.entriesToDisplay; i++)
         {
             try
             {
                 ScrollList.Entry e = this.OpsSL.Entries[i];
                 (e.item as MissionEntry).HandleInput(input);
                 if (HelperFunctions.CheckIntersection(e.clickRect, input.CursorPosition))
                 {
                     if (!HelperFunctions.CheckIntersection((e.item as MissionEntry).DoMission.Rect, input.CursorPosition))
                     {
                         ToolTip.CreateTooltip(Localizer.Token((e.item as MissionEntry).DescriptionIndex), this.ScreenManager);
                     }
                     else
                     {
                         ToolTip.CreateTooltip(Localizer.Token(2198), Ship.universeScreen.ScreenManager);
                     }
                 }
             }
             catch
             {
             }
         }
     }
 }
        //added by gremlin deveks HonPacManager
        private void DoHonPacAgentManager()
        {
            string Names;

            int income = (int)this.spyBudget;

            this.DesiredAgentsPerHostile = (int)(income * .05f) + 1;
            this.DesiredAgentsPerNeutral = (int)(income * .02f) + 1;

            //this.DesiredAgentsPerHostile = 5;
            //this.DesiredAgentsPerNeutral = 1;
            this.DesiredAgentCount = 0;
            this.BaseAgents = empire.GetPlanets().Count / 2 + (int)(this.spyBudget / (this.empire.GrossTaxes * 2));
            foreach (KeyValuePair<Empire, Ship_Game.Gameplay.Relationship> Relationship in this.empire.GetRelations())
            {
                if (!Relationship.Value.Known || Relationship.Key.isFaction || Relationship.Key.data.Defeated)
                {
                    continue;
                }
                if (Relationship.Value.Posture == Posture.Hostile)
                {
                    GSAI desiredAgentCount = this;
                    desiredAgentCount.DesiredAgentCount = desiredAgentCount.DesiredAgentCount + this.DesiredAgentsPerHostile;
                }
                if (Relationship.Value.Posture != Posture.Neutral)
                {
                    continue;
                }
                GSAI gSAI = this;
                gSAI.DesiredAgentCount = gSAI.DesiredAgentCount + this.DesiredAgentsPerNeutral;
            }
            GSAI desiredAgentCount1 = this;
            desiredAgentCount1.DesiredAgentCount = desiredAgentCount1.DesiredAgentCount + this.BaseAgents;
            //int empirePlanetSpys = empire.GetPlanets().Where(canBuildTroops => canBuildTroops.CanBuildInfantry() == true).Count();
            int empirePlanetSpys = empire.GetPlanets().Count() / 3 + 3;
            //if (empire.GetPlanets().Where(canBuildTroops => canBuildTroops.BuildingList.Where(building => building.Name == "Capital City") != null).Count() > 0) empirePlanetSpys = empirePlanetSpys + 2;

            if (this.spyBudget >= 250f && this.empire.data.AgentList.Count < empirePlanetSpys)
            {
                Names = (!File.Exists(string.Concat("Content/NameGenerators/spynames_", this.empire.data.Traits.ShipType, ".txt")) ? File.ReadAllText("Content/NameGenerators/spynames_Humans.txt") : File.ReadAllText(string.Concat("Content/NameGenerators/spynames_", this.empire.data.Traits.ShipType, ".txt")));
                string[] Tokens = Names.Split(new char[] { ',' });
                Agent a = new Agent();
                a.Name = AgentComponent.GetName(Tokens);
                this.empire.data.AgentList.Add(a);
                this.spyBudget -= 250f;
            }
            int Defenders = 0;
            int Offense = 0;
            foreach (Agent a in this.empire.data.AgentList)
            {
                if (a.Mission == AgentMission.Defending)
                {
                    Defenders++;
                }
                else if (a.Mission != AgentMission.Undercover)
                {
                    Offense++;
                }
                if (a.Mission != AgentMission.Defending || a.Level >= 2 || this.spyBudget <= 200f)
                {
                    continue;
                }
                a.AssignMission(AgentMission.Training, this.empire, "");
            }
            int DesiredOffense = (int)(this.empire.data.AgentList.Count*.25f);// /(int)(this.empire.data.AgentList.Count - empire.GetPlanets().Count * .4f);
            foreach (Agent agent in this.empire.data.AgentList)
            {
                if (agent.Mission != AgentMission.Defending && agent.Mission != AgentMission.Undercover || Offense >= DesiredOffense )
                {
                    continue;
                }
                List<Empire> PotentialTargets = new List<Empire>();
                foreach (KeyValuePair<Empire, Ship_Game.Gameplay.Relationship> Relation in this.empire.GetRelations())
                {
                    if (!Relation.Value.Known || Relation.Key.isFaction || Relation.Key.data.Defeated || Relation.Value.Posture != Posture.Neutral && Relation.Value.Posture != Posture.Hostile)
                    {
                        continue;
                    }
                    PotentialTargets.Add(Relation.Key);
                }
                if (PotentialTargets.Count <= 0)
                {
                    continue;
                }
                List<AgentMission> PotentialMissions = new List<AgentMission>();
                Empire Target = PotentialTargets[HelperFunctions.GetRandomIndex(PotentialTargets.Count)];
                if (this.empire.GetRelations()[Target].AtWar)
                {
                    if (agent.Level >= 8)
                    {
                        PotentialMissions.Add(AgentMission.InciteRebellion);
                        PotentialMissions.Add(AgentMission.Assassinate);
                        PotentialMissions.Add(AgentMission.Sabotage);
                        PotentialMissions.Add(AgentMission.Robbery);
                        //PotentialMissions.Add(AgentMission.StealTech);
                    }
                    if (agent.Level >= 4)
                    {
                        PotentialMissions.Add(AgentMission.Robbery);
                        PotentialMissions.Add(AgentMission.Sabotage);
                    }
                    if (agent.Level < 4)
                    {
                        PotentialMissions.Add(AgentMission.Sabotage);
                        PotentialMissions.Add(AgentMission.Robbery);
                        //PotentialMissions.Add(AgentMission.Infiltrate);
                    }
                }
                if (this.empire.GetRelations()[Target].SpiesDetected > 0)
                {
                    if (agent.Level >= 4) PotentialMissions.Add(AgentMission.Assassinate);
                }
                HashSet<AgentMission> remove = new HashSet<AgentMission>();
                foreach (AgentMission mission in PotentialMissions)
                {
                    switch (mission)
                    {
                        case AgentMission.Defending:
                        case AgentMission.Training:
                            break;
                        case AgentMission.Infiltrate:
                            if (ResourceManager.AgentMissionData.InfiltrateCost > this.spyBudget)
                            {
                                remove.Add(mission);
                            }
                            break;
                        case AgentMission.Assassinate:
                            if (ResourceManager.AgentMissionData.AssassinateCost > this.spyBudget)
                            {
                                remove.Add(mission);
                            }
                            break;
                        case AgentMission.Sabotage:
                            if (ResourceManager.AgentMissionData.SabotageCost > this.spyBudget)
                            {
                                remove.Add(mission);
                            }
                            break;
                        case AgentMission.StealTech:
                            if (ResourceManager.AgentMissionData.StealTechCost > this.spyBudget)
                            {
                                remove.Add(mission);
                            }
                            break;
                        case AgentMission.Robbery:
                            if (ResourceManager.AgentMissionData.RobberyCost > this.spyBudget)
                            {
                                remove.Add(mission);
                            }
                            break;
                        case AgentMission.InciteRebellion:
                            if (ResourceManager.AgentMissionData.RebellionCost > this.spyBudget)
                            {
                                remove.Add(mission);
                            }
                            break;
                        case AgentMission.Undercover:
                            if (ResourceManager.AgentMissionData.InfiltrateCost > this.spyBudget)
                            {
                                remove.Add(mission);
                            }
                            break;
                        case AgentMission.Recovering:
                            break;
                        default:
                            break;
                    }
                }
                foreach (AgentMission removeMission in remove)
                {
                    PotentialMissions.Remove(removeMission);
                }
                if (PotentialMissions.Count <= 0)
                {
                    continue;
                }
                AgentMission am = PotentialMissions[HelperFunctions.GetRandomIndex(PotentialMissions.Count)];
                agent.AssignMission(am, this.empire, Target.data.Traits.Name);
                Offense++;
            }
        }