diff --git a/src/Patches/ERScripts.cs b/src/Patches/ERScripts.cs index 7895055d..733975a5 100644 --- a/src/Patches/ERScripts.cs +++ b/src/Patches/ERScripts.cs @@ -1,4 +1,5 @@ -using System; +using JetBrains.Annotations; +using System; using System.Collections.Generic; using System.Linq; using UnityEngine; @@ -392,12 +393,6 @@ public static List RandomizePortals(int seed, Dictionary 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)); } } @@ -452,6 +447,12 @@ public static List RandomizePortals(int seed, Dictionary 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; diff --git a/src/Patches/FoxPrince.cs b/src/Patches/FoxPrince.cs index d7b48fa0..8a7ee104 100644 --- a/src/Patches/FoxPrince.cs +++ b/src/Patches/FoxPrince.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; using UnityEngine; using UnityEngine.SceneManagement; using static TunicRandomizer.ERScripts; @@ -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 CachedPlandoPortals = new Dictionary(); + // 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 DirTracker = new Dictionary(); // for use with the pin system public static string PinnedPortal { @@ -144,6 +146,22 @@ 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 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 @@ -151,6 +169,10 @@ void updateDeplando(string pname1, string pname2) { // 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 randomizedPortals = RandomizePortals(seed + trialCount, plando, deplando, canFail: true); @@ -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);