Skip to content

Commit

Permalink
Distinguish vert. and horiz. doors.
Browse files Browse the repository at this point in the history
  • Loading branch information
tommyettinger committed Apr 14, 2015
1 parent 83d916b commit c04fb86
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 15 deletions.
27 changes: 24 additions & 3 deletions src/main/java/squidpony/squidgrid/mapping/DungeonGenerator.java
Expand Up @@ -82,6 +82,20 @@ public DungeonGenerator(int width, int height, LightRNG rng)
fx = new HashMap<FillEffect, Integer>();
}

/**
* Copies all fields from copying and makes a new DungeonGenerator.
* @param copying
*/
public DungeonGenerator(DungeonGenerator copying)
{
rng = new LightRNG(copying.rng.getState());
gen = new DungeonGen(new LightRNG(copying.gen.rng.getState()));
height = copying.height;
width = copying.width;
fx = new HashMap<FillEffect, Integer>(copying.fx);
dungeon = copying.dungeon;
}

/**
* Turns the given percentage of floor cells into water cells, represented by '~'. Water will be clustered into
* a random number of pools, with more appearing if needed to fill the percentage. Each pool will have randomized
Expand All @@ -99,7 +113,8 @@ public DungeonGenerator addWater(int percentage)
return this;
}
/**
* Turns the given percentage of viable doorways into doors, represented by '+'. If doubleDoors is true,
* Turns the given percentage of viable doorways into doors, represented by '+' for doors that allow travel along
* the x-axis and '/' for doors that allow travel along the y-axis. If doubleDoors is true,
* 2-cell-wide openings will be considered viable doorways and may receive a door in each cell. If this
* DungeonGenerator previously had addDoors called, the latest call will take precedence.
* @param percentage
Expand Down Expand Up @@ -263,13 +278,19 @@ public char[][] generate(TilesetType kind)
for(int i = 0; i < total; i++)
{
Point entry = (Point) doorways.toArray()[rng.nextInt(doorways.size())];
map[entry.x][entry.y] = '+';
if(map[entry.x - 1][entry.y] != '#' && map[entry.x + 1][entry.y] != '#')
{
map[entry.x][entry.y] = '+';
}
else {
map[entry.x][entry.y] = '/';
}
obstacles.add(new Point(entry));
Point[] adj = new Point[]{new Point(entry.x + 1, entry.y), new Point(entry.x - 1, entry.y),
new Point(entry.x, entry.y + 1), new Point(entry.x, entry.y - 1)};
for(Point near : adj) {
if (doorways.contains(near)) {
map[near.x][near.y] = '+';
map[near.x][near.y] = '#';
obstacles.add(new Point(near));
doorways.remove(near);
i++;
Expand Down
24 changes: 12 additions & 12 deletions src/main/java/squidpony/squidgrid/mapping/DungeonUtility.java
Expand Up @@ -139,10 +139,10 @@ public static char[][] hashesToLines(char[][] map)
{
if (dungeon[y][x] == '#')
{
boolean n = (y <= 0 || dungeon[y - 1][x] == '#' || dungeon[y - 1][x] == '+');
boolean e = (x >= Width - 1 || dungeon[y][x + 1] == '#' || dungeon[y][x + 1] == '+');
boolean s = (y >= Height - 1 || dungeon[y + 1][x] == '#' || dungeon[y + 1][x] == '+');
boolean w = (x <= 0 || dungeon[y][x - 1] == '#' || dungeon[y][x - 1] == '+');
boolean n = (y <= 0 || dungeon[y - 1][x] == '#' || dungeon[y - 1][x] == '+' || dungeon[y - 1][x] == '/');
boolean e = (x >= Width - 1 || dungeon[y][x + 1] == '#' || dungeon[y][x + 1] == '+' || dungeon[y][x + 1] == '/');
boolean s = (y >= Height - 1 || dungeon[y + 1][x] == '#' || dungeon[y + 1][x] == '+' || dungeon[y + 1][x] == '/');
boolean w = (x <= 0 || dungeon[y][x - 1] == '#' || dungeon[y][x - 1] == '+' || dungeon[y][x - 1] == '/');

if (n)
{
Expand Down Expand Up @@ -247,10 +247,10 @@ else if (w)
{
if (neo[y - 1][x] == '┼' || neo[y - 1][x] == '├' || neo[y - 1][x] == '┤' || neo[y - 1][x] == '┬')
{
if ((x >= Width - 1 || dungeon[y - 1][x + 1] == '#' || dungeon[y - 1][x + 1] == '\1' || dungeon[y - 1][x + 1] == '+') &&
(x <= 0 || dungeon[y - 1][x - 1] == '#' || dungeon[y - 1][x - 1] == '\1' || dungeon[y - 1][x - 1] == '+') &&
(x >= Width - 1 || dungeon[y][x + 1] == '#' || dungeon[y][x + 1] == '\1' || dungeon[y][x + 1] == '+') &&
(x <= 0 || dungeon[y][x - 1] == '#' || dungeon[y][x - 1] == '\1' || dungeon[y][x - 1] == '+'))
if ((x >= Width - 1 || dungeon[y - 1][x + 1] == '#' || dungeon[y - 1][x + 1] == '\1' || dungeon[y - 1][x + 1] == '+' || dungeon[y - 1][x + 1] == '/') &&
(x <= 0 || dungeon[y - 1][x - 1] == '#' || dungeon[y - 1][x - 1] == '\1' || dungeon[y - 1][x - 1] == '+' || dungeon[y - 1][x - 1] == '/') &&
(x >= Width - 1 || dungeon[y][x + 1] == '#' || dungeon[y][x + 1] == '\1' || dungeon[y][x + 1] == '+' || dungeon[y][x + 1] == '/') &&
(x <= 0 || dungeon[y][x - 1] == '#' || dungeon[y][x - 1] == '\1' || dungeon[y][x - 1] == '+' || dungeon[y][x - 1] == '/'))
{
switch (neo[y][x])
{
Expand Down Expand Up @@ -298,10 +298,10 @@ else if (w)
{
if (neo[y][x - 1] == '┼' || neo[y][x - 1] == '├' || neo[y][x - 1] == '┬' || neo[y][x - 1] == '┴')
{
if ((y >= Height - 1 || dungeon[y + 1][x - 1] == '#' || dungeon[y + 1][x - 1] == '\1' || dungeon[y + 1][x - 1] == '+') &&
(y <= 0 || dungeon[y - 1][x - 1] == '#' || dungeon[y - 1][x - 1] == '\1' || dungeon[y - 1][x - 1] == '+') &&
(y >= Height - 1 || dungeon[y + 1][x] == '#' || dungeon[y + 1][x] == '\1' || dungeon[y + 1][x] == '+') &&
(y <= 0 || dungeon[y - 1][x] == '#' || dungeon[y - 1][x] == '\1' || dungeon[y - 1][x] == '+'))
if ((y >= Height - 1 || dungeon[y + 1][x - 1] == '#' || dungeon[y + 1][x - 1] == '\1' || dungeon[y + 1][x - 1] == '+' || dungeon[y + 1][x - 1] == '/') &&
(y <= 0 || dungeon[y - 1][x - 1] == '#' || dungeon[y - 1][x - 1] == '\1' || dungeon[y - 1][x - 1] == '+' || dungeon[y - 1][x - 1] == '/') &&
(y >= Height - 1 || dungeon[y + 1][x] == '#' || dungeon[y + 1][x] == '\1' || dungeon[y + 1][x] == '+' || dungeon[y + 1][x] == '/') &&
(y <= 0 || dungeon[y - 1][x] == '#' || dungeon[y - 1][x] == '\1' || dungeon[y - 1][x] == '+' || dungeon[y - 1][x] == '/'))
{
switch (neo[y][x])
{
Expand Down

0 comments on commit c04fb86

Please sign in to comment.