From fd1add3d313aadcda639aa13ddf43d0a6874c95c Mon Sep 17 00:00:00 2001 From: "calebschwalb@gmail.com" Date: Tue, 7 Apr 2020 09:17:55 -0500 Subject: [PATCH] Financial additions of new data types and the start of Gangs --- AboutBox.Designer.cs | 3 +- FileModel/Finance.cs | 11 +- FileModel/Gangs.cs | 42 ++ FileModel/PrisonerBio.cs | 11 + MainForm.Designer.cs | 181 +++++-- MainForm.cs | 1017 ++++++++++++++++++++------------------ PASaveEditor.csproj | 1 + Parser.cs | 2 +- PrisonerUtil.cs | 3 +- Program.cs | 2 +- 10 files changed, 745 insertions(+), 528 deletions(-) create mode 100644 FileModel/Gangs.cs diff --git a/AboutBox.Designer.cs b/AboutBox.Designer.cs index e288424..9d0f01d 100644 --- a/AboutBox.Designer.cs +++ b/AboutBox.Designer.cs @@ -36,8 +36,7 @@ private void InitializeComponent() { this.richTextBox1.ReadOnly = true; this.richTextBox1.Size = new System.Drawing.Size(258, 104); this.richTextBox1.TabIndex = 0; - this.richTextBox1.Text = "PASaveEditor {0}\nby Matvei Stefarov\nfor Prison Architect {1}\n\nhttps://github.com/" + - "fragmer/PASaveEditor"; + this.richTextBox1.Text = "PSAE DEVELOPMENT V1.0 by Crypto."; this.richTextBox1.LinkClicked += new System.Windows.Forms.LinkClickedEventHandler(this.richTextBox1_LinkClicked); // // bClose diff --git a/FileModel/Finance.cs b/FileModel/Finance.cs index c23a992..a418a50 100644 --- a/FileModel/Finance.cs +++ b/FileModel/Finance.cs @@ -8,7 +8,8 @@ internal class Finance : Node { public int BankLoan; public double BankCreditRating; public int Ownership; - + public double WardensCut; + public double DailyShopRevenue; public Finance() : base("Finance") {} @@ -34,6 +35,12 @@ public override void ReadKey(string key, string value) { case "Ownership": Ownership = Int32.Parse(value); break; + case "WardensCut": + WardensCut = double.Parse(value); + break; + case "DailyShopRevenue": + DailyShopRevenue = double.Parse(value); + break; default: base.ReadKey(key, value); break; @@ -48,6 +55,8 @@ public override void WriteProperties(Writer writer) { writer.WriteProperty("BankLoan", BankLoan); writer.WriteProperty("BankCreditRating", BankCreditRating); writer.WriteProperty("Ownership", Ownership); + writer.WriteProperty("WardensCut", WardensCut); + writer.WriteProperty("DailyShopRevenue", DailyShopRevenue); } } } diff --git a/FileModel/Gangs.cs b/FileModel/Gangs.cs new file mode 100644 index 0000000..27e325f --- /dev/null +++ b/FileModel/Gangs.cs @@ -0,0 +1,42 @@ +using System; + +namespace PASaveEditor.FileModel +{ + internal class Gang : Node + { + public int gangId; + public String gangRank; + public double recruitment; + + public Gang(string label) + : base(label) { } + + + public override void ReadKey(string key, string value) + { + switch (key) + { + case "Gang.Id": + gangId = Int32.Parse(value); + break; + case "Gang.Rank": + gangRank = value; + break; + case "Gang.Recruitment": + recruitment = Double.Parse(value); + break; + default: + base.ReadKey(key, value); + break; + } + } + + + public override void WriteProperties(Writer writer) + { + writer.WriteProperty("Prisoner.i", gangId); + writer.WriteProperty("Coverage", gangRank); + writer.WriteProperty("Suspicion", recruitment); + } + } +} diff --git a/FileModel/PrisonerBio.cs b/FileModel/PrisonerBio.cs index 0082e2f..ea2be01 100644 --- a/FileModel/PrisonerBio.cs +++ b/FileModel/PrisonerBio.cs @@ -9,6 +9,9 @@ internal class PrisonerBio : Node { public int Nitg; public List Reputations; public bool ReputationRevealed; + public double Age; + public int BodyType; + public List Traits; // might use this later TODO public PrisonerBio(string label) @@ -41,6 +44,12 @@ public override void ReadKey(string key, string value) { case "ReputationRevealed": ReputationRevealed = Boolean.Parse(value); break; + case "Age": + Age = Double.Parse(value); + break; + case "BodyType": + BodyType = Int32.Parse(value); + break; default: base.ReadKey(key, value); break; @@ -60,6 +69,8 @@ public override void WriteProperties(Writer writer) { } writer.WriteProperty("ReputationRevealed", ReputationRevealed); } + writer.WriteProperty("Age", Age); + writer.WriteProperty("BodyType", BodyType); } } } diff --git a/MainForm.Designer.cs b/MainForm.Designer.cs index 05caaed..0e767b3 100644 --- a/MainForm.Designer.cs +++ b/MainForm.Designer.cs @@ -53,12 +53,18 @@ private void InitializeComponent() { this.lDay = new System.Windows.Forms.Label(); this.lTime = new System.Windows.Forms.Label(); this.tpFinance = new System.Windows.Forms.TabPage(); + this.button1 = new System.Windows.Forms.Button(); this.nOwnership = new System.Windows.Forms.NumericUpDown(); this.xUnlimitedFunds = new System.Windows.Forms.CheckBox(); this.nBankLoanAmount = new System.Windows.Forms.NumericUpDown(); this.nCreditRating = new System.Windows.Forms.NumericUpDown(); this.nBalance = new System.Windows.Forms.NumericUpDown(); this.tpPrisoners = new System.Windows.Forms.TabPage(); + this.m_BodyType = new System.Windows.Forms.TextBox(); + this.m_Age = new System.Windows.Forms.TextBox(); + this.label2 = new System.Windows.Forms.Label(); + this.label1 = new System.Windows.Forms.Label(); + this.moveToPercentage = new System.Windows.Forms.Button(); this.bRelease = new System.Windows.Forms.Button(); this.lServedStats = new System.Windows.Forms.Label(); this.lServed = new System.Windows.Forms.Label(); @@ -71,6 +77,7 @@ private void InitializeComponent() { this.lbPrisoners = new System.Windows.Forms.ListBox(); this.tpResearch = new System.Windows.Forms.TabPage(); this.clbResearch = new System.Windows.Forms.CheckedListBox(); + this.Gang = new System.Windows.Forms.TabPage(); this.menu = new System.Windows.Forms.MenuStrip(); this.miFile = new System.Windows.Forms.ToolStripMenuItem(); this.miFileOpen = new System.Windows.Forms.ToolStripMenuItem(); @@ -79,18 +86,22 @@ private void InitializeComponent() { this.miExit = new System.Windows.Forms.ToolStripMenuItem(); this.miShortcuts = new System.Windows.Forms.ToolStripMenuItem(); this.miReleasePrisoners = new System.Windows.Forms.ToolStripMenuItem(); + this.miReleaseInsane = new System.Windows.Forms.ToolStripMenuItem(); this.miReleaseProtected = new System.Windows.Forms.ToolStripMenuItem(); this.miReleaseMinSec = new System.Windows.Forms.ToolStripMenuItem(); this.miReleaseNormal = new System.Windows.Forms.ToolStripMenuItem(); this.miReleaseMaxSec = new System.Windows.Forms.ToolStripMenuItem(); this.miReleaseSuperMax = new System.Windows.Forms.ToolStripMenuItem(); + this.miReleaseDeathRow = new System.Windows.Forms.ToolStripMenuItem(); this.miReleaseAll = new System.Windows.Forms.ToolStripMenuItem(); this.miEliminatePrisoners = new System.Windows.Forms.ToolStripMenuItem(); + this.miEliminateInsane = new System.Windows.Forms.ToolStripMenuItem(); this.miEliminateProtected = new System.Windows.Forms.ToolStripMenuItem(); this.miEliminateMinSec = new System.Windows.Forms.ToolStripMenuItem(); this.miEliminateNormal = new System.Windows.Forms.ToolStripMenuItem(); this.miEliminateMaxSec = new System.Windows.Forms.ToolStripMenuItem(); this.miEliminateSuperMax = new System.Windows.Forms.ToolStripMenuItem(); + this.miEliminateDeathRow = new System.Windows.Forms.ToolStripMenuItem(); this.sEliminatePrisonersSeparator = new System.Windows.Forms.ToolStripSeparator(); this.miEliminateAll = new System.Windows.Forms.ToolStripMenuItem(); this.miRevealReputations = new System.Windows.Forms.ToolStripMenuItem(); @@ -100,8 +111,7 @@ private void InitializeComponent() { this.miRemoveAllContraband = new System.Windows.Forms.ToolStripMenuItem(); this.miHelp = new System.Windows.Forms.ToolStripMenuItem(); this.miAbout = new System.Windows.Forms.ToolStripMenuItem(); - this.miReleaseDeathRow = new System.Windows.Forms.ToolStripMenuItem(); - this.miEliminateDeathRow = new System.Windows.Forms.ToolStripMenuItem(); + this.button2 = new System.Windows.Forms.Button(); lOwnershipUnits = new System.Windows.Forms.Label(); lBankLoanAmontUnits = new System.Windows.Forms.Label(); lBankLoanAmount = new System.Windows.Forms.Label(); @@ -129,6 +139,7 @@ private void InitializeComponent() { ((System.ComponentModel.ISupportInitialize)(this.nBalance)).BeginInit(); this.tpPrisoners.SuspendLayout(); this.tpResearch.SuspendLayout(); + this.Gang.SuspendLayout(); this.menu.SuspendLayout(); this.SuspendLayout(); // @@ -235,12 +246,12 @@ private void InitializeComponent() { lDisclaimer.AutoSize = true; lDisclaimer.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); lDisclaimer.ForeColor = System.Drawing.SystemColors.MenuHighlight; - lDisclaimer.Location = new System.Drawing.Point(8, 152); + lDisclaimer.Location = new System.Drawing.Point(28, 248); lDisclaimer.Name = "lDisclaimer"; - lDisclaimer.Size = new System.Drawing.Size(384, 48); + lDisclaimer.Size = new System.Drawing.Size(363, 48); lDisclaimer.TabIndex = 9; lDisclaimer.Text = "This tool is still in development. It\'s probably buggy\r\nand may corrupt your save" + - "s. Don\'t overwrite any\r\nexisting savegames unless you are feeling very brave."; + "s. Don\'t overwrite any\r\nexisting saves."; // // sFileSeparator1 // @@ -263,6 +274,7 @@ private void InitializeComponent() { this.tabs.Controls.Add(this.tpFinance); this.tabs.Controls.Add(this.tpPrisoners); this.tabs.Controls.Add(this.tpResearch); + this.tabs.Controls.Add(this.Gang); this.tabs.Dock = System.Windows.Forms.DockStyle.Fill; this.tabs.Location = new System.Drawing.Point(0, 24); this.tabs.Name = "tabs"; @@ -275,6 +287,7 @@ private void InitializeComponent() { this.tpGeneral.Controls.Add(lDisclaimer); this.tpGeneral.Controls.Add(this.groupBox2); this.tpGeneral.Controls.Add(this.groupBox1); + this.tpGeneral.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.tpGeneral.Location = new System.Drawing.Point(4, 22); this.tpGeneral.Name = "tpGeneral"; this.tpGeneral.Size = new System.Drawing.Size(426, 312); @@ -293,7 +306,7 @@ private void InitializeComponent() { this.groupBox2.Controls.Add(this.xContinuousIntake); this.groupBox2.Location = new System.Drawing.Point(8, 3); this.groupBox2.Name = "groupBox2"; - this.groupBox2.Size = new System.Drawing.Size(202, 143); + this.groupBox2.Size = new System.Drawing.Size(202, 198); this.groupBox2.TabIndex = 8; this.groupBox2.TabStop = false; this.groupBox2.Text = "Prison Settings"; @@ -303,7 +316,7 @@ private void InitializeComponent() { this.xDecay.AutoSize = true; this.xDecay.Location = new System.Drawing.Point(23, 111); this.xDecay.Name = "xDecay"; - this.xDecay.Size = new System.Drawing.Size(57, 17); + this.xDecay.Size = new System.Drawing.Size(62, 17); this.xDecay.TabIndex = 4; this.xDecay.Text = "Decay"; this.xDecay.UseVisualStyleBackColor = true; @@ -313,7 +326,7 @@ private void InitializeComponent() { this.xMisconduct.AutoSize = true; this.xMisconduct.Location = new System.Drawing.Point(23, 88); this.xMisconduct.Name = "xMisconduct"; - this.xMisconduct.Size = new System.Drawing.Size(81, 17); + this.xMisconduct.Size = new System.Drawing.Size(91, 17); this.xMisconduct.TabIndex = 3; this.xMisconduct.Text = "Misconduct"; this.xMisconduct.UseVisualStyleBackColor = true; @@ -323,7 +336,7 @@ private void InitializeComponent() { this.xFogOfWar.AutoSize = true; this.xFogOfWar.Location = new System.Drawing.Point(23, 65); this.xFogOfWar.Name = "xFogOfWar"; - this.xFogOfWar.Size = new System.Drawing.Size(76, 17); + this.xFogOfWar.Size = new System.Drawing.Size(86, 17); this.xFogOfWar.TabIndex = 2; this.xFogOfWar.Text = "Fog of war"; this.xFogOfWar.UseVisualStyleBackColor = true; @@ -333,7 +346,7 @@ private void InitializeComponent() { this.xFailureConditions.AutoSize = true; this.xFailureConditions.Location = new System.Drawing.Point(23, 42); this.xFailureConditions.Name = "xFailureConditions"; - this.xFailureConditions.Size = new System.Drawing.Size(108, 17); + this.xFailureConditions.Size = new System.Drawing.Size(126, 17); this.xFailureConditions.TabIndex = 1; this.xFailureConditions.Text = "Failure conditions"; this.xFailureConditions.UseVisualStyleBackColor = true; @@ -343,7 +356,7 @@ private void InitializeComponent() { this.xContinuousIntake.AutoSize = true; this.xContinuousIntake.Location = new System.Drawing.Point(23, 19); this.xContinuousIntake.Name = "xContinuousIntake"; - this.xContinuousIntake.Size = new System.Drawing.Size(111, 17); + this.xContinuousIntake.Size = new System.Drawing.Size(128, 17); this.xContinuousIntake.TabIndex = 0; this.xContinuousIntake.Text = "Continuous intake"; this.xContinuousIntake.UseVisualStyleBackColor = true; @@ -407,7 +420,7 @@ private void InitializeComponent() { this.lDay.AutoSize = true; this.lDay.Location = new System.Drawing.Point(20, 29); this.lDay.Name = "lDay"; - this.lDay.Size = new System.Drawing.Size(26, 13); + this.lDay.Size = new System.Drawing.Size(29, 13); this.lDay.TabIndex = 0; this.lDay.Text = "Day"; // @@ -416,12 +429,13 @@ private void InitializeComponent() { this.lTime.AutoSize = true; this.lTime.Location = new System.Drawing.Point(16, 56); this.lTime.Name = "lTime"; - this.lTime.Size = new System.Drawing.Size(30, 13); + this.lTime.Size = new System.Drawing.Size(34, 13); this.lTime.TabIndex = 1; this.lTime.Text = "Time"; // // tpFinance // + this.tpFinance.Controls.Add(this.button1); this.tpFinance.Controls.Add(lOwnershipUnits); this.tpFinance.Controls.Add(this.nOwnership); this.tpFinance.Controls.Add(this.xUnlimitedFunds); @@ -442,6 +456,15 @@ private void InitializeComponent() { this.tpFinance.Text = "Finance"; this.tpFinance.UseVisualStyleBackColor = true; // + // button1 + // + this.button1.Location = new System.Drawing.Point(33, 154); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(70, 23); + this.button1.TabIndex = 16; + this.button1.Text = "Count Insane number"; + this.button1.UseVisualStyleBackColor = true; + // // nOwnership // this.nOwnership.Location = new System.Drawing.Point(110, 119); @@ -476,6 +499,7 @@ private void InitializeComponent() { this.nBankLoanAmount.Name = "nBankLoanAmount"; this.nBankLoanAmount.Size = new System.Drawing.Size(75, 20); this.nBankLoanAmount.TabIndex = 12; + this.nBankLoanAmount.ValueChanged += new System.EventHandler(this.nBankLoanAmount_ValueChanged); // // nCreditRating // @@ -513,6 +537,11 @@ private void InitializeComponent() { // // tpPrisoners // + this.tpPrisoners.Controls.Add(this.m_BodyType); + this.tpPrisoners.Controls.Add(this.m_Age); + this.tpPrisoners.Controls.Add(this.label2); + this.tpPrisoners.Controls.Add(this.label1); + this.tpPrisoners.Controls.Add(this.moveToPercentage); this.tpPrisoners.Controls.Add(this.bRelease); this.tpPrisoners.Controls.Add(this.lServedStats); this.tpPrisoners.Controls.Add(this.lServed); @@ -532,12 +561,55 @@ private void InitializeComponent() { this.tpPrisoners.TabIndex = 2; this.tpPrisoners.Text = "Prisoners"; this.tpPrisoners.UseVisualStyleBackColor = true; + this.tpPrisoners.Click += new System.EventHandler(this.tpPrisoners_Click); + // + // m_BodyType + // + this.m_BodyType.Location = new System.Drawing.Point(221, 186); + this.m_BodyType.Name = "m_BodyType"; + this.m_BodyType.Size = new System.Drawing.Size(100, 20); + this.m_BodyType.TabIndex = 17; + // + // m_Age + // + this.m_Age.Location = new System.Drawing.Point(221, 162); + this.m_Age.Name = "m_Age"; + this.m_Age.Size = new System.Drawing.Size(100, 20); + this.m_Age.TabIndex = 16; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(143, 193); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(58, 13); + this.label2.TabIndex = 15; + this.label2.Text = "Body Type"; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(143, 169); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(26, 13); + this.label1.TabIndex = 14; + this.label1.Text = "Age"; + // + // moveToPercentage + // + this.moveToPercentage.Location = new System.Drawing.Point(266, 137); + this.moveToPercentage.Name = "moveToPercentage"; + this.moveToPercentage.Size = new System.Drawing.Size(58, 23); + this.moveToPercentage.TabIndex = 13; + this.moveToPercentage.Text = "Bond Out!"; + this.moveToPercentage.UseVisualStyleBackColor = true; + this.moveToPercentage.Click += new System.EventHandler(this.moveToPercentage_Click); // // bRelease // - this.bRelease.Location = new System.Drawing.Point(198, 137); + this.bRelease.Location = new System.Drawing.Point(206, 137); this.bRelease.Name = "bRelease"; - this.bRelease.Size = new System.Drawing.Size(75, 23); + this.bRelease.Size = new System.Drawing.Size(58, 23); this.bRelease.TabIndex = 12; this.bRelease.Text = "Release"; this.bRelease.UseVisualStyleBackColor = true; @@ -580,7 +652,8 @@ private void InitializeComponent() { "Normal Security", "Maximum Security", "SuperMax", - "Death Row"}); + "Death Row", + "Insane"}); this.cCategory.Location = new System.Drawing.Point(198, 81); this.cCategory.Name = "cCategory"; this.cCategory.Size = new System.Drawing.Size(121, 21); @@ -605,9 +678,9 @@ private void InitializeComponent() { // // bEliminate // - this.bEliminate.Location = new System.Drawing.Point(198, 166); + this.bEliminate.Location = new System.Drawing.Point(146, 137); this.bEliminate.Name = "bEliminate"; - this.bEliminate.Size = new System.Drawing.Size(75, 23); + this.bEliminate.Size = new System.Drawing.Size(58, 23); this.bEliminate.TabIndex = 2; this.bEliminate.Text = "Eliminate"; this.bEliminate.UseVisualStyleBackColor = true; @@ -652,6 +725,17 @@ private void InitializeComponent() { this.clbResearch.Size = new System.Drawing.Size(426, 312); this.clbResearch.TabIndex = 0; // + // Gang + // + this.Gang.BackColor = System.Drawing.Color.DimGray; + this.Gang.Controls.Add(this.button2); + this.Gang.Location = new System.Drawing.Point(4, 22); + this.Gang.Name = "Gang"; + this.Gang.Padding = new System.Windows.Forms.Padding(3); + this.Gang.Size = new System.Drawing.Size(426, 312); + this.Gang.TabIndex = 6; + this.Gang.Text = "Gang Activity"; + // // menu // this.menu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { @@ -722,6 +806,7 @@ private void InitializeComponent() { // miReleasePrisoners // this.miReleasePrisoners.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.miReleaseInsane, this.miReleaseProtected, this.miReleaseMinSec, this.miReleaseNormal, @@ -734,6 +819,12 @@ private void InitializeComponent() { this.miReleasePrisoners.Size = new System.Drawing.Size(196, 22); this.miReleasePrisoners.Text = "Release prisoners"; // + // miReleaseInsane + // + this.miReleaseInsane.Name = "miReleaseInsane"; + this.miReleaseInsane.Size = new System.Drawing.Size(174, 22); + this.miReleaseInsane.Text = "Release Insane"; + // // miReleaseProtected // this.miReleaseProtected.Name = "miReleaseProtected"; @@ -764,6 +855,12 @@ private void InitializeComponent() { this.miReleaseSuperMax.Size = new System.Drawing.Size(174, 22); this.miReleaseSuperMax.Text = "SuperMax"; // + // miReleaseDeathRow + // + this.miReleaseDeathRow.Name = "miReleaseDeathRow"; + this.miReleaseDeathRow.Size = new System.Drawing.Size(174, 22); + this.miReleaseDeathRow.Text = "Death Row"; + // // miReleaseAll // this.miReleaseAll.Name = "miReleaseAll"; @@ -773,6 +870,7 @@ private void InitializeComponent() { // miEliminatePrisoners // this.miEliminatePrisoners.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.miEliminateInsane, this.miEliminateProtected, this.miEliminateMinSec, this.miEliminateNormal, @@ -785,6 +883,12 @@ private void InitializeComponent() { this.miEliminatePrisoners.Size = new System.Drawing.Size(196, 22); this.miEliminatePrisoners.Text = "Eliminate prisoners"; // + // miEliminateInsane + // + this.miEliminateInsane.Name = "miEliminateInsane"; + this.miEliminateInsane.Size = new System.Drawing.Size(174, 22); + this.miEliminateInsane.Text = "Insane"; + // // miEliminateProtected // this.miEliminateProtected.Name = "miEliminateProtected"; @@ -815,6 +919,12 @@ private void InitializeComponent() { this.miEliminateSuperMax.Size = new System.Drawing.Size(174, 22); this.miEliminateSuperMax.Text = "SuperMax"; // + // miEliminateDeathRow + // + this.miEliminateDeathRow.Name = "miEliminateDeathRow"; + this.miEliminateDeathRow.Size = new System.Drawing.Size(174, 22); + this.miEliminateDeathRow.Text = "Death Row"; + // // sEliminatePrisonersSeparator // this.sEliminatePrisonersSeparator.Name = "sEliminatePrisonersSeparator"; @@ -876,28 +986,28 @@ private void InitializeComponent() { this.miAbout.Text = "About"; this.miAbout.Click += new System.EventHandler(this.miAbout_Click); // - // miReleaseDeathRow - // - this.miReleaseDeathRow.Name = "miReleaseDeathRow"; - this.miReleaseDeathRow.Size = new System.Drawing.Size(174, 22); - this.miReleaseDeathRow.Text = "Death Row"; + // button2 // - // miEliminateDeathRow - // - this.miEliminateDeathRow.Name = "miEliminateDeathRow"; - this.miEliminateDeathRow.Size = new System.Drawing.Size(174, 22); - this.miEliminateDeathRow.Text = "Death Row"; + this.button2.Location = new System.Drawing.Point(54, 45); + this.button2.Name = "button2"; + this.button2.Size = new System.Drawing.Size(75, 23); + this.button2.TabIndex = 0; + this.button2.Text = "GetGangMember"; + this.button2.UseVisualStyleBackColor = true; + this.button2.Click += new System.EventHandler(this.button2_Click); // // MainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.BackColor = System.Drawing.SystemColors.ActiveCaption; this.ClientSize = new System.Drawing.Size(434, 362); this.Controls.Add(this.tabs); this.Controls.Add(this.menu); + this.ForeColor = System.Drawing.SystemColors.HotTrack; this.MainMenuStrip = this.menu; this.Name = "MainForm"; - this.Text = "Prison Architect Save Editor"; + this.Text = "PSAE by Crypto"; this.tabs.ResumeLayout(false); this.tpGeneral.ResumeLayout(false); this.tpGeneral.PerformLayout(); @@ -915,6 +1025,7 @@ private void InitializeComponent() { this.tpPrisoners.ResumeLayout(false); this.tpPrisoners.PerformLayout(); this.tpResearch.ResumeLayout(false); + this.Gang.ResumeLayout(false); this.menu.ResumeLayout(false); this.menu.PerformLayout(); this.ResumeLayout(false); @@ -987,7 +1098,17 @@ private void InitializeComponent() { private System.Windows.Forms.ToolStripMenuItem miHelp; private System.Windows.Forms.ToolStripMenuItem miAbout; private System.Windows.Forms.ToolStripMenuItem miReleaseDeathRow; - private System.Windows.Forms.ToolStripMenuItem miEliminateDeathRow; + private System.Windows.Forms.ToolStripMenuItem miEliminateDeathRow; + private System.Windows.Forms.TabPage Gang; + private System.Windows.Forms.ToolStripMenuItem miEliminateInsane; + private System.Windows.Forms.Button moveToPercentage; + private System.Windows.Forms.Button button1; + private System.Windows.Forms.TextBox m_BodyType; + private System.Windows.Forms.TextBox m_Age; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.ToolStripMenuItem miReleaseInsane; + private System.Windows.Forms.Button button2; } } diff --git a/MainForm.cs b/MainForm.cs index a2685e3..0de7d39 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -1,495 +1,528 @@ -using System; -using System.Globalization; -using System.IO; -using System.Linq; -using System.Windows.Forms; -using PASaveEditor.FileModel; -using PASaveEditor.Properties; - -namespace PASaveEditor { - public partial class MainForm : Form { - const string FileFilter = "Prison Architect saves (*.prison)|*.prison|All Files (*.*)|*.*"; - const string AppName = "Prison Architect Save Editor | " + Parser.SupportedVersion; - string fileName; - Prison prison; - string[] prisonerNames; - Prisoner selectedPrisoner; - - readonly OpenFileDialog openDialog; - readonly SaveFileDialog saveAsDialog; - readonly ToolTip toolTips; - - - public MainForm() { - InitializeComponent(); - toolTips = new ToolTip(); - tPrisonerSearch.SetWatermark("Search"); - - AssignTooltips(); - - string paSavePath = Path.Combine( - Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), - "Introversion", "Prison Architect", "saves"); - - openDialog = new OpenFileDialog { - Filter = FileFilter, - InitialDirectory = paSavePath - }; - saveAsDialog = new SaveFileDialog { - Filter = FileFilter, - InitialDirectory = paSavePath - }; - - miEliminateProtected.Click += delegate { Eliminate("Protected"); }; - miEliminateMinSec.Click += delegate { Eliminate("MinSec"); }; - miEliminateNormal.Click += delegate { Eliminate("Normal"); }; - miEliminateMaxSec.Click += delegate { Eliminate("MaxSec"); }; +using System; +using System.Globalization; +using System.IO; +using System.Linq; +using System.Windows.Forms; +using PASaveEditor.FileModel; +using PASaveEditor.Properties; + +namespace PASaveEditor { + public partial class MainForm : Form { + const string FileFilter = "Prison Architect saves (*.prison)|*.prison|All Files (*.*)|*.*"; + const string AppName = "Prison Architect Save Editor | " + Parser.SupportedVersion; + string fileName; + Prison prison; + string[] prisonerNames; + Prisoner selectedPrisoner; + + readonly OpenFileDialog openDialog; + readonly SaveFileDialog saveAsDialog; + readonly ToolTip toolTips; + + + public MainForm() { + InitializeComponent(); + toolTips = new ToolTip(); + tPrisonerSearch.SetWatermark("Search"); + + AssignTooltips(); + + string paSavePath = Path.Combine( + Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), + "Introversion", "Prison Architect", "saves"); + + openDialog = new OpenFileDialog { + Filter = FileFilter, + InitialDirectory = paSavePath + }; + saveAsDialog = new SaveFileDialog { + Filter = FileFilter, + InitialDirectory = paSavePath + }; + + miEliminateProtected.Click += delegate { Eliminate("Protected"); }; + miEliminateMinSec.Click += delegate { Eliminate("MinSec"); }; + miEliminateNormal.Click += delegate { Eliminate("Normal"); }; + miEliminateMaxSec.Click += delegate { Eliminate("MaxSec"); }; miEliminateSuperMax.Click += delegate { Eliminate("SuperMax"); }; - miEliminateDeathRow.Click += delegate { Eliminate("DeathRow"); }; - miEliminateAll.Click += delegate { EliminateAll(); }; - - miReleaseProtected.Click += delegate { Release("Protected"); }; - miReleaseMinSec.Click += delegate { Release("MinSec"); }; - miReleaseNormal.Click += delegate { Release("Normal"); }; - miReleaseMaxSec.Click += delegate { Release("MaxSec"); }; + miEliminateDeathRow.Click += delegate { Eliminate("DeathRow"); }; + miEliminateAll.Click += delegate { EliminateAll(); }; + + miReleaseProtected.Click += delegate { Release("Protected"); }; + miReleaseMinSec.Click += delegate { Release("MinSec"); }; + miReleaseNormal.Click += delegate { Release("Normal"); }; + miReleaseMaxSec.Click += delegate { Release("MaxSec"); }; miReleaseSuperMax.Click += delegate { Release("SuperMax"); }; - miReleaseDeathRow.Click += delegate { Release("DeathRow"); }; - miReleaseAll.Click += delegate { ReleaseAll(); }; - - miExit.Click += delegate { Close(); }; - - Shown += delegate { miFileOpen.PerformClick(); }; - - // Disable the GUI until a prison file is loaded - Enabled = false; - } - - - void AssignTooltips() { - toolTips.SetToolTip(xContinuousIntake, Resources.TipContinuousIntake); - toolTips.SetToolTip(xDecay, Resources.TipDecay); - toolTips.SetToolTip(xFailureConditions, Resources.TipFailureConditions); - toolTips.SetToolTip(xFogOfWar, Resources.TipFogOfWar); - toolTips.SetToolTip(xMisconduct, Resources.TipMisconduct); - } - - - // Tracks selected prisoner on the "Prisoners" tab. - // GUI is automatically updated (or disabled) when this property is set. - Prisoner SelectedPrisoner { - get { return selectedPrisoner; } - set { - selectedPrisoner = value; - if (value == null) { - tName.Text = ""; - tSurname.Text = ""; - cCategory.SelectedIndex = -1; - lServedStats.Text = ""; - tName.Enabled = false; - tSurname.Enabled = false; - cCategory.Enabled = false; - pbServed.Value = 0; - bEliminate.Enabled = false; - bRelease.Enabled = false; - } else { - tName.Enabled = true; - tSurname.Enabled = true; - cCategory.Enabled = true; - bEliminate.Enabled = true; - PrisonerBio bio = selectedPrisoner.Bio; - tName.Text = bio.Forname; - tSurname.Text = bio.Surname; - cCategory.SelectedIndex = PrisonerUtil.CategoryNameToIndex(selectedPrisoner.Category); - pbServed.Value = (int)Math.Min(Math.Round(bio.Served * 100d / bio.Sentence), 100); - lServedStats.Text = String.Format("{0:0.#} of {1} years", bio.Served, bio.Sentence); - bRelease.Enabled = (bio.Served < bio.Sentence); - } - } - } - - - // Update counts in the menu items under "Eliminate prisoners" shortcut menu. - // If there are no prisoners to release in this category, option is grayed out. - void UpdatePrisonerCounts() { - // Count all Protective Custody prisoners - UpdatePrisonerCategoryItem(miEliminateProtected, miReleaseProtected, "Protected", "Protective Custody"); - UpdatePrisonerCategoryItem(miEliminateMinSec, miReleaseMinSec, "MinSec", "Minimum Security"); - UpdatePrisonerCategoryItem(miEliminateNormal, miReleaseNormal, "Normal", "Normal Security"); - UpdatePrisonerCategoryItem(miEliminateMaxSec, miReleaseMaxSec, "MaxSec", "Maximum Security"); + miReleaseDeathRow.Click += delegate { Release("DeathRow"); }; + miReleaseAll.Click += delegate { ReleaseAll(); }; + + miExit.Click += delegate { Close(); }; + + Shown += delegate { miFileOpen.PerformClick(); }; + + // Disable the GUI until a prison file is loaded + Enabled = false; + } + + + void AssignTooltips() { + toolTips.SetToolTip(xContinuousIntake, Resources.TipContinuousIntake); + toolTips.SetToolTip(xDecay, Resources.TipDecay); + toolTips.SetToolTip(xFailureConditions, Resources.TipFailureConditions); + toolTips.SetToolTip(xFogOfWar, Resources.TipFogOfWar); + toolTips.SetToolTip(xMisconduct, Resources.TipMisconduct); + } + + + // Tracks selected prisoner on the "Prisoners" tab. + // GUI is automatically updated (or disabled) when this property is set. + Prisoner SelectedPrisoner { + get { return selectedPrisoner; } + set { + selectedPrisoner = value; + if (value == null) { + tName.Text = ""; + tSurname.Text = ""; + cCategory.SelectedIndex = -1; + lServedStats.Text = ""; + tName.Enabled = false; + tSurname.Enabled = false; + cCategory.Enabled = false; + pbServed.Value = 0; + bEliminate.Enabled = false; + bRelease.Enabled = false; + } else { + tName.Enabled = true; + tSurname.Enabled = true; + cCategory.Enabled = true; + bEliminate.Enabled = true; + PrisonerBio bio = selectedPrisoner.Bio; + tName.Text = bio.Forname; + tSurname.Text = bio.Surname; + cCategory.SelectedIndex = PrisonerUtil.CategoryNameToIndex(selectedPrisoner.Category); + pbServed.Value = (int)Math.Min(Math.Round(bio.Served * 100d / bio.Sentence), 100); + lServedStats.Text = String.Format("{0:0.#} of {1} years", bio.Served, bio.Sentence); + bRelease.Enabled = (bio.Served < bio.Sentence); + m_Age.Text = bio.Age.ToString(); + m_BodyType.Text = bio.BodyType.ToString(); + // adding gang + } + } + } + + + // Update counts in the menu items under "Eliminate prisoners" shortcut menu. + // If there are no prisoners to release in this category, option is grayed out. + void UpdatePrisonerCounts() { + // Count all Protective Custody prisoners + UpdatePrisonerCategoryItem(miEliminateProtected, miReleaseProtected, "Protected", "Protective Custody"); + UpdatePrisonerCategoryItem(miEliminateMinSec, miReleaseMinSec, "MinSec", "Minimum Security"); + UpdatePrisonerCategoryItem(miEliminateNormal, miReleaseNormal, "Normal", "Normal Security"); + UpdatePrisonerCategoryItem(miEliminateMaxSec, miReleaseMaxSec, "MaxSec", "Maximum Security"); UpdatePrisonerCategoryItem(miEliminateSuperMax, miReleaseSuperMax, "SuperMax", "SuperMax"); - UpdatePrisonerCategoryItem(miEliminateDeathRow, miReleaseDeathRow, "DeathRow", "Death Row"); - UpdatePrisonerCategoryItem(miEliminateAll, miReleaseAll, null, "All"); - - int hiddenReputations = - prison.Objects.Prisoners.Values - .Count(p => p.Bio.Reputations != null && !p.Bio.ReputationRevealed); - miRevealReputations.Text = String.Format("Reveal reputations ({0})", hiddenReputations); - miRevealReputations.Enabled = (hiddenReputations > 0); - } - - - void UpdatePrisonerCategoryItem(ToolStripMenuItem miEliminate, ToolStripMenuItem miRelease, - string categoryName, string label) { - int allCount; - if (categoryName == null) { - allCount = prison.Objects.Prisoners.Count; - } else { - allCount = PrisonerUtil.CountPrisoners(prison, p => p.Category == categoryName); - } - miEliminate.Text = String.Format("{0} ({1})", label, allCount); - miEliminate.Enabled = (allCount > 0); - - int nonReleasedCount; - - if (categoryName == null) { - nonReleasedCount = PrisonerUtil.CountPrisoners(prison, p => p.Bio.Served < p.Bio.Sentence); - } else { - nonReleasedCount = - PrisonerUtil.CountPrisoners(prison, - p => p.Category == categoryName && - p.Bio.Served < p.Bio.Sentence); - } - miRelease.Text = String.Format("{0} ({1})", label, nonReleasedCount); - miRelease.Enabled = (nonReleasedCount > 0); - } - - - // Updates list on the "Prisoners" tab. Resets SelectedPrisoner. - void UpdatePrisoners() { - lbPrisoners.Items.Clear(); - prisonerNames = prison.Objects.Prisoners.Values - .Select(PrisonerUtil.NamePrisoner) - .ToArray(); - lbPrisoners.Items.AddRange(prisonerNames); - if (!prison.Objects.Prisoners.Values.Contains(selectedPrisoner)) { - SelectedPrisoner = null; - } - UpdatePrisonerCounts(); - } - - - void lbPrisoners_SelectedIndexChanged(object sender, EventArgs e) { - SelectedPrisoner = prison.Objects.Prisoners.Values.ToArray()[lbPrisoners.SelectedIndex]; - } - - - static bool ContainsIgnoreCase(string haystack, string needle) { - return CultureInfo.InvariantCulture.CompareInfo - .IndexOf(haystack, needle, CompareOptions.IgnoreCase) >= 0; - } - - - void tPrisonerSearch_TextChanged(object sender, EventArgs e) { - lbPrisoners.Items.Clear(); - lbPrisoners.Items.AddRange( - prisonerNames.Where(name => ContainsIgnoreCase(name, tPrisonerSearch.Text)).ToArray()); - } - - - void tName_TextChanged(object sender, EventArgs e) { - if (SelectedPrisoner != null) { - SelectedPrisoner.Bio.Forname = tName.Text; - } - } - - - void tSurname_TextChanged(object sender, EventArgs e) { - if (SelectedPrisoner != null) { - SelectedPrisoner.Bio.Surname = tSurname.Text; - } - } - - - void cCategory_SelectedIndexChanged(object sender, EventArgs e) { - if (SelectedPrisoner != null) { - SelectedPrisoner.Category = PrisonerUtil.CategoryIndexToName(cCategory.SelectedIndex); - } - } - - - void bEliminate_Click(object sender, EventArgs e) { - PrisonerUtil.EliminatePrisoner(prison, SelectedPrisoner.Id); - SelectedPrisoner = null; - UpdatePrisoners(); - } - - - void miAbout_Click(object sender, EventArgs e) { - new AboutBox().ShowDialog(this); - } - - - #region Shortcuts - - void miRemoveAllTrees_Click(object sender, EventArgs e) { - var idsToRemove = prison.Objects.OtherObjects - .Values - .Where(obj => obj.Type == "Tree") - .Select(obj => obj.Id) - .ToList(); - - idsToRemove.ForEach(id => prison.Objects.OtherObjects.Remove(id)); - - MessageBox.Show(String.Format("{0} trees removed.", idsToRemove.Count)); - miRemoveAllTrees.Text = "Remove all trees (0)"; - miRemoveAllTrees.Enabled = false; - } - - - void miUnlockAllResearch_Click(object sender, EventArgs e) { - for (int i = 0; i < clbResearch.Items.Count; i++) { - clbResearch.SetItemChecked(i, true); - } - MessageBox.Show("All research unlocked!"); - } - - - int CountContraband() { - Node trackers = prison.Contraband.TryGetNode("Trackers"); - if (trackers == null) return 0; - string sizeStr = trackers.TryGetProperty("Size"); - if (sizeStr == null) return 0; - return Int32.Parse(sizeStr); - } - - - void miRemoveAllContraband_Click(object sender, EventArgs e) { - prison.Contraband.Child.Prisoners.Clear(); - int numRemoved = CountContraband(); - prison.Contraband.Nodes.Remove("Trackers"); - MessageBox.Show(String.Format("{0} pieces of contraband removed!", numRemoved)); - miRemoveAllContraband.Text = "Remove all contraband (0)"; - miRemoveAllContraband.Enabled = false; - } - - - void miRevealReputations_Click(object sender, EventArgs e) { - var toReveal = - prison.Objects.Prisoners.Values - .Where(p => p.Bio.Reputations != null && !p.Bio.ReputationRevealed) - .ToList(); - - toReveal.ForEach(p => p.Bio.ReputationRevealed = true); - MessageBox.Show(String.Format("{0} prisoner reputations revealed.", toReveal.Count)); - UpdatePrisonerCounts(); - } - - - void EliminateAll() { - int released = PrisonerUtil.Eliminate(prison, prisoner => true); - MessageBox.Show(String.Format("All {0} prisoners eliminated.", released)); - UpdatePrisoners(); - } - - - void Eliminate(string categoryName) { - string groupLabel = PrisonerUtil.InternalToInGameCatName(categoryName); - int released = PrisonerUtil.Eliminate(prison, prisoner => prisoner.Category == categoryName); - MessageBox.Show(String.Format("{0} {1} prisoners eliminated.", released, groupLabel)); - UpdatePrisoners(); - } - - - void ReleaseAll() { - int released = PrisonerUtil.Release(prison, prisoner => true); - MessageBox.Show(String.Format("All {0} prisoners scheduled for release.", released)); - UpdatePrisoners(); - } - - - void Release(string categoryName) { - string groupLabel = PrisonerUtil.InternalToInGameCatName(categoryName); - int released = PrisonerUtil.Release(prison, prisoner => prisoner.Category == categoryName); - MessageBox.Show(String.Format("{0} {1} prisoners scheduled for release.", released, groupLabel)); - UpdatePrisoners(); - } - - - void miRemoveTunnels_Click(object sender, EventArgs e) { - var cellLabels = prison.Tunnels.Nodes.Keys.Where(Pos.IsPos).ToList(); - cellLabels.ForEach(label => prison.Tunnels.Nodes.Remove(label)); - prison.Tunnels.Diggers.Prisoners.Clear(); - prison.Tunnels.Nodes.Remove("Rooms"); - } - - - void bRelease_Click(object sender, EventArgs e) { - PrisonerUtil.ReleasePrisoner(prison, selectedPrisoner.Id); - pbServed.Value = 100; - PrisonerBio bio = selectedPrisoner.Bio; - lServedStats.Text = String.Format("{0:0.#} of {1} years", bio.Served, bio.Sentence); - bRelease.Enabled = false; - } - - #endregion - - - #region Loading / Saving - - void miFileOpen_Click(object sender, EventArgs e) { - if (openDialog.ShowDialog() == DialogResult.OK) { - fileName = openDialog.FileName; - using (FileStream fs = File.OpenRead(openDialog.FileName)) { - Text = String.Format("Loading {0} | {1}", Path.GetFileName(fileName), AppName); - try { - prison = new Parser().Load(fs); - } catch (Exception ex) { - string msg = String.Format("An error occured while loading:{0}{1}{0}{2}", - Environment.NewLine, ex.GetType().Name, ex.Message); - MessageBox.Show(msg, String.Format("Error loading {0}", Path.GetFileName(fileName)), - MessageBoxButtons.OK, MessageBoxIcon.Error); - Close(); - } - if (prison.Version != Parser.SupportedVersion) { - MessageBox.Show(String.Format(Resources.FileVersionWarning, Parser.SupportedVersion, - prison.Version)); - } - LoadPrisonToGui(); - Enabled = true; - Text = String.Format("{0} | {1}", Path.GetFileName(fileName), AppName); - } - } else { - if (prison == null) { - Close(); - } - } - } - - - void LoadPrisonToGui() { - // Load general tab - nDay.Value = TimeConversion.IndexToDay(prison.TimeIndex); - tTime.Text = String.Format("{0:00}:{1:00}", - TimeConversion.IndexTo12Hour(prison.TimeIndex), - TimeConversion.IndexToMinute(prison.TimeIndex)); - cAmPm.SelectedIndex = (TimeConversion.IsPm(prison.TimeIndex) ? 1 : 0); - - xMisconduct.Checked = prison.EnabledMisconduct; - xContinuousIntake.Checked = prison.EnabledIntake; - xFogOfWar.Checked = prison.EnabledVisibility; - xFailureConditions.Checked = prison.FailureConditions; - xDecay.Checked = prison.EnabledDecay; - - // Load finances tab - xUnlimitedFunds.Checked = prison.UnlimitedFunds; - nBalance.Value = prison.Finance.Balance; - nBankLoanAmount.Value = prison.Finance.BankLoan; - nCreditRating.Value = Convert.ToDecimal(prison.Finance.BankCreditRating*100); - nOwnership.Value = Convert.ToDecimal(prison.Finance.Ownership); - - // Load prisoners tab - UpdatePrisoners(); - SelectedPrisoner = null; - - // Load research tab - clbResearch.Items.Clear(); - clbResearch.Items.AddRange(ResearchData.GetInGameNames()); - if (prison.Research != null) { - foreach (ResearchItem item in prison.Research.Items) { - if (item.Label == "None") continue; - int idx = ResearchData.GetIndex(item.Label); - if (idx < 0) { - idx = ResearchData.AddItem(item.Label); - clbResearch.Items.Add(item.Label); - } - if (item.Progress > .999) { - clbResearch.SetItemChecked(idx, true); - } - } - } - - int numContraband = CountContraband(); - miRemoveAllContraband.Text = String.Format("Remove all contraband ({0})", numContraband); - miRemoveAllContraband.Enabled = (numContraband > 0); - - int numTrees = prison.Objects.OtherObjects - .Values .Count(obj => obj.Type == "Tree"); - miRemoveAllTrees.Text = String.Format("Remove all trees ({0})", numTrees); - miRemoveAllTrees.Enabled = (numTrees > 0); - } - - - void miFileSaveAs_Click(object sender, EventArgs e) { - if (saveAsDialog.ShowDialog() == DialogResult.OK) { - string newFileName = saveAsDialog.FileName; - if (File.Exists(newFileName) && !PromptToReplace(newFileName)) { - return; - } - Save(newFileName); - fileName = newFileName; - } - } - - - void miFileSave_Click(object sender, EventArgs e) { - if (PromptToReplace(fileName)) { - Save(fileName); - } - } - - - bool PromptToReplace(string file) { - string msg = String.Format("Are you sure you want to overwrite {0}?", - Path.GetFileName(file)); - return MessageBox.Show(msg, "Saving", MessageBoxButtons.OKCancel) == DialogResult.OK; - } - - - void Save(string newFileName) { - Enabled = false; - Text = String.Format("Saving {0} | {1}", Path.GetFileName(newFileName), AppName); - SaveGuiToPrison(); - - string tempFileName = Path.GetTempFileName(); - using (FileStream fs = File.Create(tempFileName)) { - using (var writer = new Writer(fs)) { - writer.WritePrison(prison); - } - } - if (File.Exists(newFileName)) { - File.Replace(tempFileName, newFileName, newFileName + ".bak"); - } else { - File.Move(tempFileName, newFileName); - } - - Text = String.Format("{0} | {1}", Path.GetFileName(fileName), AppName); - Enabled = true; - } - - - void SaveGuiToPrison() { - // Store general tab - prison.TimeIndex = TimeConversion.ToIndex( - Convert.ToInt32(nDay.Value), tTime.Text, cAmPm.SelectedIndex == 1); - - prison.EnabledMisconduct = xMisconduct.Checked; - prison.EnabledIntake = xContinuousIntake.Checked; - prison.EnabledVisibility = xFogOfWar.Checked; - prison.FailureConditions = xFailureConditions.Checked; - prison.EnabledDecay = xDecay.Checked; - - // Store finances tab - prison.UnlimitedFunds = xUnlimitedFunds.Checked; - prison.Finance.Balance = Convert.ToInt32(nBalance.Value); - prison.Finance.BankLoan = Convert.ToInt32(nBankLoanAmount.Value); - prison.Finance.BankCreditRating = Convert.ToDouble(nCreditRating.Value)/100; - prison.Finance.Ownership = Convert.ToInt32(nOwnership.Value); - - // Prisoner tab is continuously saved already - - // Store research tab - foreach (string itemName in ResearchData.AllResearch) { - if (itemName == "None") continue; - int idx = ResearchData.GetIndex(itemName); - bool isUnlocked = clbResearch.GetItemChecked(idx); - if (isUnlocked) { - prison.Research.Unlock(itemName); - } else { - prison.Research.Lock(itemName); - } - } - } - - #endregion - } -} + UpdatePrisonerCategoryItem(miEliminateDeathRow, miReleaseDeathRow, "DeathRow", "Death Row"); + UpdatePrisonerCategoryItem(miEliminateInsane, miReleaseInsane, "Insane", "Insane"); + UpdatePrisonerCategoryItem(miEliminateAll, miReleaseAll, null, "All"); + + int hiddenReputations = + prison.Objects.Prisoners.Values + .Count(p => p.Bio.Reputations != null && !p.Bio.ReputationRevealed); + miRevealReputations.Text = String.Format("Reveal reputations ({0})", hiddenReputations); + miRevealReputations.Enabled = (hiddenReputations > 0); + } + + + void UpdatePrisonerCategoryItem(ToolStripMenuItem miEliminate, ToolStripMenuItem miRelease, + string categoryName, string label) { + int allCount; + if (categoryName == null) { + allCount = prison.Objects.Prisoners.Count; + } else { + allCount = PrisonerUtil.CountPrisoners(prison, p => p.Category == categoryName); + } + miEliminate.Text = String.Format("{0} ({1})", label, allCount); + miEliminate.Enabled = (allCount > 0); + + int nonReleasedCount; + + if (categoryName == null) { + nonReleasedCount = PrisonerUtil.CountPrisoners(prison, p => p.Bio.Served < p.Bio.Sentence); + } else { + nonReleasedCount = + PrisonerUtil.CountPrisoners(prison, + p => p.Category == categoryName && + p.Bio.Served < p.Bio.Sentence); + } + miRelease.Text = String.Format("{0} ({1})", label, nonReleasedCount); + miRelease.Enabled = (nonReleasedCount > 0); + } + + + // Updates list on the "Prisoners" tab. Resets SelectedPrisoner. + void UpdatePrisoners() { + lbPrisoners.Items.Clear(); + prisonerNames = prison.Objects.Prisoners.Values + .Select(PrisonerUtil.NamePrisoner) + .ToArray(); + lbPrisoners.Items.AddRange(prisonerNames); + if (!prison.Objects.Prisoners.Values.Contains(selectedPrisoner)) { + SelectedPrisoner = null; + } + UpdatePrisonerCounts(); + } + + + void lbPrisoners_SelectedIndexChanged(object sender, EventArgs e) { + SelectedPrisoner = prison.Objects.Prisoners.Values.ToArray()[lbPrisoners.SelectedIndex]; + } + + + static bool ContainsIgnoreCase(string haystack, string needle) { + return CultureInfo.InvariantCulture.CompareInfo + .IndexOf(haystack, needle, CompareOptions.IgnoreCase) >= 0; + } + + + void tPrisonerSearch_TextChanged(object sender, EventArgs e) { + lbPrisoners.Items.Clear(); + lbPrisoners.Items.AddRange( + prisonerNames.Where(name => ContainsIgnoreCase(name, tPrisonerSearch.Text)).ToArray()); + } + + + void tName_TextChanged(object sender, EventArgs e) { + if (SelectedPrisoner != null) { + SelectedPrisoner.Bio.Forname = tName.Text; + } + } + + + void tSurname_TextChanged(object sender, EventArgs e) { + if (SelectedPrisoner != null) { + SelectedPrisoner.Bio.Surname = tSurname.Text; + } + } + + + void cCategory_SelectedIndexChanged(object sender, EventArgs e) { + if (SelectedPrisoner != null) { + SelectedPrisoner.Category = PrisonerUtil.CategoryIndexToName(cCategory.SelectedIndex); + } + } + + + void bEliminate_Click(object sender, EventArgs e) { + PrisonerUtil.EliminatePrisoner(prison, SelectedPrisoner.Id); + SelectedPrisoner = null; + UpdatePrisoners(); + } + + + void miAbout_Click(object sender, EventArgs e) { + new AboutBox().ShowDialog(this); + } + + + #region Shortcuts + + void miRemoveAllTrees_Click(object sender, EventArgs e) { + var idsToRemove = prison.Objects.OtherObjects + .Values + .Where(obj => obj.Type == "Tree") + .Select(obj => obj.Id) + .ToList(); + + idsToRemove.ForEach(id => prison.Objects.OtherObjects.Remove(id)); + + MessageBox.Show(String.Format("{0} trees removed.", idsToRemove.Count)); + miRemoveAllTrees.Text = "Remove all trees (0)"; + miRemoveAllTrees.Enabled = false; + } + + + void miUnlockAllResearch_Click(object sender, EventArgs e) { + for (int i = 0; i < clbResearch.Items.Count; i++) { + clbResearch.SetItemChecked(i, true); + } + MessageBox.Show("All research unlocked!"); + } + + + int CountContraband() { + Node trackers = prison.Contraband.TryGetNode("Trackers"); + if (trackers == null) return 0; + string sizeStr = trackers.TryGetProperty("Size"); + if (sizeStr == null) return 0; + return Int32.Parse(sizeStr); + } + + + void miRemoveAllContraband_Click(object sender, EventArgs e) { + prison.Contraband.Child.Prisoners.Clear(); + int numRemoved = CountContraband(); + prison.Contraband.Nodes.Remove("Trackers"); + MessageBox.Show(String.Format("{0} pieces of contraband removed!", numRemoved)); + miRemoveAllContraband.Text = "Remove all contraband (0)"; + miRemoveAllContraband.Enabled = false; + } + + + void miRevealReputations_Click(object sender, EventArgs e) { + var toReveal = + prison.Objects.Prisoners.Values + .Where(p => p.Bio.Reputations != null && !p.Bio.ReputationRevealed) + .ToList(); + + toReveal.ForEach(p => p.Bio.ReputationRevealed = true); + MessageBox.Show(String.Format("{0} prisoner reputations revealed.", toReveal.Count)); + UpdatePrisonerCounts(); + } + + + void EliminateAll() { + int released = PrisonerUtil.Eliminate(prison, prisoner => true); + MessageBox.Show(String.Format("All {0} prisoners eliminated.", released)); + UpdatePrisoners(); + } + + + void Eliminate(string categoryName) { + string groupLabel = PrisonerUtil.InternalToInGameCatName(categoryName); + int released = PrisonerUtil.Eliminate(prison, prisoner => prisoner.Category == categoryName); + MessageBox.Show(String.Format("{0} {1} prisoners eliminated.", released, groupLabel)); + UpdatePrisoners(); + } + + + void ReleaseAll() { + int released = PrisonerUtil.Release(prison, prisoner => true); + MessageBox.Show(String.Format("All {0} prisoners scheduled for release.", released)); + UpdatePrisoners(); + } + + + void Release(string categoryName) { + string groupLabel = PrisonerUtil.InternalToInGameCatName(categoryName); + int released = PrisonerUtil.Release(prison, prisoner => prisoner.Category == categoryName); + MessageBox.Show(String.Format("{0} {1} prisoners scheduled for release.", released, groupLabel)); + UpdatePrisoners(); + } + + + void miRemoveTunnels_Click(object sender, EventArgs e) { + var cellLabels = prison.Tunnels.Nodes.Keys.Where(Pos.IsPos).ToList(); + cellLabels.ForEach(label => prison.Tunnels.Nodes.Remove(label)); + prison.Tunnels.Diggers.Prisoners.Clear(); + prison.Tunnels.Nodes.Remove("Rooms"); + } + + + void bRelease_Click(object sender, EventArgs e) { + PrisonerUtil.ReleasePrisoner(prison, selectedPrisoner.Id); + pbServed.Value = 100; + PrisonerBio bio = selectedPrisoner.Bio; + lServedStats.Text = String.Format("{0:0.#} of {1} years", bio.Served, bio.Sentence); + bRelease.Enabled = false; + } + + #endregion + + + #region Loading / Saving + + void miFileOpen_Click(object sender, EventArgs e) { + if (openDialog.ShowDialog() == DialogResult.OK) { + fileName = openDialog.FileName; + using (FileStream fs = File.OpenRead(openDialog.FileName)) { + Text = String.Format("Loading {0} | {1}", Path.GetFileName(fileName), AppName); + try { + prison = new Parser().Load(fs); + } catch (Exception ex) { + string msg = String.Format("An error occured while loading:{0}{1}{0}{2}", + Environment.NewLine, ex.GetType().Name, ex.Message); + MessageBox.Show(msg, String.Format("Error loading {0}", Path.GetFileName(fileName)), + MessageBoxButtons.OK, MessageBoxIcon.Error); + Close(); + } + if (prison.Version != Parser.SupportedVersion) { + MessageBox.Show(String.Format(Resources.FileVersionWarning, Parser.SupportedVersion, + prison.Version)); + } + LoadPrisonToGui(); + Enabled = true; + Text = String.Format("{0} | {1}", Path.GetFileName(fileName), AppName); + } + } else { + if (prison == null) { + Close(); + } + } + } + + + void LoadPrisonToGui() { + // Load general tab + nDay.Value = TimeConversion.IndexToDay(prison.TimeIndex); + tTime.Text = String.Format("{0:00}:{1:00}", + TimeConversion.IndexTo12Hour(prison.TimeIndex), + TimeConversion.IndexToMinute(prison.TimeIndex)); + cAmPm.SelectedIndex = (TimeConversion.IsPm(prison.TimeIndex) ? 1 : 0); + + xMisconduct.Checked = prison.EnabledMisconduct; + xContinuousIntake.Checked = prison.EnabledIntake; + xFogOfWar.Checked = prison.EnabledVisibility; + xFailureConditions.Checked = prison.FailureConditions; + xDecay.Checked = prison.EnabledDecay; + + // Load finances tab + xUnlimitedFunds.Checked = prison.UnlimitedFunds; + nBalance.Value = prison.Finance.Balance; + nBankLoanAmount.Value = prison.Finance.BankLoan; + nCreditRating.Value = Convert.ToDecimal(prison.Finance.BankCreditRating*100); + nOwnership.Value = Convert.ToDecimal(prison.Finance.Ownership); + + // Load prisoners tab + UpdatePrisoners(); + SelectedPrisoner = null; + + // Load research tab + clbResearch.Items.Clear(); + clbResearch.Items.AddRange(ResearchData.GetInGameNames()); + if (prison.Research != null) { + foreach (ResearchItem item in prison.Research.Items) { + if (item.Label == "None") continue; + int idx = ResearchData.GetIndex(item.Label); + if (idx < 0) { + idx = ResearchData.AddItem(item.Label); + clbResearch.Items.Add(item.Label); + } + if (item.Progress > .999) { + clbResearch.SetItemChecked(idx, true); + } + } + } + + int numContraband = CountContraband(); + miRemoveAllContraband.Text = String.Format("Remove all contraband ({0})", numContraband); + miRemoveAllContraband.Enabled = (numContraband > 0); + + int numTrees = prison.Objects.OtherObjects + .Values .Count(obj => obj.Type == "Tree"); + miRemoveAllTrees.Text = String.Format("Remove all trees ({0})", numTrees); + miRemoveAllTrees.Enabled = (numTrees > 0); + } + + + void miFileSaveAs_Click(object sender, EventArgs e) { + if (saveAsDialog.ShowDialog() == DialogResult.OK) { + string newFileName = saveAsDialog.FileName; + if (File.Exists(newFileName) && !PromptToReplace(newFileName)) { + return; + } + Save(newFileName); + fileName = newFileName; + } + } + + + void miFileSave_Click(object sender, EventArgs e) { + if (PromptToReplace(fileName)) { + Save(fileName); + } + } + + + bool PromptToReplace(string file) { + string msg = String.Format("Are you sure you want to overwrite {0}?", + Path.GetFileName(file)); + return MessageBox.Show(msg, "Saving", MessageBoxButtons.OKCancel) == DialogResult.OK; + } + + + void Save(string newFileName) { + Enabled = false; + Text = String.Format("Saving {0} | {1}", Path.GetFileName(newFileName), AppName); + SaveGuiToPrison(); + + string tempFileName = Path.GetTempFileName(); + using (FileStream fs = File.Create(tempFileName)) { + using (var writer = new Writer(fs)) { + writer.WritePrison(prison); + } + } + if (File.Exists(newFileName)) { + File.Replace(tempFileName, newFileName, newFileName + ".bak"); + } else { + File.Move(tempFileName, newFileName); + } + + Text = String.Format("{0} | {1}", Path.GetFileName(fileName), AppName); + Enabled = true; + } + + + void SaveGuiToPrison() { + // Store general tab + prison.TimeIndex = TimeConversion.ToIndex( + Convert.ToInt32(nDay.Value), tTime.Text, cAmPm.SelectedIndex == 1); + + prison.EnabledMisconduct = xMisconduct.Checked; + prison.EnabledIntake = xContinuousIntake.Checked; + prison.EnabledVisibility = xFogOfWar.Checked; + prison.FailureConditions = xFailureConditions.Checked; + prison.EnabledDecay = xDecay.Checked; + + // Store finances tab + prison.UnlimitedFunds = xUnlimitedFunds.Checked; + prison.Finance.Balance = Convert.ToInt32(nBalance.Value); + prison.Finance.BankLoan = Convert.ToInt32(nBankLoanAmount.Value); + prison.Finance.BankCreditRating = Convert.ToDouble(nCreditRating.Value)/100; + prison.Finance.Ownership = Convert.ToInt32(nOwnership.Value); + + // Prisoner tab is continuously saved already + + // Store research tab + foreach (string itemName in ResearchData.AllResearch) { + if (itemName == "None") continue; + int idx = ResearchData.GetIndex(itemName); + bool isUnlocked = clbResearch.GetItemChecked(idx); + if (isUnlocked) { + prison.Research.Unlock(itemName); + } else { + prison.Research.Lock(itemName); + } + } + } + + #endregion + + private void moveToPercentage_Click(object sender, EventArgs e) // added by caleb + { + if(SelectedPrisoner != null) // not possible but good to check + { + selectedPrisoner.Bio.Served = selectedPrisoner.Bio.Sentence * (.95); + SelectedPrisoner = null; + UpdatePrisoners(); + } + } + + private void nBankLoanAmount_ValueChanged(object sender, EventArgs e) + { + + } + + private void tpPrisoners_Click(object sender, EventArgs e) + { + + } + + private void button2_Click(object sender, EventArgs e) + { + prison x; + foreach(string tPrisoner in prisonerNames) + { + + } + } + } +} diff --git a/PASaveEditor.csproj b/PASaveEditor.csproj index 4ff5cc0..770f1eb 100644 --- a/PASaveEditor.csproj +++ b/PASaveEditor.csproj @@ -55,6 +55,7 @@ + diff --git a/Parser.cs b/Parser.cs index 37b45f0..ea077fa 100644 --- a/Parser.cs +++ b/Parser.cs @@ -8,7 +8,7 @@ namespace PASaveEditor { // Parser for .prison file format, used by PrisonArchitect internal class Parser { - public const string SupportedVersion = "alpha-25b"; + public const string SupportedVersion = "the_sneezer_1.02"; static readonly Regex IdRegex = new Regex("^\\[i \\d+\\]$", RegexOptions.Compiled); diff --git a/PrisonerUtil.cs b/PrisonerUtil.cs index ed96a26..d8385a5 100644 --- a/PrisonerUtil.cs +++ b/PrisonerUtil.cs @@ -12,7 +12,8 @@ internal static class PrisonerUtil { { "Normal", "Normal Security" }, { "MaxSec", "Maximum Security" }, { "SuperMax", "SuperMax" }, - { "DeathRow", "Death Row" } + { "DeathRow", "Death Row" }, + {"Insane", "Insane" } }; // Converts short in-savegame name to index (0-5) diff --git a/Program.cs b/Program.cs index 5c3bd3e..cc431cc 100644 --- a/Program.cs +++ b/Program.cs @@ -12,6 +12,6 @@ static void Main() { } - public const string Version = "r32 [9 October 2014]"; + public const string Version = "revision 1, 4/6/2020"; } }