Skip to content

Commit

Permalink
added trial chamber exclusion
Browse files Browse the repository at this point in the history
  • Loading branch information
Greymerk committed Jun 13, 2024
1 parent f30649d commit 0963230
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
import java.util.List;
import java.util.Set;

import com.greymerk.roguelike.debug.Debug;
import com.greymerk.roguelike.editor.Cardinal;
import com.greymerk.roguelike.editor.Coord;
import com.greymerk.roguelike.editor.IWorldEditor;
import com.greymerk.roguelike.editor.boundingbox.BoundingBox;
import com.greymerk.roguelike.editor.boundingbox.IBounded;
import com.greymerk.roguelike.util.StructureLocator;

public class ExclusionZones {

Expand All @@ -32,15 +34,10 @@ public boolean collides(IBounded room) {
}

public void scan(IWorldEditor editor, Coord pos, int range) {
/*
ChunkSet chunks = new ChunkSet(pos, range);
chunks.forEach(cpos -> {
if(StructureLocator.hasVillage(editor.getSeed(), cpos)) {
Coord village = Coord.of(cpos.getCenterAtY(0));
this.add(village, 128);
Debug.info("village @: " + village);
}
Set<Coord> trialChambers = StructureLocator.scan(editor.getSeed(), pos, StructureLocator.TRIAL_CHAMBER, range);
trialChambers.forEach(c -> {
this.add(c, 200);
Debug.info("Chamber @" + c);
});
*/
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.greymerk.roguelike.config.Config;
import com.greymerk.roguelike.debug.Debug;
import com.greymerk.roguelike.debug.DebugLayout;
import com.greymerk.roguelike.dungeon.Dungeon;
import com.greymerk.roguelike.dungeon.Floor;
Expand Down Expand Up @@ -38,7 +37,6 @@ public LayoutManager(Coord origin) {
this.floors = createFloors();
this.settings = new DungeonSettingsDefault();
this.zones = new ExclusionZones();
//this.zones.add(BoundingBox.of(new Coord(-150, 0, 50)).grow(Cardinal.all, 200));
}

public void generate(IWorldEditor editor) {
Expand Down Expand Up @@ -89,7 +87,7 @@ private void placeRoom(IRoom room, Random rand, Floor floor) {
for(Cardinal dir : dirs) {
Coord wp = potential.getWorldPos(floor.getOrigin());
if(zones.collides(room.getBoundingBox(wp, dir))) {
Debug.info("colliding at " + wp);
//Debug.info("colliding at " + wp);
continue;
}
CellManager rcm = room.getCells(dir);
Expand Down
39 changes: 11 additions & 28 deletions src/main/java/com/greymerk/roguelike/util/StructureLocator.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
package com.greymerk.roguelike.util;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.HashSet;
import java.util.Set;

import com.greymerk.roguelike.editor.Cardinal;
import com.greymerk.roguelike.editor.Coord;
import com.greymerk.roguelike.editor.IWorldEditor;
import com.greymerk.roguelike.editor.boundingbox.BoundingBox;

import net.minecraft.util.math.ChunkPos;
import net.minecraft.util.math.random.CheckedRandom;
Expand All @@ -16,11 +12,7 @@

public enum StructureLocator {

VILLAGE;

public static Coord locate(IWorldEditor editor, StructureLocator type, Coord pos, int radius) {
return search(editor.getSeed(), VILLAGE, pos, radius);
}
VILLAGE, TRIAL_CHAMBER;

public static boolean hasVillage(long seed, ChunkPos cpos) {
return hasStructure(seed, VILLAGE, cpos);
Expand All @@ -29,6 +21,7 @@ public static boolean hasVillage(long seed, ChunkPos cpos) {
public static boolean hasStructure(long seed, StructureLocator type, ChunkPos cpos) {
switch(type) {
case VILLAGE: return hasRandomScatteredStructure(seed, cpos, 34, 8, SpreadType.LINEAR, 10387312);
case TRIAL_CHAMBER: return hasRandomScatteredStructure(seed, cpos, 34, 12, SpreadType.LINEAR, 94251327);
default: return false;
}
}
Expand All @@ -49,26 +42,16 @@ public static boolean hasConcentricRingStructure(long seed, ChunkPos cpos) {
return false;
}

public static Coord search(long seed, StructureLocator type, Coord pos, int radius) {
ChunkPos cpos = pos.getChunkPos();

List<Coord> locations = new ArrayList<Coord>();

BoundingBox.of(new Coord(cpos.x, 0, cpos.z))
.grow(Cardinal.directions, radius)
.forEach(c -> {
ChunkPos cp = new ChunkPos(c.getX(), c.getZ());
if(hasStructure(seed, type, cp)) {
locations.add(Coord.of(cp));
}
});
public static Set<Coord> scan(long seed, Coord origin, StructureLocator type, int range) {
Set<Coord> locations = new HashSet<Coord>();

locations.sort(new Comparator<Coord>() {
public int compare(Coord a, Coord b) {
return (int)a.distance(pos) - (int)b.distance(pos);
ChunkSet chunks = new ChunkSet(origin, range);
chunks.forEach(cpos -> {
if(hasStructure(seed, type, cpos)) {
locations.add(Coord.of(cpos.getCenterAtY(0)));
}
});

return locations.getFirst();
return locations;
}
}
39 changes: 39 additions & 0 deletions src/test/com/greymerk/roguelike/util/StructureLocatorTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.greymerk.roguelike.util;

import java.util.Set;

import org.junit.jupiter.api.Test;

import com.greymerk.roguelike.editor.Coord;

class StructureLocatorTest {

@Test
void testHasStructure() {

long seed = 118167;

assert(StructureLocator.hasStructure(seed, StructureLocator.VILLAGE, new Coord(112, 0, 48).getChunkPos()));

assert(!StructureLocator.hasStructure(seed, StructureLocator.VILLAGE, new Coord(150, 0, 48).getChunkPos()));

assert(StructureLocator.hasStructure(seed, StructureLocator.TRIAL_CHAMBER, new Coord(336, 0, 336).getChunkPos()));

assert(!StructureLocator.hasStructure(seed, StructureLocator.TRIAL_CHAMBER, new Coord(300, 0, 336).getChunkPos()));
}

@Test
void testScan() {
long seed = 118167;

Coord origin = new Coord(336, 0 , 336).freeze();

Set<Coord> locations = StructureLocator.scan(seed, origin, StructureLocator.TRIAL_CHAMBER, 100);

locations.forEach(pos -> {
System.out.println(pos);
});

assert(locations.contains(Coord.of(origin.getChunkPos().getCenterAtY(0))));
}
}

0 comments on commit 0963230

Please sign in to comment.