Пример #1
0
        /// <summary>
        /// Initialize the form.
        /// </summary>
        public void initialize()
        {
            List <string> monarchIDs = new List <string>();

            reader.goTo(this.countryLoc);
            textBlock country         = new textBlock('{', '}', reader);
            int       historyLocLocal = country.getPosition("history=");

            reader.goTo(this.countryLoc + historyLocLocal);
            textBlock history = new textBlock('{', '}', reader);

            monarchs    = history.findAll("monarch=", 2, '{', '}');
            heirs       = history.findAll("heir=", 2, '{', '}');
            uniqueHeirs = new List <int>();
            repeatHeirs = new List <int>();
            historyLoc  = countryLoc + historyLocLocal;

            monarchBox.Items.Clear();
            monarchIDs.Clear();
            monarchBlocks.Clear();
            heirBox.Items.Clear();
            heirBlocks.Clear();

            int i = monarchs.Length - 1;

            while (i >= 0)
            {
                reader.goTo(historyLoc + monarchs[i]);
                textBlock monarch = new textBlock('{', '}', reader);
                string    name    = monarch.getLine(monarch.getPosition("name=")).Split('=')[1].Replace("\"", "").Trim();
                int       thing   = monarch.getPosition("id=");
                string    ID      = monarch.getLine(monarch.getPosition("id=", false, 2)).Split('=')[1].Trim();
                monarchBox.Items.Add(name);
                monarchIDs.Add(ID);
                monarchBlocks.Add(monarch);
                i--;
            }

            i = heirs.Length - 1;
            while (i >= 0)
            {
                reader.goTo(historyLoc + heirs[i]);
                textBlock monarch = new textBlock('{', '}', reader);
                string    name    = monarch.getLine(monarch.getPosition("name=")).Split('=')[1].Replace("\"", "").Trim();
                string    ID      = monarch.getLine(monarch.getPosition("id=", false, 2)).Split('=')[1].Trim();
                if (!monarchIDs.Contains(ID))
                {
                    heirBox.Items.Add(name);
                    heirBlocks.Add(monarch);
                    uniqueHeirs.Add(i);
                    repeatHeirs.Add(-1);
                }
                else
                {
                    repeatHeirs.Add(monarchIDs.IndexOf(ID));
                }
                i--;
            }
        }
