Skip to content
This repository was archived by the owner on Mar 16, 2023. It is now read-only.

Commit 83a8f01

Browse files
committed
Refactoring SplitRoom() again
1 parent a37ceec commit 83a8f01

File tree

1 file changed

+25
-34
lines changed

1 file changed

+25
-34
lines changed

Assets/Scripts/Generation/POI/BuildingGenerator.cs

Lines changed: 25 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,15 @@ void ResetNoise()
5858

5959
public void Generate()
6060
{
61-
GenerateMainWing(0, minWidth:40, maxWidth:50, minHeight:80, maxHeight:100);
61+
GenerateMainWing(-1, minWidth:40, maxWidth:50, minHeight:40, maxHeight:50);
6262
GenerateRooms(wings[0]);
63-
GenerateWing(wings[0].entrances[0], wings[0], minWidth:40, maxWidth:60, minHeight:40, maxHeight:60);
63+
64+
GenerateWing(wings[0].entrances[0], wings[0], minWidth:30, maxWidth:40, minHeight:120, maxHeight:150);
6465
GenerateRooms(wings[1], wings[0], 0);
65-
GenerateWing(RandomPointOnSide(1, wings[0].bounds), wings[0], minWidth:40, maxWidth:60, minHeight:40, maxHeight:60);
66+
67+
GenerateWing(wings[1].entrances[0], wings[1], minWidth:20, maxWidth:30, minHeight:90, maxHeight:120);
68+
GenerateRooms(wings[2], wings[1], 0);
69+
6670
//GenerateWing(RandomPointOnSide(3, wings[2].bounds), wings[2], minWidth:20, maxWidth:40, minHeight:20, maxHeight:40);
6771
}
6872

@@ -77,13 +81,14 @@ void GenerateMainWing(int startPoint, int minWidth = 0, int maxWidth = 0, int mi
7781
switch(startPoint)
7882
{
7983
case -1:
80-
bounds[right] = zone.bufferedBounds[right];
81-
bounds[left] = zone.bufferedBounds[right] - width;
84+
bounds[left] = zone.bufferedBounds[left];
85+
bounds[right] = zone.bufferedBounds[left] + width;
8286
break;
8387

8488
case 1:
85-
bounds[left] = zone.bufferedBounds[left];
86-
bounds[right] = zone.bufferedBounds[left] + width;
89+
90+
bounds[right] = zone.bufferedBounds[right];
91+
bounds[left] = zone.bufferedBounds[right] - width;
8792
break;
8893

8994
case 0:
@@ -324,6 +329,7 @@ void GenerateRooms(Wing wing, Wing? connectedWing = null, int connectionIndex =
324329
}
325330

326331
// TODO: Second corridor split is always perpendicular to first
332+
// TODO: Separate into SplitRoom(), SplitRoomAtConnector - SplitHorizontal(), SplitVertical()
327333
bool SplitRoom(Room room, Wing wing, Wing? connectedWing = null, int connectionIndex = 0, int corridorWidth = 0, bool firstSplit = false)
328334
{
329335
if(connectedWing == null)
@@ -403,36 +409,15 @@ bool SplitRoom(Room room, Wing wing, Wing? connectedWing = null, int connectionI
403409
splitPoint = (int)(room.bounds[3] + splitValue);
404410
}
405411

406-
if(splitX)
407-
{
408-
int splitA = top; // Split
409-
int splitB = bottom;
410-
int perpA = right; // Perpendicular
411-
int perpB = left;
412-
int breadth = width; // Breadth of split sides
413-
int length = height; // Length of split line
414-
}
415-
else
416-
{
417-
int splitA = right;
418-
int splitB = left;
419-
int perpA = top;
420-
int perpB = bottom;
421-
int breadth = height;
422-
int length = width;
423-
}
424-
425412
// Split X axis
426413
if(splitX)
427414
{
428-
429-
430415
// If corridor reaches edge of wing create entrance
431416
if(corridorWidth > 0)
432417
{
433-
if(2 != (int)zone.back && room.bounds[2] == wing.bounds[2])
418+
if(room.bounds[2] == wing.bounds[2] && room.bounds[2] != zone.bufferedBounds[2])
434419
wing.AddEntrance(new Int2(splitPoint, room.bounds[2]), corridorWidth);
435-
else if(3 != (int)zone.back && room.bounds[3] == wing.bounds[3])
420+
if(room.bounds[3] == wing.bounds[3] && room.bounds[3] != zone.bufferedBounds[3])
436421
wing.AddEntrance(new Int2(splitPoint, room.bounds[3]), corridorWidth);
437422
}
438423

@@ -462,10 +447,10 @@ bool SplitRoom(Room room, Wing wing, Wing? connectedWing = null, int connectionI
462447

463448
if(corridorWidth > 0)
464449
{
465-
if(0 != (int)zone.back && room.bounds[0] == wing.bounds[0])
450+
if(room.bounds[0] == wing.bounds[0] && room.bounds[0] != zone.bufferedBounds[0])
466451
wing.AddEntrance(new Int2(room.bounds[0], splitPoint), corridorWidth);
467-
else if(1 != (int)zone.back && room.bounds[1] == wing.bounds[1])
468-
wing.AddEntrance(new Int2(room.bounds[1], splitPoint), corridorWidth);
452+
if(room.bounds[1] == wing.bounds[1] && room.bounds[1] != zone.bufferedBounds[1])
453+
wing.AddEntrance(new Int2(room.bounds[1], splitPoint), corridorWidth);
469454
}
470455

471456
boundsA = new int[] { room.bounds[0], room.bounds[1], splitPoint - (corridorWidth/2), room.bounds[3] };
@@ -609,10 +594,16 @@ public void ApplyMaps(POILibrary.POI poi)
609594
{
610595
foreach(int i in wing.connectedEntrances)
611596
{
612-
Debug.Log("drawing connector at "+wing.entrances[i]);
613597
DrawConnector(zone.wallMatrix, 0, wing.entrances[i], Side(wing.entrances[i], wing.bounds), wing.entranceSizes[i]);
614598
}
615599
}
600+
foreach(Wing wing in wings)
601+
{
602+
foreach(Int2 e in wing.entrances)
603+
{
604+
DrawPoint(e, zone.wallMatrix, 3);
605+
}
606+
}
616607

617608
SetColumnMaps(poi);
618609
}

0 commit comments

Comments
 (0)