/// <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> /// 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"); }
/// <summary> /// On clicking on a monarch, launch a monarchEditForm to edit the monarch, then apply the relevant changes /// </summary> private void monarchBox_MouseDoubleClick_1(object sender, MouseEventArgs e) { textBlock monarch = monarchBlocks[monarchBox.SelectedIndex]; monarchEditForm monarchEdit = new monarchEditForm(monarch); monarchEdit.ShowDialog(); int baseLocMon = historyLoc + monarchs[monarchs.Length - 1 - monarchBox.SelectedIndex]; textBlock heir = new textBlock(); reader.changeLine(baseLocMon + monarch.getPosition("name="), "\t\t\t\t\tname=\"" + monarchEdit.name + "\""); reader.changeLine(baseLocMon + monarch.getPosition("DIP="), "\t\t\t\t\tDIP=" + monarchEdit.dip); reader.changeLine(baseLocMon + monarch.getPosition("ADM="), "\t\t\t\t\tADM=" + monarchEdit.adm); reader.changeLine(baseLocMon + monarch.getPosition("MIL="), "\t\t\t\t\tMIL=" + monarchEdit.mil); //reader.changeLine(baseLocMon + monarch.getPosition("dynasty="), "\t\t\t\t\tdynasty=\"" + monarchEdit.dynasty+"\""); //reader.changeLine(baseLocMon + monarch.getPosition("birth_date="), "\t\t\t\t\tbirth_date=" + monarchEdit.birthDate); if (repeatHeirs.Contains(monarchBox.SelectedIndex)) { int baseLocHeir = historyLoc + heirs[heirs.Length - 1 - repeatHeirs.IndexOf(monarchBox.SelectedIndex)]; heir = heirBlocks[repeatHeirs.IndexOf(monarchBox.SelectedIndex)]; reader.changeLine(baseLocHeir + heir.getPosition("name="), "\t\t\t\t\tname=\"" + monarchEdit.name + "\""); reader.changeLine(baseLocHeir + heir.getPosition("DIP="), "\t\t\t\t\tDIP=" + monarchEdit.dip); reader.changeLine(baseLocHeir + heir.getPosition("ADM="), "\t\t\t\t\tADM=" + monarchEdit.adm); reader.changeLine(baseLocHeir + heir.getPosition("MIL="), "\t\t\t\t\tMIL=" + monarchEdit.mil); //reader.changeLine(baseLocHeir + heir.getPosition("dynasty="), "\t\t\t\t\tdynasty=\"" + monarchEdit.dynasty + "\""); //reader.changeLine(baseLocHeir + heir.getPosition("birth_date="), "\t\t\t\t\tbirth_date=" + monarchEdit.birthDate); } initialize(); }
/// <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(); }
/// <summary> /// Applies any changes based on user input /// </summary> private void onDoneButton(object sender, EventArgs e) { //change tech levels and units appropriately admLevel = admBox.Text; dipLevel = dipBox.Text; milLevel = milBox.Text; if (admLevel != "") { reader.changeLine(loc + techLoc + 2, "\t\t\tadm_tech=" + admLevel); } if (dipLevel != "") { int dipInt = Convert.ToInt32(dipLevel); reader.changeLine(loc + techLoc + 3, "\t\t\tdip_tech=" + dipLevel); int heavyPos = country.getPosition("heavy_ship="); if (dipInt >= 3 && heavyPos == -1) { reader.addLine("\t\theavy_ship=\"early_carrack\"", loc + country.getPosition("cavalry=") + 1); } if (dipInt < 3 && heavyPos != -1) { reader.deleteLine(loc + heavyPos); } int lightPos = country.getPosition("light_ship="); if (dipInt >= 2 && lightPos == -1) { reader.addLine("\t\tlight_ship=\"barque\"", loc + country.getPosition("cavalry=") + 1); } if (dipInt < 2 && lightPos != -1) { reader.deleteLine(loc + lightPos); } int galleyPos = country.getPosition("galley="); if (dipInt >= 2 && galleyPos == -1) { reader.addLine("\t\tgalley=\"galley\"", loc + lightPos + 1); } if (dipInt < 2 && galleyPos != -1) { reader.deleteLine(loc + galleyPos); } int transPos = country.getPosition("transport="); if (dipInt >= 2 && transPos == -1) { reader.addLine("\t\ttransport=\"cog\"", loc + galleyPos + 1); } if (dipInt < 2 && transPos != -1) { reader.deleteLine(loc + transPos); } heavyPos = loc + country.getPosition("heavy_ship="); lightPos = loc + country.getPosition("light_ship="); galleyPos = loc + country.getPosition("galley="); transPos = loc + country.getPosition("transport="); if (dipInt >= 2) { reader.changeLine(lightPos, "\t\tlight_ship=\"barque\""); reader.changeLine(galleyPos, "\t\tgalley=\"galley\""); reader.changeLine(transPos, "\t\ttransport=\"cog\""); } if (dipInt >= 3) { reader.changeLine(heavyPos, "\t\theavy_ship=\"early_carrack\""); } if (dipInt >= 9) { reader.changeLine(heavyPos, "\t\theavy_ship=\"carrack\""); reader.changeLine(lightPos, "\t\tlight_ship=\"caravel\""); } if (dipInt >= 10) { reader.changeLine(galleyPos, "\t\tgalley=\"war_galley\""); reader.changeLine(transPos, "\t\ttransport=\"flute\""); } if (dipInt >= 14) { reader.changeLine(galleyPos, "\t\tgalley=\"galleass\""); reader.changeLine(transPos, "\t\ttransport=\"brig\""); } if (dipInt >= 15) { reader.changeLine(heavyPos, "\t\theavy_ship=\"galleon\""); reader.changeLine(lightPos, "\t\tlight_ship=\"early_frigate\""); } if (dipInt >= 17) { reader.changeLine(galleyPos, "\t\tgalley=\"galiot\""); reader.changeLine(transPos, "\t\ttransport=\"merchantman\""); } if (dipInt >= 19) { reader.changeLine(heavyPos, "\t\theavy_ship=\"wargalleon\""); reader.changeLine(lightPos, "\t\tlight_ship=\"frigate\""); } if (dipInt >= 21) { reader.changeLine(galleyPos, "\t\tgalley=\"chebeck\""); } if (dipInt >= 22) { reader.changeLine(heavyPos, "\t\theavy_ship=\"twodecker\""); reader.changeLine(transPos, "\t\ttransport=\"trabakul\""); } if (dipInt >= 23) { reader.changeLine(lightPos, "\t\tlight_ship=\"heavy_frigate\""); } if (dipInt >= 24) { reader.changeLine(galleyPos, "\t\tgalley=\"archipelago_frigate\""); } if (dipInt >= 25) { reader.changeLine(heavyPos, "\t\theavy_ship=\"threedecker\""); } if (dipInt >= 26) { reader.changeLine(transPos, "\t\ttransport=\"eastindiaman\""); reader.changeLine(lightPos, "\t\tlight_ship=\"great_frigate\""); } } if (milLevel != "") { reader.changeLine(loc + techLoc + 4, "\t\t\tmil_tech=" + milLevel); int artPos = country.getPosition("artillery="); if (Convert.ToInt32(milLevel) > 6 && artPos == -1) { reader.addLine("\t\tartillery=\"houfnice\"", loc + country.getPosition("cavalry=") + 1); } if (Convert.ToInt32(milLevel) < 7 && artPos != -1) { reader.deleteLine(loc + artPos); } } this.Close(); }