Search in sources :

Example 1 with BlockedConnectorStrategy

use of ivorius.reccomplex.world.gen.feature.structure.generic.maze.rules.BlockedConnectorStrategy in project RecurrentComplex by Ivorforce.

the class WorldScriptMazeGenerator method getPlacedRooms.

public List<PlacedMazeComponent<MazeComponentStructure<Connector>, Connector>> getPlacedRooms(Random random, AxisAlignedTransform2D transform, Environment environment) {
    if (mazeComponent.rooms.isEmpty())
        return null;
    ConnectorFactory factory = new ConnectorFactory();
    Connector wallConnector = factory.get(ConnectorStrategy.DEFAULT_WALL);
    Connector defaultConnector = mazeComponent.defaultConnector.toConnector(factory);
    // TODO Make configurable
    Set<Connector> blockedConnections = Collections.singleton(wallConnector);
    int[] boundsHigher = mazeComponent.rooms.boundsHigher();
    int[] boundsLower = mazeComponent.rooms.boundsLower();
    int[] oneArray = new int[boundsHigher.length];
    Arrays.fill(oneArray, 1);
    final int[] outsideBoundsHigher = IvVecMathHelper.add(boundsHigher, oneArray);
    final int[] outsideBoundsLower = IvVecMathHelper.sub(boundsLower, oneArray);
    List<MazeComponentStructure<Connector>> transformedComponents = StructureRegistry.INSTANCE.getStructuresInMaze(mazeID).flatMap(pair -> pair.getLeft().declaredVariables().omega(environment, true).flatMap(domain -> WorldGenMaze.transforms(pair.getLeft(), pair.getRight(), transform, factory, environment.copy(domain), blockedConnections))).collect(Collectors.toList());
    MorphingMazeComponent<Connector> maze = new SetMazeComponent<>();
    WorldScriptMazeGenerator.enclose(maze, new MazeRoom(outsideBoundsLower), new MazeRoom(outsideBoundsHigher), defaultConnector);
    WorldScriptMazeGenerator.blockRooms(maze, mazeComponent.rooms.compile(false).keySet(), defaultConnector);
    WorldGenMaze.buildExitPaths(environment, factory, mazeComponent.exitPaths, maze.rooms()).forEach(path -> maze.exits().put(path.getKey(), path.getValue()));
    // Add reachability outside the maze
    maze.reachability().putAll(WorldGenMaze.addExternalReachability(ImmutableListMultimap.builder(), maze.exits(), blockedConnections).build());
    // Add reachability between exits
    maze.reachability().putAll(mazeComponent.reachability.build(ImmutableListMultimap.builder(), AxisAlignedTransform2D.ORIGINAL, mazeComponent.boundsSize(), SavedMazeReachability.notBlocked(blockedConnections, maze.exits()), maze.exits().keySet()).build());
    ConnectorStrategy connectorStrategy = new ConnectorStrategy();
    List<MazePredicate<Connector>> predicates = rules.stream().map(r -> r.build(this, blockedConnections, factory, transformedComponents, connectorStrategy)).filter(Objects::nonNull).collect(Collectors.toCollection(ArrayList::new));
    predicates.add(new LimitAABBStrategy<>(outsideBoundsHigher));
    predicates.add(new BlockedConnectorStrategy<>(blockedConnections));
    int totalRooms = mazeComponent.rooms.compile(true).size();
    return MazeComponentConnector.connect(maze, transformedComponents, connectorStrategy, new MazePredicateMany<>(predicates), random, RCConfig.mazePlacementReversesPerRoom >= 0 ? MathHelper.floor(totalRooms * RCConfig.mazePlacementReversesPerRoom + 0.5f) : MazeComponentConnector.INFINITE_REVERSES);
}
Also used : IvTranslations(ivorius.ivtoolkit.tools.IvTranslations) NBTTagLists(ivorius.ivtoolkit.tools.NBTTagLists) java.util(java.util) TIntArrayList(gnu.trove.list.array.TIntArrayList) AxisAlignedTransform2D(ivorius.ivtoolkit.math.AxisAlignedTransform2D) Constants(net.minecraftforge.common.util.Constants) StructureSpawnContext(ivorius.reccomplex.world.gen.feature.structure.context.StructureSpawnContext) StructureRegistry(ivorius.reccomplex.world.gen.feature.structure.StructureRegistry) TableDataSource(ivorius.reccomplex.gui.table.datasource.TableDataSource) RCConfig(ivorius.reccomplex.RCConfig) Environment(ivorius.reccomplex.world.gen.feature.structure.Environment) MazeRule(ivorius.reccomplex.world.gen.feature.structure.generic.maze.rules.MazeRule) NBTTagList(net.minecraft.nbt.NBTTagList) IvNBTHelper(ivorius.ivtoolkit.tools.IvNBTHelper) NBTStorable(ivorius.reccomplex.nbt.NBTStorable) IvVecMathHelper(ivorius.ivtoolkit.math.IvVecMathHelper) IntAreas(ivorius.reccomplex.utils.IntAreas) BlockedConnectorStrategy(ivorius.reccomplex.world.gen.feature.structure.generic.maze.rules.BlockedConnectorStrategy) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) StructureLoadContext(ivorius.reccomplex.world.gen.feature.structure.context.StructureLoadContext) ivorius.reccomplex.world.gen.feature.structure.generic.maze(ivorius.reccomplex.world.gen.feature.structure.generic.maze) StructurePrepareContext(ivorius.reccomplex.world.gen.feature.structure.context.StructurePrepareContext) NBTBase(net.minecraft.nbt.NBTBase) BlockPositions(ivorius.ivtoolkit.blocks.BlockPositions) BlockPos(net.minecraft.util.math.BlockPos) Selection(ivorius.reccomplex.world.gen.feature.structure.generic.Selection) Collectors(java.util.stream.Collectors) TableNavigator(ivorius.reccomplex.gui.table.TableNavigator) LimitAABBStrategy(ivorius.reccomplex.world.gen.feature.structure.generic.maze.rules.LimitAABBStrategy) MathHelper(net.minecraft.util.math.MathHelper) ImmutableListMultimap(com.google.common.collect.ImmutableListMultimap) TableDataSourceWorldScriptMazeGenerator(ivorius.reccomplex.gui.worldscripts.mazegenerator.TableDataSourceWorldScriptMazeGenerator) ivorius.ivtoolkit.maze.components(ivorius.ivtoolkit.maze.components) MazeRuleRegistry(ivorius.reccomplex.world.gen.feature.structure.generic.maze.rules.MazeRuleRegistry) TableDelegate(ivorius.reccomplex.gui.table.TableDelegate) NBTCompoundObjects(ivorius.ivtoolkit.tools.NBTCompoundObjects) BlockedConnectorStrategy(ivorius.reccomplex.world.gen.feature.structure.generic.maze.rules.BlockedConnectorStrategy)

