public RootNode(Vector2 Position, TechEntry Tech)
 {
     if (GlobalStats.Config.Language == "Russian" || GlobalStats.Config.Language == "Polish")
     {
         this.TitleFont = Fonts.Arial10;
     }
     this.tech = Tech;
     this.TechName = Localizer.Token(ResourceManager.TechTree[Tech.UID].NameIndex);
     this.RootRect.X = (int)Position.X;
     this.RootRect.Y = (int)Position.Y;
     this.IconRect = new Rectangle(this.RootRect.X + this.RootRect.Width / 2 - 39, this.RootRect.Y + this.RootRect.Height / 2 - 29, 78, 58);
     this.TitleRect = new Rectangle(this.RootRect.X + 2, this.RootRect.Y - 21, 108, 61);
 }
 private void SetNode(TechEntry tech)
 {
     Vector2 Position = new Vector2(this.Cursor.X, this.Cursor.Y);
     bool SeatTaken = false;
     foreach (Vector2 v in this.ClaimedSpots)
     {
         if (v.X != Position.X || v.Y != Position.Y)
         {
             continue;
         }
         SeatTaken = true;
     }
     if (SeatTaken)
     {
         this.Cursor.Y = this.Cursor.Y + 1f;
     }
     else
     {
         this.ClaimedSpots.Add(Position);
     }
     RootNode newNode = new RootNode(this.MainMenuOffset + new Vector2((float)(this.ColumnOffset * (int)this.Cursor.X), (float)(this.RowOffset * ((int)this.Cursor.Y - 1))), tech)
     {
         NodePosition = this.Cursor
     };
     if (EmpireManager.GetEmpireByName(this.empireUI.screen.PlayerLoyalty).GetTDict()[tech.UID].Unlocked)
     {
         newNode.isResearched = true;
     }
     this.TechTree.Add(tech.UID, newNode);
 }
        public void Initialize()
        {
            this.GSAI = new GSAI(this);
            for (int key = 1; key < 100; ++key)
            {
                Fleet fleet = new Fleet();
                fleet.Owner = this;
                string str = "";
                switch (key)
                {
                    case 0:
                        str = "10th";
                        break;
                    case 1:
                        str = "1st";
                        break;
                    case 2:
                        str = "2nd";
                        break;
                    case 3:
                        str = "3rd";
                        break;
                    case 4:
                        str = "4th";
                        break;
                    case 5:
                        str = "5th";
                        break;
                    case 6:
                        str = "6th";
                        break;
                    case 7:
                        str = "7th";
                        break;
                    case 8:
                        str = "8th";
                        break;
                    case 9:
                        str = "9th";
                        break;
                }
                fleet.Name = str + " fleet";
                this.FleetsDict.TryAdd(key, fleet);
            }
            foreach (KeyValuePair<string, Technology> keyValuePair in ResourceManager.TechTree)
            {
                TechEntry techEntry = new TechEntry();
                techEntry.Progress = 0.0f;
                techEntry.UID = keyValuePair.Key;

                //added by McShooterz: Checks if tech is racial, hides it, and reveals it only to races that pass
                if (keyValuePair.Value.RaceRestrictions.Count != 0)
                {
                    techEntry.Discovered = false;
                    techEntry.GetTech().Secret = true;
                    foreach (Technology.RequiredRace raceTech in keyValuePair.Value.RaceRestrictions)
                    {
                        if (raceTech.ShipType == this.data.Traits.ShipType)
                        {
                            techEntry.Discovered = true;
                            techEntry.Unlocked = keyValuePair.Value.RootNode == 1;
                            if (this.data.Traits.Militaristic == 1 && techEntry.GetTech().Militaristic)
                                techEntry.Unlocked = true;
                            break;
                        }
                    }
                }
                else //not racial tech
                {
                    techEntry.Unlocked = keyValuePair.Value.RootNode == 1;
                }
                if (this.isFaction || this.data.Traits.Prewarp == 1)
                {
                    techEntry.Unlocked = false;
                }
                if (this.data.Traits.Militaristic == 1)
                {
                    //added by McShooterz: alternate way to unlock militaristic techs
                    if (techEntry.GetTech().Militaristic && techEntry.GetTech().RaceRestrictions.Count == 0)
                        techEntry.Unlocked = true;

                    // If using the customMilTraitsTech option in ModInformation, default traits will NOT be automatically unlocked. Allows for totally custom militaristic traits.
                    if (GlobalStats.ActiveModInfo == null || (GlobalStats.ActiveModInfo != null && !GlobalStats.ActiveModInfo.customMilTraitTechs))
                    {
                        if (techEntry.UID == "HeavyFighterHull")
                        {
                            techEntry.Unlocked = true;
                        }
                        if (techEntry.UID == "Military")
                        {
                            techEntry.Unlocked = true;
                        }
                        if (techEntry.UID == "ArmorTheory")
                        {
                            techEntry.Unlocked = true;
                        }
                    }
                }
                if(this.data.Traits.Cybernetic >0)
                {
                    if (techEntry.UID == "Biospheres")
                        techEntry.Unlocked = true;
                }
                if (techEntry.Unlocked)
                    techEntry.Progress = techEntry.GetTech().Cost * UniverseScreen.GamePaceStatic;
                this.TechnologyDict.Add(keyValuePair.Key, techEntry);
            }
            foreach (KeyValuePair<string, ShipData> keyValuePair in ResourceManager.HullsDict)
                this.UnlockedHullsDict.Add(keyValuePair.Value.Hull, false);
            foreach (KeyValuePair<string, Troop> keyValuePair in ResourceManager.TroopsDict)
                this.UnlockedTroopDict.Add(keyValuePair.Key, false);
            foreach (KeyValuePair<string, Building> keyValuePair in ResourceManager.BuildingsDict)
                this.UnlockedBuildingsDict.Add(keyValuePair.Key, false);
            foreach (KeyValuePair<string, ShipModule> keyValuePair in ResourceManager.ShipModulesDict)
                this.UnlockedModulesDict.Add(keyValuePair.Key, false);
            //unlock from empire data file
            foreach (string building in this.data.unlockBuilding)
                this.UnlockedBuildingsDict[building] = true;
            foreach (KeyValuePair<string, TechEntry> keyValuePair in this.TechnologyDict)
            {
                if (keyValuePair.Value.Unlocked)
                {
                    keyValuePair.Value.Unlocked = false;
                    this.UnlockTech(keyValuePair.Key);
                }
            }
            //unlock ships from empire data
            foreach (string ship in this.data.unlockShips)
                this.ShipsWeCanBuild.Add(ship);
            //clear these lists as they serve no more purpose
            this.data.unlockBuilding.Clear();
            this.data.unlockShips.Clear();
            this.UpdateShipsWeCanBuild();
            if (this.data.EconomicPersonality == null)
                this.data.EconomicPersonality = new ETrait
                {
                    Name = "Generalists"
                };
            //Added by McShooterz: mod support for EconomicResearchStrategy folder
            try
            {
                if (File.Exists(string.Concat(Ship_Game.ResourceManager.WhichModPath, "/EconomicResearchStrategy/", this.data.EconomicPersonality.Name, ".xml")))
                {

                    this.economicResearchStrategy = (EconomicResearchStrategy)ResourceManager.EconSerializer.Deserialize((Stream)new FileInfo(string.Concat(Ship_Game.ResourceManager.WhichModPath, "/EconomicResearchStrategy/", this.data.EconomicPersonality.Name, ".xml")).OpenRead());
                }
                else
                {
                    this.economicResearchStrategy = (EconomicResearchStrategy)ResourceManager.EconSerializer.Deserialize((Stream)new FileInfo("Content/EconomicResearchStrategy/" + this.data.EconomicPersonality.Name + ".xml").OpenRead());
                }
            }
            catch(Exception e)
            {
                e.Data.Add("Failing File: ", string.Concat(Ship_Game.ResourceManager.WhichModPath, "/EconomicResearchStrategy/", this.data.EconomicPersonality.Name, ".xml"));
                e.Data.Add("Fail Reaseon: ", e.InnerException);
                throw e;
            }

            //Added by gremlin Figure out techs with modules that we have ships for.
            foreach (KeyValuePair<string,TechEntry> tech in this.TechnologyDict)
            {
                if(tech.Value.GetTech().ModulesUnlocked.Count>0  &&  tech.Value.GetTech().HullsUnlocked.Count()==0 && !this.WeCanUseThis(tech.Value.GetTech()))
                {
                    this.TechnologyDict[tech.Key].shipDesignsCanuseThis = false;
                }

            }
            foreach (KeyValuePair<string,TechEntry> tech in this.TechnologyDict)
            {
                if(!tech.Value.shipDesignsCanuseThis)
                {
                    if(WeCanUseThisLater(tech.Value))
                    {
                        tech.Value.shipDesignsCanuseThis = true;
                    }
                }
            }
            this.MarkShipDesignsUnlockable();
        }
        public TreeNode(Vector2 Position, TechEntry Tech, ResearchScreenNew screen)
        {
            if (GlobalStats.Config.Language == "Russian" || GlobalStats.Config.Language == "Polish")
            {
                this.TitleFont = Fonts.Arial10;
            }
            this.screen = screen;
            this.tech = Tech;
            this.TechName = string.Concat(Localizer.Token(ResourceManager.TechTree[Tech.UID].NameIndex), ResourceManager.TechTree[Tech.UID].MaxLevel > 1 ? " " + NumberToRomanConvertor.NumberToRoman(Tech.level) + "/" + NumberToRomanConvertor.NumberToRoman(ResourceManager.TechTree[Tech.UID].MaxLevel) : "");
            this.BaseRect.X = (int)Position.X;
            this.BaseRect.Y = (int)Position.Y;
            this.progressRect = new Rectangle(this.BaseRect.X + 14, this.BaseRect.Y + 21, 1, 34);
            int numUnlocks = 0;
            for (int i = 0; i < ResourceManager.TechTree[this.tech.UID].ModulesUnlocked.Count; i++)
            {
                if (numUnlocks > 3) break;
                if (ResourceManager.TechTree[this.tech.UID].ModulesUnlocked[i].Type == EmpireManager.GetEmpireByName(screen.empireUI.screen.PlayerLoyalty).data.Traits.ShipType || ResourceManager.TechTree[this.tech.UID].ModulesUnlocked[i].Type == null || ResourceManager.TechTree[this.tech.UID].ModulesUnlocked[i].Type == EmpireManager.GetEmpireByName(screen.empireUI.screen.PlayerLoyalty).GetTDict()[this.tech.UID].AcquiredFrom)
                {
                    UnlockItem unlock = new UnlockItem();
                    unlock.module = ResourceManager.ShipModulesDict[ResourceManager.TechTree[this.tech.UID].ModulesUnlocked[i].ModuleUID];
                    unlock.privateName = Localizer.Token(unlock.module.NameIndex);
                    unlock.Description = Localizer.Token(unlock.module.DescriptionIndex);
                    unlock.Type = "SHIPMODULE";
                    this.Unlocks.Add(unlock);
                    numUnlocks++;
                }
            }
            for (int i = 0; i < ResourceManager.TechTree[this.tech.UID].BonusUnlocked.Count; i++)
            {
                if (numUnlocks > 3) break;
                if (ResourceManager.TechTree[this.tech.UID].BonusUnlocked[i].Type == EmpireManager.GetEmpireByName(screen.empireUI.screen.PlayerLoyalty).data.Traits.ShipType || ResourceManager.TechTree[this.tech.UID].BonusUnlocked[i].Type == null || ResourceManager.TechTree[this.tech.UID].BonusUnlocked[i].Type == EmpireManager.GetEmpireByName(screen.empireUI.screen.PlayerLoyalty).GetTDict()[this.tech.UID].AcquiredFrom)
                {
                    UnlockItem unlock = new UnlockItem()
                    {
                        privateName = ResourceManager.TechTree[this.tech.UID].BonusUnlocked[i].Name,
                        Description = Localizer.Token(ResourceManager.TechTree[this.tech.UID].BonusUnlocked[i].BonusIndex),
                        Type = "ADVANCE"
                    };
                    numUnlocks++;
                    this.Unlocks.Add(unlock);
                }
            }
            for (int i = 0; i < ResourceManager.TechTree[this.tech.UID].BuildingsUnlocked.Count; i++)
            {
                if (numUnlocks > 3) break;
                if (ResourceManager.TechTree[this.tech.UID].BuildingsUnlocked[i].Type == EmpireManager.GetEmpireByName(screen.empireUI.screen.PlayerLoyalty).data.Traits.ShipType || ResourceManager.TechTree[this.tech.UID].BuildingsUnlocked[i].Type == null || ResourceManager.TechTree[this.tech.UID].BuildingsUnlocked[i].Type == EmpireManager.GetEmpireByName(screen.empireUI.screen.PlayerLoyalty).GetTDict()[this.tech.UID].AcquiredFrom)
                {
                    UnlockItem unlock = new UnlockItem();
                    unlock.building = ResourceManager.BuildingsDict[ResourceManager.TechTree[this.tech.UID].BuildingsUnlocked[i].Name];
                    unlock.privateName = Localizer.Token(unlock.building.NameTranslationIndex);
                    unlock.Description = Localizer.Token(unlock.building.DescriptionIndex);
                    unlock.Type = "BUILDING";
                    numUnlocks++;
                    this.Unlocks.Add(unlock);
                }
            }
            for (int i = 0; i < ResourceManager.TechTree[this.tech.UID].HullsUnlocked.Count; i++)
            {
                if (numUnlocks > 3) break;
                if (ResourceManager.TechTree[this.tech.UID].HullsUnlocked[i].ShipType == EmpireManager.GetEmpireByName(screen.empireUI.screen.PlayerLoyalty).data.Traits.ShipType || ResourceManager.TechTree[this.tech.UID].HullsUnlocked[i].ShipType == null || ResourceManager.TechTree[this.tech.UID].HullsUnlocked[i].ShipType == EmpireManager.GetEmpireByName(screen.empireUI.screen.PlayerLoyalty).GetTDict()[this.tech.UID].AcquiredFrom)
                {
                    UnlockItem unlock = new UnlockItem()
                    {
                        HullUnlocked = ResourceManager.TechTree[this.tech.UID].HullsUnlocked[i].Name,
                        privateName = ResourceManager.TechTree[this.tech.UID].HullsUnlocked[i].Name,
                        Description = "",
                        Type = "HULL"
                    };
                    numUnlocks++;
                    this.Unlocks.Add(unlock);
                }
            }
            for (int i = 0; i < ResourceManager.TechTree[this.tech.UID].TroopsUnlocked.Count; i++)
            {
                if (numUnlocks > 3) break;
                if (ResourceManager.TechTree[this.tech.UID].TroopsUnlocked[i].Type == EmpireManager.GetEmpireByName(screen.empireUI.screen.PlayerLoyalty).data.Traits.ShipType || ResourceManager.TechTree[this.tech.UID].TroopsUnlocked[i].Type == "ALL" || ResourceManager.TechTree[this.tech.UID].TroopsUnlocked[i].Type == null || ResourceManager.TechTree[this.tech.UID].TroopsUnlocked[i].Type == EmpireManager.GetEmpireByName(screen.empireUI.screen.PlayerLoyalty).GetTDict()[this.tech.UID].AcquiredFrom)
                {
                    UnlockItem unlock = new UnlockItem();
                    //{
                        unlock.troop = ResourceManager.TroopsDict[ResourceManager.TechTree[this.tech.UID].TroopsUnlocked[i].Name];
                        unlock.privateName = ResourceManager.TechTree[this.tech.UID].TroopsUnlocked[i].Name;
                        unlock.Description = unlock.troop.Description;
                        unlock.Type = "TROOP";
                    //};
                    numUnlocks++;
                    this.Unlocks.Add(unlock);
                }
            }
            int numColumns = numUnlocks / 2 + numUnlocks % 2;
            this.IconRect = new Rectangle(this.BaseRect.X + this.BaseRect.Width / 2 - 29, this.BaseRect.Y + this.BaseRect.Height / 2 - 24 - 10, 58, 49);
            if (numUnlocks <= 1)
            {
                this.UnlocksRect = new Rectangle(this.IconRect.X + this.IconRect.Width, this.IconRect.Y + this.IconRect.Height - 5, 35, 32);

                this.UnlocksRect.Y = this.UnlocksRect.Y - this.UnlocksRect.Height;

                Rectangle drawRect = this.UnlocksRect;
                drawRect.X = drawRect.X + 3;
                this.grid = new UnlocksGrid(this.Unlocks, drawRect);
            }
            else
            {
                this.UnlocksRect = new Rectangle(this.IconRect.X + this.IconRect.Width, this.IconRect.Y + this.IconRect.Height - 5, 13 + numColumns * 32, (numUnlocks == 1 ? 32 : 64));

                    this.UnlocksRect.Y = this.UnlocksRect.Y - this.UnlocksRect.Height;

                Rectangle drawRect = this.UnlocksRect;
                drawRect.X = drawRect.X + 13;
                this.grid = new UnlocksGrid(this.Unlocks, drawRect);
            }
            this.UnlocksRect.X = this.UnlocksRect.X - 2;
            this.UnlocksRect.Width = this.UnlocksRect.Width + 4;
            this.UnlocksRect.Y = this.UnlocksRect.Y - 2;
            this.UnlocksRect.Height = this.UnlocksRect.Height + 4;
            this.TitleRect = new Rectangle(this.BaseRect.X + 8, this.BaseRect.Y - 15, 82, 29);
            if (GlobalStats.Config.Language == "German" || GlobalStats.Config.Language == "Polish")
            {
                this.TitleRect.X = this.TitleRect.X - 5;
                this.TitleRect.Width = this.TitleRect.Width + 5;
                TreeNode titleWidth = this;
                titleWidth.TitleWidth = titleWidth.TitleWidth + 10f;
            }
            this.CostPos = new Vector2(65f, 70f) + new Vector2((float)this.BaseRect.X, (float)this.BaseRect.Y);
            float x = this.CostPos.X;
            SpriteFont titleFont = this.TitleFont;
            float cost = (float)((int)EmpireManager.GetEmpireByName(this.screen.empireUI.screen.PlayerLoyalty).TechnologyDict[this.tech.UID].GetTechCost()) * UniverseScreen.GamePaceStatic;
            this.CostPos.X = x - titleFont.MeasureString(cost.ToString()).X;
            this.CostPos.X = (float)((int)this.CostPos.X);
            this.CostPos.Y = (float)((int)this.CostPos.Y - 3);
        }
        private bool WeCanUseThisLater(TechEntry tech)
        {
            //List<Technology.LeadsToTech> leadsto = new List<Technology.LeadsToTech>();
            //    leadsto =tech.GetTech().LeadsTo;

            foreach (Technology.LeadsToTech leadsto in tech.GetTech().LeadsTo)
                {
                    TechEntry entry = this.TechnologyDict[leadsto.UID];
                    if (entry.shipDesignsCanuseThis == true)
                        return true;
                    else
                        if (WeCanUseThisLater(entry))
                            return true;
                }
            return false;
        }