@@ -1115,8 +1115,8 @@ Dictionary TerrainGen::generate(
11151115
11161116 for (int x = 0 ; x < width; x++) {
11171117 for (int y = 0 ; y < height; y++) {
1118- int c_height = elevationMap[x][y];
1119- int tile_id = myGridMap->get_cell_item (Vector3i (x, c_height , y));
1118+ int t_height = elevationMap[x][y];
1119+ int tile_id = myGridMap->get_cell_item (Vector3i (x, t_height , y));
11201120 if (tile_id == -1 || tile_id == GROUND)
11211121 continue ;
11221122
@@ -1141,44 +1141,75 @@ Dictionary TerrainGen::generate(
11411141
11421142 //
11431143 // +--------------------+---------------+--------------------+
1144- // | SW (x - 1 , y - 1) | S (x , y - 1) | SE (x + 1, y - 1) |
1144+ // | NE (x - 1 , y - 1) | E (x , y - 1) | SE (x + 1, y - 1) |
11451145 // +--------------------+---------------+--------------------+
1146- // | W (x - 1 , y) | T (x,y) | E (x + 1) , y |
1146+ // | N (x - 1 , y) | T (x,y) | S (x + 1) , y |
11471147 // +--------------------+---------------+--------------------+
1148- // | NW (x - 1 , y + 1) | N (x , y + 1) | NE (x + 1 , y + 1) |
1148+ // | NW (x - 1 , y + 1) | W (x , y + 1) | SW (x + 1 , y + 1) |
11491149 // +--------------------+---------------+--------------------+
11501150 //
1151+ // +----+----+----+ +----+----+----+
1152+ // | m1 | m2 | m3 | | NE | E | SE |
1153+ // +----+----+----+ +----+----+----+
1154+ // | m4 | T | m5 | | N | T | S |
1155+ // +----+----+----+ +----+----+----+
1156+ // | m6 | m7 | m8 | | NW | W | SW |
1157+ // +----+----+----+ +----+----+----+
11511158 //
11521159
11531160 //
11541161 // Cardinal Neighbors
11551162 //
11561163 //
1157- int sHeight = safe_height (x, y - 1 , c_height);
1158- int sTile = safe_tile_at (x, y - 1 ); // m2
1164+ // int nHeight = safe_height(x, y + 1, t_height);
1165+ // int nTile = safe_tile_at(x, y + 1); // m7
1166+
1167+ // int eHeight = safe_height(x + 1, y, t_height);
1168+ // int eTile = safe_tile_at(x + 1, y); // m5
1169+
1170+ // int sHeight = safe_height(x, y - 1, t_height);
1171+ // int sTile = safe_tile_at(x, y - 1); // m2
1172+
1173+ // int wHeight = safe_height(x - 1, y, t_height);
1174+ // int wTile = safe_tile_at(x - 1, y); // m4
11591175
1160- int nHeight = safe_height (x, y + 1 , c_height );
1176+ int nHeight = safe_height (x, y + 1 , t_height );
11611177 int nTile = safe_tile_at (x, y + 1 ); // m7
11621178
1163- int eHeight = safe_height (x + 1 , y, c_height );
1179+ int eHeight = safe_height (x + 1 , y, t_height );
11641180 int eTile = safe_tile_at (x + 1 , y); // m5
11651181
1166- int wHeight = safe_height (x - 1 , y, c_height);
1182+ int sHeight = safe_height (x, y - 1 , t_height);
1183+ int sTile = safe_tile_at (x, y - 1 ); // m2
1184+
1185+ int wHeight = safe_height (x - 1 , y, t_height);
11671186 int wTile = safe_tile_at (x - 1 , y); // m4
11681187
11691188 //
11701189 // Diagonal Neighbors
11711190 //
1172- int neHeight = safe_height (x + 1 , y + 1 , c_height);
1191+ // int neHeight = safe_height(x + 1, y + 1, t_height);
1192+ // int neTile = safe_tile_at(x + 1, y + 1); // m3
1193+
1194+ // int seHeight = safe_height(x + 1, y - 1, t_height);
1195+ // int seTile = safe_tile_at(x + 1, y - 1); // m8
1196+
1197+ // int swHeight = safe_height(x - 1, y - 1, t_height);
1198+ // int swTile = safe_tile_at(x - 1, y - 1); // m6
1199+
1200+ // int nwHeight = safe_height(x - 1, y + 1, t_height);
1201+ // int nwTile = safe_tile_at(x - 1, y + 1); // m1
1202+
1203+ int neHeight = safe_height (x + 1 , y + 1 , t_height);
11731204 int neTile = safe_tile_at (x + 1 , y + 1 ); // m3
11741205
1175- int seHeight = safe_height (x + 1 , y - 1 , c_height );
1206+ int seHeight = safe_height (x + 1 , y - 1 , t_height );
11761207 int seTile = safe_tile_at (x + 1 , y - 1 ); // m8
11771208
1178- int swHeight = safe_height (x - 1 , y - 1 , c_height );
1209+ int swHeight = safe_height (x - 1 , y - 1 , t_height );
11791210 int swTile = safe_tile_at (x - 1 , y - 1 ); // m6
11801211
1181- int nwHeight = safe_height (x - 1 , y + 1 , c_height );
1212+ int nwHeight = safe_height (x - 1 , y + 1 , t_height );
11821213 int nwTile = safe_tile_at (x - 1 , y + 1 ); // m1
11831214
11841215 //
@@ -1354,37 +1385,134 @@ Dictionary TerrainGen::generate(
13541385
13551386 if (tile_id == RAMP_CORNER) {
13561387 // Place Ground under Ramp Tiles
1357- myGridMap->set_cell_item (Vector3i (x, c_height - 1 , y), GROUND, rotation_val);
1388+ myGridMap->set_cell_item (Vector3i (x, t_height - 1 , y), GROUND, rotation_val);
13581389 }
13591390
1360- myGridMap->set_cell_item (Vector3i (x, c_height , y), tile_id, rotation_val);
1391+ myGridMap->set_cell_item (Vector3i (x, t_height , y), tile_id, rotation_val);
13611392
13621393 // ? : Below is 2 Edge case's that need fixed
13631394 // TODO : Fix these Edge Case's
13641395
1365- // EDGE CASE : Higher Ground has to connect to Cliffs
1366- // nwTile = m1 (n1) | sTile = m2 (n2) | wTile = m4 (n3) | T = tile_id (n4)
1396+ /* ****************************************************
1397+
1398+ EDGE CASE FIX :
1399+
1400+ Floating Ground Tile Fix
1401+
1402+ *****************************************************/
1403+
1404+ // EDGE CASE : Higher Ground has to connect to Cliffs 1
1405+ //
1406+ // +--------------------+---------------+--------------------+
1407+ // | NE (x - 1 , y - 1) | E (x , y - 1) | SE (x + 1, y - 1) |
1408+ // +--------------------+---------------+--------------------+
1409+ // | N (x - 1 , y) | T (x,y) | S (x + 1) , y |
1410+ // +--------------------+---------------+--------------------+
1411+ // | NW (x - 1 , y + 1) | W (x , y + 1) | SW (x + 1 , y + 1) |
1412+ // +--------------------+---------------+--------------------+
13671413 //
1368- // +----+----+ +----+----+ +----+----+ +----+----+
1369- // | n1 | n2 | | g1 | r2 | | r2 | g1 | | g1 | c2 |
1370- // +----+----+ +----+----+ +----+----+ -> +----+----+
1371- // | n3 | n4 | | r2 | g2 | | g2 | r2 | | c2 | g2 |
1372- // +----+----+ +----+----+ +----+----+ +----+----+
1414+ // +----+----+----+ +----+----+----+ +----+----+----+
1415+ // | m1 | m2 | m3 | | G | R | X | | R | G | X |
1416+ // +----+----+----+ +----+----+----+ +----+----+----+
1417+ // | m4 | T | m5 | | R | G | X | | G | R | X |
1418+ // +----+----+----+ +----+----+----+ +----+----+----+
1419+ // | m6 | m7 | m8 | | X | X | X | | X | X | X |
1420+ // +----+----+----+ +----+----+----+ +----+----+----+
13731421 //
1374- if ((nwTile == GROUND && sTile == RAMP && wTile == RAMP && tile_id == GROUND)) {
1422+
1423+ if ((swTile == GROUND && sTile == RAMP && wTile == RAMP && tile_id == GROUND)) {
1424+ // Set Floating Ground to Cliff Corner
1425+ if (swHeight > t_height) {
1426+ myGridMap->set_cell_item (Vector3i (x - 1 , swHeight, y - 1 ), CLIFF_CORNER, WEST); // m1
1427+ } else {
1428+ myGridMap->set_cell_item (Vector3i (x, t_height, y), CLIFF_CORNER, EAST); // T
1429+ }
1430+
13751431 // Get Orientation (Rotation) Value
1376- int n1O = myGridMap->get_cell_item_orientation (Vector3i (x - 1 , nwHeight, y - 1 )); // m1
1377- // int n2O = myGridMap->get_cell_item_orientation(Vector3i(x, sHeight, y - 1)); // m2
1378- // int n3O = myGridMap->get_cell_item_orientation(Vector3i(x - 1, wHeight, y)); // m4
1379- int n4O = myGridMap->get_cell_item_orientation (Vector3i (x, c_height, y)); // Target
1432+ int rot1 = myGridMap->get_cell_item_orientation (Vector3i (x, sHeight , y - 1 )); // m2
1433+ int rot2 = myGridMap->get_cell_item_orientation (Vector3i (x - 1 , wHeight, y)); // m4
13801434
13811435 // Set Ramps to Cliffs
1382- myGridMap->set_cell_item (Vector3i (x - 1 , nwHeight, y - 1 ), CLIFF, n1O); // n1
1383- // myGridMap->set_cell_item(Vector3i(x, sHeight, y - 1), CLIFF, n2O); // n2
1384- // myGridMap->set_cell_item(Vector3i(x - 1, wHeight, y), CLIFF, n3O); // n3
1385- myGridMap->set_cell_item (Vector3i (x, c_height, y), CLIFF, n4O); // n4
1436+ myGridMap->set_cell_item (Vector3i (x, sHeight , y - 1 ), CLIFF, rot1); // m2
1437+ myGridMap->set_cell_item (Vector3i (x - 1 , wHeight, y), CLIFF, rot2); // m4
13861438 }
13871439
1440+ if ((swTile == RAMP && sTile == GROUND && wTile == GROUND && tile_id == RAMP)) {
1441+ // Set Floating Ground to Cliff Corner
1442+ if (sHeight > wHeight) {
1443+ myGridMap->set_cell_item (Vector3i (x, sHeight , y - 1 ), CLIFF_CORNER, NORTH); // m3
1444+ } else {
1445+ myGridMap->set_cell_item (Vector3i (x - 1 , wHeight, y), CLIFF_CORNER, WEST); // m4
1446+ }
1447+
1448+ // Get Orientation (Rotation) Value
1449+ int rot1 = myGridMap->get_cell_item_orientation (Vector3i (x - 1 , swHeight, y - 1 )); // m3
1450+ int rot2 = myGridMap->get_cell_item_orientation (Vector3i (x, t_height, y)); // T
1451+
1452+ // Set Ramps to Cliffs
1453+ myGridMap->set_cell_item (Vector3i (x - 1 , swHeight, y - 1 ), CLIFF, rot1); // m3
1454+ myGridMap->set_cell_item (Vector3i (x, t_height, y), CLIFF, rot2); // T
1455+ }
1456+
1457+ // EDGE CASE : Higher Ground has to connect to Cliffs 2
1458+ //
1459+ // +--------------------+---------------+--------------------+
1460+ // | NE (x - 1 , y - 1) | E (x , y - 1) | SE (x + 1, y - 1) |
1461+ // +--------------------+---------------+--------------------+
1462+ // | N (x - 1 , y) | T (x,y) | S (x + 1) , y |
1463+ // +--------------------+---------------+--------------------+
1464+ // | NW (x - 1 , y + 1) | W (x , y + 1) | SW (x + 1 , y + 1) |
1465+ // +--------------------+---------------+--------------------+
1466+ //
1467+ // +----+----+----+ +----+----+----+ +----+----+----+
1468+ // | m1 | m2 | m3 | | X | G | R | | X | R | G |
1469+ // +----+----+----+ +----+----+----+ +----+----+----+
1470+ // | m4 | T | m5 | | X | R | G | | X | G | R |
1471+ // +----+----+----+ +----+----+----+ +----+----+----+
1472+ // | m6 | m7 | m8 | | X | X | X | | X | X | X |
1473+ // +----+----+----+ +----+----+----+ +----+----+----+
1474+
1475+ if ((seTile == RAMP && sTile == GROUND && eTile == GROUND && tile_id == RAMP)) {
1476+ // Set Floating Ground to Cliff Corner
1477+ if (sHeight > eHeight) {
1478+ myGridMap->set_cell_item (Vector3i (x, sHeight , y - 1 ), CLIFF_CORNER, WEST); // m3
1479+ } else {
1480+ myGridMap->set_cell_item (Vector3i (x + 1 , eHeight, y), CLIFF_CORNER, EAST); // T
1481+ }
1482+
1483+ // Get Orientation (Rotation) Value
1484+ int rot1 = myGridMap->get_cell_item_orientation (Vector3i (x + 1 , seHeight, y - 1 )); // m3
1485+ int rot2 = myGridMap->get_cell_item_orientation (Vector3i (x, t_height, y)); // T
1486+
1487+ // Set Ramps to Cliffs
1488+ myGridMap->set_cell_item (Vector3i (x + 1 , seHeight, y - 1 ), CLIFF, rot1); // m3
1489+ myGridMap->set_cell_item (Vector3i (x, t_height, y), CLIFF, rot2); // T
1490+ }
1491+
1492+ if ((seTile == GROUND && sTile == RAMP && eTile == RAMP && tile_id == GROUND)) {
1493+ // Set Floating Ground to Cliff Corner
1494+ if (seHeight > t_height) {
1495+ myGridMap->set_cell_item (Vector3i (x + 1 , seHeight, y - 1 ), CLIFF_CORNER, NORTH); // m3
1496+ } else {
1497+ myGridMap->set_cell_item (Vector3i (x, t_height, y), CLIFF_CORNER, SOUTH); // T
1498+ }
1499+
1500+ // Set Ramp's to Cliffs
1501+ int rot1 = myGridMap->get_cell_item_orientation (Vector3i (x, sHeight , y - 1 )); // m2
1502+ int rot2 = myGridMap->get_cell_item_orientation (Vector3i (x + 1 , eHeight, y)); // m5
1503+
1504+ myGridMap->set_cell_item (Vector3i (x, sHeight , y - 1 ), CLIFF, rot1); // m2
1505+ myGridMap->set_cell_item (Vector3i (x + 1 , eHeight, y), CLIFF, rot2); // m5
1506+ }
1507+
1508+ /* ****************************************************
1509+
1510+ EDGE CASE FIX :
1511+
1512+
1513+
1514+ *****************************************************/
1515+
13881516 // EDGE CASE : Higher Ground has to connect to Cliffs
13891517 //
13901518 // +----+----+ +----+----+ +----+----+ +----+----+ +----+----+ +----+----+
0 commit comments