@@ -1260,9 +1260,9 @@ Dictionary TerrainGen::generate(
1260
1260
//
1261
1261
// Phase 2 : Determine the Tile's Rotation
1262
1262
//
1263
- // Models: ramps/cliffs/water_edge start with HIGH side pointing −Z (NORTH).
1264
- // Corner models start with HIGH at (−Z, +X) i.e., NE corner.
1265
- // Rotation indices: NORTH=0, EAST=16, SOUTH=10, WEST=22
1263
+ // Models: Ramp Corner's/ Cliff Corner's / Water Corner's start with HIGH at (−Z, +X)
1264
+ // i.e., NE corner.
1265
+ // Ramps / Cliffs / Water Edge's point at -Z (North)
1266
1266
//
1267
1267
// T = Target Cell / Target Tile
1268
1268
// +----+----+----+
@@ -1326,59 +1326,48 @@ Dictionary TerrainGen::generate(
1326
1326
int nwTile = safe_tile_at (x - 1 , y + 1 ); // m1
1327
1327
1328
1328
if (tile_id == RAMP || tile_id == CLIFF || tile_id == WATER_EDGE) {
1329
- // Point HIGH side toward the highest GROUND neighbor (uphill)
1330
- float best_diff = -1e9f;
1331
- if (sTile == GROUND) {
1332
- float d = float (sHeight ) - float (c_height);
1333
- if (d > best_diff) {
1334
- best_diff = d;
1335
- rotation_val = SOUTH;
1336
- }
1337
- }
1338
- if (nTile == GROUND) {
1339
- float d = float (nHeight) - float (c_height);
1340
- if (d > best_diff) {
1341
- best_diff = d;
1342
- rotation_val = NORTH;
1343
- }
1329
+ // +----+----+----+
1330
+ // | m1 | m2 | m3 |
1331
+ // +----+----+----+
1332
+ // | m4 | T | m5 |
1333
+ // +----+----+----+
1334
+ // | m6 | m7 | m8 |
1335
+ // +----+----+----+
1336
+
1337
+ // Cardinal's
1338
+ //
1339
+ // N (m7), E (m5), S (m2), W (m4)
1340
+ //
1341
+ // Only two possible combinations an edge piece can be placed
1342
+ // Since an edge piece must connect from lower elevation to
1343
+ // higher elevation.
1344
+ // Thus, m2 + m7 vs m4 + m5
1345
+ //
1346
+ // Of those two combinations, there is two ways to rotate
1347
+ //
1348
+
1349
+ // North is higher than South
1350
+ // Point to m7
1351
+ if (nHeight == sHeight + 1 && static_cast <TileType>(nTile) == GROUND) {
1352
+ rotation_val = NORTH;
1344
1353
}
1345
- if (eTile == GROUND) {
1346
- float d = float (eHeight) - float (c_height);
1347
- if (d > best_diff) {
1348
- best_diff = d;
1349
- rotation_val = EAST;
1350
- }
1354
+
1355
+ // South is higher than North
1356
+ // Point to m2
1357
+ if (sHeight == nHeight + 1 && static_cast <TileType>(sTile ) == GROUND) {
1358
+ rotation_val = SOUTH;
1351
1359
}
1352
- if (wTile == GROUND) {
1353
- float d = float (wHeight) - float (c_height);
1354
- if (d > best_diff) {
1355
- best_diff = d;
1356
- rotation_val = WEST;
1357
- }
1360
+
1361
+ // East is higher than West
1362
+ // Point to m5
1363
+ if (eHeight == wHeight + 1 && static_cast <TileType>(eTile) == GROUND) {
1364
+ rotation_val = EAST;
1358
1365
}
1359
1366
1360
- // Fallback: if no GROUND neighbor higher, use steepest slope regardless of type
1361
- if (best_diff <= -1e8f) {
1362
- float bd = -1e9f;
1363
- float dN = float (nHeight) - float (c_height);
1364
- float dS = float (sHeight ) - float (c_height);
1365
- float dE = float (eHeight) - float (c_height);
1366
- float dW = float (wHeight) - float (c_height);
1367
- if (dN > bd) {
1368
- bd = dN;
1369
- }
1370
- if (dS > bd) {
1371
- bd = dS;
1372
- rotation_val = SOUTH;
1373
- }
1374
- if (dE > bd) {
1375
- bd = dE;
1376
- rotation_val = EAST;
1377
- }
1378
- if (dW > bd) {
1379
- bd = dW;
1380
- rotation_val = WEST;
1381
- }
1367
+ // West is higher than East
1368
+ // Point to m4
1369
+ if (wHeight == eHeight + 1 && static_cast <TileType>(wTile) == GROUND) {
1370
+ rotation_val = WEST;
1382
1371
}
1383
1372
}
1384
1373
@@ -1393,10 +1382,9 @@ Dictionary TerrainGen::generate(
1393
1382
//
1394
1383
// T should consider m2 + m5, m5 + m7, m7 + m4, and m4 + m2; for cliffs and ramps
1395
1384
// Then it should find the highest elevation of ground piece at, m3, m8, m6, m1
1396
- // Then it should decide the rotation by rotating the cliff corner / ramp corner / water corner
1397
- // toward the higher elevation
1385
+ // Then it should decide the rotation by rotating the corner toward the higher elevation
1398
1386
//
1399
- // Corner meshes: choose the corner defined by edge tiles around T, then aim toward the higher diagonal ground
1387
+ // choose corner defined by edge tiles around T, aim toward the higher diagonal ground
1400
1388
//
1401
1389
else if (tile_id == RAMP_CORNER || tile_id == CLIFF_CORNER || tile_id == WATER_CORNER) {
1402
1390
int ROT_CORNER_NE = WEST;
@@ -1429,8 +1417,6 @@ Dictionary TerrainGen::generate(
1429
1417
const bool swGround = (static_cast <TileType>(swTile) == GROUND);
1430
1418
const bool nwGround = (static_cast <TileType>(nwTile) == GROUND);
1431
1419
1432
- // TODO : Find Cardinal Pairs
1433
-
1434
1420
// +----+----+----+
1435
1421
// | m1 | m2 | m3 |
1436
1422
// +----+----+----+
0 commit comments