1
0
Fork 0

Merge remote-tracking branch 'origin/PiegamesDev'

This commit is contained in:
Saibotk 2018-04-23 01:26:33 +02:00
commit 0ed78a8bce
4 changed files with 99 additions and 76 deletions

View file

@ -17,9 +17,6 @@ public class DungeonGenerator {
// All rooms except the three above
public HashSet<GenRoom> rooms;
private const float percentageRocks = 0.03f;
private const int maxRockCluster = 5;
public void Generate() {
int minRoomSize = 50;
rooms = new HashSet<GenRoom>();
@ -147,41 +144,72 @@ public class DungeonGenerator {
path = new GenRoom();
foreach (GenRoom r in rooms2)
{
{
for (int x1 = r.bounds.x; x1 < r.bounds.x + r.bounds.width; x1++)
for (int y1 = r.bounds.y; y1 < r.bounds.y + r.bounds.height; y1++)
{
Vector2Int pos1 = new Vector2Int(x1, y1);
if (path.tiles.ContainsKey(pos1))
path.tiles[pos1].type = Room.TileType.GROUND;
else
path.tiles.Add(pos1, new GenTile(Room.TileType.GROUND));
for (int x2 = x1 - 1; x2 <= x1 + 1; x2++)
{
for (int y2 = y1 - 1; y2 <= y1 + 1; y2++)
{
Vector2Int pos2 = new Vector2Int(x2, y2);
if (!path.tiles.ContainsKey(pos2) && !allDoors.Contains(pos2))
path.tiles.Add(pos2, new GenTile(Room.TileType.WALL));
}
}
if (path.tiles.ContainsKey(pos1))
path.tiles[pos1].type = Room.TileType.GROUND;
else
path.tiles.Add(pos1, new GenTile(Room.TileType.GROUND));
Vector2Int pos2 = new Vector2Int(x1 + 1, y1);
if (!path.tiles.ContainsKey(pos2) && !allDoors.Contains(pos2))
path.tiles.Add(pos2, new GenTile(Room.TileType.WALL, GenTile.Position.RIGHT));
pos2 = new Vector2Int(x1 - 1, y1);
if (!path.tiles.ContainsKey(pos2) && !allDoors.Contains(pos2))
path.tiles.Add(pos2, new GenTile(Room.TileType.WALL, GenTile.Position.LEFT));
pos2 = new Vector2Int(x1, y1 + 1);
if (!path.tiles.ContainsKey(pos2) && !allDoors.Contains(pos2))
path.tiles.Add(pos2, new GenTile(Room.TileType.WALL, GenTile.Position.TOP));
pos2 = new Vector2Int(x1, y1 - 1);
if (!path.tiles.ContainsKey(pos2) && !allDoors.Contains(pos2))
path.tiles.Add(pos2, new GenTile(Room.TileType.WALL, GenTile.Position.BOTTOM));
}
for (int x1 = r.bounds.x; x1 < r.bounds.x + r.bounds.width; x1++)
for (int y1 = r.bounds.y; y1 < r.bounds.y + r.bounds.height; y1++)
{
Vector2Int pos2 = new Vector2Int(x1 + 1, y1 + 1);
if (!path.tiles.ContainsKey(pos2) && !allDoors.Contains(pos2))
path.tiles.Add(pos2, new GenTile(Room.TileType.WALL, GenTile.Position.TOP_RIGHT));
pos2 = new Vector2Int(x1 - 1, y1 + 1);
if (!path.tiles.ContainsKey(pos2) && !allDoors.Contains(pos2))
path.tiles.Add(pos2, new GenTile(Room.TileType.WALL, GenTile.Position.TOP_LEFT));
pos2 = new Vector2Int(x1 + 1, y1 - 1);
if (!path.tiles.ContainsKey(pos2) && !allDoors.Contains(pos2))
path.tiles.Add(pos2, new GenTile(Room.TileType.WALL, GenTile.Position.BOTTOM_RIGHT));
pos2 = new Vector2Int(x1 - 1, y1 - 1);
if (!path.tiles.ContainsKey(pos2) && !allDoors.Contains(pos2))
path.tiles.Add(pos2, new GenTile(Room.TileType.WALL, GenTile.Position.BOTTOM_LEFT));
}
if (r.AllDoors().Count > 0)
throw new NotSupportedException("Paths should not have any doors");
}
//foreach (GenRoom r in rooms) {
// generateInterior (r);
//}
start = root.r;
end = null; foreach ( GenRoom r in rooms ) {
end = null;
foreach ( GenRoom r in rooms ) {
if ( end == null || r.bounds.x > end.bounds.x )
end = r;
end = r;
}
rooms.Remove(start);
rooms.Remove(end);
rooms.Remove(end);
foreach (GenRoom r in rooms)
{
GenerateInterior(r);
}
foreach (Vector2Int v in allDoors) {
foreach (GenRoom r in rooms) {
for (int x = -TUNNEL_THICKNESS; x < TUNNEL_THICKNESS; x++)
for (int y = -TUNNEL_THICKNESS; y < TUNNEL_THICKNESS; y++)
if (r.tiles.ContainsKey(v + new Vector2Int(x, y)) && r.tiles[v + new Vector2Int(x, y)].type == Room.TileType.ROCK)
r.tiles[v + new Vector2Int(x, y)].type = Room.TileType.GROUND;
}
}
foreach ( GenRoom r in rooms )
makeRoomRelative(r);
@ -373,37 +401,34 @@ public class DungeonGenerator {
}
}
public static void generateInterior(GenRoom r) {
//int width = r.bounds.width;
//int height = r.bounds.height;
//Vector2Int root = new Vector2Int (1, 1);
//Random rand = new Random (System.DateTime.Now);
//for(int x = 0; i != width; ++x)
//{
// for(int y = 0; y != width; ++y)
// {
// Room.TileType tempTile;
// r.tiles.TryGetValue (root + new Vector2Int (x, y), tempTile);
// if(rand.NextDouble() <= percentageRocks && tempTile.Equals(Room.TileType.GROUND)
// {
// int clusterSize = rand.Next (1, maxRockCluster + 1);
// r.tiles.Add (root + new Vector2Int (x, y), Room.TileType.ROCK);
// for(int i = 0; i != clusterSize; ++i)
// {
// Vector2Int newRock = root + new Vector2Int(x + rand.Next(0, 2), y + rand.Next(0, 2));
// r.tiles.TryGetValue (newRock, tempTile);
// if(!tempTile.Equals(Room.TileType.GROUND))
// break;
public void GenerateInterior(GenRoom r) {
Vector2Int root = new Vector2Int (1, 1);
for (int x = r.bounds.x; x < r.bounds.x + r.bounds.width; x++)
{
for (int y = r.bounds.y; y < r.bounds.y + r.bounds.height; y++)
{
Vector2Int pos = new Vector2Int(x, y);
if (!r.tiles.ContainsKey(pos) || r.tiles[pos].type != Room.TileType.GROUND)
continue;
float prob = 0.0075f;
if (UnityEngine.Random.value > 1 - prob)
{
r.tiles[pos].type = Room.TileType.ROCK;
}
if (UnityEngine.Random.value > 1 - prob * 2)
{
int count = (int ) (UnityEngine.Random.value * UnityEngine.Random.value * 6);
for (int i = 0; i < count; i++) {
Vector2Int pos2 = pos + new Vector2Int(
(int)((UnityEngine.Random.value - 0.5) * 3),
(int)((UnityEngine.Random.value - 0.5) * 3));
if (r.tiles.ContainsKey(pos2) && r.tiles[pos2].type == Room.TileType.GROUND)
r.tiles[pos2].type = Room.TileType.ROCK;
}
}
}
}
}
}

View file

@ -42,8 +42,4 @@ public class GenRoom {
ret.UnionWith(doorsRight);
return ret;
}
public void generateInteror() {
}
}

View file

@ -6,15 +6,15 @@ public class GenTile
{
public enum Position
{
TOP_LEFT = 0,
TOP = 1,
TOP_RIGHT = 2,
BOTTOM_LEFT = 0,
BOTTOM = 1,
BOTTOM_RIGHT = 2,
LEFT = 3,
CENTER = 4,
RIGHT = 5,
BOTTOM_LEFT = 6,
BOTTOM = 7,
BOTTOM_RIGHT = 8
TOP_LEFT = 6,
TOP = 7,
TOP_RIGHT = 8
}
public Room.TileType type;

View file

@ -27,13 +27,13 @@ public class GenerationProcessor {
switch (tiles[v].position)
{
case GenTile.Position.BOTTOM:
rotation = 0;
rotation = 180;
break;
case GenTile.Position.LEFT:
rotation = 90;
break;
case GenTile.Position.TOP:
rotation = 180;
rotation = 0;
break;
case GenTile.Position.RIGHT:
rotation = 270;
@ -44,16 +44,16 @@ public class GenerationProcessor {
switch (tiles[v].position)
{
case GenTile.Position.BOTTOM_LEFT:
rotation = 0;
break;
case GenTile.Position.TOP_LEFT:
rotation = 90;
break;
case GenTile.Position.TOP_LEFT:
rotation = 0;
break;
case GenTile.Position.TOP_RIGHT:
rotation = 180;
rotation = 270;
break;
case GenTile.Position.BOTTOM_RIGHT:
rotation = 270;
rotation = 180;
break;
}
break;
@ -78,6 +78,8 @@ public class GenerationProcessor {
private GameObject CreateGOFromType(Vector2 v, int rotation, ExtendedTileType t, GameObject root) {
GameObject tmp = null;
//if (t == ExtendedTileType.BorderInner || t == ExtendedTileType.BorderOuter || t == ExtendedTileType.BorderInner)
// CreateGOFromType(v, rotation, ExtendedTileType.Ground, root);
if ( prefabs.ContainsKey(t) && root != null ) {
tmp = Object.Instantiate(prefabs[t], root.transform);
tmp.transform.position = v;
@ -104,7 +106,7 @@ public class GenerationProcessor {
}
private ExtendedTileType getCorrectWallType(Dictionary<Vector2Int, GenTile> tiles, Vector2Int position){
int groundNumber = CountSpecificNeighbours(tiles, position, Room.TileType.GROUND);
int groundNumber = CountSpecificNeighbours(tiles, position, Room.TileType.GROUND) + CountSpecificNeighbours(tiles, position, Room.TileType.ROCK);
switch(groundNumber){
case 0:
return ExtendedTileType.BorderInner;
@ -116,14 +118,14 @@ public class GenerationProcessor {
}
private ExtendedTileType getCorrectRockType(Dictionary<Vector2Int, GenTile> tiles, Vector2Int position){
ExtendedTileType type = ExtendedTileType.Rock;
bool left = false;
bool top = false;
bool right = false;
bool bottom = false;
Vector2Int toCheck = position + new Vector2Int(0, -1);
if (tiles.ContainsKey(toCheck) && tiles[toCheck].type == Room.TileType.ROCK)
bottom = true;
@ -176,7 +178,7 @@ public class GenerationProcessor {
if (right && bottom && !top && !left)
{
return ExtendedTileType.RockRD;
}
}
if (left && top && bottom && !right)
{
return ExtendedTileType.RockLUD;
@ -199,4 +201,4 @@ public class GenerationProcessor {
}
return type;
}
}
}