-
Notifications
You must be signed in to change notification settings - Fork 9
/
PrisonerUtil.cs
116 lines (94 loc) · 4.33 KB
/
PrisonerUtil.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
using System;
using System.Collections.Generic;
using System.Linq;
using PASaveEditor.FileModel;
namespace PASaveEditor {
internal static class PrisonerUtil {
// Names as they appear in the savegame are different from displayed names.
static readonly Dictionary<string, string> CategoryNames = new Dictionary<string, string> {
{ "Protected", "Protective Custody" },
{ "MinSec", "Minimum Security" },
{ "Normal", "Normal Security" },
{ "MaxSec", "Maximum Security" },
{ "SuperMax", "SuperMax" },
{ "DeathRow", "Death Row" }
};
// Converts short in-savegame name to index (0-5)
public static string CategoryIndexToName(int index) {
return CategoryNames.Keys.ToArray()[index];
}
public static string InternalToInGameCatName(string catName) {
return CategoryNames[catName];
}
// Converts index (0-5) to short in-savegame name
public static int CategoryNameToIndex(string catName) {
return Array.IndexOf(CategoryNames.Keys.ToArray(), catName);
}
// Returns a list of IDs of all prisoners who match the given predicate
public static int[] FindPrisoners(Prison prison, Predicate<Prisoner> predicate) {
return prison.Objects.Prisoners.Values
.Where(prisoner => predicate(prisoner))
.Select(prisoner => prisoner.Id)
.ToArray();
}
public static int CountPrisoners(Prison prison, Predicate<Prisoner> predicate) {
return prison.Objects.Prisoners.Values
.Count(prisoner => predicate(prisoner));
}
// Eliminates all prisoners who match the given predicate
public static int Eliminate(Prison prison, Predicate<Prisoner> predicate) {
int[] idsToRemove = FindPrisoners(prison, predicate);
foreach (int id in idsToRemove) {
EliminatePrisoner(prison, id);
}
return idsToRemove.Length;
}
// Schedules all prisoners who match the given predicate for release
public static int Release(Prison prison, Predicate<Prisoner> predicate) {
int[] idsToRemove = FindPrisoners(prison, predicate);
foreach (int id in idsToRemove) {
ReleasePrisoner(prison, id);
}
return idsToRemove.Length;
}
// Eliminates a single prisoner, by ID. Erases all traces of their existence.
public static void EliminatePrisoner(Prison prison, int id) {
prison.Objects.Prisoners.Remove(id);
prison.Contraband.Child.Prisoners.Remove(id);
prison.Informants.Child.Prisoners.RemoveAll(informant => informant.PrisonerId == id);
prison.Misconduct.Reports.Reports.Remove(id);
prison.Penalties.Child.PenaltyList.Remove(id);
foreach (ReformProgram program in prison.Reform.Programs.Programs) {
program.Students.Students.Remove(id);
}
prison.Tunnels.Diggers.Prisoners.RemoveAll(p => p.PrisonerId == id);
prison.Victory.Child.Log.RemoveAll(entry => entry.PrisonerId == id);
}
// Schedules a single prisoner for release, by ID.
public static void ReleasePrisoner(Prison prison, int id) {
PrisonerBio bio = prison.Objects.Prisoners[id].Bio;
bio.Served = bio.Sentence;
}
static readonly Dictionary<int, string> UnnamedPrisoners = new Dictionary<int, string> {
{ 93446, "SoulCake" },
{ 94805, "BrawnyFanta" },
{ 95177, "Neotin" },
{ 111475, "Squirrel" },
{ 114697, "DarkKnightPyro" },
{ 114969, "The Kracksquatch" },
{ 118793, "The Joker" },
{ 124835, "Heisenberg" },
{ 127230, "TotmasterT" },
{ 136059, "konflakes" }
};
public static string NamePrisoner(Prisoner prisoner) {
string nickName;
if (UnnamedPrisoners.TryGetValue(prisoner.Bio.Nitg, out nickName)) {
// Fix for nameless prisoners
return '"' + nickName + '"';
} else {
return prisoner.Bio.Forname + " " + prisoner.Bio.Surname;
}
}
}
}