-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrandomize.cs
More file actions
278 lines (252 loc) · 10.1 KB
/
randomize.cs
File metadata and controls
278 lines (252 loc) · 10.1 KB
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace randomize
{
internal class Randomize
{
public void reset(ref string[] Names, bool[] activeGames, ref int[] insert, ref string[] curMissions, ref int[] curInsert, ref string output)
{
addNames(ref Names, activeGames, ref insert);
Array.Clear(curMissions, 0, curMissions.Length);
Array.Resize(ref curMissions, 0);
Array.Clear(curInsert, 0, curInsert.Length);
Array.Resize(ref curInsert, 0);
output =
$@"<?xml version=""1.0"" encoding=""utf-8""?>
<!--Please increment version number inside the MissionPlaylists tag if the list is updated. The game uses version number to ensure coop players have same data and also save games will be based on this (The version inside XML tag is not used.)-->
<MissionPlaylists version=""4"">
<Halo1 />
<Halo2 />
<Halo3 />
<Halo3ODST />
<HaloReach />
<Halo4 />
<CrossTitle>
<Playlist id=""hydraulic"" name=""Randomizer Playlist"" desc=""H4sIAAAAAAAAAzNkqGHIYKhkSGEoYkhkKGXIYchkSAaKGQCxIZSGsEGkH5ilx2DEYApmYUIDukIAM+Jwa74AAAA="" image=""CT_Setlist_Preview_01"" highestDiffID=""_campaign_difficulty_level_legendary"" hasRallyPoints=""false"">
<MapList>
";
}
public void addNames(ref string[] Names, bool[] activeGames, ref int[] insert)
{
int index = 0;
int pastIndex;
string filename;
Array.Clear(Names, 0, Names.Length);
Array.Clear(insert, 0, insert.Length);
if (activeGames[0])
{
pastIndex = index;
index += 10;
Array.Resize(ref Names, index);
Array.Resize(ref insert, index);
filename = "resources/missions/CE.txt";
using (var reader = new StreamReader(filename))
{
for (int i = pastIndex; i < index; i++)
{
Names[i] = reader.ReadLine();
}
}
}
if (activeGames[1])
{
pastIndex = index;
index += 14;
Array.Resize(ref Names, index);
Array.Resize(ref insert, index);
filename = "resources/missions/H2.txt";
using (var reader = new StreamReader(filename))
{
for (int i = pastIndex; i < index; i++)
{
Names[i] = reader.ReadLine();
}
}
}
if (activeGames[2])
{
pastIndex = index;
index += 9;
Array.Resize(ref Names, index);
Array.Resize(ref insert, index);
filename = "resources/missions/H3.txt";
using (var reader = new StreamReader(filename))
{
for (int i = pastIndex; i < index; i++)
{
Names[i] = reader.ReadLine();
}
}
}
if (activeGames[3])
{
pastIndex = index;
index += 15;
Array.Resize(ref Names, index);
Array.Resize(ref insert, index);
filename = "resources/missions/ODST.txt";
using (var reader = new StreamReader(filename))
{
for (int i = pastIndex; i < index; i++)
{
Names[i] = reader.ReadLine();
}
}
insert[pastIndex + 2] = 1;
insert[pastIndex + 4] = 2;
insert[pastIndex + 6] = 3;
insert[pastIndex + 8] = 4;
insert[pastIndex + 10] = 5;
insert[pastIndex + 12] = 6;
}
if (activeGames[4])
{
pastIndex = index;
index += 9;
Array.Resize(ref Names, index);
Array.Resize(ref insert, index);
filename = "resources/missions/Reach.txt";
using (var reader = new StreamReader(filename))
{
for (int i = pastIndex; i < index; i++)
{
Names[i] = reader.ReadLine();
}
}
}
if (activeGames[5])
{
pastIndex = index;
index += 10;
Array.Resize(ref Names, index);
Array.Resize(ref insert, index);
filename = "resources/missions/H4.txt";
using (var reader = new StreamReader(filename))
{
for (int i = pastIndex; i < index; i++)
{
Names[i] = reader.ReadLine();
}
}
}
}
public void choose(ref string[] Names, ref string[] curMissions, int[] insert, ref int[] curInsert, TextBox seed, TextBox numLevels, bool allowDups)
{
Array.Resize(ref curMissions, int.Parse(numLevels.Text));
Array.Resize(ref curInsert, int.Parse(numLevels.Text));
bool finding = true;
int Seed = int.Parse(seed.Text);
Random num = new Random(Seed);
int numIndex = num.Next(0, Names.Length);
if (!allowDups)
{
for (int i = 0; i < int.Parse(numLevels.Text); i++)
{
finding = true;
while (finding)
{
numIndex = num.Next(0, Names.Length);
if (!curMissions.Contains(Names[numIndex]))
{
finding = false;
curMissions[i] = Names[numIndex];
if (insert[numIndex] != 0)
{
curInsert[i] = insert[numIndex];
}
}
}
}
}
else
{
for (int i = 0; i < int.Parse(numLevels.Text); i++)
{
numIndex = num.Next(0, Names.Length);
curMissions[i] = Names[numIndex];
if (insert[numIndex] != 0)
{
curInsert[i] = insert[numIndex];
}
}
}
}
public void RandDiff(string difficulty, TextBox Seed)
{
Random diff = new Random(int.Parse(Seed.Text));
int diffIndex = diff.Next(0, 4);
if (diffIndex == 0)
{
difficulty = "_campaign_difficulty_level_impossible";
}
else if (diffIndex == 1)
{
difficulty = "_campaign_difficulty_level_easy";
}
else if (diffIndex == 2)
{
difficulty = "_campaign_difficulty_level_normal";
}
else if (diffIndex == 3)
{
difficulty = "_campaign_difficulty_level_heroic";
}
}
public void create(string[] curMissions, string difficulty, bool fullRand, int[] curInsert, string output, TextBox Seed, string path)
{
Random diff = new Random(int.Parse(Seed.Text));
int diffIndex = diff.Next(0, 4);
for (int i = 0; i < curMissions.Length; i++)
{
//this one uses the same variable as the semirand but changes the value to be random for every mission
if (fullRand)
{
diffIndex = diff.Next(0, 4);
if (diffIndex == 0)
{
difficulty = "_campaign_difficulty_level_impossible";
}
else if (diffIndex == 1)
{
difficulty = "_campaign_difficulty_level_easy";
}
else if (diffIndex == 2)
{
difficulty = "_campaign_difficulty_level_normal";
}
else if (diffIndex == 3)
{
difficulty = "_campaign_difficulty_level_heroic";
}
}
//checks for the mombasa streets insertion points
if (curInsert[i] != 0)
{
//if the level has insertion points it will add them to the end
output = output + ("<" + curMissions[i] + " diffID='" + difficulty + "' insertionpoint='" + curInsert[i] + "' />");
}
else
{
//if not it will add the standard mission code
output = output + ("<" + curMissions[i] + " diffID='" + difficulty + "' />");
}
}
output = output +
$@"</MapList>
</Playlist>
</CrossTitle>
<Extras>
<!-- Status: 0 = greyed out, 1 = visible, 2 = hidden, 3 = invalid -->
<Halo5Beta status=""0"" />
</Extras>
</MissionPlaylists>";
//writes the data in output to the path youve selected
File.WriteAllText(path, output);
}
}
}