Aggregations

ImmutableListMultimap (com.google.common.collect.ImmutableListMultimap)1 TIntArrayList (gnu.trove.list.array.TIntArrayList)1 BlockPositions (ivorius.ivtoolkit.blocks.BlockPositions)1 AxisAlignedTransform2D (ivorius.ivtoolkit.math.AxisAlignedTransform2D)1 IvVecMathHelper (ivorius.ivtoolkit.math.IvVecMathHelper)1 ivorius.ivtoolkit.maze.components (ivorius.ivtoolkit.maze.components)1 IvNBTHelper (ivorius.ivtoolkit.tools.IvNBTHelper)1 IvTranslations (ivorius.ivtoolkit.tools.IvTranslations)1 NBTCompoundObjects (ivorius.ivtoolkit.tools.NBTCompoundObjects)1 NBTTagLists (ivorius.ivtoolkit.tools.NBTTagLists)1 RCConfig (ivorius.reccomplex.RCConfig)1 TableDelegate (ivorius.reccomplex.gui.table.TableDelegate)1 TableNavigator (ivorius.reccomplex.gui.table.TableNavigator)1 TableDataSource (ivorius.reccomplex.gui.table.datasource.TableDataSource)1 TableDataSourceWorldScriptMazeGenerator (ivorius.reccomplex.gui.worldscripts.mazegenerator.TableDataSourceWorldScriptMazeGenerator)1 NBTStorable (ivorius.reccomplex.nbt.NBTStorable)1 IntAreas (ivorius.reccomplex.utils.IntAreas)1 Environment (ivorius.reccomplex.world.gen.feature.structure.Environment)1 StructureRegistry (ivorius.reccomplex.world.gen.feature.structure.StructureRegistry)1 StructureLoadContext (ivorius.reccomplex.world.gen.feature.structure.context.StructureLoadContext)1