public List <StrategicRegion> loadStrategicRegions()
        {
            strategicRegionNameLookup = new Dictionary <string, StrategicRegion>();
            List <StrategicRegion> returnList = new List <StrategicRegion>();

            provincesInStrategicRegion = new Dictionary <StrategicRegion, int[]>();

            string strategicRegionsFolder = ModFileReader.FolderPath + "/map/strategicregions";

            foreach (string file in Directory.GetFiles(strategicRegionsFolder))
            {
                StreamReader sr         = new StreamReader(file);
                string       totalText  = sr.ReadToEnd();
                int          idVal      = int.Parse(TextParser.getVariable(totalText, "id"));
                string       regionName = TextParser.getVariable(totalText, "name").Replace("\"", "").Trim();
                //Console.WriteLine(regionName);
                regionName = baseGame.LocalisationLookup.ContainsKey(regionName) ? baseGame.LocalisationLookup[regionName] : regionName;

                string   provinceText = TextParser.GetContentsOfBrackets(totalText, "provinces");
                string[] provs        = provinceText.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                List <int> provIds     = new List <int>();
                bool       isOnlyWater = true;
                for (int i = 0; i < provs.Length; i++)
                {
                    // If i can parse the value then add it to the list of ids
                    int provId;
                    if (int.TryParse(provs[i], out provId))
                    {
                        if (!baseGame.ProvinceLookup[provId].IsWater)
                        {
                            isOnlyWater = false;
                        }
                        provIds.Add(provId);
                    }
                }

                StrategicRegion newRegion = new StrategicRegion(idVal, regionName);
                newRegion.IsOnlyWater = isOnlyWater;

                // Don't bother with regions that are only ocean
                if (!newRegion.IsOnlyWater)
                {
                    strategicRegionNameLookup.Add(newRegion.Name, newRegion);
                    returnList.Add(newRegion);
                    provincesInStrategicRegion.Add(newRegion, provIds.ToArray());
                }

                //Console.WriteLine(idVal+": "+provinceText);
                sr.Close();
            }
            return(returnList);
        }
Exemple #2
0
        private void StrategicRegionCombo_SelectedIndexChanged(object sender, EventArgs e)
        {
            StateDetailsPanel.Visible = false;
            StateTagTextBox.Text      = "";

            if (StrategicRegionCombo.SelectedIndex == 0)
            {
                listStates.Items.Clear();
                listStates.Items.AddRange(stateIndexer.AllStates);
            }
            else
            {
                listStates.Items.Clear();
                string selectedText = ((StrategicRegion)StrategicRegionCombo.SelectedItem).Name;
                //Console.WriteLine("Selected Text: " + selectedText);
                if (stateIndexer.strategicRegionNameLookup.ContainsKey(selectedText))
                {
                    StrategicRegion selectedRegion = stateIndexer.strategicRegionNameLookup[selectedText];
                    List <State>    statesToShow   = new List <State>();
                    foreach (int provId in stateIndexer.provincesInStrategicRegion[selectedRegion])
                    {
                        if (stateIndexer.stateProvinceIdLookup.ContainsKey(provId))
                        {
                            State provState = stateIndexer.stateProvinceIdLookup[provId];
                            if (!statesToShow.Contains(provState))
                            {
                                statesToShow.Add(provState);
                            }
                        }
                        else
                        {
                            //Console.WriteLine("Missing Province (probably sea): "+provId);
                            // Probably a sea province which means it won't have a state associate with it
                        }
                    }

                    listStates.Items.AddRange(statesToShow.ToArray());
                }
            }
        }