diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/dungeon/pack/DungeonPack.java b/src/main/java/StevenDimDoors/mod_pocketDim/dungeon/pack/DungeonPack.java index af997fa5..44ea2d1f 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/dungeon/pack/DungeonPack.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/dungeon/pack/DungeonPack.java @@ -21,6 +21,7 @@ public class DungeonPack //FIXME: Do not release this code as an update without dealing with disowned types! private static final int MAX_HISTORY_LENGTH = 30; + private static final int MAX_SUBTREE_LIST_SIZE = 30; private final String name; private final HashMap nameToTypeMapping; @@ -136,15 +137,30 @@ public class DungeonPack int maxSearchLength = config.allowDuplicatesInChain() ? maxRuleLength : MAX_HISTORY_LENGTH; ArrayList history = DungeonHelper.getDungeonChainHistory(dimension, this, maxSearchLength); - return getNextDungeon(history, random); + + ArrayList subtreeHistory; + /*if (config.getDuplicateSearchLevels() > 0) + { + subtreeHistory = DungeonHelper.getFlatDungeonTree( + DungeonHelper.getAncestor(dimension, config.getDuplicateSearchLevels()), + MAX_SUBTREE_LIST_SIZE); + } + else + { + subtreeHistory = new ArrayList(); + }*/ + subtreeHistory = new ArrayList(); + + return getNextDungeon(history, subtreeHistory, random); } - private DungeonData getNextDungeon(ArrayList history, Random random) + private DungeonData getNextDungeon(ArrayList history, ArrayList subtreeHistory, Random random) { //Extract the dungeon types that have been used from history and convert them into an array of IDs int index; int[] typeHistory = new int[history.size()]; HashSet excludedDungeons = null; + boolean doExclude = !config.allowDuplicatesInChain() || !subtreeHistory.isEmpty(); for (index = 0; index < typeHistory.length; index++) { typeHistory[index] = history.get(index).dungeonType().ID; @@ -163,9 +179,19 @@ public class DungeonPack if (nextType != null) { //Initialize the set of excluded dungeons if needed - if (excludedDungeons == null && !config.allowDuplicatesInChain()) + if (excludedDungeons == null && doExclude) { - excludedDungeons = new HashSet(history); + if (config.allowDuplicatesInChain()) + { + excludedDungeons = new HashSet(subtreeHistory); + excludedDungeons.addAll(subtreeHistory); + } + else + { + excludedDungeons = new HashSet(2 * (history.size() + subtreeHistory.size())); + excludedDungeons.addAll(history); + excludedDungeons.addAll(subtreeHistory); + } } //List which dungeons are allowed diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/dungeon/pack/DungeonPackConfig.java b/src/main/java/StevenDimDoors/mod_pocketDim/dungeon/pack/DungeonPackConfig.java index 00745450..e5eaa54b 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/dungeon/pack/DungeonPackConfig.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/dungeon/pack/DungeonPackConfig.java @@ -11,6 +11,7 @@ public class DungeonPackConfig private boolean allowPackChangeOut; private boolean distortDoorCoordinates; private int packWeight; + private int duplicateSearchLevels; private ArrayList rules; public DungeonPackConfig() { } @@ -25,6 +26,7 @@ public class DungeonPackConfig this.allowPackChangeOut = source.allowPackChangeOut; this.distortDoorCoordinates = source.distortDoorCoordinates; this.packWeight = source.packWeight; + this.duplicateSearchLevels = source.duplicateSearchLevels; this.rules = (source.rules != null) ? (ArrayList) source.rules.clone() : null; } @@ -114,6 +116,16 @@ public class DungeonPackConfig this.packWeight = packWeight; } + public int getDuplicateSearchLevels() + { + return duplicateSearchLevels; + } + + public void setDuplicateSearchLevels(int duplicateSearchLevels) + { + this.duplicateSearchLevels = duplicateSearchLevels; + } + public boolean doDistortDoorCoordinates() { return distortDoorCoordinates; diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/dungeon/pack/DungeonPackConfigReader.java b/src/main/java/StevenDimDoors/mod_pocketDim/dungeon/pack/DungeonPackConfigReader.java index e24ecc69..0f8b05c0 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/dungeon/pack/DungeonPackConfigReader.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/dungeon/pack/DungeonPackConfigReader.java @@ -35,6 +35,8 @@ public class DungeonPackConfigReader extends BaseConfigurationProcessor= MIN_DUPLICATE_SEARCH_LEVELS && levels <= MAX_DUPLICATE_SEARCH_LEVELS) + { + config.setDuplicateSearchLevels(levels); + } + else + { + valid = false; + } + } else { valid = false; diff --git a/src/main/java/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java b/src/main/java/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java index 545168d7..419ffcd9 100644 --- a/src/main/java/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java +++ b/src/main/java/StevenDimDoors/mod_pocketDim/helpers/DungeonHelper.java @@ -615,7 +615,7 @@ public class DungeonHelper { throw new IllegalArgumentException("dimension cannot be null."); } - if(dimension.parent()==null) + if (dimension.parent() == null) { return new ArrayList(); } @@ -664,4 +664,11 @@ public class DungeonHelper } return dungeons; } + + public static NewDimData getAncestor(NewDimData dimension, int levels) + { + // Find the ancestor of a dimension located a specified number of levels up. + // If such an ancestor does not exist, return the root dimension. + return null; + } } \ No newline at end of file diff --git a/src/main/resources/schematics/ruins/rules.txt b/src/main/resources/schematics/ruins/rules.txt index a14fe17d..06188586 100644 --- a/src/main/resources/schematics/ruins/rules.txt +++ b/src/main/resources/schematics/ruins/rules.txt @@ -16,6 +16,8 @@ DistortDoorCoordinates = true ## Prevent this pack from being selected for transitioning in once we've transitioned out AllowPackChangeIn = false +DuplicateSearchLevels = 1 + Rules: Exit -> DeadEnd Exit