Skip to content

Commit

Permalink
Dungeons and Themes refactor
Browse files Browse the repository at this point in the history
- Changed some stuff
  • Loading branch information
Greymerk committed Jun 9, 2014
1 parent 84ae4ce commit 159a92b
Show file tree
Hide file tree
Showing 35 changed files with 596 additions and 439 deletions.
5 changes: 3 additions & 2 deletions greymerk/roguelike/catacomb/Catacomb.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import greymerk.roguelike.catacomb.dungeon.IDungeonFactory;
import greymerk.roguelike.catacomb.dungeon.RoomSet;
import greymerk.roguelike.catacomb.theme.ITheme;
import greymerk.roguelike.catacomb.theme.Themes;
import greymerk.roguelike.catacomb.theme.Theme;
import greymerk.roguelike.config.RogueConfig;
import greymerk.roguelike.worldgen.Coord;
import greymerk.roguelike.worldgen.WorldGenPrimitive;
Expand All @@ -22,6 +22,7 @@ public class Catacomb {
public static final int DEPTH = 5;
public static final int VERTICAL_SPACING = 10;
public static final int TOPLEVEL = 50;
public static final int NUM_LEVELS = 5;

public static void generateNear(World world, Random rand, int x, int z){
int attempts = 50;
Expand Down Expand Up @@ -49,7 +50,7 @@ public static void generate(World world, int inX, int inZ){
CatacombLevel level;

ITheme theme = DungeonCustomization.getTheme(world.getBiomeGenForCoords(inX, inZ), getLevel(y));
if(theme == null) theme = Themes.getByLevel(world.getBiomeGenForCoords(inX, inZ), getLevel(y));
if(theme == null) theme = Theme.getByLevel(world.getBiomeGenForCoords(inX, inZ), getLevel(y));
IDungeonFactory rooms = DungeonCustomization.getRooms(world.getBiomeGenForCoords(inX, inZ), getLevel(y));
if(rooms == null) rooms = DungeonFactoryProvider.getByLevel(Catacomb.getLevel(y));

Expand Down
22 changes: 13 additions & 9 deletions greymerk/roguelike/catacomb/CatacombTower.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

import greymerk.roguelike.catacomb.dungeon.DungeonCustomization;
import greymerk.roguelike.catacomb.theme.ITheme;
import greymerk.roguelike.catacomb.theme.Themes;
import greymerk.roguelike.catacomb.theme.Theme;
import greymerk.roguelike.config.RogueConfig;
import greymerk.roguelike.treasure.TreasureChest;
import greymerk.roguelike.treasure.TreasureChestStarter;
import greymerk.roguelike.worldgen.BlockWeightedRandom;
import greymerk.roguelike.worldgen.Cardinal;
Expand Down Expand Up @@ -68,7 +69,7 @@ private Coord getBaseCoord(World world, int x, int y, int z){
public void generate(World world, Random rand, int x, int y, int z){

ITheme theme = DungeonCustomization.getTheme(world.getBiomeGenForCoords(x, z), 0);
if(theme == null) theme = Themes.getByLevel(world.getBiomeGenForCoords(x, z), 0);
if(theme == null) theme = Theme.getByLevel(world.getBiomeGenForCoords(x, z), 0);


MetaBlock air = new MetaBlock(0);
Expand All @@ -90,7 +91,7 @@ public void generate(World world, Random rand, int x, int y, int z){
Coord end;
Coord cursor;

WorldGenPrimitive.fillRectSolid(world, rand, x - 3, main, z - 3, x + 3, main, z + 3, new MetaBlock(Block.planks.blockID, 1), true, true);
WorldGenPrimitive.fillRectSolid(world, rand, x - 3, main, z - 3, x + 3, main, z + 3, theme.getSecondaryWall(), true, true);
WorldGenPrimitive.fillRectSolid(world, rand, x - 3, roof, z - 3, x + 3, roof, z + 3, blocks, true, true);

for(Cardinal dir : Cardinal.directions){
Expand Down Expand Up @@ -246,13 +247,16 @@ public void generate(World world, Random rand, int x, int y, int z){
cursor.add(orth, 2);
WorldGenPrimitive.setBlock(world, rand, cursor, new MetaBlock(Block.fenceIron.blockID), true, true);
}



for(int i = main; i > y; --i){
WorldGenPrimitive.spiralStairStep(world, rand, x, i, z, stair, theme.getPrimaryPillar());
}
}

for(int i = main; i > y; --i){
WorldGenPrimitive.spiralStairStep(world, rand, x, i, z, stair, theme.getPrimaryPillar());
}

cursor = new Coord(x, main + 1, z);
cursor.add(Cardinal.NORTH, 3);
cursor.add(Cardinal.EAST, 1);
TreasureChest.generate(world, rand, cursor, TreasureChest.STARTER);
}


Expand Down
4 changes: 2 additions & 2 deletions greymerk/roguelike/catacomb/CatacombTunneler.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import greymerk.roguelike.catacomb.segment.ISegment;
import greymerk.roguelike.catacomb.segment.Segment;
import greymerk.roguelike.catacomb.theme.ITheme;
import greymerk.roguelike.catacomb.theme.Themes;
import greymerk.roguelike.catacomb.theme.Theme;
import greymerk.roguelike.worldgen.BlockJumble;
import greymerk.roguelike.worldgen.BlockWeightedRandom;
import greymerk.roguelike.worldgen.Cardinal;
Expand Down Expand Up @@ -154,7 +154,7 @@ public void construct(World world){
public void addSegments(World world){

for(Coord location : tunnel){
theme.genSegment(world, rand, level, dir, theme, location);
theme.genSegment(world, rand, level, dir, location);
}
}
}
27 changes: 21 additions & 6 deletions greymerk/roguelike/catacomb/dungeon/DungeonCustomization.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
package greymerk.roguelike.catacomb.dungeon;

import greymerk.roguelike.catacomb.Catacomb;
import greymerk.roguelike.catacomb.theme.ITheme;
import greymerk.roguelike.catacomb.theme.Themes;
import greymerk.roguelike.catacomb.theme.Theme;
import greymerk.roguelike.config.RogueConfig;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import net.minecraft.src.BiomeGenBase;

import com.google.common.base.Charsets;
import com.google.common.io.Files;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

import net.minecraft.src.BiomeGenBase;

public class DungeonCustomization {

private static List<Customization> customizations = new ArrayList<Customization>();
Expand Down Expand Up @@ -47,6 +48,7 @@ private static Customization getCustomization(BiomeGenBase biome){
Customization toReturn;

for(Customization custom : customizations){
if(custom.global) return custom;
if(custom.match(biome.biomeName)) return custom;
}

Expand Down Expand Up @@ -79,6 +81,7 @@ private static void init() throws Exception{

private static class Customization{

private boolean global;
private List<String> biomes;
private List<ITheme> theme;
private List<IDungeonFactory> rooms;
Expand All @@ -93,7 +96,13 @@ public Customization(JsonObject json) throws Exception{
rooms.add(null);
}

if(json.has("biomes")) parseBiomes(json.get("biomes").getAsJsonArray());
if(json.get("biomes") instanceof JsonArray){
global = false;
parseBiomes(json.get("biomes").getAsJsonArray());
} else if(json.get("biomes").getAsString().equals("all")){
global = true;
}

if(json.has("levels")) parseLevels(json.get("levels").getAsJsonObject());
}

Expand All @@ -104,7 +113,13 @@ private void parseBiomes(JsonArray json){
}

private void parseLevels(JsonObject json) throws Exception{
for(int i = 0; i < 5; ++i){
if(json.has("all")){
for(int i = 0; i < Catacomb.NUM_LEVELS; ++i){
parseLevel(json.get("all").getAsJsonObject(), i);
}
}

for(int i = 0; i < Catacomb.NUM_LEVELS; ++i){
String level = Integer.toString(i);
if(json.has(level)) parseLevel(json.get(level).getAsJsonObject(), i);
}
Expand All @@ -113,7 +128,7 @@ private void parseLevels(JsonObject json) throws Exception{
private void parseLevel(JsonObject json, int level) throws Exception{
if(json.has("theme")){
JsonObject themeData = json.get("theme").getAsJsonObject();
theme.set(level, Themes.create(themeData));
theme.set(level, Theme.create(themeData));
}

if(json.has("rooms")){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ public static IDungeonFactory getFactory(DungeonFactoryProvider type){
factory = new DungeonFactory();
factory.addSecret(Dungeon.SLIME, 5);
factory.addSecret(Dungeon.FIRE, 10);
factory.addRandom(Dungeon.BRICK, 1);
factory.addSingle(Dungeon.CAKE);
factory.addRandom(Dungeon.BRICK, 10);
factory.addRandom(Dungeon.CORNER, 3);
break;
case SPRUCE:
factory = new DungeonFactory();
factory.addSecret(Dungeon.CORNER, 50);
factory.addSecret(Dungeon.CORNER, 40);
factory.addSecret(Dungeon.ETHO, 10);
factory.addSecret(Dungeon.BTEAM, 10);
factory.addSecret(Dungeon.AVIDYA, 10);
Expand Down
31 changes: 17 additions & 14 deletions greymerk/roguelike/catacomb/dungeon/room/DungeonBTeam.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ public boolean generate(World world, Random rand, ITheme theme, int x, int y, in

MetaBlock cocao = new MetaBlock(Block.cocoaPlant.blockID, 9);
WorldGenPrimitive.setBlock(world, x - 5, y + 2, z - 2, Log.getLog(Log.JUNGLE, Cardinal.EAST));
WorldGenPrimitive.setBlock(world, x - 4, y + 2, z - 2, cocao, true, true);
cocao.setBlock(world, x - 4, y + 2, z - 2);
WorldGenPrimitive.setBlock(world, x - 5, y + 2, z + 3, Log.getLog(Log.JUNGLE, Cardinal.EAST));
WorldGenPrimitive.setBlock(world, x - 4, y + 2, z + 3, cocao, true, true);
cocao.setBlock(world, x - 4, y + 2, z + 3);

lamp(world, x - 2, y, z - 4);
lamp(world, x + 2, y, z - 4);
Expand All @@ -83,10 +83,10 @@ public boolean generate(World world, Random rand, ITheme theme, int x, int y, in
WorldGenPrimitive.fillRectSolid(world, rand, x + 5, y, z - 1, x + 5, y + 4, z - 1, greenBlock, true, true);
WorldGenPrimitive.fillRectSolid(world, rand, x + 5, y, z, x + 5, y, z + 1, greenBlock, true, true);
WorldGenPrimitive.fillRectSolid(world, rand, x + 5, y + 1, z, x + 5, y + 1, z + 1, 0);
WorldGenPrimitive.setBlock(world, x + 5, y + 1, z + 2, greenBlock, true, true);
greenBlock.setBlock(world, x + 5, y + 1, z + 2);
WorldGenPrimitive.fillRectSolid(world, rand, x + 5, y + 2, z, x + 5, y + 2, z + 1, greenBlock, true, true);
WorldGenPrimitive.fillRectSolid(world, rand, x + 5, y + 3, z, x + 5, y + 3, z + 1, 0);
WorldGenPrimitive.setBlock(world, x + 5, y + 3, z + 2, greenBlock, true, true);
greenBlock.setBlock(world, x + 5, y + 3, z + 2);
WorldGenPrimitive.fillRectSolid(world, rand, x + 5, y + 4, z, x + 5, y + 4, z + 1, greenBlock, true, true);

// roof
Expand All @@ -111,11 +111,14 @@ public boolean generate(World world, Random rand, ITheme theme, int x, int y, in
WorldGenPrimitive.fillRectSolid(world, rand, x - 1, y, z, x + 1, y, z + 1, spruceSlabUpsideDown, true, true);

// chairs
WorldGenPrimitive.setBlock(world, x - 1, y, z - 2, new MetaBlock(Block.stairsNetherBrick.blockID, WorldGenPrimitive.blockOrientation(Cardinal.SOUTH, false)), true, true);
WorldGenPrimitive.setBlock(world, x + 1, y, z - 2, new MetaBlock(Block.stairsNetherBrick.blockID, WorldGenPrimitive.blockOrientation(Cardinal.SOUTH, false)), true, true);
MetaBlock chair = new MetaBlock(Block.stairsNetherBrick.blockID);
chair.setMeta(WorldGenPrimitive.blockOrientation(Cardinal.SOUTH, false));
chair.setBlock(world, x - 1, y, z - 2);
chair.setBlock(world, x + 1, y, z - 2);

WorldGenPrimitive.setBlock(world, x - 1, y, z + 3, new MetaBlock(Block.stairsNetherBrick.blockID, WorldGenPrimitive.blockOrientation(Cardinal.NORTH, false)), true, true);
WorldGenPrimitive.setBlock(world, x + 1, y, z + 3, new MetaBlock(Block.stairsNetherBrick.blockID, WorldGenPrimitive.blockOrientation(Cardinal.NORTH, false)), true, true);
chair.setMeta(WorldGenPrimitive.blockOrientation(Cardinal.NORTH, false));
chair.setBlock(world, x - 1, y, z + 3);
chair.setBlock(world, x + 1, y, z + 3);

// wall entrances
WorldGenPrimitive.fillRectSolid(world, rand, x - 7, y - 1, z - 4, x - 6, y + 4, z + 4, Block.stoneBrick.blockID);
Expand Down Expand Up @@ -163,21 +166,21 @@ public boolean generate(World world, Random rand, ITheme theme, int x, int y, in

private static void lamp(World world, int x, int y, int z){
MetaBlock spruce = new MetaBlock(Block.planks.blockID, 1);
WorldGenPrimitive.setBlock(world, x, y + 4, z, spruce, true, true);
spruce.setBlock(world, x, y + 4, z);
WorldGenPrimitive.setBlock(world, x, y + 3, z, Block.fence.blockID);

WorldGenPrimitive.setBlock(world, x, y + 2, z, Block.glowStone.blockID);
MetaBlock fence = new MetaBlock(Block.trapdoor.blockID, 4);
WorldGenPrimitive.setBlock(world, x, y + 2, z - 1, fence, true, false);
fence.setBlock(world, x, y + 2, z - 1);
fence.setMeta(5);
WorldGenPrimitive.setBlock(world, x, y + 2, z + 1, fence, true, false);
fence.setBlock(world, x, y + 2, z + 1);
fence.setMeta(6);
WorldGenPrimitive.setBlock(world, x - 1, y + 2, z, fence, true, false);
fence.setBlock(world, x - 1, y + 2, z);
fence.setMeta(7);
WorldGenPrimitive.setBlock(world, x + 1, y + 2, z, fence, true, false);
fence.setBlock(world, x + 1, y + 2, z);

WorldGenPrimitive.setBlock(world, x, y + 1, z, Block.fence.blockID);
WorldGenPrimitive.setBlock(world, x, y, z, spruce, true, true);
spruce.setBlock(world, x, y, z);
}

public int getSize(){
Expand Down
84 changes: 41 additions & 43 deletions greymerk/roguelike/catacomb/dungeon/room/DungeonCorner.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import greymerk.roguelike.catacomb.dungeon.IDungeon;
import greymerk.roguelike.catacomb.theme.ITheme;
import greymerk.roguelike.worldgen.Cardinal;
import greymerk.roguelike.worldgen.Coord;
import greymerk.roguelike.worldgen.IBlockFactory;
import greymerk.roguelike.worldgen.MetaBlock;
import greymerk.roguelike.worldgen.WorldGenPrimitive;
Expand All @@ -15,59 +16,56 @@

public class DungeonCorner implements IDungeon {

World world;
Random rand;
int originX;
int originY;
int originZ;

@Override
public boolean generate(World inWorld, Random inRandom, ITheme theme, int inOriginX, int inOriginY, int inOriginZ) {

world = inWorld;
rand = inRandom;
originX = inOriginX;
originY = inOriginY;
originZ = inOriginZ;

MetaBlock southStair = theme.getPrimaryStair();
southStair.setMeta(WorldGenPrimitive.blockOrientation(Cardinal.SOUTH, true));
MetaBlock northStair = theme.getPrimaryStair();
northStair.setMeta(WorldGenPrimitive.blockOrientation(Cardinal.NORTH, true));
MetaBlock eastStair = theme.getPrimaryStair();
eastStair.setMeta(WorldGenPrimitive.blockOrientation(Cardinal.EAST, true));
MetaBlock westStair = theme.getPrimaryStair();
westStair.setMeta(WorldGenPrimitive.blockOrientation(Cardinal.WEST, true));
public boolean generate(World world, Random rand, ITheme theme, int x, int y, int z) {

MetaBlock stair = theme.getPrimaryStair();
IBlockFactory blocks = theme.getPrimaryWall();
IBlockFactory pillar = theme.getPrimaryPillar();

// fill air inside
WorldGenPrimitive.fillRectSolid(world, rand, originX - 2, originY, originZ - 2, originX + 2, originY + 3, originZ + 2, 0);
WorldGenPrimitive.fillRectSolid(world, rand, x - 2, y, z - 2, x + 2, y + 3, z + 2, 0);

// shell
WorldGenPrimitive.fillRectHollow(world, rand, originX - 3, originY - 1, originZ - 3, originX + 3, originY + 4, originZ + 3, blocks, false, true);
WorldGenPrimitive.fillRectHollow(world, rand, x - 3, y - 1, z - 3, x + 3, y + 4, z + 3, blocks, false, true);

// pillars
WorldGenPrimitive.fillRectSolid(world, rand, originX - 2, originY, originZ - 2, originX - 2, originY + 3, originZ - 2, blocks, true, true);
WorldGenPrimitive.setBlock(world, rand, originX - 2, originY + 3, originZ - 1, southStair, true, true);
WorldGenPrimitive.setBlock(world, originX - 1, originY + 3, originZ - 2, eastStair, true, true);
WorldGenPrimitive.fillRectSolid(world, rand, originX - 2, originY, originZ + 2, originX - 2, originY + 3, originZ + 2, blocks, true, true);
WorldGenPrimitive.setBlock(world, originX - 1, originY + 3, originZ + 2, eastStair, true, true);
WorldGenPrimitive.setBlock(world, originX - 2, originY + 3, originZ + 1, northStair, true, true);
WorldGenPrimitive.fillRectSolid(world, rand, originX + 2, originY, originZ - 2, originX + 2, originY + 3, originZ - 2, blocks, true, true);
WorldGenPrimitive.setBlock(world, originX + 1, originY + 3, originZ - 2, westStair, true, true);
WorldGenPrimitive.setBlock(world, originX + 2, originY + 3, originZ - 1, southStair, true, true);
WorldGenPrimitive.fillRectSolid(world, rand, originX + 2, originY, originZ + 2, originX + 2, originY + 3, originZ + 2, blocks, true, true);
WorldGenPrimitive.setBlock(world, originX + 1, originY + 3, originZ + 2, westStair, true, true);
WorldGenPrimitive.setBlock(world, originX + 2, originY + 3, originZ + 1, northStair, true, true);
Coord start;
Coord end;
Coord cursor;

WorldGenPrimitive.setBlock(world, originX - 1, originY + 4, originZ, eastStair, false, true);
WorldGenPrimitive.setBlock(world, originX + 1, originY + 4, originZ, westStair, false, true);
WorldGenPrimitive.setBlock(world, originX, originY + 4, originZ - 1, southStair, false, true);
WorldGenPrimitive.setBlock(world, originX, originY + 4, originZ + 1, northStair, false, true);
cursor = new Coord(x, y, z);
cursor.add(Cardinal.UP, 4);
WorldGenPrimitive.setBlock(world, cursor, 0);
cursor.add(Cardinal.UP, 1);
WorldGenPrimitive.setBlock(world, rand, cursor, blocks, true, true);

WorldGenPrimitive.setBlock(world, originX, originY + 4, originZ, 0);
blocks.setBlock(world, rand, originX, originY + 5, originZ, false, true);
for(Cardinal dir : Cardinal.directions){

cursor = new Coord(x, y, z);
cursor.add(dir, 2);
cursor.add(Cardinal.getOrthogonal(dir)[0], 2);
start = new Coord(cursor);
cursor.add(Cardinal.UP, 2);
end = new Coord(cursor);
WorldGenPrimitive.fillRectSolid(world, rand, start, end, pillar, true, true);
cursor.add(Cardinal.UP, 1);
WorldGenPrimitive.setBlock(world, rand, cursor, blocks, true, true);

cursor = new Coord(x, y, z);
cursor.add(dir, 1);
cursor.add(Cardinal.UP, 4);
stair.setMeta(WorldGenPrimitive.blockOrientation(Cardinal.reverse(dir), true));
WorldGenPrimitive.setBlock(world, rand, cursor, stair, true, true);

for(Cardinal orth : Cardinal.getOrthogonal(dir)){
cursor = new Coord(x, y, z);
cursor.add(dir, 2);
cursor.add(orth, 1);
cursor.add(Cardinal.UP, 3);
stair.setMeta(WorldGenPrimitive.blockOrientation(Cardinal.reverse(orth), true));
WorldGenPrimitive.setBlock(world, rand, cursor, stair, true, true);
}
}

return true;
}
Expand Down
11 changes: 6 additions & 5 deletions greymerk/roguelike/catacomb/dungeon/room/DungeonLab.java
Original file line number Diff line number Diff line change
Expand Up @@ -224,16 +224,17 @@ private static void northEast(World world, Random rand, ITheme theme, int x, int

private static void pillar(World world, Random rand, ITheme theme, int x, int y, int z){

WorldGenPrimitive.fillRectSolid(world, rand, x, y, z, x, y + 3, z, theme.getSecondaryPillar(), true, true);
WorldGenPrimitive.fillRectSolid(world, rand, x, y, z, x, y + 2, z, theme.getSecondaryPillar(), true, true);
WorldGenPrimitive.setBlock(world, rand, x, y + 3, z, theme.getPrimaryWall(), true, true);
MetaBlock stair = theme.getSecondaryStair();
stair.setMeta(WorldGenPrimitive.blockOrientation(Cardinal.EAST, true));
WorldGenPrimitive.setBlock(world, x + 1, y + 3, z, stair, true, true);
stair.setBlock(world, x + 1, y + 3, z);
stair.setMeta(WorldGenPrimitive.blockOrientation(Cardinal.WEST, true));
WorldGenPrimitive.setBlock(world, x - 1, y + 3, z, stair, true, true);
stair.setBlock(world, x - 1, y + 3, z);
stair.setMeta(WorldGenPrimitive.blockOrientation(Cardinal.SOUTH, true));
WorldGenPrimitive.setBlock(world, x, y + 3, z + 1, stair, true, true);
stair.setBlock(world, x, y + 3, z + 1);
stair.setMeta(WorldGenPrimitive.blockOrientation(Cardinal.NORTH, true));
WorldGenPrimitive.setBlock(world, x, y + 3, z - 1, stair, true, true);
stair.setBlock(world, x, y + 3, z - 1);
}

public int getSize(){
Expand Down
Loading

0 comments on commit 159a92b

Please sign in to comment.