Skip to content

Commit ec10505

Browse files
author
Ellendar
committed
More bridge fixes
1 parent afe5328 commit ec10505

1 file changed

Lines changed: 64 additions & 6 deletions

File tree

RandomizerCore/Overworld/World.cs

Lines changed: 64 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -837,8 +837,8 @@ protected bool ConnectIslands(int maxBridges, bool placeSaria, Terrain riverTerr
837837
int adjacentRiverTerrainDirectionCount = 0;
838838
//If the tile just before or just after is walkable, this is the first or last tile of the bridge
839839
//When that happens, the adjacent (not forward/back) directions are allowed to be any walkable terrain
840-
bool isFirstStep = walkableTerrains.Contains(map[y - deltaY, x - deltaX]);
841-
bool isLastStep = walkableTerrains.Contains(map[y + deltaY, x + deltaX]);
840+
bool isFirstStep = !crossingTerrains.Contains(map[y - deltaY, x - deltaX]);
841+
bool isLastStep = !crossingTerrains.Contains(map[y + deltaY, x + deltaX]);
842842
Terrain[] effectiveCrossingTerrain = isFirstStep || isLastStep ? edgeCrossingTerrains : crossingTerrains;
843843

844844
//Check forward
@@ -944,7 +944,7 @@ protected bool ConnectIslands(int maxBridges, bool placeSaria, Terrain riverTerr
944944
map[y - deltaY, x - deltaX] = Terrain.BRIDGE;
945945
}
946946

947-
while (walkableTerrains.Contains(map[y + perpDy, x + perpDx]) || walkableTerrains.Contains(map[y - perpDy, x - perpDx]))
947+
while (!crossingTerrains.Contains(map[y + perpDy, x + perpDx]) || !crossingTerrains.Contains(map[y - perpDy, x - perpDx]))
948948
{
949949
if ((deltaY < 0 && y > startY) || (deltaY > 0 && y < startY) || (deltaX < 0 && x > startX) || (deltaX > 0 && x < startX))
950950
{
@@ -954,6 +954,11 @@ protected bool ConnectIslands(int maxBridges, bool placeSaria, Terrain riverTerr
954954
x -= deltaX;
955955
y -= deltaY;
956956
}
957+
if (crossingTerrains.Contains(map[y + deltaY, x + deltaX]))
958+
{
959+
x += deltaX;
960+
y += deltaY;
961+
}
957962

958963
if (deltaX > 0 || deltaY > 0)
959964
{
@@ -966,15 +971,40 @@ protected bool ConnectIslands(int maxBridges, bool placeSaria, Terrain riverTerr
966971
bridge1.Y = y;
967972
}
968973

969-
while (crossingTerrains.Contains(map[y, x]))
974+
if ((map[y + perpDy, x + perpDx] == Terrain.MOUNTAIN || map[y + perpDy, x + perpDx].IsWater())
975+
&& map[y - perpDy, x - perpDx] != Terrain.MOUNTAIN && !map[y - perpDy, x - perpDx].IsWater())
976+
{
977+
map[y - perpDy, x - perpDx] = map[y + perpDy, x + perpDx];
978+
}
979+
if ((map[y - perpDy, x - perpDx] == Terrain.MOUNTAIN || map[y - perpDy, x - perpDx].IsWater())
980+
&& map[y + perpDy, x + perpDx] != Terrain.MOUNTAIN && !map[y + perpDy, x + perpDx].IsWater())
981+
{
982+
map[y + perpDy, x + perpDx] = map[y - perpDy, x - perpDx];
983+
}
984+
985+
while ((deltaX != 0 && x != startX) || (deltaY != 0 && y != startY))
970986
{
971987
map[y, x] = Terrain.BRIDGE;
972988
x -= deltaX;
973989
y -= deltaY;
990+
}
974991

992+
if (crossingTerrains.Contains(map[y,x]))
993+
{
994+
map[y, x] = map[y - deltaY, x - deltaX];
975995
}
976996
x += deltaX;
977997
y += deltaY;
998+
if ((map[y + perpDy, x + perpDx] == Terrain.MOUNTAIN || map[y + perpDy, x + perpDx].IsWater())
999+
&& map[y - perpDy, x - perpDx] != Terrain.MOUNTAIN && !map[y - perpDy, x - perpDx].IsWater())
1000+
{
1001+
map[y - perpDy, x - perpDx] = map[y + perpDy, x + perpDx];
1002+
}
1003+
if ((map[y - perpDy, x - perpDx] == Terrain.MOUNTAIN || map[y - perpDy, x - perpDx].IsWater())
1004+
&& map[y + perpDy, x + perpDx] != Terrain.MOUNTAIN && !map[y + perpDy, x + perpDx].IsWater())
1005+
{
1006+
map[y + perpDy, x + perpDx] = map[y - perpDy, x - perpDx];
1007+
}
9781008
map[y, x] = Terrain.BRIDGE;
9791009
if (deltaX > 0 || deltaY > 0)
9801010
{
@@ -1001,7 +1031,7 @@ protected bool ConnectIslands(int maxBridges, bool placeSaria, Terrain riverTerr
10011031
map[y - deltaY, x - deltaX] = Terrain.DESERT;
10021032
}
10031033
//Walk backwards until the first tile flanked on both sides by the river
1004-
while (walkableTerrains.Contains(map[y + perpDy, x + perpDx]) || walkableTerrains.Contains(map[y - perpDy, x - perpDx]))
1034+
while (!crossingTerrains.Contains(map[y + perpDy, x + perpDx]) && !crossingTerrains.Contains(map[y - perpDy, x - perpDx]))
10051035
{
10061036
if ((deltaY < 0 && y > startY) || (deltaY > 0 && y < startY) || (deltaX < 0 && x > startX) || (deltaX > 0 && x < startX))
10071037
{
@@ -1024,17 +1054,45 @@ protected bool ConnectIslands(int maxBridges, bool placeSaria, Terrain riverTerr
10241054
bridge1.Y = y;
10251055
}
10261056

1057+
if ((map[y + perpDy, x + perpDx] == Terrain.MOUNTAIN || map[y + perpDy, x + perpDx].IsWater())
1058+
&& map[y - perpDy, x - perpDx] != Terrain.MOUNTAIN && !map[y - perpDy, x - perpDx].IsWater())
1059+
{
1060+
map[y - perpDy, x - perpDx] = map[y + perpDy, x + perpDx];
1061+
}
1062+
if ((map[y - perpDy, x - perpDx] == Terrain.MOUNTAIN || map[y - perpDy, x - perpDx].IsWater())
1063+
&& map[y + perpDy, x + perpDx] != Terrain.MOUNTAIN && !map[y + perpDy, x + perpDx].IsWater())
1064+
{
1065+
map[y + perpDy, x + perpDx] = map[y - perpDy, x - perpDx];
1066+
}
1067+
10271068
//Keep walking back placing deserts until the path opens up
1028-
while (!walkableTerrains.Contains(map[y + perpDy, x + perpDx]) && !walkableTerrains.Contains(map[y - perpDy, x - perpDx]))
1069+
while ((deltaX != 0 && x != startX) || (deltaY != 0 && y != startY))
10291070
{
10301071
map[y, x] = Terrain.DESERT;
10311072
x -= deltaX;
10321073
y -= deltaY;
10331074
}
1075+
//If you're going into a C-shape, you'll have a dead stub of water. fill it in
1076+
if (map[y, x].IsWater())
1077+
{
1078+
map[y, x] = map[y - deltaY, x - deltaX];
1079+
}
10341080

10351081
//now we're past the opening, so go the other way 1
10361082
x += deltaX;
10371083
y += deltaY;
1084+
1085+
//If exactly one of the tiles adjacent to the bridge is a potentially impassable, demolish it so you can't get stuck in it.
1086+
if ((map[y + perpDy, x + perpDx] == Terrain.MOUNTAIN || map[y + perpDy, x + perpDx].IsWater())
1087+
&& map[y - perpDy, x - perpDx] != Terrain.MOUNTAIN && !map[y - perpDy, x - perpDx].IsWater())
1088+
{
1089+
map[y - perpDy, x - perpDx] = map[y + perpDy, x + perpDx];
1090+
}
1091+
if ((map[y - perpDy, x - perpDx] == Terrain.MOUNTAIN || map[y - perpDy, x - perpDx].IsWater())
1092+
&& map[y + perpDy, x + perpDx] != Terrain.MOUNTAIN && !map[y + perpDy, x + perpDx].IsWater())
1093+
{
1094+
map[y + perpDy, x + perpDx] = map[y - perpDy, x - perpDx];
1095+
}
10381096
map[y, x] = Terrain.DESERT;
10391097
if (deltaX > 0 || deltaY > 0)
10401098
{

0 commit comments

Comments
 (0)