Пример #2
0
        /// <summary>
        /// Eliminates the aggressive expansion opinion penalty 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 alterAggExp(fileReader reader, string input)
        {
            string[] tags = input.Replace(" ", "").Split(',');

            int[] locations = reader.findAll("active_relations=");
            foreach (int location in locations)
            {
                reader.setLineNum(location);
                reader.setCharNum(0);
                textBlock relationsBlock = new textBlock('{', '}', reader);
                foreach (string tag in tags)
                {
                    int pos = relationsBlock.getPosition("\t\t\t" + tag + "=", false, 1);
                    if (pos != -1)
                    {
                        reader.goTo(location + pos);
                        textBlock relations = new textBlock('{', '}', reader);
                        int       innerPos  = relations.getPosition("modifier=\"aggressive_expansion\"", false, 2);
                        if (innerPos != -1)
                        {
                            reader.changeLine(location + pos + innerPos + 2, "\t\t\t\t\tcurrent_opinion=0.000");
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Initialize a tech level editing form
        /// </summary>
        /// <param name="readerIn">The reader containing the file to edit</param>
        /// <param name="Loc">The location in the reader of the country to edit</param>
        /// <param name="tag">The three letter identifier of the country to edit (e.g. FRA for france)</param>
        public techLevelForm(fileReader readerIn, int Loc, string tag)
        {
            loc    = Loc;
            reader = readerIn;
            InitializeComponent();
            reader.goTo(Loc);
            country = new textBlock('{', '}', reader);
            techLoc = country.getPosition("technology=");
            reader.goTo(Loc + techLoc + 2);
            string currentTech = reader.peekLine();

            oldAdmLabel.Text = currentTech.Split('=')[1].Trim();
            reader.moveBy(1);
            currentTech      = reader.peekLine();
            oldDipLabel.Text = currentTech.Split('=')[1].Trim();
            reader.moveBy(1);
            currentTech          = reader.peekLine();
            oldMilLabel.Text     = currentTech.Split('=')[1].Trim();
            instructionText.Text = "Please enter new tech values for country " + tag + "\nor leave a box blank to leave that text level unchanged.";
        }
        /// <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");
        }
Пример #5
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;
            }
        }
Пример #6
0
        /// <summary>
        /// Apply changes and close when done
        /// </summary>
        private void doneButton_Click(object sender, EventArgs e)
        {
            if (cashBox.Text != "")
            {
                cash = cashBox.Text;
            }
            if (manpowerBox.Text != "")
            {
                manpower = manpowerBox.Text;
            }
            if (admBox.Text != "")
            {
                adm = admBox.Text;
            }
            if (dipBox.Text != "")
            {
                dip = dipBox.Text;
            }
            if (milBox.Text != "")
            {
                mil = milBox.Text;
            }
            if (techGroupBox.SelectedItem != null)
            {
                techGroup = (string)techGroupBox.SelectedItem;
            }
            if (capitalBox.Text != "")
            {
                capital = capitalBox.Text;
            }
            if (stabilityBox.Text != "")
            {
                stability = stabilityBox.Text;
            }
            if (cultureBox.Text != "")
            {
                cultures = cultureBox.Text.Split(',').ToList <string>();
            }
            if (religionBox.Text != "")
            {
                religion = religionBox.Text;
            }
            if (governmentBox.SelectedItem != null)
            {
                government = (string)governmentBox.SelectedItem;
            }
            if (vassalBox.Text != "")
            {
                vassalTag = vassalBox.Text;
            }
            if (warExhaustionBox.Text != "")
            {
                warExhaustion = warExhaustionBox.Text;
            }
            reader.changeLine(loc + country.getPosition("treasury="), "\t\ttreasury=" + cash);
            reader.changeLine(loc + country.getPosition("manpower="), "\t\tmanpower=" + manpower);
            reader.changeLine(loc + country.getPosition("powers=") + 2, "\t\t\t" + adm + " " + dip + " " + mil + " ");
            reader.changeLine(loc + country.getPosition("technology_group="), "\t\ttechnology_group=" + techGroup);
            reader.changeLine(loc + country.getPosition("capital="), "\t\tcapital=" + capital);
            reader.changeLine(loc + country.getPosition("stability="), "\t\tstability=" + stability);
            int[] acceptedCultureLocs = country.findAll("accepted_culture=");
            reader.changeLine(loc + country.getPosition("primary_culture="), "\t\tprimary_culture=" + cultures[0]);
            foreach (int i in acceptedCultureLocs)
            {
                reader.removeLine(loc + i);
            }
            int j = 1;

            while (j < cultures.Count)
            {
                reader.addLine("\t\taccepted_culture=" + cultures[j], loc + country.getPosition("primary_culture=") + 1);
                j++;
            }
            reader.changeLine(loc + country.getPosition("religion="), "\t\treligion=" + religion);
            reader.changeLine(loc + country.getPosition("government="), "\t\tgovernment=" + government);

            int warExPos = country.getPosition("war_exhaustion=");

            if (warExPos != -1)
            {
                reader.changeLine(loc + warExPos, "\t\twar_exhaustion=" + warExhaustion);
            }
            else
            {
                reader.addLine("\t\twar_exhaustion=" + warExhaustion, loc + country.getPosition("last_bankrupt="));
            }

            if (vassalTag != "" && vassalTag != null)
            {
                if (vassalLabel.Text != "none")
                {
                    reader.goTo(vassalLoc);
                    textBlock vassal = new textBlock('{', '}', reader);
                    reader.changeLine(vassalLoc + vassal.getPosition("first="), "\t\tfirst=\"" + vassalTag + "\"");
                }
                else
                {
                    reader.addLine("\tvassal=", vassalLoc);
                    reader.addLine("\t{", vassalLoc + 1);
                    reader.addLine("\t\tfirst=\"" + vassalTag + "\"", vassalLoc + 2);
                    reader.addLine("\t\tsecond=\"" + countryTag + "\"", vassalLoc + 3);
                    reader.addLine("\t\tend_date=1.1.1", vassalLoc + 4);
                    reader.addLine("\t\tcancel=no", vassalLoc + 5);
                    reader.addLine("\t\tstart_date=1.1.1", vassalLoc + 6);
                    reader.addLine("\t}", vassalLoc + 7);
                }
            }

            this.Close();
        }