Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions src/Patches/ERScripts.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using JetBrains.Annotations;
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
Expand Down Expand Up @@ -392,12 +393,6 @@ public static List<PortalCombo> RandomizePortals(int seed, Dictionary<string, st
string destination = SaveFile.stringStore[key];
Portal portal1 = portalsList.First(portal => portal.Name == origin);
Portal portal2 = portalsList.First(portal => portal.Name == destination);
// if we end up having to redo RandomizePortals during initial generation, we end up adding this portal twice, which breaks stuff
foreach (PortalCombo portalCombo in FoxPrince.FPRandomizedPortals) {
if (portalCombo.Portal1.Name == portal1.Name && portalCombo.Portal2.Name == portal2.Name) {
continue;
}
}
FoxPrince.FPRandomizedPortals.Add(new PortalCombo(portal1, portal2));
}
}
Expand Down Expand Up @@ -452,6 +447,12 @@ public static List<PortalCombo> RandomizePortals(int seed, Dictionary<string, st
}
}

// this is to keep track of how many portals are left in the pool, so we can dynamically reduce the retry count to make late game load choices faster
FoxPrince.PortalsLeftInPool = portalsList.Count + portalsList2.Count;
foreach (KeyValuePair<int, int> kvp in twoPlusPortalDirectionTracker) {
FoxPrince.DirTracker[kvp.Key] = kvp.Value + deadEndPortalDirectionTracker[kvp.Key];
}

// add the plando'd connections to the traversal reqs
foreach (PortalCombo portalCombo in randomizedPortals) {
Portal p1 = portalCombo.Portal1;
Expand Down
25 changes: 23 additions & 2 deletions src/Patches/FoxPrince.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.SceneManagement;
using static TunicRandomizer.ERScripts;
Expand All @@ -18,6 +17,9 @@ public class FoxPrince {
// so we aren't just reading them off the save file every time
// this might be overengineering it though, idk
public static Dictionary<string, string> CachedPlandoPortals = new Dictionary<string, string>();
// these are to see how many portals are left in the pool, so we can reduce the retry count dynamically
public static int PortalsLeftInPool = 440;
public static Dictionary<int, int> DirTracker = new Dictionary<int, int>();

// for use with the pin system
public static string PinnedPortal {
Expand Down Expand Up @@ -144,13 +146,33 @@ void updateDeplando(string pname1, string pname2) {
// we want to fine tune this to try to get 3 different portals when possible, but not take overly long if there aren't 3+ possibilities
int maxTrialCount = 1000;
int trialCount = 0;

// this is a little sloppy, it's mostly so that we update PortalsLeftInPool and DirTracker
List<PortalCombo> portalsForCounting = RandomizePortals(seed, plando, deplando, canFail: true);
// we're adjusting max trial count based on how many potential portals are left in the pool
// in practice, if there's a high portal count left, it'll probably never get through a handful of portals before it gets to 3
// at low portal counts, it'll probably never need more than a few dozen trials
int potentialValidPortalsLeft;
if (GetBool(PortalDirectionPairs)) {
int portalDir = TunicUtils.FindPortalDirectionFromName(currentPortalName);
potentialValidPortalsLeft = DirTracker[TunicUtils.DirectionPairs[portalDir]];
} else {
potentialValidPortalsLeft = PortalsLeftInPool;
}
// this equation is entirely based on vibes
maxTrialCount = potentialValidPortalsLeft * 5 + 20;

while (portalChoices.Count < 3) {
if (trialCount >= maxTrialCount && (portalChoices.Count > 0 || excludedPortals != null)) {
// we've done enough trials to say that we probably won't find any more connections, so it's time to give the player less than 3 choices
// if we don't have any choices yet, keep trying -- if it's failing, we'd wanna know that, but maybe it's just something really restrictive and weird
// if there's excluded portals, that's because they rerolled, so they'll just need to get a set of old portals now
break;
}
if (potentialValidPortalsLeft == portalChoices.Count) {
// we've already found all the portals possible, so let's just break it now and save a quarter second
break;
}
trialCount++;
TunicLogger.LogTesting($"Current trial: {trialCount}");
List<PortalCombo> randomizedPortals = RandomizePortals(seed + trialCount, plando, deplando, canFail: true);
Expand All @@ -165,7 +187,6 @@ void updateDeplando(string pname1, string pname2) {

TunicLogger.LogTesting("portal choice is " + newPortalCombo.Portal2.Name);

// todo: remove this later when confident that it's not going to be a problem
TunicLogger.LogTesting($"Starting check all reachable in trials for {newPortalCombo.Portal2.Name}");
TunicUtils.CheckAllLocsReachable(randomizedPortals);

Expand Down