public void UpdateTransitionStandby(string transition1, string transition2) { bool ableToRelink1; bool ableToRelink2; bool T1InStandby = standbyTransitions.TryGetValue(transition1, out string oldTransition2); bool T2InStandby = standbyTransitions.TryGetValue(transition2, out string oldTransition1); standbyTransitions.Remove(transition1); standbyTransitions.Remove(transition2); if (T1InStandby && oldTransition1 == transition1) { return; // this means t1 and t2 were already linked in standby } if (T1InStandby || T2InStandby) { DirectedTransitions dt = new DirectedTransitions(rand); dt.Add(unplacedTransitions); if (T1InStandby && dt.GetNextTransition(oldTransition2) is string newTransition1) { standbyTransitions[oldTransition2] = newTransition1; standbyTransitions[newTransition1] = oldTransition2; unplacedTransitions.Remove(newTransition1); dt.Remove(newTransition1); ableToRelink1 = true; } else { ableToRelink1 = !T1InStandby; } if (T2InStandby && dt.GetNextTransition(oldTransition1) is string newTransition2) { standbyTransitions[oldTransition1] = newTransition2; standbyTransitions[newTransition2] = oldTransition1; unplacedTransitions.Remove(newTransition2); ableToRelink2 = true; } else { ableToRelink2 = !T2InStandby; } if (T1InStandby && T2InStandby && !ableToRelink1 && !ableToRelink2) { standbyTransitions[oldTransition1] = oldTransition2; standbyTransitions[oldTransition2] = oldTransition1; return; } if (!ableToRelink1 || !ableToRelink2) { LogError("Error encountered in updating standby transitions. Unable to relink after removing standby transition."); Randomizer.randomizationError = true; } } }
private static void PlaceIsolatedTransitions() { if (randomizationError) { return; } List <string> isolatedTransitions = tm.unplacedTransitions.Where(transition => LogicManager.GetTransitionDef(transition).isolated).ToList(); List <string> nonisolatedTransitions = tm.unplacedTransitions.Where(transition => !LogicManager.GetTransitionDef(transition).isolated).ToList(); DirectedTransitions directed = new DirectedTransitions(rand); isolatedTransitions.Remove(startTransition); nonisolatedTransitions.Remove(startTransition); directed.Add(nonisolatedTransitions); bool connectAreas = RandomizerMod.Instance.Settings.ConnectAreas; while (isolatedTransitions.Any()) { string transition1 = isolatedTransitions[rand.Next(isolatedTransitions.Count)]; string transition2 = directed.GetNextTransition(transition1, favorSameArea: connectAreas); if (transition2 is null) { Log("Ran out of nonisolated transitions during preplacement!"); randomizationError = true; return; } tm.PlaceStandbyPair(transition1, transition2); isolatedTransitions.Remove(transition1); directed.Remove(transition2); } }
private static void PlaceOneWayTransitions() { if (randomizationError) { return; } List <string> oneWayEntrances = LogicManager.TransitionNames().Where(transition => LogicManager.GetTransitionDef(transition).oneWay == 1).ToList(); List <string> oneWayExits = LogicManager.TransitionNames().Where(transition => LogicManager.GetTransitionDef(transition).oneWay == 2).ToList(); List <string> horizontalOneWays = oneWayEntrances.Where(t => !LogicManager.GetTransitionDef(t).doorName.StartsWith("b")).ToList(); while (horizontalOneWays.Any()) { string horizontalEntrance = horizontalOneWays.First(); string downExit = oneWayExits[rand.Next(oneWayExits.Count)]; tm.PlaceOneWayPair(horizontalEntrance, downExit); oneWayEntrances.Remove(horizontalEntrance); horizontalOneWays.Remove(horizontalEntrance); oneWayExits.Remove(downExit); } DirectedTransitions directed = new DirectedTransitions(rand); directed.Add(oneWayExits); while (oneWayEntrances.Any()) { string entrance = oneWayEntrances[rand.Next(oneWayEntrances.Count)]; string exit = directed.GetNextTransition(entrance); tm.PlaceOneWayPair(entrance, exit); oneWayEntrances.Remove(entrance); oneWayExits.Remove(exit); directed.Remove(exit); } }
public void UpdateTransitionStandby(string transition1, string transition2) { if (standbyTransitions.TryGetValue(transition1, out string oldTransition2)) { DirectedTransitions dt = new DirectedTransitions(rand); dt.Add(unplacedTransitions); standbyTransitions.Remove(transition1); string newTransition1 = dt.GetNextTransition(oldTransition2); standbyTransitions[oldTransition2] = newTransition1; standbyTransitions.Add(newTransition1, oldTransition2); unplacedTransitions.Remove(newTransition1); } if (standbyTransitions.TryGetValue(transition2, out string oldTransition1)) { DirectedTransitions dt = new DirectedTransitions(rand); dt.Add(unplacedTransitions); standbyTransitions.Remove(transition2); string newTransition2 = dt.GetNextTransition(oldTransition1); standbyTransitions[oldTransition1] = newTransition2; standbyTransitions.Add(newTransition2, oldTransition1); unplacedTransitions.Remove(newTransition2); } }
private static void ConnectStartToGraph() { if (randomizationError) { return; } Log("Attaching start to graph..."); tm.pm = new ProgressionManager( RandomizerState.InProgress ); im.ResetReachableLocations(); vm.ResetReachableLocations(); tm.ResetReachableTransitions(); tm.pm.Add(startProgression); { // keeping local variables out of the way DirectedTransitions d = new DirectedTransitions(rand); d.Add(startTransition); string transition2 = tm.ForceTransition(d); if (transition2 is null) // this should happen extremely rarely, but it has to be handled { Log("No way out of start?!?"); Log("Was the start transition already placed? " + TransitionManager.transitionPlacements.ContainsKey(startTransition)); randomizationError = true; return; } tm.PlaceTransitionPair(startTransition, transition2); } while (true) { if (!RandomizerMod.Instance.Settings.RandomizeSkills) { // it is essentially impossible to generate a transition randomizer without one of these accessible if (tm.pm.CanGet("Mantis_Claw") || tm.pm.CanGet("Mothwing_Cloak") || tm.pm.CanGet("Shade_Cloak")) { return; } } else if (im.FindNextLocation(tm.pm) != null) { return; } tm.UnloadReachableStandby(); List <string> placeableTransitions = tm.reachableTransitions.Intersect(tm.unplacedTransitions.Union(tm.standbyTransitions.Keys)).ToList(); if (!placeableTransitions.Any()) { Log("Could not connect start to map--ran out of placeable transitions."); foreach (string t in tm.reachableTransitions) { Log(t); } randomizationError = true; return; } DirectedTransitions directed = new DirectedTransitions(rand); directed.Add(placeableTransitions); if (tm.ForceTransition(directed) is string transition1) { string transition2 = directed.GetNextTransition(transition1); tm.PlaceTransitionPair(transition1, transition2); } else { Log("Could not connect start to map--ran out of progression transitions."); randomizationError = true; return; } } }