| 1542 | #include "EditLineDialog.h" |
| 1543 | |
| 1544 | void CTerrainDialog::OnDropTerrain() { |
| 1545 | int desired_height, lowest_height, highest_height, delta_height; |
| 1546 | int x, y; |
| 1547 | |
| 1548 | // Find lowest & highest terrain values |
| 1549 | for (x = 0, lowest_height = INT_MAX, highest_height = 0; x < TERRAIN_WIDTH; x++) |
| 1550 | for (y = 0; y < TERRAIN_DEPTH; y++) { |
| 1551 | if (Terrain_seg[x * TERRAIN_WIDTH + y].ypos < lowest_height) |
| 1552 | lowest_height = Terrain_seg[x * TERRAIN_WIDTH + y].ypos; |
| 1553 | if (Terrain_seg[x * TERRAIN_WIDTH + y].ypos > highest_height) |
| 1554 | highest_height = Terrain_seg[x * TERRAIN_WIDTH + y].ypos; |
| 1555 | } |
| 1556 | |
| 1557 | // Get desired terrain level |
| 1558 | get_height:; |
| 1559 | if (!InputNumber(&desired_height, "Raise/Lower Terrain", "Enter the desired height for the lowest terrain point:")) |
| 1560 | return; |
| 1561 | |
| 1562 | // Check valid values |
| 1563 | if ((desired_height < 0) || (desired_height > 255)) { |
| 1564 | OutrageMessageBox("Invalid value: the height must be between 0 and 255, inclusive."); |
| 1565 | goto get_height; |
| 1566 | } |
| 1567 | if (((highest_height - lowest_height) + desired_height) > 255) { |
| 1568 | OutrageMessageBox("The delta height of the terrain is %d, so you cannot set the lowest point above %d.", |
| 1569 | highest_height - lowest_height, 255 - (highest_height - lowest_height)); |
| 1570 | goto get_height; |
| 1571 | } |
| 1572 | |
| 1573 | // Compute delta |
| 1574 | delta_height = desired_height - lowest_height; |
| 1575 | |
| 1576 | // Now lower the terrain |
| 1577 | for (x = 0; x < TERRAIN_WIDTH; x++) |
| 1578 | for (y = 0; y < TERRAIN_DEPTH; y++) |
| 1579 | Terrain_seg[x * TERRAIN_WIDTH + y].ypos += delta_height; |
| 1580 | |
| 1581 | // Update stuff |
| 1582 | BuildMinMaxTerrain(); |
| 1583 | |
| 1584 | // How much we move by |
| 1585 | float delta_y = delta_height * TERRAIN_HEIGHT_INCREMENT; |
| 1586 | |
| 1587 | int r, v, o, p, n; |
| 1588 | room *rp; |
| 1589 | |
| 1590 | // Drop all the rooms |
| 1591 | for (r = 0, rp = Rooms; r <= Highest_room_index; r++, rp++) |
| 1592 | if (rp->used) |
| 1593 | for (v = 0; v < rp->num_verts; v++) |
| 1594 | rp->verts[v].y += delta_y; |
| 1595 | |
| 1596 | // Drop all the objects |
| 1597 | for (o = 0; o <= Highest_object_index; o++) |
| 1598 | if (Objects[o].type != OBJ_NONE) { |
| 1599 | vector new_pos = Objects[o].pos; |
| 1600 | new_pos.y += delta_y; |
| 1601 | ObjSetPos(&Objects[o], &new_pos, Objects[o].roomnum, NULL, false); |
nothing calls this directly
no test coverage detected