Exemplo n.º 1
0
        /// <summary>
        /// Launches the country resource change form for one or more countries
        /// </summary>
        /// <param name="reader">The reader for the save file</param>
        /// <param name="input">A string containing a comma separated list of country tags</param>
        public static void changeCountyResouces(fileReader reader, string inputText)
        {
            string[] tags         = inputText.Replace(" ", "").Split(',');
            int      countriesLoc = reader.getPosition("countries=\r", 0, '{', '}', true);

            reader.setLineNum(countriesLoc);
            reader.setCharNum(0);

            textBlock countries = new textBlock('{', '}', reader);

            foreach (string tag in tags)
            {
                int countryLoc             = countries.getPosition(tag + "=");
                countryResources resources = new countryResources(reader, countriesLoc + countryLoc, tag);
                resources.ShowDialog();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Launches the technology level change form for one or more countries
        /// </summary>
        /// <param name="reader">The reader for the save file</param>
        /// <param name="input">A string containing a comma separated list of country tags</param>
        public static void alterTechLevel(fileReader reader, string input)
        {
            string[] tags         = input.Replace(" ", "").Split(',');
            int      countriesLoc = reader.getPosition("countries=\r", 0, '{', '}', true);

            reader.setLineNum(countriesLoc);
            reader.setCharNum(0);

            textBlock countries = new textBlock('{', '}', reader);

            foreach (string tag in tags)
            {
                int           countryLoc = countries.getPosition(tag + "=");
                techLevelForm techLevel  = new techLevelForm(reader, countriesLoc + countryLoc, tag);
                techLevel.ShowDialog();
            }
        }
        /// <summary>
        /// Batch edit provinces based on user entries when run button pressed
        /// </summary>
        private void runButton_Click(object sender, EventArgs e)
        {
            string newOwner    = newOwnerBox.Text;
            string newCore     = newCoreBox.Text;
            string newCulture  = newCultureBox.Text;
            string newReligion = newReligionBox.Text;
            string newTax      = newTaxBox.Text;
            string newManpower = newManpowerBox.Text;
            bool   taxMult     = taxMultCheck.Checked;
            bool   manMult     = manpowerMultCheck.Checked;
            int    provLoc     = reader.getPosition("provinces=", 0, '{', '}');

            reader.goTo(provLoc);
            textBlock provinces = new textBlock('{', '}', reader);
            Regex     rgx       = new Regex(@"-[0-9]+=");//province number finding regular expression

            string[] editList = editByInputBox.Text.Replace(" ", "").Split(',');
            int[]    provLocs = provinces.findAll(x => rgx.IsMatch(x), 1, '{', '}');


            //for every province, make changes based on user entry in this form
            foreach (int prov in provLocs)
            {
                //check if this province is included in the user's province specificiation
                textBlock thisProv = new textBlock();
                bool      editThis = false;
                if ((string)editByButton.SelectedItem == "Province ID")
                {
                    reader.goTo(provLoc + prov);
                    thisProv = new textBlock('{', '}', reader);
                    editThis = editList.Contains(reader.readLine(provLoc + prov).Replace("-", "").Replace("=", "").Trim());
                }
                else if ((string)editByButton.SelectedItem == "Owner")
                {
                    reader.goTo(provLoc + prov);
                    thisProv = new textBlock('{', '}', reader);
                    int ownerLoc = thisProv.getPosition("owner=");
                    if (ownerLoc != -1)
                    {
                        string owner = reader.readLine(provLoc + prov + ownerLoc).Split('=')[1].Trim();
                        editThis = editList.Contains(owner);
                    }
                }
                else if ((string)editByButton.SelectedItem == "Culture")
                {
                    reader.goTo(provLoc + prov);
                    thisProv = new textBlock('{', '}', reader);
                    int cultureLoc = thisProv.getPosition("culture=");
                    if (cultureLoc != -1)
                    {
                        string culture = reader.readLine(provLoc + prov + cultureLoc).Split('=')[1].Trim();
                        editThis = editList.Contains(culture);
                    }
                }
                else if ((string)editByButton.SelectedItem == "Religion")
                {
                    reader.goTo(provLoc + prov);
                    thisProv = new textBlock('{', '}', reader);
                    int relLoc = thisProv.getPosition("religion=");
                    if (relLoc != -1)
                    {
                        string rel = reader.readLine(provLoc + prov + relLoc).Split('=')[1].Trim();
                        editThis = editList.Contains(rel);
                    }
                }
                else if ((string)editByButton.SelectedItem == "Name")
                {
                    reader.goTo(provLoc + prov);
                    thisProv = new textBlock('{', '}', reader);
                    int nameLoc = thisProv.getPosition("name=");
                    if (nameLoc != -1)
                    {
                        string name = reader.readLine(provLoc + prov + nameLoc).Split('=')[1].Trim().Replace("\"", "");
                        editThis = editList.Contains(name);
                    }
                }
                else if ((string)editByButton.SelectedItem == "All")
                {
                    reader.goTo(provLoc + prov);
                    thisProv = new textBlock('{', '}', reader);
                    editThis = true;
                }
                //If it is something to edit, edit it appropriately
                if (editThis)
                {
                    int nameLoc = thisProv.getPosition("name=");
                    if (nameLoc != -1)
                    {
                        string name = reader.readLine(provLoc + prov + nameLoc).Split('=')[1].Trim().Replace("\"", "");
                        outputBox.AppendText("Editing province " + name + "\r\n");
                    }
                    if (newOwner != "")
                    {
                        reader.changeLine(provLoc + prov + thisProv.getPosition("owner="), "\t\towner=" + newOwner);
                        reader.changeLine(provLoc + prov + thisProv.getPosition("controller="), "\t\tcontroller=" + newOwner);
                    }
                    if (newCore != "")
                    {
                        if (thisProv.getPosition("\t\tcore=" + newCore) == -1)
                        {
                            reader.addLine("\t\tcore=" + newCore, provLoc + prov + thisProv.getPosition("core="));
                            provLoc++;
                        }
                    }
                    if (newCulture != "")
                    {
                        reader.changeLine(provLoc + prov + thisProv.getPosition("culture="), "\t\tculture=" + newCulture);
                    }
                    if (newReligion != "")
                    {
                        reader.changeLine(provLoc + prov + thisProv.getPosition("religion="), "\t\treligion=" + newReligion);
                    }
                    if (newTax != "")
                    {
                        int taxLine = thisProv.getPosition("base_tax=");
                        if (taxLine != -1)
                        {
                            if (!taxMult)
                            {
                                reader.changeLine(provLoc + prov + taxLine, "\t\tbase_tax=" + newTax);
                            }
                            else
                            {
                                double oldTax       = Convert.ToDouble(thisProv.getLine(taxLine).Split('=')[1]);
                                double newTaxDouble = Convert.ToDouble(newTax);
                                string overwriteTax = (newTaxDouble * oldTax).ToString();
                                reader.changeLine(provLoc + prov + thisProv.getPosition("base_tax="), "\t\tbase_tax=" + overwriteTax);
                            }
                        }
                    }
                    if (newManpower != "")
                    {
                        int manLine = thisProv.getPosition("manpower=");
                        if (manLine != -1)
                        {
                            if (!manMult)
                            {
                                reader.changeLine(provLoc + prov + manLine, "\t\tmanpower=" + newManpower);
                            }
                            else
                            {
                                double oldMan       = Convert.ToDouble(thisProv.getLine(manLine).Split('=')[1]);
                                double newManDouble = Convert.ToDouble(newManpower);
                                string overwriteMan = (newManDouble * oldMan).ToString();
                                reader.changeLine(provLoc + prov + thisProv.getPosition("manpower="), "\t\tmanpower=" + overwriteMan);
                            }
                        }
                    }
                }
            }
            outputBox.AppendText("Done!\r\n");
        }
Exemplo n.º 4
0
        /// <summary>
        /// Initialize a form for changing country resources
        /// </summary>
        /// <param name="readerIn">a reader for the save to edit</param>
        /// <param name="Loc">the index for the beginning of the relevant country text block</param>
        /// <param name="tag">the three letter identifier for the country to edit (e.g. FRA for France)</param>
        public countryResources(fileReader readerIn, int Loc, string tag)
        {
            //read in all the current values from the save
            loc        = Loc;
            countryTag = tag;
            reader     = readerIn;
            InitializeComponent();
            reader.goTo(loc);
            country  = new textBlock('{', '}', reader);
            cash     = country.getLine(country.getPosition("treasury=")).Split('=')[1];
            manpower = country.getLine(country.getPosition("manpower=")).Split('=')[1];
            int powerLoc = country.getPosition("powers=");

            adm       = country.getLine(powerLoc + 2).Split(' ')[0].Trim();
            dip       = country.getLine(powerLoc + 2).Split(' ')[1].Trim();
            mil       = country.getLine(powerLoc + 2).Split(' ')[2].Trim();
            techGroup = country.getLine(country.getPosition("technology_group=")).Split('=')[1];
            capital   = country.getLine(country.getPosition("capital=")).Split('=')[1];
            stability = country.getLine(country.getPosition("stability=")).Split('=')[1];
            cultures  = new List <string>();
            cultures.Add(country.getLine(country.getPosition("primary_culture=")).Split('=')[1]);
            int[] acceptedCultureLocs = country.findAll("accepted_culture=");
            foreach (int pos in acceptedCultureLocs)
            {
                cultures.Add(country.getLine(pos).Split('=')[1]);
            }
            religion   = country.getLine(country.getPosition("religion=")).Split('=')[1];
            government = country.getLine(country.getPosition("government=")).Split('=')[1];
            int warExPos = country.getPosition("war_exhaustion=");

            if (warExPos != -1)
            {
                warExhaustion = country.getLine(country.getPosition("war_exhaustion=")).Split('=')[1];
            }
            else
            {
                warExhaustion = "0.000";
            }

            cashLabel.Text          = cash;
            manpowerLabel.Text      = manpower;
            admLabel.Text           = adm;
            dipLabel.Text           = dip;
            milLabel.Text           = mil;
            techGroupLabel.Text     = techGroup;
            capitalLabel.Text       = capital;
            stabilityLabel.Text     = stability;
            cultureLabel.Text       = string.Join(", ", cultures);
            religionLabel.Text      = religion;
            governmentLabel.Text    = government;
            warExhaustionLabel.Text = warExhaustion;

            int dipPosition = reader.getPosition("diplomacy=", 0, '{', '}');

            reader.goTo(dipPosition);
            textBlock diplomacy = new textBlock('{', '}', reader);

            int[]  vassalages = diplomacy.findAll("vassal=");
            string overlord   = "";

            foreach (int i in vassalages)
            {
                reader.goTo(dipPosition + i);
                textBlock vassal = new textBlock('{', '}', reader);
                if (vassal.getLine(vassal.getPosition("second=")).Split('=')[1] == "\"" + tag + "\"")
                {
                    overlord  = vassal.getLine(vassal.getPosition("first=")).Split('=')[1].Replace("\"", "");
                    vassalLoc = dipPosition + i;
                    break;
                }
            }
            if (overlord == "")
            {
                vassalLabel.Text = "none";
                vassalLoc        = dipPosition + 2;
            }
            else
            {
                vassalLabel.Text = overlord;
            }
        }