Skip to content

Commit

Permalink
preview 46
Browse files Browse the repository at this point in the history
  • Loading branch information
igorseabra4 committed Jul 26, 2019
1 parent 12e2560 commit 141d855
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 37 deletions.
21 changes: 13 additions & 8 deletions IndustrialPark/ArchiveEditor/ArchiveEditorFunctions_Randomizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ private void ShufflePKUPPositions(Random r)
break;
case "jf01":
case "bc01":
case "rb03":
case "sm01":
for (int i = 0; i < assets.Count; i++)
{
Expand Down Expand Up @@ -636,31 +637,35 @@ private void ShuffleTimers(Random r)
private string LevelName => Path.GetFileNameWithoutExtension(currentlyOpenFilePath);

private bool IsWarpToSameLevel(string warpName) =>
LevelName.ToLower().Equals(warpName.ToLower()) || new string(warpName.Reverse().ToArray()).ToLower().Equals(LevelName);
LevelName.ToLower().Equals(warpName.ToLower()) || new string(warpName.Reverse().ToArray()).ToLower().Equals(LevelName.ToLower());

public void GetWarpNames(ref List<string> warpNames, List<string> lines)
public void GetWarpNames(ref List<string> warpNames, List<string> toSkip)
{
foreach (Asset a in assetDictionary.Values)
if (a is AssetPORT port && !IsWarpToSameLevel(port.DestinationLevel) && !PortInLines(port.DestinationLevel, lines))
if (a is AssetPORT port && !IsWarpToSameLevel(port.DestinationLevel) && !PortInToSkip(port.DestinationLevel, toSkip))
warpNames.Add(port.DestinationLevel);
}

private bool PortInLines(string port, List<string> lines)
private bool PortInToSkip(string port, List<string> toSkip)
{
foreach (string s in lines)
if (port.ToLower().Contains(s.ToLower()))
foreach (string s in toSkip)
if (port.ToLower().Equals(s.ToLower()))
return true;
else if (new string(port.Reverse().ToArray()).ToLower().Contains(s.ToLower()))
else if (new string(port.Reverse().ToArray()).ToLower().Equals(s.ToLower()))
return true;

return false;
}

public void SetWarpNames(Random r, ref List<string> warpNames, List<string> lines)
{

foreach (Asset a in assetDictionary.Values)
if (a is AssetPORT port && !IsWarpToSameLevel(port.DestinationLevel) && !PortInLines(port.DestinationLevel, lines))
if (a is AssetPORT port && !IsWarpToSameLevel(port.DestinationLevel) && !PortInToSkip(port.DestinationLevel, lines))
{
if (warpNames.Count == 0)
throw new Exception("warpNames is empty");

int index;
int times = 0;
do
Expand Down
4 changes: 2 additions & 2 deletions IndustrialPark/MainForm/Json/IPversion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
public class IPversion
{
public string version = "preview45";
public string versionName = "Preview 45";
public string version = "preview46";
public string versionName = "Preview 46";
}
}
2 changes: 1 addition & 1 deletion IndustrialPark/Research/Randomizer.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 29 additions & 24 deletions IndustrialPark/Research/Randomizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,42 +155,33 @@ private void PerformDirRandomizer(Random r, RandomizerFlags flags, RandomizerFla
foreach (string hipPath in Directory.GetFiles(dir))
if (Path.GetExtension(hipPath).ToLower() == ".hip")
{
bool skip = false;
foreach (string s in richTextBoxSkip.Lines)
if (Path.GetFileName(hipPath).ToLower().Contains(s.ToLower()))
skip = true;
if (skip)
if (FileInFirstBox(hipPath))
continue;

ArchiveEditorFunctions hip = new ArchiveEditorFunctions();
hip.OpenFile(hipPath, false, true);

if ((flags & RandomizerFlags.Warps) != 0)
hip.GetWarpNames(ref warpNames, toSkip);
if ((flags & RandomizerFlags.Warps) != 0 && !FileInSecondBox(hipPath))
hip.GetWarpNames(ref warpNames, toSkip);

ArchiveEditorFunctions hop = null;
string hopPath = Path.ChangeExtension(hipPath, ".HOP");

bool secondSkip = false;
foreach (string s in richTextBox2.Lines)
if (Path.GetFileName(hip.currentlyOpenFilePath).ToLower().Contains(s.ToLower()))
secondSkip = true;


if (File.Exists(hopPath))
{
hop = new ArchiveEditorFunctions();
hop.OpenFile(hopPath, false, true);

levelPairs.Add((hip, hop));

if (!secondSkip)
if (!FileInSecondBox(hipPath))
levelPathPairs.Add((hipPath, hopPath));
}
else
{
levelPairs.Add((hip, null));

if (!secondSkip)
if (!FileInSecondBox(hipPath))
levelPathPairs.Add((hipPath, null));
}

Expand Down Expand Up @@ -268,23 +259,18 @@ private void PerformDirRandomizer(Random r, RandomizerFlags flags, RandomizerFla

for (int i = 0; i < levelPairs.Count; i++)
{
bool secondSkip = false;
foreach (string s in richTextBox2.Lines)
if (Path.GetFileName(levelPairs[i].Item1.currentlyOpenFilePath).ToLower().Contains(s.ToLower()))
secondSkip = true;

bool item1shuffled =
levelPairs[i].Item1.Shuffle(r, flags, flags2, (float)numericPlatSpeedMin.Value, (float)numericPlatSpeedMax.Value, (float)numericPlatTimeMin.Value, (float)numericPlatTimeMax.Value);

if ((flags & RandomizerFlags.Warps) != 0 && !secondSkip)
if ((flags & RandomizerFlags.Warps) != 0 && !FileInSecondBox(levelPairs[i].Item1.currentlyOpenFilePath))
levelPairs[i].Item1.SetWarpNames(r, ref warpNames, toSkip);

bool item2shuffled = false;
if (levelPairs[i].Item2 != null)
item2shuffled =
levelPairs[i].Item2.Shuffle(r, flags, flags2, (float)numericPlatSpeedMin.Value, (float)numericPlatSpeedMax.Value, (float)numericPlatTimeMin.Value, (float)numericPlatTimeMax.Value);

if ((flags2 & RandomizerFlagsP2.Level_Files) != 0 && !secondSkip)
if ((flags2 & RandomizerFlagsP2.Level_Files) != 0 && !FileInSecondBox(levelPairs[i].Item1.currentlyOpenFilePath))
{
int newPathIndex = r.Next(0, levelPathPairs.Count);

Expand Down Expand Up @@ -313,13 +299,32 @@ private void PerformDirRandomizer(Random r, RandomizerFlags flags, RandomizerFla
progressBar1.PerformStep();
}

if (warpNames.Count != 0)
MessageBox.Show("There was a problem with the warp randomizer. It is likely some warps are broken.");

if (flags3 != 0)
ApplyINISettings(flags3, r, namesForBoot);
}

private bool ShouldShuffle(RandomizerFlagsP3 flags, RandomizerFlagsP3 flag)
=> (flags & flag) != 0;

private bool FileInFirstBox(string levelName)
{
foreach (string s in richTextBoxSkip.Lines)
if (Path.GetFileNameWithoutExtension(levelName).ToLower().Contains(s.ToLower()))
return true;
return false;
}

private bool FileInSecondBox(string levelName)
{
foreach (string s in richTextBox2.Lines)
if (Path.GetFileNameWithoutExtension(levelName).ToLower().Contains(s.ToLower()))
return true;
return false;
}

private void ApplyINISettings(RandomizerFlagsP3 flags3, Random r, List<string> namesForBoot)
{
string[] ini;
Expand Down Expand Up @@ -476,7 +481,7 @@ private void ButtonLoadJson_Click(object sender, EventArgs e)
}
else
{
MessageBox.Show("Randomizer instance cannot be opened because it was made with an earlier or different version of Industrial Park.");
MessageBox.Show("Randomizer settings cannot be opened because it was made with an earlier or different version of Industrial Park.");
}
}
}
Expand Down Expand Up @@ -523,7 +528,7 @@ public class RandoSettings

public RandoSettings FromInstance() => new RandoSettings()
{
version = 45,
version = 46,
seedText = textBoxSeed.Text,
seedNum = seed,
flags = GetActiveFlags(),
Expand Down
4 changes: 2 additions & 2 deletions IndustrialPark/Resources/ip_version.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"version": "preview45",
"versionName": "Preview 45:\nRandomizer update. Check wiki page for more info.\n"
"version": "preview46",
"versionName": "Preview 46:\nRandomizer update: fixes major issue with Warps randomizer.\n"
}

0 comments on commit 141d855

Please sign in to comment.